diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio index 2e33dc6b2346..dda81ffae5cf 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio +++ b/Documentation/ABI/testing/sysfs-bus-iio @@ -690,45 +690,45 @@ Description: Actually start the buffer capture up. Will start trigger if first device and appropriate. -What: /sys/bus/iio/devices/iio:deviceX/buffer/scan_elements +What: /sys/bus/iio/devices/iio:deviceX/scan_elements KernelVersion: 2.6.37 Contact: linux-iio@vger.kernel.org Description: Directory containing interfaces for elements that will be captured for a single triggered sample set in the buffer. -What: /sys/.../buffer/scan_elements/in_accel_x_en -What: /sys/.../buffer/scan_elements/in_accel_y_en -What: /sys/.../buffer/scan_elements/in_accel_z_en -What: /sys/.../buffer/scan_elements/in_anglvel_x_en -What: /sys/.../buffer/scan_elements/in_anglvel_y_en -What: /sys/.../buffer/scan_elements/in_anglvel_z_en -What: /sys/.../buffer/scan_elements/in_magn_x_en -What: /sys/.../buffer/scan_elements/in_magn_y_en -What: /sys/.../buffer/scan_elements/in_magn_z_en -What: /sys/.../buffer/scan_elements/in_timestamp_en -What: /sys/.../buffer/scan_elements/in_voltageY_supply_en -What: /sys/.../buffer/scan_elements/in_voltageY_en -What: /sys/.../buffer/scan_elements/in_voltageY-voltageZ_en -What: /sys/.../buffer/scan_elements/in_incli_x_en -What: /sys/.../buffer/scan_elements/in_incli_y_en -What: /sys/.../buffer/scan_elements/in_pressureY_en -What: /sys/.../buffer/scan_elements/in_pressure_en +What: /sys/.../iio:deviceX/scan_elements/in_accel_x_en +What: /sys/.../iio:deviceX/scan_elements/in_accel_y_en +What: /sys/.../iio:deviceX/scan_elements/in_accel_z_en +What: /sys/.../iio:deviceX/scan_elements/in_anglvel_x_en +What: /sys/.../iio:deviceX/scan_elements/in_anglvel_y_en +What: /sys/.../iio:deviceX/scan_elements/in_anglvel_z_en +What: /sys/.../iio:deviceX/scan_elements/in_magn_x_en +What: /sys/.../iio:deviceX/scan_elements/in_magn_y_en +What: /sys/.../iio:deviceX/scan_elements/in_magn_z_en +What: /sys/.../iio:deviceX/scan_elements/in_timestamp_en +What: /sys/.../iio:deviceX/scan_elements/in_voltageY_supply_en +What: /sys/.../iio:deviceX/scan_elements/in_voltageY_en +What: /sys/.../iio:deviceX/scan_elements/in_voltageY-voltageZ_en +What: /sys/.../iio:deviceX/scan_elements/in_incli_x_en +What: /sys/.../iio:deviceX/scan_elements/in_incli_y_en +What: /sys/.../iio:deviceX/scan_elements/in_pressureY_en +What: /sys/.../iio:deviceX/scan_elements/in_pressure_en KernelVersion: 2.6.37 Contact: linux-iio@vger.kernel.org Description: Scan element control for triggered data capture. -What: /sys/.../buffer/scan_elements/in_accel_type -What: /sys/.../buffer/scan_elements/in_anglvel_type -What: /sys/.../buffer/scan_elements/in_magn_type -What: /sys/.../buffer/scan_elements/in_incli_type -What: /sys/.../buffer/scan_elements/in_voltageY_type -What: /sys/.../buffer/scan_elements/in_voltage_type -What: /sys/.../buffer/scan_elements/in_voltageY_supply_type -What: /sys/.../buffer/scan_elements/in_timestamp_type -What: /sys/.../buffer/scan_elements/in_pressureY_type -What: /sys/.../buffer/scan_elements/in_pressure_type +What: /sys/.../iio:deviceX/scan_elements/in_accel_type +What: /sys/.../iio:deviceX/scan_elements/in_anglvel_type +What: /sys/.../iio:deviceX/scan_elements/in_magn_type +What: /sys/.../iio:deviceX/scan_elements/in_incli_type +What: /sys/.../iio:deviceX/scan_elements/in_voltageY_type +What: /sys/.../iio:deviceX/scan_elements/in_voltage_type +What: /sys/.../iio:deviceX/scan_elements/in_voltageY_supply_type +What: /sys/.../iio:deviceX/scan_elements/in_timestamp_type +What: /sys/.../iio:deviceX/scan_elements/in_pressureY_type +What: /sys/.../iio:deviceX/scan_elements/in_pressure_type KernelVersion: 2.6.37 Contact: linux-iio@vger.kernel.org Description: @@ -752,29 +752,29 @@ Description: For other storage combinations this attribute will be extended appropriately. -What: /sys/.../buffer/scan_elements/in_accel_type_available +What: /sys/.../iio:deviceX/scan_elements/in_accel_type_available KernelVersion: 2.6.37 Contact: linux-iio@vger.kernel.org Description: If the type parameter can take one of a small set of values, this attribute lists them. -What: /sys/.../buffer/scan_elements/in_voltageY_index -What: /sys/.../buffer/scan_elements/in_voltageY_supply_index -What: /sys/.../buffer/scan_elements/in_accel_x_index -What: /sys/.../buffer/scan_elements/in_accel_y_index -What: /sys/.../buffer/scan_elements/in_accel_z_index -What: /sys/.../buffer/scan_elements/in_anglvel_x_index -What: /sys/.../buffer/scan_elements/in_anglvel_y_index -What: /sys/.../buffer/scan_elements/in_anglvel_z_index -What: /sys/.../buffer/scan_elements/in_magn_x_index -What: /sys/.../buffer/scan_elements/in_magn_y_index -What: /sys/.../buffer/scan_elements/in_magn_z_index -What: /sys/.../buffer/scan_elements/in_incli_x_index -What: /sys/.../buffer/scan_elements/in_incli_y_index -What: /sys/.../buffer/scan_elements/in_timestamp_index -What: /sys/.../buffer/scan_elements/in_pressureY_index -What: /sys/.../buffer/scan_elements/in_pressure_index +What: /sys/.../iio:deviceX/scan_elements/in_voltageY_index +What: /sys/.../iio:deviceX/scan_elements/in_voltageY_supply_index +What: /sys/.../iio:deviceX/scan_elements/in_accel_x_index +What: /sys/.../iio:deviceX/scan_elements/in_accel_y_index +What: /sys/.../iio:deviceX/scan_elements/in_accel_z_index +What: /sys/.../iio:deviceX/scan_elements/in_anglvel_x_index +What: /sys/.../iio:deviceX/scan_elements/in_anglvel_y_index +What: /sys/.../iio:deviceX/scan_elements/in_anglvel_z_index +What: /sys/.../iio:deviceX/scan_elements/in_magn_x_index +What: /sys/.../iio:deviceX/scan_elements/in_magn_y_index +What: /sys/.../iio:deviceX/scan_elements/in_magn_z_index +What: /sys/.../iio:deviceX/scan_elements/in_incli_x_index +What: /sys/.../iio:deviceX/scan_elements/in_incli_y_index +What: /sys/.../iio:deviceX/scan_elements/in_timestamp_index +What: /sys/.../iio:deviceX/scan_elements/in_pressureY_index +What: /sys/.../iio:deviceX/scan_elements/in_pressure_index KernelVersion: 2.6.37 Contact: linux-iio@vger.kernel.org Description: diff --git a/Documentation/devicetree/bindings/iio/dac/ad7303.txt b/Documentation/devicetree/bindings/iio/dac/ad7303.txt new file mode 100644 index 000000000000..914610f0556e --- /dev/null +++ b/Documentation/devicetree/bindings/iio/dac/ad7303.txt @@ -0,0 +1,23 @@ +Analog Devices AD7303 DAC device driver + +Required properties: + - compatible: Must be "adi,ad7303" + - reg: SPI chip select number for the device + - spi-max-frequency: Max SPI frequency to use (< 30000000) + - Vdd-supply: Phandle to the Vdd power supply + +Optional properties: + - REF-supply: Phandle to the external reference voltage supply. This should + only be set if there is an external reference voltage connected to the REF + pin. If the property is not set Vdd/2 is used as the reference voltage. + +Example: + + ad7303@4 { + compatible = "adi,ad7303"; + reg = <4>; + spi-max-frequency = <10000000>; + Vdd-supply = <&vdd_supply>; + adi,use-external-reference; + REF-supply = <&vref_supply>; + }; diff --git a/Documentation/devicetree/bindings/iio/frequency/adf4350.txt b/Documentation/devicetree/bindings/iio/frequency/adf4350.txt new file mode 100644 index 000000000000..f8c181d81d2d --- /dev/null +++ b/Documentation/devicetree/bindings/iio/frequency/adf4350.txt @@ -0,0 +1,86 @@ +Analog Devices ADF4350/ADF4351 device driver + +Required properties: + - compatible: Should be one of + * "adi,adf4350": When using the ADF4350 device + * "adi,adf4351": When using the ADF4351 device + - reg: SPI chip select numbert for the device + - spi-max-frequency: Max SPI frequency to use (< 20000000) + - clocks: From common clock binding. Clock is phandle to clock for + ADF435x Reference Clock (CLKIN). + +Optional properties: + - gpios: GPIO Lock detect - If set with a valid phandle and GPIO number, + pll lock state is tested upon read. + - adi,channel-spacing: Channel spacing in Hz (influences MODULUS). + - adi,power-up-frequency: If set in Hz the PLL tunes to + the desired frequency on probe. + - adi,reference-div-factor: If set the driver skips dynamic calculation + and uses this default value instead. + - adi,reference-doubler-enable: Enables reference doubler. + - adi,reference-div2-enable: Enables reference divider. + - adi,phase-detector-polarity-positive-enable: Enables positive phase + detector polarity. Default = negative. + - adi,lock-detect-precision-6ns-enable: Enables 6ns lock detect precision. + Default = 10ns. + - adi,lock-detect-function-integer-n-enable: Enables lock detect + for integer-N mode. Default = factional-N mode. + - adi,charge-pump-current: Charge pump current in mA. + Default = 2500mA. + - adi,muxout-select: On chip multiplexer output selection. + Valid values for the multiplexer output are: + 0: Three-State Output (default) + 1: DVDD + 2: DGND + 3: R-Counter output + 4: N-Divider output + 5: Analog lock detect + 6: Digital lock detect + - adi,low-spur-mode-enable: Enables low spur mode. + Default = Low noise mode. + - adi,cycle-slip-reduction-enable: Enables cycle slip reduction. + - adi,charge-cancellation-enable: Enabled charge pump + charge cancellation for integer-N modes. + - adi,anti-backlash-3ns-enable: Enables 3ns antibacklash pulse width + for integer-N modes. + - adi,band-select-clock-mode-high-enable: Enables faster band + selection logic. + - adi,12bit-clk-divider: Clock divider value used when + adi,12bit-clkdiv-mode != 0 + - adi,clk-divider-mode: + Valid values for the clkdiv mode are: + 0: Clock divider off (default) + 1: Fast lock enable + 2: Phase resync enable + - adi,aux-output-enable: Enables auxiliary RF output. + - adi,aux-output-fundamental-enable: Selects fundamental VCO output on + the auxiliary RF output. Default = Output of RF dividers. + - adi,mute-till-lock-enable: Enables Mute-Till-Lock-Detect function. + - adi,output-power: Output power selection. + Valid values for the power mode are: + 0: -4dBm (default) + 1: -1dBm + 2: +2dBm + 3: +5dBm + - adi,aux-output-power: Auxiliary output power selection. + Valid values for the power mode are: + 0: -4dBm (default) + 1: -1dBm + 2: +2dBm + 3: +5dBm + + +Example: + lo_pll0_rx_adf4351: adf4351-rx-lpc@4 { + compatible = "adi,adf4351"; + reg = <4>; + spi-max-frequency = <10000000>; + clocks = <&clk0_ad9523 9>; + clock-names = "clkin"; + adi,channel-spacing = <10000>; + adi,power-up-frequency = <2400000000>; + adi,phase-detector-polarity-positive-enable; + adi,charge-pump-current = <2500>; + adi,output-power = <3>; + adi,mute-till-lock-enable; + }; diff --git a/Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt b/Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt new file mode 100644 index 000000000000..011679f1a425 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt @@ -0,0 +1,18 @@ +* AsahiKASEI AK8975 magnetometer sensor + +Required properties: + + - compatible : should be "asahi-kasei,ak8975" + - reg : the I2C address of the magnetometer + +Optional properties: + + - gpios : should be device tree identifier of the magnetometer DRDY pin + +Example: + +ak8975@0c { + compatible = "asahi-kasei,ak8975"; + reg = <0x0c>; + gpios = <&gpj0 7 0>; +}; diff --git a/Documentation/devicetree/bindings/staging/imx-drm/ldb.txt b/Documentation/devicetree/bindings/staging/imx-drm/ldb.txt new file mode 100644 index 000000000000..ed9377811ee2 --- /dev/null +++ b/Documentation/devicetree/bindings/staging/imx-drm/ldb.txt @@ -0,0 +1,99 @@ +Device-Tree bindings for LVDS Display Bridge (ldb) + +LVDS Display Bridge +=================== + +The LVDS Display Bridge device tree node contains up to two lvds-channel +nodes describing each of the two LVDS encoder channels of the bridge. + +Required properties: + - #address-cells : should be <1> + - #size-cells : should be <0> + - compatible : should be "fsl,imx53-ldb" or "fsl,imx6q-ldb". + Both LDB versions are similar, but i.MX6 has an additional + multiplexer in the front to select any of the four IPU display + interfaces as input for each LVDS channel. + - gpr : should be <&gpr> on i.MX53 and i.MX6q. + The phandle points to the iomuxc-gpr region containing the LVDS + control register. +- clocks, clock-names : phandles to the LDB divider and selector clocks and to + the display interface selector clocks, as described in + Documentation/devicetree/bindings/clock/clock-bindings.txt + The following clocks are expected on i.MX53: + "di0_pll" - LDB LVDS channel 0 mux + "di1_pll" - LDB LVDS channel 1 mux + "di0" - LDB LVDS channel 0 gate + "di1" - LDB LVDS channel 1 gate + "di0_sel" - IPU1 DI0 mux + "di1_sel" - IPU1 DI1 mux + On i.MX6q the following additional clocks are needed: + "di2_sel" - IPU2 DI0 mux + "di3_sel" - IPU2 DI1 mux + The needed clock numbers for each are documented in + Documentation/devicetree/bindings/clock/imx5-clock.txt, and in + Documentation/devicetree/bindings/clock/imx6q-clock.txt. + +Optional properties: + - pinctrl-names : should be "default" on i.MX53, not used on i.MX6q + - pinctrl-0 : a phandle pointing to LVDS pin settings on i.MX53, + not used on i.MX6q + - fsl,dual-channel : boolean. if it exists, only LVDS channel 0 should + be configured - one input will be distributed on both outputs in dual + channel mode + +LVDS Channel +============ + +Each LVDS Channel has to contain a display-timings node that describes the +video timings for the connected LVDS display. For detailed information, also +have a look at Documentation/devicetree/bindings/video/display-timing.txt. + +Required properties: + - reg : should be <0> or <1> + - crtcs : a list of phandles with index pointing to the IPU display interfaces + that can be used as video source for this channel. + - fsl,data-mapping : should be "spwg" or "jeida" + This describes how the color bits are laid out in the + serialized LVDS signal. + - fsl,data-width : should be <18> or <24> + +example: + +gpr: iomuxc-gpr@53fa8000 { + /* ... */ +}; + +ldb: ldb@53fa8008 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "fsl,imx53-ldb"; + gpr = <&gpr>; + clocks = <&clks 122>, <&clks 120>, + <&clks 115>, <&clks 116>, + <&clks 123>, <&clks 85>; + clock-names = "di0_pll", "di1_pll", + "di0_sel", "di1_sel", + "di0", "di1"; + + lvds-channel@0 { + reg = <0>; + crtcs = <&ipu 0>; + fsl,data-mapping = "spwg"; + fsl,data-width = <24>; + + display-timings { + /* ... */ + }; + }; + + lvds-channel@1 { + reg = <1>; + crtcs = <&ipu 1>; + fsl,data-mapping = "spwg"; + fsl,data-width = <24>; + + display-timings { + /* ... */ + }; + }; +}; diff --git a/MAINTAINERS b/MAINTAINERS index a996ab582211..4f43ddf7350a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7783,7 +7783,7 @@ F: drivers/staging/media/solo6x10/ STAGING - SPEAKUP CONSOLE SPEECH DRIVER M: William Hubbs M: Chris Brannon -M: Kirk Reiser +M: Kirk Reiser M: Samuel Thibault L: speakup@braille.uwo.ca W: http://www.linux-speakup.org/ diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig index b2f963be3993..9af763a90d93 100644 --- a/drivers/iio/Kconfig +++ b/drivers/iio/Kconfig @@ -70,5 +70,9 @@ source "drivers/iio/gyro/Kconfig" source "drivers/iio/imu/Kconfig" source "drivers/iio/light/Kconfig" source "drivers/iio/magnetometer/Kconfig" +if IIO_TRIGGER + source "drivers/iio/trigger/Kconfig" +endif #IIO_TRIGGER +source "drivers/iio/pressure/Kconfig" endif # IIO diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile index a0e8cdd67e4d..7a3866c2d2a1 100644 --- a/drivers/iio/Makefile +++ b/drivers/iio/Makefile @@ -21,3 +21,5 @@ obj-y += frequency/ obj-y += imu/ obj-y += light/ obj-y += magnetometer/ +obj-y += trigger/ +obj-y += pressure/ diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index bb594963f91e..719d83fe51dd 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -28,7 +28,6 @@ config IIO_ST_ACCEL_3AXIS select IIO_ST_ACCEL_I2C_3AXIS if (I2C) select IIO_ST_ACCEL_SPI_3AXIS if (SPI_MASTER) select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) - select IIO_ST_ACCEL_BUFFER if (IIO_TRIGGERED_BUFFER) help Say yes here to build support for STMicroelectronics accelerometers: LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC, diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index e0f5a3ceba5e..4aec121261d7 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -26,6 +26,8 @@ #include #include "st_accel.h" +#define ST_ACCEL_NUMBER_DATA_CHANNELS 3 + /* DEFAULT VALUE FOR SENSORS */ #define ST_ACCEL_DEFAULT_OUT_X_L_ADDR 0x28 #define ST_ACCEL_DEFAULT_OUT_Y_L_ADDR 0x2a @@ -125,22 +127,34 @@ #define ST_ACCEL_3_MULTIREAD_BIT false static const struct iio_chan_spec st_accel_12bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE, - ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_X_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE, - ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_Y_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE, - ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_Z_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 12, 16, + ST_ACCEL_DEFAULT_OUT_X_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 12, 16, + ST_ACCEL_DEFAULT_OUT_Y_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 12, 16, + ST_ACCEL_DEFAULT_OUT_Z_L_ADDR), IIO_CHAN_SOFT_TIMESTAMP(3) }; static const struct iio_chan_spec st_accel_16bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE, - ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_X_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE, - ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_Y_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE, - ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_Z_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16, + ST_ACCEL_DEFAULT_OUT_X_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16, + ST_ACCEL_DEFAULT_OUT_Y_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16, + ST_ACCEL_DEFAULT_OUT_Z_L_ADDR), IIO_CHAN_SOFT_TIMESTAMP(3) }; @@ -442,6 +456,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev) if (err < 0) goto st_accel_common_probe_error; + adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS; adata->multiread_bit = adata->sensor->multi_read_bit; indio_dev->channels = adata->sensor->ch; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index ab0767e6727e..93129ec4b649 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -133,6 +133,16 @@ config MAX1363 max11646, max11647) Provides direct access via sysfs and buffered data via the iio dev interface. +config MCP320X + tristate "Microchip Technology MCP3204/08" + depends on SPI + help + Say yes here to build support for Microchip Technology's MCP3204 or + MCP3208 analog to digital converter. + + This driver can also be built as a module. If so, the module will be + called mcp320x. + config TI_ADC081C tristate "Texas Instruments ADC081C021/027" depends on I2C diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 0a825bed43f6..8f475d31fe4d 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_AT91_ADC) += at91_adc.o obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o obj-$(CONFIG_MAX1363) += max1363.o +obj-$(CONFIG_MCP320X) += mcp320x.o obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c index e5b88d5d3b59..b6db6a0e09cd 100644 --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c @@ -774,11 +774,13 @@ static int at91_adc_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_OF static const struct of_device_id at91_adc_dt_ids[] = { { .compatible = "atmel,at91sam9260-adc" }, {}, }; MODULE_DEVICE_TABLE(of, at91_adc_dt_ids); +#endif static struct platform_driver at91_adc_driver = { .probe = at91_adc_probe, diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c index b3d03d335948..9809fc9a35d2 100644 --- a/drivers/iio/adc/exynos_adc.c +++ b/drivers/iio/adc/exynos_adc.c @@ -270,16 +270,16 @@ static int exynos_adc_probe(struct platform_device *pdev) info = iio_priv(indio_dev); mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); - info->regs = devm_request_and_ioremap(&pdev->dev, mem); - if (!info->regs) { - ret = -ENOMEM; + info->regs = devm_ioremap_resource(&pdev->dev, mem); + if (IS_ERR(info->regs)) { + ret = PTR_ERR(info->regs); goto err_iio; } mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); - info->enable_reg = devm_request_and_ioremap(&pdev->dev, mem); - if (!info->enable_reg) { - ret = -ENOMEM; + info->enable_reg = devm_ioremap_resource(&pdev->dev, mem); + if (IS_ERR(info->enable_reg)) { + ret = PTR_ERR(info->enable_reg); goto err_iio; } diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 9e6da72ad823..f148d00b83f7 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -660,7 +660,7 @@ static ssize_t max1363_monitor_store_freq(struct device *dev, unsigned long val; bool found = false; - ret = strict_strtoul(buf, 10, &val); + ret = kstrtoul(buf, 10, &val); if (ret) return -EINVAL; for (i = 0; i < ARRAY_SIZE(max1363_monitor_speeds); i++) diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c new file mode 100644 index 000000000000..ebc015922a79 --- /dev/null +++ b/drivers/iio/adc/mcp320x.c @@ -0,0 +1,257 @@ +/* + * Copyright (C) 2013 Oskar Andero + * + * Driver for Microchip Technology's MCP3204 and MCP3208 ADC chips. + * Datasheet can be found here: + * http://ww1.microchip.com/downloads/en/devicedoc/21298c.pdf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include + +#define MCP_SINGLE_ENDED (1 << 3) +#define MCP_START_BIT (1 << 4) + +enum { + mcp3204, + mcp3208, +}; + +struct mcp320x { + struct spi_device *spi; + struct spi_message msg; + struct spi_transfer transfer[2]; + + u8 tx_buf; + u8 rx_buf[2]; + + struct regulator *reg; + struct mutex lock; +}; + +static int mcp320x_adc_conversion(struct mcp320x *adc, u8 msg) +{ + int ret; + + adc->tx_buf = msg; + ret = spi_sync(adc->spi, &adc->msg); + if (ret < 0) + return ret; + + return ((adc->rx_buf[0] & 0x3f) << 6) | + (adc->rx_buf[1] >> 2); +} + +static int mcp320x_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, int *val, + int *val2, long mask) +{ + struct mcp320x *adc = iio_priv(indio_dev); + int ret = -EINVAL; + + mutex_lock(&adc->lock); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + if (channel->differential) + ret = mcp320x_adc_conversion(adc, + MCP_START_BIT | channel->address); + else + ret = mcp320x_adc_conversion(adc, + MCP_START_BIT | MCP_SINGLE_ENDED | + channel->address); + if (ret < 0) + goto out; + + *val = ret; + ret = IIO_VAL_INT; + break; + + case IIO_CHAN_INFO_SCALE: + /* Digital output code = (4096 * Vin) / Vref */ + ret = regulator_get_voltage(adc->reg); + if (ret < 0) + goto out; + + *val = ret / 1000; + *val2 = 12; + ret = IIO_VAL_FRACTIONAL_LOG2; + break; + + default: + break; + } + +out: + mutex_unlock(&adc->lock); + + return ret; +} + +#define MCP320X_VOLTAGE_CHANNEL(num) \ + { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = (num), \ + .address = (num), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \ + } + +#define MCP320X_VOLTAGE_CHANNEL_DIFF(num) \ + { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = (num * 2), \ + .channel2 = (num * 2 + 1), \ + .address = (num * 2), \ + .differential = 1, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \ + } + +static const struct iio_chan_spec mcp3204_channels[] = { + MCP320X_VOLTAGE_CHANNEL(0), + MCP320X_VOLTAGE_CHANNEL(1), + MCP320X_VOLTAGE_CHANNEL(2), + MCP320X_VOLTAGE_CHANNEL(3), + MCP320X_VOLTAGE_CHANNEL_DIFF(0), + MCP320X_VOLTAGE_CHANNEL_DIFF(1), +}; + +static const struct iio_chan_spec mcp3208_channels[] = { + MCP320X_VOLTAGE_CHANNEL(0), + MCP320X_VOLTAGE_CHANNEL(1), + MCP320X_VOLTAGE_CHANNEL(2), + MCP320X_VOLTAGE_CHANNEL(3), + MCP320X_VOLTAGE_CHANNEL(4), + MCP320X_VOLTAGE_CHANNEL(5), + MCP320X_VOLTAGE_CHANNEL(6), + MCP320X_VOLTAGE_CHANNEL(7), + MCP320X_VOLTAGE_CHANNEL_DIFF(0), + MCP320X_VOLTAGE_CHANNEL_DIFF(1), + MCP320X_VOLTAGE_CHANNEL_DIFF(2), + MCP320X_VOLTAGE_CHANNEL_DIFF(3), +}; + +static const struct iio_info mcp320x_info = { + .read_raw = mcp320x_read_raw, + .driver_module = THIS_MODULE, +}; + +struct mcp3208_chip_info { + const struct iio_chan_spec *channels; + unsigned int num_channels; +}; + +static const struct mcp3208_chip_info mcp3208_chip_infos[] = { + [mcp3204] = { + .channels = mcp3204_channels, + .num_channels = ARRAY_SIZE(mcp3204_channels) + }, + [mcp3208] = { + .channels = mcp3208_channels, + .num_channels = ARRAY_SIZE(mcp3208_channels) + }, +}; + +static int mcp320x_probe(struct spi_device *spi) +{ + struct iio_dev *indio_dev; + struct mcp320x *adc; + const struct mcp3208_chip_info *chip_info; + int ret; + + indio_dev = iio_device_alloc(sizeof(*adc)); + if (!indio_dev) + return -ENOMEM; + + adc = iio_priv(indio_dev); + adc->spi = spi; + + indio_dev->dev.parent = &spi->dev; + indio_dev->name = spi_get_device_id(spi)->name; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &mcp320x_info; + + chip_info = &mcp3208_chip_infos[spi_get_device_id(spi)->driver_data]; + indio_dev->channels = chip_info->channels; + indio_dev->num_channels = chip_info->num_channels; + + adc->transfer[0].tx_buf = &adc->tx_buf; + adc->transfer[0].len = sizeof(adc->tx_buf); + adc->transfer[1].rx_buf = adc->rx_buf; + adc->transfer[1].len = sizeof(adc->rx_buf); + + spi_message_init_with_transfers(&adc->msg, adc->transfer, + ARRAY_SIZE(adc->transfer)); + + adc->reg = regulator_get(&spi->dev, "vref"); + if (IS_ERR(adc->reg)) { + ret = PTR_ERR(adc->reg); + goto iio_free; + } + + ret = regulator_enable(adc->reg); + if (ret < 0) + goto reg_free; + + mutex_init(&adc->lock); + + ret = iio_device_register(indio_dev); + if (ret < 0) + goto reg_disable; + + return 0; + +reg_disable: + regulator_disable(adc->reg); +reg_free: + regulator_put(adc->reg); +iio_free: + iio_device_free(indio_dev); + + return ret; +} + +static int mcp320x_remove(struct spi_device *spi) +{ + struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct mcp320x *adc = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + regulator_disable(adc->reg); + regulator_put(adc->reg); + iio_device_free(indio_dev); + + return 0; +} + +static const struct spi_device_id mcp320x_id[] = { + { "mcp3204", mcp3204 }, + { "mcp3208", mcp3208 }, + { } +}; +MODULE_DEVICE_TABLE(spi, mcp320x_id); + +static struct spi_driver mcp320x_driver = { + .driver = { + .name = "mcp320x", + .owner = THIS_MODULE, + }, + .probe = mcp320x_probe, + .remove = mcp320x_remove, + .id_table = mcp320x_id, +}; +module_spi_driver(mcp320x_driver); + +MODULE_AUTHOR("Oskar Andero "); +MODULE_DESCRIPTION("Microchip Technology MCP3204/08"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c index 09b236d6ee89..71a2c5f63b9c 100644 --- a/drivers/iio/common/st_sensors/st_sensors_buffer.c +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c @@ -24,11 +24,20 @@ int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) { + u8 *addr; int i, n = 0, len; - u8 addr[ST_SENSORS_NUMBER_DATA_CHANNELS]; struct st_sensor_data *sdata = iio_priv(indio_dev); + unsigned int num_data_channels = sdata->num_data_channels; + unsigned int byte_for_channel = + indio_dev->channels[0].scan_type.storagebits >> 3; - for (i = 0; i < ST_SENSORS_NUMBER_DATA_CHANNELS; i++) { + addr = kmalloc(num_data_channels, GFP_KERNEL); + if (!addr) { + len = -ENOMEM; + goto st_sensors_get_buffer_element_error; + } + + for (i = 0; i < num_data_channels; i++) { if (test_bit(i, indio_dev->active_scan_mask)) { addr[n] = indio_dev->channels[i].address; n++; @@ -37,52 +46,58 @@ int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) switch (n) { case 1: len = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, - addr[0], ST_SENSORS_BYTE_FOR_CHANNEL, buf, - sdata->multiread_bit); + addr[0], byte_for_channel, buf, sdata->multiread_bit); break; case 2: - if ((addr[1] - addr[0]) == ST_SENSORS_BYTE_FOR_CHANNEL) { + if ((addr[1] - addr[0]) == byte_for_channel) { len = sdata->tf->read_multiple_byte(&sdata->tb, - sdata->dev, addr[0], - ST_SENSORS_BYTE_FOR_CHANNEL*n, - buf, sdata->multiread_bit); + sdata->dev, addr[0], byte_for_channel * n, + buf, sdata->multiread_bit); } else { - u8 rx_array[ST_SENSORS_BYTE_FOR_CHANNEL* - ST_SENSORS_NUMBER_DATA_CHANNELS]; + u8 *rx_array; + rx_array = kmalloc(byte_for_channel * num_data_channels, + GFP_KERNEL); + if (!rx_array) { + len = -ENOMEM; + goto st_sensors_free_memory; + } + len = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, addr[0], - ST_SENSORS_BYTE_FOR_CHANNEL* - ST_SENSORS_NUMBER_DATA_CHANNELS, + byte_for_channel * num_data_channels, rx_array, sdata->multiread_bit); - if (len < 0) - goto read_data_channels_error; + if (len < 0) { + kfree(rx_array); + goto st_sensors_free_memory; + } - for (i = 0; i < n * ST_SENSORS_NUMBER_DATA_CHANNELS; - i++) { + for (i = 0; i < n * num_data_channels; i++) { if (i < n) buf[i] = rx_array[i]; else buf[i] = rx_array[n + i]; } - len = ST_SENSORS_BYTE_FOR_CHANNEL*n; + kfree(rx_array); + len = byte_for_channel * n; } break; case 3: len = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, - addr[0], ST_SENSORS_BYTE_FOR_CHANNEL* - ST_SENSORS_NUMBER_DATA_CHANNELS, + addr[0], byte_for_channel * num_data_channels, buf, sdata->multiread_bit); break; default: len = -EINVAL; - goto read_data_channels_error; + goto st_sensors_free_memory; } - if (len != ST_SENSORS_BYTE_FOR_CHANNEL*n) { + if (len != byte_for_channel * n) { len = -EIO; - goto read_data_channels_error; + goto st_sensors_free_memory; } -read_data_channels_error: +st_sensors_free_memory: + kfree(addr); +st_sensors_get_buffer_element_error: return len; } EXPORT_SYMBOL(st_sensors_get_buffer_element); diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index ed9bc8ae9330..865b1781df66 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -20,6 +20,11 @@ #define ST_SENSORS_WAI_ADDRESS 0x0f +static inline u32 st_sensors_get_unaligned_le24(const u8 *p) +{ + return ((s32)((p[0] | p[1] << 8 | p[2] << 16) << 8) >> 8); +} + static int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, u8 reg_addr, u8 mask, u8 data) { @@ -112,7 +117,8 @@ st_sensors_match_odr_error: return ret; } -static int st_sensors_set_fullscale(struct iio_dev *indio_dev, unsigned int fs) +static int st_sensors_set_fullscale(struct iio_dev *indio_dev, + unsigned int fs) { int err, i = 0; struct st_sensor_data *sdata = iio_priv(indio_dev); @@ -273,21 +279,33 @@ st_sensors_match_scale_error: EXPORT_SYMBOL(st_sensors_set_fullscale_by_gain); static int st_sensors_read_axis_data(struct iio_dev *indio_dev, - u8 ch_addr, int *data) + struct iio_chan_spec const *ch, int *data) { int err; - u8 outdata[ST_SENSORS_BYTE_FOR_CHANNEL]; + u8 *outdata; struct st_sensor_data *sdata = iio_priv(indio_dev); + unsigned int byte_for_channel = ch->scan_type.storagebits >> 3; + + outdata = kmalloc(byte_for_channel, GFP_KERNEL); + if (!outdata) { + err = -EINVAL; + goto st_sensors_read_axis_data_error; + } err = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, - ch_addr, ST_SENSORS_BYTE_FOR_CHANNEL, + ch->address, byte_for_channel, outdata, sdata->multiread_bit); if (err < 0) - goto read_error; + goto st_sensors_free_memory; - *data = (s16)get_unaligned_le16(outdata); + if (byte_for_channel == 2) + *data = (s16)get_unaligned_le16(outdata); + else if (byte_for_channel == 3) + *data = (s32)st_sensors_get_unaligned_le24(outdata); -read_error: +st_sensors_free_memory: + kfree(outdata); +st_sensors_read_axis_data_error: return err; } @@ -307,7 +325,7 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev, goto read_error; msleep((sdata->sensor->bootime * 1000) / sdata->odr); - err = st_sensors_read_axis_data(indio_dev, ch->address, val); + err = st_sensors_read_axis_data(indio_dev, ch, val); if (err < 0) goto read_error; diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig index b61160bd935e..c9c33ce32d3a 100644 --- a/drivers/iio/dac/Kconfig +++ b/drivers/iio/dac/Kconfig @@ -130,6 +130,16 @@ config AD5686 To compile this driver as a module, choose M here: the module will be called ad5686. +config AD7303 + tristate "Analog Devices Analog Devices AD7303 DAC driver" + depends on SPI + help + Say yes here to build support for Analog Devices AD7303 Digital to Analog + Converters (DAC). + + To compile this driver as module choose M here: the module will be called + ad7303. + config MAX517 tristate "Maxim MAX517/518/519 DAC driver" depends on I2C diff --git a/drivers/iio/dac/Makefile b/drivers/iio/dac/Makefile index 5b528ebb3343..c8d7ab6bff01 100644 --- a/drivers/iio/dac/Makefile +++ b/drivers/iio/dac/Makefile @@ -14,5 +14,6 @@ obj-$(CONFIG_AD5755) += ad5755.o obj-$(CONFIG_AD5764) += ad5764.o obj-$(CONFIG_AD5791) += ad5791.o obj-$(CONFIG_AD5686) += ad5686.o +obj-$(CONFIG_AD7303) += ad7303.o obj-$(CONFIG_MAX517) += max517.o obj-$(CONFIG_MCP4725) += mcp4725.o diff --git a/drivers/iio/dac/ad7303.c b/drivers/iio/dac/ad7303.c new file mode 100644 index 000000000000..85aeef60dc5f --- /dev/null +++ b/drivers/iio/dac/ad7303.c @@ -0,0 +1,315 @@ +/* + * AD7303 Digital to analog converters driver + * + * Copyright 2013 Analog Devices Inc. + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#define AD7303_CFG_EXTERNAL_VREF BIT(15) +#define AD7303_CFG_POWER_DOWN(ch) BIT(11 + (ch)) +#define AD7303_CFG_ADDR_OFFSET 10 + +#define AD7303_CMD_UPDATE_DAC (0x3 << 8) + +/** + * struct ad7303_state - driver instance specific data + * @spi: the device for this driver instance + * @config: cached config register value + * @dac_cache: current DAC raw value (chip does not support readback) + * @data: spi transfer buffer + */ + +struct ad7303_state { + struct spi_device *spi; + uint16_t config; + uint8_t dac_cache[2]; + + struct regulator *vdd_reg; + struct regulator *vref_reg; + + /* + * DMA (thus cache coherency maintenance) requires the + * transfer buffers to live in their own cache lines. + */ + __be16 data ____cacheline_aligned; +}; + +static int ad7303_write(struct ad7303_state *st, unsigned int chan, + uint8_t val) +{ + st->data = cpu_to_be16(AD7303_CMD_UPDATE_DAC | + (chan << AD7303_CFG_ADDR_OFFSET) | + st->config | val); + + return spi_write(st->spi, &st->data, sizeof(st->data)); +} + +static ssize_t ad7303_read_dac_powerdown(struct iio_dev *indio_dev, + uintptr_t private, const struct iio_chan_spec *chan, char *buf) +{ + struct ad7303_state *st = iio_priv(indio_dev); + + return sprintf(buf, "%d\n", (bool)(st->config & + AD7303_CFG_POWER_DOWN(chan->channel))); +} + +static ssize_t ad7303_write_dac_powerdown(struct iio_dev *indio_dev, + uintptr_t private, const struct iio_chan_spec *chan, const char *buf, + size_t len) +{ + struct ad7303_state *st = iio_priv(indio_dev); + bool pwr_down; + int ret; + + ret = strtobool(buf, &pwr_down); + if (ret) + return ret; + + mutex_lock(&indio_dev->mlock); + + if (pwr_down) + st->config |= AD7303_CFG_POWER_DOWN(chan->channel); + else + st->config &= ~AD7303_CFG_POWER_DOWN(chan->channel); + + /* There is no noop cmd which allows us to only update the powerdown + * mode, so just write one of the DAC channels again */ + ad7303_write(st, chan->channel, st->dac_cache[chan->channel]); + + mutex_unlock(&indio_dev->mlock); + return ret ? ret : len; +} + +static int ad7303_get_vref(struct ad7303_state *st, + struct iio_chan_spec const *chan) +{ + int ret; + + if (st->config & AD7303_CFG_EXTERNAL_VREF) + return regulator_get_voltage(st->vref_reg); + + ret = regulator_get_voltage(st->vdd_reg); + if (ret < 0) + return ret; + return ret / 2; +} + +static int ad7303_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, int *val2, long info) +{ + struct ad7303_state *st = iio_priv(indio_dev); + int vref_uv; + + switch (info) { + case IIO_CHAN_INFO_RAW: + *val = st->dac_cache[chan->channel]; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + vref_uv = ad7303_get_vref(st, chan); + if (vref_uv < 0) + return vref_uv; + + *val = 2 * vref_uv / 1000; + *val2 = chan->scan_type.realbits; + + return IIO_VAL_FRACTIONAL_LOG2; + default: + break; + } + return -EINVAL; +} + +static int ad7303_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, int val2, long mask) +{ + struct ad7303_state *st = iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + if (val >= (1 << chan->scan_type.realbits) || val < 0) + return -EINVAL; + + mutex_lock(&indio_dev->mlock); + ret = ad7303_write(st, chan->address, val); + if (ret == 0) + st->dac_cache[chan->channel] = val; + mutex_unlock(&indio_dev->mlock); + break; + default: + ret = -EINVAL; + } + + return ret; +} + +static const struct iio_info ad7303_info = { + .read_raw = ad7303_read_raw, + .write_raw = ad7303_write_raw, + .driver_module = THIS_MODULE, +}; + +static const struct iio_chan_spec_ext_info ad7303_ext_info[] = { + { + .name = "powerdown", + .read = ad7303_read_dac_powerdown, + .write = ad7303_write_dac_powerdown, + }, + { }, +}; + +#define AD7303_CHANNEL(chan) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .output = 1, \ + .channel = (chan), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .address = (chan), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = '8', \ + .storagebits = '8', \ + .shift = '0', \ + }, \ + .ext_info = ad7303_ext_info, \ +} + +static const struct iio_chan_spec ad7303_channels[] = { + AD7303_CHANNEL(0), + AD7303_CHANNEL(1), +}; + +static int ad7303_probe(struct spi_device *spi) +{ + const struct spi_device_id *id = spi_get_device_id(spi); + struct iio_dev *indio_dev; + struct ad7303_state *st; + bool ext_ref; + int ret; + + indio_dev = iio_device_alloc(sizeof(*st)); + if (indio_dev == NULL) + return -ENOMEM; + + st = iio_priv(indio_dev); + spi_set_drvdata(spi, indio_dev); + + st->spi = spi; + + st->vdd_reg = regulator_get(&spi->dev, "Vdd"); + if (IS_ERR(st->vdd_reg)) { + ret = PTR_ERR(st->vdd_reg); + goto err_free; + } + + ret = regulator_enable(st->vdd_reg); + if (ret) + goto err_put_vdd_reg; + + if (spi->dev.of_node) { + ext_ref = of_property_read_bool(spi->dev.of_node, + "REF-supply"); + } else { + struct ad7303_platform_data *pdata = spi->dev.platform_data; + if (pdata && pdata->use_external_ref) + ext_ref = true; + else + ext_ref = false; + } + + if (ext_ref) { + st->vref_reg = regulator_get(&spi->dev, "REF"); + if (IS_ERR(st->vref_reg)) + goto err_disable_vdd_reg; + + ret = regulator_enable(st->vref_reg); + if (ret) + goto err_put_vref_reg; + + st->config |= AD7303_CFG_EXTERNAL_VREF; + } + + indio_dev->dev.parent = &spi->dev; + indio_dev->name = id->name; + indio_dev->info = &ad7303_info; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = ad7303_channels; + indio_dev->num_channels = ARRAY_SIZE(ad7303_channels); + + ret = iio_device_register(indio_dev); + if (ret) + goto err_disable_vref_reg; + + return 0; + +err_disable_vref_reg: + if (st->vref_reg) + regulator_disable(st->vref_reg); +err_put_vref_reg: + if (st->vref_reg) + regulator_put(st->vref_reg); +err_disable_vdd_reg: + regulator_disable(st->vdd_reg); +err_put_vdd_reg: + regulator_put(st->vdd_reg); +err_free: + iio_device_free(indio_dev); + + return ret; +} + +static int ad7303_remove(struct spi_device *spi) +{ + struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct ad7303_state *st = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + + if (st->vref_reg) { + regulator_disable(st->vref_reg); + regulator_put(st->vref_reg); + } + regulator_disable(st->vdd_reg); + regulator_put(st->vdd_reg); + + iio_device_free(indio_dev); + + return 0; +} + +static const struct spi_device_id ad7303_spi_ids[] = { + { "ad7303", 0 }, + {} +}; +MODULE_DEVICE_TABLE(spi, ad7303_spi_ids); + +static struct spi_driver ad7303_driver = { + .driver = { + .name = "ad7303", + .owner = THIS_MODULE, + }, + .probe = ad7303_probe, + .remove = ad7303_remove, + .id_table = ad7303_spi_ids, +}; +module_spi_driver(ad7303_driver); + +MODULE_AUTHOR("Lars-Peter Clausen "); +MODULE_DESCRIPTION("Analog Devices AD7303 DAC driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/frequency/adf4350.c b/drivers/iio/frequency/adf4350.c index e76d4ace53ff..a4157cdb314d 100644 --- a/drivers/iio/frequency/adf4350.c +++ b/drivers/iio/frequency/adf4350.c @@ -1,7 +1,7 @@ /* * ADF4350/ADF4351 SPI Wideband Synthesizer driver * - * Copyright 2012 Analog Devices Inc. + * Copyright 2012-2013 Analog Devices Inc. * * Licensed under the GPL-2. */ @@ -17,6 +17,9 @@ #include #include #include +#include +#include +#include #include #include @@ -33,6 +36,7 @@ struct adf4350_state { struct spi_device *spi; struct regulator *reg; struct adf4350_platform_data *pdata; + struct clk *clk; unsigned long clkin; unsigned long chspc; /* Channel Spacing */ unsigned long fpfd; /* Phase Frequency Detector */ @@ -43,7 +47,7 @@ struct adf4350_state { unsigned r4_rf_div_sel; unsigned long regs[6]; unsigned long regs_hw[6]; - + unsigned long long freq_req; /* * DMA (thus cache coherency maintenance) requires the * transfer buffers to live in their own cache lines. @@ -52,7 +56,6 @@ struct adf4350_state { }; static struct adf4350_platform_data default_pdata = { - .clkin = 122880000, .channel_spacing = 10000, .r2_user_settings = ADF4350_REG2_PD_POLARITY_POS | ADF4350_REG2_CHARGE_PUMP_CURR_uA(2500), @@ -235,6 +238,7 @@ static int adf4350_set_freq(struct adf4350_state *st, unsigned long long freq) ADF4350_REG4_MUTE_TILL_LOCK_EN)); st->regs[ADF4350_REG5] = ADF4350_REG5_LD_PIN_MODE_DIGITAL; + st->freq_req = freq; return adf4350_sync_config(st); } @@ -246,6 +250,7 @@ static ssize_t adf4350_write(struct iio_dev *indio_dev, { struct adf4350_state *st = iio_priv(indio_dev); unsigned long long readin; + unsigned long tmp; int ret; ret = kstrtoull(buf, 10, &readin); @@ -258,10 +263,23 @@ static ssize_t adf4350_write(struct iio_dev *indio_dev, ret = adf4350_set_freq(st, readin); break; case ADF4350_FREQ_REFIN: - if (readin > ADF4350_MAX_FREQ_REFIN) + if (readin > ADF4350_MAX_FREQ_REFIN) { ret = -EINVAL; - else - st->clkin = readin; + break; + } + + if (st->clk) { + tmp = clk_round_rate(st->clk, readin); + if (tmp != readin) { + ret = -EINVAL; + break; + } + ret = clk_set_rate(st->clk, tmp); + if (ret < 0) + break; + } + st->clkin = readin; + ret = adf4350_set_freq(st, st->freq_req); break; case ADF4350_FREQ_RESOLUTION: if (readin == 0) @@ -308,6 +326,9 @@ static ssize_t adf4350_read(struct iio_dev *indio_dev, } break; case ADF4350_FREQ_REFIN: + if (st->clk) + st->clkin = clk_get_rate(st->clk); + val = st->clkin; break; case ADF4350_FREQ_RESOLUTION: @@ -318,6 +339,7 @@ static ssize_t adf4350_read(struct iio_dev *indio_dev, break; default: ret = -EINVAL; + val = 0; } mutex_unlock(&indio_dev->mlock); @@ -355,19 +377,153 @@ static const struct iio_info adf4350_info = { .driver_module = THIS_MODULE, }; +#ifdef CONFIG_OF +static struct adf4350_platform_data *adf4350_parse_dt(struct device *dev) +{ + struct device_node *np = dev->of_node; + struct adf4350_platform_data *pdata; + unsigned int tmp; + int ret; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) { + dev_err(dev, "could not allocate memory for platform data\n"); + return NULL; + } + + strncpy(&pdata->name[0], np->name, SPI_NAME_SIZE - 1); + + tmp = 10000; + of_property_read_u32(np, "adi,channel-spacing", &tmp); + pdata->channel_spacing = tmp; + + tmp = 0; + of_property_read_u32(np, "adi,power-up-frequency", &tmp); + pdata->power_up_frequency = tmp; + + tmp = 0; + of_property_read_u32(np, "adi,reference-div-factor", &tmp); + pdata->ref_div_factor = tmp; + + ret = of_get_gpio(np, 0); + if (ret < 0) + pdata->gpio_lock_detect = -1; + else + pdata->gpio_lock_detect = ret; + + pdata->ref_doubler_en = of_property_read_bool(np, + "adi,reference-doubler-enable"); + pdata->ref_div2_en = of_property_read_bool(np, + "adi,reference-div2-enable"); + + /* r2_user_settings */ + pdata->r2_user_settings = of_property_read_bool(np, + "adi,phase-detector-polarity-positive-enable") ? + ADF4350_REG2_PD_POLARITY_POS : 0; + pdata->r2_user_settings |= of_property_read_bool(np, + "adi,lock-detect-precision-6ns-enable") ? + ADF4350_REG2_LDP_6ns : 0; + pdata->r2_user_settings |= of_property_read_bool(np, + "adi,lock-detect-function-integer-n-enable") ? + ADF4350_REG2_LDF_INT_N : 0; + + tmp = 2500; + of_property_read_u32(np, "adi,charge-pump-current", &tmp); + pdata->r2_user_settings |= ADF4350_REG2_CHARGE_PUMP_CURR_uA(tmp); + + tmp = 0; + of_property_read_u32(np, "adi,muxout-select", &tmp); + pdata->r2_user_settings |= ADF4350_REG2_MUXOUT(tmp); + + pdata->r2_user_settings |= of_property_read_bool(np, + "adi,low-spur-mode-enable") ? + ADF4350_REG2_NOISE_MODE(0x3) : 0; + + /* r3_user_settings */ + + pdata->r3_user_settings = of_property_read_bool(np, + "adi,cycle-slip-reduction-enable") ? + ADF4350_REG3_12BIT_CSR_EN : 0; + pdata->r3_user_settings |= of_property_read_bool(np, + "adi,charge-cancellation-enable") ? + ADF4351_REG3_CHARGE_CANCELLATION_EN : 0; + + pdata->r3_user_settings |= of_property_read_bool(np, + "adi,anti-backlash-3ns-enable") ? + ADF4351_REG3_ANTI_BACKLASH_3ns_EN : 0; + pdata->r3_user_settings |= of_property_read_bool(np, + "adi,band-select-clock-mode-high-enable") ? + ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH : 0; + + tmp = 0; + of_property_read_u32(np, "adi,12bit-clk-divider", &tmp); + pdata->r3_user_settings |= ADF4350_REG3_12BIT_CLKDIV(tmp); + + tmp = 0; + of_property_read_u32(np, "adi,clk-divider-mode", &tmp); + pdata->r3_user_settings |= ADF4350_REG3_12BIT_CLKDIV_MODE(tmp); + + /* r4_user_settings */ + + pdata->r4_user_settings = of_property_read_bool(np, + "adi,aux-output-enable") ? + ADF4350_REG4_AUX_OUTPUT_EN : 0; + pdata->r4_user_settings |= of_property_read_bool(np, + "adi,aux-output-fundamental-enable") ? + ADF4350_REG4_AUX_OUTPUT_FUND : 0; + pdata->r4_user_settings |= of_property_read_bool(np, + "adi,mute-till-lock-enable") ? + ADF4350_REG4_MUTE_TILL_LOCK_EN : 0; + + tmp = 0; + of_property_read_u32(np, "adi,output-power", &tmp); + pdata->r4_user_settings |= ADF4350_REG4_OUTPUT_PWR(tmp); + + tmp = 0; + of_property_read_u32(np, "adi,aux-output-power", &tmp); + pdata->r4_user_settings |= ADF4350_REG4_AUX_OUTPUT_PWR(tmp); + + return pdata; +} +#else +static +struct adf4350_platform_data *adf4350_parse_dt(struct device *dev) +{ + return NULL; +} +#endif + static int adf4350_probe(struct spi_device *spi) { - struct adf4350_platform_data *pdata = spi->dev.platform_data; + struct adf4350_platform_data *pdata; struct iio_dev *indio_dev; struct adf4350_state *st; + struct clk *clk = NULL; int ret; + if (spi->dev.of_node) { + pdata = adf4350_parse_dt(&spi->dev); + if (pdata == NULL) + return -EINVAL; + } else { + pdata = spi->dev.platform_data; + } + if (!pdata) { dev_warn(&spi->dev, "no platform data? using default\n"); - pdata = &default_pdata; } + if (!pdata->clkin) { + clk = clk_get(&spi->dev, "clkin"); + if (IS_ERR(clk)) + return -EPROBE_DEFER; + + ret = clk_prepare_enable(clk); + if (ret < 0) + return ret; + } + indio_dev = iio_device_alloc(sizeof(*st)); if (indio_dev == NULL) return -ENOMEM; @@ -395,7 +551,12 @@ static int adf4350_probe(struct spi_device *spi) indio_dev->num_channels = 1; st->chspc = pdata->channel_spacing; - st->clkin = pdata->clkin; + if (clk) { + st->clk = clk; + st->clkin = clk_get_rate(clk); + } else { + st->clkin = pdata->clkin; + } st->min_out_freq = spi_get_device_id(spi)->driver_data == 4351 ? ADF4351_MIN_OUT_FREQ : ADF4350_MIN_OUT_FREQ; @@ -435,6 +596,8 @@ error_put_reg: if (!IS_ERR(st->reg)) regulator_put(st->reg); + if (clk) + clk_disable_unprepare(clk); iio_device_free(indio_dev); return ret; @@ -451,6 +614,9 @@ static int adf4350_remove(struct spi_device *spi) iio_device_unregister(indio_dev); + if (st->clk) + clk_disable_unprepare(st->clk); + if (!IS_ERR(reg)) { regulator_disable(reg); regulator_put(reg); @@ -481,6 +647,6 @@ static struct spi_driver adf4350_driver = { }; module_spi_driver(adf4350_driver); -MODULE_AUTHOR("Michael Hennerich "); +MODULE_AUTHOR("Michael Hennerich "); MODULE_DESCRIPTION("Analog Devices ADF4350/ADF4351 PLL"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig index 6be4628faffe..8498e9dcda68 100644 --- a/drivers/iio/gyro/Kconfig +++ b/drivers/iio/gyro/Kconfig @@ -10,6 +10,13 @@ config ADIS16080 Say yes here to build support for Analog Devices ADIS16080, ADIS16100 Yaw Rate Gyroscope with SPI. +config ADIS16130 + tristate "Analog Devices ADIS16130 High Precision Angular Rate Sensor driver" + depends on SPI + help + Say yes here to build support for Analog Devices ADIS16130 High Precision + Angular Rate Sensor driver. + config ADIS16136 tristate "Analog devices ADIS16136 and similar gyroscopes driver" depends on SPI_MASTER @@ -47,7 +54,6 @@ config IIO_ST_GYRO_3AXIS select IIO_ST_GYRO_I2C_3AXIS if (I2C) select IIO_ST_GYRO_SPI_3AXIS if (SPI_MASTER) select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) - select IIO_ST_GYRO_BUFFER if (IIO_TRIGGERED_BUFFER) help Say yes here to build support for STMicroelectronics gyroscopes: L3G4200D, LSM330DL, L3GD20, L3GD20H, LSM330DLC, L3G4IS, LSM330. diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile index 225d289082e6..e9dc034aa18b 100644 --- a/drivers/iio/gyro/Makefile +++ b/drivers/iio/gyro/Makefile @@ -3,6 +3,7 @@ # obj-$(CONFIG_ADIS16080) += adis16080.o +obj-$(CONFIG_ADIS16130) += adis16130.o obj-$(CONFIG_ADIS16136) += adis16136.o obj-$(CONFIG_ADXRS450) += adxrs450.o diff --git a/drivers/staging/iio/gyro/adis16130_core.c b/drivers/iio/gyro/adis16130.c similarity index 77% rename from drivers/staging/iio/gyro/adis16130_core.c rename to drivers/iio/gyro/adis16130.c index 531b803cb2ac..129acdf801a4 100644 --- a/drivers/staging/iio/gyro/adis16130_core.c +++ b/drivers/iio/gyro/adis16130.c @@ -6,18 +6,12 @@ * Licensed under the GPL-2 or later. */ -#include #include -#include #include #include -#include -#include -#include #include #include -#include #define ADIS16130_CON 0x0 #define ADIS16130_CON_RD (1 << 6) @@ -68,7 +62,6 @@ static int adis16130_spi_read(struct iio_dev *indio_dev, u8 reg_addr, u32 *val) spi_message_init(&msg); spi_message_add_tail(&xfer, &msg); ret = spi_sync(st->us, &msg); - ret = spi_read(st->us, st->buf, 4); if (ret == 0) *val = (st->buf[1] << 16) | (st->buf[2] << 8) | st->buf[3]; @@ -85,14 +78,47 @@ static int adis16130_read_raw(struct iio_dev *indio_dev, int ret; u32 temp; - /* Take the iio_dev status lock */ - mutex_lock(&indio_dev->mlock); - ret = adis16130_spi_read(indio_dev, chan->address, &temp); - mutex_unlock(&indio_dev->mlock); - if (ret) - return ret; - *val = temp; - return IIO_VAL_INT; + switch (mask) { + case IIO_CHAN_INFO_RAW: + /* Take the iio_dev status lock */ + mutex_lock(&indio_dev->mlock); + ret = adis16130_spi_read(indio_dev, chan->address, &temp); + mutex_unlock(&indio_dev->mlock); + if (ret) + return ret; + *val = temp; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_ANGL_VEL: + /* 0 degree = 838860, 250 degree = 14260608 */ + *val = 250; + *val2 = 336440817; /* RAD_TO_DEGREE(14260608 - 8388608) */ + return IIO_VAL_FRACTIONAL; + case IIO_TEMP: + /* 0C = 8036283, 105C = 9516048 */ + *val = 105000; + *val2 = 9516048 - 8036283; + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; + } + break; + case IIO_CHAN_INFO_OFFSET: + switch (chan->type) { + case IIO_ANGL_VEL: + *val = -8388608; + return IIO_VAL_INT; + case IIO_TEMP: + *val = -8036283; + return IIO_VAL_INT; + default: + return -EINVAL; + } + break; + } + + return -EINVAL; } static const struct iio_chan_spec adis16130_channels[] = { @@ -100,13 +126,17 @@ static const struct iio_chan_spec adis16130_channels[] = { .type = IIO_ANGL_VEL, .modified = 1, .channel2 = IIO_MOD_Z, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_OFFSET), .address = ADIS16130_RATEDATA, }, { .type = IIO_TEMP, .indexed = 1, .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_OFFSET), .address = ADIS16130_TEMPDATA, } }; @@ -153,7 +183,6 @@ error_ret: return ret; } -/* fixme, confirm ordering in this function */ static int adis16130_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c index fa9b24219987..f9ed3488c314 100644 --- a/drivers/iio/gyro/st_gyro_core.c +++ b/drivers/iio/gyro/st_gyro_core.c @@ -27,6 +27,8 @@ #include #include "st_gyro.h" +#define ST_GYRO_NUMBER_DATA_CHANNELS 3 + /* DEFAULT VALUE FOR SENSORS */ #define ST_GYRO_DEFAULT_OUT_X_L_ADDR 0x28 #define ST_GYRO_DEFAULT_OUT_Y_L_ADDR 0x2a @@ -86,15 +88,18 @@ #define ST_GYRO_2_MULTIREAD_BIT true static const struct iio_chan_spec st_gyro_16bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_X, - IIO_MOD_X, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS, - ST_GYRO_DEFAULT_OUT_X_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_Y, - IIO_MOD_Y, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS, - ST_GYRO_DEFAULT_OUT_Y_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_Z, - IIO_MOD_Z, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS, - ST_GYRO_DEFAULT_OUT_Z_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16, + ST_GYRO_DEFAULT_OUT_X_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16, + ST_GYRO_DEFAULT_OUT_Y_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16, + ST_GYRO_DEFAULT_OUT_Z_L_ADDR), IIO_CHAN_SOFT_TIMESTAMP(3) }; @@ -310,6 +315,7 @@ int st_gyro_common_probe(struct iio_dev *indio_dev) if (err < 0) goto st_gyro_common_probe_error; + gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS; gdata->multiread_bit = gdata->sensor->multi_read_bit; indio_dev->channels = gdata->sensor->ch; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index aaadd32f9f0d..e73033f3839a 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -542,8 +542,7 @@ int iio_update_buffers(struct iio_dev *indio_dev, ret = indio_dev->setup_ops->preenable(indio_dev); if (ret) { printk(KERN_ERR - "Buffer not started:" - "buffer preenable failed\n"); + "Buffer not started: buffer preenable failed (%d)\n", ret); goto error_remove_inserted; } } @@ -556,8 +555,7 @@ int iio_update_buffers(struct iio_dev *indio_dev, ret = buffer->access->request_update(buffer); if (ret) { printk(KERN_INFO - "Buffer not started:" - "buffer parameter update failed\n"); + "Buffer not started: buffer parameter update failed (%d)\n", ret); goto error_run_postdisable; } } @@ -566,7 +564,7 @@ int iio_update_buffers(struct iio_dev *indio_dev, ->update_scan_mode(indio_dev, indio_dev->active_scan_mask); if (ret < 0) { - printk(KERN_INFO "update scan mode failed\n"); + printk(KERN_INFO "Buffer not started: update scan mode failed (%d)\n", ret); goto error_run_postdisable; } } @@ -590,7 +588,7 @@ int iio_update_buffers(struct iio_dev *indio_dev, ret = indio_dev->setup_ops->postenable(indio_dev); if (ret) { printk(KERN_INFO - "Buffer not started: postenable failed\n"); + "Buffer not started: postenable failed (%d)\n", ret); indio_dev->currentmode = INDIO_DIRECT_MODE; if (indio_dev->setup_ops->postdisable) indio_dev->setup_ops->postdisable(indio_dev); diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index 80d68ff02d29..cdc2cad0f01b 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -31,7 +31,7 @@ #include "../common/hid-sensors/hid-sensor-trigger.h" /*Format: HID-SENSOR-usage_id_in_hex*/ -/*Usage ID from spec for Accelerometer-3D: 0x200041*/ +/*Usage ID from spec for Ambiant-Light: 0x200041*/ #define DRIVER_NAME "HID-SENSOR-200041" #define CHANNEL_SCAN_INDEX_ILLUM 0 diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig index bd1cfb666695..c332b0ae4a3b 100644 --- a/drivers/iio/magnetometer/Kconfig +++ b/drivers/iio/magnetometer/Kconfig @@ -32,7 +32,6 @@ config IIO_ST_MAGN_3AXIS select IIO_ST_MAGN_I2C_3AXIS if (I2C) select IIO_ST_MAGN_SPI_3AXIS if (SPI_MASTER) select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) - select IIO_ST_MAGN_BUFFER if (IIO_TRIGGERED_BUFFER) help Say yes here to build support for STMicroelectronics magnetometers: LSM303DLHC, LSM303DLM, LIS3MDL. diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index af6c320a534e..7105f22d6cd7 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -24,11 +24,13 @@ #include #include #include +#include #include #include #include - +#include #include +#include #include #include @@ -82,6 +84,7 @@ */ #define AK8975_MAX_CONVERSION_TIMEOUT 500 #define AK8975_CONVERSION_DONE_POLL_TIME 10 +#define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000) /* * Per-instance context data for the device. @@ -94,6 +97,9 @@ struct ak8975_data { long raw_to_gauss[3]; u8 reg_cache[AK8975_MAX_REGS]; int eoc_gpio; + int eoc_irq; + wait_queue_head_t data_ready_queue; + unsigned long flags; }; static const int ak8975_index_to_reg[] = { @@ -122,6 +128,51 @@ static int ak8975_write_data(struct i2c_client *client, return 0; } +/* + * Handle data ready irq + */ +static irqreturn_t ak8975_irq_handler(int irq, void *data) +{ + struct ak8975_data *ak8975 = data; + + set_bit(0, &ak8975->flags); + wake_up(&ak8975->data_ready_queue); + + return IRQ_HANDLED; +} + +/* + * Install data ready interrupt handler + */ +static int ak8975_setup_irq(struct ak8975_data *data) +{ + struct i2c_client *client = data->client; + int rc; + int irq; + + if (client->irq) + irq = client->irq; + else + irq = gpio_to_irq(data->eoc_gpio); + + rc = request_irq(irq, ak8975_irq_handler, + IRQF_TRIGGER_RISING | IRQF_ONESHOT, + dev_name(&client->dev), data); + if (rc < 0) { + dev_err(&client->dev, + "irq %d request failed, (gpio %d): %d\n", + irq, data->eoc_gpio, rc); + return rc; + } + + init_waitqueue_head(&data->data_ready_queue); + clear_bit(0, &data->flags); + data->eoc_irq = irq; + + return rc; +} + + /* * Perform some start-of-day setup, including reading the asa calibration * values and caching them. @@ -170,6 +221,16 @@ static int ak8975_setup(struct i2c_client *client) AK8975_REG_CNTL_MODE_POWER_DOWN, AK8975_REG_CNTL_MODE_MASK, AK8975_REG_CNTL_MODE_SHIFT); + + if (data->eoc_gpio > 0 || client->irq) { + ret = ak8975_setup_irq(data); + if (ret < 0) { + dev_err(&client->dev, + "Error setting data ready interrupt\n"); + return ret; + } + } + if (ret < 0) { dev_err(&client->dev, "Error in setting power-down mode\n"); return ret; @@ -266,9 +327,23 @@ static int wait_conversion_complete_polled(struct ak8975_data *data) dev_err(&client->dev, "Conversion timeout happened\n"); return -EINVAL; } + return read_status; } +/* Returns 0 if the end of conversion interrupt occured or -ETIME otherwise */ +static int wait_conversion_complete_interrupt(struct ak8975_data *data) +{ + int ret; + + ret = wait_event_timeout(data->data_ready_queue, + test_bit(0, &data->flags), + AK8975_DATA_READY_TIMEOUT); + clear_bit(0, &data->flags); + + return ret > 0 ? 0 : -ETIME; +} + /* * Emits the raw flux value for the x, y, or z axis. */ @@ -294,13 +369,16 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val) } /* Wait for the conversion to complete. */ - if (gpio_is_valid(data->eoc_gpio)) + if (data->eoc_irq) + ret = wait_conversion_complete_interrupt(data); + else if (gpio_is_valid(data->eoc_gpio)) ret = wait_conversion_complete_gpio(data); else ret = wait_conversion_complete_polled(data); if (ret < 0) goto exit; + /* This will be executed only for non-interrupt based waiting case */ if (ret & AK8975_REG_ST1_DRDY_MASK) { ret = i2c_smbus_read_byte_data(client, AK8975_REG_ST2); if (ret < 0) { @@ -384,10 +462,15 @@ static int ak8975_probe(struct i2c_client *client, int err; /* Grab and set up the supplied GPIO. */ - if (client->dev.platform_data == NULL) - eoc_gpio = -1; - else + if (client->dev.platform_data) eoc_gpio = *(int *)(client->dev.platform_data); + else if (client->dev.of_node) + eoc_gpio = of_get_gpio(client->dev.of_node, 0); + else + eoc_gpio = -1; + + if (eoc_gpio == -EPROBE_DEFER) + return -EPROBE_DEFER; /* We may not have a GPIO based IRQ to scan, that is fine, we will poll if so */ @@ -409,6 +492,11 @@ static int ak8975_probe(struct i2c_client *client, } data = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); + + data->client = client; + data->eoc_gpio = eoc_gpio; + data->eoc_irq = 0; + /* Perform some basic start-of-day setup of the device. */ err = ak8975_setup(client); if (err < 0) { @@ -433,6 +521,8 @@ static int ak8975_probe(struct i2c_client *client, exit_free_iio: iio_device_free(indio_dev); + if (data->eoc_irq) + free_irq(data->eoc_irq, data); exit_gpio: if (gpio_is_valid(eoc_gpio)) gpio_free(eoc_gpio); @@ -447,6 +537,9 @@ static int ak8975_remove(struct i2c_client *client) iio_device_unregister(indio_dev); + if (data->eoc_irq) + free_irq(data->eoc_irq, data); + if (gpio_is_valid(data->eoc_gpio)) gpio_free(data->eoc_gpio); diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c index 16f0d6df239f..ebfe8f11a0c2 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -26,6 +26,8 @@ #include #include "st_magn.h" +#define ST_MAGN_NUMBER_DATA_CHANNELS 3 + /* DEFAULT VALUE FOR SENSORS */ #define ST_MAGN_DEFAULT_OUT_X_L_ADDR 0X04 #define ST_MAGN_DEFAULT_OUT_Y_L_ADDR 0X08 @@ -113,22 +115,34 @@ #define ST_MAGN_2_OUT_Z_L_ADDR 0x2c static const struct iio_chan_spec st_magn_16bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE, - ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_X_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE, - ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_Y_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE, - ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_Z_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16, + ST_MAGN_DEFAULT_OUT_X_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16, + ST_MAGN_DEFAULT_OUT_Y_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16, + ST_MAGN_DEFAULT_OUT_Z_L_ADDR), IIO_CHAN_SOFT_TIMESTAMP(3) }; static const struct iio_chan_spec st_magn_2_16bit_channels[] = { - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE, - ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_X_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE, - ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_Y_L_ADDR), - ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE, - ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_Z_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16, + ST_MAGN_2_OUT_X_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16, + ST_MAGN_2_OUT_Y_L_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_MAGN, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16, + ST_MAGN_2_OUT_Z_L_ADDR), IIO_CHAN_SOFT_TIMESTAMP(3) }; @@ -344,6 +358,7 @@ int st_magn_common_probe(struct iio_dev *indio_dev) if (err < 0) goto st_magn_common_probe_error; + mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS; mdata->multiread_bit = mdata->sensor->multi_read_bit; indio_dev->channels = mdata->sensor->ch; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig new file mode 100644 index 000000000000..9427f01e1499 --- /dev/null +++ b/drivers/iio/pressure/Kconfig @@ -0,0 +1,35 @@ +# +# Pressure drivers +# +menu "Pressure Sensors" + +config IIO_ST_PRESS + tristate "STMicroelectronics pressures Driver" + depends on (I2C || SPI_MASTER) && SYSFS + select IIO_ST_SENSORS_CORE + select IIO_ST_PRESS_I2C if (I2C) + select IIO_ST_PRESS_SPI if (SPI_MASTER) + select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) + help + Say yes here to build support for STMicroelectronics pressures: + LPS331AP. + + This driver can also be built as a module. If so, will be created + these modules: + - st_pressure (core functions for the driver [it is mandatory]); + - st_pressure_i2c (necessary for the I2C devices [optional*]); + - st_pressure_spi (necessary for the SPI devices [optional*]); + + (*) one of these is necessary to do something. + +config IIO_ST_PRESS_I2C + tristate + depends on IIO_ST_PRESS + depends on IIO_ST_SENSORS_I2C + +config IIO_ST_PRESS_SPI + tristate + depends on IIO_ST_PRESS + depends on IIO_ST_SENSORS_SPI + +endmenu diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile new file mode 100644 index 000000000000..d4bb33e5c846 --- /dev/null +++ b/drivers/iio/pressure/Makefile @@ -0,0 +1,10 @@ +# +# Makefile for industrial I/O pressure drivers +# + +obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o +st_pressure-y := st_pressure_core.o +st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o + +obj-$(CONFIG_IIO_ST_PRESS_I2C) += st_pressure_i2c.o +obj-$(CONFIG_IIO_ST_PRESS_SPI) += st_pressure_spi.o diff --git a/drivers/iio/pressure/st_pressure.h b/drivers/iio/pressure/st_pressure.h new file mode 100644 index 000000000000..414e45ac9b9b --- /dev/null +++ b/drivers/iio/pressure/st_pressure.h @@ -0,0 +1,39 @@ +/* + * STMicroelectronics pressures driver + * + * Copyright 2013 STMicroelectronics Inc. + * + * Denis Ciocca + * v. 1.0.0 + * Licensed under the GPL-2. + */ + +#ifndef ST_PRESS_H +#define ST_PRESS_H + +#include +#include + +#define LPS331AP_PRESS_DEV_NAME "lps331ap" + +int st_press_common_probe(struct iio_dev *indio_dev); +void st_press_common_remove(struct iio_dev *indio_dev); + +#ifdef CONFIG_IIO_BUFFER +int st_press_allocate_ring(struct iio_dev *indio_dev); +void st_press_deallocate_ring(struct iio_dev *indio_dev); +int st_press_trig_set_state(struct iio_trigger *trig, bool state); +#define ST_PRESS_TRIGGER_SET_STATE (&st_press_trig_set_state) +#else /* CONFIG_IIO_BUFFER */ +static inline int st_press_allocate_ring(struct iio_dev *indio_dev) +{ + return 0; +} + +static inline void st_press_deallocate_ring(struct iio_dev *indio_dev) +{ +} +#define ST_PRESS_TRIGGER_SET_STATE NULL +#endif /* CONFIG_IIO_BUFFER */ + +#endif /* ST_PRESS_H */ diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c new file mode 100644 index 000000000000..f877ef8af520 --- /dev/null +++ b/drivers/iio/pressure/st_pressure_buffer.c @@ -0,0 +1,105 @@ +/* + * STMicroelectronics pressures driver + * + * Copyright 2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "st_pressure.h" + +int st_press_trig_set_state(struct iio_trigger *trig, bool state) +{ + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); + + return st_sensors_set_dataready_irq(indio_dev, state); +} + +static int st_press_buffer_preenable(struct iio_dev *indio_dev) +{ + int err; + + err = st_sensors_set_enable(indio_dev, true); + if (err < 0) + goto st_press_set_enable_error; + + err = iio_sw_buffer_preenable(indio_dev); + +st_press_set_enable_error: + return err; +} + +static int st_press_buffer_postenable(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *pdata = iio_priv(indio_dev); + + pdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); + if (pdata->buffer_data == NULL) { + err = -ENOMEM; + goto allocate_memory_error; + } + + err = iio_triggered_buffer_postenable(indio_dev); + if (err < 0) + goto st_press_buffer_postenable_error; + + return err; + +st_press_buffer_postenable_error: + kfree(pdata->buffer_data); +allocate_memory_error: + return err; +} + +static int st_press_buffer_predisable(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *pdata = iio_priv(indio_dev); + + err = iio_triggered_buffer_predisable(indio_dev); + if (err < 0) + goto st_press_buffer_predisable_error; + + err = st_sensors_set_enable(indio_dev, false); + +st_press_buffer_predisable_error: + kfree(pdata->buffer_data); + return err; +} + +static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = { + .preenable = &st_press_buffer_preenable, + .postenable = &st_press_buffer_postenable, + .predisable = &st_press_buffer_predisable, +}; + +int st_press_allocate_ring(struct iio_dev *indio_dev) +{ + return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, + &st_sensors_trigger_handler, &st_press_buffer_setup_ops); +} + +void st_press_deallocate_ring(struct iio_dev *indio_dev) +{ + iio_triggered_buffer_cleanup(indio_dev); +} + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics pressures buffer"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c new file mode 100644 index 000000000000..9c343b40665e --- /dev/null +++ b/drivers/iio/pressure/st_pressure_core.c @@ -0,0 +1,272 @@ +/* + * STMicroelectronics pressures driver + * + * Copyright 2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "st_pressure.h" + +#define ST_PRESS_MBAR_TO_KPASCAL(x) (x * 10) +#define ST_PRESS_NUMBER_DATA_CHANNELS 1 + +/* DEFAULT VALUE FOR SENSORS */ +#define ST_PRESS_DEFAULT_OUT_XL_ADDR 0x28 +#define ST_TEMP_DEFAULT_OUT_L_ADDR 0x2b + +/* FULLSCALE */ +#define ST_PRESS_FS_AVL_1260MB 1260 + +/* CUSTOM VALUES FOR SENSOR 1 */ +#define ST_PRESS_1_WAI_EXP 0xbb +#define ST_PRESS_1_ODR_ADDR 0x20 +#define ST_PRESS_1_ODR_MASK 0x70 +#define ST_PRESS_1_ODR_AVL_1HZ_VAL 0x01 +#define ST_PRESS_1_ODR_AVL_7HZ_VAL 0x05 +#define ST_PRESS_1_ODR_AVL_13HZ_VAL 0x06 +#define ST_PRESS_1_ODR_AVL_25HZ_VAL 0x07 +#define ST_PRESS_1_PW_ADDR 0x20 +#define ST_PRESS_1_PW_MASK 0x80 +#define ST_PRESS_1_FS_ADDR 0x23 +#define ST_PRESS_1_FS_MASK 0x30 +#define ST_PRESS_1_FS_AVL_1260_VAL 0x00 +#define ST_PRESS_1_FS_AVL_1260_GAIN ST_PRESS_MBAR_TO_KPASCAL(244141) +#define ST_PRESS_1_FS_AVL_TEMP_GAIN 2083000 +#define ST_PRESS_1_BDU_ADDR 0x20 +#define ST_PRESS_1_BDU_MASK 0x04 +#define ST_PRESS_1_DRDY_IRQ_ADDR 0x22 +#define ST_PRESS_1_DRDY_IRQ_MASK 0x04 +#define ST_PRESS_1_MULTIREAD_BIT true +#define ST_PRESS_1_TEMP_OFFSET 42500 + +static const struct iio_chan_spec st_press_channels[] = { + ST_SENSORS_LSM_CHANNELS(IIO_PRESSURE, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + ST_SENSORS_SCAN_X, 0, IIO_NO_MOD, 'u', IIO_LE, 24, 24, + ST_PRESS_DEFAULT_OUT_XL_ADDR), + ST_SENSORS_LSM_CHANNELS(IIO_TEMP, + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_OFFSET), + -1, 0, IIO_NO_MOD, 's', IIO_LE, 16, 16, + ST_TEMP_DEFAULT_OUT_L_ADDR), + IIO_CHAN_SOFT_TIMESTAMP(1) +}; + +static const struct st_sensors st_press_sensors[] = { + { + .wai = ST_PRESS_1_WAI_EXP, + .sensors_supported = { + [0] = LPS331AP_PRESS_DEV_NAME, + }, + .ch = (struct iio_chan_spec *)st_press_channels, + .odr = { + .addr = ST_PRESS_1_ODR_ADDR, + .mask = ST_PRESS_1_ODR_MASK, + .odr_avl = { + { 1, ST_PRESS_1_ODR_AVL_1HZ_VAL, }, + { 7, ST_PRESS_1_ODR_AVL_7HZ_VAL, }, + { 13, ST_PRESS_1_ODR_AVL_13HZ_VAL, }, + { 25, ST_PRESS_1_ODR_AVL_25HZ_VAL, }, + }, + }, + .pw = { + .addr = ST_PRESS_1_PW_ADDR, + .mask = ST_PRESS_1_PW_MASK, + .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE, + .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, + }, + .fs = { + .addr = ST_PRESS_1_FS_ADDR, + .mask = ST_PRESS_1_FS_MASK, + .fs_avl = { + [0] = { + .num = ST_PRESS_FS_AVL_1260MB, + .value = ST_PRESS_1_FS_AVL_1260_VAL, + .gain = ST_PRESS_1_FS_AVL_1260_GAIN, + .gain2 = ST_PRESS_1_FS_AVL_TEMP_GAIN, + }, + }, + }, + .bdu = { + .addr = ST_PRESS_1_BDU_ADDR, + .mask = ST_PRESS_1_BDU_MASK, + }, + .drdy_irq = { + .addr = ST_PRESS_1_DRDY_IRQ_ADDR, + .mask = ST_PRESS_1_DRDY_IRQ_MASK, + }, + .multi_read_bit = ST_PRESS_1_MULTIREAD_BIT, + .bootime = 2, + }, +}; + +static int st_press_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *ch, int *val, + int *val2, long mask) +{ + int err; + struct st_sensor_data *pdata = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + err = st_sensors_read_info_raw(indio_dev, ch, val); + if (err < 0) + goto read_error; + + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 0; + + switch (ch->type) { + case IIO_PRESSURE: + *val2 = pdata->current_fullscale->gain; + break; + case IIO_TEMP: + *val2 = pdata->current_fullscale->gain2; + break; + default: + err = -EINVAL; + goto read_error; + } + + return IIO_VAL_INT_PLUS_NANO; + case IIO_CHAN_INFO_OFFSET: + switch (ch->type) { + case IIO_TEMP: + *val = 425; + *val2 = 10; + break; + default: + err = -EINVAL; + goto read_error; + } + + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; + } + +read_error: + return err; +} + +static ST_SENSOR_DEV_ATTR_SAMP_FREQ(); +static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL(); + +static struct attribute *st_press_attributes[] = { + &iio_dev_attr_sampling_frequency_available.dev_attr.attr, + &iio_dev_attr_sampling_frequency.dev_attr.attr, + NULL, +}; + +static const struct attribute_group st_press_attribute_group = { + .attrs = st_press_attributes, +}; + +static const struct iio_info press_info = { + .driver_module = THIS_MODULE, + .attrs = &st_press_attribute_group, + .read_raw = &st_press_read_raw, +}; + +#ifdef CONFIG_IIO_TRIGGER +static const struct iio_trigger_ops st_press_trigger_ops = { + .owner = THIS_MODULE, + .set_trigger_state = ST_PRESS_TRIGGER_SET_STATE, +}; +#define ST_PRESS_TRIGGER_OPS (&st_press_trigger_ops) +#else +#define ST_PRESS_TRIGGER_OPS NULL +#endif + +int st_press_common_probe(struct iio_dev *indio_dev) +{ + int err; + struct st_sensor_data *pdata = iio_priv(indio_dev); + + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &press_info; + + err = st_sensors_check_device_support(indio_dev, + ARRAY_SIZE(st_press_sensors), st_press_sensors); + if (err < 0) + goto st_press_common_probe_error; + + pdata->num_data_channels = ST_PRESS_NUMBER_DATA_CHANNELS; + pdata->multiread_bit = pdata->sensor->multi_read_bit; + indio_dev->channels = pdata->sensor->ch; + indio_dev->num_channels = ARRAY_SIZE(st_press_channels); + + pdata->current_fullscale = (struct st_sensor_fullscale_avl *) + &pdata->sensor->fs.fs_avl[0]; + pdata->odr = pdata->sensor->odr.odr_avl[0].hz; + + err = st_sensors_init_sensor(indio_dev); + if (err < 0) + goto st_press_common_probe_error; + + if (pdata->get_irq_data_ready(indio_dev) > 0) { + err = st_press_allocate_ring(indio_dev); + if (err < 0) + goto st_press_common_probe_error; + + err = st_sensors_allocate_trigger(indio_dev, + ST_PRESS_TRIGGER_OPS); + if (err < 0) + goto st_press_probe_trigger_error; + } + + err = iio_device_register(indio_dev); + if (err) + goto st_press_device_register_error; + + return err; + +st_press_device_register_error: + if (pdata->get_irq_data_ready(indio_dev) > 0) + st_sensors_deallocate_trigger(indio_dev); +st_press_probe_trigger_error: + if (pdata->get_irq_data_ready(indio_dev) > 0) + st_press_deallocate_ring(indio_dev); +st_press_common_probe_error: + return err; +} +EXPORT_SYMBOL(st_press_common_probe); + +void st_press_common_remove(struct iio_dev *indio_dev) +{ + struct st_sensor_data *pdata = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + if (pdata->get_irq_data_ready(indio_dev) > 0) { + st_sensors_deallocate_trigger(indio_dev); + st_press_deallocate_ring(indio_dev); + } + iio_device_free(indio_dev); +} +EXPORT_SYMBOL(st_press_common_remove); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics pressures driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c new file mode 100644 index 000000000000..7cebcc73bfb0 --- /dev/null +++ b/drivers/iio/pressure/st_pressure_i2c.c @@ -0,0 +1,77 @@ +/* + * STMicroelectronics pressures driver + * + * Copyright 2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include "st_pressure.h" + +static int st_press_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct iio_dev *indio_dev; + struct st_sensor_data *pdata; + int err; + + indio_dev = iio_device_alloc(sizeof(*pdata)); + if (indio_dev == NULL) { + err = -ENOMEM; + goto iio_device_alloc_error; + } + + pdata = iio_priv(indio_dev); + pdata->dev = &client->dev; + + st_sensors_i2c_configure(indio_dev, client, pdata); + + err = st_press_common_probe(indio_dev); + if (err < 0) + goto st_press_common_probe_error; + + return 0; + +st_press_common_probe_error: + iio_device_free(indio_dev); +iio_device_alloc_error: + return err; +} + +static int st_press_i2c_remove(struct i2c_client *client) +{ + st_press_common_remove(i2c_get_clientdata(client)); + + return 0; +} + +static const struct i2c_device_id st_press_id_table[] = { + { LPS331AP_PRESS_DEV_NAME }, + {}, +}; +MODULE_DEVICE_TABLE(i2c, st_press_id_table); + +static struct i2c_driver st_press_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "st-press-i2c", + }, + .probe = st_press_i2c_probe, + .remove = st_press_i2c_remove, + .id_table = st_press_id_table, +}; +module_i2c_driver(st_press_driver); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/pressure/st_pressure_spi.c b/drivers/iio/pressure/st_pressure_spi.c new file mode 100644 index 000000000000..17a14907940a --- /dev/null +++ b/drivers/iio/pressure/st_pressure_spi.c @@ -0,0 +1,76 @@ +/* + * STMicroelectronics pressures driver + * + * Copyright 2013 STMicroelectronics Inc. + * + * Denis Ciocca + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include "st_pressure.h" + +static int st_press_spi_probe(struct spi_device *spi) +{ + struct iio_dev *indio_dev; + struct st_sensor_data *pdata; + int err; + + indio_dev = iio_device_alloc(sizeof(*pdata)); + if (indio_dev == NULL) { + err = -ENOMEM; + goto iio_device_alloc_error; + } + + pdata = iio_priv(indio_dev); + pdata->dev = &spi->dev; + + st_sensors_spi_configure(indio_dev, spi, pdata); + + err = st_press_common_probe(indio_dev); + if (err < 0) + goto st_press_common_probe_error; + + return 0; + +st_press_common_probe_error: + iio_device_free(indio_dev); +iio_device_alloc_error: + return err; +} + +static int st_press_spi_remove(struct spi_device *spi) +{ + st_press_common_remove(spi_get_drvdata(spi)); + + return 0; +} + +static const struct spi_device_id st_press_id_table[] = { + { LPS331AP_PRESS_DEV_NAME }, + {}, +}; +MODULE_DEVICE_TABLE(spi, st_press_id_table); + +static struct spi_driver st_press_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "st-press-spi", + }, + .probe = st_press_spi_probe, + .remove = st_press_spi_remove, + .id_table = st_press_id_table, +}; +module_spi_driver(st_press_driver); + +MODULE_AUTHOR("Denis Ciocca "); +MODULE_DESCRIPTION("STMicroelectronics pressures spi driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/trigger/Kconfig b/drivers/iio/trigger/Kconfig new file mode 100644 index 000000000000..360fd508b088 --- /dev/null +++ b/drivers/iio/trigger/Kconfig @@ -0,0 +1,26 @@ +# +# Industrial I/O standalone triggers +# +menu "Triggers - standalone" + +config IIO_INTERRUPT_TRIGGER + tristate "Generic interrupt trigger" + help + Provides support for using an interrupt of any type as an IIO + trigger. This may be provided by a gpio driver for example. + + To compile this driver as a module, choose M here: the + module will be called iio-trig-interrupt. + +config IIO_SYSFS_TRIGGER + tristate "SYSFS trigger" + depends on SYSFS + select IRQ_WORK + help + Provides support for using SYSFS entry as IIO triggers. + If unsure, say N (but it's safe to say "Y"). + + To compile this driver as a module, choose M here: the + module will be called iio-trig-sysfs. + +endmenu diff --git a/drivers/iio/trigger/Makefile b/drivers/iio/trigger/Makefile new file mode 100644 index 000000000000..ce319a51b6af --- /dev/null +++ b/drivers/iio/trigger/Makefile @@ -0,0 +1,6 @@ +# +# Makefile for triggers not associated with iio-devices +# + +obj-$(CONFIG_IIO_INTERRUPT_TRIGGER) += iio-trig-interrupt.o +obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o diff --git a/drivers/iio/trigger/iio-trig-interrupt.c b/drivers/iio/trigger/iio-trig-interrupt.c new file mode 100644 index 000000000000..02577ec54c6b --- /dev/null +++ b/drivers/iio/trigger/iio-trig-interrupt.c @@ -0,0 +1,121 @@ +/* + * Industrial I/O - generic interrupt based trigger support + * + * Copyright (c) 2008-2013 Jonathan Cameron + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include +#include +#include +#include +#include + +#include +#include + + +struct iio_interrupt_trigger_info { + unsigned int irq; +}; + +static irqreturn_t iio_interrupt_trigger_poll(int irq, void *private) +{ + /* Timestamp not currently provided */ + iio_trigger_poll(private, 0); + return IRQ_HANDLED; +} + +static const struct iio_trigger_ops iio_interrupt_trigger_ops = { + .owner = THIS_MODULE, +}; + +static int iio_interrupt_trigger_probe(struct platform_device *pdev) +{ + struct iio_interrupt_trigger_info *trig_info; + struct iio_trigger *trig; + unsigned long irqflags; + struct resource *irq_res; + int irq, ret = 0; + + irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + + if (irq_res == NULL) + return -ENODEV; + + irqflags = (irq_res->flags & IRQF_TRIGGER_MASK) | IRQF_SHARED; + + irq = irq_res->start; + + trig = iio_trigger_alloc("irqtrig%d", irq); + if (!trig) { + ret = -ENOMEM; + goto error_ret; + } + + trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL); + if (!trig_info) { + ret = -ENOMEM; + goto error_put_trigger; + } + iio_trigger_set_drvdata(trig, trig_info); + trig_info->irq = irq; + trig->ops = &iio_interrupt_trigger_ops; + ret = request_irq(irq, iio_interrupt_trigger_poll, + irqflags, trig->name, trig); + if (ret) { + dev_err(&pdev->dev, + "request IRQ-%d failed", irq); + goto error_free_trig_info; + } + + ret = iio_trigger_register(trig); + if (ret) + goto error_release_irq; + platform_set_drvdata(pdev, trig); + + return 0; + +/* First clean up the partly allocated trigger */ +error_release_irq: + free_irq(irq, trig); +error_free_trig_info: + kfree(trig_info); +error_put_trigger: + iio_trigger_put(trig); +error_ret: + return ret; +} + +static int iio_interrupt_trigger_remove(struct platform_device *pdev) +{ + struct iio_trigger *trig; + struct iio_interrupt_trigger_info *trig_info; + + trig = platform_get_drvdata(pdev); + trig_info = iio_trigger_get_drvdata(trig); + iio_trigger_unregister(trig); + free_irq(trig_info->irq, trig); + kfree(trig_info); + iio_trigger_put(trig); + + return 0; +} + +static struct platform_driver iio_interrupt_trigger_driver = { + .probe = iio_interrupt_trigger_probe, + .remove = iio_interrupt_trigger_remove, + .driver = { + .name = "iio_interrupt_trigger", + .owner = THIS_MODULE, + }, +}; + +module_platform_driver(iio_interrupt_trigger_driver); + +MODULE_AUTHOR("Jonathan Cameron "); +MODULE_DESCRIPTION("Interrupt trigger for the iio subsystem"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/trigger/iio-trig-sysfs.c b/drivers/iio/trigger/iio-trig-sysfs.c similarity index 98% rename from drivers/staging/iio/trigger/iio-trig-sysfs.c rename to drivers/iio/trigger/iio-trig-sysfs.c index b727bde8b7fe..effcd0ac98d8 100644 --- a/drivers/staging/iio/trigger/iio-trig-sysfs.c +++ b/drivers/iio/trigger/iio-trig-sysfs.c @@ -34,7 +34,7 @@ static ssize_t iio_sysfs_trig_add(struct device *dev, int ret; unsigned long input; - ret = strict_strtoul(buf, 10, &input); + ret = kstrtoul(buf, 10, &input); if (ret) return ret; ret = iio_sysfs_trigger_probe(input); @@ -53,7 +53,7 @@ static ssize_t iio_sysfs_trig_remove(struct device *dev, int ret; unsigned long input; - ret = strict_strtoul(buf, 10, &input); + ret = kstrtoul(buf, 10, &input); if (ret) return ret; ret = iio_sysfs_trigger_remove(input); diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index aefe820a8005..f64b662c74db 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -62,6 +62,8 @@ source "drivers/staging/line6/Kconfig" source "drivers/staging/octeon/Kconfig" +source "drivers/staging/octeon-usb/Kconfig" + source "drivers/staging/serqt_usb2/Kconfig" source "drivers/staging/vt6655/Kconfig" @@ -140,4 +142,8 @@ source "drivers/staging/netlogic/Kconfig" source "drivers/staging/dwc2/Kconfig" +source "drivers/staging/lustre/Kconfig" + +source "drivers/staging/btmtk_usb/Kconfig" + endif # STAGING diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index 415772ea306d..1fb58a1562cb 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_LINE6_USB) += line6/ obj-$(CONFIG_NETLOGIC_XLR_NET) += netlogic/ obj-$(CONFIG_USB_SERIAL_QUATECH2) += serqt_usb2/ obj-$(CONFIG_OCTEON_ETHERNET) += octeon/ +obj-$(CONFIG_OCTEON_USB) += octeon-usb/ obj-$(CONFIG_VT6655) += vt6655/ obj-$(CONFIG_VT6656) += vt6656/ obj-$(CONFIG_VME_BUS) += vme/ @@ -62,3 +63,5 @@ obj-$(CONFIG_FIREWIRE_SERIAL) += fwserial/ obj-$(CONFIG_ZCACHE) += zcache/ obj-$(CONFIG_GOLDFISH) += goldfish/ obj-$(CONFIG_USB_DWC2) += dwc2/ +obj-$(CONFIG_LUSTRE_FS) += lustre/ +obj-$(CONFIG_USB_BTMTK) += btmtk_usb/ diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c index e681bdd9aa5f..21a3f7250531 100644 --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -704,7 +704,8 @@ static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg) /* support of 32bit userspace on 64bit platforms */ #ifdef CONFIG_COMPAT -static long compat_ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +static long compat_ashmem_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) { switch (cmd) { diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c index 1567ac296b39..c6dc1846943f 100644 --- a/drivers/staging/android/binder.c +++ b/drivers/staging/android/binder.c @@ -790,7 +790,7 @@ static void binder_delete_free_buffer(struct binder_proc *proc, list_del(&buffer->entry); if (free_page_start || free_page_end) { binder_debug(BINDER_DEBUG_BUFFER_ALLOC, - "%d: merge free, buffer %p do not share page%s%s with with %p or %p\n", + "%d: merge free, buffer %p do not share page%s%s with %p or %p\n", proc->pid, buffer, free_page_start ? "" : " end", free_page_end ? "" : " start", prev, next); binder_update_page_range(proc, 0, free_page_start ? diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c index 4928f93bdf3d..765c757b120f 100644 --- a/drivers/staging/android/sw_sync.c +++ b/drivers/staging/android/sw_sync.c @@ -160,7 +160,8 @@ static int sw_sync_release(struct inode *inode, struct file *file) return 0; } -static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj, unsigned long arg) +static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj, + unsigned long arg) { int fd = get_unused_fd(); int err; @@ -218,7 +219,8 @@ static long sw_sync_ioctl_inc(struct sw_sync_timeline *obj, unsigned long arg) return 0; } -static long sw_sync_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +static long sw_sync_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) { struct sw_sync_timeline *obj = file->private_data; diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 3893a3574769..2996077fedef 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -125,9 +125,9 @@ static void sync_timeline_remove_pt(struct sync_pt *pt) spin_unlock_irqrestore(&obj->active_list_lock, flags); spin_lock_irqsave(&obj->child_list_lock, flags); - if (!list_empty(&pt->child_list)) { + if (!list_empty(&pt->child_list)) list_del_init(&pt->child_list); - } + spin_unlock_irqrestore(&obj->child_list_lock, flags); } @@ -876,11 +876,11 @@ static void sync_print_pt(struct seq_file *s, struct sync_pt *pt, bool fence) seq_printf(s, " / %s", value); } } else if (pt->parent->ops->print_pt) { - seq_printf(s, ": "); + seq_puts(s, ": "); pt->parent->ops->print_pt(s, pt); } - seq_printf(s, "\n"); + seq_puts(s, "\n"); } static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj) @@ -895,11 +895,11 @@ static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj) obj->ops->timeline_value_str(obj, value, sizeof(value)); seq_printf(s, ": %s", value); } else if (obj->ops->print_obj) { - seq_printf(s, ": "); + seq_puts(s, ": "); obj->ops->print_obj(s, obj); } - seq_printf(s, "\n"); + seq_puts(s, "\n"); spin_lock_irqsave(&obj->child_list_lock, flags); list_for_each(pos, &obj->child_list_head) { @@ -940,7 +940,7 @@ static int sync_debugfs_show(struct seq_file *s, void *unused) unsigned long flags; struct list_head *pos; - seq_printf(s, "objs:\n--------------\n"); + seq_puts(s, "objs:\n--------------\n"); spin_lock_irqsave(&sync_timeline_list_lock, flags); list_for_each(pos, &sync_timeline_list_head) { @@ -949,11 +949,11 @@ static int sync_debugfs_show(struct seq_file *s, void *unused) sync_timeline_list); sync_print_obj(s, obj); - seq_printf(s, "\n"); + seq_puts(s, "\n"); } spin_unlock_irqrestore(&sync_timeline_list_lock, flags); - seq_printf(s, "fences:\n--------------\n"); + seq_puts(s, "fences:\n--------------\n"); spin_lock_irqsave(&sync_fence_list_lock, flags); list_for_each(pos, &sync_fence_list_head) { @@ -961,7 +961,7 @@ static int sync_debugfs_show(struct seq_file *s, void *unused) container_of(pos, struct sync_fence, sync_fence_list); sync_print_fence(s, fence); - seq_printf(s, "\n"); + seq_puts(s, "\n"); } spin_unlock_irqrestore(&sync_fence_list_lock, flags); return 0; @@ -988,7 +988,7 @@ late_initcall(sync_debugfs_init); #define DUMP_CHUNK 256 static char sync_dump_buf[64 * 1024]; -void sync_dump(void) +static void sync_dump(void) { struct seq_file s = { .buf = sync_dump_buf, diff --git a/drivers/staging/asus_oled/asus_oled.c b/drivers/staging/asus_oled/asus_oled.c index d0a5a28a8fe2..3654dc32a0c6 100644 --- a/drivers/staging/asus_oled/asus_oled.c +++ b/drivers/staging/asus_oled/asus_oled.c @@ -50,9 +50,9 @@ #define ASUS_OLED_DISP_HEIGHT 32 #define ASUS_OLED_PACKET_BUF_SIZE 256 -#define USB_VENDOR_ID_ASUS 0x0b05 -#define USB_DEVICE_ID_ASUS_LCM 0x1726 -#define USB_DEVICE_ID_ASUS_LCM2 0x175b +#define USB_VENDOR_ID_ASUS 0x0b05 +#define USB_DEVICE_ID_ASUS_LCM 0x1726 +#define USB_DEVICE_ID_ASUS_LCM2 0x175b MODULE_AUTHOR("Jakub Schmidtke, sjakub@gmail.com"); MODULE_DESCRIPTION("Asus OLED Driver"); @@ -324,9 +324,11 @@ static void send_data(struct asus_oled_dev *odev) return; if (odev->pack_mode == PACK_MODE_G1) { - /* When sending roll-mode data the display updated only - first packet. I have no idea why, but when static picture - is sent just before rolling picture everything works fine. */ + /* + * When sending roll-mode data the display updated only + * first packet. I have no idea why, but when static picture + * is sent just before rolling picture everything works fine. + */ if (odev->pic_mode == ASUS_OLED_ROLL) send_packets(odev->udev, packet, odev->buf, ASUS_OLED_STATIC, 2); @@ -363,9 +365,11 @@ static int append_values(struct asus_oled_dev *odev, uint8_t val, size_t count) switch (odev->pack_mode) { case PACK_MODE_G1: - /* i = (x/128)*640 + 127 - x + (y/8)*128; - This one for 128 is the same, but might be better - for different widths? */ + /* + * i = (x/128)*640 + 127 - x + (y/8)*128; + * This one for 128 is the same, but might be better + * for different widths? + */ i = (x/odev->dev_width)*640 + odev->dev_width - 1 - x + (y/8)*odev->dev_width; @@ -383,10 +387,8 @@ static int append_values(struct asus_oled_dev *odev, uint8_t val, size_t count) } if (i >= odev->buf_size) { - dev_err(odev->dev, "Buffer overflow! Report a bug:" - "offs: %d >= %d i: %d (x: %d y: %d)\n", - (int) odev->buf_offs, (int) odev->buf_size, - (int) i, (int) x, (int) y); + dev_err(odev->dev, "Buffer overflow! Report a bug: offs: %zu >= %zu i: %zu (x: %zu y: %zu)\n", + odev->buf_offs, odev->buf_size, i, x, y); return -EIO; } @@ -401,7 +403,7 @@ static int append_values(struct asus_oled_dev *odev, uint8_t val, size_t count) default: /* cannot get here; stops gcc complaining*/ - ; + break; } odev->buf_offs++; @@ -566,9 +568,11 @@ static ssize_t odev_set_picture(struct asus_oled_dev *odev, if (ret < 0) return ret; } else if (buf[offs] == '\n') { - /* New line detected. Lets assume, that all characters - till the end of the line were equal to the last - character in this line.*/ + /* + * New line detected. Lets assume, that all characters + * till the end of the line were equal to the last + * character in this line. + */ if (odev->buf_offs % odev->width != 0) ret = append_values(odev, odev->last_val, odev->width - diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c index 35641e529396..f67a22536cbf 100644 --- a/drivers/staging/bcm/Bcmchar.c +++ b/drivers/staging/bcm/Bcmchar.c @@ -13,7 +13,7 @@ * Returns - Zero(Success) ****************************************************************/ -static int bcm_char_open(struct inode *inode, struct file * filp) +static int bcm_char_open(struct inode *inode, struct file *filp) { struct bcm_mini_adapter *Adapter = NULL; struct bcm_tarang_data *pTarang = NULL; diff --git a/drivers/staging/bcm/InterfaceIdleMode.c b/drivers/staging/bcm/InterfaceIdleMode.c index a1bf21579d3f..534782866042 100644 --- a/drivers/staging/bcm/InterfaceIdleMode.c +++ b/drivers/staging/bcm/InterfaceIdleMode.c @@ -42,107 +42,95 @@ send to f/w with in 200 ms after the Idle/Shutdown req issued */ -int InterfaceIdleModeRespond(struct bcm_mini_adapter *Adapter, unsigned int* puiBuffer) +int InterfaceIdleModeRespond(struct bcm_mini_adapter *Adapter, unsigned int *puiBuffer) { int status = STATUS_SUCCESS; unsigned int uiRegRead = 0; int bytes; - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL,"SubType of Message :0x%X", ntohl(*puiBuffer)); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "SubType of Message :0x%X", ntohl(*puiBuffer)); - if(ntohl(*puiBuffer) == GO_TO_IDLE_MODE_PAYLOAD) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL," Got GO_TO_IDLE_MODE_PAYLOAD(210) Msg Subtype"); - if(ntohl(*(puiBuffer+1)) == 0 ) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL,"Got IDLE MODE WAKE UP Response From F/W"); + if (ntohl(*puiBuffer) == GO_TO_IDLE_MODE_PAYLOAD) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, " Got GO_TO_IDLE_MODE_PAYLOAD(210) Msg Subtype"); + if (ntohl(*(puiBuffer+1)) == 0 ) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Got IDLE MODE WAKE UP Response From F/W"); - status = wrmalt (Adapter,SW_ABORT_IDLEMODE_LOC, &uiRegRead, sizeof(uiRegRead)); - if(status) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "wrm failed while clearing Idle Mode Reg"); + status = wrmalt (Adapter, SW_ABORT_IDLEMODE_LOC, &uiRegRead, sizeof(uiRegRead)); + if (status) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "wrm failed while clearing Idle Mode Reg"); return status; } - if(Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) - { + if (Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) { uiRegRead = 0x00000000 ; - status = wrmalt (Adapter,DEBUG_INTERRUPT_GENERATOR_REGISTOR, &uiRegRead, sizeof(uiRegRead)); - if(status) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "wrm failed while clearing Idle Mode Reg"); + status = wrmalt (Adapter, DEBUG_INTERRUPT_GENERATOR_REGISTOR, &uiRegRead, sizeof(uiRegRead)); + if (status) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "wrm failed while clearing Idle Mode Reg"); return status; } } - //Below Register should not br read in case of Manual and Protocol Idle mode. - else if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) - { - //clear on read Register + /* Below Register should not br read in case of Manual and Protocol Idle mode */ + else if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) { + /* clear on read Register */ bytes = rdmalt(Adapter, DEVICE_INT_OUT_EP_REG0, &uiRegRead, sizeof(uiRegRead)); if (bytes < 0) { status = bytes; - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm failed while clearing H/W Abort Reg0"); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed while clearing H/W Abort Reg0"); return status; } - //clear on read Register + /* clear on read Register */ bytes = rdmalt(Adapter, DEVICE_INT_OUT_EP_REG1, &uiRegRead, sizeof(uiRegRead)); if (bytes < 0) { status = bytes; - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm failed while clearing H/W Abort Reg1"); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed while clearing H/W Abort Reg1"); return status; } } - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Device Up from Idle Mode"); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Device Up from Idle Mode"); - // Set Idle Mode Flag to False and Clear IdleMode reg. + /* Set Idle Mode Flag to False and Clear IdleMode reg. */ Adapter->IdleMode = FALSE; Adapter->bTriedToWakeUpFromlowPowerMode = FALSE; wake_up(&Adapter->lowpower_mode_wait_queue); - } - else - { - if(TRUE == Adapter->IdleMode) + } else { + if (TRUE == Adapter->IdleMode) { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL,"Device is already in Idle mode...."); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Device is already in Idle mode...."); return status ; } uiRegRead = 0; - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Got Req from F/W to go in IDLE mode \n"); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Got Req from F/W to go in IDLE mode \n"); - if (Adapter->chip_id== BCS220_2 || + if (Adapter->chip_id == BCS220_2 || Adapter->chip_id == BCS220_2BC || - Adapter->chip_id== BCS250_BC || - Adapter->chip_id== BCS220_3) - { + Adapter->chip_id == BCS250_BC || + Adapter->chip_id == BCS220_3) { bytes = rdmalt(Adapter, HPM_CONFIG_MSW, &uiRegRead, sizeof(uiRegRead)); if (bytes < 0) { status = bytes; - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "rdm failed while Reading HPM_CONFIG_LDO145 Reg 0\n"); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "rdm failed while Reading HPM_CONFIG_LDO145 Reg 0\n"); return status; } uiRegRead |= (1<<17); - status = wrmalt (Adapter,HPM_CONFIG_MSW, &uiRegRead, sizeof(uiRegRead)); - if(status) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "wrm failed while clearing Idle Mode Reg\n"); + status = wrmalt (Adapter, HPM_CONFIG_MSW, &uiRegRead, sizeof(uiRegRead)); + if (status) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "wrm failed while clearing Idle Mode Reg\n"); return status; } } SendIdleModeResponse(Adapter); } - } - else if(ntohl(*puiBuffer) == IDLE_MODE_SF_UPDATE_MSG) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "OverRiding Service Flow Params"); - OverrideServiceFlowParams(Adapter,puiBuffer); + } else if (ntohl(*puiBuffer) == IDLE_MODE_SF_UPDATE_MSG) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "OverRiding Service Flow Params"); + OverrideServiceFlowParams(Adapter, puiBuffer); } return status; } @@ -152,46 +140,40 @@ static int InterfaceAbortIdlemode(struct bcm_mini_adapter *Adapter, unsigned int int status = STATUS_SUCCESS; unsigned int value; unsigned int chip_id ; - unsigned long timeout = 0 ,itr = 0; + unsigned long timeout = 0, itr = 0; int lenwritten = 0; - unsigned char aucAbortPattern[8]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; + unsigned char aucAbortPattern[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; struct bcm_interface_adapter *psInterfaceAdapter = Adapter->pvInterfaceAdapter; - //Abort Bus suspend if its already suspended - if((TRUE == psInterfaceAdapter->bSuspended) && (TRUE == Adapter->bDoSuspend)) - { + /* Abort Bus suspend if its already suspended */ + if ((TRUE == psInterfaceAdapter->bSuspended) && (TRUE == Adapter->bDoSuspend)) { status = usb_autopm_get_interface(psInterfaceAdapter->interface); - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL,"Bus got wakeup..Aborting Idle mode... status:%d \n",status); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Bus got wakeup..Aborting Idle mode... status:%d \n", status); } - if((Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) + if ((Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) || - (Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) - { - //write the SW abort pattern. - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Writing pattern<%d> to SW_ABORT_IDLEMODE_LOC\n", Pattern); - status = wrmalt(Adapter,SW_ABORT_IDLEMODE_LOC, &Pattern, sizeof(Pattern)); - if(status) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL,"WRM to Register SW_ABORT_IDLEMODE_LOC failed.."); + (Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) { + /* write the SW abort pattern. */ + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Writing pattern<%d> to SW_ABORT_IDLEMODE_LOC\n", Pattern); + status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, &Pattern, sizeof(Pattern)); + if (status) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "WRM to Register SW_ABORT_IDLEMODE_LOC failed.."); return status; } } - if(Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) - { + if (Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) { value = 0x80000000; - status = wrmalt(Adapter,DEBUG_INTERRUPT_GENERATOR_REGISTOR, &value, sizeof(value)); - if(status) + status = wrmalt(Adapter, DEBUG_INTERRUPT_GENERATOR_REGISTOR, &value, sizeof(value)); + if (status) { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL,"WRM to DEBUG_INTERRUPT_GENERATOR_REGISTOR Register failed"); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "WRM to DEBUG_INTERRUPT_GENERATOR_REGISTOR Register failed"); return status; } - } - else if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) - { + } else if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) { /* * Get a Interrupt Out URB and send 8 Bytes Down * To be Done in Thread Context. @@ -204,43 +186,32 @@ static int InterfaceAbortIdlemode(struct bcm_mini_adapter *Adapter, unsigned int 8, &lenwritten, 5000); - if(status) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Sending Abort pattern down fails with status:%d..\n",status); + if (status) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Sending Abort pattern down fails with status:%d..\n", status); return status; - } - else - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "NOB Sent down :%d", lenwritten); + } else { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "NOB Sent down :%d", lenwritten); } - //mdelay(25); + /* mdelay(25); */ - timeout= jiffies + msecs_to_jiffies(50) ; - while( timeout > jiffies ) - { + timeout = jiffies + msecs_to_jiffies(50) ; + while ( timeout > jiffies ) { itr++ ; rdmalt(Adapter, CHIP_ID_REG, &chip_id, sizeof(UINT)); - if(0xbece3200==(chip_id&~(0xF0))) - { + if (0xbece3200 == (chip_id&~(0xF0))) chip_id = chip_id&~(0xF0); - } - if(chip_id == Adapter->chip_id) + if (chip_id == Adapter->chip_id) break; } - if(timeout < jiffies ) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL,"Not able to read chip-id even after 25 msec"); - } + if (timeout < jiffies ) + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Not able to read chip-id even after 25 msec"); else - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL,"Number of completed iteration to read chip-id :%lu", itr); - } + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Number of completed iteration to read chip-id :%lu", itr); - status = wrmalt(Adapter,SW_ABORT_IDLEMODE_LOC, &Pattern, sizeof(status)); - if(status) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to Register SW_ABORT_IDLEMODE_LOC failed.."); + status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, &Pattern, sizeof(status)); + if (status) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM to Register SW_ABORT_IDLEMODE_LOC failed.."); return status; } } @@ -249,13 +220,10 @@ static int InterfaceAbortIdlemode(struct bcm_mini_adapter *Adapter, unsigned int int InterfaceIdleModeWakeup(struct bcm_mini_adapter *Adapter) { ULONG Status = 0; - if(Adapter->bTriedToWakeUpFromlowPowerMode) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Wake up already attempted.. ignoring\n"); - } - else - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL,"Writing Low Power Mode Abort pattern to the Device\n"); + if (Adapter->bTriedToWakeUpFromlowPowerMode) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Wake up already attempted.. ignoring\n"); + } else { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL, "Writing Low Power Mode Abort pattern to the Device\n"); Adapter->bTriedToWakeUpFromlowPowerMode = TRUE; InterfaceAbortIdlemode(Adapter, Adapter->usIdleModePattern); @@ -269,33 +237,30 @@ void InterfaceHandleShutdownModeWakeup(struct bcm_mini_adapter *Adapter) INT Status = 0; int bytes; - if(Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) - { - // clear idlemode interrupt. + if (Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) { + /* clear idlemode interrupt. */ uiRegVal = 0; - Status =wrmalt(Adapter,DEBUG_INTERRUPT_GENERATOR_REGISTOR, &uiRegVal, sizeof(uiRegVal)); - if(Status) - { - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to DEBUG_INTERRUPT_GENERATOR_REGISTOR Failed with err :%d", Status); + Status = wrmalt(Adapter, DEBUG_INTERRUPT_GENERATOR_REGISTOR, &uiRegVal, sizeof(uiRegVal)); + if (Status) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,"WRM to DEBUG_INTERRUPT_GENERATOR_REGISTOR Failed with err :%d", Status); return; } } - else - { + else { - //clear Interrupt EP registers. - bytes = rdmalt(Adapter,DEVICE_INT_OUT_EP_REG0, &uiRegVal, sizeof(uiRegVal)); + /* clear Interrupt EP registers. */ + bytes = rdmalt(Adapter, DEVICE_INT_OUT_EP_REG0, &uiRegVal, sizeof(uiRegVal)); if (bytes < 0) { Status = bytes; - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"RDM of DEVICE_INT_OUT_EP_REG0 failed with Err :%d", Status); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM of DEVICE_INT_OUT_EP_REG0 failed with Err :%d", Status); return; } - bytes = rdmalt(Adapter,DEVICE_INT_OUT_EP_REG1, &uiRegVal, sizeof(uiRegVal)); + bytes = rdmalt(Adapter, DEVICE_INT_OUT_EP_REG1, &uiRegVal, sizeof(uiRegVal)); if (bytes < 0) { Status = bytes; - BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"RDM of DEVICE_INT_OUT_EP_REG1 failed with Err :%d", Status); + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM of DEVICE_INT_OUT_EP_REG1 failed with Err :%d", Status); return; } } diff --git a/drivers/staging/bcm/Version.h b/drivers/staging/bcm/Version.h index a07b956b9ff5..f1cb9de734a6 100644 --- a/drivers/staging/bcm/Version.h +++ b/drivers/staging/bcm/Version.h @@ -1,4 +1,3 @@ - /*Copyright (c) 2005 Beceem Communications Inc. Module Name: @@ -17,7 +16,6 @@ Abstract: #define VER_FILETYPE VFT_DRV #define VER_FILESUBTYPE VFT2_DRV_NETWORK - #define VER_FILEVERSION 5.2.45 #define VER_FILEVERSION_STR "5.2.45" @@ -28,8 +26,4 @@ Abstract: #define VER_PRODUCTVERSION_STR VER_FILEVERSION_STR - - -//#include "common.ver" - -#endif //VERSION_H +#endif /* VERSION_H */ diff --git a/drivers/staging/bcm/vendorspecificextn.c b/drivers/staging/bcm/vendorspecificextn.c index be1f91d955aa..d38a06f762df 100644 --- a/drivers/staging/bcm/vendorspecificextn.c +++ b/drivers/staging/bcm/vendorspecificextn.c @@ -1,70 +1,70 @@ #include "headers.h" -//----------------------------------------------------------------------------- -// Procedure: vendorextnGetSectionInfo -// -// Description: Finds the type of NVM used. -// -// Arguments: -// Adapter - ptr to Adapter object instance -// pNVMType - ptr to NVM type. -// Returns: -// STATUS_SUCCESS/STATUS_FAILURE -// -//----------------------------------------------------------------------------- +/* + * Procedure: vendorextnGetSectionInfo + * + * Description: Finds the type of NVM used. + * + * Arguments: + * Adapter - ptr to Adapter object instance + * pNVMType - ptr to NVM type. + * Returns: + * STATUS_SUCCESS/STATUS_FAILURE + * + */ INT vendorextnGetSectionInfo(PVOID pContext, struct bcm_flash2x_vendor_info *pVendorInfo) { return STATUS_FAILURE; } -//----------------------------------------------------------------------------- -// Procedure: vendorextnInit -// -// Description: Initializing the vendor extension NVM interface -// -// Arguments: -// Adapter - Pointer to MINI Adapter Structure. - -// Returns: -// STATUS_SUCCESS/STATUS_FAILURE -// -//----------------------------------------------------------------------------- +/* + * Procedure: vendorextnInit + * + * Description: Initializing the vendor extension NVM interface + * + * Arguments: + * Adapter - Pointer to MINI Adapter Structure + * Returns: + * STATUS_SUCCESS/STATUS_FAILURE + * + * + */ INT vendorextnInit(struct bcm_mini_adapter *Adapter) { return STATUS_SUCCESS; } -//----------------------------------------------------------------------------- -// Procedure: vendorextnExit -// -// Description: Free the resource associated with vendor extension NVM interface -// -// Arguments: -// Adapter - Pointer to MINI Adapter Structure. - -// Returns: -// STATUS_SUCCESS/STATUS_FAILURE -// -//----------------------------------------------------------------------------- +/* + * Procedure: vendorextnExit + * + * Description: Free the resource associated with vendor extension NVM interface + * + * Arguments: + * + * Returns: + * STATUS_SUCCESS/STATUS_FAILURE + * + * + */ INT vendorextnExit(struct bcm_mini_adapter *Adapter) { return STATUS_SUCCESS; } -//------------------------------------------------------------------------ -// Procedure: vendorextnIoctl -// -// Description: execute the vendor extension specific ioctl -// -//Arguments: -// Adapter -Beceem private Adapter Structure -// cmd -vendor extension specific Ioctl commad -// arg -input parameter sent by vendor -// -// Returns: -// CONTINUE_COMMON_PATH in case it is not meant to be processed by vendor ioctls -// STATUS_SUCCESS/STATUS_FAILURE as per the IOCTL return value -// -//-------------------------------------------------------------------------- +/* + * Procedure: vendorextnIoctl + * + * Description: execute the vendor extension specific ioctl + * + * Arguments: + * Adapter -Beceem private Adapter Structure + * cmd -vendor extension specific Ioctl commad + * arg -input parameter sent by vendor + * + * Returns: + * CONTINUE_COMMON_PATH in case it is not meant to be processed by vendor ioctls + * STATUS_SUCCESS/STATUS_FAILURE as per the IOCTL return value + */ + INT vendorextnIoctl(struct bcm_mini_adapter *Adapter, UINT cmd, ULONG arg) { return CONTINUE_COMMON_PATH; @@ -72,22 +72,21 @@ INT vendorextnIoctl(struct bcm_mini_adapter *Adapter, UINT cmd, ULONG arg) -//------------------------------------------------------------------ -// Procedure: vendorextnReadSection -// -// Description: Reads from a section of NVM -// -// Arguments: -// pContext - ptr to Adapter object instance -// pBuffer - Read the data from Vendor Area to this buffer -// SectionVal - Value of type of Section -// Offset - Read from the Offset of the Vendor Section. -// numOfBytes - Read numOfBytes from the Vendor section to Buffer -// -// Returns: -// STATUS_SUCCESS/STATUS_FAILURE -// -//------------------------------------------------------------------ +/* + * Procedure: vendorextnReadSection + * + * Description: Reads from a section of NVM + * + * Arguments: + * pContext - ptr to Adapter object instance + * pBuffer - Read the data from Vendor Area to this buffer + * SectionVal - Value of type of Section + * Offset - Read from the Offset of the Vendor Section. + * numOfBytes - Read numOfBytes from the Vendor section to Buffer + * + * Returns: + * STATUS_SUCCESS/STATUS_FAILURE + */ INT vendorextnReadSection(PVOID pContext, PUCHAR pBuffer, enum bcm_flash2x_section_val SectionVal, UINT offset, UINT numOfBytes) @@ -97,23 +96,22 @@ INT vendorextnReadSection(PVOID pContext, PUCHAR pBuffer, enum bcm_flash2x_sect -//------------------------------------------------------------------ -// Procedure: vendorextnWriteSection -// -// Description: Write to a Section of NVM -// -// Arguments: -// pContext - ptr to Adapter object instance -// pBuffer - Write the data provided in the buffer -// SectionVal - Value of type of Section -// Offset - Writes to the Offset of the Vendor Section. -// numOfBytes - Write num Bytes after reading from pBuffer. -// bVerify - the Buffer Written should be verified. -// -// Returns: -// STATUS_SUCCESS/STATUS_FAILURE -// -//------------------------------------------------------------------ +/* + * Procedure: vendorextnWriteSection + * + * Description: Write to a Section of NVM + * + * Arguments: + * pContext - ptr to Adapter object instance + * pBuffer - Write the data provided in the buffer + * SectionVal - Value of type of Section + * Offset - Writes to the Offset of the Vendor Section. + * numOfBytes - Write num Bytes after reading from pBuffer. + * bVerify - the Buffer Written should be verified. + * + * Returns: + * STATUS_SUCCESS/STATUS_FAILURE + */ INT vendorextnWriteSection(PVOID pContext, PUCHAR pBuffer, enum bcm_flash2x_section_val SectionVal, UINT offset, UINT numOfBytes, BOOLEAN bVerify) { @@ -122,25 +120,23 @@ INT vendorextnWriteSection(PVOID pContext, PUCHAR pBuffer, enum bcm_flash2x_sec -//------------------------------------------------------------------ -// Procedure: vendorextnWriteSectionWithoutErase -// -// Description: Write to a Section of NVM without erasing the sector -// -// Arguments: -// pContext - ptr to Adapter object instance -// pBuffer - Write the data provided in the buffer -// SectionVal - Value of type of Section -// Offset - Writes to the Offset of the Vendor Section. -// numOfBytes - Write num Bytes after reading from pBuffer. -// -// Returns: -// STATUS_SUCCESS/STATUS_FAILURE -// -//------------------------------------------------------------------ +/* + * Procedure: vendorextnWriteSectionWithoutErase + * + * Description: Write to a Section of NVM without erasing the sector + * + * Arguments: + * pContext - ptr to Adapter object instance + * pBuffer - Write the data provided in the buffer + * SectionVal - Value of type of Section + * Offset - Writes to the Offset of the Vendor Section. + * numOfBytes - Write num Bytes after reading from pBuffer. + * + * Returns: + * STATUS_SUCCESS/STATUS_FAILURE + */ INT vendorextnWriteSectionWithoutErase(PVOID pContext, PUCHAR pBuffer, enum bcm_flash2x_section_val SectionVal, UINT offset, UINT numOfBytes) { return STATUS_FAILURE; } - diff --git a/drivers/staging/btmtk_usb/Kconfig b/drivers/staging/btmtk_usb/Kconfig new file mode 100644 index 000000000000..a425ebda6c7a --- /dev/null +++ b/drivers/staging/btmtk_usb/Kconfig @@ -0,0 +1,11 @@ +config USB_BTMTK + tristate "Mediatek Bluetooth support" + depends on USB && BT && m + ---help--- + Say Y here if you wish to control a MTK USB Bluetooth. + + This option depends on 'USB' support being enabled + + To compile this driver as a module, choose M here: the + module will be called btmtk_usb. + diff --git a/drivers/staging/btmtk_usb/Makefile b/drivers/staging/btmtk_usb/Makefile new file mode 100644 index 000000000000..4d6c9d764621 --- /dev/null +++ b/drivers/staging/btmtk_usb/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_USB_BTMTK) += btmtk_usb.o diff --git a/drivers/staging/btmtk_usb/README b/drivers/staging/btmtk_usb/README new file mode 100644 index 000000000000..c046c8e96b2d --- /dev/null +++ b/drivers/staging/btmtk_usb/README @@ -0,0 +1,14 @@ +-build driver modules + make + +-install driver modules + make install + +-remove driver modules + make clean + +-dynamic debug message + turn on CONFIG_DYNAMIC_DEBUG compiler flag for current kernel + mount -t debugfs none /sys/kernel/debug/ + echo "module module_name +p" > /sys/kernel/debug/dynamic_debug/control(turn on debug messages, module name such as btmtk_usb) + echo "module module_name -p" > /sys/kernel/debug/dynamic_debug/control(turn off debug messages, module name such as btmtk_usb) diff --git a/drivers/staging/btmtk_usb/TODO b/drivers/staging/btmtk_usb/TODO new file mode 100644 index 000000000000..a71d1297942d --- /dev/null +++ b/drivers/staging/btmtk_usb/TODO @@ -0,0 +1,10 @@ +TODO: + - checkpatch.pl clean + - determine if the driver should not be using a duplicate + version of the usb-bluetooth interface code, but should + be merged into the drivers/bluetooth/ directory and + infrastructure instead. + - review by the bluetooth developer community + +Please send any patches for this driver to Yu-Chen, Cho and +jay.hung@mediatek.com diff --git a/drivers/staging/btmtk_usb/btmtk_usb.c b/drivers/staging/btmtk_usb/btmtk_usb.c new file mode 100644 index 000000000000..0e783e8d71ca --- /dev/null +++ b/drivers/staging/btmtk_usb/btmtk_usb.c @@ -0,0 +1,1784 @@ +/* + * MediaTek Bluetooth USB Driver + * + * Copyright (C) 2013, MediaTek co. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * or on the worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "btmtk_usb.h" + +#define VERSION "1.0.4" +#define MT7650_FIRMWARE "mt7650.bin" +#define MT7662_FIRMWARE "mt7662.bin" + +static struct usb_driver btmtk_usb_driver; + + +static int btmtk_usb_load_rom_patch(struct btmtk_usb_data *); +static int btmtk_usb_load_fw(struct btmtk_usb_data *); + +static void hex_dump(char *str, u8 *src_buf, u32 src_buf_len) +{ + unsigned char *pt; + int x; + + pt = src_buf; + + BT_DBG("%s: %p, len = %d\n", str, src_buf, src_buf_len); + + for (x = 0; x < src_buf_len; x++) { + if (x % 16 == 0) + BT_DBG("0x%04x : ", x); + BT_DBG("%02x ", ((unsigned char)pt[x])); + if (x % 16 == 15) + BT_DBG("\n"); + } + + BT_DBG("\n"); +} + +static int btmtk_usb_reset(struct usb_device *udev) +{ + int ret; + + BT_DBG("%s\n", __func__); + + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x01, DEVICE_VENDOR_REQUEST_OUT, + 0x01, 0x00, NULL, 0x00, CONTROL_TIMEOUT_JIFFIES); + + if (ret < 0) { + BT_ERR("%s error(%d)\n", __func__, ret); + return ret; + } + + if (ret > 0) + ret = 0; + + return ret; +} + +static int btmtk_usb_io_read32(struct btmtk_usb_data *data, u32 reg, u32 *val) +{ + u8 request = data->r_request; + struct usb_device *udev = data->udev; + int ret; + + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), request, DEVICE_VENDOR_REQUEST_IN, + 0x0, reg, data->io_buf, 4, + CONTROL_TIMEOUT_JIFFIES); + + if (ret < 0) { + *val = 0xffffffff; + BT_ERR("%s error(%d), reg=%x, value=%x\n", __func__, ret, reg, *val); + return ret; + } + + memmove(val, data->io_buf, 4); + + *val = le32_to_cpu(*val); + + if (ret > 0) + ret = 0; + + return ret; +} + +static int btmtk_usb_io_write32(struct btmtk_usb_data *data, u32 reg, u32 val) +{ + u16 value, index; + u8 request = data->w_request; + struct usb_device *udev = data->udev; + int ret; + + index = (u16)reg; + value = val & 0x0000ffff; + + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), request, DEVICE_VENDOR_REQUEST_OUT, + value, index, NULL, 0, + CONTROL_TIMEOUT_JIFFIES); + + if (ret < 0) { + BT_ERR("%s error(%d), reg=%x, value=%x\n", __func__, ret, reg, val); + return ret; + } + + index = (u16)(reg + 2); + value = (val & 0xffff0000) >> 16; + + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + request, DEVICE_VENDOR_REQUEST_OUT, + value, index, NULL, 0, CONTROL_TIMEOUT_JIFFIES); + + if (ret < 0) { + BT_ERR("%s error(%d), reg=%x, value=%x\n", __func__, ret, reg, val); + return ret; + } + + if (ret > 0) + ret = 0; + + return ret; +} + +static int btmtk_usb_switch_iobase(struct btmtk_usb_data *data, int base) +{ + int ret = 0; + + switch (base) { + case SYSCTL: + data->w_request = 0x42; + data->r_request = 0x47; + break; + case WLAN: + data->w_request = 0x02; + data->r_request = 0x07; + break; + + default: + return -EINVAL; + } + + return ret; +} + +static void btmtk_usb_cap_init(struct btmtk_usb_data *data) +{ + const struct firmware *firmware; + struct usb_device *udev = data->udev; + int ret; + + btmtk_usb_io_read32(data, 0x00, &data->chip_id); + + BT_DBG("chip id = %x\n", data->chip_id); + + if (is_mt7630(data) || is_mt7650(data)) { + data->need_load_fw = 1; + data->need_load_rom_patch = 0; + ret = request_firmware(&firmware, MT7650_FIRMWARE, &udev->dev); + if (ret < 0) { + if (ret == -ENOENT) { + BT_ERR("Firmware file \"%s\" not found \n", MT7650_FIRMWARE); + } else { + BT_ERR("Firmware file \"%s\" request failed (err=%d) \n", + MT7650_FIRMWARE, ret); + } + } else { + BT_DBG("Firmware file \"%s\" Found \n", MT7650_FIRMWARE); + /* load firmware here */ + data->firmware = firmware; + btmtk_usb_load_fw(data); + } + release_firmware(firmware); + } else if (is_mt7632(data) || is_mt7662(data)) { + data->need_load_fw = 0; + data->need_load_rom_patch = 1; + data->rom_patch_offset = 0x90000; + ret = request_firmware(&firmware, MT7662_FIRMWARE, &udev->dev); + if (ret < 0) { + if (ret == -ENOENT) { + BT_ERR("Firmware file \"%s\" not found\n", MT7662_FIRMWARE); + } else { + BT_ERR("Firmware file \"%s\" request failed (err=%d)\n", + MT7662_FIRMWARE, ret); + } + } else { + BT_DBG("Firmware file \"%s\" Found\n", MT7662_FIRMWARE); + /* load rom patch here */ + data->firmware = firmware; + data->rom_patch_len = firmware->size; + btmtk_usb_load_rom_patch(data); + } + release_firmware(firmware); + } else { + BT_ERR("unknow chip(%x)\n", data->chip_id); + } +} + +static u16 checksume16(u8 *pData, int len) +{ + int sum = 0; + + while (len > 1) { + sum += *((u16 *)pData); + + pData = pData + 2; + + if (sum & 0x80000000) + sum = (sum & 0xFFFF) + (sum >> 16); + + len -= 2; + } + + if (len) + sum += *((u8 *)pData); + + while (sum >> 16) { + sum = (sum & 0xFFFF) + (sum >> 16); + } + + return ~sum; +} + +static int btmtk_usb_chk_crc(struct btmtk_usb_data *data, u32 checksum_len) +{ + int ret = 0; + struct usb_device *udev = data->udev; + + BT_DBG("%s\n", __func__); + + memmove(data->io_buf, &data->rom_patch_offset, 4); + memmove(&data->io_buf[4], &checksum_len, 4); + + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x1, DEVICE_VENDOR_REQUEST_IN, + 0x20, 0x00, data->io_buf, 8, + CONTROL_TIMEOUT_JIFFIES); + + if (ret < 0) { + BT_ERR("%s error(%d)\n", __func__, ret); + } + + return ret; +} + +static u16 btmtk_usb_get_crc(struct btmtk_usb_data *data) +{ + int ret = 0; + struct usb_device *udev = data->udev; + u16 crc, count = 0; + + BT_DBG("%s\n", __func__); + + while (1) { + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), + 0x01, DEVICE_VENDOR_REQUEST_IN, + 0x21, 0x00, data->io_buf, 2, + CONTROL_TIMEOUT_JIFFIES); + + if (ret < 0) { + crc = 0xFFFF; + BT_ERR("%s error(%d)\n", __func__, ret); + } + + memmove(&crc, data->io_buf, 2); + + crc = le16_to_cpu(crc); + + if (crc != 0xFFFF) + break; + + mdelay(100); + + if (count++ > 100) { + BT_ERR("Query CRC over %d times\n", count); + break; + } + } + + return crc; +} + +static int btmtk_usb_reset_wmt(struct btmtk_usb_data *data) +{ + int ret = 0; + + /* reset command */ + u8 cmd[8] = {0x6F, 0xFC, 0x05, 0x01, 0x07, 0x01, 0x00, 0x04}; + + memmove(data->io_buf, cmd, 8); + + BT_DBG("%s\n", __func__); + + ret = usb_control_msg(data->udev, usb_sndctrlpipe(data->udev, 0), 0x01, + DEVICE_CLASS_REQUEST_OUT, 0x12, 0x00, data->io_buf, + 8, CONTROL_TIMEOUT_JIFFIES); + + if (ret) + BT_ERR("%s:(%d)\n", __func__, ret); + + return ret; +} + +static void load_rom_patch_complete(struct urb *urb) +{ + + struct completion *sent_to_mcu_done = (struct completion *)urb->context; + + complete(sent_to_mcu_done); +} + +static int btmtk_usb_load_rom_patch(struct btmtk_usb_data *data) +{ + u32 loop = 0; + u32 value; + s32 sent_len; + int ret = 0, total_checksum = 0; + struct urb *urb; + u32 patch_len = 0; + u32 cur_len = 0; + dma_addr_t data_dma; + struct completion sent_to_mcu_done; + int first_block = 1; + unsigned char phase; + void *buf; + char *pos; + unsigned int pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress); + + if (!data->firmware) { + BT_ERR("%s:please assign a rom patch\n", __func__); + return -1; + } + +load_patch_protect: + btmtk_usb_switch_iobase(data, WLAN); + btmtk_usb_io_read32(data, SEMAPHORE_03, &value); + loop++; + + if (((value & 0x01) == 0x00) && (loop < 600)) { + mdelay(1); + goto load_patch_protect; + } + + btmtk_usb_io_write32(data, 0x1004, 0x2c); + + btmtk_usb_switch_iobase(data, SYSCTL); + + btmtk_usb_io_write32(data, 0x1c, 0x30); + + /* Enable USB_DMA_CFG */ + btmtk_usb_io_write32(data, 0x9018, 0x00c00020); + + btmtk_usb_switch_iobase(data, WLAN); + + /* check ROM patch if upgrade */ + btmtk_usb_io_read32(data, COM_REG0, &value); + + if ((value & 0x02) == 0x02) + goto error0; + + urb = usb_alloc_urb(0, GFP_ATOMIC); + + if (!urb) { + ret = -ENOMEM; + goto error0; + } + + buf = usb_alloc_coherent(data->udev, UPLOAD_PATCH_UNIT, GFP_ATOMIC, &data_dma); + + if (!buf) { + ret = -ENOMEM; + goto error1; + } + + pos = buf; + BT_DBG("loading rom patch"); + + init_completion(&sent_to_mcu_done); + + cur_len = 0x00; + patch_len = data->rom_patch_len - PATCH_INFO_SIZE; + + /* loading rom patch */ + while (1) { + s32 sent_len_max = UPLOAD_PATCH_UNIT - PATCH_HEADER_SIZE; + sent_len = (patch_len - cur_len) >= sent_len_max ? sent_len_max : (patch_len - cur_len); + + BT_DBG("patch_len = %d\n", patch_len); + BT_DBG("cur_len = %d\n", cur_len); + BT_DBG("sent_len = %d\n", sent_len); + + if (sent_len > 0) { + if (first_block == 1) { + if (sent_len < sent_len_max) + phase = PATCH_PHASE3; + else + phase = PATCH_PHASE1; + first_block = 0; + } else if (sent_len == sent_len_max) { + phase = PATCH_PHASE2; + } else { + phase = PATCH_PHASE3; + } + + /* prepare HCI header */ + pos[0] = 0x6F; + pos[1] = 0xFC; + pos[2] = (sent_len + 5) & 0xFF; + pos[3] = ((sent_len + 5) >> 8) & 0xFF; + + /* prepare WMT header */ + pos[4] = 0x01; + pos[5] = 0x01; + pos[6] = (sent_len + 1) & 0xFF; + pos[7] = ((sent_len + 1) >> 8) & 0xFF; + + pos[8] = phase; + + memcpy(&pos[9], data->firmware->data + PATCH_INFO_SIZE + cur_len, sent_len); + + BT_DBG("sent_len + PATCH_HEADER_SIZE = %d, phase = %d\n", + sent_len + PATCH_HEADER_SIZE, phase); + + usb_fill_bulk_urb(urb, + data->udev, + pipe, + buf, + sent_len + PATCH_HEADER_SIZE, + load_rom_patch_complete, + &sent_to_mcu_done); + + urb->transfer_dma = data_dma; + urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; + + ret = usb_submit_urb(urb, GFP_ATOMIC); + + if (ret) + goto error2; + + if (!wait_for_completion_timeout(&sent_to_mcu_done, msecs_to_jiffies(1000))) { + usb_kill_urb(urb); + BT_ERR("upload rom_patch timeout\n"); + goto error2; + } + + BT_DBG("."); + + mdelay(200); + + cur_len += sent_len; + + } else { + break; + } + } + + total_checksum = checksume16((u8 *)data->firmware->data + PATCH_INFO_SIZE, patch_len); + + BT_DBG("Send checksum req..\n"); + + btmtk_usb_chk_crc(data, patch_len); + + mdelay(20); + + if (total_checksum != btmtk_usb_get_crc(data)) { + BT_ERR("checksum fail!, local(0x%x) <> fw(0x%x)\n", + total_checksum, btmtk_usb_get_crc(data)); + ret = -1; + goto error2; + } + + mdelay(20); + + ret = btmtk_usb_reset_wmt(data); + + mdelay(20); + +error2: + usb_free_coherent(data->udev, UPLOAD_PATCH_UNIT, buf, data_dma); +error1: + usb_free_urb(urb); +error0: + btmtk_usb_io_write32(data, SEMAPHORE_03, 0x1); + return ret; +} + + +static int load_fw_iv(struct btmtk_usb_data *data) +{ + int ret; + struct usb_device *udev = data->udev; + char *buf = kmalloc(64, GFP_ATOMIC); + + memmove(buf, data->firmware->data + 32, 64); + + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x01, + DEVICE_VENDOR_REQUEST_OUT, 0x12, 0x0, buf, 64, + CONTROL_TIMEOUT_JIFFIES); + + if (ret < 0) { + BT_ERR("%s error(%d) step4\n", __func__, ret); + kfree(buf); + return ret; + } + + if (ret > 0) + ret = 0; + + kfree(buf); + + return ret; +} + +static void load_fw_complete(struct urb *urb) +{ + + struct completion *sent_to_mcu_done = (struct completion *)urb->context; + + complete(sent_to_mcu_done); +} + +static int btmtk_usb_load_fw(struct btmtk_usb_data *data) +{ + struct usb_device *udev = data->udev; + struct urb *urb; + void *buf; + u32 cur_len = 0; + u32 packet_header = 0; + u32 value; + u32 ilm_len = 0, dlm_len = 0; + u16 fw_ver, build_ver; + u32 loop = 0; + dma_addr_t data_dma; + int ret = 0, sent_len; + struct completion sent_to_mcu_done; + unsigned int pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress); + + if (!data->firmware) { + BT_ERR("%s:please assign a fw\n", __func__); + return -1; + } + + BT_DBG("bulk_tx_ep = %x\n", data->bulk_tx_ep->bEndpointAddress); + +loadfw_protect: + btmtk_usb_switch_iobase(data, WLAN); + btmtk_usb_io_read32(data, SEMAPHORE_00, &value); + loop++; + + if (((value & 0x1) == 0) && (loop < 10000)) + goto loadfw_protect; + + /* check MCU if ready */ + btmtk_usb_io_read32(data, COM_REG0, &value); + + if ((value & 0x01) == 0x01) + goto error0; + + /* Enable MPDMA TX and EP2 load FW mode */ + btmtk_usb_io_write32(data, 0x238, 0x1c000000); + + btmtk_usb_reset(udev); + mdelay(100); + + ilm_len = (*(data->firmware->data + 3) << 24) + | (*(data->firmware->data + 2) << 16) + | (*(data->firmware->data + 1) << 8) + | (*data->firmware->data); + + dlm_len = (*(data->firmware->data + 7) << 24) + | (*(data->firmware->data + 6) << 16) + | (*(data->firmware->data + 5) << 8) + | (*(data->firmware->data + 4)); + + fw_ver = (*(data->firmware->data + 11) << 8) | (*(data->firmware->data + 10)); + + build_ver = (*(data->firmware->data + 9) << 8) | (*(data->firmware->data + 8)); + + BT_DBG("fw version:%d.%d.%02d ", + (fw_ver & 0xf000) >> 8, + (fw_ver & 0x0f00) >> 8, + (fw_ver & 0x00ff)); + + BT_DBG("build:%x\n", build_ver); + + BT_DBG("build Time ="); + + for (loop = 0; loop < 16; loop++) + BT_DBG("%c", *(data->firmware->data + 16 + loop)); + + BT_DBG("\n"); + + BT_DBG("ILM length = %d(bytes)\n", ilm_len); + BT_DBG("DLM length = %d(bytes)\n", dlm_len); + + btmtk_usb_switch_iobase(data, SYSCTL); + + /* U2M_PDMA rx_ring_base_ptr */ + btmtk_usb_io_write32(data, 0x790, 0x400230); + + /* U2M_PDMA rx_ring_max_cnt */ + btmtk_usb_io_write32(data, 0x794, 0x1); + + /* U2M_PDMA cpu_idx */ + btmtk_usb_io_write32(data, 0x798, 0x1); + + /* U2M_PDMA enable */ + btmtk_usb_io_write32(data, 0x704, 0x44); + + urb = usb_alloc_urb(0, GFP_ATOMIC); + + if (!urb) { + ret = -ENOMEM; + goto error1; + } + + buf = usb_alloc_coherent(udev, 14592, GFP_ATOMIC, &data_dma); + + if (!buf) { + ret = -ENOMEM; + goto error2; + } + + BT_DBG("loading fw"); + + init_completion(&sent_to_mcu_done); + + btmtk_usb_switch_iobase(data, SYSCTL); + + cur_len = 0x40; + + /* Loading ILM */ + while (1) { + sent_len = (ilm_len - cur_len) >= 14336 ? 14336 : (ilm_len - cur_len); + + if (sent_len > 0) { + packet_header &= ~(0xffffffff); + packet_header |= (sent_len << 16); + packet_header = cpu_to_le32(packet_header); + + memmove(buf, &packet_header, 4); + memmove(buf + 4, data->firmware->data + 32 + cur_len, sent_len); + + /* U2M_PDMA descriptor */ + btmtk_usb_io_write32(data, 0x230, cur_len); + + while ((sent_len % 4) != 0) { + sent_len++; + } + + /* U2M_PDMA length */ + btmtk_usb_io_write32(data, 0x234, sent_len << 16); + + usb_fill_bulk_urb(urb, + udev, + pipe, + buf, + sent_len + 4, + load_fw_complete, + &sent_to_mcu_done); + + urb->transfer_dma = data_dma; + urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; + + ret = usb_submit_urb(urb, GFP_ATOMIC); + + if (ret) + goto error3; + + if (!wait_for_completion_timeout(&sent_to_mcu_done, msecs_to_jiffies(1000))) { + usb_kill_urb(urb); + BT_ERR("upload ilm fw timeout\n"); + goto error3; + } + + BT_DBG("."); + + mdelay(200); + + cur_len += sent_len; + } else { + break; + } + } + + init_completion(&sent_to_mcu_done); + cur_len = 0x00; + + /* Loading DLM */ + while (1) { + sent_len = (dlm_len - cur_len) >= 14336 ? 14336 : (dlm_len - cur_len); + + if (sent_len > 0) { + packet_header &= ~(0xffffffff); + packet_header |= (sent_len << 16); + packet_header = cpu_to_le32(packet_header); + + memmove(buf, &packet_header, 4); + memmove(buf + 4, data->firmware->data + 32 + ilm_len + cur_len, sent_len); + + /* U2M_PDMA descriptor */ + btmtk_usb_io_write32(data, 0x230, 0x80000 + cur_len); + + while ((sent_len % 4) != 0) { + BT_DBG("sent_len is not divided by 4\n"); + sent_len++; + } + + /* U2M_PDMA length */ + btmtk_usb_io_write32(data, 0x234, sent_len << 16); + + usb_fill_bulk_urb(urb, + udev, + pipe, + buf, + sent_len + 4, + load_fw_complete, + &sent_to_mcu_done); + + urb->transfer_dma = data_dma; + urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; + + ret = usb_submit_urb(urb, GFP_ATOMIC); + + if (ret) + goto error3; + + if (!wait_for_completion_timeout(&sent_to_mcu_done, msecs_to_jiffies(1000))) { + usb_kill_urb(urb); + BT_ERR("upload dlm fw timeout\n"); + goto error3; + } + + BT_DBG("."); + + mdelay(500); + + cur_len += sent_len; + + } else { + break; + } + } + + /* upload 64bytes interrupt vector */ + ret = load_fw_iv(data); + mdelay(100); + + btmtk_usb_switch_iobase(data, WLAN); + + /* check MCU if ready */ + loop = 0; + + do { + btmtk_usb_io_read32(data, COM_REG0, &value); + + if (value == 0x01) + break; + + mdelay(10); + loop++; + } while (loop <= 100); + + if (loop > 1000) { + BT_ERR("wait for 100 times\n"); + ret = -ENODEV; + } + +error3: + usb_free_coherent(udev, 14592, buf, data_dma); +error2: + usb_free_urb(urb); +error1: + /* Disbale load fw mode */ + btmtk_usb_io_read32(data, 0x238, &value); + value = value & ~(0x10000000); + btmtk_usb_io_write32(data, 0x238, value); +error0: + btmtk_usb_io_write32(data, SEMAPHORE_00, 0x1); + return ret; +} + +static int inc_tx(struct btmtk_usb_data *data) +{ + unsigned long flags; + int rv; + + spin_lock_irqsave(&data->txlock, flags); + rv = test_bit(BTUSB_SUSPENDING, &data->flags); + if (!rv) + data->tx_in_flight++; + spin_unlock_irqrestore(&data->txlock, flags); + + return rv; +} + +static void btmtk_usb_intr_complete(struct urb *urb) +{ + struct hci_dev *hdev = urb->context; + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + int err; + + BT_DBG("%s: %s urb %p status %d count %d\n", __func__, hdev->name, + urb, urb->status, urb->actual_length); + + if (!test_bit(HCI_RUNNING, &hdev->flags)) + return; + + if (urb->status == 0) { + hdev->stat.byte_rx += urb->actual_length; + + hex_dump("hci event", urb->transfer_buffer, urb->actual_length); + + if (hci_recv_fragment(hdev, HCI_EVENT_PKT, + urb->transfer_buffer, + urb->actual_length) < 0) { + BT_ERR("%s corrupted event packet", hdev->name); + hdev->stat.err_rx++; + } + } + + if (!test_bit(BTUSB_INTR_RUNNING, &data->flags)) + return; + + usb_mark_last_busy(data->udev); + usb_anchor_urb(urb, &data->intr_anchor); + + err = usb_submit_urb(urb, GFP_ATOMIC); + + if (err < 0) { + /* -EPERM: urb is being killed; + * -ENODEV: device got disconnected */ + if (err != -EPERM && err != -ENODEV) + BT_ERR("%s urb %p failed to resubmit (%d)", + hdev->name, urb, -err); + usb_unanchor_urb(urb); + } +} + +static int btmtk_usb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags) +{ + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + struct urb *urb; + unsigned char *buf; + unsigned int pipe; + int err, size; + + BT_DBG("%s\n", __func__); + + if (!data->intr_ep) + return -ENODEV; + + urb = usb_alloc_urb(0, mem_flags); + if (!urb) + return -ENOMEM; + + size = le16_to_cpu(data->intr_ep->wMaxPacketSize); + + buf = kmalloc(size, mem_flags); + if (!buf) { + usb_free_urb(urb); + return -ENOMEM; + } + + pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress); + + usb_fill_int_urb(urb, data->udev, pipe, buf, size, + btmtk_usb_intr_complete, hdev, + data->intr_ep->bInterval); + + urb->transfer_flags |= URB_FREE_BUFFER; + + usb_anchor_urb(urb, &data->intr_anchor); + + err = usb_submit_urb(urb, mem_flags); + if (err < 0) { + if (err != -EPERM && err != -ENODEV) + BT_ERR("%s urb %p submission failed (%d)", + hdev->name, urb, -err); + usb_unanchor_urb(urb); + } + + usb_free_urb(urb); + + return err; + +} + +static void btmtk_usb_bulk_in_complete(struct urb *urb) +{ + struct hci_dev *hdev = urb->context; + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + int err; + + BT_DBG("%s:%s urb %p status %d count %d", __func__, hdev->name, + urb, urb->status, urb->actual_length); + + if (!test_bit(HCI_RUNNING, &hdev->flags)) { + return; + } + + if (urb->status == 0) { + hdev->stat.byte_rx += urb->actual_length; + + if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT, + urb->transfer_buffer, + urb->actual_length) < 0) { + BT_ERR("%s corrupted ACL packet", hdev->name); + hdev->stat.err_rx++; + } + } + + if (!test_bit(BTUSB_BULK_RUNNING, &data->flags)) + return; + + usb_anchor_urb(urb, &data->bulk_anchor); + usb_mark_last_busy(data->udev); + + err = usb_submit_urb(urb, GFP_ATOMIC); + if (err < 0) { + /* -EPERM: urb is being killed; + * -ENODEV: device got disconnected */ + if (err != -EPERM && err != -ENODEV) + BT_ERR("%s urb %p failed to resubmit (%d)", + hdev->name, urb, -err); + usb_unanchor_urb(urb); + } +} + +static int btmtk_usb_submit_bulk_in_urb(struct hci_dev *hdev, gfp_t mem_flags) +{ + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + struct urb *urb; + unsigned char *buf; + unsigned int pipe; + int err, size = HCI_MAX_FRAME_SIZE; + + BT_DBG("%s:%s\n", __func__, hdev->name); + + if (!data->bulk_rx_ep) + return -ENODEV; + + urb = usb_alloc_urb(0, mem_flags); + if (!urb) + return -ENOMEM; + + buf = kmalloc(size, mem_flags); + if (!buf) { + usb_free_urb(urb); + return -ENOMEM; + } + + pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress); + + usb_fill_bulk_urb(urb, data->udev, pipe, + buf, size, btmtk_usb_bulk_in_complete, hdev); + + urb->transfer_flags |= URB_FREE_BUFFER; + + usb_mark_last_busy(data->udev); + usb_anchor_urb(urb, &data->bulk_anchor); + + err = usb_submit_urb(urb, mem_flags); + if (err < 0) { + if (err != -EPERM && err != -ENODEV) + BT_ERR("%s urb %p submission failed (%d)", + hdev->name, urb, -err); + usb_unanchor_urb(urb); + } + + usb_free_urb(urb); + + return err; +} + +static void btmtk_usb_isoc_in_complete(struct urb *urb) + +{ + struct hci_dev *hdev = urb->context; + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + int i, err; + + BT_DBG("%s: %s urb %p status %d count %d", __func__, hdev->name, + urb, urb->status, urb->actual_length); + + if (!test_bit(HCI_RUNNING, &hdev->flags)) + return; + + if (urb->status == 0) { + for (i = 0; i < urb->number_of_packets; i++) { + unsigned int offset = urb->iso_frame_desc[i].offset; + unsigned int length = urb->iso_frame_desc[i].actual_length; + + if (urb->iso_frame_desc[i].status) + continue; + + hdev->stat.byte_rx += length; + + if (hci_recv_fragment(hdev, HCI_SCODATA_PKT, + urb->transfer_buffer + offset, + length) < 0) { + BT_ERR("%s corrupted SCO packet", hdev->name); + hdev->stat.err_rx++; + } + } + } + + if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags)) + return; + + usb_anchor_urb(urb, &data->isoc_anchor); + + err = usb_submit_urb(urb, GFP_ATOMIC); + if (err < 0) { + /* -EPERM: urb is being killed; + * -ENODEV: device got disconnected */ + if (err != -EPERM && err != -ENODEV) + BT_ERR("%s urb %p failed to resubmit (%d)", + hdev->name, urb, -err); + usb_unanchor_urb(urb); + } +} + +static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu) +{ + int i, offset = 0; + + BT_DBG("len %d mtu %d", len, mtu); + + for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu; + i++, offset += mtu, len -= mtu) { + urb->iso_frame_desc[i].offset = offset; + urb->iso_frame_desc[i].length = mtu; + } + + if (len && i < BTUSB_MAX_ISOC_FRAMES) { + urb->iso_frame_desc[i].offset = offset; + urb->iso_frame_desc[i].length = len; + i++; + } + + urb->number_of_packets = i; +} + +static int btmtk_usb_submit_isoc_in_urb(struct hci_dev *hdev, gfp_t mem_flags) +{ + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + struct urb *urb; + unsigned char *buf; + unsigned int pipe; + int err, size; + + BT_DBG("%s\n", __func__); + + if (!data->isoc_rx_ep) + return -ENODEV; + + urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags); + if (!urb) + return -ENOMEM; + + size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) * + BTUSB_MAX_ISOC_FRAMES; + + buf = kmalloc(size, mem_flags); + if (!buf) { + usb_free_urb(urb); + return -ENOMEM; + } + + pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress); + + usb_fill_int_urb(urb, data->udev, pipe, buf, size, btmtk_usb_isoc_in_complete, + hdev, data->isoc_rx_ep->bInterval); + + urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP; + + __fill_isoc_descriptor(urb, size, + le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize)); + + usb_anchor_urb(urb, &data->isoc_anchor); + + err = usb_submit_urb(urb, mem_flags); + if (err < 0) { + if (err != -EPERM && err != -ENODEV) + BT_ERR("%s urb %p submission failed (%d)", + hdev->name, urb, -err); + usb_unanchor_urb(urb); + } + + usb_free_urb(urb); + + return err; +} + +static int btmtk_usb_open(struct hci_dev *hdev) +{ + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + int err; + + BT_DBG("%s\n", __func__); + + err = usb_autopm_get_interface(data->intf); + if (err < 0) + return err; + + data->intf->needs_remote_wakeup = 1; + + if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) + goto done; + + if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) + goto done; + + err = btmtk_usb_submit_intr_urb(hdev, GFP_KERNEL); + if (err < 0) + goto failed; + + err = btmtk_usb_submit_bulk_in_urb(hdev, GFP_KERNEL); + if (err < 0) { + usb_kill_anchored_urbs(&data->intr_anchor); + goto failed; + } + + set_bit(BTUSB_BULK_RUNNING, &data->flags); + btmtk_usb_submit_bulk_in_urb(hdev, GFP_KERNEL); + +done: + usb_autopm_put_interface(data->intf); + return 0; + +failed: + clear_bit(BTUSB_INTR_RUNNING, &data->flags); + clear_bit(HCI_RUNNING, &hdev->flags); + usb_autopm_put_interface(data->intf); + return err; +} + +static void btmtk_usb_stop_traffic(struct btmtk_usb_data *data) +{ + BT_DBG("%s\n", __func__); + + usb_kill_anchored_urbs(&data->intr_anchor); + usb_kill_anchored_urbs(&data->bulk_anchor); + usb_kill_anchored_urbs(&data->isoc_anchor); +} + +static int btmtk_usb_close(struct hci_dev *hdev) +{ + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + int err; + + BT_DBG("%s\n", __func__); + + if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) + return 0; + + cancel_work_sync(&data->work); + cancel_work_sync(&data->waker); + + clear_bit(BTUSB_ISOC_RUNNING, &data->flags); + clear_bit(BTUSB_BULK_RUNNING, &data->flags); + clear_bit(BTUSB_INTR_RUNNING, &data->flags); + + btmtk_usb_stop_traffic(data); + + err = usb_autopm_get_interface(data->intf); + if (err < 0) + goto failed; + + data->intf->needs_remote_wakeup = 0; + usb_autopm_put_interface(data->intf); + +failed: + usb_scuttle_anchored_urbs(&data->deferred); + return 0; +} + +static int btmtk_usb_flush(struct hci_dev *hdev) +{ + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + + BT_DBG("%s\n", __func__); + + usb_kill_anchored_urbs(&data->tx_anchor); + + return 0; +} + +static void btmtk_usb_tx_complete(struct urb *urb) +{ + struct sk_buff *skb = urb->context; + struct hci_dev *hdev = (struct hci_dev *)skb->dev; + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + + BT_DBG("%s: %s urb %p status %d count %d\n", __func__, hdev->name, + urb, urb->status, urb->actual_length); + + if (!test_bit(HCI_RUNNING, &hdev->flags)) + goto done; + + if (!urb->status) + hdev->stat.byte_tx += urb->transfer_buffer_length; + else + hdev->stat.err_tx++; + +done: + spin_lock(&data->txlock); + data->tx_in_flight--; + spin_unlock(&data->txlock); + + kfree(urb->setup_packet); + + kfree_skb(skb); +} + +static void btmtk_usb_isoc_tx_complete(struct urb *urb) +{ + struct sk_buff *skb = urb->context; + struct hci_dev *hdev = (struct hci_dev *) skb->dev; + + BT_DBG("%s: %s urb %p status %d count %d", __func__, hdev->name, + urb, urb->status, urb->actual_length); + + if (!test_bit(HCI_RUNNING, &hdev->flags)) + goto done; + + if (!urb->status) + hdev->stat.byte_tx += urb->transfer_buffer_length; + else + hdev->stat.err_tx++; + +done: + kfree(urb->setup_packet); + + kfree_skb(skb); +} + +static int btmtk_usb_send_frame(struct sk_buff *skb) +{ + struct hci_dev *hdev = (struct hci_dev *)skb->dev; + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + struct usb_ctrlrequest *dr; + struct urb *urb; + unsigned int pipe; + int err; + + BT_DBG("%s\n", __func__); + + if (!test_bit(HCI_RUNNING, &hdev->flags)) + return -EBUSY; + + switch (bt_cb(skb)->pkt_type) { + case HCI_COMMAND_PKT: + urb = usb_alloc_urb(0, GFP_ATOMIC); + if (!urb) + return -ENOMEM; + + dr = kmalloc(sizeof(*dr), GFP_ATOMIC); + if (!dr) { + usb_free_urb(urb); + return -ENOMEM; + } + + dr->bRequestType = data->cmdreq_type; + dr->bRequest = 0; + dr->wIndex = 0; + dr->wValue = 0; + dr->wLength = __cpu_to_le16(skb->len); + + pipe = usb_sndctrlpipe(data->udev, 0x00); + + if (test_bit(HCI_RUNNING, &hdev->flags)) { + u16 op_code; + memcpy(&op_code, skb->data, 2); + BT_DBG("ogf = %x\n", (op_code & 0xfc00) >> 10); + BT_DBG("ocf = %x\n", op_code & 0x03ff); + hex_dump("hci command", skb->data, skb->len); + + } + + usb_fill_control_urb(urb, data->udev, pipe, (void *) dr, + skb->data, skb->len, btmtk_usb_tx_complete, skb); + + hdev->stat.cmd_tx++; + break; + + case HCI_ACLDATA_PKT: + if (!data->bulk_tx_ep) + return -ENODEV; + + urb = usb_alloc_urb(0, GFP_ATOMIC); + if (!urb) + return -ENOMEM; + + pipe = usb_sndbulkpipe(data->udev, + data->bulk_tx_ep->bEndpointAddress); + + usb_fill_bulk_urb(urb, data->udev, pipe, + skb->data, skb->len, btmtk_usb_tx_complete, skb); + + hdev->stat.acl_tx++; + BT_DBG("HCI_ACLDATA_PKT:\n"); + break; + + case HCI_SCODATA_PKT: + if (!data->isoc_tx_ep || hdev->conn_hash.sco_num < 1) + return -ENODEV; + + urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_ATOMIC); + if (!urb) + return -ENOMEM; + + pipe = usb_sndisocpipe(data->udev, + data->isoc_tx_ep->bEndpointAddress); + + usb_fill_int_urb(urb, data->udev, pipe, + skb->data, skb->len, btmtk_usb_isoc_tx_complete, + skb, data->isoc_tx_ep->bInterval); + + urb->transfer_flags = URB_ISO_ASAP; + + __fill_isoc_descriptor(urb, skb->len, + le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize)); + + hdev->stat.sco_tx++; + BT_DBG("HCI_SCODATA_PKT:\n"); + goto skip_waking; + + default: + return -EILSEQ; + } + + err = inc_tx(data); + + if (err) { + usb_anchor_urb(urb, &data->deferred); + schedule_work(&data->waker); + err = 0; + goto done; + } + +skip_waking: + usb_anchor_urb(urb, &data->tx_anchor); + + err = usb_submit_urb(urb, GFP_ATOMIC); + if (err < 0) { + if (err != -EPERM && err != -ENODEV) + BT_ERR("%s urb %p submission failed (%d)", + hdev->name, urb, -err); + kfree(urb->setup_packet); + usb_unanchor_urb(urb); + } else { + usb_mark_last_busy(data->udev); + } + +done: + usb_free_urb(urb); + return err; +} + +static void btmtk_usb_notify(struct hci_dev *hdev, unsigned int evt) +{ + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + + BT_DBG("%s evt %d", hdev->name, evt); + + if (hdev->conn_hash.sco_num != data->sco_num) { + data->sco_num = hdev->conn_hash.sco_num; + schedule_work(&data->work); + } +} + +static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting) +{ + struct btmtk_usb_data *data = hci_get_drvdata(hdev); + struct usb_interface *intf = data->isoc; + struct usb_endpoint_descriptor *ep_desc; + int i, err; + + if (!data->isoc) + return -ENODEV; + + err = usb_set_interface(data->udev, 1, altsetting); + if (err < 0) { + BT_ERR("%s setting interface failed (%d)", hdev->name, -err); + return err; + } + + data->isoc_altsetting = altsetting; + + data->isoc_tx_ep = NULL; + data->isoc_rx_ep = NULL; + + for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { + ep_desc = &intf->cur_altsetting->endpoint[i].desc; + + if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) { + data->isoc_tx_ep = ep_desc; + continue; + } + + if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) { + data->isoc_rx_ep = ep_desc; + continue; + } + } + + if (!data->isoc_tx_ep || !data->isoc_rx_ep) { + BT_ERR("%s invalid SCO descriptors", hdev->name); + return -ENODEV; + } + + return 0; +} + +static void btmtk_usb_work(struct work_struct *work) +{ + struct btmtk_usb_data *data = container_of(work, struct btmtk_usb_data, work); + struct hci_dev *hdev = data->hdev; + int new_alts; + int err; + + BT_DBG("%s\n", __func__); + + if (hdev->conn_hash.sco_num > 0) { + if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) { + err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf); + if (err < 0) { + clear_bit(BTUSB_ISOC_RUNNING, &data->flags); + usb_kill_anchored_urbs(&data->isoc_anchor); + return; + } + + set_bit(BTUSB_DID_ISO_RESUME, &data->flags); + } + + if (hdev->voice_setting & 0x0020) { + static const int alts[3] = { 2, 4, 5 }; + new_alts = alts[hdev->conn_hash.sco_num - 1]; + } else { + new_alts = hdev->conn_hash.sco_num; + } + + if (data->isoc_altsetting != new_alts) { + clear_bit(BTUSB_ISOC_RUNNING, &data->flags); + usb_kill_anchored_urbs(&data->isoc_anchor); + + if (__set_isoc_interface(hdev, new_alts) < 0) + return; + } + + if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) { + if (btmtk_usb_submit_isoc_in_urb(hdev, GFP_KERNEL) < 0) + clear_bit(BTUSB_ISOC_RUNNING, &data->flags); + else + btmtk_usb_submit_isoc_in_urb(hdev, GFP_KERNEL); + } + } else { + clear_bit(BTUSB_ISOC_RUNNING, &data->flags); + usb_kill_anchored_urbs(&data->isoc_anchor); + + __set_isoc_interface(hdev, 0); + + if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags)) + usb_autopm_put_interface(data->isoc ? data->isoc : data->intf); + } +} + +static void btmtk_usb_waker(struct work_struct *work) +{ + struct btmtk_usb_data *data = container_of(work, struct btmtk_usb_data, waker); + int err; + + err = usb_autopm_get_interface(data->intf); + + if (err < 0) + return; + + usb_autopm_put_interface(data->intf); +} + +static int btmtk_usb_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + struct btmtk_usb_data *data; + struct usb_endpoint_descriptor *ep_desc; + int i, err; + struct hci_dev *hdev; + + /* interface numbers are hardcoded in the spec */ + if (intf->cur_altsetting->desc.bInterfaceNumber != 0) + return -ENODEV; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + + if (!data) + return -ENOMEM; + + for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { + ep_desc = &intf->cur_altsetting->endpoint[i].desc; + + if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) { + data->intr_ep = ep_desc; + continue; + } + + if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) { + data->bulk_tx_ep = ep_desc; + continue; + } + + if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) { + data->bulk_rx_ep = ep_desc; + continue; + } + } + + if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) { + kfree(data); + return -ENODEV; + } + + data->cmdreq_type = USB_TYPE_CLASS; + + data->udev = interface_to_usbdev(intf); + data->intf = intf; + + spin_lock_init(&data->lock); + INIT_WORK(&data->work, btmtk_usb_work); + INIT_WORK(&data->waker, btmtk_usb_waker); + spin_lock_init(&data->txlock); + + init_usb_anchor(&data->tx_anchor); + init_usb_anchor(&data->intr_anchor); + init_usb_anchor(&data->bulk_anchor); + init_usb_anchor(&data->isoc_anchor); + init_usb_anchor(&data->deferred); + + hdev = hci_alloc_dev(); + if (!hdev) { + kfree(data); + return -ENOMEM; + } + + hdev->bus = HCI_USB; + + hci_set_drvdata(hdev, data); + + data->hdev = hdev; + + SET_HCIDEV_DEV(hdev, &intf->dev); + + hdev->open = btmtk_usb_open; + hdev->close = btmtk_usb_close; + hdev->flush = btmtk_usb_flush; + hdev->send = btmtk_usb_send_frame; + hdev->notify = btmtk_usb_notify; + + /* Interface numbers are hardcoded in the specification */ + data->isoc = usb_ifnum_to_if(data->udev, 1); + + if (data->isoc) { + err = usb_driver_claim_interface(&btmtk_usb_driver, + data->isoc, data); + if (err < 0) { + hci_free_dev(hdev); + kfree(data); + return err; + } + } + + data->io_buf = kmalloc(256, GFP_KERNEL); + if (!data->io_buf) { + hci_free_dev(hdev); + kfree(data); + return -ENOMEM; + } + + btmtk_usb_switch_iobase(data, WLAN); + + btmtk_usb_cap_init(data); + + err = hci_register_dev(hdev); + if (err < 0) { + hci_free_dev(hdev); + kfree(data); + return err; + } + + usb_set_intfdata(intf, data); + + return 0; +} + +static void btmtk_usb_disconnect(struct usb_interface *intf) +{ + struct btmtk_usb_data *data = usb_get_intfdata(intf); + struct hci_dev *hdev; + + BT_DBG("%s\n", __func__); + + if (!data) + return; + + hdev = data->hdev; + usb_set_intfdata(data->intf, NULL); + + if (data->isoc) + usb_set_intfdata(data->isoc, NULL); + + hci_unregister_dev(hdev); + + if (intf == data->isoc) + usb_driver_release_interface(&btmtk_usb_driver, data->intf); + else if (data->isoc) + usb_driver_release_interface(&btmtk_usb_driver, data->isoc); + + hci_free_dev(hdev); + + kfree(data->io_buf); + + kfree(data); +} + +#ifdef CONFIG_PM +static int btmtk_usb_suspend(struct usb_interface *intf, pm_message_t message) +{ + struct btmtk_usb_data *data = usb_get_intfdata(intf); + + BT_DBG("%s\n", __func__); + + if (data->suspend_count++) + return 0; + + spin_lock_irq(&data->txlock); + if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) { + set_bit(BTUSB_SUSPENDING, &data->flags); + spin_unlock_irq(&data->txlock); + } else { + spin_unlock_irq(&data->txlock); + data->suspend_count--; + return -EBUSY; + } + + cancel_work_sync(&data->work); + + btmtk_usb_stop_traffic(data); + usb_kill_anchored_urbs(&data->tx_anchor); + + return 0; +} + +static void play_deferred(struct btmtk_usb_data *data) +{ + struct urb *urb; + int err; + + while ((urb = usb_get_from_anchor(&data->deferred))) { + err = usb_submit_urb(urb, GFP_ATOMIC); + if (err < 0) + break; + + data->tx_in_flight++; + } + + usb_scuttle_anchored_urbs(&data->deferred); +} + +static int btmtk_usb_resume(struct usb_interface *intf) +{ + struct btmtk_usb_data *data = usb_get_intfdata(intf); + struct hci_dev *hdev = data->hdev; + int err = 0; + + BT_DBG("%s\n", __func__); + + if (--data->suspend_count) + return 0; + + if (!test_bit(HCI_RUNNING, &hdev->flags)) + goto done; + + if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) { + err = btmtk_usb_submit_intr_urb(hdev, GFP_NOIO); + if (err < 0) { + clear_bit(BTUSB_INTR_RUNNING, &data->flags); + goto failed; + } + } + + if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) { + err = btmtk_usb_submit_bulk_in_urb(hdev, GFP_NOIO); + if (err < 0) { + clear_bit(BTUSB_BULK_RUNNING, &data->flags); + goto failed; + } + + btmtk_usb_submit_bulk_in_urb(hdev, GFP_NOIO); + } + + if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) { + if (btmtk_usb_submit_isoc_in_urb(hdev, GFP_NOIO) < 0) + clear_bit(BTUSB_ISOC_RUNNING, &data->flags); + else + btmtk_usb_submit_isoc_in_urb(hdev, GFP_NOIO); + } + + spin_lock_irq(&data->txlock); + play_deferred(data); + clear_bit(BTUSB_SUSPENDING, &data->flags); + spin_unlock_irq(&data->txlock); + schedule_work(&data->work); + + return 0; + +failed: + usb_scuttle_anchored_urbs(&data->deferred); +done: + spin_lock_irq(&data->txlock); + clear_bit(BTUSB_SUSPENDING, &data->flags); + spin_unlock_irq(&data->txlock); + + return err; +} +#endif + +static struct usb_device_id btmtk_usb_table[] = { + /* Mediatek MT7650 */ + { USB_DEVICE(0x0e8d, 0x7650) }, + { USB_DEVICE(0x0e8d, 0x7630) }, + { USB_DEVICE(0x0e8d, 0x763e) }, + /* Mediatek MT662 */ + { USB_DEVICE(0x0e8d, 0x7662) }, + { USB_DEVICE(0x0e8d, 0x7632) }, + { } /* Terminating entry */ +}; + +static struct usb_driver btmtk_usb_driver = { + .name = "btmtk_usb", + .probe = btmtk_usb_probe, + .disconnect = btmtk_usb_disconnect, +#ifdef CONFIG_PM + .suspend = btmtk_usb_suspend, + .resume = btmtk_usb_resume, +#endif + .id_table = btmtk_usb_table, + .supports_autosuspend = 1, + .disable_hub_initiated_lpm = 1, +}; + +module_usb_driver(btmtk_usb_driver); + +MODULE_DESCRIPTION("Mediatek Bluetooth USB driver ver " VERSION); +MODULE_VERSION(VERSION); +MODULE_LICENSE("GPL"); +MODULE_FIRMWARE(MT7650_FIRMWARE); +MODULE_FIRMWARE(MT7662_FIRMWARE); diff --git a/drivers/staging/btmtk_usb/btmtk_usb.h b/drivers/staging/btmtk_usb/btmtk_usb.h new file mode 100644 index 000000000000..12f0d3b27bfe --- /dev/null +++ b/drivers/staging/btmtk_usb/btmtk_usb.h @@ -0,0 +1,138 @@ +/* + * MediaTek Bluetooth USB Driver + * + * Copyright (C) 2013, MediaTek co. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * or on the worldwide web at + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + */ + +#ifndef __BTMTK_USB_H__ +#define __BTMTK_USB_H_ + +/* Memory map for MTK BT */ + +/* SYS Control */ +#define SYSCTL 0x400000 + +/* WLAN */ +#define WLAN 0x410000 + +/* MCUCTL */ +#define INT_LEVEL 0x0718 +#define COM_REG0 0x0730 +#define SEMAPHORE_00 0x07B0 +#define SEMAPHORE_01 0x07B4 +#define SEMAPHORE_02 0x07B8 +#define SEMAPHORE_03 0x07BC + +/* Chip definition */ + +#define CONTROL_TIMEOUT_JIFFIES ((300 * HZ) / 100) +#define DEVICE_VENDOR_REQUEST_OUT 0x40 +#define DEVICE_VENDOR_REQUEST_IN 0xc0 +#define DEVICE_CLASS_REQUEST_OUT 0x20 + +#define BTUSB_MAX_ISOC_FRAMES 10 +#define BTUSB_INTR_RUNNING 0 +#define BTUSB_BULK_RUNNING 1 +#define BTUSB_ISOC_RUNNING 2 +#define BTUSB_SUSPENDING 3 +#define BTUSB_DID_ISO_RESUME 4 + +/* ROM Patch */ +#define PATCH_HCI_HEADER_SIZE 4 +#define PATCH_WMT_HEADER_SIZE 5 +#define PATCH_HEADER_SIZE (PATCH_HCI_HEADER_SIZE + PATCH_WMT_HEADER_SIZE) +#define UPLOAD_PATCH_UNIT 2048 +#define PATCH_INFO_SIZE 30 +#define PATCH_PHASE1 1 +#define PATCH_PHASE2 2 +#define PATCH_PHASE3 3 + +struct btmtk_usb_data { + struct hci_dev *hdev; + struct usb_device *udev; + struct usb_interface *intf; + struct usb_interface *isoc; + + spinlock_t lock; + + unsigned long flags; + struct work_struct work; + struct work_struct waker; + + struct usb_anchor tx_anchor; + struct usb_anchor intr_anchor; + struct usb_anchor bulk_anchor; + struct usb_anchor isoc_anchor; + struct usb_anchor deferred; + int tx_in_flight; + spinlock_t txlock; + + struct usb_endpoint_descriptor *intr_ep; + struct usb_endpoint_descriptor *bulk_tx_ep; + struct usb_endpoint_descriptor *bulk_rx_ep; + struct usb_endpoint_descriptor *isoc_tx_ep; + struct usb_endpoint_descriptor *isoc_rx_ep; + + __u8 cmdreq_type; + + unsigned int sco_num; + int isoc_altsetting; + int suspend_count; + + /* request for different io operation */ + u8 w_request; + u8 r_request; + + /* io buffer for usb control transfer */ + char *io_buf; + + struct semaphore fw_upload_sem; + + /* unsigned char *fw_image; */ + /* unsigned char *rom_patch; */ + const struct firmware *firmware; + u32 chip_id; + u8 need_load_fw; + u8 need_load_rom_patch; + u32 rom_patch_offset; + u32 rom_patch_len; +}; + +static inline int is_mt7630(struct btmtk_usb_data *data) +{ + return ((data->chip_id & 0xffff0000) == 0x76300000); +} + +static inline int is_mt7650(struct btmtk_usb_data *data) +{ + return ((data->chip_id & 0xffff0000) == 0x76500000); +} + +static inline int is_mt7632(struct btmtk_usb_data *data) +{ + return ((data->chip_id & 0xffff0000) == 0x76320000); +} + +static inline int is_mt7662(struct btmtk_usb_data *data) +{ + return ((data->chip_id & 0xffff0000) == 0x76620000); +} + +#endif diff --git a/drivers/staging/ced1401/ced_ioc.c b/drivers/staging/ced1401/ced_ioc.c index 82a333f6433e..2dbaf39e2fc2 100644 --- a/drivers/staging/ced1401/ced_ioc.c +++ b/drivers/staging/ced1401/ced_ioc.c @@ -37,13 +37,14 @@ ** ** Empties the Output buffer and sets int lines. Used from user level only ****************************************************************************/ -void FlushOutBuff(DEVICE_EXTENSION * pdx) +static void FlushOutBuff(DEVICE_EXTENSION *pdx) { dev_dbg(&pdx->interface->dev, "%s currentState=%d", __func__, pdx->sCurrentState); if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */ return; -// CharSend_Cancel(pdx); /* Kill off any pending I/O */ + /* Kill off any pending I/O */ + /* CharSend_Cancel(pdx); */ spin_lock_irq(&pdx->charOutLock); pdx->dwNumOutput = 0; pdx->dwOutBuffGet = 0; @@ -57,13 +58,14 @@ void FlushOutBuff(DEVICE_EXTENSION * pdx) ** ** Empties the input buffer and sets int lines ****************************************************************************/ -void FlushInBuff(DEVICE_EXTENSION * pdx) +static void FlushInBuff(DEVICE_EXTENSION *pdx) { dev_dbg(&pdx->interface->dev, "%s currentState=%d", __func__, pdx->sCurrentState); if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */ return; -// CharRead_Cancel(pDevObject); /* Kill off any pending I/O */ + /* Kill off any pending I/O */ + /* CharRead_Cancel(pDevObject); */ spin_lock_irq(&pdx->charInLock); pdx->dwNumInput = 0; pdx->dwInBuffGet = 0; @@ -77,11 +79,11 @@ void FlushInBuff(DEVICE_EXTENSION * pdx) ** Utility routine to copy chars into the output buffer and fire them off. ** called from user mode, holds charOutLock. ****************************************************************************/ -static int PutChars(DEVICE_EXTENSION * pdx, const char *pCh, +static int PutChars(DEVICE_EXTENSION *pdx, const char *pCh, unsigned int uCount) { int iReturn; - spin_lock_irq(&pdx->charOutLock); // get the output spin lock + spin_lock_irq(&pdx->charOutLock); /* get the output spin lock */ if ((OUTBUF_SZ - pdx->dwNumOutput) >= uCount) { unsigned int u; for (u = 0; u < uCount; u++) { @@ -91,9 +93,9 @@ static int PutChars(DEVICE_EXTENSION * pdx, const char *pCh, } pdx->dwNumOutput += uCount; spin_unlock_irq(&pdx->charOutLock); - iReturn = SendChars(pdx); // ...give a chance to transmit data + iReturn = SendChars(pdx); /* ...give a chance to transmit data */ } else { - iReturn = U14ERR_NOOUT; // no room at the out (ha-ha) + iReturn = U14ERR_NOOUT; /* no room at the out (ha-ha) */ spin_unlock_irq(&pdx->charOutLock); } return iReturn; @@ -104,26 +106,25 @@ static int PutChars(DEVICE_EXTENSION * pdx, const char *pCh, ** trigger an output transfer if this is appropriate. User mode. ** Holds the io_mutex *****************************************************************************/ -int SendString(DEVICE_EXTENSION * pdx, const char __user * pData, +int SendString(DEVICE_EXTENSION *pdx, const char __user *pData, unsigned int n) { - int iReturn = U14ERR_NOERROR; // assume all will be well - char buffer[OUTBUF_SZ + 1]; // space in our address space for characters - if (n > OUTBUF_SZ) // check space in local buffer... - return U14ERR_NOOUT; // ...too many characters + int iReturn = U14ERR_NOERROR; /* assume all will be well */ + char buffer[OUTBUF_SZ + 1]; /* space in our address space for characters */ + if (n > OUTBUF_SZ) /* check space in local buffer... */ + return U14ERR_NOOUT; /* ...too many characters */ if (copy_from_user(buffer, pData, n)) return -EFAULT; - buffer[n] = 0; // terminate for debug purposes + buffer[n] = 0; /* terminate for debug purposes */ - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - if (n > 0) // do nothing if nowt to do! - { + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ + if (n > 0) { /* do nothing if nowt to do! */ dev_dbg(&pdx->interface->dev, "%s n=%d>%s<", __func__, n, buffer); iReturn = PutChars(pdx, buffer, n); } - Allowi(pdx); // make sure we have input int + Allowi(pdx); /* make sure we have input int */ mutex_unlock(&pdx->io_mutex); return iReturn; @@ -134,13 +135,13 @@ int SendString(DEVICE_EXTENSION * pdx, const char __user * pData, ** ** Sends a single character to the 1401. User mode, holds io_mutex. ****************************************************************************/ -int SendChar(DEVICE_EXTENSION * pdx, char c) +int SendChar(DEVICE_EXTENSION *pdx, char c) { int iReturn; - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ iReturn = PutChars(pdx, &c, 1); dev_dbg(&pdx->interface->dev, "SendChar >%c< (0x%02x)", c, c); - Allowi(pdx); // Make sure char reads are running + Allowi(pdx); /* Make sure char reads are running */ mutex_unlock(&pdx->io_mutex); return iReturn; } @@ -171,20 +172,20 @@ int SendChar(DEVICE_EXTENSION * pdx, char c) ** ** return error code (U14ERR_NOERROR for OK) */ -int Get1401State(DEVICE_EXTENSION * pdx, __u32 * state, __u32 * error) +int Get1401State(DEVICE_EXTENSION *pdx, __u32 *state, __u32 *error) { int nGot; dev_dbg(&pdx->interface->dev, "Get1401State() entry"); - *state = 0xFFFFFFFF; // Start off with invalid state + *state = 0xFFFFFFFF; /* Start off with invalid state */ nGot = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0), GET_STATUS, (D_TO_H | VENDOR | DEVREQ), 0, 0, pdx->statBuf, sizeof(pdx->statBuf), HZ); if (nGot != sizeof(pdx->statBuf)) { dev_err(&pdx->interface->dev, "Get1401State() FAILED, return code %d", nGot); - pdx->sCurrentState = U14ERR_TIME; // Indicate that things are very wrong indeed - *state = 0; // Force status values to a known state + pdx->sCurrentState = U14ERR_TIME; /* Indicate that things are very wrong indeed */ + *state = 0; /* Force status values to a known state */ *error = 0; } else { int nDevice; @@ -192,17 +193,16 @@ int Get1401State(DEVICE_EXTENSION * pdx, __u32 * state, __u32 * error) "Get1401State() Success, state: 0x%x, 0x%x", pdx->statBuf[0], pdx->statBuf[1]); - *state = pdx->statBuf[0]; // Return the state values to the calling code + *state = pdx->statBuf[0]; /* Return the state values to the calling code */ *error = pdx->statBuf[1]; - nDevice = pdx->udev->descriptor.bcdDevice >> 8; // 1401 type code value - switch (nDevice) // so we can clean up current state - { + nDevice = pdx->udev->descriptor.bcdDevice >> 8; /* 1401 type code value */ + switch (nDevice) { /* so we can clean up current state */ case 0: pdx->sCurrentState = U14ERR_U1401; break; - default: // allow lots of device codes for future 1401s + default: /* allow lots of device codes for future 1401s */ if ((nDevice >= 1) && (nDevice <= 23)) pdx->sCurrentState = (short)(nDevice + 6); else @@ -219,7 +219,7 @@ int Get1401State(DEVICE_EXTENSION * pdx, __u32 * state, __u32 * error) ** ** Kills off staged read\write request from the USB if one is pending. ****************************************************************************/ -int ReadWrite_Cancel(DEVICE_EXTENSION * pdx) +int ReadWrite_Cancel(DEVICE_EXTENSION *pdx) { dev_dbg(&pdx->interface->dev, "ReadWrite_Cancel entry %d", pdx->bStagedUrbPending); @@ -227,24 +227,23 @@ int ReadWrite_Cancel(DEVICE_EXTENSION * pdx) int ntStatus = STATUS_SUCCESS; bool bResult = false; unsigned int i; - // We can fill this in when we know how we will implement the staged transfer stuff + /* We can fill this in when we know how we will implement the staged transfer stuff */ spin_lock_irq(&pdx->stagedLock); - if (pdx->bStagedUrbPending) // anything to be cancelled? May need more... - { + if (pdx->bStagedUrbPending) { /* anything to be cancelled? May need more... */ dev_info(&pdx->interface - dev, "ReadWrite_Cancel about to cancel Urb"); - - // KeClearEvent(&pdx->StagingDoneEvent); // Clear the staging done flag + /* Clear the staging done flag */ + /* KeClearEvent(&pdx->StagingDoneEvent); */ USB_ASSERT(pdx->pStagedIrp != NULL); - // Release the spinlock first otherwise the completion routine may hang - // on the spinlock while this function hands waiting for the event. + /* Release the spinlock first otherwise the completion routine may hang */ + /* on the spinlock while this function hands waiting for the event. */ spin_unlock_irq(&pdx->stagedLock); - bResult = IoCancelIrp(pdx->pStagedIrp); // Actually do the cancel + bResult = IoCancelIrp(pdx->pStagedIrp); /* Actually do the cancel */ if (bResult) { LARGE_INTEGER timeout; - timeout.QuadPart = -10000000; // Use a timeout of 1 second + timeout.QuadPart = -10000000; /* Use a timeout of 1 second */ dev_info(&pdx->interface - dev, "ReadWrite_Cancel about to wait till done"); ntStatus = @@ -274,14 +273,14 @@ int ReadWrite_Cancel(DEVICE_EXTENSION * pdx) ** InSelfTest - utility to check in self test. Return 1 for ST, 0 for not or ** a -ve error code if we failed for some reason. ***************************************************************************/ -static int InSelfTest(DEVICE_EXTENSION * pdx, unsigned int *pState) +static int InSelfTest(DEVICE_EXTENSION *pdx, unsigned int *pState) { unsigned int state, error; - int iReturn = Get1401State(pdx, &state, &error); // see if in self-test - if (iReturn == U14ERR_NOERROR) // if all still OK - iReturn = (state == (unsigned int)-1) || // TX problem or... - ((state & 0xff) == 0x80); // ...self test - *pState = state; // return actual state + int iReturn = Get1401State(pdx, &state, &error); /* see if in self-test */ + if (iReturn == U14ERR_NOERROR) /* if all still OK */ + iReturn = (state == (unsigned int)-1) || /* TX problem or... */ + ((state & 0xff) == 0x80); /* ...self test */ + *pState = state; /* return actual state */ return iReturn; } @@ -303,48 +302,45 @@ static int InSelfTest(DEVICE_EXTENSION * pdx, unsigned int *pState) ** ** Returns TRUE if a 1401 detected and OK, else FALSE ****************************************************************************/ -bool Is1401(DEVICE_EXTENSION * pdx) +bool Is1401(DEVICE_EXTENSION *pdx) { int iReturn; dev_dbg(&pdx->interface->dev, "%s", __func__); - ced_draw_down(pdx); // wait for, then kill outstanding Urbs - FlushInBuff(pdx); // Clear out input buffer & pipe - FlushOutBuff(pdx); // Clear output buffer & pipe + ced_draw_down(pdx); /* wait for, then kill outstanding Urbs */ + FlushInBuff(pdx); /* Clear out input buffer & pipe */ + FlushOutBuff(pdx); /* Clear output buffer & pipe */ - // The next call returns 0 if OK, but has returned 1 in the past, meaning that - // usb_unlock_device() is needed... now it always is + /* The next call returns 0 if OK, but has returned 1 in the past, meaning that */ + /* usb_unlock_device() is needed... now it always is */ iReturn = usb_lock_device_for_reset(pdx->udev, pdx->interface); - // release the io_mutex because if we don't, we will deadlock due to system - // calls back into the driver. - mutex_unlock(&pdx->io_mutex); // locked, so we will not get system calls - if (iReturn >= 0) // if we failed - { - iReturn = usb_reset_device(pdx->udev); // try to do the reset - usb_unlock_device(pdx->udev); // undo the lock + /* release the io_mutex because if we don't, we will deadlock due to system */ + /* calls back into the driver. */ + mutex_unlock(&pdx->io_mutex); /* locked, so we will not get system calls */ + if (iReturn >= 0) { /* if we failed */ + iReturn = usb_reset_device(pdx->udev); /* try to do the reset */ + usb_unlock_device(pdx->udev); /* undo the lock */ } - mutex_lock(&pdx->io_mutex); // hold stuff off while we wait - pdx->dwDMAFlag = MODE_CHAR; // Clear DMA mode flag regardless! - if (iReturn == 0) // if all is OK still - { + mutex_lock(&pdx->io_mutex); /* hold stuff off while we wait */ + pdx->dwDMAFlag = MODE_CHAR; /* Clear DMA mode flag regardless! */ + if (iReturn == 0) { /* if all is OK still */ unsigned int state; - iReturn = InSelfTest(pdx, &state); // see if likely in self test - if (iReturn > 0) // do we need to wait for self-test? - { - unsigned long ulTimeOut = jiffies + 30 * HZ; // when to give up + iReturn = InSelfTest(pdx, &state); /* see if likely in self test */ + if (iReturn > 0) { /* do we need to wait for self-test? */ + unsigned long ulTimeOut = jiffies + 30 * HZ; /* when to give up */ while ((iReturn > 0) && time_before(jiffies, ulTimeOut)) { - schedule(); // let other stuff run - iReturn = InSelfTest(pdx, &state); // see if done yet + schedule(); /* let other stuff run */ + iReturn = InSelfTest(pdx, &state); /* see if done yet */ } } - if (iReturn == 0) // if all is OK... - iReturn = state == 0; // then success is that the state is 0 + if (iReturn == 0) /* if all is OK... */ + iReturn = state == 0; /* then success is that the state is 0 */ } else - iReturn = 0; // we failed - pdx->bForceReset = false; // Clear forced reset flag now + iReturn = 0; /* we failed */ + pdx->bForceReset = false; /* Clear forced reset flag now */ return iReturn > 0; } @@ -363,45 +359,42 @@ bool Is1401(DEVICE_EXTENSION * pdx) ** ** The return value is TRUE if a useable 1401 is found, FALSE if not */ -bool QuickCheck(DEVICE_EXTENSION * pdx, bool bTestBuff, bool bCanReset) +bool QuickCheck(DEVICE_EXTENSION *pdx, bool bTestBuff, bool bCanReset) { - bool bRet = false; // assume it will fail and we will reset + bool bRet = false; /* assume it will fail and we will reset */ bool bShortTest; - bShortTest = ((pdx->dwDMAFlag == MODE_CHAR) && // no DMA running - (!pdx->bForceReset) && // Not had a real reset forced - (pdx->sCurrentState >= U14ERR_STD)); // No 1401 errors stored + bShortTest = ((pdx->dwDMAFlag == MODE_CHAR) && /* no DMA running */ + (!pdx->bForceReset) && /* Not had a real reset forced */ + (pdx->sCurrentState >= U14ERR_STD)); /* No 1401 errors stored */ dev_dbg(&pdx->interface->dev, "%s DMAFlag:%d, state:%d, force:%d, testBuff:%d, short:%d", __func__, pdx->dwDMAFlag, pdx->sCurrentState, pdx->bForceReset, bTestBuff, bShortTest); - if ((bTestBuff) && // Buffer check requested, and... - (pdx->dwNumInput || pdx->dwNumOutput)) // ...characters were in the buffer? - { - bShortTest = false; // Then do the full test + if ((bTestBuff) && /* Buffer check requested, and... */ + (pdx->dwNumInput || pdx->dwNumOutput)) { /* ...characters were in the buffer? */ + bShortTest = false; /* Then do the full test */ dev_dbg(&pdx->interface->dev, "%s will reset as buffers not empty", __func__); } - if (bShortTest || !bCanReset) // Still OK to try the short test? - { // Always test if no reset - we want state update + if (bShortTest || !bCanReset) { /* Still OK to try the short test? */ + /* Always test if no reset - we want state update */ unsigned int state, error; dev_dbg(&pdx->interface->dev, "%s->Get1401State", __func__); - if (Get1401State(pdx, &state, &error) == U14ERR_NOERROR) // Check on the 1401 state - { - if ((state & 0xFF) == 0) // If call worked, check the status value - bRet = true; // If that was zero, all is OK, no reset needed + if (Get1401State(pdx, &state, &error) == U14ERR_NOERROR) { /* Check on the 1401 state */ + if ((state & 0xFF) == 0) /* If call worked, check the status value */ + bRet = true; /* If that was zero, all is OK, no reset needed */ } } - if (!bRet && bCanReset) // If all not OK, then - { + if (!bRet && bCanReset) { /* If all not OK, then */ dev_info(&pdx->interface->dev, "%s->Is1401 %d %d %d %d", __func__, bShortTest, pdx->sCurrentState, bTestBuff, pdx->bForceReset); - bRet = Is1401(pdx); // do full test + bRet = Is1401(pdx); /* do full test */ } return bRet; @@ -412,11 +405,11 @@ bool QuickCheck(DEVICE_EXTENSION * pdx, bool bTestBuff, bool bCanReset) ** ** Resets the 1401 and empties the i/o buffers *****************************************************************************/ -int Reset1401(DEVICE_EXTENSION * pdx) +int Reset1401(DEVICE_EXTENSION *pdx) { - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ dev_dbg(&pdx->interface->dev, "ABout to call QuickCheck"); - QuickCheck(pdx, true, true); // Check 1401, reset if not OK + QuickCheck(pdx, true, true); /* Check 1401, reset if not OK */ mutex_unlock(&pdx->io_mutex); return U14ERR_NOERROR; } @@ -426,30 +419,29 @@ int Reset1401(DEVICE_EXTENSION * pdx) ** ** Gets a single character from the 1401 ****************************************************************************/ -int GetChar(DEVICE_EXTENSION * pdx) +int GetChar(DEVICE_EXTENSION *pdx) { - int iReturn = U14ERR_NOIN; // assume we will get nothing - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o + int iReturn = U14ERR_NOIN; /* assume we will get nothing */ + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ dev_dbg(&pdx->interface->dev, "GetChar"); - Allowi(pdx); // Make sure char reads are running - SendChars(pdx); // and send any buffered chars + Allowi(pdx); /* Make sure char reads are running */ + SendChars(pdx); /* and send any buffered chars */ spin_lock_irq(&pdx->charInLock); - if (pdx->dwNumInput > 0) // worth looking - { + if (pdx->dwNumInput > 0) { /* worth looking */ iReturn = pdx->inputBuffer[pdx->dwInBuffGet++]; if (pdx->dwInBuffGet >= INBUF_SZ) pdx->dwInBuffGet = 0; pdx->dwNumInput--; } else - iReturn = U14ERR_NOIN; // no input data to read + iReturn = U14ERR_NOIN; /* no input data to read */ spin_unlock_irq(&pdx->charInLock); - Allowi(pdx); // Make sure char reads are running + Allowi(pdx); /* Make sure char reads are running */ - mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o + mutex_unlock(&pdx->io_mutex); /* Protect disconnect from new i/o */ return iReturn; } @@ -464,46 +456,43 @@ int GetChar(DEVICE_EXTENSION * pdx) ** returns the count of characters (including the terminator, or 0 if none ** or a negative error code. ****************************************************************************/ -int GetString(DEVICE_EXTENSION * pdx, char __user * pUser, int n) +int GetString(DEVICE_EXTENSION *pdx, char __user *pUser, int n) { - int nAvailable; // character in the buffer + int nAvailable; /* character in the buffer */ int iReturn = U14ERR_NOIN; if (n <= 0) return -ENOMEM; - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - Allowi(pdx); // Make sure char reads are running - SendChars(pdx); // and send any buffered chars + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ + Allowi(pdx); /* Make sure char reads are running */ + SendChars(pdx); /* and send any buffered chars */ spin_lock_irq(&pdx->charInLock); - nAvailable = pdx->dwNumInput; // characters available now - if (nAvailable > n) // read max of space in pUser... - nAvailable = n; // ...or input characters + nAvailable = pdx->dwNumInput; /* characters available now */ + if (nAvailable > n) /* read max of space in pUser... */ + nAvailable = n; /* ...or input characters */ - if (nAvailable > 0) // worth looking? - { - char buffer[INBUF_SZ + 1]; // space for a linear copy of data + if (nAvailable > 0) { /* worth looking? */ + char buffer[INBUF_SZ + 1]; /* space for a linear copy of data */ int nGot = 0; - int nCopyToUser; // number to copy to user + int nCopyToUser; /* number to copy to user */ char cData; do { cData = pdx->inputBuffer[pdx->dwInBuffGet++]; - if (cData == CR_CHAR) // replace CR with zero + if (cData == CR_CHAR) /* replace CR with zero */ cData = (char)0; if (pdx->dwInBuffGet >= INBUF_SZ) - pdx->dwInBuffGet = 0; // wrap buffer pointer + pdx->dwInBuffGet = 0; /* wrap buffer pointer */ - buffer[nGot++] = cData; // save the output - } - while ((nGot < nAvailable) && cData); + buffer[nGot++] = cData; /* save the output */ + } while ((nGot < nAvailable) && cData); - nCopyToUser = nGot; // what to copy... - if (cData) // do we need null - { - buffer[nGot] = (char)0; // make it tidy - if (nGot < n) // if space in user buffer... - ++nCopyToUser; // ...copy the 0 as well. + nCopyToUser = nGot; /* what to copy... */ + if (cData) { /* do we need null */ + buffer[nGot] = (char)0; /* make it tidy */ + if (nGot < n) /* if space in user buffer... */ + ++nCopyToUser; /* ...copy the 0 as well. */ } pdx->dwNumInput -= nGot; @@ -514,12 +503,12 @@ int GetString(DEVICE_EXTENSION * pdx, char __user * pUser, int n) if (copy_to_user(pUser, buffer, nCopyToUser)) iReturn = -EFAULT; else - iReturn = nGot; // report characters read + iReturn = nGot; /* report characters read */ } else spin_unlock_irq(&pdx->charInLock); - Allowi(pdx); // Make sure char reads are running - mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o + Allowi(pdx); /* Make sure char reads are running */ + mutex_unlock(&pdx->io_mutex); /* Protect disconnect from new i/o */ return iReturn; } @@ -527,14 +516,14 @@ int GetString(DEVICE_EXTENSION * pdx, char __user * pUser, int n) /******************************************************************************* ** Get count of characters in the inout buffer. *******************************************************************************/ -int Stat1401(DEVICE_EXTENSION * pdx) +int Stat1401(DEVICE_EXTENSION *pdx) { int iReturn; - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - Allowi(pdx); // make sure we allow pending chars - SendChars(pdx); // in both directions - iReturn = pdx->dwNumInput; // no lock as single read - mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ + Allowi(pdx); /* make sure we allow pending chars */ + SendChars(pdx); /* in both directions */ + iReturn = pdx->dwNumInput; /* no lock as single read */ + mutex_unlock(&pdx->io_mutex); /* Protect disconnect from new i/o */ return iReturn; } @@ -545,32 +534,30 @@ int Stat1401(DEVICE_EXTENSION * pdx) ** any fancy interlocks as we only read the interrupt routine data, and the ** system is arranged so nothing can be destroyed. ****************************************************************************/ -int LineCount(DEVICE_EXTENSION * pdx) +int LineCount(DEVICE_EXTENSION *pdx) { - int iReturn = 0; // will be count of line ends + int iReturn = 0; /* will be count of line ends */ - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - Allowi(pdx); // Make sure char reads are running - SendChars(pdx); // and send any buffered chars - spin_lock_irq(&pdx->charInLock); // Get protection + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ + Allowi(pdx); /* Make sure char reads are running */ + SendChars(pdx); /* and send any buffered chars */ + spin_lock_irq(&pdx->charInLock); /* Get protection */ - if (pdx->dwNumInput > 0) // worth looking? - { - unsigned int dwIndex = pdx->dwInBuffGet; // start at first available - unsigned int dwEnd = pdx->dwInBuffPut; // Position for search end + if (pdx->dwNumInput > 0) { /* worth looking? */ + unsigned int dwIndex = pdx->dwInBuffGet; /* start at first available */ + unsigned int dwEnd = pdx->dwInBuffPut; /* Position for search end */ do { if (pdx->inputBuffer[dwIndex++] == CR_CHAR) - ++iReturn; // inc count if CR + ++iReturn; /* inc count if CR */ - if (dwIndex >= INBUF_SZ) // see if we fall off buff + if (dwIndex >= INBUF_SZ) /* see if we fall off buff */ dwIndex = 0; - } - while (dwIndex != dwEnd); // go to last available + } while (dwIndex != dwEnd); /* go to last available */ } spin_unlock_irq(&pdx->charInLock); dev_dbg(&pdx->interface->dev, "LineCount returned %d", iReturn); - mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o + mutex_unlock(&pdx->io_mutex); /* Protect disconnect from new i/o */ return iReturn; } @@ -579,14 +566,14 @@ int LineCount(DEVICE_EXTENSION * pdx) ** ** Gets the space in the output buffer. Called from user code. *****************************************************************************/ -int GetOutBufSpace(DEVICE_EXTENSION * pdx) +int GetOutBufSpace(DEVICE_EXTENSION *pdx) { int iReturn; - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - SendChars(pdx); // send any buffered chars - iReturn = (int)(OUTBUF_SZ - pdx->dwNumOutput); // no lock needed for single read + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ + SendChars(pdx); /* send any buffered chars */ + iReturn = (int)(OUTBUF_SZ - pdx->dwNumOutput); /* no lock needed for single read */ dev_dbg(&pdx->interface->dev, "OutBufSpace %d", iReturn); - mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o + mutex_unlock(&pdx->io_mutex); /* Protect disconnect from new i/o */ return iReturn; } @@ -597,7 +584,7 @@ int GetOutBufSpace(DEVICE_EXTENSION * pdx) ** Clears up a transfer area. This is always called in the context of a user ** request, never from a call-back. ****************************************************************************/ -int ClearArea(DEVICE_EXTENSION * pdx, int nArea) +int ClearArea(DEVICE_EXTENSION *pdx, int nArea) { int iReturn = U14ERR_NOERROR; @@ -606,14 +593,14 @@ int ClearArea(DEVICE_EXTENSION * pdx, int nArea) dev_err(&pdx->interface->dev, "%s Attempt to clear area %d", __func__, nArea); } else { - TRANSAREA *pTA = &pdx->rTransDef[nArea]; // to save typing - if (!pTA->bUsed) // if not used... - iReturn = U14ERR_NOTSET; // ...nothing to be done + TRANSAREA *pTA = &pdx->rTransDef[nArea]; /* to save typing */ + if (!pTA->bUsed) /* if not used... */ + iReturn = U14ERR_NOTSET; /* ...nothing to be done */ else { - // We must save the memory we return as we shouldn't mess with memory while - // holding a spin lock. - struct page **pPages = 0; // save page address list - int nPages = 0; // and number of pages + /* We must save the memory we return as we shouldn't mess with memory while */ + /* holding a spin lock. */ + struct page **pPages = NULL; /*save page address list*/ + int nPages = 0; /* and number of pages */ int np; dev_dbg(&pdx->interface->dev, "%s area %d", __func__, @@ -621,33 +608,32 @@ int ClearArea(DEVICE_EXTENSION * pdx, int nArea) spin_lock_irq(&pdx->stagedLock); if ((pdx->StagedId == nArea) && (pdx->dwDMAFlag > MODE_CHAR)) { - iReturn = U14ERR_UNLOCKFAIL; // cannot delete as in use + iReturn = U14ERR_UNLOCKFAIL; /* cannot delete as in use */ dev_err(&pdx->interface->dev, "%s call on area %d while active", __func__, nArea); } else { - pPages = pTA->pPages; // save page address list - nPages = pTA->nPages; // and page count - if (pTA->dwEventSz) // if events flagging in use - wake_up_interruptible(&pTA->wqEvent); // release anything that was waiting + pPages = pTA->pPages; /* save page address list */ + nPages = pTA->nPages; /* and page count */ + if (pTA->dwEventSz) /* if events flagging in use */ + wake_up_interruptible(&pTA->wqEvent); /* release anything that was waiting */ if (pdx->bXFerWaiting && (pdx->rDMAInfo.wIdent == nArea)) - pdx->bXFerWaiting = false; // Cannot have pending xfer if area cleared + pdx->bXFerWaiting = false; /* Cannot have pending xfer if area cleared */ - // Clean out the TRANSAREA except for the wait queue, which is at the end - // This sets bUsed to false and dwEventSz to 0 to say area not used and no events. + /* Clean out the TRANSAREA except for the wait queue, which is at the end */ + /* This sets bUsed to false and dwEventSz to 0 to say area not used and no events. */ memset(pTA, 0, sizeof(TRANSAREA) - sizeof(wait_queue_head_t)); } spin_unlock_irq(&pdx->stagedLock); - if (pPages) // if we decided to release the memory - { - // Now we must undo the pinning down of the pages. We will assume the worst and mark - // all the pages as dirty. Don't be tempted to move this up above as you must not be - // holding a spin lock to do this stuff as it is not atomic. + if (pPages) { /* if we decided to release the memory */ + /* Now we must undo the pinning down of the pages. We will assume the worst and mark */ + /* all the pages as dirty. Don't be tempted to move this up above as you must not be */ + /* holding a spin lock to do this stuff as it is not atomic. */ dev_dbg(&pdx->interface->dev, "%s nPages=%d", __func__, nPages); @@ -674,29 +660,29 @@ int ClearArea(DEVICE_EXTENSION * pdx, int nArea) ** Sets up a transfer area - the functional part. Called by both ** SetTransfer and SetCircular. ****************************************************************************/ -static int SetArea(DEVICE_EXTENSION * pdx, int nArea, char __user * puBuf, +static int SetArea(DEVICE_EXTENSION *pdx, int nArea, char __user *puBuf, unsigned int dwLength, bool bCircular, bool bCircToHost) { - // Start by working out the page aligned start of the area and the size - // of the area in pages, allowing for the start not being aligned and the - // end needing to be rounded up to a page boundary. + /* Start by working out the page aligned start of the area and the size */ + /* of the area in pages, allowing for the start not being aligned and the */ + /* end needing to be rounded up to a page boundary. */ unsigned long ulStart = ((unsigned long)puBuf) & PAGE_MASK; unsigned int ulOffset = ((unsigned long)puBuf) & (PAGE_SIZE - 1); int len = (dwLength + ulOffset + PAGE_SIZE - 1) >> PAGE_SHIFT; - TRANSAREA *pTA = &pdx->rTransDef[nArea]; // to save typing - struct page **pPages = 0; // space for page tables - int nPages = 0; // and number of pages + TRANSAREA *pTA = &pdx->rTransDef[nArea]; /* to save typing */ + struct page **pPages = NULL; /* space for page tables */ + int nPages = 0; /* and number of pages */ - int iReturn = ClearArea(pdx, nArea); // see if OK to use this area - if ((iReturn != U14ERR_NOTSET) && // if not area unused and... - (iReturn != U14ERR_NOERROR)) // ...not all OK, then... - return iReturn; // ...we cannot use this area + int iReturn = ClearArea(pdx, nArea); /* see if OK to use this area */ + if ((iReturn != U14ERR_NOTSET) && /* if not area unused and... */ + (iReturn != U14ERR_NOERROR)) /* ...not all OK, then... */ + return iReturn; /* ...we cannot use this area */ - if (!access_ok(VERIFY_WRITE, puBuf, dwLength)) // if we cannot access the memory... - return -EFAULT; // ...then we are done + if (!access_ok(VERIFY_WRITE, puBuf, dwLength)) /* if we cannot access the memory... */ + return -EFAULT; /* ...then we are done */ - // Now allocate space to hold the page pointer and virtual address pointer tables + /* Now allocate space to hold the page pointer and virtual address pointer tables */ pPages = kmalloc(len * sizeof(struct page *), GFP_KERNEL); if (!pPages) { iReturn = U14ERR_NOMEMORY; @@ -705,24 +691,23 @@ static int SetArea(DEVICE_EXTENSION * pdx, int nArea, char __user * puBuf, dev_dbg(&pdx->interface->dev, "%s %p, length=%06x, circular %d", __func__, puBuf, dwLength, bCircular); - // To pin down user pages we must first acquire the mapping semaphore. - down_read(¤t->mm->mmap_sem); // get memory map semaphore - nPages = - get_user_pages(current, current->mm, ulStart, len, 1, 0, pPages, 0); - up_read(¤t->mm->mmap_sem); // release the semaphore + /* To pin down user pages we must first acquire the mapping semaphore. */ + down_read(¤t->mm->mmap_sem); /* get memory map semaphore */ + nPages = get_user_pages(current, current->mm, ulStart, len, 1, 0, + pPages, NULL); + up_read(¤t->mm->mmap_sem); /* release the semaphore */ dev_dbg(&pdx->interface->dev, "%s nPages = %d", __func__, nPages); - if (nPages > 0) // if we succeeded - { - // If you are tempted to use page_address (form LDD3), forget it. You MUST use - // kmap() or kmap_atomic() to get a virtual address. page_address will give you - // (null) or at least it does in this context with an x86 machine. + if (nPages > 0) { /* if we succeeded */ + /* If you are tempted to use page_address (form LDD3), forget it. You MUST use */ + /* kmap() or kmap_atomic() to get a virtual address. page_address will give you */ + /* (null) or at least it does in this context with an x86 machine. */ spin_lock_irq(&pdx->stagedLock); - pTA->lpvBuff = puBuf; // keep start of region (user address) - pTA->dwBaseOffset = ulOffset; // save offset in first page to start of xfer - pTA->dwLength = dwLength; // Size if the region in bytes - pTA->pPages = pPages; // list of pages that are used by buffer - pTA->nPages = nPages; // number of pages + pTA->lpvBuff = puBuf; /* keep start of region (user address) */ + pTA->dwBaseOffset = ulOffset; /* save offset in first page to start of xfer */ + pTA->dwLength = dwLength; /* Size if the region in bytes */ + pTA->pPages = pPages; /* list of pages that are used by buffer */ + pTA->nPages = nPages; /* number of pages */ pTA->bCircular = bCircular; pTA->bCircToHost = bCircToHost; @@ -731,10 +716,10 @@ static int SetArea(DEVICE_EXTENSION * pdx, int nArea, char __user * puBuf, pTA->aBlocks[0].dwSize = 0; pTA->aBlocks[1].dwOffset = 0; pTA->aBlocks[1].dwSize = 0; - pTA->bUsed = true; // This is now a used block + pTA->bUsed = true; /* This is now a used block */ spin_unlock_irq(&pdx->stagedLock); - iReturn = U14ERR_NOERROR; // say all was well + iReturn = U14ERR_NOERROR; /* say all was well */ } else { iReturn = U14ERR_LOCKFAIL; goto error; @@ -754,7 +739,7 @@ error: ** unset it. Unsetting will fail if the area is booked, and a transfer to that ** area is in progress. Otherwise, we will release the area and re-assign it. ****************************************************************************/ -int SetTransfer(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD) +int SetTransfer(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD) { int iReturn; TRANSFERDESC td; @@ -765,9 +750,9 @@ int SetTransfer(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD) mutex_lock(&pdx->io_mutex); dev_dbg(&pdx->interface->dev, "%s area:%d, size:%08x", __func__, td.wAreaNum, td.dwLength); - // The strange cast is done so that we don't get warnings in 32-bit linux about the size of the - // pointer. The pointer is always passed as a 64-bit object so that we don't have problems using - // a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system. + /* The strange cast is done so that we don't get warnings in 32-bit linux about the size of the */ + /* pointer. The pointer is always passed as a 64-bit object so that we don't have problems using */ + /* a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system. */ iReturn = SetArea(pdx, td.wAreaNum, (char __user *)((unsigned long)td.lpvBuff), td.dwLength, @@ -780,7 +765,7 @@ int SetTransfer(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD) ** UnSetTransfer ** Erases a transfer area record ****************************************************************************/ -int UnsetTransfer(DEVICE_EXTENSION * pdx, int nArea) +int UnsetTransfer(DEVICE_EXTENSION *pdx, int nArea) { int iReturn; mutex_lock(&pdx->io_mutex); @@ -797,27 +782,26 @@ int UnsetTransfer(DEVICE_EXTENSION * pdx, int nArea) ** pretend that whatever the user asked for was achieved, so we return 1 if ** try to create one, and 0 if they ask to remove (assuming all else was OK). ****************************************************************************/ -int SetEvent(DEVICE_EXTENSION * pdx, TRANSFEREVENT __user * pTE) +int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user *pTE) { int iReturn = U14ERR_NOERROR; TRANSFEREVENT te; - // get a local copy of the data + /* get a local copy of the data */ if (copy_from_user(&te, pTE, sizeof(te))) return -EFAULT; - if (te.wAreaNum >= MAX_TRANSAREAS) // the area must exist + if (te.wAreaNum >= MAX_TRANSAREAS) /* the area must exist */ return U14ERR_BADAREA; else { TRANSAREA *pTA = &pdx->rTransDef[te.wAreaNum]; - mutex_lock(&pdx->io_mutex); // make sure we have no competitor + mutex_lock(&pdx->io_mutex); /* make sure we have no competitor */ spin_lock_irq(&pdx->stagedLock); - if (pTA->bUsed) // area must be in use - { - pTA->dwEventSt = te.dwStart; // set area regions - pTA->dwEventSz = te.dwLength; // set size (0 cancels it) - pTA->bEventToHost = te.wFlags & 1; // set the direction - pTA->iWakeUp = 0; // zero the wake up count + if (pTA->bUsed) { /* area must be in use */ + pTA->dwEventSt = te.dwStart; /* set area regions */ + pTA->dwEventSz = te.dwLength; /* set size (0 cancels it) */ + pTA->bEventToHost = te.wFlags & 1; /* set the direction */ + pTA->iWakeUp = 0; /* zero the wake up count */ } else iReturn = U14ERR_NOTSET; spin_unlock_irq(&pdx->stagedLock); @@ -833,7 +817,7 @@ int SetEvent(DEVICE_EXTENSION * pdx, TRANSFEREVENT __user * pTE) ** of times that a block met the event condition since we last cleared it or ** 0 if timed out, or -ve error (bad area or not set, or signal). ****************************************************************************/ -int WaitEvent(DEVICE_EXTENSION * pdx, int nArea, int msTimeOut) +int WaitEvent(DEVICE_EXTENSION *pdx, int nArea, int msTimeOut) { int iReturn; if ((unsigned)nArea >= MAX_TRANSAREAS) @@ -841,15 +825,15 @@ int WaitEvent(DEVICE_EXTENSION * pdx, int nArea, int msTimeOut) else { int iWait; TRANSAREA *pTA = &pdx->rTransDef[nArea]; - msTimeOut = (msTimeOut * HZ + 999) / 1000; // convert timeout to jiffies + msTimeOut = (msTimeOut * HZ + 999) / 1000; /* convert timeout to jiffies */ - // We cannot wait holding the mutex, but we check the flags while holding - // it. This may well be pointless as another thread could get in between - // releasing it and the wait call. However, this would have to clear the - // iWakeUp flag. However, the !pTA-bUsed may help us in this case. - mutex_lock(&pdx->io_mutex); // make sure we have no competitor - if (!pTA->bUsed || !pTA->dwEventSz) // check something to wait for... - return U14ERR_NOTSET; // ...else we do nothing + /* We cannot wait holding the mutex, but we check the flags while holding */ + /* it. This may well be pointless as another thread could get in between */ + /* releasing it and the wait call. However, this would have to clear the */ + /* iWakeUp flag. However, the !pTA-bUsed may help us in this case. */ + mutex_lock(&pdx->io_mutex); /* make sure we have no competitor */ + if (!pTA->bUsed || !pTA->dwEventSz) /* check something to wait for... */ + return U14ERR_NOTSET; /* ...else we do nothing */ mutex_unlock(&pdx->io_mutex); if (msTimeOut) @@ -863,12 +847,12 @@ int WaitEvent(DEVICE_EXTENSION * pdx, int nArea, int msTimeOut) wait_event_interruptible(pTA->wqEvent, pTA->iWakeUp || !pTA->bUsed); if (iWait) - iReturn = -ERESTARTSYS; // oops - we have had a SIGNAL + iReturn = -ERESTARTSYS; /* oops - we have had a SIGNAL */ else - iReturn = pTA->iWakeUp; // else the wakeup count + iReturn = pTA->iWakeUp; /* else the wakeup count */ spin_lock_irq(&pdx->stagedLock); - pTA->iWakeUp = 0; // clear the flag + pTA->iWakeUp = 0; /* clear the flag */ spin_unlock_irq(&pdx->stagedLock); } return iReturn; @@ -880,17 +864,17 @@ int WaitEvent(DEVICE_EXTENSION * pdx, int nArea, int msTimeOut) ** number of times a block completed since the last call, or 0 if none or a ** negative error. ****************************************************************************/ -int TestEvent(DEVICE_EXTENSION * pdx, int nArea) +int TestEvent(DEVICE_EXTENSION *pdx, int nArea) { int iReturn; if ((unsigned)nArea >= MAX_TRANSAREAS) iReturn = U14ERR_BADAREA; else { TRANSAREA *pTA = &pdx->rTransDef[nArea]; - mutex_lock(&pdx->io_mutex); // make sure we have no competitor + mutex_lock(&pdx->io_mutex); /* make sure we have no competitor */ spin_lock_irq(&pdx->stagedLock); - iReturn = pTA->iWakeUp; // get wakeup count since last call - pTA->iWakeUp = 0; // clear the count + iReturn = pTA->iWakeUp; /* get wakeup count since last call */ + pTA->iWakeUp = 0; /* clear the count */ spin_unlock_irq(&pdx->stagedLock); mutex_unlock(&pdx->io_mutex); } @@ -901,17 +885,17 @@ int TestEvent(DEVICE_EXTENSION * pdx, int nArea) ** GetTransferInfo ** Puts the current state of the 1401 in a TGET_TX_BLOCK. *****************************************************************************/ -int GetTransfer(DEVICE_EXTENSION * pdx, TGET_TX_BLOCK __user * pTX) +int GetTransfer(DEVICE_EXTENSION *pdx, TGET_TX_BLOCK __user *pTX) { int iReturn = U14ERR_NOERROR; unsigned int dwIdent; mutex_lock(&pdx->io_mutex); - dwIdent = pdx->StagedId; // area ident for last xfer + dwIdent = pdx->StagedId; /* area ident for last xfer */ if (dwIdent >= MAX_TRANSAREAS) iReturn = U14ERR_BADAREA; else { - // Return the best information we have - we don't have physical addresses + /* Return the best information we have - we don't have physical addresses */ TGET_TX_BLOCK *tx; tx = kzalloc(sizeof(*tx), GFP_KERNEL); @@ -921,8 +905,8 @@ int GetTransfer(DEVICE_EXTENSION * pdx, TGET_TX_BLOCK __user * pTX) } tx->size = pdx->rTransDef[dwIdent].dwLength; tx->linear = (long long)((long)pdx->rTransDef[dwIdent].lpvBuff); - tx->avail = GET_TX_MAXENTRIES; // how many blocks we could return - tx->used = 1; // number we actually return + tx->avail = GET_TX_MAXENTRIES; /* how many blocks we could return */ + tx->used = 1; /* number we actually return */ tx->entries[0].physical = (long long)(tx->linear + pdx->StagedOffset); tx->entries[0].size = tx->size; @@ -940,7 +924,7 @@ int GetTransfer(DEVICE_EXTENSION * pdx, TGET_TX_BLOCK __user * pTX) ** ** Empties the host i/o buffers ****************************************************************************/ -int KillIO1401(DEVICE_EXTENSION * pdx) +int KillIO1401(DEVICE_EXTENSION *pdx) { dev_dbg(&pdx->interface->dev, "%s", __func__); mutex_lock(&pdx->io_mutex); @@ -955,7 +939,7 @@ int KillIO1401(DEVICE_EXTENSION * pdx) ** Returns a 0 or a 1 for whether DMA is happening. No point holding a mutex ** for this as it only does one read. *****************************************************************************/ -int BlkTransState(DEVICE_EXTENSION * pdx) +int BlkTransState(DEVICE_EXTENSION *pdx) { int iReturn = pdx->dwDMAFlag != MODE_CHAR; dev_dbg(&pdx->interface->dev, "%s = %d", __func__, iReturn); @@ -967,12 +951,12 @@ int BlkTransState(DEVICE_EXTENSION * pdx) ** ** Puts the current state of the 1401 in the Irp return buffer. *****************************************************************************/ -int StateOf1401(DEVICE_EXTENSION * pdx) +int StateOf1401(DEVICE_EXTENSION *pdx) { int iReturn; mutex_lock(&pdx->io_mutex); - QuickCheck(pdx, false, false); // get state up to date, no reset + QuickCheck(pdx, false, false); /* get state up to date, no reset */ iReturn = pdx->sCurrentState; mutex_unlock(&pdx->io_mutex); @@ -987,20 +971,23 @@ int StateOf1401(DEVICE_EXTENSION * pdx) ** Initiates a self-test cycle. The assumption is that we have no interrupts ** active, so we should make sure that this is the case. *****************************************************************************/ -int StartSelfTest(DEVICE_EXTENSION * pdx) +int StartSelfTest(DEVICE_EXTENSION *pdx) { int nGot; mutex_lock(&pdx->io_mutex); dev_dbg(&pdx->interface->dev, "%s", __func__); - ced_draw_down(pdx); // wait for, then kill outstanding Urbs - FlushInBuff(pdx); // Clear out input buffer & pipe - FlushOutBuff(pdx); // Clear output buffer & pipe -// ReadWrite_Cancel(pDeviceObject); /* so things stay tidy */ + ced_draw_down(pdx); /* wait for, then kill outstanding Urbs */ + FlushInBuff(pdx); /* Clear out input buffer & pipe */ + FlushOutBuff(pdx); /* Clear output buffer & pipe */ + /* so things stay tidy */ + /* ReadWrite_Cancel(pDeviceObject); */ pdx->dwDMAFlag = MODE_CHAR; /* Clear DMA mode flags here */ - nGot = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0), DB_SELFTEST, (H_TO_D | VENDOR | DEVREQ), 0, 0, 0, 0, HZ); // allow 1 second timeout - pdx->ulSelfTestTime = jiffies + HZ * 30; // 30 seconds into the future + nGot = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0), + DB_SELFTEST, (H_TO_D | VENDOR | DEVREQ), + 0, 0, NULL, 0, HZ); /* allow 1 second timeout */ + pdx->ulSelfTestTime = jiffies + HZ * 30; /* 30 seconds into the future */ mutex_unlock(&pdx->io_mutex); if (nGot < 0) @@ -1013,53 +1000,49 @@ int StartSelfTest(DEVICE_EXTENSION * pdx) ** ** Check progress of a self-test cycle ****************************************************************************/ -int CheckSelfTest(DEVICE_EXTENSION * pdx, TGET_SELFTEST __user * pGST) +int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST) { unsigned int state, error; int iReturn; - TGET_SELFTEST gst; // local work space - memset(&gst, 0, sizeof(gst)); // clear out the space (sets code 0) + TGET_SELFTEST gst; /* local work space */ + memset(&gst, 0, sizeof(gst)); /* clear out the space (sets code 0) */ mutex_lock(&pdx->io_mutex); dev_dbg(&pdx->interface->dev, "%s", __func__); iReturn = Get1401State(pdx, &state, &error); - if (iReturn == U14ERR_NOERROR) // Only accept zero if it happens twice + if (iReturn == U14ERR_NOERROR) /* Only accept zero if it happens twice */ iReturn = Get1401State(pdx, &state, &error); - if (iReturn != U14ERR_NOERROR) // Self-test can cause comms errors - { // so we assume still testing + if (iReturn != U14ERR_NOERROR) { /* Self-test can cause comms errors */ + /* so we assume still testing */ dev_err(&pdx->interface->dev, "%s Get1401State=%d, assuming still testing", __func__, iReturn); - state = 0x80; // Force still-testing, no error + state = 0x80; /* Force still-testing, no error */ error = 0; iReturn = U14ERR_NOERROR; } - if ((state == -1) && (error == -1)) // If Get1401State had problems - { + if ((state == -1) && (error == -1)) { /* If Get1401State had problems */ dev_err(&pdx->interface->dev, "%s Get1401State failed, assuming still testing", __func__); - state = 0x80; // Force still-testing, no error + state = 0x80; /* Force still-testing, no error */ error = 0; } - if ((state & 0xFF) == 0x80) // If we are still in self-test - { - if (state & 0x00FF0000) // Have we got an error? - { - gst.code = (state & 0x00FF0000) >> 16; // read the error code - gst.x = error & 0x0000FFFF; // Error data X - gst.y = (error & 0xFFFF0000) >> 16; // and data Y + if ((state & 0xFF) == 0x80) { /* If we are still in self-test */ + if (state & 0x00FF0000) { /* Have we got an error? */ + gst.code = (state & 0x00FF0000) >> 16; /* read the error code */ + gst.x = error & 0x0000FFFF; /* Error data X */ + gst.y = (error & 0xFFFF0000) >> 16; /* and data Y */ dev_dbg(&pdx->interface->dev, "Self-test error code %d", gst.code); - } else // No error, check for timeout - { - unsigned long ulNow = jiffies; // get current time + } else { /* No error, check for timeout */ + unsigned long ulNow = jiffies; /* get current time */ if (time_after(ulNow, pdx->ulSelfTestTime)) { - gst.code = -2; // Flag the timeout + gst.code = -2; /* Flag the timeout */ dev_dbg(&pdx->interface->dev, "Self-test timed-out"); } else @@ -1067,16 +1050,16 @@ int CheckSelfTest(DEVICE_EXTENSION * pdx, TGET_SELFTEST __user * pGST) "Self-test on-going"); } } else { - gst.code = -1; // Flag the test is done + gst.code = -1; /* Flag the test is done */ dev_dbg(&pdx->interface->dev, "Self-test done"); } - if (gst.code < 0) // If we have a problem or finished - { // If using the 2890 we should reset properly + if (gst.code < 0) { /* If we have a problem or finished */ + /* If using the 2890 we should reset properly */ if ((pdx->nPipes == 4) && (pdx->s1401Type <= TYPEPOWER)) - Is1401(pdx); // Get 1401 reset and OK + Is1401(pdx); /* Get 1401 reset and OK */ else - QuickCheck(pdx, true, true); // Otherwise check without reset unless problems + QuickCheck(pdx, true, true); /* Otherwise check without reset unless problems */ } mutex_unlock(&pdx->io_mutex); @@ -1091,7 +1074,7 @@ int CheckSelfTest(DEVICE_EXTENSION * pdx, TGET_SELFTEST __user * pGST) ** ** Returns code for standard, plus, micro1401, power1401 or none ****************************************************************************/ -int TypeOf1401(DEVICE_EXTENSION * pdx) +int TypeOf1401(DEVICE_EXTENSION *pdx) { int iReturn = TYPEUNKNOWN; mutex_lock(&pdx->io_mutex); @@ -1100,7 +1083,7 @@ int TypeOf1401(DEVICE_EXTENSION * pdx) switch (pdx->s1401Type) { case TYPE1401: iReturn = U14ERR_STD; - break; // Handle these types directly + break; /* Handle these types directly */ case TYPEPLUS: iReturn = U14ERR_PLUS; break; @@ -1109,9 +1092,9 @@ int TypeOf1401(DEVICE_EXTENSION * pdx) break; default: if ((pdx->s1401Type >= TYPEPOWER) && (pdx->s1401Type <= 25)) - iReturn = pdx->s1401Type + 4; // We can calculate types - else // for up-coming 1401 designs - iReturn = TYPEUNKNOWN; // Don't know or not there + iReturn = pdx->s1401Type + 4; /* We can calculate types */ + else /* for up-coming 1401 designs */ + iReturn = TYPEUNKNOWN; /* Don't know or not there */ } dev_dbg(&pdx->interface->dev, "%s %d", __func__, iReturn); mutex_unlock(&pdx->io_mutex); @@ -1124,13 +1107,13 @@ int TypeOf1401(DEVICE_EXTENSION * pdx) ** ** Returns flags on block transfer abilities ****************************************************************************/ -int TransferFlags(DEVICE_EXTENSION * pdx) +int TransferFlags(DEVICE_EXTENSION *pdx) { - int iReturn = U14TF_MULTIA | U14TF_DIAG | // we always have multiple DMA area - U14TF_NOTIFY | U14TF_CIRCTH; // diagnostics, notify and circular + int iReturn = U14TF_MULTIA | U14TF_DIAG | /* we always have multiple DMA area */ + U14TF_NOTIFY | U14TF_CIRCTH; /* diagnostics, notify and circular */ dev_dbg(&pdx->interface->dev, "%s", __func__); mutex_lock(&pdx->io_mutex); - if (pdx->bIsUSB2) // Set flag for USB2 if appropriate + if (pdx->bIsUSB2) /* Set flag for USB2 if appropriate */ iReturn |= U14TF_USB2; mutex_unlock(&pdx->io_mutex); @@ -1142,12 +1125,16 @@ int TransferFlags(DEVICE_EXTENSION * pdx) ** Issues a debug\diagnostic command to the 1401 along with a 32-bit datum ** This is a utility command used for dbg operations. */ -static int DbgCmd1401(DEVICE_EXTENSION * pdx, unsigned char cmd, +static int DbgCmd1401(DEVICE_EXTENSION *pdx, unsigned char cmd, unsigned int data) { int iReturn; dev_dbg(&pdx->interface->dev, "%s entry", __func__); - iReturn = usb_control_msg(pdx->udev, usb_sndctrlpipe(pdx->udev, 0), cmd, (H_TO_D | VENDOR | DEVREQ), (unsigned short)data, (unsigned short)(data >> 16), 0, 0, HZ); // allow 1 second timeout + iReturn = usb_control_msg(pdx->udev, usb_sndctrlpipe(pdx->udev, 0), cmd, + (H_TO_D | VENDOR | DEVREQ), + (unsigned short)data, + (unsigned short)(data >> 16), NULL, 0, HZ); + /* allow 1 second timeout */ if (iReturn < 0) dev_err(&pdx->interface->dev, "%s fail code=%d", __func__, iReturn); @@ -1160,7 +1147,7 @@ static int DbgCmd1401(DEVICE_EXTENSION * pdx, unsigned char cmd, ** ** Execute the diagnostic peek operation. Uses address, width and repeats. ****************************************************************************/ -int DbgPeek(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) +int DbgPeek(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) { int iReturn; TDBGBLOCK db; @@ -1189,7 +1176,7 @@ int DbgPeek(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) ** Execute the diagnostic poke operation. Parameters are in the CSBLOCK struct ** in order address, size, repeats and value to poke. ****************************************************************************/ -int DbgPoke(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) +int DbgPoke(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) { int iReturn; TDBGBLOCK db; @@ -1218,7 +1205,7 @@ int DbgPoke(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) ** Execute the diagnostic ramp data operation. Parameters are in the CSBLOCK struct ** in order address, default, enable mask, size and repeats. ****************************************************************************/ -int DbgRampData(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) +int DbgRampData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) { int iReturn; TDBGBLOCK db; @@ -1250,7 +1237,7 @@ int DbgRampData(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) ** ** Execute the diagnostic ramp address operation ****************************************************************************/ -int DbgRampAddr(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) +int DbgRampAddr(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) { int iReturn; TDBGBLOCK db; @@ -1280,16 +1267,16 @@ int DbgRampAddr(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) ** ** Retrieve the data resulting from the last debug Peek operation ****************************************************************************/ -int DbgGetData(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) +int DbgGetData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) { int iReturn; TDBGBLOCK db; - memset(&db, 0, sizeof(db)); // fill returned block with 0s + memset(&db, 0, sizeof(db)); /* fill returned block with 0s */ mutex_lock(&pdx->io_mutex); dev_dbg(&pdx->interface->dev, "%s", __func__); - // Read back the last peeked value from the 1401. + /* Read back the last peeked value from the 1401. */ iReturn = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0), DB_DATA, (D_TO_H | VENDOR | DEVREQ), 0, 0, &db.iData, sizeof(db.iData), HZ); @@ -1313,7 +1300,7 @@ int DbgGetData(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) ** Stop any never-ending debug loop, we just call Get1401State for USB ** ****************************************************************************/ -int DbgStopLoop(DEVICE_EXTENSION * pdx) +int DbgStopLoop(DEVICE_EXTENSION *pdx) { int iReturn; unsigned int uState, uErr; @@ -1334,7 +1321,7 @@ int DbgStopLoop(DEVICE_EXTENSION * pdx) ** booked and a transfer to that area is in progress. Otherwise, we will ** release the area and re-assign it. ****************************************************************************/ -int SetCircular(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD) +int SetCircular(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD) { int iReturn; bool bToHost; @@ -1346,11 +1333,11 @@ int SetCircular(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD) mutex_lock(&pdx->io_mutex); dev_dbg(&pdx->interface->dev, "%s area:%d, size:%08x", __func__, td.wAreaNum, td.dwLength); - bToHost = td.eSize != 0; // this is used as the tohost flag + bToHost = td.eSize != 0; /* this is used as the tohost flag */ - // The strange cast is done so that we don't get warnings in 32-bit linux about the size of the - // pointer. The pointer is always passed as a 64-bit object so that we don't have problems using - // a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system. + /* The strange cast is done so that we don't get warnings in 32-bit linux about the size of the */ + /* pointer. The pointer is always passed as a 64-bit object so that we don't have problems using */ + /* a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system. */ iReturn = SetArea(pdx, td.wAreaNum, (char __user *)((unsigned long)td.lpvBuff), td.dwLength, @@ -1364,7 +1351,7 @@ int SetCircular(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD) ** ** Return the next available block of circularly-transferred data. ****************************************************************************/ -int GetCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) +int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user *pCB) { int iReturn = U14ERR_NOERROR; unsigned int nArea; @@ -1377,20 +1364,17 @@ int GetCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) mutex_lock(&pdx->io_mutex); - nArea = cb.nArea; // Retrieve parameters first - cb.dwOffset = 0; // set default result (nothing) + nArea = cb.nArea; /* Retrieve parameters first */ + cb.dwOffset = 0; /* set default result (nothing) */ cb.dwSize = 0; - if (nArea < MAX_TRANSAREAS) // The area number must be OK - { - TRANSAREA *pArea = &pdx->rTransDef[nArea]; // Pointer to relevant info - spin_lock_irq(&pdx->stagedLock); // Lock others out + if (nArea < MAX_TRANSAREAS) { /* The area number must be OK */ + TRANSAREA *pArea = &pdx->rTransDef[nArea]; /* Pointer to relevant info */ + spin_lock_irq(&pdx->stagedLock); /* Lock others out */ - if ((pArea->bUsed) && (pArea->bCircular) && // Must be circular area - (pArea->bCircToHost)) // For now at least must be to host - { - if (pArea->aBlocks[0].dwSize > 0) // Got anything? - { + if ((pArea->bUsed) && (pArea->bCircular) && /* Must be circular area */ + (pArea->bCircToHost)) { /* For now at least must be to host */ + if (pArea->aBlocks[0].dwSize > 0) { /* Got anything? */ cb.dwOffset = pArea->aBlocks[0].dwOffset; cb.dwSize = pArea->aBlocks[0].dwSize; dev_dbg(&pdx->interface->dev, @@ -1416,7 +1400,7 @@ int GetCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) ** ** Frees a block of circularly-transferred data and returns the next one. ****************************************************************************/ -int FreeCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) +int FreeCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user *pCB) { int iReturn = U14ERR_NOERROR; unsigned int nArea, uStart, uSize; @@ -1429,33 +1413,28 @@ int FreeCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) mutex_lock(&pdx->io_mutex); - nArea = cb.nArea; // Retrieve parameters first + nArea = cb.nArea; /* Retrieve parameters first */ uStart = cb.dwOffset; uSize = cb.dwSize; - cb.dwOffset = 0; // then set default result (nothing) + cb.dwOffset = 0; /* then set default result (nothing) */ cb.dwSize = 0; - if (nArea < MAX_TRANSAREAS) // The area number must be OK - { - TRANSAREA *pArea = &pdx->rTransDef[nArea]; // Pointer to relevant info - spin_lock_irq(&pdx->stagedLock); // Lock others out + if (nArea < MAX_TRANSAREAS) { /* The area number must be OK */ + TRANSAREA *pArea = &pdx->rTransDef[nArea]; /* Pointer to relevant info */ + spin_lock_irq(&pdx->stagedLock); /* Lock others out */ - if ((pArea->bUsed) && (pArea->bCircular) && // Must be circular area - (pArea->bCircToHost)) // For now at least must be to host - { + if ((pArea->bUsed) && (pArea->bCircular) && /* Must be circular area */ + (pArea->bCircToHost)) { /* For now at least must be to host */ bool bWaiting = false; - if ((pArea->aBlocks[0].dwSize >= uSize) && // Got anything? - (pArea->aBlocks[0].dwOffset == uStart)) // Must be legal data - { + if ((pArea->aBlocks[0].dwSize >= uSize) && /* Got anything? */ + (pArea->aBlocks[0].dwOffset == uStart)) { /* Must be legal data */ pArea->aBlocks[0].dwSize -= uSize; pArea->aBlocks[0].dwOffset += uSize; - if (pArea->aBlocks[0].dwSize == 0) // Have we emptied this block? - { - if (pArea->aBlocks[1].dwSize) // Is there a second block? - { - pArea->aBlocks[0] = pArea->aBlocks[1]; // Copy down block 2 data - pArea->aBlocks[1].dwSize = 0; // and mark the second block as unused + if (pArea->aBlocks[0].dwSize == 0) { /* Have we emptied this block? */ + if (pArea->aBlocks[1].dwSize) { /* Is there a second block? */ + pArea->aBlocks[0] = pArea->aBlocks[1]; /* Copy down block 2 data */ + pArea->aBlocks[1].dwSize = 0; /* and mark the second block as unused */ pArea->aBlocks[1].dwOffset = 0; } else pArea->aBlocks[0].dwOffset = 0; @@ -1468,9 +1447,8 @@ int FreeCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) pArea->aBlocks[0].dwOffset, pdx->bXFerWaiting); - // Return the next available block of memory as well - if (pArea->aBlocks[0].dwSize > 0) // Got anything? - { + /* Return the next available block of memory as well */ + if (pArea->aBlocks[0].dwSize > 0) { /* Got anything? */ cb.dwOffset = pArea->aBlocks[0].dwOffset; cb.dwSize = pArea->aBlocks[0].dwSize; @@ -1492,9 +1470,8 @@ int FreeCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) iReturn = U14ERR_NOMEMORY; } - // If we have one, kick off pending transfer - if (bWaiting) // Got a block xfer waiting? - { + /* If we have one, kick off pending transfer */ + if (bWaiting) { /* Got a block xfer waiting? */ int RWMStat = ReadWriteMem(pdx, !pdx->rDMAInfo.bOutWard, pdx->rDMAInfo.wIdent, diff --git a/drivers/staging/ced1401/ced_ioctl.h b/drivers/staging/ced1401/ced_ioctl.h index 0895c9414b4f..aa68878bd251 100644 --- a/drivers/staging/ced1401/ced_ioctl.h +++ b/drivers/staging/ced1401/ced_ioctl.h @@ -35,7 +35,7 @@ typedef struct TransferDesc { short eSize; /* element size - is tohost flag for circular */ } TRANSFERDESC; -typedef TRANSFERDESC * LPTRANSFERDESC; +typedef TRANSFERDESC *LPTRANSFERDESC; typedef struct TransferEvent { unsigned int dwStart; /* offset into the area */ diff --git a/drivers/staging/ced1401/machine.h b/drivers/staging/ced1401/machine.h index af073790b942..dbd4036d9bdd 100644 --- a/drivers/staging/ced1401/machine.h +++ b/drivers/staging/ced1401/machine.h @@ -77,20 +77,13 @@ #endif #if defined(LINUX) || defined(MAXOSX) - #define FAR + #define FAR - typedef int BOOL; // To match Windows - typedef char * LPSTR; - typedef const char * LPCSTR; - typedef unsigned short WORD; - typedef unsigned int DWORD; - typedef unsigned char BYTE; - typedef BYTE BOOLEAN; - typedef unsigned char UCHAR; - #define __packed __attribute__((packed)) - typedef BYTE * LPBYTE; - #define HIWORD(x) (WORD)(((x)>>16) & 0xffff) - #define LOWORD(x) (WORD)((x) & 0xffff) + typedef int BOOL; /* To match Windows */ + typedef unsigned char BYTE; + #define __packed __attribute__((packed)) + #define HIWORD(x) (unsigned short)(((x)>>16) & 0xffff) + #define LOWORD(x) (unsigned short)((x) & 0xffff) #endif #ifdef _IS_WINDOWS_ @@ -104,21 +97,20 @@ ** a synonym. */ #ifdef GNUC - #define DllExport __attribute__((dllexport)) - #define DllImport __attribute__((dllimport)) + #define DllExport __attribute__((dllexport)) + #define DllImport __attribute__((dllimport)) #endif #ifndef DllExport #ifdef _IS_WINDOWS_ - #define DllExport __declspec(dllexport) - #define DllImport __declspec(dllimport) + #define DllExport __declspec(dllexport) + #define DllImport __declspec(dllimport) #else - #define DllExport - #define DllImport + #define DllExport + #define DllImport #endif #endif /* _IS_WINDOWS_ */ - #ifndef TRUE #define TRUE 1 #define FALSE 0 diff --git a/drivers/staging/ced1401/usb1401.c b/drivers/staging/ced1401/usb1401.c index 254131d8be5f..97c55f9e5151 100644 --- a/drivers/staging/ced1401/usb1401.c +++ b/drivers/staging/ced1401/usb1401.c @@ -126,18 +126,18 @@ static void ced_delete(struct kref *kref) { DEVICE_EXTENSION *pdx = to_DEVICE_EXTENSION(kref); - // Free up the output buffer, then free the output urb. Note that the interface member - // of pdx will probably be NULL, so cannot be used to get to dev. + /* Free up the output buffer, then free the output urb. Note that the interface member */ + /* of pdx will probably be NULL, so cannot be used to get to dev. */ usb_free_coherent(pdx->udev, OUTBUF_SZ, pdx->pCoherCharOut, pdx->pUrbCharOut->transfer_dma); usb_free_urb(pdx->pUrbCharOut); - // Do the same for chan input + /* Do the same for chan input */ usb_free_coherent(pdx->udev, INBUF_SZ, pdx->pCoherCharIn, pdx->pUrbCharIn->transfer_dma); usb_free_urb(pdx->pUrbCharIn); - // Do the same for the block transfers + /* Do the same for the block transfers */ usb_free_coherent(pdx->udev, STAGED_SZ, pdx->pCoherStagedIO, pdx->pStagedUrb->transfer_dma); usb_free_urb(pdx->pStagedUrb); @@ -146,7 +146,7 @@ static void ced_delete(struct kref *kref) kfree(pdx); } -// This is the driver end of the open() call from user space. +/* This is the driver end of the open() call from user space. */ static int ced_open(struct inode *inode, struct file *file) { DEVICE_EXTENSION *pdx; @@ -184,7 +184,7 @@ static int ced_open(struct inode *inode, struct file *file) kref_put(&pdx->kref, ced_delete); goto exit; } - } else { //uncomment this block if you want exclusive open + } else { /* uncomment this block if you want exclusive open */ dev_err(&interface->dev, "%s fail: already open", __func__); retval = -EBUSY; pdx->open_count--; @@ -210,11 +210,11 @@ static int ced_release(struct inode *inode, struct file *file) dev_dbg(&pdx->interface->dev, "%s called", __func__); mutex_lock(&pdx->io_mutex); - if (!--pdx->open_count && pdx->interface) // Allow autosuspend + if (!--pdx->open_count && pdx->interface) /* Allow autosuspend */ usb_autopm_put_interface(pdx->interface); mutex_unlock(&pdx->io_mutex); - kref_put(&pdx->kref, ced_delete); // decrement the count on our device + kref_put(&pdx->kref, ced_delete); /* decrement the count on our device */ return 0; } @@ -252,9 +252,9 @@ static int ced_flush(struct file *file, fl_owner_t id) ** not help with a device extension held by a file. ** return true if can accept new io requests, else false */ -static bool CanAcceptIoRequests(DEVICE_EXTENSION * pdx) +static bool CanAcceptIoRequests(DEVICE_EXTENSION *pdx) { - return pdx && pdx->interface; // Can we accept IO requests + return pdx && pdx->interface; /* Can we accept IO requests */ } /**************************************************************************** @@ -264,9 +264,9 @@ static bool CanAcceptIoRequests(DEVICE_EXTENSION * pdx) static void ced_writechar_callback(struct urb *pUrb) { DEVICE_EXTENSION *pdx = pUrb->context; - int nGot = pUrb->actual_length; // what we transferred + int nGot = pUrb->actual_length; /* what we transferred */ - if (pUrb->status) { // sync/async unlink faults aren't errors + if (pUrb->status) { /* sync/async unlink faults aren't errors */ if (! (pUrb->status == -ENOENT || pUrb->status == -ECONNRESET || pUrb->status == -ESHUTDOWN)) { @@ -278,36 +278,35 @@ static void ced_writechar_callback(struct urb *pUrb) spin_lock(&pdx->err_lock); pdx->errors = pUrb->status; spin_unlock(&pdx->err_lock); - nGot = 0; // and tidy up again if so + nGot = 0; /* and tidy up again if so */ - spin_lock(&pdx->charOutLock); // already at irq level - pdx->dwOutBuffGet = 0; // Reset the output buffer + spin_lock(&pdx->charOutLock); /* already at irq level */ + pdx->dwOutBuffGet = 0; /* Reset the output buffer */ pdx->dwOutBuffPut = 0; - pdx->dwNumOutput = 0; // Clear the char count - pdx->bPipeError[0] = 1; // Flag an error for later - pdx->bSendCharsPending = false; // Allow other threads again - spin_unlock(&pdx->charOutLock); // already at irq level + pdx->dwNumOutput = 0; /* Clear the char count */ + pdx->bPipeError[0] = 1; /* Flag an error for later */ + pdx->bSendCharsPending = false; /* Allow other threads again */ + spin_unlock(&pdx->charOutLock); /* already at irq level */ dev_dbg(&pdx->interface->dev, "%s - char out done, 0 chars sent", __func__); } else { dev_dbg(&pdx->interface->dev, "%s - char out done, %d chars sent", __func__, nGot); - spin_lock(&pdx->charOutLock); // already at irq level - pdx->dwNumOutput -= nGot; // Now adjust the char send buffer - pdx->dwOutBuffGet += nGot; // to match what we did - if (pdx->dwOutBuffGet >= OUTBUF_SZ) // Can't do this any earlier as data could be overwritten + spin_lock(&pdx->charOutLock); /* already at irq level */ + pdx->dwNumOutput -= nGot; /* Now adjust the char send buffer */ + pdx->dwOutBuffGet += nGot; /* to match what we did */ + if (pdx->dwOutBuffGet >= OUTBUF_SZ) /* Can't do this any earlier as data could be overwritten */ pdx->dwOutBuffGet = 0; - if (pdx->dwNumOutput > 0) // if more to be done... - { - int nPipe = 0; // The pipe number to use + if (pdx->dwNumOutput > 0) { /* if more to be done... */ + int nPipe = 0; /* The pipe number to use */ int iReturn; char *pDat = &pdx->outputBuffer[pdx->dwOutBuffGet]; - unsigned int dwCount = pdx->dwNumOutput; // maximum to send - if ((pdx->dwOutBuffGet + dwCount) > OUTBUF_SZ) // does it cross buffer end? + unsigned int dwCount = pdx->dwNumOutput; /* maximum to send */ + if ((pdx->dwOutBuffGet + dwCount) > OUTBUF_SZ) /* does it cross buffer end? */ dwCount = OUTBUF_SZ - pdx->dwOutBuffGet; - spin_unlock(&pdx->charOutLock); // we are done with stuff that changes - memcpy(pdx->pCoherCharOut, pDat, dwCount); // copy output data to the buffer + spin_unlock(&pdx->charOutLock); /* we are done with stuff that changes */ + memcpy(pdx->pCoherCharOut, pDat, dwCount); /* copy output data to the buffer */ usb_fill_bulk_urb(pdx->pUrbCharOut, pdx->udev, usb_sndbulkpipe(pdx->udev, pdx->epAddr[0]), @@ -315,22 +314,22 @@ static void ced_writechar_callback(struct urb *pUrb) ced_writechar_callback, pdx); pdx->pUrbCharOut->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - usb_anchor_urb(pdx->pUrbCharOut, &pdx->submitted); // in case we need to kill it + usb_anchor_urb(pdx->pUrbCharOut, &pdx->submitted); /* in case we need to kill it */ iReturn = usb_submit_urb(pdx->pUrbCharOut, GFP_ATOMIC); dev_dbg(&pdx->interface->dev, "%s n=%d>%s<", __func__, dwCount, pDat); - spin_lock(&pdx->charOutLock); // grab lock for errors + spin_lock(&pdx->charOutLock); /* grab lock for errors */ if (iReturn) { - pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later - pdx->bSendCharsPending = false; // Allow other threads again + pdx->bPipeError[nPipe] = 1; /* Flag an error to be handled later */ + pdx->bSendCharsPending = false; /* Allow other threads again */ usb_unanchor_urb(pdx->pUrbCharOut); dev_err(&pdx->interface->dev, "%s usb_submit_urb() returned %d", __func__, iReturn); } } else - pdx->bSendCharsPending = false; // Allow other threads again - spin_unlock(&pdx->charOutLock); // already at irq level + pdx->bSendCharsPending = false; /* Allow other threads again */ + spin_unlock(&pdx->charOutLock); /* already at irq level */ } } @@ -339,44 +338,43 @@ static void ced_writechar_callback(struct urb *pUrb) ** Transmit the characters in the output buffer to the 1401. This may need ** breaking down into multiple transfers. ****************************************************************************/ -int SendChars(DEVICE_EXTENSION * pdx) +int SendChars(DEVICE_EXTENSION *pdx) { int iReturn = U14ERR_NOERROR; - spin_lock_irq(&pdx->charOutLock); // Protect ourselves + spin_lock_irq(&pdx->charOutLock); /* Protect ourselves */ - if ((!pdx->bSendCharsPending) && // Not currently sending - (pdx->dwNumOutput > 0) && // has characters to output - (CanAcceptIoRequests(pdx))) // and current activity is OK - { - unsigned int dwCount = pdx->dwNumOutput; // Get a copy of the character count - pdx->bSendCharsPending = true; // Set flag to lock out other threads + if ((!pdx->bSendCharsPending) && /* Not currently sending */ + (pdx->dwNumOutput > 0) && /* has characters to output */ + (CanAcceptIoRequests(pdx))) { /* and current activity is OK */ + unsigned int dwCount = pdx->dwNumOutput; /* Get a copy of the character count */ + pdx->bSendCharsPending = true; /* Set flag to lock out other threads */ dev_dbg(&pdx->interface->dev, "Send %d chars to 1401, EP0 flag %d\n", dwCount, pdx->nPipes == 3); - // If we have only 3 end points we must send the characters to the 1401 using EP0. + /* If we have only 3 end points we must send the characters to the 1401 using EP0. */ if (pdx->nPipes == 3) { - // For EP0 character transmissions to the 1401, we have to hang about until they - // are gone, as otherwise without more character IO activity they will never go. - unsigned int count = dwCount; // Local char counter - unsigned int index = 0; // The index into the char buffer + /* For EP0 character transmissions to the 1401, we have to hang about until they */ + /* are gone, as otherwise without more character IO activity they will never go. */ + unsigned int count = dwCount; /* Local char counter */ + unsigned int index = 0; /* The index into the char buffer */ - spin_unlock_irq(&pdx->charOutLock); // Free spinlock as we call USBD + spin_unlock_irq(&pdx->charOutLock); /* Free spinlock as we call USBD */ while ((count > 0) && (iReturn == U14ERR_NOERROR)) { - // We have to break the transfer up into 64-byte chunks because of a 2270 problem - int n = count > 64 ? 64 : count; // Chars for this xfer, max of 64 + /* We have to break the transfer up into 64-byte chunks because of a 2270 problem */ + int n = count > 64 ? 64 : count; /* Chars for this xfer, max of 64 */ int nSent = usb_control_msg(pdx->udev, - usb_sndctrlpipe(pdx->udev, 0), // use end point 0 - DB_CHARS, // bRequest - (H_TO_D | VENDOR | DEVREQ), // to the device, vendor request to the device - 0, 0, // value and index are both 0 - &pdx->outputBuffer[index], // where to send from - n, // how much to send - 1000); // timeout in jiffies + usb_sndctrlpipe(pdx->udev, 0), /* use end point 0 */ + DB_CHARS, /* bRequest */ + (H_TO_D | VENDOR | DEVREQ), /* to the device, vendor request to the device */ + 0, 0, /* value and index are both 0 */ + &pdx->outputBuffer[index], /* where to send from */ + n, /* how much to send */ + 1000); /* timeout in jiffies */ if (nSent <= 0) { - iReturn = nSent ? nSent : -ETIMEDOUT; // if 0 chars says we timed out + iReturn = nSent ? nSent : -ETIMEDOUT; /* if 0 chars says we timed out */ dev_err(&pdx->interface->dev, "Send %d chars by EP0 failed: %d", n, iReturn); @@ -388,19 +386,19 @@ int SendChars(DEVICE_EXTENSION * pdx) } } - spin_lock_irq(&pdx->charOutLock); // Protect pdx changes, released by general code - pdx->dwOutBuffGet = 0; // so reset the output buffer + spin_lock_irq(&pdx->charOutLock); /* Protect pdx changes, released by general code */ + pdx->dwOutBuffGet = 0; /* so reset the output buffer */ pdx->dwOutBuffPut = 0; - pdx->dwNumOutput = 0; // and clear the buffer count - pdx->bSendCharsPending = false; // Allow other threads again - } else { // Here for sending chars normally - we hold the spin lock - int nPipe = 0; // The pipe number to use + pdx->dwNumOutput = 0; /* and clear the buffer count */ + pdx->bSendCharsPending = false; /* Allow other threads again */ + } else { /* Here for sending chars normally - we hold the spin lock */ + int nPipe = 0; /* The pipe number to use */ char *pDat = &pdx->outputBuffer[pdx->dwOutBuffGet]; - if ((pdx->dwOutBuffGet + dwCount) > OUTBUF_SZ) // does it cross buffer end? + if ((pdx->dwOutBuffGet + dwCount) > OUTBUF_SZ) /* does it cross buffer end? */ dwCount = OUTBUF_SZ - pdx->dwOutBuffGet; - spin_unlock_irq(&pdx->charOutLock); // we are done with stuff that changes - memcpy(pdx->pCoherCharOut, pDat, dwCount); // copy output data to the buffer + spin_unlock_irq(&pdx->charOutLock); /* we are done with stuff that changes */ + memcpy(pdx->pCoherCharOut, pDat, dwCount); /* copy output data to the buffer */ usb_fill_bulk_urb(pdx->pUrbCharOut, pdx->udev, usb_sndbulkpipe(pdx->udev, pdx->epAddr[0]), @@ -410,11 +408,11 @@ int SendChars(DEVICE_EXTENSION * pdx) URB_NO_TRANSFER_DMA_MAP; usb_anchor_urb(pdx->pUrbCharOut, &pdx->submitted); iReturn = usb_submit_urb(pdx->pUrbCharOut, GFP_KERNEL); - spin_lock_irq(&pdx->charOutLock); // grab lock for errors + spin_lock_irq(&pdx->charOutLock); /* grab lock for errors */ if (iReturn) { - pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later - pdx->bSendCharsPending = false; // Allow other threads again - usb_unanchor_urb(pdx->pUrbCharOut); // remove from list of active urbs + pdx->bPipeError[nPipe] = 1; /* Flag an error to be handled later */ + pdx->bSendCharsPending = false; /* Allow other threads again */ + usb_unanchor_urb(pdx->pUrbCharOut); /* remove from list of active urbs */ } } } else if (pdx->bSendCharsPending && (pdx->dwNumOutput > 0)) @@ -422,7 +420,7 @@ int SendChars(DEVICE_EXTENSION * pdx) "SendChars bSendCharsPending:true"); dev_dbg(&pdx->interface->dev, "SendChars exit code: %d", iReturn); - spin_unlock_irq(&pdx->charOutLock); // Now let go of the spinlock + spin_unlock_irq(&pdx->charOutLock); /* Now let go of the spinlock */ return iReturn; } @@ -440,14 +438,14 @@ int SendChars(DEVICE_EXTENSION * pdx) ** pdx Is our device extension which holds all we know about the transfer. ** n The number of bytes to move one way or the other. ***************************************************************************/ -static void CopyUserSpace(DEVICE_EXTENSION * pdx, int n) +static void CopyUserSpace(DEVICE_EXTENSION *pdx, int n) { unsigned int nArea = pdx->StagedId; if (nArea < MAX_TRANSAREAS) { - TRANSAREA *pArea = &pdx->rTransDef[nArea]; // area to be used + TRANSAREA *pArea = &pdx->rTransDef[nArea]; /* area to be used */ unsigned int dwOffset = pdx->StagedDone + pdx->StagedOffset + pArea->dwBaseOffset; - char *pCoherBuf = pdx->pCoherStagedIO; // coherent buffer + char *pCoherBuf = pdx->pCoherStagedIO; /* coherent buffer */ if (!pArea->bUsed) { dev_err(&pdx->interface->dev, "%s area %d unused", __func__, nArea); @@ -455,15 +453,15 @@ static void CopyUserSpace(DEVICE_EXTENSION * pdx, int n) } while (n) { - int nPage = dwOffset >> PAGE_SHIFT; // page number in table + int nPage = dwOffset >> PAGE_SHIFT; /* page number in table */ if (nPage < pArea->nPages) { char *pvAddress = (char *)kmap_atomic(pArea->pPages[nPage]); if (pvAddress) { - unsigned int uiPageOff = dwOffset & (PAGE_SIZE - 1); // offset into the page - size_t uiXfer = PAGE_SIZE - uiPageOff; // max to transfer on this page - if (uiXfer > n) // limit byte count if too much - uiXfer = n; // for the page + unsigned int uiPageOff = dwOffset & (PAGE_SIZE - 1); /* offset into the page */ + size_t uiXfer = PAGE_SIZE - uiPageOff; /* max to transfer on this page */ + if (uiXfer > n) /* limit byte count if too much */ + uiXfer = n; /* for the page */ if (pdx->StagedRead) memcpy(pvAddress + uiPageOff, pCoherBuf, uiXfer); @@ -494,8 +492,8 @@ static void CopyUserSpace(DEVICE_EXTENSION * pdx, int n) nArea); } -// Forward declarations for stuff used circularly -static int StageChunk(DEVICE_EXTENSION * pdx); +/* Forward declarations for stuff used circularly */ +static int StageChunk(DEVICE_EXTENSION *pdx); /*************************************************************************** ** ReadWrite_Complete ** @@ -504,14 +502,14 @@ static int StageChunk(DEVICE_EXTENSION * pdx); static void staged_callback(struct urb *pUrb) { DEVICE_EXTENSION *pdx = pUrb->context; - unsigned int nGot = pUrb->actual_length; // what we transferred + unsigned int nGot = pUrb->actual_length; /* what we transferred */ bool bCancel = false; - bool bRestartCharInput; // used at the end + bool bRestartCharInput; /* used at the end */ - spin_lock(&pdx->stagedLock); // stop ReadWriteMem() action while this routine is running - pdx->bStagedUrbPending = false; // clear the flag for staged IRP pending + spin_lock(&pdx->stagedLock); /* stop ReadWriteMem() action while this routine is running */ + pdx->bStagedUrbPending = false; /* clear the flag for staged IRP pending */ - if (pUrb->status) { // sync/async unlink faults aren't errors + if (pUrb->status) { /* sync/async unlink faults aren't errors */ if (! (pUrb->status == -ENOENT || pUrb->status == -ECONNRESET || pUrb->status == -ESHUTDOWN)) { @@ -525,40 +523,37 @@ static void staged_callback(struct urb *pUrb) spin_lock(&pdx->err_lock); pdx->errors = pUrb->status; spin_unlock(&pdx->err_lock); - nGot = 0; // and tidy up again if so + nGot = 0; /* and tidy up again if so */ bCancel = true; } else { dev_dbg(&pdx->interface->dev, "%s %d chars xferred", __func__, nGot); - if (pdx->StagedRead) // if reading, save to user space - CopyUserSpace(pdx, nGot); // copy from buffer to user + if (pdx->StagedRead) /* if reading, save to user space */ + CopyUserSpace(pdx, nGot); /* copy from buffer to user */ if (nGot == 0) dev_dbg(&pdx->interface->dev, "%s ZLP", __func__); } - // Update the transfer length based on the TransferBufferLength value in the URB + /* Update the transfer length based on the TransferBufferLength value in the URB */ pdx->StagedDone += nGot; dev_dbg(&pdx->interface->dev, "%s, done %d bytes of %d", __func__, pdx->StagedDone, pdx->StagedLength); - if ((pdx->StagedDone == pdx->StagedLength) || // If no more to do - (bCancel)) // or this IRP was cancelled - { - TRANSAREA *pArea = &pdx->rTransDef[pdx->StagedId]; // Transfer area info + if ((pdx->StagedDone == pdx->StagedLength) || /* If no more to do */ + (bCancel)) { /* or this IRP was cancelled */ + TRANSAREA *pArea = &pdx->rTransDef[pdx->StagedId]; /* Transfer area info */ dev_dbg(&pdx->interface->dev, "%s transfer done, bytes %d, cancel %d", __func__, pdx->StagedDone, bCancel); - // Here is where we sort out what to do with this transfer if using a circular buffer. We have - // a completed transfer that can be assumed to fit into the transfer area. We should be able to - // add this to the end of a growing block or to use it to start a new block unless the code - // that calculates the offset to use (in ReadWriteMem) is totally duff. - if ((pArea->bCircular) && (pArea->bCircToHost) && (!bCancel) && // Time to sort out circular buffer info? - (pdx->StagedRead)) // Only for tohost transfers for now - { - if (pArea->aBlocks[1].dwSize > 0) // If block 1 is in use we must append to it - { + /* Here is where we sort out what to do with this transfer if using a circular buffer. We have */ + /* a completed transfer that can be assumed to fit into the transfer area. We should be able to */ + /* add this to the end of a growing block or to use it to start a new block unless the code */ + /* that calculates the offset to use (in ReadWriteMem) is totally duff. */ + if ((pArea->bCircular) && (pArea->bCircToHost) && (!bCancel) && /* Time to sort out circular buffer info? */ + (pdx->StagedRead)) { /* Only for tohost transfers for now */ + if (pArea->aBlocks[1].dwSize > 0) { /* If block 1 is in use we must append to it */ if (pdx->StagedOffset == (pArea->aBlocks[1].dwOffset + pArea->aBlocks[1].dwSize)) { @@ -569,7 +564,7 @@ static void staged_callback(struct urb *pUrb) pArea->aBlocks[1].dwSize, pArea->aBlocks[1].dwOffset); } else { - // Here things have gone very, very, wrong, but I cannot see how this can actually be achieved + /* Here things have gone very, very, wrong, but I cannot see how this can actually be achieved */ pArea->aBlocks[1].dwOffset = pdx->StagedOffset; pArea->aBlocks[1].dwSize = @@ -580,22 +575,20 @@ static void staged_callback(struct urb *pUrb) pArea->aBlocks[1].dwSize, pArea->aBlocks[1].dwOffset); } - } else // If block 1 is not used, we try to add to block 0 - { - if (pArea->aBlocks[0].dwSize > 0) // Got stored block 0 information? - { // Must append onto the existing block 0 + } else { /* If block 1 is not used, we try to add to block 0 */ + if (pArea->aBlocks[0].dwSize > 0) { /* Got stored block 0 information? */ + /* Must append onto the existing block 0 */ if (pdx->StagedOffset == (pArea->aBlocks[0].dwOffset + pArea->aBlocks[0].dwSize)) { - pArea->aBlocks[0].dwSize += pdx->StagedLength; // Just add this transfer in + pArea->aBlocks[0].dwSize += pdx->StagedLength; /* Just add this transfer in */ dev_dbg(&pdx->interface->dev, "RWM_Complete, circ block 0 now %d bytes at %d", pArea->aBlocks[0]. dwSize, pArea->aBlocks[0]. dwOffset); - } else // If it doesn't append, put into new block 1 - { + } else { /* If it doesn't append, put into new block 1 */ pArea->aBlocks[1].dwOffset = pdx->StagedOffset; pArea->aBlocks[1].dwSize = @@ -607,8 +600,7 @@ static void staged_callback(struct urb *pUrb) pArea->aBlocks[1]. dwOffset); } - } else // No info stored yet, just save in block 0 - { + } else { /* No info stored yet, just save in block 0 */ pArea->aBlocks[0].dwOffset = pdx->StagedOffset; pArea->aBlocks[0].dwSize = @@ -621,21 +613,19 @@ static void staged_callback(struct urb *pUrb) } } - if (!bCancel) // Don't generate an event if cancelled - { + if (!bCancel) { /* Don't generate an event if cancelled */ dev_dbg(&pdx->interface->dev, "RWM_Complete, bCircular %d, bToHost %d, eStart %d, eSize %d", pArea->bCircular, pArea->bEventToHost, pArea->dwEventSt, pArea->dwEventSz); - if ((pArea->dwEventSz) && // Set a user-mode event... - (pdx->StagedRead == pArea->bEventToHost)) // ...on transfers in this direction? - { - int iWakeUp = 0; // assume - // If we have completed the right sort of DMA transfer then set the event to notify - // the user code to wake up anyone that is waiting. - if ((pArea->bCircular) && // Circular areas use a simpler test - (pArea->bCircToHost)) // only in supported direction - { // Is total data waiting up to size limit? + if ((pArea->dwEventSz) && /* Set a user-mode event... */ + (pdx->StagedRead == pArea->bEventToHost)) { /* ...on transfers in this direction? */ + int iWakeUp = 0; /* assume */ + /* If we have completed the right sort of DMA transfer then set the event to notify */ + /* the user code to wake up anyone that is waiting. */ + if ((pArea->bCircular) && /* Circular areas use a simpler test */ + (pArea->bCircToHost)) { /* only in supported direction */ + /* Is total data waiting up to size limit? */ unsigned int dwTotal = pArea->aBlocks[0].dwSize + pArea->aBlocks[1].dwSize; @@ -653,19 +643,17 @@ static void staged_callback(struct urb *pUrb) if (iWakeUp) { dev_dbg(&pdx->interface->dev, "About to set event to notify app"); - wake_up_interruptible(&pArea->wqEvent); // wake up waiting processes - ++pArea->iWakeUp; // increment wakeup count + wake_up_interruptible(&pArea->wqEvent); /* wake up waiting processes */ + ++pArea->iWakeUp; /* increment wakeup count */ } } } - pdx->dwDMAFlag = MODE_CHAR; // Switch back to char mode before ReadWriteMem call + pdx->dwDMAFlag = MODE_CHAR; /* Switch back to char mode before ReadWriteMem call */ - if (!bCancel) // Don't look for waiting transfer if cancelled - { - // If we have a transfer waiting, kick it off - if (pdx->bXFerWaiting) // Got a block xfer waiting? - { + if (!bCancel) { /* Don't look for waiting transfer if cancelled */ + /* If we have a transfer waiting, kick it off */ + if (pdx->bXFerWaiting) { /* Got a block xfer waiting? */ int iReturn; dev_info(&pdx->interface->dev, "*** RWM_Complete *** pending transfer will now be set up!!!"); @@ -682,22 +670,22 @@ static void staged_callback(struct urb *pUrb) } } - } else // Here for more to do - StageChunk(pdx); // fire off the next bit + } else /* Here for more to do */ + StageChunk(pdx); /* fire off the next bit */ - // While we hold the stagedLock, see if we should reallow character input ints - // Don't allow if cancelled, or if a new block has started or if there is a waiting block. - // This feels wrong as we should ask which spin lock protects dwDMAFlag. + /* While we hold the stagedLock, see if we should reallow character input ints */ + /* Don't allow if cancelled, or if a new block has started or if there is a waiting block. */ + /* This feels wrong as we should ask which spin lock protects dwDMAFlag. */ bRestartCharInput = !bCancel && (pdx->dwDMAFlag == MODE_CHAR) && !pdx->bXFerWaiting; - spin_unlock(&pdx->stagedLock); // Finally release the lock again + spin_unlock(&pdx->stagedLock); /* Finally release the lock again */ - // This is not correct as dwDMAFlag is protected by the staged lock, but it is treated - // in Allowi as if it were protected by the char lock. In any case, most systems will - // not be upset by char input during DMA... sigh. Needs sorting out. - if (bRestartCharInput) // may be out of date, but... - Allowi(pdx); // ...Allowi tests a lock too. + /* This is not correct as dwDMAFlag is protected by the staged lock, but it is treated */ + /* in Allowi as if it were protected by the char lock. In any case, most systems will */ + /* not be upset by char input during DMA... sigh. Needs sorting out. */ + if (bRestartCharInput) /* may be out of date, but... */ + Allowi(pdx); /* ...Allowi tests a lock too. */ dev_dbg(&pdx->interface->dev, "%s done", __func__); } @@ -709,29 +697,28 @@ static void staged_callback(struct urb *pUrb) ** The calling code must have acquired the staging spinlock before calling ** this function, and is responsible for releasing it. We are at callback level. ****************************************************************************/ -static int StageChunk(DEVICE_EXTENSION * pdx) +static int StageChunk(DEVICE_EXTENSION *pdx) { int iReturn = U14ERR_NOERROR; unsigned int ChunkSize; - int nPipe = pdx->StagedRead ? 3 : 2; // The pipe number to use for reads or writes + int nPipe = pdx->StagedRead ? 3 : 2; /* The pipe number to use for reads or writes */ if (pdx->nPipes == 3) - nPipe--; // Adjust for the 3-pipe case - if (nPipe < 0) // and trap case that should never happen + nPipe--; /* Adjust for the 3-pipe case */ + if (nPipe < 0) /* and trap case that should never happen */ return U14ERR_FAIL; - if (!CanAcceptIoRequests(pdx)) // got sudden remove? - { + if (!CanAcceptIoRequests(pdx)) { /* got sudden remove? */ dev_info(&pdx->interface->dev, "%s sudden remove, giving up", __func__); - return U14ERR_FAIL; // could do with a better error + return U14ERR_FAIL; /* could do with a better error */ } - ChunkSize = (pdx->StagedLength - pdx->StagedDone); // transfer length remaining - if (ChunkSize > STAGED_SZ) // make sure to keep legal - ChunkSize = STAGED_SZ; // limit to max allowed + ChunkSize = (pdx->StagedLength - pdx->StagedDone); /* transfer length remaining */ + if (ChunkSize > STAGED_SZ) /* make sure to keep legal */ + ChunkSize = STAGED_SZ; /* limit to max allowed */ - if (!pdx->StagedRead) // if writing... - CopyUserSpace(pdx, ChunkSize); // ...copy data into the buffer + if (!pdx->StagedRead) /* if writing... */ + CopyUserSpace(pdx, ChunkSize); /* ...copy data into the buffer */ usb_fill_bulk_urb(pdx->pStagedUrb, pdx->udev, pdx->StagedRead ? usb_rcvbulkpipe(pdx->udev, @@ -740,15 +727,15 @@ static int StageChunk(DEVICE_EXTENSION * pdx) usb_sndbulkpipe(pdx->udev, pdx->epAddr[nPipe]), pdx->pCoherStagedIO, ChunkSize, staged_callback, pdx); pdx->pStagedUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - usb_anchor_urb(pdx->pStagedUrb, &pdx->submitted); // in case we need to kill it + usb_anchor_urb(pdx->pStagedUrb, &pdx->submitted); /* in case we need to kill it */ iReturn = usb_submit_urb(pdx->pStagedUrb, GFP_ATOMIC); if (iReturn) { - usb_unanchor_urb(pdx->pStagedUrb); // kill it - pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later + usb_unanchor_urb(pdx->pStagedUrb); /* kill it */ + pdx->bPipeError[nPipe] = 1; /* Flag an error to be handled later */ dev_err(&pdx->interface->dev, "%s submit urb failed, code %d", __func__, iReturn); } else - pdx->bStagedUrbPending = true; // Set the flag for staged URB pending + pdx->bStagedUrbPending = true; /* Set the flag for staged URB pending */ dev_dbg(&pdx->interface->dev, "%s done so far:%d, this size:%d", __func__, pdx->StagedDone, ChunkSize); @@ -772,13 +759,12 @@ static int StageChunk(DEVICE_EXTENSION * pdx) ** transfer. ** dwLen - the number of bytes to transfer. */ -int ReadWriteMem(DEVICE_EXTENSION * pdx, bool Read, unsigned short wIdent, +int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent, unsigned int dwOffs, unsigned int dwLen) { - TRANSAREA *pArea = &pdx->rTransDef[wIdent]; // Transfer area info + TRANSAREA *pArea = &pdx->rTransDef[wIdent]; /* Transfer area info */ - if (!CanAcceptIoRequests(pdx)) // Are we in a state to accept new requests? - { + if (!CanAcceptIoRequests(pdx)) { /* Are we in a state to accept new requests? */ dev_err(&pdx->interface->dev, "%s can't accept requests", __func__); return U14ERR_FAIL; @@ -788,56 +774,51 @@ int ReadWriteMem(DEVICE_EXTENSION * pdx, bool Read, unsigned short wIdent, "%s xfer %d bytes to %s, offset %d, area %d", __func__, dwLen, Read ? "host" : "1401", dwOffs, wIdent); - // Amazingly, we can get an escape sequence back before the current staged Urb is done, so we - // have to check for this situation and, if so, wait until all is OK. + /* Amazingly, we can get an escape sequence back before the current staged Urb is done, so we */ + /* have to check for this situation and, if so, wait until all is OK. */ if (pdx->bStagedUrbPending) { - pdx->bXFerWaiting = true; // Flag we are waiting + pdx->bXFerWaiting = true; /* Flag we are waiting */ dev_info(&pdx->interface->dev, "%s xfer is waiting, as previous staged pending", __func__); return U14ERR_NOERROR; } - if (dwLen == 0) // allow 0-len read or write; just return success - { + if (dwLen == 0) { /* allow 0-len read or write; just return success */ dev_dbg(&pdx->interface->dev, "%s OK; zero-len read/write request", __func__); return U14ERR_NOERROR; } - if ((pArea->bCircular) && // Circular transfer? - (pArea->bCircToHost) && (Read)) // In a supported direction - { // If so, we sort out offset ourself - bool bWait = false; // Flag for transfer having to wait + if ((pArea->bCircular) && /* Circular transfer? */ + (pArea->bCircToHost) && (Read)) { /* In a supported direction */ + /* If so, we sort out offset ourself */ + bool bWait = false; /* Flag for transfer having to wait */ dev_dbg(&pdx->interface->dev, "Circular buffers are %d at %d and %d at %d", pArea->aBlocks[0].dwSize, pArea->aBlocks[0].dwOffset, pArea->aBlocks[1].dwSize, pArea->aBlocks[1].dwOffset); - if (pArea->aBlocks[1].dwSize > 0) // Using the second block already? - { - dwOffs = pArea->aBlocks[1].dwOffset + pArea->aBlocks[1].dwSize; // take offset from that - bWait = (dwOffs + dwLen) > pArea->aBlocks[0].dwOffset; // Wait if will overwrite block 0? - bWait |= (dwOffs + dwLen) > pArea->dwLength; // or if it overflows the buffer - } else // Area 1 not in use, try to use area 0 - { - if (pArea->aBlocks[0].dwSize == 0) // Reset block 0 if not in use + if (pArea->aBlocks[1].dwSize > 0) { /* Using the second block already? */ + dwOffs = pArea->aBlocks[1].dwOffset + pArea->aBlocks[1].dwSize; /* take offset from that */ + bWait = (dwOffs + dwLen) > pArea->aBlocks[0].dwOffset; /* Wait if will overwrite block 0? */ + bWait |= (dwOffs + dwLen) > pArea->dwLength; /* or if it overflows the buffer */ + } else { /* Area 1 not in use, try to use area 0 */ + if (pArea->aBlocks[0].dwSize == 0) /* Reset block 0 if not in use */ pArea->aBlocks[0].dwOffset = 0; dwOffs = pArea->aBlocks[0].dwOffset + pArea->aBlocks[0].dwSize; - if ((dwOffs + dwLen) > pArea->dwLength) // Off the end of the buffer? - { - pArea->aBlocks[1].dwOffset = 0; // Set up to use second block + if ((dwOffs + dwLen) > pArea->dwLength) { /* Off the end of the buffer? */ + pArea->aBlocks[1].dwOffset = 0; /* Set up to use second block */ dwOffs = 0; - bWait = (dwOffs + dwLen) > pArea->aBlocks[0].dwOffset; // Wait if will overwrite block 0? - bWait |= (dwOffs + dwLen) > pArea->dwLength; // or if it overflows the buffer + bWait = (dwOffs + dwLen) > pArea->aBlocks[0].dwOffset; /* Wait if will overwrite block 0? */ + bWait |= (dwOffs + dwLen) > pArea->dwLength; /* or if it overflows the buffer */ } } - if (bWait) // This transfer will have to wait? - { - pdx->bXFerWaiting = true; // Flag we are waiting + if (bWait) { /* This transfer will have to wait? */ + pdx->bXFerWaiting = true; /* Flag we are waiting */ dev_dbg(&pdx->interface->dev, "%s xfer waiting for circular buffer space", __func__); @@ -848,17 +829,17 @@ int ReadWriteMem(DEVICE_EXTENSION * pdx, bool Read, unsigned short wIdent, "%s circular xfer, %d bytes starting at %d", __func__, dwLen, dwOffs); } - // Save the parameters for the read\write transfer - pdx->StagedRead = Read; // Save the parameters for this read - pdx->StagedId = wIdent; // ID allows us to get transfer area info - pdx->StagedOffset = dwOffs; // The area within the transfer area + /* Save the parameters for the read\write transfer */ + pdx->StagedRead = Read; /* Save the parameters for this read */ + pdx->StagedId = wIdent; /* ID allows us to get transfer area info */ + pdx->StagedOffset = dwOffs; /* The area within the transfer area */ pdx->StagedLength = dwLen; - pdx->StagedDone = 0; // Initialise the byte count - pdx->dwDMAFlag = MODE_LINEAR; // Set DMA mode flag at this point - pdx->bXFerWaiting = false; // Clearly not a transfer waiting now + pdx->StagedDone = 0; /* Initialise the byte count */ + pdx->dwDMAFlag = MODE_LINEAR; /* Set DMA mode flag at this point */ + pdx->bXFerWaiting = false; /* Clearly not a transfer waiting now */ -// KeClearEvent(&pdx->StagingDoneEvent); // Clear the transfer done event - StageChunk(pdx); // fire off the first chunk +/* KeClearEvent(&pdx->StagingDoneEvent); // Clear the transfer done event */ + StageChunk(pdx); /* fire off the first chunk */ return U14ERR_NOERROR; } @@ -877,12 +858,11 @@ static bool ReadChar(unsigned char *pChar, char *pBuf, unsigned int *pdDone, bool bRead = false; unsigned int dDone = *pdDone; - if (dDone < dGot) // If there is more data - { - *pChar = (unsigned char)pBuf[dDone]; // Extract the next char - dDone++; // Increment the done count + if (dDone < dGot) { /* If there is more data */ + *pChar = (unsigned char)pBuf[dDone]; /* Extract the next char */ + dDone++; /* Increment the done count */ *pdDone = dDone; - bRead = true; // and flag success + bRead = true; /* and flag success */ } return bRead; @@ -962,32 +942,32 @@ static bool ReadHuff(volatile unsigned int *pDWord, char *pBuf, ** we start handling the data at offset zero. ** *****************************************************************************/ -static bool ReadDMAInfo(volatile DMADESC * pDmaDesc, DEVICE_EXTENSION * pdx, +static bool ReadDMAInfo(volatile DMADESC *pDmaDesc, DEVICE_EXTENSION *pdx, char *pBuf, unsigned int dwCount) { - bool bResult = false; // assume we won't succeed + bool bResult = false; /* assume we won't succeed */ unsigned char ucData; - unsigned int dDone = 0; // We haven't parsed anything so far + unsigned int dDone = 0; /* We haven't parsed anything so far */ dev_dbg(&pdx->interface->dev, "%s", __func__); if (ReadChar(&ucData, pBuf, &dDone, dwCount)) { - unsigned char ucTransCode = (ucData & 0x0F); // get code for transfer type - unsigned short wIdent = ((ucData >> 4) & 0x07); // and area identifier + unsigned char ucTransCode = (ucData & 0x0F); /* get code for transfer type */ + unsigned short wIdent = ((ucData >> 4) & 0x07); /* and area identifier */ - // fill in the structure we were given - pDmaDesc->wTransType = ucTransCode; // type of transfer - pDmaDesc->wIdent = wIdent; // area to use - pDmaDesc->dwSize = 0; // initialise other bits + /* fill in the structure we were given */ + pDmaDesc->wTransType = ucTransCode; /* type of transfer */ + pDmaDesc->wIdent = wIdent; /* area to use */ + pDmaDesc->dwSize = 0; /* initialise other bits */ pDmaDesc->dwOffset = 0; dev_dbg(&pdx->interface->dev, "%s type: %d ident: %d", __func__, pDmaDesc->wTransType, pDmaDesc->wIdent); - pDmaDesc->bOutWard = (ucTransCode != TM_EXTTOHOST); // set transfer direction + pDmaDesc->bOutWard = (ucTransCode != TM_EXTTOHOST); /* set transfer direction */ switch (ucTransCode) { - case TM_EXTTOHOST: // Extended linear transfer modes (the only ones!) + case TM_EXTTOHOST: /* Extended linear transfer modes (the only ones!) */ case TM_EXTTO1401: { bResult = @@ -1001,14 +981,14 @@ static bool ReadDMAInfo(volatile DMADESC * pDmaDesc, DEVICE_EXTENSION * pdx, __func__, pDmaDesc->dwOffset, pDmaDesc->dwSize); - if ((wIdent >= MAX_TRANSAREAS) || // Illegal area number, or... - (!pdx->rTransDef[wIdent].bUsed) || // area not set up, or... - (pDmaDesc->dwOffset > pdx->rTransDef[wIdent].dwLength) || // range/size + if ((wIdent >= MAX_TRANSAREAS) || /* Illegal area number, or... */ + (!pdx->rTransDef[wIdent].bUsed) || /* area not set up, or... */ + (pDmaDesc->dwOffset > pdx->rTransDef[wIdent].dwLength) || /* range/size */ ((pDmaDesc->dwOffset + pDmaDesc->dwSize) > (pdx->rTransDef[wIdent]. dwLength))) { - bResult = false; // bad parameter(s) + bResult = false; /* bad parameter(s) */ dev_dbg(&pdx->interface->dev, "%s bad param - id %d, bUsed %d, offset %d, size %d, area length %d", __func__, wIdent, @@ -1028,7 +1008,7 @@ static bool ReadDMAInfo(volatile DMADESC * pDmaDesc, DEVICE_EXTENSION * pdx, } else bResult = false; - if (!bResult) // now check parameters for validity + if (!bResult) /* now check parameters for validity */ dev_err(&pdx->interface->dev, "%s error reading Esc sequence", __func__); @@ -1049,30 +1029,29 @@ static bool ReadDMAInfo(volatile DMADESC * pDmaDesc, DEVICE_EXTENSION * pdx, ** this is known to be at least 2 or we will not be called. ** ****************************************************************************/ -static int Handle1401Esc(DEVICE_EXTENSION * pdx, char *pCh, +static int Handle1401Esc(DEVICE_EXTENSION *pdx, char *pCh, unsigned int dwCount) { int iReturn = U14ERR_FAIL; - // I have no idea what this next test is about. '?' is 0x3f, which is area 3, code - // 15. At the moment, this is not used, so it does no harm, but unless someone can - // tell me what this is for, it should be removed from this and the Windows driver. - if (pCh[0] == '?') // Is this an information response - { // Parse and save the information + /* I have no idea what this next test is about. '?' is 0x3f, which is area 3, code */ + /* 15. At the moment, this is not used, so it does no harm, but unless someone can */ + /* tell me what this is for, it should be removed from this and the Windows driver. */ + if (pCh[0] == '?') { /* Is this an information response */ + /* Parse and save the information */ } else { - spin_lock(&pdx->stagedLock); // Lock others out + spin_lock(&pdx->stagedLock); /* Lock others out */ - if (ReadDMAInfo(&pdx->rDMAInfo, pdx, pCh, dwCount)) // Get DMA parameters - { - unsigned short wTransType = pdx->rDMAInfo.wTransType; // check transfer type + if (ReadDMAInfo(&pdx->rDMAInfo, pdx, pCh, dwCount)) { /* Get DMA parameters */ + unsigned short wTransType = pdx->rDMAInfo.wTransType; /* check transfer type */ dev_dbg(&pdx->interface->dev, "%s xfer to %s, offset %d, length %d", __func__, pdx->rDMAInfo.bOutWard ? "1401" : "host", pdx->rDMAInfo.dwOffset, pdx->rDMAInfo.dwSize); - if (pdx->bXFerWaiting) // Check here for badly out of kilter... - { // This can never happen, really + if (pdx->bXFerWaiting) { /* Check here for badly out of kilter... */ + /* This can never happen, really */ dev_err(&pdx->interface->dev, "ERROR: DMA setup while transfer still waiting"); spin_unlock(&pdx->stagedLock); @@ -1090,16 +1069,16 @@ static int Handle1401Esc(DEVICE_EXTENSION * pdx, char *pCh, dev_err(&pdx->interface->dev, "%s ReadWriteMem() failed %d", __func__, iReturn); - } else // This covers non-linear transfer setup + } else /* This covers non-linear transfer setup */ dev_err(&pdx->interface->dev, "%s Unknown block xfer type %d", __func__, wTransType); } - } else // Failed to read parameters + } else /* Failed to read parameters */ dev_err(&pdx->interface->dev, "%s ReadDMAInfo() fail", __func__); - spin_unlock(&pdx->stagedLock); // OK here + spin_unlock(&pdx->stagedLock); /* OK here */ } dev_dbg(&pdx->interface->dev, "%s returns %d", __func__, iReturn); @@ -1113,12 +1092,11 @@ static int Handle1401Esc(DEVICE_EXTENSION * pdx, char *pCh, static void ced_readchar_callback(struct urb *pUrb) { DEVICE_EXTENSION *pdx = pUrb->context; - int nGot = pUrb->actual_length; // what we transferred + int nGot = pUrb->actual_length; /* what we transferred */ - if (pUrb->status) // Do we have a problem to handle? - { - int nPipe = pdx->nPipes == 4 ? 1 : 0; // The pipe number to use for error - // sync/async unlink faults aren't errors... just saying device removed or stopped + if (pUrb->status) { /* Do we have a problem to handle? */ + int nPipe = pdx->nPipes == 4 ? 1 : 0; /* The pipe number to use for error */ + /* sync/async unlink faults aren't errors... just saying device removed or stopped */ if (! (pUrb->status == -ENOENT || pUrb->status == -ECONNRESET || pUrb->status == -ESHUTDOWN)) { @@ -1133,27 +1111,26 @@ static void ced_readchar_callback(struct urb *pUrb) spin_lock(&pdx->err_lock); pdx->errors = pUrb->status; spin_unlock(&pdx->err_lock); - nGot = 0; // and tidy up again if so + nGot = 0; /* and tidy up again if so */ - spin_lock(&pdx->charInLock); // already at irq level - pdx->bPipeError[nPipe] = 1; // Flag an error for later + spin_lock(&pdx->charInLock); /* already at irq level */ + pdx->bPipeError[nPipe] = 1; /* Flag an error for later */ } else { - if ((nGot > 1) && ((pdx->pCoherCharIn[0] & 0x7f) == 0x1b)) // Esc sequence? - { - Handle1401Esc(pdx, &pdx->pCoherCharIn[1], nGot - 1); // handle it - spin_lock(&pdx->charInLock); // already at irq level + if ((nGot > 1) && ((pdx->pCoherCharIn[0] & 0x7f) == 0x1b)) { /* Esc sequence? */ + Handle1401Esc(pdx, &pdx->pCoherCharIn[1], nGot - 1); /* handle it */ + spin_lock(&pdx->charInLock); /* already at irq level */ } else { - spin_lock(&pdx->charInLock); // already at irq level + spin_lock(&pdx->charInLock); /* already at irq level */ if (nGot > 0) { unsigned int i; if (nGot < INBUF_SZ) { - pdx->pCoherCharIn[nGot] = 0; // tidy the string + pdx->pCoherCharIn[nGot] = 0; /* tidy the string */ dev_dbg(&pdx->interface->dev, "%s got %d chars >%s<", __func__, nGot, pdx->pCoherCharIn); } - // We know that whatever we read must fit in the input buffer + /* We know that whatever we read must fit in the input buffer */ for (i = 0; i < nGot; i++) { pdx->inputBuffer[pdx->dwInBuffPut++] = pdx->pCoherCharIn[i] & 0x7F; @@ -1162,17 +1139,17 @@ static void ced_readchar_callback(struct urb *pUrb) } if ((pdx->dwNumInput + nGot) <= INBUF_SZ) - pdx->dwNumInput += nGot; // Adjust the buffer count accordingly + pdx->dwNumInput += nGot; /* Adjust the buffer count accordingly */ } else dev_dbg(&pdx->interface->dev, "%s read ZLP", __func__); } } - pdx->bReadCharsPending = false; // No longer have a pending read - spin_unlock(&pdx->charInLock); // already at irq level + pdx->bReadCharsPending = false; /* No longer have a pending read */ + spin_unlock(&pdx->charInLock); /* already at irq level */ - Allowi(pdx); // see if we can do the next one + Allowi(pdx); /* see if we can do the next one */ } /**************************************************************************** @@ -1182,25 +1159,25 @@ static void ced_readchar_callback(struct urb *pUrb) ** we can pick up any inward transfers. This can be called in multiple contexts ** so we use the irqsave version of the spinlock. ****************************************************************************/ -int Allowi(DEVICE_EXTENSION * pdx) +int Allowi(DEVICE_EXTENSION *pdx) { int iReturn = U14ERR_NOERROR; unsigned long flags; - spin_lock_irqsave(&pdx->charInLock, flags); // can be called in multiple contexts + spin_lock_irqsave(&pdx->charInLock, flags); /* can be called in multiple contexts */ - // We don't want char input running while DMA is in progress as we know that this - // can cause sequencing problems for the 2270. So don't. It will also allow the - // ERR response to get back to the host code too early on some PCs, even if there - // is no actual driver failure, so we don't allow this at all. - if (!pdx->bInDrawDown && // stop input if - !pdx->bReadCharsPending && // If no read request outstanding - (pdx->dwNumInput < (INBUF_SZ / 2)) && // and there is some space - (pdx->dwDMAFlag == MODE_CHAR) && // not doing any DMA - (!pdx->bXFerWaiting) && // no xfer waiting to start - (CanAcceptIoRequests(pdx))) // and activity is generally OK - { // then off we go - unsigned int nMax = INBUF_SZ - pdx->dwNumInput; // max we could read - int nPipe = pdx->nPipes == 4 ? 1 : 0; // The pipe number to use + /* We don't want char input running while DMA is in progress as we know that this */ + /* can cause sequencing problems for the 2270. So don't. It will also allow the */ + /* ERR response to get back to the host code too early on some PCs, even if there */ + /* is no actual driver failure, so we don't allow this at all. */ + if (!pdx->bInDrawDown && /* stop input if */ + !pdx->bReadCharsPending && /* If no read request outstanding */ + (pdx->dwNumInput < (INBUF_SZ / 2)) && /* and there is some space */ + (pdx->dwDMAFlag == MODE_CHAR) && /* not doing any DMA */ + (!pdx->bXFerWaiting) && /* no xfer waiting to start */ + (CanAcceptIoRequests(pdx))) { /* and activity is generally OK */ + /* then off we go */ + unsigned int nMax = INBUF_SZ - pdx->dwNumInput; /* max we could read */ + int nPipe = pdx->nPipes == 4 ? 1 : 0; /* The pipe number to use */ dev_dbg(&pdx->interface->dev, "%s %d chars in input buffer", __func__, pdx->dwNumInput); @@ -1209,16 +1186,16 @@ int Allowi(DEVICE_EXTENSION * pdx) usb_rcvintpipe(pdx->udev, pdx->epAddr[nPipe]), pdx->pCoherCharIn, nMax, ced_readchar_callback, pdx, pdx->bInterval); - pdx->pUrbCharIn->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; // short xfers are OK by default - usb_anchor_urb(pdx->pUrbCharIn, &pdx->submitted); // in case we need to kill it + pdx->pUrbCharIn->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; /* short xfers are OK by default */ + usb_anchor_urb(pdx->pUrbCharIn, &pdx->submitted); /* in case we need to kill it */ iReturn = usb_submit_urb(pdx->pUrbCharIn, GFP_ATOMIC); if (iReturn) { - usb_unanchor_urb(pdx->pUrbCharIn); // remove from list of active Urbs - pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later + usb_unanchor_urb(pdx->pUrbCharIn); /* remove from list of active Urbs */ + pdx->bPipeError[nPipe] = 1; /* Flag an error to be handled later */ dev_err(&pdx->interface->dev, "%s submit urb failed: %d", __func__, iReturn); } else - pdx->bReadCharsPending = true; // Flag that we are active here + pdx->bReadCharsPending = true; /* Flag that we are active here */ } spin_unlock_irqrestore(&pdx->charInLock, flags); @@ -1238,15 +1215,15 @@ static long ced_ioctl(struct file *file, unsigned int cmd, unsigned long ulArg) { int err = 0; DEVICE_EXTENSION *pdx = file->private_data; - if (!CanAcceptIoRequests(pdx)) // check we still exist + if (!CanAcceptIoRequests(pdx)) /* check we still exist */ return -ENODEV; - // Check that access is allowed, where is is needed. Anything that would have an indeterminate - // size will be checked by the specific command. - if (_IOC_DIR(cmd) & _IOC_READ) // read from point of view of user... - err = !access_ok(VERIFY_WRITE, (void __user *)ulArg, _IOC_SIZE(cmd)); // is kernel write - else if (_IOC_DIR(cmd) & _IOC_WRITE) // and write from point of view of user... - err = !access_ok(VERIFY_READ, (void __user *)ulArg, _IOC_SIZE(cmd)); // is kernel read + /* Check that access is allowed, where is is needed. Anything that would have an indeterminate */ + /* size will be checked by the specific command. */ + if (_IOC_DIR(cmd) & _IOC_READ) /* read from point of view of user... */ + err = !access_ok(VERIFY_WRITE, (void __user *)ulArg, _IOC_SIZE(cmd)); /* is kernel write */ + else if (_IOC_DIR(cmd) & _IOC_WRITE) /* and write from point of view of user... */ + err = !access_ok(VERIFY_READ, (void __user *)ulArg, _IOC_SIZE(cmd)); /* is kernel read */ if (err) return -EFAULT; @@ -1289,7 +1266,7 @@ static long ced_ioctl(struct file *file, unsigned int cmd, unsigned long ulArg) return -1; case _IOC_NR(IOCTL_CED_GETDRIVERREVISION): - return (2 << 24) | (DRIVERMAJREV << 16) | DRIVERMINREV; // USB | MAJOR | MINOR + return (2 << 24) | (DRIVERMAJREV << 16) | DRIVERMINREV; /* USB | MAJOR | MINOR */ case _IOC_NR(IOCTL_CED_GETTRANSFER): return GetTransfer(pdx, (TGET_TX_BLOCK __user *) ulArg); @@ -1335,7 +1312,7 @@ static long ced_ioctl(struct file *file, unsigned int cmd, unsigned long ulArg) return DbgStopLoop(pdx); case _IOC_NR(IOCTL_CED_FULLRESET): - pdx->bForceReset = true; // Set a flag for a full reset + pdx->bForceReset = true; /* Set a flag for a full reset */ break; case _IOC_NR(IOCTL_CED_SETCIRCULAR): @@ -1378,8 +1355,8 @@ static struct usb_class_driver ced_class = { .minor_base = USB_CED_MINOR_BASE, }; -// Check that the device that matches a 1401 vendor and product ID is OK to use and -// initialise our DEVICE_EXTENSION. +/* Check that the device that matches a 1401 vendor and product ID is OK to use and */ +/* initialise our DEVICE_EXTENSION. */ static int ced_probe(struct usb_interface *interface, const struct usb_device_id *id) { @@ -1389,23 +1366,22 @@ static int ced_probe(struct usb_interface *interface, int i, bcdDevice; int retval = -ENOMEM; - // allocate memory for our device extension and initialize it + /* allocate memory for our device extension and initialize it */ pdx = kzalloc(sizeof(*pdx), GFP_KERNEL); if (!pdx) goto error; - for (i = 0; i < MAX_TRANSAREAS; ++i) // Initialise the wait queues - { + for (i = 0; i < MAX_TRANSAREAS; ++i) { /* Initialise the wait queues */ init_waitqueue_head(&pdx->rTransDef[i].wqEvent); } - // Put initialises for our stuff here. Note that all of *pdx is zero, so - // no need to explicitly zero it. + /* Put initialises for our stuff here. Note that all of *pdx is zero, so */ + /* no need to explicitly zero it. */ spin_lock_init(&pdx->charOutLock); spin_lock_init(&pdx->charInLock); spin_lock_init(&pdx->stagedLock); - // Initialises from the skeleton stuff + /* Initialises from the skeleton stuff */ kref_init(&pdx->kref); mutex_init(&pdx->io_mutex); spin_lock_init(&pdx->err_lock); @@ -1414,7 +1390,7 @@ static int ced_probe(struct usb_interface *interface, pdx->udev = usb_get_dev(interface_to_usbdev(interface)); pdx->interface = interface; - // Attempt to identify the device + /* Attempt to identify the device */ bcdDevice = pdx->udev->descriptor.bcdDevice; i = (bcdDevice >> 8); if (i == 0) @@ -1426,8 +1402,8 @@ static int ced_probe(struct usb_interface *interface, __func__, bcdDevice); goto error; } - // set up the endpoint information. We only care about the number of EP as - // we know that we are dealing with a 1401 device. + /* set up the endpoint information. We only care about the number of EP as */ + /* we know that we are dealing with a 1401 device. */ iface_desc = interface->cur_altsetting; pdx->nPipes = iface_desc->desc.bNumEndpoints; dev_info(&interface->dev, "1401Type=%d with %d End Points", @@ -1435,10 +1411,10 @@ static int ced_probe(struct usb_interface *interface, if ((pdx->nPipes < 3) || (pdx->nPipes > 4)) goto error; - // Allocate the URBs we hold for performing transfers - pdx->pUrbCharOut = usb_alloc_urb(0, GFP_KERNEL); // character output URB - pdx->pUrbCharIn = usb_alloc_urb(0, GFP_KERNEL); // character input URB - pdx->pStagedUrb = usb_alloc_urb(0, GFP_KERNEL); // block transfer URB + /* Allocate the URBs we hold for performing transfers */ + pdx->pUrbCharOut = usb_alloc_urb(0, GFP_KERNEL); /* character output URB */ + pdx->pUrbCharIn = usb_alloc_urb(0, GFP_KERNEL); /* character input URB */ + pdx->pStagedUrb = usb_alloc_urb(0, GFP_KERNEL); /* block transfer URB */ if (!pdx->pUrbCharOut || !pdx->pUrbCharIn || !pdx->pStagedUrb) { dev_err(&interface->dev, "%s URB alloc failed", __func__); goto error; @@ -1464,15 +1440,14 @@ static int ced_probe(struct usb_interface *interface, pdx->epAddr[i] = endpoint->bEndpointAddress; dev_info(&interface->dev, "Pipe %d, ep address %02x", i, pdx->epAddr[i]); - if (((pdx->nPipes == 3) && (i == 0)) || // if char input end point + if (((pdx->nPipes == 3) && (i == 0)) || /* if char input end point */ ((pdx->nPipes == 4) && (i == 1))) { - pdx->bInterval = endpoint->bInterval; // save the endpoint interrupt interval + pdx->bInterval = endpoint->bInterval; /* save the endpoint interrupt interval */ dev_info(&interface->dev, "Pipe %d, bInterval = %d", i, pdx->bInterval); } - // Detect USB2 by checking last ep size (64 if USB1) - if (i == pdx->nPipes - 1) // if this is the last ep (bulk) - { + /* Detect USB2 by checking last ep size (64 if USB1) */ + if (i == pdx->nPipes - 1) { /* if this is the last ep (bulk) */ pdx->bIsUSB2 = le16_to_cpu(endpoint->wMaxPacketSize) > 64; dev_info(&pdx->interface->dev, "USB%d", @@ -1501,7 +1476,7 @@ static int ced_probe(struct usb_interface *interface, error: if (pdx) - kref_put(&pdx->kref, ced_delete); // frees allocated memory + kref_put(&pdx->kref, ced_delete); /* frees allocated memory */ return retval; } @@ -1511,39 +1486,39 @@ static void ced_disconnect(struct usb_interface *interface) int minor = interface->minor; int i; - usb_set_intfdata(interface, NULL); // remove the pdx from the interface - usb_deregister_dev(interface, &ced_class); // give back our minor device number + usb_set_intfdata(interface, NULL); /* remove the pdx from the interface */ + usb_deregister_dev(interface, &ced_class); /* give back our minor device number */ - mutex_lock(&pdx->io_mutex); // stop more I/O starting while... - ced_draw_down(pdx); // ...wait for then kill any io + mutex_lock(&pdx->io_mutex); /* stop more I/O starting while... */ + ced_draw_down(pdx); /* ...wait for then kill any io */ for (i = 0; i < MAX_TRANSAREAS; ++i) { - int iErr = ClearArea(pdx, i); // ...release any used memory + int iErr = ClearArea(pdx, i); /* ...release any used memory */ if (iErr == U14ERR_UNLOCKFAIL) dev_err(&pdx->interface->dev, "%s Area %d was in used", __func__, i); } - pdx->interface = NULL; // ...we kill off link to interface + pdx->interface = NULL; /* ...we kill off link to interface */ mutex_unlock(&pdx->io_mutex); usb_kill_anchored_urbs(&pdx->submitted); - kref_put(&pdx->kref, ced_delete); // decrement our usage count + kref_put(&pdx->kref, ced_delete); /* decrement our usage count */ dev_info(&interface->dev, "USB cedusb #%d now disconnected", minor); } -// Wait for all the urbs we know of to be done with, then kill off any that -// are left. NBNB we will need to have a mechanism to stop circular xfers -// from trying to fire off more urbs. We will wait up to 3 seconds for Urbs -// to be done. -void ced_draw_down(DEVICE_EXTENSION * pdx) +/* Wait for all the urbs we know of to be done with, then kill off any that */ +/* are left. NBNB we will need to have a mechanism to stop circular xfers */ +/* from trying to fire off more urbs. We will wait up to 3 seconds for Urbs */ +/* to be done. */ +void ced_draw_down(DEVICE_EXTENSION *pdx) { int time; dev_dbg(&pdx->interface->dev, "%s called", __func__); pdx->bInDrawDown = true; time = usb_wait_anchor_empty_timeout(&pdx->submitted, 3000); - if (!time) { // if we timed out we kill the urbs + if (!time) { /* if we timed out we kill the urbs */ usb_kill_anchored_urbs(&pdx->submitted); dev_err(&pdx->interface->dev, "%s timed out", __func__); } diff --git a/drivers/staging/ced1401/usb1401.h b/drivers/staging/ced1401/usb1401.h index 8fc6958b6f08..f031e3a2c7cf 100644 --- a/drivers/staging/ced1401/usb1401.h +++ b/drivers/staging/ced1401/usb1401.h @@ -26,31 +26,32 @@ #define UINT unsigned int #endif -/// Device type codes, but these don't need to be extended - a succession is assumed -/// These are set for usb from the bcdDevice field (suitably mangled). Future devices -/// will be added in order of device creation to the list, so the names here are just -/// to help use remember which device is which. The U14ERR_... values follow the same -/// pattern for modern devices. -#define TYPEUNKNOWN -1 // dont know -#define TYPE1401 0 // standard 1401 -#define TYPEPLUS 1 // 1401 plus -#define TYPEU1401 2 // u1401 -#define TYPEPOWER 3 // Power1401 -#define TYPEU14012 4 // u1401 mkII -#define TYPEPOWER2 5 // Power1401 mk II -#define TYPEMICRO3 6 // Micro1401-3 -#define TYPEPOWER3 7 // Power1401-3 +/** Device type codes, but these don't need to be extended - a succession is assumed +** These are set for usb from the bcdDevice field (suitably mangled). Future devices +** will be added in order of device creation to the list, so the names here are just +** to help use remember which device is which. The U14ERR_... values follow the same +** pattern for modern devices.a +**/ +#define TYPEUNKNOWN -1 /* dont know */ +#define TYPE1401 0 /* standard 1401 */ +#define TYPEPLUS 1 /* 1401 plus */ +#define TYPEU1401 2 /* u1401 */ +#define TYPEPOWER 3 /* Power1401 */ +#define TYPEU14012 4 /* u1401 mkII */ +#define TYPEPOWER2 5 /* Power1401 mk II */ +#define TYPEMICRO3 6 /* Micro1401-3 */ +#define TYPEPOWER3 7 /* Power1401-3 */ -/// Some useful defines of constants. DONT FORGET to change the version in the -/// resources whenever you change it here!. -#define DRIVERMAJREV 2 // driver revision level major (match windows) -#define DRIVERMINREV 0 // driver revision level minor +/* Some useful defines of constants. DONT FORGET to change the version in the */ +/* resources whenever you change it here!. */ +#define DRIVERMAJREV 2 /* driver revision level major (match windows) */ +#define DRIVERMINREV 0 /* driver revision level minor */ -/// Definitions of the various block transfer command codes -#define TM_EXTTOHOST 8 // extended tohost -#define TM_EXTTO1401 9 // extended to1401 +/* Definitions of the various block transfer command codes */ +#define TM_EXTTOHOST 8 /* extended tohost */ +#define TM_EXTTO1401 9 /* extended to1401 */ -/// Definitions of values in usbReqtype. Used in sorting out setup actions +/* Definitions of values in usbReqtype. Used in sorting out setup actions */ #define H_TO_D 0x00 #define D_TO_H 0x80 #define VENDOR 0x40 @@ -58,7 +59,7 @@ #define INTREQ 0x01 #define ENDREQ 0x02 -/// Definition of values in usbRequest, again used to sort out setup +/* Definition of values in usbRequest, again used to sort out setup */ #define GET_STATUS 0x00 #define CLEAR_FEATURE 0x01 #define SET_FEATURE 0x03 @@ -71,8 +72,8 @@ #define SET_INTERFACE 0x0b #define SYNCH_FRAME 0x0c -/// Definitions of the various debug command codes understood by the 1401. These -/// are used in various vendor-specific commands to achieve the desired effect +/* Definitions of the various debug command codes understood by the 1401. These */ +/* are used in various vendor-specific commands to achieve the desired effect */ #define DB_GRAB 0x50 /* Grab is a NOP for USB */ #define DB_FREE 0x51 /* Free is a NOP for the USB */ #define DB_SETADD 0x52 /* Set debug address (double) */ @@ -91,139 +92,135 @@ #define CR_CHAR 0x0D /* The carriage return character */ #define CR_CHAR_80 0x8d /* and with bit 7 set */ -/// A structure holding information about a block of memory for use in circular transfers -typedef struct circBlk -{ - volatile UINT dwOffset; /* Offset within area of block start */ - volatile UINT dwSize; /* Size of the block, in bytes (0 = unused) */ +/* A structure holding information about a block of memory for use in circular transfers */ +typedef struct circBlk { + volatile UINT dwOffset; /* Offset within area of block start */ + volatile UINT dwSize; /* Size of the block, in bytes (0 = unused) */ } CIRCBLK; -/// A structure holding all of the information about a transfer area - an area of -/// memory set up for use either as a source or destination in DMA transfers. -typedef struct transarea -{ - void* lpvBuff; // User address of xfer area saved for completeness - UINT dwBaseOffset; // offset to start of xfer area in first page - UINT dwLength; // Length of xfer area, in bytes - struct page **pPages; // Points at array of locked down pages - int nPages; // number of pages that are locked down - bool bUsed; // Is this structure in use? - bool bCircular; // Is this area for circular transfers? - bool bCircToHost; // Flag for direction of circular transfer - bool bEventToHost; // Set event on transfer to host? - int iWakeUp; // Set 1 on event, cleared by TestEvent() - UINT dwEventSt; // Defines section within xfer area for... - UINT dwEventSz; // ...notification by the event SZ is 0 if unset - CIRCBLK aBlocks[2]; // Info on a pair of circular blocks - wait_queue_head_t wqEvent; // The wait queue for events in this area MUST BE LAST +/* A structure holding all of the information about a transfer area - an area of */ +/* memory set up for use either as a source or destination in DMA transfers. */ +typedef struct transarea { + void *lpvBuff; /* User address of xfer area saved for completeness */ + UINT dwBaseOffset; /* offset to start of xfer area in first page */ + UINT dwLength; /* Length of xfer area, in bytes */ + struct page **pPages; /* Points at array of locked down pages */ + int nPages; /* number of pages that are locked down */ + bool bUsed; /* Is this structure in use? */ + bool bCircular; /* Is this area for circular transfers? */ + bool bCircToHost; /* Flag for direction of circular transfer */ + bool bEventToHost; /* Set event on transfer to host? */ + int iWakeUp; /* Set 1 on event, cleared by TestEvent() */ + UINT dwEventSt; /* Defines section within xfer area for... */ + UINT dwEventSz; /* ...notification by the event SZ is 0 if unset */ + CIRCBLK aBlocks[2]; /* Info on a pair of circular blocks */ + wait_queue_head_t wqEvent; /* The wait queue for events in this area MUST BE LAST */ } TRANSAREA; -/// The DMADESC structure is used to hold information on the transfer in progress. It -/// is set up by ReadDMAInfo, using information sent by the 1401 in an escape sequence. -typedef struct dmadesc -{ - unsigned short wTransType; /* transfer type as TM_xxx above */ - unsigned short wIdent; /* identifier word */ - unsigned int dwSize; /* bytes to transfer */ - unsigned int dwOffset; /* offset into transfer area for trans */ - bool bOutWard; /* true when data is going TO 1401 */ +/* The DMADESC structure is used to hold information on the transfer in progress. It */ +/* is set up by ReadDMAInfo, using information sent by the 1401 in an escape sequence. */ +typedef struct dmadesc { + unsigned short wTransType; /* transfer type as TM_xxx above */ + unsigned short wIdent; /* identifier word */ + unsigned int dwSize; /* bytes to transfer */ + unsigned int dwOffset; /* offset into transfer area for trans */ + bool bOutWard; /* true when data is going TO 1401 */ } DMADESC; #define INBUF_SZ 256 /* input buffer size */ #define OUTBUF_SZ 256 /* output buffer size */ -#define STAGED_SZ 0x10000 // size of coherent buffer for staged transfers +#define STAGED_SZ 0x10000 /* size of coherent buffer for staged transfers */ -/// Structure to hold all of our device specific stuff. We are making this as similar as we -/// can to the Windows driver to help in our understanding of what is going on. -typedef struct _DEVICE_EXTENSION -{ - char inputBuffer[INBUF_SZ]; /* The two buffers */ - char outputBuffer[OUTBUF_SZ]; /* accessed by the host functions */ - volatile unsigned int dwNumInput; /* num of chars in input buffer */ - volatile unsigned int dwInBuffGet; /* where to get from input buffer */ - volatile unsigned int dwInBuffPut; /* where to put into input buffer */ - volatile unsigned int dwNumOutput; /* num of chars in output buffer */ - volatile unsigned int dwOutBuffGet; /* where to get from output buffer*/ - volatile unsigned int dwOutBuffPut; /* where to put into output buffer*/ +/* Structure to hold all of our device specific stuff. We are making this as similar as we */ +/* can to the Windows driver to help in our understanding of what is going on. */ +typedef struct _DEVICE_EXTENSION { + char inputBuffer[INBUF_SZ]; /* The two buffers */ + char outputBuffer[OUTBUF_SZ]; /* accessed by the host functions */ + volatile unsigned int dwNumInput; /* num of chars in input buffer */ + volatile unsigned int dwInBuffGet; /* where to get from input buffer */ + volatile unsigned int dwInBuffPut; /* where to put into input buffer */ + volatile unsigned int dwNumOutput; /* num of chars in output buffer */ + volatile unsigned int dwOutBuffGet; /* where to get from output buffer*/ + volatile unsigned int dwOutBuffPut; /* where to put into output buffer*/ - volatile bool bSendCharsPending; /* Flag to indicate sendchar active */ - volatile bool bReadCharsPending; /* Flag to indicate a read is primed */ - char* pCoherCharOut; /* special aligned buffer for chars to 1401 */ - struct urb* pUrbCharOut; /* urb used for chars to 1401 */ - char* pCoherCharIn; /* special aligned buffer for chars to host */ - struct urb* pUrbCharIn; /* urb used for chars to host */ + volatile bool bSendCharsPending; /* Flag to indicate sendchar active */ + volatile bool bReadCharsPending; /* Flag to indicate a read is primed */ + char *pCoherCharOut; /* special aligned buffer for chars to 1401 */ + struct urb *pUrbCharOut; /* urb used for chars to 1401 */ + char *pCoherCharIn; /* special aligned buffer for chars to host */ + struct urb *pUrbCharIn; /* urb used for chars to host */ - spinlock_t charOutLock; /* to protect the outputBuffer and outputting */ - spinlock_t charInLock; /* to protect the inputBuffer and char reads */ - __u8 bInterval; /* Interrupt end point interval */ + spinlock_t charOutLock; /* to protect the outputBuffer and outputting */ + spinlock_t charInLock; /* to protect the inputBuffer and char reads */ + __u8 bInterval; /* Interrupt end point interval */ - volatile unsigned int dwDMAFlag; /* state of DMA */ - TRANSAREA rTransDef[MAX_TRANSAREAS];/* transfer area info */ - volatile DMADESC rDMAInfo; // info on current DMA transfer - volatile bool bXFerWaiting; // Flag set if DMA transfer stalled - volatile bool bInDrawDown; // Flag that we want to halt transfers + volatile unsigned int dwDMAFlag; /* state of DMA */ + TRANSAREA rTransDef[MAX_TRANSAREAS];/* transfer area info */ + volatile DMADESC rDMAInfo; /* info on current DMA transfer */ + volatile bool bXFerWaiting; /* Flag set if DMA transfer stalled */ + volatile bool bInDrawDown; /* Flag that we want to halt transfers */ - // Parameters relating to a block read\write that is in progress. Some of these values - // are equivalent to values in rDMAInfo. The values here are those in use, while those - // in rDMAInfo are those received from the 1401 via an escape sequence. If another - // escape sequence arrives before the previous xfer ends, rDMAInfo values are updated while these - // are used to finish off the current transfer. - volatile short StagedId; // The transfer area id for this transfer - volatile bool StagedRead; // Flag TRUE for read from 1401, FALSE for write - volatile unsigned int StagedLength; // Total length of this transfer - volatile unsigned int StagedOffset; // Offset within memory area for transfer start - volatile unsigned int StagedDone; // Bytes transferred so far - volatile bool bStagedUrbPending; // Flag to indicate active - char* pCoherStagedIO; // buffer used for block transfers - struct urb* pStagedUrb; // The URB to use - spinlock_t stagedLock; // protects ReadWriteMem() and circular buffer stuff + /* Parameters relating to a block read\write that is in progress. Some of these values */ + /* are equivalent to values in rDMAInfo. The values here are those in use, while those */ + /* in rDMAInfo are those received from the 1401 via an escape sequence. If another */ + /* escape sequence arrives before the previous xfer ends, rDMAInfo values are updated while these */ + /* are used to finish off the current transfer. */ + volatile short StagedId; /* The transfer area id for this transfer */ + volatile bool StagedRead; /* Flag TRUE for read from 1401, FALSE for write */ + volatile unsigned int StagedLength; /* Total length of this transfer */ + volatile unsigned int StagedOffset; /* Offset within memory area for transfer start */ + volatile unsigned int StagedDone; /* Bytes transferred so far */ + volatile bool bStagedUrbPending; /* Flag to indicate active */ + char *pCoherStagedIO; /* buffer used for block transfers */ + struct urb *pStagedUrb; /* The URB to use */ + spinlock_t stagedLock; /* protects ReadWriteMem() and circular buffer stuff */ - short s1401Type; // type of 1401 attached - short sCurrentState; // current error state - bool bIsUSB2; // type of the interface we connect to - bool bForceReset; // Flag to make sure we get a real reset - __u32 statBuf[2]; // buffer for 1401 state info + short s1401Type; /* type of 1401 attached */ + short sCurrentState; /* current error state */ + bool bIsUSB2; /* type of the interface we connect to */ + bool bForceReset; /* Flag to make sure we get a real reset */ + __u32 statBuf[2]; /* buffer for 1401 state info */ - unsigned long ulSelfTestTime; // used to timeout self test + unsigned long ulSelfTestTime; /* used to timeout self test */ - int nPipes; // Should be 3 or 4 depending on 1401 usb chip - int bPipeError[4]; // set non-zero if an error on one of the pipe - __u8 epAddr[4]; // addresses of the 3/4 end points + int nPipes; /* Should be 3 or 4 depending on 1401 usb chip */ + int bPipeError[4]; /* set non-zero if an error on one of the pipe */ + __u8 epAddr[4]; /* addresses of the 3/4 end points */ - struct usb_device *udev; // the usb device for this device - struct usb_interface *interface; // the interface for this device, NULL if removed - struct usb_anchor submitted; // in case we need to retract our submissions - struct mutex io_mutex; // synchronize I/O with disconnect, one user-mode caller at a time + struct usb_device *udev; /* the usb device for this device */ + struct usb_interface *interface; /* the interface for this device, NULL if removed */ + struct usb_anchor submitted; /* in case we need to retract our submissions */ + struct mutex io_mutex; /* synchronize I/O with disconnect, one user-mode caller at a time */ - int errors; // the last request tanked - int open_count; // count the number of openers - spinlock_t err_lock; // lock for errors - struct kref kref; -}DEVICE_EXTENSION, *PDEVICE_EXTENSION; + int errors; /* the last request tanked */ + int open_count; /* count the number of openers */ + spinlock_t err_lock; /* lock for errors */ + struct kref kref; +} DEVICE_EXTENSION, *PDEVICE_EXTENSION; #define to_DEVICE_EXTENSION(d) container_of(d, DEVICE_EXTENSION, kref) -/// Definitions of routimes used between compilation object files -// in usb1401.c -extern int Allowi(DEVICE_EXTENSION* pdx); -extern int SendChars(DEVICE_EXTENSION* pdx); +/* Definitions of routimes used between compilation object files */ +/* in usb1401.c */ +extern int Allowi(DEVICE_EXTENSION *pdx); +extern int SendChars(DEVICE_EXTENSION *pdx); extern void ced_draw_down(DEVICE_EXTENSION *pdx); extern int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent, - unsigned int dwOffs, unsigned int dwLen); + unsigned int dwOffs, unsigned int dwLen); -// in ced_ioc.c +/* in ced_ioc.c */ extern int ClearArea(DEVICE_EXTENSION *pdx, int nArea); -extern int SendString(DEVICE_EXTENSION* pdx, const char __user* pData, unsigned int n); +extern int SendString(DEVICE_EXTENSION *pdx, const char __user *pData, unsigned int n); extern int SendChar(DEVICE_EXTENSION *pdx, char c); -extern int Get1401State(DEVICE_EXTENSION* pdx, __u32* state, __u32* error); +extern int Get1401State(DEVICE_EXTENSION *pdx, __u32 *state, __u32 *error); extern int ReadWrite_Cancel(DEVICE_EXTENSION *pdx); -extern bool Is1401(DEVICE_EXTENSION* pdx); -extern bool QuickCheck(DEVICE_EXTENSION* pdx, bool bTestBuff, bool bCanReset); +extern bool Is1401(DEVICE_EXTENSION *pdx); +extern bool QuickCheck(DEVICE_EXTENSION *pdx, bool bTestBuff, bool bCanReset); extern int Reset1401(DEVICE_EXTENSION *pdx); extern int GetChar(DEVICE_EXTENSION *pdx); -extern int GetString(DEVICE_EXTENSION *pdx, char __user* pUser, int n); +extern int GetString(DEVICE_EXTENSION *pdx, char __user *pUser, int n); extern int SetTransfer(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD); extern int UnsetTransfer(DEVICE_EXTENSION *pdx, int nArea); -extern int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user*pTE); +extern int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user *pTE); extern int Stat1401(DEVICE_EXTENSION *pdx); extern int LineCount(DEVICE_EXTENSION *pdx); extern int GetOutBufSpace(DEVICE_EXTENSION *pdx); @@ -235,15 +232,15 @@ extern int StartSelfTest(DEVICE_EXTENSION *pdx); extern int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST); extern int TypeOf1401(DEVICE_EXTENSION *pdx); extern int TransferFlags(DEVICE_EXTENSION *pdx); -extern int DbgPeek(DEVICE_EXTENSION *pdx, TDBGBLOCK __user* pDB); +extern int DbgPeek(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB); extern int DbgPoke(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB); extern int DbgRampData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB); extern int DbgRampAddr(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB); extern int DbgGetData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB); extern int DbgStopLoop(DEVICE_EXTENSION *pdx); extern int SetCircular(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD); -extern int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB); -extern int FreeCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB); +extern int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user *pCB); +extern int FreeCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user *pCB); extern int WaitEvent(DEVICE_EXTENSION *pdx, int nArea, int msTimeOut); extern int TestEvent(DEVICE_EXTENSION *pdx, int nArea); #endif diff --git a/drivers/staging/ced1401/use1401.h b/drivers/staging/ced1401/use1401.h index 86294e21db0c..b7997c9835c2 100644 --- a/drivers/staging/ced1401/use1401.h +++ b/drivers/staging/ced1401/use1401.h @@ -11,16 +11,16 @@ #define __USE1401_H__ #include "machine.h" -// Some definitions to make things compatible. If you want to use Use1401 directly -// from a Windows program you should define U14_NOT_DLL, in which case you also -// MUST make sure that your application startup code calls U14InitLib(). -// DLL_USE1401 is defined when you are building the Use1401 dll, not otherwise. +/* Some definitions to make things compatible. If you want to use Use1401 directly */ +/* from a Windows program you should define U14_NOT_DLL, in which case you also */ +/* MUST make sure that your application startup code calls U14InitLib(). */ +/* DLL_USE1401 is defined when you are building the Use1401 dll, not otherwise. */ #ifdef _IS_WINDOWS_ #ifndef U14_NOT_DLL #ifdef DLL_USE1401 -#define U14API(retType) retType DllExport __stdcall +#define U14API(retType) (retType DllExport __stdcall) #else -#define U14API(retType) retType DllImport __stdcall +#define U14API(retType) (retType DllImport __stdcall) #endif #endif @@ -36,7 +36,7 @@ #ifdef _QT #ifndef U14_NOT_DLL #undef U14API -#define U14API(retType) retType __declspec(dllimport) __stdcall +#define U14API(retType) (retType __declspec(dllimport) __stdcall) #endif #undef U14LONG #define U14LONG int @@ -50,20 +50,20 @@ #define U14LONG long #endif -/// Error codes: We need them here as user space can see them. -#define U14ERR_NOERROR 0 // no problems +/* Error codes: We need them here as user space can see them. */ +#define U14ERR_NOERROR 0 /* no problems */ -/// Device error codes, but these don't need to be extended - a succession is assumed -#define U14ERR_STD 4 // standard 1401 connected -#define U14ERR_U1401 5 // u1401 connected -#define U14ERR_PLUS 6 // 1401 plus connected -#define U14ERR_POWER 7 // Power1401 connected -#define U14ERR_U14012 8 // u1401 mkII connected +/* Device error codes, but these don't need to be extended - a succession is assumed */ +#define U14ERR_STD 4 /* standard 1401 connected */ +#define U14ERR_U1401 5 /* u1401 connected */ +#define U14ERR_PLUS 6 /* 1401 plus connected */ +#define U14ERR_POWER 7 /* Power1401 connected */ +#define U14ERR_U14012 8 /* u1401 mkII connected */ #define U14ERR_POWER2 9 #define U14ERR_U14013 10 #define U14ERR_POWER3 11 -/// NBNB Error numbers need shifting as some linux error codes start at 512 +/* NBNB Error numbers need shifting as some linux error codes start at 512 */ #define U14ERR(n) (n+U14ERRBASE) #define U14ERR_OFF U14ERR(0) /* 1401 there but switched off */ #define U14ERR_NC U14ERR(-1) /* 1401 not connected */ @@ -113,7 +113,7 @@ #define U14ERR_DRIVCOMMS U14ERR(-110) /* failed talking to driver */ #define U14ERR_OUTOFMEMORY U14ERR(-111) /* needed memory and couldnt get it*/ -/// 1401 type codes. +/* / 1401 type codes. */ #define U14TYPE1401 0 /* standard 1401 */ #define U14TYPEPLUS 1 /* 1401 plus */ #define U14TYPEU1401 2 /* u1401 */ @@ -124,9 +124,9 @@ #define U14TYPEPOWER3 7 /* power1401-3 */ #define U14TYPEUNKNOWN -1 /* dont know */ -/// Transfer flags to allow driver capabilities to be interrogated +/* Transfer flags to allow driver capabilities to be interrogated */ -/// Constants for transfer flags +/* Constants for transfer flags */ #define U14TF_USEDMA 1 /* Transfer flag for use DMA */ #define U14TF_MULTIA 2 /* Transfer flag for multi areas */ #define U14TF_FIFO 4 /* for FIFO interface card */ @@ -138,18 +138,18 @@ #define U14TF_DIAG 256 /* Diagnostics/debug functions */ #define U14TF_CIRC14 512 /* Circular-mode to 1401 */ -/// Definitions of element sizes for DMA transfers - to allow byte-swapping +/* Definitions of element sizes for DMA transfers - to allow byte-swapping */ #define ESZBYTES 0 /* BYTE element size value */ -#define ESZWORDS 1 /* WORD element size value */ +#define ESZWORDS 1 /* unsigned short element size value */ #define ESZLONGS 2 /* long element size value */ #define ESZUNKNOWN 0 /* unknown element size value */ -/// These define required access types for the debug/diagnostics function +/* These define required access types for the debug/diagnostics function */ #define BYTE_SIZE 1 /* 8-bit access */ #define WORD_SIZE 2 /* 16-bit access */ #define LONG_SIZE 3 /* 32-bit access */ -/// Stuff used by U14_GetTransfer +/* Stuff used by U14_GetTransfer */ #define GET_TX_MAXENTRIES 257 /* (max length / page size + 1) */ #ifdef _IS_WINDOWS_ @@ -157,19 +157,19 @@ typedef struct /* used for U14_GetTransfer results */ { /* Info on a single mapped block */ - U14LONG physical; - U14LONG size; + U14LONG physical; + U14LONG size; } TXENTRY; typedef struct TGetTxBlock /* used for U14_GetTransfer results */ { /* matches structure in VXD */ - U14LONG size; - U14LONG linear; - short seg; - short reserved; - short avail; /* number of available entries */ - short used; /* number of used entries */ - TXENTRY entries[GET_TX_MAXENTRIES]; /* Array of mapped block info */ + U14LONG size; + U14LONG linear; + short seg; + short reserved; + short avail; /* number of available entries */ + short used; /* number of used entries */ + TXENTRY entries[GET_TX_MAXENTRIES]; /* Array of mapped block info */ } TGET_TX_BLOCK; typedef TGET_TX_BLOCK *LPGET_TX_BLOCK; @@ -180,19 +180,19 @@ typedef TGET_TX_BLOCK *LPGET_TX_BLOCK; #ifdef LINUX typedef struct /* used for U14_GetTransfer results */ { /* Info on a single mapped block */ - long long physical; - long size; + long long physical; + long size; } TXENTRY; typedef struct TGetTxBlock /* used for U14_GetTransfer results */ { /* matches structure in VXD */ - long long linear; /* linear address */ - long size; /* total size of the mapped area, holds id when called */ - short seg; /* segment of the address for Win16 */ - short reserved; - short avail; /* number of available entries */ - short used; /* number of used entries */ - TXENTRY entries[GET_TX_MAXENTRIES]; /* Array of mapped block info */ + long long linear; /* linear address */ + long size; /* total size of the mapped area, holds id when called */ + short seg; /* segment of the address for Win16 */ + short reserved; + short avail; /* number of available entries */ + short used; /* number of used entries */ + TXENTRY entries[GET_TX_MAXENTRIES]; /* Array of mapped block info */ } TGET_TX_BLOCK; #endif @@ -200,84 +200,84 @@ typedef struct TGetTxBlock /* used for U14_GetTransfer results */ extern "C" { #endif -U14API(int) U14WhenToTimeOut(short hand); // when to timeout in ms -U14API(short) U14PassedTime(int iTime); // non-zero if iTime passed +U14API(int) U14WhenToTimeOut(short hand); /* when to timeout in ms */ +U14API(short) U14PassedTime(int iTime); /* non-zero if iTime passed */ -U14API(short) U14LastErrCode(short hand); +U14API(short) U14LastErrCode(short hand); -U14API(short) U14Open1401(short n1401); -U14API(short) U14Close1401(short hand); -U14API(short) U14Reset1401(short hand); -U14API(short) U14ForceReset(short hand); -U14API(short) U14TypeOf1401(short hand); -U14API(short) U14NameOf1401(short hand, char* pBuf, WORD wMax); +U14API(short) U14Open1401(short n1401); +U14API(short) U14Close1401(short hand); +U14API(short) U14Reset1401(short hand); +U14API(short) U14ForceReset(short hand); +U14API(short) U14TypeOf1401(short hand); +U14API(short) U14NameOf1401(short hand, char *pBuf, unsigned short wMax); -U14API(short) U14Stat1401(short hand); -U14API(short) U14CharCount(short hand); -U14API(short) U14LineCount(short hand); +U14API(short) U14Stat1401(short hand); +U14API(short) U14CharCount(short hand); +U14API(short) U14LineCount(short hand); -U14API(short) U14SendString(short hand, const char* pString); -U14API(short) U14GetString(short hand, char* pBuffer, WORD wMaxLen); -U14API(short) U14SendChar(short hand, char cChar); -U14API(short) U14GetChar(short hand, char* pcChar); +U14API(short) U14SendString(short hand, const char *pString); +U14API(short) U14GetString(short hand, char *pBuffer, unsigned short wMaxLen); +U14API(short) U14SendChar(short hand, char cChar); +U14API(short) U14GetChar(short hand, char *pcChar); -U14API(short) U14LdCmd(short hand, const char* command); -U14API(DWORD) U14Ld(short hand, const char* vl, const char* str); +U14API(short) U14LdCmd(short hand, const char *command); +U14API(unsigned int) U14Ld(short hand, const char *vl, const char *str); -U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, - DWORD dwLength, short eSz); -U14API(short) U14UnSetTransfer(short hand, WORD wArea); -U14API(short) U14SetTransferEvent(short hand, WORD wArea, BOOL bEvent, - BOOL bToHost, DWORD dwStart, DWORD dwLength); -U14API(int) U14TestTransferEvent(short hand, WORD wArea); -U14API(int) U14WaitTransferEvent(short hand, WORD wArea, int msTimeOut); -U14API(short) U14GetTransfer(short hand, TGET_TX_BLOCK *pTransBlock); +U14API(short) U14SetTransArea(short hand, unsigned short wArea, void *pvBuff, + unsigned int dwLength, short eSz); +U14API(short) U14UnSetTransfer(short hand, unsigned short wArea); +U14API(short) U14SetTransferEvent(short hand, unsigned short wArea, BOOL bEvent, + BOOL bToHost, unsigned int dwStart, unsigned int dwLength); +U14API(int) U14TestTransferEvent(short hand, unsigned short wArea); +U14API(int) U14WaitTransferEvent(short hand, unsigned short wArea, int msTimeOut); +U14API(short) U14GetTransfer(short hand, TGET_TX_BLOCK *pTransBlock); -U14API(short) U14ToHost(short hand, char* pAddrHost,DWORD dwSize,DWORD dw1401, - short eSz); -U14API(short) U14To1401(short hand, const char* pAddrHost,DWORD dwSize,DWORD dw1401, - short eSz); +U14API(short) U14ToHost(short hand, char *pAddrHost, unsigned int dwSize, unsigned int dw1401, + short eSz); +U14API(short) U14To1401(short hand, const char *pAddrHost, unsigned int dwSize, unsigned int dw1401, + short eSz); -U14API(short) U14SetCircular(short hand, WORD wArea, BOOL bToHost, void *pvBuff, - DWORD dwLength); +U14API(short) U14SetCircular(short hand, unsigned short wArea, BOOL bToHost, void *pvBuff, + unsigned int dwLength); -U14API(int) U14GetCircBlk(short hand, WORD wArea, DWORD *pdwOffs); -U14API(int) U14FreeCircBlk(short hand, WORD wArea, DWORD dwOffs, DWORD dwSize, - DWORD *pdwOffs); +U14API(int) U14GetCircBlk(short hand, unsigned short wArea, unsigned int *pdwOffs); +U14API(int) U14FreeCircBlk(short hand, unsigned short wArea, unsigned int dwOffs, unsigned int dwSize, + unsigned int *pdwOffs); -U14API(short) U14StrToLongs(const char* pszBuff, U14LONG *palNums, short sMaxLongs); -U14API(short) U14LongsFrom1401(short hand, U14LONG *palBuff, short sMaxLongs); +U14API(short) U14StrToLongs(const char *pszBuff, U14LONG *palNums, short sMaxLongs); +U14API(short) U14LongsFrom1401(short hand, U14LONG *palBuff, short sMaxLongs); U14API(void) U14SetTimeout(short hand, int lTimeout); U14API(int) U14GetTimeout(short hand); -U14API(short) U14OutBufSpace(short hand); +U14API(short) U14OutBufSpace(short hand); U14API(int) U14BaseAddr1401(short hand); U14API(int) U14DriverVersion(short hand); U14API(int) U14DriverType(short hand); -U14API(short) U14DriverName(short hand, char* pBuf, WORD wMax); -U14API(short) U14GetUserMemorySize(short hand, DWORD *pMemorySize); -U14API(short) U14KillIO1401(short hand); +U14API(short) U14DriverName(short hand, char *pBuf, unsigned short wMax); +U14API(short) U14GetUserMemorySize(short hand, unsigned int *pMemorySize); +U14API(short) U14KillIO1401(short hand); -U14API(short) U14BlkTransState(short hand); -U14API(short) U14StateOf1401(short hand); +U14API(short) U14BlkTransState(short hand); +U14API(short) U14StateOf1401(short hand); -U14API(short) U14Grab1401(short hand); -U14API(short) U14Free1401(short hand); -U14API(short) U14Peek1401(short hand, DWORD dwAddr, int nSize, int nRepeats); -U14API(short) U14Poke1401(short hand, DWORD dwAddr, DWORD dwValue, int nSize, int nRepeats); -U14API(short) U14Ramp1401(short hand, DWORD dwAddr, DWORD dwDef, DWORD dwEnable, int nSize, int nRepeats); -U14API(short) U14RampAddr(short hand, DWORD dwDef, DWORD dwEnable, int nSize, int nRepeats); -U14API(short) U14StopDebugLoop(short hand); -U14API(short) U14GetDebugData(short hand, U14LONG *plValue); +U14API(short) U14Grab1401(short hand); +U14API(short) U14Free1401(short hand); +U14API(short) U14Peek1401(short hand, unsigned int dwAddr, int nSize, int nRepeats); +U14API(short) U14Poke1401(short hand, unsigned int dwAddr, unsigned int dwValue, int nSize, int nRepeats); +U14API(short) U14Ramp1401(short hand, unsigned int dwAddr, unsigned int dwDef, unsigned int dwEnable, int nSize, int nRepeats); +U14API(short) U14RampAddr(short hand, unsigned int dwDef, unsigned int dwEnable, int nSize, int nRepeats); +U14API(short) U14StopDebugLoop(short hand); +U14API(short) U14GetDebugData(short hand, U14LONG *plValue); -U14API(short) U14StartSelfTest(short hand); -U14API(short) U14CheckSelfTest(short hand, U14LONG *pData); -U14API(short) U14TransferFlags(short hand); -U14API(void) U14GetErrorString(short nErr, char* pStr, WORD wMax); +U14API(short) U14StartSelfTest(short hand); +U14API(short) U14CheckSelfTest(short hand, U14LONG *pData); +U14API(short) U14TransferFlags(short hand); +U14API(void) U14GetErrorString(short nErr, char *pStr, unsigned short wMax); U14API(int) U14MonitorRev(short hand); U14API(void) U14CloseAll(void); -U14API(short) U14WorkingSet(DWORD dwMinKb, DWORD dwMaxKb); +U14API(short) U14WorkingSet(unsigned int dwMinKb, unsigned int dwMaxKb); U14API(int) U14InitLib(void); #ifdef __cplusplus @@ -285,3 +285,4 @@ U14API(int) U14InitLib(void); #endif #endif /* End of ifndef __USE1401_H__ */ + diff --git a/drivers/staging/ced1401/use14_ioc.h b/drivers/staging/ced1401/use14_ioc.h index 15ca63888380..97d7913840dc 100644 --- a/drivers/staging/ced1401/use14_ioc.h +++ b/drivers/staging/ced1401/use14_ioc.h @@ -19,283 +19,282 @@ ** The IOCTL function codes from 0x80 to 0xFF are for developer use. */ #define FILE_DEVICE_CED1401 0x8001 -#define FNNUMBASE 0x800 + FNNUMBASE 0x800 -#define U14_OPEN1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_OPEN1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_CLOSE1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+1, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_CLOSE1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+1, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_SENDSTRING CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+2, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_SENDSTRING CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+2, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_RESET1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+3, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_RESET1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+3, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_GETCHAR CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+4, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_GETCHAR CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+4, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_SENDCHAR CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+5, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_SENDCHAR CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+5, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_STAT1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+6, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_STAT1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+6, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_LINECOUNT CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+7, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_LINECOUNT CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+7, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_GETSTRING CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+8, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_GETSTRING CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+8, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_REGCALLBACK CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+9, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_REGCALLBACK CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+9, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_GETMONITORBUF CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+10, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_GETMONITORBUF CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+10, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_SETTRANSFER CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+11, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_SETTRANSFER CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+11, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_UNSETTRANSFER CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+12, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_UNSETTRANSFER CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+12, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_SETTRANSEVENT CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+13, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_SETTRANSEVENT CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+13, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_GETOUTBUFSPACE CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+14, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_GETOUTBUFSPACE CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+14, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_GETBASEADDRESS CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+15, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_GETBASEADDRESS CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+15, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_GETDRIVERREVISION CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+16, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_GETDRIVERREVISION CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+16, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_GETTRANSFER CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+17, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_GETTRANSFER CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+17, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_KILLIO1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+18, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_KILLIO1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+18, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_BLKTRANSSTATE CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+19, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_BLKTRANSSTATE CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+19, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_BYTECOUNT CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+20, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_BYTECOUNT CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+20, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_ZEROBLOCKCOUNT CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+21, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_ZEROBLOCKCOUNT CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+21, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_STOPCIRCULAR CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+22, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_STOPCIRCULAR CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+22, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_STATEOF1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+23, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_STATEOF1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+23, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_REGISTERS1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+24, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_REGISTERS1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+24, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_GRAB1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+25, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_GRAB1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+25, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_FREE1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+26, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_FREE1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+26, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_STEP1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+27, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_STEP1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+27, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_SET1401REGISTERS CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+28, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_SET1401REGISTERS CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+28, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_STEPTILL1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+29, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_STEPTILL1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+29, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_SETORIN CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+30, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_SETORIN CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+30, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_STARTSELFTEST CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+31, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_STARTSELFTEST CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+31, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_CHECKSELFTEST CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+32, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_CHECKSELFTEST CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+32, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_TYPEOF1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+33, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_TYPEOF1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+33, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_TRANSFERFLAGS CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+34, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_TRANSFERFLAGS CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+34, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_DBGPEEK CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+35, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_DBGPEEK CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+35, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_DBGPOKE CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+36, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_DBGPOKE CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+36, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_DBGRAMPDATA CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+37, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_DBGRAMPDATA CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+37, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_DBGRAMPADDR CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+38, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_DBGRAMPADDR CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+38, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_DBGGETDATA CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+39, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_DBGGETDATA CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+39, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_DBGSTOPLOOP CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+40, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_DBGSTOPLOOP CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+40, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_FULLRESET CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+41, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_FULLRESET CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+41, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_SETCIRCULAR CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+42, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_SETCIRCULAR CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+42, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_GETCIRCBLK CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+43, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_GETCIRCBLK CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+43, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define U14_FREECIRCBLK CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+44, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define U14_FREECIRCBLK CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+44, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -//--------------- Structures that are shared with the driver ------------- +/*--------------- Structures that are shared with the driver ------------- */ #pragma pack(1) typedef struct /* used for get/set standard 1401 registers */ { - short sPC; - char A; - char X; - char Y; - char stat; - char rubbish; + short sPC; + char A; + char X; + char Y; + char stat; + char rubbish; } T1401REGISTERS; typedef union /* to communicate with 1401 driver status & control funcs */ { - char chrs[22]; - short ints[11]; - long longs[5]; - T1401REGISTERS registers; + char chrs[22]; + short ints[11]; + long longs[5]; + T1401REGISTERS registers; } TCSBLOCK; typedef TCSBLOCK* LPTCSBLOCK; -typedef struct paramBlk -{ - short sState; - TCSBLOCK csBlock; +typedef struct paramBlk { + short sState; + TCSBLOCK csBlock; } PARAMBLK; typedef PARAMBLK* PPARAMBLK; typedef struct TransferDesc /* Structure and type for SetTransArea */ { - WORD wArea; /* number of transfer area to set up */ - void FAR * lpvBuff; /* address of transfer area */ - DWORD dwLength; /* length of area to set up */ - short eSize; /* size to move (for swapping on MAC) */ + unsigned short wArea; /* number of transfer area to set up */ + void FAR *lpvBuff; /* address of transfer area */ + unsigned int dwLength; /* length of area to set up */ + short eSize; /* size to move (for swapping on MAC) */ } TRANSFERDESC; -typedef TRANSFERDESC FAR * LPTRANSFERDESC; +typedef TRANSFERDESC FAR *LPTRANSFERDESC; /* This is the structure used to set up a transfer area */ typedef struct VXTransferDesc /* use1401.c and use1432x.x use only */ { - WORD wArea; /* number of transfer area to set up */ - WORD wAddrSel; /* 16 bit selector for area */ - DWORD dwAddrOfs; /* 32 bit offset for area start */ - DWORD dwLength; /* length of area to set up */ + unsigned short wArea; /* number of transfer area to set up */ + unsigned short wAddrSel; /* 16 bit selector for area */ + unsigned int dwAddrOfs; /* 32 bit offset for area start */ + unsigned int dwLength; /* length of area to set up */ } VXTRANSFERDESC; #pragma pack() -#endif \ No newline at end of file +#endif diff --git a/drivers/staging/ced1401/userspace/use1401.c b/drivers/staging/ced1401/userspace/use1401.c index 38e7c1c82d43..c9bc2ebfef1a 100644 --- a/drivers/staging/ced1401/userspace/use1401.c +++ b/drivers/staging/ced1401/userspace/use1401.c @@ -36,7 +36,7 @@ ** Under Windows 9x and NT, Use1401 uses DeviceIoControl to get access to ** the 1401 driver. This has parameters for the device handle, the function ** code, an input pointer and byte count, an output pointer and byte count -** and a pointer to a DWORD to hold the output byte count. Note that input +** and a pointer to a unsigned int to hold the output byte count. Note that input ** and output are from the point-of-view of the driver, so the output stuff ** is used to read values from the 1401, not send to the 1401. The use of ** these parameters varies with the function in use and the operating @@ -250,7 +250,7 @@ static int iAttached = 0; // counts process attaches so ca static HANDLE aHand1401[MAX1401] = {0}; // handles for 1401s static HANDLE aXferEvent[MAX1401] = {0}; // transfer events for the 1401s static LPVOID apAreas[MAX1401][MAX_TRANSAREAS]; // Locked areas -static DWORD auAreas[MAX1401][MAX_TRANSAREAS]; // Size of locked areas +static unsigned int auAreas[MAX1401][MAX_TRANSAREAS]; // Size of locked areas static BOOL bWindows9x = FALSE; // if we are Windows 95 or better #ifdef _WIN64 #define USE_NT_DIOC(ind) TRUE @@ -276,8 +276,8 @@ static int aHand1401[MAX1401] = {0}; // handles for 1401s typedef struct CmdHead // defines header block on command { // for PC commands char acBasic[5]; // BASIC information - needed to align things - WORD wBasicSz; // size as seen by BASIC - WORD wCmdSize; // size of the following info + unsigned short wBasicSz; // size as seen by BASIC + unsigned short wCmdSize; // size of the following info } __packed CMDHEAD; #pragma pack() // back to normal @@ -311,7 +311,7 @@ static short CheckHandle(short h) ****************************************************************************/ static short U14Status1401(short sHand, LONG lCode, TCSBLOCK* pBlk) { - DWORD dwBytes = 0; + unsigned int dwBytes = 0; if ((sHand < 0) || (sHand >= MAX1401)) /* Check parameters */ return U14ERR_BADHAND; @@ -345,7 +345,7 @@ static short U14Status1401(short sHand, LONG lCode, TCSBLOCK* pBlk) ****************************************************************************/ static short U14Control1401(short sHand, LONG lCode, TCSBLOCK* pBlk) { - DWORD dwBytes = 0; + unsigned int dwBytes = 0; if ((sHand < 0) || (sHand >= MAX1401)) /* Check parameters */ return U14ERR_BADHAND; @@ -455,7 +455,7 @@ static void TranslateString(char* pStr) ****************************************************************************/ U14API(short) U14StrToLongs(const char* pszBuff, U14LONG *palNums, short sMaxLongs) { - WORD wChInd = 0; // index into source + unsigned short wChInd = 0; // index into source short sLgInd = 0; // index into result longs while (pszBuff[wChInd] && // until we get to end of string... @@ -681,7 +681,7 @@ U14API(int) U14DriverType(short hand) ** U14DriverName ** Returns the driver type as 3 character (ISA, PCI, USB or HSS)) ****************************************************************************/ -U14API(short) U14DriverName(short hand, char* pBuf, WORD wMax) +U14API(short) U14DriverName(short hand, char* pBuf, unsigned short wMax) { char* pName; *pBuf = 0; // Start off with a blank string @@ -779,7 +779,7 @@ U14API(short) U14Free1401(short hand) ** is called. After the peek is done, use U14GetDebugData to retrieve ** the results of the peek. ****************************************************************************/ -U14API(short) U14Peek1401(short hand, DWORD dwAddr, int nSize, int nRepeats) +U14API(short) U14Peek1401(short hand, unsigned int dwAddr, int nSize, int nRepeats) { short sErr = CheckHandle(hand); if (sErr == U14ERR_NOERROR) @@ -813,7 +813,7 @@ U14API(short) U14Peek1401(short hand, DWORD dwAddr, int nSize, int nRepeats) ** If lRepeats is zero, the loop will continue until U14StopDebugLoop ** is called. ****************************************************************************/ -U14API(short) U14Poke1401(short hand, DWORD dwAddr, DWORD dwValue, +U14API(short) U14Poke1401(short hand, unsigned int dwAddr, unsigned int dwValue, int nSize, int nRepeats) { short sErr = CheckHandle(hand); @@ -849,7 +849,7 @@ U14API(short) U14Poke1401(short hand, DWORD dwAddr, DWORD dwValue, ** DESCRIPTION Cause the 1401 to loop, writing a ramp to a location. ** If lRepeats is zero, the loop will continue until U14StopDebugLoop. ****************************************************************************/ -U14API(short) U14Ramp1401(short hand, DWORD dwAddr, DWORD dwDef, DWORD dwEnable, +U14API(short) U14Ramp1401(short hand, unsigned int dwAddr, unsigned int dwDef, unsigned int dwEnable, int nSize, int nRepeats) { short sErr = CheckHandle(hand); @@ -887,7 +887,7 @@ U14API(short) U14Ramp1401(short hand, DWORD dwAddr, DWORD dwDef, DWORD dwEnable, ** DESCRIPTION Cause the 1401 to loop, reading from a ramping location. ** If lRepeats is zero, the loop will continue until U14StopDebugLoop ****************************************************************************/ -U14API(short) U14RampAddr(short hand, DWORD dwDef, DWORD dwEnable, +U14API(short) U14RampAddr(short hand, unsigned int dwDef, unsigned int dwEnable, int nSize, int nRepeats) { short sErr = CheckHandle(hand); @@ -1024,7 +1024,7 @@ U14API(short) U14CheckSelfTest(short hand, U14LONG *pData) /**************************************************************************** ** U14GetUserMemorySize ****************************************************************************/ -U14API(short) U14GetUserMemorySize(short hand, DWORD *pMemorySize) +U14API(short) U14GetUserMemorySize(short hand, unsigned int *pMemorySize) { // The original 1401 used a different command for getting the size short sErr = U14SendString(hand, (asType1401[hand] == U14TYPE1401) ? "MEMTOP;" : "MEMTOP,?;"); @@ -1061,7 +1061,7 @@ U14API(short) U14TypeOf1401(short hand) ** U14NameOf1401 ** Returns the type of the 1401 as a string, blank if unknown ****************************************************************************/ -U14API(short) U14NameOf1401(short hand, char* pBuf, WORD wMax) +U14API(short) U14NameOf1401(short hand, char* pBuf, unsigned short wMax) { short sErr = CheckHandle(hand); if (sErr == U14ERR_NOERROR) @@ -1207,7 +1207,7 @@ static short U14TryToOpen(int n1401, long* plRetVal, short* psHandle) { short sErr = U14ERR_NOERROR; HANDLE hDevice = INVALID_HANDLE_VALUE; - DWORD dwErr = 0; + unsigned int dwErr = 0; int nFirst, nLast, nDev = 0; /* Used for the search for a 1401 */ BOOL bOldName = FALSE; /* start by looking for a modern driver */ @@ -1262,7 +1262,7 @@ static short U14TryToOpen(int n1401, long* plRetVal, short* psHandle) } else { - DWORD dwe = GetLastError(); /* Get error code otherwise */ + unsigned int dwe = GetLastError(); /* Get error code otherwise */ if ((dwe != ERROR_FILE_NOT_FOUND) || (dwErr == 0)) dwErr = dwe; /* Ignore repeats of 'not found' */ } @@ -1454,7 +1454,7 @@ U14API(short) U14Close1401(short hand) U14Reset1401(hand); // in case an active transfer running for (j = 0; j < MAX_TRANSAREAS; ++j) // Locate locked areas if (iAreaMask & (1 << j)) // And kill off any transfers - U14UnSetTransfer(hand, (WORD)j); + U14UnSetTransfer(hand, (unsigned short)j); } #ifdef _IS_WINDOWS_ @@ -1581,7 +1581,7 @@ U14API(short) U14SendString(short hand, const char* pString) if (bSpaceToSend) { PARAMBLK rData; - DWORD dwBytes; + unsigned int dwBytes; char tstr[MAXSTRLEN+5]; /* Buffer for chars */ if ((hand < 0) || (hand >= MAX1401)) @@ -1592,18 +1592,18 @@ U14API(short) U14SendString(short hand, const char* pString) #ifndef _WIN64 if (!USE_NT_DIOC(hand)) /* Using WIN 95 driver access? */ { - int iOK = DeviceIoControl(aHand1401[hand], (DWORD)U14_SENDSTRING, + int iOK = DeviceIoControl(aHand1401[hand], (unsigned int)U14_SENDSTRING, NULL, 0, tstr, nChars, &dwBytes, NULL); if (iOK) - sErr = (dwBytes >= (DWORD)nChars) ? U14ERR_NOERROR : U14ERR_DRIVCOMMS; + sErr = (dwBytes >= (unsigned int)nChars) ? U14ERR_NOERROR : U14ERR_DRIVCOMMS; else sErr = (short)GetLastError(); } else #endif { - int iOK = DeviceIoControl(aHand1401[hand],(DWORD)U14_SENDSTRING, + int iOK = DeviceIoControl(aHand1401[hand],(unsigned int)U14_SENDSTRING, tstr, nChars, &rData,sizeof(PARAMBLK),&dwBytes,NULL); if (iOK && (dwBytes >= sizeof(PARAMBLK))) @@ -1697,7 +1697,7 @@ U14API(short) U14SendChar(short hand, char cChar) ** error code. Any error from the device causes us to set up for ** a full reset. ****************************************************************************/ -U14API(short) U14GetString(short hand, char* pBuffer, WORD wMaxLen) +U14API(short) U14GetString(short hand, char* pBuffer, unsigned short wMaxLen) { short sErr = CheckHandle(hand); if (sErr != U14ERR_NOERROR) // If an error... @@ -1726,8 +1726,8 @@ U14API(short) U14GetString(short hand, char* pBuffer, WORD wMaxLen) { if (asLastRetCode[hand] == U14ERR_NOERROR) /* all ok so far */ { - DWORD dwBytes = 0; - *((WORD *)pBuffer) = wMaxLen; /* set up length */ + unsigned int dwBytes = 0; + *((unsigned short *)pBuffer) = wMaxLen; /* set up length */ #ifndef _WIN64 if (!USE_NT_DIOC(hand)) /* Win 95 DIOC here ? */ { @@ -1737,9 +1737,9 @@ U14API(short) U14GetString(short hand, char* pBuffer, WORD wMaxLen) if (wMaxLen > MAXSTRLEN) /* Truncate length */ wMaxLen = MAXSTRLEN; - *((WORD *)tstr) = wMaxLen; /* set len */ + *((unsigned short *)tstr) = wMaxLen; /* set len */ - iOK = DeviceIoControl(aHand1401[hand],(DWORD)U14_GETSTRING, + iOK = DeviceIoControl(aHand1401[hand],(unsigned int)U14_GETSTRING, NULL, 0, tstr, wMaxLen+sizeof(short), &dwBytes, NULL); if (iOK) /* Device IO control OK ? */ @@ -1768,7 +1768,7 @@ U14API(short) U14GetString(short hand, char* pBuffer, WORD wMaxLen) char* pMem = (char*)GlobalLock(hMem); if (pMem) { - int iOK = DeviceIoControl(aHand1401[hand],(DWORD)U14_GETSTRING, + int iOK = DeviceIoControl(aHand1401[hand],(unsigned int)U14_GETSTRING, NULL, 0, pMem, wMaxLen+sizeof(short), &dwBytes, NULL); if (iOK) /* Device IO control OK ? */ @@ -1946,7 +1946,7 @@ U14API(short) U14LineCount(short hand) ** other functions after getting an error and before using ** this function. ****************************************************************************/ -U14API(void) U14GetErrorString(short nErr, char* pStr, WORD wMax) +U14API(void) U14GetErrorString(short nErr, char* pStr, unsigned short wMax) { char wstr[150]; @@ -2105,7 +2105,7 @@ U14API(void) U14GetErrorString(short nErr, char* pStr, WORD wMax) break; } - if ((WORD)strlen(wstr) >= wMax-1) /* Check for string being too long */ + if ((unsigned short)strlen(wstr) >= wMax-1) /* Check for string being too long */ wstr[wMax-1] = 0; /* and truncate it if so */ strcpy(pStr, wstr); /* Return the error string */ } @@ -2120,8 +2120,8 @@ U14API(short) U14GetTransfer(short hand, TGET_TX_BLOCK *pTransBlock) #ifdef _IS_WINDOWS_ if (sErr == U14ERR_NOERROR) { - DWORD dwBytes = 0; - BOOL bOK = DeviceIoControl(aHand1401[hand], (DWORD)U14_GETTRANSFER, NULL, 0, pTransBlock, + unsigned int dwBytes = 0; + BOOL bOK = DeviceIoControl(aHand1401[hand], (unsigned int)U14_GETTRANSFER, NULL, 0, pTransBlock, sizeof(TGET_TX_BLOCK), &dwBytes, NULL); if (bOK && (dwBytes >= sizeof(TGET_TX_BLOCK))) @@ -2145,12 +2145,12 @@ U14API(short) U14GetTransfer(short hand, TGET_TX_BLOCK *pTransBlock) // 1 unable to access process (insufficient rights?) // 2 unable to read process working set // 3 unable to set process working set - bad parameters? -U14API(short) U14WorkingSet(DWORD dwMinKb, DWORD dwMaxKb) +U14API(short) U14WorkingSet(unsigned int dwMinKb, unsigned int dwMaxKb) { #ifdef _IS_WINDOWS_ short sRetVal = 0; // 0 means all is OK HANDLE hProcess; - DWORD dwVer = GetVersion(); + unsigned int dwVer = GetVersion(); if (dwVer & 0x80000000) // is this not NT? return 0; // then give up right now @@ -2164,8 +2164,8 @@ U14API(short) U14WorkingSet(DWORD dwMinKb, DWORD dwMaxKb) SIZE_T dwMinSize,dwMaxSize; if (GetProcessWorkingSetSize(hProcess, &dwMinSize, &dwMaxSize)) { - DWORD dwMin = dwMinKb << 10; // convert from kb to bytes - DWORD dwMax = dwMaxKb << 10; + unsigned int dwMin = dwMinKb << 10; // convert from kb to bytes + unsigned int dwMax = dwMaxKb << 10; // if we get here, we have managed to read the current size if (dwMin > dwMinSize) // need to change sizes? @@ -2200,7 +2200,7 @@ U14API(short) U14WorkingSet(DWORD dwMinKb, DWORD dwMaxKb) ** U14UnSetTransfer Cancels a transfer area ** wArea The index of a block previously used in by SetTransfer *****************************************************************************/ -U14API(short) U14UnSetTransfer(short hand, WORD wArea) +U14API(short) U14UnSetTransfer(short hand, unsigned short wArea) { short sErr = CheckHandle(hand); #ifdef _IS_WINDOWS_ @@ -2223,13 +2223,13 @@ U14API(short) U14UnSetTransfer(short hand, WORD wArea) /**************************************************************************** ** U14SetTransArea Sets an area up to be used for transfers -** WORD wArea The area number to set up +** unsigned short wArea The area number to set up ** void *pvBuff The address of the buffer for the data. -** DWORD dwLength The length of the buffer for the data +** unsigned int dwLength The length of the buffer for the data ** short eSz The element size (used for byte swapping on the Mac) ****************************************************************************/ -U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, - DWORD dwLength, short eSz) +U14API(short) U14SetTransArea(short hand, unsigned short wArea, void *pvBuff, + unsigned int dwLength, short eSz) { TRANSFERDESC td; short sErr = CheckHandle(hand); @@ -2254,7 +2254,7 @@ U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, #ifndef _WIN64 if (!USE_NT_DIOC(hand)) /* Use Win 9x DIOC? */ { - DWORD dwBytes; + unsigned int dwBytes; VXTRANSFERDESC vxDesc; /* Structure to pass to VXD */ vxDesc.wArea = wArea; /* Copy across simple params */ vxDesc.dwLength = dwLength; @@ -2264,10 +2264,10 @@ U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, sErr = U14ERR_DRIVTOOOLD; else { - vxDesc.dwAddrOfs = (DWORD)pvBuff; /* 32 bit offset */ + vxDesc.dwAddrOfs = (unsigned int)pvBuff; /* 32 bit offset */ vxDesc.wAddrSel = 0; - if (DeviceIoControl(aHand1401[hand], (DWORD)U14_SETTRANSFER, + if (DeviceIoControl(aHand1401[hand], (unsigned int)U14_SETTRANSFER, pvBuff,dwLength, /* Will translate pointer */ &vxDesc,sizeof(VXTRANSFERDESC), &dwBytes,NULL)) @@ -2285,13 +2285,13 @@ U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, #endif { PARAMBLK rWork; - DWORD dwBytes; + unsigned int dwBytes; td.wArea = wArea; /* Pure NT - put data into struct */ td.lpvBuff = pvBuff; td.dwLength = dwLength; td.eSize = 0; // Dummy element size - if (DeviceIoControl(aHand1401[hand],(DWORD)U14_SETTRANSFER, + if (DeviceIoControl(aHand1401[hand],(unsigned int)U14_SETTRANSFER, &td,sizeof(TRANSFERDESC), &rWork,sizeof(PARAMBLK),&dwBytes,NULL)) { @@ -2344,8 +2344,8 @@ U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, ** Returns 1 if an event handle exists, 0 if all OK and no event handle or ** a negative code for an error. ****************************************************************************/ -U14API(short) U14SetTransferEvent(short hand, WORD wArea, BOOL bEvent, - BOOL bToHost, DWORD dwStart, DWORD dwLength) +U14API(short) U14SetTransferEvent(short hand, unsigned short wArea, BOOL bEvent, + BOOL bToHost, unsigned int dwStart, unsigned int dwLength) { #ifdef _IS_WINDOWS_ TCSBLOCK csBlock; @@ -2416,7 +2416,7 @@ U14API(short) U14SetTransferEvent(short hand, WORD wArea, BOOL bEvent, ** Would a U14WaitTransferEvent() call return immediately? return 1 if so, ** 0 if not or a negative code if a problem. ****************************************************************************/ -U14API(int) U14TestTransferEvent(short hand, WORD wArea) +U14API(int) U14TestTransferEvent(short hand, unsigned short wArea) { #ifdef _IS_WINDOWS_ int iErr = CheckHandle(hand); @@ -2441,7 +2441,7 @@ U14API(int) U14TestTransferEvent(short hand, WORD wArea) ** Returns If no event handle then return immediately. Else return 1 if ** timed out or 0=event, and a negative code if a problem. ****************************************************************************/ -U14API(int) U14WaitTransferEvent(short hand, WORD wArea, int msTimeOut) +U14API(int) U14WaitTransferEvent(short hand, unsigned short wArea, int msTimeOut) { #ifdef _IS_WINDOWS_ int iErr = CheckHandle(hand); @@ -2466,13 +2466,13 @@ U14API(int) U14WaitTransferEvent(short hand, WORD wArea, int msTimeOut) /**************************************************************************** ** U14SetCircular Sets an area up for circular DMA transfers -** WORD wArea The area number to set up +** unsigned short wArea The area number to set up ** BOOL bToHost Sets the direction of data transfer ** void *pvBuff The address of the buffer for the data -** DWORD dwLength The length of the buffer for the data +** unsigned int dwLength The length of the buffer for the data ****************************************************************************/ -U14API(short) U14SetCircular(short hand, WORD wArea, BOOL bToHost, - void *pvBuff, DWORD dwLength) +U14API(short) U14SetCircular(short hand, unsigned short wArea, BOOL bToHost, + void *pvBuff, unsigned int dwLength) { short sErr = CheckHandle(hand); if (sErr != U14ERR_NOERROR) @@ -2495,14 +2495,14 @@ U14API(short) U14SetCircular(short hand, WORD wArea, BOOL bToHost, else { PARAMBLK rWork; - DWORD dwBytes; + unsigned int dwBytes; TRANSFERDESC txDesc; txDesc.wArea = wArea; /* Pure NT - put data into struct */ txDesc.lpvBuff = pvBuff; txDesc.dwLength = dwLength; txDesc.eSize = (short)bToHost; /* Use this for direction flag */ - if (DeviceIoControl(aHand1401[hand],(DWORD)U14_SETCIRCULAR, + if (DeviceIoControl(aHand1401[hand],(unsigned int)U14_SETCIRCULAR, &txDesc, sizeof(TRANSFERDESC), &rWork, sizeof(PARAMBLK),&dwBytes,NULL)) { @@ -2542,7 +2542,7 @@ U14API(short) U14SetCircular(short hand, WORD wArea, BOOL bToHost, ** Function GetCircBlk returns the size (& start offset) of the next ** available block of circular data. ****************************************************************************/ -U14API(int) U14GetCircBlk(short hand, WORD wArea, DWORD *pdwOffs) +U14API(int) U14GetCircBlk(short hand, unsigned short wArea, unsigned int *pdwOffs) { int lErr = CheckHandle(hand); if (lErr != U14ERR_NOERROR) @@ -2555,10 +2555,10 @@ U14API(int) U14GetCircBlk(short hand, WORD wArea, DWORD *pdwOffs) #ifdef _IS_WINDOWS_ PARAMBLK rWork; TCSBLOCK csBlock; - DWORD dwBytes; + unsigned int dwBytes; csBlock.longs[0] = wArea; // Area number into control block rWork.sState = U14ERR_DRIVCOMMS; - if (DeviceIoControl(aHand1401[hand], (DWORD)U14_GETCIRCBLK, &csBlock, sizeof(TCSBLOCK), &rWork, sizeof(PARAMBLK), &dwBytes, NULL) && + if (DeviceIoControl(aHand1401[hand], (unsigned int)U14_GETCIRCBLK, &csBlock, sizeof(TCSBLOCK), &rWork, sizeof(PARAMBLK), &dwBytes, NULL) && (dwBytes >= sizeof(PARAMBLK))) lErr = rWork.sState; else @@ -2591,8 +2591,8 @@ U14API(int) U14GetCircBlk(short hand, WORD wArea, DWORD *pdwOffs) ** resuse for circular transfers and returns the size (& start ** offset) of the next available block of circular data. ****************************************************************************/ -U14API(int) U14FreeCircBlk(short hand, WORD wArea, DWORD dwOffs, DWORD dwSize, - DWORD *pdwOffs) +U14API(int) U14FreeCircBlk(short hand, unsigned short wArea, unsigned int dwOffs, unsigned int dwSize, + unsigned int *pdwOffs) { int lErr = CheckHandle(hand); if (lErr != U14ERR_NOERROR) @@ -2603,12 +2603,12 @@ U14API(int) U14FreeCircBlk(short hand, WORD wArea, DWORD dwOffs, DWORD dwSize, #ifdef _IS_WINDOWS_ PARAMBLK rWork; TCSBLOCK csBlock; - DWORD dwBytes; + unsigned int dwBytes; csBlock.longs[0] = wArea; // Area number into control block csBlock.longs[1] = dwOffs; csBlock.longs[2] = dwSize; rWork.sState = U14ERR_DRIVCOMMS; - if (DeviceIoControl(aHand1401[hand], (DWORD)U14_FREECIRCBLK, &csBlock, sizeof(TCSBLOCK), + if (DeviceIoControl(aHand1401[hand], (unsigned int)U14_FREECIRCBLK, &csBlock, sizeof(TCSBLOCK), &rWork, sizeof(PARAMBLK), &dwBytes, NULL) && (dwBytes >= sizeof(PARAMBLK))) lErr = rWork.sState; @@ -2647,7 +2647,7 @@ U14API(int) U14FreeCircBlk(short hand, WORD wArea, DWORD dwOffs, DWORD dwSize, ** which it should be to get a pointer *****************************************************************************/ static short Transfer(short hand, BOOL bTo1401, char* pData, - DWORD dwSize, DWORD dw1401, short eSz) + unsigned int dwSize, unsigned int dw1401, short eSz) { char strcopy[MAXSTRLEN+1]; // to hold copy of work string short sResult = U14SetTransArea(hand, 0, (void *)pData, dwSize, eSz); @@ -2670,8 +2670,8 @@ static short Transfer(short hand, BOOL bTo1401, char* pData, /**************************************************************************** ** Function ToHost transfers data into the host from the 1401 ****************************************************************************/ -U14API(short) U14ToHost(short hand, char* pAddrHost, DWORD dwSize, - DWORD dw1401, short eSz) +U14API(short) U14ToHost(short hand, char* pAddrHost, unsigned int dwSize, + unsigned int dw1401, short eSz) { short sErr = CheckHandle(hand); if ((sErr == U14ERR_NOERROR) && dwSize) // TOHOST is a constant @@ -2682,8 +2682,8 @@ U14API(short) U14ToHost(short hand, char* pAddrHost, DWORD dwSize, /**************************************************************************** ** Function To1401 transfers data into the 1401 from the host ****************************************************************************/ -U14API(short) U14To1401(short hand, const char* pAddrHost,DWORD dwSize, - DWORD dw1401, short eSz) +U14API(short) U14To1401(short hand, const char* pAddrHost,unsigned int dwSize, + unsigned int dw1401, short eSz) { short sErr = CheckHandle(hand); if ((sErr == U14ERR_NOERROR) && dwSize) // TO1401 is a constant @@ -2707,7 +2707,7 @@ U14API(short) U14To1401(short hand, const char* pAddrHost,DWORD dwSize, #define file_close(h) close(h) #define file_seek(h, pos) lseek(h, pos, SEEK_SET) #define file_read(h, buffer, size) (read(h, buffer, size) == (ssize_t)size) -static DWORD GetModuleFileName(void* dummy, char* buffer, int max) +static unsigned int GetModuleFileName(void* dummy, char* buffer, int max) { // The following works for Linux systems with a /proc file system. char szProcPath[32]; @@ -2766,7 +2766,7 @@ U14API(short) U14LdCmd(short hand, const char* command) // application was run from. if (!bGotIt) // Still not got it? { - DWORD dwLen = GetModuleFileName(NULL, filnam, FNSZ); // Get app path + unsigned int dwLen = GetModuleFileName(NULL, filnam, FNSZ); // Get app path if (dwLen > 0) // and use it as path if found { char* pStr = strrchr(filnam, PATHSEP); // Point to last separator @@ -2821,7 +2821,7 @@ U14API(short) U14LdCmd(short hand, const char* command) file_seek(iFHandle, sizeof(CMDHEAD)); if (file_read(iFHandle, pMem, (UINT)nComSize)) { - sErr = U14SetTransArea(hand, 0, (void *)pMem, (DWORD)nComSize, ESZBYTES); + sErr = U14SetTransArea(hand, 0, (void *)pMem, (unsigned int)nComSize, ESZBYTES); if (sErr == U14ERR_NOERROR) { sprintf(strcopy, "CLOAD,0,$%X;", (int)nComSize); @@ -2858,9 +2858,9 @@ U14API(short) U14LdCmd(short hand, const char* command) ** Returns NOERROR code or a long with error in lo word and index of ** command that failed in high word ****************************************************************************/ -U14API(DWORD) U14Ld(short hand, const char* vl, const char* str) +U14API(unsigned int) U14Ld(short hand, const char* vl, const char* str) { - DWORD dwIndex = 0; // index to current command + unsigned int dwIndex = 0; // index to current command long lErr = U14ERR_NOERROR; // what the error was that went wrong char strcopy[MAXSTRLEN+1]; // stores unmodified str parameter char szFExt[8]; // The command file extension @@ -2939,7 +2939,7 @@ U14API(DWORD) U14Ld(short hand, const char* vl, const char* str) return lErr; } else - return ((dwIndex<<16) | ((DWORD)lErr & 0x0000FFFF)); + return ((dwIndex<<16) | ((unsigned int)lErr & 0x0000FFFF)); } // Initialise the library (if not initialised) and return the library version @@ -2951,7 +2951,7 @@ U14API(int) U14InitLib(void) int i; #ifdef _IS_WINDOWS_ int j; - DWORD dwVersion = GetVersion(); + unsigned int dwVersion = GetVersion(); bWindows9x = FALSE; // Assume not Win9x if (dwVersion & 0x80000000) // if not windows NT @@ -2993,12 +2993,12 @@ U14API(int) U14InitLib(void) #ifdef _IS_WINDOWS_ #ifndef U14_NOT_DLL /**************************************************************************** -** FUNCTION: DllMain(HANDLE, DWORD, LPVOID) +** FUNCTION: DllMain(HANDLE, unsigned int, LPVOID) ** LibMain is called by Windows when the DLL is initialized, Thread Attached, ** and other times. Refer to SDK documentation, as to the different ways this ** may be called. ****************************************************************************/ -INT APIENTRY DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved) +INT APIENTRY DllMain(HANDLE hInst, unsigned int ul_reason_being_called, LPVOID lpReserved) { int iRetVal = 1; diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 87e852a0ef49..8c8a55132257 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -110,15 +110,6 @@ menuconfig COMEDI_ISA_DRIVERS if COMEDI_ISA_DRIVERS -config COMEDI_ACL7225B - tristate "ADlink NuDAQ ACL-7225b and compatibles support" - ---help--- - Enable support for ADlink NuDAQ ACL-7225b and compatibles, - ADlink ACL-7225b (acl7225b), ICP P16R16DIO (p16r16dio) - - To compile this driver as a module, choose M here: the module will be - called acl7225b. - config COMEDI_PCL711 tristate "Advantech PCL-711/711b and ADlink ACL-8112 ISA card support" ---help--- @@ -137,14 +128,6 @@ config COMEDI_PCL724 To compile this driver as a module, choose M here: the module will be called pcl724. -config COMEDI_PCL725 - tristate "Advantech PCL-725 and compatible ISA card support" - ---help--- - Enable support for Advantech PCL-725 and compatible ISA cards. - - To compile this driver as a module, choose M here: the module will be - called pcl725. - config COMEDI_PCL726 tristate "Advantech PCL-726 and compatible ISA card support" ---help--- @@ -154,10 +137,21 @@ config COMEDI_PCL726 called pcl726. config COMEDI_PCL730 - tristate "Advantech PCL-730 and ADlink ACL-7130 ISA card support" + tristate "Simple Digital I/O board support (8-bit ports)" ---help--- - Enable support for Advantech PCL-730, ICP ISO-730 and ADlink - ACL-7130 ISA cards + Enable support for various simple ISA or PC/104 Digital I/O boards. + These boards all use 8-bit I/O ports. + + Advantech PCL-730 isolated - 16 in/16 out ttl - 16 in/16 out + ICP ISO-730 isolated - 16 in/16 out ttl - 16 in/16 out + ADlink ACL-7130 isolated - 16 in/16 out ttl - 16 in/16 out + Advantech PCM-3730 isolated - 8 in/8 out ttl - 16 in/16 out + Advantech PCL-725 isolated - 8 in/8 out + ICP P8R8-DIO isolated - 8 in/8 out + ADlink ACL-7225b isolated - 16 in/16 out + ICP P16R16-DIO isolated - 16 in/16 out + Advantech PCL-733 isolated - 32 in + Advantech PCL-734 isolated - 32 out To compile this driver as a module, choose M here: the module will be called pcl730. @@ -201,14 +195,6 @@ config COMEDI_PCM3724 To compile this driver as a module, choose M here: the module will be called pcm3724. -config COMEDI_PCM3730 - tristate "Advantech PCM-3730 and clone PC/104 board support" - ---help--- - Enable support for Advantech PCM-3730 and clone PC/104 boards - - To compile this driver as a module, choose M here: the module will be - called pcm3730. - config COMEDI_AMPLC_DIO200_ISA tristate "Amplicon PC212E/PC214E/PC215E/PC218E/PC272E" select COMEDI_AMPLC_DIO200 @@ -543,12 +529,19 @@ config COMEDI_POC tristate "Generic driver for very simple devices" ---help--- Enable generic support for very simple / POC (Piece of Crap) boards, - Keithley Metrabyte DAC-02 (dac02), Advantech PCL-733 (pcl733) and - PCL-734 (pcl734) + Keithley Metrabyte DAC-02 (dac02). To compile this driver as a module, choose M here: the module will be called poc. +config COMEDI_S526 + tristate "Sensoray s526 support" + ---help--- + Enable support for Sensoray s526 + + To compile this driver as a module, choose M here: the module will be + called s526. + endif # COMEDI_ISA_DRIVERS menuconfig COMEDI_PCI_DRIVERS @@ -1076,14 +1069,6 @@ config COMEDI_RTD520 To compile this driver as a module, choose M here: the module will be called rtd520. -config COMEDI_S526 - tristate "Sensoray s526 support" - ---help--- - Enable support for Sensoray s526 - - To compile this driver as a module, choose M here: the module will be - called s526. - config COMEDI_S626 tristate "Sensoray 626 support" select COMEDI_FC diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h index 4233605df30a..6bbbe5b08954 100644 --- a/drivers/staging/comedi/comedi.h +++ b/drivers/staging/comedi/comedi.h @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _COMEDI_H diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index d4be0e68509b..b4c001b6f88f 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -13,10 +13,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "comedidev.h" diff --git a/drivers/staging/comedi/comedi_compat32.c b/drivers/staging/comedi/comedi_compat32.c index ad208cdd53d4..2dfb06aedb15 100644 --- a/drivers/staging/comedi/comedi_compat32.c +++ b/drivers/staging/comedi/comedi_compat32.c @@ -17,11 +17,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #include diff --git a/drivers/staging/comedi/comedi_compat32.h b/drivers/staging/comedi/comedi_compat32.h index 60cf51c4a793..28e3c3059037 100644 --- a/drivers/staging/comedi/comedi_compat32.h +++ b/drivers/staging/comedi/comedi_compat32.h @@ -17,11 +17,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _COMEDI_COMPAT32_H diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 924c54c9c31f..0794aacc928a 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #undef DEBUG @@ -536,6 +531,23 @@ static bool comedi_is_subdevice_idle(struct comedi_subdevice *s) return (runflags & (SRF_ERROR | SRF_RUNNING)) ? false : true; } +/** + * comedi_alloc_spriv() - Allocate memory for the subdevice private data. + * @s: comedi_subdevice struct + * @size: size of the memory to allocate + * + * This also sets the subdevice runflags to allow the core to automatically + * free the private data during the detach. + */ +void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size) +{ + s->private = kzalloc(size, GFP_KERNEL); + if (s->private) + comedi_set_subdevice_runflags(s, ~0, SRF_FREE_SPRIV); + return s->private; +} +EXPORT_SYMBOL_GPL(comedi_alloc_spriv); + /* This function restores a subdevice to an idle state. */ @@ -665,7 +677,7 @@ static int do_bufconfig_ioctl(struct comedi_device *dev, if (copy_from_user(&bc, arg, sizeof(bc))) return -EFAULT; - if (bc.subdevice >= dev->n_subdevices || bc.subdevice < 0) + if (bc.subdevice >= dev->n_subdevices) return -EINVAL; s = &dev->subdevices[bc.subdevice]; @@ -918,7 +930,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev, if (copy_from_user(&bi, arg, sizeof(bi))) return -EFAULT; - if (bi.subdevice >= dev->n_subdevices || bi.subdevice < 0) + if (bi.subdevice >= dev->n_subdevices) return -EINVAL; s = &dev->subdevices[bi.subdevice]; diff --git a/drivers/staging/comedi/comedi_pci.c b/drivers/staging/comedi/comedi_pci.c index 5fad084cfbd4..abbc0e4f5c51 100644 --- a/drivers/staging/comedi/comedi_pci.c +++ b/drivers/staging/comedi/comedi_pci.c @@ -14,10 +14,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include diff --git a/drivers/staging/comedi/comedi_pcmcia.c b/drivers/staging/comedi/comedi_pcmcia.c index 453ff3b28617..9d49d5d01ad9 100644 --- a/drivers/staging/comedi/comedi_pcmcia.c +++ b/drivers/staging/comedi/comedi_pcmcia.c @@ -14,10 +14,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include diff --git a/drivers/staging/comedi/comedi_usb.c b/drivers/staging/comedi/comedi_usb.c index 9d9716a248f1..13f18bef6091 100644 --- a/drivers/staging/comedi/comedi_usb.c +++ b/drivers/staging/comedi/comedi_usb.c @@ -14,10 +14,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include @@ -34,6 +30,18 @@ struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev) } EXPORT_SYMBOL_GPL(comedi_to_usb_interface); +/** + * comedi_to_usb_dev() - comedi_device pointer to usb_device pointer. + * @dev: comedi_device struct + */ +struct usb_device *comedi_to_usb_dev(struct comedi_device *dev) +{ + struct usb_interface *intf = comedi_to_usb_interface(dev); + + return intf ? interface_to_usbdev(intf) : NULL; +} +EXPORT_SYMBOL_GPL(comedi_to_usb_dev); + /** * comedi_usb_auto_config() - Configure/probe a comedi USB driver. * @intf: usb_interface struct diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index cdd472094cee..b75915f30f48 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _COMEDIDEV_H @@ -270,11 +265,14 @@ enum subdevice_runflags { /* indicates an COMEDI_CB_ERROR event has occurred since the last * command was started */ SRF_ERROR = 0x00000004, - SRF_RUNNING = 0x08000000 + SRF_RUNNING = 0x08000000, + SRF_FREE_SPRIV = 0x80000000, /* free s->private on detach */ }; bool comedi_is_subdevice_running(struct comedi_subdevice *s); +void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size); + int comedi_check_chanlist(struct comedi_subdevice *s, int n, unsigned int *chanlist); @@ -312,6 +310,18 @@ struct comedi_lrange { struct comedi_krange range[GCC_ZERO_LENGTH_ARRAY]; }; +static inline bool comedi_range_is_bipolar(struct comedi_subdevice *s, + unsigned int range) +{ + return s->range_table->range[range].min < 0; +} + +static inline bool comedi_range_is_unipolar(struct comedi_subdevice *s, + unsigned int range) +{ + return s->range_table->range[range].min >= 0; +} + /* some silly little inline functions */ static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd) @@ -349,7 +359,12 @@ void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, int comedi_alloc_subdevices(struct comedi_device *, int); -void comedi_spriv_free(struct comedi_device *, int subdev_num); +int comedi_load_firmware(struct comedi_device *, struct device *, + const char *name, + int (*cb)(struct comedi_device *, + const u8 *data, size_t size, + unsigned long context), + unsigned long context); int __comedi_request_region(struct comedi_device *, unsigned long start, unsigned long len); @@ -489,6 +504,7 @@ struct usb_driver; struct usb_interface; struct usb_interface *comedi_to_usb_interface(struct comedi_device *); +struct usb_device *comedi_to_usb_dev(struct comedi_device *); int comedi_usb_auto_config(struct usb_interface *, struct comedi_driver *, unsigned long context); diff --git a/drivers/staging/comedi/comedilib.h b/drivers/staging/comedi/comedilib.h index ca92c43fdb38..1a78b15543c4 100644 --- a/drivers/staging/comedi/comedilib.h +++ b/drivers/staging/comedi/comedilib.h @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _LINUX_COMEDILIB_H diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 06d190f8fd34..e25eba5713c1 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #include @@ -38,6 +33,7 @@ #include #include #include +#include #include "comedidev.h" #include "comedi_internal.h" @@ -87,18 +83,6 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) } EXPORT_SYMBOL_GPL(comedi_alloc_subdevices); -void comedi_spriv_free(struct comedi_device *dev, int subdev_num) -{ - struct comedi_subdevice *s; - - if (dev->subdevices && subdev_num < dev->n_subdevices) { - s = &dev->subdevices[subdev_num]; - kfree(s->private); - s->private = NULL; - } -} -EXPORT_SYMBOL_GPL(comedi_spriv_free); - static void cleanup_device(struct comedi_device *dev) { int i; @@ -107,6 +91,8 @@ static void cleanup_device(struct comedi_device *dev) if (dev->subdevices) { for (i = 0; i < dev->n_subdevices; i++) { s = &dev->subdevices[i]; + if (s->runflags & SRF_FREE_SPRIV) + kfree(s->private); comedi_free_subdevice_minor(s); if (s->async) { comedi_buf_alloc(dev, s, 0); @@ -351,6 +337,38 @@ static void comedi_report_boards(struct comedi_driver *driv) pr_info(" %s\n", driv->driver_name); } +/** + * comedi_load_firmware() - Request and load firmware for a device. + * @dev: comedi_device struct + * @hw_device: device struct for the comedi_device + * @name: the name of the firmware image + * @cb: callback to the upload the firmware image + * @context: private context from the driver + */ +int comedi_load_firmware(struct comedi_device *dev, + struct device *device, + const char *name, + int (*cb)(struct comedi_device *dev, + const u8 *data, size_t size, + unsigned long context), + unsigned long context) +{ + const struct firmware *fw; + int ret; + + if (!cb) + return -EINVAL; + + ret = request_firmware(&fw, name, device); + if (ret == 0) { + ret = cb(dev, fw->data, fw->size, context); + release_firmware(fw); + } + + return ret; +} +EXPORT_SYMBOL_GPL(comedi_load_firmware); + /** * __comedi_request_region() - Request an I/O reqion for a legacy driver. * @dev: comedi_device struct diff --git a/drivers/staging/comedi/drivers/8253.h b/drivers/staging/comedi/drivers/8253.h index 429e0d60c0a3..3abedcd2527b 100644 --- a/drivers/staging/comedi/drivers/8253.h +++ b/drivers/staging/comedi/drivers/8253.h @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _8253_H diff --git a/drivers/staging/comedi/drivers/8255.c b/drivers/staging/comedi/drivers/8255.c index 1d48aa602ece..94e17500150f 100644 --- a/drivers/staging/comedi/drivers/8255.c +++ b/drivers/staging/comedi/drivers/8255.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: 8255 @@ -81,7 +76,6 @@ I/O port base address can be found in the output of 'lspci -v'. #include "../comedidev.h" #include -#include #include "comedi_fc.h" #include "8255.h" @@ -290,15 +284,13 @@ int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, { struct subdev_8255_private *spriv; - spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); + spriv = comedi_alloc_spriv(s, sizeof(*spriv)); if (!spriv) return -ENOMEM; spriv->iobase = iobase; spriv->io = io ? io : subdev_8255_io; - s->private = spriv; - s->type = COMEDI_SUBD_DIO; s->subdev_flags = SDF_READABLE | SDF_WRITABLE; s->n_chan = 24; @@ -391,7 +383,6 @@ static void dev_8255_detach(struct comedi_device *dev) spriv = s->private; release_region(spriv->iobase, _8255_SIZE); } - comedi_spriv_free(dev, i); } } diff --git a/drivers/staging/comedi/drivers/8255.h b/drivers/staging/comedi/drivers/8255.h index 0f6e7492b7db..4f16ea78f86a 100644 --- a/drivers/staging/comedi/drivers/8255.h +++ b/drivers/staging/comedi/drivers/8255.h @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _8255_H diff --git a/drivers/staging/comedi/drivers/8255_pci.c b/drivers/staging/comedi/drivers/8255_pci.c index 76dec96aeb2a..3d3547c19480 100644 --- a/drivers/staging/comedi/drivers/8255_pci.c +++ b/drivers/staging/comedi/drivers/8255_pci.c @@ -19,10 +19,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -242,10 +238,7 @@ static int pci_8255_auto_attach(struct comedi_device *dev, static void pci_8255_detach(struct comedi_device *dev) { struct pci_8255_private *devpriv = dev->private; - int i; - for (i = 0; i < dev->n_subdevices; i++) - comedi_spriv_free(dev, i); if (devpriv && devpriv->mmio_base) iounmap(devpriv->mmio_base); comedi_pci_disable(dev); diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile index 57e984f0f462..dbb93e332487 100644 --- a/drivers/staging/comedi/drivers/Makefile +++ b/drivers/staging/comedi/drivers/Makefile @@ -11,19 +11,16 @@ obj-$(CONFIG_COMEDI_SERIAL2002) += serial2002.o obj-$(CONFIG_COMEDI_SKEL) += skel.o # Comedi ISA drivers -obj-$(CONFIG_COMEDI_ACL7225B) += acl7225b.o obj-$(CONFIG_COMEDI_AMPLC_DIO200_ISA) += amplc_dio200.o obj-$(CONFIG_COMEDI_AMPLC_PC263_ISA) += amplc_pc263.o obj-$(CONFIG_COMEDI_PCL711) += pcl711.o obj-$(CONFIG_COMEDI_PCL724) += pcl724.o -obj-$(CONFIG_COMEDI_PCL725) += pcl725.o obj-$(CONFIG_COMEDI_PCL726) += pcl726.o obj-$(CONFIG_COMEDI_PCL730) += pcl730.o obj-$(CONFIG_COMEDI_PCL812) += pcl812.o obj-$(CONFIG_COMEDI_PCL816) += pcl816.o obj-$(CONFIG_COMEDI_PCL818) += pcl818.o obj-$(CONFIG_COMEDI_PCM3724) += pcm3724.o -obj-$(CONFIG_COMEDI_PCM3730) += pcm3730.o obj-$(CONFIG_COMEDI_RTI800) += rti800.o obj-$(CONFIG_COMEDI_RTI802) += rti802.o obj-$(CONFIG_COMEDI_DAS16M1) += das16m1.o @@ -55,6 +52,7 @@ obj-$(CONFIG_COMEDI_PCMMIO) += pcmmio.o obj-$(CONFIG_COMEDI_PCMUIO) += pcmuio.o obj-$(CONFIG_COMEDI_MULTIQ3) += multiq3.o obj-$(CONFIG_COMEDI_POC) += poc.o +obj-$(CONFIG_COMEDI_S526) += s526.o # Comedi PCI drivers obj-$(CONFIG_COMEDI_8255_PCI) += 8255_pci.o @@ -110,7 +108,6 @@ obj-$(CONFIG_COMEDI_NI_LABPC_PCI) += ni_labpc_pci.o obj-$(CONFIG_COMEDI_NI_PCIDIO) += ni_pcidio.o obj-$(CONFIG_COMEDI_NI_PCIMIO) += ni_pcimio.o obj-$(CONFIG_COMEDI_RTD520) += rtd520.o -obj-$(CONFIG_COMEDI_S526) += s526.o obj-$(CONFIG_COMEDI_S626) += s626.o obj-$(CONFIG_COMEDI_SSV_DNP) += ssv_dnp.o diff --git a/drivers/staging/comedi/drivers/acl7225b.c b/drivers/staging/comedi/drivers/acl7225b.c deleted file mode 100644 index 9e2c7aeea535..000000000000 --- a/drivers/staging/comedi/drivers/acl7225b.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * comedi/drivers/acl7225b.c - * Driver for Adlink NuDAQ ACL-7225b and clones - * José Luis Sánchez - */ -/* -Driver: acl7225b -Description: Adlink NuDAQ ACL-7225b & compatibles -Author: José Luis Sánchez (jsanchezv@teleline.es) -Status: testing -Devices: [Adlink] ACL-7225b (acl7225b), [ICP] P16R16DIO (p16r16dio) -*/ - -#include "../comedidev.h" - -#include - -#define ACL7225_RIO_LO 0 /* Relays input/output low byte (R0-R7) */ -#define ACL7225_RIO_HI 1 /* Relays input/output high byte (R8-R15) */ -#define ACL7225_DI_LO 2 /* Digital input low byte (DI0-DI7) */ -#define ACL7225_DI_HI 3 /* Digital input high byte (DI8-DI15) */ - -struct acl7225b_boardinfo { - const char *name; - int io_range; -}; - -static const struct acl7225b_boardinfo acl7225b_boards[] = { - { - .name = "acl7225b", - .io_range = 8, /* only 4 are used */ - }, { - .name = "p16r16dio", - .io_range = 4, - }, -}; - -static int acl7225b_do_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - unsigned long reg = (unsigned long)s->private; - unsigned int mask = data[0]; - unsigned int bits = data[1]; - - if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); - - if (mask & 0x00ff) - outb(s->state & 0xff, dev->iobase + reg); - if (mask & 0xff00) - outb((s->state >> 8), dev->iobase + reg + 1); - } - - data[1] = s->state; - - return insn->n; -} - -static int acl7225b_di_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - unsigned long reg = (unsigned long)s->private; - - data[1] = inb(dev->iobase + reg) | - (inb(dev->iobase + reg + 1) << 8); - - return insn->n; -} - -static int acl7225b_attach(struct comedi_device *dev, - struct comedi_devconfig *it) -{ - const struct acl7225b_boardinfo *board = comedi_board(dev); - struct comedi_subdevice *s; - int ret; - - ret = comedi_request_region(dev, it->options[0], board->io_range); - if (ret) - return ret; - - ret = comedi_alloc_subdevices(dev, 3); - if (ret) - return ret; - - s = &dev->subdevices[0]; - /* Relays outputs */ - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->maxdata = 1; - s->n_chan = 16; - s->insn_bits = acl7225b_do_insn_bits; - s->range_table = &range_digital; - s->private = (void *)ACL7225_RIO_LO; - - s = &dev->subdevices[1]; - /* Relays status */ - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->maxdata = 1; - s->n_chan = 16; - s->insn_bits = acl7225b_di_insn_bits; - s->range_table = &range_digital; - s->private = (void *)ACL7225_RIO_LO; - - s = &dev->subdevices[2]; - /* Isolated digital inputs */ - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->maxdata = 1; - s->n_chan = 16; - s->insn_bits = acl7225b_di_insn_bits; - s->range_table = &range_digital; - s->private = (void *)ACL7225_DI_LO; - - return 0; -} - -static struct comedi_driver acl7225b_driver = { - .driver_name = "acl7225b", - .module = THIS_MODULE, - .attach = acl7225b_attach, - .detach = comedi_legacy_detach, - .board_name = &acl7225b_boards[0].name, - .num_names = ARRAY_SIZE(acl7225b_boards), - .offset = sizeof(struct acl7225b_boardinfo), -}; -module_comedi_driver(acl7225b_driver); - -MODULE_DESCRIPTION("Comedi: NuDAQ ACL-7225B, 16 Relay & 16 Isolated DI Card"); -MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/addi-data/APCI1710_Chrono.c b/drivers/staging/comedi/drivers/addi-data/APCI1710_Chrono.c index 5bd7fe64637c..d91f586fdd26 100644 --- a/drivers/staging/comedi/drivers/addi-data/APCI1710_Chrono.c +++ b/drivers/staging/comedi/drivers/addi-data/APCI1710_Chrono.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/APCI1710_Dig_io.c b/drivers/staging/comedi/drivers/addi-data/APCI1710_Dig_io.c index 6b38ce7a275b..27de18e79895 100644 --- a/drivers/staging/comedi/drivers/addi-data/APCI1710_Dig_io.c +++ b/drivers/staging/comedi/drivers/addi-data/APCI1710_Dig_io.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/APCI1710_INCCPT.c b/drivers/staging/comedi/drivers/addi-data/APCI1710_INCCPT.c index 70a7f953fa2f..c9db601da2c9 100644 --- a/drivers/staging/comedi/drivers/addi-data/APCI1710_INCCPT.c +++ b/drivers/staging/comedi/drivers/addi-data/APCI1710_INCCPT.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/APCI1710_Inp_cpt.c b/drivers/staging/comedi/drivers/addi-data/APCI1710_Inp_cpt.c index be0c6adbdc94..6bbcb06cc279 100644 --- a/drivers/staging/comedi/drivers/addi-data/APCI1710_Inp_cpt.c +++ b/drivers/staging/comedi/drivers/addi-data/APCI1710_Inp_cpt.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/APCI1710_Pwm.c b/drivers/staging/comedi/drivers/addi-data/APCI1710_Pwm.c index a211e78dd3ba..5c830337db85 100644 --- a/drivers/staging/comedi/drivers/addi-data/APCI1710_Pwm.c +++ b/drivers/staging/comedi/drivers/addi-data/APCI1710_Pwm.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/APCI1710_Ssi.c b/drivers/staging/comedi/drivers/addi-data/APCI1710_Ssi.c index 97e7eec343d7..6ef1d6a434d9 100644 --- a/drivers/staging/comedi/drivers/addi-data/APCI1710_Ssi.c +++ b/drivers/staging/comedi/drivers/addi-data/APCI1710_Ssi.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/APCI1710_Tor.c b/drivers/staging/comedi/drivers/addi-data/APCI1710_Tor.c index 3bc9826ce40b..0b79531ac24b 100644 --- a/drivers/staging/comedi/drivers/addi-data/APCI1710_Tor.c +++ b/drivers/staging/comedi/drivers/addi-data/APCI1710_Tor.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/APCI1710_Ttl.c b/drivers/staging/comedi/drivers/addi-data/APCI1710_Ttl.c index c8238b8921cd..fb56360444ee 100644 --- a/drivers/staging/comedi/drivers/addi-data/APCI1710_Ttl.c +++ b/drivers/staging/comedi/drivers/addi-data/APCI1710_Ttl.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/addi_common.c b/drivers/staging/comedi/drivers/addi-data/addi_common.c index 0c3db57a50f4..f25e0085219d 100644 --- a/drivers/staging/comedi/drivers/addi-data/addi_common.c +++ b/drivers/staging/comedi/drivers/addi-data/addi_common.c @@ -20,13 +20,6 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., -59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this -source code. - @endverbatim */ /* @@ -46,10 +39,6 @@ source code. +-----------------------------------------------------------------------+ */ -#ifndef COMEDI_SUBD_TTLIO -#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ -#endif - static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -105,23 +94,14 @@ static int addi_auto_attach(struct comedi_device *dev, if (ret) return ret; - if (!this_board->pc_EepromChip || - strcmp(this_board->pc_EepromChip, ADDIDATA_9054)) { - /* board does not have an eeprom or is not ADDIDATA_9054 */ - if (this_board->i_IorangeBase1) - dev->iobase = pci_resource_start(pcidev, 1); - else - dev->iobase = pci_resource_start(pcidev, 0); + if (this_board->i_IorangeBase1) + dev->iobase = pci_resource_start(pcidev, 1); + else + dev->iobase = pci_resource_start(pcidev, 0); - devpriv->iobase = dev->iobase; - devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); - devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); - } else { - /* board has an ADDIDATA_9054 eeprom */ - dev->iobase = pci_resource_start(pcidev, 2); - devpriv->iobase = pci_resource_start(pcidev, 2); - devpriv->dw_AiBase = pci_ioremap_bar(pcidev, 3); - } + devpriv->iobase = dev->iobase; + devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); + devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); /* Initialize parameters that can be overridden in EEPROM */ @@ -132,7 +112,6 @@ static int addi_auto_attach(struct comedi_device *dev, devpriv->s_EeParameters.i_NbrDiChannel = this_board->i_NbrDiChannel; devpriv->s_EeParameters.i_NbrDoChannel = this_board->i_NbrDoChannel; devpriv->s_EeParameters.i_DoMaxdata = this_board->i_DoMaxdata; - devpriv->s_EeParameters.i_Dma = this_board->i_Dma; devpriv->s_EeParameters.i_Timer = this_board->i_Timer; devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = this_board->ui_MinAcquisitiontimeNs; @@ -191,9 +170,6 @@ static int addi_auto_attach(struct comedi_device *dev, s->len_chanlist = this_board->i_AiChannelList; s->range_table = this_board->pr_AiRangelist; - /* Set the initialisation flag */ - devpriv->b_AiInitialisation = 1; - s->insn_config = this_board->ai_config; s->insn_read = this_board->ai_read; s->insn_write = this_board->ai_write; @@ -215,8 +191,6 @@ static int addi_auto_attach(struct comedi_device *dev, s->maxdata = devpriv->s_EeParameters.i_AoMaxdata; s->len_chanlist = devpriv->s_EeParameters.i_NbrAoChannel; - s->range_table = this_board->pr_AoRangelist; - s->insn_config = this_board->ao_config; s->insn_write = this_board->ao_write; } else { s->type = COMEDI_SUBD_UNUSED; @@ -281,22 +255,7 @@ static int addi_auto_attach(struct comedi_device *dev, /* Allocate and Initialise TTL */ s = &dev->subdevices[5]; - if (this_board->i_NbrTTLChannel) { - s->type = COMEDI_SUBD_TTLIO; - s->subdev_flags = - SDF_WRITEABLE | SDF_READABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = this_board->i_NbrTTLChannel; - s->maxdata = 1; - s->io_bits = 0; /* all bits input */ - s->len_chanlist = this_board->i_NbrTTLChannel; - s->range_table = &range_digital; - s->insn_config = this_board->ttl_config; - s->insn_bits = this_board->ttl_bits; - s->insn_read = this_board->ttl_read; - s->insn_write = this_board->ttl_write; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + s->type = COMEDI_SUBD_UNUSED; /* EEPROM */ s = &dev->subdevices[6]; @@ -323,8 +282,6 @@ static void i_ADDI_Detach(struct comedi_device *dev) i_ADDI_Reset(dev); if (dev->irq) free_irq(dev->irq, dev); - if (devpriv->dw_AiBase) - iounmap(devpriv->dw_AiBase); } comedi_pci_disable(dev); } diff --git a/drivers/staging/comedi/drivers/addi-data/addi_common.h b/drivers/staging/comedi/drivers/addi-data/addi_common.h index c034bf1426eb..f1be5ade9962 100644 --- a/drivers/staging/comedi/drivers/addi-data/addi_common.h +++ b/drivers/staging/comedi/drivers/addi-data/addi_common.h @@ -18,12 +18,8 @@ #include #include -#define LOBYTE(W) (unsigned char)((W) & 0xFF) -#define HIBYTE(W) (unsigned char)(((W) >> 8) & 0xFF) -#define MAKEWORD(H, L) (unsigned short)((L) | ((H) << 8)) #define LOWORD(W) (unsigned short)((W) & 0xFFFF) #define HIWORD(W) (unsigned short)(((W) >> 16) & 0xFFFF) -#define MAKEDWORD(H, L) (unsigned int)((L) | ((H) << 16)) #define ADDI_ENABLE 1 #define ADDI_DISABLE 0 @@ -33,8 +29,6 @@ #define ADDIDATA_NO_EEPROM 0 #define ADDIDATA_93C76 "93C76" #define ADDIDATA_S5920 "S5920" -#define ADDIDATA_S5933 "S5933" -#define ADDIDATA_9054 "9054" /* ADDIDATA Enable Disable */ #define ADDIDATA_ENABLE 1 @@ -55,17 +49,12 @@ struct addi_board { int i_AiMaxdata; /* resolution of A/D */ int i_AoMaxdata; /* resolution of D/A */ const struct comedi_lrange *pr_AiRangelist; /* rangelist for A/D */ - const struct comedi_lrange *pr_AoRangelist; /* rangelist for D/A */ int i_NbrDiChannel; /* Number of DI channels */ int i_NbrDoChannel; /* Number of DO channels */ int i_DoMaxdata; /* data to set all channels high */ - int i_NbrTTLChannel; /* Number of TTL channels */ - - int i_Dma; /* dma present or not */ int i_Timer; /* timer subdevice present or not */ - unsigned char b_AvailableConvertUnit; unsigned int ui_MinAcquisitiontimeNs; /* Minimum Acquisition in Nano secs */ unsigned int ui_MinDelaytimeNs; /* Minimum Delay in Nano secs */ @@ -90,12 +79,8 @@ struct addi_board { int (*ai_cancel)(struct comedi_device *, struct comedi_subdevice *); /* Analog Output */ - int (*ao_config)(struct comedi_device *, struct comedi_subdevice *, - struct comedi_insn *, unsigned int *); int (*ao_write)(struct comedi_device *, struct comedi_subdevice *, struct comedi_insn *, unsigned int *); - int (*ao_bits)(struct comedi_device *, struct comedi_subdevice *, - struct comedi_insn *, unsigned int *); /* Digital Input */ int (*di_config)(struct comedi_device *, struct comedi_subdevice *, @@ -126,16 +111,6 @@ struct addi_board { struct comedi_insn *, unsigned int *); int (*timer_bits)(struct comedi_device *, struct comedi_subdevice *, struct comedi_insn *, unsigned int *); - - /* TTL IO */ - int (*ttl_config)(struct comedi_device *, struct comedi_subdevice *, - struct comedi_insn *, unsigned int *); - int (*ttl_bits)(struct comedi_device *, struct comedi_subdevice *, - struct comedi_insn *, unsigned int *); - int (*ttl_read)(struct comedi_device *, struct comedi_subdevice *, - struct comedi_insn *, unsigned int *); - int (*ttl_write)(struct comedi_device *, struct comedi_subdevice *, - struct comedi_insn *, unsigned int *); }; /* MODULE INFO STRUCTURE */ @@ -283,58 +258,41 @@ union str_ModuleInfo { /* Private structure for the addi_apci3120 driver */ struct addi_private { - int iobase; int i_IobaseAmcc; /* base+size for AMCC chip */ int i_IobaseAddon; /* addon base address */ int i_IobaseReserved; - void __iomem *dw_AiBase; unsigned char b_AiContinuous; /* we do unlimited AI */ - unsigned char b_AiInitialisation; unsigned int ui_AiActualScan; /* how many scans we finished */ - unsigned int ui_AiBufferPtr; /* data buffer ptr in samples */ unsigned int ui_AiNbrofChannels; /* how many channels is measured */ unsigned int ui_AiScanLength; /* Length of actual scanlist */ - unsigned int ui_AiActualScanPosition; /* position in actual scan */ unsigned int *pui_AiChannelList; /* actual chanlist */ unsigned int ui_AiChannelList[32]; /* actual chanlist */ - unsigned char b_AiChannelConfiguration[32]; /* actual chanlist */ unsigned int ui_AiReadData[32]; - unsigned int dw_AiInitialised; unsigned int ui_AiTimer0; /* Timer Constant for Timer0 */ unsigned int ui_AiTimer1; /* Timer constant for Timer1 */ unsigned int ui_AiFlags; unsigned int ui_AiDataLength; - short *AiData; /* Pointer to sample data */ unsigned int ui_AiNbrofScans; /* number of scans to do */ unsigned short us_UseDma; /* To use Dma or not */ unsigned char b_DmaDoubleBuffer; /* we can use double buffering */ unsigned int ui_DmaActualBuffer; /* which buffer is used now */ - /* UPDATE-0.7.57->0.7.68 */ - /* unsigned int ul_DmaBufferVirtual[2]; pointers to begin of DMA buffer */ short *ul_DmaBufferVirtual[2]; /* pointers to begin of DMA buffer */ unsigned int ul_DmaBufferHw[2]; /* hw address of DMA buff */ unsigned int ui_DmaBufferSize[2]; /* size of dma buffer in bytes */ unsigned int ui_DmaBufferUsesize[2]; /* which size we may now used for transfer */ - unsigned int ui_DmaBufferSamples[2]; /* size in samples */ unsigned int ui_DmaBufferPages[2]; /* number of pages in buffer */ unsigned char b_DigitalOutputRegister; /* Digital Output Register */ unsigned char b_OutputMemoryStatus; - unsigned char b_AnalogInputChannelNbr; /* Analog input channel Nbr */ - unsigned char b_AnalogOutputChannelNbr; /* Analog input Output Nbr */ unsigned char b_TimerSelectMode; /* Contain data written at iobase + 0C */ unsigned char b_ModeSelectRegister; /* Contain data written at iobase + 0E */ unsigned short us_OutputRegister; /* Contain data written at iobase + 0 */ - unsigned char b_InterruptState; - unsigned char b_TimerInit; /* Specify if InitTimerWatchdog was load */ - unsigned char b_TimerStarted; /* Specify if timer 2 is running or not */ unsigned char b_Timer2Mode; /* Specify the timer 2 mode */ unsigned char b_Timer2Interrupt; /* Timer2 interrupt enable or disable */ unsigned char b_AiCyclicAcquisition; /* indicate cyclic acquisition */ unsigned char b_InterruptMode; /* eoc eos or dma */ unsigned char b_EocEosInterrupt; /* Enable disable eoc eos interrupt */ unsigned int ui_EocEosConversionTime; - unsigned char b_EocEosConversionTimeBase; unsigned char b_SingelDiff; unsigned char b_ExttrigEnable; /* To enable or disable external trigger */ @@ -365,7 +323,6 @@ struct addi_private { } s_InterruptParameters; union str_ModuleInfo s_ModuleInfo[4]; - unsigned int ul_TTLPortConfiguration[10]; /* Parameters read from EEPROM overriding static board info */ struct { @@ -376,7 +333,6 @@ struct addi_private { int i_NbrDiChannel; /* Number of DI channels */ int i_NbrDoChannel; /* Number of DO channels */ int i_DoMaxdata; /* data to set all channels high */ - int i_Dma; /* dma present or not */ int i_Timer; /* timer subdevice present or not */ unsigned int ui_MinAcquisitiontimeNs; /* Minimum Acquisition in Nano secs */ diff --git a/drivers/staging/comedi/drivers/addi-data/addi_eeprom.c b/drivers/staging/comedi/drivers/addi-data/addi_eeprom.c index 5124ac9f1818..dc031c494a27 100644 --- a/drivers/staging/comedi/drivers/addi-data/addi_eeprom.c +++ b/drivers/staging/comedi/drivers/addi-data/addi_eeprom.c @@ -20,13 +20,6 @@ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * You should also find the complete GPL in the COPYING file accompanying - * this source code. */ #define NVRAM_USER_DATA_START 0x100 @@ -302,7 +295,7 @@ static void addi_eeprom_read_ai_info(struct comedi_device *dev, devpriv->s_EeParameters.ui_MinDelaytimeNs = tmp * 1000; tmp = addi_eeprom_readw(iobase, type, addr + 20); - devpriv->s_EeParameters.i_Dma = (tmp >> 13) & 0x01; + /* dma = (tmp >> 13) & 0x01; */ tmp = addi_eeprom_readw(iobase, type, addr + 72) & 0xff; if (tmp) { /* > 0 */ diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_APCI1710.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_APCI1710.c index b05f8505c894..b1a7ec1035e1 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_APCI1710.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_APCI1710.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci035.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci035.c index 3d66e48e0cf7..1128c22e7517 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci035.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci035.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c index 24c4c983db38..054910511e9e 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c index fc31c4b93407..e3cc429403c0 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c index 74065baa3c08..a89e505c8a3a 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* @@ -724,9 +720,7 @@ static int i_APCI3120_StopCyclicAcquisition(struct comedi_device *dev, inb(dev->iobase + APCI3120_RESET_FIFO); inw(dev->iobase + APCI3120_RD_STATUS); devpriv->ui_AiActualScan = 0; - devpriv->ui_AiActualScanPosition = 0; s->async->cur_chan = 0; - devpriv->ui_AiBufferPtr = 0; devpriv->b_AiContinuous = 0; devpriv->ui_DmaActualBuffer = 0; @@ -895,9 +889,7 @@ static int i_APCI3120_CyclicAnalogInput(int mode, /* END JK 07.05.04: Comparison between WIN32 and Linux driver */ devpriv->ui_AiActualScan = 0; - devpriv->ui_AiActualScanPosition = 0; s->async->cur_chan = 0; - devpriv->ui_AiBufferPtr = 0; devpriv->ui_DmaActualBuffer = 0; /* value for timer2 minus -2 has to be done .....dunno y?? */ @@ -1351,8 +1343,6 @@ static int i_APCI3120_CommandAnalogInput(struct comedi_device *dev, devpriv->ui_AiScanLength = cmd->scan_end_arg; devpriv->pui_AiChannelList = cmd->chanlist; - /* UPDATE-0.7.57->0.7.68devpriv->AiData=s->async->data; */ - devpriv->AiData = s->async->prealloc_buf; /* UPDATE-0.7.57->0.7.68devpriv->ui_AiDataLength=s->async->data_len; */ devpriv->ui_AiDataLength = s->async->prealloc_bufsz; diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c index c7908730caa5..32dce0329fd5 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c @@ -15,10 +15,6 @@ This program is free software; you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - @endverbatim */ /* diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c deleted file mode 100644 index a45a2a26e0da..000000000000 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3xxx.c +++ /dev/null @@ -1,1376 +0,0 @@ -/** -@verbatim - -Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. - - ADDI-DATA GmbH - Dieselstrasse 3 - D-77833 Ottersweier - Tel: +19(0)7223/9493-0 - Fax: +49(0)7223/9493-92 - http://www.addi-data.com - info@addi-data.com - -This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You should also find the complete GPL in the COPYING file accompanying this source code. - -@endverbatim -*/ -/* - +-----------------------------------------------------------------------+ - | (C) ADDI-DATA GmbH Dieselstrasse 3 D-77833 Ottersweier | - +-----------------------------------------------------------------------+ - | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com | - | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com | - +-----------------------------------------------------------------------+ - | Project : APCI-3XXX | Compiler : GCC | - | Module name : hwdrv_apci3xxx.c| Version : 2.96 | - +-------------------------------+---------------------------------------+ - | Project manager: S. Weber | Date : 15/09/2005 | - +-----------------------------------------------------------------------+ - | Description :APCI3XXX Module. Hardware abstraction Layer for APCI3XXX| - +-----------------------------------------------------------------------+ - | UPDATE'S | - +-----------------------------------------------------------------------+ - | Date | Author | Description of updates | - +----------+-----------+------------------------------------------------+ - | | | | - | | | | - +----------+-----------+------------------------------------------------+ -*/ - -#ifndef COMEDI_SUBD_TTLIO -#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ -#endif - -#define APCI3XXX_SINGLE 0 -#define APCI3XXX_DIFF 1 -#define APCI3XXX_CONFIGURATION 0 - -#define APCI3XXX_TTL_INIT_DIRECTION_PORT2 0 - -static const struct comedi_lrange range_apci3XXX_ai = { - 8, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2), - BIP_RANGE(1), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2), - UNI_RANGE(1) - } -}; - -static const struct comedi_lrange range_apci3XXX_ao = { - 2, { - BIP_RANGE(10), - UNI_RANGE(10) - } -}; - -/* -+----------------------------------------------------------------------------+ -| ANALOG INPUT FUNCTIONS | -+----------------------------------------------------------------------------+ -*/ - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3XXX_TestConversionStarted | -| (struct comedi_device *dev) | -+----------------------------------------------------------------------------+ -| Task Test if any conversion started | -+----------------------------------------------------------------------------+ -| Input Parameters : - | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value : 0 : Conversion not started | -| 1 : Conversion started | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3XXX_TestConversionStarted(struct comedi_device *dev) -{ - struct addi_private *devpriv = dev->private; - - if ((readl(devpriv->dw_AiBase + 8) & 0x80000UL) == 0x80000UL) - return 1; - else - return 0; - -} - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3XXX_AnalogInputConfigOperatingMode | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task Converting mode and convert time selection | -+----------------------------------------------------------------------------+ -| Input Parameters : b_SingleDiff = (unsigned char) data[1]; | -| b_TimeBase = (unsigned char) data[2]; (0: ns, 1:micros 2:ms)| -| dw_ReloadValue = (unsigned int) data[3]; | -| ........ | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value :>0 : No error | -| -1 : Single/Diff selection error | -| -2 : Convert time base unity selection error | -| -3 : Convert time value selection error | -| -10: Any conversion started | -| .... | -| -100 : Config command error | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3XXX_AnalogInputConfigOperatingMode(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - const struct addi_board *this_board = comedi_board(dev); - struct addi_private *devpriv = dev->private; - int i_ReturnValue = insn->n; - unsigned char b_TimeBase = 0; - unsigned char b_SingleDiff = 0; - unsigned int dw_ReloadValue = 0; - unsigned int dw_TestReloadValue = 0; - - /************************/ - /* Test the buffer size */ - /************************/ - - if (insn->n == 4) { - /****************************/ - /* Get the Singel/Diff flag */ - /****************************/ - - b_SingleDiff = (unsigned char) data[1]; - - /****************************/ - /* Get the time base unitiy */ - /****************************/ - - b_TimeBase = (unsigned char) data[2]; - - /*************************************/ - /* Get the convert time reload value */ - /*************************************/ - - dw_ReloadValue = (unsigned int) data[3]; - - /**********************/ - /* Test the time base */ - /**********************/ - - if ((this_board->b_AvailableConvertUnit & (1 << b_TimeBase)) != - 0) { - /*******************************/ - /* Test the convert time value */ - /*******************************/ - - if (dw_ReloadValue <= 65535) { - dw_TestReloadValue = dw_ReloadValue; - - if (b_TimeBase == 1) { - dw_TestReloadValue = - dw_TestReloadValue * 1000UL; - } - if (b_TimeBase == 2) { - dw_TestReloadValue = - dw_TestReloadValue * 1000000UL; - } - - /*******************************/ - /* Test the convert time value */ - /*******************************/ - - if (dw_TestReloadValue >= - devpriv->s_EeParameters. - ui_MinAcquisitiontimeNs) { - if ((b_SingleDiff == APCI3XXX_SINGLE) - || (b_SingleDiff == - APCI3XXX_DIFF)) { - if (((b_SingleDiff == APCI3XXX_SINGLE) - && (devpriv->s_EeParameters.i_NbrAiChannel == 0)) - || ((b_SingleDiff == APCI3XXX_DIFF) - && (this_board->i_NbrAiChannelDiff == 0)) - ) { - /*******************************/ - /* Single/Diff selection error */ - /*******************************/ - - printk("Single/Diff selection error\n"); - i_ReturnValue = -1; - } else { - /**********************************/ - /* Test if conversion not started */ - /**********************************/ - - if (i_APCI3XXX_TestConversionStarted(dev) == 0) { - devpriv-> - ui_EocEosConversionTime - = - (unsigned int) - dw_ReloadValue; - devpriv-> - b_EocEosConversionTimeBase - = - b_TimeBase; - devpriv-> - b_SingelDiff - = - b_SingleDiff; - devpriv-> - b_AiInitialisation - = 1; - - /*******************************/ - /* Set the convert timing unit */ - /*******************************/ - - writel((unsigned int)b_TimeBase, - devpriv->dw_AiBase + 36); - - /**************************/ - /* Set the convert timing */ - /*************************/ - - writel(dw_ReloadValue, devpriv->dw_AiBase + 32); - } else { - /**************************/ - /* Any conversion started */ - /**************************/ - - printk("Any conversion started\n"); - i_ReturnValue = - -10; - } - } - } else { - /*******************************/ - /* Single/Diff selection error */ - /*******************************/ - - printk("Single/Diff selection error\n"); - i_ReturnValue = -1; - } - } else { - /************************/ - /* Time selection error */ - /************************/ - - printk("Convert time value selection error\n"); - i_ReturnValue = -3; - } - } else { - /************************/ - /* Time selection error */ - /************************/ - - printk("Convert time value selection error\n"); - i_ReturnValue = -3; - } - } else { - /*****************************/ - /* Time base selection error */ - /*****************************/ - - printk("Convert time base unity selection error\n"); - i_ReturnValue = -2; - } - } else { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return i_ReturnValue; -} - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3XXX_InsnConfigAnalogInput | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task Converting mode and convert time selection | -+----------------------------------------------------------------------------+ -| Input Parameters : b_ConvertMode = (unsigned char) data[0]; | -| b_TimeBase = (unsigned char) data[1]; (0: ns, 1:micros 2:ms)| -| dw_ReloadValue = (unsigned int) data[2]; | -| ........ | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value :>0: No error | -| .... | -| -100 : Config command error | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3XXX_InsnConfigAnalogInput(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - int i_ReturnValue = insn->n; - - /************************/ - /* Test the buffer size */ - /************************/ - - if (insn->n >= 1) { - switch ((unsigned char) data[0]) { - case APCI3XXX_CONFIGURATION: - i_ReturnValue = - i_APCI3XXX_AnalogInputConfigOperatingMode(dev, - s, insn, data); - break; - - default: - i_ReturnValue = -100; - printk("Config command error %d\n", data[0]); - break; - } - } else { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return i_ReturnValue; -} - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3XXX_InsnReadAnalogInput | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task Read 1 analog input | -+----------------------------------------------------------------------------+ -| Input Parameters : b_Range = CR_RANGE(insn->chanspec); | -| b_Channel = CR_CHAN(insn->chanspec); | -| dw_NbrOfAcquisition = insn->n; | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value :>0: No error | -| -3 : Channel selection error | -| -4 : Configuration selelection error | -| -10: Any conversion started | -| .... | -| -100 : Config command error | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3XXX_InsnReadAnalogInput(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - const struct addi_board *this_board = comedi_board(dev); - struct addi_private *devpriv = dev->private; - int i_ReturnValue = insn->n; - unsigned char b_Configuration = (unsigned char) CR_RANGE(insn->chanspec); - unsigned char b_Channel = (unsigned char) CR_CHAN(insn->chanspec); - unsigned int dw_Temp = 0; - unsigned int dw_Configuration = 0; - unsigned int dw_AcquisitionCpt = 0; - unsigned char b_Interrupt = 0; - - /*************************************/ - /* Test if operating mode configured */ - /*************************************/ - - if (devpriv->b_AiInitialisation) { - /***************************/ - /* Test the channel number */ - /***************************/ - - if (((b_Channel < devpriv->s_EeParameters.i_NbrAiChannel) - && (devpriv->b_SingelDiff == APCI3XXX_SINGLE)) - || ((b_Channel < this_board->i_NbrAiChannelDiff) - && (devpriv->b_SingelDiff == APCI3XXX_DIFF))) { - /**********************************/ - /* Test the channel configuration */ - /**********************************/ - - if (b_Configuration > 7) { - /***************************/ - /* Channel not initialised */ - /***************************/ - - i_ReturnValue = -4; - printk("Channel %d range %d selection error\n", - b_Channel, b_Configuration); - } - } else { - /***************************/ - /* Channel selection error */ - /***************************/ - - i_ReturnValue = -3; - printk("Channel %d selection error\n", b_Channel); - } - - /**************************/ - /* Test if no error occur */ - /**************************/ - - if (i_ReturnValue >= 0) { - /************************/ - /* Test the buffer size */ - /************************/ - - if ((b_Interrupt != 0) || ((b_Interrupt == 0) - && (insn->n >= 1))) { - /**********************************/ - /* Test if conversion not started */ - /**********************************/ - - if (i_APCI3XXX_TestConversionStarted(dev) == 0) { - /******************/ - /* Clear the FIFO */ - /******************/ - - writel(0x10000UL, devpriv->dw_AiBase + 12); - - /*******************************/ - /* Get and save the delay mode */ - /*******************************/ - - dw_Temp = readl(devpriv->dw_AiBase + 4); - dw_Temp = dw_Temp & 0xFFFFFEF0UL; - - /***********************************/ - /* Channel configuration selection */ - /***********************************/ - - writel(dw_Temp, devpriv->dw_AiBase + 4); - - /**************************/ - /* Make the configuration */ - /**************************/ - - dw_Configuration = - (b_Configuration & 3) | - ((unsigned int) (b_Configuration >> 2) - << 6) | ((unsigned int) devpriv-> - b_SingelDiff << 7); - - /***************************/ - /* Write the configuration */ - /***************************/ - - writel(dw_Configuration, - devpriv->dw_AiBase + 0); - - /*********************/ - /* Channel selection */ - /*********************/ - - writel(dw_Temp | 0x100UL, - devpriv->dw_AiBase + 4); - writel((unsigned int) b_Channel, - devpriv->dw_AiBase + 0); - - /***********************/ - /* Restaure delay mode */ - /***********************/ - - writel(dw_Temp, devpriv->dw_AiBase + 4); - - /***********************************/ - /* Set the number of sequence to 1 */ - /***********************************/ - - writel(1, devpriv->dw_AiBase + 48); - - /***************************/ - /* Save the interrupt flag */ - /***************************/ - - devpriv->b_EocEosInterrupt = - b_Interrupt; - - /*******************************/ - /* Save the number of channels */ - /*******************************/ - - devpriv->ui_AiNbrofChannels = 1; - - /******************************/ - /* Test if interrupt not used */ - /******************************/ - - if (b_Interrupt == 0) { - for (dw_AcquisitionCpt = 0; - dw_AcquisitionCpt < - insn->n; - dw_AcquisitionCpt++) { - /************************/ - /* Start the conversion */ - /************************/ - - writel(0x80000UL, devpriv->dw_AiBase + 8); - - /****************/ - /* Wait the EOS */ - /****************/ - - do { - dw_Temp = readl(devpriv->dw_AiBase + 20); - dw_Temp = dw_Temp & 1; - } while (dw_Temp != 1); - - /*************************/ - /* Read the analog value */ - /*************************/ - - data[dw_AcquisitionCpt] = (unsigned int)readl(devpriv->dw_AiBase + 28); - } - } else { - /************************/ - /* Start the conversion */ - /************************/ - - writel(0x180000UL, devpriv->dw_AiBase + 8); - } - } else { - /**************************/ - /* Any conversion started */ - /**************************/ - - printk("Any conversion started\n"); - i_ReturnValue = -10; - } - } else { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - } - } else { - /***************************/ - /* Channel selection error */ - /***************************/ - - printk("Operating mode not configured\n"); - i_ReturnValue = -1; - } - return i_ReturnValue; -} - -/* -+----------------------------------------------------------------------------+ -| Function name : void v_APCI3XXX_Interrupt (int irq, | -| void *d) | -+----------------------------------------------------------------------------+ -| Task :Interrupt handler for APCI3XXX | -| When interrupt occurs this gets called. | -| First it finds which interrupt has been generated and | -| handles corresponding interrupt | -+----------------------------------------------------------------------------+ -| Input Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value : - | -+----------------------------------------------------------------------------+ -*/ - -static void v_APCI3XXX_Interrupt(int irq, void *d) -{ - struct comedi_device *dev = d; - struct addi_private *devpriv = dev->private; - unsigned char b_CopyCpt = 0; - unsigned int dw_Status = 0; - - /***************************/ - /* Test if interrupt occur */ - /***************************/ - - dw_Status = readl(devpriv->dw_AiBase + 16); - if ( (dw_Status & 0x2UL) == 0x2UL) { - /***********************/ - /* Reset the interrupt */ - /***********************/ - - writel(dw_Status, devpriv->dw_AiBase + 16); - - /*****************************/ - /* Test if interrupt enabled */ - /*****************************/ - - if (devpriv->b_EocEosInterrupt == 1) { - /********************************/ - /* Read all analog inputs value */ - /********************************/ - - for (b_CopyCpt = 0; - b_CopyCpt < devpriv->ui_AiNbrofChannels; - b_CopyCpt++) { - devpriv->ui_AiReadData[b_CopyCpt] = - (unsigned int)readl(devpriv->dw_AiBase + 28); - } - - /**************************/ - /* Set the interrupt flag */ - /**************************/ - - devpriv->b_EocEosInterrupt = 2; - - /**********************************************/ - /* Send a signal to from kernel to user space */ - /**********************************************/ - - send_sig(SIGIO, devpriv->tsk_Current, 0); - } - } -} - -/* -+----------------------------------------------------------------------------+ -| ANALOG OUTPUT SUBDEVICE | -+----------------------------------------------------------------------------+ -*/ - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3XXX_InsnWriteAnalogOutput | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task Read 1 analog input | -+----------------------------------------------------------------------------+ -| Input Parameters : b_Range = CR_RANGE(insn->chanspec); | -| b_Channel = CR_CHAN(insn->chanspec); | -| data[0] = analog value; | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value :>0: No error | -| -3 : Channel selection error | -| -4 : Configuration selelection error | -| .... | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3XXX_InsnWriteAnalogOutput(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - unsigned char b_Range = (unsigned char) CR_RANGE(insn->chanspec); - unsigned char b_Channel = (unsigned char) CR_CHAN(insn->chanspec); - unsigned int dw_Status = 0; - int i_ReturnValue = insn->n; - - /************************/ - /* Test the buffer size */ - /************************/ - - if (insn->n >= 1) { - /***************************/ - /* Test the channel number */ - /***************************/ - - if (b_Channel < devpriv->s_EeParameters.i_NbrAoChannel) { - /**********************************/ - /* Test the channel configuration */ - /**********************************/ - - if (b_Range < 2) { - /***************************/ - /* Set the range selection */ - /***************************/ - - writel(b_Range, devpriv->dw_AiBase + 96); - - /**************************************************/ - /* Write the analog value to the selected channel */ - /**************************************************/ - - writel((data[0] << 8) | b_Channel, - devpriv->dw_AiBase + 100); - - /****************************/ - /* Wait the end of transfer */ - /****************************/ - - do { - dw_Status = readl(devpriv->dw_AiBase + 96); - } while ((dw_Status & 0x100) != 0x100); - } else { - /***************************/ - /* Channel not initialised */ - /***************************/ - - i_ReturnValue = -4; - printk("Channel %d range %d selection error\n", - b_Channel, b_Range); - } - } else { - /***************************/ - /* Channel selection error */ - /***************************/ - - i_ReturnValue = -3; - printk("Channel %d selection error\n", b_Channel); - } - } else { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return i_ReturnValue; -} - -/* -+----------------------------------------------------------------------------+ -| TTL FUNCTIONS | -+----------------------------------------------------------------------------+ -*/ - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3XXX_InsnConfigInitTTLIO | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task You must calling this function be | -| for you call any other function witch access of TTL. | -| APCI3XXX_TTL_INIT_DIRECTION_PORT2(user inputs for direction)| -+----------------------------------------------------------------------------+ -| Input Parameters : b_InitType = (unsigned char) data[0]; | -| b_Port2Mode = (unsigned char) data[1]; | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value :>0: No error | -| -1: Port 2 mode selection is wrong | -| .... | -| -100 : Config command error | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3XXX_InsnConfigInitTTLIO(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - int i_ReturnValue = insn->n; - unsigned char b_Command = 0; - - /************************/ - /* Test the buffer size */ - /************************/ - - if (insn->n >= 1) { - /*******************/ - /* Get the command */ - /* **************** */ - - b_Command = (unsigned char) data[0]; - - /********************/ - /* Test the command */ - /********************/ - - if (b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2) { - /***************************************/ - /* Test the initialisation buffer size */ - /***************************************/ - - if ((b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2) - && (insn->n != 2)) { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - } else { - /************************/ - /* Config command error */ - /************************/ - - printk("Command selection error\n"); - i_ReturnValue = -100; - } - } else { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - /*********************************************************************************/ - /* Test if no error occur and APCI3XXX_TTL_INIT_DIRECTION_PORT2 command selected */ - /*********************************************************************************/ - - if ((i_ReturnValue >= 0) - && (b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2)) { - /**********************/ - /* Test the direction */ - /**********************/ - - if ((data[1] == 0) || (data[1] == 0xFF)) { - /**************************/ - /* Save the configuration */ - /**************************/ - - devpriv->ul_TTLPortConfiguration[0] = - devpriv->ul_TTLPortConfiguration[0] | data[1]; - } else { - /************************/ - /* Port direction error */ - /************************/ - - printk("Port 2 direction selection error\n"); - i_ReturnValue = -1; - } - } - - /**************************/ - /* Test if no error occur */ - /**************************/ - - if (i_ReturnValue >= 0) { - /***********************************/ - /* Test if TTL port initilaisation */ - /***********************************/ - - if (b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2) { - /*************************/ - /* Set the configuration */ - /*************************/ - - outl(data[1], devpriv->iobase + 224); - } - } - - return i_ReturnValue; -} - -/* -+----------------------------------------------------------------------------+ -| TTL INPUT FUNCTIONS | -+----------------------------------------------------------------------------+ -*/ - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3XXX_InsnBitsTTLIO | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Write the selected output mask and read the status from| -| all TTL channles | -+----------------------------------------------------------------------------+ -| Input Parameters : dw_ChannelMask = data [0]; | -| dw_BitMask = data [1]; | -+----------------------------------------------------------------------------+ -| Output Parameters : data[1] : All TTL channles states | -+----------------------------------------------------------------------------+ -| Return Value : >0 : No error | -| -4 : Channel mask error | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3XXX_InsnBitsTTLIO(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - int i_ReturnValue = insn->n; - unsigned char b_ChannelCpt = 0; - unsigned int dw_ChannelMask = 0; - unsigned int dw_BitMask = 0; - unsigned int dw_Status = 0; - - /************************/ - /* Test the buffer size */ - /************************/ - - if (insn->n >= 2) { - /*******************************/ - /* Get the channe and bit mask */ - /*******************************/ - - dw_ChannelMask = data[0]; - dw_BitMask = data[1]; - - /*************************/ - /* Test the channel mask */ - /*************************/ - - if (((dw_ChannelMask & 0XFF00FF00) == 0) && - (((devpriv->ul_TTLPortConfiguration[0] & 0xFF) == 0xFF) - || (((devpriv->ul_TTLPortConfiguration[0] & - 0xFF) == 0) - && ((dw_ChannelMask & 0XFF0000) == - 0)))) { - /*********************************/ - /* Test if set/reset any channel */ - /*********************************/ - - if (dw_ChannelMask) { - /****************************************/ - /* Test if set/rest any port 0 channels */ - /****************************************/ - - if (dw_ChannelMask & 0xFF) { - /*******************************************/ - /* Read port 0 (first digital output port) */ - /*******************************************/ - - dw_Status = inl(devpriv->iobase + 80); - - for (b_ChannelCpt = 0; b_ChannelCpt < 8; - b_ChannelCpt++) { - if ((dw_ChannelMask >> - b_ChannelCpt) & - 1) { - dw_Status = - (dw_Status & - (0xFF - (1 << b_ChannelCpt))) | (dw_BitMask & (1 << b_ChannelCpt)); - } - } - - outl(dw_Status, devpriv->iobase + 80); - } - - /****************************************/ - /* Test if set/rest any port 2 channels */ - /****************************************/ - - if (dw_ChannelMask & 0xFF0000) { - dw_BitMask = dw_BitMask >> 16; - dw_ChannelMask = dw_ChannelMask >> 16; - - /********************************************/ - /* Read port 2 (second digital output port) */ - /********************************************/ - - dw_Status = inl(devpriv->iobase + 112); - - for (b_ChannelCpt = 0; b_ChannelCpt < 8; - b_ChannelCpt++) { - if ((dw_ChannelMask >> - b_ChannelCpt) & - 1) { - dw_Status = - (dw_Status & - (0xFF - (1 << b_ChannelCpt))) | (dw_BitMask & (1 << b_ChannelCpt)); - } - } - - outl(dw_Status, devpriv->iobase + 112); - } - } - - /*******************************************/ - /* Read port 0 (first digital output port) */ - /*******************************************/ - - data[1] = inl(devpriv->iobase + 80); - - /******************************************/ - /* Read port 1 (first digital input port) */ - /******************************************/ - - data[1] = data[1] | (inl(devpriv->iobase + 64) << 8); - - /************************/ - /* Test if port 2 input */ - /************************/ - - if ((devpriv->ul_TTLPortConfiguration[0] & 0xFF) == 0) { - data[1] = - data[1] | (inl(devpriv->iobase + - 96) << 16); - } else { - data[1] = - data[1] | (inl(devpriv->iobase + - 112) << 16); - } - } else { - /************************/ - /* Config command error */ - /************************/ - - printk("Channel mask error\n"); - i_ReturnValue = -4; - } - } else { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return i_ReturnValue; -} - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3XXX_InsnReadTTLIO | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Read the status from selected channel | -+----------------------------------------------------------------------------+ -| Input Parameters : b_Channel = CR_CHAN(insn->chanspec) | -+----------------------------------------------------------------------------+ -| Output Parameters : data[0] : Selected TTL channel state | -+----------------------------------------------------------------------------+ -| Return Value : 0 : No error | -| -3 : Channel selection error | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3XXX_InsnReadTTLIO(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - unsigned char b_Channel = (unsigned char) CR_CHAN(insn->chanspec); - int i_ReturnValue = insn->n; - unsigned int *pls_ReadData = data; - - /************************/ - /* Test the buffer size */ - /************************/ - - if (insn->n >= 1) { - /***********************/ - /* Test if read port 0 */ - /***********************/ - - if (b_Channel < 8) { - /*******************************************/ - /* Read port 0 (first digital output port) */ - /*******************************************/ - - pls_ReadData[0] = inl(devpriv->iobase + 80); - pls_ReadData[0] = (pls_ReadData[0] >> b_Channel) & 1; - } else { - /***********************/ - /* Test if read port 1 */ - /***********************/ - - if ((b_Channel > 7) && (b_Channel < 16)) { - /******************************************/ - /* Read port 1 (first digital input port) */ - /******************************************/ - - pls_ReadData[0] = inl(devpriv->iobase + 64); - pls_ReadData[0] = - (pls_ReadData[0] >> (b_Channel - - 8)) & 1; - } else { - /***********************/ - /* Test if read port 2 */ - /***********************/ - - if ((b_Channel > 15) && (b_Channel < 24)) { - /************************/ - /* Test if port 2 input */ - /************************/ - - if ((devpriv->ul_TTLPortConfiguration[0] - & 0xFF) == 0) { - pls_ReadData[0] = - inl(devpriv->iobase + - 96); - pls_ReadData[0] = - (pls_ReadData[0] >> - (b_Channel - 16)) & 1; - } else { - pls_ReadData[0] = - inl(devpriv->iobase + - 112); - pls_ReadData[0] = - (pls_ReadData[0] >> - (b_Channel - 16)) & 1; - } - } else { - /***************************/ - /* Channel selection error */ - /***************************/ - - i_ReturnValue = -3; - printk("Channel %d selection error\n", - b_Channel); - } - } - } - } else { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return i_ReturnValue; -} - -/* -+----------------------------------------------------------------------------+ -| TTL OUTPUT FUNCTIONS | -+----------------------------------------------------------------------------+ -*/ - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3XXX_InsnWriteTTLIO | -| (struct comedi_device *dev, | -| struct comedi_subdevice *s, | -| struct comedi_insn *insn, | -| unsigned int *data) | -+----------------------------------------------------------------------------+ -| Task : Set the state from TTL output channel | -+----------------------------------------------------------------------------+ -| Input Parameters : b_Channel = CR_CHAN(insn->chanspec) | -| b_State = data [0] | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value : 0 : No error | -| -3 : Channel selection error | -| -101 : Data size error | -+----------------------------------------------------------------------------+ -*/ -static int i_APCI3XXX_InsnWriteTTLIO(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - int i_ReturnValue = insn->n; - unsigned char b_Channel = (unsigned char) CR_CHAN(insn->chanspec); - unsigned char b_State = 0; - unsigned int dw_Status = 0; - - /************************/ - /* Test the buffer size */ - /************************/ - - if (insn->n >= 1) { - b_State = (unsigned char) data[0]; - - /***********************/ - /* Test if read port 0 */ - /***********************/ - - if (b_Channel < 8) { - /*****************************************************************************/ - /* Read port 0 (first digital output port) and set/reset the selected channel */ - /*****************************************************************************/ - - dw_Status = inl(devpriv->iobase + 80); - dw_Status = - (dw_Status & (0xFF - - (1 << b_Channel))) | ((b_State & 1) << - b_Channel); - outl(dw_Status, devpriv->iobase + 80); - } else { - /***********************/ - /* Test if read port 2 */ - /***********************/ - - if ((b_Channel > 15) && (b_Channel < 24)) { - /*************************/ - /* Test if port 2 output */ - /*************************/ - - if ((devpriv->ul_TTLPortConfiguration[0] & 0xFF) - == 0xFF) { - /*****************************************************************************/ - /* Read port 2 (first digital output port) and set/reset the selected channel */ - /*****************************************************************************/ - - dw_Status = inl(devpriv->iobase + 112); - dw_Status = - (dw_Status & (0xFF - - (1 << (b_Channel - - 16)))) | - ((b_State & 1) << (b_Channel - - 16)); - outl(dw_Status, devpriv->iobase + 112); - } else { - /***************************/ - /* Channel selection error */ - /***************************/ - - i_ReturnValue = -3; - printk("Channel %d selection error\n", - b_Channel); - } - } else { - /***************************/ - /* Channel selection error */ - /***************************/ - - i_ReturnValue = -3; - printk("Channel %d selection error\n", - b_Channel); - } - } - } else { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return i_ReturnValue; -} - -static int apci3xxx_di_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - - data[1] = inl(devpriv->iobase + 32) & 0xf; - - return insn->n; -} - -static int apci3xxx_do_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - unsigned int mask = data[0]; - unsigned int bits = data[1]; - - s->state = inl(devpriv->iobase + 48) & 0xf; - if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); - - outl(s->state, devpriv->iobase + 48); - } - - data[1] = s->state; - - return insn->n; -} - -/* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI3XXX_Reset(struct comedi_device *dev) | +----------------------------------------------------------------------------+ -| Task :resets all the registers | -+----------------------------------------------------------------------------+ -| Input Parameters : struct comedi_device *dev | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value : - | -+----------------------------------------------------------------------------+ -*/ - -static int i_APCI3XXX_Reset(struct comedi_device *dev) -{ - struct addi_private *devpriv = dev->private; - unsigned char b_Cpt = 0; - - /*************************/ - /* Disable the interrupt */ - /*************************/ - - disable_irq(dev->irq); - - /****************************/ - /* Reset the interrupt flag */ - /****************************/ - - devpriv->b_EocEosInterrupt = 0; - - /***************************/ - /* Clear the start command */ - /***************************/ - - writel(0, devpriv->dw_AiBase + 8); - - /*****************************/ - /* Reset the interrupt flags */ - /*****************************/ - - writel(readl(devpriv->dw_AiBase + 16), devpriv->dw_AiBase + 16); - - /*****************/ - /* clear the EOS */ - /*****************/ - - readl(devpriv->dw_AiBase + 20); - - /******************/ - /* Clear the FIFO */ - /******************/ - - for (b_Cpt = 0; b_Cpt < 16; b_Cpt++) { - readl(devpriv->dw_AiBase + 28); - } - - /************************/ - /* Enable the interrupt */ - /************************/ - - enable_irq(dev->irq); - - return 0; -} diff --git a/drivers/staging/comedi/drivers/addi_apci_1032.c b/drivers/staging/comedi/drivers/addi_apci_1032.c index 3d4878facc26..8a93542faedc 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1032.c +++ b/drivers/staging/comedi/drivers/addi_apci_1032.c @@ -20,13 +20,6 @@ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA 02111-1307 USA - * - * You should also find the complete GPL in the COPYING file accompanying this - * source code. */ #include diff --git a/drivers/staging/comedi/drivers/addi_apci_1516.c b/drivers/staging/comedi/drivers/addi_apci_1516.c index ed01c56630bb..b626738bb73c 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1516.c +++ b/drivers/staging/comedi/drivers/addi_apci_1516.c @@ -20,13 +20,6 @@ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * You should also find the complete GPL in the COPYING file accompanying - * this source code. */ #include @@ -203,7 +196,6 @@ static void apci1516_detach(struct comedi_device *dev) { if (dev->iobase) apci1516_reset(dev); - comedi_spriv_free(dev, 2); comedi_pci_disable(dev); } diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c index 4c6a9b5a06ae..1f7bed9a3f7f 100644 --- a/drivers/staging/comedi/drivers/addi_apci_16xx.c +++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c @@ -20,13 +20,6 @@ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * You should also find the complete GPL in the COPYING file accompanying - * this source code. */ #include diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index b666637f61be..89ead8eb3c70 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -20,13 +20,6 @@ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * You should also find the complete GPL in the COPYING file accompanying - * this source code. */ #include @@ -354,7 +347,6 @@ static void apci2032_detach(struct comedi_device *dev) free_irq(dev->irq, dev); if (dev->read_subdev) kfree(dev->read_subdev->private); - comedi_spriv_free(dev, 1); comedi_pci_disable(dev); } diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c index 1cdc08d79792..ca1bd92ecb17 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2200.c +++ b/drivers/staging/comedi/drivers/addi_apci_2200.c @@ -20,13 +20,6 @@ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * You should also find the complete GPL in the COPYING file accompanying - * this source code. */ #include @@ -130,7 +123,6 @@ static void apci2200_detach(struct comedi_device *dev) { if (dev->iobase) apci2200_reset(dev); - comedi_spriv_free(dev, 2); comedi_pci_disable(dev); } diff --git a/drivers/staging/comedi/drivers/addi_apci_3120.c b/drivers/staging/comedi/drivers/addi_apci_3120.c index 317a26d97c2e..61452848510f 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3120.c +++ b/drivers/staging/comedi/drivers/addi_apci_3120.c @@ -103,8 +103,6 @@ static int apci3120_auto_attach(struct comedi_device *dev, if (devpriv->ul_DmaBufferVirtual[i]) { devpriv->ui_DmaBufferPages[i] = pages; devpriv->ui_DmaBufferSize[i] = PAGE_SIZE * pages; - devpriv->ui_DmaBufferSamples[i] = - devpriv->ui_DmaBufferSize[i] >> 1; devpriv->ul_DmaBufferHw[i] = virt_to_bus((void *)devpriv-> ul_DmaBufferVirtual[i]); @@ -138,9 +136,6 @@ static int apci3120_auto_attach(struct comedi_device *dev, s->len_chanlist = this_board->i_AiChannelList; s->range_table = &range_apci3120_ai; - /* Set the initialisation flag */ - devpriv->b_AiInitialisation = 1; - s->insn_config = i_APCI3120_InsnConfigAnalogInput; s->insn_read = i_APCI3120_InsnReadAnalogInput; s->do_cmdtest = i_APCI3120_CommandTestAnalogInput; diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index a0cf6ecdef0e..f9b63689a12a 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -20,13 +20,6 @@ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * You should also find the complete GPL in the COPYING file accompanying - * this source code. */ #include diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c index ec4d6ca6863f..5b37cbf9228e 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c +++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c @@ -1,14 +1,57 @@ +/* + * addi_apci_3xxx.c + * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. + * Project manager: S. Weber + * + * ADDI-DATA GmbH + * Dieselstrasse 3 + * D-77833 Ottersweier + * Tel: +19(0)7223/9493-0 + * Fax: +49(0)7223/9493-92 + * http://www.addi-data.com + * info@addi-data.com + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + #include +#include #include "../comedidev.h" + #include "comedi_fc.h" -#include "amcc_s5933.h" -#include "addi-data/addi_common.h" +#define CONV_UNIT_NS (1 << 0) +#define CONV_UNIT_US (1 << 1) +#define CONV_UNIT_MS (1 << 2) -#include "addi-data/addi_eeprom.c" -#include "addi-data/hwdrv_apci3xxx.c" -#include "addi-data/addi_common.c" +static const struct comedi_lrange apci3xxx_ai_range = { + 8, { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2), + BIP_RANGE(1), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2), + UNI_RANGE(1) + } +}; + +static const struct comedi_lrange apci3xxx_ao_range = { + 2, { + BIP_RANGE(10), + UNI_RANGE(10) + } +}; enum apci3xxx_boardid { BOARD_APCI3000_16, @@ -38,651 +81,853 @@ enum apci3xxx_boardid { BOARD_APCI3500, }; -static const struct addi_board apci3xxx_boardtypes[] = { +struct apci3xxx_boardinfo { + const char *name; + int ai_subdev_flags; + int ai_n_chan; + unsigned int ai_maxdata; + unsigned char ai_conv_units; + unsigned int ai_min_acq_ns; + unsigned int has_ao:1; + unsigned int has_dig_in:1; + unsigned int has_dig_out:1; + unsigned int has_ttl_io:1; +}; + +static const struct apci3xxx_boardinfo apci3xxx_boardtypes[] = { [BOARD_APCI3000_16] = { - .pc_DriverName = "apci3000-16", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 16, - .i_NbrAiChannelDiff = 8, - .i_AiChannelList = 16, - .i_AiMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 10000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3000-16", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 16, + .ai_maxdata = 0x0fff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 10000, + .has_ttl_io = 1, }, [BOARD_APCI3000_8] = { - .pc_DriverName = "apci3000-8", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 8, - .i_NbrAiChannelDiff = 4, - .i_AiChannelList = 8, - .i_AiMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 10000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3000-8", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 8, + .ai_maxdata = 0x0fff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 10000, + .has_ttl_io = 1, }, [BOARD_APCI3000_4] = { - .pc_DriverName = "apci3000-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 4, - .i_NbrAiChannelDiff = 2, - .i_AiChannelList = 4, - .i_AiMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 10000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3000-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 4, + .ai_maxdata = 0x0fff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 10000, + .has_ttl_io = 1, }, [BOARD_APCI3006_16] = { - .pc_DriverName = "apci3006-16", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 16, - .i_NbrAiChannelDiff = 8, - .i_AiChannelList = 16, - .i_AiMaxdata = 65535, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 10000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3006-16", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 16, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 10000, + .has_ttl_io = 1, }, [BOARD_APCI3006_8] = { - .pc_DriverName = "apci3006-8", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 8, - .i_NbrAiChannelDiff = 4, - .i_AiChannelList = 8, - .i_AiMaxdata = 65535, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 10000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3006-8", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 8, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 10000, + .has_ttl_io = 1, }, [BOARD_APCI3006_4] = { - .pc_DriverName = "apci3006-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 4, - .i_NbrAiChannelDiff = 2, - .i_AiChannelList = 4, - .i_AiMaxdata = 65535, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 10000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3006-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 4, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 10000, + .has_ttl_io = 1, }, [BOARD_APCI3010_16] = { - .pc_DriverName = "apci3010-16", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 16, - .i_NbrAiChannelDiff = 8, - .i_AiChannelList = 16, - .i_AiMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3010-16", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 16, + .ai_maxdata = 0x0fff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_dig_in = 1, + .has_dig_out = 1, + .has_ttl_io = 1, }, [BOARD_APCI3010_8] = { - .pc_DriverName = "apci3010-8", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 8, - .i_NbrAiChannelDiff = 4, - .i_AiChannelList = 8, - .i_AiMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3010-8", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 8, + .ai_maxdata = 0x0fff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_dig_in = 1, + .has_dig_out = 1, + .has_ttl_io = 1, }, [BOARD_APCI3010_4] = { - .pc_DriverName = "apci3010-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 4, - .i_NbrAiChannelDiff = 2, - .i_AiChannelList = 4, - .i_AiMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3010-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 4, + .ai_maxdata = 0x0fff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_dig_in = 1, + .has_dig_out = 1, + .has_ttl_io = 1, }, [BOARD_APCI3016_16] = { - .pc_DriverName = "apci3016-16", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 16, - .i_NbrAiChannelDiff = 8, - .i_AiChannelList = 16, - .i_AiMaxdata = 65535, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3016-16", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 16, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_dig_in = 1, + .has_dig_out = 1, + .has_ttl_io = 1, }, [BOARD_APCI3016_8] = { - .pc_DriverName = "apci3016-8", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 8, - .i_NbrAiChannelDiff = 4, - .i_AiChannelList = 8, - .i_AiMaxdata = 65535, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3016-8", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 8, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_dig_in = 1, + .has_dig_out = 1, + .has_ttl_io = 1, }, [BOARD_APCI3016_4] = { - .pc_DriverName = "apci3016-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 4, - .i_NbrAiChannelDiff = 2, - .i_AiChannelList = 4, - .i_AiMaxdata = 65535, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3016-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 4, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_dig_in = 1, + .has_dig_out = 1, + .has_ttl_io = 1, }, [BOARD_APCI3100_16_4] = { - .pc_DriverName = "apci3100-16-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 16, - .i_NbrAiChannelDiff = 8, - .i_AiChannelList = 16, - .i_NbrAoChannel = 4, - .i_AiMaxdata = 4095, - .i_AoMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .pr_AoRangelist = &range_apci3XXX_ao, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 10000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3100-16-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 16, + .ai_maxdata = 0x0fff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 10000, + .has_ao = 1, + .has_ttl_io = 1, }, [BOARD_APCI3100_8_4] = { - .pc_DriverName = "apci3100-8-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 8, - .i_NbrAiChannelDiff = 4, - .i_AiChannelList = 8, - .i_NbrAoChannel = 4, - .i_AiMaxdata = 4095, - .i_AoMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .pr_AoRangelist = &range_apci3XXX_ao, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 10000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3100-8-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 8, + .ai_maxdata = 0x0fff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 10000, + .has_ao = 1, + .has_ttl_io = 1, }, [BOARD_APCI3106_16_4] = { - .pc_DriverName = "apci3106-16-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 16, - .i_NbrAiChannelDiff = 8, - .i_AiChannelList = 16, - .i_NbrAoChannel = 4, - .i_AiMaxdata = 65535, - .i_AoMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .pr_AoRangelist = &range_apci3XXX_ao, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 10000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3106-16-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 16, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 10000, + .has_ao = 1, + .has_ttl_io = 1, }, [BOARD_APCI3106_8_4] = { - .pc_DriverName = "apci3106-8-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 8, - .i_NbrAiChannelDiff = 4, - .i_AiChannelList = 8, - .i_NbrAoChannel = 4, - .i_AiMaxdata = 65535, - .i_AoMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .pr_AoRangelist = &range_apci3XXX_ao, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 10000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3106-8-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 8, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 10000, + .has_ao = 1, + .has_ttl_io = 1, }, [BOARD_APCI3110_16_4] = { - .pc_DriverName = "apci3110-16-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 16, - .i_NbrAiChannelDiff = 8, - .i_AiChannelList = 16, - .i_NbrAoChannel = 4, - .i_AiMaxdata = 4095, - .i_AoMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .pr_AoRangelist = &range_apci3XXX_ao, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3110-16-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 16, + .ai_maxdata = 0x0fff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_ao = 1, + .has_dig_in = 1, + .has_dig_out = 1, + .has_ttl_io = 1, }, [BOARD_APCI3110_8_4] = { - .pc_DriverName = "apci3110-8-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 8, - .i_NbrAiChannelDiff = 4, - .i_AiChannelList = 8, - .i_NbrAoChannel = 4, - .i_AiMaxdata = 4095, - .i_AoMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .pr_AoRangelist = &range_apci3XXX_ao, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3110-8-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 8, + .ai_maxdata = 0x0fff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_ao = 1, + .has_dig_in = 1, + .has_dig_out = 1, + .has_ttl_io = 1, }, [BOARD_APCI3116_16_4] = { - .pc_DriverName = "apci3116-16-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 16, - .i_NbrAiChannelDiff = 8, - .i_AiChannelList = 16, - .i_NbrAoChannel = 4, - .i_AiMaxdata = 65535, - .i_AoMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .pr_AoRangelist = &range_apci3XXX_ao, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3116-16-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 16, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_ao = 1, + .has_dig_in = 1, + .has_dig_out = 1, + .has_ttl_io = 1, }, [BOARD_APCI3116_8_4] = { - .pc_DriverName = "apci3116-8-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannel = 8, - .i_NbrAiChannelDiff = 4, - .i_AiChannelList = 8, - .i_NbrAoChannel = 4, - .i_AiMaxdata = 65535, - .i_AoMaxdata = 4095, - .pr_AiRangelist = &range_apci3XXX_ai, - .pr_AoRangelist = &range_apci3XXX_ao, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .i_NbrTTLChannel = 24, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3116-8-4", + .ai_subdev_flags = SDF_COMMON | SDF_GROUND | SDF_DIFF, + .ai_n_chan = 8, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_ao = 1, + .has_dig_in = 1, + .has_dig_out = 1, + .has_ttl_io = 1, }, [BOARD_APCI3003] = { - .pc_DriverName = "apci3003", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannelDiff = 4, - .i_AiChannelList = 4, - .i_AiMaxdata = 65535, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .b_AvailableConvertUnit = 7, - .ui_MinAcquisitiontimeNs = 2500, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, + .name = "apci3003", + .ai_subdev_flags = SDF_DIFF, + .ai_n_chan = 4, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US | + CONV_UNIT_NS, + .ai_min_acq_ns = 2500, + .has_dig_in = 1, + .has_dig_out = 1, }, [BOARD_APCI3002_16] = { - .pc_DriverName = "apci3002-16", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannelDiff = 16, - .i_AiChannelList = 16, - .i_AiMaxdata = 65535, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, + .name = "apci3002-16", + .ai_subdev_flags = SDF_DIFF, + .ai_n_chan = 16, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_dig_in = 1, + .has_dig_out = 1, }, [BOARD_APCI3002_8] = { - .pc_DriverName = "apci3002-8", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannelDiff = 8, - .i_AiChannelList = 8, - .i_AiMaxdata = 65535, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, + .name = "apci3002-8", + .ai_subdev_flags = SDF_DIFF, + .ai_n_chan = 8, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_dig_in = 1, + .has_dig_out = 1, }, [BOARD_APCI3002_4] = { - .pc_DriverName = "apci3002-4", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAiChannelDiff = 4, - .i_AiChannelList = 4, - .i_AiMaxdata = 65535, - .pr_AiRangelist = &range_apci3XXX_ai, - .i_NbrDiChannel = 4, - .i_NbrDoChannel = 4, - .i_DoMaxdata = 1, - .b_AvailableConvertUnit = 6, - .ui_MinAcquisitiontimeNs = 5000, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ai_config = i_APCI3XXX_InsnConfigAnalogInput, - .ai_read = i_APCI3XXX_InsnReadAnalogInput, - .di_bits = apci3xxx_di_insn_bits, - .do_bits = apci3xxx_do_insn_bits, + .name = "apci3002-4", + .ai_subdev_flags = SDF_DIFF, + .ai_n_chan = 4, + .ai_maxdata = 0xffff, + .ai_conv_units = CONV_UNIT_MS | CONV_UNIT_US, + .ai_min_acq_ns = 5000, + .has_dig_in = 1, + .has_dig_out = 1, }, [BOARD_APCI3500] = { - .pc_DriverName = "apci3500", - .i_IorangeBase1 = 256, - .i_PCIEeprom = ADDIDATA_NO_EEPROM, - .pc_EepromChip = ADDIDATA_9054, - .i_NbrAoChannel = 4, - .i_AoMaxdata = 4095, - .pr_AoRangelist = &range_apci3XXX_ao, - .i_NbrTTLChannel = 24, - .interrupt = v_APCI3XXX_Interrupt, - .reset = i_APCI3XXX_Reset, - .ao_write = i_APCI3XXX_InsnWriteAnalogOutput, - .ttl_config = i_APCI3XXX_InsnConfigInitTTLIO, - .ttl_bits = i_APCI3XXX_InsnBitsTTLIO, - .ttl_read = i_APCI3XXX_InsnReadTTLIO, - .ttl_write = i_APCI3XXX_InsnWriteTTLIO, + .name = "apci3500", + .has_ao = 1, + .has_ttl_io = 1, }, }; +struct apci3xxx_private { + void __iomem *mmio; + unsigned int ai_timer; + unsigned char ai_time_base; +}; + +static irqreturn_t apci3xxx_irq_handler(int irq, void *d) +{ + struct comedi_device *dev = d; + struct apci3xxx_private *devpriv = dev->private; + struct comedi_subdevice *s = dev->read_subdev; + unsigned int status; + unsigned int val; + + /* Test if interrupt occur */ + status = readl(devpriv->mmio + 16); + if ((status & 0x2) == 0x2) { + /* Reset the interrupt */ + writel(status, devpriv->mmio + 16); + + val = readl(devpriv->mmio + 28); + comedi_buf_put(s->async, val); + + s->async->events |= COMEDI_CB_EOA; + comedi_event(dev, s); + + return IRQ_HANDLED; + } + return IRQ_NONE; +} + +static int apci3xxx_ai_started(struct comedi_device *dev) +{ + struct apci3xxx_private *devpriv = dev->private; + + if ((readl(devpriv->mmio + 8) & 0x80000) == 0x80000) + return 1; + else + return 0; + +} + +static int apci3xxx_ai_setup(struct comedi_device *dev, unsigned int chanspec) +{ + struct apci3xxx_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(chanspec); + unsigned int range = CR_RANGE(chanspec); + unsigned int aref = CR_AREF(chanspec); + unsigned int delay_mode; + unsigned int val; + + if (apci3xxx_ai_started(dev)) + return -EBUSY; + + /* Clear the FIFO */ + writel(0x10000, devpriv->mmio + 12); + + /* Get and save the delay mode */ + delay_mode = readl(devpriv->mmio + 4); + delay_mode &= 0xfffffef0; + + /* Channel configuration selection */ + writel(delay_mode, devpriv->mmio + 4); + + /* Make the configuration */ + val = (range & 3) | ((range >> 2) << 6) | + ((aref == AREF_DIFF) << 7); + writel(val, devpriv->mmio + 0); + + /* Channel selection */ + writel(delay_mode | 0x100, devpriv->mmio + 4); + writel(chan, devpriv->mmio + 0); + + /* Restore delay mode */ + writel(delay_mode, devpriv->mmio + 4); + + /* Set the number of sequence to 1 */ + writel(1, devpriv->mmio + 48); + + return 0; +} + +static int apci3xxx_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct apci3xxx_private *devpriv = dev->private; + unsigned int val; + int ret; + int i; + + ret = apci3xxx_ai_setup(dev, insn->chanspec); + if (ret) + return ret; + + for (i = 0; i < insn->n; i++) { + /* Start the conversion */ + writel(0x80000, devpriv->mmio + 8); + + /* Wait the EOS */ + do { + val = readl(devpriv->mmio + 20); + val &= 0x1; + } while (!val); + + /* Read the analog value */ + data[i] = readl(devpriv->mmio + 28); + } + + return insn->n; +} + +static int apci3xxx_ai_ns_to_timer(struct comedi_device *dev, + unsigned int *ns, int round_mode) +{ + const struct apci3xxx_boardinfo *board = comedi_board(dev); + struct apci3xxx_private *devpriv = dev->private; + unsigned int base; + unsigned int timer; + int time_base; + + /* time_base: 0 = ns, 1 = us, 2 = ms */ + for (time_base = 0; time_base < 3; time_base++) { + /* skip unsupported time bases */ + if (!(board->ai_conv_units & (1 << time_base))) + continue; + + switch (time_base) { + case 0: + base = 1; + break; + case 1: + base = 1000; + break; + case 2: + base = 1000000; + break; + } + + switch (round_mode) { + case TRIG_ROUND_NEAREST: + default: + timer = (*ns + base / 2) / base; + break; + case TRIG_ROUND_DOWN: + timer = *ns / base; + break; + case TRIG_ROUND_UP: + timer = (*ns + base - 1) / base; + break; + } + + if (timer < 0x10000) { + devpriv->ai_time_base = time_base; + devpriv->ai_timer = timer; + *ns = timer * time_base; + return 0; + } + } + return -EINVAL; +} + +static int apci3xxx_ai_cmdtest(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_cmd *cmd) +{ + const struct apci3xxx_boardinfo *board = comedi_board(dev); + int err = 0; + unsigned int tmp; + + /* Step 1 : check if triggers are trivially valid */ + + err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW); + err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW); + err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER); + err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); + err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); + + if (err) + return 1; + + /* Step 2a : make sure trigger sources are unique */ + + err |= cfc_check_trigger_is_unique(cmd->stop_src); + + /* Step 2b : and mutually compatible */ + + if (err) + return 2; + + /* Step 3: check if arguments are trivially valid */ + + err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); + err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0); + err |= cfc_check_trigger_arg_min(&cmd->convert_arg, + board->ai_min_acq_ns); + err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); + + if (cmd->stop_src == TRIG_COUNT) + err |= cfc_check_trigger_arg_min(&cmd->stop_arg, 1); + else /* TRIG_NONE */ + err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0); + + if (err) + return 3; + + /* step 4: fix up any arguments */ + + /* + * FIXME: The hardware supports multiple scan modes but the original + * addi-data driver only supported reading a single channel with + * interrupts. Need a proper datasheet to fix this. + * + * The following scan modes are supported by the hardware: + * 1) Single software scan + * 2) Single hardware triggered scan + * 3) Continuous software scan + * 4) Continuous software scan with timer delay + * 5) Continuous hardware triggered scan + * 6) Continuous hardware triggered scan with timer delay + * + * For now, limit the chanlist to a single channel. + */ + if (cmd->chanlist_len > 1) { + cmd->chanlist_len = 1; + err |= -EINVAL; + } + + tmp = cmd->convert_arg; + err |= apci3xxx_ai_ns_to_timer(dev, &cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->convert_arg) + err |= -EINVAL; + + if (err) + return 4; + + return 0; +} + +static int apci3xxx_ai_cmd(struct comedi_device *dev, + struct comedi_subdevice *s) +{ + struct apci3xxx_private *devpriv = dev->private; + struct comedi_cmd *cmd = &s->async->cmd; + int ret; + + ret = apci3xxx_ai_setup(dev, cmd->chanlist[0]); + if (ret) + return ret; + + /* Set the convert timing unit */ + writel(devpriv->ai_time_base, devpriv->mmio + 36); + + /* Set the convert timing */ + writel(devpriv->ai_timer, devpriv->mmio + 32); + + /* Start the conversion */ + writel(0x180000, devpriv->mmio + 8); + + return 0; +} + +static int apci3xxx_ai_cancel(struct comedi_device *dev, + struct comedi_subdevice *s) +{ + return 0; +} + +static int apci3xxx_ao_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct apci3xxx_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int range = CR_RANGE(insn->chanspec); + unsigned int status; + int i; + + for (i = 0; i < insn->n; i++) { + /* Set the range selection */ + writel(range, devpriv->mmio + 96); + + /* Write the analog value to the selected channel */ + writel((data[i] << 8) | chan, devpriv->mmio + 100); + + /* Wait the end of transfer */ + do { + status = readl(devpriv->mmio + 96); + } while ((status & 0x100) != 0x100); + } + + return insn->n; +} + +static int apci3xxx_di_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + data[1] = inl(dev->iobase + 32) & 0xf; + + return insn->n; +} + +static int apci3xxx_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int mask = data[0]; + unsigned int bits = data[1]; + + s->state = inl(dev->iobase + 48) & 0xf; + if (mask) { + s->state &= ~mask; + s->state |= (bits & mask); + + outl(s->state, dev->iobase + 48); + } + + data[1] = s->state; + + return insn->n; +} + +static int apci3xxx_dio_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int mask = 1 << chan; + unsigned int bits; + + /* + * Port 0 (channels 0-7) are always inputs + * Port 1 (channels 8-15) are always outputs + * Port 2 (channels 16-23) are programmable i/o + * + * Changing any channel in port 2 changes the entire port. + */ + if (mask & 0xff0000) + bits = 0xff0000; + else + bits = 0; + + switch (data[0]) { + case INSN_CONFIG_DIO_INPUT: + s->io_bits &= ~bits; + break; + case INSN_CONFIG_DIO_OUTPUT: + s->io_bits |= bits; + break; + case INSN_CONFIG_DIO_QUERY: + data[1] = (s->io_bits & bits) ? COMEDI_OUTPUT : COMEDI_INPUT; + return insn->n; + default: + return -EINVAL; + } + + /* update port 2 configuration */ + if (bits) + outl((s->io_bits >> 24) & 0xff, dev->iobase + 224); + + return insn->n; +} + +static int apci3xxx_dio_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int mask = data[0]; + unsigned int bits = data[1]; + unsigned int val; + + /* only update output channels */ + mask &= s->io_bits; + if (mask) { + s->state &= ~mask; + s->state |= (bits & mask); + + if (mask & 0xff) + outl(s->state & 0xff, dev->iobase + 80); + if (mask & 0xff0000) + outl((s->state >> 16) & 0xff, dev->iobase + 112); + } + + val = inl(dev->iobase + 80); + val |= (inl(dev->iobase + 64) << 8); + if (s->io_bits & 0xff0000) + val |= (inl(dev->iobase + 112) << 16); + else + val |= (inl(dev->iobase + 96) << 16); + + data[1] = val; + + return insn->n; +} + +static int apci3xxx_reset(struct comedi_device *dev) +{ + struct apci3xxx_private *devpriv = dev->private; + unsigned int val; + int i; + + /* Disable the interrupt */ + disable_irq(dev->irq); + + /* Clear the start command */ + writel(0, devpriv->mmio + 8); + + /* Reset the interrupt flags */ + val = readl(devpriv->mmio + 16); + writel(val, devpriv->mmio + 16); + + /* clear the EOS */ + readl(devpriv->mmio + 20); + + /* Clear the FIFO */ + for (i = 0; i < 16; i++) + val = readl(devpriv->mmio + 28); + + /* Enable the interrupt */ + enable_irq(dev->irq); + + return 0; +} + static int apci3xxx_auto_attach(struct comedi_device *dev, unsigned long context) { - const struct addi_board *board = NULL; + struct pci_dev *pcidev = comedi_to_pci_dev(dev); + const struct apci3xxx_boardinfo *board = NULL; + struct apci3xxx_private *devpriv; + struct comedi_subdevice *s; + int n_subdevices; + int subdev; + int ret; if (context < ARRAY_SIZE(apci3xxx_boardtypes)) board = &apci3xxx_boardtypes[context]; if (!board) return -ENODEV; dev->board_ptr = board; + dev->board_name = board->name; - return addi_auto_attach(dev, context); + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; + + ret = comedi_pci_enable(dev); + if (ret) + return ret; + + dev->iobase = pci_resource_start(pcidev, 2); + devpriv->mmio = pci_ioremap_bar(pcidev, 3); + + if (pcidev->irq > 0) { + ret = request_irq(pcidev->irq, apci3xxx_irq_handler, + IRQF_SHARED, dev->board_name, dev); + if (ret == 0) + dev->irq = pcidev->irq; + } + + n_subdevices = (board->ai_n_chan ? 0 : 1) + board->has_ao + + board->has_dig_in + board->has_dig_out + + board->has_ttl_io; + ret = comedi_alloc_subdevices(dev, n_subdevices); + if (ret) + return ret; + + subdev = 0; + + /* Analog Input subdevice */ + if (board->ai_n_chan) { + s = &dev->subdevices[subdev]; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | board->ai_subdev_flags; + s->n_chan = board->ai_n_chan; + s->maxdata = board->ai_maxdata; + s->len_chanlist = s->n_chan; + s->range_table = &apci3xxx_ai_range; + s->insn_read = apci3xxx_ai_insn_read; + if (dev->irq) { + dev->read_subdev = s; + s->subdev_flags |= SDF_CMD_READ; + s->do_cmdtest = apci3xxx_ai_cmdtest; + s->do_cmd = apci3xxx_ai_cmd; + s->cancel = apci3xxx_ai_cancel; + } + + subdev++; + } + + /* Analog Output subdevice */ + if (board->has_ao) { + s = &dev->subdevices[subdev]; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = 4; + s->maxdata = 0x0fff; + s->range_table = &apci3xxx_ao_range; + s->insn_write = apci3xxx_ao_insn_write; + + subdev++; + } + + /* Digital Input subdevice */ + if (board->has_dig_in) { + s = &dev->subdevices[subdev]; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 4; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = apci3xxx_di_insn_bits; + + subdev++; + } + + /* Digital Output subdevice */ + if (board->has_dig_out) { + s = &dev->subdevices[subdev]; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 4; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = apci3xxx_do_insn_bits; + + subdev++; + } + + /* TTL Digital I/O subdevice */ + if (board->has_ttl_io) { + s = &dev->subdevices[subdev]; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; + s->n_chan = 24; + s->maxdata = 1; + s->io_bits = 0xff; /* channels 0-7 are always outputs */ + s->range_table = &range_digital; + s->insn_config = apci3xxx_dio_insn_config; + s->insn_bits = apci3xxx_dio_insn_bits; + + subdev++; + } + + apci3xxx_reset(dev); + return 0; +} + +static void apci3xxx_detach(struct comedi_device *dev) +{ + struct apci3xxx_private *devpriv = dev->private; + + if (devpriv) { + if (dev->iobase) + apci3xxx_reset(dev); + if (dev->irq) + free_irq(dev->irq, dev); + if (devpriv->mmio) + iounmap(devpriv->mmio); + } + comedi_pci_disable(dev); } static struct comedi_driver apci3xxx_driver = { .driver_name = "addi_apci_3xxx", .module = THIS_MODULE, .auto_attach = apci3xxx_auto_attach, - .detach = i_ADDI_Detach, + .detach = apci3xxx_detach, }; static int apci3xxx_pci_probe(struct pci_dev *dev, diff --git a/drivers/staging/comedi/drivers/addi_watchdog.c b/drivers/staging/comedi/drivers/addi_watchdog.c index 1666b5f510d3..7b21acc93929 100644 --- a/drivers/staging/comedi/drivers/addi_watchdog.c +++ b/drivers/staging/comedi/drivers/addi_watchdog.c @@ -16,10 +16,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "../comedidev.h" @@ -130,14 +126,12 @@ int addi_watchdog_init(struct comedi_subdevice *s, unsigned long iobase) { struct addi_watchdog_private *spriv; - spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); + spriv = comedi_alloc_spriv(s, sizeof(*spriv)); if (!spriv) return -ENOMEM; spriv->iobase = iobase; - s->private = spriv; - s->type = COMEDI_SUBD_TIMER; s->subdev_flags = SDF_WRITEABLE; s->n_chan = 1; diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c b/drivers/staging/comedi/drivers/adl_pci6208.c index 8a438ff1bd45..b5e4e53f737f 100644 --- a/drivers/staging/comedi/drivers/adl_pci6208.c +++ b/drivers/staging/comedi/drivers/adl_pci6208.c @@ -20,10 +20,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Driver: adl_pci6208 diff --git a/drivers/staging/comedi/drivers/adl_pci7x3x.c b/drivers/staging/comedi/drivers/adl_pci7x3x.c index e3960745f506..0d9243a5f495 100644 --- a/drivers/staging/comedi/drivers/adl_pci7x3x.c +++ b/drivers/staging/comedi/drivers/adl_pci7x3x.c @@ -19,10 +19,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c b/drivers/staging/comedi/drivers/adl_pci8164.c index b3ec60afe3a0..0b591b0b5501 100644 --- a/drivers/staging/comedi/drivers/adl_pci8164.c +++ b/drivers/staging/comedi/drivers/adl_pci8164.c @@ -13,10 +13,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c index 6247fdcedcbf..af51c7460048 100644 --- a/drivers/staging/comedi/drivers/adl_pci9111.c +++ b/drivers/staging/comedi/drivers/adl_pci9111.c @@ -17,10 +17,6 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* diff --git a/drivers/staging/comedi/drivers/adq12b.c b/drivers/staging/comedi/drivers/adq12b.c index 71142e36e7fb..d187a7bf0a55 100644 --- a/drivers/staging/comedi/drivers/adq12b.c +++ b/drivers/staging/comedi/drivers/adq12b.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: adq12b diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c b/drivers/staging/comedi/drivers/adv_pci1723.c index ccc114d6c08b..8430a27ec1b5 100644 --- a/drivers/staging/comedi/drivers/adv_pci1723.c +++ b/drivers/staging/comedi/drivers/adv_pci1723.c @@ -1,4 +1,4 @@ -/******************************************************************************* +/* comedi/drivers/pci1723.c COMEDI - Linux Control and Measurement Device Interface @@ -13,12 +13,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*******************************************************************************/ +*/ /* Driver: adv_pci1723 Description: Advantech PCI-1723 diff --git a/drivers/staging/comedi/drivers/adv_pci1724.c b/drivers/staging/comedi/drivers/adv_pci1724.c index e60f12578d44..da7462e01faa 100644 --- a/drivers/staging/comedi/drivers/adv_pci1724.c +++ b/drivers/staging/comedi/drivers/adv_pci1724.c @@ -17,12 +17,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************/ +*/ /* diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c b/drivers/staging/comedi/drivers/adv_pci_dio.c index f70c67471c13..8e6ec75bd294 100644 --- a/drivers/staging/comedi/drivers/adv_pci_dio.c +++ b/drivers/staging/comedi/drivers/adv_pci_dio.c @@ -1173,19 +1173,11 @@ static int pci_dio_auto_attach(struct comedi_device *dev, static void pci_dio_detach(struct comedi_device *dev) { struct pci_dio_private *devpriv = dev->private; - struct comedi_subdevice *s; - int i; if (devpriv) { if (devpriv->valid) pci_dio_reset(dev); } - for (i = 0; i < dev->n_subdevices; i++) { - s = &dev->subdevices[i]; - if (s->type == COMEDI_SUBD_DIO) - comedi_spriv_free(dev, i); - s->private = NULL; /* some private data is static */ - } comedi_pci_disable(dev); } diff --git a/drivers/staging/comedi/drivers/aio_aio12_8.c b/drivers/staging/comedi/drivers/aio_aio12_8.c index e2dc08a058bc..279dfe8951f7 100644 --- a/drivers/staging/comedi/drivers/aio_aio12_8.c +++ b/drivers/staging/comedi/drivers/aio_aio12_8.c @@ -14,10 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -259,17 +255,11 @@ static int aio_aio12_8_attach(struct comedi_device *dev, return 0; } -static void aio_aio12_8_detach(struct comedi_device *dev) -{ - comedi_spriv_free(dev, 2); - comedi_legacy_detach(dev); -} - static struct comedi_driver aio_aio12_8_driver = { .driver_name = "aio_aio12_8", .module = THIS_MODULE, .attach = aio_aio12_8_attach, - .detach = aio_aio12_8_detach, + .detach = comedi_legacy_detach, .board_name = &board_types[0].name, .num_names = ARRAY_SIZE(board_types), .offset = sizeof(struct aio12_8_boardtype), diff --git a/drivers/staging/comedi/drivers/aio_iiro_16.c b/drivers/staging/comedi/drivers/aio_iiro_16.c index 126854c05093..029834d0ff1f 100644 --- a/drivers/staging/comedi/drivers/aio_iiro_16.c +++ b/drivers/staging/comedi/drivers/aio_iiro_16.c @@ -14,10 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c b/drivers/staging/comedi/drivers/amplc_dio200.c index 297750bef0f7..e2478105ac1a 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200.c +++ b/drivers/staging/comedi/drivers/amplc_dio200.c @@ -17,11 +17,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* * Driver: amplc_dio200 diff --git a/drivers/staging/comedi/drivers/amplc_dio200.h b/drivers/staging/comedi/drivers/amplc_dio200.h index cf2e7261740e..43160b9944bb 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200.h +++ b/drivers/staging/comedi/drivers/amplc_dio200.h @@ -18,11 +18,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef AMPLC_DIO200_H_INCLUDED diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c index 3403e5ccfa93..649fc69724fb 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200_common.c +++ b/drivers/staging/comedi/drivers/amplc_dio200_common.c @@ -17,11 +17,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #include @@ -561,7 +556,7 @@ dio200_subdev_intr_init(struct comedi_device *dev, struct comedi_subdevice *s, const struct dio200_layout *layout = dio200_dev_layout(dev); struct dio200_subdev_intr *subpriv; - subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL); + subpriv = comedi_alloc_spriv(s, sizeof(*subpriv)); if (!subpriv) return -ENOMEM; @@ -573,7 +568,6 @@ dio200_subdev_intr_init(struct comedi_device *dev, struct comedi_subdevice *s, /* Disable interrupt sources. */ dio200_write8(dev, subpriv->ofs, 0); - s->private = subpriv; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE | SDF_CMD_READ; if (layout->has_int_sce) { @@ -888,11 +882,10 @@ dio200_subdev_8254_init(struct comedi_device *dev, struct comedi_subdevice *s, struct dio200_subdev_8254 *subpriv; unsigned int chan; - subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL); + subpriv = comedi_alloc_spriv(s, sizeof(*subpriv)); if (!subpriv) return -ENOMEM; - s->private = subpriv; s->type = COMEDI_SUBD_COUNTER; s->subdev_flags = SDF_WRITABLE | SDF_READABLE; s->n_chan = 3; @@ -1024,11 +1017,12 @@ static int dio200_subdev_8255_init(struct comedi_device *dev, { struct dio200_subdev_8255 *subpriv; - subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL); + subpriv = comedi_alloc_spriv(s, sizeof(*subpriv)); if (!subpriv) return -ENOMEM; + subpriv->ofs = offset; - s->private = subpriv; + s->type = COMEDI_SUBD_DIO; s->subdev_flags = SDF_READABLE | SDF_WRITABLE; s->n_chan = 24; @@ -1230,28 +1224,11 @@ void amplc_dio200_common_detach(struct comedi_device *dev) { const struct dio200_board *thisboard = comedi_board(dev); struct dio200_private *devpriv = dev->private; - const struct dio200_layout *layout; - unsigned n; if (!thisboard || !devpriv) return; if (dev->irq) free_irq(dev->irq, dev); - if (dev->subdevices) { - layout = dio200_board_layout(thisboard); - for (n = 0; n < dev->n_subdevices; n++) { - switch (layout->sdtype[n]) { - case sd_8254: - case sd_8255: - case sd_intr: - comedi_spriv_free(dev, n); - break; - case sd_timer: - default: - break; - } - } - } } EXPORT_SYMBOL_GPL(amplc_dio200_common_detach); diff --git a/drivers/staging/comedi/drivers/amplc_dio200_pci.c b/drivers/staging/comedi/drivers/amplc_dio200_pci.c index 4be44e877373..d7d9f5cc3ab4 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200_pci.c +++ b/drivers/staging/comedi/drivers/amplc_dio200_pci.c @@ -16,11 +16,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* * Driver: amplc_dio200_pci diff --git a/drivers/staging/comedi/drivers/amplc_pc236.c b/drivers/staging/comedi/drivers/amplc_pc236.c index 115ecd51677e..4e889b82cbf2 100644 --- a/drivers/staging/comedi/drivers/amplc_pc236.c +++ b/drivers/staging/comedi/drivers/amplc_pc236.c @@ -16,11 +16,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: amplc_pc236 @@ -543,7 +538,6 @@ static void pc236_detach(struct comedi_device *dev) return; if (dev->iobase) pc236_intr_disable(dev); - comedi_spriv_free(dev, 0); if (is_isa_board(thisboard)) { comedi_legacy_detach(dev); } else if (is_pci_board(thisboard)) { diff --git a/drivers/staging/comedi/drivers/amplc_pc263.c b/drivers/staging/comedi/drivers/amplc_pc263.c index 94a752d852bb..6546095e7a45 100644 --- a/drivers/staging/comedi/drivers/amplc_pc263.c +++ b/drivers/staging/comedi/drivers/amplc_pc263.c @@ -16,11 +16,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: amplc_pc263 diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c index 4d7eab9b5565..f1e36f08b103 100644 --- a/drivers/staging/comedi/drivers/amplc_pci224.c +++ b/drivers/staging/comedi/drivers/amplc_pci224.c @@ -16,11 +16,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: amplc_pci224 diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c index 49200fbd60b9..846d6448fa4d 100644 --- a/drivers/staging/comedi/drivers/amplc_pci230.c +++ b/drivers/staging/comedi/drivers/amplc_pci230.c @@ -16,10 +16,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Driver: amplc_pci230 @@ -2834,7 +2830,6 @@ static void pci230_detach(struct comedi_device *dev) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - comedi_spriv_free(dev, 2); if (dev->irq) free_irq(dev->irq, dev); comedi_pci_disable(dev); diff --git a/drivers/staging/comedi/drivers/amplc_pci263.c b/drivers/staging/comedi/drivers/amplc_pci263.c index 8b57533bf406..4da900cc5845 100644 --- a/drivers/staging/comedi/drivers/amplc_pci263.c +++ b/drivers/staging/comedi/drivers/amplc_pci263.c @@ -16,11 +16,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: amplc_pci263 diff --git a/drivers/staging/comedi/drivers/c6xdigio.c b/drivers/staging/comedi/drivers/c6xdigio.c index 92376dc86dd8..929218a35975 100644 --- a/drivers/staging/comedi/drivers/c6xdigio.c +++ b/drivers/staging/comedi/drivers/c6xdigio.c @@ -16,11 +16,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: c6xdigio diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c index f874fff44523..ae9a2082b5a4 100644 --- a/drivers/staging/comedi/drivers/cb_das16_cs.c +++ b/drivers/staging/comedi/drivers/cb_das16_cs.c @@ -15,10 +15,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - PCMCIA support code for this driver is adapted from the dummy_cs.c driver of the Linux PCMCIA Card Services package. diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c index 53dd298d2b54..58bca184bf22 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas.c +++ b/drivers/staging/comedi/drivers/cb_pcidas.c @@ -19,12 +19,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************ */ /* Driver: cb_pcidas @@ -1608,7 +1602,6 @@ static void cb_pcidas_detach(struct comedi_device *dev) } if (dev->irq) free_irq(dev->irq, dev); - comedi_spriv_free(dev, 2); comedi_pci_disable(dev); } diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c index c3e5495b4f06..43c0bf58771a 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas64.c +++ b/drivers/staging/comedi/drivers/cb_pcidas64.c @@ -28,12 +28,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************/ +*/ /* * Driver: cb_pcidas64 @@ -4163,7 +4158,6 @@ static void detach(struct comedi_device *dev) devpriv->ao_dma_desc_bus_addr); } } - comedi_spriv_free(dev, 4); comedi_pci_disable(dev); } diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c b/drivers/staging/comedi/drivers/cb_pcidda.c index f9b459888b8b..2d3e920e5987 100644 --- a/drivers/staging/comedi/drivers/cb_pcidda.c +++ b/drivers/staging/comedi/drivers/cb_pcidda.c @@ -17,10 +17,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -397,18 +393,11 @@ static int cb_pcidda_auto_attach(struct comedi_device *dev, return 0; } -static void cb_pcidda_detach(struct comedi_device *dev) -{ - comedi_spriv_free(dev, 1); - comedi_spriv_free(dev, 2); - comedi_pci_disable(dev); -} - static struct comedi_driver cb_pcidda_driver = { .driver_name = "cb_pcidda", .module = THIS_MODULE, .auto_attach = cb_pcidda_auto_attach, - .detach = cb_pcidda_detach, + .detach = comedi_pci_disable, }; static int cb_pcidda_pci_probe(struct pci_dev *dev, diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c index 29813c9d4a2a..8b5c198862a1 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdas.c +++ b/drivers/staging/comedi/drivers/cb_pcimdas.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: cb_pcimdas diff --git a/drivers/staging/comedi/drivers/cb_pcimdda.c b/drivers/staging/comedi/drivers/cb_pcimdda.c index 88f03ae6f3e6..406cba8cba88 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdda.c +++ b/drivers/staging/comedi/drivers/cb_pcimdda.c @@ -15,11 +15,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: cb_pcimdda @@ -197,17 +192,11 @@ static int cb_pcimdda_auto_attach(struct comedi_device *dev, return 1; } -static void cb_pcimdda_detach(struct comedi_device *dev) -{ - comedi_spriv_free(dev, 1); - comedi_pci_disable(dev); -} - static struct comedi_driver cb_pcimdda_driver = { .driver_name = "cb_pcimdda", .module = THIS_MODULE, .auto_attach = cb_pcimdda_auto_attach, - .detach = cb_pcimdda_detach, + .detach = comedi_pci_disable, }; static int cb_pcimdda_pci_probe(struct pci_dev *dev, diff --git a/drivers/staging/comedi/drivers/comedi_bond.c b/drivers/staging/comedi/drivers/comedi_bond.c index 1bb53816eca3..1a51866be6f7 100644 --- a/drivers/staging/comedi/drivers/comedi_bond.c +++ b/drivers/staging/comedi/drivers/comedi_bond.c @@ -15,11 +15,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: comedi_bond diff --git a/drivers/staging/comedi/drivers/comedi_fc.c b/drivers/staging/comedi/drivers/comedi_fc.c index 37dc79637d2a..b3d89c82d087 100644 --- a/drivers/staging/comedi/drivers/comedi_fc.c +++ b/drivers/staging/comedi/drivers/comedi_fc.c @@ -17,12 +17,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************/ +*/ #include "../comedidev.h" diff --git a/drivers/staging/comedi/drivers/comedi_fc.h b/drivers/staging/comedi/drivers/comedi_fc.h index 31afab79f39a..a4dea7cb86be 100644 --- a/drivers/staging/comedi/drivers/comedi_fc.h +++ b/drivers/staging/comedi/drivers/comedi_fc.h @@ -17,12 +17,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************/ +*/ #ifndef _COMEDI_FC_H #define _COMEDI_FC_H diff --git a/drivers/staging/comedi/drivers/comedi_parport.c b/drivers/staging/comedi/drivers/comedi_parport.c index 3e061cc9b48e..772a8f5f0c1c 100644 --- a/drivers/staging/comedi/drivers/comedi_parport.c +++ b/drivers/staging/comedi/drivers/comedi_parport.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: comedi_parport diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c index c1d8e86f53a2..907e7a3822f5 100644 --- a/drivers/staging/comedi/drivers/comedi_test.c +++ b/drivers/staging/comedi/drivers/comedi_test.c @@ -21,12 +21,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************/ +*/ /* Driver: comedi_test Description: generates fake waveforms diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c b/drivers/staging/comedi/drivers/contec_pci_dio.c index f2230bfd4eb9..0fb9027dde2d 100644 --- a/drivers/staging/comedi/drivers/contec_pci_dio.c +++ b/drivers/staging/comedi/drivers/contec_pci_dio.c @@ -13,11 +13,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: contec_pci_dio diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c index b87f95c3e17d..44c912b48b6e 100644 --- a/drivers/staging/comedi/drivers/daqboard2000.c +++ b/drivers/staging/comedi/drivers/daqboard2000.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: daqboard2000 @@ -110,7 +105,6 @@ Configuration options: not applicable, uses PCI auto config #include #include #include -#include #include "../comedidev.h" @@ -524,7 +518,8 @@ static int daqboard2000_writeCPLD(struct comedi_device *dev, int data) } static int initialize_daqboard2000(struct comedi_device *dev, - const u8 *cpld_array, size_t len) + const u8 *cpld_array, size_t len, + unsigned long context) { struct daqboard2000_private *devpriv = dev->private; int result = -EIO; @@ -565,22 +560,6 @@ static int initialize_daqboard2000(struct comedi_device *dev, return result; } -static int daqboard2000_upload_firmware(struct comedi_device *dev) -{ - struct pci_dev *pcidev = comedi_to_pci_dev(dev); - const struct firmware *fw; - int ret; - - ret = request_firmware(&fw, DAQBOARD2000_FIRMWARE, &pcidev->dev); - if (ret) - return ret; - - ret = initialize_daqboard2000(dev, fw->data, fw->size); - release_firmware(fw); - - return ret; -} - static void daqboard2000_adcStopDmaTransfer(struct comedi_device *dev) { } @@ -724,7 +703,9 @@ static int daqboard2000_auto_attach(struct comedi_device *dev, readl(devpriv->plx + 0x6c); - result = daqboard2000_upload_firmware(dev); + result = comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev, + DAQBOARD2000_FIRMWARE, + initialize_daqboard2000, 0); if (result < 0) return result; @@ -766,7 +747,6 @@ static void daqboard2000_detach(struct comedi_device *dev) { struct daqboard2000_private *devpriv = dev->private; - comedi_spriv_free(dev, 2); if (dev->irq) free_irq(dev->irq, dev); if (devpriv) { diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c index ba12c1d605fb..2e7e3e202390 100644 --- a/drivers/staging/comedi/drivers/das08.c +++ b/drivers/staging/comedi/drivers/das08.c @@ -16,12 +16,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - ***************************************************************** */ /* @@ -566,12 +560,6 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase) } EXPORT_SYMBOL_GPL(das08_common_attach); -void das08_common_detach(struct comedi_device *dev) -{ - comedi_spriv_free(dev, 4); -} -EXPORT_SYMBOL_GPL(das08_common_detach); - static int __init das08_init(void) { return 0; diff --git a/drivers/staging/comedi/drivers/das08.h b/drivers/staging/comedi/drivers/das08.h index 89bb8d6fdfc6..cce1b584200a 100644 --- a/drivers/staging/comedi/drivers/das08.h +++ b/drivers/staging/comedi/drivers/das08.h @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _DAS08_H @@ -52,6 +47,5 @@ struct das08_private_struct { }; int das08_common_attach(struct comedi_device *dev, unsigned long iobase); -void das08_common_detach(struct comedi_device *dev); #endif /* _DAS08_H */ diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c index d9f3e92317d3..885fb179c9b4 100644 --- a/drivers/staging/comedi/drivers/das08_cs.c +++ b/drivers/staging/comedi/drivers/das08_cs.c @@ -16,19 +16,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - PCMCIA support code for this driver is adapted from the dummy_cs.c driver of the Linux PCMCIA Card Services package. The initial developer of the original code is David A. Hinds . Portions created by David A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights Reserved. - -***************************************************************** - */ /* Driver: das08_cs @@ -93,17 +86,11 @@ static int das08_cs_auto_attach(struct comedi_device *dev, return das08_common_attach(dev, iobase); } -static void das08_cs_detach(struct comedi_device *dev) -{ - das08_common_detach(dev); - comedi_pcmcia_disable(dev); -} - static struct comedi_driver driver_das08_cs = { .driver_name = "das08_cs", .module = THIS_MODULE, .auto_attach = das08_cs_auto_attach, - .detach = das08_cs_detach, + .detach = comedi_pcmcia_disable, }; static int das08_pcmcia_attach(struct pcmcia_device *link) diff --git a/drivers/staging/comedi/drivers/das08_isa.c b/drivers/staging/comedi/drivers/das08_isa.c index f09f6966ed65..21a94389b8b2 100644 --- a/drivers/staging/comedi/drivers/das08_isa.c +++ b/drivers/staging/comedi/drivers/das08_isa.c @@ -16,10 +16,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -193,17 +189,11 @@ static int das08_isa_attach(struct comedi_device *dev, return das08_common_attach(dev, dev->iobase); } -static void das08_isa_detach(struct comedi_device *dev) -{ - das08_common_detach(dev); - comedi_legacy_detach(dev); -} - static struct comedi_driver das08_isa_driver = { .driver_name = "isa-das08", .module = THIS_MODULE, .attach = das08_isa_attach, - .detach = das08_isa_detach, + .detach = comedi_legacy_detach, .board_name = &das08_isa_boards[0].name, .num_names = ARRAY_SIZE(das08_isa_boards), .offset = sizeof(das08_isa_boards[0]), diff --git a/drivers/staging/comedi/drivers/das08_pci.c b/drivers/staging/comedi/drivers/das08_pci.c index 53fa943dd0b7..9c5d234e063f 100644 --- a/drivers/staging/comedi/drivers/das08_pci.c +++ b/drivers/staging/comedi/drivers/das08_pci.c @@ -16,10 +16,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -79,17 +75,11 @@ static int das08_pci_auto_attach(struct comedi_device *dev, return das08_common_attach(dev, dev->iobase); } -static void das08_pci_detach(struct comedi_device *dev) -{ - das08_common_detach(dev); - comedi_pci_disable(dev); -} - static struct comedi_driver das08_pci_comedi_driver = { .driver_name = "pci-das08", .module = THIS_MODULE, .auto_attach = das08_pci_auto_attach, - .detach = das08_pci_detach, + .detach = comedi_pci_disable, }; static int das08_pci_probe(struct pci_dev *dev, diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c index 762b5a6eac5a..dbec3ba99548 100644 --- a/drivers/staging/comedi/drivers/das16.c +++ b/drivers/staging/comedi/drivers/das16.c @@ -16,12 +16,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************ */ /* Driver: das16 @@ -1339,7 +1333,6 @@ static void das16_detach(struct comedi_device *dev) struct das16_private_struct *devpriv = dev->private; das16_reset(dev); - comedi_spriv_free(dev, 4); if (devpriv) { int i; for (i = 0; i < 2; i++) { diff --git a/drivers/staging/comedi/drivers/das16m1.c b/drivers/staging/comedi/drivers/das16m1.c index 9cb9c3b04797..0b33808c3a7d 100644 --- a/drivers/staging/comedi/drivers/das16m1.c +++ b/drivers/staging/comedi/drivers/das16m1.c @@ -17,12 +17,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************ */ /* Driver: das16m1 @@ -672,7 +666,6 @@ static void das16m1_detach(struct comedi_device *dev) { struct das16m1_private_struct *devpriv = dev->private; - comedi_spriv_free(dev, 3); if (devpriv && devpriv->extra_iobase) release_region(devpriv->extra_iobase, DAS16M1_SIZE2); comedi_legacy_detach(dev); diff --git a/drivers/staging/comedi/drivers/das1800.c b/drivers/staging/comedi/drivers/das1800.c index abf7638a9f71..23b4a661eb1a 100644 --- a/drivers/staging/comedi/drivers/das1800.c +++ b/drivers/staging/comedi/drivers/das1800.c @@ -15,12 +15,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************ */ /* Driver: das1800 diff --git a/drivers/staging/comedi/drivers/das6402.c b/drivers/staging/comedi/drivers/das6402.c index 11424fb5b4d4..f0530778bb3b 100644 --- a/drivers/staging/comedi/drivers/das6402.c +++ b/drivers/staging/comedi/drivers/das6402.c @@ -22,11 +22,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: das6402 diff --git a/drivers/staging/comedi/drivers/das800.c b/drivers/staging/comedi/drivers/das800.c index 9ce6cbcc7ee8..091cd911b38a 100644 --- a/drivers/staging/comedi/drivers/das800.c +++ b/drivers/staging/comedi/drivers/das800.c @@ -15,12 +15,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************ */ /* Driver: das800 diff --git a/drivers/staging/comedi/drivers/dmm32at.c b/drivers/staging/comedi/drivers/dmm32at.c index 6c85dd2d549b..e29847d73b43 100644 --- a/drivers/staging/comedi/drivers/dmm32at.c +++ b/drivers/staging/comedi/drivers/dmm32at.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: dmm32at diff --git a/drivers/staging/comedi/drivers/dt2811.c b/drivers/staging/comedi/drivers/dt2811.c index 8757b54ad4ac..5348cdae408a 100644 --- a/drivers/staging/comedi/drivers/dt2811.c +++ b/drivers/staging/comedi/drivers/dt2811.c @@ -18,10 +18,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Driver: dt2811 diff --git a/drivers/staging/comedi/drivers/dt2814.c b/drivers/staging/comedi/drivers/dt2814.c index 7c95b3b68131..87e9749c4be7 100644 --- a/drivers/staging/comedi/drivers/dt2814.c +++ b/drivers/staging/comedi/drivers/dt2814.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: dt2814 diff --git a/drivers/staging/comedi/drivers/dt2815.c b/drivers/staging/comedi/drivers/dt2815.c index b24e87681fe3..0fcd4fe7acdc 100644 --- a/drivers/staging/comedi/drivers/dt2815.c +++ b/drivers/staging/comedi/drivers/dt2815.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: dt2815 diff --git a/drivers/staging/comedi/drivers/dt2817.c b/drivers/staging/comedi/drivers/dt2817.c index b5c8e8213faf..2f46be715f79 100644 --- a/drivers/staging/comedi/drivers/dt2817.c +++ b/drivers/staging/comedi/drivers/dt2817.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: dt2817 diff --git a/drivers/staging/comedi/drivers/dt282x.c b/drivers/staging/comedi/drivers/dt282x.c index 90f2de9bc402..c1950e3b19a2 100644 --- a/drivers/staging/comedi/drivers/dt282x.c +++ b/drivers/staging/comedi/drivers/dt282x.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: dt282x diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c index 7e03929c9a14..01a2f889d5b0 100644 --- a/drivers/staging/comedi/drivers/dt3000.c +++ b/drivers/staging/comedi/drivers/dt3000.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: dt3000 diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c index 81eb5ed6ec97..6c60949d9193 100644 --- a/drivers/staging/comedi/drivers/dt9812.c +++ b/drivers/staging/comedi/drivers/dt9812.c @@ -15,11 +15,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * */ /* @@ -43,14 +38,11 @@ for my needs. * says P1). */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include #include #include -#include #include #include @@ -60,6 +52,9 @@ for my needs. #define DT9812_MAX_WRITE_CMD_PIPE_SIZE 32 #define DT9812_MAX_READ_CMD_PIPE_SIZE 32 +/* usb_bulk_msg() timout in milliseconds */ +#define DT9812_USB_TIMEOUT 1000 + /* * See Silican Laboratories C8051F020/1/2/3 manual */ @@ -242,87 +237,25 @@ struct dt9812_usb_cmd { struct dt9812_write_multi write_multi_info; struct dt9812_rmw_multi rmw_multi_info; } u; -#if 0 - WRITE_BYTE_INFO WriteByteInfo; - READ_BYTE_INFO ReadByteInfo; - WRITE_MULTI_INFO WriteMultiInfo; - READ_MULTI_INFO ReadMultiInfo; - RMW_BYTE_INFO RMWByteInfo; - RMW_MULTI_INFO RMWMultiInfo; - DAC_THRESHOLD_INFO DacThresholdInfo; - INT_ON_CHANGE_MASK_INFO IntOnChangeMaskInfo; - CGL_INFO CglInfo; - SUBSYSTEM_INFO SubsystemInfo; - CAL_POT_CMD CalPotCmd; - WRITE_DEV_BYTE_INFO WriteDevByteInfo; - READ_DEV_BYTE_INFO ReadDevByteInfo; - WRITE_DEV_MULTI_INFO WriteDevMultiInfo; - READ_DEV_MULTI_INFO ReadDevMultiInfo; - READ_SINGLE_VALUE_INFO ReadSingleValueInfo; - WRITE_SINGLE_VALUE_INFO WriteSingleValueInfo; -#endif }; -#define DT9812_NUM_SLOTS 16 - -static DEFINE_SEMAPHORE(dt9812_mutex); - -static const struct usb_device_id dt9812_table[] = { - {USB_DEVICE(0x0867, 0x9812)}, - {} /* Terminating entry */ -}; - -MODULE_DEVICE_TABLE(usb, dt9812_table); - -struct usb_dt9812 { - struct slot_dt9812 *slot; - struct usb_device *udev; - struct usb_interface *interface; - u16 vendor; - u16 product; - u16 device; - u32 serial; +struct dt9812_private { + struct semaphore sem; struct { __u8 addr; size_t size; - } message_pipe, command_write, command_read, write_stream, read_stream; - struct kref kref; - u16 analog_out_shadow[2]; - u8 digital_out_shadow; + } cmd_wr, cmd_rd; + u16 device; + u16 ao_shadow[2]; }; -struct comedi_dt9812 { - struct slot_dt9812 *slot; - u32 serial; -}; - -struct slot_dt9812 { - struct semaphore mutex; - u32 serial; - struct usb_dt9812 *usb; - struct comedi_dt9812 *comedi; -}; - -static struct slot_dt9812 dt9812[DT9812_NUM_SLOTS]; - -static inline struct usb_dt9812 *to_dt9812_dev(struct kref *d) -{ - return container_of(d, struct usb_dt9812, kref); -} - -static void dt9812_delete(struct kref *kref) -{ - struct usb_dt9812 *dev = to_dt9812_dev(kref); - - usb_put_dev(dev->udev); - kfree(dev); -} - -static int dt9812_read_info(struct usb_dt9812 *dev, int offset, void *buf, - size_t buf_size) +static int dt9812_read_info(struct comedi_device *dev, + int offset, void *buf, size_t buf_size) { + struct usb_device *usb = comedi_to_usb_dev(dev); + struct dt9812_private *devpriv = dev->private; struct dt9812_usb_cmd cmd; - int count, retval; + int count, ret; cmd.cmd = cpu_to_le32(DT9812_R_FLASH_DATA); cmd.u.flash_data_info.address = @@ -330,25 +263,23 @@ static int dt9812_read_info(struct usb_dt9812 *dev, int offset, void *buf, cmd.u.flash_data_info.numbytes = cpu_to_le16(buf_size); /* DT9812 only responds to 32 byte writes!! */ - count = 32; - retval = usb_bulk_msg(dev->udev, - usb_sndbulkpipe(dev->udev, - dev->command_write.addr), - &cmd, 32, &count, HZ * 1); - if (retval) - return retval; - retval = usb_bulk_msg(dev->udev, - usb_rcvbulkpipe(dev->udev, - dev->command_read.addr), - buf, buf_size, &count, HZ * 1); - return retval; + ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr), + &cmd, 32, &count, DT9812_USB_TIMEOUT); + if (ret) + return ret; + + return usb_bulk_msg(usb, usb_rcvbulkpipe(usb, devpriv->cmd_rd.addr), + buf, buf_size, &count, DT9812_USB_TIMEOUT); } -static int dt9812_read_multiple_registers(struct usb_dt9812 *dev, int reg_count, - u8 *address, u8 *value) +static int dt9812_read_multiple_registers(struct comedi_device *dev, + int reg_count, u8 *address, + u8 *value) { + struct usb_device *usb = comedi_to_usb_dev(dev); + struct dt9812_private *devpriv = dev->private; struct dt9812_usb_cmd cmd; - int i, count, retval; + int i, count, ret; cmd.cmd = cpu_to_le32(DT9812_R_MULTI_BYTE_REG); cmd.u.read_multi_info.count = reg_count; @@ -356,26 +287,23 @@ static int dt9812_read_multiple_registers(struct usb_dt9812 *dev, int reg_count, cmd.u.read_multi_info.address[i] = address[i]; /* DT9812 only responds to 32 byte writes!! */ - count = 32; - retval = usb_bulk_msg(dev->udev, - usb_sndbulkpipe(dev->udev, - dev->command_write.addr), - &cmd, 32, &count, HZ * 1); - if (retval) - return retval; - retval = usb_bulk_msg(dev->udev, - usb_rcvbulkpipe(dev->udev, - dev->command_read.addr), - value, reg_count, &count, HZ * 1); - return retval; + ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr), + &cmd, 32, &count, DT9812_USB_TIMEOUT); + if (ret) + return ret; + + return usb_bulk_msg(usb, usb_rcvbulkpipe(usb, devpriv->cmd_rd.addr), + value, reg_count, &count, DT9812_USB_TIMEOUT); } -static int dt9812_write_multiple_registers(struct usb_dt9812 *dev, +static int dt9812_write_multiple_registers(struct comedi_device *dev, int reg_count, u8 *address, u8 *value) { + struct usb_device *usb = comedi_to_usb_dev(dev); + struct dt9812_private *devpriv = dev->private; struct dt9812_usb_cmd cmd; - int i, count, retval; + int i, count; cmd.cmd = cpu_to_le32(DT9812_W_MULTI_BYTE_REG); cmd.u.read_multi_info.count = reg_count; @@ -383,19 +311,20 @@ static int dt9812_write_multiple_registers(struct usb_dt9812 *dev, cmd.u.write_multi_info.write[i].address = address[i]; cmd.u.write_multi_info.write[i].value = value[i]; } + /* DT9812 only responds to 32 byte writes!! */ - retval = usb_bulk_msg(dev->udev, - usb_sndbulkpipe(dev->udev, - dev->command_write.addr), - &cmd, 32, &count, HZ * 1); - return retval; + return usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr), + &cmd, 32, &count, DT9812_USB_TIMEOUT); } -static int dt9812_rmw_multiple_registers(struct usb_dt9812 *dev, int reg_count, +static int dt9812_rmw_multiple_registers(struct comedi_device *dev, + int reg_count, struct dt9812_rmw_byte *rmw) { + struct usb_device *usb = comedi_to_usb_dev(dev); + struct dt9812_private *devpriv = dev->private; struct dt9812_usb_cmd cmd; - int i, count, retval; + int i, count; cmd.cmd = cpu_to_le32(DT9812_RMW_MULTI_BYTE_REG); cmd.u.rmw_multi_info.count = reg_count; @@ -403,76 +332,52 @@ static int dt9812_rmw_multiple_registers(struct usb_dt9812 *dev, int reg_count, cmd.u.rmw_multi_info.rmw[i] = rmw[i]; /* DT9812 only responds to 32 byte writes!! */ - retval = usb_bulk_msg(dev->udev, - usb_sndbulkpipe(dev->udev, - dev->command_write.addr), - &cmd, 32, &count, HZ * 1); - return retval; + return usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr), + &cmd, 32, &count, DT9812_USB_TIMEOUT); } -static int dt9812_digital_in(struct slot_dt9812 *slot, u8 *bits) +static int dt9812_digital_in(struct comedi_device *dev, u8 *bits) { - int result = -ENODEV; + struct dt9812_private *devpriv = dev->private; + u8 reg[2] = { F020_SFR_P3, F020_SFR_P1 }; + u8 value[2]; + int ret; - down(&slot->mutex); - if (slot->usb) { - u8 reg[2] = { F020_SFR_P3, F020_SFR_P1 }; - u8 value[2]; - - result = dt9812_read_multiple_registers(slot->usb, 2, reg, - value); - if (result == 0) { - /* - * bits 0-6 in F020_SFR_P3 are bits 0-6 in the digital - * input port bit 3 in F020_SFR_P1 is bit 7 in the - * digital input port - */ - *bits = (value[0] & 0x7f) | ((value[1] & 0x08) << 4); - /* printk("%2.2x, %2.2x -> %2.2x\n", - value[0], value[1], *bits); */ - } + down(&devpriv->sem); + ret = dt9812_read_multiple_registers(dev, 2, reg, value); + if (ret == 0) { + /* + * bits 0-6 in F020_SFR_P3 are bits 0-6 in the digital + * input port bit 3 in F020_SFR_P1 is bit 7 in the + * digital input port + */ + *bits = (value[0] & 0x7f) | ((value[1] & 0x08) << 4); } - up(&slot->mutex); + up(&devpriv->sem); - return result; + return ret; } -static int dt9812_digital_out(struct slot_dt9812 *slot, u8 bits) +static int dt9812_digital_out(struct comedi_device *dev, u8 bits) { - int result = -ENODEV; + struct dt9812_private *devpriv = dev->private; + u8 reg[1] = { F020_SFR_P2 }; + u8 value[1] = { bits }; + int ret; - down(&slot->mutex); - if (slot->usb) { - u8 reg[1]; - u8 value[1]; + down(&devpriv->sem); + ret = dt9812_write_multiple_registers(dev, 1, reg, value); + up(&devpriv->sem); - reg[0] = F020_SFR_P2; - value[0] = bits; - result = dt9812_write_multiple_registers(slot->usb, 1, reg, - value); - slot->usb->digital_out_shadow = bits; - } - up(&slot->mutex); - return result; + return ret; } -static int dt9812_digital_out_shadow(struct slot_dt9812 *slot, u8 *bits) -{ - int result = -ENODEV; - - down(&slot->mutex); - if (slot->usb) { - *bits = slot->usb->digital_out_shadow; - result = 0; - } - up(&slot->mutex); - return result; -} - -static void dt9812_configure_mux(struct usb_dt9812 *dev, +static void dt9812_configure_mux(struct comedi_device *dev, struct dt9812_rmw_byte *rmw, int channel) { - if (dev->device == DT9812_DEVID_DT9812_10) { + struct dt9812_private *devpriv = dev->private; + + if (devpriv->device == DT9812_DEVID_DT9812_10) { /* In the DT9812/10V MUX is selected by P1.5-7 */ rmw->address = F020_SFR_P1; rmw->and_mask = 0xe0; @@ -485,18 +390,21 @@ static void dt9812_configure_mux(struct usb_dt9812 *dev, } } -static void dt9812_configure_gain(struct usb_dt9812 *dev, +static void dt9812_configure_gain(struct comedi_device *dev, struct dt9812_rmw_byte *rmw, enum dt9812_gain gain) { - if (dev->device == DT9812_DEVID_DT9812_10) { - /* In the DT9812/10V, there is an external gain of 0.5 */ + struct dt9812_private *devpriv = dev->private; + + /* In the DT9812/10V, there is an external gain of 0.5 */ + if (devpriv->device == DT9812_DEVID_DT9812_10) gain <<= 1; - } rmw->address = F020_SFR_ADC0CF; rmw->and_mask = F020_MASK_ADC0CF_AMP0GN2 | - F020_MASK_ADC0CF_AMP0GN1 | F020_MASK_ADC0CF_AMP0GN0; + F020_MASK_ADC0CF_AMP0GN1 | + F020_MASK_ADC0CF_AMP0GN0; + switch (gain) { /* * 000 -> Gain = 1 @@ -508,8 +416,10 @@ static void dt9812_configure_gain(struct usb_dt9812 *dev, */ case DT9812_GAIN_0PT5: rmw->or_value = F020_MASK_ADC0CF_AMP0GN2 | - F020_MASK_ADC0CF_AMP0GN1; + F020_MASK_ADC0CF_AMP0GN1; break; + default: + /* this should never happen, just use a gain of 1 */ case DT9812_GAIN_1: rmw->or_value = 0x00; break; @@ -521,20 +431,18 @@ static void dt9812_configure_gain(struct usb_dt9812 *dev, break; case DT9812_GAIN_8: rmw->or_value = F020_MASK_ADC0CF_AMP0GN1 | - F020_MASK_ADC0CF_AMP0GN0; + F020_MASK_ADC0CF_AMP0GN0; break; case DT9812_GAIN_16: rmw->or_value = F020_MASK_ADC0CF_AMP0GN2; break; - default: - dev_err(&dev->interface->dev, "Illegal gain %d\n", gain); - } } -static int dt9812_analog_in(struct slot_dt9812 *slot, int channel, u16 *value, - enum dt9812_gain gain) +static int dt9812_analog_in(struct comedi_device *dev, + int channel, u16 *value, enum dt9812_gain gain) { + struct dt9812_private *devpriv = dev->private; struct dt9812_rmw_byte rmw[3]; u8 reg[3] = { F020_SFR_ADC0CN, @@ -542,31 +450,30 @@ static int dt9812_analog_in(struct slot_dt9812 *slot, int channel, u16 *value, F020_SFR_ADC0L }; u8 val[3]; - int result = -ENODEV; + int ret; - down(&slot->mutex); - if (!slot->usb) - goto exit; + down(&devpriv->sem); /* 1 select the gain */ - dt9812_configure_gain(slot->usb, &rmw[0], gain); + dt9812_configure_gain(dev, &rmw[0], gain); /* 2 set the MUX to select the channel */ - dt9812_configure_mux(slot->usb, &rmw[1], channel); + dt9812_configure_mux(dev, &rmw[1], channel); /* 3 start conversion */ rmw[2].address = F020_SFR_ADC0CN; rmw[2].and_mask = 0xff; rmw[2].or_value = F020_MASK_ADC0CN_AD0EN | F020_MASK_ADC0CN_AD0BUSY; - result = dt9812_rmw_multiple_registers(slot->usb, 3, rmw); - if (result) + ret = dt9812_rmw_multiple_registers(dev, 3, rmw); + if (ret) goto exit; /* read the status and ADC */ - result = dt9812_read_multiple_registers(slot->usb, 3, reg, val); - if (result) + ret = dt9812_read_multiple_registers(dev, 3, reg, val); + if (ret) goto exit; + /* * An ADC conversion takes 16 SAR clocks cycles, i.e. about 9us. * Therefore, between the instant that AD0BUSY was set via @@ -578,7 +485,7 @@ static int dt9812_analog_in(struct slot_dt9812 *slot, int channel, u16 *value, */ if ((val[0] & (F020_MASK_ADC0CN_AD0INT | F020_MASK_ADC0CN_AD0BUSY)) == F020_MASK_ADC0CN_AD0INT) { - switch (slot->usb->device) { + switch (devpriv->device) { case DT9812_DEVID_DT9812_10: /* * For DT9812-10V the personality module set the @@ -594,422 +501,284 @@ static int dt9812_analog_in(struct slot_dt9812 *slot, int channel, u16 *value, } exit: - up(&slot->mutex); - return result; + up(&devpriv->sem); + + return ret; } -static int dt9812_analog_out_shadow(struct slot_dt9812 *slot, int channel, - u16 *value) +static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value) { - int result = -ENODEV; + struct dt9812_private *devpriv = dev->private; + struct dt9812_rmw_byte rmw[3]; + int ret; - down(&slot->mutex); - if (slot->usb) { - *value = slot->usb->analog_out_shadow[channel]; - result = 0; + down(&devpriv->sem); + + switch (channel) { + case 0: + /* 1. Set DAC mode */ + rmw[0].address = F020_SFR_DAC0CN; + rmw[0].and_mask = 0xff; + rmw[0].or_value = F020_MASK_DACxCN_DACxEN; + + /* 2 load low byte of DAC value first */ + rmw[1].address = F020_SFR_DAC0L; + rmw[1].and_mask = 0xff; + rmw[1].or_value = value & 0xff; + + /* 3 load high byte of DAC value next to latch the + 12-bit value */ + rmw[2].address = F020_SFR_DAC0H; + rmw[2].and_mask = 0xff; + rmw[2].or_value = (value >> 8) & 0xf; + break; + + case 1: + /* 1. Set DAC mode */ + rmw[0].address = F020_SFR_DAC1CN; + rmw[0].and_mask = 0xff; + rmw[0].or_value = F020_MASK_DACxCN_DACxEN; + + /* 2 load low byte of DAC value first */ + rmw[1].address = F020_SFR_DAC1L; + rmw[1].and_mask = 0xff; + rmw[1].or_value = value & 0xff; + + /* 3 load high byte of DAC value next to latch the + 12-bit value */ + rmw[2].address = F020_SFR_DAC1H; + rmw[2].and_mask = 0xff; + rmw[2].or_value = (value >> 8) & 0xf; + break; } - up(&slot->mutex); + ret = dt9812_rmw_multiple_registers(dev, 3, rmw); + devpriv->ao_shadow[channel] = value; - return result; + up(&devpriv->sem); + + return ret; } -static int dt9812_analog_out(struct slot_dt9812 *slot, int channel, u16 value) +static int dt9812_di_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - int result = -ENODEV; + u8 bits = 0; + int ret; - down(&slot->mutex); - if (slot->usb) { - struct dt9812_rmw_byte rmw[3]; + ret = dt9812_digital_in(dev, &bits); + if (ret) + return ret; - switch (channel) { - case 0: - /* 1. Set DAC mode */ - rmw[0].address = F020_SFR_DAC0CN; - rmw[0].and_mask = 0xff; - rmw[0].or_value = F020_MASK_DACxCN_DACxEN; + data[1] = bits; - /* 2 load low byte of DAC value first */ - rmw[1].address = F020_SFR_DAC0L; - rmw[1].and_mask = 0xff; - rmw[1].or_value = value & 0xff; + return insn->n; +} - /* 3 load high byte of DAC value next to latch the - 12-bit value */ - rmw[2].address = F020_SFR_DAC0H; - rmw[2].and_mask = 0xff; - rmw[2].or_value = (value >> 8) & 0xf; - break; +static int dt9812_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int mask = data[0]; + unsigned int bits = data[1]; - case 1: - /* 1. Set DAC mode */ - rmw[0].address = F020_SFR_DAC1CN; - rmw[0].and_mask = 0xff; - rmw[0].or_value = F020_MASK_DACxCN_DACxEN; + if (mask) { + s->state &= ~mask; + s->state |= (bits & mask); - /* 2 load low byte of DAC value first */ - rmw[1].address = F020_SFR_DAC1L; - rmw[1].and_mask = 0xff; - rmw[1].or_value = value & 0xff; - - /* 3 load high byte of DAC value next to latch the - 12-bit value */ - rmw[2].address = F020_SFR_DAC1H; - rmw[2].and_mask = 0xff; - rmw[2].or_value = (value >> 8) & 0xf; - break; - } - result = dt9812_rmw_multiple_registers(slot->usb, 3, rmw); - slot->usb->analog_out_shadow[channel] = value; + dt9812_digital_out(dev, s->state); } - up(&slot->mutex); - return result; + data[1] = s->state; + + return insn->n; } -/* - * USB framework functions - */ - -static int dt9812_probe(struct usb_interface *interface, - const struct usb_device_id *id) +static int dt9812_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - int retval = -ENOMEM; - struct usb_dt9812 *dev = NULL; - struct usb_host_interface *iface_desc; - struct usb_endpoint_descriptor *endpoint; + unsigned int chan = CR_CHAN(insn->chanspec); + u16 val = 0; + int ret; int i; - u8 fw; - /* allocate memory for our device state and initialize it */ - dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (dev == NULL) - goto error; - - kref_init(&dev->kref); - - dev->udev = usb_get_dev(interface_to_usbdev(interface)); - dev->interface = interface; - - /* Check endpoints */ - iface_desc = interface->cur_altsetting; - - if (iface_desc->desc.bNumEndpoints != 5) { - dev_err(&interface->dev, "Wrong number of endpoints.\n"); - retval = -ENODEV; - goto error; + for (i = 0; i < insn->n; i++) { + ret = dt9812_analog_in(dev, chan, &val, DT9812_GAIN_1); + if (ret) + return ret; + data[i] = val; } - for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { - int direction = -1; - endpoint = &iface_desc->endpoint[i].desc; + return insn->n; +} + +static int dt9812_ao_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct dt9812_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + int i; + + down(&devpriv->sem); + for (i = 0; i < insn->n; i++) + data[i] = devpriv->ao_shadow[chan]; + up(&devpriv->sem); + + return insn->n; +} + +static int dt9812_ao_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int chan = CR_CHAN(insn->chanspec); + int ret; + int i; + + for (i = 0; i < insn->n; i++) { + ret = dt9812_analog_out(dev, chan, data[i]); + if (ret) + return ret; + } + + return insn->n; +} + +static int dt9812_find_endpoints(struct comedi_device *dev) +{ + struct usb_interface *intf = comedi_to_usb_interface(dev); + struct usb_host_interface *host = intf->cur_altsetting; + struct dt9812_private *devpriv = dev->private; + struct usb_endpoint_descriptor *ep; + int i; + + if (host->desc.bNumEndpoints != 5) { + dev_err(dev->class_dev, "Wrong number of endpoints\n"); + return -ENODEV; + } + + for (i = 0; i < host->desc.bNumEndpoints; ++i) { + int dir = -1; + ep = &host->endpoint[i].desc; switch (i) { case 0: - direction = USB_DIR_IN; - dev->message_pipe.addr = endpoint->bEndpointAddress; - dev->message_pipe.size = - le16_to_cpu(endpoint->wMaxPacketSize); - + /* unused message pipe */ + dir = USB_DIR_IN; break; case 1: - direction = USB_DIR_OUT; - dev->command_write.addr = endpoint->bEndpointAddress; - dev->command_write.size = - le16_to_cpu(endpoint->wMaxPacketSize); + dir = USB_DIR_OUT; + devpriv->cmd_wr.addr = ep->bEndpointAddress; + devpriv->cmd_wr.size = le16_to_cpu(ep->wMaxPacketSize); break; case 2: - direction = USB_DIR_IN; - dev->command_read.addr = endpoint->bEndpointAddress; - dev->command_read.size = - le16_to_cpu(endpoint->wMaxPacketSize); + dir = USB_DIR_IN; + devpriv->cmd_rd.addr = ep->bEndpointAddress; + devpriv->cmd_rd.size = le16_to_cpu(ep->wMaxPacketSize); break; case 3: - direction = USB_DIR_OUT; - dev->write_stream.addr = endpoint->bEndpointAddress; - dev->write_stream.size = - le16_to_cpu(endpoint->wMaxPacketSize); + /* unused write stream */ + dir = USB_DIR_OUT; break; case 4: - direction = USB_DIR_IN; - dev->read_stream.addr = endpoint->bEndpointAddress; - dev->read_stream.size = - le16_to_cpu(endpoint->wMaxPacketSize); + /* unused read stream */ + dir = USB_DIR_IN; break; } - if ((endpoint->bEndpointAddress & USB_DIR_IN) != direction) { - dev_err(&interface->dev, - "Endpoint has wrong direction.\n"); - retval = -ENODEV; - goto error; + if ((ep->bEndpointAddress & USB_DIR_IN) != dir) { + dev_err(dev->class_dev, + "Endpoint has wrong direction\n"); + return -ENODEV; } } - if (dt9812_read_info(dev, 0, &fw, sizeof(fw)) != 0) { + return 0; +} + +static int dt9812_reset_device(struct comedi_device *dev) +{ + struct usb_device *usb = comedi_to_usb_dev(dev); + struct dt9812_private *devpriv = dev->private; + u32 serial; + u16 vendor; + u16 product; + u16 tmp16; + u8 tmp8; + int ret; + int i; + + ret = dt9812_read_info(dev, 0, &tmp8, sizeof(tmp8)); + if (ret) { /* * Seems like a configuration reset is necessary if driver is * reloaded while device is attached */ - usb_reset_configuration(dev->udev); + usb_reset_configuration(usb); for (i = 0; i < 10; i++) { - retval = dt9812_read_info(dev, 1, &fw, sizeof(fw)); - if (retval == 0) { - dev_info(&interface->dev, - "usb_reset_configuration succeeded " - "after %d iterations\n", i); + ret = dt9812_read_info(dev, 1, &tmp8, sizeof(tmp8)); + if (ret == 0) break; - } + } + if (ret) { + dev_err(dev->class_dev, + "unable to reset configuration\n"); + return ret; } } - if (dt9812_read_info(dev, 1, &dev->vendor, sizeof(dev->vendor)) != 0) { - dev_err(&interface->dev, "Failed to read vendor.\n"); - retval = -ENODEV; - goto error; - } - if (dt9812_read_info(dev, 3, &dev->product, sizeof(dev->product)) != 0) { - dev_err(&interface->dev, "Failed to read product.\n"); - retval = -ENODEV; - goto error; - } - if (dt9812_read_info(dev, 5, &dev->device, sizeof(dev->device)) != 0) { - dev_err(&interface->dev, "Failed to read device.\n"); - retval = -ENODEV; - goto error; - } - if (dt9812_read_info(dev, 7, &dev->serial, sizeof(dev->serial)) != 0) { - dev_err(&interface->dev, "Failed to read serial.\n"); - retval = -ENODEV; - goto error; + ret = dt9812_read_info(dev, 1, &vendor, sizeof(vendor)); + if (ret) { + dev_err(dev->class_dev, "failed to read vendor id\n"); + return ret; } + vendor = le16_to_cpu(vendor); - dev->vendor = le16_to_cpu(dev->vendor); - dev->product = le16_to_cpu(dev->product); - dev->device = le16_to_cpu(dev->device); - dev->serial = le32_to_cpu(dev->serial); - switch (dev->device) { - case DT9812_DEVID_DT9812_10: - dev->analog_out_shadow[0] = 0x0800; - dev->analog_out_shadow[1] = 0x800; - break; - case DT9812_DEVID_DT9812_2PT5: - dev->analog_out_shadow[0] = 0x0000; - dev->analog_out_shadow[1] = 0x0000; - break; + ret = dt9812_read_info(dev, 3, &product, sizeof(product)); + if (ret) { + dev_err(dev->class_dev, "failed to read product id\n"); + return ret; } - dev->digital_out_shadow = 0; + product = le16_to_cpu(product); - /* save our data pointer in this interface device */ - usb_set_intfdata(interface, dev); + ret = dt9812_read_info(dev, 5, &tmp16, sizeof(tmp16)); + if (ret) { + dev_err(dev->class_dev, "failed to read device id\n"); + return ret; + } + devpriv->device = le16_to_cpu(tmp16); + + ret = dt9812_read_info(dev, 7, &serial, sizeof(serial)); + if (ret) { + dev_err(dev->class_dev, "failed to read serial number\n"); + return ret; + } + serial = le32_to_cpu(serial); /* let the user know what node this device is now attached to */ - dev_info(&interface->dev, "USB DT9812 (%4.4x.%4.4x.%4.4x) #0x%8.8x\n", - dev->vendor, dev->product, dev->device, dev->serial); + dev_info(dev->class_dev, "USB DT9812 (%4.4x.%4.4x.%4.4x) #0x%8.8x\n", + vendor, product, devpriv->device, serial); - down(&dt9812_mutex); - { - /* Find a slot for the USB device */ - struct slot_dt9812 *first = NULL; - struct slot_dt9812 *best = NULL; - - for (i = 0; i < DT9812_NUM_SLOTS; i++) { - if (!first && !dt9812[i].usb && dt9812[i].serial == 0) - first = &dt9812[i]; - if (!best && dt9812[i].serial == dev->serial) - best = &dt9812[i]; - } - - if (!best) - best = first; - - if (best) { - down(&best->mutex); - best->usb = dev; - dev->slot = best; - up(&best->mutex); - } + if (devpriv->device != DT9812_DEVID_DT9812_10 && + devpriv->device != DT9812_DEVID_DT9812_2PT5) { + dev_err(dev->class_dev, "Unsupported device!\n"); + return -EINVAL; } - up(&dt9812_mutex); return 0; - -error: - if (dev) - kref_put(&dev->kref, dt9812_delete); - return retval; } -static void dt9812_disconnect(struct usb_interface *interface) +static int dt9812_auto_attach(struct comedi_device *dev, + unsigned long context) { - struct usb_dt9812 *dev; - int minor = interface->minor; - - down(&dt9812_mutex); - dev = usb_get_intfdata(interface); - if (dev->slot) { - down(&dev->slot->mutex); - dev->slot->usb = NULL; - up(&dev->slot->mutex); - dev->slot = NULL; - } - usb_set_intfdata(interface, NULL); - up(&dt9812_mutex); - - /* queue final destruction */ - kref_put(&dev->kref, dt9812_delete); - - dev_info(&interface->dev, "USB Dt9812 #%d now disconnected\n", minor); -} - -static struct usb_driver dt9812_usb_driver = { - .name = "dt9812", - .probe = dt9812_probe, - .disconnect = dt9812_disconnect, - .id_table = dt9812_table, -}; - -/* - * Comedi functions - */ - -static int dt9812_comedi_open(struct comedi_device *dev) -{ - struct comedi_dt9812 *devpriv = dev->private; - int result = -ENODEV; - - down(&devpriv->slot->mutex); - if (devpriv->slot->usb) { - /* We have an attached device, fill in current range info */ - struct comedi_subdevice *s; - - s = &dev->subdevices[0]; - s->n_chan = 8; - s->maxdata = 1; - - s = &dev->subdevices[1]; - s->n_chan = 8; - s->maxdata = 1; - - s = &dev->subdevices[2]; - s->n_chan = 8; - switch (devpriv->slot->usb->device) { - case 0:{ - s->maxdata = 4095; - s->range_table = &range_bipolar10; - } - break; - case 1:{ - s->maxdata = 4095; - s->range_table = &range_unipolar2_5; - } - break; - } - - s = &dev->subdevices[3]; - s->n_chan = 2; - switch (devpriv->slot->usb->device) { - case 0:{ - s->maxdata = 4095; - s->range_table = &range_bipolar10; - } - break; - case 1:{ - s->maxdata = 4095; - s->range_table = &range_unipolar2_5; - } - break; - } - result = 0; - } - up(&devpriv->slot->mutex); - return result; -} - -static int dt9812_di_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, struct comedi_insn *insn, - unsigned int *data) -{ - struct comedi_dt9812 *devpriv = dev->private; - unsigned int channel = CR_CHAN(insn->chanspec); - int n; - u8 bits = 0; - - dt9812_digital_in(devpriv->slot, &bits); - for (n = 0; n < insn->n; n++) - data[n] = ((1 << channel) & bits) != 0; - return n; -} - -static int dt9812_do_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, struct comedi_insn *insn, - unsigned int *data) -{ - struct comedi_dt9812 *devpriv = dev->private; - unsigned int channel = CR_CHAN(insn->chanspec); - int n; - u8 bits = 0; - - dt9812_digital_out_shadow(devpriv->slot, &bits); - for (n = 0; n < insn->n; n++) { - u8 mask = 1 << channel; - - bits &= ~mask; - if (data[n]) - bits |= mask; - } - dt9812_digital_out(devpriv->slot, bits); - return n; -} - -static int dt9812_ai_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, struct comedi_insn *insn, - unsigned int *data) -{ - struct comedi_dt9812 *devpriv = dev->private; - unsigned int channel = CR_CHAN(insn->chanspec); - int n; - - for (n = 0; n < insn->n; n++) { - u16 value = 0; - - dt9812_analog_in(devpriv->slot, channel, &value, DT9812_GAIN_1); - data[n] = value; - } - return n; -} - -static int dt9812_ao_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, struct comedi_insn *insn, - unsigned int *data) -{ - struct comedi_dt9812 *devpriv = dev->private; - unsigned int channel = CR_CHAN(insn->chanspec); - int n; - u16 value; - - for (n = 0; n < insn->n; n++) { - value = 0; - dt9812_analog_out_shadow(devpriv->slot, channel, &value); - data[n] = value; - } - return n; -} - -static int dt9812_ao_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, struct comedi_insn *insn, - unsigned int *data) -{ - struct comedi_dt9812 *devpriv = dev->private; - unsigned int channel = CR_CHAN(insn->chanspec); - int n; - - for (n = 0; n < insn->n; n++) - dt9812_analog_out(devpriv->slot, channel, data[n]); - return n; -} - -static int dt9812_attach(struct comedi_device *dev, struct comedi_devconfig *it) -{ - struct comedi_dt9812 *devpriv; - int i; + struct usb_interface *intf = comedi_to_usb_interface(dev); + struct dt9812_private *devpriv; struct comedi_subdevice *s; + bool is_unipolar; int ret; devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); @@ -1017,125 +786,107 @@ static int dt9812_attach(struct comedi_device *dev, struct comedi_devconfig *it) return -ENOMEM; dev->private = devpriv; - /* - * Special open routine, since USB unit may be unattached at - * comedi_config time, hence range can not be determined - */ - dev->open = dt9812_comedi_open; + sema_init(&devpriv->sem, 1); + usb_set_intfdata(intf, devpriv); - devpriv->serial = it->options[0]; + ret = dt9812_find_endpoints(dev); + if (ret) + return ret; + + ret = dt9812_reset_device(dev); + if (ret) + return ret; + + is_unipolar = (devpriv->device == DT9812_DEVID_DT9812_2PT5); ret = comedi_alloc_subdevices(dev, 4); if (ret) return ret; - /* digital input subdevice */ + /* Digital Input subdevice */ s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_read = &dt9812_di_rinsn; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = dt9812_di_insn_bits; - /* digital output subdevice */ + /* Digital Output subdevice */ s = &dev->subdevices[1]; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITEABLE; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_write = &dt9812_do_winsn; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = dt9812_do_insn_bits; - /* analog input subdevice */ + /* Analog Input subdevice */ s = &dev->subdevices[2]; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_GROUND; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = NULL; - s->insn_read = &dt9812_ai_rinsn; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = 8; + s->maxdata = 0x0fff; + s->range_table = is_unipolar ? &range_unipolar2_5 : &range_bipolar10; + s->insn_read = dt9812_ai_insn_read; - /* analog output subdevice */ + /* Analog Output subdevice */ s = &dev->subdevices[3]; - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITEABLE; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = NULL; - s->insn_write = &dt9812_ao_winsn; - s->insn_read = &dt9812_ao_rinsn; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 2; + s->maxdata = 0x0fff; + s->range_table = is_unipolar ? &range_unipolar2_5 : &range_bipolar10; + s->insn_write = dt9812_ao_insn_write; + s->insn_read = dt9812_ao_insn_read; - dev_info(dev->class_dev, "successfully attached to dt9812.\n"); - - down(&dt9812_mutex); - /* Find a slot for the comedi device */ - { - struct slot_dt9812 *first = NULL; - struct slot_dt9812 *best = NULL; - for (i = 0; i < DT9812_NUM_SLOTS; i++) { - if (!first && !dt9812[i].comedi) { - /* First free slot from comedi side */ - first = &dt9812[i]; - } - if (!best && - dt9812[i].usb && - dt9812[i].usb->serial == devpriv->serial) { - /* We have an attaced device with matching ID */ - best = &dt9812[i]; - } - } - if (!best) - best = first; - if (best) { - down(&best->mutex); - best->comedi = devpriv; - best->serial = devpriv->serial; - devpriv->slot = best; - up(&best->mutex); - } - } - up(&dt9812_mutex); + devpriv->ao_shadow[0] = is_unipolar ? 0x0000 : 0x0800; + devpriv->ao_shadow[1] = is_unipolar ? 0x0000 : 0x0800; return 0; } static void dt9812_detach(struct comedi_device *dev) { - /* Nothing to cleanup */ + struct usb_interface *intf = comedi_to_usb_interface(dev); + struct dt9812_private *devpriv = dev->private; + + if (!devpriv) + return; + + down(&devpriv->sem); + + usb_set_intfdata(intf, NULL); + + up(&devpriv->sem); } -static struct comedi_driver dt9812_comedi_driver = { - .module = THIS_MODULE, - .driver_name = "dt9812", - .attach = dt9812_attach, - .detach = dt9812_detach, +static struct comedi_driver dt9812_driver = { + .driver_name = "dt9812", + .module = THIS_MODULE, + .auto_attach = dt9812_auto_attach, + .detach = dt9812_detach, }; -static int __init usb_dt9812_init(void) +static int dt9812_usb_probe(struct usb_interface *intf, + const struct usb_device_id *id) { - int i; - - /* Initialize all driver slots */ - for (i = 0; i < DT9812_NUM_SLOTS; i++) { - sema_init(&dt9812[i].mutex, 1); - dt9812[i].serial = 0; - dt9812[i].usb = NULL; - dt9812[i].comedi = NULL; - } - dt9812[12].serial = 0x0; - - return comedi_usb_driver_register(&dt9812_comedi_driver, - &dt9812_usb_driver); + return comedi_usb_auto_config(intf, &dt9812_driver, id->driver_info); } -static void __exit usb_dt9812_exit(void) -{ - comedi_usb_driver_unregister(&dt9812_comedi_driver, &dt9812_usb_driver); -} +static const struct usb_device_id dt9812_usb_table[] = { + { USB_DEVICE(0x0867, 0x9812) }, + { } +}; +MODULE_DEVICE_TABLE(usb, dt9812_usb_table); -module_init(usb_dt9812_init); -module_exit(usb_dt9812_exit); +static struct usb_driver dt9812_usb_driver = { + .name = "dt9812", + .id_table = dt9812_usb_table, + .probe = dt9812_usb_probe, + .disconnect = comedi_usb_auto_unconfig, +}; +module_comedi_usb_driver(dt9812_driver, dt9812_usb_driver); MODULE_AUTHOR("Anders Blomdell "); MODULE_DESCRIPTION("Comedi DT9812 driver"); diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c b/drivers/staging/comedi/drivers/dyna_pci10xx.c index 93ec8e492ccc..e14dd3ae9ec6 100644 --- a/drivers/staging/comedi/drivers/dyna_pci10xx.c +++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c @@ -11,10 +11,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c b/drivers/staging/comedi/drivers/gsc_hpdi.c index 0c061df0978c..2fceff93867b 100644 --- a/drivers/staging/comedi/drivers/gsc_hpdi.c +++ b/drivers/staging/comedi/drivers/gsc_hpdi.c @@ -18,12 +18,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************/ +*/ /* * Driver: gsc_hpdi diff --git a/drivers/staging/comedi/drivers/icp_multi.c b/drivers/staging/comedi/drivers/icp_multi.c index 08ab9d6e7190..a11e015dc03d 100644 --- a/drivers/staging/comedi/drivers/icp_multi.c +++ b/drivers/staging/comedi/drivers/icp_multi.c @@ -13,11 +13,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c index 90b303ab2300..94609f4aa4c9 100644 --- a/drivers/staging/comedi/drivers/jr3_pci.c +++ b/drivers/staging/comedi/drivers/jr3_pci.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* * Driver: jr3_pci @@ -46,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -97,37 +91,6 @@ struct jr3_pci_subdev_private { int retries; }; -/* Hotplug firmware loading stuff */ -static int comedi_load_firmware(struct comedi_device *dev, const char *name, - int (*cb)(struct comedi_device *dev, - const u8 *data, size_t size)) -{ - struct pci_dev *pcidev = comedi_to_pci_dev(dev); - int result = 0; - const struct firmware *fw; - char *firmware_path; - static const char *prefix = "comedi/"; - - firmware_path = kmalloc(strlen(prefix) + strlen(name) + 1, GFP_KERNEL); - if (!firmware_path) { - result = -ENOMEM; - } else { - firmware_path[0] = '\0'; - strcat(firmware_path, prefix); - strcat(firmware_path, name); - result = request_firmware(&fw, firmware_path, &pcidev->dev); - if (result == 0) { - if (!cb) - result = -EINVAL; - else - result = cb(dev, fw->data, fw->size); - release_firmware(fw); - } - kfree(firmware_path); - } - return result; -} - static struct poll_delay_t poll_delay_min_max(int min, int max) { struct poll_delay_t result; @@ -362,8 +325,9 @@ static int read_idm_word(const u8 *data, size_t size, int *pos, return result; } -static int jr3_download_firmware(struct comedi_device *dev, const u8 *data, - size_t size) +static int jr3_download_firmware(struct comedi_device *dev, + const u8 *data, size_t size, + unsigned long context) { /* * IDM file format is: @@ -768,7 +732,9 @@ static int jr3_pci_auto_attach(struct comedi_device *dev, /* Reset DSP card */ writel(0, &devpriv->iobase->channel[0].reset); - result = comedi_load_firmware(dev, "jr3pci.idm", jr3_download_firmware); + result = comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev, + "comedi/jr3pci.idm", + jr3_download_firmware, 0); dev_dbg(dev->class_dev, "Firmare load %d\n", result); if (result < 0) @@ -778,8 +744,9 @@ static int jr3_pci_auto_attach(struct comedi_device *dev, * format: * model serial Fx Fy Fz Mx My Mz\n * - * comedi_load_firmware(dev, "jr3_offsets_table", - * jr3_download_firmware); + * comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev, + * "comedi/jr3_offsets_table", + * jr3_download_firmware, 1); */ /* diff --git a/drivers/staging/comedi/drivers/ke_counter.c b/drivers/staging/comedi/drivers/ke_counter.c index e0e64752e310..f10cf10e5fe3 100644 --- a/drivers/staging/comedi/drivers/ke_counter.c +++ b/drivers/staging/comedi/drivers/ke_counter.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: ke_counter diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c index 641e693d5d0e..c2308fd24d6a 100644 --- a/drivers/staging/comedi/drivers/me4000.c +++ b/drivers/staging/comedi/drivers/me4000.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: me4000 diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c index 09f2a9feaf7c..7533ece3670e 100644 --- a/drivers/staging/comedi/drivers/me_daq.c +++ b/drivers/staging/comedi/drivers/me_daq.c @@ -14,10 +14,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -37,7 +33,6 @@ #include #include #include -#include #include "../comedidev.h" @@ -391,7 +386,8 @@ static int me_ao_insn_read(struct comedi_device *dev, } static int me2600_xilinx_download(struct comedi_device *dev, - const u8 *data, size_t size) + const u8 *data, size_t size, + unsigned long context) { struct me_private_data *dev_private = dev->private; unsigned int value; @@ -460,22 +456,6 @@ static int me2600_xilinx_download(struct comedi_device *dev, return 0; } -static int me2600_upload_firmware(struct comedi_device *dev) -{ - struct pci_dev *pcidev = comedi_to_pci_dev(dev); - const struct firmware *fw; - int ret; - - ret = request_firmware(&fw, ME2600_FIRMWARE, &pcidev->dev); - if (ret) - return ret; - - ret = me2600_xilinx_download(dev, fw->data, fw->size); - release_firmware(fw); - - return ret; -} - static int me_reset(struct comedi_device *dev) { struct me_private_data *dev_private = dev->private; @@ -529,7 +509,9 @@ static int me_auto_attach(struct comedi_device *dev, /* Download firmware and reset card */ if (board->needs_firmware) { - ret = me2600_upload_firmware(dev); + ret = comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev, + ME2600_FIRMWARE, + me2600_xilinx_download, 0); if (ret < 0) return ret; } diff --git a/drivers/staging/comedi/drivers/mite.c b/drivers/staging/comedi/drivers/mite.c index 523c6564ffca..12c34db61d63 100644 --- a/drivers/staging/comedi/drivers/mite.c +++ b/drivers/staging/comedi/drivers/mite.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* diff --git a/drivers/staging/comedi/drivers/mite.h b/drivers/staging/comedi/drivers/mite.h index 255b8ba9c917..d4487e888e64 100644 --- a/drivers/staging/comedi/drivers/mite.h +++ b/drivers/staging/comedi/drivers/mite.h @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _MITE_H_ diff --git a/drivers/staging/comedi/drivers/mpc624.c b/drivers/staging/comedi/drivers/mpc624.c index 4717be4ad268..713842ad6ff6 100644 --- a/drivers/staging/comedi/drivers/mpc624.c +++ b/drivers/staging/comedi/drivers/mpc624.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: mpc624 diff --git a/drivers/staging/comedi/drivers/multiq3.c b/drivers/staging/comedi/drivers/multiq3.c index 7a8292086e18..5ecd1b1666fb 100644 --- a/drivers/staging/comedi/drivers/multiq3.c +++ b/drivers/staging/comedi/drivers/multiq3.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: multiq3 diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c index d10f777b7f17..903c2ef5dd9a 100644 --- a/drivers/staging/comedi/drivers/ni_6527.c +++ b/drivers/staging/comedi/drivers/ni_6527.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: ni_6527 diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c index 3f71f0f54d3c..42a78de47316 100644 --- a/drivers/staging/comedi/drivers/ni_65xx.c +++ b/drivers/staging/comedi/drivers/ni_65xx.c @@ -17,11 +17,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: ni_65xx @@ -286,15 +281,6 @@ static inline struct ni_65xx_subdevice_private *sprivate(struct comedi_subdevice return subdev->private; } -static struct ni_65xx_subdevice_private *ni_65xx_alloc_subdevice_private(void) -{ - struct ni_65xx_subdevice_private *subdev_private = - kzalloc(sizeof(struct ni_65xx_subdevice_private), GFP_KERNEL); - if (subdev_private == NULL) - return NULL; - return subdev_private; -} - static int ni_65xx_config_filter(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) @@ -589,6 +575,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, struct pci_dev *pcidev = comedi_to_pci_dev(dev); const struct ni_65xx_board *board = NULL; struct ni_65xx_private *devpriv; + struct ni_65xx_subdevice_private *spriv; struct comedi_subdevice *s; unsigned i; int ret; @@ -637,10 +624,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, s->maxdata = 1; s->insn_config = ni_65xx_dio_insn_config; s->insn_bits = ni_65xx_dio_insn_bits; - s->private = ni_65xx_alloc_subdevice_private(); - if (s->private == NULL) + spriv = comedi_alloc_spriv(s, sizeof(*spriv)); + if (!spriv) return -ENOMEM; - sprivate(s)->base_port = 0; + spriv->base_port = 0; } else { s->type = COMEDI_SUBD_UNUSED; } @@ -654,10 +641,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, s->range_table = &range_digital; s->maxdata = 1; s->insn_bits = ni_65xx_dio_insn_bits; - s->private = ni_65xx_alloc_subdevice_private(); - if (s->private == NULL) + spriv = comedi_alloc_spriv(s, sizeof(*spriv)); + if (!spriv) return -ENOMEM; - sprivate(s)->base_port = board->num_di_ports; + spriv->base_port = board->num_di_ports; } else { s->type = COMEDI_SUBD_UNUSED; } @@ -672,10 +659,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, s->maxdata = 1; s->insn_config = ni_65xx_dio_insn_config; s->insn_bits = ni_65xx_dio_insn_bits; - s->private = ni_65xx_alloc_subdevice_private(); - if (s->private == NULL) + spriv = comedi_alloc_spriv(s, sizeof(*spriv)); + if (!spriv) return -ENOMEM; - sprivate(s)->base_port = 0; + spriv->base_port = 0; for (i = 0; i < board->num_dio_ports; ++i) { /* configure all ports for input */ writeb(0x1, @@ -730,7 +717,6 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, static void ni_65xx_detach(struct comedi_device *dev) { struct ni_65xx_private *devpriv = dev->private; - int i; if (devpriv && devpriv->mite && devpriv->mite->daq_io_addr) { writeb(0x00, @@ -739,8 +725,6 @@ static void ni_65xx_detach(struct comedi_device *dev) } if (dev->irq) free_irq(dev->irq, dev); - for (i = 0; i < dev->n_subdevices; ++i) - comedi_spriv_free(dev, i); if (devpriv) { if (devpriv->mite) { mite_unsetup(devpriv->mite); diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c index 5cdda7fe97a7..a9e000461ec7 100644 --- a/drivers/staging/comedi/drivers/ni_660x.c +++ b/drivers/staging/comedi/drivers/ni_660x.c @@ -11,10 +11,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c index 42ab6dbf9d39..1a185b9c529f 100644 --- a/drivers/staging/comedi/drivers/ni_670x.c +++ b/drivers/staging/comedi/drivers/ni_670x.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: ni_670x diff --git a/drivers/staging/comedi/drivers/ni_at_a2150.c b/drivers/staging/comedi/drivers/ni_at_a2150.c index 2d375168f36d..7ea5aa32e9d2 100644 --- a/drivers/staging/comedi/drivers/ni_at_a2150.c +++ b/drivers/staging/comedi/drivers/ni_at_a2150.c @@ -15,12 +15,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************ */ /* Driver: ni_at_a2150 diff --git a/drivers/staging/comedi/drivers/ni_at_ao.c b/drivers/staging/comedi/drivers/ni_at_ao.c index 7e5783a4f4e7..e080053c697b 100644 --- a/drivers/staging/comedi/drivers/ni_at_ao.c +++ b/drivers/staging/comedi/drivers/ni_at_ao.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: ni_at_ao diff --git a/drivers/staging/comedi/drivers/ni_atmio.c b/drivers/staging/comedi/drivers/ni_atmio.c index 4ced7ba119b0..713edd55a91b 100644 --- a/drivers/staging/comedi/drivers/ni_atmio.c +++ b/drivers/staging/comedi/drivers/ni_atmio.c @@ -14,10 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Driver: ni_atmio diff --git a/drivers/staging/comedi/drivers/ni_atmio16d.c b/drivers/staging/comedi/drivers/ni_atmio16d.c index 6c97a0925aad..da7396f94297 100644 --- a/drivers/staging/comedi/drivers/ni_atmio16d.c +++ b/drivers/staging/comedi/drivers/ni_atmio16d.c @@ -12,11 +12,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: ni_atmio16d @@ -767,7 +762,6 @@ static int atmio16d_attach(struct comedi_device *dev, static void atmio16d_detach(struct comedi_device *dev) { - comedi_spriv_free(dev, 3); reset_atmio16d(dev); comedi_legacy_detach(dev); } diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c index d067ef70e194..3c50e31ecc60 100644 --- a/drivers/staging/comedi/drivers/ni_daq_700.c +++ b/drivers/staging/comedi/drivers/ni_daq_700.c @@ -15,11 +15,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * */ /* @@ -40,7 +35,7 @@ port, bit 0; channel 8 corresponds to the input port, bit 0. Digital direction configuration: channels 0-7 output, 8-15 input (8225 device emu as port A output, port B input, port C N/A). -Analog: The input range is 0 to 4095 for -10 to +10 volts +Analog: The input range is 0 to 4095 for -10 to +10 volts IRQ is assigned but not used. Version 0.1 Original DIO only driver @@ -183,7 +178,7 @@ static int daq700_ai_rinsn(struct comedi_device *dev, */ static void daq700_ai_config(struct comedi_device *dev, struct comedi_subdevice *s) -{ +{ unsigned long iobase = dev->iobase; outb(0x80, iobase + CMD_R1); /* disable scanning, ADC to chan 0 */ diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 9b7805fda932..d3d4eb9356a7 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -18,12 +18,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************ */ /* Driver: ni_daq_dio24 @@ -71,17 +65,11 @@ static int dio24_auto_attach(struct comedi_device *dev, return 0; } -static void dio24_detach(struct comedi_device *dev) -{ - comedi_spriv_free(dev, 0); - comedi_pcmcia_disable(dev); -} - static struct comedi_driver driver_dio24 = { .driver_name = "ni_daq_dio24", .module = THIS_MODULE, .auto_attach = dio24_auto_attach, - .detach = dio24_detach, + .detach = comedi_pcmcia_disable, }; static int dio24_cs_attach(struct pcmcia_device *link) diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c index 77a7bb632580..f161e70b3a0d 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.c +++ b/drivers/staging/comedi/drivers/ni_labpc.c @@ -12,10 +12,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -88,7 +84,7 @@ #define CMD1_REG 0x00 /* W: Command 1 reg */ #define CMD1_MA(x) (((x) & 0x7) << 0) #define CMD1_TWOSCMP (1 << 3) -#define CMD1_GAIN_MASK (7 << 4) +#define CMD1_GAIN(x) (((x) & 0x7) << 4) #define CMD1_SCANEN (1 << 7) #define CMD2_REG 0x01 /* W: Command 2 reg */ #define CMD2_PRETRIG (1 << 0) @@ -153,11 +149,6 @@ enum scan_mode { MODE_MULT_CHAN_DOWN, }; -static const int labpc_plus_ai_gain_bits[] = { - 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, - 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, -}; - static const struct comedi_lrange range_labpc_plus_ai = { 16, { BIP_RANGE(5), @@ -179,13 +170,7 @@ static const struct comedi_lrange range_labpc_plus_ai = { } }; -const int labpc_1200_ai_gain_bits[] = { - 0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, - 0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, -}; -EXPORT_SYMBOL_GPL(labpc_1200_ai_gain_bits); - -const struct comedi_lrange range_labpc_1200_ai = { +static const struct comedi_lrange range_labpc_1200_ai = { 14, { BIP_RANGE(5), BIP_RANGE(2.5), @@ -203,7 +188,6 @@ const struct comedi_lrange range_labpc_1200_ai = { UNI_RANGE(0.1) } }; -EXPORT_SYMBOL_GPL(range_labpc_1200_ai); static const struct comedi_lrange range_labpc_ao = { 2, { @@ -239,25 +223,18 @@ static const struct labpc_boardinfo labpc_boards[] = { { .name = "lab-pc-1200", .ai_speed = 10000, - .register_layout = labpc_1200_layout, - .has_ao = 1, - .ai_range_table = &range_labpc_1200_ai, - .ai_range_code = labpc_1200_ai_gain_bits, .ai_scan_up = 1, + .has_ao = 1, + .is_labpc1200 = 1, }, { .name = "lab-pc-1200ai", .ai_speed = 10000, - .register_layout = labpc_1200_layout, - .ai_range_table = &range_labpc_1200_ai, - .ai_range_code = labpc_1200_ai_gain_bits, .ai_scan_up = 1, + .is_labpc1200 = 1, }, { .name = "lab-pc+", .ai_speed = 12000, - .register_layout = labpc_plus_layout, .has_ao = 1, - .ai_range_table = &range_labpc_plus_ai, - .ai_range_code = labpc_plus_ai_gain_bits, }, }; #endif @@ -326,12 +303,21 @@ static void labpc_ai_set_chan_and_gain(struct comedi_device *dev, const struct labpc_boardinfo *board = comedi_board(dev); struct labpc_private *devpriv = dev->private; + if (board->is_labpc1200) { + /* + * The LabPC-1200 boards do not have a gain + * of '0x10'. Skip the range values that would + * result in this gain. + */ + range += (range > 0) + (range > 7); + } + /* munge channel bits for differential/scan disabled mode */ if ((mode == MODE_SINGLE_CHAN || mode == MODE_SINGLE_CHAN_INTERVAL) && aref == AREF_DIFF) chan *= 2; devpriv->cmd1 = CMD1_MA(chan); - devpriv->cmd1 |= board->ai_range_code[range]; + devpriv->cmd1 |= CMD1_GAIN(range); devpriv->write_byte(devpriv->cmd1, dev->iobase + CMD1_REG); } @@ -347,7 +333,7 @@ static void labpc_setup_cmd6_reg(struct comedi_device *dev, const struct labpc_boardinfo *board = comedi_board(dev); struct labpc_private *devpriv = dev->private; - if (board->register_layout != labpc_1200_layout) + if (!board->is_labpc1200) return; /* reference inputs to ground or common? */ @@ -759,7 +745,7 @@ static int labpc_ai_cmdtest(struct comedi_device *dev, err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); stop_mask = TRIG_COUNT | TRIG_NONE; - if (board->register_layout == labpc_1200_layout) + if (board->is_labpc1200) stop_mask |= TRIG_EXT; err |= cfc_check_trigger_src(&cmd->stop_src, stop_mask); @@ -895,7 +881,7 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) /* pc-plus has no fifo-half full interrupt */ } else #endif - if (board->register_layout == labpc_1200_layout && + if (board->is_labpc1200 && /* wake-end-of-scan should interrupt on fifo not empty */ (cmd->flags & TRIG_WAKE_EOS) == 0 && /* make sure we are taking more than just a few points */ @@ -1175,7 +1161,7 @@ static irqreturn_t labpc_interrupt(int irq, void *d) /* read board status */ devpriv->stat1 = devpriv->read_byte(dev->iobase + STAT1_REG); - if (board->register_layout == labpc_1200_layout) + if (board->is_labpc1200) devpriv->stat2 = devpriv->read_byte(dev->iobase + STAT2_REG); if ((devpriv->stat1 & (STAT1_GATA0 | STAT1_CNTINT | STAT1_OVERFLOW | @@ -1201,8 +1187,7 @@ static irqreturn_t labpc_interrupt(int irq, void *d) * has occurred */ if (devpriv->stat1 & STAT1_GATA0 || - (board->register_layout == labpc_1200_layout - && devpriv->stat2 & STAT2_OUTA1)) { + (board->is_labpc1200 && devpriv->stat2 & STAT2_OUTA1)) { handle_isa_dma(dev); } } else @@ -1266,7 +1251,7 @@ static int labpc_ao_insn_write(struct comedi_device *dev, spin_unlock_irqrestore(&dev->spinlock, flags); /* set range */ - if (board->register_layout == labpc_1200_layout) { + if (board->is_labpc1200) { range = CR_RANGE(insn->chanspec); if (labpc_range_is_unipolar(s, range)) devpriv->cmd6 |= CMD6_DACUNI(channel); @@ -1603,7 +1588,7 @@ int labpc_common_attach(struct comedi_device *dev, devpriv->write_byte(devpriv->cmd2, dev->iobase + CMD2_REG); devpriv->write_byte(devpriv->cmd3, dev->iobase + CMD3_REG); devpriv->write_byte(devpriv->cmd4, dev->iobase + CMD4_REG); - if (board->register_layout == labpc_1200_layout) { + if (board->is_labpc1200) { devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG); devpriv->write_byte(devpriv->cmd6, dev->iobase + CMD6_REG); } @@ -1626,7 +1611,8 @@ int labpc_common_attach(struct comedi_device *dev, s->n_chan = 8; s->len_chanlist = 8; s->maxdata = 0x0fff; - s->range_table = board->ai_range_table; + s->range_table = board->is_labpc1200 + ? &range_labpc_1200_ai : &range_labpc_plus_ai; s->insn_read = labpc_ai_insn_read; if (dev->irq) { dev->read_subdev = s; @@ -1671,7 +1657,7 @@ int labpc_common_attach(struct comedi_device *dev, /* calibration subdevices for boards that have one */ s = &dev->subdevices[3]; - if (board->register_layout == labpc_1200_layout) { + if (board->is_labpc1200) { s->type = COMEDI_SUBD_CALIB; s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; s->n_chan = 16; @@ -1686,7 +1672,7 @@ int labpc_common_attach(struct comedi_device *dev, /* EEPROM */ s = &dev->subdevices[4]; - if (board->register_layout == labpc_1200_layout) { + if (board->is_labpc1200) { s->type = COMEDI_SUBD_MEMORY; s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; s->n_chan = EEPROM_SIZE; @@ -1703,12 +1689,6 @@ int labpc_common_attach(struct comedi_device *dev, } EXPORT_SYMBOL_GPL(labpc_common_attach); -void labpc_common_detach(struct comedi_device *dev) -{ - comedi_spriv_free(dev, 2); -} -EXPORT_SYMBOL_GPL(labpc_common_detach); - #if IS_ENABLED(CONFIG_COMEDI_NI_LABPC_ISA) static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) { @@ -1761,8 +1741,6 @@ static void labpc_detach(struct comedi_device *dev) { struct labpc_private *devpriv = dev->private; - labpc_common_detach(dev); - if (devpriv) { kfree(devpriv->dma_buffer); if (devpriv->dma_chan) diff --git a/drivers/staging/comedi/drivers/ni_labpc.h b/drivers/staging/comedi/drivers/ni_labpc.h index 4b691f5a9965..486589fa6fd8 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.h +++ b/drivers/staging/comedi/drivers/ni_labpc.h @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _NI_LABPC_H @@ -27,27 +22,17 @@ #define EEPROM_SIZE 256 /* 256 byte eeprom */ #define NUM_AO_CHAN 2 /* boards have two analog output channels */ -enum labpc_register_layout { labpc_plus_layout, labpc_1200_layout }; enum transfer_type { fifo_not_empty_transfer, fifo_half_full_transfer, isa_dma_transfer }; struct labpc_boardinfo { const char *name; - int device_id; /* device id for pci and pcmcia boards */ - int ai_speed; /* maximum input speed in nanoseconds */ - - /* 1200 has extra registers compared to pc+ */ - enum labpc_register_layout register_layout; - int has_ao; /* has analog output true/false */ - const struct comedi_lrange *ai_range_table; - const int *ai_range_code; - - /* board can auto scan up in ai channels, not just down */ - unsigned ai_scan_up:1; - - /* uses memory mapped io instead of ioports */ - unsigned has_mmio:1; + int ai_speed; /* maximum input speed in ns */ + unsigned ai_scan_up:1; /* can auto scan up in ai channels */ + unsigned has_ao:1; /* has analog outputs */ + unsigned is_labpc1200:1; /* has extra regs compared to pc+ */ + unsigned has_mmio:1; /* uses memory mapped io */ }; struct labpc_private { @@ -101,9 +86,5 @@ struct labpc_private { int labpc_common_attach(struct comedi_device *dev, unsigned int irq, unsigned long isr_flags); -void labpc_common_detach(struct comedi_device *dev); - -extern const int labpc_1200_ai_gain_bits[]; -extern const struct comedi_lrange range_labpc_1200_ai; #endif /* _NI_LABPC_H */ diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c index 9e3737c6918d..ce67f4bbb1f5 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_cs.c +++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c @@ -18,12 +18,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -************************************************************************ */ /* Driver: ni_labpc_cs @@ -76,12 +70,9 @@ NI manuals: static const struct labpc_boardinfo labpc_cs_boards[] = { { .name = "daqcard-1200", - .device_id = 0x103, .ai_speed = 10000, - .register_layout = labpc_1200_layout, .has_ao = 1, - .ai_range_table = &range_labpc_1200_ai, - .ai_range_code = labpc_1200_ai_gain_bits, + .is_labpc1200 = 1, }, }; @@ -113,17 +104,11 @@ static int labpc_auto_attach(struct comedi_device *dev, return labpc_common_attach(dev, link->irq, IRQF_SHARED); } -static void labpc_detach(struct comedi_device *dev) -{ - labpc_common_detach(dev); - comedi_pcmcia_disable(dev); -} - static struct comedi_driver driver_labpc_cs = { .driver_name = "ni_labpc_cs", .module = THIS_MODULE, .auto_attach = labpc_auto_attach, - .detach = labpc_detach, + .detach = comedi_pcmcia_disable, }; static int labpc_cs_attach(struct pcmcia_device *link) diff --git a/drivers/staging/comedi/drivers/ni_labpc_pci.c b/drivers/staging/comedi/drivers/ni_labpc_pci.c index 8e916f86ccea..6c79237b2b5c 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_pci.c +++ b/drivers/staging/comedi/drivers/ni_labpc_pci.c @@ -12,10 +12,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -50,11 +46,9 @@ static const struct labpc_boardinfo labpc_pci_boards[] = { [BOARD_NI_PCI1200] = { .name = "ni_pci-1200", .ai_speed = 10000, - .register_layout = labpc_1200_layout, - .has_ao = 1, - .ai_range_table = &range_labpc_1200_ai, - .ai_range_code = labpc_1200_ai_gain_bits, .ai_scan_up = 1, + .has_ao = 1, + .is_labpc1200 = 1, .has_mmio = 1, }, }; @@ -98,8 +92,6 @@ static void labpc_pci_detach(struct comedi_device *dev) { struct labpc_private *devpriv = dev->private; - labpc_common_detach(dev); - if (devpriv && devpriv->mite) { mite_unsetup(devpriv->mite); mite_free(devpriv->mite); diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c index 8c5dee9b3b05..3e9f544e67fc 100644 --- a/drivers/staging/comedi/drivers/ni_mio_common.c +++ b/drivers/staging/comedi/drivers/ni_mio_common.c @@ -15,11 +15,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* @@ -4077,7 +4072,6 @@ static void mio_common_detach(struct comedi_device *dev) ni_gpct_device_destroy(devpriv->counter_dev); } } - comedi_spriv_free(dev, NI_8255_DIO_SUBDEV); } static void init_ao_67xx(struct comedi_device *dev, struct comedi_subdevice *s) diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c index 888be7b89d2d..f813f5763671 100644 --- a/drivers/staging/comedi/drivers/ni_mio_cs.c +++ b/drivers/staging/comedi/drivers/ni_mio_cs.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: ni_mio_cs diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c index b5f340c186ec..5b2f72e102e1 100644 --- a/drivers/staging/comedi/drivers/ni_pcidio.c +++ b/drivers/staging/comedi/drivers/ni_pcidio.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: ni_pcidio @@ -58,7 +53,6 @@ comedi_nonfree_firmware tarball available from http://www.comedi.org #include #include #include -#include #include "../comedidev.h" @@ -971,11 +965,13 @@ static int ni_pcidio_change(struct comedi_device *dev, return 0; } -static int pci_6534_load_fpga(struct comedi_device *dev, int fpga_index, - const u8 *data, size_t data_len) +static int pci_6534_load_fpga(struct comedi_device *dev, + const u8 *data, size_t data_len, + unsigned long context) { struct nidio96_private *devpriv = dev->private; static const int timeout = 1000; + int fpga_index = context; int i; size_t j; @@ -1033,7 +1029,7 @@ static int pci_6534_load_fpga(struct comedi_device *dev, int fpga_index, static int pci_6534_reset_fpga(struct comedi_device *dev, int fpga_index) { - return pci_6534_load_fpga(dev, fpga_index, NULL, 0); + return pci_6534_load_fpga(dev, NULL, 0, fpga_index); } static int pci_6534_reset_fpgas(struct comedi_device *dev) @@ -1067,13 +1063,12 @@ static void pci_6534_init_main_fpga(struct comedi_device *dev) static int pci_6534_upload_firmware(struct comedi_device *dev) { struct nidio96_private *devpriv = dev->private; - int ret; - const struct firmware *fw; static const char *const fw_file[3] = { FW_PCI_6534_SCARAB_DI, /* loaded into scarab A for DI */ FW_PCI_6534_SCARAB_DO, /* loaded into scarab B for DO */ FW_PCI_6534_MAIN, /* loaded into main FPGA */ }; + int ret; int n; ret = pci_6534_reset_fpgas(dev); @@ -1081,14 +1076,11 @@ static int pci_6534_upload_firmware(struct comedi_device *dev) return ret; /* load main FPGA first, then the two scarabs */ for (n = 2; n >= 0; n--) { - ret = request_firmware(&fw, fw_file[n], - &devpriv->mite->pcidev->dev); - if (ret == 0) { - ret = pci_6534_load_fpga(dev, n, fw->data, fw->size); - if (ret == 0 && n == 2) - pci_6534_init_main_fpga(dev); - release_firmware(fw); - } + ret = comedi_load_firmware(dev, &devpriv->mite->pcidev->dev, + fw_file[n], + pci_6534_load_fpga, n); + if (ret == 0 && n == 2) + pci_6534_init_main_fpga(dev); if (ret < 0) break; } diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c index 634d02303aa0..35681ba1f369 100644 --- a/drivers/staging/comedi/drivers/ni_pcimio.c +++ b/drivers/staging/comedi/drivers/ni_pcimio.c @@ -14,10 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Driver: ni_pcimio diff --git a/drivers/staging/comedi/drivers/ni_stc.h b/drivers/staging/comedi/drivers/ni_stc.h index 0a613c077608..11bf0aab82ea 100644 --- a/drivers/staging/comedi/drivers/ni_stc.h +++ b/drivers/staging/comedi/drivers/ni_stc.h @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c index 225287769dc1..f2cf76d15d78 100644 --- a/drivers/staging/comedi/drivers/ni_tio.c +++ b/drivers/staging/comedi/drivers/ni_tio.c @@ -13,10 +13,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* diff --git a/drivers/staging/comedi/drivers/ni_tio.h b/drivers/staging/comedi/drivers/ni_tio.h index 8572996539fa..7e13697b3254 100644 --- a/drivers/staging/comedi/drivers/ni_tio.h +++ b/drivers/staging/comedi/drivers/ni_tio.h @@ -13,11 +13,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _COMEDI_NI_TIO_H diff --git a/drivers/staging/comedi/drivers/ni_tio_internal.h b/drivers/staging/comedi/drivers/ni_tio_internal.h index 5e00212aa022..b009876754a8 100644 --- a/drivers/staging/comedi/drivers/ni_tio_internal.h +++ b/drivers/staging/comedi/drivers/ni_tio_internal.h @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _COMEDI_NI_TIO_INTERNAL_H diff --git a/drivers/staging/comedi/drivers/ni_tiocmd.c b/drivers/staging/comedi/drivers/ni_tiocmd.c index 13747f324936..cff50bc45bcd 100644 --- a/drivers/staging/comedi/drivers/ni_tiocmd.c +++ b/drivers/staging/comedi/drivers/ni_tiocmd.c @@ -13,10 +13,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* diff --git a/drivers/staging/comedi/drivers/pcl711.c b/drivers/staging/comedi/drivers/pcl711.c index 8be2a4c503cc..7abf3f74144e 100644 --- a/drivers/staging/comedi/drivers/pcl711.c +++ b/drivers/staging/comedi/drivers/pcl711.c @@ -17,11 +17,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: pcl711 diff --git a/drivers/staging/comedi/drivers/pcl724.c b/drivers/staging/comedi/drivers/pcl724.c index 4f033d88eeca..cea657c7801d 100644 --- a/drivers/staging/comedi/drivers/pcl724.c +++ b/drivers/staging/comedi/drivers/pcl724.c @@ -1,42 +1,28 @@ /* - comedi/drivers/pcl724.c + * pcl724.c + * Comedi driver for 8255 based ISA DIO boards + * + * Michal Dobes + */ - Michal Dobes - - hardware driver for Advantech cards: - card: PCL-724, PCL-722, PCL-731 - driver: pcl724, pcl722, pcl731 - and ADLink cards: - card: ACL-7122, ACL-7124, PET-48DIO - driver: acl7122, acl7124, pet48dio - - Options for PCL-724, PCL-731, ACL-7124 and PET-48DIO: - [0] - IO Base - - Options for PCL-722 and ACL-7122: - [0] - IO Base - [1] - IRQ (0=disable IRQ) IRQ isn't supported at this time! - [2] -number of DIO: - 0, 144: 144 DIO configuration - 1, 96: 96 DIO configuration -*/ /* -Driver: pcl724 -Description: Advantech PCL-724, PCL-722, PCL-731 ADLink ACL-7122, ACL-7124, - PET-48DIO -Author: Michal Dobes -Devices: [Advantech] PCL-724 (pcl724), PCL-722 (pcl722), PCL-731 (pcl731), - [ADLink] ACL-7122 (acl7122), ACL-7124 (acl7124), PET-48DIO (pet48dio) -Status: untested - -This is driver for digital I/O boards PCL-722/724/731 with 144/24/48 DIO -and for digital I/O boards ACL-7122/7124/PET-48DIO with 144/24/48 DIO. -It need 8255.o for operations and only immediate mode is supported. -See the source for configuration details. -*/ -/* - * check_driver overrides: - * struct comedi_insn + * Driver: pcl724 + * Description: Comedi driver for 8255 based ISA DIO boards + * Devices: (Advantech) PCL-724 [pcl724] + * (Advantech) PCL-722 [pcl722] + * (Advantech) PCL-731 [pcl731] + * (ADLink) ACL-7122 [acl7122] + * (ADLink) ACL-7124 [acl7124] + * (ADLink) PET-48DIO [pet48dio] + * Author: Michal Dobes + * Status: untested + * + * Configuration options: + * [0] - IO Base + * [1] - IRQ (not supported) + * [2] - number of DIO (pcl722 and acl7122 boards) + * 0, 144: 144 DIO configuration + * 1, 96: 96 DIO configuration */ #include "../comedidev.h" @@ -46,40 +32,48 @@ See the source for configuration details. #include "8255.h" -#define PCL722_SIZE 32 -#define PCL722_96_SIZE 16 -#define PCL724_SIZE 4 -#define PCL731_SIZE 8 -#define PET48_SIZE 2 - #define SIZE_8255 4 -/* #define PCL724_IRQ 1 no IRQ support now */ - struct pcl724_board { - - const char *name; /* board name */ - int dio; /* num of DIO */ - int numofports; /* num of 8255 subdevices */ - unsigned int IRQbits; /* allowed interrupts */ - unsigned int io_range; /* len of IO space */ - char can_have96; - char is_pet48; + const char *name; + unsigned int io_range; + unsigned int can_have96:1; + unsigned int is_pet48:1; + int numofports; }; -static int subdev_8255_cb(int dir, int port, int data, unsigned long arg) -{ - unsigned long iobase = arg; +static const struct pcl724_board boardtypes[] = { + { + .name = "pcl724", + .io_range = 0x04, + .numofports = 1, /* 24 DIO channels */ + }, { + .name = "pcl722", + .io_range = 0x20, + .can_have96 = 1, + .numofports = 6, /* 144 (or 96) DIO channels */ + }, { + .name = "pcl731", + .io_range = 0x08, + .numofports = 2, /* 48 DIO channels */ + }, { + .name = "acl7122", + .io_range = 0x20, + .can_have96 = 1, + .numofports = 6, /* 144 (or 96) DIO channels */ + }, { + .name = "acl7124", + .io_range = 0x04, + .numofports = 1, /* 24 DIO channels */ + }, { + .name = "pet48dio", + .io_range = 0x02, + .is_pet48 = 1, + .numofports = 2, /* 48 DIO channels */ + }, +}; - if (dir) { - outb(data, iobase + port); - return 0; - } else { - return inb(iobase + port); - } -} - -static int subdev_8255mapped_cb(int dir, int port, int data, +static int pcl724_8255mapped_io(int dir, int port, int data, unsigned long iobase) { int movport = SIZE_8255 * (iobase >> 12); @@ -96,58 +90,31 @@ static int subdev_8255mapped_cb(int dir, int port, int data, } } -static int pcl724_attach(struct comedi_device *dev, struct comedi_devconfig *it) +static int pcl724_attach(struct comedi_device *dev, + struct comedi_devconfig *it) { const struct pcl724_board *board = comedi_board(dev); struct comedi_subdevice *s; + unsigned long iobase; unsigned int iorange; - int ret, i, n_subdevices; -#ifdef PCL724_IRQ - unsigned int irq; -#endif + int n_subdevices; + int ret; + int i; iorange = board->io_range; - if ((board->can_have96) && - ((it->options[1] == 1) || (it->options[1] == 96))) - iorange = PCL722_96_SIZE; /* PCL-724 in 96 DIO configuration */ + n_subdevices = board->numofports; + + /* Handle PCL-724 in 96 DIO configuration */ + if (board->can_have96 && + (it->options[2] == 1 || it->options[2] == 96)) { + iorange = 0x10; + n_subdevices = 4; + } + ret = comedi_request_region(dev, it->options[0], iorange); if (ret) return ret; -#ifdef PCL724_IRQ - irq = 0; - if (board->IRQbits != 0) { /* board support IRQ */ - irq = it->options[1]; - if (irq) { /* we want to use IRQ */ - if (((1 << irq) & board->IRQbits) == 0) { - printk(KERN_WARNING - ", IRQ %u is out of allowed range, " - "DISABLING IT", irq); - irq = 0; /* Bad IRQ */ - } else { - if (request_irq(irq, interrupt_pcl724, 0, - dev->board_name, dev)) { - printk(KERN_WARNING - ", unable to allocate IRQ %u, " - "DISABLING IT", irq); - irq = 0; /* Can't use IRQ */ - } else { - printk(", irq=%u", irq); - } - } - } - } - - dev->irq = irq; -#endif - - printk("\n"); - - n_subdevices = board->numofports; - if ((board->can_have96) && ((it->options[1] == 1) - || (it->options[1] == 96))) - n_subdevices = 4; /* PCL-724 in 96 DIO configuration */ - ret = comedi_alloc_subdevices(dev, n_subdevices); if (ret) return ret; @@ -155,41 +122,25 @@ static int pcl724_attach(struct comedi_device *dev, struct comedi_devconfig *it) for (i = 0; i < dev->n_subdevices; i++) { s = &dev->subdevices[i]; if (board->is_pet48) { - subdev_8255_init(dev, s, subdev_8255mapped_cb, - (unsigned long)(dev->iobase + - i * 0x1000)); - } else - subdev_8255_init(dev, s, subdev_8255_cb, - (unsigned long)(dev->iobase + - SIZE_8255 * i)); + iobase = dev->iobase + (i * 0x1000); + ret = subdev_8255_init(dev, s, pcl724_8255mapped_io, + iobase); + } else { + iobase = dev->iobase + (i * SIZE_8255); + ret = subdev_8255_init(dev, s, NULL, iobase); + } + if (ret) + return ret; } return 0; } -static void pcl724_detach(struct comedi_device *dev) -{ - int i; - - for (i = 0; i < dev->n_subdevices; i++) - comedi_spriv_free(dev, i); - comedi_legacy_detach(dev); -} - -static const struct pcl724_board boardtypes[] = { - { "pcl724", 24, 1, 0x00fc, PCL724_SIZE, 0, 0, }, - { "pcl722", 144, 6, 0x00fc, PCL722_SIZE, 1, 0, }, - { "pcl731", 48, 2, 0x9cfc, PCL731_SIZE, 0, 0, }, - { "acl7122", 144, 6, 0x9ee8, PCL722_SIZE, 1, 0, }, - { "acl7124", 24, 1, 0x00fc, PCL724_SIZE, 0, 0, }, - { "pet48dio", 48, 2, 0x9eb8, PET48_SIZE, 0, 1, }, -}; - static struct comedi_driver pcl724_driver = { .driver_name = "pcl724", .module = THIS_MODULE, .attach = pcl724_attach, - .detach = pcl724_detach, + .detach = comedi_legacy_detach, .board_name = &boardtypes[0].name, .num_names = ARRAY_SIZE(boardtypes), .offset = sizeof(struct pcl724_board), @@ -197,5 +148,5 @@ static struct comedi_driver pcl724_driver = { module_comedi_driver(pcl724_driver); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_DESCRIPTION("Comedi driver for 8255 based ISA DIO boards"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/pcl725.c b/drivers/staging/comedi/drivers/pcl725.c deleted file mode 100644 index 6b02f0631b4c..000000000000 --- a/drivers/staging/comedi/drivers/pcl725.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * comedi/drivers/pcl725.c - * Driver for PCL725 and clones - * David A. Schleef - */ -/* -Driver: pcl725 -Description: Advantech PCL-725 (& compatibles) -Author: ds -Status: unknown -Devices: [Advantech] PCL-725 (pcl725) -*/ - -#include "../comedidev.h" - -#include - -#define PCL725_SIZE 2 - -#define PCL725_DO 0 -#define PCL725_DI 1 - -static int pcl725_do_insn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - if (data[0]) { - s->state &= ~data[0]; - s->state |= (data[0] & data[1]); - outb(s->state, dev->iobase + PCL725_DO); - } - - data[1] = s->state; - - return insn->n; -} - -static int pcl725_di_insn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - data[1] = inb(dev->iobase + PCL725_DI); - - return insn->n; -} - -static int pcl725_attach(struct comedi_device *dev, struct comedi_devconfig *it) -{ - struct comedi_subdevice *s; - int ret; - - ret = comedi_request_region(dev, it->options[0], PCL725_SIZE); - if (ret) - return ret; - - ret = comedi_alloc_subdevices(dev, 2); - if (ret) - return ret; - - s = &dev->subdevices[0]; - /* do */ - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->maxdata = 1; - s->n_chan = 8; - s->insn_bits = pcl725_do_insn; - s->range_table = &range_digital; - - s = &dev->subdevices[1]; - /* di */ - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->maxdata = 1; - s->n_chan = 8; - s->insn_bits = pcl725_di_insn; - s->range_table = &range_digital; - - printk(KERN_INFO "\n"); - - return 0; -} - -static struct comedi_driver pcl725_driver = { - .driver_name = "pcl725", - .module = THIS_MODULE, - .attach = pcl725_attach, - .detach = comedi_legacy_detach, -}; -module_comedi_driver(pcl725_driver); - -MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/pcl726.c b/drivers/staging/comedi/drivers/pcl726.c index 4aa994393fae..893f012a1b7a 100644 --- a/drivers/staging/comedi/drivers/pcl726.c +++ b/drivers/staging/comedi/drivers/pcl726.c @@ -20,11 +20,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: pcl726 diff --git a/drivers/staging/comedi/drivers/pcl730.c b/drivers/staging/comedi/drivers/pcl730.c index 2879db75da3e..862e75fd68fd 100644 --- a/drivers/staging/comedi/drivers/pcl730.c +++ b/drivers/staging/comedi/drivers/pcl730.c @@ -3,135 +3,299 @@ * Driver for Advantech PCL-730 and clones * José Luis Sánchez */ -/* -Driver: pcl730 -Description: Advantech PCL-730 (& compatibles) -Author: José Luis Sánchez (jsanchezv@teleline.es) -Status: untested -Devices: [Advantech] PCL-730 (pcl730), [ICP] ISO-730 (iso730), - [Adlink] ACL-7130 (acl7130) -Interrupts are not supported. -The ACL-7130 card have an 8254 timer/counter not supported by this driver. -*/ +/* + * Driver: pcl730 + * Description: Advantech PCL-730 (& compatibles) + * Devices: (Advantech) PCL-730 [pcl730] + * (ICP) ISO-730 [iso730] + * (Adlink) ACL-7130 [acl7130] + * (Advantech) PCM-3730 [pcm3730] + * (Advantech) PCL-725 [pcl725] + * (ICP) P8R8-DIO [p16r16dio] + * (Adlink) ACL-7225b [acl7225b] + * (ICP) P16R16-DIO [p16r16dio] + * (Advantech) PCL-733 [pcl733] + * (Advantech) PCL-734 [pcl734] + * Author: José Luis Sánchez (jsanchezv@teleline.es) + * Status: untested + * + * Configuration options: + * [0] - I/O port base + * + * Interrupts are not supported. + * The ACL-7130 card has an 8254 timer/counter not supported by this driver. + */ #include "../comedidev.h" #include -#define PCL730_SIZE 4 -#define ACL7130_SIZE 8 -#define PCL730_IDIO_LO 0 /* Isolated Digital I/O low byte (ID0-ID7) */ -#define PCL730_IDIO_HI 1 /* Isolated Digital I/O high byte (ID8-ID15) */ -#define PCL730_DIO_LO 2 /* TTL Digital I/O low byte (D0-D7) */ -#define PCL730_DIO_HI 3 /* TTL Digital I/O high byte (D8-D15) */ +/* + * Register map + * + * The register map varies slightly depending on the board type but + * all registers are 8-bit. + * + * The boardinfo 'io_range' is used to allow comedi to request the + * proper range required by the board. + * + * The comedi_subdevice 'private' data is used to pass the register + * offset to the (*insn_bits) functions to read/write the correct + * registers. + * + * The basic register mapping looks like this: + * + * BASE+0 Isolated outputs 0-7 (write) / inputs 0-7 (read) + * BASE+1 Isolated outputs 8-15 (write) / inputs 8-15 (read) + * BASE+2 TTL outputs 0-7 (write) / inputs 0-7 (read) + * BASE+3 TTL outputs 8-15 (write) / inputs 8-15 (read) + * + * The pcm3730 board does not have register BASE+1. + * + * The pcl725 and p8r8dio only have registers BASE+0 and BASE+1: + * + * BASE+0 Isolated outputs 0-7 (write) (read back on p8r8dio) + * BASE+1 Isolated inputs 0-7 (read) + * + * The acl7225b and p16r16dio boards have this register mapping: + * + * BASE+0 Isolated outputs 0-7 (write) (read back) + * BASE+1 Isolated outputs 8-15 (write) (read back) + * BASE+2 Isolated inputs 0-7 (read) + * BASE+3 Isolated inputs 8-15 (read) + * + * The pcl733 and pcl733 boards have this register mapping: + * + * BASE+0 Isolated outputs 0-7 (write) or inputs 0-7 (read) + * BASE+1 Isolated outputs 8-15 (write) or inputs 8-15 (read) + * BASE+2 Isolated outputs 16-23 (write) or inputs 16-23 (read) + * BASE+3 Isolated outputs 24-31 (write) or inputs 24-31 (read) + */ struct pcl730_board { - - const char *name; /* board name */ - unsigned int io_range; /* len of I/O space */ + const char *name; + unsigned int io_range; + unsigned is_pcl725:1; + unsigned is_acl7225b:1; + unsigned has_readback:1; + unsigned has_ttl_io:1; + int n_subdevs; + int n_iso_out_chan; + int n_iso_in_chan; + int n_ttl_chan; }; -static int pcl730_do_insn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static const struct pcl730_board pcl730_boards[] = { + { + .name = "pcl730", + .io_range = 0x04, + .has_ttl_io = 1, + .n_subdevs = 4, + .n_iso_out_chan = 16, + .n_iso_in_chan = 16, + .n_ttl_chan = 16, + }, { + .name = "iso730", + .io_range = 0x04, + .n_subdevs = 4, + .n_iso_out_chan = 16, + .n_iso_in_chan = 16, + .n_ttl_chan = 16, + }, { + .name = "acl7130", + .io_range = 0x08, + .has_ttl_io = 1, + .n_subdevs = 4, + .n_iso_out_chan = 16, + .n_iso_in_chan = 16, + .n_ttl_chan = 16, + }, { + .name = "pcm3730", + .io_range = 0x04, + .has_ttl_io = 1, + .n_subdevs = 4, + .n_iso_out_chan = 8, + .n_iso_in_chan = 8, + .n_ttl_chan = 16, + }, { + .name = "pcl725", + .io_range = 0x02, + .is_pcl725 = 1, + .n_subdevs = 2, + .n_iso_out_chan = 8, + .n_iso_in_chan = 8, + }, { + .name = "p8r8dio", + .io_range = 0x02, + .is_pcl725 = 1, + .has_readback = 1, + .n_subdevs = 2, + .n_iso_out_chan = 8, + .n_iso_in_chan = 8, + }, { + .name = "acl7225b", + .io_range = 0x08, /* only 4 are used */ + .is_acl7225b = 1, + .has_readback = 1, + .n_subdevs = 2, + .n_iso_out_chan = 16, + .n_iso_in_chan = 16, + }, { + .name = "p16r16dio", + .io_range = 0x04, + .is_acl7225b = 1, + .has_readback = 1, + .n_subdevs = 2, + .n_iso_out_chan = 16, + .n_iso_in_chan = 16, + }, { + .name = "pcl733", + .io_range = 0x04, + .n_subdevs = 1, + .n_iso_in_chan = 32, + }, { + .name = "pcl734", + .io_range = 0x04, + .n_subdevs = 1, + .n_iso_out_chan = 32, + }, +}; + +static int pcl730_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - if (data[0]) { - s->state &= ~data[0]; - s->state |= (data[0] & data[1]); + unsigned long reg = (unsigned long)s->private; + unsigned int mask = data[0]; + unsigned int bits = data[1]; + + if (mask) { + s->state &= ~mask; + s->state |= (bits & mask); + + if (mask & 0x00ff) + outb(s->state & 0xff, dev->iobase + reg); + if ((mask & 0xff00) && (s->n_chan > 8)) + outb((s->state >> 8) & 0xff, dev->iobase + reg + 1); + if ((mask & 0xff0000) && (s->n_chan > 16)) + outb((s->state >> 16) & 0xff, dev->iobase + reg + 2); + if ((mask & 0xff000000) && (s->n_chan > 24)) + outb((s->state >> 24) & 0xff, dev->iobase + reg + 3); } - if (data[0] & 0x00ff) - outb(s->state & 0xff, - dev->iobase + ((unsigned long)s->private)); - if (data[0] & 0xff00) - outb((s->state >> 8), - dev->iobase + ((unsigned long)s->private) + 1); data[1] = s->state; return insn->n; } -static int pcl730_di_insn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static unsigned int pcl730_get_bits(struct comedi_device *dev, + struct comedi_subdevice *s) { - data[1] = inb(dev->iobase + ((unsigned long)s->private)) | - (inb(dev->iobase + ((unsigned long)s->private) + 1) << 8); + unsigned long reg = (unsigned long)s->private; + unsigned int val; + + val = inb(dev->iobase + reg); + if (s->n_chan > 8) + val |= (inb(dev->iobase + reg + 1) << 8); + if (s->n_chan > 16) + val |= (inb(dev->iobase + reg + 2) << 16); + if (s->n_chan > 24) + val |= (inb(dev->iobase + reg + 3) << 24); + + return val; +} + +static int pcl730_di_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + data[1] = pcl730_get_bits(dev, s); return insn->n; } -static int pcl730_attach(struct comedi_device *dev, struct comedi_devconfig *it) +static int pcl730_attach(struct comedi_device *dev, + struct comedi_devconfig *it) { const struct pcl730_board *board = comedi_board(dev); struct comedi_subdevice *s; + int subdev; int ret; ret = comedi_request_region(dev, it->options[0], board->io_range); if (ret) return ret; - ret = comedi_alloc_subdevices(dev, 4); + ret = comedi_alloc_subdevices(dev, board->n_subdevs); if (ret) return ret; - s = &dev->subdevices[0]; - /* Isolated do */ - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->maxdata = 1; - s->n_chan = 16; - s->insn_bits = pcl730_do_insn; - s->range_table = &range_digital; - s->private = (void *)PCL730_IDIO_LO; + subdev = 0; - s = &dev->subdevices[1]; - /* Isolated di */ - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->maxdata = 1; - s->n_chan = 16; - s->insn_bits = pcl730_di_insn; - s->range_table = &range_digital; - s->private = (void *)PCL730_IDIO_LO; + if (board->n_iso_out_chan) { + /* Isolated Digital Outputs */ + s = &dev->subdevices[subdev++]; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = board->n_iso_out_chan; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = pcl730_do_insn_bits; + s->private = (void *)0; - s = &dev->subdevices[2]; - /* TTL do */ - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->maxdata = 1; - s->n_chan = 16; - s->insn_bits = pcl730_do_insn; - s->range_table = &range_digital; - s->private = (void *)PCL730_DIO_LO; + /* get the initial state if supported */ + if (board->has_readback) + s->state = pcl730_get_bits(dev, s); + } - s = &dev->subdevices[3]; - /* TTL di */ - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->maxdata = 1; - s->n_chan = 16; - s->insn_bits = pcl730_di_insn; - s->range_table = &range_digital; - s->private = (void *)PCL730_DIO_LO; + if (board->n_iso_in_chan) { + /* Isolated Digital Inputs */ + s = &dev->subdevices[subdev++]; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = board->n_iso_in_chan; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = pcl730_di_insn_bits; + s->private = board->is_acl7225b ? (void *)2 : + board->is_pcl725 ? (void *)1 : (void *)0; + } - printk(KERN_INFO "\n"); + if (board->has_ttl_io) { + /* TTL Digital Outputs */ + s = &dev->subdevices[subdev++]; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = board->n_ttl_chan; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = pcl730_do_insn_bits; + s->private = (void *)2; + + /* TTL Digital Inputs */ + s = &dev->subdevices[subdev++]; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = board->n_ttl_chan; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = pcl730_di_insn_bits; + s->private = (void *)2; + } return 0; } -static const struct pcl730_board boardtypes[] = { - { "pcl730", PCL730_SIZE, }, - { "iso730", PCL730_SIZE, }, - { "acl7130", ACL7130_SIZE, }, -}; - static struct comedi_driver pcl730_driver = { .driver_name = "pcl730", .module = THIS_MODULE, .attach = pcl730_attach, .detach = comedi_legacy_detach, - .board_name = &boardtypes[0].name, - .num_names = ARRAY_SIZE(boardtypes), + .board_name = &pcl730_boards[0].name, + .num_names = ARRAY_SIZE(pcl730_boards), .offset = sizeof(struct pcl730_board), }; module_comedi_driver(pcl730_driver); diff --git a/drivers/staging/comedi/drivers/pcm3724.c b/drivers/staging/comedi/drivers/pcm3724.c index 4ef0df30b07a..5a9cd38e15f2 100644 --- a/drivers/staging/comedi/drivers/pcm3724.c +++ b/drivers/staging/comedi/drivers/pcm3724.c @@ -250,20 +250,11 @@ static int pcm3724_attach(struct comedi_device *dev, return 0; } -static void pcm3724_detach(struct comedi_device *dev) -{ - int i; - - for (i = 0; i < dev->n_subdevices; i++) - comedi_spriv_free(dev, i); - comedi_legacy_detach(dev); -} - static struct comedi_driver pcm3724_driver = { .driver_name = "pcm3724", .module = THIS_MODULE, .attach = pcm3724_attach, - .detach = pcm3724_detach, + .detach = comedi_legacy_detach, }; module_comedi_driver(pcm3724_driver); diff --git a/drivers/staging/comedi/drivers/pcm3730.c b/drivers/staging/comedi/drivers/pcm3730.c deleted file mode 100644 index 3a3ce2c769a2..000000000000 --- a/drivers/staging/comedi/drivers/pcm3730.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * comedi/drivers/pcm3730.c - * Driver for PCM3730 and clones - * Blaine Lee - * from pcl725 by David S. - */ -/* -Driver: pcm3730 -Description: PCM3730 -Author: Blaine Lee -Devices: [Advantech] PCM-3730 (pcm3730) -Status: unknown - -Configuration options: - [0] - I/O port base -*/ - -#include "../comedidev.h" - -#include - -#define PCM3730_SIZE 4 /* consecutive io port addresses */ - -#define PCM3730_DOA 0 /* offsets for each port */ -#define PCM3730_DOB 2 -#define PCM3730_DOC 3 -#define PCM3730_DIA 0 -#define PCM3730_DIB 2 -#define PCM3730_DIC 3 - -static int pcm3730_do_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - if (data[0]) { - s->state &= ~data[0]; - s->state |= (data[0] & data[1]); - outb(s->state, dev->iobase + (unsigned long)(s->private)); - } - data[1] = s->state; - - return insn->n; -} - -static int pcm3730_di_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - data[1] = inb(dev->iobase + (unsigned long)(s->private)); - return insn->n; -} - -static int pcm3730_attach(struct comedi_device *dev, - struct comedi_devconfig *it) -{ - struct comedi_subdevice *s; - int ret; - - ret = comedi_request_region(dev, it->options[0], PCM3730_SIZE); - if (ret) - return ret; - - ret = comedi_alloc_subdevices(dev, 6); - if (ret) - return ret; - - s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->maxdata = 1; - s->n_chan = 8; - s->insn_bits = pcm3730_do_insn_bits; - s->range_table = &range_digital; - s->private = (void *)PCM3730_DOA; - - s = &dev->subdevices[1]; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->maxdata = 1; - s->n_chan = 8; - s->insn_bits = pcm3730_do_insn_bits; - s->range_table = &range_digital; - s->private = (void *)PCM3730_DOB; - - s = &dev->subdevices[2]; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->maxdata = 1; - s->n_chan = 8; - s->insn_bits = pcm3730_do_insn_bits; - s->range_table = &range_digital; - s->private = (void *)PCM3730_DOC; - - s = &dev->subdevices[3]; - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->maxdata = 1; - s->n_chan = 8; - s->insn_bits = pcm3730_di_insn_bits; - s->range_table = &range_digital; - s->private = (void *)PCM3730_DIA; - - s = &dev->subdevices[4]; - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->maxdata = 1; - s->n_chan = 8; - s->insn_bits = pcm3730_di_insn_bits; - s->range_table = &range_digital; - s->private = (void *)PCM3730_DIB; - - s = &dev->subdevices[5]; - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->maxdata = 1; - s->n_chan = 8; - s->insn_bits = pcm3730_di_insn_bits; - s->range_table = &range_digital; - s->private = (void *)PCM3730_DIC; - - printk(KERN_INFO "\n"); - - return 0; -} - -static struct comedi_driver pcm3730_driver = { - .driver_name = "pcm3730", - .module = THIS_MODULE, - .attach = pcm3730_attach, - .detach = comedi_legacy_detach, -}; -module_comedi_driver(pcm3730_driver); - -MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/pcmad.c b/drivers/staging/comedi/drivers/pcmad.c index b7c932e152e0..d5c728dc6192 100644 --- a/drivers/staging/comedi/drivers/pcmad.c +++ b/drivers/staging/comedi/drivers/pcmad.c @@ -1,53 +1,45 @@ /* - comedi/drivers/pcmad.c - Hardware driver for Winsystems PCM-A/D12 and PCM-A/D16 + * pcmad.c + * Hardware driver for Winsystems PCM-A/D12 and PCM-A/D16 + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000,2001 David A. Schleef + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 2000,2001 David A. Schleef - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ /* -Driver: pcmad -Description: Winsystems PCM-A/D12, PCM-A/D16 -Author: ds -Devices: [Winsystems] PCM-A/D12 (pcmad12), PCM-A/D16 (pcmad16) -Status: untested + * Driver: pcmad + * Description: Winsystems PCM-A/D12, PCM-A/D16 + * Devices: (Winsystems) PCM-A/D12 [pcmad12] + * (Winsystems) PCM-A/D16 [pcmad16] + * Author: ds + * Status: untested + * + * This driver was written on a bet that I couldn't write a driver + * in less than 2 hours. I won the bet, but never got paid. =( + * + * Configuration options: + * [0] - I/O port base + * [1] - IRQ (unused) + * [2] - Analog input reference (must match jumpers) + * 0 = single-ended (16 channels) + * 1 = differential (8 channels) + * [3] - Analog input encoding (must match jumpers) + * 0 = straight binary (0-5V input range) + * 1 = two's complement (+-10V input range) + */ -This driver was written on a bet that I couldn't write a driver -in less than 2 hours. I won the bet, but never got paid. =( - -Configuration options: - [0] - I/O port base - [1] - unused - [2] - Analog input reference - 0 = single ended - 1 = differential - [3] - Analog input encoding (must match jumpers) - 0 = straight binary - 1 = two's complement -*/ - -#include #include "../comedidev.h" -#include - -#define PCMAD_SIZE 4 - #define PCMAD_STATUS 0 #define PCMAD_LSB 1 #define PCMAD_MSB 2 @@ -55,60 +47,82 @@ Configuration options: struct pcmad_board_struct { const char *name; - int n_ai_bits; + unsigned int ai_maxdata; }; -struct pcmad_priv_struct { - int differential; - int twos_comp; +static const struct pcmad_board_struct pcmad_boards[] = { + { + .name = "pcmad12", + .ai_maxdata = 0x0fff, + }, { + .name = "pcmad16", + .ai_maxdata = 0xffff, + }, }; #define TIMEOUT 100 -static int pcmad_ai_insn_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int pcmad_ai_wait_for_eoc(struct comedi_device *dev, + int timeout) { - const struct pcmad_board_struct *board = comedi_board(dev); - struct pcmad_priv_struct *devpriv = dev->private; int i; - int chan; - int n; - chan = CR_CHAN(insn->chanspec); - - for (n = 0; n < insn->n; n++) { - outb(chan, dev->iobase + PCMAD_CONVERT); - - for (i = 0; i < TIMEOUT; i++) { - if ((inb(dev->iobase + PCMAD_STATUS) & 0x3) == 0x3) - break; - } - data[n] = inb(dev->iobase + PCMAD_LSB); - data[n] |= (inb(dev->iobase + PCMAD_MSB) << 8); - - if (devpriv->twos_comp) - data[n] ^= (1 << (board->n_ai_bits - 1)); + for (i = 0; i < timeout; i++) { + if ((inb(dev->iobase + PCMAD_STATUS) & 0x3) == 0x3) + return 0; } - - return n; + return -ETIME; +} + +static bool pcmad_range_is_bipolar(struct comedi_subdevice *s, + unsigned int range) +{ + return s->range_table->range[range].min < 0; +} + +static int pcmad_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int range = CR_RANGE(insn->chanspec); + unsigned int val; + int ret; + int i; + + for (i = 0; i < insn->n; i++) { + outb(chan, dev->iobase + PCMAD_CONVERT); + + ret = pcmad_ai_wait_for_eoc(dev, TIMEOUT); + if (ret) + return ret; + + val = inb(dev->iobase + PCMAD_LSB) | + (inb(dev->iobase + PCMAD_MSB) << 8); + + /* data is shifted on the pcmad12, fix it */ + if (s->maxdata == 0x0fff) + val >>= 4; + + if (pcmad_range_is_bipolar(s, range)) { + /* munge the two's complement value */ + val ^= ((s->maxdata + 1) >> 1); + } + + data[i] = val; + } + + return insn->n; } -/* - * options: - * 0 i/o base - * 1 unused - * 2 0=single ended 1=differential - * 3 0=straight binary 1=two's comp - */ static int pcmad_attach(struct comedi_device *dev, struct comedi_devconfig *it) { const struct pcmad_board_struct *board = comedi_board(dev); - struct pcmad_priv_struct *devpriv; struct comedi_subdevice *s; int ret; - ret = comedi_request_region(dev, it->options[0], PCMAD_SIZE); + ret = comedi_request_region(dev, it->options[0], 0x04); if (ret) return ret; @@ -116,32 +130,25 @@ static int pcmad_attach(struct comedi_device *dev, struct comedi_devconfig *it) if (ret) return ret; - devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); - if (!devpriv) - return -ENOMEM; - dev->private = devpriv; - s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | AREF_GROUND; - s->n_chan = 16; /* XXX */ - s->len_chanlist = 1; - s->insn_read = pcmad_ai_insn_read; - s->maxdata = (1 << board->n_ai_bits) - 1; - s->range_table = &range_unknown; + s->type = COMEDI_SUBD_AI; + if (it->options[1]) { + /* 8 differential channels */ + s->subdev_flags = SDF_READABLE | AREF_DIFF; + s->n_chan = 8; + } else { + /* 16 single-ended channels */ + s->subdev_flags = SDF_READABLE | AREF_GROUND; + s->n_chan = 16; + } + s->len_chanlist = 1; + s->maxdata = board->ai_maxdata; + s->range_table = it->options[2] ? &range_bipolar10 : &range_unipolar5; + s->insn_read = pcmad_ai_insn_read; return 0; } -static const struct pcmad_board_struct pcmad_boards[] = { - { - .name = "pcmad12", - .n_ai_bits = 12, - }, { - .name = "pcmad16", - .n_ai_bits = 16, - }, -}; static struct comedi_driver pcmad_driver = { .driver_name = "pcmad", .module = THIS_MODULE, diff --git a/drivers/staging/comedi/drivers/pcmda12.c b/drivers/staging/comedi/drivers/pcmda12.c index 61e7fd14a1e8..774a63dfe040 100644 --- a/drivers/staging/comedi/drivers/pcmda12.c +++ b/drivers/staging/comedi/drivers/pcmda12.c @@ -1,152 +1,130 @@ /* - comedi/drivers/pcmda12.c - Driver for Winsystems PC-104 based PCM-D/A-12 8-channel AO board. + * pcmda12.c + * Driver for Winsystems PC-104 based PCM-D/A-12 8-channel AO board. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2006 Calin A. Culianu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 2006 Calin A. Culianu - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ /* -Driver: pcmda12 -Description: A driver for the Winsystems PCM-D/A-12 -Devices: [Winsystems] PCM-D/A-12 (pcmda12) -Author: Calin Culianu -Updated: Fri, 13 Jan 2006 12:01:01 -0500 -Status: works - -A driver for the relatively straightforward-to-program PCM-D/A-12. -This board doesn't support commands, and the only way to set its -analog output range is to jumper the board. As such, -comedi_data_write() ignores the range value specified. - -The board uses 16 consecutive I/O addresses starting at the I/O port -base address. Each address corresponds to the LSB then MSB of a -particular channel from 0-7. - -Note that the board is not ISA-PNP capable and thus -needs the I/O port comedi_config parameter. - -Note that passing a nonzero value as the second config option will -enable "simultaneous xfer" mode for this board, in which AO writes -will not take effect until a subsequent read of any AO channel. This -is so that one can speed up programming by preloading all AO registers -with values before simultaneously setting them to take effect with one -read command. - -Configuration Options: - [0] - I/O port base address - [1] - Do Simultaneous Xfer (see description) -*/ + * Driver: pcmda12 + * Description: A driver for the Winsystems PCM-D/A-12 + * Devices: (Winsystems) PCM-D/A-12 [pcmda12] + * Author: Calin Culianu + * Updated: Fri, 13 Jan 2006 12:01:01 -0500 + * Status: works + * + * A driver for the relatively straightforward-to-program PCM-D/A-12. + * This board doesn't support commands, and the only way to set its + * analog output range is to jumper the board. As such, + * comedi_data_write() ignores the range value specified. + * + * The board uses 16 consecutive I/O addresses starting at the I/O port + * base address. Each address corresponds to the LSB then MSB of a + * particular channel from 0-7. + * + * Note that the board is not ISA-PNP capable and thus needs the I/O + * port comedi_config parameter. + * + * Note that passing a nonzero value as the second config option will + * enable "simultaneous xfer" mode for this board, in which AO writes + * will not take effect until a subsequent read of any AO channel. This + * is so that one can speed up programming by preloading all AO registers + * with values before simultaneously setting them to take effect with one + * read command. + * + * Configuration Options: + * [0] - I/O port base address + * [1] - Do Simultaneous Xfer (see description) + */ #include "../comedidev.h" -#define CHANS 8 -#define IOSIZE 16 -#define LSB(x) ((unsigned char)((x) & 0xff)) -#define MSB(x) ((unsigned char)((((unsigned short)(x))>>8) & 0xff)) -#define LSB_PORT(chan) (dev->iobase + (chan)*2) -#define MSB_PORT(chan) (LSB_PORT(chan)+1) -#define BITS 12 - -/* note these have no effect and are merely here for reference.. - these are configured by jumpering the board! */ +/* AI range is not configurable, it's set by jumpers on the board */ static const struct comedi_lrange pcmda12_ranges = { - 3, - { - UNI_RANGE(5), UNI_RANGE(10), BIP_RANGE(5) - } + 3, { + UNI_RANGE(5), + UNI_RANGE(10), + BIP_RANGE(5) + } }; struct pcmda12_private { - - unsigned int ao_readback[CHANS]; + unsigned int ao_readback[8]; int simultaneous_xfer_mode; }; -static void zero_chans(struct comedi_device *dev) -{ /* sets up an - ASIC chip to defaults */ - int i; - for (i = 0; i < CHANS; ++i) { -/* /\* do this as one instruction?? *\/ */ -/* outw(0, LSB_PORT(chan)); */ - outb(0, LSB_PORT(i)); - outb(0, MSB_PORT(i)); - } - inb(LSB_PORT(0)); /* update chans. */ -} - -static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int pcmda12_ao_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct pcmda12_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int val = devpriv->ao_readback[chan]; + unsigned long ioreg = dev->iobase + (chan * 2); int i; - int chan = CR_CHAN(insn->chanspec); - /* Writing a list of values to an AO channel is probably not - * very useful, but that's how the interface is defined. */ for (i = 0; i < insn->n; ++i) { + val = data[i]; + outb(val & 0xff, ioreg); + outb((val >> 8) & 0xff, ioreg + 1); -/* /\* do this as one instruction?? *\/ */ -/* outw(data[i], LSB_PORT(chan)); */ - - /* Need to do this as two instructions due to 8-bit bus?? */ - /* first, load the low byte */ - outb(LSB(data[i]), LSB_PORT(chan)); - /* next, write the high byte */ - outb(MSB(data[i]), MSB_PORT(chan)); - - /* save shadow register */ - devpriv->ao_readback[chan] = data[i]; - + /* + * Initiate transfer if not in simultaneaous xfer + * mode by reading one of the AO registers. + */ if (!devpriv->simultaneous_xfer_mode) - inb(LSB_PORT(chan)); + inb(ioreg); } + devpriv->ao_readback[chan] = val; - /* return the number of samples written */ - return i; + return insn->n; } -/* AO subdevices should have a read insn as well as a write insn. - - Usually this means copying a value stored in devpriv->ao_readback. - However, since this driver supports simultaneous xfer then sometimes - this function actually accomplishes work. - - Simultaneaous xfer mode is accomplished by loading ALL the values - you want for AO in all the channels, then READing off one of the AO - registers to initiate the instantaneous simultaneous update of all - DAC outputs, which makes all AO channels update simultaneously. - This is useful for some control applications, I would imagine. -*/ -static int ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int pcmda12_ao_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct pcmda12_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); int i; - int chan = CR_CHAN(insn->chanspec); - for (i = 0; i < insn->n; i++) { - if (devpriv->simultaneous_xfer_mode) - inb(LSB_PORT(chan)); - /* read back shadow register */ + /* + * Initiate simultaneaous xfer mode by reading one of the + * AO registers. All analog outputs will then be updated. + */ + if (devpriv->simultaneous_xfer_mode) + inb(dev->iobase); + + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_readback[chan]; - } - return i; + return insn->n; +} + +static void pcmda12_ao_reset(struct comedi_device *dev, + struct comedi_subdevice *s) +{ + int i; + + for (i = 0; i < s->n_chan; ++i) { + outb(0, dev->iobase + (i * 2)); + outb(0, dev->iobase + (i * 2) + 1); + } + /* Initiate transfer by reading one of the AO registers. */ + inb(dev->iobase); } static int pcmda12_attach(struct comedi_device *dev, @@ -156,7 +134,7 @@ static int pcmda12_attach(struct comedi_device *dev, struct comedi_subdevice *s; int ret; - ret = comedi_request_region(dev, it->options[0], IOSIZE); + ret = comedi_request_region(dev, it->options[0], 0x10); if (ret) return ret; @@ -172,18 +150,17 @@ static int pcmda12_attach(struct comedi_device *dev, return ret; s = &dev->subdevices[0]; - s->private = NULL; - s->maxdata = (0x1 << BITS) - 1; - s->range_table = &pcmda12_ranges; - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE; - s->n_chan = CHANS; - s->insn_write = &ao_winsn; - s->insn_read = &ao_rinsn; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 0x0fff; + s->range_table = &pcmda12_ranges; + s->insn_write = pcmda12_ao_insn_write; + s->insn_read = pcmda12_ao_insn_read; - zero_chans(dev); /* clear out all the registers, basically */ + pcmda12_ao_reset(dev, s); - return 1; + return 0; } static struct comedi_driver pcmda12_driver = { diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c index 5a236cd5b33d..9f76b1f59983 100644 --- a/drivers/staging/comedi/drivers/pcmmio.c +++ b/drivers/staging/comedi/drivers/pcmmio.c @@ -14,10 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Driver: pcmmio diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c index 0c98e26bbba1..c43b6334ceae 100644 --- a/drivers/staging/comedi/drivers/pcmuio.c +++ b/drivers/staging/comedi/drivers/pcmuio.c @@ -1,79 +1,77 @@ /* - comedi/drivers/pcmuio.c - Driver for Winsystems PC-104 based 48-channel and 96-channel DIO boards. + * pcmuio.c + * Comedi driver for Winsystems PC-104 based 48/96-channel DIO boards. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2006 Calin A. Culianu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 2006 Calin A. Culianu - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ /* -Driver: pcmuio -Description: A driver for the PCM-UIO48A and PCM-UIO96A boards from Winsystems. -Devices: [Winsystems] PCM-UIO48A (pcmuio48), PCM-UIO96A (pcmuio96) -Author: Calin Culianu -Updated: Fri, 13 Jan 2006 12:01:01 -0500 -Status: works - -A driver for the relatively straightforward-to-program PCM-UIO48A and -PCM-UIO96A boards from Winsystems. These boards use either one or two -(in the 96-DIO version) WS16C48 ASIC HighDensity I/O Chips (HDIO). -This chip is interesting in that each I/O line is individually -programmable for INPUT or OUTPUT (thus comedi_dio_config can be done -on a per-channel basis). Also, each chip supports edge-triggered -interrupts for the first 24 I/O lines. Of course, since the -96-channel version of the board has two ASICs, it can detect polarity -changes on up to 48 I/O lines. Since this is essentially an (non-PnP) -ISA board, I/O Address and IRQ selection are done through jumpers on -the board. You need to pass that information to this driver as the -first and second comedi_config option, respectively. Note that the -48-channel version uses 16 bytes of IO memory and the 96-channel -version uses 32-bytes (in case you are worried about conflicts). The -48-channel board is split into two 24-channel comedi subdevices. -The 96-channel board is split into 4 24-channel DIO subdevices. - -Note that IRQ support has been added, but it is untested. - -To use edge-detection IRQ support, pass the IRQs of both ASICS -(for the 96 channel version) or just 1 ASIC (for 48-channel version). -Then, use use comedi_commands with TRIG_NOW. -Your callback will be called each time an edge is triggered, and the data -values will be two sample_t's, which should be concatenated to form one -32-bit unsigned int. This value is the mask of channels that had -edges detected from your channel list. Note that the bits positions -in the mask correspond to positions in your chanlist when you specified -the command and *not* channel id's! - -To set the polarity of the edge-detection interrupts pass a nonzero value for -either CR_RANGE or CR_AREF for edge-up polarity, or a zero value for both -CR_RANGE and CR_AREF if you want edge-down polarity. - -In the 48-channel version: - -On subdev 0, the first 24 channels channels are edge-detect channels. - -In the 96-channel board you have the collowing channels that can do edge detection: - -subdev 0, channels 0-24 (first 24 channels of 1st ASIC) -subdev 2, channels 0-24 (first 24 channels of 2nd ASIC) - -Configuration Options: - [0] - I/O port base address - [1] - IRQ (for first ASIC, or first 24 channels) - [2] - IRQ for second ASIC (pcmuio96 only - IRQ for chans 48-72 .. can be the same as first irq!) -*/ + * Driver: pcmuio + * Description: Winsystems PC-104 based 48/96-channel DIO boards. + * Devices: (Winsystems) PCM-UIO48A [pcmuio48] + * (Winsystems) PCM-UIO96A [pcmuio96] + * Author: Calin Culianu + * Updated: Fri, 13 Jan 2006 12:01:01 -0500 + * Status: works + * + * A driver for the relatively straightforward-to-program PCM-UIO48A and + * PCM-UIO96A boards from Winsystems. These boards use either one or two + * (in the 96-DIO version) WS16C48 ASIC HighDensity I/O Chips (HDIO). This + * chip is interesting in that each I/O line is individually programmable + * for INPUT or OUTPUT (thus comedi_dio_config can be done on a per-channel + * basis). Also, each chip supports edge-triggered interrupts for the first + * 24 I/O lines. Of course, since the 96-channel version of the board has + * two ASICs, it can detect polarity changes on up to 48 I/O lines. Since + * this is essentially an (non-PnP) ISA board, I/O Address and IRQ selection + * are done through jumpers on the board. You need to pass that information + * to this driver as the first and second comedi_config option, respectively. + * Note that the 48-channel version uses 16 bytes of IO memory and the 96- + * channel version uses 32-bytes (in case you are worried about conflicts). + * The 48-channel board is split into two 24-channel comedi subdevices. The + * 96-channel board is split into 4 24-channel DIO subdevices. + * + * Note that IRQ support has been added, but it is untested. + * + * To use edge-detection IRQ support, pass the IRQs of both ASICS (for the + * 96 channel version) or just 1 ASIC (for 48-channel version). Then, use + * comedi_commands with TRIG_NOW. Your callback will be called each time an + * edge is triggered, and the data values will be two sample_t's, which + * should be concatenated to form one 32-bit unsigned int. This value is + * the mask of channels that had edges detected from your channel list. Note + * that the bits positions in the mask correspond to positions in your + * chanlist when you specified the command and *not* channel id's! + * + * To set the polarity of the edge-detection interrupts pass a nonzero value + * for either CR_RANGE or CR_AREF for edge-up polarity, or a zero value for + * both CR_RANGE and CR_AREF if you want edge-down polarity. + * + * In the 48-channel version: + * + * On subdev 0, the first 24 channels channels are edge-detect channels. + * + * In the 96-channel board you have the following channels that can do edge + * detection: + * + * subdev 0, channels 0-24 (first 24 channels of 1st ASIC) + * subdev 2, channels 0-24 (first 24 channels of 2nd ASIC) + * + * Configuration Options: + * [0] - I/O port base address + * [1] - IRQ (for first ASIC, or first 24 channels) + * [2] - IRQ (for second ASIC, pcmuio96 only - IRQ for chans 48-72 + * can be the same as first irq!) + */ #include #include @@ -82,94 +80,62 @@ Configuration Options: #include "comedi_fc.h" -#define CHANS_PER_PORT 8 -#define PORTS_PER_ASIC 6 -#define INTR_PORTS_PER_ASIC 3 -#define MAX_CHANS_PER_SUBDEV 24 /* number of channels per comedi subdevice */ -#define PORTS_PER_SUBDEV (MAX_CHANS_PER_SUBDEV/CHANS_PER_PORT) -#define CHANS_PER_ASIC (CHANS_PER_PORT*PORTS_PER_ASIC) -#define INTR_CHANS_PER_ASIC 24 -#define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT) -#define MAX_DIO_CHANS (PORTS_PER_ASIC*2*CHANS_PER_PORT) -#define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC) -#define CALC_N_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) /*+ (nchans > INTR_CHANS_PER_ASIC ? 2 : 1)*/) -/* IO Memory sizes */ -#define ASIC_IOSIZE (0x10) -#define PCMUIO48_IOSIZE ASIC_IOSIZE -#define PCMUIO96_IOSIZE (ASIC_IOSIZE*2) - -/* Some offsets - these are all in the 16byte IO memory offset from - the base address. Note that there is a paging scheme to swap out - offsets 0x8-0xA using the PAGELOCK register. See the table below. - - Register(s) Pages R/W? Description - -------------------------------------------------------------- - REG_PORTx All R/W Read/Write/Configure IO - REG_INT_PENDING All ReadOnly Quickly see which INT_IDx has int. - REG_PAGELOCK All WriteOnly Select a page - REG_POLx Pg. 1 only WriteOnly Select edge-detection polarity - REG_ENABx Pg. 2 only WriteOnly Enable/Disable edge-detect. int. - REG_INT_IDx Pg. 3 only R/W See which ports/bits have ints. - */ -#define REG_PORT0 0x0 -#define REG_PORT1 0x1 -#define REG_PORT2 0x2 -#define REG_PORT3 0x3 -#define REG_PORT4 0x4 -#define REG_PORT5 0x5 -#define REG_INT_PENDING 0x6 -#define REG_PAGELOCK 0x7 /* page selector register, upper 2 bits select a page - and bits 0-5 are used to 'lock down' a particular - port above to make it readonly. */ -#define REG_POL0 0x8 -#define REG_POL1 0x9 -#define REG_POL2 0xA -#define REG_ENAB0 0x8 -#define REG_ENAB1 0x9 -#define REG_ENAB2 0xA -#define REG_INT_ID0 0x8 -#define REG_INT_ID1 0x9 -#define REG_INT_ID2 0xA - -#define NUM_PAGED_REGS 3 -#define NUM_PAGES 4 -#define FIRST_PAGED_REG 0x8 -#define REG_PAGE_BITOFFSET 6 -#define REG_LOCK_BITOFFSET 0 -#define REG_PAGE_MASK (~((0x1<private) +static void pcmuio_write(struct comedi_device *dev, unsigned int val, + int asic, int page, int port) +{ + unsigned long iobase = dev->iobase + (asic * PCMUIO_ASIC_IOSIZE); -/* DIO devices are slightly special. Although it is possible to - * implement the insn_read/insn_write interface, it is much more - * useful to applications if you implement the insn_bits interface. - * This allows packed reading/writing of the DIO channels. The - * comedi core can convert between insn_bits and insn_read/write */ + if (page == 0) { + /* Port registers are valid for any page */ + outb(val & 0xff, iobase + PCMUIO_PORT_REG(port + 0)); + outb((val >> 8) & 0xff, iobase + PCMUIO_PORT_REG(port + 1)); + outb((val >> 16) & 0xff, iobase + PCMUIO_PORT_REG(port + 2)); + } else { + outb(PCMUIO_PAGE(page), iobase + PCMUIO_PAGE_LOCK_REG); + outb(val & 0xff, iobase + PCMUIO_PAGE_REG(0)); + outb((val >> 8) & 0xff, iobase + PCMUIO_PAGE_REG(1)); + outb((val >> 16) & 0xff, iobase + PCMUIO_PAGE_REG(2)); + } +} + +static unsigned int pcmuio_read(struct comedi_device *dev, + int asic, int page, int port) +{ + unsigned long iobase = dev->iobase + (asic * PCMUIO_ASIC_IOSIZE); + unsigned int val; + + if (page == 0) { + /* Port registers are valid for any page */ + val = inb(iobase + PCMUIO_PORT_REG(port + 0)); + val |= (inb(iobase + PCMUIO_PORT_REG(port + 1)) << 8); + val |= (inb(iobase + PCMUIO_PORT_REG(port + 2)) << 16); + } else { + outb(PCMUIO_PAGE(page), iobase + PCMUIO_PAGE_LOCK_REG); + val = inb(iobase + PCMUIO_PAGE_REG(0)); + val |= (inb(iobase + PCMUIO_PAGE_REG(1)) << 8); + val |= (inb(iobase + PCMUIO_PAGE_REG(2)) << 16); + } + + return val; +} + +/* + * Each channel can be individually programmed for input or output. + * Writing a '0' to a channel causes the corresponding output pin + * to go to a high-z state (pulled high by an external 10K resistor). + * This allows it to be used as an input. When used in the input mode, + * a read reflects the inverted state of the I/O pin, such that a + * high on the pin will read as a '0' in the register. Writing a '1' + * to a bit position causes the pin to sink current (up to 12mA), + * effectively pulling it low. + */ static int pcmuio_dio_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - int byte_no; + unsigned int mask = data[0] & s->io_bits; /* outputs only */ + unsigned int bits = data[1]; + int asic = s->index / 2; + int port = (s->index % 2) ? 3 : 0; + unsigned int val; - /* NOTE: - reading a 0 means this channel was high - writine a 0 sets the channel high - reading a 1 means this channel was low - writing a 1 means set this channel low + /* get inverted state of the channels from the port */ + val = pcmuio_read(dev, asic, 0, port); - Therefore everything is always inverted. */ + /* get the true state of the channels */ + s->state = val ^ ((0x1 << s->n_chan) - 1); - /* The insn data is a mask in data[0] and the new data - * in data[1], each channel cooresponding to a bit. */ + if (mask) { + s->state &= ~mask; + s->state |= (mask & bits); -#ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - dev_dbg(dev->class_dev, "write mask: %08x data: %08x\n", data[0], - data[1]); -#endif - - s->state = 0; - - for (byte_no = 0; byte_no < s->n_chan / CHANS_PER_PORT; ++byte_no) { - /* address of 8-bit port */ - unsigned long ioaddr = subpriv->iobases[byte_no], - /* bit offset of port in 32-bit doubleword */ - offset = byte_no * 8; - /* this 8-bit port's data */ - unsigned char byte = 0, - /* The write mask for this port (if any) */ - write_mask_byte = (data[0] >> offset) & 0xff, - /* The data byte for this port */ - data_byte = (data[1] >> offset) & 0xff; - - byte = inb(ioaddr); /* read all 8-bits for this port */ - -#ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - printk - ("byte %d wmb %02x db %02x offset %02d io %04x, data_in %02x ", - byte_no, (unsigned)write_mask_byte, (unsigned)data_byte, - offset, ioaddr, (unsigned)byte); -#endif - - if (write_mask_byte) { - /* this byte has some write_bits -- so set the output lines */ - byte &= ~write_mask_byte; /* clear bits for write mask */ - byte |= ~data_byte & write_mask_byte; /* set to inverted data_byte */ - /* Write out the new digital output state */ - outb(byte, ioaddr); - } -#ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - dev_dbg(dev->class_dev, "data_out_byte %02x\n", (unsigned)byte); -#endif - /* save the digital input lines for this byte.. */ - s->state |= ((unsigned int)byte) << offset; + /* invert the state and update the channels */ + val = s->state ^ ((0x1 << s->n_chan) - 1); + pcmuio_write(dev, val, asic, 0, port); } - /* now return the DIO lines to data[1] - note they came inverted! */ - data[1] = ~s->state; - -#ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - dev_dbg(dev->class_dev, "s->state %08x data_out %08x\n", s->state, - data[1]); -#endif + data[1] = s->state; return insn->n; } -/* The input or output configuration of each digital line is - * configured by a special insn_config instruction. chanspec - * contains the channel to be changed, and data[0] contains the - * value COMEDI_INPUT or COMEDI_OUTPUT. */ static int pcmuio_dio_insn_config(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - int chan = CR_CHAN(insn->chanspec), byte_no = chan / 8, bit_no = - chan % 8; - unsigned long ioaddr; - unsigned char byte; - - /* Compute ioaddr for this channel */ - ioaddr = subpriv->iobases[byte_no]; - - /* NOTE: - writing a 0 an IO channel's bit sets the channel to INPUT - and pulls the line high as well - - writing a 1 to an IO channel's bit pulls the line low - - All channels are implicitly always in OUTPUT mode -- but when - they are high they can be considered to be in INPUT mode.. - - Thus, we only force channels low if the config request was INPUT, - otherwise we do nothing to the hardware. */ + unsigned int chan_mask = 1 << CR_CHAN(insn->chanspec); + int asic = s->index / 2; + int port = (s->index % 2) ? 3 : 0; switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - /* save to io_bits -- don't actually do anything since - all input channels are also output channels... */ - s->io_bits |= 1 << chan; + s->io_bits |= chan_mask; break; case INSN_CONFIG_DIO_INPUT: - /* write a 0 to the actual register representing the channel - to set it to 'input'. 0 means "float high". */ - byte = inb(ioaddr); - byte &= ~(1 << bit_no); - /**< set input channel to '0' */ - - /* write out byte -- this is the only time we actually affect the - hardware as all channels are implicitly output -- but input - channels are set to float-high */ - outb(byte, ioaddr); - - /* save to io_bits */ - s->io_bits &= ~(1 << chan); + s->io_bits &= ~chan_mask; + pcmuio_write(dev, s->io_bits, asic, 0, port); break; - case INSN_CONFIG_DIO_QUERY: - /* retrieve from shadow register */ - data[1] = - (s->io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; - return insn->n; + data[1] = (s->io_bits & chan_mask) ? COMEDI_OUTPUT : COMEDI_INPUT; break; - default: return -EINVAL; break; @@ -339,100 +257,28 @@ static int pcmuio_dio_insn_config(struct comedi_device *dev, return insn->n; } -static void switch_page(struct comedi_device *dev, int asic, int page) +static void pcmuio_reset(struct comedi_device *dev) { const struct pcmuio_board *board = comedi_board(dev); - struct pcmuio_private *devpriv = dev->private; - - if (asic < 0 || asic >= board->num_asics) - return; /* paranoia */ - if (page < 0 || page >= NUM_PAGES) - return; /* more paranoia */ - - devpriv->asics[asic].pagelock &= ~REG_PAGE_MASK; - devpriv->asics[asic].pagelock |= page << REG_PAGE_BITOFFSET; - - /* now write out the shadow register */ - outb(devpriv->asics[asic].pagelock, - dev->iobase + ASIC_IOSIZE * asic + REG_PAGELOCK); -} - -static void init_asics(struct comedi_device *dev) -{ /* sets up an - ASIC chip to defaults */ - const struct pcmuio_board *board = comedi_board(dev); int asic; for (asic = 0; asic < board->num_asics; ++asic) { - int port, page; - unsigned long baseaddr = dev->iobase + asic * ASIC_IOSIZE; - - switch_page(dev, asic, 0); /* switch back to page 0 */ - /* first, clear all the DIO port bits */ - for (port = 0; port < PORTS_PER_ASIC; ++port) - outb(0, baseaddr + REG_PORT0 + port); + pcmuio_write(dev, 0, asic, 0, 0); + pcmuio_write(dev, 0, asic, 0, 3); /* Next, clear all the paged registers for each page */ - for (page = 1; page < NUM_PAGES; ++page) { - int reg; - /* now clear all the paged registers */ - switch_page(dev, asic, page); - for (reg = FIRST_PAGED_REG; - reg < FIRST_PAGED_REG + NUM_PAGED_REGS; ++reg) - outb(0, baseaddr + reg); - } - - /* DEBUG set rising edge interrupts on port0 of both asics */ - /*switch_page(dev, asic, PAGE_POL); - outb(0xff, baseaddr + REG_POL0); - switch_page(dev, asic, PAGE_ENAB); - outb(0xff, baseaddr + REG_ENAB0); */ - /* END DEBUG */ - - switch_page(dev, asic, 0); /* switch back to default page 0 */ - + pcmuio_write(dev, 0, asic, PCMUIO_PAGE_POL, 0); + pcmuio_write(dev, 0, asic, PCMUIO_PAGE_ENAB, 0); + pcmuio_write(dev, 0, asic, PCMUIO_PAGE_INT_ID, 0); } } -#ifdef notused -static void lock_port(struct comedi_device *dev, int asic, int port) -{ - const struct pcmuio_board *board = comedi_board(dev); - struct pcmuio_private *devpriv = dev->private; - - if (asic < 0 || asic >= board->num_asics) - return; /* paranoia */ - if (port < 0 || port >= PORTS_PER_ASIC) - return; /* more paranoia */ - - devpriv->asics[asic].pagelock |= 0x1 << port; - /* now write out the shadow register */ - outb(devpriv->asics[asic].pagelock, - dev->iobase + ASIC_IOSIZE * asic + REG_PAGELOCK); -} - -static void unlock_port(struct comedi_device *dev, int asic, int port) -{ - const struct pcmuio_board *board = comedi_board(dev); - struct pcmuio_private *devpriv = dev->private; - - if (asic < 0 || asic >= board->num_asics) - return; /* paranoia */ - if (port < 0 || port >= PORTS_PER_ASIC) - return; /* more paranoia */ - devpriv->asics[asic].pagelock &= ~(0x1 << port) | REG_LOCK_MASK; - /* now write out the shadow register */ - outb(devpriv->asics[asic].pagelock, - dev->iobase + ASIC_IOSIZE * asic + REG_PAGELOCK); -} -#endif /* notused */ - static void pcmuio_stop_intr(struct comedi_device *dev, struct comedi_subdevice *s) { - int nports, firstport, asic, port; - struct pcmuio_private *devpriv = dev->private; + struct pcmuio_subdev_private *subpriv = s->private; + int asic; asic = subpriv->intr.asic; if (asic < 0) @@ -441,161 +287,124 @@ static void pcmuio_stop_intr(struct comedi_device *dev, subpriv->intr.enabled_mask = 0; subpriv->intr.active = 0; s->async->inttrig = NULL; - nports = subpriv->intr.num_asic_chans / CHANS_PER_PORT; - firstport = subpriv->intr.asic_chan / CHANS_PER_PORT; - switch_page(dev, asic, PAGE_ENAB); - for (port = firstport; port < firstport + nports; ++port) { - /* disable all intrs for this subdev.. */ - outb(0, devpriv->asics[asic].iobase + REG_ENAB0 + port); - } + + /* disable all intrs for this subdev.. */ + pcmuio_write(dev, 0, asic, PCMUIO_PAGE_ENAB, 0); } -static irqreturn_t interrupt_pcmuio(int irq, void *d) +static void pcmuio_handle_intr_subdev(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned triggered) +{ + struct pcmuio_subdev_private *subpriv = s->private; + unsigned int len = s->async->cmd.chanlist_len; + unsigned oldevents = s->async->events; + unsigned int val = 0; + unsigned long flags; + unsigned mytrig; + unsigned int i; + + spin_lock_irqsave(&subpriv->intr.spinlock, flags); + + if (!subpriv->intr.active) + goto done; + + mytrig = triggered; + mytrig &= ((0x1 << s->n_chan) - 1); + + if (!(mytrig & subpriv->intr.enabled_mask)) + goto done; + + for (i = 0; i < len; i++) { + unsigned int chan = CR_CHAN(s->async->cmd.chanlist[i]); + if (mytrig & (1U << chan)) + val |= (1U << i); + } + + /* Write the scan to the buffer. */ + if (comedi_buf_put(s->async, ((short *)&val)[0]) && + comedi_buf_put(s->async, ((short *)&val)[1])) { + s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS); + } else { + /* Overflow! Stop acquisition!! */ + /* TODO: STOP_ACQUISITION_CALL_HERE!! */ + pcmuio_stop_intr(dev, s); + } + + /* Check for end of acquisition. */ + if (!subpriv->intr.continuous) { + /* stop_src == TRIG_COUNT */ + if (subpriv->intr.stop_count > 0) { + subpriv->intr.stop_count--; + if (subpriv->intr.stop_count == 0) { + s->async->events |= COMEDI_CB_EOA; + /* TODO: STOP_ACQUISITION_CALL_HERE!! */ + pcmuio_stop_intr(dev, s); + } + } + } + +done: + spin_unlock_irqrestore(&subpriv->intr.spinlock, flags); + + if (oldevents != s->async->events) + comedi_event(dev, s); +} + +static int pcmuio_handle_asic_interrupt(struct comedi_device *dev, int asic) { - int asic, got1 = 0; - struct comedi_device *dev = (struct comedi_device *)d; struct pcmuio_private *devpriv = dev->private; + struct pcmuio_subdev_private *subpriv; + unsigned long iobase = dev->iobase + (asic * PCMUIO_ASIC_IOSIZE); + unsigned int triggered = 0; + int got1 = 0; + unsigned long flags; + unsigned char int_pend; int i; - for (asic = 0; asic < MAX_ASICS; ++asic) { + spin_lock_irqsave(&devpriv->asics[asic].spinlock, flags); + + int_pend = inb(iobase + PCMUIO_INT_PENDING_REG) & 0x07; + if (int_pend) { + triggered = pcmuio_read(dev, asic, PCMUIO_PAGE_INT_ID, 0); + pcmuio_write(dev, 0, asic, PCMUIO_PAGE_INT_ID, 0); + + ++got1; + } + + spin_unlock_irqrestore(&devpriv->asics[asic].spinlock, flags); + + if (triggered) { + struct comedi_subdevice *s; + /* TODO here: dispatch io lines to subdevs with commands.. */ + for (i = 0; i < dev->n_subdevices; i++) { + s = &dev->subdevices[i]; + subpriv = s->private; + if (subpriv->intr.asic == asic) { + /* + * This is an interrupt subdev, and it + * matches this asic! + */ + pcmuio_handle_intr_subdev(dev, s, + triggered); + } + } + } + return got1; +} + +static irqreturn_t pcmuio_interrupt(int irq, void *d) +{ + struct comedi_device *dev = d; + struct pcmuio_private *devpriv = dev->private; + int got1 = 0; + int asic; + + for (asic = 0; asic < PCMUIO_MAX_ASICS; ++asic) { if (irq == devpriv->asics[asic].irq) { - unsigned long flags; - unsigned triggered = 0; - unsigned long iobase = devpriv->asics[asic].iobase; /* it is an interrupt for ASIC #asic */ - unsigned char int_pend; - - spin_lock_irqsave(&devpriv->asics[asic].spinlock, - flags); - - int_pend = inb(iobase + REG_INT_PENDING) & 0x07; - - if (int_pend) { - int port; - for (port = 0; port < INTR_PORTS_PER_ASIC; - ++port) { - if (int_pend & (0x1 << port)) { - unsigned char - io_lines_with_edges = 0; - switch_page(dev, asic, - PAGE_INT_ID); - io_lines_with_edges = - inb(iobase + - REG_INT_ID0 + port); - - if (io_lines_with_edges) - /* clear pending interrupt */ - outb(0, iobase + - REG_INT_ID0 + - port); - - triggered |= - io_lines_with_edges << - port * 8; - } - } - - ++got1; - } - - spin_unlock_irqrestore(&devpriv->asics[asic].spinlock, - flags); - - if (triggered) { - struct comedi_subdevice *s; - /* TODO here: dispatch io lines to subdevs with commands.. */ - printk - ("PCMUIO DEBUG: got edge detect interrupt %d asic %d which_chans: %06x\n", - irq, asic, triggered); - for (i = 0; i < dev->n_subdevices; i++) { - s = &dev->subdevices[i]; - if (subpriv->intr.asic == asic) { /* this is an interrupt subdev, and it matches this asic! */ - unsigned long flags; - unsigned oldevents; - - spin_lock_irqsave(&subpriv-> - intr.spinlock, - flags); - - oldevents = s->async->events; - - if (subpriv->intr.active) { - unsigned mytrig = - ((triggered >> - subpriv->intr.asic_chan) - & - ((0x1 << subpriv-> - intr. - num_asic_chans) - - 1)) << subpriv-> - intr.first_chan; - if (mytrig & - subpriv->intr.enabled_mask) - { - unsigned int val - = 0; - unsigned int n, - ch, len; - - len = - s-> - async->cmd.chanlist_len; - for (n = 0; - n < len; - n++) { - ch = CR_CHAN(s->async->cmd.chanlist[n]); - if (mytrig & (1U << ch)) { - val |= (1U << n); - } - } - /* Write the scan to the buffer. */ - if (comedi_buf_put(s->async, ((short *)&val)[0]) - && - comedi_buf_put - (s->async, - ((short *) - &val)[1])) - { - s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS); - } else { - /* Overflow! Stop acquisition!! */ - /* TODO: STOP_ACQUISITION_CALL_HERE!! */ - pcmuio_stop_intr - (dev, - s); - } - - /* Check for end of acquisition. */ - if (!subpriv->intr.continuous) { - /* stop_src == TRIG_COUNT */ - if (subpriv->intr.stop_count > 0) { - subpriv->intr.stop_count--; - if (subpriv->intr.stop_count == 0) { - s->async->events |= COMEDI_CB_EOA; - /* TODO: STOP_ACQUISITION_CALL_HERE!! */ - pcmuio_stop_intr - (dev, - s); - } - } - } - } - } - - spin_unlock_irqrestore - (&subpriv->intr.spinlock, - flags); - - if (oldevents != - s->async->events) { - comedi_event(dev, s); - } - - } - - } - } - + if (pcmuio_handle_asic_interrupt(dev, asic)) + got1++; } } if (!got1) @@ -606,7 +415,7 @@ static irqreturn_t interrupt_pcmuio(int irq, void *d) static int pcmuio_start_intr(struct comedi_device *dev, struct comedi_subdevice *s) { - struct pcmuio_private *devpriv = dev->private; + struct pcmuio_subdev_private *subpriv = s->private; if (!subpriv->intr.continuous && subpriv->intr.stop_count == 0) { /* An empty acquisition! */ @@ -615,7 +424,7 @@ static int pcmuio_start_intr(struct comedi_device *dev, return 1; } else { unsigned bits = 0, pol_bits = 0, n; - int nports, firstport, asic, port; + int asic; struct comedi_cmd *cmd = &s->async->cmd; asic = subpriv->intr.asic; @@ -624,8 +433,6 @@ static int pcmuio_start_intr(struct comedi_device *dev, subdev */ subpriv->intr.enabled_mask = 0; subpriv->intr.active = 1; - nports = subpriv->intr.num_asic_chans / CHANS_PER_PORT; - firstport = subpriv->intr.asic_chan / CHANS_PER_PORT; if (cmd->chanlist) { for (n = 0; n < cmd->chanlist_len; n++) { bits |= (1U << CR_CHAN(cmd->chanlist[n])); @@ -635,31 +442,19 @@ static int pcmuio_start_intr(struct comedi_device *dev, << CR_CHAN(cmd->chanlist[n]); } } - bits &= ((0x1 << subpriv->intr.num_asic_chans) - - 1) << subpriv->intr.first_chan; + bits &= ((0x1 << s->n_chan) - 1); subpriv->intr.enabled_mask = bits; - switch_page(dev, asic, PAGE_ENAB); - for (port = firstport; port < firstport + nports; ++port) { - unsigned enab = - bits >> (subpriv->intr.first_chan + (port - - firstport) * - 8) & 0xff, pol = - pol_bits >> (subpriv->intr.first_chan + - (port - firstport) * 8) & 0xff; - /* set enab intrs for this subdev.. */ - outb(enab, - devpriv->asics[asic].iobase + REG_ENAB0 + port); - switch_page(dev, asic, PAGE_POL); - outb(pol, - devpriv->asics[asic].iobase + REG_ENAB0 + port); - } + /* set pol and enab intrs for this subdev.. */ + pcmuio_write(dev, pol_bits, asic, PCMUIO_PAGE_POL, 0); + pcmuio_write(dev, bits, asic, PCMUIO_PAGE_ENAB, 0); } return 0; } static int pcmuio_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { + struct pcmuio_subdev_private *subpriv = s->private; unsigned long flags; spin_lock_irqsave(&subpriv->intr.spinlock, flags); @@ -677,6 +472,7 @@ static int pcmuio_inttrig_start_intr(struct comedi_device *dev, struct comedi_subdevice *s, unsigned int trignum) { + struct pcmuio_subdev_private *subpriv = s->private; unsigned long flags; int event = 0; @@ -701,6 +497,7 @@ pcmuio_inttrig_start_intr(struct comedi_device *dev, struct comedi_subdevice *s, */ static int pcmuio_cmd(struct comedi_device *dev, struct comedi_subdevice *s) { + struct pcmuio_subdev_private *subpriv = s->private; struct comedi_cmd *cmd = &s->async->cmd; unsigned long flags; int event = 0; @@ -797,17 +594,18 @@ static int pcmuio_cmdtest(struct comedi_device *dev, static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it) { const struct pcmuio_board *board = comedi_board(dev); - struct pcmuio_private *devpriv; struct comedi_subdevice *s; - int sdev_no, chans_left, n_subdevs, port, asic, thisasic_chanct = 0; - unsigned int irq[MAX_ASICS]; + struct pcmuio_private *devpriv; + struct pcmuio_subdev_private *subpriv; + int sdev_no, n_subdevs, asic; + unsigned int irq[PCMUIO_MAX_ASICS]; int ret; irq[0] = it->options[1]; irq[1] = it->options[2]; ret = comedi_request_region(dev, it->options[0], - board->num_asics * ASIC_IOSIZE); + board->num_asics * PCMUIO_ASIC_IOSIZE); if (ret) return ret; @@ -816,20 +614,11 @@ static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it) return -ENOMEM; dev->private = devpriv; - for (asic = 0; asic < MAX_ASICS; ++asic) { - devpriv->asics[asic].num = asic; - devpriv->asics[asic].iobase = dev->iobase + asic * ASIC_IOSIZE; - devpriv->asics[asic].irq = 0; /* this gets actually set at the end of - this function when we - request_irqs */ + for (asic = 0; asic < PCMUIO_MAX_ASICS; ++asic) spin_lock_init(&devpriv->asics[asic].spinlock); - } - chans_left = CHANS_PER_ASIC * board->num_asics; - n_subdevs = CALC_N_SUBDEVS(chans_left); - devpriv->sprivs = kcalloc(n_subdevs, - sizeof(struct pcmuio_subdev_private), - GFP_KERNEL); + n_subdevs = board->num_asics * 2; + devpriv->sprivs = kcalloc(n_subdevs, sizeof(*subpriv), GFP_KERNEL); if (!devpriv->sprivs) return -ENOMEM; @@ -837,74 +626,40 @@ static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it) if (ret) return ret; - port = 0; - asic = 0; for (sdev_no = 0; sdev_no < (int)dev->n_subdevices; ++sdev_no) { - int byte_no; - s = &dev->subdevices[sdev_no]; - s->private = &devpriv->sprivs[sdev_no]; + subpriv = &devpriv->sprivs[sdev_no]; + s->private = subpriv; s->maxdata = 1; s->range_table = &range_digital; s->subdev_flags = SDF_READABLE | SDF_WRITABLE; s->type = COMEDI_SUBD_DIO; s->insn_bits = pcmuio_dio_insn_bits; s->insn_config = pcmuio_dio_insn_config; - s->n_chan = min(chans_left, MAX_CHANS_PER_SUBDEV); - subpriv->intr.asic = -1; - subpriv->intr.first_chan = -1; - subpriv->intr.asic_chan = -1; - subpriv->intr.num_asic_chans = -1; - subpriv->intr.active = 0; - s->len_chanlist = 1; + s->n_chan = 24; - /* save the ioport address for each 'port' of 8 channels in the - subdevice */ - for (byte_no = 0; byte_no < PORTS_PER_SUBDEV; ++byte_no, ++port) { - if (port >= PORTS_PER_ASIC) { - port = 0; - ++asic; - thisasic_chanct = 0; - } - subpriv->iobases[byte_no] = - devpriv->asics[asic].iobase + port; - - if (thisasic_chanct < - CHANS_PER_PORT * INTR_PORTS_PER_ASIC - && subpriv->intr.asic < 0) { - /* this is an interrupt subdevice, so setup the struct */ - subpriv->intr.asic = asic; - subpriv->intr.active = 0; - subpriv->intr.stop_count = 0; - subpriv->intr.first_chan = byte_no * 8; - subpriv->intr.asic_chan = thisasic_chanct; - subpriv->intr.num_asic_chans = - s->n_chan - subpriv->intr.first_chan; - dev->read_subdev = s; - s->subdev_flags |= SDF_CMD_READ; - s->cancel = pcmuio_cancel; - s->do_cmd = pcmuio_cmd; - s->do_cmdtest = pcmuio_cmdtest; - s->len_chanlist = subpriv->intr.num_asic_chans; - } - thisasic_chanct += CHANS_PER_PORT; + /* subdevices 0 and 2 suppport interrupts */ + if ((sdev_no % 2) == 0) { + /* setup the interrupt subdevice */ + subpriv->intr.asic = sdev_no / 2; + dev->read_subdev = s; + s->subdev_flags |= SDF_CMD_READ; + s->cancel = pcmuio_cancel; + s->do_cmd = pcmuio_cmd; + s->do_cmdtest = pcmuio_cmdtest; + s->len_chanlist = s->n_chan; + } else { + subpriv->intr.asic = -1; + s->len_chanlist = 1; } spin_lock_init(&subpriv->intr.spinlock); - - chans_left -= s->n_chan; - - if (!chans_left) { - asic = 0; /* reset the asic to our first asic, to do intr subdevs */ - port = 0; - } - } - init_asics(dev); /* clear out all the registers, basically */ + pcmuio_reset(dev); - for (asic = 0; irq[0] && asic < MAX_ASICS; ++asic) { + for (asic = 0; irq[0] && asic < PCMUIO_MAX_ASICS; ++asic) { if (irq[asic] - && request_irq(irq[asic], interrupt_pcmuio, + && request_irq(irq[asic], pcmuio_interrupt, IRQF_SHARED, board->name, dev)) { int i; /* unroll the allocated irqs.. */ @@ -917,17 +672,7 @@ static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it) devpriv->asics[asic].irq = irq[asic]; } - if (irq[0]) { - dev_dbg(dev->class_dev, "irq: %u\n", irq[0]); - if (irq[1] && board->num_asics == 2) - dev_dbg(dev->class_dev, "second ASIC irq: %u\n", - irq[1]); - } else { - dev_dbg(dev->class_dev, "(IRQ mode disabled)\n"); - } - - - return 1; + return 0; } static void pcmuio_detach(struct comedi_device *dev) @@ -935,7 +680,7 @@ static void pcmuio_detach(struct comedi_device *dev) struct pcmuio_private *devpriv = dev->private; int i; - for (i = 0; i < MAX_ASICS; ++i) { + for (i = 0; i < PCMUIO_MAX_ASICS; ++i) { if (devpriv->asics[i].irq) free_irq(devpriv->asics[i].irq, dev); } @@ -944,18 +689,6 @@ static void pcmuio_detach(struct comedi_device *dev) comedi_legacy_detach(dev); } -static const struct pcmuio_board pcmuio_boards[] = { - { - .name = "pcmuio48", - .num_asics = 1, - .num_ports = 6, - }, { - .name = "pcmuio96", - .num_asics = 2, - .num_ports = 12, - }, -}; - static struct comedi_driver pcmuio_driver = { .driver_name = "pcmuio", .module = THIS_MODULE, diff --git a/drivers/staging/comedi/drivers/plx9052.h b/drivers/staging/comedi/drivers/plx9052.h index ff76fbb4b3ef..fbcf25069807 100644 --- a/drivers/staging/comedi/drivers/plx9052.h +++ b/drivers/staging/comedi/drivers/plx9052.h @@ -16,11 +16,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #ifndef _PLX9052_H_ diff --git a/drivers/staging/comedi/drivers/poc.c b/drivers/staging/comedi/drivers/poc.c index b55a16baeb14..005fbefae295 100644 --- a/drivers/staging/comedi/drivers/poc.c +++ b/drivers/staging/comedi/drivers/poc.c @@ -13,25 +13,18 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Driver: poc Description: Generic driver for very simple devices Author: ds -Devices: [Keithley Metrabyte] DAC-02 (dac02), [Advantech] PCL-733 (pcl733), - PCL-734 (pcl734) +Devices: [Keithley Metrabyte] DAC-02 (dac02) Updated: Sat, 16 Mar 2002 17:34:48 -0800 Status: unknown This driver is indended to support very simple ISA-based devices, including: dac02 - Keithley DAC-02 analog output board - pcl733 - Advantech PCL-733 - pcl734 - Advantech PCL-734 Configuration options: [0] - I/O port base @@ -101,39 +94,6 @@ static int dac02_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, return 1; } -static int pcl733_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - data[1] = inb(dev->iobase + 0); - data[1] |= (inb(dev->iobase + 1) << 8); - data[1] |= (inb(dev->iobase + 2) << 16); - data[1] |= (inb(dev->iobase + 3) << 24); - - return insn->n; -} - -static int pcl734_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - if (data[0]) { - s->state &= ~data[0]; - s->state |= (data[0] & data[1]); - if ((data[0] >> 0) & 0xff) - outb((s->state >> 0) & 0xff, dev->iobase + 0); - if ((data[0] >> 8) & 0xff) - outb((s->state >> 8) & 0xff, dev->iobase + 1); - if ((data[0] >> 16) & 0xff) - outb((s->state >> 16) & 0xff, dev->iobase + 2); - if ((data[0] >> 24) & 0xff) - outb((s->state >> 24) & 0xff, dev->iobase + 3); - } - data[1] = s->state; - - return insn->n; -} - static int poc_attach(struct comedi_device *dev, struct comedi_devconfig *it) { const struct boarddef_struct *board = comedi_board(dev); @@ -180,22 +140,6 @@ static const struct boarddef_struct boards[] = { .winsn = dac02_ao_winsn, .rinsn = readback_insn, .range = &range_unknown, - }, { - .name = "pcl733", - .iosize = 4, - .type = COMEDI_SUBD_DI, - .n_chan = 32, - .n_bits = 1, - .insnbits = pcl733_insn_bits, - .range = &range_digital, - }, { - .name = "pcl734", - .iosize = 4, - .type = COMEDI_SUBD_DO, - .n_chan = 32, - .n_bits = 1, - .insnbits = pcl734_insn_bits, - .range = &range_digital, }, }; diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c index 30a17284fac9..9b93a1fc4a59 100644 --- a/drivers/staging/comedi/drivers/rtd520.c +++ b/drivers/staging/comedi/drivers/rtd520.c @@ -14,10 +14,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* diff --git a/drivers/staging/comedi/drivers/rti800.c b/drivers/staging/comedi/drivers/rti800.c index f4163fd35a00..f698c7fc5726 100644 --- a/drivers/staging/comedi/drivers/rti800.c +++ b/drivers/staging/comedi/drivers/rti800.c @@ -14,10 +14,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* diff --git a/drivers/staging/comedi/drivers/rti802.c b/drivers/staging/comedi/drivers/rti802.c index 46dbbe6cdd76..9e7445055482 100644 --- a/drivers/staging/comedi/drivers/rti802.c +++ b/drivers/staging/comedi/drivers/rti802.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: rti802 diff --git a/drivers/staging/comedi/drivers/s526.c b/drivers/staging/comedi/drivers/s526.c index d240ce87bd68..e1587e58a732 100644 --- a/drivers/staging/comedi/drivers/s526.c +++ b/drivers/staging/comedi/drivers/s526.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: s526 diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c index 0cf4b3d1279a..48c4b70b736a 100644 --- a/drivers/staging/comedi/drivers/s626.c +++ b/drivers/staging/comedi/drivers/s626.c @@ -17,11 +17,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* diff --git a/drivers/staging/comedi/drivers/s626.h b/drivers/staging/comedi/drivers/s626.h index 99cd57b092ea..d2756b83b62d 100644 --- a/drivers/staging/comedi/drivers/s626.h +++ b/drivers/staging/comedi/drivers/s626.h @@ -17,11 +17,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c index 8900086374db..b4f5fe35b0fa 100644 --- a/drivers/staging/comedi/drivers/serial2002.c +++ b/drivers/staging/comedi/drivers/serial2002.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* diff --git a/drivers/staging/comedi/drivers/skel.c b/drivers/staging/comedi/drivers/skel.c index dbc8c54d6da7..06aee302bbc2 100644 --- a/drivers/staging/comedi/drivers/skel.c +++ b/drivers/staging/comedi/drivers/skel.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: skel diff --git a/drivers/staging/comedi/drivers/ssv_dnp.c b/drivers/staging/comedi/drivers/ssv_dnp.c index a76df092a57b..45c661cbdbb9 100644 --- a/drivers/staging/comedi/drivers/ssv_dnp.c +++ b/drivers/staging/comedi/drivers/ssv_dnp.c @@ -15,11 +15,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: ssv_dnp diff --git a/drivers/staging/comedi/drivers/unioxx5.c b/drivers/staging/comedi/drivers/unioxx5.c index 0c243477cbe5..c9201d821fbc 100644 --- a/drivers/staging/comedi/drivers/unioxx5.c +++ b/drivers/staging/comedi/drivers/unioxx5.c @@ -18,10 +18,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * * ***************************************************************************/ /* @@ -375,15 +371,13 @@ static int __unioxx5_subdev_init(struct comedi_device *dev, int i, to, ndef_flag = 0; int ret; - usp = kzalloc(sizeof(*usp), GFP_KERNEL); - if (usp == NULL) + usp = comedi_alloc_spriv(s, sizeof(*usp)); + if (!usp) return -ENOMEM; ret = __comedi_request_region(dev, iobase, UNIOXX5_SIZE); - if (ret) { - kfree(usp); + if (ret) return ret; - } usp->usp_iobase = iobase; /* defining modules types */ @@ -417,7 +411,6 @@ static int __unioxx5_subdev_init(struct comedi_device *dev, /* initial subdevice for digital or analog i/o */ s->type = COMEDI_SUBD_DIO; - s->private = usp; s->subdev_flags = SDF_READABLE | SDF_WRITABLE; s->n_chan = UNIOXX5_NUM_OF_CHANS; s->maxdata = 0xFFF; @@ -478,15 +471,15 @@ static int unioxx5_attach(struct comedi_device *dev, static void unioxx5_detach(struct comedi_device *dev) { + struct comedi_subdevice *s; + struct unioxx5_subd_priv *spriv; int i; - struct comedi_subdevice *subdev; - struct unioxx5_subd_priv *usp; for (i = 0; i < dev->n_subdevices; i++) { - subdev = &dev->subdevices[i]; - usp = subdev->private; - release_region(usp->usp_iobase, UNIOXX5_SIZE); - kfree(subdev->private); + s = &dev->subdevices[i]; + spriv = s->private; + if (spriv && spriv->usp_iobase) + release_region(spriv->usp_iobase, UNIOXX5_SIZE); } } diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c index 6f5da67e26cb..279e5bd493fa 100644 --- a/drivers/staging/comedi/drivers/usbdux.c +++ b/drivers/staging/comedi/drivers/usbdux.c @@ -11,11 +11,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: usbdux @@ -94,7 +89,6 @@ sampling rate. If you sample two channels you get 4kHz and so on. #include #include #include -#include #include "../comedidev.h" @@ -727,154 +721,82 @@ static void usbduxsub_ao_isoc_irq(struct urb *urb) } } -static int usbduxsub_start(struct usbduxsub *usbduxsub) -{ - int errcode = 0; - uint8_t *local_transfer_buffer; - - local_transfer_buffer = kmalloc(1, GFP_KERNEL); - if (!local_transfer_buffer) - return -ENOMEM; - - /* 7f92 to zero */ - *local_transfer_buffer = 0; - errcode = usb_control_msg(usbduxsub->usbdev, - /* create a pipe for a control transfer */ - usb_sndctrlpipe(usbduxsub->usbdev, 0), - /* bRequest, "Firmware" */ - USBDUXSUB_FIRMWARE, - /* bmRequestType */ - VENDOR_DIR_OUT, - /* Value */ - USBDUXSUB_CPUCS, - /* Index */ - 0x0000, - /* address of the transfer buffer */ - local_transfer_buffer, - /* Length */ - 1, - /* Timeout */ - BULK_TIMEOUT); - if (errcode < 0) - dev_err(&usbduxsub->interface->dev, - "comedi_: control msg failed (start)\n"); - - kfree(local_transfer_buffer); - return errcode; -} - -static int usbduxsub_stop(struct usbduxsub *usbduxsub) -{ - int errcode = 0; - uint8_t *local_transfer_buffer; - - local_transfer_buffer = kmalloc(1, GFP_KERNEL); - if (!local_transfer_buffer) - return -ENOMEM; - - /* 7f92 to one */ - *local_transfer_buffer = 1; - errcode = usb_control_msg(usbduxsub->usbdev, - usb_sndctrlpipe(usbduxsub->usbdev, 0), - /* bRequest, "Firmware" */ - USBDUXSUB_FIRMWARE, - /* bmRequestType */ - VENDOR_DIR_OUT, - /* Value */ - USBDUXSUB_CPUCS, - /* Index */ - 0x0000, local_transfer_buffer, - /* Length */ - 1, - /* Timeout */ - BULK_TIMEOUT); - if (errcode < 0) - dev_err(&usbduxsub->interface->dev, - "comedi_: control msg failed (stop)\n"); - - kfree(local_transfer_buffer); - return errcode; -} - -static int usbduxsub_upload(struct usbduxsub *usbduxsub, - uint8_t *local_transfer_buffer, - unsigned int start_addr, unsigned int len) -{ - int errcode; - - errcode = usb_control_msg(usbduxsub->usbdev, - usb_sndctrlpipe(usbduxsub->usbdev, 0), - /* brequest, firmware */ - USBDUXSUB_FIRMWARE, - /* bmRequestType */ - VENDOR_DIR_OUT, - /* value */ - start_addr, - /* index */ - 0x0000, - /* our local safe buffer */ - local_transfer_buffer, - /* length */ - len, - /* timeout */ - BULK_TIMEOUT); - dev_dbg(&usbduxsub->interface->dev, "comedi_: result=%d\n", errcode); - if (errcode < 0) { - dev_err(&usbduxsub->interface->dev, "comedi_: upload failed\n"); - return errcode; - } - return 0; -} - #define FIRMWARE_MAX_LEN 0x2000 -static int firmware_upload(struct usbduxsub *usbduxsub, - const u8 *firmware_binary, int size_firmware) +static int usbdux_firmware_upload(struct comedi_device *dev, + const u8 *data, size_t size, + unsigned long context) { + struct usbduxsub *usbduxsub = dev->private; + struct usb_device *usb = usbduxsub->usbdev; + uint8_t *buf; + uint8_t *tmp; int ret; - uint8_t *fw_buf; - if (!firmware_binary) + if (!data) return 0; - if (size_firmware > FIRMWARE_MAX_LEN) { + if (size > FIRMWARE_MAX_LEN) { dev_err(&usbduxsub->interface->dev, "usbdux firmware binary it too large for FX2.\n"); return -ENOMEM; } /* we generate a local buffer for the firmware */ - fw_buf = kmemdup(firmware_binary, size_firmware, GFP_KERNEL); - if (!fw_buf) { - dev_err(&usbduxsub->interface->dev, - "comedi_: mem alloc for firmware failed\n"); + buf = kmemdup(data, size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + /* we need a malloc'ed buffer for usb_control_msg() */ + tmp = kmalloc(1, GFP_KERNEL); + if (!tmp) { + kfree(buf); return -ENOMEM; } - ret = usbduxsub_stop(usbduxsub); + /* stop the current firmware on the device */ + *tmp = 1; /* 7f92 to one */ + ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), + USBDUXSUB_FIRMWARE, + VENDOR_DIR_OUT, + USBDUXSUB_CPUCS, 0x0000, + tmp, 1, + BULK_TIMEOUT); if (ret < 0) { dev_err(&usbduxsub->interface->dev, "comedi_: can not stop firmware\n"); - kfree(fw_buf); - return ret; + goto done; } - ret = usbduxsub_upload(usbduxsub, fw_buf, 0, size_firmware); + /* upload the new firmware to the device */ + ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), + USBDUXSUB_FIRMWARE, + VENDOR_DIR_OUT, + 0, 0x0000, + buf, size, + BULK_TIMEOUT); if (ret < 0) { dev_err(&usbduxsub->interface->dev, "comedi_: firmware upload failed\n"); - kfree(fw_buf); - return ret; + goto done; } - ret = usbduxsub_start(usbduxsub); - if (ret < 0) { + + /* start the new firmware on the device */ + *tmp = 0; /* 7f92 to zero */ + ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), + USBDUXSUB_FIRMWARE, + VENDOR_DIR_OUT, + USBDUXSUB_CPUCS, 0x0000, + tmp, 1, + BULK_TIMEOUT); + if (ret < 0) dev_err(&usbduxsub->interface->dev, "comedi_: can not start firmware\n"); - kfree(fw_buf); - return ret; - } - kfree(fw_buf); - return 0; + +done: + kfree(tmp); + kfree(buf); + return ret; } static int usbduxsub_submit_inurbs(struct usbduxsub *usbduxsub) @@ -2328,13 +2250,21 @@ static int usbdux_auto_attach(struct comedi_device *dev, unsigned long context_unused) { struct usb_interface *uinterf = comedi_to_usb_interface(dev); + struct usbduxsub *this_usbduxsub = usb_get_intfdata(uinterf); + struct usb_device *usb = usbduxsub->usbdev; int ret; - struct usbduxsub *this_usbduxsub; + + dev->private = this_usbduxsub; /* This is temporary... */ + ret = comedi_load_firmware(dev, &usb->dev, FIRMWARE, + usbdux_firmware_upload, 0); + if (ret < 0) { + dev->private = NULL; + return ret; + } dev->private = NULL; down(&start_stop_sem); - this_usbduxsub = usb_get_intfdata(uinterf); if (!this_usbduxsub || !this_usbduxsub->probed) { dev_err(dev->class_dev, "usbdux: error: auto_attach failed, not connected\n"); @@ -2369,35 +2299,6 @@ static struct comedi_driver usbdux_driver = { .detach = usbdux_detach, }; -static void usbdux_firmware_request_complete_handler(const struct firmware *fw, - void *context) -{ - struct usbduxsub *usbduxsub_tmp = context; - struct usb_interface *uinterf = usbduxsub_tmp->interface; - int ret; - - if (fw == NULL) { - dev_err(&uinterf->dev, - "Firmware complete handler without firmware!\n"); - return; - } - - /* - * we need to upload the firmware here because fw will be - * freed once we've left this function - */ - ret = firmware_upload(usbduxsub_tmp, fw->data, fw->size); - - if (ret) { - dev_err(&uinterf->dev, - "Could not upload firmware (err=%d)\n", ret); - goto out; - } - comedi_usb_auto_config(uinterf, &usbdux_driver, 0); - out: - release_firmware(fw); -} - static int usbdux_usb_probe(struct usb_interface *uinterf, const struct usb_device_id *id) { @@ -2405,7 +2306,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, struct device *dev = &uinterf->dev; int i; int index; - int ret; dev_dbg(dev, "comedi_: usbdux_: " "finding a free structure for the usb-device\n"); @@ -2622,23 +2522,7 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, usbduxsub[index].probed = 1; up(&start_stop_sem); - ret = request_firmware_nowait(THIS_MODULE, - FW_ACTION_HOTPLUG, - FIRMWARE, - &udev->dev, - GFP_KERNEL, - usbduxsub + index, - usbdux_firmware_request_complete_handler); - - if (ret) { - dev_err(dev, "Could not load firmware (err=%d)\n", ret); - return ret; - } - - dev_info(dev, "comedi_: usbdux%d " - "has been successfully initialised.\n", index); - /* success */ - return 0; + return comedi_usb_auto_config(uinterf, &usbdux_driver, 0); } static void usbdux_usb_disconnect(struct usb_interface *intf) diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c index 7f95af33085d..27898c44e543 100644 --- a/drivers/staging/comedi/drivers/usbduxfast.c +++ b/drivers/staging/comedi/drivers/usbduxfast.c @@ -10,10 +10,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -40,7 +36,6 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include -#include #include #include #include @@ -60,6 +55,7 @@ * constants for "firmware" upload and download */ #define FIRMWARE "usbduxfast_firmware.bin" +#define FIRMWARE_MAX_LEN 0x2000 #define USBDUXFASTSUB_FIRMWARE 0xA0 #define VENDOR_DIR_IN 0xC0 #define VENDOR_DIR_OUT 0x40 @@ -112,23 +108,13 @@ /* * size of the buffer for the dux commands in bytes */ -#define SIZEOFDUXBUFFER 256 +#define SIZEOFDUXBUF 256 /* * number of in-URBs which receive the data: min=5 */ #define NUMOFINBUFFERSHIGH 10 -/* - * total number of usbduxfast devices - */ -#define NUMUSBDUXFAST 16 - -/* - * analogue in subdevice - */ -#define SUBDEV_AD 0 - /* * min delay steps for more than one channel * basically when the mux gives up ;-) @@ -161,143 +147,83 @@ static const struct comedi_lrange range_usbduxfast_ai_range = { * this is the structure which holds all the data of this driver * one sub device just now: A/D */ -struct usbduxfastsub_s { - int attached; /* is attached? */ - int probed; /* is it associated with a subdevice? */ - struct usb_device *usbdev; /* pointer to the usb-device */ - struct urb *urbIn; /* BULK-transfer handling: urb */ - int8_t *transfer_buffer; - int16_t *insnBuffer; /* input buffer for single insn */ - int ifnum; /* interface number */ - struct usb_interface *interface; /* interface structure */ - /* comedi device for the interrupt context */ - struct comedi_device *comedidev; +struct usbduxfast_private { + struct urb *urb; /* BULK-transfer handling: urb */ + uint8_t *duxbuf; + int8_t *inbuf; short int ai_cmd_running; /* asynchronous command is running */ short int ai_continous; /* continous acquisition */ long int ai_sample_count; /* number of samples to acquire */ - uint8_t *dux_commands; /* commands */ int ignore; /* counter which ignores the first buffers */ struct semaphore sem; }; -/* - * The pointer to the private usb-data of the driver - * is also the private data for the comedi-device. - * This has to be global as the usb subsystem needs - * global variables. The other reason is that this - * structure must be there _before_ any comedi - * command is issued. The usb subsystem must be - * initialised before comedi can access it. - */ -static struct usbduxfastsub_s usbduxfastsub[NUMUSBDUXFAST]; - -static DEFINE_SEMAPHORE(start_stop_sem); - /* * bulk transfers to usbduxfast */ #define SENDADCOMMANDS 0 #define SENDINITEP6 1 -static int send_dux_commands(struct usbduxfastsub_s *udfs, int cmd_type) +static int usbduxfast_send_cmd(struct comedi_device *dev, int cmd_type) { - int tmp, nsent; + struct usb_device *usb = comedi_to_usb_dev(dev); + struct usbduxfast_private *devpriv = dev->private; + int nsent; + int ret; - udfs->dux_commands[0] = cmd_type; - -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi%d: usbduxfast: dux_commands: ", - udfs->comedidev->minor); - for (tmp = 0; tmp < SIZEOFDUXBUFFER; tmp++) - printk(" %02x", udfs->dux_commands[tmp]); - printk("\n"); -#endif - - tmp = usb_bulk_msg(udfs->usbdev, - usb_sndbulkpipe(udfs->usbdev, CHANNELLISTEP), - udfs->dux_commands, SIZEOFDUXBUFFER, &nsent, 10000); - if (tmp < 0) - dev_err(&udfs->interface->dev, - "could not transmit dux_commands to the usb-device, err=%d\n", - tmp); - return tmp; -} - -/* - * Stops the data acquision. - * It should be safe to call this function from any context. - */ -static int usbduxfastsub_unlink_InURBs(struct usbduxfastsub_s *udfs) -{ - int j = 0; - int err = 0; - - if (udfs && udfs->urbIn) { - udfs->ai_cmd_running = 0; - /* waits until a running transfer is over */ - usb_kill_urb(udfs->urbIn); - j = 0; - } -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi: usbduxfast: unlinked InURB: res=%d\n", j); -#endif - return err; -} - -/* - * This will stop a running acquisition operation. - * Is called from within this driver from both the - * interrupt context and from comedi. - */ -static int usbduxfast_ai_stop(struct usbduxfastsub_s *udfs, int do_unlink) -{ - int ret = 0; - - if (!udfs) { - pr_err("%s: udfs=NULL!\n", __func__); - return -EFAULT; - } -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi: usbduxfast_ai_stop\n"); -#endif - - udfs->ai_cmd_running = 0; - - if (do_unlink) - /* stop aquistion */ - ret = usbduxfastsub_unlink_InURBs(udfs); + devpriv->duxbuf[0] = cmd_type; + ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, CHANNELLISTEP), + devpriv->duxbuf, SIZEOFDUXBUF, + &nsent, 10000); + if (ret < 0) + dev_err(dev->class_dev, + "could not transmit command to the usb-device, err=%d\n", + ret); return ret; } -/* - * This will cancel a running acquisition operation. - * This is called by comedi but never from inside the driver. - */ +static void usbduxfast_cmd_data(struct comedi_device *dev, int index, + uint8_t len, uint8_t op, uint8_t out, + uint8_t log) +{ + struct usbduxfast_private *devpriv = dev->private; + + /* Set the GPIF bytes, the first byte is the command byte */ + devpriv->duxbuf[1 + 0x00 + index] = len; + devpriv->duxbuf[1 + 0x08 + index] = op; + devpriv->duxbuf[1 + 0x10 + index] = out; + devpriv->duxbuf[1 + 0x18 + index] = log; +} + +static int usbduxfast_ai_stop(struct comedi_device *dev, int do_unlink) +{ + struct usbduxfast_private *devpriv = dev->private; + + /* stop aquistion */ + devpriv->ai_cmd_running = 0; + + if (do_unlink && devpriv->urb) { + /* kill the running transfer */ + usb_kill_urb(devpriv->urb); + } + + return 0; +} + static int usbduxfast_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { - struct usbduxfastsub_s *udfs; + struct usbduxfast_private *devpriv = dev->private; int ret; - /* force unlink of all urbs */ -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi: usbduxfast_ai_cancel\n"); -#endif - udfs = dev->private; - if (!udfs) { - dev_err(dev->class_dev, "%s: udfs=NULL\n", __func__); + if (!devpriv) return -EFAULT; - } - down(&udfs->sem); - if (!udfs->probed) { - up(&udfs->sem); - return -ENODEV; - } - /* unlink */ - ret = usbduxfast_ai_stop(udfs, 1); - up(&udfs->sem); + + down(&devpriv->sem); + ret = usbduxfast_ai_stop(dev, 1); + up(&devpriv->sem); return ret; } @@ -306,32 +232,17 @@ static int usbduxfast_ai_cancel(struct comedi_device *dev, * analogue IN * interrupt service routine */ -static void usbduxfastsub_ai_Irq(struct urb *urb) +static void usbduxfast_ai_interrupt(struct urb *urb) { + struct comedi_device *dev = urb->context; + struct comedi_subdevice *s = dev->read_subdev; + struct comedi_async *async = s->async; + struct usb_device *usb = comedi_to_usb_dev(dev); + struct usbduxfast_private *devpriv = dev->private; int n, err; - struct usbduxfastsub_s *udfs; - struct comedi_device *this_comedidev; - struct comedi_subdevice *s; - /* sanity checks - is the urb there? */ - if (!urb) { - pr_err("ao int-handler called with urb=NULL!\n"); - return; - } - /* the context variable points to the subdevice */ - this_comedidev = urb->context; - if (!this_comedidev) { - pr_err("urb context is a NULL pointer!\n"); - return; - } - /* the private structure of the subdevice is usbduxfastsub_s */ - udfs = this_comedidev->private; - if (!udfs) { - pr_err("private of comedi subdev is a NULL pointer!\n"); - return; - } /* are we running a command? */ - if (unlikely(!udfs->ai_cmd_running)) { + if (unlikely(!devpriv->ai_cmd_running)) { /* * not running a command * do not continue execution if no asynchronous command @@ -340,13 +251,6 @@ static void usbduxfastsub_ai_Irq(struct urb *urb) return; } - if (unlikely(!udfs->attached)) { - /* no comedi device there */ - return; - } - /* subdevice which is the AD converter */ - s = &this_comedidev->subdevices[SUBDEV_AD]; - /* first we test if something unusual has just happened */ switch (urb->status) { case 0: @@ -361,189 +265,93 @@ static void usbduxfastsub_ai_Irq(struct urb *urb) case -ESHUTDOWN: case -ECONNABORTED: /* tell this comedi */ - s->async->events |= COMEDI_CB_EOA; - s->async->events |= COMEDI_CB_ERROR; - comedi_event(udfs->comedidev, s); + async->events |= COMEDI_CB_EOA; + async->events |= COMEDI_CB_ERROR; + comedi_event(dev, s); /* stop the transfer w/o unlink */ - usbduxfast_ai_stop(udfs, 0); + usbduxfast_ai_stop(dev, 0); return; default: pr_err("non-zero urb status received in ai intr context: %d\n", urb->status); - s->async->events |= COMEDI_CB_EOA; - s->async->events |= COMEDI_CB_ERROR; - comedi_event(udfs->comedidev, s); - usbduxfast_ai_stop(udfs, 0); + async->events |= COMEDI_CB_EOA; + async->events |= COMEDI_CB_ERROR; + comedi_event(dev, s); + usbduxfast_ai_stop(dev, 0); return; } - if (!udfs->ignore) { - if (!udfs->ai_continous) { + if (!devpriv->ignore) { + if (!devpriv->ai_continous) { /* not continuous, fixed number of samples */ n = urb->actual_length / sizeof(uint16_t); - if (unlikely(udfs->ai_sample_count < n)) { - /* - * we have send only a fraction of the bytes - * received - */ + if (unlikely(devpriv->ai_sample_count < n)) { + unsigned int num_bytes; + + /* partial sample received */ + num_bytes = devpriv->ai_sample_count * + sizeof(uint16_t); cfc_write_array_to_buffer(s, urb->transfer_buffer, - udfs->ai_sample_count - * sizeof(uint16_t)); - usbduxfast_ai_stop(udfs, 0); + num_bytes); + usbduxfast_ai_stop(dev, 0); /* tell comedi that the acquistion is over */ - s->async->events |= COMEDI_CB_EOA; - comedi_event(udfs->comedidev, s); + async->events |= COMEDI_CB_EOA; + comedi_event(dev, s); return; } - udfs->ai_sample_count -= n; + devpriv->ai_sample_count -= n; } /* write the full buffer to comedi */ err = cfc_write_array_to_buffer(s, urb->transfer_buffer, urb->actual_length); if (unlikely(err == 0)) { /* buffer overflow */ - usbduxfast_ai_stop(udfs, 0); + usbduxfast_ai_stop(dev, 0); return; } /* tell comedi that data is there */ - comedi_event(udfs->comedidev, s); - + comedi_event(dev, s); } else { /* ignore this packet */ - udfs->ignore--; + devpriv->ignore--; } /* * command is still running * resubmit urb for BULK transfer */ - urb->dev = udfs->usbdev; + urb->dev = usb; urb->status = 0; err = usb_submit_urb(urb, GFP_ATOMIC); if (err < 0) { - dev_err(&urb->dev->dev, + dev_err(dev->class_dev, "urb resubm failed: %d", err); - s->async->events |= COMEDI_CB_EOA; - s->async->events |= COMEDI_CB_ERROR; - comedi_event(udfs->comedidev, s); - usbduxfast_ai_stop(udfs, 0); + async->events |= COMEDI_CB_EOA; + async->events |= COMEDI_CB_ERROR; + comedi_event(dev, s); + usbduxfast_ai_stop(dev, 0); } } -static int usbduxfastsub_start(struct usbduxfastsub_s *udfs) -{ - int ret; - unsigned char *local_transfer_buffer; - - local_transfer_buffer = kmalloc(1, GFP_KERNEL); - if (!local_transfer_buffer) - return -ENOMEM; - - /* 7f92 to zero */ - *local_transfer_buffer = 0; - /* bRequest, "Firmware" */ - ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0), - USBDUXFASTSUB_FIRMWARE, - VENDOR_DIR_OUT, /* bmRequestType */ - USBDUXFASTSUB_CPUCS, /* Value */ - 0x0000, /* Index */ - /* address of the transfer buffer */ - local_transfer_buffer, - 1, /* Length */ - EZTIMEOUT); /* Timeout */ - if (ret < 0) - dev_err(&udfs->interface->dev, - "control msg failed (start)\n"); - - kfree(local_transfer_buffer); - return ret; -} - -static int usbduxfastsub_stop(struct usbduxfastsub_s *udfs) -{ - int ret; - unsigned char *local_transfer_buffer; - - local_transfer_buffer = kmalloc(1, GFP_KERNEL); - if (!local_transfer_buffer) - return -ENOMEM; - - /* 7f92 to one */ - *local_transfer_buffer = 1; - /* bRequest, "Firmware" */ - ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0), - USBDUXFASTSUB_FIRMWARE, - VENDOR_DIR_OUT, /* bmRequestType */ - USBDUXFASTSUB_CPUCS, /* Value */ - 0x0000, /* Index */ - local_transfer_buffer, 1, /* Length */ - EZTIMEOUT); /* Timeout */ - if (ret < 0) - dev_err(&udfs->interface->dev, - "control msg failed (stop)\n"); - - kfree(local_transfer_buffer); - return ret; -} - -static int usbduxfastsub_upload(struct usbduxfastsub_s *udfs, - unsigned char *local_transfer_buffer, - unsigned int startAddr, unsigned int len) +static int usbduxfast_submit_urb(struct comedi_device *dev) { + struct usb_device *usb = comedi_to_usb_dev(dev); + struct usbduxfast_private *devpriv = dev->private; int ret; -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi: usbduxfast: uploading %d bytes", len); - printk(KERN_DEBUG " to addr %d, first byte=%d.\n", - startAddr, local_transfer_buffer[0]); -#endif - /* brequest, firmware */ - ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0), - USBDUXFASTSUB_FIRMWARE, - VENDOR_DIR_OUT, /* bmRequestType */ - startAddr, /* value */ - 0x0000, /* index */ - /* our local safe buffer */ - local_transfer_buffer, - len, /* length */ - EZTIMEOUT); /* timeout */ - -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi_: usbduxfast: result=%d\n", ret); -#endif - - if (ret < 0) { - dev_err(&udfs->interface->dev, "uppload failed\n"); - return ret; - } - - return 0; -} - -static int usbduxfastsub_submit_InURBs(struct usbduxfastsub_s *udfs) -{ - int ret; - - if (!udfs) + if (!devpriv) return -EFAULT; - usb_fill_bulk_urb(udfs->urbIn, udfs->usbdev, - usb_rcvbulkpipe(udfs->usbdev, BULKINEP), - udfs->transfer_buffer, - SIZEINBUF, usbduxfastsub_ai_Irq, udfs->comedidev); + usb_fill_bulk_urb(devpriv->urb, usb, usb_rcvbulkpipe(usb, BULKINEP), + devpriv->inbuf, SIZEINBUF, + usbduxfast_ai_interrupt, dev); -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi%d: usbduxfast: submitting in-urb: " - "0x%p,0x%p\n", udfs->comedidev->minor, udfs->urbIn->context, - udfs->urbIn->dev); -#endif - ret = usb_submit_urb(udfs->urbIn, GFP_ATOMIC); + ret = usb_submit_urb(devpriv->urb, GFP_ATOMIC); if (ret) { - dev_err(&udfs->interface->dev, - "ai: usb_submit_urb error %d\n", ret); + dev_err(dev->class_dev, "usb_submit_urb error %d\n", ret); return ret; } return 0; @@ -553,13 +361,9 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) { - struct usbduxfastsub_s *udfs = dev->private; int err = 0; long int steps, tmp; - int minSamplPer; - - if (!udfs->probed) - return -ENODEV; + int min_sample_period; /* Step 1 : check if triggers are trivially valid */ @@ -601,14 +405,14 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev, err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); if (cmd->chanlist_len == 1) - minSamplPer = 1; + min_sample_period = 1; else - minSamplPer = MIN_SAMPLING_PERIOD; + min_sample_period = MIN_SAMPLING_PERIOD; if (cmd->convert_src == TRIG_TIMER) { steps = cmd->convert_arg * 30; - if (steps < (minSamplPer * 1000)) - steps = minSamplPer * 1000; + if (steps < (min_sample_period * 1000)) + steps = min_sample_period * 1000; if (steps > (MAX_SAMPLING_PERIOD * 1000)) steps = MAX_SAMPLING_PERIOD * 1000; @@ -650,80 +454,53 @@ static int usbduxfast_ai_inttrig(struct comedi_device *dev, struct comedi_subdevice *s, unsigned int trignum) { + struct usbduxfast_private *devpriv = dev->private; int ret; - struct usbduxfastsub_s *udfs = dev->private; - if (!udfs) + if (!devpriv) return -EFAULT; - down(&udfs->sem); - if (!udfs->probed) { - up(&udfs->sem); - return -ENODEV; - } -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi%d: usbduxfast_ai_inttrig\n", dev->minor); -#endif + down(&devpriv->sem); if (trignum != 0) { - dev_err(dev->class_dev, "%s: invalid trignum\n", __func__); - up(&udfs->sem); + dev_err(dev->class_dev, "invalid trignum\n"); + up(&devpriv->sem); return -EINVAL; } - if (!udfs->ai_cmd_running) { - udfs->ai_cmd_running = 1; - ret = usbduxfastsub_submit_InURBs(udfs); + if (!devpriv->ai_cmd_running) { + devpriv->ai_cmd_running = 1; + ret = usbduxfast_submit_urb(dev); if (ret < 0) { - dev_err(dev->class_dev, - "%s: urbSubmit: err=%d\n", __func__, ret); - udfs->ai_cmd_running = 0; - up(&udfs->sem); + dev_err(dev->class_dev, "urbSubmit: err=%d\n", ret); + devpriv->ai_cmd_running = 0; + up(&devpriv->sem); return ret; } s->async->inttrig = NULL; } else { - dev_err(dev->class_dev, - "ai_inttrig but acqu is already running\n"); + dev_err(dev->class_dev, "ai is already running\n"); } - up(&udfs->sem); + up(&devpriv->sem); return 1; } -/* - * offsets for the GPIF bytes - * the first byte is the command byte - */ -#define LENBASE (1+0x00) -#define OPBASE (1+0x08) -#define OUTBASE (1+0x10) -#define LOGBASE (1+0x18) - static int usbduxfast_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) { + struct usbduxfast_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; unsigned int chan, gain, rngmask = 0xff; int i, j, ret; - struct usbduxfastsub_s *udfs; int result; long steps, steps_tmp; -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi%d: usbduxfast_ai_cmd\n", dev->minor); -#endif - udfs = dev->private; - if (!udfs) + if (!devpriv) return -EFAULT; - down(&udfs->sem); - if (!udfs->probed) { - up(&udfs->sem); - return -ENODEV; - } - if (udfs->ai_cmd_running) { - dev_err(dev->class_dev, - "ai_cmd not possible. Another ai_cmd is running.\n"); - up(&udfs->sem); + down(&devpriv->sem); + if (devpriv->ai_cmd_running) { + dev_err(dev->class_dev, "ai_cmd not possible\n"); + up(&devpriv->sem); return -EBUSY; } /* set current channel of the running acquisition to zero */ @@ -733,7 +510,7 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, * ignore the first buffers from the device if there * is an error condition */ - udfs->ignore = PACKETS_TO_IGNORE; + devpriv->ignore = PACKETS_TO_IGNORE; if (cmd->chanlist_len > 0) { gain = CR_RANGE(cmd->chanlist[0]); @@ -741,20 +518,19 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, chan = CR_CHAN(cmd->chanlist[i]); if (chan != i) { dev_err(dev->class_dev, - "cmd is accepting only consecutive channels.\n"); - up(&udfs->sem); + "channels are not consecutive\n"); + up(&devpriv->sem); return -EINVAL; } if ((gain != CR_RANGE(cmd->chanlist[i])) && (cmd->chanlist_len > 3)) { dev_err(dev->class_dev, - "the gain must be the same for all channels.\n"); - up(&udfs->sem); + "gain must be the same for all channels\n"); + up(&devpriv->sem); return -EINVAL; } if (i >= NUMCHANNELS) { - dev_err(dev->class_dev, - "channel list too long\n"); + dev_err(dev->class_dev, "chanlist too long\n"); break; } } @@ -762,8 +538,8 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, steps = 0; if (cmd->scan_begin_src == TRIG_TIMER) { dev_err(dev->class_dev, - "scan_begin_src==TRIG_TIMER not valid.\n"); - up(&udfs->sem); + "scan_begin_src==TRIG_TIMER not valid\n"); + up(&devpriv->sem); return -EINVAL; } if (cmd->convert_src == TRIG_TIMER) @@ -771,27 +547,23 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, if ((steps < MIN_SAMPLING_PERIOD) && (cmd->chanlist_len != 1)) { dev_err(dev->class_dev, - "ai_cmd: steps=%ld, scan_begin_arg=%d. Not properly tested by cmdtest?\n", + "steps=%ld, scan_begin_arg=%d. Not properly tested by cmdtest?\n", steps, cmd->scan_begin_arg); - up(&udfs->sem); + up(&devpriv->sem); return -EINVAL; } if (steps > MAX_SAMPLING_PERIOD) { - dev_err(dev->class_dev, "ai_cmd: sampling rate too low.\n"); - up(&udfs->sem); + dev_err(dev->class_dev, "sampling rate too low\n"); + up(&devpriv->sem); return -EINVAL; } if ((cmd->start_src == TRIG_EXT) && (cmd->chanlist_len != 1) && (cmd->chanlist_len != 16)) { dev_err(dev->class_dev, - "ai_cmd: TRIG_EXT only with 1 or 16 channels possible.\n"); - up(&udfs->sem); + "TRIG_EXT only with 1 or 16 channels possible\n"); + up(&devpriv->sem); return -EINVAL; } -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi%d: usbduxfast: steps=%ld, convert_arg=%u\n", - dev->minor, steps, cmd->convert_arg); -#endif switch (cmd->chanlist_len) { case 1: @@ -812,17 +584,11 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, /* we loop here until ready has been set */ if (cmd->start_src == TRIG_EXT) { /* branch back to state 0 */ - udfs->dux_commands[LENBASE + 0] = 0x01; /* deceision state w/o data */ - udfs->dux_commands[OPBASE + 0] = 0x01; - udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask; /* RDY0 = 0 */ - udfs->dux_commands[LOGBASE + 0] = 0x00; + usbduxfast_cmd_data(dev, 0, 0x01, 0x01, rngmask, 0x00); } else { /* we just proceed to state 1 */ - udfs->dux_commands[LENBASE + 0] = 1; - udfs->dux_commands[OPBASE + 0] = 0; - udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 0] = 0; + usbduxfast_cmd_data(dev, 0, 0x01, 0x00, rngmask, 0x00); } if (steps < MIN_SAMPLING_PERIOD) { @@ -835,33 +601,25 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, */ /* branch back to state 1 */ - udfs->dux_commands[LENBASE + 1] = 0x89; /* deceision state with data */ - udfs->dux_commands[OPBASE + 1] = 0x03; - udfs->dux_commands[OUTBASE + 1] = - 0xFF & rngmask; /* doesn't matter */ - udfs->dux_commands[LOGBASE + 1] = 0xFF; + usbduxfast_cmd_data(dev, 1, + 0x89, 0x03, rngmask, 0xff); } else { /* * we loop through two states: data and delay * max rate is 15MHz */ - udfs->dux_commands[LENBASE + 1] = steps - 1; /* data */ - udfs->dux_commands[OPBASE + 1] = 0x02; - udfs->dux_commands[OUTBASE + 1] = - 0xFF & rngmask; /* doesn't matter */ - udfs->dux_commands[LOGBASE + 1] = 0; + usbduxfast_cmd_data(dev, 1, steps - 1, + 0x02, rngmask, 0x00); + /* branch back to state 1 */ - udfs->dux_commands[LENBASE + 2] = 0x09; /* deceision state w/o data */ - udfs->dux_commands[OPBASE + 2] = 0x01; - udfs->dux_commands[OUTBASE + 2] = - 0xFF & rngmask; /* doesn't matter */ - udfs->dux_commands[LOGBASE + 2] = 0xFF; + usbduxfast_cmd_data(dev, 2, + 0x09, 0x01, rngmask, 0xff); } } else { /* @@ -873,26 +631,20 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, steps = steps - 1; /* do the first part of the delay */ - udfs->dux_commands[LENBASE + 1] = steps / 2; - udfs->dux_commands[OPBASE + 1] = 0; - udfs->dux_commands[OUTBASE + 1] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 1] = 0; + usbduxfast_cmd_data(dev, 1, + steps / 2, 0x00, rngmask, 0x00); /* and the second part */ - udfs->dux_commands[LENBASE + 2] = steps - steps / 2; - udfs->dux_commands[OPBASE + 2] = 0; - udfs->dux_commands[OUTBASE + 2] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 2] = 0; + usbduxfast_cmd_data(dev, 2, steps - steps / 2, + 0x00, rngmask, 0x00); /* get the data and branch back */ /* branch back to state 1 */ - udfs->dux_commands[LENBASE + 3] = 0x09; /* deceision state w data */ - udfs->dux_commands[OPBASE + 3] = 0x03; - udfs->dux_commands[OUTBASE + 3] = 0xFF & rngmask; /* doesn't matter */ - udfs->dux_commands[LOGBASE + 3] = 0xFF; + usbduxfast_cmd_data(dev, 3, + 0x09, 0x03, rngmask, 0xff); } break; @@ -907,11 +659,8 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, else rngmask = 0xff; - udfs->dux_commands[LENBASE + 0] = 1; /* data */ - udfs->dux_commands[OPBASE + 0] = 0x02; - udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 0] = 0; + usbduxfast_cmd_data(dev, 0, 0x01, 0x02, rngmask, 0x00); /* we have 1 state with duration 1: state 0 */ steps_tmp = steps - 1; @@ -922,23 +671,16 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, rngmask = 0xff; /* do the first part of the delay */ - udfs->dux_commands[LENBASE + 1] = steps_tmp / 2; - udfs->dux_commands[OPBASE + 1] = 0; /* count */ - udfs->dux_commands[OUTBASE + 1] = 0xFE & rngmask; - udfs->dux_commands[LOGBASE + 1] = 0; + usbduxfast_cmd_data(dev, 1, steps_tmp / 2, + 0x00, 0xfe & rngmask, 0x00); /* and the second part */ - udfs->dux_commands[LENBASE + 2] = steps_tmp - steps_tmp / 2; - udfs->dux_commands[OPBASE + 2] = 0; - udfs->dux_commands[OUTBASE + 2] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 2] = 0; + usbduxfast_cmd_data(dev, 2, steps_tmp - steps_tmp / 2, + 0x00, rngmask, 0x00); - udfs->dux_commands[LENBASE + 3] = 1; /* data */ - udfs->dux_commands[OPBASE + 3] = 0x02; - udfs->dux_commands[OUTBASE + 3] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 3] = 0; + usbduxfast_cmd_data(dev, 3, 0x01, 0x02, rngmask, 0x00); /* * we have 2 states with duration 1: step 6 and @@ -952,22 +694,15 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, rngmask = 0xff; /* do the first part of the delay */ - udfs->dux_commands[LENBASE + 4] = steps_tmp / 2; - udfs->dux_commands[OPBASE + 4] = 0; /* reset */ - udfs->dux_commands[OUTBASE + 4] = (0xFF - 0x02) & rngmask; - udfs->dux_commands[LOGBASE + 4] = 0; + usbduxfast_cmd_data(dev, 4, steps_tmp / 2, + 0x00, (0xff - 0x02) & rngmask, 0x00); /* and the second part */ - udfs->dux_commands[LENBASE + 5] = steps_tmp - steps_tmp / 2; - udfs->dux_commands[OPBASE + 5] = 0; - udfs->dux_commands[OUTBASE + 5] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 5] = 0; + usbduxfast_cmd_data(dev, 5, steps_tmp - steps_tmp / 2, + 0x00, rngmask, 0x00); - udfs->dux_commands[LENBASE + 6] = 1; - udfs->dux_commands[OPBASE + 6] = 0; - udfs->dux_commands[OUTBASE + 6] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 6] = 0; + usbduxfast_cmd_data(dev, 6, 0x01, 0x00, rngmask, 0x00); break; case 3: @@ -975,6 +710,8 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, * three channels */ for (j = 0; j < 1; j++) { + int index = j * 2; + if (CR_RANGE(cmd->chanlist[j]) > 0) rngmask = 0xff - 0x04; else @@ -983,12 +720,10 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, * commit data to the FIFO and do the first part * of the delay */ - udfs->dux_commands[LENBASE + j * 2] = steps / 2; /* data */ - udfs->dux_commands[OPBASE + j * 2] = 0x02; /* no change */ - udfs->dux_commands[OUTBASE + j * 2] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + j * 2] = 0; + usbduxfast_cmd_data(dev, index, steps / 2, + 0x02, rngmask, 0x00); if (CR_RANGE(cmd->chanlist[j + 1]) > 0) rngmask = 0xff - 0x04; @@ -996,25 +731,19 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, rngmask = 0xff; /* do the second part of the delay */ - udfs->dux_commands[LENBASE + j * 2 + 1] = - steps - steps / 2; /* no data */ - udfs->dux_commands[OPBASE + j * 2 + 1] = 0; /* count */ - udfs->dux_commands[OUTBASE + j * 2 + 1] = - 0xFE & rngmask; - udfs->dux_commands[LOGBASE + j * 2 + 1] = 0; + usbduxfast_cmd_data(dev, index + 1, steps - steps / 2, + 0x00, 0xfe & rngmask, 0x00); } /* 2 steps with duration 1: the idele step and step 6: */ steps_tmp = steps - 2; /* commit data to the FIFO and do the first part of the delay */ - udfs->dux_commands[LENBASE + 4] = steps_tmp / 2; /* data */ - udfs->dux_commands[OPBASE + 4] = 0x02; - udfs->dux_commands[OUTBASE + 4] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 4] = 0; + usbduxfast_cmd_data(dev, 4, steps_tmp / 2, + 0x02, rngmask, 0x00); if (CR_RANGE(cmd->chanlist[0]) > 0) rngmask = 0xff - 0x04; @@ -1022,17 +751,12 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, rngmask = 0xff; /* do the second part of the delay */ - udfs->dux_commands[LENBASE + 5] = steps_tmp - steps_tmp / 2; /* no data */ - udfs->dux_commands[OPBASE + 5] = 0; /* reset */ - udfs->dux_commands[OUTBASE + 5] = (0xFF - 0x02) & rngmask; - udfs->dux_commands[LOGBASE + 5] = 0; + usbduxfast_cmd_data(dev, 5, steps_tmp - steps_tmp / 2, + 0x00, (0xff - 0x02) & rngmask, 0x00); - udfs->dux_commands[LENBASE + 6] = 1; - udfs->dux_commands[OPBASE + 6] = 0; - udfs->dux_commands[OUTBASE + 6] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 6] = 0; + usbduxfast_cmd_data(dev, 6, 0x01, 0x00, rngmask, 0x00); case 16: if (CR_RANGE(cmd->chanlist[0]) > 0) @@ -1046,101 +770,79 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, */ /* branch back to state 0 */ - udfs->dux_commands[LENBASE + 0] = 0x01; /* deceision state w/o data */ - udfs->dux_commands[OPBASE + 0] = 0x01; /* reset */ - udfs->dux_commands[OUTBASE + 0] = - (0xFF - 0x02) & rngmask; /* RDY0 = 0 */ - udfs->dux_commands[LOGBASE + 0] = 0x00; + usbduxfast_cmd_data(dev, 0, 0x01, 0x01, + (0xff - 0x02) & rngmask, 0x00); } else { /* * we just proceed to state 1 */ /* 30us reset pulse */ - udfs->dux_commands[LENBASE + 0] = 255; - udfs->dux_commands[OPBASE + 0] = 0; /* reset */ - udfs->dux_commands[OUTBASE + 0] = - (0xFF - 0x02) & rngmask; - udfs->dux_commands[LOGBASE + 0] = 0; + usbduxfast_cmd_data(dev, 0, 0xff, 0x00, + (0xff - 0x02) & rngmask, 0x00); } /* commit data to the FIFO */ - udfs->dux_commands[LENBASE + 1] = 1; /* data */ - udfs->dux_commands[OPBASE + 1] = 0x02; - udfs->dux_commands[OUTBASE + 1] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 1] = 0; + usbduxfast_cmd_data(dev, 1, 0x01, 0x02, rngmask, 0x00); /* we have 2 states with duration 1 */ steps = steps - 2; /* do the first part of the delay */ - udfs->dux_commands[LENBASE + 2] = steps / 2; - udfs->dux_commands[OPBASE + 2] = 0; - udfs->dux_commands[OUTBASE + 2] = 0xFE & rngmask; - udfs->dux_commands[LOGBASE + 2] = 0; + usbduxfast_cmd_data(dev, 2, steps / 2, + 0x00, 0xfe & rngmask, 0x00); /* and the second part */ - udfs->dux_commands[LENBASE + 3] = steps - steps / 2; - udfs->dux_commands[OPBASE + 3] = 0; - udfs->dux_commands[OUTBASE + 3] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 3] = 0; + usbduxfast_cmd_data(dev, 3, steps - steps / 2, + 0x00, rngmask, 0x00); /* branch back to state 1 */ - udfs->dux_commands[LENBASE + 4] = 0x09; /* deceision state w/o data */ - udfs->dux_commands[OPBASE + 4] = 0x01; - udfs->dux_commands[OUTBASE + 4] = 0xFF & rngmask; /* doesn't matter */ - udfs->dux_commands[LOGBASE + 4] = 0xFF; + usbduxfast_cmd_data(dev, 4, 0x09, 0x01, rngmask, 0xff); break; default: dev_err(dev->class_dev, "unsupported combination of channels\n"); - up(&udfs->sem); + up(&devpriv->sem); return -EFAULT; } -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi %d: sending commands to the usb device\n", - dev->minor); -#endif /* 0 means that the AD commands are sent */ - result = send_dux_commands(udfs, SENDADCOMMANDS); + result = usbduxfast_send_cmd(dev, SENDADCOMMANDS); if (result < 0) { - dev_err(dev->class_dev, - "adc command could not be submitted. Aborting...\n"); - up(&udfs->sem); + up(&devpriv->sem); return result; } if (cmd->stop_src == TRIG_COUNT) { - udfs->ai_sample_count = cmd->stop_arg * cmd->scan_end_arg; - if (udfs->ai_sample_count < 1) { + devpriv->ai_sample_count = cmd->stop_arg * cmd->scan_end_arg; + if (devpriv->ai_sample_count < 1) { dev_err(dev->class_dev, - "(cmd->stop_arg)*(cmd->scan_end_arg)<1, aborting.\n"); - up(&udfs->sem); + "(cmd->stop_arg)*(cmd->scan_end_arg)<1, aborting\n"); + up(&devpriv->sem); return -EFAULT; } - udfs->ai_continous = 0; + devpriv->ai_continous = 0; } else { /* continous acquisition */ - udfs->ai_continous = 1; - udfs->ai_sample_count = 0; + devpriv->ai_continous = 1; + devpriv->ai_sample_count = 0; } if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) { /* enable this acquisition operation */ - udfs->ai_cmd_running = 1; - ret = usbduxfastsub_submit_InURBs(udfs); + devpriv->ai_cmd_running = 1; + ret = usbduxfast_submit_urb(dev); if (ret < 0) { - udfs->ai_cmd_running = 0; + devpriv->ai_cmd_running = 0; /* fixme: unlink here?? */ - up(&udfs->sem); + up(&devpriv->sem); return ret; } s->async->inttrig = NULL; @@ -1152,7 +854,7 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, */ s->async->inttrig = usbduxfast_ai_inttrig; } - up(&udfs->sem); + up(&devpriv->sem); return 0; } @@ -1162,309 +864,270 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, */ static int usbduxfast_ai_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { + struct usb_device *usb = comedi_to_usb_dev(dev); + struct usbduxfast_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int range = CR_RANGE(insn->chanspec); + uint8_t rngmask = range ? (0xff - 0x04) : 0xff; int i, j, n, actual_length; - int chan, range, rngmask; - int err; - struct usbduxfastsub_s *udfs; + int ret; - udfs = dev->private; - if (!udfs) { - dev_err(dev->class_dev, "%s: no usb dev.\n", __func__); - return -ENODEV; - } -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi%d: ai_insn_read, insn->n=%d, " - "insn->subdev=%d\n", dev->minor, insn->n, insn->subdev); -#endif - down(&udfs->sem); - if (!udfs->probed) { - up(&udfs->sem); - return -ENODEV; - } - if (udfs->ai_cmd_running) { + down(&devpriv->sem); + + if (devpriv->ai_cmd_running) { dev_err(dev->class_dev, - "ai_insn_read not possible. Async Command is running.\n"); - up(&udfs->sem); + "ai_insn_read not possible, async cmd is running\n"); + up(&devpriv->sem); return -EBUSY; } - /* sample one channel */ - chan = CR_CHAN(insn->chanspec); - range = CR_RANGE(insn->chanspec); + /* set command for the first channel */ - if (range > 0) - rngmask = 0xff - 0x04; - else - rngmask = 0xff; - /* commit data to the FIFO */ - udfs->dux_commands[LENBASE + 0] = 1; /* data */ - udfs->dux_commands[OPBASE + 0] = 0x02; - udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 0] = 0; + usbduxfast_cmd_data(dev, 0, 0x01, 0x02, rngmask, 0x00); /* do the first part of the delay */ - udfs->dux_commands[LENBASE + 1] = 12; - udfs->dux_commands[OPBASE + 1] = 0; - udfs->dux_commands[OUTBASE + 1] = 0xFE & rngmask; - udfs->dux_commands[LOGBASE + 1] = 0; - - udfs->dux_commands[LENBASE + 2] = 1; - udfs->dux_commands[OPBASE + 2] = 0; - udfs->dux_commands[OUTBASE + 2] = 0xFE & rngmask; - udfs->dux_commands[LOGBASE + 2] = 0; - - udfs->dux_commands[LENBASE + 3] = 1; - udfs->dux_commands[OPBASE + 3] = 0; - udfs->dux_commands[OUTBASE + 3] = 0xFE & rngmask; - udfs->dux_commands[LOGBASE + 3] = 0; - - udfs->dux_commands[LENBASE + 4] = 1; - udfs->dux_commands[OPBASE + 4] = 0; - udfs->dux_commands[OUTBASE + 4] = 0xFE & rngmask; - udfs->dux_commands[LOGBASE + 4] = 0; + usbduxfast_cmd_data(dev, 1, 0x0c, 0x00, 0xfe & rngmask, 0x00); + usbduxfast_cmd_data(dev, 2, 0x01, 0x00, 0xfe & rngmask, 0x00); + usbduxfast_cmd_data(dev, 3, 0x01, 0x00, 0xfe & rngmask, 0x00); + usbduxfast_cmd_data(dev, 4, 0x01, 0x00, 0xfe & rngmask, 0x00); /* second part */ - udfs->dux_commands[LENBASE + 5] = 12; - udfs->dux_commands[OPBASE + 5] = 0; - udfs->dux_commands[OUTBASE + 5] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 5] = 0; + usbduxfast_cmd_data(dev, 5, 0x0c, 0x00, rngmask, 0x00); + usbduxfast_cmd_data(dev, 6, 0x01, 0x00, rngmask, 0x00); - udfs->dux_commands[LENBASE + 6] = 1; - udfs->dux_commands[OPBASE + 6] = 0; - udfs->dux_commands[OUTBASE + 6] = 0xFF & rngmask; - udfs->dux_commands[LOGBASE + 0] = 0; - -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi %d: sending commands to the usb device\n", - dev->minor); -#endif - /* 0 means that the AD commands are sent */ - err = send_dux_commands(udfs, SENDADCOMMANDS); - if (err < 0) { - dev_err(dev->class_dev, - "adc command could not be submitted. Aborting...\n"); - up(&udfs->sem); - return err; + ret = usbduxfast_send_cmd(dev, SENDADCOMMANDS); + if (ret < 0) { + up(&devpriv->sem); + return ret; } -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi%d: usbduxfast: submitting in-urb: " - "0x%p,0x%p\n", udfs->comedidev->minor, udfs->urbIn->context, - udfs->urbIn->dev); -#endif + for (i = 0; i < PACKETS_TO_IGNORE; i++) { - err = usb_bulk_msg(udfs->usbdev, - usb_rcvbulkpipe(udfs->usbdev, BULKINEP), - udfs->transfer_buffer, SIZEINBUF, + ret = usb_bulk_msg(usb, usb_rcvbulkpipe(usb, BULKINEP), + devpriv->inbuf, SIZEINBUF, &actual_length, 10000); - if (err < 0) { - dev_err(dev->class_dev, "insn timeout. No data.\n"); - up(&udfs->sem); - return err; + if (ret < 0) { + dev_err(dev->class_dev, "insn timeout, no data\n"); + up(&devpriv->sem); + return ret; } } - /* data points */ + for (i = 0; i < insn->n;) { - err = usb_bulk_msg(udfs->usbdev, - usb_rcvbulkpipe(udfs->usbdev, BULKINEP), - udfs->transfer_buffer, SIZEINBUF, + ret = usb_bulk_msg(usb, usb_rcvbulkpipe(usb, BULKINEP), + devpriv->inbuf, SIZEINBUF, &actual_length, 10000); - if (err < 0) { - dev_err(dev->class_dev, "insn data error: %d\n", err); - up(&udfs->sem); - return err; + if (ret < 0) { + dev_err(dev->class_dev, "insn data error: %d\n", ret); + up(&devpriv->sem); + return ret; } n = actual_length / sizeof(uint16_t); if ((n % 16) != 0) { - dev_err(dev->class_dev, "insn data packet corrupted.\n"); - up(&udfs->sem); + dev_err(dev->class_dev, "insn data packet corrupted\n"); + up(&devpriv->sem); return -EINVAL; } for (j = chan; (j < n) && (i < insn->n); j = j + 16) { - data[i] = ((uint16_t *) (udfs->transfer_buffer))[j]; + data[i] = ((uint16_t *) (devpriv->inbuf))[j]; i++; } } - up(&udfs->sem); - return i; + + up(&devpriv->sem); + + return insn->n; } -#define FIRMWARE_MAX_LEN 0x2000 - -static int firmwareUpload(struct usbduxfastsub_s *usbduxfastsub, - const u8 *firmwareBinary, int sizeFirmware) +static int usbduxfast_attach_common(struct comedi_device *dev) { + struct usbduxfast_private *devpriv = dev->private; + struct comedi_subdevice *s; int ret; - uint8_t *fwBuf; - if (!firmwareBinary) + down(&devpriv->sem); + + ret = comedi_alloc_subdevices(dev, 1); + if (ret) { + up(&devpriv->sem); + return ret; + } + + /* Analog Input subdevice */ + s = &dev->subdevices[0]; + dev->read_subdev = s; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ; + s->n_chan = 16; + s->len_chanlist = 16; + s->insn_read = usbduxfast_ai_insn_read; + s->do_cmdtest = usbduxfast_ai_cmdtest; + s->do_cmd = usbduxfast_ai_cmd; + s->cancel = usbduxfast_ai_cancel; + s->maxdata = 0x1000; + s->range_table = &range_usbduxfast_ai_range; + + up(&devpriv->sem); + + return 0; +} + +static int usbduxfast_upload_firmware(struct comedi_device *dev, + const u8 *data, size_t size, + unsigned long context) +{ + struct usb_device *usb = comedi_to_usb_dev(dev); + uint8_t *buf; + unsigned char *tmp; + int ret; + + if (!data) return 0; - if (sizeFirmware > FIRMWARE_MAX_LEN) { - dev_err(&usbduxfastsub->interface->dev, - "comedi_: usbduxfast firmware binary it too large for FX2.\n"); + if (size > FIRMWARE_MAX_LEN) { + dev_err(dev->class_dev, "firmware binary too large for FX2\n"); return -ENOMEM; } /* we generate a local buffer for the firmware */ - fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL); - if (!fwBuf) { - dev_err(&usbduxfastsub->interface->dev, - "comedi_: mem alloc for firmware failed\n"); + buf = kmemdup(data, size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + /* we need a malloc'ed buffer for usb_control_msg() */ + tmp = kmalloc(1, GFP_KERNEL); + if (!tmp) { + kfree(buf); return -ENOMEM; } - ret = usbduxfastsub_stop(usbduxfastsub); + /* stop the current firmware on the device */ + *tmp = 1; /* 7f92 to one */ + ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), + USBDUXFASTSUB_FIRMWARE, + VENDOR_DIR_OUT, + USBDUXFASTSUB_CPUCS, 0x0000, + tmp, 1, + EZTIMEOUT); if (ret < 0) { - dev_err(&usbduxfastsub->interface->dev, - "comedi_: can not stop firmware\n"); - kfree(fwBuf); - return ret; + dev_err(dev->class_dev, "can not stop firmware\n"); + goto done; } - ret = usbduxfastsub_upload(usbduxfastsub, fwBuf, 0, sizeFirmware); + /* upload the new firmware to the device */ + ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), + USBDUXFASTSUB_FIRMWARE, + VENDOR_DIR_OUT, + 0, 0x0000, + buf, size, + EZTIMEOUT); if (ret < 0) { - dev_err(&usbduxfastsub->interface->dev, - "comedi_: firmware upload failed\n"); - kfree(fwBuf); - return ret; - } - ret = usbduxfastsub_start(usbduxfastsub); - if (ret < 0) { - dev_err(&usbduxfastsub->interface->dev, - "comedi_: can not start firmware\n"); - kfree(fwBuf); - return ret; - } - kfree(fwBuf); - return 0; -} - -static void tidy_up(struct usbduxfastsub_s *udfs) -{ -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi_: usbduxfast: tiding up\n"); -#endif - - if (!udfs) - return; - - /* shows the usb subsystem that the driver is down */ - if (udfs->interface) - usb_set_intfdata(udfs->interface, NULL); - - udfs->probed = 0; - - if (udfs->urbIn) { - /* waits until a running transfer is over */ - usb_kill_urb(udfs->urbIn); - - kfree(udfs->transfer_buffer); - udfs->transfer_buffer = NULL; - - usb_free_urb(udfs->urbIn); - udfs->urbIn = NULL; + dev_err(dev->class_dev, "firmware upload failed\n"); + goto done; } - kfree(udfs->insnBuffer); - udfs->insnBuffer = NULL; + /* start the new firmware on the device */ + *tmp = 0; /* 7f92 to zero */ + ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), + USBDUXFASTSUB_FIRMWARE, + VENDOR_DIR_OUT, + USBDUXFASTSUB_CPUCS, 0x0000, + tmp, 1, + EZTIMEOUT); + if (ret < 0) + dev_err(dev->class_dev, "can not start firmware\n"); - kfree(udfs->dux_commands); - udfs->dux_commands = NULL; - - udfs->ai_cmd_running = 0; -} - -static int usbduxfast_attach_common(struct comedi_device *dev, - struct usbduxfastsub_s *udfs) -{ - int ret; - struct comedi_subdevice *s; - - down(&udfs->sem); - /* pointer back to the corresponding comedi device */ - udfs->comedidev = dev; - - ret = comedi_alloc_subdevices(dev, 1); - if (ret) { - up(&udfs->sem); - return ret; - } - /* private structure is also simply the usb-structure */ - dev->private = udfs; - /* the first subdevice is the A/D converter */ - s = &dev->subdevices[SUBDEV_AD]; - /* - * the URBs get the comedi subdevice which is responsible for reading - * this is the subdevice which reads data - */ - dev->read_subdev = s; - /* the subdevice receives as private structure the usb-structure */ - s->private = NULL; - /* analog input */ - s->type = COMEDI_SUBD_AI; - /* readable and ref is to ground */ - s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ; - /* 16 channels */ - s->n_chan = 16; - /* length of the channellist */ - s->len_chanlist = 16; - /* callback functions */ - s->insn_read = usbduxfast_ai_insn_read; - s->do_cmdtest = usbduxfast_ai_cmdtest; - s->do_cmd = usbduxfast_ai_cmd; - s->cancel = usbduxfast_ai_cancel; - /* max value from the A/D converter (12bit+1 bit for overflow) */ - s->maxdata = 0x1000; - /* range table to convert to physical units */ - s->range_table = &range_usbduxfast_ai_range; - /* finally decide that it's attached */ - udfs->attached = 1; - up(&udfs->sem); - dev_info(dev->class_dev, "successfully attached to usbduxfast.\n"); - return 0; +done: + kfree(tmp); + kfree(buf); + return ret; } static int usbduxfast_auto_attach(struct comedi_device *dev, unsigned long context_unused) { - struct usb_interface *uinterf = comedi_to_usb_interface(dev); + struct usb_interface *intf = comedi_to_usb_interface(dev); + struct usb_device *usb = comedi_to_usb_dev(dev); + struct usbduxfast_private *devpriv; int ret; - struct usbduxfastsub_s *udfs; - dev->private = NULL; - down(&start_stop_sem); - udfs = usb_get_intfdata(uinterf); - if (!udfs || !udfs->probed) { + if (usb->speed != USB_SPEED_HIGH) { dev_err(dev->class_dev, - "usbduxfast: error: auto_attach failed, not connected\n"); - ret = -ENODEV; - } else if (udfs->attached) { + "This driver needs USB 2.0 to operate. Aborting...\n"); + return -ENODEV; + } + + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; + + sema_init(&devpriv->sem, 1); + usb_set_intfdata(intf, devpriv); + + devpriv->duxbuf = kmalloc(SIZEOFDUXBUF, GFP_KERNEL); + if (!devpriv->duxbuf) + return -ENOMEM; + + ret = usb_set_interface(usb, + intf->altsetting->desc.bInterfaceNumber, 1); + if (ret < 0) { dev_err(dev->class_dev, - "usbduxfast: error: auto_attach failed, already attached\n"); - ret = -ENODEV; - } else - ret = usbduxfast_attach_common(dev, udfs); - up(&start_stop_sem); - return ret; + "could not switch to alternate setting 1\n"); + return -ENODEV; + } + + devpriv->urb = usb_alloc_urb(0, GFP_KERNEL); + if (!devpriv->urb) { + dev_err(dev->class_dev, "Could not alloc. urb\n"); + return -ENOMEM; + } + + devpriv->inbuf = kmalloc(SIZEINBUF, GFP_KERNEL); + if (!devpriv->inbuf) + return -ENOMEM; + + ret = comedi_load_firmware(dev, &usb->dev, FIRMWARE, + usbduxfast_upload_firmware, 0); + if (ret) + return ret; + + return usbduxfast_attach_common(dev); } static void usbduxfast_detach(struct comedi_device *dev) { - struct usbduxfastsub_s *usb = dev->private; + struct usb_interface *intf = comedi_to_usb_interface(dev); + struct usbduxfast_private *devpriv = dev->private; - if (usb) { - down(&usb->sem); - down(&start_stop_sem); - dev->private = NULL; - usb->attached = 0; - usb->comedidev = NULL; - up(&start_stop_sem); - up(&usb->sem); + if (!devpriv) + return; + + down(&devpriv->sem); + + usb_set_intfdata(intf, NULL); + + if (devpriv->urb) { + /* waits until a running transfer is over */ + usb_kill_urb(devpriv->urb); + + kfree(devpriv->inbuf); + devpriv->inbuf = NULL; + + usb_free_urb(devpriv->urb); + devpriv->urb = NULL; } + + kfree(devpriv->duxbuf); + devpriv->duxbuf = NULL; + + devpriv->ai_cmd_running = 0; + + up(&devpriv->sem); } static struct comedi_driver usbduxfast_driver = { @@ -1474,178 +1137,10 @@ static struct comedi_driver usbduxfast_driver = { .detach = usbduxfast_detach, }; -static void usbduxfast_firmware_request_complete_handler(const struct firmware - *fw, void *context) -{ - struct usbduxfastsub_s *usbduxfastsub_tmp = context; - struct usb_interface *uinterf = usbduxfastsub_tmp->interface; - int ret; - - if (fw == NULL) - return; - - /* - * we need to upload the firmware here because fw will be - * freed once we've left this function - */ - ret = firmwareUpload(usbduxfastsub_tmp, fw->data, fw->size); - - if (ret) { - dev_err(&uinterf->dev, - "Could not upload firmware (err=%d)\n", ret); - goto out; - } - - comedi_usb_auto_config(uinterf, &usbduxfast_driver, 0); - out: - release_firmware(fw); -} - -static int usbduxfast_usb_probe(struct usb_interface *uinterf, +static int usbduxfast_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) { - struct usb_device *udev = interface_to_usbdev(uinterf); - int i; - int index; - int ret; - - if (udev->speed != USB_SPEED_HIGH) { - dev_err(&uinterf->dev, - "This driver needs USB 2.0 to operate. Aborting...\n"); - return -ENODEV; - } -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi_: usbduxfast_: finding a free structure for " - "the usb-device\n"); -#endif - down(&start_stop_sem); - /* look for a free place in the usbduxfast array */ - index = -1; - for (i = 0; i < NUMUSBDUXFAST; i++) { - if (!usbduxfastsub[i].probed) { - index = i; - break; - } - } - - /* no more space */ - if (index == -1) { - dev_err(&uinterf->dev, - "Too many usbduxfast-devices connected.\n"); - up(&start_stop_sem); - return -EMFILE; - } -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi_: usbduxfast: usbduxfastsub[%d] is ready to " - "connect to comedi.\n", index); -#endif - - sema_init(&(usbduxfastsub[index].sem), 1); - /* save a pointer to the usb device */ - usbduxfastsub[index].usbdev = udev; - - /* save the interface itself */ - usbduxfastsub[index].interface = uinterf; - /* get the interface number from the interface */ - usbduxfastsub[index].ifnum = uinterf->altsetting->desc.bInterfaceNumber; - /* - * hand the private data over to the usb subsystem - * will be needed for disconnect - */ - usb_set_intfdata(uinterf, &(usbduxfastsub[index])); - -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi_: usbduxfast: ifnum=%d\n", - usbduxfastsub[index].ifnum); -#endif - /* create space for the commands going to the usb device */ - usbduxfastsub[index].dux_commands = kmalloc(SIZEOFDUXBUFFER, - GFP_KERNEL); - if (!usbduxfastsub[index].dux_commands) { - tidy_up(&(usbduxfastsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - /* create space of the instruction buffer */ - usbduxfastsub[index].insnBuffer = kmalloc(SIZEINSNBUF, GFP_KERNEL); - if (!usbduxfastsub[index].insnBuffer) { - tidy_up(&(usbduxfastsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - /* setting to alternate setting 1: enabling bulk ep */ - i = usb_set_interface(usbduxfastsub[index].usbdev, - usbduxfastsub[index].ifnum, 1); - if (i < 0) { - dev_err(&uinterf->dev, - "usbduxfast%d: could not switch to alternate setting 1.\n", - index); - tidy_up(&(usbduxfastsub[index])); - up(&start_stop_sem); - return -ENODEV; - } - usbduxfastsub[index].urbIn = usb_alloc_urb(0, GFP_KERNEL); - if (!usbduxfastsub[index].urbIn) { - dev_err(&uinterf->dev, - "usbduxfast%d: Could not alloc. urb\n", index); - tidy_up(&(usbduxfastsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - usbduxfastsub[index].transfer_buffer = kmalloc(SIZEINBUF, GFP_KERNEL); - if (!usbduxfastsub[index].transfer_buffer) { - tidy_up(&(usbduxfastsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - /* we've reached the bottom of the function */ - usbduxfastsub[index].probed = 1; - up(&start_stop_sem); - - ret = request_firmware_nowait(THIS_MODULE, - FW_ACTION_HOTPLUG, - FIRMWARE, - &udev->dev, - GFP_KERNEL, - usbduxfastsub + index, - usbduxfast_firmware_request_complete_handler); - - if (ret) { - dev_err(&uinterf->dev, "could not load firmware (err=%d)\n", ret); - return ret; - } - - dev_info(&uinterf->dev, - "usbduxfast%d has been successfully initialized.\n", index); - /* success */ - return 0; -} - -static void usbduxfast_usb_disconnect(struct usb_interface *intf) -{ - struct usbduxfastsub_s *udfs = usb_get_intfdata(intf); - struct usb_device *udev = interface_to_usbdev(intf); - - if (!udfs) { - dev_err(&intf->dev, "disconnect called with null pointer.\n"); - return; - } - if (udfs->usbdev != udev) { - dev_err(&intf->dev, "BUG! called with wrong ptr!!!\n"); - return; - } - - comedi_usb_auto_unconfig(intf); - - down(&start_stop_sem); - down(&udfs->sem); - tidy_up(udfs); - up(&udfs->sem); - up(&start_stop_sem); - -#ifdef CONFIG_COMEDI_DEBUG - printk(KERN_DEBUG "comedi_: usbduxfast: disconnected from the usb\n"); -#endif + return comedi_usb_auto_config(intf, &usbduxfast_driver, 0); } static const struct usb_device_id usbduxfast_usb_table[] = { @@ -1657,12 +1152,9 @@ static const struct usb_device_id usbduxfast_usb_table[] = { MODULE_DEVICE_TABLE(usb, usbduxfast_usb_table); static struct usb_driver usbduxfast_usb_driver = { -#ifdef COMEDI_HAVE_USB_DRIVER_OWNER - .owner = THIS_MODULE, -#endif .name = "usbduxfast", .probe = usbduxfast_usb_probe, - .disconnect = usbduxfast_usb_disconnect, + .disconnect = comedi_usb_auto_unconfig, .id_table = usbduxfast_usb_table, }; module_comedi_usb_driver(usbduxfast_driver, usbduxfast_usb_driver); diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c index d3bc1b9910a7..898c3c450406 100644 --- a/drivers/staging/comedi/drivers/usbduxsigma.c +++ b/drivers/staging/comedi/drivers/usbduxsigma.c @@ -1,30 +1,27 @@ /* - comedi/drivers/usbdux.c - Copyright (C) 2011 Bernd Porr, Bernd.Porr@f2s.com - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - + * usbduxsigma.c + * Copyright (C) 2011 Bernd Porr, Bernd.Porr@f2s.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ + /* -Driver: usbduxsigma -Description: University of Stirling USB DAQ & INCITE Technology Limited -Devices: [ITL] USB-DUX (usbduxsigma.o) -Author: Bernd Porr -Updated: 8 Nov 2011 -Status: testing -*/ + * Driver: usbduxsigma + * Description: University of Stirling USB DAQ & INCITE Technology Limited + * Devices: (ITL) USB-DUX [usbduxsigma] + * Author: Bernd Porr + * Updated: 8 Nov 2011 + * Status: testing + */ + /* * I must give credit here to Chris Baugher who * wrote the driver for AT-MIO-16d. I used some parts of this @@ -44,9 +41,6 @@ Status: testing * 0.6: corrected wrong input range */ -/* generates loads of debug info */ -/* #define NOISY_DUX_DEBUGBUG */ - #include #include #include @@ -55,7 +49,7 @@ Status: testing #include #include #include -#include + #include "comedi_fc.h" #include "../comedidev.h" @@ -63,38 +57,21 @@ Status: testing #define BULK_TIMEOUT 1000 /* constants for "firmware" upload and download */ -#define FIRMWARE "usbduxsigma_firmware.bin" -#define USBDUXSUB_FIRMWARE 0xA0 -#define VENDOR_DIR_IN 0xC0 -#define VENDOR_DIR_OUT 0x40 +#define FIRMWARE "usbduxsigma_firmware.bin" +#define FIRMWARE_MAX_LEN 0x4000 +#define USBDUXSUB_FIRMWARE 0xa0 +#define VENDOR_DIR_IN 0xc0 +#define VENDOR_DIR_OUT 0x40 /* internal addresses of the 8051 processor */ #define USBDUXSUB_CPUCS 0xE600 -/* - * the minor device number, major is 180 only for debugging purposes and to - * upload special firmware (programming the eeprom etc) which is not - * compatible with the comedi framwork - */ -#define USBDUXSUB_MINOR 32 - -/* max lenghth of the transfer-buffer for software upload */ -#define TB_LEN 0x2000 - -/* Input endpoint number: ISO/IRQ */ -#define ISOINEP 6 - -/* Output endpoint number: ISO/IRQ */ -#define ISOOUTEP 2 - -/* This EP sends DUX commands to USBDUX */ -#define COMMAND_OUT_EP 1 - -/* This EP receives the DUX commands from USBDUX */ -#define COMMAND_IN_EP 8 - -/* Output endpoint for PWM */ -#define PWM_EP 4 +/* USB endpoints */ +#define USBDUXSIGMA_CMD_OUT_EP 1 /* command output */ +#define USBDUXSIGMA_ISO_OUT_EP 2 /* analog output ISO/IRQ */ +#define USBDUXSIGMA_PWM_OUT_EP 4 /* pwm output */ +#define USBDUXSIGMA_ISO_IN_EP 6 /* analog input ISO/IRQ */ +#define USBDUXSIGMA_CMD_IN_EP 8 /* command input */ /* 300Hz max frequ under PWM */ #define MIN_PWM_PERIOD ((long)(1E9/300)) @@ -105,6 +82,8 @@ Status: testing /* Number of channels (16 AD and offset)*/ #define NUMCHANNELS 16 +#define USBDUXSIGMA_NUM_AO_CHAN 4 + /* Size of one A/D value */ #define SIZEADIN ((sizeof(int32_t))) @@ -150,84 +129,54 @@ Status: testing /* must have more buffers due to buggy USB ctr */ #define NUMOFOUTBUFFERSHIGH 10 -/* Total number of usbdux devices */ -#define NUMUSBDUX 16 - -/* Analogue in subdevice */ -#define SUBDEV_AD 0 - -/* Analogue out subdevice */ -#define SUBDEV_DA 1 - -/* Digital I/O */ -#define SUBDEV_DIO 2 - -/* timer aka pwm output */ -#define SUBDEV_PWM 3 - /* number of retries to get the right dux command */ #define RETRIES 10 -/**************************************************/ -/* comedi constants */ -static const struct comedi_lrange range_usbdux_ai_range = { 1, { - BIP_RANGE - (2.65/2.0) - } +/* bulk transfer commands to usbduxsigma */ +#define USBBUXSIGMA_AD_CMD 0 +#define USBDUXSIGMA_DA_CMD 1 +#define USBDUXSIGMA_DIO_CFG_CMD 2 +#define USBDUXSIGMA_DIO_BITS_CMD 3 +#define USBDUXSIGMA_SINGLE_AD_CMD 4 +#define USBDUXSIGMA_PWM_ON_CMD 7 +#define USBDUXSIGMA_PWM_OFF_CMD 8 + +static const struct comedi_lrange usbduxsigma_ai_range = { + 1, { + BIP_RANGE(2.65 / 2.0) + } }; -/* - * private structure of one subdevice - */ - -/* - * This is the structure which holds all the data of - * this driver one sub device just now: A/D - */ -struct usbduxsub { - /* attached? */ - int attached; - /* is it associated with a subdevice? */ - int probed; - /* pointer to the usb-device */ - struct usb_device *usbdev; +struct usbduxsigma_private { /* actual number of in-buffers */ - int numOfInBuffers; + int n_ai_urbs; /* actual number of out-buffers */ - int numOfOutBuffers; + int n_ao_urbs; /* ISO-transfer handling: buffers */ - struct urb **urbIn; - struct urb **urbOut; + struct urb **ai_urbs; + struct urb **ao_urbs; /* pwm-transfer handling */ - struct urb *urbPwm; + struct urb *pwm_urb; /* PWM period */ - unsigned int pwmPeriod; + unsigned int pwm_period; /* PWM internal delay for the GPIF in the FX2 */ - uint8_t pwmDelay; + uint8_t pwm_delay; /* size of the PWM buffer which holds the bit pattern */ - int sizePwmBuf; + int pwm_buf_sz; /* input buffer for the ISO-transfer */ - int32_t *inBuffer; + int32_t *in_buf; /* input buffer for single insn */ - int8_t *insnBuffer; - /* output buffer for single DA outputs */ - int16_t *outBuffer; - /* interface number */ - int ifnum; - /* interface structure in 2.6 */ - struct usb_interface *interface; - /* comedi device for the interrupt context */ - struct comedi_device *comedidev; - /* is it USB_SPEED_HIGH or not? */ - short int high_speed; - /* asynchronous command is running */ - short int ai_cmd_running; - short int ao_cmd_running; - /* pwm is running */ - short int pwm_cmd_running; - /* continuous acquisition */ - short int ai_continuous; - short int ao_continuous; + int8_t *insn_buf; + + unsigned int ao_readback[USBDUXSIGMA_NUM_AO_CHAN]; + + unsigned high_speed:1; + unsigned ai_cmd_running:1; + unsigned ai_continuous:1; + unsigned ao_cmd_running:1; + unsigned ao_continuous:1; + unsigned pwm_cmd_running:1; + /* number of samples to acquire */ int ai_sample_count; int ao_sample_count; @@ -246,126 +195,58 @@ struct usbduxsub { struct semaphore sem; }; -/* - * The pointer to the private usb-data of the driver is also the private data - * for the comedi-device. This has to be global as the usb subsystem needs - * global variables. The other reason is that this structure must be there - * _before_ any comedi command is issued. The usb subsystem must be initialised - * before comedi can access it. - */ -static struct usbduxsub usbduxsub[NUMUSBDUX]; - -static DEFINE_SEMAPHORE(start_stop_sem); - -/* - * Stops the data acquision - * It should be safe to call this function from any context - */ -static int usbduxsub_unlink_InURBs(struct usbduxsub *usbduxsub_tmp) +static void usbduxsigma_ai_stop(struct comedi_device *dev, int do_unlink) { - int i = 0; - int err = 0; - - if (usbduxsub_tmp && usbduxsub_tmp->urbIn) { - for (i = 0; i < usbduxsub_tmp->numOfInBuffers; i++) { - if (usbduxsub_tmp->urbIn[i]) { - /* We wait here until all transfers have been - * cancelled. */ - usb_kill_urb(usbduxsub_tmp->urbIn[i]); - } - dev_dbg(&usbduxsub_tmp->interface->dev, - "comedi: usbdux: unlinked InURB %d, err=%d\n", - i, err); - } - } - return err; -} - -/* - * This will stop a running acquisition operation - * Is called from within this driver from both the - * interrupt context and from comedi - */ -static int usbdux_ai_stop(struct usbduxsub *this_usbduxsub, int do_unlink) -{ - int ret = 0; - - if (!this_usbduxsub) { - pr_err("comedi?: usbdux_ai_stop: this_usbduxsub=NULL!\n"); - return -EFAULT; - } - dev_dbg(&this_usbduxsub->interface->dev, "comedi: usbdux_ai_stop\n"); + struct usbduxsigma_private *devpriv = dev->private; if (do_unlink) { - /* stop aquistion */ - ret = usbduxsub_unlink_InURBs(this_usbduxsub); + int i; + + for (i = 0; i < devpriv->n_ai_urbs; i++) { + if (devpriv->ai_urbs[i]) + usb_kill_urb(devpriv->ai_urbs[i]); + } } - this_usbduxsub->ai_cmd_running = 0; - - return ret; + devpriv->ai_cmd_running = 0; } -/* - * This will cancel a running acquisition operation. - * This is called by comedi but never from inside the driver. - */ -static int usbdux_ai_cancel(struct comedi_device *dev, - struct comedi_subdevice *s) +static int usbduxsigma_ai_cancel(struct comedi_device *dev, + struct comedi_subdevice *s) { - struct usbduxsub *this_usbduxsub; - int res = 0; + struct usbduxsigma_private *devpriv = dev->private; - /* force unlink of all urbs */ - this_usbduxsub = dev->private; - if (!this_usbduxsub) - return -EFAULT; + down(&devpriv->sem); + /* unlink only if it is really running */ + usbduxsigma_ai_stop(dev, devpriv->ai_cmd_running); + up(&devpriv->sem); - dev_dbg(&this_usbduxsub->interface->dev, "comedi: usbdux_ai_cancel\n"); - - /* prevent other CPUs from submitting new commands just now */ - down(&this_usbduxsub->sem); - if (!(this_usbduxsub->probed)) { - up(&this_usbduxsub->sem); - return -ENODEV; - } - /* unlink only if the urb really has been submitted */ - res = usbdux_ai_stop(this_usbduxsub, this_usbduxsub->ai_cmd_running); - up(&this_usbduxsub->sem); - return res; + return 0; } -/* analogue IN - interrupt service routine */ -static void usbduxsub_ai_IsocIrq(struct urb *urb) +static void usbduxsigma_ai_urb_complete(struct urb *urb) { - int i, err, n; - struct usbduxsub *this_usbduxsub; - struct comedi_device *this_comedidev; - struct comedi_subdevice *s; - int32_t v; + struct comedi_device *dev = urb->context; + struct usbduxsigma_private *devpriv = dev->private; + struct comedi_subdevice *s = dev->read_subdev; unsigned int dio_state; - - /* the context variable points to the comedi device */ - this_comedidev = urb->context; - /* the private structure of the subdevice is struct usbduxsub */ - this_usbduxsub = this_comedidev->private; - /* subdevice which is the AD converter */ - s = &this_comedidev->subdevices[SUBDEV_AD]; + int32_t val; + int ret; + int i; /* first we test if something unusual has just happened */ switch (urb->status) { case 0: /* copy the result in the transfer buffer */ - memcpy(this_usbduxsub->inBuffer, - urb->transfer_buffer, SIZEINBUF); + memcpy(devpriv->in_buf, urb->transfer_buffer, SIZEINBUF); break; case -EILSEQ: - /* error in the ISOchronous data */ - /* we don't copy the data into the transfer buffer */ - /* and recycle the last data byte */ - dev_dbg(&urb->dev->dev, - "comedi%d: usbdux: CRC error in ISO IN stream.\n", - this_usbduxsub->comedidev->minor); + /* + * error in the ISOchronous data + * we don't copy the data into the transfer buffer + * and recycle the last data byte + */ + dev_dbg(dev->class_dev, "CRC error in ISO IN stream\n"); break; @@ -374,185 +255,127 @@ static void usbduxsub_ai_IsocIrq(struct urb *urb) case -ESHUTDOWN: case -ECONNABORTED: /* happens after an unlink command */ - if (this_usbduxsub->ai_cmd_running) { - /* we are still running a command */ - /* tell this comedi */ - s->async->events |= COMEDI_CB_EOA; - s->async->events |= COMEDI_CB_ERROR; - comedi_event(this_usbduxsub->comedidev, s); - /* stop the transfer w/o unlink */ - usbdux_ai_stop(this_usbduxsub, 0); + if (devpriv->ai_cmd_running) { + usbduxsigma_ai_stop(dev, 0); /* w/o unlink */ + /* we are still running a command, tell comedi */ + s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR); + comedi_event(dev, s); } return; default: - /* a real error on the bus */ - /* pass error to comedi if we are really running a command */ - if (this_usbduxsub->ai_cmd_running) { - dev_err(&urb->dev->dev, - "Non-zero urb status received in ai intr " - "context: %d\n", urb->status); - s->async->events |= COMEDI_CB_EOA; - s->async->events |= COMEDI_CB_ERROR; - comedi_event(this_usbduxsub->comedidev, s); - /* don't do an unlink here */ - usbdux_ai_stop(this_usbduxsub, 0); + /* + * a real error on the bus + * pass error to comedi if we are really running a command + */ + if (devpriv->ai_cmd_running) { + dev_err(dev->class_dev, + "%s: non-zero urb status (%d)\n", + __func__, urb->status); + usbduxsigma_ai_stop(dev, 0); /* w/o unlink */ + s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR); + comedi_event(dev, s); } return; } - /* - * at this point we are reasonably sure that nothing dodgy has happened - * are we running a command? - */ - if (unlikely((!(this_usbduxsub->ai_cmd_running)))) { - /* - * not running a command, do not continue execution if no - * asynchronous command is running in particular not resubmit - */ + if (unlikely(!devpriv->ai_cmd_running)) return; - } - urb->dev = this_usbduxsub->usbdev; + urb->dev = comedi_to_usb_dev(dev); - /* resubmit the urb */ - err = usb_submit_urb(urb, GFP_ATOMIC); - if (unlikely(err < 0)) { - dev_err(&urb->dev->dev, - "comedi_: urb resubmit failed in int-context!" - "err=%d\n", - err); - if (err == -EL2NSYNC) - dev_err(&urb->dev->dev, - "buggy USB host controller or bug in IRQ " - "handler!\n"); - s->async->events |= COMEDI_CB_EOA; - s->async->events |= COMEDI_CB_ERROR; - comedi_event(this_usbduxsub->comedidev, s); - /* don't do an unlink here */ - usbdux_ai_stop(this_usbduxsub, 0); + ret = usb_submit_urb(urb, GFP_ATOMIC); + if (unlikely(ret < 0)) { + dev_err(dev->class_dev, "%s: urb resubmit failed (%d)\n", + __func__, ret); + if (ret == -EL2NSYNC) + dev_err(dev->class_dev, + "buggy USB host controller or bug in IRQ handler\n"); + usbduxsigma_ai_stop(dev, 0); /* w/o unlink */ + s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR); + comedi_event(dev, s); return; } /* get the state of the dio pins to allow external trigger */ - dio_state = be32_to_cpu(this_usbduxsub->inBuffer[0]); + dio_state = be32_to_cpu(devpriv->in_buf[0]); - this_usbduxsub->ai_counter--; - if (likely(this_usbduxsub->ai_counter > 0)) + devpriv->ai_counter--; + if (likely(devpriv->ai_counter > 0)) return; /* timer zero, transfer measurements to comedi */ - this_usbduxsub->ai_counter = this_usbduxsub->ai_timer; + devpriv->ai_counter = devpriv->ai_timer; - /* test, if we transmit only a fixed number of samples */ - if (!(this_usbduxsub->ai_continuous)) { + if (!devpriv->ai_continuous) { /* not continuous, fixed number of samples */ - this_usbduxsub->ai_sample_count--; - /* all samples received? */ - if (this_usbduxsub->ai_sample_count < 0) { - /* prevent a resubmit next time */ - usbdux_ai_stop(this_usbduxsub, 0); - /* say comedi that the acquistion is over */ + devpriv->ai_sample_count--; + if (devpriv->ai_sample_count < 0) { + usbduxsigma_ai_stop(dev, 0); /* w/o unlink */ + /* acquistion is over, tell comedi */ s->async->events |= COMEDI_CB_EOA; - comedi_event(this_usbduxsub->comedidev, s); + comedi_event(dev, s); return; } } + /* get the data from the USB bus and hand it over to comedi */ - n = s->async->cmd.chanlist_len; - for (i = 0; i < n; i++) { + for (i = 0; i < s->async->cmd.chanlist_len; i++) { /* transfer data, note first byte is the DIO state */ - v = be32_to_cpu(this_usbduxsub->inBuffer[i+1]); - /* strip status byte */ - v = v & 0x00ffffff; - /* convert to unsigned */ - v = v ^ 0x00800000; - /* write the byte to the buffer */ - err = cfc_write_array_to_buffer(s, &v, sizeof(uint32_t)); - if (unlikely(err == 0)) { + val = be32_to_cpu(devpriv->in_buf[i+1]); + val &= 0x00ffffff; /* strip status byte */ + val ^= 0x00800000; /* convert to unsigned */ + + ret = cfc_write_array_to_buffer(s, &val, sizeof(uint32_t)); + if (unlikely(ret == 0)) { /* buffer overflow */ - usbdux_ai_stop(this_usbduxsub, 0); + usbduxsigma_ai_stop(dev, 0); /* w/o unlink */ return; } } /* tell comedi that data is there */ - s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; - comedi_event(this_usbduxsub->comedidev, s); + s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS); + comedi_event(dev, s); } -static int usbduxsub_unlink_OutURBs(struct usbduxsub *usbduxsub_tmp) +static void usbduxsigma_ao_stop(struct comedi_device *dev, int do_unlink) { - int i = 0; - int err = 0; + struct usbduxsigma_private *devpriv = dev->private; - if (usbduxsub_tmp && usbduxsub_tmp->urbOut) { - for (i = 0; i < usbduxsub_tmp->numOfOutBuffers; i++) { - if (usbduxsub_tmp->urbOut[i]) - usb_kill_urb(usbduxsub_tmp->urbOut[i]); + if (do_unlink) { + int i; - dev_dbg(&usbduxsub_tmp->interface->dev, - "comedi: usbdux: unlinked OutURB %d: res=%d\n", - i, err); + for (i = 0; i < devpriv->n_ao_urbs; i++) { + if (devpriv->ao_urbs[i]) + usb_kill_urb(devpriv->ao_urbs[i]); } } - return err; + + devpriv->ao_cmd_running = 0; } -/* This will cancel a running acquisition operation - * in any context. - */ -static int usbdux_ao_stop(struct usbduxsub *this_usbduxsub, int do_unlink) +static int usbduxsigma_ao_cancel(struct comedi_device *dev, + struct comedi_subdevice *s) { - int ret = 0; + struct usbduxsigma_private *devpriv = dev->private; - if (!this_usbduxsub) - return -EFAULT; - dev_dbg(&this_usbduxsub->interface->dev, "comedi: usbdux_ao_cancel\n"); - - if (do_unlink) - ret = usbduxsub_unlink_OutURBs(this_usbduxsub); - - this_usbduxsub->ao_cmd_running = 0; - - return ret; -} - -/* force unlink, is called by comedi */ -static int usbdux_ao_cancel(struct comedi_device *dev, - struct comedi_subdevice *s) -{ - struct usbduxsub *this_usbduxsub = dev->private; - int res = 0; - - if (!this_usbduxsub) - return -EFAULT; - - /* prevent other CPUs from submitting a command just now */ - down(&this_usbduxsub->sem); - if (!(this_usbduxsub->probed)) { - up(&this_usbduxsub->sem); - return -ENODEV; - } + down(&devpriv->sem); /* unlink only if it is really running */ - res = usbdux_ao_stop(this_usbduxsub, this_usbduxsub->ao_cmd_running); - up(&this_usbduxsub->sem); - return res; + usbduxsigma_ao_stop(dev, devpriv->ao_cmd_running); + up(&devpriv->sem); + + return 0; } -static void usbduxsub_ao_IsocIrq(struct urb *urb) +static void usbduxsigma_ao_urb_complete(struct urb *urb) { - int i, ret; + struct comedi_device *dev = urb->context; + struct usbduxsigma_private *devpriv = dev->private; + struct comedi_subdevice *s = dev->write_subdev; uint8_t *datap; - struct usbduxsub *this_usbduxsub; - struct comedi_device *this_comedidev; - struct comedi_subdevice *s; - - /* the context variable points to the subdevice */ - this_comedidev = urb->context; - /* the private structure of the subdevice is struct usbduxsub */ - this_usbduxsub = this_comedidev->private; - - s = &this_comedidev->subdevices[SUBDEV_DA]; + int len; + int ret; + int i; switch (urb->status) { case 0: @@ -563,347 +386,141 @@ static void usbduxsub_ao_IsocIrq(struct urb *urb) case -ENOENT: case -ESHUTDOWN: case -ECONNABORTED: - /* after an unlink command, unplug, ... etc */ - /* no unlink needed here. Already shutting down. */ - if (this_usbduxsub->ao_cmd_running) { + /* happens after an unlink command */ + if (devpriv->ao_cmd_running) { + usbduxsigma_ao_stop(dev, 0); /* w/o unlink */ s->async->events |= COMEDI_CB_EOA; - comedi_event(this_usbduxsub->comedidev, s); - usbdux_ao_stop(this_usbduxsub, 0); + comedi_event(dev, s); } return; default: /* a real error */ - if (this_usbduxsub->ao_cmd_running) { - dev_err(&urb->dev->dev, - "comedi_: Non-zero urb status received in ao " - "intr context: %d\n", urb->status); - s->async->events |= COMEDI_CB_ERROR; - s->async->events |= COMEDI_CB_EOA; - comedi_event(this_usbduxsub->comedidev, s); - /* we do an unlink if we are in the high speed mode */ - usbdux_ao_stop(this_usbduxsub, 0); + if (devpriv->ao_cmd_running) { + dev_err(dev->class_dev, + "%s: non-zero urb status (%d)\n", + __func__, urb->status); + usbduxsigma_ao_stop(dev, 0); /* w/o unlink */ + s->async->events |= (COMEDI_CB_ERROR | COMEDI_CB_EOA); + comedi_event(dev, s); } return; } - /* are we actually running? */ - if (!(this_usbduxsub->ao_cmd_running)) + if (!devpriv->ao_cmd_running) return; - /* normal operation: executing a command in this subdevice */ - this_usbduxsub->ao_counter--; - if ((int)this_usbduxsub->ao_counter <= 0) { - /* timer zero */ - this_usbduxsub->ao_counter = this_usbduxsub->ao_timer; + devpriv->ao_counter--; + if ((int)devpriv->ao_counter <= 0) { + /* timer zero, transfer from comedi */ + devpriv->ao_counter = devpriv->ao_timer; - /* handle non continuous acquisition */ - if (!(this_usbduxsub->ao_continuous)) { - /* fixed number of samples */ - this_usbduxsub->ao_sample_count--; - if (this_usbduxsub->ao_sample_count < 0) { - /* all samples transmitted */ - usbdux_ao_stop(this_usbduxsub, 0); + if (!devpriv->ao_continuous) { + /* not continuous, fixed number of samples */ + devpriv->ao_sample_count--; + if (devpriv->ao_sample_count < 0) { + usbduxsigma_ao_stop(dev, 0); /* w/o unlink */ + /* acquistion is over, tell comedi */ s->async->events |= COMEDI_CB_EOA; - comedi_event(this_usbduxsub->comedidev, s); - /* no resubmit of the urb */ + comedi_event(dev, s); return; } } + /* transmit data to the USB bus */ - ((uint8_t *) (urb->transfer_buffer))[0] = - s->async->cmd.chanlist_len; - for (i = 0; i < s->async->cmd.chanlist_len; i++) { - short temp; - if (i >= NUMOUTCHANNELS) - break; + datap = urb->transfer_buffer; + len = s->async->cmd.chanlist_len; + *datap++ = len; + for (i = 0; i < len; i++) { + unsigned int chan = devpriv->dac_commands[i]; + short val; - /* pointer to the DA */ - datap = - (&(((uint8_t *) urb->transfer_buffer)[i * 2 + 1])); - /* get the data from comedi */ - ret = comedi_buf_get(s->async, &temp); - datap[0] = temp; - datap[1] = this_usbduxsub->dac_commands[i]; - /* printk("data[0]=%x, data[1]=%x, data[2]=%x\n", */ - /* datap[0],datap[1],datap[2]); */ + ret = comedi_buf_get(s->async, &val); if (ret < 0) { - dev_err(&urb->dev->dev, - "comedi: buffer underflow\n"); - s->async->events |= COMEDI_CB_EOA; - s->async->events |= COMEDI_CB_OVERFLOW; + dev_err(dev->class_dev, "buffer underflow\n"); + s->async->events |= (COMEDI_CB_EOA | + COMEDI_CB_OVERFLOW); } - /* transmit data to comedi */ + *datap++ = val; + *datap++ = chan; + devpriv->ao_readback[chan] = val; + s->async->events |= COMEDI_CB_BLOCK; - comedi_event(this_usbduxsub->comedidev, s); + comedi_event(dev, s); } } + urb->transfer_buffer_length = SIZEOUTBUF; - urb->dev = this_usbduxsub->usbdev; + urb->dev = comedi_to_usb_dev(dev); urb->status = 0; - if (this_usbduxsub->ao_cmd_running) { - if (this_usbduxsub->high_speed) { - /* uframes */ - urb->interval = 8; - } else { - /* frames */ - urb->interval = 1; - } - urb->number_of_packets = 1; - urb->iso_frame_desc[0].offset = 0; - urb->iso_frame_desc[0].length = SIZEOUTBUF; - urb->iso_frame_desc[0].status = 0; - ret = usb_submit_urb(urb, GFP_ATOMIC); - if (ret < 0) { - dev_err(&urb->dev->dev, - "comedi_: ao urb resubm failed in int-cont. " - "ret=%d", ret); - if (ret == EL2NSYNC) - dev_err(&urb->dev->dev, - "buggy USB host controller or bug in " - "IRQ handling!\n"); - - s->async->events |= COMEDI_CB_EOA; - s->async->events |= COMEDI_CB_ERROR; - comedi_event(this_usbduxsub->comedidev, s); - /* don't do an unlink here */ - usbdux_ao_stop(this_usbduxsub, 0); - } + if (devpriv->high_speed) + urb->interval = 8; /* uframes */ + else + urb->interval = 1; /* frames */ + urb->number_of_packets = 1; + urb->iso_frame_desc[0].offset = 0; + urb->iso_frame_desc[0].length = SIZEOUTBUF; + urb->iso_frame_desc[0].status = 0; + ret = usb_submit_urb(urb, GFP_ATOMIC); + if (ret < 0) { + dev_err(dev->class_dev, + "%s: urb resubmit failed (%d)\n", + __func__, ret); + if (ret == EL2NSYNC) + dev_err(dev->class_dev, + "buggy USB host controller or bug in IRQ handler\n"); + usbduxsigma_ao_stop(dev, 0); /* w/o unlink */ + s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR); + comedi_event(dev, s); } } -static int usbduxsub_start(struct usbduxsub *usbduxsub) -{ - int errcode = 0; - uint8_t *local_transfer_buffer; - - local_transfer_buffer = kmalloc(16, GFP_KERNEL); - if (!local_transfer_buffer) - return -ENOMEM; - - /* 7f92 to zero */ - local_transfer_buffer[0] = 0; - errcode = usb_control_msg(usbduxsub->usbdev, - /* create a pipe for a control transfer */ - usb_sndctrlpipe(usbduxsub->usbdev, 0), - /* bRequest, "Firmware" */ - USBDUXSUB_FIRMWARE, - /* bmRequestType */ - VENDOR_DIR_OUT, - /* Value */ - USBDUXSUB_CPUCS, - /* Index */ - 0x0000, - /* address of the transfer buffer */ - local_transfer_buffer, - /* Length */ - 1, - /* Timeout */ - BULK_TIMEOUT); - if (errcode < 0) - dev_err(&usbduxsub->interface->dev, - "comedi_: control msg failed (start)\n"); - - kfree(local_transfer_buffer); - return errcode; -} - -static int usbduxsub_stop(struct usbduxsub *usbduxsub) -{ - int errcode = 0; - uint8_t *local_transfer_buffer; - - local_transfer_buffer = kmalloc(16, GFP_KERNEL); - if (!local_transfer_buffer) - return -ENOMEM; - - /* 7f92 to one */ - local_transfer_buffer[0] = 1; - errcode = usb_control_msg(usbduxsub->usbdev, - usb_sndctrlpipe(usbduxsub->usbdev, 0), - /* bRequest, "Firmware" */ - USBDUXSUB_FIRMWARE, - /* bmRequestType */ - VENDOR_DIR_OUT, - /* Value */ - USBDUXSUB_CPUCS, - /* Index */ - 0x0000, local_transfer_buffer, - /* Length */ - 1, - /* Timeout */ - BULK_TIMEOUT); - if (errcode < 0) - dev_err(&usbduxsub->interface->dev, - "comedi_: control msg failed (stop)\n"); - - kfree(local_transfer_buffer); - return errcode; -} - -static int usbduxsub_upload(struct usbduxsub *usbduxsub, - uint8_t *local_transfer_buffer, - unsigned int startAddr, unsigned int len) -{ - int errcode; - - errcode = usb_control_msg(usbduxsub->usbdev, - usb_sndctrlpipe(usbduxsub->usbdev, 0), - /* brequest, firmware */ - USBDUXSUB_FIRMWARE, - /* bmRequestType */ - VENDOR_DIR_OUT, - /* value */ - startAddr, - /* index */ - 0x0000, - /* our local safe buffer */ - local_transfer_buffer, - /* length */ - len, - /* timeout */ - BULK_TIMEOUT); - dev_dbg(&usbduxsub->interface->dev, "comedi_: result=%d\n", errcode); - if (errcode < 0) { - dev_err(&usbduxsub->interface->dev, - "comedi_: upload failed\n"); - return errcode; - } - return 0; -} - -/* the FX2LP has twice as much as the standard FX2 */ -#define FIRMWARE_MAX_LEN 0x4000 - -static int firmwareUpload(struct usbduxsub *usbduxsub, - const u8 *firmwareBinary, int sizeFirmware) +static int usbduxsigma_submit_urbs(struct comedi_device *dev, + struct urb **urbs, int num_urbs, + int input_urb) { + struct usb_device *usb = comedi_to_usb_dev(dev); + struct usbduxsigma_private *devpriv = dev->private; + struct urb *urb; int ret; - uint8_t *fwBuf; - - if (!firmwareBinary) - return 0; - - if (sizeFirmware > FIRMWARE_MAX_LEN) { - dev_err(&usbduxsub->interface->dev, - "usbduxsigma firmware binary it too large for FX2.\n"); - return -ENOMEM; - } - - /* we generate a local buffer for the firmware */ - fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL); - if (!fwBuf) { - dev_err(&usbduxsub->interface->dev, - "comedi_: mem alloc for firmware failed\n"); - return -ENOMEM; - } - - ret = usbduxsub_stop(usbduxsub); - if (ret < 0) { - dev_err(&usbduxsub->interface->dev, - "comedi_: can not stop firmware\n"); - kfree(fwBuf); - return ret; - } - - ret = usbduxsub_upload(usbduxsub, fwBuf, 0, sizeFirmware); - if (ret < 0) { - dev_err(&usbduxsub->interface->dev, - "comedi_: firmware upload failed\n"); - kfree(fwBuf); - return ret; - } - ret = usbduxsub_start(usbduxsub); - if (ret < 0) { - dev_err(&usbduxsub->interface->dev, - "comedi_: can not start firmware\n"); - kfree(fwBuf); - return ret; - } - kfree(fwBuf); - return 0; -} - -static int usbduxsub_submit_InURBs(struct usbduxsub *usbduxsub) -{ - int i, errFlag; - - if (!usbduxsub) - return -EFAULT; + int i; /* Submit all URBs and start the transfer on the bus */ - for (i = 0; i < usbduxsub->numOfInBuffers; i++) { + for (i = 0; i < num_urbs; i++) { + urb = urbs[i]; + /* in case of a resubmission after an unlink... */ - usbduxsub->urbIn[i]->interval = usbduxsub->ai_interval; - usbduxsub->urbIn[i]->context = usbduxsub->comedidev; - usbduxsub->urbIn[i]->dev = usbduxsub->usbdev; - usbduxsub->urbIn[i]->status = 0; - usbduxsub->urbIn[i]->transfer_flags = URB_ISO_ASAP; - dev_dbg(&usbduxsub->interface->dev, - "comedi%d: submitting in-urb[%d]: %p,%p intv=%d\n", - usbduxsub->comedidev->minor, i, - (usbduxsub->urbIn[i]->context), - (usbduxsub->urbIn[i]->dev), - (usbduxsub->urbIn[i]->interval)); - errFlag = usb_submit_urb(usbduxsub->urbIn[i], GFP_ATOMIC); - if (errFlag) { - dev_err(&usbduxsub->interface->dev, - "comedi_: ai: usb_submit_urb(%d) error %d\n", - i, errFlag); - return errFlag; - } + if (input_urb) + urb->interval = devpriv->ai_interval; + urb->context = dev; + urb->dev = usb; + urb->status = 0; + urb->transfer_flags = URB_ISO_ASAP; + + ret = usb_submit_urb(urb, GFP_ATOMIC); + if (ret) + return ret; } return 0; } -static int usbduxsub_submit_OutURBs(struct usbduxsub *usbduxsub) +static int usbduxsigma_chans_to_interval(int num_chan) { - int i, errFlag; - - if (!usbduxsub) - return -EFAULT; - - for (i = 0; i < usbduxsub->numOfOutBuffers; i++) { - dev_dbg(&usbduxsub->interface->dev, - "comedi_: submitting out-urb[%d]\n", i); - /* in case of a resubmission after an unlink... */ - usbduxsub->urbOut[i]->context = usbduxsub->comedidev; - usbduxsub->urbOut[i]->dev = usbduxsub->usbdev; - usbduxsub->urbOut[i]->status = 0; - usbduxsub->urbOut[i]->transfer_flags = URB_ISO_ASAP; - errFlag = usb_submit_urb(usbduxsub->urbOut[i], GFP_ATOMIC); - if (errFlag) { - dev_err(&usbduxsub->interface->dev, - "comedi_: ao: usb_submit_urb(%d) error %d\n", - i, errFlag); - return errFlag; - } - } - return 0; + if (num_chan <= 2) + return 2; /* 4kHz */ + if (num_chan <= 8) + return 4; /* 2kHz */ + return 8; /* 1kHz */ } -static int chanToInterval(int nChannels) +static int usbduxsigma_ai_cmdtest(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_cmd *cmd) { - if (nChannels <= 2) - /* 4kHz */ - return 2; - if (nChannels <= 8) - /* 2kHz */ - return 4; - /* 1kHz */ - return 8; -} - -static int usbdux_ai_cmdtest(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_cmd *cmd) -{ - struct usbduxsub *this_usbduxsub = dev->private; - int err = 0, i; - unsigned int tmpTimer; - - if (!(this_usbduxsub->probed)) - return -ENODEV; + struct usbduxsigma_private *devpriv = dev->private; + int high_speed = devpriv->high_speed; + int interval = usbduxsigma_chans_to_interval(cmd->chanlist_len); + int err = 0; /* Step 1 : check if triggers are trivially valid */ @@ -934,34 +551,28 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev, err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0); if (cmd->scan_begin_src == TRIG_TIMER) { - if (this_usbduxsub->high_speed) { + unsigned int tmp; + + if (high_speed) { /* * In high speed mode microframes are possible. * However, during one microframe we can roughly * sample two channels. Thus, the more channels * are in the channel list the more time we need. */ - i = chanToInterval(cmd->chanlist_len); err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg, - (1000000 / 8 * i)); - /* now calc the real sampling rate with all the - * rounding errors */ - tmpTimer = - ((unsigned int)(cmd->scan_begin_arg / 125000)) * - 125000; + (1000000 / 8 * interval)); + + tmp = (cmd->scan_begin_arg / 125000) * 125000; } else { /* full speed */ /* 1kHz scans every USB frame */ err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg, 1000000); - /* - * calc the real sampling rate with the rounding errors - */ - tmpTimer = ((unsigned int)(cmd->scan_begin_arg / - 1000000)) * 1000000; + + tmp = (cmd->scan_begin_arg / 1000000) * 1000000; } - err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, - tmpTimer); + err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, tmp); } err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); @@ -976,6 +587,37 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev, if (err) return 3; + /* Step 4: fix up any arguments */ + + if (high_speed) { + /* + * every 2 channels get a time window of 125us. Thus, if we + * sample all 16 channels we need 1ms. If we sample only one + * channel we need only 125us + */ + devpriv->ai_interval = interval; + devpriv->ai_timer = cmd->scan_begin_arg / (125000 * interval); + } else { + /* interval always 1ms */ + devpriv->ai_interval = 1; + devpriv->ai_timer = cmd->scan_begin_arg / 1000000; + } + if (devpriv->ai_timer < 1) + err |= -EINVAL; + + if (cmd->stop_src == TRIG_COUNT) { + /* data arrives as one packet */ + devpriv->ai_sample_count = cmd->stop_arg; + devpriv->ai_continuous = 0; + } else { + /* continuous acquisition */ + devpriv->ai_continuous = 1; + devpriv->ai_sample_count = 0; + } + + if (err) + return 4; + return 0; } @@ -993,536 +635,278 @@ static void create_adc_command(unsigned int chan, (*muxsg1) = (*muxsg1) | (1 << (chan-8)); } - -/* bulk transfers to usbdux */ - -#define SENDADCOMMANDS 0 -#define SENDDACOMMANDS 1 -#define SENDDIOCONFIGCOMMAND 2 -#define SENDDIOBITSCOMMAND 3 -#define SENDSINGLEAD 4 -#define SENDPWMON 7 -#define SENDPWMOFF 8 - -static int send_dux_commands(struct usbduxsub *this_usbduxsub, int cmd_type) +static int usbbuxsigma_send_cmd(struct comedi_device *dev, int cmd_type) { - int result, nsent; + struct usb_device *usb = comedi_to_usb_dev(dev); + struct usbduxsigma_private *devpriv = dev->private; + int nsent; - this_usbduxsub->dux_commands[0] = cmd_type; -#ifdef NOISY_DUX_DEBUGBUG - printk(KERN_DEBUG "comedi%d: usbdux: dux_commands: ", - this_usbduxsub->comedidev->minor); - for (result = 0; result < SIZEOFDUXBUFFER; result++) - printk(" %02x", this_usbduxsub->dux_commands[result]); - printk("\n"); -#endif - result = usb_bulk_msg(this_usbduxsub->usbdev, - usb_sndbulkpipe(this_usbduxsub->usbdev, - COMMAND_OUT_EP), - this_usbduxsub->dux_commands, SIZEOFDUXBUFFER, - &nsent, BULK_TIMEOUT); - if (result < 0) - dev_err(&this_usbduxsub->interface->dev, "comedi%d: " - "could not transmit dux_command to the usb-device, " - "err=%d\n", this_usbduxsub->comedidev->minor, result); + devpriv->dux_commands[0] = cmd_type; - return result; + return usb_bulk_msg(usb, usb_sndbulkpipe(usb, USBDUXSIGMA_CMD_OUT_EP), + devpriv->dux_commands, SIZEOFDUXBUFFER, + &nsent, BULK_TIMEOUT); } -static int receive_dux_commands(struct usbduxsub *this_usbduxsub, int command) +static int usbduxsigma_receive_cmd(struct comedi_device *dev, int command) { - int result = (-EFAULT); + struct usb_device *usb = comedi_to_usb_dev(dev); + struct usbduxsigma_private *devpriv = dev->private; int nrec; + int ret; int i; for (i = 0; i < RETRIES; i++) { - result = usb_bulk_msg(this_usbduxsub->usbdev, - usb_rcvbulkpipe(this_usbduxsub->usbdev, - COMMAND_IN_EP), - this_usbduxsub->insnBuffer, SIZEINSNBUF, - &nrec, BULK_TIMEOUT); - if (result < 0) { - dev_err(&this_usbduxsub->interface->dev, "comedi%d: " - "insn: USB error %d " - "while receiving DUX command" - "\n", this_usbduxsub->comedidev->minor, - result); - return result; - } - if (this_usbduxsub->insnBuffer[0] == command) - return result; + ret = usb_bulk_msg(usb, + usb_rcvbulkpipe(usb, USBDUXSIGMA_CMD_IN_EP), + devpriv->insn_buf, SIZEINSNBUF, + &nrec, BULK_TIMEOUT); + if (ret < 0) + return ret; + + if (devpriv->insn_buf[0] == command) + return 0; } - /* this is only reached if the data has been requested a couple of - * times */ - dev_err(&this_usbduxsub->interface->dev, "comedi%d: insn: " - "wrong data returned from firmware: want %d, got %d.\n", - this_usbduxsub->comedidev->minor, command, - this_usbduxsub->insnBuffer[0]); + /* + * This is only reached if the data has been requested a + * couple of times and the command was not received. + */ return -EFAULT; } -static int usbdux_ai_inttrig(struct comedi_device *dev, - struct comedi_subdevice *s, unsigned int trignum) +static int usbduxsigma_ai_inttrig(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned int trignum) { + struct usbduxsigma_private *devpriv = dev->private; int ret; - struct usbduxsub *this_usbduxsub = dev->private; - if (!this_usbduxsub) - return -EFAULT; - down(&this_usbduxsub->sem); - if (!(this_usbduxsub->probed)) { - up(&this_usbduxsub->sem); - return -ENODEV; - } - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: usbdux_ai_inttrig\n", dev->minor); - - if (trignum != 0) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: usbdux_ai_inttrig: invalid trignum\n", - dev->minor); - up(&this_usbduxsub->sem); + if (trignum != 0) return -EINVAL; - } - if (!(this_usbduxsub->ai_cmd_running)) { - this_usbduxsub->ai_cmd_running = 1; - ret = usbduxsub_submit_InURBs(this_usbduxsub); + + down(&devpriv->sem); + if (!devpriv->ai_cmd_running) { + ret = usbduxsigma_submit_urbs(dev, devpriv->ai_urbs, + devpriv->n_ai_urbs, 1); if (ret < 0) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: usbdux_ai_inttrig: " - "urbSubmit: err=%d\n", dev->minor, ret); - this_usbduxsub->ai_cmd_running = 0; - up(&this_usbduxsub->sem); + up(&devpriv->sem); return ret; } + devpriv->ai_cmd_running = 1; s->async->inttrig = NULL; - } else { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: ai_inttrig but acqu is already running\n", - dev->minor); } - up(&this_usbduxsub->sem); + up(&devpriv->sem); + return 1; } -static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) +static int usbduxsigma_ai_cmd(struct comedi_device *dev, + struct comedi_subdevice *s) { + struct usbduxsigma_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; - unsigned int chan; - int i, ret; - struct usbduxsub *this_usbduxsub = dev->private; - int result; + unsigned int len = cmd->chanlist_len; uint8_t muxsg0 = 0; uint8_t muxsg1 = 0; uint8_t sysred = 0; + int ret; + int i; - if (!this_usbduxsub) - return -EFAULT; + down(&devpriv->sem); - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: usbdux_ai_cmd\n", dev->minor); - - /* block other CPUs from starting an ai_cmd */ - down(&this_usbduxsub->sem); - - if (!(this_usbduxsub->probed)) { - up(&this_usbduxsub->sem); - return -ENODEV; - } - if (this_usbduxsub->ai_cmd_running) { - dev_err(&this_usbduxsub->interface->dev, "comedi%d: " - "ai_cmd not possible. Another ai_cmd is running.\n", - dev->minor); - up(&this_usbduxsub->sem); - return -EBUSY; - } /* set current channel of the running acquisition to zero */ s->async->cur_chan = 0; + for (i = 0; i < len; i++) { + unsigned int chan = CR_CHAN(cmd->chanlist[i]); - /* first the number of channels per time step */ - this_usbduxsub->dux_commands[1] = cmd->chanlist_len; - - /* CONFIG0 */ - this_usbduxsub->dux_commands[2] = 0x12; - - /* CONFIG1: 23kHz sampling rate, delay = 0us, */ - this_usbduxsub->dux_commands[3] = 0x03; - - /* CONFIG3: differential channels off */ - this_usbduxsub->dux_commands[4] = 0x00; - - for (i = 0; i < cmd->chanlist_len; i++) { - chan = CR_CHAN(cmd->chanlist[i]); create_adc_command(chan, &muxsg0, &muxsg1); - if (i >= NUMCHANNELS) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: channel list too long\n", - dev->minor); - break; - } - } - this_usbduxsub->dux_commands[5] = muxsg0; - this_usbduxsub->dux_commands[6] = muxsg1; - this_usbduxsub->dux_commands[7] = sysred; - - dev_dbg(&this_usbduxsub->interface->dev, - "comedi %d: sending commands to the usb device: size=%u\n", - dev->minor, NUMCHANNELS); - - result = send_dux_commands(this_usbduxsub, SENDADCOMMANDS); - if (result < 0) { - up(&this_usbduxsub->sem); - return result; } - if (this_usbduxsub->high_speed) { - /* - * every 2 channels get a time window of 125us. Thus, if we - * sample all 16 channels we need 1ms. If we sample only one - * channel we need only 125us - */ - this_usbduxsub->ai_interval = - chanToInterval(cmd->chanlist_len); - this_usbduxsub->ai_timer = cmd->scan_begin_arg / (125000 * - (this_usbduxsub-> - ai_interval)); - } else { - /* interval always 1ms */ - this_usbduxsub->ai_interval = 1; - this_usbduxsub->ai_timer = cmd->scan_begin_arg / 1000000; - } - if (this_usbduxsub->ai_timer < 1) { - dev_err(&this_usbduxsub->interface->dev, "comedi%d: ai_cmd: " - "timer=%d, scan_begin_arg=%d. " - "Not properly tested by cmdtest?\n", dev->minor, - this_usbduxsub->ai_timer, cmd->scan_begin_arg); - up(&this_usbduxsub->sem); - return -EINVAL; - } - this_usbduxsub->ai_counter = this_usbduxsub->ai_timer; + devpriv->dux_commands[1] = len; /* num channels per time step */ + devpriv->dux_commands[2] = 0x12; /* CONFIG0 */ + devpriv->dux_commands[3] = 0x03; /* CONFIG1: 23kHz sample, delay 0us */ + devpriv->dux_commands[4] = 0x00; /* CONFIG3: diff. channels off */ + devpriv->dux_commands[5] = muxsg0; + devpriv->dux_commands[6] = muxsg1; + devpriv->dux_commands[7] = sysred; - if (cmd->stop_src == TRIG_COUNT) { - /* data arrives as one packet */ - this_usbduxsub->ai_sample_count = cmd->stop_arg; - this_usbduxsub->ai_continuous = 0; - } else { - /* continuous acquisition */ - this_usbduxsub->ai_continuous = 1; - this_usbduxsub->ai_sample_count = 0; + ret = usbbuxsigma_send_cmd(dev, USBBUXSIGMA_AD_CMD); + if (ret < 0) { + up(&devpriv->sem); + return ret; } + devpriv->ai_counter = devpriv->ai_timer; + if (cmd->start_src == TRIG_NOW) { /* enable this acquisition operation */ - this_usbduxsub->ai_cmd_running = 1; - ret = usbduxsub_submit_InURBs(this_usbduxsub); + ret = usbduxsigma_submit_urbs(dev, devpriv->ai_urbs, + devpriv->n_ai_urbs, 1); if (ret < 0) { - this_usbduxsub->ai_cmd_running = 0; - /* fixme: unlink here?? */ - up(&this_usbduxsub->sem); + up(&devpriv->sem); return ret; } s->async->inttrig = NULL; - } else { - /* TRIG_INT */ - /* don't enable the acquision operation */ - /* wait for an internal signal */ - s->async->inttrig = usbdux_ai_inttrig; + devpriv->ai_cmd_running = 1; + } else { /* TRIG_INT */ + /* wait for an internal signal and submit the urbs later */ + s->async->inttrig = usbduxsigma_ai_inttrig; } - up(&this_usbduxsub->sem); + + up(&devpriv->sem); + return 0; } -/* Mode 0 is used to get a single conversion on demand */ -static int usbdux_ai_insn_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int usbduxsigma_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - int i; - int32_t one = 0; - int chan; - int err; - struct usbduxsub *this_usbduxsub = dev->private; + struct usbduxsigma_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); uint8_t muxsg0 = 0; uint8_t muxsg1 = 0; uint8_t sysred = 0; + int ret; + int i; - if (!this_usbduxsub) - return 0; - - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: ai_insn_read, insn->n=%d, insn->subdev=%d\n", - dev->minor, insn->n, insn->subdev); - - down(&this_usbduxsub->sem); - if (!(this_usbduxsub->probed)) { - up(&this_usbduxsub->sem); - return -ENODEV; - } - if (this_usbduxsub->ai_cmd_running) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: ai_insn_read not possible. " - "Async Command is running.\n", dev->minor); - up(&this_usbduxsub->sem); - return 0; + down(&devpriv->sem); + if (devpriv->ai_cmd_running) { + up(&devpriv->sem); + return -EBUSY; } - /* sample one channel */ - /* CONFIG0: chopper on */ - this_usbduxsub->dux_commands[1] = 0x16; - - /* CONFIG1: 2kHz sampling rate */ - this_usbduxsub->dux_commands[2] = 0x80; - - /* CONFIG3: differential channels off */ - this_usbduxsub->dux_commands[3] = 0x00; - - chan = CR_CHAN(insn->chanspec); create_adc_command(chan, &muxsg0, &muxsg1); - this_usbduxsub->dux_commands[4] = muxsg0; - this_usbduxsub->dux_commands[5] = muxsg1; - this_usbduxsub->dux_commands[6] = sysred; + /* Mode 0 is used to get a single conversion on demand */ + devpriv->dux_commands[1] = 0x16; /* CONFIG0: chopper on */ + devpriv->dux_commands[2] = 0x80; /* CONFIG1: 2kHz sampling rate */ + devpriv->dux_commands[3] = 0x00; /* CONFIG3: diff. channels off */ + devpriv->dux_commands[4] = muxsg0; + devpriv->dux_commands[5] = muxsg1; + devpriv->dux_commands[6] = sysred; /* adc commands */ - err = send_dux_commands(this_usbduxsub, SENDSINGLEAD); - if (err < 0) { - up(&this_usbduxsub->sem); - return err; + ret = usbbuxsigma_send_cmd(dev, USBDUXSIGMA_SINGLE_AD_CMD); + if (ret < 0) { + up(&devpriv->sem); + return ret; } for (i = 0; i < insn->n; i++) { - err = receive_dux_commands(this_usbduxsub, SENDSINGLEAD); - if (err < 0) { - up(&this_usbduxsub->sem); - return 0; - } - /* 32 bits big endian from the A/D converter */ - one = be32_to_cpu(*((int32_t *) - ((this_usbduxsub->insnBuffer)+1))); - /* mask out the status byte */ - one = one & 0x00ffffff; - /* turn it into an unsigned integer */ - one = one ^ 0x00800000; - data[i] = one; - } - up(&this_usbduxsub->sem); - return i; -} + int32_t val; - - - -static int usbdux_getstatusinfo(struct comedi_device *dev, int chan) -{ - struct usbduxsub *this_usbduxsub = dev->private; - uint8_t sysred = 0; - uint32_t one; - int err; - - if (!this_usbduxsub) - return 0; - - if (this_usbduxsub->ai_cmd_running) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: status read not possible. " - "Async Command is running.\n", dev->minor); - return 0; - } - - /* CONFIG0 */ - this_usbduxsub->dux_commands[1] = 0x12; - - /* CONFIG1: 2kHz sampling rate */ - this_usbduxsub->dux_commands[2] = 0x80; - - /* CONFIG3: differential channels off */ - this_usbduxsub->dux_commands[3] = 0x00; - - if (chan == 1) { - /* ADC offset */ - sysred = sysred | 1; - } else if (chan == 2) { - /* VCC */ - sysred = sysred | 4; - } else if (chan == 3) { - /* temperature */ - sysred = sysred | 8; - } else if (chan == 4) { - /* gain */ - sysred = sysred | 16; - } else if (chan == 5) { - /* ref */ - sysred = sysred | 32; - } - - this_usbduxsub->dux_commands[4] = 0; - this_usbduxsub->dux_commands[5] = 0; - this_usbduxsub->dux_commands[6] = sysred; - - /* adc commands */ - err = send_dux_commands(this_usbduxsub, SENDSINGLEAD); - if (err < 0) - return err; - - err = receive_dux_commands(this_usbduxsub, SENDSINGLEAD); - if (err < 0) - return err; - - /* 32 bits big endian from the A/D converter */ - one = be32_to_cpu(*((int32_t *)((this_usbduxsub->insnBuffer)+1))); - /* mask out the status byte */ - one = one & 0x00ffffff; - one = one ^ 0x00800000; - - return (int)one; -} - - - - - - -/************************************/ -/* analog out */ - -static int usbdux_ao_insn_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - int i; - int chan = CR_CHAN(insn->chanspec); - struct usbduxsub *this_usbduxsub = dev->private; - - if (!this_usbduxsub) - return -EFAULT; - - down(&this_usbduxsub->sem); - if (!(this_usbduxsub->probed)) { - up(&this_usbduxsub->sem); - return -ENODEV; - } - for (i = 0; i < insn->n; i++) - data[i] = this_usbduxsub->outBuffer[chan]; - - up(&this_usbduxsub->sem); - return i; -} - -static int usbdux_ao_insn_write(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - int i, err; - int chan = CR_CHAN(insn->chanspec); - struct usbduxsub *this_usbduxsub = dev->private; - - if (!this_usbduxsub) - return -EFAULT; - - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: ao_insn_write\n", dev->minor); - - down(&this_usbduxsub->sem); - if (!(this_usbduxsub->probed)) { - up(&this_usbduxsub->sem); - return -ENODEV; - } - if (this_usbduxsub->ao_cmd_running) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: ao_insn_write: " - "ERROR: asynchronous ao_cmd is running\n", dev->minor); - up(&this_usbduxsub->sem); - return 0; - } - - for (i = 0; i < insn->n; i++) { - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: ao_insn_write: data[chan=%d,i=%d]=%d\n", - dev->minor, chan, i, data[i]); - - /* number of channels: 1 */ - this_usbduxsub->dux_commands[1] = 1; - /* channel number */ - this_usbduxsub->dux_commands[2] = data[i]; - this_usbduxsub->outBuffer[chan] = data[i]; - this_usbduxsub->dux_commands[3] = chan; - err = send_dux_commands(this_usbduxsub, SENDDACOMMANDS); - if (err < 0) { - up(&this_usbduxsub->sem); - return err; - } - } - up(&this_usbduxsub->sem); - - return i; -} - -static int usbdux_ao_inttrig(struct comedi_device *dev, - struct comedi_subdevice *s, unsigned int trignum) -{ - int ret; - struct usbduxsub *this_usbduxsub = dev->private; - - if (!this_usbduxsub) - return -EFAULT; - - down(&this_usbduxsub->sem); - - if (!(this_usbduxsub->probed)) { - ret = -ENODEV; - goto out; - } - if (trignum != 0) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: usbdux_ao_inttrig: invalid trignum\n", - dev->minor); - ret = -EINVAL; - goto out; - } - if (!(this_usbduxsub->ao_cmd_running)) { - this_usbduxsub->ao_cmd_running = 1; - ret = usbduxsub_submit_OutURBs(this_usbduxsub); + ret = usbduxsigma_receive_cmd(dev, USBDUXSIGMA_SINGLE_AD_CMD); if (ret < 0) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: usbdux_ao_inttrig: submitURB: " - "err=%d\n", dev->minor, ret); - this_usbduxsub->ao_cmd_running = 0; - goto out; + up(&devpriv->sem); + return ret; } - s->async->inttrig = NULL; - } else { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: ao_inttrig but acqu is already running.\n", - dev->minor); + + /* 32 bits big endian from the A/D converter */ + val = be32_to_cpu(*((int32_t *)((devpriv->insn_buf) + 1))); + val &= 0x00ffffff; /* strip status byte */ + val ^= 0x00800000; /* convert to unsigned */ + + data[i] = val; } - ret = 1; -out: - up(&this_usbduxsub->sem); - return ret; + up(&devpriv->sem); + + return insn->n; } -static int usbdux_ao_cmdtest(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_cmd *cmd) +static int usbduxsigma_ao_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - struct usbduxsub *this_usbduxsub = dev->private; + struct usbduxsigma_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + int i; + + down(&devpriv->sem); + for (i = 0; i < insn->n; i++) + data[i] = devpriv->ao_readback[chan]; + up(&devpriv->sem); + + return insn->n; +} + +static int usbduxsigma_ao_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct usbduxsigma_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + int ret; + int i; + + down(&devpriv->sem); + if (devpriv->ao_cmd_running) { + up(&devpriv->sem); + return -EBUSY; + } + + for (i = 0; i < insn->n; i++) { + devpriv->dux_commands[1] = 1; /* num channels */ + devpriv->dux_commands[2] = data[i]; /* value */ + devpriv->dux_commands[3] = chan; /* channel number */ + ret = usbbuxsigma_send_cmd(dev, USBDUXSIGMA_DA_CMD); + if (ret < 0) { + up(&devpriv->sem); + return ret; + } + devpriv->ao_readback[chan] = data[i]; + } + up(&devpriv->sem); + + return insn->n; +} + +static int usbduxsigma_ao_inttrig(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned int trignum) +{ + struct usbduxsigma_private *devpriv = dev->private; + int ret; + + if (trignum != 0) + return -EINVAL; + + down(&devpriv->sem); + if (!devpriv->ao_cmd_running) { + ret = usbduxsigma_submit_urbs(dev, devpriv->ao_urbs, + devpriv->n_ao_urbs, 0); + if (ret < 0) { + up(&devpriv->sem); + return ret; + } + devpriv->ao_cmd_running = 1; + s->async->inttrig = NULL; + } + up(&devpriv->sem); + + return 1; +} + +static int usbduxsigma_ao_cmdtest(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_cmd *cmd) +{ + struct usbduxsigma_private *devpriv = dev->private; int err = 0; + int high_speed; unsigned int flags; - if (!this_usbduxsub) - return -EFAULT; - - if (!(this_usbduxsub->probed)) - return -ENODEV; - - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: usbdux_ao_cmdtest\n", dev->minor); + /* high speed conversions are not used yet */ + high_speed = 0; /* (devpriv->high_speed) */ /* Step 1 : check if triggers are trivially valid */ err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT); - if (0) { /* (this_usbduxsub->high_speed) */ + if (high_speed) { /* * start immediately a new scan * the sampling rate is set by the coversion rate @@ -1538,8 +922,10 @@ static int usbdux_ao_cmdtest(struct comedi_device *dev, err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); - if (err) + if (err) { + up(&devpriv->sem); return 1; + } /* Step 2a : make sure trigger sources are unique */ @@ -1578,272 +964,186 @@ static int usbdux_ao_cmdtest(struct comedi_device *dev, if (err) return 3; + /* Step 4: fix up any arguments */ + + /* we count in timer steps */ + if (high_speed) { + /* timing of the conversion itself: every 125 us */ + devpriv->ao_timer = cmd->convert_arg / 125000; + } else { + /* + * timing of the scan: every 1ms + * we get all channels at once + */ + devpriv->ao_timer = cmd->scan_begin_arg / 1000000; + } + if (devpriv->ao_timer < 1) + err |= -EINVAL; + + if (cmd->stop_src == TRIG_COUNT) { + /* not continuous, use counter */ + if (high_speed) { + /* high speed also scans everything at once */ + devpriv->ao_sample_count = cmd->stop_arg * + cmd->scan_end_arg; + } else { + /* + * There's no scan as the scan has been + * handled inside the FX2. Data arrives as + * one packet. + */ + devpriv->ao_sample_count = cmd->stop_arg; + } + devpriv->ao_continuous = 0; + } else { + /* continuous acquisition */ + devpriv->ao_continuous = 1; + devpriv->ao_sample_count = 0; + } + + if (err) + return 4; + return 0; } -static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s) +static int usbduxsigma_ao_cmd(struct comedi_device *dev, + struct comedi_subdevice *s) { + struct usbduxsigma_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; - unsigned int chan, gain; - int i, ret; - struct usbduxsub *this_usbduxsub = dev->private; + int ret; + int i; - if (!this_usbduxsub) - return -EFAULT; - - down(&this_usbduxsub->sem); - if (!(this_usbduxsub->probed)) { - up(&this_usbduxsub->sem); - return -ENODEV; - } - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: %s\n", dev->minor, __func__); + down(&devpriv->sem); /* set current channel of the running acquisition to zero */ s->async->cur_chan = 0; - for (i = 0; i < cmd->chanlist_len; ++i) { - chan = CR_CHAN(cmd->chanlist[i]); - gain = CR_RANGE(cmd->chanlist[i]); - if (i >= NUMOUTCHANNELS) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: %s: channel list too long\n", - dev->minor, __func__); - break; - } - this_usbduxsub->dac_commands[i] = chan; - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: dac command for ch %d is %x\n", - dev->minor, i, this_usbduxsub->dac_commands[i]); - } + for (i = 0; i < cmd->chanlist_len; ++i) + devpriv->dac_commands[i] = CR_CHAN(cmd->chanlist[i]); - /* we count in steps of 1ms (125us) */ - /* 125us mode not used yet */ - if (0) { /* (this_usbduxsub->high_speed) */ - /* 125us */ - /* timing of the conversion itself: every 125 us */ - this_usbduxsub->ao_timer = cmd->convert_arg / 125000; - } else { - /* 1ms */ - /* timing of the scan: we get all channels at once */ - this_usbduxsub->ao_timer = cmd->scan_begin_arg / 1000000; - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: scan_begin_src=%d, scan_begin_arg=%d, " - "convert_src=%d, convert_arg=%d\n", dev->minor, - cmd->scan_begin_src, cmd->scan_begin_arg, - cmd->convert_src, cmd->convert_arg); - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: ao_timer=%d (ms)\n", - dev->minor, this_usbduxsub->ao_timer); - if (this_usbduxsub->ao_timer < 1) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: usbdux: ao_timer=%d, " - "scan_begin_arg=%d. " - "Not properly tested by cmdtest?\n", - dev->minor, this_usbduxsub->ao_timer, - cmd->scan_begin_arg); - up(&this_usbduxsub->sem); - return -EINVAL; - } - } - this_usbduxsub->ao_counter = this_usbduxsub->ao_timer; - - if (cmd->stop_src == TRIG_COUNT) { - /* not continuous */ - /* counter */ - /* high speed also scans everything at once */ - if (0) { /* (this_usbduxsub->high_speed) */ - this_usbduxsub->ao_sample_count = - (cmd->stop_arg) * (cmd->scan_end_arg); - } else { - /* there's no scan as the scan has been */ - /* perf inside the FX2 */ - /* data arrives as one packet */ - this_usbduxsub->ao_sample_count = cmd->stop_arg; - } - this_usbduxsub->ao_continuous = 0; - } else { - /* continuous acquisition */ - this_usbduxsub->ao_continuous = 1; - this_usbduxsub->ao_sample_count = 0; - } + devpriv->ao_counter = devpriv->ao_timer; if (cmd->start_src == TRIG_NOW) { /* enable this acquisition operation */ - this_usbduxsub->ao_cmd_running = 1; - ret = usbduxsub_submit_OutURBs(this_usbduxsub); + ret = usbduxsigma_submit_urbs(dev, devpriv->ao_urbs, + devpriv->n_ao_urbs, 0); if (ret < 0) { - this_usbduxsub->ao_cmd_running = 0; - /* fixme: unlink here?? */ - up(&this_usbduxsub->sem); + up(&devpriv->sem); return ret; } s->async->inttrig = NULL; - } else { - /* TRIG_INT */ - /* submit the urbs later */ - /* wait for an internal signal */ - s->async->inttrig = usbdux_ao_inttrig; + devpriv->ao_cmd_running = 1; + } else { /* TRIG_INT */ + /* wait for an internal signal and submit the urbs later */ + s->async->inttrig = usbduxsigma_ao_inttrig; } - up(&this_usbduxsub->sem); + up(&devpriv->sem); + return 0; } -static int usbdux_dio_insn_config(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int usbduxsigma_dio_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - int chan = CR_CHAN(insn->chanspec); - - /* The input or output configuration of each digital line is - * configured by a special insn_config instruction. chanspec - * contains the channel to be changed, and data[0] contains the - * value COMEDI_INPUT or COMEDI_OUTPUT. */ + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int mask = 1 << chan; switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - s->io_bits |= 1 << chan; /* 1 means Out */ + s->io_bits |= mask; break; case INSN_CONFIG_DIO_INPUT: - s->io_bits &= ~(1 << chan); + s->io_bits &= ~mask; break; case INSN_CONFIG_DIO_QUERY: - data[1] = - (s->io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; + data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT; break; default: return -EINVAL; break; } - /* we don't tell the firmware here as it would take 8 frames */ - /* to submit the information. We do it in the insn_bits. */ + + /* + * We don't tell the firmware here as it would take 8 frames + * to submit the information. We do it in the (*insn_bits). + */ return insn->n; } -static int usbdux_dio_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) +static int usbduxsigma_dio_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { + struct usbduxsigma_private *devpriv = dev->private; + unsigned int mask = data[0]; + unsigned int bits = data[1]; + int ret; - struct usbduxsub *this_usbduxsub = dev->private; - int err; + down(&devpriv->sem); - if (!this_usbduxsub) - return -EFAULT; + s->state &= ~mask; + s->state |= (bits & mask); - down(&this_usbduxsub->sem); + devpriv->dux_commands[1] = s->io_bits & 0xff; + devpriv->dux_commands[4] = s->state & 0xff; + devpriv->dux_commands[2] = (s->io_bits >> 8) & 0xff; + devpriv->dux_commands[5] = (s->state >> 8) & 0xff; + devpriv->dux_commands[3] = (s->io_bits >> 16) & 0xff; + devpriv->dux_commands[6] = (s->state >> 16) & 0xff; - if (!(this_usbduxsub->probed)) { - up(&this_usbduxsub->sem); - return -ENODEV; - } + ret = usbbuxsigma_send_cmd(dev, USBDUXSIGMA_DIO_BITS_CMD); + if (ret < 0) + goto done; + ret = usbduxsigma_receive_cmd(dev, USBDUXSIGMA_DIO_BITS_CMD); + if (ret < 0) + goto done; - /* The insn data is a mask in data[0] and the new data - * in data[1], each channel cooresponding to a bit. */ - s->state &= ~data[0]; - s->state |= data[0] & data[1]; - /* The commands are 8 bits wide */ - this_usbduxsub->dux_commands[1] = (s->io_bits) & 0x000000FF; - this_usbduxsub->dux_commands[4] = (s->state) & 0x000000FF; - this_usbduxsub->dux_commands[2] = ((s->io_bits) & 0x0000FF00) >> 8; - this_usbduxsub->dux_commands[5] = ((s->state) & 0x0000FF00) >> 8; - this_usbduxsub->dux_commands[3] = ((s->io_bits) & 0x00FF0000) >> 16; - this_usbduxsub->dux_commands[6] = ((s->state) & 0x00FF0000) >> 16; + s->state = devpriv->insn_buf[1] | + (devpriv->insn_buf[2] << 8) | + (devpriv->insn_buf[3] << 16); - /* This command also tells the firmware to return */ - /* the digital input lines */ - err = send_dux_commands(this_usbduxsub, SENDDIOBITSCOMMAND); - if (err < 0) { - up(&this_usbduxsub->sem); - return err; - } - err = receive_dux_commands(this_usbduxsub, SENDDIOBITSCOMMAND); - if (err < 0) { - up(&this_usbduxsub->sem); - return err; - } + data[1] = s->state; + ret = insn->n; - data[1] = (((unsigned int)(this_usbduxsub->insnBuffer[1]))&0xff) | - ((((unsigned int)(this_usbduxsub->insnBuffer[2]))&0xff) << 8) | - ((((unsigned int)(this_usbduxsub->insnBuffer[3]))&0xff) << 16); - - s->state = data[1]; - - up(&this_usbduxsub->sem); - return insn->n; -} - -/***********************************/ -/* PWM */ - -static int usbduxsub_unlink_PwmURBs(struct usbduxsub *usbduxsub_tmp) -{ - int err = 0; - - if (usbduxsub_tmp && usbduxsub_tmp->urbPwm) { - if (usbduxsub_tmp->urbPwm) - usb_kill_urb(usbduxsub_tmp->urbPwm); - dev_dbg(&usbduxsub_tmp->interface->dev, - "comedi: unlinked PwmURB: res=%d\n", err); - } - return err; -} - -/* This cancels a running acquisition operation - * in any context. - */ -static int usbdux_pwm_stop(struct usbduxsub *this_usbduxsub, int do_unlink) -{ - int ret = 0; - - if (!this_usbduxsub) - return -EFAULT; - - dev_dbg(&this_usbduxsub->interface->dev, "comedi: %s\n", __func__); - if (do_unlink) - ret = usbduxsub_unlink_PwmURBs(this_usbduxsub); - - this_usbduxsub->pwm_cmd_running = 0; +done: + up(&devpriv->sem); return ret; } -/* force unlink - is called by comedi */ -static int usbdux_pwm_cancel(struct comedi_device *dev, - struct comedi_subdevice *s) +static void usbduxsigma_pwm_stop(struct comedi_device *dev, int do_unlink) { - struct usbduxsub *this_usbduxsub = dev->private; - int res = 0; + struct usbduxsigma_private *devpriv = dev->private; - /* unlink only if it is really running */ - res = usbdux_pwm_stop(this_usbduxsub, this_usbduxsub->pwm_cmd_running); + if (do_unlink) { + if (devpriv->pwm_urb) + usb_kill_urb(devpriv->pwm_urb); + } - dev_dbg(&this_usbduxsub->interface->dev, - "comedi %d: sending pwm off command to the usb device.\n", - dev->minor); - res = send_dux_commands(this_usbduxsub, SENDPWMOFF); - if (res < 0) - return res; - - return res; + devpriv->pwm_cmd_running = 0; } -static void usbduxsub_pwm_irq(struct urb *urb) +static int usbduxsigma_pwm_cancel(struct comedi_device *dev, + struct comedi_subdevice *s) { + struct usbduxsigma_private *devpriv = dev->private; + + /* unlink only if it is really running */ + usbduxsigma_pwm_stop(dev, devpriv->pwm_cmd_running); + + return usbbuxsigma_send_cmd(dev, USBDUXSIGMA_PWM_OFF_CMD); +} + +static void usbduxsigma_pwm_urb_complete(struct urb *urb) +{ + struct comedi_device *dev = urb->context; + struct usbduxsigma_private *devpriv = dev->private; int ret; - struct usbduxsub *this_usbduxsub; - struct comedi_device *this_comedidev; - struct comedi_subdevice *s; - - /* printk(KERN_DEBUG "PWM: IRQ\n"); */ - - /* the context variable points to the subdevice */ - this_comedidev = urb->context; - /* the private structure of the subdevice is struct usbduxsub */ - this_usbduxsub = this_comedidev->private; - - s = &this_comedidev->subdevices[SUBDEV_DA]; switch (urb->status) { case 0: @@ -1854,260 +1154,180 @@ static void usbduxsub_pwm_irq(struct urb *urb) case -ENOENT: case -ESHUTDOWN: case -ECONNABORTED: - /* - * after an unlink command, unplug, ... etc - * no unlink needed here. Already shutting down. - */ - if (this_usbduxsub->pwm_cmd_running) - usbdux_pwm_stop(this_usbduxsub, 0); - + /* happens after an unlink command */ + if (devpriv->pwm_cmd_running) + usbduxsigma_pwm_stop(dev, 0); /* w/o unlink */ return; default: /* a real error */ - if (this_usbduxsub->pwm_cmd_running) { - dev_err(&this_usbduxsub->interface->dev, - "comedi_: Non-zero urb status received in " - "pwm intr context: %d\n", urb->status); - usbdux_pwm_stop(this_usbduxsub, 0); + if (devpriv->pwm_cmd_running) { + dev_err(dev->class_dev, + "%s: non-zero urb status (%d)\n", + __func__, urb->status); + usbduxsigma_pwm_stop(dev, 0); /* w/o unlink */ } return; } - /* are we actually running? */ - if (!(this_usbduxsub->pwm_cmd_running)) + if (!devpriv->pwm_cmd_running) return; - urb->transfer_buffer_length = this_usbduxsub->sizePwmBuf; - urb->dev = this_usbduxsub->usbdev; + urb->transfer_buffer_length = devpriv->pwm_buf_sz; + urb->dev = comedi_to_usb_dev(dev); urb->status = 0; - if (this_usbduxsub->pwm_cmd_running) { - ret = usb_submit_urb(urb, GFP_ATOMIC); - if (ret < 0) { - dev_err(&this_usbduxsub->interface->dev, - "comedi_: pwm urb resubm failed in int-cont. " - "ret=%d", ret); - if (ret == EL2NSYNC) - dev_err(&this_usbduxsub->interface->dev, - "buggy USB host controller or bug in " - "IRQ handling!\n"); - - /* don't do an unlink here */ - usbdux_pwm_stop(this_usbduxsub, 0); - } + ret = usb_submit_urb(urb, GFP_ATOMIC); + if (ret < 0) { + dev_err(dev->class_dev, "%s: urb resubmit failed (%d)\n", + __func__, ret); + if (ret == EL2NSYNC) + dev_err(dev->class_dev, + "buggy USB host controller or bug in IRQ handler\n"); + usbduxsigma_pwm_stop(dev, 0); /* w/o unlink */ } } -static int usbduxsub_submit_PwmURBs(struct usbduxsub *usbduxsub) +static int usbduxsigma_submit_pwm_urb(struct comedi_device *dev) { - int errFlag; - - if (!usbduxsub) - return -EFAULT; - - dev_dbg(&usbduxsub->interface->dev, "comedi_: submitting pwm-urb\n"); + struct usb_device *usb = comedi_to_usb_dev(dev); + struct usbduxsigma_private *devpriv = dev->private; + struct urb *urb = devpriv->pwm_urb; /* in case of a resubmission after an unlink... */ - usb_fill_bulk_urb(usbduxsub->urbPwm, - usbduxsub->usbdev, - usb_sndbulkpipe(usbduxsub->usbdev, PWM_EP), - usbduxsub->urbPwm->transfer_buffer, - usbduxsub->sizePwmBuf, usbduxsub_pwm_irq, - usbduxsub->comedidev); + usb_fill_bulk_urb(urb, + usb, usb_sndbulkpipe(usb, USBDUXSIGMA_PWM_OUT_EP), + urb->transfer_buffer, devpriv->pwm_buf_sz, + usbduxsigma_pwm_urb_complete, dev); - errFlag = usb_submit_urb(usbduxsub->urbPwm, GFP_ATOMIC); - if (errFlag) { - dev_err(&usbduxsub->interface->dev, - "comedi_: usbduxsigma: pwm: usb_submit_urb error %d\n", - errFlag); - return errFlag; - } - return 0; + return usb_submit_urb(urb, GFP_ATOMIC); } -static int usbdux_pwm_period(struct comedi_device *dev, - struct comedi_subdevice *s, unsigned int period) +static int usbduxsigma_pwm_period(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned int period) { - struct usbduxsub *this_usbduxsub = dev->private; + struct usbduxsigma_private *devpriv = dev->private; int fx2delay = 255; if (period < MIN_PWM_PERIOD) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: illegal period setting for pwm.\n", - dev->minor); return -EAGAIN; } else { - fx2delay = period / ((int)(6 * 512 * (1.0 / 0.033))) - 6; - if (fx2delay > 255) { - dev_err(&this_usbduxsub->interface->dev, - "comedi%d: period %d for pwm is too low.\n", - dev->minor, period); + fx2delay = (period / (6 * 512 * 1000 / 33)) - 6; + if (fx2delay > 255) return -EAGAIN; - } } - this_usbduxsub->pwmDelay = fx2delay; - this_usbduxsub->pwmPeriod = period; - dev_dbg(&this_usbduxsub->interface->dev, "%s: frequ=%d, period=%d\n", - __func__, period, fx2delay); + devpriv->pwm_delay = fx2delay; + devpriv->pwm_period = period; return 0; } -/* is called from insn so there's no need to do all the sanity checks */ -static int usbdux_pwm_start(struct comedi_device *dev, - struct comedi_subdevice *s) +static int usbduxsigma_pwm_start(struct comedi_device *dev, + struct comedi_subdevice *s) { - int ret, i; - struct usbduxsub *this_usbduxsub = dev->private; + struct usbduxsigma_private *devpriv = dev->private; + int ret; - dev_dbg(&this_usbduxsub->interface->dev, "comedi%d: %s\n", - dev->minor, __func__); - - if (this_usbduxsub->pwm_cmd_running) { - /* already running */ + if (devpriv->pwm_cmd_running) return 0; - } - this_usbduxsub->dux_commands[1] = ((uint8_t) this_usbduxsub->pwmDelay); - ret = send_dux_commands(this_usbduxsub, SENDPWMON); + devpriv->dux_commands[1] = devpriv->pwm_delay; + ret = usbbuxsigma_send_cmd(dev, USBDUXSIGMA_PWM_ON_CMD); if (ret < 0) return ret; - /* initialise the buffer */ - for (i = 0; i < this_usbduxsub->sizePwmBuf; i++) - ((char *)(this_usbduxsub->urbPwm->transfer_buffer))[i] = 0; + memset(devpriv->pwm_urb->transfer_buffer, 0, devpriv->pwm_buf_sz); - this_usbduxsub->pwm_cmd_running = 1; - ret = usbduxsub_submit_PwmURBs(this_usbduxsub); - if (ret < 0) { - this_usbduxsub->pwm_cmd_running = 0; + ret = usbduxsigma_submit_pwm_urb(dev); + if (ret < 0) return ret; - } + devpriv->pwm_cmd_running = 1; + return 0; } -/* generates the bit pattern for PWM with the optional sign bit */ -static int usbdux_pwm_pattern(struct comedi_device *dev, - struct comedi_subdevice *s, int channel, - unsigned int value, unsigned int sign) +static int usbduxsigma_pwm_pattern(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned int chan, + unsigned int value, + unsigned int sign) { - struct usbduxsub *this_usbduxsub = dev->private; - int i, szbuf; - char *pBuf; - char pwm_mask; - char sgn_mask; - char c; + struct usbduxsigma_private *devpriv = dev->private; + char pwm_mask = (1 << chan); /* DIO bit for the PWM data */ + char sgn_mask = (16 << chan); /* DIO bit for the sign */ + char *buf = (char *)(devpriv->pwm_urb->transfer_buffer); + int szbuf = devpriv->pwm_buf_sz; + int i; - if (!this_usbduxsub) - return -EFAULT; - - /* this is the DIO bit which carries the PWM data */ - pwm_mask = (1 << channel); - /* this is the DIO bit which carries the optional direction bit */ - sgn_mask = (16 << channel); - /* this is the buffer which will be filled with the with bit */ - /* pattern for one period */ - szbuf = this_usbduxsub->sizePwmBuf; - pBuf = (char *)(this_usbduxsub->urbPwm->transfer_buffer); for (i = 0; i < szbuf; i++) { - c = *pBuf; - /* reset bits */ - c = c & (~pwm_mask); - /* set the bit as long as the index is lower than the value */ + char c = *buf; + + c &= ~pwm_mask; if (i < value) - c = c | pwm_mask; - /* set the optional sign bit for a relay */ - if (!sign) { - /* positive value */ - c = c & (~sgn_mask); - } else { - /* negative value */ - c = c | sgn_mask; - } - *(pBuf++) = c; + c |= pwm_mask; + if (!sign) + c &= ~sgn_mask; + else + c |= sgn_mask; + *buf++ = c; } return 1; } -static int usbdux_pwm_write(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int usbduxsigma_pwm_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - struct usbduxsub *this_usbduxsub = dev->private; - - if (!this_usbduxsub) - return -EFAULT; - - if ((insn->n) != 1) { - /* - * doesn't make sense to have more than one value here because - * it would just overwrite the PWM buffer a couple of times - */ - return -EINVAL; - } + unsigned int chan = CR_CHAN(insn->chanspec); /* - * the sign is set via a special INSN only, this gives us 8 bits for - * normal operation - * relay sign 0 by default + * It doesn't make sense to support more than one value here + * because it would just overwrite the PWM buffer. */ - return usbdux_pwm_pattern(dev, s, CR_CHAN(insn->chanspec), data[0], 0); + if (insn->n != 1) + return -EINVAL; + + /* + * The sign is set via a special INSN only, this gives us 8 bits + * for normal operation, sign is 0 by default. + */ + return usbduxsigma_pwm_pattern(dev, s, chan, data[0], 0); } -static int usbdux_pwm_read(struct comedi_device *x1, - struct comedi_subdevice *x2, struct comedi_insn *x3, - unsigned int *x4) +static int usbduxsigma_pwm_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - /* not needed */ - return -EINVAL; -}; + struct usbduxsigma_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); -/* switches on/off PWM */ -static int usbdux_pwm_config(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - struct usbduxsub *this_usbduxsub = dev->private; switch (data[0]) { case INSN_CONFIG_ARM: - /* switch it on */ - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: %s: pwm on\n", dev->minor, __func__); /* * if not zero the PWM is limited to a certain time which is * not supported here */ if (data[1] != 0) return -EINVAL; - return usbdux_pwm_start(dev, s); + return usbduxsigma_pwm_start(dev, s); case INSN_CONFIG_DISARM: - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: %s: pwm off\n", dev->minor, __func__); - return usbdux_pwm_cancel(dev, s); + return usbduxsigma_pwm_cancel(dev, s); case INSN_CONFIG_GET_PWM_STATUS: - /* - * to check if the USB transmission has failed or in case PWM - * was limited to n cycles to check if it has terminated - */ - data[1] = this_usbduxsub->pwm_cmd_running; + data[1] = devpriv->pwm_cmd_running; return 0; case INSN_CONFIG_PWM_SET_PERIOD: - dev_dbg(&this_usbduxsub->interface->dev, - "comedi%d: %s: setting period\n", dev->minor, - __func__); - return usbdux_pwm_period(dev, s, data[1]); + return usbduxsigma_pwm_period(dev, s, data[1]); case INSN_CONFIG_PWM_GET_PERIOD: - data[1] = this_usbduxsub->pwmPeriod; + data[1] = devpriv->pwm_period; return 0; case INSN_CONFIG_PWM_SET_H_BRIDGE: - /* value in the first byte and the sign in the second for a - relay */ - return usbdux_pwm_pattern(dev, s, - /* the channel number */ - CR_CHAN(insn->chanspec), - /* actual PWM data */ - data[1], - /* just a sign */ - (data[2] != 0)); + /* + * data[1] = value + * data[2] = sign (for a relay) + */ + return usbduxsigma_pwm_pattern(dev, s, chan, + data[1], (data[2] != 0)); case INSN_CONFIG_PWM_GET_H_BRIDGE: /* values are not kept in this driver, nothing to return */ return -EINVAL; @@ -2115,233 +1335,399 @@ static int usbdux_pwm_config(struct comedi_device *dev, return -EINVAL; } -/* end of PWM */ -/*****************************************************************/ - -static void tidy_up(struct usbduxsub *usbduxsub_tmp) +static int usbduxsigma_getstatusinfo(struct comedi_device *dev, int chan) { - int i; + struct usbduxsigma_private *devpriv = dev->private; + uint8_t sysred; + uint32_t val; + int ret; - if (!usbduxsub_tmp) - return; - dev_dbg(&usbduxsub_tmp->interface->dev, "comedi_: tiding up\n"); - - /* shows the usb subsystem that the driver is down */ - if (usbduxsub_tmp->interface) - usb_set_intfdata(usbduxsub_tmp->interface, NULL); - - usbduxsub_tmp->probed = 0; - - if (usbduxsub_tmp->urbIn) { - if (usbduxsub_tmp->ai_cmd_running) { - usbduxsub_tmp->ai_cmd_running = 0; - usbduxsub_unlink_InURBs(usbduxsub_tmp); - } - for (i = 0; i < usbduxsub_tmp->numOfInBuffers; i++) { - kfree(usbduxsub_tmp->urbIn[i]->transfer_buffer); - usbduxsub_tmp->urbIn[i]->transfer_buffer = NULL; - usb_kill_urb(usbduxsub_tmp->urbIn[i]); - usb_free_urb(usbduxsub_tmp->urbIn[i]); - usbduxsub_tmp->urbIn[i] = NULL; - } - kfree(usbduxsub_tmp->urbIn); - usbduxsub_tmp->urbIn = NULL; + switch (chan) { + default: + case 0: + sysred = 0; /* ADC zero */ + break; + case 1: + sysred = 1; /* ADC offset */ + break; + case 2: + sysred = 4; /* VCC */ + break; + case 3: + sysred = 8; /* temperature */ + break; + case 4: + sysred = 16; /* gain */ + break; + case 5: + sysred = 32; /* ref */ + break; } - if (usbduxsub_tmp->urbOut) { - if (usbduxsub_tmp->ao_cmd_running) { - usbduxsub_tmp->ao_cmd_running = 0; - usbduxsub_unlink_OutURBs(usbduxsub_tmp); - } - for (i = 0; i < usbduxsub_tmp->numOfOutBuffers; i++) { - if (usbduxsub_tmp->urbOut[i]->transfer_buffer) { - kfree(usbduxsub_tmp-> - urbOut[i]->transfer_buffer); - usbduxsub_tmp->urbOut[i]->transfer_buffer = - NULL; - } - if (usbduxsub_tmp->urbOut[i]) { - usb_kill_urb(usbduxsub_tmp->urbOut[i]); - usb_free_urb(usbduxsub_tmp->urbOut[i]); - usbduxsub_tmp->urbOut[i] = NULL; - } - } - kfree(usbduxsub_tmp->urbOut); - usbduxsub_tmp->urbOut = NULL; - } - if (usbduxsub_tmp->urbPwm) { - if (usbduxsub_tmp->pwm_cmd_running) { - usbduxsub_tmp->pwm_cmd_running = 0; - usbduxsub_unlink_PwmURBs(usbduxsub_tmp); - } - kfree(usbduxsub_tmp->urbPwm->transfer_buffer); - usbduxsub_tmp->urbPwm->transfer_buffer = NULL; - usb_kill_urb(usbduxsub_tmp->urbPwm); - usb_free_urb(usbduxsub_tmp->urbPwm); - usbduxsub_tmp->urbPwm = NULL; - } - kfree(usbduxsub_tmp->inBuffer); - usbduxsub_tmp->inBuffer = NULL; - kfree(usbduxsub_tmp->insnBuffer); - usbduxsub_tmp->insnBuffer = NULL; - kfree(usbduxsub_tmp->outBuffer); - usbduxsub_tmp->outBuffer = NULL; - kfree(usbduxsub_tmp->dac_commands); - usbduxsub_tmp->dac_commands = NULL; - kfree(usbduxsub_tmp->dux_commands); - usbduxsub_tmp->dux_commands = NULL; - usbduxsub_tmp->ai_cmd_running = 0; - usbduxsub_tmp->ao_cmd_running = 0; - usbduxsub_tmp->pwm_cmd_running = 0; + + devpriv->dux_commands[1] = 0x12; /* CONFIG0 */ + devpriv->dux_commands[2] = 0x80; /* CONFIG1: 2kHz sampling rate */ + devpriv->dux_commands[3] = 0x00; /* CONFIG3: diff. channels off */ + devpriv->dux_commands[4] = 0; + devpriv->dux_commands[5] = 0; + devpriv->dux_commands[6] = sysred; + ret = usbbuxsigma_send_cmd(dev, USBDUXSIGMA_SINGLE_AD_CMD); + if (ret < 0) + return ret; + + ret = usbduxsigma_receive_cmd(dev, USBDUXSIGMA_SINGLE_AD_CMD); + if (ret < 0) + return ret; + + /* 32 bits big endian from the A/D converter */ + val = be32_to_cpu(*((int32_t *)((devpriv->insn_buf)+1))); + val &= 0x00ffffff; /* strip status byte */ + val ^= 0x00800000; /* convert to unsigned */ + + return (int)val; } -static int usbduxsigma_attach_common(struct comedi_device *dev, - struct usbduxsub *uds) +static int usbduxsigma_attach_common(struct comedi_device *dev) { - int ret; + struct usbduxsigma_private *devpriv = dev->private; struct comedi_subdevice *s; int n_subdevs; int offset; + int ret; - down(&uds->sem); - /* pointer back to the corresponding comedi device */ - uds->comedidev = dev; + down(&devpriv->sem); - /* set number of subdevices */ - if (uds->high_speed) + if (devpriv->high_speed) n_subdevs = 4; /* with pwm */ else n_subdevs = 3; /* without pwm */ ret = comedi_alloc_subdevices(dev, n_subdevs); if (ret) { - up(&uds->sem); + up(&devpriv->sem); return ret; } - /* private structure is also simply the usb-structure */ - dev->private = uds; - /* the first subdevice is the A/D converter */ - s = &dev->subdevices[SUBDEV_AD]; - /* the URBs get the comedi subdevice */ - /* which is responsible for reading */ - /* this is the subdevice which reads data */ + + /* Analog Input subdevice */ + s = &dev->subdevices[0]; dev->read_subdev = s; - /* the subdevice receives as private structure the */ - /* usb-structure */ - s->private = NULL; - /* analog input */ - s->type = COMEDI_SUBD_AI; - /* readable and ref is to ground, 32 bit wide data! */ - s->subdev_flags = SDF_READABLE | SDF_GROUND | - SDF_CMD_READ | SDF_LSAMPL; - /* 16 A/D channels */ - s->n_chan = NUMCHANNELS; - /* length of the channellist */ - s->len_chanlist = NUMCHANNELS; - /* callback functions */ - s->insn_read = usbdux_ai_insn_read; - s->do_cmdtest = usbdux_ai_cmdtest; - s->do_cmd = usbdux_ai_cmd; - s->cancel = usbdux_ai_cancel; - /* max value from the A/D converter (24bit) */ - s->maxdata = 0x00FFFFFF; - /* range table to convert to physical units */ - s->range_table = (&range_usbdux_ai_range); - /* analog output subdevice */ - s = &dev->subdevices[SUBDEV_DA]; - /* analog out */ - s->type = COMEDI_SUBD_AO; - /* backward pointer */ + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ | SDF_LSAMPL; + s->n_chan = NUMCHANNELS; + s->len_chanlist = NUMCHANNELS; + s->maxdata = 0x00ffffff; + s->range_table = &usbduxsigma_ai_range; + s->insn_read = usbduxsigma_ai_insn_read; + s->do_cmdtest = usbduxsigma_ai_cmdtest; + s->do_cmd = usbduxsigma_ai_cmd; + s->cancel = usbduxsigma_ai_cancel; + + /* Analog Output subdevice */ + s = &dev->subdevices[1]; dev->write_subdev = s; - /* the subdevice receives as private structure the */ - /* usb-structure */ - s->private = NULL; - /* are writable */ - s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_CMD_WRITE; - /* 4 channels */ - s->n_chan = 4; - /* length of the channellist */ - s->len_chanlist = 4; - /* 8 bit resolution */ - s->maxdata = 0x00ff; - /* unipolar range */ - s->range_table = &range_unipolar2_5; - /* callback */ - s->do_cmdtest = usbdux_ao_cmdtest; - s->do_cmd = usbdux_ao_cmd; - s->cancel = usbdux_ao_cancel; - s->insn_read = usbdux_ao_insn_read; - s->insn_write = usbdux_ao_insn_write; - /* digital I/O subdevice */ - s = &dev->subdevices[SUBDEV_DIO]; - s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE; - /* 8 external and 16 internal channels */ - s->n_chan = 24; - s->maxdata = 1; - s->range_table = (&range_digital); - s->insn_bits = usbdux_dio_insn_bits; - s->insn_config = usbdux_dio_insn_config; - /* we don't use it */ - s->private = NULL; - if (uds->high_speed) { - /* timer / pwm subdevice */ - s = &dev->subdevices[SUBDEV_PWM]; - s->type = COMEDI_SUBD_PWM; - s->subdev_flags = SDF_WRITABLE | SDF_PWM_HBRIDGE; - s->n_chan = 8; - /* this defines the max duty cycle resolution */ - s->maxdata = uds->sizePwmBuf; - s->insn_write = usbdux_pwm_write; - s->insn_read = usbdux_pwm_read; - s->insn_config = usbdux_pwm_config; - usbdux_pwm_period(dev, s, PWM_DEFAULT_PERIOD); + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_CMD_WRITE; + s->n_chan = USBDUXSIGMA_NUM_AO_CHAN; + s->len_chanlist = s->n_chan; + s->maxdata = 0x00ff; + s->range_table = &range_unipolar2_5; + s->insn_write = usbduxsigma_ao_insn_write; + s->insn_read = usbduxsigma_ao_insn_read; + s->do_cmdtest = usbduxsigma_ao_cmdtest; + s->do_cmd = usbduxsigma_ao_cmd; + s->cancel = usbduxsigma_ao_cancel; + + /* Digital I/O subdevice */ + s = &dev->subdevices[2]; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 24; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = usbduxsigma_dio_insn_bits; + s->insn_config = usbduxsigma_dio_insn_config; + + if (devpriv->high_speed) { + /* Timer / pwm subdevice */ + s = &dev->subdevices[3]; + s->type = COMEDI_SUBD_PWM; + s->subdev_flags = SDF_WRITABLE | SDF_PWM_HBRIDGE; + s->n_chan = 8; + s->maxdata = devpriv->pwm_buf_sz; + s->insn_write = usbduxsigma_pwm_write; + s->insn_config = usbduxsigma_pwm_config; + + usbduxsigma_pwm_period(dev, s, PWM_DEFAULT_PERIOD); } - /* finally decide that it's attached */ - uds->attached = 1; - up(&uds->sem); - offset = usbdux_getstatusinfo(dev, 0); + + up(&devpriv->sem); + + offset = usbduxsigma_getstatusinfo(dev, 0); if (offset < 0) - dev_err(&uds->interface->dev, - "Communication to USBDUXSIGMA failed! Check firmware and cabling."); - dev_info(&uds->interface->dev, - "comedi%d: attached, ADC_zero = %x\n", dev->minor, offset); + dev_err(dev->class_dev, + "Communication to USBDUXSIGMA failed! Check firmware and cabling\n"); + + dev_info(dev->class_dev, "attached, ADC_zero = %x\n", offset); + return 0; } +static int usbduxsigma_firmware_upload(struct comedi_device *dev, + const u8 *data, size_t size, + unsigned long context) +{ + struct usb_device *usb = comedi_to_usb_dev(dev); + uint8_t *buf; + uint8_t *tmp; + int ret; + + if (!data) + return 0; + + if (size > FIRMWARE_MAX_LEN) { + dev_err(dev->class_dev, "firmware binary too large for FX2\n"); + return -ENOMEM; + } + + /* we generate a local buffer for the firmware */ + buf = kmemdup(data, size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + /* we need a malloc'ed buffer for usb_control_msg() */ + tmp = kmalloc(1, GFP_KERNEL); + if (!tmp) { + kfree(buf); + return -ENOMEM; + } + + /* stop the current firmware on the device */ + *tmp = 1; /* 7f92 to one */ + ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), + USBDUXSUB_FIRMWARE, + VENDOR_DIR_OUT, + USBDUXSUB_CPUCS, 0x0000, + tmp, 1, + BULK_TIMEOUT); + if (ret < 0) { + dev_err(dev->class_dev, "can not stop firmware\n"); + goto done; + } + + /* upload the new firmware to the device */ + ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), + USBDUXSUB_FIRMWARE, + VENDOR_DIR_OUT, + 0, 0x0000, + buf, size, + BULK_TIMEOUT); + if (ret < 0) { + dev_err(dev->class_dev, "firmware upload failed\n"); + goto done; + } + + /* start the new firmware on the device */ + *tmp = 0; /* 7f92 to zero */ + ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), + USBDUXSUB_FIRMWARE, + VENDOR_DIR_OUT, + USBDUXSUB_CPUCS, 0x0000, + tmp, 1, + BULK_TIMEOUT); + if (ret < 0) + dev_err(dev->class_dev, "can not start firmware\n"); + +done: + kfree(tmp); + kfree(buf); + return ret; +} + +static int usbduxsigma_alloc_usb_buffers(struct comedi_device *dev) +{ + struct usb_device *usb = comedi_to_usb_dev(dev); + struct usbduxsigma_private *devpriv = dev->private; + struct urb *urb; + int i; + + devpriv->dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL); + devpriv->dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL); + devpriv->in_buf = kzalloc(SIZEINBUF, GFP_KERNEL); + devpriv->insn_buf = kzalloc(SIZEINSNBUF, GFP_KERNEL); + devpriv->ai_urbs = kcalloc(devpriv->n_ai_urbs, sizeof(*urb), + GFP_KERNEL); + devpriv->ao_urbs = kcalloc(devpriv->n_ao_urbs, sizeof(*urb), + GFP_KERNEL); + if (!devpriv->dac_commands || !devpriv->dux_commands || + !devpriv->in_buf || !devpriv->insn_buf || + !devpriv->ai_urbs || !devpriv->ao_urbs) + return -ENOMEM; + + for (i = 0; i < devpriv->n_ai_urbs; i++) { + /* one frame: 1ms */ + urb = usb_alloc_urb(1, GFP_KERNEL); + if (!urb) + return -ENOMEM; + devpriv->ai_urbs[i] = urb; + urb->dev = usb; + /* will be filled later with a pointer to the comedi-device */ + /* and ONLY then the urb should be submitted */ + urb->context = NULL; + urb->pipe = usb_rcvisocpipe(usb, USBDUXSIGMA_ISO_IN_EP); + urb->transfer_flags = URB_ISO_ASAP; + urb->transfer_buffer = kzalloc(SIZEINBUF, GFP_KERNEL); + if (!urb->transfer_buffer) + return -ENOMEM; + urb->complete = usbduxsigma_ai_urb_complete; + urb->number_of_packets = 1; + urb->transfer_buffer_length = SIZEINBUF; + urb->iso_frame_desc[0].offset = 0; + urb->iso_frame_desc[0].length = SIZEINBUF; + } + + for (i = 0; i < devpriv->n_ao_urbs; i++) { + /* one frame: 1ms */ + urb = usb_alloc_urb(1, GFP_KERNEL); + if (!urb) + return -ENOMEM; + devpriv->ao_urbs[i] = urb; + urb->dev = usb; + /* will be filled later with a pointer to the comedi-device */ + /* and ONLY then the urb should be submitted */ + urb->context = NULL; + urb->pipe = usb_sndisocpipe(usb, USBDUXSIGMA_ISO_OUT_EP); + urb->transfer_flags = URB_ISO_ASAP; + urb->transfer_buffer = kzalloc(SIZEOUTBUF, GFP_KERNEL); + if (!urb->transfer_buffer) + return -ENOMEM; + urb->complete = usbduxsigma_ao_urb_complete; + urb->number_of_packets = 1; + urb->transfer_buffer_length = SIZEOUTBUF; + urb->iso_frame_desc[0].offset = 0; + urb->iso_frame_desc[0].length = SIZEOUTBUF; + if (devpriv->high_speed) + urb->interval = 8; /* uframes */ + else + urb->interval = 1; /* frames */ + } + + if (devpriv->high_speed) { + /* max bulk ep size in high speed */ + devpriv->pwm_buf_sz = 512; + urb = usb_alloc_urb(0, GFP_KERNEL); + if (!urb) + return -ENOMEM; + devpriv->pwm_urb = urb; + urb->transfer_buffer = kzalloc(devpriv->pwm_buf_sz, GFP_KERNEL); + if (!urb->transfer_buffer) + return -ENOMEM; + } else { + devpriv->pwm_urb = NULL; + devpriv->pwm_buf_sz = 0; + } + + return 0; +} + +static void usbduxsigma_free_usb_buffers(struct comedi_device *dev) +{ + struct usbduxsigma_private *devpriv = dev->private; + struct urb *urb; + int i; + + /* force unlink all urbs */ + usbduxsigma_ai_stop(dev, 1); + usbduxsigma_ao_stop(dev, 1); + usbduxsigma_pwm_stop(dev, 1); + + urb = devpriv->pwm_urb; + if (urb) { + kfree(urb->transfer_buffer); + usb_free_urb(urb); + } + if (devpriv->ao_urbs) { + for (i = 0; i < devpriv->n_ao_urbs; i++) { + urb = devpriv->ao_urbs[i]; + if (urb) { + kfree(urb->transfer_buffer); + usb_free_urb(urb); + } + } + kfree(devpriv->ao_urbs); + } + if (devpriv->ai_urbs) { + for (i = 0; i < devpriv->n_ai_urbs; i++) { + urb = devpriv->ai_urbs[i]; + if (urb) { + kfree(urb->transfer_buffer); + usb_free_urb(urb); + } + } + kfree(devpriv->ai_urbs); + } + kfree(devpriv->insn_buf); + kfree(devpriv->in_buf); + kfree(devpriv->dux_commands); + kfree(devpriv->dac_commands); +} + static int usbduxsigma_auto_attach(struct comedi_device *dev, unsigned long context_unused) { - struct usb_interface *uinterf = comedi_to_usb_interface(dev); + struct usb_interface *intf = comedi_to_usb_interface(dev); + struct usb_device *usb = comedi_to_usb_dev(dev); + struct usbduxsigma_private *devpriv; int ret; - struct usbduxsub *uds; - dev->private = NULL; - down(&start_stop_sem); - uds = usb_get_intfdata(uinterf); - if (!uds || !uds->probed) { + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; + + sema_init(&devpriv->sem, 1); + usb_set_intfdata(intf, devpriv); + + ret = usb_set_interface(usb, + intf->altsetting->desc.bInterfaceNumber, 3); + if (ret < 0) { dev_err(dev->class_dev, - "usbduxsigma: error: auto_attach failed, not connected\n"); - ret = -ENODEV; - } else if (uds->attached) { - dev_err(dev->class_dev, - "usbduxsigma: error: auto_attach failed, already attached\n"); - ret = -ENODEV; - } else - ret = usbduxsigma_attach_common(dev, uds); - up(&start_stop_sem); - return ret; + "could not set alternate setting 3 in high speed\n"); + return -ENODEV; + } + + /* test if it is high speed (USB 2.0) */ + devpriv->high_speed = (usb->speed == USB_SPEED_HIGH); + if (devpriv->high_speed) { + devpriv->n_ai_urbs = NUMOFINBUFFERSHIGH; + devpriv->n_ao_urbs = NUMOFOUTBUFFERSHIGH; + } else { + devpriv->n_ai_urbs = NUMOFINBUFFERSFULL; + devpriv->n_ao_urbs = NUMOFOUTBUFFERSFULL; + } + + ret = usbduxsigma_alloc_usb_buffers(dev); + if (ret) + return ret; + + ret = comedi_load_firmware(dev, &usb->dev, FIRMWARE, + usbduxsigma_firmware_upload, 0); + if (ret) + return ret; + + return usbduxsigma_attach_common(dev); } static void usbduxsigma_detach(struct comedi_device *dev) { - struct usbduxsub *usb = dev->private; + struct usb_interface *intf = comedi_to_usb_interface(dev); + struct usbduxsigma_private *devpriv = dev->private; - if (usb) { - down(&usb->sem); - dev->private = NULL; - usb->attached = 0; - usb->comedidev = NULL; - up(&usb->sem); - } + if (!devpriv) + return; + + usb_set_intfdata(intf, NULL); + + down(&devpriv->sem); + usbduxsigma_free_usb_buffers(dev); + up(&devpriv->sem); } static struct comedi_driver usbduxsigma_driver = { @@ -2351,306 +1737,10 @@ static struct comedi_driver usbduxsigma_driver = { .detach = usbduxsigma_detach, }; -static void usbdux_firmware_request_complete_handler(const struct firmware *fw, - void *context) -{ - struct usbduxsub *usbduxsub_tmp = context; - struct usb_interface *uinterf = usbduxsub_tmp->interface; - int ret; - - if (fw == NULL) { - dev_err(&uinterf->dev, - "Firmware complete handler without firmware!\n"); - return; - } - - /* - * we need to upload the firmware here because fw will be - * freed once we've left this function - */ - ret = firmwareUpload(usbduxsub_tmp, fw->data, fw->size); - - if (ret) { - dev_err(&uinterf->dev, - "Could not upload firmware (err=%d)\n", ret); - goto out; - } - comedi_usb_auto_config(uinterf, &usbduxsigma_driver, 0); -out: - release_firmware(fw); -} - -static int usbduxsigma_usb_probe(struct usb_interface *uinterf, +static int usbduxsigma_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) { - struct usb_device *udev = interface_to_usbdev(uinterf); - struct device *dev = &uinterf->dev; - int i; - int index; - int ret; - - dev_dbg(dev, "comedi_: usbdux_: " - "finding a free structure for the usb-device\n"); - - down(&start_stop_sem); - /* look for a free place in the usbdux array */ - index = -1; - for (i = 0; i < NUMUSBDUX; i++) { - if (!(usbduxsub[i].probed)) { - index = i; - break; - } - } - - /* no more space */ - if (index == -1) { - dev_err(dev, "Too many usbduxsigma-devices connected.\n"); - up(&start_stop_sem); - return -EMFILE; - } - dev_dbg(dev, "comedi_: usbdux: " - "usbduxsub[%d] is ready to connect to comedi.\n", index); - - sema_init(&(usbduxsub[index].sem), 1); - /* save a pointer to the usb device */ - usbduxsub[index].usbdev = udev; - - /* save the interface itself */ - usbduxsub[index].interface = uinterf; - /* get the interface number from the interface */ - usbduxsub[index].ifnum = uinterf->altsetting->desc.bInterfaceNumber; - /* hand the private data over to the usb subsystem */ - /* will be needed for disconnect */ - usb_set_intfdata(uinterf, &(usbduxsub[index])); - - dev_dbg(dev, "comedi_: usbdux: ifnum=%d\n", usbduxsub[index].ifnum); - - /* test if it is high speed (USB 2.0) */ - usbduxsub[index].high_speed = - (usbduxsub[index].usbdev->speed == USB_SPEED_HIGH); - - /* create space for the commands of the DA converter */ - usbduxsub[index].dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL); - if (!usbduxsub[index].dac_commands) { - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - /* create space for the commands going to the usb device */ - usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL); - if (!usbduxsub[index].dux_commands) { - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - /* create space for the in buffer and set it to zero */ - usbduxsub[index].inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL); - if (!(usbduxsub[index].inBuffer)) { - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - /* create space of the instruction buffer */ - usbduxsub[index].insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL); - if (!(usbduxsub[index].insnBuffer)) { - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - /* create space for the outbuffer */ - usbduxsub[index].outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL); - if (!(usbduxsub[index].outBuffer)) { - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - /* setting to alternate setting 3: enabling iso ep and bulk ep. */ - i = usb_set_interface(usbduxsub[index].usbdev, - usbduxsub[index].ifnum, 3); - if (i < 0) { - dev_err(dev, "comedi_: usbduxsigma%d: " - "could not set alternate setting 3 in high speed.\n", - index); - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENODEV; - } - if (usbduxsub[index].high_speed) - usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSHIGH; - else - usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSFULL; - - usbduxsub[index].urbIn = kcalloc(usbduxsub[index].numOfInBuffers, - sizeof(struct urb *), - GFP_KERNEL); - if (!(usbduxsub[index].urbIn)) { - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - for (i = 0; i < usbduxsub[index].numOfInBuffers; i++) { - /* one frame: 1ms */ - usbduxsub[index].urbIn[i] = usb_alloc_urb(1, GFP_KERNEL); - if (usbduxsub[index].urbIn[i] == NULL) { - dev_err(dev, "comedi_: usbduxsigma%d: " - "Could not alloc. urb(%d)\n", index, i); - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - usbduxsub[index].urbIn[i]->dev = usbduxsub[index].usbdev; - /* will be filled later with a pointer to the comedi-device */ - /* and ONLY then the urb should be submitted */ - usbduxsub[index].urbIn[i]->context = NULL; - usbduxsub[index].urbIn[i]->pipe = - usb_rcvisocpipe(usbduxsub[index].usbdev, ISOINEP); - usbduxsub[index].urbIn[i]->transfer_flags = URB_ISO_ASAP; - usbduxsub[index].urbIn[i]->transfer_buffer = - kzalloc(SIZEINBUF, GFP_KERNEL); - if (!(usbduxsub[index].urbIn[i]->transfer_buffer)) { - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - usbduxsub[index].urbIn[i]->complete = usbduxsub_ai_IsocIrq; - usbduxsub[index].urbIn[i]->number_of_packets = 1; - usbduxsub[index].urbIn[i]->transfer_buffer_length = SIZEINBUF; - usbduxsub[index].urbIn[i]->iso_frame_desc[0].offset = 0; - usbduxsub[index].urbIn[i]->iso_frame_desc[0].length = - SIZEINBUF; - } - - /* out */ - if (usbduxsub[index].high_speed) - usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSHIGH; - else - usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSFULL; - - usbduxsub[index].urbOut = kcalloc(usbduxsub[index].numOfOutBuffers, - sizeof(struct urb *), GFP_KERNEL); - if (!(usbduxsub[index].urbOut)) { - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - for (i = 0; i < usbduxsub[index].numOfOutBuffers; i++) { - /* one frame: 1ms */ - usbduxsub[index].urbOut[i] = usb_alloc_urb(1, GFP_KERNEL); - if (usbduxsub[index].urbOut[i] == NULL) { - dev_err(dev, "comedi_: usbduxsigma%d: " - "Could not alloc. urb(%d)\n", index, i); - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - usbduxsub[index].urbOut[i]->dev = usbduxsub[index].usbdev; - /* will be filled later with a pointer to the comedi-device */ - /* and ONLY then the urb should be submitted */ - usbduxsub[index].urbOut[i]->context = NULL; - usbduxsub[index].urbOut[i]->pipe = - usb_sndisocpipe(usbduxsub[index].usbdev, ISOOUTEP); - usbduxsub[index].urbOut[i]->transfer_flags = URB_ISO_ASAP; - usbduxsub[index].urbOut[i]->transfer_buffer = - kzalloc(SIZEOUTBUF, GFP_KERNEL); - if (!(usbduxsub[index].urbOut[i]->transfer_buffer)) { - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - usbduxsub[index].urbOut[i]->complete = usbduxsub_ao_IsocIrq; - usbduxsub[index].urbOut[i]->number_of_packets = 1; - usbduxsub[index].urbOut[i]->transfer_buffer_length = - SIZEOUTBUF; - usbduxsub[index].urbOut[i]->iso_frame_desc[0].offset = 0; - usbduxsub[index].urbOut[i]->iso_frame_desc[0].length = - SIZEOUTBUF; - if (usbduxsub[index].high_speed) { - /* uframes */ - usbduxsub[index].urbOut[i]->interval = 8; - } else { - /* frames */ - usbduxsub[index].urbOut[i]->interval = 1; - } - } - - /* pwm */ - if (usbduxsub[index].high_speed) { - /* max bulk ep size in high speed */ - usbduxsub[index].sizePwmBuf = 512; - usbduxsub[index].urbPwm = usb_alloc_urb(0, GFP_KERNEL); - if (usbduxsub[index].urbPwm == NULL) { - dev_err(dev, "comedi_: usbduxsigma%d: " - "Could not alloc. pwm urb\n", index); - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - usbduxsub[index].urbPwm->transfer_buffer = - kzalloc(usbduxsub[index].sizePwmBuf, GFP_KERNEL); - if (!(usbduxsub[index].urbPwm->transfer_buffer)) { - tidy_up(&(usbduxsub[index])); - up(&start_stop_sem); - return -ENOMEM; - } - } else { - usbduxsub[index].urbPwm = NULL; - usbduxsub[index].sizePwmBuf = 0; - } - - usbduxsub[index].ai_cmd_running = 0; - usbduxsub[index].ao_cmd_running = 0; - usbduxsub[index].pwm_cmd_running = 0; - - /* we've reached the bottom of the function */ - usbduxsub[index].probed = 1; - up(&start_stop_sem); - - ret = request_firmware_nowait(THIS_MODULE, - FW_ACTION_HOTPLUG, - FIRMWARE, - &udev->dev, - GFP_KERNEL, - usbduxsub + index, - usbdux_firmware_request_complete_handler - ); - - if (ret) { - dev_err(dev, "Could not load firmware (err=%d)\n", ret); - return ret; - } - - dev_info(dev, "comedi_: successfully initialised.\n"); - /* success */ - return 0; -} - -static void usbduxsigma_usb_disconnect(struct usb_interface *intf) -{ - struct usbduxsub *usbduxsub_tmp = usb_get_intfdata(intf); - struct usb_device *udev = interface_to_usbdev(intf); - - if (!usbduxsub_tmp) { - dev_err(&intf->dev, - "comedi_: disconnect called with null pointer.\n"); - return; - } - if (usbduxsub_tmp->usbdev != udev) { - dev_err(&intf->dev, "comedi_: BUG! wrong ptr!\n"); - return; - } - if (usbduxsub_tmp->ai_cmd_running) - /* we are still running a command */ - usbdux_ai_stop(usbduxsub_tmp, 1); - if (usbduxsub_tmp->ao_cmd_running) - /* we are still running a command */ - usbdux_ao_stop(usbduxsub_tmp, 1); - comedi_usb_auto_unconfig(intf); - down(&start_stop_sem); - down(&usbduxsub_tmp->sem); - tidy_up(usbduxsub_tmp); - up(&usbduxsub_tmp->sem); - up(&start_stop_sem); - dev_info(&intf->dev, "comedi_: disconnected from the usb\n"); + return comedi_usb_auto_config(intf, &usbduxsigma_driver, 0); } static const struct usb_device_id usbduxsigma_usb_table[] = { @@ -2664,7 +1754,7 @@ MODULE_DEVICE_TABLE(usb, usbduxsigma_usb_table); static struct usb_driver usbduxsigma_usb_driver = { .name = "usbduxsigma", .probe = usbduxsigma_usb_probe, - .disconnect = usbduxsigma_usb_disconnect, + .disconnect = comedi_usb_auto_unconfig, .id_table = usbduxsigma_usb_table, }; module_comedi_usb_driver(usbduxsigma_driver, usbduxsigma_usb_driver); diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 2be5087414f6..0ab04c0dd410 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -16,11 +16,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* Driver: vmk80xx @@ -159,8 +154,6 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { }; struct vmk80xx_private { - struct usb_device *usb; - struct usb_interface *intf; struct usb_endpoint_descriptor *ep_rx; struct usb_endpoint_descriptor *ep_tx; struct firmware_version fw; @@ -170,9 +163,10 @@ struct vmk80xx_private { enum vmk80xx_model model; }; -static int vmk80xx_check_data_link(struct vmk80xx_private *devpriv) +static int vmk80xx_check_data_link(struct comedi_device *dev) { - struct usb_device *usb = devpriv->usb; + struct vmk80xx_private *devpriv = dev->private; + struct usb_device *usb = comedi_to_usb_dev(dev); unsigned int tx_pipe; unsigned int rx_pipe; unsigned char tx[1]; @@ -194,9 +188,10 @@ static int vmk80xx_check_data_link(struct vmk80xx_private *devpriv) return (int)rx[1]; } -static void vmk80xx_read_eeprom(struct vmk80xx_private *devpriv, int flag) +static void vmk80xx_read_eeprom(struct comedi_device *dev, int flag) { - struct usb_device *usb = devpriv->usb; + struct vmk80xx_private *devpriv = dev->private; + struct usb_device *usb = comedi_to_usb_dev(dev); unsigned int tx_pipe; unsigned int rx_pipe; unsigned char tx[1]; @@ -223,9 +218,10 @@ static void vmk80xx_read_eeprom(struct vmk80xx_private *devpriv, int flag) strncpy(devpriv->fw.ic6_vers, rx + 25, 24); } -static void vmk80xx_do_bulk_msg(struct vmk80xx_private *devpriv) +static void vmk80xx_do_bulk_msg(struct comedi_device *dev) { - struct usb_device *usb = devpriv->usb; + struct vmk80xx_private *devpriv = dev->private; + struct usb_device *usb = comedi_to_usb_dev(dev); __u8 tx_addr; __u8 rx_addr; unsigned int tx_pipe; @@ -248,21 +244,18 @@ static void vmk80xx_do_bulk_msg(struct vmk80xx_private *devpriv) usb_bulk_msg(usb, rx_pipe, devpriv->usb_rx_buf, size, NULL, HZ * 10); } -static int vmk80xx_read_packet(struct vmk80xx_private *devpriv) +static int vmk80xx_read_packet(struct comedi_device *dev) { - struct usb_device *usb; + struct vmk80xx_private *devpriv = dev->private; + struct usb_device *usb = comedi_to_usb_dev(dev); struct usb_endpoint_descriptor *ep; unsigned int pipe; - if (!devpriv->intf) - return -ENODEV; - if (devpriv->model == VMK8061_MODEL) { - vmk80xx_do_bulk_msg(devpriv); + vmk80xx_do_bulk_msg(dev); return 0; } - usb = devpriv->usb; ep = devpriv->ep_rx; pipe = usb_rcvintpipe(usb, ep->bEndpointAddress); return usb_interrupt_msg(usb, pipe, devpriv->usb_rx_buf, @@ -270,23 +263,20 @@ static int vmk80xx_read_packet(struct vmk80xx_private *devpriv) HZ * 10); } -static int vmk80xx_write_packet(struct vmk80xx_private *devpriv, int cmd) +static int vmk80xx_write_packet(struct comedi_device *dev, int cmd) { - struct usb_device *usb; + struct vmk80xx_private *devpriv = dev->private; + struct usb_device *usb = comedi_to_usb_dev(dev); struct usb_endpoint_descriptor *ep; unsigned int pipe; - if (!devpriv->intf) - return -ENODEV; - devpriv->usb_tx_buf[0] = cmd; if (devpriv->model == VMK8061_MODEL) { - vmk80xx_do_bulk_msg(devpriv); + vmk80xx_do_bulk_msg(dev); return 0; } - usb = devpriv->usb; ep = devpriv->ep_tx; pipe = usb_sndintpipe(usb, ep->bEndpointAddress); return usb_interrupt_msg(usb, pipe, devpriv->usb_tx_buf, @@ -294,18 +284,19 @@ static int vmk80xx_write_packet(struct vmk80xx_private *devpriv, int cmd) HZ * 10); } -static int vmk80xx_reset_device(struct vmk80xx_private *devpriv) +static int vmk80xx_reset_device(struct comedi_device *dev) { + struct vmk80xx_private *devpriv = dev->private; size_t size; int retval; size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); memset(devpriv->usb_tx_buf, 0, size); - retval = vmk80xx_write_packet(devpriv, VMK8055_CMD_RST); + retval = vmk80xx_write_packet(dev, VMK8055_CMD_RST); if (retval) return retval; /* set outputs to known state as we cannot read them */ - return vmk80xx_write_packet(devpriv, VMK8055_CMD_WRT_AD); + return vmk80xx_write_packet(dev, VMK8055_CMD_WRT_AD); } static int vmk80xx_ai_insn_read(struct comedi_device *dev, @@ -338,7 +329,7 @@ static int vmk80xx_ai_insn_read(struct comedi_device *dev, } for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(devpriv)) + if (vmk80xx_read_packet(dev)) break; if (devpriv->model == VMK8055_MODEL) { @@ -388,7 +379,7 @@ static int vmk80xx_ao_insn_write(struct comedi_device *dev, for (n = 0; n < insn->n; n++) { devpriv->usb_tx_buf[reg] = data[n]; - if (vmk80xx_write_packet(devpriv, cmd)) + if (vmk80xx_write_packet(dev, cmd)) break; } @@ -415,7 +406,7 @@ static int vmk80xx_ao_insn_read(struct comedi_device *dev, devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_AO; for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(devpriv)) + if (vmk80xx_read_packet(dev)) break; data[n] = devpriv->usb_rx_buf[reg + chan]; @@ -447,7 +438,7 @@ static int vmk80xx_di_insn_bits(struct comedi_device *dev, reg = VMK8055_DI_REG; } - retval = vmk80xx_read_packet(devpriv); + retval = vmk80xx_read_packet(dev); if (!retval) { if (devpriv->model == VMK8055_MODEL) @@ -492,7 +483,7 @@ static int vmk80xx_do_insn_bits(struct comedi_device *dev, tx_buf[reg] &= ~data[0]; tx_buf[reg] |= (data[0] & data[1]); - retval = vmk80xx_write_packet(devpriv, cmd); + retval = vmk80xx_write_packet(dev, cmd); if (retval) goto out; @@ -501,7 +492,7 @@ static int vmk80xx_do_insn_bits(struct comedi_device *dev, if (devpriv->model == VMK8061_MODEL) { tx_buf[0] = VMK8061_CMD_RD_DO; - retval = vmk80xx_read_packet(devpriv); + retval = vmk80xx_read_packet(dev); if (!retval) { data[1] = rx_buf[reg]; @@ -547,7 +538,7 @@ static int vmk80xx_cnt_insn_read(struct comedi_device *dev, } for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(devpriv)) + if (vmk80xx_read_packet(dev)) break; if (devpriv->model == VMK8055_MODEL) @@ -597,7 +588,7 @@ static int vmk80xx_cnt_insn_config(struct comedi_device *dev, } for (n = 0; n < insn->n; n++) - if (vmk80xx_write_packet(devpriv, cmd)) + if (vmk80xx_write_packet(dev, cmd)) break; up(&devpriv->limit_sem); @@ -640,7 +631,7 @@ static int vmk80xx_cnt_insn_write(struct comedi_device *dev, devpriv->usb_tx_buf[6 + chan] = val; - if (vmk80xx_write_packet(devpriv, cmd)) + if (vmk80xx_write_packet(dev, cmd)) break; } @@ -671,7 +662,7 @@ static int vmk80xx_pwm_insn_read(struct comedi_device *dev, tx_buf[0] = VMK8061_CMD_RD_PWM; for (n = 0; n < insn->n; n++) { - if (vmk80xx_read_packet(devpriv)) + if (vmk80xx_read_packet(dev)) break; data[n] = rx_buf[reg[0]] + 4 * rx_buf[reg[1]]; @@ -719,7 +710,7 @@ static int vmk80xx_pwm_insn_write(struct comedi_device *dev, tx_buf[reg[0]] = (unsigned char)(data[n] & 0x03); tx_buf[reg[1]] = (unsigned char)(data[n] >> 2) & 0xff; - if (vmk80xx_write_packet(devpriv, cmd)) + if (vmk80xx_write_packet(dev, cmd)) break; } @@ -731,7 +722,7 @@ static int vmk80xx_pwm_insn_write(struct comedi_device *dev, static int vmk80xx_find_usb_endpoints(struct comedi_device *dev) { struct vmk80xx_private *devpriv = dev->private; - struct usb_interface *intf = devpriv->intf; + struct usb_interface *intf = comedi_to_usb_interface(dev); struct usb_host_interface *iface_desc = intf->cur_altsetting; struct usb_endpoint_descriptor *ep_desc; int i; @@ -889,8 +880,6 @@ static int vmk80xx_auto_attach(struct comedi_device *dev, return -ENOMEM; dev->private = devpriv; - devpriv->usb = interface_to_usbdev(intf); - devpriv->intf = intf; devpriv->model = boardinfo->model; ret = vmk80xx_find_usb_endpoints(dev); @@ -906,23 +895,24 @@ static int vmk80xx_auto_attach(struct comedi_device *dev, usb_set_intfdata(intf, devpriv); if (devpriv->model == VMK8061_MODEL) { - vmk80xx_read_eeprom(devpriv, IC3_VERSION); + vmk80xx_read_eeprom(dev, IC3_VERSION); dev_info(&intf->dev, "%s\n", devpriv->fw.ic3_vers); - if (vmk80xx_check_data_link(devpriv)) { - vmk80xx_read_eeprom(devpriv, IC6_VERSION); + if (vmk80xx_check_data_link(dev)) { + vmk80xx_read_eeprom(dev, IC6_VERSION); dev_info(&intf->dev, "%s\n", devpriv->fw.ic6_vers); } } if (devpriv->model == VMK8055_MODEL) - vmk80xx_reset_device(devpriv); + vmk80xx_reset_device(dev); return vmk80xx_init_subdevices(dev); } static void vmk80xx_detach(struct comedi_device *dev) { + struct usb_interface *intf = comedi_to_usb_interface(dev); struct vmk80xx_private *devpriv = dev->private; if (!devpriv) @@ -930,7 +920,7 @@ static void vmk80xx_detach(struct comedi_device *dev) down(&devpriv->limit_sem); - usb_set_intfdata(devpriv->intf, NULL); + usb_set_intfdata(intf, NULL); kfree(devpriv->usb_rx_buf); kfree(devpriv->usb_tx_buf); diff --git a/drivers/staging/comedi/kcomedilib/kcomedilib_main.c b/drivers/staging/comedi/kcomedilib/kcomedilib_main.c index 3231a483f561..da8988c6bf50 100644 --- a/drivers/staging/comedi/kcomedilib/kcomedilib_main.c +++ b/drivers/staging/comedi/kcomedilib/kcomedilib_main.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #include diff --git a/drivers/staging/comedi/proc.c b/drivers/staging/comedi/proc.c index 886c202de9ab..8ee94424bc8f 100644 --- a/drivers/staging/comedi/proc.c +++ b/drivers/staging/comedi/proc.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ /* diff --git a/drivers/staging/comedi/range.c b/drivers/staging/comedi/range.c index 1dc391b76447..1f20332cc459 100644 --- a/drivers/staging/comedi/range.c +++ b/drivers/staging/comedi/range.c @@ -14,11 +14,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ #include diff --git a/drivers/staging/cptm1217/clearpad_tm1217.c b/drivers/staging/cptm1217/clearpad_tm1217.c index e96eee3ca898..42a5f5c8d3d1 100644 --- a/drivers/staging/cptm1217/clearpad_tm1217.c +++ b/drivers/staging/cptm1217/clearpad_tm1217.c @@ -547,10 +547,8 @@ fail_gpio: fail: /* Clean up before returning failure */ for (i = 0; i < TOUCH_SUPPORTED; i++) { - if (ts->cp_input_info[i].input) { + if (ts->cp_input_info[i].input) input_unregister_device(ts->cp_input_info[i].input); - input_free_device(ts->cp_input_info[i].input); - } } kfree(ts); return retval; diff --git a/drivers/staging/crystalhd/bc_dts_glob_lnx.h b/drivers/staging/crystalhd/bc_dts_glob_lnx.h index fd1a6e680c8a..981708f3ee39 100644 --- a/drivers/staging/crystalhd/bc_dts_glob_lnx.h +++ b/drivers/staging/crystalhd/bc_dts_glob_lnx.h @@ -58,11 +58,11 @@ * between the driver and the application. */ enum BC_DTS_GLOBALS { - BC_MAX_FW_CMD_BUFF_SZ = 0x40, /* FW passthrough cmd/rsp buffer size */ + BC_MAX_FW_CMD_BUFF_SZ = 0x40, /* FW passthrough cmd/rsp buffer size */ PCI_CFG_SIZE = 256, /* PCI config size buffer */ BC_IOCTL_DATA_POOL_SIZE = 8, /* BC_IOCTL_DATA Pool size */ - BC_LINK_MAX_OPENS = 3, /* Maximum simultaneous opens*/ - BC_LINK_MAX_SGLS = 1024, /* Maximum SG elements 4M/4K */ + BC_LINK_MAX_OPENS = 3, /* Maximum simultaneous opens*/ + BC_LINK_MAX_SGLS = 1024, /* Maximum SG elements 4M/4K */ BC_TX_LIST_CNT = 2, /* Max Tx DMA Rings */ BC_RX_LIST_CNT = 8, /* Max Rx DMA Rings*/ BC_PROC_OUTPUT_TIMEOUT = 3000, /* Milliseconds */ @@ -240,11 +240,14 @@ enum BC_DRV_CMD { DRV_CMD_ADD_RXBUFFS, /* Add Rx side buffers to driver pool */ DRV_CMD_FETCH_RXBUFF, /* Get Rx DMAed buffer */ DRV_CMD_START_RX_CAP, /* Start Rx Buffer Capture */ - DRV_CMD_FLUSH_RX_CAP, /* Stop the capture for now...we will enhance this later*/ + DRV_CMD_FLUSH_RX_CAP, /* Stop the capture for now... + we will enhance this later*/ DRV_CMD_GET_DRV_STAT, /* Get Driver Internal Statistics */ DRV_CMD_RST_DRV_STAT, /* Reset Driver Internal Statistics */ - DRV_CMD_NOTIFY_MODE, /* Notify the Mode to driver in which the application is Operating*/ - DRV_CMD_CHANGE_CLOCK, /* Change the core clock to either save power or improve performance */ + DRV_CMD_NOTIFY_MODE, /* Notify the Mode to driver + in which the application is Operating*/ + DRV_CMD_CHANGE_CLOCK, /* Change the core clock to either save power + or improve performance */ /* MUST be the last one.. */ DRV_CMD_END, /* End of the List.. */ @@ -283,8 +286,8 @@ struct crystalhd_ioctl_data { struct BC_IOCTL_DATA udata; /* IOCTL from App..*/ uint32_t u_id; /* Driver specific user ID */ uint32_t cmd; /* Cmd ID for driver's use. */ - void *add_cdata; /* Additional command specific data..*/ - uint32_t add_cdata_sz; /* Additional command specific data size */ + void *add_cdata; /* Additional command specific data..*/ + uint32_t add_cdata_sz; /* Additional command specific data size */ struct crystalhd_ioctl_data *next; /* List/Fifo management */ }; diff --git a/drivers/staging/crystalhd/crystalhd_cmds.c b/drivers/staging/crystalhd/crystalhd_cmds.c index ed99daa6ef46..3ab502b8c3be 100644 --- a/drivers/staging/crystalhd/crystalhd_cmds.c +++ b/drivers/staging/crystalhd/crystalhd_cmds.c @@ -472,8 +472,8 @@ static enum BC_STATUS bc_cproc_hw_txdma(struct crystalhd_cmd *ctx, } /* Helper function to check on user buffers */ -static enum BC_STATUS bc_cproc_check_inbuffs(bool pin, void *ubuff, uint32_t ub_sz, - uint32_t uv_off, bool en_422) +static enum BC_STATUS bc_cproc_check_inbuffs(bool pin, void *ubuff, + uint32_t ub_sz, uint32_t uv_off, bool en_422) { if (!ubuff || !ub_sz) { BCMLOG_ERR("%s->Invalid Arg %p %x\n", @@ -483,8 +483,9 @@ static enum BC_STATUS bc_cproc_check_inbuffs(bool pin, void *ubuff, uint32_t ub_ /* Check for alignment */ if (((uintptr_t)ubuff) & 0x03) { - BCMLOG_ERR("%s-->Un-aligned address not implemented yet.. %p\n", - ((pin) ? "TX" : "RX"), ubuff); + BCMLOG_ERR( + "%s-->Un-aligned address not implemented yet.. %p\n", + ((pin) ? "TX" : "RX"), ubuff); return BC_STS_NOT_IMPL; } if (pin) @@ -572,7 +573,8 @@ static enum BC_STATUS bc_cproc_add_cap_buff(struct crystalhd_cmd *ctx, if (!dio_hnd) return BC_STS_ERROR; - sts = crystalhd_hw_add_cap_buffer(&ctx->hw_ctx, dio_hnd, (ctx->state == BC_LINK_READY)); + sts = crystalhd_hw_add_cap_buffer(&ctx->hw_ctx, dio_hnd, + (ctx->state == BC_LINK_READY)); if ((sts != BC_STS_SUCCESS) && (sts != BC_STS_BUSY)) { crystalhd_unmap_dio(ctx->adp, dio_hnd); return sts; @@ -618,7 +620,8 @@ static enum BC_STATUS bc_cproc_fetch_frame(struct crystalhd_cmd *ctx, sts = crystalhd_hw_get_cap_buffer(&ctx->hw_ctx, &frame->PibInfo, &dio); if (sts != BC_STS_SUCCESS) - return (ctx->state & BC_LINK_SUSPEND) ? BC_STS_IO_USER_ABORT : sts; + return (ctx->state & BC_LINK_SUSPEND) ? + BC_STS_IO_USER_ABORT : sts; frame->Flags = dio->uinfo.comp_flags; @@ -673,7 +676,8 @@ static enum BC_STATUS bc_cproc_flush_cap_buffs(struct crystalhd_cmd *ctx, frame = &idata->udata.u.DecOutData; for (count = 0; count < BC_RX_LIST_CNT; count++) { - sts = crystalhd_hw_get_cap_buffer(&ctx->hw_ctx, &frame->PibInfo, &dio); + sts = crystalhd_hw_get_cap_buffer(&ctx->hw_ctx, + &frame->PibInfo, &dio); if (sts != BC_STS_SUCCESS) break; @@ -916,7 +920,8 @@ enum BC_STATUS crystalhd_user_open(struct crystalhd_cmd *ctx, * Closer application handle and release app specific * resources. */ -enum BC_STATUS crystalhd_user_close(struct crystalhd_cmd *ctx, struct crystalhd_user *uc) +enum BC_STATUS crystalhd_user_close(struct crystalhd_cmd *ctx, + struct crystalhd_user *uc) { uint32_t mode = uc->mode; @@ -1008,8 +1013,8 @@ enum BC_STATUS crystalhd_delete_cmd_context(struct crystalhd_cmd *ctx) * mode of operation and returns the function pointer * from the cproc table. */ -crystalhd_cmd_proc crystalhd_get_cmd_proc(struct crystalhd_cmd *ctx, uint32_t cmd, - struct crystalhd_user *uc) +crystalhd_cmd_proc crystalhd_get_cmd_proc(struct crystalhd_cmd *ctx, + uint32_t cmd, struct crystalhd_user *uc) { crystalhd_cmd_proc cproc = NULL; unsigned int i, tbl_sz; @@ -1024,7 +1029,8 @@ crystalhd_cmd_proc crystalhd_get_cmd_proc(struct crystalhd_cmd *ctx, uint32_t cm return NULL; } - tbl_sz = sizeof(g_crystalhd_cproc_tbl) / sizeof(struct crystalhd_cmd_tbl); + tbl_sz = sizeof(g_crystalhd_cproc_tbl) / + sizeof(struct crystalhd_cmd_tbl); for (i = 0; i < tbl_sz; i++) { if (g_crystalhd_cproc_tbl[i].cmd_id == cmd) { if ((uc->mode == DTS_MONITOR_MODE) && diff --git a/drivers/staging/crystalhd/crystalhd_cmds.h b/drivers/staging/crystalhd/crystalhd_cmds.h index 4066ba393a17..377cd9d68b08 100644 --- a/drivers/staging/crystalhd/crystalhd_cmds.h +++ b/drivers/staging/crystalhd/crystalhd_cmds.h @@ -66,7 +66,8 @@ struct crystalhd_cmd { struct crystalhd_hw hw_ctx; }; -typedef enum BC_STATUS(*crystalhd_cmd_proc)(struct crystalhd_cmd *, struct crystalhd_ioctl_data *); +typedef enum BC_STATUS(*crystalhd_cmd_proc)(struct crystalhd_cmd *, + struct crystalhd_ioctl_data *); struct crystalhd_cmd_tbl { uint32_t cmd_id; @@ -74,13 +75,17 @@ struct crystalhd_cmd_tbl { uint32_t block_mon; }; -enum BC_STATUS crystalhd_suspend(struct crystalhd_cmd *ctx, struct crystalhd_ioctl_data *idata); +enum BC_STATUS crystalhd_suspend(struct crystalhd_cmd *ctx, + struct crystalhd_ioctl_data *idata); enum BC_STATUS crystalhd_resume(struct crystalhd_cmd *ctx); -crystalhd_cmd_proc crystalhd_get_cmd_proc(struct crystalhd_cmd *ctx, uint32_t cmd, - struct crystalhd_user *uc); -enum BC_STATUS crystalhd_user_open(struct crystalhd_cmd *ctx, struct crystalhd_user **user_ctx); -enum BC_STATUS crystalhd_user_close(struct crystalhd_cmd *ctx, struct crystalhd_user *uc); -enum BC_STATUS crystalhd_setup_cmd_context(struct crystalhd_cmd *ctx, struct crystalhd_adp *adp); +crystalhd_cmd_proc crystalhd_get_cmd_proc(struct crystalhd_cmd *ctx, + uint32_t cmd, struct crystalhd_user *uc); +enum BC_STATUS crystalhd_user_open(struct crystalhd_cmd *ctx, + struct crystalhd_user **user_ctx); +enum BC_STATUS crystalhd_user_close(struct crystalhd_cmd *ctx, + struct crystalhd_user *uc); +enum BC_STATUS crystalhd_setup_cmd_context(struct crystalhd_cmd *ctx, + struct crystalhd_adp *adp); enum BC_STATUS crystalhd_delete_cmd_context(struct crystalhd_cmd *ctx); bool crystalhd_cmd_interrupt(struct crystalhd_cmd *ctx); diff --git a/drivers/staging/crystalhd/crystalhd_fw_if.h b/drivers/staging/crystalhd/crystalhd_fw_if.h index 9e2831e68bba..4b363a5069d7 100644 --- a/drivers/staging/crystalhd/crystalhd_fw_if.h +++ b/drivers/staging/crystalhd/crystalhd_fw_if.h @@ -106,7 +106,8 @@ struct ppb_vc1 { struct fgt_sei { struct fgt_sei *next; - unsigned char model_values[3][MAX_FGT_VALUE_INTERVAL][MAX_FGT_MODEL_VALUE]; + unsigned char + model_values[3][MAX_FGT_VALUE_INTERVAL][MAX_FGT_MODEL_VALUE]; unsigned char upper_bound[3][MAX_FGT_VALUE_INTERVAL]; unsigned char lower_bound[3][MAX_FGT_VALUE_INTERVAL]; @@ -125,10 +126,12 @@ struct fgt_sei { unsigned char blending_mode_id; /* Blending mode. */ unsigned char log2_scale_factor; /* Log2 scale factor (2-7). */ - unsigned char comp_flag[3]; /* Components [0,2] parameters present flag. */ - unsigned char num_intervals_minus1[3]; /* Number of intensity level intervals. */ + unsigned char comp_flag[3]; /* Components [0,2] + parameters present flag. */ + unsigned char num_intervals_minus1[3]; /* Number of + intensity level intervals. */ unsigned char num_model_values[3]; /* Number of model values. */ - uint16_t repetition_period; /* Repetition period (0-16384) */ + uint16_t repetition_period; /* Repetition period (0-16384) */ }; @@ -266,40 +269,40 @@ enum c011_ts_cmd { /* Decoding commands */ eCMD_C011_DEC_CHAN_OPEN = eCMD_C011_CMD_BASE + 0x100, - eCMD_C011_DEC_CHAN_CLOSE = eCMD_C011_CMD_BASE + 0x101, - eCMD_C011_DEC_CHAN_ACTIVATE = eCMD_C011_CMD_BASE + 0x102, - eCMD_C011_DEC_CHAN_STATUS = eCMD_C011_CMD_BASE + 0x103, - eCMD_C011_DEC_CHAN_FLUSH = eCMD_C011_CMD_BASE + 0x104, + eCMD_C011_DEC_CHAN_CLOSE = eCMD_C011_CMD_BASE + 0x101, + eCMD_C011_DEC_CHAN_ACTIVATE = eCMD_C011_CMD_BASE + 0x102, + eCMD_C011_DEC_CHAN_STATUS = eCMD_C011_CMD_BASE + 0x103, + eCMD_C011_DEC_CHAN_FLUSH = eCMD_C011_CMD_BASE + 0x104, eCMD_C011_DEC_CHAN_TRICK_PLAY = eCMD_C011_CMD_BASE + 0x105, - eCMD_C011_DEC_CHAN_TS_PIDS = eCMD_C011_CMD_BASE + 0x106, + eCMD_C011_DEC_CHAN_TS_PIDS = eCMD_C011_CMD_BASE + 0x106, eCMD_C011_DEC_CHAN_PS_STREAM_ID = eCMD_C011_CMD_BASE + 0x107, eCMD_C011_DEC_CHAN_INPUT_PARAMS = eCMD_C011_CMD_BASE + 0x108, eCMD_C011_DEC_CHAN_VIDEO_OUTPUT = eCMD_C011_CMD_BASE + 0x109, - eCMD_C011_DEC_CHAN_OUTPUT_FORMAT = eCMD_C011_CMD_BASE + 0x10A, - eCMD_C011_DEC_CHAN_SCALING_FILTERS = eCMD_C011_CMD_BASE + 0x10B, - eCMD_C011_DEC_CHAN_OSD_MODE = eCMD_C011_CMD_BASE + 0x10D, + eCMD_C011_DEC_CHAN_OUTPUT_FORMAT = eCMD_C011_CMD_BASE + 0x10A, + eCMD_C011_DEC_CHAN_SCALING_FILTERS = eCMD_C011_CMD_BASE + 0x10B, + eCMD_C011_DEC_CHAN_OSD_MODE = eCMD_C011_CMD_BASE + 0x10D, eCMD_C011_DEC_CHAN_DROP = eCMD_C011_CMD_BASE + 0x10E, - eCMD_C011_DEC_CHAN_RELEASE = eCMD_C011_CMD_BASE + 0x10F, - eCMD_C011_DEC_CHAN_STREAM_SETTINGS = eCMD_C011_CMD_BASE + 0x110, + eCMD_C011_DEC_CHAN_RELEASE = eCMD_C011_CMD_BASE + 0x10F, + eCMD_C011_DEC_CHAN_STREAM_SETTINGS = eCMD_C011_CMD_BASE + 0x110, eCMD_C011_DEC_CHAN_PAUSE_OUTPUT = eCMD_C011_CMD_BASE + 0x111, - eCMD_C011_DEC_CHAN_CHANGE = eCMD_C011_CMD_BASE + 0x112, - eCMD_C011_DEC_CHAN_SET_STC = eCMD_C011_CMD_BASE + 0x113, - eCMD_C011_DEC_CHAN_SET_PTS = eCMD_C011_CMD_BASE + 0x114, - eCMD_C011_DEC_CHAN_CC_MODE = eCMD_C011_CMD_BASE + 0x115, - eCMD_C011_DEC_CREATE_AUDIO_CONTEXT = eCMD_C011_CMD_BASE + 0x116, - eCMD_C011_DEC_COPY_AUDIO_CONTEXT = eCMD_C011_CMD_BASE + 0x117, - eCMD_C011_DEC_DELETE_AUDIO_CONTEXT = eCMD_C011_CMD_BASE + 0x118, - eCMD_C011_DEC_CHAN_SET_DECYPTION = eCMD_C011_CMD_BASE + 0x119, + eCMD_C011_DEC_CHAN_CHANGE = eCMD_C011_CMD_BASE + 0x112, + eCMD_C011_DEC_CHAN_SET_STC = eCMD_C011_CMD_BASE + 0x113, + eCMD_C011_DEC_CHAN_SET_PTS = eCMD_C011_CMD_BASE + 0x114, + eCMD_C011_DEC_CHAN_CC_MODE = eCMD_C011_CMD_BASE + 0x115, + eCMD_C011_DEC_CREATE_AUDIO_CONTEXT = eCMD_C011_CMD_BASE + 0x116, + eCMD_C011_DEC_COPY_AUDIO_CONTEXT = eCMD_C011_CMD_BASE + 0x117, + eCMD_C011_DEC_DELETE_AUDIO_CONTEXT = eCMD_C011_CMD_BASE + 0x118, + eCMD_C011_DEC_CHAN_SET_DECYPTION = eCMD_C011_CMD_BASE + 0x119, eCMD_C011_DEC_CHAN_START_VIDEO = eCMD_C011_CMD_BASE + 0x11A, eCMD_C011_DEC_CHAN_STOP_VIDEO = eCMD_C011_CMD_BASE + 0x11B, eCMD_C011_DEC_CHAN_PIC_CAPTURE = eCMD_C011_CMD_BASE + 0x11C, - eCMD_C011_DEC_CHAN_PAUSE = eCMD_C011_CMD_BASE + 0x11D, + eCMD_C011_DEC_CHAN_PAUSE = eCMD_C011_CMD_BASE + 0x11D, eCMD_C011_DEC_CHAN_PAUSE_STATE = eCMD_C011_CMD_BASE + 0x11E, - eCMD_C011_DEC_CHAN_SET_SLOWM_RATE = eCMD_C011_CMD_BASE + 0x11F, - eCMD_C011_DEC_CHAN_GET_SLOWM_RATE = eCMD_C011_CMD_BASE + 0x120, + eCMD_C011_DEC_CHAN_SET_SLOWM_RATE = eCMD_C011_CMD_BASE + 0x11F, + eCMD_C011_DEC_CHAN_GET_SLOWM_RATE = eCMD_C011_CMD_BASE + 0x120, eCMD_C011_DEC_CHAN_SET_FF_RATE = eCMD_C011_CMD_BASE + 0x121, eCMD_C011_DEC_CHAN_GET_FF_RATE = eCMD_C011_CMD_BASE + 0x122, - eCMD_C011_DEC_CHAN_FRAME_ADVANCE = eCMD_C011_CMD_BASE + 0x123, + eCMD_C011_DEC_CHAN_FRAME_ADVANCE = eCMD_C011_CMD_BASE + 0x123, eCMD_C011_DEC_CHAN_SET_SKIP_PIC_MODE = eCMD_C011_CMD_BASE + 0x124, eCMD_C011_DEC_CHAN_GET_SKIP_PIC_MODE = eCMD_C011_CMD_BASE + 0x125, eCMD_C011_DEC_CHAN_FILL_PIC_BUF = eCMD_C011_CMD_BASE + 0x126, @@ -308,15 +311,16 @@ enum c011_ts_cmd { eCMD_C011_DEC_CHAN_SET_BRCM_TRICK_MODE = eCMD_C011_CMD_BASE + 0x129, eCMD_C011_DEC_CHAN_GET_BRCM_TRICK_MODE = eCMD_C011_CMD_BASE + 0x12A, eCMD_C011_DEC_CHAN_REVERSE_FIELD_STATUS = eCMD_C011_CMD_BASE + 0x12B, - eCMD_C011_DEC_CHAN_I_PICTURE_FOUND = eCMD_C011_CMD_BASE + 0x12C, - eCMD_C011_DEC_CHAN_SET_PARAMETER = eCMD_C011_CMD_BASE + 0x12D, + eCMD_C011_DEC_CHAN_I_PICTURE_FOUND = eCMD_C011_CMD_BASE + 0x12C, + eCMD_C011_DEC_CHAN_SET_PARAMETER = eCMD_C011_CMD_BASE + 0x12D, eCMD_C011_DEC_CHAN_SET_USER_DATA_MODE = eCMD_C011_CMD_BASE + 0x12E, - eCMD_C011_DEC_CHAN_SET_PAUSE_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x12F, - eCMD_C011_DEC_CHAN_SET_SLOW_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x130, + eCMD_C011_DEC_CHAN_SET_PAUSE_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x12F, + eCMD_C011_DEC_CHAN_SET_SLOW_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x130, eCMD_C011_DEC_CHAN_SET_FF_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x131, - eCMD_C011_DEC_CHAN_SET_DISPLAY_TIMING_MODE = eCMD_C011_CMD_BASE + 0x132, - eCMD_C011_DEC_CHAN_SET_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x133, - eCMD_C011_DEC_CHAN_GET_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x134, + eCMD_C011_DEC_CHAN_SET_DISPLAY_TIMING_MODE = eCMD_C011_CMD_BASE + + 0x132, + eCMD_C011_DEC_CHAN_SET_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x133, + eCMD_C011_DEC_CHAN_GET_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x134, eCMD_C011_DEC_CHAN_SET_REVERSE_FIELD = eCMD_C011_CMD_BASE + 0x135, eCMD_C011_DEC_CHAN_STREAM_OPEN = eCMD_C011_CMD_BASE + 0x136, eCMD_C011_DEC_CHAN_SET_PCR_PID = eCMD_C011_CMD_BASE + 0x137, @@ -328,19 +332,22 @@ enum c011_ts_cmd { eCMD_C011_DEC_CHAN_GET_DISPLAY_ORDER = eCMD_C011_CMD_BASE + 0x143, eCMD_C011_DEC_CHAN_SET_HOST_TRICK_MODE = eCMD_C011_CMD_BASE + 0x144, eCMD_C011_DEC_CHAN_SET_OPERATION_MODE = eCMD_C011_CMD_BASE + 0x145, - eCMD_C011_DEC_CHAN_DISPLAY_PAUSE_UNTO_PTS = eCMD_C011_CMD_BASE + 0x146, - eCMD_C011_DEC_CHAN_SET_PTS_STC_DIFF_THRESHOLD = eCMD_C011_CMD_BASE + 0x147, + eCMD_C011_DEC_CHAN_DISPLAY_PAUSE_UNTO_PTS = eCMD_C011_CMD_BASE + 0x146, + eCMD_C011_DEC_CHAN_SET_PTS_STC_DIFF_THRESHOLD = eCMD_C011_CMD_BASE + + 0x147, eCMD_C011_DEC_CHAN_SEND_COMPRESSED_BUF = eCMD_C011_CMD_BASE + 0x148, eCMD_C011_DEC_CHAN_SET_CLIPPING = eCMD_C011_CMD_BASE + 0x149, eCMD_C011_DEC_CHAN_SET_PARAMETERS_FOR_HARD_RESET_INTERRUPT_TO_HOST = eCMD_C011_CMD_BASE + 0x150, /* Decoder RevD commands */ - eCMD_C011_DEC_CHAN_SET_CSC = eCMD_C011_CMD_BASE + 0x180, /* color space conversion */ + eCMD_C011_DEC_CHAN_SET_CSC = eCMD_C011_CMD_BASE + 0x180, /* color + space conversion */ eCMD_C011_DEC_CHAN_SET_RANGE_REMAP = eCMD_C011_CMD_BASE + 0x181, eCMD_C011_DEC_CHAN_SET_FGT = eCMD_C011_CMD_BASE + 0x182, /* Note: 0x183 not implemented yet in Rev D main */ - eCMD_C011_DEC_CHAN_SET_LASTPICTURE_PADDING = eCMD_C011_CMD_BASE + 0x183, + eCMD_C011_DEC_CHAN_SET_LASTPICTURE_PADDING = eCMD_C011_CMD_BASE + + 0x183, /* Decoder 7412 commands (7412-only) */ eCMD_C011_DEC_CHAN_SET_CONTENT_KEY = eCMD_C011_CMD_BASE + 0x190, diff --git a/drivers/staging/crystalhd/crystalhd_hw.c b/drivers/staging/crystalhd/crystalhd_hw.c index e617d2fcbb1f..0c8cb329420f 100644 --- a/drivers/staging/crystalhd/crystalhd_hw.c +++ b/drivers/staging/crystalhd/crystalhd_hw.c @@ -94,15 +94,19 @@ static bool crystalhd_bring_out_of_rst(struct crystalhd_adp *adp) * Enable clocks while 7412 reset is asserted, delay * De-assert 7412 reset */ - rst_deco_cntrl.whole_reg = crystalhd_reg_rd(adp, MISC_PERST_DECODER_CTRL); + rst_deco_cntrl.whole_reg = crystalhd_reg_rd(adp, + MISC_PERST_DECODER_CTRL); rst_deco_cntrl.stop_bcm_7412_clk = 0; rst_deco_cntrl.bcm7412_rst = 1; - crystalhd_reg_wr(adp, MISC_PERST_DECODER_CTRL, rst_deco_cntrl.whole_reg); + crystalhd_reg_wr(adp, MISC_PERST_DECODER_CTRL, + rst_deco_cntrl.whole_reg); msleep_interruptible(10); - rst_deco_cntrl.whole_reg = crystalhd_reg_rd(adp, MISC_PERST_DECODER_CTRL); + rst_deco_cntrl.whole_reg = crystalhd_reg_rd(adp, + MISC_PERST_DECODER_CTRL); rst_deco_cntrl.bcm7412_rst = 0; - crystalhd_reg_wr(adp, MISC_PERST_DECODER_CTRL, rst_deco_cntrl.whole_reg); + crystalhd_reg_wr(adp, MISC_PERST_DECODER_CTRL, + rst_deco_cntrl.whole_reg); msleep_interruptible(50); /* Disable OTP_CONTENT_MISC to 0 to disable all secure modes */ @@ -132,9 +136,11 @@ static bool crystalhd_put_in_reset(struct crystalhd_adp *adp) * Assert 7412 reset, delay * Assert 7412 stop clock */ - rst_deco_cntrl.whole_reg = crystalhd_reg_rd(adp, MISC_PERST_DECODER_CTRL); + rst_deco_cntrl.whole_reg = crystalhd_reg_rd(adp, + MISC_PERST_DECODER_CTRL); rst_deco_cntrl.stop_bcm_7412_clk = 1; - crystalhd_reg_wr(adp, MISC_PERST_DECODER_CTRL, rst_deco_cntrl.whole_reg); + crystalhd_reg_wr(adp, MISC_PERST_DECODER_CTRL, + rst_deco_cntrl.whole_reg); msleep_interruptible(50); /* Bus Arbiter Timeout: GISB_ARBITER_TIMER @@ -213,7 +219,8 @@ static void crystalhd_clear_errors(struct crystalhd_adp *adp) { uint32_t reg; - /* FIXME: jarod: wouldn't we want to write a 0 to the reg? Or does the write clear the bits specified? */ + /* FIXME: jarod: wouldn't we want to write a 0 to the reg? + Or does the write clear the bits specified? */ reg = crystalhd_reg_rd(adp, MISC1_Y_RX_ERROR_STATUS); if (reg) crystalhd_reg_wr(adp, MISC1_Y_RX_ERROR_STATUS, reg); @@ -263,10 +270,12 @@ static bool crystalhd_load_firmware_config(struct crystalhd_adp *adp) crystalhd_reg_wr(adp, DCI_DRAM_BASE_ADDR, (BC_DRAM_FW_CFG_ADDR >> 19)); crystalhd_reg_wr(adp, AES_CMD, 0); - crystalhd_reg_wr(adp, AES_CONFIG_INFO, (BC_DRAM_FW_CFG_ADDR & 0x7FFFF)); + crystalhd_reg_wr(adp, AES_CONFIG_INFO, + (BC_DRAM_FW_CFG_ADDR & 0x7FFFF)); crystalhd_reg_wr(adp, AES_CMD, 0x1); - /* FIXME: jarod: I've seen this fail, and introducing extra delays helps... */ + /* FIXME: jarod: I've seen this fail, + and introducing extra delays helps... */ for (i = 0; i < 100; ++i) { reg = crystalhd_reg_rd(adp, AES_STATUS); if (reg & 0x1) @@ -349,7 +358,8 @@ static bool crystalhd_stop_device(struct crystalhd_adp *adp) return true; } -static struct crystalhd_rx_dma_pkt *crystalhd_hw_alloc_rx_pkt(struct crystalhd_hw *hw) +static struct crystalhd_rx_dma_pkt *crystalhd_hw_alloc_rx_pkt( + struct crystalhd_hw *hw) { unsigned long flags = 0; struct crystalhd_rx_dma_pkt *temp = NULL; @@ -484,8 +494,8 @@ hw_create_ioq_err: } -static bool crystalhd_code_in_full(struct crystalhd_adp *adp, uint32_t needed_sz, - bool b_188_byte_pkts, uint8_t flags) +static bool crystalhd_code_in_full(struct crystalhd_adp *adp, + uint32_t needed_sz, bool b_188_byte_pkts, uint8_t flags) { uint32_t base, end, writep, readp; uint32_t cpbSize, cpbFullness, fifoSize; @@ -525,7 +535,7 @@ static bool crystalhd_code_in_full(struct crystalhd_adp *adp, uint32_t needed_sz } static enum BC_STATUS crystalhd_hw_tx_req_complete(struct crystalhd_hw *hw, - uint32_t list_id, enum BC_STATUS cs) + uint32_t list_id, enum BC_STATUS cs) { struct tx_dma_pkt *tx_req; @@ -536,7 +546,8 @@ static enum BC_STATUS crystalhd_hw_tx_req_complete(struct crystalhd_hw *hw, hw->pwr_lock--; - tx_req = (struct tx_dma_pkt *)crystalhd_dioq_find_and_fetch(hw->tx_actq, list_id); + tx_req = (struct tx_dma_pkt *)crystalhd_dioq_find_and_fetch( + hw->tx_actq, list_id); if (!tx_req) { if (cs != BC_STS_IO_USER_ABORT) BCMLOG_ERR("Find and Fetch Did not find req\n"); @@ -559,7 +570,8 @@ static enum BC_STATUS crystalhd_hw_tx_req_complete(struct crystalhd_hw *hw, return crystalhd_dioq_add(hw->tx_freeq, tx_req, false, 0); } -static bool crystalhd_tx_list0_handler(struct crystalhd_hw *hw, uint32_t err_sts) +static bool crystalhd_tx_list0_handler(struct crystalhd_hw *hw, + uint32_t err_sts) { uint32_t err_mask, tmp; unsigned long flags = 0; @@ -591,7 +603,8 @@ static bool crystalhd_tx_list0_handler(struct crystalhd_hw *hw, uint32_t err_sts return true; } -static bool crystalhd_tx_list1_handler(struct crystalhd_hw *hw, uint32_t err_sts) +static bool crystalhd_tx_list1_handler(struct crystalhd_hw *hw, + uint32_t err_sts) { uint32_t err_mask, tmp; unsigned long flags = 0; @@ -663,14 +676,15 @@ static void crystalhd_hw_dump_desc(struct dma_descriptor *p_dma_desc, if (!p_dma_desc || !cnt) return; - /* FIXME: jarod: perhaps a modparam desc_debug to enable this, rather than - * setting ll (log level, I presume) to non-zero? */ + /* FIXME: jarod: perhaps a modparam desc_debug to enable this, + rather than setting ll (log level, I presume) to non-zero? */ if (!ll) return; for (ix = ul_desc_index; ix < (ul_desc_index + cnt); ix++) { - BCMLOG(ll, "%s[%d] Buff[%x:%x] Next:[%x:%x] XferSz:%x Intr:%x,Last:%x\n", - ((p_dma_desc[ul_desc_index].dma_dir) ? "TDesc" : "RDesc"), + BCMLOG(ll, + "%s[%d] Buff[%x:%x] Next:[%x:%x] XferSz:%x Intr:%x,Last:%x\n", + ((p_dma_desc[ul_desc_index].dma_dir) ? "TDesc" : "RDesc"), ul_desc_index, p_dma_desc[ul_desc_index].buff_addr_high, p_dma_desc[ul_desc_index].buff_addr_low, @@ -707,7 +721,8 @@ static enum BC_STATUS crystalhd_hw_fill_desc(struct crystalhd_dio_req *ioreq, /* Get SGLE length */ len = crystalhd_get_sgle_len(ioreq, sg_ix); if (len % 4) { - BCMLOG_ERR(" len in sg %d %d %d\n", len, sg_ix, sg_cnt); + BCMLOG_ERR(" len in sg %d %d %d\n", len, sg_ix, + sg_cnt); return BC_STS_NOT_IMPL; } /* Setup DMA desc with Phy addr & Length at current index. */ @@ -722,7 +737,8 @@ static enum BC_STATUS crystalhd_hw_fill_desc(struct crystalhd_dio_req *ioreq, desc[ix].dma_dir = ioreq->uinfo.dir_tx; /* Chain DMA descriptor. */ - addr_temp.full_addr = desc_phy_addr + sizeof(struct dma_descriptor); + addr_temp.full_addr = desc_phy_addr + + sizeof(struct dma_descriptor); desc[ix].next_desc_addr_low = addr_temp.low_part; desc[ix].next_desc_addr_high = addr_temp.high_part; @@ -731,8 +747,9 @@ static enum BC_STATUS crystalhd_hw_fill_desc(struct crystalhd_dio_req *ioreq, /* Debug.. */ if ((!len) || (len > crystalhd_get_sgle_len(ioreq, sg_ix))) { - BCMLOG_ERR("inv-len(%x) Ix(%d) count:%x xfr_sz:%x sg_cnt:%d\n", - len, ix, count, xfr_sz, sg_cnt); + BCMLOG_ERR( + "inv-len(%x) Ix(%d) count:%x xfr_sz:%x sg_cnt:%d\n", + len, ix, count, xfr_sz, sg_cnt); return BC_STS_ERROR; } /* Length expects Multiple of 4 */ @@ -774,7 +791,8 @@ static enum BC_STATUS crystalhd_hw_fill_desc(struct crystalhd_dio_req *ioreq, return BC_STS_SUCCESS; } -static enum BC_STATUS crystalhd_xlat_sgl_to_dma_desc(struct crystalhd_dio_req *ioreq, +static enum BC_STATUS crystalhd_xlat_sgl_to_dma_desc( + struct crystalhd_dio_req *ioreq, struct dma_desc_mem *pdesc_mem, uint32_t *uv_desc_index) { @@ -887,12 +905,14 @@ static enum BC_STATUS crystalhd_stop_tx_dma_engine(struct crystalhd_hw *hw) while ((l1 || l2) && cnt) { if (l1) { - l1 = crystalhd_reg_rd(hw->adp, MISC1_TX_FIRST_DESC_L_ADDR_LIST0); + l1 = crystalhd_reg_rd(hw->adp, + MISC1_TX_FIRST_DESC_L_ADDR_LIST0); l1 &= DMA_START_BIT; } if (l2) { - l2 = crystalhd_reg_rd(hw->adp, MISC1_TX_FIRST_DESC_L_ADDR_LIST1); + l2 = crystalhd_reg_rd(hw->adp, + MISC1_TX_FIRST_DESC_L_ADDR_LIST1); l2 &= DMA_START_BIT; } @@ -986,7 +1006,8 @@ static uint32_t crystalhd_get_addr_from_pib_Q(struct crystalhd_hw *hw) return addr_entry; } -static bool crystalhd_rel_addr_to_pib_Q(struct crystalhd_hw *hw, uint32_t addr_to_rel) +static bool crystalhd_rel_addr_to_pib_Q(struct crystalhd_hw *hw, + uint32_t addr_to_rel) { uint32_t Q_addr; uint32_t r_offset, w_offset, n_offset; @@ -1021,7 +1042,8 @@ static bool crystalhd_rel_addr_to_pib_Q(struct crystalhd_hw *hw, uint32_t addr_t return true; } -static void cpy_pib_to_app(struct c011_pib *src_pib, struct BC_PIC_INFO_BLOCK *dst_pib) +static void cpy_pib_to_app(struct c011_pib *src_pib, + struct BC_PIC_INFO_BLOCK *dst_pib) { if (!src_pib || !dst_pib) { BCMLOG_ERR("Invalid Arguments\n"); @@ -1063,11 +1085,13 @@ static void crystalhd_hw_proc_pib(struct crystalhd_hw *hw) (uint32_t *)&src_pib); if (src_pib.bFormatChange) { - rx_pkt = (struct crystalhd_rx_dma_pkt *)crystalhd_dioq_fetch(hw->rx_freeq); + rx_pkt = (struct crystalhd_rx_dma_pkt *) + crystalhd_dioq_fetch(hw->rx_freeq); if (!rx_pkt) return; rx_pkt->flags = 0; - rx_pkt->flags |= COMP_FLAG_PIB_VALID | COMP_FLAG_FMT_CHANGE; + rx_pkt->flags |= COMP_FLAG_PIB_VALID | + COMP_FLAG_FMT_CHANGE; AppPib = &rx_pkt->pib; cpy_pib_to_app(&src_pib, AppPib); @@ -1084,7 +1108,8 @@ static void crystalhd_hw_proc_pib(struct crystalhd_hw *hw) rx_pkt->pib.pulldown, rx_pkt->pib.ycom); - crystalhd_dioq_add(hw->rx_rdyq, (void *)rx_pkt, true, rx_pkt->pkt_tag); + crystalhd_dioq_add(hw->rx_rdyq, (void *)rx_pkt, true, + rx_pkt->pkt_tag); } @@ -1096,16 +1121,20 @@ static void crystalhd_start_rx_dma_engine(struct crystalhd_hw *hw) { uint32_t dma_cntrl; - dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS); + dma_cntrl = crystalhd_reg_rd(hw->adp, + MISC1_Y_RX_SW_DESC_LIST_CTRL_STS); if (!(dma_cntrl & DMA_START_BIT)) { dma_cntrl |= DMA_START_BIT; - crystalhd_reg_wr(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); + crystalhd_reg_wr(hw->adp, + MISC1_Y_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); } - dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS); + dma_cntrl = crystalhd_reg_rd(hw->adp, + MISC1_UV_RX_SW_DESC_LIST_CTRL_STS); if (!(dma_cntrl & DMA_START_BIT)) { dma_cntrl |= DMA_START_BIT; - crystalhd_reg_wr(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); + crystalhd_reg_wr(hw->adp, + MISC1_UV_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); } return; @@ -1116,44 +1145,52 @@ static void crystalhd_stop_rx_dma_engine(struct crystalhd_hw *hw) uint32_t dma_cntrl = 0, count = 30; uint32_t l0y = 1, l0uv = 1, l1y = 1, l1uv = 1; - dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS); + dma_cntrl = crystalhd_reg_rd(hw->adp, + MISC1_Y_RX_SW_DESC_LIST_CTRL_STS); if ((dma_cntrl & DMA_START_BIT)) { dma_cntrl &= ~DMA_START_BIT; - crystalhd_reg_wr(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); + crystalhd_reg_wr(hw->adp, + MISC1_Y_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); } - dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS); + dma_cntrl = crystalhd_reg_rd(hw->adp, + MISC1_UV_RX_SW_DESC_LIST_CTRL_STS); if ((dma_cntrl & DMA_START_BIT)) { dma_cntrl &= ~DMA_START_BIT; - crystalhd_reg_wr(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); + crystalhd_reg_wr(hw->adp, + MISC1_UV_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); } /* Poll for 3seconds (30 * 100ms) on both the lists..*/ while ((l0y || l0uv || l1y || l1uv) && count) { if (l0y) { - l0y = crystalhd_reg_rd(hw->adp, MISC1_Y_RX_FIRST_DESC_L_ADDR_LIST0); + l0y = crystalhd_reg_rd(hw->adp, + MISC1_Y_RX_FIRST_DESC_L_ADDR_LIST0); l0y &= DMA_START_BIT; if (!l0y) hw->rx_list_sts[0] &= ~rx_waiting_y_intr; } if (l1y) { - l1y = crystalhd_reg_rd(hw->adp, MISC1_Y_RX_FIRST_DESC_L_ADDR_LIST1); + l1y = crystalhd_reg_rd(hw->adp, + MISC1_Y_RX_FIRST_DESC_L_ADDR_LIST1); l1y &= DMA_START_BIT; if (!l1y) hw->rx_list_sts[1] &= ~rx_waiting_y_intr; } if (l0uv) { - l0uv = crystalhd_reg_rd(hw->adp, MISC1_UV_RX_FIRST_DESC_L_ADDR_LIST0); + l0uv = crystalhd_reg_rd(hw->adp, + MISC1_UV_RX_FIRST_DESC_L_ADDR_LIST0); l0uv &= DMA_START_BIT; if (!l0uv) hw->rx_list_sts[0] &= ~rx_waiting_uv_intr; } if (l1uv) { - l1uv = crystalhd_reg_rd(hw->adp, MISC1_UV_RX_FIRST_DESC_L_ADDR_LIST1); + l1uv = crystalhd_reg_rd(hw->adp, + MISC1_UV_RX_FIRST_DESC_L_ADDR_LIST1); l1uv &= DMA_START_BIT; if (!l1uv) hw->rx_list_sts[1] &= ~rx_waiting_uv_intr; @@ -1168,7 +1205,8 @@ static void crystalhd_stop_rx_dma_engine(struct crystalhd_hw *hw) count, hw->rx_list_sts[0], hw->rx_list_sts[1]); } -static enum BC_STATUS crystalhd_hw_prog_rxdma(struct crystalhd_hw *hw, struct crystalhd_rx_dma_pkt *rx_pkt) +static enum BC_STATUS crystalhd_hw_prog_rxdma(struct crystalhd_hw *hw, + struct crystalhd_rx_dma_pkt *rx_pkt) { uint32_t y_low_addr_reg, y_high_addr_reg; uint32_t uv_low_addr_reg, uv_high_addr_reg; @@ -1186,7 +1224,8 @@ static enum BC_STATUS crystalhd_hw_prog_rxdma(struct crystalhd_hw *hw, struct cr } spin_lock_irqsave(&hw->rx_lock, flags); - /* FIXME: jarod: sts_free is an enum for 0, in crystalhd_hw.h... yuk... */ + /* FIXME: jarod: sts_free is an enum for 0, + in crystalhd_hw.h... yuk... */ if (sts_free != hw->rx_list_sts[hw->rx_list_post_index]) { spin_unlock_irqrestore(&hw->rx_lock, flags); return BC_STS_BUSY; @@ -1210,7 +1249,8 @@ static enum BC_STATUS crystalhd_hw_prog_rxdma(struct crystalhd_hw *hw, struct cr hw->rx_list_post_index = (hw->rx_list_post_index + 1) % DMA_ENGINE_CNT; spin_unlock_irqrestore(&hw->rx_lock, flags); - crystalhd_dioq_add(hw->rx_actq, (void *)rx_pkt, false, rx_pkt->pkt_tag); + crystalhd_dioq_add(hw->rx_actq, (void *)rx_pkt, false, + rx_pkt->pkt_tag); crystalhd_start_rx_dma_engine(hw); /* Program the Y descriptor */ @@ -1221,8 +1261,10 @@ static enum BC_STATUS crystalhd_hw_prog_rxdma(struct crystalhd_hw *hw, struct cr if (rx_pkt->uv_phy_addr) { /* Program the UV descriptor */ desc_addr.full_addr = rx_pkt->uv_phy_addr; - crystalhd_reg_wr(hw->adp, uv_high_addr_reg, desc_addr.high_part); - crystalhd_reg_wr(hw->adp, uv_low_addr_reg, desc_addr.low_part | 0x01); + crystalhd_reg_wr(hw->adp, uv_high_addr_reg, + desc_addr.high_part); + crystalhd_reg_wr(hw->adp, uv_low_addr_reg, + desc_addr.low_part | 0x01); } return BC_STS_SUCCESS; @@ -1268,16 +1310,20 @@ static void crystalhd_hw_finalize_pause(struct crystalhd_hw *hw) hw->stop_pending = 0; - dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS); + dma_cntrl = crystalhd_reg_rd(hw->adp, + MISC1_Y_RX_SW_DESC_LIST_CTRL_STS); if (dma_cntrl & DMA_START_BIT) { dma_cntrl &= ~DMA_START_BIT; - crystalhd_reg_wr(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); + crystalhd_reg_wr(hw->adp, + MISC1_Y_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); } - dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS); + dma_cntrl = crystalhd_reg_rd(hw->adp, + MISC1_UV_RX_SW_DESC_LIST_CTRL_STS); if (dma_cntrl & DMA_START_BIT) { dma_cntrl &= ~DMA_START_BIT; - crystalhd_reg_wr(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); + crystalhd_reg_wr(hw->adp, + MISC1_UV_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); } hw->rx_list_post_index = 0; @@ -1287,8 +1333,8 @@ static void crystalhd_hw_finalize_pause(struct crystalhd_hw *hw) crystalhd_reg_wr(hw->adp, PCIE_DLL_DATA_LINK_CONTROL, aspm); } -static enum BC_STATUS crystalhd_rx_pkt_done(struct crystalhd_hw *hw, uint32_t list_index, - enum BC_STATUS comp_sts) +static enum BC_STATUS crystalhd_rx_pkt_done(struct crystalhd_hw *hw, + uint32_t list_index, enum BC_STATUS comp_sts) { struct crystalhd_rx_dma_pkt *rx_pkt = NULL; uint32_t y_dw_dnsz, uv_dw_dnsz; @@ -1302,7 +1348,8 @@ static enum BC_STATUS crystalhd_rx_pkt_done(struct crystalhd_hw *hw, uint32_t li rx_pkt = crystalhd_dioq_find_and_fetch(hw->rx_actq, hw->rx_pkt_tag_seed + list_index); if (!rx_pkt) { - BCMLOG_ERR("Act-Q:PostIx:%x L0Sts:%x L1Sts:%x current L:%x tag:%x comp:%x\n", + BCMLOG_ERR( + "Act-Q:PostIx:%x L0Sts:%x L1Sts:%x current L:%x tag:%x comp:%x\n", hw->rx_list_post_index, hw->rx_list_sts[0], hw->rx_list_sts[1], list_index, hw->rx_pkt_tag_seed + list_index, comp_sts); @@ -1324,8 +1371,8 @@ static enum BC_STATUS crystalhd_rx_pkt_done(struct crystalhd_hw *hw, uint32_t li return crystalhd_hw_post_cap_buff(hw, rx_pkt); } -static bool crystalhd_rx_list0_handler(struct crystalhd_hw *hw, uint32_t int_sts, - uint32_t y_err_sts, uint32_t uv_err_sts) +static bool crystalhd_rx_list0_handler(struct crystalhd_hw *hw, + uint32_t int_sts, uint32_t y_err_sts, uint32_t uv_err_sts) { uint32_t tmp; enum list_sts tmp_lsts; @@ -1367,7 +1414,8 @@ static bool crystalhd_rx_list0_handler(struct crystalhd_hw *hw, uint32_t int_sts tmp &= ~MISC1_UV_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK; } - if (uv_err_sts & MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK) { + if (uv_err_sts & + MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK) { hw->rx_list_sts[0] &= ~rx_uv_mask; hw->rx_list_sts[0] |= rx_uv_error; tmp &= ~MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK; @@ -1392,8 +1440,8 @@ static bool crystalhd_rx_list0_handler(struct crystalhd_hw *hw, uint32_t int_sts return (tmp_lsts != hw->rx_list_sts[0]); } -static bool crystalhd_rx_list1_handler(struct crystalhd_hw *hw, uint32_t int_sts, - uint32_t y_err_sts, uint32_t uv_err_sts) +static bool crystalhd_rx_list1_handler(struct crystalhd_hw *hw, + uint32_t int_sts, uint32_t y_err_sts, uint32_t uv_err_sts) { uint32_t tmp; enum list_sts tmp_lsts; @@ -1486,9 +1534,11 @@ static void crystalhd_rx_isr(struct crystalhd_hw *hw, uint32_t intr_sts) /* Update States..*/ spin_lock_irqsave(&hw->rx_lock, flags); if (i == 0) - ret = crystalhd_rx_list0_handler(hw, intr_sts, y_err_sts, uv_err_sts); + ret = crystalhd_rx_list0_handler(hw, intr_sts, + y_err_sts, uv_err_sts); else - ret = crystalhd_rx_list1_handler(hw, intr_sts, y_err_sts, uv_err_sts); + ret = crystalhd_rx_list1_handler(hw, intr_sts, + y_err_sts, uv_err_sts); if (ret) { switch (hw->rx_list_sts[i]) { case sts_free: @@ -1501,11 +1551,13 @@ static void crystalhd_rx_isr(struct crystalhd_hw *hw, uint32_t intr_sts) /* We got error on both or Y or uv. */ hw->stats.rx_errors++; crystalhd_get_dnsz(hw, i, &y_dn_sz, &uv_dn_sz); - /* FIXME: jarod: this is where my mini pci-e card is tripping up */ + /* FIXME: jarod: this is where + my mini pci-e card is tripping up */ BCMLOG(BCMLOG_DBG, "list_index:%x rx[%d] Y:%x " "UV:%x Int:%x YDnSz:%x UVDnSz:%x\n", i, hw->stats.rx_errors, y_err_sts, - uv_err_sts, intr_sts, y_dn_sz, uv_dn_sz); + uv_err_sts, intr_sts, y_dn_sz, + uv_dn_sz); hw->rx_list_sts[i] = sts_free; comp_sts = BC_STS_ERROR; break; @@ -1567,14 +1619,17 @@ static enum BC_STATUS crystalhd_put_ddr2sleep(struct crystalhd_hw *hw) union link_misc_perst_decoder_ctrl rst_cntrl_reg; /* Pulse reset pin of 7412 (MISC_PERST_DECODER_CTRL) */ - rst_cntrl_reg.whole_reg = crystalhd_reg_rd(hw->adp, MISC_PERST_DECODER_CTRL); + rst_cntrl_reg.whole_reg = crystalhd_reg_rd(hw->adp, + MISC_PERST_DECODER_CTRL); rst_cntrl_reg.bcm_7412_rst = 1; - crystalhd_reg_wr(hw->adp, MISC_PERST_DECODER_CTRL, rst_cntrl_reg.whole_reg); + crystalhd_reg_wr(hw->adp, MISC_PERST_DECODER_CTRL, + rst_cntrl_reg.whole_reg); msleep_interruptible(50); rst_cntrl_reg.bcm_7412_rst = 0; - crystalhd_reg_wr(hw->adp, MISC_PERST_DECODER_CTRL, rst_cntrl_reg.whole_reg); + crystalhd_reg_wr(hw->adp, MISC_PERST_DECODER_CTRL, + rst_cntrl_reg.whole_reg); /* Close all banks, put DDR in idle */ bc_dec_reg_wr(hw->adp, SDRAM_PRECHARGE, 0); @@ -1622,7 +1677,8 @@ static enum BC_STATUS crystalhd_put_ddr2sleep(struct crystalhd_hw *hw) ** *************************************************/ -enum BC_STATUS crystalhd_download_fw(struct crystalhd_adp *adp, void *buffer, uint32_t sz) +enum BC_STATUS crystalhd_download_fw(struct crystalhd_adp *adp, void *buffer, + uint32_t sz) { uint32_t reg_data, cnt, *temp_buff; uint32_t fw_sig_len = 36; @@ -1828,7 +1884,8 @@ bool crystalhd_hw_interrupt(struct crystalhd_adp *adp, struct crystalhd_hw *hw) crystalhd_hw_proc_pib(hw); bc_dec_reg_wr(adp, Stream2Host_Intr_Sts, deco_intr); - /* FIXME: jarod: No udelay? might this be the real reason mini pci-e cards were stalling out? */ + /* FIXME: jarod: No udelay? might this be + the real reason mini pci-e cards were stalling out? */ bc_dec_reg_wr(adp, Stream2Host_Intr_Sts, 0); rc = 1; } @@ -1852,7 +1909,8 @@ bool crystalhd_hw_interrupt(struct crystalhd_adp *adp, struct crystalhd_hw *hw) return rc; } -enum BC_STATUS crystalhd_hw_open(struct crystalhd_hw *hw, struct crystalhd_adp *adp) +enum BC_STATUS crystalhd_hw_open(struct crystalhd_hw *hw, + struct crystalhd_adp *adp) { if (!hw || !adp) { BCMLOG_ERR("Invalid Arguments\n"); @@ -1967,7 +2025,8 @@ enum BC_STATUS crystalhd_hw_setup_dma_rings(struct crystalhd_hw *hw) } rpkt->desc_mem.pdma_desc_start = mem; rpkt->desc_mem.phy_addr = phy_addr; - rpkt->desc_mem.sz = BC_LINK_MAX_SGLS * sizeof(struct dma_descriptor); + rpkt->desc_mem.sz = BC_LINK_MAX_SGLS * + sizeof(struct dma_descriptor); rpkt->pkt_tag = hw->rx_pkt_tag_seed + i; crystalhd_hw_free_rx_pkt(hw, rpkt); } @@ -2013,7 +2072,8 @@ enum BC_STATUS crystalhd_hw_free_dma_rings(struct crystalhd_hw *hw) return BC_STS_SUCCESS; } -enum BC_STATUS crystalhd_hw_post_tx(struct crystalhd_hw *hw, struct crystalhd_dio_req *ioreq, +enum BC_STATUS crystalhd_hw_post_tx(struct crystalhd_hw *hw, + struct crystalhd_dio_req *ioreq, hw_comp_callback call_back, wait_queue_head_t *cb_event, uint32_t *list_id, uint8_t data_flags) @@ -2047,7 +2107,8 @@ enum BC_STATUS crystalhd_hw_post_tx(struct crystalhd_hw *hw, struct crystalhd_di } /* Get a list from TxFreeQ */ - tx_dma_packet = (struct tx_dma_pkt *)crystalhd_dioq_fetch(hw->tx_freeq); + tx_dma_packet = (struct tx_dma_pkt *)crystalhd_dioq_fetch( + hw->tx_freeq); if (!tx_dma_packet) { BCMLOG_ERR("No empty elements..\n"); return BC_STS_ERR_USAGE; @@ -2105,7 +2166,8 @@ enum BC_STATUS crystalhd_hw_post_tx(struct crystalhd_hw *hw, struct crystalhd_di crystalhd_start_tx_dma_engine(hw); crystalhd_reg_wr(hw->adp, first_desc_u_addr, desc_addr.high_part); - crystalhd_reg_wr(hw->adp, first_desc_l_addr, desc_addr.low_part | 0x01); + crystalhd_reg_wr(hw->adp, first_desc_l_addr, desc_addr.low_part | + 0x01); /* Be sure we set the valid bit ^^^^ */ return BC_STS_SUCCESS; @@ -2120,7 +2182,8 @@ enum BC_STATUS crystalhd_hw_post_tx(struct crystalhd_hw *hw, struct crystalhd_di * * FIX_ME: Not Tested the actual condition.. */ -enum BC_STATUS crystalhd_hw_cancel_tx(struct crystalhd_hw *hw, uint32_t list_id) +enum BC_STATUS crystalhd_hw_cancel_tx(struct crystalhd_hw *hw, + uint32_t list_id) { if (!hw || !list_id) { BCMLOG_ERR("Invalid Arguments\n"); @@ -2134,7 +2197,7 @@ enum BC_STATUS crystalhd_hw_cancel_tx(struct crystalhd_hw *hw, uint32_t list_id) } enum BC_STATUS crystalhd_hw_add_cap_buffer(struct crystalhd_hw *hw, - struct crystalhd_dio_req *ioreq, bool en_post) + struct crystalhd_dio_req *ioreq, bool en_post) { struct crystalhd_rx_dma_pkt *rpkt; uint32_t tag, uv_desc_ix = 0; @@ -2154,7 +2217,8 @@ enum BC_STATUS crystalhd_hw_add_cap_buffer(struct crystalhd_hw *hw, rpkt->dio_req = ioreq; tag = rpkt->pkt_tag; - sts = crystalhd_xlat_sgl_to_dma_desc(ioreq, &rpkt->desc_mem, &uv_desc_ix); + sts = crystalhd_xlat_sgl_to_dma_desc(ioreq, &rpkt->desc_mem, + &uv_desc_ix); if (sts != BC_STS_SUCCESS) return sts; @@ -2163,7 +2227,7 @@ enum BC_STATUS crystalhd_hw_add_cap_buffer(struct crystalhd_hw *hw, /* Store the address of UV in the rx packet for post*/ if (uv_desc_ix) rpkt->uv_phy_addr = rpkt->desc_mem.phy_addr + - (sizeof(struct dma_descriptor) * (uv_desc_ix + 1)); + (sizeof(struct dma_descriptor) * (uv_desc_ix + 1)); if (en_post) sts = crystalhd_hw_post_cap_buff(hw, rpkt); @@ -2190,7 +2254,8 @@ enum BC_STATUS crystalhd_hw_get_cap_buffer(struct crystalhd_hw *hw, rpkt = crystalhd_dioq_fetch_wait(hw->rx_rdyq, timeout, &sig_pending); if (!rpkt) { if (sig_pending) { - BCMLOG(BCMLOG_INFO, "wait on frame time out %d\n", sig_pending); + BCMLOG(BCMLOG_INFO, "wait on frame time out %d\n", + sig_pending); return BC_STS_IO_USER_ABORT; } else { return BC_STS_TIMEOUT; @@ -2305,7 +2370,8 @@ enum BC_STATUS crystalhd_hw_suspend(struct crystalhd_hw *hw) return BC_STS_SUCCESS; } -void crystalhd_hw_stats(struct crystalhd_hw *hw, struct crystalhd_hw_stats *stats) +void crystalhd_hw_stats(struct crystalhd_hw *hw, + struct crystalhd_hw_stats *stats) { if (!hw) { BCMLOG_ERR("Invalid Arguments\n"); @@ -2378,7 +2444,8 @@ enum BC_STATUS crystalhd_hw_set_core_clock(struct crystalhd_hw *hw) if (reg & 0x00020000) { hw->prev_n = n; - /* FIXME: jarod: outputting a random "C" is... confusing... */ + /* FIXME: jarod: outputting + a random "C" is... confusing... */ BCMLOG(BCMLOG_INFO, "C"); return BC_STS_SUCCESS; } else { diff --git a/drivers/staging/crystalhd/crystalhd_hw.h b/drivers/staging/crystalhd/crystalhd_hw.h index 2d0e6c6005e5..37809442c553 100644 --- a/drivers/staging/crystalhd/crystalhd_hw.h +++ b/drivers/staging/crystalhd/crystalhd_hw.h @@ -46,7 +46,7 @@ #define Cpu2HstMbx1 0x00100F04 #define MbxStat1 0x00100F08 #define Stream2Host_Intr_Sts 0x00100F24 -#define C011_RET_SUCCESS 0x0 /* Reutrn status of firmware command. */ +#define C011_RET_SUCCESS 0x0 /* Reutrn status of firmware command. */ /* TS input status register */ #define TS_StreamAFIFOStatus 0x0010044C @@ -103,7 +103,7 @@ #define BC_FWIMG_ST_ADDR 0x00000000 /* FIXME: jarod: there's a kernel function that'll do this for us... */ #define rotr32_1(x, n) (((x) >> n) | ((x) << (32 - n))) -#define bswap_32_1(x) ((rotr32_1((x), 24) & 0x00ff00ff) | (rotr32_1((x), 8) & 0xff00ff00)) +#define bswap_32_1(x) ((rotr32_1((x), 24) & 0x00ff00ff) | (rotr32_1((x), 8) & 0xff00ff00)) #define DecHt_HostSwReset 0x340000 #define BC_DRAM_FW_CFG_ADDR 0x001c2000 @@ -136,9 +136,11 @@ union intr_mask_reg { union link_misc_perst_deco_ctrl { struct { - uint32_t bcm7412_rst:1; /* 1 -> BCM7412 is held in reset. Reset value 1.*/ + uint32_t bcm7412_rst:1; /* 1 -> BCM7412 is held + in reset. Reset value 1.*/ uint32_t reserved0:3; /* Reserved.No Effect*/ - uint32_t stop_bcm_7412_clk:1; /* 1 ->Stops branch of 27MHz clk used to clk BCM7412*/ + uint32_t stop_bcm_7412_clk:1; /* 1 ->Stops branch of + 27MHz clk used to clk BCM7412*/ uint32_t reserved1:27; /* Reseved. No Effect*/ }; @@ -148,13 +150,18 @@ union link_misc_perst_deco_ctrl { union link_misc_perst_clk_ctrl { struct { - uint32_t sel_alt_clk:1; /* When set, selects a 6.75MHz clock as the source of core_clk */ - uint32_t stop_core_clk:1; /* When set, stops the branch of core_clk that is not needed for low power operation */ - uint32_t pll_pwr_dn:1; /* When set, powers down the main PLL. The alternate clock bit should be set - to select an alternate clock before setting this bit.*/ + uint32_t sel_alt_clk:1; /* When set, selects a + 6.75MHz clock as the source of core_clk */ + uint32_t stop_core_clk:1; /* When set, stops the branch + of core_clk that is not needed for low power operation */ + uint32_t pll_pwr_dn:1; /* When set, powers down the + main PLL. The alternate clock bit should be set to + select an alternate clock before setting this bit.*/ uint32_t reserved0:5; /* Reserved */ - uint32_t pll_mult:8; /* This setting controls the multiplier for the PLL. */ - uint32_t pll_div:4; /* This setting controls the divider for the PLL. */ + uint32_t pll_mult:8; /* This setting controls + the multiplier for the PLL. */ + uint32_t pll_div:4; /* This setting controls + the divider for the PLL. */ uint32_t reserved1:12; /* Reserved */ }; @@ -164,9 +171,11 @@ union link_misc_perst_clk_ctrl { union link_misc_perst_decoder_ctrl { struct { - uint32_t bcm_7412_rst:1; /* 1 -> BCM7412 is held in reset. Reset value 1.*/ + uint32_t bcm_7412_rst:1; /* 1 -> BCM7412 is held + in reset. Reset value 1.*/ uint32_t res0:3; /* Reserved.No Effect*/ - uint32_t stop_7412_clk:1; /* 1 ->Stops branch of 27MHz clk used to clk BCM7412*/ + uint32_t stop_7412_clk:1; /* 1 ->Stops branch of 27MHz + clk used to clk BCM7412*/ uint32_t res1:27; /* Reseved. No Effect */ }; @@ -225,10 +234,12 @@ struct dma_descriptor { /* 8 32-bit values */ * The virtual address will determine what should be freed. */ struct dma_desc_mem { - struct dma_descriptor *pdma_desc_start; /* 32-bytes for dma descriptor. should be first element */ - dma_addr_t phy_addr; /* physical address of each DMA desc */ + struct dma_descriptor *pdma_desc_start; /* 32-bytes for dma + descriptor. should be first element */ + dma_addr_t phy_addr; /* physical address + of each DMA desc */ uint32_t sz; - struct _dma_desc_mem_ *Next; /* points to Next Descriptor in chain */ + struct _dma_desc_mem_ *Next; /* points to Next Descriptor in chain */ }; @@ -323,50 +334,54 @@ struct crystalhd_hw { #define CLOCK_PRESET 175 /* DMA engine register BIT mask wrappers.. */ -#define DMA_START_BIT MISC1_TX_SW_DESC_LIST_CTRL_STS_TX_DMA_RUN_STOP_MASK +#define DMA_START_BIT MISC1_TX_SW_DESC_LIST_CTRL_STS_TX_DMA_RUN_STOP_MASK -#define GET_RX_INTR_MASK (INTR_INTR_STATUS_L1_UV_RX_DMA_ERR_INTR_MASK | \ - INTR_INTR_STATUS_L1_UV_RX_DMA_DONE_INTR_MASK | \ - INTR_INTR_STATUS_L1_Y_RX_DMA_ERR_INTR_MASK | \ - INTR_INTR_STATUS_L1_Y_RX_DMA_DONE_INTR_MASK | \ - INTR_INTR_STATUS_L0_UV_RX_DMA_ERR_INTR_MASK | \ - INTR_INTR_STATUS_L0_UV_RX_DMA_DONE_INTR_MASK | \ - INTR_INTR_STATUS_L0_Y_RX_DMA_ERR_INTR_MASK | \ - INTR_INTR_STATUS_L0_Y_RX_DMA_DONE_INTR_MASK) +#define GET_RX_INTR_MASK (INTR_INTR_STATUS_L1_UV_RX_DMA_ERR_INTR_MASK | \ + INTR_INTR_STATUS_L1_UV_RX_DMA_DONE_INTR_MASK | \ + INTR_INTR_STATUS_L1_Y_RX_DMA_ERR_INTR_MASK | \ + INTR_INTR_STATUS_L1_Y_RX_DMA_DONE_INTR_MASK | \ + INTR_INTR_STATUS_L0_UV_RX_DMA_ERR_INTR_MASK | \ + INTR_INTR_STATUS_L0_UV_RX_DMA_DONE_INTR_MASK | \ + INTR_INTR_STATUS_L0_Y_RX_DMA_ERR_INTR_MASK | \ + INTR_INTR_STATUS_L0_Y_RX_DMA_DONE_INTR_MASK) -#define GET_Y0_ERR_MSK (MISC1_Y_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_MASK | \ - MISC1_Y_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK | \ - MISC1_Y_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_MASK | \ - MISC1_Y_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK) +#define GET_Y0_ERR_MSK (MISC1_Y_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_MASK | \ + MISC1_Y_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK | \ + MISC1_Y_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_MASK | \ + MISC1_Y_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK) -#define GET_UV0_ERR_MSK (MISC1_UV_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_MASK | \ - MISC1_UV_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK | \ - MISC1_UV_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_MASK | \ - MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK) +#define GET_UV0_ERR_MSK (MISC1_UV_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_MASK | \ + MISC1_UV_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK | \ + MISC1_UV_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_MASK | \ + MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK) -#define GET_Y1_ERR_MSK (MISC1_Y_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_MASK | \ - MISC1_Y_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK | \ - MISC1_Y_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_MASK | \ - MISC1_Y_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK) +#define GET_Y1_ERR_MSK (MISC1_Y_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_MASK | \ + MISC1_Y_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK | \ + MISC1_Y_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_MASK | \ + MISC1_Y_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK) -#define GET_UV1_ERR_MSK (MISC1_UV_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_MASK | \ - MISC1_UV_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK | \ - MISC1_UV_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_MASK | \ - MISC1_UV_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK) +#define GET_UV1_ERR_MSK (MISC1_UV_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_MASK | \ + MISC1_UV_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK | \ + MISC1_UV_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_MASK | \ + MISC1_UV_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK) /**** API Exposed to the other layers ****/ enum BC_STATUS crystalhd_download_fw(struct crystalhd_adp *adp, void *buffer, uint32_t sz); -enum BC_STATUS crystalhd_do_fw_cmd(struct crystalhd_hw *hw, struct BC_FW_CMD *fw_cmd); -bool crystalhd_hw_interrupt(struct crystalhd_adp *adp, struct crystalhd_hw *hw); -enum BC_STATUS crystalhd_hw_open(struct crystalhd_hw *, struct crystalhd_adp *); +enum BC_STATUS crystalhd_do_fw_cmd(struct crystalhd_hw *hw, + struct BC_FW_CMD *fw_cmd); +bool crystalhd_hw_interrupt(struct crystalhd_adp *adp, + struct crystalhd_hw *hw); +enum BC_STATUS crystalhd_hw_open(struct crystalhd_hw *, + struct crystalhd_adp *); enum BC_STATUS crystalhd_hw_close(struct crystalhd_hw *); enum BC_STATUS crystalhd_hw_setup_dma_rings(struct crystalhd_hw *); enum BC_STATUS crystalhd_hw_free_dma_rings(struct crystalhd_hw *); -enum BC_STATUS crystalhd_hw_post_tx(struct crystalhd_hw *hw, struct crystalhd_dio_req *ioreq, +enum BC_STATUS crystalhd_hw_post_tx(struct crystalhd_hw *hw, + struct crystalhd_dio_req *ioreq, hw_comp_callback call_back, wait_queue_head_t *cb_event, uint32_t *list_id, uint8_t data_flags); @@ -374,15 +389,17 @@ enum BC_STATUS crystalhd_hw_post_tx(struct crystalhd_hw *hw, struct crystalhd_di enum BC_STATUS crystalhd_hw_pause(struct crystalhd_hw *hw); enum BC_STATUS crystalhd_hw_unpause(struct crystalhd_hw *hw); enum BC_STATUS crystalhd_hw_suspend(struct crystalhd_hw *hw); -enum BC_STATUS crystalhd_hw_cancel_tx(struct crystalhd_hw *hw, uint32_t list_id); +enum BC_STATUS crystalhd_hw_cancel_tx(struct crystalhd_hw *hw, + uint32_t list_id); enum BC_STATUS crystalhd_hw_add_cap_buffer(struct crystalhd_hw *hw, - struct crystalhd_dio_req *ioreq, bool en_post); + struct crystalhd_dio_req *ioreq, bool en_post); enum BC_STATUS crystalhd_hw_get_cap_buffer(struct crystalhd_hw *hw, struct BC_PIC_INFO_BLOCK *pib, struct crystalhd_dio_req **ioreq); enum BC_STATUS crystalhd_hw_stop_capture(struct crystalhd_hw *hw); enum BC_STATUS crystalhd_hw_start_capture(struct crystalhd_hw *hw); -void crystalhd_hw_stats(struct crystalhd_hw *hw, struct crystalhd_hw_stats *stats); +void crystalhd_hw_stats(struct crystalhd_hw *hw, + struct crystalhd_hw_stats *stats); /* API to program the core clock on the decoder */ enum BC_STATUS crystalhd_hw_set_core_clock(struct crystalhd_hw *); diff --git a/drivers/staging/crystalhd/crystalhd_lnx.c b/drivers/staging/crystalhd/crystalhd_lnx.c index 85f51fb18425..c1f6163cdeb8 100644 --- a/drivers/staging/crystalhd/crystalhd_lnx.c +++ b/drivers/staging/crystalhd/crystalhd_lnx.c @@ -75,7 +75,8 @@ static int chd_dec_disable_int(struct crystalhd_adp *adp) return 0; } -struct crystalhd_ioctl_data *chd_dec_alloc_iodata(struct crystalhd_adp *adp, bool isr) +struct crystalhd_ioctl_data *chd_dec_alloc_iodata(struct crystalhd_adp *adp, + bool isr) { unsigned long flags = 0; struct crystalhd_ioctl_data *temp; @@ -95,8 +96,8 @@ struct crystalhd_ioctl_data *chd_dec_alloc_iodata(struct crystalhd_adp *adp, boo return temp; } -void chd_dec_free_iodata(struct crystalhd_adp *adp, struct crystalhd_ioctl_data *iodata, - bool isr) +void chd_dec_free_iodata(struct crystalhd_adp *adp, + struct crystalhd_ioctl_data *iodata, bool isr) { unsigned long flags = 0; @@ -109,7 +110,8 @@ void chd_dec_free_iodata(struct crystalhd_adp *adp, struct crystalhd_ioctl_data spin_unlock_irqrestore(&adp->lock, flags); } -static inline int crystalhd_user_data(unsigned long ud, void *dr, int size, int set) +static inline int crystalhd_user_data(unsigned long ud, void *dr, + int size, int set) { int rc; @@ -131,8 +133,8 @@ static inline int crystalhd_user_data(unsigned long ud, void *dr, int size, int return rc; } -static int chd_dec_fetch_cdata(struct crystalhd_adp *adp, struct crystalhd_ioctl_data *io, - uint32_t m_sz, unsigned long ua) +static int chd_dec_fetch_cdata(struct crystalhd_adp *adp, + struct crystalhd_ioctl_data *io, uint32_t m_sz, unsigned long ua) { unsigned long ua_off; int rc = 0; @@ -163,7 +165,7 @@ static int chd_dec_fetch_cdata(struct crystalhd_adp *adp, struct crystalhd_ioctl } static int chd_dec_release_cdata(struct crystalhd_adp *adp, - struct crystalhd_ioctl_data *io, unsigned long ua) + struct crystalhd_ioctl_data *io, unsigned long ua) { unsigned long ua_off; int rc; @@ -178,8 +180,9 @@ static int chd_dec_release_cdata(struct crystalhd_adp *adp, rc = crystalhd_user_data(ua_off, io->add_cdata, io->add_cdata_sz, 1); if (rc) { - BCMLOG_ERR("failed to push add_cdata sz:%x ua_off:%x\n", - io->add_cdata_sz, (unsigned int)ua_off); + BCMLOG_ERR( + "failed to push add_cdata sz:%x ua_off:%x\n", + io->add_cdata_sz, (unsigned int)ua_off); return -ENODATA; } } @@ -252,10 +255,7 @@ static int chd_dec_api_cmd(struct crystalhd_adp *adp, unsigned long ua, rc = chd_dec_proc_user_data(adp, temp, ua, 1); } - if (temp) { - chd_dec_free_iodata(adp, temp, 0); - temp = NULL; - } + chd_dec_free_iodata(adp, temp, 0); return rc; } @@ -378,8 +378,8 @@ static int chd_dec_init_chdev(struct crystalhd_adp *adp) goto class_create_fail; } - dev = device_create(crystalhd_class, NULL, MKDEV(adp->chd_dec_major, 0), - NULL, "crystalhd"); + dev = device_create(crystalhd_class, NULL, + MKDEV(adp->chd_dec_major, 0), NULL, "crystalhd"); if (IS_ERR(dev)) { rc = PTR_ERR(dev); BCMLOG_ERR("failed to create device\n"); @@ -394,7 +394,8 @@ static int chd_dec_init_chdev(struct crystalhd_adp *adp) /* Allocate general purpose ioctl pool. */ for (i = 0; i < CHD_IODATA_POOL_SZ; i++) { - temp = kzalloc(sizeof(struct crystalhd_ioctl_data), GFP_KERNEL); + temp = kzalloc(sizeof(struct crystalhd_ioctl_data), + GFP_KERNEL); if (!temp) { BCMLOG_ERR("ioctl data pool kzalloc failed\n"); rc = -ENOMEM; diff --git a/drivers/staging/crystalhd/crystalhd_lnx.h b/drivers/staging/crystalhd/crystalhd_lnx.h index a9e36336d097..bac572a8bc2e 100644 --- a/drivers/staging/crystalhd/crystalhd_lnx.h +++ b/drivers/staging/crystalhd/crystalhd_lnx.h @@ -77,8 +77,8 @@ struct crystalhd_adp { int chd_dec_major; unsigned int cfg_users; - struct crystalhd_ioctl_data *idata_free_head; /* ioctl data pool */ - struct crystalhd_elem *elem_pool_head; /* Queue element pool */ + struct crystalhd_ioctl_data *idata_free_head; /* ioctl data pool */ + struct crystalhd_elem *elem_pool_head; /* Queue element pool */ struct crystalhd_cmd cmds; diff --git a/drivers/staging/crystalhd/crystalhd_misc.c b/drivers/staging/crystalhd/crystalhd_misc.c index a5f109c632dc..51f698052aff 100644 --- a/drivers/staging/crystalhd/crystalhd_misc.c +++ b/drivers/staging/crystalhd/crystalhd_misc.c @@ -30,19 +30,22 @@ uint32_t g_linklog_level; -static inline uint32_t crystalhd_dram_rd(struct crystalhd_adp *adp, uint32_t mem_off) +static inline uint32_t crystalhd_dram_rd(struct crystalhd_adp *adp, + uint32_t mem_off) { crystalhd_reg_wr(adp, DCI_DRAM_BASE_ADDR, (mem_off >> 19)); return bc_dec_reg_rd(adp, (0x00380000 | (mem_off & 0x0007FFFF))); } -static inline void crystalhd_dram_wr(struct crystalhd_adp *adp, uint32_t mem_off, uint32_t val) +static inline void crystalhd_dram_wr(struct crystalhd_adp *adp, + uint32_t mem_off, uint32_t val) { crystalhd_reg_wr(adp, DCI_DRAM_BASE_ADDR, (mem_off >> 19)); bc_dec_reg_wr(adp, (0x00380000 | (mem_off & 0x0007FFFF)), val); } -static inline enum BC_STATUS bc_chk_dram_range(struct crystalhd_adp *adp, uint32_t start_off, uint32_t cnt) +static inline enum BC_STATUS bc_chk_dram_range(struct crystalhd_adp *adp, + uint32_t start_off, uint32_t cnt) { return BC_STS_SUCCESS; } @@ -66,7 +69,8 @@ static struct crystalhd_dio_req *crystalhd_alloc_dio(struct crystalhd_adp *adp) return temp; } -static void crystalhd_free_dio(struct crystalhd_adp *adp, struct crystalhd_dio_req *dio) +static void crystalhd_free_dio(struct crystalhd_adp *adp, + struct crystalhd_dio_req *dio) { unsigned long flags = 0; @@ -99,7 +103,8 @@ static struct crystalhd_elem *crystalhd_alloc_elem(struct crystalhd_adp *adp) return temp; } -static void crystalhd_free_elem(struct crystalhd_adp *adp, struct crystalhd_elem *elem) +static void crystalhd_free_elem(struct crystalhd_adp *adp, + struct crystalhd_elem *elem) { unsigned long flags = 0; @@ -120,7 +125,8 @@ static inline void crystalhd_set_sg(struct scatterlist *sg, struct page *page, #endif } -static inline void crystalhd_init_sg(struct scatterlist *sg, unsigned int entries) +static inline void crystalhd_init_sg(struct scatterlist *sg, + unsigned int entries) { /* http://lkml.org/lkml/2007/11/27/68 */ sg_init_table(sg, entries); @@ -208,7 +214,8 @@ uint32_t crystalhd_reg_rd(struct crystalhd_adp *adp, uint32_t reg_off) * configuration space. * */ -void crystalhd_reg_wr(struct crystalhd_adp *adp, uint32_t reg_off, uint32_t val) +void crystalhd_reg_wr(struct crystalhd_adp *adp, uint32_t reg_off, + uint32_t val) { if (!adp || (reg_off > adp->pci_i2o_len)) { BCMLOG_ERR("link_wr_reg_off outof range: 0x%08x\n", reg_off); @@ -469,7 +476,8 @@ enum BC_STATUS crystalhd_create_dioq(struct crystalhd_adp *adp, * by calling the call back provided during creation. * */ -void crystalhd_delete_dioq(struct crystalhd_adp *adp, struct crystalhd_dioq *dioq) +void crystalhd_delete_dioq(struct crystalhd_adp *adp, + struct crystalhd_dioq *dioq) { void *temp; @@ -639,7 +647,8 @@ void *crystalhd_dioq_fetch_wait(struct crystalhd_dioq *ioq, uint32_t to_secs, while ((ioq->count == 0) && count) { spin_unlock_irqrestore(&ioq->lock, flags); - crystalhd_wait_on_event(&ioq->event, (ioq->count > 0), 1000, rc, 0); + crystalhd_wait_on_event(&ioq->event, + (ioq->count > 0), 1000, rc, 0); if (rc == 0) { goto out; } else if (rc == -EINTR) { @@ -678,7 +687,8 @@ enum BC_STATUS crystalhd_map_dio(struct crystalhd_adp *adp, void *ubuff, struct crystalhd_dio_req **dio_hnd) { struct crystalhd_dio_req *dio; - /* FIXME: jarod: should some of these unsigned longs be uint32_t or uintptr_t? */ + /* FIXME: jarod: should some of these + unsigned longs be uint32_t or uintptr_t? */ unsigned long start = 0, end = 0, uaddr = 0, count = 0; unsigned long spsz = 0, uv_start = 0; int i = 0, rw = 0, res = 0, nr_pages = 0, skip_fb_sg = 0; @@ -723,7 +733,8 @@ enum BC_STATUS crystalhd_map_dio(struct crystalhd_adp *adp, void *ubuff, if (uv_offset) { uv_start = (uaddr + (unsigned long)uv_offset) >> PAGE_SHIFT; dio->uinfo.uv_sg_ix = uv_start - start; - dio->uinfo.uv_sg_off = ((uaddr + (unsigned long)uv_offset) & ~PAGE_MASK); + dio->uinfo.uv_sg_off = ((uaddr + (unsigned long)uv_offset) & + ~PAGE_MASK); } dio->fb_size = ubuff_sz & 0x03; @@ -819,7 +830,8 @@ enum BC_STATUS crystalhd_map_dio(struct crystalhd_adp *adp, void *ubuff, * * This routine is to unmap the user buffer pages. */ -enum BC_STATUS crystalhd_unmap_dio(struct crystalhd_adp *adp, struct crystalhd_dio_req *dio) +enum BC_STATUS crystalhd_unmap_dio(struct crystalhd_adp *adp, + struct crystalhd_dio_req *dio) { struct page *page = NULL; int j = 0; @@ -841,7 +853,8 @@ enum BC_STATUS crystalhd_unmap_dio(struct crystalhd_adp *adp, struct crystalhd_d } } if (dio->sig == crystalhd_dio_sg_mapped) - pci_unmap_sg(adp->pdev, dio->sg, dio->page_cnt, dio->direction); + pci_unmap_sg(adp->pdev, dio->sg, dio->page_cnt, + dio->direction); crystalhd_free_dio(adp, dio); diff --git a/drivers/staging/crystalhd/crystalhd_misc.h b/drivers/staging/crystalhd/crystalhd_misc.h index 8cdaa7a34814..4dae3a797e95 100644 --- a/drivers/staging/crystalhd/crystalhd_misc.h +++ b/drivers/staging/crystalhd/crystalhd_misc.h @@ -127,12 +127,16 @@ uint32_t crystalhd_reg_rd(struct crystalhd_adp *, uint32_t); void crystalhd_reg_wr(struct crystalhd_adp *, uint32_t, uint32_t); /*========= Decoder (7412) memory access routines..=================*/ -enum BC_STATUS crystalhd_mem_rd(struct crystalhd_adp *, uint32_t, uint32_t, uint32_t *); -enum BC_STATUS crystalhd_mem_wr(struct crystalhd_adp *, uint32_t, uint32_t, uint32_t *); +enum BC_STATUS crystalhd_mem_rd(struct crystalhd_adp *, + uint32_t, uint32_t, uint32_t *); +enum BC_STATUS crystalhd_mem_wr(struct crystalhd_adp *, + uint32_t, uint32_t, uint32_t *); /*==========Link (70012) PCIe Config access routines.================*/ -enum BC_STATUS crystalhd_pci_cfg_rd(struct crystalhd_adp *, uint32_t, uint32_t, uint32_t *); -enum BC_STATUS crystalhd_pci_cfg_wr(struct crystalhd_adp *, uint32_t, uint32_t, uint32_t); +enum BC_STATUS crystalhd_pci_cfg_rd(struct crystalhd_adp *, + uint32_t, uint32_t, uint32_t *); +enum BC_STATUS crystalhd_pci_cfg_wr(struct crystalhd_adp *, + uint32_t, uint32_t, uint32_t); /*========= Linux Kernel Interface routines. ======================= */ void *bc_kern_dma_alloc(struct crystalhd_adp *, uint32_t, dma_addr_t *); @@ -168,20 +172,26 @@ do { \ /*================ Direct IO mapping routines ==================*/ extern int crystalhd_create_dio_pool(struct crystalhd_adp *, uint32_t); extern void crystalhd_destroy_dio_pool(struct crystalhd_adp *); -extern enum BC_STATUS crystalhd_map_dio(struct crystalhd_adp *, void *, uint32_t, - uint32_t, bool, bool, struct crystalhd_dio_req**); +extern enum BC_STATUS crystalhd_map_dio(struct crystalhd_adp *, void *, + uint32_t, uint32_t, bool, bool, struct crystalhd_dio_req**); -extern enum BC_STATUS crystalhd_unmap_dio(struct crystalhd_adp *, struct crystalhd_dio_req*); +extern enum BC_STATUS crystalhd_unmap_dio(struct crystalhd_adp *, + struct crystalhd_dio_req*); #define crystalhd_get_sgle_paddr(_dio, _ix) (cpu_to_le64(sg_dma_address(&_dio->sg[_ix]))) #define crystalhd_get_sgle_len(_dio, _ix) (cpu_to_le32(sg_dma_len(&_dio->sg[_ix]))) /*================ General Purpose Queues ==================*/ -extern enum BC_STATUS crystalhd_create_dioq(struct crystalhd_adp *, struct crystalhd_dioq **, crystalhd_data_free_cb , void *); -extern void crystalhd_delete_dioq(struct crystalhd_adp *, struct crystalhd_dioq *); -extern enum BC_STATUS crystalhd_dioq_add(struct crystalhd_dioq *ioq, void *data, bool wake, uint32_t tag); +extern enum BC_STATUS crystalhd_create_dioq(struct crystalhd_adp *, + struct crystalhd_dioq **, crystalhd_data_free_cb , void *); +extern void crystalhd_delete_dioq(struct crystalhd_adp *, + struct crystalhd_dioq *); +extern enum BC_STATUS crystalhd_dioq_add(struct crystalhd_dioq *ioq, + void *data, bool wake, uint32_t tag); extern void *crystalhd_dioq_fetch(struct crystalhd_dioq *ioq); -extern void *crystalhd_dioq_find_and_fetch(struct crystalhd_dioq *ioq, uint32_t tag); -extern void *crystalhd_dioq_fetch_wait(struct crystalhd_dioq *ioq, uint32_t to_secs, uint32_t *sig_pend); +extern void *crystalhd_dioq_find_and_fetch(struct crystalhd_dioq *ioq, + uint32_t tag); +extern void *crystalhd_dioq_fetch_wait(struct crystalhd_dioq *ioq, + uint32_t to_secs, uint32_t *sig_pend); #define crystalhd_dioq_count(_ioq) ((_ioq) ? _ioq->count : 0) @@ -190,7 +200,8 @@ extern void crystalhd_delete_elem_pool(struct crystalhd_adp *); /*================ Debug routines/macros .. ================================*/ -extern void crystalhd_show_buffer(uint32_t off, uint8_t *buff, uint32_t dwcount); +extern void crystalhd_show_buffer(uint32_t off, uint8_t *buff, + uint32_t dwcount); enum _chd_log_levels { BCMLOG_ERROR = 0x80000000, /* Don't disable this option */ diff --git a/drivers/staging/csr/bh.c b/drivers/staging/csr/bh.c index b53a9e29a97c..d795852ccb1c 100644 --- a/drivers/staging/csr/bh.c +++ b/drivers/staging/csr/bh.c @@ -241,67 +241,72 @@ static int bh_thread_function(void *arg) this_thread = &priv->bh_thread; t = timeout = 0; - while (!kthread_should_stop()) { - /* wait until an error occurs, or we need to process something. */ - unifi_trace(priv, UDBG3, "bh_thread goes to sleep.\n"); + while (!kthread_should_stop()) { + /* + * wait until an error occurs, + * or we need to process something. + */ + unifi_trace(priv, UDBG3, "bh_thread goes to sleep.\n"); - if (timeout > 0) { - /* Convert t in ms to jiffies */ - t = msecs_to_jiffies(timeout); - ret = wait_event_interruptible_timeout(this_thread->wakeup_q, - (this_thread->wakeup_flag && !this_thread->block_thread) || - kthread_should_stop(), - t); - timeout = (ret > 0) ? jiffies_to_msecs(ret) : 0; - } else { - ret = wait_event_interruptible(this_thread->wakeup_q, - (this_thread->wakeup_flag && !this_thread->block_thread) || - kthread_should_stop()); - } + if (timeout > 0) { + /* Convert t in ms to jiffies */ + t = msecs_to_jiffies(timeout); + ret = wait_event_interruptible_timeout( + this_thread->wakeup_q, + (this_thread->wakeup_flag && !this_thread->block_thread) || + kthread_should_stop(), + t); + timeout = (ret > 0) ? jiffies_to_msecs(ret) : 0; + } else { + ret = wait_event_interruptible(this_thread->wakeup_q, + (this_thread->wakeup_flag && !this_thread->block_thread) || + kthread_should_stop()); + } - if (kthread_should_stop()) { - unifi_trace(priv, UDBG2, "bh_thread: signalled to exit\n"); - break; - } + if (kthread_should_stop()) { + unifi_trace(priv, UDBG2, + "bh_thread: signalled to exit\n"); + break; + } - if (ret < 0) { - unifi_notice(priv, - "bh_thread: wait_event returned %d, thread will exit\n", - ret); - uf_wait_for_thread_to_stop(priv, this_thread); - break; - } + if (ret < 0) { + unifi_notice(priv, + "bh_thread: wait_event returned %d, thread will exit\n", + ret); + uf_wait_for_thread_to_stop(priv, this_thread); + break; + } - this_thread->wakeup_flag = 0; + this_thread->wakeup_flag = 0; - unifi_trace(priv, UDBG3, "bh_thread calls unifi_bh().\n"); + unifi_trace(priv, UDBG3, "bh_thread calls unifi_bh().\n"); - CsrSdioClaim(priv->sdio); - csrResult = unifi_bh(priv->card, &timeout); - if(csrResult != CSR_RESULT_SUCCESS) { - if (csrResult == CSR_WIFI_HIP_RESULT_NO_DEVICE) { - CsrSdioRelease(priv->sdio); - uf_wait_for_thread_to_stop(priv, this_thread); - break; - } - /* Errors must be delivered to the error task */ - handle_bh_error(priv); - } - CsrSdioRelease(priv->sdio); - } + CsrSdioClaim(priv->sdio); + csrResult = unifi_bh(priv->card, &timeout); + if (csrResult != CSR_RESULT_SUCCESS) { + if (csrResult == CSR_WIFI_HIP_RESULT_NO_DEVICE) { + CsrSdioRelease(priv->sdio); + uf_wait_for_thread_to_stop(priv, this_thread); + break; + } + /* Errors must be delivered to the error task */ + handle_bh_error(priv); + } + CsrSdioRelease(priv->sdio); + } - /* - * I would normally try to call csr_sdio_remove_irq() here to make sure - * that we do not get any interrupts while this thread is not running. - * However, the MMC/SDIO driver tries to kill its' interrupt thread. - * The kernel threads implementation does not allow to kill threads - * from a signalled to stop thread. - * So, instead call csr_sdio_linux_remove_irq() always after calling - * uf_stop_thread() to kill this thread. - */ + /* + * I would normally try to call csr_sdio_remove_irq() here to make sure + * that we do not get any interrupts while this thread is not running. + * However, the MMC/SDIO driver tries to kill its' interrupt thread. + * The kernel threads implementation does not allow to kill threads + * from a signalled to stop thread. + * So, instead call csr_sdio_linux_remove_irq() always after calling + * uf_stop_thread() to kill this thread. + */ - unifi_trace(priv, UDBG2, "bh_thread exiting....\n"); - return 0; + unifi_trace(priv, UDBG2, "bh_thread exiting....\n"); + return 0; } /* bh_thread_function() */ @@ -319,33 +324,33 @@ static int bh_thread_function(void *arg) * 0 on success or else a Linux error code. * --------------------------------------------------------------------------- */ - int +int uf_init_bh(unifi_priv_t *priv) { - int r; + int r; - /* Enable mlme interface. */ - priv->io_aborted = 0; + /* Enable mlme interface. */ + priv->io_aborted = 0; - /* Start the BH thread */ - r = uf_start_thread(priv, &priv->bh_thread, bh_thread_function); - if (r) { - unifi_error(priv, - "uf_init_bh: failed to start the BH thread.\n"); - return r; - } + /* Start the BH thread */ + r = uf_start_thread(priv, &priv->bh_thread, bh_thread_function); + if (r) { + unifi_error(priv, + "uf_init_bh: failed to start the BH thread.\n"); + return r; + } - /* Allow interrupts */ - r = csr_sdio_linux_install_irq(priv->sdio); - if (r) { - unifi_error(priv, - "uf_init_bh: failed to install the IRQ.\n"); + /* Allow interrupts */ + r = csr_sdio_linux_install_irq(priv->sdio); + if (r) { + unifi_error(priv, + "uf_init_bh: failed to install the IRQ.\n"); - uf_stop_thread(priv, &priv->bh_thread); - } + uf_stop_thread(priv, &priv->bh_thread); + } - return r; + return r; } /* uf_init_bh() */ @@ -370,28 +375,30 @@ uf_init_bh(unifi_priv_t *priv) */ CsrResult unifi_run_bh(void *ospriv) { - unifi_priv_t *priv = ospriv; + unifi_priv_t *priv = ospriv; - /* - * If an error has occurred, we discard silently all messages from the bh - * until the error has been processed and the unifi has been reinitialised. - */ - if (priv->bh_thread.block_thread == 1) { - unifi_trace(priv, UDBG3, "unifi_run_bh: discard message.\n"); - /* - * Do not try to acknowledge a pending interrupt here. - * This function is called by unifi_send_signal() which in turn can be - * running in an atomic or 'disabled irq' level if a signal is sent - * from a workqueue task (i.e multicass addresses set). - * We can not hold the SDIO lock because it might sleep. - */ - return CSR_RESULT_FAILURE; - } + /* + * If an error has occurred, we discard silently all messages from the bh + * until the error has been processed and the unifi has been + * reinitialised. + */ + if (priv->bh_thread.block_thread == 1) { + unifi_trace(priv, UDBG3, "unifi_run_bh: discard message.\n"); + /* + * Do not try to acknowledge a pending interrupt here. + * This function is called by unifi_send_signal() + * which in turn can be running in an atomic or 'disabled irq' + * level if a signal is sent from a workqueue task + * (i.e multicass addresses set). We can not hold the SDIO lock + * because it might sleep. + */ + return CSR_RESULT_FAILURE; + } - priv->bh_thread.wakeup_flag = 1; - /* wake up I/O thread */ - wake_up_interruptible(&priv->bh_thread.wakeup_q); + priv->bh_thread.wakeup_flag = 1; + /* wake up I/O thread */ + wake_up_interruptible(&priv->bh_thread.wakeup_q); - return CSR_RESULT_SUCCESS; + return CSR_RESULT_SUCCESS; } /* unifi_run_bh() */ diff --git a/drivers/staging/csr/csr_framework_ext.c b/drivers/staging/csr/csr_framework_ext.c index 2aabb6c6b0af..98122bce1427 100644 --- a/drivers/staging/csr/csr_framework_ext.c +++ b/drivers/staging/csr/csr_framework_ext.c @@ -1,10 +1,10 @@ /***************************************************************************** - (c) Cambridge Silicon Radio Limited 2010 - All rights reserved and confidential information of CSR + (c) Cambridge Silicon Radio Limited 2010 + All rights reserved and confidential information of CSR - Refer to LICENSE.txt included with this source for details - on the license terms. + Refer to LICENSE.txt included with this source for details + on the license terms. *****************************************************************************/ @@ -31,10 +31,10 @@ *----------------------------------------------------------------------------*/ void CsrThreadSleep(u16 sleepTimeInMs) { - unsigned long t; + unsigned long t; - /* Convert t in ms to jiffies and round up */ - t = ((sleepTimeInMs * HZ) + 999) / 1000; - schedule_timeout_uninterruptible(t); + /* Convert t in ms to jiffies and round up */ + t = ((sleepTimeInMs * HZ) + 999) / 1000; + schedule_timeout_uninterruptible(t); } EXPORT_SYMBOL_GPL(CsrThreadSleep); diff --git a/drivers/staging/csr/csr_framework_ext.h b/drivers/staging/csr/csr_framework_ext.h index e8ae490c09d6..6d26ac6173b0 100644 --- a/drivers/staging/csr/csr_framework_ext.h +++ b/drivers/staging/csr/csr_framework_ext.h @@ -2,11 +2,11 @@ #define CSR_FRAMEWORK_EXT_H__ /***************************************************************************** - (c) Cambridge Silicon Radio Limited 2010 - All rights reserved and confidential information of CSR + (c) Cambridge Silicon Radio Limited 2010 + All rights reserved and confidential information of CSR - Refer to LICENSE.txt included with this source for details - on the license terms. + Refer to LICENSE.txt included with this source for details + on the license terms. *****************************************************************************/ diff --git a/drivers/staging/csr/csr_wifi_nme_ap_sef.c b/drivers/staging/csr/csr_wifi_nme_ap_sef.c index e048848883d5..bfebb1529779 100644 --- a/drivers/staging/csr/csr_wifi_nme_ap_sef.c +++ b/drivers/staging/csr/csr_wifi_nme_ap_sef.c @@ -21,10 +21,10 @@ void CsrWifiNmeApUpstreamStateHandlers(void* drvpriv, CsrWifiFsmEvent* msg) CsrWifiNmeApStopCfmHandler(drvpriv, msg); break; case CSR_WIFI_NME_AP_CONFIG_SET_CFM: - CsrWifiNmeApConfigSetCfmHandler(drvpriv,msg); + CsrWifiNmeApConfigSetCfmHandler(drvpriv, msg); break; default: - unifi_error(drvpriv, "CsrWifiNmeApUpstreamStateHandlers: unhandled NME_AP message type 0x%.4X\n",msg->type); + unifi_error(drvpriv, "CsrWifiNmeApUpstreamStateHandlers: unhandled NME_AP message type 0x%.4X\n", msg->type); break; } } diff --git a/drivers/staging/csr/drv.c b/drivers/staging/csr/drv.c index bdc25236ab00..92898de921f5 100644 --- a/drivers/staging/csr/drv.c +++ b/drivers/staging/csr/drv.c @@ -1159,13 +1159,13 @@ unifi_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) break; #ifdef CSR_SUPPORT_SME case UNIFI_CFG_CORE_DUMP: - CsrWifiRouterCtrlWifiOffIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,CSR_WIFI_SME_CONTROL_INDICATION_ERROR); + CsrWifiRouterCtrlWifiOffIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, CSR_WIFI_SME_CONTROL_INDICATION_ERROR); unifi_trace(priv, UDBG2, "UNIFI_CFG_CORE_DUMP: sent wifi off indication\n"); break; #endif #ifdef CSR_SUPPORT_WEXT_AP case UNIFI_CFG_SET_AP_CONFIG: - r= unifi_cfg_set_ap_config(priv,(unsigned char*)arg); + r= unifi_cfg_set_ap_config(priv, (unsigned char*)arg); break; #endif default: @@ -1275,7 +1275,7 @@ unifi_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) /* Attach the network device to the stack */ if (!interfacePriv->netdev_registered) { - r = uf_register_netdev(priv,interfaceTag); + r = uf_register_netdev(priv, interfaceTag); if (r) { unifi_error(priv, "Failed to register the network device.\n"); goto out; diff --git a/drivers/staging/csr/io.c b/drivers/staging/csr/io.c index fe4a7ba2acc9..f903022b4079 100644 --- a/drivers/staging/csr/io.c +++ b/drivers/staging/csr/io.c @@ -117,7 +117,7 @@ static CsrResult signal_buffer_init(unifi_priv_t * priv, int size) if (priv->rxSignalBuffer.rx_buff[i].bufptr == NULL) { int j; - unifi_error(priv,"signal_buffer_init:Failed to Allocate shared memory for T-H signals \n"); + unifi_error(priv, "signal_buffer_init:Failed to Allocate shared memory for T-H signals \n"); for(j=0;jrxSignalBuffer.rx_buff[j].sig_len=0; @@ -360,13 +360,13 @@ register_unifi_sdio(CsrSdioFunction *sdio_dev, int bus_id, struct device *dev) for(i=1;irx_workqueue = create_singlethread_workqueue("rx_workq"); if (priv->rx_workqueue == NULL) { - unifi_error(priv,"create_singlethread_workqueue failed \n"); + unifi_error(priv, "create_singlethread_workqueue failed \n"); goto failed3; } INIT_WORK(&priv->rx_work_struct, rx_wq_handler); @@ -442,7 +442,7 @@ if (log_hip_signals) flush_workqueue(priv->rx_workqueue); destroy_workqueue(priv->rx_workqueue); failed3: - signal_buffer_free(priv,CSR_WIFI_RX_SIGNAL_BUFFER_SIZE); + signal_buffer_free(priv, CSR_WIFI_RX_SIGNAL_BUFFER_SIZE); failed2: #endif /* Remove the device nodes */ @@ -558,8 +558,8 @@ cleanup_unifi_sdio(unifi_priv_t *priv) /* Free any packets left in the Rx queues */ for(i=0;irx_workqueue); destroy_workqueue(priv->rx_workqueue); - signal_buffer_free(priv,CSR_WIFI_RX_SIGNAL_BUFFER_SIZE); + signal_buffer_free(priv, CSR_WIFI_RX_SIGNAL_BUFFER_SIZE); #endif /* Priv is freed as part of the net_device */ diff --git a/drivers/staging/csr/monitor.c b/drivers/staging/csr/monitor.c index c8e20e4c6111..e11f6cba8266 100644 --- a/drivers/staging/csr/monitor.c +++ b/drivers/staging/csr/monitor.c @@ -188,7 +188,7 @@ netrx_radiotap(unifi_priv_t *priv, skb->dev = dev; - skb->mac_header = skb->data; + skb_reset_mac_header(skb); skb->pkt_type = PACKET_OTHERHOST; skb->protocol = __constant_htons(ETH_P_80211_RAW); memset(skb->cb, 0, sizeof(skb->cb)); diff --git a/drivers/staging/csr/netdev.c b/drivers/staging/csr/netdev.c index a0177d998978..5ead2d404115 100644 --- a/drivers/staging/csr/netdev.c +++ b/drivers/staging/csr/netdev.c @@ -754,7 +754,7 @@ get_packet_priority(unifi_priv_t *priv, struct sk_buff *skb, const struct ethhdr case CSR_WIFI_ROUTER_CTRL_MODE_IBSS: { CsrWifiRouterCtrlStaInfo_t * dstStaInfo = - CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,ehdr->h_dest, interfacePriv->InterfaceTag); + CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, ehdr->h_dest, interfacePriv->InterfaceTag); unifi_trace(priv, UDBG4, "mode is AP \n"); if (!(ehdr->h_dest[0] & 0x01) && dstStaInfo && dstStaInfo->wmmOrQosEnabled) { /* If packet is not Broadcast/multicast */ @@ -1011,7 +1011,7 @@ skb_80211_to_ether(unifi_priv_t *priv, struct sk_buff *skb, #endif if(skb== NULL || daddr == NULL || saddr == NULL){ - unifi_error(priv,"skb_80211_to_ether: PBC fail\n"); + unifi_error(priv, "skb_80211_to_ether: PBC fail\n"); return 1; } @@ -1198,7 +1198,7 @@ int prepare_and_add_macheader(unifi_priv_t *priv, struct sk_buff *skb, struct sk u8 bQosNull = false; if (skb == NULL) { - unifi_error(priv,"prepare_and_add_macheader: Invalid SKB reference\n"); + unifi_error(priv, "prepare_and_add_macheader: Invalid SKB reference\n"); return -1; } @@ -1383,7 +1383,7 @@ int prepare_and_add_macheader(unifi_priv_t *priv, struct sk_buff *skb, struct sk macHeaderLengthInBytes -= ETH_ALEN; break; default: - unifi_error(priv,"Unknown direction =%d : Not handled now\n",direction); + unifi_error(priv, "Unknown direction =%d : Not handled now\n", direction); return -1; } /* 2 bytes of frame control field, appended by firmware */ @@ -1569,8 +1569,8 @@ send_ma_pkt_request(unifi_priv_t *priv, struct sk_buff *skb, const struct ethhdr memcpy(peerAddress.a, ((u8 *) bulkdata.d[0].os_data_ptr) + 4, ETH_ALEN); unifi_trace(priv, UDBG5, "RA[0]=%x, RA[1]=%x, RA[2]=%x, RA[3]=%x, RA[4]=%x, RA[5]=%x\n", - peerAddress.a[0],peerAddress.a[1], peerAddress.a[2], peerAddress.a[3], - peerAddress.a[4],peerAddress.a[5]); + peerAddress.a[0], peerAddress.a[1], peerAddress.a[2], peerAddress.a[3], + peerAddress.a[4], peerAddress.a[5]); if ((proto == ETH_P_PAE) @@ -1865,10 +1865,10 @@ unifi_pause_xmit(void *ospriv, unifi_TrafficQueue queue) #ifdef CSR_SUPPORT_SME if(queue<=3) { - routerStartBuffering(priv,queue); - unifi_trace(priv,UDBG2,"Start buffering %d\n", queue); + routerStartBuffering(priv, queue); + unifi_trace(priv, UDBG2, "Start buffering %d\n", queue); } else { - routerStartBuffering(priv,0); + routerStartBuffering(priv, 0); unifi_error(priv, "Start buffering %d defaulting to 0\n", queue); } #endif @@ -1893,11 +1893,11 @@ unifi_restart_xmit(void *ospriv, unifi_TrafficQueue queue) #ifdef CSR_SUPPORT_SME if(queue <=3) { - routerStopBuffering(priv,queue); - uf_send_buffered_frames(priv,queue); + routerStopBuffering(priv, queue); + uf_send_buffered_frames(priv, queue); } else { - routerStopBuffering(priv,0); - uf_send_buffered_frames(priv,0); + routerStopBuffering(priv, 0); + uf_send_buffered_frames(priv, 0); } #endif } /* unifi_restart_xmit() */ @@ -2102,14 +2102,14 @@ uf_resume_data_plane(unifi_priv_t *priv, int queue, netif_tx_schedule_all(priv->netdev[interfaceTag]); } #endif - uf_process_rx_pending_queue(priv, queue, peer_address, 1,interfaceTag); + uf_process_rx_pending_queue(priv, queue, peer_address, 1, interfaceTag); } } /* uf_resume_data_plane() */ -void uf_free_pending_rx_packets(unifi_priv_t *priv, int queue, CsrWifiMacAddress peer_address,u16 interfaceTag) +void uf_free_pending_rx_packets(unifi_priv_t *priv, int queue, CsrWifiMacAddress peer_address, u16 interfaceTag) { - uf_process_rx_pending_queue(priv, queue, peer_address, 0,interfaceTag); + uf_process_rx_pending_queue(priv, queue, peer_address, 0, interfaceTag); } /* uf_free_pending_rx_packets() */ @@ -2153,7 +2153,7 @@ unifi_rx(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata) if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) { unifi_error(priv, "%s: MA-PACKET indication with bad interfaceTag %d\n", __FUNCTION__, interfaceTag); - unifi_net_data_free(priv,&bulkdata->d[0]); + unifi_net_data_free(priv, &bulkdata->d[0]); return; } @@ -2167,7 +2167,7 @@ unifi_rx(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata) if (bulkdata->d[0].data_length == 0) { unifi_warning(priv, "%s: MA-PACKET indication with zero bulk data\n", __FUNCTION__); - unifi_net_data_free(priv,&bulkdata->d[0]); + unifi_net_data_free(priv, &bulkdata->d[0]); return; } @@ -2179,8 +2179,8 @@ unifi_rx(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata) toDs = (skb->data[1] & 0x01) ? 1 : 0; fromDs = (skb->data[1] & 0x02) ? 1 : 0; - memcpy(da,(skb->data+4+toDs*12),ETH_ALEN);/* Address1 or 3 */ - memcpy(sa,(skb->data+10+fromDs*(6+toDs*8)),ETH_ALEN); /* Address2, 3 or 4 */ + memcpy(da, (skb->data+4+toDs*12), ETH_ALEN);/* Address1 or 3 */ + memcpy(sa, (skb->data+10+fromDs*(6+toDs*8)), ETH_ALEN); /* Address2, 3 or 4 */ pData = &bulkdata->d[0]; @@ -2189,7 +2189,7 @@ unifi_rx(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata) dataFrameType =((frameControl & 0x00f0) >> 4); unifi_trace(priv, UDBG6, - "%s: Receive Data Frame Type %d \n", __FUNCTION__,dataFrameType); + "%s: Receive Data Frame Type %d \n", __FUNCTION__, dataFrameType); switch(dataFrameType) { @@ -2276,7 +2276,7 @@ unifi_rx(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata) /* AP/P2PGO specific handling here */ CsrWifiRouterCtrlStaInfo_t * srcStaInfo = - CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,sa,interfaceTag); + CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, sa, interfaceTag); /* Defensive check only; Source address is already checked in process_ma_packet_ind and we should have a valid source address here */ @@ -2284,10 +2284,10 @@ unifi_rx(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata) if(srcStaInfo == NULL) { CsrWifiMacAddress peerMacAddress; /* Unknown data PDU */ - memcpy(peerMacAddress.a,sa,ETH_ALEN); + memcpy(peerMacAddress.a, sa, ETH_ALEN); unifi_trace(priv, UDBG1, "%s: Unexpected frame from peer = %x:%x:%x:%x:%x:%x\n", __FUNCTION__, - sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]); - CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress); + sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]); + CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, peerMacAddress); unifi_net_data_free(priv, &bulkdata->d[0]); return; } @@ -2296,11 +2296,11 @@ unifi_rx(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata) if (port_action != CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN) { /* Drop the packet and return */ CsrWifiMacAddress peerMacAddress; - memcpy(peerMacAddress.a,sa,ETH_ALEN); + memcpy(peerMacAddress.a, sa, ETH_ALEN); unifi_trace(priv, UDBG3, "%s: Port is not open: unexpected frame from peer = %x:%x:%x:%x:%x:%x\n", - __FUNCTION__, sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]); + __FUNCTION__, sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]); - CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress); + CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, peerMacAddress); interfacePriv->stats.rx_dropped++; unifi_net_data_free(priv, &bulkdata->d[0]); unifi_notice(priv, "%s: Dropping packet, proto=0x%04x, %s port\n", __FUNCTION__, @@ -2328,7 +2328,7 @@ unifi_rx(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata) { return; } - unifi_trace(priv, UDBG5, "unifi_rx: no specific AP handling process as normal frame, MAC Header len %d\n",macHeaderLengthInBytes); + unifi_trace(priv, UDBG5, "unifi_rx: no specific AP handling process as normal frame, MAC Header len %d\n", macHeaderLengthInBytes); /* Remove the MAC header for subsequent conversion */ skb_pull(skb, macHeaderLengthInBytes); pData->os_data_ptr = skb->data; @@ -2422,7 +2422,7 @@ static void process_ma_packet_cfm(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_d if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP || interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) { - uf_process_ma_pkt_cfm_for_ap(priv,interfaceTag,pkt_cfm); + uf_process_ma_pkt_cfm_for_ap(priv, interfaceTag, pkt_cfm); } else if (interfacePriv->m4_sent && (pkt_cfm->HostTag == interfacePriv->m4_hostTag)) { /* Check if this is a confirm for EAPOL M4 frame and we need to send transmistted ind*/ CsrResult result = pkt_cfm->TransmissionStatus == CSR_TX_SUCCESSFUL?CSR_RESULT_SUCCESS:CSR_RESULT_FAILURE; @@ -2486,7 +2486,7 @@ static void process_ma_packet_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_d if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) { unifi_error(priv, "%s: MA-PACKET indication with bad interfaceTag %d\n", __FUNCTION__, interfaceTag); - unifi_net_data_free(priv,&bulkdata->d[0]); + unifi_net_data_free(priv, &bulkdata->d[0]); return; } @@ -2500,7 +2500,7 @@ static void process_ma_packet_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_d if (bulkdata->d[0].data_length == 0) { unifi_warning(priv, "%s: MA-PACKET indication with zero bulk data\n", __FUNCTION__); - unifi_net_data_free(priv,&bulkdata->d[0]); + unifi_net_data_free(priv, &bulkdata->d[0]); return; } /* For monitor mode we need to pass this indication to the registered application @@ -2508,8 +2508,8 @@ static void process_ma_packet_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_d /* MIC failure is already taken care of so no need to send the PDUs which are not successfully received in non-monitor mode*/ if(pkt_ind->ReceptionStatus != CSR_RX_SUCCESS) { - unifi_warning(priv, "%s: MA-PACKET indication with status = %d\n",__FUNCTION__, pkt_ind->ReceptionStatus); - unifi_net_data_free(priv,&bulkdata->d[0]); + unifi_warning(priv, "%s: MA-PACKET indication with status = %d\n", __FUNCTION__, pkt_ind->ReceptionStatus); + unifi_net_data_free(priv, &bulkdata->d[0]); return; } @@ -2521,8 +2521,8 @@ static void process_ma_packet_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_d toDs = (skb->data[1] & 0x01) ? 1 : 0; fromDs = (skb->data[1] & 0x02) ? 1 : 0; - memcpy(da,(skb->data+4+toDs*12),ETH_ALEN);/* Address1 or 3 */ - memcpy(sa,(skb->data+10+fromDs*(6+toDs*8)),ETH_ALEN); /* Address2, 3 or 4 */ + memcpy(da, (skb->data+4+toDs*12), ETH_ALEN);/* Address1 or 3 */ + memcpy(sa, (skb->data+10+fromDs*(6+toDs*8)), ETH_ALEN); /* Address2, 3 or 4 */ /* Find the BSSID, which will be used to match the BA session */ if (toDs && fromDs) @@ -2539,7 +2539,7 @@ static void process_ma_packet_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_d frameControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr); frameType = ((frameControl & 0x000C) >> 2); - unifi_trace(priv, UDBG3, "Rx Frame Type: %d sn: %d\n",frameType, + unifi_trace(priv, UDBG3, "Rx Frame Type: %d sn: %d\n", frameType, (le16_to_cpu(*((u16*)(bulkdata->d[0].os_data_ptr + IEEE802_11_SEQUENCE_CONTROL_OFFSET))) >> 4) & 0xfff); if(frameType == IEEE802_11_FRAMETYPE_CONTROL){ #ifdef CSR_SUPPORT_SME @@ -2550,18 +2550,18 @@ static void process_ma_packet_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_d u8 pmBit = (frameControl & 0x1000)?0x01:0x00; unifi_trace(priv, UDBG6, "%s: Received PS-POLL Frame\n", __FUNCTION__); - uf_process_ps_poll(priv,sa,da,pmBit,interfaceTag); + uf_process_ps_poll(priv, sa, da, pmBit, interfaceTag); } else { unifi_warning(priv, "%s: Non PS-POLL control frame is received\n", __FUNCTION__); } #endif - unifi_net_data_free(priv,&bulkdata->d[0]); + unifi_net_data_free(priv, &bulkdata->d[0]); return; } if(frameType != IEEE802_11_FRAMETYPE_DATA) { - unifi_warning(priv, "%s: Non control Non Data frame is received\n",__FUNCTION__); - unifi_net_data_free(priv,&bulkdata->d[0]); + unifi_warning(priv, "%s: Non control Non Data frame is received\n", __FUNCTION__); + unifi_net_data_free(priv, &bulkdata->d[0]); return; } @@ -2569,15 +2569,15 @@ static void process_ma_packet_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_d if((interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP) || (interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO)){ - srcStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,sa,interfaceTag); + srcStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, sa, interfaceTag); if(srcStaInfo == NULL) { CsrWifiMacAddress peerMacAddress; /* Unknown data PDU */ - memcpy(peerMacAddress.a,sa,ETH_ALEN); + memcpy(peerMacAddress.a, sa, ETH_ALEN); unifi_trace(priv, UDBG1, "%s: Unexpected frame from peer = %x:%x:%x:%x:%x:%x\n", __FUNCTION__, - sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]); - CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress); + sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]); + CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, peerMacAddress); unifi_net_data_free(priv, &bulkdata->d[0]); return; } @@ -2591,7 +2591,7 @@ static void process_ma_packet_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_d */ pmBit = (frameControl & 0x1000)?0x01:0x00; - powerSaveChanged = uf_process_pm_bit_for_peer(priv,srcStaInfo,pmBit,interfaceTag); + powerSaveChanged = uf_process_pm_bit_for_peer(priv, srcStaInfo, pmBit, interfaceTag); /* Update station last activity time */ srcStaInfo->activity_flag = TRUE; @@ -2616,8 +2616,8 @@ static void process_ma_packet_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_d else{ qosControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr + 24); } - unifi_trace(priv, UDBG5, "%s: Check if U-APSD operations are triggered for qosControl: 0x%x\n",__FUNCTION__,qosControl); - uf_process_wmm_deliver_ac_uapsd(priv,srcStaInfo,qosControl,interfaceTag); + unifi_trace(priv, UDBG5, "%s: Check if U-APSD operations are triggered for qosControl: 0x%x\n", __FUNCTION__, qosControl); + uf_process_wmm_deliver_ac_uapsd(priv, srcStaInfo, qosControl, interfaceTag); } } } @@ -2918,8 +2918,8 @@ uf_netdev_event(struct notifier_block *notif, unsigned long event, void* ptr) { interfacePriv->connected = UnifiConnected; interfacePriv->wait_netdev_change = FALSE; /* Note: passing the broadcast address here will allow anyone to attempt to join our adhoc network */ - uf_process_rx_pending_queue(priv, UF_UNCONTROLLED_PORT_Q, broadcast_address, 1,interfacePriv->InterfaceTag); - uf_process_rx_pending_queue(priv, UF_CONTROLLED_PORT_Q, broadcast_address, 1,interfacePriv->InterfaceTag); + uf_process_rx_pending_queue(priv, UF_UNCONTROLLED_PORT_Q, broadcast_address, 1, interfacePriv->InterfaceTag); + uf_process_rx_pending_queue(priv, UF_CONTROLLED_PORT_Q, broadcast_address, 1, interfacePriv->InterfaceTag); } break; diff --git a/drivers/staging/csr/sdio_mmc.c b/drivers/staging/csr/sdio_mmc.c index 30271d35af55..2b503c23efae 100644 --- a/drivers/staging/csr/sdio_mmc.c +++ b/drivers/staging/csr/sdio_mmc.c @@ -1135,8 +1135,8 @@ uf_glue_sdio_remove(struct sdio_func *func) * them from the list passed in csr_sdio_register_driver(). */ static const struct sdio_device_id unifi_ids[] = { - { SDIO_DEVICE(SDIO_MANF_ID_CSR,SDIO_CARD_ID_UNIFI_3) }, - { SDIO_DEVICE(SDIO_MANF_ID_CSR,SDIO_CARD_ID_UNIFI_4) }, + { SDIO_DEVICE(SDIO_MANF_ID_CSR, SDIO_CARD_ID_UNIFI_3) }, + { SDIO_DEVICE(SDIO_MANF_ID_CSR, SDIO_CARD_ID_UNIFI_4) }, { /* end: all zeroes */ }, }; diff --git a/drivers/staging/csr/sme_blocking.c b/drivers/staging/csr/sme_blocking.c index d88ccd5bd428..0c6e21636e7f 100644 --- a/drivers/staging/csr/sme_blocking.c +++ b/drivers/staging/csr/sme_blocking.c @@ -1280,7 +1280,7 @@ int sme_sys_suspend(unifi_priv_t *priv) return -EIO; /* Suspend the SME, which MAY cause it to power down UniFi */ - CsrWifiRouterCtrlSuspendIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0, 0, priv->wol_suspend); + CsrWifiRouterCtrlSuspendIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, 0, priv->wol_suspend); r = sme_wait_for_reply(priv, UNIFI_SME_SYS_LONG_TIMEOUT); if (r) { /* No reply - forcibly power down in case the request wasn't processed */ @@ -1366,7 +1366,7 @@ int sme_sys_resume(unifi_priv_t *priv) if (r) return -EIO; - CsrWifiRouterCtrlResumeIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0, priv->wol_suspend); + CsrWifiRouterCtrlResumeIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, priv->wol_suspend); r = sme_wait_for_reply(priv, UNIFI_SME_SYS_LONG_TIMEOUT); if (r) @@ -1377,7 +1377,7 @@ int sme_sys_resume(unifi_priv_t *priv) } #ifdef CSR_SUPPORT_WEXT_AP -int sme_ap_stop(unifi_priv_t *priv,u16 interface_tag) +int sme_ap_stop(unifi_priv_t *priv, u16 interface_tag) { int r; @@ -1390,7 +1390,7 @@ int sme_ap_stop(unifi_priv_t *priv,u16 interface_tag) if (r) return -EIO; - CsrWifiNmeApStopReqSend(0,interface_tag); + CsrWifiNmeApStopReqSend(0, interface_tag); r = sme_wait_for_reply(priv, UNIFI_SME_MGT_SHORT_TIMEOUT); if (r) @@ -1403,12 +1403,12 @@ int sme_ap_stop(unifi_priv_t *priv,u16 interface_tag) } -int sme_ap_start(unifi_priv_t *priv,u16 interface_tag, +int sme_ap_start(unifi_priv_t *priv, u16 interface_tag, CsrWifiSmeApConfig_t * ap_config) { int r; CsrWifiSmeApP2pGoConfig p2p_go_param; - memset(&p2p_go_param,0,sizeof(CsrWifiSmeApP2pGoConfig)); + memset(&p2p_go_param, 0, sizeof(CsrWifiSmeApP2pGoConfig)); if (priv->smepriv == NULL) { unifi_error(priv, "sme_ap_start: invalid smepriv\n"); @@ -1419,10 +1419,10 @@ int sme_ap_start(unifi_priv_t *priv,u16 interface_tag, if (r) return -EIO; - CsrWifiNmeApStartReqSend(0,interface_tag,CSR_WIFI_AP_TYPE_LEGACY,FALSE, - ap_config->ssid,1,ap_config->channel, - ap_config->credentials,ap_config->max_connections, - p2p_go_param,FALSE); + CsrWifiNmeApStartReqSend(0, interface_tag, CSR_WIFI_AP_TYPE_LEGACY, FALSE, + ap_config->ssid, 1, ap_config->channel, + ap_config->credentials, ap_config->max_connections, + p2p_go_param, FALSE); r = sme_wait_for_reply(priv, UNIFI_SME_MGT_SHORT_TIMEOUT); if (r) @@ -1440,7 +1440,7 @@ int sme_ap_config(unifi_priv_t *priv, { int r; CsrWifiSmeApP2pGoConfig p2p_go_param; - memset(&p2p_go_param,0,sizeof(CsrWifiSmeApP2pGoConfig)); + memset(&p2p_go_param, 0, sizeof(CsrWifiSmeApP2pGoConfig)); if (priv->smepriv == NULL) { unifi_error(priv, "sme_ap_config: invalid smepriv\n"); @@ -1451,7 +1451,7 @@ int sme_ap_config(unifi_priv_t *priv, if (r) return -EIO; - CsrWifiNmeApConfigSetReqSend(0,*group_security_config, + CsrWifiNmeApConfigSetReqSend(0, *group_security_config, *ap_mac_config); r = sme_wait_for_reply(priv, UNIFI_SME_MGT_SHORT_TIMEOUT); diff --git a/drivers/staging/csr/sme_native.c b/drivers/staging/csr/sme_native.c index ca55249bde3e..d0b9be31e12c 100644 --- a/drivers/staging/csr/sme_native.c +++ b/drivers/staging/csr/sme_native.c @@ -55,7 +55,7 @@ uf_sme_deinit(unifi_priv_t *priv) int sme_mgt_wifi_on(unifi_priv_t *priv) { - int r,i; + int r, i; s32 csrResult; if (priv == NULL) { diff --git a/drivers/staging/csr/sme_sys.c b/drivers/staging/csr/sme_sys.c index b1151a28d8e3..b5258d71d250 100644 --- a/drivers/staging/csr/sme_sys.c +++ b/drivers/staging/csr/sme_sys.c @@ -158,7 +158,7 @@ void CsrWifiRouterCtrlMediaStatusReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) unifi_error(priv, "CsrWifiRouterCtrlMediaStatusReqHandler: invalid interfaceTag\n"); return; } - unifi_trace(priv, UDBG3, "CsrWifiRouterCtrlMediaStatusReqHandler: Mode = %d req->mediaStatus = %d\n",interfacePriv->interfaceMode,req->mediaStatus); + unifi_trace(priv, UDBG3, "CsrWifiRouterCtrlMediaStatusReqHandler: Mode = %d req->mediaStatus = %d\n", interfacePriv->interfaceMode, req->mediaStatus); if (interfacePriv->interfaceMode != CSR_WIFI_ROUTER_CTRL_MODE_AMP) { bulk_data_desc_t bulk_data; @@ -389,7 +389,7 @@ void CsrWifiRouterCtrlHipReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) unifi_error(priv, "CsrWifiRouterCtrlHipReqHandler: Failed to send signal (0x%.4X - %u)\n", *((u16*)signal_ptr), r); - CsrWifiRouterCtrlWifiOffIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,CSR_WIFI_SME_CONTROL_INDICATION_ERROR); + CsrWifiRouterCtrlWifiOffIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, CSR_WIFI_SME_CONTROL_INDICATION_ERROR); } unifi_trace(priv, UDBG4, "CsrWifiRouterCtrlHipReqHandler: <----\n"); @@ -474,7 +474,7 @@ uf_send_gratuitous_arp(unifi_priv_t *priv, u16 interfaceTag) r = ul_send_signal_unpacked(priv, &signal, &bulkdata); if (r) { - unifi_error(priv, "CsrWifiSmeRoamCompleteIndHandler: failed to send QOS data null packet result: %d\n",r); + unifi_error(priv, "CsrWifiSmeRoamCompleteIndHandler: failed to send QOS data null packet result: %d\n", r); unifi_net_data_free(priv, &bulkdata.d[0]); return; } @@ -574,7 +574,7 @@ configure_data_port(unifi_priv_t *priv, /* If port is closed, discard all the pending Rx packets */ if (port_action == CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_DISCARD) { - uf_free_pending_rx_packets(priv, queue, *macAddress,interfaceTag); + uf_free_pending_rx_packets(priv, queue, *macAddress, interfaceTag); } } } else { @@ -645,7 +645,7 @@ configure_data_port(unifi_priv_t *priv, * coming from the peer station. */ if (port_action == CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_DISCARD) { - uf_free_pending_rx_packets(priv, queue, *macAddress,interfaceTag); + uf_free_pending_rx_packets(priv, queue, *macAddress, interfaceTag); } unifi_trace(priv, UDBG2, @@ -712,7 +712,7 @@ void CsrWifiRouterCtrlPortConfigureReqHandler(void* drvpriv, CsrWifiFsmEvent* ms configure_data_port(priv, req->controlledPortAction, (const CsrWifiMacAddress *)&req->macAddress, UF_CONTROLLED_PORT_Q, req->interfaceTag); - CsrWifiRouterCtrlPortConfigureCfmSend(msg->source,req->clientData,req->interfaceTag, + CsrWifiRouterCtrlPortConfigureCfmSend(msg->source, req->clientData, req->interfaceTag, CSR_RESULT_SUCCESS, req->macAddress); unifi_trace(priv, UDBG3, "leaving CsrWifiRouterCtrlPortConfigureReqHandler\n"); } @@ -723,7 +723,7 @@ void CsrWifiRouterCtrlWifiOnReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) unifi_priv_t *priv = (unifi_priv_t*)drvpriv; CsrWifiRouterCtrlVersions versions; CsrWifiRouterCtrlWifiOnReq* req = (CsrWifiRouterCtrlWifiOnReq*)msg; - int r,i; + int r, i; CsrResult csrResult; if (priv == NULL) { @@ -963,7 +963,7 @@ void CsrWifiRouterCtrlWifiOffReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) } wifi_off(priv); - CsrWifiRouterCtrlWifiOffCfmSend(msg->source,req->clientData); + CsrWifiRouterCtrlWifiOffCfmSend(msg->source, req->clientData); /* If this is called in response to closing the character device, the * caller must use uf_sme_cancel_request() to terminate any pending SME @@ -1239,7 +1239,7 @@ void CsrWifiRouterMaPacketSubscribeReqHandler(void* drvpriv, CsrWifiFsmEvent* ms unifi_trace(priv, UDBG1, "subscribe_req: encap=%d, handle=%d, result=%d\n", req->encapsulation, i, result); - CsrWifiRouterMaPacketSubscribeCfmSend(msg->source,req->interfaceTag, i, result, 0); + CsrWifiRouterMaPacketSubscribeCfmSend(msg->source, req->interfaceTag, i, result, 0); } @@ -1268,7 +1268,7 @@ void CsrWifiRouterMaPacketUnsubscribeReqHandler(void* drvpriv, CsrWifiFsmEvent* unifi_trace(priv, UDBG1, "unsubscribe_req: handle=%d, result=%d\n", req->subscriptionHandle, result); - CsrWifiRouterMaPacketUnsubscribeCfmSend(msg->source,req->interfaceTag, result); + CsrWifiRouterMaPacketUnsubscribeCfmSend(msg->source, req->interfaceTag, result); } @@ -1282,7 +1282,7 @@ void CsrWifiRouterCtrlCapabilitiesReqHandler(void* drvpriv, CsrWifiFsmEvent* msg return; } - CsrWifiRouterCtrlCapabilitiesCfmSend(msg->source,req->clientData, + CsrWifiRouterCtrlCapabilitiesCfmSend(msg->source, req->clientData, UNIFI_SOFT_COMMAND_Q_LENGTH - 1, UNIFI_SOFT_TRAFFIC_Q_LENGTH - 1); } @@ -1404,7 +1404,7 @@ _sys_packet_req(unifi_priv_t *priv, const CSR_SIGNAL *signal, if (r) { unifi_error(priv, "_sys_packet_req: failed to translate eth frame.\n"); - unifi_net_data_free(priv,&bulkdata.d[0]); + unifi_net_data_free(priv, &bulkdata.d[0]); return r; } @@ -1439,7 +1439,7 @@ _sys_packet_req(unifi_priv_t *priv, const CSR_SIGNAL *signal, #ifdef CSR_SUPPORT_SME if ((protection = uf_get_protection_bit_from_interfacemode(priv, interfaceTag, peerMacAddress.a)) < 0) { unifi_error(priv, "unicast address, but destination not in station record database\n"); - unifi_net_data_free(priv,&bulkdata.d[0]); + unifi_net_data_free(priv, &bulkdata.d[0]); return -1; } #else @@ -1453,7 +1453,7 @@ _sys_packet_req(unifi_priv_t *priv, const CSR_SIGNAL *signal, /* add Mac header */ if (prepare_and_add_macheader(priv, skb, newSkb, req.Priority, &bulkdata, interfaceTag, frame, frame + ETH_ALEN, protection)) { unifi_error(priv, "failed to create MAC header\n"); - unifi_net_data_free(priv,&bulkdata.d[0]); + unifi_net_data_free(priv, &bulkdata.d[0]); return -1; } @@ -1479,7 +1479,7 @@ _sys_packet_req(unifi_priv_t *priv, const CSR_SIGNAL *signal, if (r) { unifi_error(priv, "_sys_packet_req: failed to send signal.\n"); - unifi_net_data_free(priv,&bulkdata.d[0]); + unifi_net_data_free(priv, &bulkdata.d[0]); return r; } /* The final CsrWifiRouterMaPacketCfmSend() will called when the actual MA-PACKET.cfm is received from the chip */ @@ -1558,7 +1558,7 @@ void CsrWifiRouterMaPacketReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) memcpy(req->Ra.x, daddr, ETH_ALEN); req->Priority = mareq->priority; req->TransmitRate = 0; /* Let firmware select the rate*/ - req->VirtualInterfaceIdentifier = uf_get_vif_identifier(interfacePriv->interfaceMode,interfaceTag); + req->VirtualInterfaceIdentifier = uf_get_vif_identifier(interfacePriv->interfaceMode, interfaceTag); req->HostTag = mareq->hostTag; if(mareq->cfmRequested) @@ -1571,7 +1571,7 @@ void CsrWifiRouterMaPacketReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) if (r && mareq->cfmRequested) { - CsrWifiRouterMaPacketCfmSend(msg->source,interfaceTag, + CsrWifiRouterMaPacketCfmSend(msg->source, interfaceTag, CSR_RESULT_FAILURE, mareq->hostTag, 0); } @@ -1637,7 +1637,7 @@ void CsrWifiRouterCtrlM4TransmitReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) /* reset the station records when the mode is set as CSR_WIFI_ROUTER_CTRL_MODE_NONE */ static void CsrWifiRouterCtrlResetStationRecordList(unifi_priv_t *priv, u16 interfaceTag) { - u8 i,j; + u8 i, j; CsrWifiRouterCtrlStaInfo_t *staInfo=NULL; netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag]; unsigned long lock_flags; @@ -1658,15 +1658,15 @@ static void CsrWifiRouterCtrlResetStationRecordList(unifi_priv_t *priv, u16 inte uf_prepare_send_cfm_list_for_queued_pkts(priv, &send_cfm_list, &(staInfo->mgtFrames)); - uf_flush_list(priv,&(staInfo->mgtFrames)); + uf_flush_list(priv, &(staInfo->mgtFrames)); for(j=0;jdataPdu[j])); - uf_flush_list(priv,&(staInfo->dataPdu[j])); + uf_flush_list(priv, &(staInfo->dataPdu[j])); } - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); /* Removing station record information from port config array */ memset(staInfo->peerControlledPort, 0, sizeof(unifi_port_cfg_t)); staInfo->peerControlledPort->port_action = CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_DISCARD; @@ -1680,7 +1680,7 @@ static void CsrWifiRouterCtrlResetStationRecordList(unifi_priv_t *priv, u16 inte kfree(interfacePriv->staInfo[i]); interfacePriv->staInfo[i] = NULL; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); } } /* after the critical region process the list of frames that requested cfm @@ -1697,9 +1697,9 @@ static void CsrWifiRouterCtrlResetStationRecordList(unifi_priv_t *priv, u16 inte case CSR_WIFI_ROUTER_CTRL_MODE_NONE: if (priv->noOfPktQueuedInDriver) { unifi_warning(priv, "After reset the noOfPktQueuedInDriver = %x\n", priv->noOfPktQueuedInDriver); - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); priv->noOfPktQueuedInDriver = 0; - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); } break; case CSR_WIFI_ROUTER_CTRL_MODE_IBSS: @@ -1745,18 +1745,18 @@ void CsrWifiRouterCtrlInterfaceReset(unifi_priv_t *priv, u16 interfaceTag) uf_prepare_send_cfm_list_for_queued_pkts(priv, &send_cfm_list, &(interfacePriv->genericMgtFrames)); - uf_flush_list(priv,&(interfacePriv->genericMgtFrames)); + uf_flush_list(priv, &(interfacePriv->genericMgtFrames)); uf_prepare_send_cfm_list_for_queued_pkts(priv, &send_cfm_list, &(interfacePriv->genericMulticastOrBroadCastMgtFrames)); - uf_flush_list(priv,&(interfacePriv->genericMulticastOrBroadCastMgtFrames)); + uf_flush_list(priv, &(interfacePriv->genericMulticastOrBroadCastMgtFrames)); uf_prepare_send_cfm_list_for_queued_pkts(priv, &send_cfm_list, &(interfacePriv->genericMulticastOrBroadCastFrames)); - uf_flush_list(priv,&(interfacePriv->genericMulticastOrBroadCastFrames)); + uf_flush_list(priv, &(interfacePriv->genericMulticastOrBroadCastFrames)); /* process the list of frames that requested cfm and send cfm to requestor one by one */ @@ -1772,7 +1772,7 @@ void CsrWifiRouterCtrlInterfaceReset(unifi_priv_t *priv, u16 interfaceTag) /* station records not available in these modes */ break; default: - CsrWifiRouterCtrlResetStationRecordList(priv,interfaceTag); + CsrWifiRouterCtrlResetStationRecordList(priv, interfaceTag); } interfacePriv->num_stations_joined = 0; @@ -1880,7 +1880,7 @@ void CsrWifiRouterCtrlModeSetReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) * other then CSR_WIFI_TIM_SET or CSR_WIFI_TIM_RESET value */ interfacePriv->bcTimSetReqQueued =0xFF; - CsrWifiRouterCtrlInterfaceReset(priv,req->interfaceTag); + CsrWifiRouterCtrlInterfaceReset(priv, req->interfaceTag); if(req->mode == CSR_WIFI_ROUTER_CTRL_MODE_AP || req->mode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) { @@ -1900,7 +1900,7 @@ void CsrWifiRouterCtrlModeSetReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) } } else { - unifi_error(priv, "CsrWifiRouterCtrlModeSetReqHandler: invalid interfaceTag :%d\n",req->interfaceTag); + unifi_error(priv, "CsrWifiRouterCtrlModeSetReqHandler: invalid interfaceTag :%d\n", req->interfaceTag); } } @@ -1941,15 +1941,15 @@ static int peer_delete_record(unifi_priv_t *priv, CsrWifiRouterCtrlPeerDelReq *r &send_cfm_list, &(staInfo->mgtFrames)); - uf_flush_list(priv,&(staInfo->mgtFrames)); + uf_flush_list(priv, &(staInfo->mgtFrames)); for(j=0;jdataPdu[j])); - uf_flush_list(priv,&(staInfo->dataPdu[j])); + uf_flush_list(priv, &(staInfo->dataPdu[j])); } - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); /* clear the port configure array info, for the corresponding peer entry */ controlledPort = &interfacePriv->controlled_data_port; unControlledPort = &interfacePriv->uncontrolled_data_port; @@ -1975,12 +1975,12 @@ static int peer_delete_record(unifi_priv_t *priv, CsrWifiRouterCtrlPeerDelReq *r unifi_warning(priv, "number of uncontrolled port entries is zero, trying to decrement: debug\n"); } - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); /* update the TIM with zero */ if (interfacePriv->interfaceMode != CSR_WIFI_ROUTER_CTRL_MODE_IBSS && staInfo->timSet == CSR_WIFI_TIM_SET) { unifi_trace(priv, UDBG3, "peer is deleted so TIM updated to 0, in firmware\n"); - update_tim(priv,staInfo->aid,0,req->interfaceTag, req->peerRecordHandle); + update_tim(priv, staInfo->aid, 0, req->interfaceTag, req->peerRecordHandle); } @@ -2021,7 +2021,7 @@ static int peer_delete_record(unifi_priv_t *priv, CsrWifiRouterCtrlPeerDelReq *r cancel_work_sync(&staInfo->send_disconnected_ind_task); #endif - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); #ifdef CSR_SUPPORT_SME interfacePriv->num_stations_joined--; @@ -2039,7 +2039,7 @@ static int peer_delete_record(unifi_priv_t *priv, CsrWifiRouterCtrlPeerDelReq *r /* Free the station record for corresponding peer */ kfree(interfacePriv->staInfo[req->peerRecordHandle]); interfacePriv->staInfo[req->peerRecordHandle] = NULL; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); /* after the critical region process the list of frames that requested cfm and send cfm to requestor one by one */ @@ -2092,12 +2092,12 @@ void CsrWifiRouterCtrlPeerDelReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) break; } - CsrWifiRouterCtrlPeerDelCfmSend(msg->source,req->clientData,req->interfaceTag,status); + CsrWifiRouterCtrlPeerDelCfmSend(msg->source, req->clientData, req->interfaceTag, status); unifi_trace(priv, UDBG2, "leaving CsrWifiRouterCtrlPeerDelReqHandler \n"); } /* Add the new station to the station record data base */ -static int peer_add_new_record(unifi_priv_t *priv,CsrWifiRouterCtrlPeerAddReq *req,u32 *handle) +static int peer_add_new_record(unifi_priv_t *priv, CsrWifiRouterCtrlPeerAddReq *req, u32 *handle) { u8 i, powerModeTemp = 0; u8 freeSlotFound = FALSE; @@ -2135,11 +2135,11 @@ static int peer_add_new_record(unifi_priv_t *priv,CsrWifiRouterCtrlPeerAddReq *r req->staInfo.listenIntervalInTus); /* disable the preemption until station record updated */ - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); interfacePriv->staInfo[i] = newRecord; /* Initialize the record*/ - memset(newRecord,0,sizeof(CsrWifiRouterCtrlStaInfo_t)); + memset(newRecord, 0, sizeof(CsrWifiRouterCtrlStaInfo_t)); /* update the station record */ memcpy(newRecord->peerMacAddress.a, req->peerMacAddress.a, ETH_ALEN); newRecord->wmmOrQosEnabled = req->staInfo.wmmOrQosEnabled; @@ -2182,11 +2182,11 @@ static int peer_add_new_record(unifi_priv_t *priv,CsrWifiRouterCtrlPeerAddReq *r u8 k; for(k=0; k< MAX_ACCESS_CATOGORY ;k++) unifi_trace(priv, UDBG2, "peer_add_new_record: WMM : %d ,AC %d, powersaveMode %x \n", - req->staInfo.wmmOrQosEnabled,k,newRecord->powersaveMode[k]); + req->staInfo.wmmOrQosEnabled, k, newRecord->powersaveMode[k]); } unifi_trace(priv, UDBG3, "newRecord->wmmOrQosEnabled : %d , MAX SP : %d\n", - newRecord->wmmOrQosEnabled,newRecord->maxSpLength); + newRecord->wmmOrQosEnabled, newRecord->maxSpLength); /* Initialize the mgtFrames & data Pdu list */ { @@ -2201,7 +2201,7 @@ static int peer_add_new_record(unifi_priv_t *priv,CsrWifiRouterCtrlPeerAddReq *r newRecord->activity_flag = TRUE; /* enable the preemption as station record updated */ - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); /* First time port actions are set for the peer with below information */ configure_data_port(priv, CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN, &newRecord->peerMacAddress, @@ -2216,7 +2216,7 @@ static int peer_add_new_record(unifi_priv_t *priv,CsrWifiRouterCtrlPeerAddReq *r } - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); /* Port status must be already set before calling the Add Peer request */ newRecord->peerControlledPort = uf_sme_port_config_handle(priv, newRecord->peerMacAddress.a, UF_CONTROLLED_PORT_Q, req->interfaceTag); @@ -2228,7 +2228,7 @@ static int peer_add_new_record(unifi_priv_t *priv,CsrWifiRouterCtrlPeerAddReq *r unifi_warning(priv, "Un/ControlledPort record not found in port configuration array index = %d\n", i); kfree(interfacePriv->staInfo[i]); interfacePriv->staInfo[i] = NULL; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); return CSR_RESULT_FAILURE; } @@ -2279,7 +2279,7 @@ static int peer_add_new_record(unifi_priv_t *priv,CsrWifiRouterCtrlPeerAddReq *r } #endif - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); break; } } @@ -2446,7 +2446,7 @@ void uf_send_disconnected_ind_wq(struct work_struct *work) &send_cfm_list, &(staInfo->dataPdu[j])); - uf_flush_list(priv,&(staInfo->dataPdu[j])); + uf_flush_list(priv, &(staInfo->dataPdu[j])); } send_auto_ma_packet_confirm(priv, staInfo->interfacePriv, &send_cfm_list); @@ -2471,7 +2471,7 @@ void uf_send_disconnected_ind_wq(struct work_struct *work) #endif -void CsrWifiRouterCtrlPeerAddReqHandler(void* drvpriv,CsrWifiFsmEvent* msg) +void CsrWifiRouterCtrlPeerAddReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) { CsrWifiRouterCtrlPeerAddReq* req = (CsrWifiRouterCtrlPeerAddReq*)msg; CsrResult status = CSR_RESULT_SUCCESS; @@ -2500,7 +2500,7 @@ void CsrWifiRouterCtrlPeerAddReqHandler(void* drvpriv,CsrWifiFsmEvent* msg) case CSR_WIFI_ROUTER_CTRL_MODE_IBSS: case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO: /* Add station record */ - status = peer_add_new_record(priv,req,&handle); + status = peer_add_new_record(priv, req, &handle); break; case CSR_WIFI_ROUTER_CTRL_MODE_STA: case CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI: @@ -2509,11 +2509,11 @@ void CsrWifiRouterCtrlPeerAddReqHandler(void* drvpriv,CsrWifiFsmEvent* msg) break; } - CsrWifiRouterCtrlPeerAddCfmSend(msg->source,req->clientData,req->interfaceTag,req->peerMacAddress,handle,status); + CsrWifiRouterCtrlPeerAddCfmSend(msg->source, req->clientData, req->interfaceTag, req->peerMacAddress, handle, status); unifi_trace(priv, UDBG2, "leaving CsrWifiRouterCtrlPeerAddReqHandler \n"); } -void CsrWifiRouterCtrlPeerUpdateReqHandler(void* drvpriv,CsrWifiFsmEvent* msg) +void CsrWifiRouterCtrlPeerUpdateReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) { CsrWifiRouterCtrlPeerUpdateReq* req = (CsrWifiRouterCtrlPeerUpdateReq*)msg; CsrResult status = CSR_RESULT_SUCCESS; @@ -2526,7 +2526,7 @@ void CsrWifiRouterCtrlPeerUpdateReqHandler(void* drvpriv,CsrWifiFsmEvent* msg) return; } - CsrWifiRouterCtrlPeerUpdateCfmSend(msg->source,req->clientData,req->interfaceTag,status); + CsrWifiRouterCtrlPeerUpdateCfmSend(msg->source, req->clientData, req->interfaceTag, status); unifi_trace(priv, UDBG2, "leaving CsrWifiRouterCtrlPeerUpdateReqHandler \n"); } @@ -2986,13 +2986,13 @@ void CsrWifiRouterCtrlWapiMulticastFilterReqHandler(void* drvpriv, CsrWifiFsmEve unifi_trace(priv, UDBG6, "<<%s\n", __FUNCTION__); } else { - unifi_warning(priv, "%s is NOT applicable for interface mode - %d\n", __FUNCTION__,interfacePriv->interfaceMode); + unifi_warning(priv, "%s is NOT applicable for interface mode - %d\n", __FUNCTION__, interfacePriv->interfaceMode); } #elif defined(UNIFI_DEBUG) /*WAPI Disabled*/ unifi_priv_t *priv = (unifi_priv_t*)drvpriv; - unifi_error(priv,"CsrWifiRouterCtrlWapiMulticastFilterReqHandler: called when WAPI isn't enabled\n"); + unifi_error(priv, "CsrWifiRouterCtrlWapiMulticastFilterReqHandler: called when WAPI isn't enabled\n"); #endif } @@ -3022,13 +3022,13 @@ void CsrWifiRouterCtrlWapiUnicastFilterReqHandler(void* drvpriv, CsrWifiFsmEvent unifi_trace(priv, UDBG6, "<<%s\n", __FUNCTION__); } else { - unifi_warning(priv, "%s is NOT applicable for interface mode - %d\n", __FUNCTION__,interfacePriv->interfaceMode); + unifi_warning(priv, "%s is NOT applicable for interface mode - %d\n", __FUNCTION__, interfacePriv->interfaceMode); } #elif defined(UNIFI_DEBUG) /*WAPI Disabled*/ unifi_priv_t *priv = (unifi_priv_t*)drvpriv; - unifi_error(priv,"CsrWifiRouterCtrlWapiUnicastFilterReqHandler: called when WAPI isn't enabled\n"); + unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastFilterReqHandler: called when WAPI isn't enabled\n"); #endif } @@ -3064,13 +3064,13 @@ void CsrWifiRouterCtrlWapiRxPktReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) if (req->dataLength == 0 || req->data == NULL) { - unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq: invalid request\n",__FUNCTION__); + unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq: invalid request\n", __FUNCTION__); return; } res = unifi_net_data_malloc(priv, &bulkdata.d[0], req->dataLength); if (res != CSR_RESULT_SUCCESS) { - unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq: Could not allocate net data\n",__FUNCTION__); + unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq: Could not allocate net data\n", __FUNCTION__); return; } @@ -3078,15 +3078,15 @@ void CsrWifiRouterCtrlWapiRxPktReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) * So reset the reception status to rx_success */ res = read_unpack_signal(req->signal, &signal); if (res) { - unifi_error(priv,"CsrWifiRouterCtrlWapiRxPktReqHandler: Received unknown or corrupted signal.\n"); + unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReqHandler: Received unknown or corrupted signal.\n"); return; } pkt_ind = (CSR_MA_PACKET_INDICATION*) (&((&signal)->u).MaPacketIndication); if (pkt_ind->ReceptionStatus != CSR_MICHAEL_MIC_ERROR) { - unifi_error(priv,"CsrWifiRouterCtrlWapiRxPktReqHandler: Unknown signal with reception status = %d\n",pkt_ind->ReceptionStatus); + unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReqHandler: Unknown signal with reception status = %d\n", pkt_ind->ReceptionStatus); return; } else { - unifi_trace(priv, UDBG4,"CsrWifiRouterCtrlWapiRxPktReqHandler: MIC verified , RX_SUCCESS \n",__FUNCTION__); + unifi_trace(priv, UDBG4, "CsrWifiRouterCtrlWapiRxPktReqHandler: MIC verified , RX_SUCCESS \n", __FUNCTION__); pkt_ind->ReceptionStatus = CSR_RX_SUCCESS; write_pack(&signal, req->signal, &(req->signalLength)); } @@ -3113,12 +3113,12 @@ void CsrWifiRouterCtrlWapiRxPktReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) unifi_trace(priv, UDBG6, "<<%s\n", __FUNCTION__); } else { - unifi_warning(priv, "%s is NOT applicable for interface mode - %d\n", __FUNCTION__,interfacePriv->interfaceMode); + unifi_warning(priv, "%s is NOT applicable for interface mode - %d\n", __FUNCTION__, interfacePriv->interfaceMode); } #elif defined(UNIFI_DEBUG) /*WAPI Disabled*/ unifi_priv_t *priv = (unifi_priv_t*)drvpriv; - unifi_error(priv,"CsrWifiRouterCtrlWapiRxPktReqHandler: called when WAPI isn't enabled\n"); + unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReqHandler: called when WAPI isn't enabled\n"); #endif } @@ -3142,15 +3142,15 @@ void CsrWifiRouterCtrlWapiUnicastTxPktReqHandler(void* drvpriv, CsrWifiFsmEvent* unifi_trace(priv, UDBG6, ">>%s\n", __FUNCTION__); if (priv == NULL) { - unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastTxPktReqHandler : invalid priv\n",__FUNCTION__); + unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastTxPktReqHandler : invalid priv\n", __FUNCTION__); return; } if (priv->smepriv == NULL) { - unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastTxPktReqHandler : invalid sme priv\n",__FUNCTION__); + unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastTxPktReqHandler : invalid sme priv\n", __FUNCTION__); return; } if (req->data == NULL) { - unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastTxPktReqHandler: invalid request\n",__FUNCTION__); + unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastTxPktReqHandler: invalid request\n", __FUNCTION__); return; } else { /* If it is QoS data (type = data subtype = QoS), frame header contains QoS control field */ @@ -3159,7 +3159,7 @@ void CsrWifiRouterCtrlWapiUnicastTxPktReqHandler(void* drvpriv, CsrWifiFsmEvent* } } if ( !(req->dataLength>(macHeaderLengthInBytes+appendedCryptoFields)) ) { - unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastTxPktReqHandler: invalid dataLength\n",__FUNCTION__); + unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastTxPktReqHandler: invalid dataLength\n", __FUNCTION__); return; } @@ -3174,7 +3174,7 @@ void CsrWifiRouterCtrlWapiUnicastTxPktReqHandler(void* drvpriv, CsrWifiFsmEvent* */ result = unifi_net_data_malloc(priv, &bulkdata.d[0], req->dataLength); if (result != CSR_RESULT_SUCCESS) { - unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastTxPktReqHandler: Could not allocate net data\n",__FUNCTION__); + unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastTxPktReqHandler: Could not allocate net data\n", __FUNCTION__); return; } memcpy((void*)bulkdata.d[0].os_data_ptr, req->data, req->dataLength); @@ -3217,13 +3217,13 @@ void CsrWifiRouterCtrlWapiUnicastTxPktReqHandler(void* drvpriv, CsrWifiFsmEvent* } else { - unifi_warning(priv, "%s is NOT applicable for interface mode - %d\n", __FUNCTION__,interfacePriv->interfaceMode); + unifi_warning(priv, "%s is NOT applicable for interface mode - %d\n", __FUNCTION__, interfacePriv->interfaceMode); } #elif defined(UNIFI_DEBUG) /*WAPI Disabled*/ unifi_priv_t *priv = (unifi_priv_t*)drvpriv; - unifi_error(priv,"CsrWifiRouterCtrlWapiUnicastTxPktReqHandler: called when WAPI SW ENCRYPTION isn't enabled\n"); + unifi_error(priv, "CsrWifiRouterCtrlWapiUnicastTxPktReqHandler: called when WAPI SW ENCRYPTION isn't enabled\n"); #endif } @@ -3240,14 +3240,14 @@ void CsrWifiRouterCtrlWapiFilterReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) unifi_trace(priv, UDBG6, ">>%s\n", __FUNCTION__); - unifi_trace(priv, UDBG1, "CsrWifiRouterCtrlWapiFilterReq: req->isWapiConnected [0/1] = %d \n",req->isWapiConnected); + unifi_trace(priv, UDBG1, "CsrWifiRouterCtrlWapiFilterReq: req->isWapiConnected [0/1] = %d \n", req->isWapiConnected); priv->isWapiConnection = req->isWapiConnected; unifi_trace(priv, UDBG6, "<<%s\n", __FUNCTION__); } else { - unifi_warning(priv, "%s is NOT applicable for interface mode - %d\n", __FUNCTION__,interfacePriv->interfaceMode); + unifi_warning(priv, "%s is NOT applicable for interface mode - %d\n", __FUNCTION__, interfacePriv->interfaceMode); } #endif @@ -3255,6 +3255,6 @@ void CsrWifiRouterCtrlWapiFilterReqHandler(void* drvpriv, CsrWifiFsmEvent* msg) #elif defined(UNIFI_DEBUG) /*WAPI Disabled*/ unifi_priv_t *priv = (unifi_priv_t*)drvpriv; - unifi_error(priv,"CsrWifiRouterCtrlWapiFilterReq: called when WAPI isn't enabled\n"); + unifi_error(priv, "CsrWifiRouterCtrlWapiFilterReq: called when WAPI isn't enabled\n"); #endif } diff --git a/drivers/staging/csr/sme_userspace.c b/drivers/staging/csr/sme_userspace.c index abcb446fb8c0..b919b001ef7c 100644 --- a/drivers/staging/csr/sme_userspace.c +++ b/drivers/staging/csr/sme_userspace.c @@ -118,7 +118,7 @@ uf_sme_init(unifi_priv_t *priv) void uf_sme_deinit(unifi_priv_t *priv) { - int i,j; + int i, j; u8 ba_session_idx; ba_session_rx_struct *ba_session_rx = NULL; ba_session_tx_struct *ba_session_tx = NULL; @@ -224,7 +224,7 @@ unifi_ta_indicate_protocol(void *ospriv, if (CSR_WIFI_ROUTER_CTRL_PROTOCOL_DIRECTION_RX == direction) { u16 interfaceTag = 0; - CsrWifiRouterCtrlTrafficProtocolIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0, + CsrWifiRouterCtrlTrafficProtocolIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, packet_type, direction, diff --git a/drivers/staging/csr/sme_wext.c b/drivers/staging/csr/sme_wext.c index 4129a6436b76..84f11cb53596 100644 --- a/drivers/staging/csr/sme_wext.c +++ b/drivers/staging/csr/sme_wext.c @@ -120,7 +120,7 @@ channel_to_mhz(int ch, int dot11a) #ifdef CSR_SUPPORT_WEXT_AP void uf_sme_wext_ap_set_defaults(unifi_priv_t *priv) { - memcpy(priv->ap_config.ssid.ssid,"defaultssid",sizeof("defaultssid")); + memcpy(priv->ap_config.ssid.ssid, "defaultssid", sizeof("defaultssid")); priv->ap_config.ssid.length = 8; priv->ap_config.channel = 6; @@ -202,7 +202,7 @@ void uf_sme_wext_ap_set_defaults(unifi_priv_t *priv) to enable different types of devices to join us */ priv->ap_mac_config.supportedRatesCount = - uf_configure_supported_rates(priv->ap_mac_config.supportedRates,priv->ap_mac_config.phySupportedBitmap); + uf_configure_supported_rates(priv->ap_mac_config.supportedRates, priv->ap_mac_config.phySupportedBitmap); } #endif /* @@ -459,7 +459,7 @@ static int decode_parameter_from_string(unifi_priv_t* priv, char **str_ptr, { u8 int_str[7] = "0"; u32 param_str_len; - u8 *param_str_begin,*param_str_end; + u8 *param_str_begin, *param_str_end; u8 *orig_str = *str_ptr; if (!strncmp(*str_ptr, token, strlen(token))) { @@ -472,41 +472,41 @@ static int decode_parameter_from_string(unifi_priv_t* priv, char **str_ptr, param_str_end = *str_ptr-1; param_str_len = param_str_end - param_str_begin; } - unifi_trace(priv,UDBG2,"'token:%s', len:%d, ", token, param_str_len); + unifi_trace(priv, UDBG2, "'token:%s', len:%d, ", token, param_str_len); if (param_str_len > param_max_len) { - unifi_notice(priv,"extracted param len:%d is > MAX:%d\n",param_str_len, param_max_len); + unifi_notice(priv, "extracted param len:%d is > MAX:%d\n", param_str_len, param_max_len); param_str_len = param_max_len; } switch (param_type) { case PARAM_TYPE_INT: { - u32 *pdst_int = dst,num =0; - int i,j=0; + u32 *pdst_int = dst, num =0; + int i, j=0; if (param_str_len > sizeof(int_str)) { param_str_len = sizeof(int_str); } memcpy(int_str, param_str_begin, param_str_len); for(i = param_str_len; i>0;i--) { if(int_str[i-1] >= '0' && int_str[i-1] <='9') { - num += ((int_str[i-1]-'0')*power(10,j)); + num += ((int_str[i-1]-'0')*power(10, j)); j++; } else { - unifi_error(priv,"decode_parameter_from_string:not a number %c\n",(int_str[i-1])); + unifi_error(priv, "decode_parameter_from_string:not a number %c\n", (int_str[i-1])); return -1; } } *pdst_int = num; - unifi_trace(priv,UDBG2,"decode_parameter_from_string:decoded int = %d\n",*pdst_int); + unifi_trace(priv, UDBG2, "decode_parameter_from_string:decoded int = %d\n", *pdst_int); } break; default: memcpy(dst, param_str_begin, param_str_len); *((char *)dst + param_str_len) = 0; - unifi_trace(priv,UDBG2,"decode_parameter_from_string:decoded string = %s\n",(char *)dst); + unifi_trace(priv, UDBG2, "decode_parameter_from_string:decoded string = %s\n", (char *)dst); break; } } else { - unifi_error(priv,"decode_parameter_from_string: Token:%s not found in %s \n",token,orig_str); + unifi_error(priv, "decode_parameter_from_string: Token:%s not found in %s \n", token, orig_str); return -1; } return 0; @@ -514,7 +514,7 @@ static int decode_parameter_from_string(unifi_priv_t* priv, char **str_ptr, static int store_ap_advanced_config_from_string(unifi_priv_t *priv, char *param_str) { char * str_ptr=param_str; - int ret = 0,tmp_var; + int ret = 0, tmp_var; char phy_mode[6]; CsrWifiSmeApMacConfig * ap_mac_config = &priv->ap_mac_config; @@ -522,36 +522,36 @@ static int store_ap_advanced_config_from_string(unifi_priv_t *priv, char *param_ ret = decode_parameter_from_string(priv, &str_ptr, "BI=", PARAM_TYPE_INT, &tmp_var, 5); if(ret) { - unifi_error(priv,"store_ap_advanced_config_from_string: BI not found\n"); + unifi_error(priv, "store_ap_advanced_config_from_string: BI not found\n"); return -1; } ap_mac_config->beaconInterval = tmp_var; ret = decode_parameter_from_string(priv, &str_ptr, "DTIM_PER=", PARAM_TYPE_INT, &tmp_var, 5); if(ret) { - unifi_error(priv,"store_ap_advanced_config_from_string: DTIM_PER not found\n"); + unifi_error(priv, "store_ap_advanced_config_from_string: DTIM_PER not found\n"); return -1; } ap_mac_config->dtimPeriod = tmp_var; ret = decode_parameter_from_string(priv, &str_ptr, "WMM=", PARAM_TYPE_INT, &tmp_var, 5); if(ret) { - unifi_error(priv,"store_ap_advanced_config_from_string: WMM not found\n"); + unifi_error(priv, "store_ap_advanced_config_from_string: WMM not found\n"); return -1; } ap_mac_config->wmmEnabled = tmp_var; ret = decode_parameter_from_string(priv, &str_ptr, "PHY=", PARAM_TYPE_STRING, phy_mode, 5); if(ret) { - unifi_error(priv,"store_ap_advanced_config_from_string: PHY not found\n"); + unifi_error(priv, "store_ap_advanced_config_from_string: PHY not found\n"); } else { - if(strstr(phy_mode,"b")){ + if(strstr(phy_mode, "b")){ ap_mac_config->phySupportedBitmap = CSR_WIFI_SME_AP_PHY_SUPPORT_B; } - if(strstr(phy_mode,"g")) { + if(strstr(phy_mode, "g")) { ap_mac_config->phySupportedBitmap |= CSR_WIFI_SME_AP_PHY_SUPPORT_G; } - if(strstr(phy_mode,"n")) { + if(strstr(phy_mode, "n")) { ap_mac_config->phySupportedBitmap |= CSR_WIFI_SME_AP_PHY_SUPPORT_N; } ap_mac_config->supportedRatesCount = @@ -560,39 +560,39 @@ static int store_ap_advanced_config_from_string(unifi_priv_t *priv, char *param_ return ret; } -static int store_ap_config_from_string( unifi_priv_t * priv,char *param_str) +static int store_ap_config_from_string( unifi_priv_t * priv, char *param_str) { char *str_ptr = param_str; char sub_cmd[16]; char sec[CSR_WIFI_MAX_SEC_LEN]; char key[CSR_WIFI_MAX_KEY_LEN]; - int ret = 0,tmp_var; + int ret = 0, tmp_var; CsrWifiSmeApConfig_t *ap_config = &priv->ap_config; CsrWifiSmeApMacConfig * ap_mac_config = &priv->ap_mac_config; memset(sub_cmd, 0, sizeof(sub_cmd)); - if(!strstr(param_str,"END")) { - unifi_error(priv,"store_ap_config_from_string:Invalid config string:%s\n",param_str); + if(!strstr(param_str, "END")) { + unifi_error(priv, "store_ap_config_from_string:Invalid config string:%s\n", param_str); return -1; } - if (decode_parameter_from_string(priv,&str_ptr, "ASCII_CMD=", + if (decode_parameter_from_string(priv, &str_ptr, "ASCII_CMD=", PARAM_TYPE_STRING, sub_cmd, 6) != 0) { return -1; } if (strncmp(sub_cmd, "AP_CFG", 6)) { - if(!strncmp(sub_cmd ,"ADVCFG", 6)) { + if(!strncmp(sub_cmd , "ADVCFG", 6)) { return store_ap_advanced_config_from_string(priv, str_ptr); } - unifi_error(priv,"store_ap_config_from_string: sub_cmd:%s != 'AP_CFG or ADVCFG'!\n", sub_cmd); + unifi_error(priv, "store_ap_config_from_string: sub_cmd:%s != 'AP_CFG or ADVCFG'!\n", sub_cmd); return -1; } memset(ap_config, 0, sizeof(CsrWifiSmeApConfig_t)); - ret = decode_parameter_from_string(priv,&str_ptr, "SSID=", + ret = decode_parameter_from_string(priv, &str_ptr, "SSID=", PARAM_TYPE_STRING, ap_config->ssid.ssid, CSR_WIFI_MAX_SSID_LEN); if(ret) { - unifi_error(priv,"store_ap_config_from_string: SSID not found\n"); + unifi_error(priv, "store_ap_config_from_string: SSID not found\n"); return -1; } ap_config->ssid.length = strlen(ap_config->ssid.ssid); @@ -600,27 +600,27 @@ static int store_ap_config_from_string( unifi_priv_t * priv,char *param_str) ret = decode_parameter_from_string(priv, &str_ptr, "SEC=", PARAM_TYPE_STRING, sec, CSR_WIFI_MAX_SEC_LEN); if(ret) { - unifi_error(priv,"store_ap_config_from_string: SEC not found\n"); + unifi_error(priv, "store_ap_config_from_string: SEC not found\n"); return -1; } - ret = decode_parameter_from_string(priv,&str_ptr, "KEY=", - PARAM_TYPE_STRING, key, CSR_WIFI_MAX_KEY_LEN); - if(!strcasecmp(sec,"open")) { - unifi_trace(priv,UDBG2,"store_ap_config_from_string: security open"); + ret = decode_parameter_from_string(priv, &str_ptr, "KEY=", + PARAM_TYPE_STRING, key, CSR_WIFI_MAX_KEY_LEN); + if(!strcasecmp(sec, "open")) { + unifi_trace(priv, UDBG2, "store_ap_config_from_string: security open"); ap_config->credentials.authType = CSR_WIFI_SME_AP_AUTH_TYPE_OPEN_SYSTEM; if(ret) { - unifi_notice(priv,"store_ap_config_from_string: KEY not found:fine with Open\n"); + unifi_notice(priv, "store_ap_config_from_string: KEY not found:fine with Open\n"); } } - else if(!strcasecmp(sec,"wpa2-psk")) { - int i,j=0; + else if(!strcasecmp(sec, "wpa2-psk")) { + int i, j=0; CsrWifiNmeApAuthPers *pers = ((CsrWifiNmeApAuthPers *)&(ap_config->credentials.nmeAuthType.authTypePersonal)); u8 *psk = pers->authPers_credentials.psk.psk; - unifi_trace(priv,UDBG2,"store_ap_config_from_string: security WPA2"); + unifi_trace(priv, UDBG2, "store_ap_config_from_string: security WPA2"); if(ret) { - unifi_error(priv,"store_ap_config_from_string: KEY not found for WPA2\n"); + unifi_error(priv, "store_ap_config_from_string: KEY not found for WPA2\n"); return -1; } ap_config->credentials.authType = CSR_WIFI_SME_AP_AUTH_TYPE_PERSONAL; @@ -636,21 +636,21 @@ static int store_ap_config_from_string( unifi_priv_t * priv,char *param_str) } } else { - unifi_notice(priv,"store_ap_config_from_string: Unknown security: Assuming Open"); + unifi_notice(priv, "store_ap_config_from_string: Unknown security: Assuming Open"); ap_config->credentials.authType = CSR_WIFI_SME_AP_AUTH_TYPE_OPEN_SYSTEM; return -1; } /* Get the decoded value in a temp int variable to ensure that other fields within the struct which are of type other than int are not over written */ - ret = decode_parameter_from_string(priv,&str_ptr, "CHANNEL=", PARAM_TYPE_INT, &tmp_var, 5); + ret = decode_parameter_from_string(priv, &str_ptr, "CHANNEL=", PARAM_TYPE_INT, &tmp_var, 5); if(ret) return -1; ap_config->channel = tmp_var; - ret = decode_parameter_from_string(priv,&str_ptr, "PREAMBLE=", PARAM_TYPE_INT, &tmp_var, 5); + ret = decode_parameter_from_string(priv, &str_ptr, "PREAMBLE=", PARAM_TYPE_INT, &tmp_var, 5); if(ret) return -1; ap_mac_config->preamble = tmp_var; - ret = decode_parameter_from_string(priv,&str_ptr, "MAX_SCB=", PARAM_TYPE_INT, &tmp_var, 5); + ret = decode_parameter_from_string(priv, &str_ptr, "MAX_SCB=", PARAM_TYPE_INT, &tmp_var, 5); ap_config->max_connections = tmp_var; return ret; } @@ -664,9 +664,9 @@ iwprivsapstart(struct net_device *dev, struct iw_request_info *info, int r; unifi_trace(priv, UDBG1, "iwprivsapstart\n" ); - r = sme_ap_start(priv,interfacePriv->InterfaceTag,&priv->ap_config); + r = sme_ap_start(priv, interfacePriv->InterfaceTag, &priv->ap_config); if(r) { - unifi_error(priv,"iwprivsapstart AP START failed : %d\n",-r); + unifi_error(priv, "iwprivsapstart AP START failed : %d\n", -r); } return r; } @@ -692,28 +692,28 @@ iwprivsapconfig(struct net_device *dev, struct iw_request_info *info, return -EFAULT; } cfg_str[wrqu->data.length] = 0; - unifi_trace(priv,UDBG2,"length:%d\n",wrqu->data.length); - unifi_trace(priv,UDBG2,"AP configuration string:%s\n",cfg_str); + unifi_trace(priv, UDBG2, "length:%d\n", wrqu->data.length); + unifi_trace(priv, UDBG2, "AP configuration string:%s\n", cfg_str); str = cfg_str; - if ((r = store_ap_config_from_string(priv,str))) { - unifi_error(priv, "iwprivsapconfig:Failed to decode the string %d\n",r); + if ((r = store_ap_config_from_string(priv, str))) { + unifi_error(priv, "iwprivsapconfig:Failed to decode the string %d\n", r); kfree(cfg_str); return -EIO; } } else { - unifi_error(priv,"iwprivsapconfig argument length = 0 \n"); + unifi_error(priv, "iwprivsapconfig argument length = 0 \n"); return -EIO; } r = sme_ap_config(priv, &priv->ap_mac_config, &priv->group_sec_config); if(r) { - unifi_error(priv,"iwprivsapstop AP Config failed : %d\n",-r); + unifi_error(priv, "iwprivsapstop AP Config failed : %d\n", -r); } else if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP || interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) { unifi_trace(priv, UDBG1, "iwprivsapconfig: Starting the AP"); - r = sme_ap_start(priv,interfacePriv->InterfaceTag,&priv->ap_config); + r = sme_ap_start(priv, interfacePriv->InterfaceTag, &priv->ap_config); if(r) { - unifi_error(priv,"iwprivsapstart AP START failed : %d\n",-r); + unifi_error(priv, "iwprivsapstart AP START failed : %d\n", -r); } } kfree(cfg_str); @@ -730,9 +730,9 @@ iwprivsapstop(struct net_device *dev, struct iw_request_info *info, u16 interface_tag = interfacePriv->InterfaceTag; unifi_trace(priv, UDBG1, "iwprivsapstop\n" ); - r = sme_ap_stop(priv,interface_tag); + r = sme_ap_stop(priv, interface_tag); if(r) { - unifi_error(priv,"iwprivsapstop AP STOP failed : %d\n",-r); + unifi_error(priv, "iwprivsapstop AP STOP failed : %d\n", -r); } return r; } @@ -778,14 +778,14 @@ iwprivsstackstop(struct net_device *dev, struct iw_request_info *info, break; case CSR_WIFI_ROUTER_CTRL_MODE_AP: case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO: - r = sme_ap_stop(priv,interface_tag); + r = sme_ap_stop(priv, interface_tag); break; default : break; } if(r) { - unifi_error(priv,"iwprivsstackstop Stack stop failed : %d\n",-r); + unifi_error(priv, "iwprivsstackstop Stack stop failed : %d\n", -r); } return 0; } @@ -3167,7 +3167,7 @@ static const struct iw_priv_args unifi_private_args[] = { #endif #ifdef CSR_SUPPORT_WEXT_AP { SIOCIWSAPCFGPRIV, IW_PRIV_TYPE_CHAR | 256, IW_PRIV_TYPE_NONE, "AP_SET_CFG" }, - { SIOCIWSAPSTARTPRIV, 0,IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED|IWPRIV_SME_MAX_STRING,"AP_BSS_START" }, + { SIOCIWSAPSTARTPRIV, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED|IWPRIV_SME_MAX_STRING, "AP_BSS_START" }, { SIOCIWSAPSTOPPRIV, IW_PRIV_TYPE_CHAR |IW_PRIV_SIZE_FIXED|0, IW_PRIV_TYPE_CHAR |IW_PRIV_SIZE_FIXED|0, "AP_BSS_STOP" }, #ifdef ANDROID_BUILD diff --git a/drivers/staging/csr/ul_int.c b/drivers/staging/csr/ul_int.c index 0fae6f48f79b..eb286e5f7467 100644 --- a/drivers/staging/csr/ul_int.c +++ b/drivers/staging/csr/ul_int.c @@ -258,7 +258,7 @@ ul_log_config_ind(unifi_priv_t *priv, u8 *conf_param, int len) unifi_notice(priv, "ul_log_config_ind: wifi on in progress, suppress error\n"); } else { /* wifi_off_ind (error or exit) */ - CsrWifiRouterCtrlWifiOffIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0, (CsrWifiRouterCtrlControlIndication)(*conf_param)); + CsrWifiRouterCtrlWifiOffIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, (CsrWifiRouterCtrlControlIndication)(*conf_param)); } #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE unifi_debug_buf_dump(); diff --git a/drivers/staging/csr/unifi_event.c b/drivers/staging/csr/unifi_event.c index e81a99878272..71fdb2180e3d 100644 --- a/drivers/staging/csr/unifi_event.c +++ b/drivers/staging/csr/unifi_event.c @@ -105,7 +105,7 @@ static u8 check_routing_pkt_data_ind(unifi_priv_t *priv, u8 isDataFrameSubTypeNoData = FALSE; #ifdef CSR_WIFI_SECURITY_WAPI_ENABLE - static const u8 wapiProtocolIdSNAPHeader[] = {0x88,0xb4}; + static const u8 wapiProtocolIdSNAPHeader[] = {0x88, 0xb4}; static const u8 wapiProtocolIdSNAPHeaderOffset = 6; u8 *destAddr; u8 *srcAddr; @@ -206,7 +206,7 @@ static u8 check_routing_pkt_data_ind(unifi_priv_t *priv, unifi_trace(priv, UDBG4, "Discarding the contents of the frame with MIC failure \n"); if (isWapiUnicastPkt && - ((uf_sme_port_state(priv,srcAddr,UF_CONTROLLED_PORT_Q,interfaceTag) != CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN)|| + ((uf_sme_port_state(priv, srcAddr, UF_CONTROLLED_PORT_Q, interfaceTag) != CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN)|| #ifndef CSR_WIFI_SECURITY_WAPI_SW_ENCRYPTION (priv->wapi_unicast_filter) || #endif @@ -231,7 +231,7 @@ static u8 check_routing_pkt_data_ind(unifi_priv_t *priv, unifi_trace(priv, UDBG6, "check_routing_pkt_data_ind - MIC FAILURE : Dest Addr %x:%x:%x:%x:%x:%x\n", destAddr[0], destAddr[1], destAddr[2], destAddr[3], destAddr[4], destAddr[5]); unifi_trace(priv, UDBG6, "check_routing_pkt_data_ind - MIC FAILURE : Control Port State - 0x%.4X \n", - uf_sme_port_state(priv,srcAddr,UF_CONTROLLED_PORT_Q,interfaceTag)); + uf_sme_port_state(priv, srcAddr, UF_CONTROLLED_PORT_Q, interfaceTag)); unifi_error(priv, "MIC failure in %s\n", __FUNCTION__); @@ -285,9 +285,9 @@ static u8 check_routing_pkt_data_ind(unifi_priv_t *priv, if (llcSnapHeaderOffset > 0) { /* QoS data or Data */ - unifi_trace(priv, UDBG6, "check_routing_pkt_data_ind(): SNAP header found & its offset %d\n",llcSnapHeaderOffset); + unifi_trace(priv, UDBG6, "check_routing_pkt_data_ind(): SNAP header found & its offset %d\n", llcSnapHeaderOffset); if (memcmp((u8 *)(bulkdata->d[0].os_data_ptr+llcSnapHeaderOffset+wapiProtocolIdSNAPHeaderOffset), - wapiProtocolIdSNAPHeader,sizeof(wapiProtocolIdSNAPHeader))) { + wapiProtocolIdSNAPHeader, sizeof(wapiProtocolIdSNAPHeader))) { unifi_trace(priv, UDBG6, "check_routing_pkt_data_ind(): This is a data & NOT a WAI protocol packet\n"); /* On the first unicast data pkt that is decrypted successfully after re-keying, reset the filter */ @@ -584,14 +584,14 @@ void unifi_rx_queue_flush(void *ospriv) unifi_priv_t *priv = (unifi_priv_t*)ospriv; unifi_trace(priv, UDBG4, "rx_wq_handler: RdPtr = %d WritePtr = %d\n", - priv->rxSignalBuffer.readPointer,priv->rxSignalBuffer.writePointer); + priv->rxSignalBuffer.readPointer, priv->rxSignalBuffer.writePointer); if(priv != NULL) { u8 readPointer = priv->rxSignalBuffer.readPointer; while (readPointer != priv->rxSignalBuffer.writePointer) { rx_buff_struct_t *buf = &priv->rxSignalBuffer.rx_buff[readPointer]; unifi_trace(priv, UDBG6, "rx_wq_handler: RdPtr = %d WritePtr = %d\n", - readPointer,priv->rxSignalBuffer.writePointer); + readPointer, priv->rxSignalBuffer.writePointer); unifi_process_receive_event(priv, buf->bufptr, buf->sig_len, &buf->data_ptrs); readPointer ++; if(readPointer >= priv->rxSignalBuffer.size) { @@ -661,7 +661,7 @@ unifi_receive_event(void *ospriv, CSR_GET_UINT16_FROM_LITTLE_ENDIAN((sigdata) + sizeof(s16)*6) & 0xFFFF, CSR_GET_UINT16_FROM_LITTLE_ENDIAN((sigdata) + sizeof(s16)*7) & 0xFFFF, siglen); if(signal_buffer_is_full(priv)) { - unifi_error(priv,"TO HOST signal queue FULL dropping the PDU\n"); + unifi_error(priv, "TO HOST signal queue FULL dropping the PDU\n"); for (i = 0; i < UNIFI_MAX_DATA_REFERENCES; i++) { if (bulkdata->d[i].data_length != 0) { unifi_net_data_free(priv, (void *)&bulkdata->d[i]); @@ -671,14 +671,14 @@ unifi_receive_event(void *ospriv, } writePointer = priv->rxSignalBuffer.writePointer; rx_buff = &priv->rxSignalBuffer.rx_buff[writePointer]; - memcpy(rx_buff->bufptr,sigdata,siglen); + memcpy(rx_buff->bufptr, sigdata, siglen); rx_buff->sig_len = siglen; rx_buff->data_ptrs = *bulkdata; writePointer++; if(writePointer >= priv->rxSignalBuffer.size) { writePointer =0; } - unifi_trace(priv, UDBG4, "unifi_receive_event:writePtr = %d\n",priv->rxSignalBuffer.writePointer); + unifi_trace(priv, UDBG4, "unifi_receive_event:writePtr = %d\n", priv->rxSignalBuffer.writePointer); priv->rxSignalBuffer.writePointer = writePointer; #ifndef CSR_WIFI_RX_PATH_SPLIT_DONT_USE_WQ diff --git a/drivers/staging/csr/unifi_pdu_processing.c b/drivers/staging/csr/unifi_pdu_processing.c index f9b421b5aa35..04fe9e2acf0e 100644 --- a/drivers/staging/csr/unifi_pdu_processing.c +++ b/drivers/staging/csr/unifi_pdu_processing.c @@ -38,7 +38,7 @@ static void _update_buffered_pkt_params_after_alignment(unifi_priv_t *priv, bulk skb = (struct sk_buff*)bulkdata->d[0].os_net_buf_ptr; align_offset = (u32)(long)(bulkdata->d[0].os_data_ptr) & (CSR_WIFI_ALIGN_BYTES-1); if(align_offset){ - skb_pull(skb,align_offset); + skb_pull(skb, align_offset); } buffered_pkt->bulkdata.os_data_ptr = bulkdata->d[0].os_data_ptr; @@ -86,7 +86,7 @@ unifi_frame_ma_packet_req(unifi_priv_t *priv, CSR_PRIORITY priority, */ req->TransmissionControl = transmissionControl; req->VirtualInterfaceIdentifier = - uf_get_vif_identifier(interfacePriv->interfaceMode,interfaceTag); + uf_get_vif_identifier(interfacePriv->interfaceMode, interfaceTag); memcpy(req->Ra.x, peerMacAddress, ETH_ALEN); if (hostTag == 0xffffffff) { @@ -124,8 +124,8 @@ unifi_frame_ma_packet_req(unifi_priv_t *priv, CSR_PRIORITY priority, #define TRANSMISSION_CONTROL_EOSP_MASK 0x0002 static -int frame_and_send_queued_pdu(unifi_priv_t* priv,tx_buffered_packets_t* buffered_pkt, - CsrWifiRouterCtrlStaInfo_t *staRecord,u8 moreData , u8 eosp) +int frame_and_send_queued_pdu(unifi_priv_t* priv, tx_buffered_packets_t* buffered_pkt, + CsrWifiRouterCtrlStaInfo_t *staRecord, u8 moreData , u8 eosp) { CSR_SIGNAL signal; @@ -135,7 +135,7 @@ int frame_and_send_queued_pdu(unifi_priv_t* priv,tx_buffered_packets_t* buffered u8 *qc; u16 *fc = (u16*)(buffered_pkt->bulkdata.os_data_ptr); unsigned long lock_flags; - unifi_trace(priv, UDBG3, "frame_and_send_queued_pdu with moreData: %d , EOSP: %d\n",moreData,eosp); + unifi_trace(priv, UDBG3, "frame_and_send_queued_pdu with moreData: %d , EOSP: %d\n", moreData, eosp); unifi_frame_ma_packet_req(priv, buffered_pkt->priority, buffered_pkt->rate, buffered_pkt->hostTag, buffered_pkt->interfaceTag, buffered_pkt->transmissionControl, buffered_pkt->leSenderProcessId, buffered_pkt->peerMacAddress.a, &signal); @@ -156,7 +156,7 @@ int frame_and_send_queued_pdu(unifi_priv_t* priv,tx_buffered_packets_t* buffered if((staRecord != NULL)&& (staRecord->wmmOrQosEnabled == TRUE)) { - unifi_trace(priv, UDBG3, "frame_and_send_queued_pdu WMM Enabled: %d \n",staRecord->wmmOrQosEnabled); + unifi_trace(priv, UDBG3, "frame_and_send_queued_pdu WMM Enabled: %d \n", staRecord->wmmOrQosEnabled); toDs = (*fc & cpu_to_le16(IEEE802_11_FC_TO_DS_MASK))?1 : 0; fromDs = (*fc & cpu_to_le16(IEEE802_11_FC_FROM_DS_MASK))? 1: 0; @@ -190,7 +190,7 @@ int frame_and_send_queued_pdu(unifi_priv_t* priv,tx_buffered_packets_t* buffered } result = ul_send_signal_unpacked(priv, &signal, &bulkdata); if(result){ - _update_buffered_pkt_params_after_alignment(priv, &bulkdata,buffered_pkt); + _update_buffered_pkt_params_after_alignment(priv, &bulkdata, buffered_pkt); } /* Decrement the packet counts queued in driver */ @@ -199,13 +199,13 @@ int frame_and_send_queued_pdu(unifi_priv_t* priv,tx_buffered_packets_t* buffered if (!priv->noOfPktQueuedInDriver) { unifi_error(priv, "packets queued in driver 0 still decrementing\n"); } else { - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); priv->noOfPktQueuedInDriver--; - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); } /* Sta Record is available for all unicast (except genericMgt Frames) & in other case its NULL */ if (staRecord) { - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); if (!staRecord->noOfPktQueued) { unifi_error(priv, "packets queued in driver per station is 0 still decrementing\n"); } else { @@ -217,7 +217,7 @@ int frame_and_send_queued_pdu(unifi_priv_t* priv,tx_buffered_packets_t* buffered staRecord->nullDataHostTag = INVALID_HOST_TAG; } } - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); } } @@ -243,24 +243,24 @@ void set_eosp_transmit_ctrl(unifi_priv_t *priv, struct list_head *txList) /* return the last node , and modify it. */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_for_each_prev_safe(listHead, placeHolder, txList) { tx_q_item = list_entry(listHead, tx_buffered_packets_t, q); tx_q_item->transmissionControl |= TRANSMISSION_CONTROL_EOSP_MASK; tx_q_item->transmissionControl = (tx_q_item->transmissionControl & ~(CSR_NO_CONFIRM_REQUIRED)); unifi_trace(priv, UDBG1, - "set_eosp_transmit_ctrl Transmission Control = 0x%x hostTag = 0x%x \n",tx_q_item->transmissionControl,tx_q_item->hostTag); - unifi_trace(priv,UDBG3,"in set_eosp_transmit_ctrl no.of buffered frames %d\n",priv->noOfPktQueuedInDriver); + "set_eosp_transmit_ctrl Transmission Control = 0x%x hostTag = 0x%x \n", tx_q_item->transmissionControl, tx_q_item->hostTag); + unifi_trace(priv, UDBG3, "in set_eosp_transmit_ctrl no.of buffered frames %d\n", priv->noOfPktQueuedInDriver); break; } - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); - unifi_trace(priv, UDBG1,"List Empty %d\n",list_empty(txList)); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); + unifi_trace(priv, UDBG1, "List Empty %d\n", list_empty(txList)); unifi_trace(priv, UDBG5, "leaving set_eosp_transmit_ctrl\n"); return; } static -void send_vif_availibility_rsp(unifi_priv_t *priv,CSR_VIF_IDENTIFIER vif,CSR_RESULT_CODE resultCode) +void send_vif_availibility_rsp(unifi_priv_t *priv, CSR_VIF_IDENTIFIER vif, CSR_RESULT_CODE resultCode) { CSR_SIGNAL signal; CSR_MA_VIF_AVAILABILITY_RESPONSE *rsp; @@ -269,7 +269,7 @@ void send_vif_availibility_rsp(unifi_priv_t *priv,CSR_VIF_IDENTIFIER vif,CSR_RES unifi_trace(priv, UDBG3, "send_vif_availibility_rsp : invoked with resultCode = %d \n", resultCode); - memset(&signal,0,sizeof(CSR_SIGNAL)); + memset(&signal, 0, sizeof(CSR_SIGNAL)); rsp = &signal.u.MaVifAvailabilityResponse; rsp->VirtualInterfaceIdentifier = vif; rsp->ResultCode = resultCode; @@ -280,7 +280,7 @@ void send_vif_availibility_rsp(unifi_priv_t *priv,CSR_VIF_IDENTIFIER vif,CSR_RES /* Send the signal to UniFi */ r = ul_send_signal_unpacked(priv, &signal, bulkdata); if(r) { - unifi_error(priv,"Availibility response sending failed %x status %d\n",vif,r); + unifi_error(priv, "Availibility response sending failed %x status %d\n", vif, r); } else { unifi_trace(priv, UDBG3, "send_vif_availibility_rsp : status = %d \n", r); @@ -295,7 +295,7 @@ void verify_and_accomodate_tx_packet(unifi_priv_t *priv) unsigned long lock_flags; struct list_head *listHead, *list; struct list_head *placeHolder; - u8 i, j,eospFramedeleted=0; + u8 i, j, eospFramedeleted=0; u8 thresholdExcedeDueToBroadcast = TRUE; /* it will be made it interface Specific in the future when multi interfaces are supported , right now interface 0 is considered */ @@ -311,10 +311,10 @@ void verify_and_accomodate_tx_packet(unifi_priv_t *priv) * packets for station record crossed the threshold limit (64 for AP supporting * 8 peers) */ - unifi_trace(priv,UDBG3,"number of station pkts queued= %d for sta id = %d\n", staInfo->noOfPktQueued, staInfo->aid); + unifi_trace(priv, UDBG3, "number of station pkts queued= %d for sta id = %d\n", staInfo->noOfPktQueued, staInfo->aid); for(j = 0; j < MAX_ACCESS_CATOGORY; j++) { list = &staInfo->dataPdu[j]; - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_for_each_safe(listHead, placeHolder, list) { tx_q_item = list_entry(listHead, tx_buffered_packets_t, q); list_del(listHead); @@ -339,7 +339,7 @@ void verify_and_accomodate_tx_packet(unifi_priv_t *priv) } break; } - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); } } } @@ -347,13 +347,13 @@ void verify_and_accomodate_tx_packet(unifi_priv_t *priv) /* Remove the packets from genericMulticastOrBroadCastFrames queue * (the max packets in driver is reached due to broadcast/multicast frames) */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_for_each_safe(listHead, placeHolder, &interfacePriv->genericMulticastOrBroadCastFrames) { tx_q_item = list_entry(listHead, tx_buffered_packets_t, q); if(eospFramedeleted){ tx_q_item->transmissionControl |= TRANSMISSION_CONTROL_EOSP_MASK; tx_q_item->transmissionControl = (tx_q_item->transmissionControl & ~(CSR_NO_CONFIRM_REQUIRED)); - unifi_trace(priv, UDBG1,"updating eosp for next packet hostTag:= 0x%x ",tx_q_item->hostTag); + unifi_trace(priv, UDBG1, "updating eosp for next packet hostTag:= 0x%x ", tx_q_item->hostTag); eospFramedeleted =0; break; } @@ -361,7 +361,7 @@ void verify_and_accomodate_tx_packet(unifi_priv_t *priv) if(tx_q_item->transmissionControl & TRANSMISSION_CONTROL_EOSP_MASK ){ eospFramedeleted = 1; } - unifi_trace(priv,UDBG1, "freeing of multicast packets ToC = 0x%x hostTag = 0x%x \n",tx_q_item->transmissionControl,tx_q_item->hostTag); + unifi_trace(priv, UDBG1, "freeing of multicast packets ToC = 0x%x hostTag = 0x%x \n", tx_q_item->transmissionControl, tx_q_item->hostTag); list_del(listHead); unifi_net_data_free(priv, &tx_q_item->bulkdata); kfree(tx_q_item); @@ -373,7 +373,7 @@ void verify_and_accomodate_tx_packet(unifi_priv_t *priv) break; } } - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); } unifi_trace(priv, UDBG3, "leaving verify_and_accomodate_tx_packet\n"); } @@ -391,13 +391,13 @@ CsrResult enque_tx_data_pdu(unifi_priv_t *priv, bulk_data_param_t *bulkdata, unifi_trace(priv, UDBG5, "entering enque_tx_data_pdu\n"); if(!list) { - unifi_error(priv,"List is not specified\n"); + unifi_error(priv, "List is not specified\n"); return CSR_RESULT_FAILURE; } /* Removes aged packets & adds the incoming packet */ if (priv->noOfPktQueuedInDriver >= CSR_WIFI_DRIVER_SUPPORT_FOR_MAX_PKT_QUEUEING) { - unifi_trace(priv,UDBG3,"number of pkts queued= %d \n", priv->noOfPktQueuedInDriver); + unifi_trace(priv, UDBG3, "number of pkts queued= %d \n", priv->noOfPktQueuedInDriver); verify_and_accomodate_tx_packet(priv); } @@ -412,7 +412,7 @@ CsrResult enque_tx_data_pdu(unifi_priv_t *priv, bulk_data_param_t *bulkdata, } /* disable the preemption */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); INIT_LIST_HEAD(&tx_q_item->q); /* fill the tx_q structure members */ tx_q_item->bulkdata.os_data_ptr = bulkdata->d[0].os_data_ptr; @@ -437,7 +437,7 @@ CsrResult enque_tx_data_pdu(unifi_priv_t *priv, bulk_data_param_t *bulkdata, /* Count of packet queued in driver */ priv->noOfPktQueuedInDriver++; - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); unifi_trace(priv, UDBG5, "leaving enque_tx_data_pdu\n"); return CSR_RESULT_SUCCESS; } @@ -655,13 +655,13 @@ void uf_handle_tim_cfm(unifi_priv_t *priv, CSR_MLME_SET_TIM_CONFIRM *cfm, u16 re } if (handle != CSR_WIFI_BROADCAST_OR_MULTICAST_HANDLE) { - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); if ((staRecord = ((CsrWifiRouterCtrlStaInfo_t *) (interfacePriv->staInfo[handle]))) == NULL) { - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); unifi_warning(priv, "uf_handle_tim_cfm: station record is NULL handle = %x\n", handle); return; } - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); } switch(timSetStatus) { @@ -909,13 +909,13 @@ void update_tim(unifi_priv_t * priv, u16 aid, u8 setTim, u16 interfaceTag, u32 h (u8*)&signal.SignalPrimitiveHeader.SenderProcessId); /* set The virtual interfaceIdentifier, aid, tim value */ - req->VirtualInterfaceIdentifier = uf_get_vif_identifier(interfacePriv->interfaceMode,interfaceTag); + req->VirtualInterfaceIdentifier = uf_get_vif_identifier(interfacePriv->interfaceMode, interfaceTag); req->AssociationId = aid; req->TimValue = setTim; unifi_trace(priv, UDBG2, "update_tim:AID %x,senderIdLsb = 0x%x, handle = 0x%x, timSetStatus = %x, sender proceesID = %x \n", - aid,senderIdLsb, handle, timSetStatus, signal.SignalPrimitiveHeader.SenderProcessId); + aid, senderIdLsb, handle, timSetStatus, signal.SignalPrimitiveHeader.SenderProcessId); /* Send the signal to UniFi */ r = ul_send_signal_unpacked(priv, &signal, bulkdata); @@ -953,17 +953,17 @@ void process_peer_active_transition(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t *staRecord, u16 interfaceTag) { - int r,i; - u8 spaceAvail[4] = {TRUE,TRUE,TRUE,TRUE}; + int r, i; + u8 spaceAvail[4] = {TRUE, TRUE, TRUE, TRUE}; tx_buffered_packets_t * buffered_pkt = NULL; unsigned long lock_flags; netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag]; unifi_trace(priv, UDBG5, "entering process_peer_active_transition\n"); - if(IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag)) { + if(IS_DTIM_ACTIVE(interfacePriv->dtimActive, interfacePriv->multicastPduHostTag)) { /* giving more priority to multicast packets so delaying unicast packets*/ - unifi_trace(priv,UDBG2, "Multicast transmission is going on so resume unicast transmission after DTIM over\n"); + unifi_trace(priv, UDBG2, "Multicast transmission is going on so resume unicast transmission after DTIM over\n"); /* As station is active now, even though AP is not able to send frames to it * because of DTIM, it needs to reset the TIM here @@ -987,12 +987,12 @@ void process_peer_active_transition(unifi_priv_t * priv, while((buffered_pkt=dequeue_tx_data_pdu(priv, &staRecord->mgtFrames))) { buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK); - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,0,FALSE)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, staRecord, 0, FALSE)) == -ENOSPC) { unifi_trace(priv, UDBG2, "p_p_a_t:(ENOSPC) Mgt Frame queueing \n"); /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &staRecord->mgtFrames); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); priv->pausedStaHandle[3]=(u8)(staRecord->assignedHandle); spaceAvail[3] = FALSE; break; @@ -1008,7 +1008,7 @@ void process_peer_active_transition(unifi_priv_t * priv, if (!staRecord->timRequestPendingFlag) { if (staRecord->txSuspend) { if(staRecord->timSet == CSR_WIFI_TIM_SET) { - update_tim(priv,staRecord->aid,0,interfaceTag, staRecord->assignedHandle); + update_tim(priv, staRecord->aid, 0, interfaceTag, staRecord->assignedHandle); } return; } @@ -1025,16 +1025,16 @@ void process_peer_active_transition(unifi_priv_t * priv, for(i=3;i>=0;i--) { if(!spaceAvail[i]) continue; - unifi_trace(priv, UDBG6, "p_p_a_t:data pkt sending for AC %d \n",i); + unifi_trace(priv, UDBG6, "p_p_a_t:data pkt sending for AC %d \n", i); while((buffered_pkt=dequeue_tx_data_pdu(priv, &staRecord->dataPdu[i]))) { buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK); - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,0,FALSE)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, staRecord, 0, FALSE)) == -ENOSPC) { /* Clear the trigger bit transmission control*/ /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &staRecord->dataPdu[i]); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); priv->pausedStaHandle[i]=(u8)(staRecord->assignedHandle); break; } else { @@ -1050,7 +1050,7 @@ void process_peer_active_transition(unifi_priv_t * priv, if (!staRecord->timRequestPendingFlag){ if((staRecord->timSet == CSR_WIFI_TIM_SET) || (staRecord->timSet == CSR_WIFI_TIM_SETTING)) { unifi_trace(priv, UDBG3, "p_p_a_t:resetting tim .....\n"); - update_tim(priv,staRecord->aid,0,interfaceTag, staRecord->assignedHandle); + update_tim(priv, staRecord->aid, 0, interfaceTag, staRecord->assignedHandle); } } else @@ -1067,7 +1067,7 @@ void process_peer_active_transition(unifi_priv_t * priv, -void uf_process_ma_pkt_cfm_for_ap(unifi_priv_t *priv,u16 interfaceTag, const CSR_MA_PACKET_CONFIRM *pkt_cfm) +void uf_process_ma_pkt_cfm_for_ap(unifi_priv_t *priv, u16 interfaceTag, const CSR_MA_PACKET_CONFIRM *pkt_cfm) { netInterface_priv_t *interfacePriv; u8 i; @@ -1076,16 +1076,16 @@ void uf_process_ma_pkt_cfm_for_ap(unifi_priv_t *priv,u16 interfaceTag, const CSR if(pkt_cfm->HostTag == interfacePriv->multicastPduHostTag) { - unifi_trace(priv,UDBG2,"CFM for marked Multicast Tag = %x\n",interfacePriv->multicastPduHostTag); + unifi_trace(priv, UDBG2, "CFM for marked Multicast Tag = %x\n", interfacePriv->multicastPduHostTag); interfacePriv->multicastPduHostTag = 0xffffffff; - resume_suspended_uapsd(priv,interfaceTag); - resume_unicast_buffered_frames(priv,interfaceTag); + resume_suspended_uapsd(priv, interfaceTag); + resume_unicast_buffered_frames(priv, interfaceTag); if(list_empty(&interfacePriv->genericMulticastOrBroadCastMgtFrames) && list_empty(&interfacePriv->genericMulticastOrBroadCastFrames)) { - unifi_trace(priv,UDBG1,"Resetting multicastTIM"); + unifi_trace(priv, UDBG1, "Resetting multicastTIM"); if (!interfacePriv->bcTimSetReqPendingFlag) { - update_tim(priv,0,CSR_WIFI_TIM_RESET,interfaceTag, 0xFFFFFFFF); + update_tim(priv, 0, CSR_WIFI_TIM_RESET, interfaceTag, 0xFFFFFFFF); } else { @@ -1164,7 +1164,7 @@ void uf_process_ma_pkt_cfm_for_ap(unifi_priv_t *priv,u16 interfaceTag, const CSR &send_cfm_list, &(staRecord->dataPdu[j])); - uf_flush_list(priv,&(staRecord->dataPdu[j])); + uf_flush_list(priv, &(staRecord->dataPdu[j])); } send_auto_ma_packet_confirm(priv, staRecord->interfacePriv, &send_cfm_list); @@ -1469,7 +1469,7 @@ static int update_macheader(unifi_priv_t *priv, struct sk_buff *skb, } /* prepare the complete skb, by pushing the MAC header to the beginning of the skb->data */ - unifi_trace(priv, UDBG5, "updated Mac Header: %d \n",macHeaderLengthInBytes); + unifi_trace(priv, UDBG5, "updated Mac Header: %d \n", macHeaderLengthInBytes); memcpy(bufPtr, macHeaderBuf, macHeaderLengthInBytes); unifi_trace(priv, UDBG5, "leaving the update_macheader function\n"); @@ -1515,7 +1515,7 @@ uf_ap_process_data_pdu(unifi_priv_t *priv, struct sk_buff *skb, CsrWifiRouterCtrlStaInfo_t *dstStaInfo = NULL; netInterface_priv_t *interfacePriv; - unifi_trace(priv, UDBG5, "entering uf_ap_process_data_pdu %d\n",macHeaderLengthInBytes); + unifi_trace(priv, UDBG5, "entering uf_ap_process_data_pdu %d\n", macHeaderLengthInBytes); /* InterfaceTag validation from MA_PACKET.indication */ if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) { unifi_trace(priv, UDBG1, "Interface Tag is Invalid in uf_ap_process_data_pdu\n"); @@ -1608,7 +1608,7 @@ uf_ap_process_data_pdu(unifi_priv_t *priv, struct sk_buff *skb, unifi_trace(priv, UDBG3, "Mac Header updated...calling uf_process_ma_packet_req \n"); /* Packet is ready to send to unifi ,transmissionControl = 0x0004, confirmation is not needed for data packets */ - if (uf_process_ma_packet_req(priv, ehdr->h_dest, 0xffffffff, interfaceTag, CSR_NO_CONFIRM_REQUIRED, (CSR_RATE)0,priority, priv->netdev_client->sender_id, bulkdata)) { + if (uf_process_ma_packet_req(priv, ehdr->h_dest, 0xffffffff, interfaceTag, CSR_NO_CONFIRM_REQUIRED, (CSR_RATE)0, priority, priv->netdev_client->sender_id, bulkdata)) { if (sendToNetdev) { unifi_trace(priv, UDBG1, "In uf_ap_process_data_pdu, (Packet Drop) uf_process_ma_packet_req failed. freeing skb_copy data (original data sent to Netdev)\n"); /* Free's the skb_copy(skbPtr) data since packet processing failed */ @@ -1750,7 +1750,7 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, /* push the packet to the unifi if list is empty (if packet lost how to re-enque) */ if (list_empty(&interfacePriv->genericMgtFrames)) { #ifdef CSR_SUPPORT_SME - if(!(IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag))) { + if(!(IS_DTIM_ACTIVE(interfacePriv->dtimActive, interfacePriv->multicastPduHostTag))) { #endif unifi_trace(priv, UDBG3, "genericMgtFrames list is empty uf_process_ma_packet_req \n"); @@ -1765,8 +1765,8 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, #ifdef CSR_SUPPORT_SME }else{ list = &interfacePriv->genericMgtFrames; - unifi_trace(priv, UDBG3, "genericMgtFrames queue empty and dtim started\n hosttag is 0x%x,\n",signal.u.MaPacketRequest.HostTag); - update_eosp_to_head_of_broadcast_list_head(priv,interfaceTag); + unifi_trace(priv, UDBG3, "genericMgtFrames queue empty and dtim started\n hosttag is 0x%x,\n", signal.u.MaPacketRequest.HostTag); + update_eosp_to_head_of_broadcast_list_head(priv, interfaceTag); } #endif } else { @@ -1776,15 +1776,15 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, } } else { /* check peer power state */ - if (queuePacketDozing || !list_empty(&staRecord->mgtFrames) || IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag)) { + if (queuePacketDozing || !list_empty(&staRecord->mgtFrames) || IS_DTIM_ACTIVE(interfacePriv->dtimActive, interfacePriv->multicastPduHostTag)) { /* peer is in dozing mode, so queue packet in mgt frame list of station record */ /*if multicast traffic is going on, buffer the unicast packets*/ list = &staRecord->mgtFrames; unifi_trace(priv, UDBG1, "staRecord->MgtFrames list empty? = %s, handle = %d, queuePacketDozing = %d\n", (list_empty(&staRecord->mgtFrames))? "YES": "NO", staRecord->assignedHandle, queuePacketDozing); - if(IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag)){ - update_eosp_to_head_of_broadcast_list_head(priv,interfaceTag); + if(IS_DTIM_ACTIVE(interfacePriv->dtimActive, interfacePriv->multicastPduHostTag)){ + update_eosp_to_head_of_broadcast_list_head(priv, interfaceTag); } } else { @@ -1794,7 +1794,7 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, /* requeue the failed packet to staRecord->mgtFrames with same position */ list = &staRecord->mgtFrames; requeueOnSamePos = TRUE; - unifi_trace(priv, UDBG1, "(ENOSPC) Sending MgtFrames Failed handle = %d so buffering\n",staRecord->assignedHandle); + unifi_trace(priv, UDBG1, "(ENOSPC) Sending MgtFrames Failed handle = %d so buffering\n", staRecord->assignedHandle); priv->pausedStaHandle[0]=(u8)(staRecord->assignedHandle); } else if (result) { status = CSR_RESULT_FAILURE; @@ -1827,11 +1827,11 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, if(!staRecord) { unifi_error(priv, "In %s unicast but staRecord = NULL\n", __FUNCTION__); return CSR_RESULT_FAILURE; - } else if (queuePacketDozing || isRouterBufferEnabled(priv,priority_q)|| !list_empty(&staRecord->dataPdu[priority_q]) || IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag)) { + } else if (queuePacketDozing || isRouterBufferEnabled(priv, priority_q)|| !list_empty(&staRecord->dataPdu[priority_q]) || IS_DTIM_ACTIVE(interfacePriv->dtimActive, interfacePriv->multicastPduHostTag)) { /* peer is in dozing mode, so queue packet in mgt frame list of station record */ /* if multicast traffic is going on, buffet the unicast packets */ unifi_trace(priv, UDBG2, "Enqueued to staRecord->dataPdu[%d] queuePacketDozing=%d,\ - Buffering enabled = %d \n", priority_q,queuePacketDozing,isRouterBufferEnabled(priv,priority_q)); + Buffering enabled = %d \n", priority_q, queuePacketDozing, isRouterBufferEnabled(priv, priority_q)); list = &staRecord->dataPdu[priority_q]; } else { unifi_trace(priv, UDBG5, "staRecord->dataPdu[%d] list is empty uf_process_ma_packet_req \n", priority_q); @@ -1839,12 +1839,12 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, result = ul_send_signal_unpacked(priv, &signal, bulkdata); if(result == -ENOSPC) { /* requeue the failed packet to staRecord->dataPdu[priority_q] with same position */ - unifi_trace(priv, UDBG1, "(ENOSPC) Sending Unicast DataPDU to queue %d Failed so buffering\n",priority_q); + unifi_trace(priv, UDBG1, "(ENOSPC) Sending Unicast DataPDU to queue %d Failed so buffering\n", priority_q); requeueOnSamePos = TRUE; list = &staRecord->dataPdu[priority_q]; priv->pausedStaHandle[priority_q]=(u8)(staRecord->assignedHandle); - if(!isRouterBufferEnabled(priv,priority_q)) { - unifi_error(priv,"Buffering Not enabled for queue %d \n",priority_q); + if(!isRouterBufferEnabled(priv, priority_q)) { + unifi_error(priv, "Buffering Not enabled for queue %d \n", priority_q); } } else if (result) { status = CSR_RESULT_FAILURE; @@ -1869,19 +1869,19 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, unifi_error(priv, "unrecognized frame type\n"); } if(list) { - status = enque_tx_data_pdu(priv, bulkdata,list, &signal,requeueOnSamePos); + status = enque_tx_data_pdu(priv, bulkdata, list, &signal, requeueOnSamePos); /* Record no. of packet queued for each peer */ if (staRecord && (pktType == CSR_WIFI_UNICAST_PDU) && (!status)) { - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); staRecord->noOfPktQueued++; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); } else if ((pktType == CSR_WIFI_MULTICAST_PDU) && (!status)) { /* If broadcast Tim is set && queuing is successful, then only update TIM */ - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); interfacePriv->noOfbroadcastPktQueued++; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); } } /* If broadcast Tim is set && queuing is successful, then only update TIM */ @@ -1889,7 +1889,7 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, unifi_trace(priv, UDBG3, "tim set due to broadcast pkt\n"); if (!interfacePriv->bcTimSetReqPendingFlag) { - update_tim(priv,0,CSR_WIFI_TIM_SET,interfaceTag, handle); + update_tim(priv, 0, CSR_WIFI_TIM_SET, interfaceTag, handle); } else { @@ -1909,7 +1909,7 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, !list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION])) { unifi_trace(priv, UDBG3, "tim set due to unicast pkt & peer in powersave\n"); if (!staRecord->timRequestPendingFlag){ - update_tim(priv,staRecord->aid,1,interfaceTag, handle); + update_tim(priv, staRecord->aid, 1, interfaceTag, handle); } else { @@ -1929,7 +1929,7 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, if (uf_is_more_data_for_non_delivery_ac(staRecord) || (allDeliveryEnabled && dataAvailable) || (!list_empty(&staRecord->mgtFrames))) { if (!staRecord->timRequestPendingFlag) { - update_tim(priv,staRecord->aid,1,interfaceTag, handle); + update_tim(priv, staRecord->aid, 1, interfaceTag, handle); } else { @@ -1945,8 +1945,8 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, } } - if((list) && (pktType == CSR_WIFI_UNICAST_PDU && !queuePacketDozing) && !(isRouterBufferEnabled(priv,priority_q)) && !(IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag))) { - unifi_trace(priv, UDBG2, "buffering cleared for queue = %d So resending buffered frames\n",priority_q); + if((list) && (pktType == CSR_WIFI_UNICAST_PDU && !queuePacketDozing) && !(isRouterBufferEnabled(priv, priority_q)) && !(IS_DTIM_ACTIVE(interfacePriv->dtimActive, interfacePriv->multicastPduHostTag))) { + unifi_trace(priv, UDBG2, "buffering cleared for queue = %d So resending buffered frames\n", priority_q); uf_send_buffered_frames(priv, priority_q); } unifi_trace(priv, UDBG5, "leaving uf_process_ma_packet_req \n"); @@ -2022,23 +2022,23 @@ u8 send_multicast_frames(unifi_priv_t *priv, u16 interfaceTag) netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag]; u32 hostTag = 0xffffffff; - if(!isRouterBufferEnabled(priv,UNIFI_TRAFFIC_Q_VO)) { - while((interfacePriv->dtimActive)&& (buffered_pkt=dequeue_tx_data_pdu(priv,&interfacePriv->genericMulticastOrBroadCastMgtFrames))) { + if(!isRouterBufferEnabled(priv, UNIFI_TRAFFIC_Q_VO)) { + while((interfacePriv->dtimActive)&& (buffered_pkt=dequeue_tx_data_pdu(priv, &interfacePriv->genericMulticastOrBroadCastMgtFrames))) { buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK); moreData = (buffered_pkt->transmissionControl & TRANSMISSION_CONTROL_EOSP_MASK)?FALSE:TRUE; - unifi_trace(priv,UDBG2,"DTIM Occurred for interface:sending Mgt packet %d\n",interfaceTag); + unifi_trace(priv, UDBG2, "DTIM Occurred for interface:sending Mgt packet %d\n", interfaceTag); - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,NULL,moreData,FALSE)) == -ENOSPC) { - unifi_trace(priv,UDBG1,"frame_and_send_queued_pdu failed with ENOSPC for host tag = %x\n", buffered_pkt->hostTag); + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, NULL, moreData, FALSE)) == -ENOSPC) { + unifi_trace(priv, UDBG1, "frame_and_send_queued_pdu failed with ENOSPC for host tag = %x\n", buffered_pkt->hostTag); /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &interfacePriv->genericMulticastOrBroadCastMgtFrames); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); break; } else { - unifi_trace(priv,UDBG1,"send_multicast_frames: Send genericMulticastOrBroadCastMgtFrames (%x, %x)\n", + unifi_trace(priv, UDBG1, "send_multicast_frames: Send genericMulticastOrBroadCastMgtFrames (%x, %x)\n", buffered_pkt->hostTag, r); if(r) { @@ -2051,35 +2051,35 @@ u8 send_multicast_frames(unifi_priv_t *priv, u16 interfaceTag) hostTag = buffered_pkt->hostTag; pduSent++; } else { - send_vif_availibility_rsp(priv,uf_get_vif_identifier(interfacePriv->interfaceMode,interfaceTag),CSR_RC_UNSPECIFIED_FAILURE); + send_vif_availibility_rsp(priv, uf_get_vif_identifier(interfacePriv->interfaceMode, interfaceTag), CSR_RC_UNSPECIFIED_FAILURE); } } /* Buffered frame sent successfully */ - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); interfacePriv->noOfbroadcastPktQueued--; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); kfree(buffered_pkt); } } } - if(!isRouterBufferEnabled(priv,UNIFI_TRAFFIC_Q_CONTENTION)) { - while((interfacePriv->dtimActive)&& (buffered_pkt=dequeue_tx_data_pdu(priv,&interfacePriv->genericMulticastOrBroadCastFrames))) { + if(!isRouterBufferEnabled(priv, UNIFI_TRAFFIC_Q_CONTENTION)) { + while((interfacePriv->dtimActive)&& (buffered_pkt=dequeue_tx_data_pdu(priv, &interfacePriv->genericMulticastOrBroadCastFrames))) { buffered_pkt->transmissionControl |= TRANSMISSION_CONTROL_TRIGGER_MASK; moreData = (buffered_pkt->transmissionControl & TRANSMISSION_CONTROL_EOSP_MASK)?FALSE:TRUE; - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,NULL,moreData,FALSE)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, NULL, moreData, FALSE)) == -ENOSPC) { /* Clear the trigger bit transmission control*/ buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK); /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &interfacePriv->genericMulticastOrBroadCastFrames); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); break; } else { if(r) { - unifi_trace(priv,UDBG1,"send_multicast_frames: Send genericMulticastOrBroadCastFrame failed (%x, %x)\n", + unifi_trace(priv, UDBG1, "send_multicast_frames: Send genericMulticastOrBroadCastFrame failed (%x, %x)\n", buffered_pkt->hostTag, r); unifi_net_data_free(priv, &buffered_pkt->bulkdata); @@ -2090,26 +2090,26 @@ u8 send_multicast_frames(unifi_priv_t *priv, u16 interfaceTag) pduSent ++; hostTag = buffered_pkt->hostTag; } else { - send_vif_availibility_rsp(priv,uf_get_vif_identifier(interfacePriv->interfaceMode,interfaceTag),CSR_RC_UNSPECIFIED_FAILURE); + send_vif_availibility_rsp(priv, uf_get_vif_identifier(interfacePriv->interfaceMode, interfaceTag), CSR_RC_UNSPECIFIED_FAILURE); } } /* Buffered frame sent successfully */ - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); interfacePriv->noOfbroadcastPktQueued--; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); kfree(buffered_pkt); } } } if((interfacePriv->dtimActive == FALSE)) { /* Record the host Tag*/ - unifi_trace(priv,UDBG2,"send_multicast_frames: Recorded hostTag of EOSP packet: = 0x%x\n",hostTag); + unifi_trace(priv, UDBG2, "send_multicast_frames: Recorded hostTag of EOSP packet: = 0x%x\n", hostTag); interfacePriv->multicastPduHostTag = hostTag; } return pduSent; } #endif -void uf_process_ma_vif_availibility_ind(unifi_priv_t *priv,u8 *sigdata, +void uf_process_ma_vif_availibility_ind(unifi_priv_t *priv, u8 *sigdata, u32 siglen) { #ifdef CSR_SUPPORT_SME @@ -2148,15 +2148,15 @@ void uf_process_ma_vif_availibility_ind(unifi_priv_t *priv,u8 *sigdata, /* This condition can occur because of a potential race where the TIM is not yet reset as host is waiting for confirm but it is sent by firmware and DTIM occurs*/ - unifi_notice(priv,"ma_vif_availibility_ind recevied for multicast but queues are empty%d\n",interfaceTag); - send_vif_availibility_rsp(priv,ind->VirtualInterfaceIdentifier,CSR_RC_NO_BUFFERED_BROADCAST_MULTICAST_FRAMES); + unifi_notice(priv, "ma_vif_availibility_ind recevied for multicast but queues are empty%d\n", interfaceTag); + send_vif_availibility_rsp(priv, ind->VirtualInterfaceIdentifier, CSR_RC_NO_BUFFERED_BROADCAST_MULTICAST_FRAMES); interfacePriv->dtimActive = FALSE; if(interfacePriv->multicastPduHostTag == 0xffffffff) { - unifi_notice(priv,"ma_vif_availibility_ind recevied for multicast but queues are empty%d\n",interfaceTag); + unifi_notice(priv, "ma_vif_availibility_ind recevied for multicast but queues are empty%d\n", interfaceTag); /* This may be an extra request in very rare race conditions but it is fine as it would atleast remove the potential lock up */ if (!interfacePriv->bcTimSetReqPendingFlag) { - update_tim(priv,0,CSR_WIFI_TIM_RESET,interfaceTag, 0xFFFFFFFF); + update_tim(priv, 0, CSR_WIFI_TIM_RESET, interfaceTag, 0xFFFFFFFF); } else { @@ -2171,23 +2171,23 @@ void uf_process_ma_vif_availibility_ind(unifi_priv_t *priv,u8 *sigdata, return; } if(interfacePriv->dtimActive) { - unifi_trace(priv,UDBG2,"DTIM Occurred for already active DTIM interface %d\n",interfaceTag); + unifi_trace(priv, UDBG2, "DTIM Occurred for already active DTIM interface %d\n", interfaceTag); return; } else { - unifi_trace(priv,UDBG2,"DTIM Occurred for interface %d\n",interfaceTag); + unifi_trace(priv, UDBG2, "DTIM Occurred for interface %d\n", interfaceTag); if(list_empty(&interfacePriv->genericMulticastOrBroadCastFrames)) { - set_eosp_transmit_ctrl(priv,&interfacePriv->genericMulticastOrBroadCastMgtFrames); + set_eosp_transmit_ctrl(priv, &interfacePriv->genericMulticastOrBroadCastMgtFrames); } else { - set_eosp_transmit_ctrl(priv,&interfacePriv->genericMulticastOrBroadCastFrames); + set_eosp_transmit_ctrl(priv, &interfacePriv->genericMulticastOrBroadCastFrames); } } interfacePriv->dtimActive = TRUE; - pduSent = send_multicast_frames(priv,interfaceTag); + pduSent = send_multicast_frames(priv, interfaceTag); } else { - unifi_error(priv,"Interface switching is not supported %d\n",interfaceTag); + unifi_error(priv, "Interface switching is not supported %d\n", interfaceTag); resultCode = CSR_RC_NOT_SUPPORTED; - send_vif_availibility_rsp(priv,ind->VirtualInterfaceIdentifier,CSR_RC_NOT_SUPPORTED); + send_vif_availibility_rsp(priv, ind->VirtualInterfaceIdentifier, CSR_RC_NOT_SUPPORTED); } #endif } @@ -2204,12 +2204,12 @@ static u8 uf_is_more_data_for_delivery_ac(unifi_priv_t *priv, CsrWifiRouterCtrlS if(((staRecord->powersaveMode[i]==CSR_WIFI_AC_DELIVERY_ONLY_ENABLE) ||(staRecord->powersaveMode[i]==CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED)) &&(!list_empty(&staRecord->dataPdu[i]))) { - unifi_trace(priv,UDBG2,"uf_is_more_data_for_delivery_ac: Data Available AC = %d\n", i); + unifi_trace(priv, UDBG2, "uf_is_more_data_for_delivery_ac: Data Available AC = %d\n", i); return TRUE; } } - unifi_trace(priv,UDBG2,"uf_is_more_data_for_delivery_ac: Data NOT Available \n"); + unifi_trace(priv, UDBG2, "uf_is_more_data_for_delivery_ac: Data NOT Available \n"); return FALSE; } @@ -2222,12 +2222,12 @@ static u8 uf_is_more_data_for_usp_delivery(unifi_priv_t *priv, CsrWifiRouterCtrl if(((staRecord->powersaveMode[i]==CSR_WIFI_AC_DELIVERY_ONLY_ENABLE) ||(staRecord->powersaveMode[i]==CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED)) &&(!list_empty(&staRecord->dataPdu[i]))) { - unifi_trace(priv,UDBG2,"uf_is_more_data_for_usp_delivery: Data Available AC = %d\n", i); + unifi_trace(priv, UDBG2, "uf_is_more_data_for_usp_delivery: Data Available AC = %d\n", i); return TRUE; } } - unifi_trace(priv,UDBG2,"uf_is_more_data_for_usp_delivery: Data NOT Available \n"); + unifi_trace(priv, UDBG2, "uf_is_more_data_for_usp_delivery: Data NOT Available \n"); return FALSE; } @@ -2272,18 +2272,18 @@ void uf_send_buffered_data_from_delivery_ac(unifi_priv_t *priv, return; } while((buffered_pkt=dequeue_tx_data_pdu(priv, txList))) { - if((IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag))) { + if((IS_DTIM_ACTIVE(interfacePriv->dtimActive, interfacePriv->multicastPduHostTag))) { unifi_trace(priv, UDBG2, "uf_send_buffered_data_from_delivery_ac: DTIM Active, suspend UAPSD, staId: 0x%x\n", staInfo->aid); /* Once resume called, the U-APSD delivery operation will resume */ - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); staInfo->uspSuspend = TRUE; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); /* re-queueing the packet as DTIM started */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); - list_add(&buffered_pkt->q,txList); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); + list_add(&buffered_pkt->q, txList); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); break; } @@ -2315,20 +2315,20 @@ void uf_send_buffered_data_from_delivery_ac(unifi_priv_t *priv, unifi_warning(priv, "uf_send_buffered_data_from_delivery_ac: non U-APSD !!! \n"); } - unifi_trace(priv,UDBG2,"uf_send_buffered_data_from_delivery_ac : MoreData:%d, EOSP:%d\n",moreData,eosp); + unifi_trace(priv, UDBG2, "uf_send_buffered_data_from_delivery_ac : MoreData:%d, EOSP:%d\n", moreData, eosp); - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staInfo,moreData,eosp)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, staInfo, moreData, eosp)) == -ENOSPC) { unifi_trace(priv, UDBG2, "uf_send_buffered_data_from_delivery_ac: UASPD suspended, ENOSPC in hipQ=%x\n", queue); /* Once resume called, the U-APSD delivery operation will resume */ - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); staInfo->uspSuspend = TRUE; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); - list_add(&buffered_pkt->q,txList); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); + list_add(&buffered_pkt->q, txList); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); priv->pausedStaHandle[queue]=(u8)(staInfo->assignedHandle); break; } else { @@ -2337,17 +2337,17 @@ void uf_send_buffered_data_from_delivery_ac(unifi_priv_t *priv, unifi_net_data_free(priv, &buffered_pkt->bulkdata); } kfree(buffered_pkt); - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); staInfo->noOfSpFramesSent++; if((!moreData) || (staInfo->noOfSpFramesSent == staInfo->maxSpLength)) { unifi_trace(priv, UDBG2, "uf_send_buffered_data_from_delivery_ac: Terminating USP\n"); staInfo->uapsdActive = FALSE; staInfo->uspSuspend = FALSE; staInfo->noOfSpFramesSent = 0; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); break; } - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); } } unifi_trace(priv, UDBG2, "--uf_send_buffered_data_from_delivery_ac, active=%x\n", staInfo->uapsdActive); @@ -2364,25 +2364,25 @@ void uf_send_buffered_data_from_ac(unifi_priv_t *priv, u8 moreData = FALSE; s8 r =0; - unifi_trace(priv,UDBG2,"uf_send_buffered_data_from_ac :\n"); + unifi_trace(priv, UDBG2, "uf_send_buffered_data_from_ac :\n"); - while(!isRouterBufferEnabled(priv,queue) && + while(!isRouterBufferEnabled(priv, queue) && ((buffered_pkt=dequeue_tx_data_pdu(priv, txList))!=NULL)){ buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK); - unifi_trace(priv,UDBG3,"uf_send_buffered_data_from_ac : MoreData:%d, EOSP:%d\n",moreData,eosp); + unifi_trace(priv, UDBG3, "uf_send_buffered_data_from_ac : MoreData:%d, EOSP:%d\n", moreData, eosp); - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staInfo,moreData,eosp)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, staInfo, moreData, eosp)) == -ENOSPC) { /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); - list_add(&buffered_pkt->q,txList); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); + list_add(&buffered_pkt->q, txList); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); if(staInfo != NULL){ priv->pausedStaHandle[queue]=(u8)(staInfo->assignedHandle); } - unifi_trace(priv,UDBG3," uf_send_buffered_data_from_ac: PDU sending failed .. no space for queue %d \n",queue); + unifi_trace(priv, UDBG3, " uf_send_buffered_data_from_ac: PDU sending failed .. no space for queue %d \n", queue); } else { if(r){ /* the PDU failed where we can't do any thing so free the storage */ @@ -2394,10 +2394,10 @@ void uf_send_buffered_data_from_ac(unifi_priv_t *priv, } -void uf_send_buffered_frames(unifi_priv_t *priv,unifi_TrafficQueue q) +void uf_send_buffered_frames(unifi_priv_t *priv, unifi_TrafficQueue q) { u16 interfaceTag = GET_ACTIVE_INTERFACE_TAG(priv); - u32 startIndex=0,endIndex=0; + u32 startIndex=0, endIndex=0; CsrWifiRouterCtrlStaInfo_t * staInfo = NULL; u8 queue; u8 moreData = FALSE; @@ -2412,14 +2412,14 @@ void uf_send_buffered_frames(unifi_priv_t *priv,unifi_TrafficQueue q) if(interfacePriv->dtimActive) { /* this function updates dtimActive*/ - send_multicast_frames(priv,interfaceTag); + send_multicast_frames(priv, interfaceTag); if(!interfacePriv->dtimActive) { moreData = (!list_empty(&interfacePriv->genericMulticastOrBroadCastMgtFrames) || !list_empty(&interfacePriv->genericMulticastOrBroadCastFrames)); if(!moreData) { if (!interfacePriv->bcTimSetReqPendingFlag) { - update_tim(priv,0,CSR_WIFI_TIM_RESET,interfaceTag, 0XFFFFFFFF); + update_tim(priv, 0, CSR_WIFI_TIM_RESET, interfaceTag, 0XFFFFFFFF); } else { @@ -2436,8 +2436,8 @@ void uf_send_buffered_frames(unifi_priv_t *priv,unifi_TrafficQueue q) !list_empty(&interfacePriv->genericMulticastOrBroadCastFrames)); if(!moreData) { /* This should never happen but if it happens, we need a way out */ - unifi_error(priv,"ERROR: No More Data but DTIM is active sending Response\n"); - send_vif_availibility_rsp(priv,uf_get_vif_identifier(interfacePriv->interfaceMode,interfaceTag),CSR_RC_NO_BUFFERED_BROADCAST_MULTICAST_FRAMES); + unifi_error(priv, "ERROR: No More Data but DTIM is active sending Response\n"); + send_vif_availibility_rsp(priv, uf_get_vif_identifier(interfacePriv->interfaceMode, interfaceTag), CSR_RC_NO_BUFFERED_BROADCAST_MULTICAST_FRAMES); interfacePriv->dtimActive = FALSE; } } @@ -2450,9 +2450,9 @@ void uf_send_buffered_frames(unifi_priv_t *priv,unifi_TrafficQueue q) if(queue == UNIFI_TRAFFIC_Q_VO) { - unifi_trace(priv,UDBG2,"uf_send_buffered_frames : trying mgt from queue=%d\n",queue); + unifi_trace(priv, UDBG2, "uf_send_buffered_frames : trying mgt from queue=%d\n", queue); for(startIndex= 0; startIndex < UNIFI_MAX_CONNECTIONS;startIndex++) { - staInfo = CsrWifiRouterCtrlGetStationRecordFromHandle(priv,startIndex,interfaceTag); + staInfo = CsrWifiRouterCtrlGetStationRecordFromHandle(priv, startIndex, interfaceTag); if(!staInfo ) { continue; } else if((staInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE) @@ -2464,31 +2464,31 @@ void uf_send_buffered_frames(unifi_priv_t *priv,unifi_TrafficQueue q) &&(staInfo->uapsdActive == FALSE)){ /*Non-UAPSD case push the management frames out*/ if(!list_empty(&staInfo->mgtFrames)){ - uf_send_buffered_data_from_ac(priv,staInfo, UNIFI_TRAFFIC_Q_VO, &staInfo->mgtFrames); + uf_send_buffered_data_from_ac(priv, staInfo, UNIFI_TRAFFIC_Q_VO, &staInfo->mgtFrames); } } - if(isRouterBufferEnabled(priv,queue)) { - unifi_notice(priv,"uf_send_buffered_frames : No space Left for queue = %d\n",queue); + if(isRouterBufferEnabled(priv, queue)) { + unifi_notice(priv, "uf_send_buffered_frames : No space Left for queue = %d\n", queue); break; } } /*push generic management frames out*/ if(!list_empty(&interfacePriv->genericMgtFrames)) { - unifi_trace(priv,UDBG2,"uf_send_buffered_frames : trying generic mgt from queue=%d\n",queue); - uf_send_buffered_data_from_ac(priv,staInfo, UNIFI_TRAFFIC_Q_VO, &interfacePriv->genericMgtFrames); + unifi_trace(priv, UDBG2, "uf_send_buffered_frames : trying generic mgt from queue=%d\n", queue); + uf_send_buffered_data_from_ac(priv, staInfo, UNIFI_TRAFFIC_Q_VO, &interfacePriv->genericMgtFrames); } } - unifi_trace(priv,UDBG2,"uf_send_buffered_frames : Resume called for Queue=%d\n",queue); - unifi_trace(priv,UDBG2,"uf_send_buffered_frames : start=%d end=%d\n",startIndex,endIndex); + unifi_trace(priv, UDBG2, "uf_send_buffered_frames : Resume called for Queue=%d\n", queue); + unifi_trace(priv, UDBG2, "uf_send_buffered_frames : start=%d end=%d\n", startIndex, endIndex); startIndex = priv->pausedStaHandle[queue]; endIndex = (startIndex + UNIFI_MAX_CONNECTIONS -1) % UNIFI_MAX_CONNECTIONS; while(startIndex != endIndex) { - staInfo = CsrWifiRouterCtrlGetStationRecordFromHandle(priv,startIndex,interfaceTag); + staInfo = CsrWifiRouterCtrlGetStationRecordFromHandle(priv, startIndex, interfaceTag); if(!staInfo) { startIndex ++; if(startIndex >= UNIFI_MAX_CONNECTIONS) { @@ -2504,7 +2504,7 @@ void uf_send_buffered_frames(unifi_priv_t *priv,unifi_TrafficQueue q) continue; } /* Peer is active or U-APSD is active so send PDUs to the peer */ - unifi_trace(priv,UDBG2,"uf_send_buffered_frames : trying data from queue=%d\n",queue); + unifi_trace(priv, UDBG2, "uf_send_buffered_frames : trying data from queue=%d\n", queue); if((staInfo != NULL)&&(staInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE) @@ -2520,7 +2520,7 @@ void uf_send_buffered_frames(unifi_priv_t *priv,unifi_TrafficQueue q) startIndex = 0; } } - if(isRouterBufferEnabled(priv,queue)) { + if(isRouterBufferEnabled(priv, queue)) { priv->pausedStaHandle[queue] = endIndex; } else { priv->pausedStaHandle[queue] = 0; @@ -2561,7 +2561,7 @@ u8 uf_is_more_data_for_non_delivery_ac(CsrWifiRouterCtrlStaInfo_t *staRecord) } -int uf_process_station_records_for_sending_data(unifi_priv_t *priv,u16 interfaceTag, +int uf_process_station_records_for_sending_data(unifi_priv_t *priv, u16 interfaceTag, CsrWifiRouterCtrlStaInfo_t *srcStaInfo, CsrWifiRouterCtrlStaInfo_t *dstStaInfo) { @@ -2647,10 +2647,10 @@ static void uf_handle_uspframes_delivery(unifi_priv_t * priv, CsrWifiRouterCtrlS return; } - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); staInfo->uapsdActive = TRUE; staInfo->uspSuspend = FALSE; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); if(((staInfo->powersaveMode[UNIFI_TRAFFIC_Q_VO]==CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED)|| (staInfo->powersaveMode[UNIFI_TRAFFIC_Q_VO]==CSR_WIFI_AC_DELIVERY_ONLY_ENABLE)) @@ -2666,9 +2666,9 @@ static void uf_handle_uspframes_delivery(unifi_priv_t * priv, CsrWifiRouterCtrlS * NOTE: If we have sent Mgt frame also, we must send QNULL followed to terminate USP */ if (!staInfo->uspSuspend) { - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); staInfo->uapsdActive = FALSE; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); unifi_trace(priv, UDBG2, "uf_handle_uspframes_delivery: sending QNull for trigger\n"); uf_send_qos_null(priv, interfaceTag, staInfo->peerMacAddress.a, (CSR_PRIORITY) staInfo->triggerFramePriority, staInfo); @@ -2687,12 +2687,12 @@ static void uf_handle_uspframes_delivery(unifi_priv_t * priv, CsrWifiRouterCtrlS } if ((!staInfo->uapsdActive) || - (staInfo->uspSuspend && IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag))) { + (staInfo->uspSuspend && IS_DTIM_ACTIVE(interfacePriv->dtimActive, interfacePriv->multicastPduHostTag))) { /* If DTIM active found on one AC, No need to parse the remaining AC's * as USP suspended. Break out of loop */ unifi_trace(priv, UDBG2, "uf_handle_uspframes_delivery: suspend=%x, DTIM=%x, USP terminated=%s\n", - staInfo->uspSuspend, IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag), + staInfo->uspSuspend, IS_DTIM_ACTIVE(interfacePriv->dtimActive, interfacePriv->multicastPduHostTag), staInfo->uapsdActive?"NO":"YES"); break; } @@ -2704,7 +2704,7 @@ static void uf_handle_uspframes_delivery(unifi_priv_t * priv, CsrWifiRouterCtrlS */ is_all_ac_deliver_enabled_and_moredata(staInfo, &allDeliveryEnabled, &dataAvailable); if ((allDeliveryEnabled && !dataAvailable)) { - if ((staInfo->timSet != CSR_WIFI_TIM_RESET) || (staInfo->timSet != CSR_WIFI_TIM_RESETTING)) { + if ((staInfo->timSet != CSR_WIFI_TIM_RESET) && (staInfo->timSet != CSR_WIFI_TIM_RESETTING)) { staInfo->updateTimReqQueued = (u8) CSR_WIFI_TIM_RESET; unifi_trace(priv, UDBG4, " --uf_handle_uspframes_delivery, UAPSD timset\n"); if (!staInfo->timRequestPendingFlag) { @@ -2734,9 +2734,9 @@ void uf_process_wmm_deliver_ac_uapsd(unifi_priv_t * priv, if((srcStaInfo->powersaveMode[priority_q]==CSR_WIFI_AC_TRIGGER_ONLY_ENABLED) ||(srcStaInfo->powersaveMode[priority_q]==CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED)) { - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); srcStaInfo->triggerFramePriority = priority; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); unifi_trace(priv, UDBG2, "uf_process_wmm_deliver_ac_uapsd: trigger frame, Begin U-APSD, triggerQ=%x\n", priority_q); uf_handle_uspframes_delivery(priv, srcStaInfo, interfaceTag); } @@ -2744,7 +2744,7 @@ void uf_process_wmm_deliver_ac_uapsd(unifi_priv_t * priv, } -void uf_send_qos_null(unifi_priv_t * priv,u16 interfaceTag, const u8 *da,CSR_PRIORITY priority,CsrWifiRouterCtrlStaInfo_t * srcStaInfo) +void uf_send_qos_null(unifi_priv_t * priv, u16 interfaceTag, const u8 *da, CSR_PRIORITY priority, CsrWifiRouterCtrlStaInfo_t * srcStaInfo) { bulk_data_param_t bulkdata; CsrResult csrResult; @@ -2806,14 +2806,14 @@ void uf_send_qos_null(unifi_priv_t * priv,u16 interfaceTag, const u8 *da,CSR_PRI r = ul_send_signal_unpacked(priv, &signal, &bulkdata); if(r) { - unifi_error(priv, "failed to send QOS data null packet result: %d\n",r); + unifi_error(priv, "failed to send QOS data null packet result: %d\n", r); unifi_net_data_free(priv, &bulkdata.d[0]); } return; } -void uf_send_nulldata(unifi_priv_t * priv,u16 interfaceTag, const u8 *da,CSR_PRIORITY priority,CsrWifiRouterCtrlStaInfo_t * srcStaInfo) +void uf_send_nulldata(unifi_priv_t * priv, u16 interfaceTag, const u8 *da, CSR_PRIORITY priority, CsrWifiRouterCtrlStaInfo_t * srcStaInfo) { bulk_data_param_t bulkdata; CsrResult csrResult; @@ -2882,14 +2882,14 @@ void uf_send_nulldata(unifi_priv_t * priv,u16 interfaceTag, const u8 *da,CSR_PRI if(r == -ENOSPC) { unifi_trace(priv, UDBG1, "uf_send_nulldata: ENOSPC Requeue the Null frame\n"); enque_tx_data_pdu(priv, &bulkdata, &srcStaInfo->dataPdu[priority_q], &signal, 1); - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); srcStaInfo->noOfPktQueued++; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); } if(r && r != -ENOSPC){ - unifi_error(priv, "uf_send_nulldata: Failed to send Null frame Error = %d\n",r); + unifi_error(priv, "uf_send_nulldata: Failed to send Null frame Error = %d\n", r); unifi_net_data_free(priv, &bulkdata.d[0]); srcStaInfo->nullDataHostTag = INVALID_HOST_TAG; } @@ -2939,7 +2939,7 @@ u8 uf_check_broadcast_bssid(unifi_priv_t *priv, const bulk_data_param_t *bulkdat u8 uf_process_pm_bit_for_peer(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t * srcStaInfo, - u8 pmBit,u16 interfaceTag) + u8 pmBit, u16 interfaceTag) { u8 moreData = FALSE; u8 powerSaveChanged = FALSE; @@ -2955,22 +2955,22 @@ u8 uf_process_pm_bit_for_peer(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t * if(srcStaInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE) { /* disable the preemption */ - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); srcStaInfo->currentPeerState =CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE; powerSaveChanged = TRUE; /* enable the preemption */ - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); } else { return powerSaveChanged; } } else { if(srcStaInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE) { /* disable the preemption */ - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); srcStaInfo->currentPeerState = CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE; powerSaveChanged = TRUE; /* enable the preemption */ - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); }else { return powerSaveChanged; } @@ -2978,10 +2978,10 @@ u8 uf_process_pm_bit_for_peer(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t * if(srcStaInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE) { - unifi_trace(priv,UDBG3, "Peer with AID = %d is active now\n",srcStaInfo->aid); - process_peer_active_transition(priv,srcStaInfo,interfaceTag); + unifi_trace(priv, UDBG3, "Peer with AID = %d is active now\n", srcStaInfo->aid); + process_peer_active_transition(priv, srcStaInfo, interfaceTag); } else { - unifi_trace(priv,UDBG3, "Peer with AID = %d is in PS Now\n",srcStaInfo->aid); + unifi_trace(priv, UDBG3, "Peer with AID = %d is in PS Now\n", srcStaInfo->aid); /* Set TIM if needed */ if(!srcStaInfo->wmmOrQosEnabled) { moreData = (!list_empty(&srcStaInfo->mgtFrames) || @@ -2990,7 +2990,7 @@ u8 uf_process_pm_bit_for_peer(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t * if(moreData && (srcStaInfo->timSet == CSR_WIFI_TIM_RESET)) { unifi_trace(priv, UDBG3, "This condition should not occur\n"); if (!srcStaInfo->timRequestPendingFlag){ - update_tim(priv,srcStaInfo->aid,1,interfaceTag, srcStaInfo->assignedHandle); + update_tim(priv, srcStaInfo->aid, 1, interfaceTag, srcStaInfo->assignedHandle); } else { @@ -3013,7 +3013,7 @@ u8 uf_process_pm_bit_for_peer(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t * if(moreData && (srcStaInfo->timSet == CSR_WIFI_TIM_RESET)) { if (!srcStaInfo->timRequestPendingFlag){ - update_tim(priv,srcStaInfo->aid,1,interfaceTag, srcStaInfo->assignedHandle); + update_tim(priv, srcStaInfo->aid, 1, interfaceTag, srcStaInfo->assignedHandle); } else { @@ -3033,7 +3033,7 @@ u8 uf_process_pm_bit_for_peer(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t * -void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceTag) +void uf_process_ps_poll(unifi_priv_t *priv, u8* sa, u8* da, u8 pmBit, u16 interfaceTag) { CsrWifiRouterCtrlStaInfo_t *staRecord = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, sa, interfaceTag); @@ -3046,27 +3046,27 @@ void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceT unifi_trace(priv, UDBG3, "entering uf_process_ps_poll\n"); if(!staRecord) { - memcpy(peerMacAddress.a,sa,ETH_ALEN); + memcpy(peerMacAddress.a, sa, ETH_ALEN); unifi_trace(priv, UDBG3, "In uf_process_ps_poll, sta record not found:unexpected frame addr = %x:%x:%x:%x:%x:%x\n", - sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]); - CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress); + sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]); + CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, peerMacAddress); return; } - uf_process_pm_bit_for_peer(priv,staRecord,pmBit,interfaceTag); + uf_process_pm_bit_for_peer(priv, staRecord, pmBit, interfaceTag); /* Update station last activity time */ staRecord->activity_flag = TRUE; /* This should not change the PM bit as PS-POLL has PM bit always set */ if(!pmBit) { - unifi_notice (priv," PM bit reset in PS-POLL\n"); + unifi_notice (priv, " PM bit reset in PS-POLL\n"); return; } - if(IS_DTIM_ACTIVE(interfacePriv->dtimActive,interfacePriv->multicastPduHostTag)) { + if(IS_DTIM_ACTIVE(interfacePriv->dtimActive, interfacePriv->multicastPduHostTag)) { /* giving more priority to multicast packets so dropping ps-poll*/ - unifi_notice (priv," multicast transmission is going on so don't take action on PS-POLL\n"); + unifi_notice (priv, " multicast transmission is going on so don't take action on PS-POLL\n"); return; } @@ -3078,13 +3078,13 @@ void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceT !list_empty(&staRecord->mgtFrames)); buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK); - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,moreData,FALSE)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, staRecord, moreData, FALSE)) == -ENOSPC) { /* Clear the trigger bit transmission control*/ buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK); /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &staRecord->mgtFrames); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); unifi_trace(priv, UDBG1, "(ENOSPC) PS-POLL received : PDU sending failed \n"); priv->pausedStaHandle[3]=(u8)(staRecord->assignedHandle); } else { @@ -3101,13 +3101,13 @@ void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceT !list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_VO])); buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK); - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,moreData,FALSE)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, staRecord, moreData, FALSE)) == -ENOSPC) { /* Clear the trigger bit transmission control*/ buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK); /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &staRecord->dataPdu[UNIFI_TRAFFIC_Q_VO]); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); priv->pausedStaHandle[3]=(u8)(staRecord->assignedHandle); unifi_trace(priv, UDBG1, "(ENOSPC) PS-POLL received : PDU sending failed \n"); } else { @@ -3123,13 +3123,13 @@ void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceT moreData = !list_empty(&staRecord->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION]); buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK); - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,moreData,FALSE)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, staRecord, moreData, FALSE)) == -ENOSPC) { /* Clear the trigger bit transmission control*/ buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK); /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &staRecord->dataPdu[UNIFI_TRAFFIC_Q_CONTENTION]); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); priv->pausedStaHandle[0]=(u8)(staRecord->assignedHandle); unifi_trace(priv, UDBG1, "(ENOSPC) PS-POLL received : PDU sending failed \n"); } else { @@ -3150,7 +3150,7 @@ void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceT if(!moreData && (staRecord->timSet == CSR_WIFI_TIM_SET)) { unifi_trace(priv, UDBG3, "more data = NULL, set tim to 0 in uf_process_ps_poll\n"); if (!staRecord->timRequestPendingFlag){ - update_tim(priv,staRecord->aid,0,interfaceTag, staRecord->assignedHandle); + update_tim(priv, staRecord->aid, 0, interfaceTag, staRecord->assignedHandle); } else { @@ -3165,7 +3165,7 @@ void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceT } else { u8 allDeliveryEnabled = 0, dataAvailable = 0; - unifi_trace(priv, UDBG3,"Qos Support station.Processing PS-Poll\n"); + unifi_trace(priv, UDBG3, "Qos Support station.Processing PS-Poll\n"); /*Send Data From Management Frames*/ /* Priority orders for delivering the buffered packets are @@ -3179,7 +3179,7 @@ void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceT if (allDeliveryEnabled) { unifi_trace(priv, UDBG3, "uf_process_ps_poll: All ACs are delivery enable so Sending QOS Null in response of Ps-poll\n"); - uf_send_qos_null(priv,interfaceTag,sa,CSR_QOS_UP0,staRecord); + uf_send_qos_null(priv, interfaceTag, sa, CSR_QOS_UP0, staRecord); return; } @@ -3192,13 +3192,13 @@ void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceT buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK); /* Last parameter is EOSP & its false always for PS-POLL processing */ - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,moreData,FALSE)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, staRecord, moreData, FALSE)) == -ENOSPC) { /* Clear the trigger bit transmission control*/ buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK); /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &staRecord->mgtFrames); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); priv->pausedStaHandle[0]=(u8)(staRecord->assignedHandle); unifi_trace(priv, UDBG1, "(ENOSPC) PS-POLL received : PDU sending failed \n"); } else { @@ -3227,13 +3227,13 @@ void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceT buffered_pkt->transmissionControl |= (TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK); /* Last parameter is EOSP & its false always for PS-POLL processing */ - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staRecord,moreData,FALSE)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, staRecord, moreData, FALSE)) == -ENOSPC) { /* Clear the trigger bit transmission control*/ buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK | TRANSMISSION_CONTROL_EOSP_MASK); /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &staRecord->dataPdu[i]); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); priv->pausedStaHandle[0]=(u8)(staRecord->assignedHandle); unifi_trace(priv, UDBG1, "(ENOSPC) PS-POLL received : PDU sending failed \n"); } else { @@ -3256,7 +3256,7 @@ void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceT if(!moreData && (staRecord->timSet == CSR_WIFI_TIM_SET)) { unifi_trace(priv, UDBG3, "more data = NULL, set tim to 0 in uf_process_ps_poll\n"); if (!staRecord->timRequestPendingFlag){ - update_tim(priv,staRecord->aid,0,interfaceTag, staRecord->assignedHandle); + update_tim(priv, staRecord->aid, 0, interfaceTag, staRecord->assignedHandle); } else { @@ -3311,7 +3311,7 @@ void uf_prepare_send_cfm_list_for_queued_pkts(unifi_priv_t * priv, struct list_head *placeHolder; unsigned long lock_flags; - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); /* Search through the list and if confirmation required for any frames, add it to the send_cfm list */ @@ -3337,7 +3337,7 @@ void uf_prepare_send_cfm_list_for_queued_pkts(unifi_priv_t * priv, } } - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); } @@ -3352,7 +3352,7 @@ void uf_flush_list(unifi_priv_t * priv, struct list_head * list) unifi_trace(priv, UDBG5, "entering the uf_flush_list \n"); - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); /* go through list, delete & free memory */ list_for_each_safe(listHead, placeHolder, list) { tx_q_item = list_entry(listHead, tx_buffered_packets_t, q); @@ -3378,7 +3378,7 @@ void uf_flush_list(unifi_priv_t * priv, struct list_head * list) priv->noOfPktQueuedInDriver--; } } - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); } tx_buffered_packets_t *dequeue_tx_data_pdu(unifi_priv_t *priv, struct list_head *txList) @@ -3403,13 +3403,13 @@ tx_buffered_packets_t *dequeue_tx_data_pdu(unifi_priv_t *priv, struct list_head } /* return first node after header, & delete from the list && atleast one item exist */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_for_each_safe(listHead, placeHolder, txList) { tx_q_item = list_entry(listHead, tx_buffered_packets_t, q); list_del(listHead); break; } - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); if (tx_q_item) { unifi_trace(priv, UDBG5, @@ -3440,20 +3440,20 @@ CsrWifiRouterCtrlStaInfo_t *CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress( interfacePriv = priv->interfacePriv[interfaceTag]; /* disable the preemption until station record is fetched */ - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); for (i = 0; i < UNIFI_MAX_CONNECTIONS; i++) { if (interfacePriv->staInfo[i]!= NULL) { if (!memcmp(((CsrWifiRouterCtrlStaInfo_t *) (interfacePriv->staInfo[i]))->peerMacAddress.a, peerMacAddress, ETH_ALEN)) { /* enable the preemption as station record is fetched */ - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); unifi_trace(priv, UDBG5, "peer entry found in station record\n"); return ((CsrWifiRouterCtrlStaInfo_t *) (interfacePriv->staInfo[i])); } } } /* enable the preemption as station record is fetched */ - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); unifi_trace(priv, UDBG5, "peer entry not found in station record\n"); return NULL; } @@ -3487,7 +3487,7 @@ void uf_check_inactivity(unifi_priv_t *priv, u16 interfaceTag, u32 currentTime) return; } - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); /* Go through the list of stations to check for inactivity */ for(i = 0; i < UNIFI_MAX_CONNECTIONS; i++) { staInfo = CsrWifiRouterCtrlGetStationRecordFromHandle(priv, i, interfaceTag); @@ -3502,7 +3502,7 @@ void uf_check_inactivity(unifi_priv_t *priv, u16 interfaceTag, u32 currentTime) elapsedTime = (currentTime >= staInfo->lastActivity)? (currentTime - staInfo->lastActivity): (~((u32)0) - staInfo->lastActivity + currentTime); - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); if (elapsedTime > MAX_INACTIVITY_INTERVAL) { memcpy((u8*)&peerMacAddress, (u8*)&staInfo->peerMacAddress, sizeof(CsrWifiMacAddress)); @@ -3545,7 +3545,7 @@ void uf_update_sta_activity(unifi_priv_t *priv, u16 interfaceTag, const u8 *peer return; } - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); /* Update activity */ staInfo->lastActivity = currentTime; @@ -3558,7 +3558,7 @@ void uf_update_sta_activity(unifi_priv_t *priv, u16 interfaceTag, const u8 *peer (currentTime - interfacePriv->last_inactivity_check): (~((u32)0) - interfacePriv->last_inactivity_check + currentTime); - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); /* Check if it is time to run the inactivity handler */ if (elapsedTime > INACTIVITY_CHECK_INTERVAL) { @@ -3572,19 +3572,19 @@ void resume_unicast_buffered_frames(unifi_priv_t *priv, u16 interfaceTag) u8 i; int j; tx_buffered_packets_t * buffered_pkt = NULL; - u8 hipslotFree[4] = {TRUE,TRUE,TRUE,TRUE}; + u8 hipslotFree[4] = {TRUE, TRUE, TRUE, TRUE}; int r; unsigned long lock_flags; - while(!isRouterBufferEnabled(priv,3) && - ((buffered_pkt=dequeue_tx_data_pdu(priv,&interfacePriv->genericMgtFrames))!=NULL)) { + while(!isRouterBufferEnabled(priv, 3) && + ((buffered_pkt=dequeue_tx_data_pdu(priv, &interfacePriv->genericMgtFrames))!=NULL)) { buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK); - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,NULL,0,FALSE)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, NULL, 0, FALSE)) == -ENOSPC) { /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &interfacePriv->genericMgtFrames); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); hipslotFree[3]=FALSE; break; }else { @@ -3606,12 +3606,12 @@ void resume_unicast_buffered_frames(unifi_priv_t *priv, u16 interfaceTag) while((( TRUE == hipslotFree[3] ) && (buffered_pkt=dequeue_tx_data_pdu(priv, &staInfo->mgtFrames)))) { buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK); - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staInfo,0,FALSE)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, staInfo, 0, FALSE)) == -ENOSPC) { unifi_trace(priv, UDBG3, "(ENOSPC) in resume_unicast_buffered_frames:: hip slots are full for voice queue\n"); /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &staInfo->mgtFrames); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); priv->pausedStaHandle[3]=(u8)(staInfo->assignedHandle); hipslotFree[3] = FALSE; break; @@ -3632,11 +3632,11 @@ void resume_unicast_buffered_frames(unifi_priv_t *priv, u16 interfaceTag) while((buffered_pkt=dequeue_tx_data_pdu(priv, &staInfo->dataPdu[j]))) { buffered_pkt->transmissionControl &= ~(TRANSMISSION_CONTROL_TRIGGER_MASK|TRANSMISSION_CONTROL_EOSP_MASK); - if((r=frame_and_send_queued_pdu(priv,buffered_pkt,staInfo,0,FALSE)) == -ENOSPC) { + if((r=frame_and_send_queued_pdu(priv, buffered_pkt, staInfo, 0, FALSE)) == -ENOSPC) { /* Enqueue at the head of the queue */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_add(&buffered_pkt->q, &staInfo->dataPdu[j]); - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); priv->pausedStaHandle[j]=(u8)(staInfo->assignedHandle); hipslotFree[j]=FALSE; break; @@ -3653,7 +3653,7 @@ void resume_unicast_buffered_frames(unifi_priv_t *priv, u16 interfaceTag) } } } -void update_eosp_to_head_of_broadcast_list_head(unifi_priv_t *priv,u16 interfaceTag) +void update_eosp_to_head_of_broadcast_list_head(unifi_priv_t *priv, u16 interfaceTag) { netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag]; @@ -3668,15 +3668,15 @@ void update_eosp_to_head_of_broadcast_list_head(unifi_priv_t *priv,u16 interface * because we have received any mgmt packet so it should not hold for long time * peer may time out. */ - spin_lock_irqsave(&priv->tx_q_lock,lock_flags); + spin_lock_irqsave(&priv->tx_q_lock, lock_flags); list_for_each_safe(listHead, placeHolder, &interfacePriv->genericMulticastOrBroadCastFrames) { tx_q_item = list_entry(listHead, tx_buffered_packets_t, q); tx_q_item->transmissionControl |= TRANSMISSION_CONTROL_EOSP_MASK; tx_q_item->transmissionControl = (tx_q_item->transmissionControl & ~(CSR_NO_CONFIRM_REQUIRED)); - unifi_trace(priv, UDBG1,"updating eosp for list Head hostTag:= 0x%x ",tx_q_item->hostTag); + unifi_trace(priv, UDBG1, "updating eosp for list Head hostTag:= 0x%x ", tx_q_item->hostTag); break; } - spin_unlock_irqrestore(&priv->tx_q_lock,lock_flags); + spin_unlock_irqrestore(&priv->tx_q_lock, lock_flags); } } @@ -3692,7 +3692,7 @@ void update_eosp_to_head_of_broadcast_list_head(unifi_priv_t *priv,u16 interface * interfaceTag For which resume should happen * --------------------------------------------------------------------------- */ -void resume_suspended_uapsd(unifi_priv_t* priv,u16 interfaceTag) +void resume_suspended_uapsd(unifi_priv_t* priv, u16 interfaceTag) { u8 startIndex; @@ -3701,7 +3701,7 @@ void resume_suspended_uapsd(unifi_priv_t* priv,u16 interfaceTag) unifi_trace(priv, UDBG2, "++resume_suspended_uapsd: \n"); for(startIndex= 0; startIndex < UNIFI_MAX_CONNECTIONS;startIndex++) { - staInfo = CsrWifiRouterCtrlGetStationRecordFromHandle(priv,startIndex,interfaceTag); + staInfo = CsrWifiRouterCtrlGetStationRecordFromHandle(priv, startIndex, interfaceTag); if(!staInfo || !staInfo->wmmOrQosEnabled) { continue; @@ -3716,10 +3716,10 @@ void resume_suspended_uapsd(unifi_priv_t* priv,u16 interfaceTag) staInfo->currentPeerState, staInfo->uapsdActive, staInfo->uspSuspend); if (staInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_ACTIVE) { - spin_lock_irqsave(&priv->staRecord_lock,lock_flags); + spin_lock_irqsave(&priv->staRecord_lock, lock_flags); staInfo->uapsdActive = FALSE; staInfo->uspSuspend = FALSE; - spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags); + spin_unlock_irqrestore(&priv->staRecord_lock, lock_flags); } } } diff --git a/drivers/staging/csr/unifi_priv.h b/drivers/staging/csr/unifi_priv.h index d20d74ce56cb..37302f3c2f6c 100644 --- a/drivers/staging/csr/unifi_priv.h +++ b/drivers/staging/csr/unifi_priv.h @@ -259,7 +259,7 @@ typedef u8 CsrWifiAcPowersaveMode; #define IS_DELIVERY_ENABLED(mode) (mode & CSR_WIFI_AC_DELIVERY_ONLY_ENABLE)? 1: 0 #define IS_DELIVERY_AND_TRIGGER_ENABLED(mode) ((mode & CSR_WIFI_AC_DELIVERY_ONLY_ENABLE)||(mode & CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED))? 1: 0 -#define IS_DTIM_ACTIVE(flag,hostTag) ((flag == TRUE || hostTag != INVALID_HOST_TAG)) +#define IS_DTIM_ACTIVE(flag, hostTag) ((flag == TRUE || hostTag != INVALID_HOST_TAG)) #define INVALID_HOST_TAG 0xFFFFFFFF #define UNIFI_TRAFFIC_Q_CONTENTION UNIFI_TRAFFIC_Q_BE @@ -767,9 +767,9 @@ typedef struct netInterface_priv } netInterface_priv_t; #ifdef CSR_SUPPORT_SME -#define routerStartBuffering(priv,queue) priv->routerBufferEnable[(queue)] = TRUE; -#define routerStopBuffering(priv,queue) priv->routerBufferEnable[(queue)] = FALSE; -#define isRouterBufferEnabled(priv,queue) priv->routerBufferEnable[(queue)] +#define routerStartBuffering(priv, queue) priv->routerBufferEnable[(queue)] = TRUE; +#define routerStopBuffering(priv, queue) priv->routerBufferEnable[(queue)] = FALSE; +#define isRouterBufferEnabled(priv, queue) priv->routerBufferEnable[(queue)] #endif #ifdef USE_DRIVER_LOCK @@ -919,8 +919,8 @@ int uf_verify_m4(unifi_priv_t *priv, const unsigned char *packet, #ifdef CSR_SUPPORT_SME u8 uf_check_broadcast_bssid(unifi_priv_t *priv, const bulk_data_param_t *bulkdata); -u8 uf_process_pm_bit_for_peer(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t * srcStaInfo,u8 pmBit,u16 interfaceTag); -void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceTag); +u8 uf_process_pm_bit_for_peer(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t * srcStaInfo, u8 pmBit, u16 interfaceTag); +void uf_process_ps_poll(unifi_priv_t *priv, u8* sa, u8* da, u8 pmBit, u16 interfaceTag); int uf_ap_process_data_pdu(unifi_priv_t *priv, struct sk_buff *skb, struct ethhdr *ehdr, CsrWifiRouterCtrlStaInfo_t * srcStaInfo, const CSR_SIGNAL *signal, @@ -936,17 +936,17 @@ void uf_send_buffered_data_from_ac(unifi_priv_t *priv, CsrWifiRouterCtrlStaInfo_ void uf_send_buffered_data_from_delivery_ac(unifi_priv_t *priv, CsrWifiRouterCtrlStaInfo_t * staInfo, u8 queue, struct list_head *txList); void uf_continue_uapsd(unifi_priv_t *priv, CsrWifiRouterCtrlStaInfo_t * staInfo); -void uf_send_qos_null(unifi_priv_t * priv,u16 interfaceTag, const u8 *da,CSR_PRIORITY priority,CsrWifiRouterCtrlStaInfo_t * srcStaInfo); -void uf_send_nulldata(unifi_priv_t * priv,u16 interfaceTag, const u8 *da,CSR_PRIORITY priority,CsrWifiRouterCtrlStaInfo_t * srcStaInfo); +void uf_send_qos_null(unifi_priv_t * priv, u16 interfaceTag, const u8 *da, CSR_PRIORITY priority, CsrWifiRouterCtrlStaInfo_t * srcStaInfo); +void uf_send_nulldata(unifi_priv_t * priv, u16 interfaceTag, const u8 *da, CSR_PRIORITY priority, CsrWifiRouterCtrlStaInfo_t * srcStaInfo); #endif CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, u8 *peerMacAddress, CSR_CLIENT_TAG hostTag, u16 interfaceTag, CSR_TRANSMISSION_CONTROL transmissionControl, CSR_RATE TransmitRate, CSR_PRIORITY priority, CSR_PROCESS_ID senderId, bulk_data_param_t *bulkdata); -void uf_process_ma_vif_availibility_ind(unifi_priv_t *priv,u8 *sigdata, u32 siglen); +void uf_process_ma_vif_availibility_ind(unifi_priv_t *priv, u8 *sigdata, u32 siglen); #ifdef CSR_SUPPORT_SME -void uf_send_buffered_frames(unifi_priv_t *priv,unifi_TrafficQueue queue); -int uf_process_station_records_for_sending_data(unifi_priv_t *priv,u16 interfaceTag, +void uf_send_buffered_frames(unifi_priv_t *priv, unifi_TrafficQueue queue); +int uf_process_station_records_for_sending_data(unifi_priv_t *priv, u16 interfaceTag, CsrWifiRouterCtrlStaInfo_t *srcStaInfo, CsrWifiRouterCtrlStaInfo_t *dstStaInfo); void uf_prepare_send_cfm_list_for_queued_pkts(unifi_priv_t * priv, @@ -958,8 +958,8 @@ void send_auto_ma_packet_confirm(unifi_priv_t *priv, void uf_flush_list(unifi_priv_t * priv, struct list_head * list); tx_buffered_packets_t *dequeue_tx_data_pdu(unifi_priv_t *priv, struct list_head *txList); void resume_unicast_buffered_frames(unifi_priv_t *priv, u16 interfaceTag); -void update_eosp_to_head_of_broadcast_list_head(unifi_priv_t *priv,u16 interfaceTag); -void resume_suspended_uapsd(unifi_priv_t* priv,u16 interfaceTag); +void update_eosp_to_head_of_broadcast_list_head(unifi_priv_t *priv, u16 interfaceTag); +void resume_suspended_uapsd(unifi_priv_t* priv, u16 interfaceTag); #endif /* * netdev.c @@ -1048,14 +1048,14 @@ CsrWifiRouterCtrlStaInfo_t * CsrWifiRouterCtrlGetStationRecordFromHandle(unifi_p u16 interfaceTag); void uf_update_sta_activity(unifi_priv_t *priv, u16 interfaceTag, const u8 *peerMacAddress); -void uf_process_ma_pkt_cfm_for_ap(unifi_priv_t *priv,u16 interfaceTag, const CSR_MA_PACKET_CONFIRM *pkt_cfm); +void uf_process_ma_pkt_cfm_for_ap(unifi_priv_t *priv, u16 interfaceTag, const CSR_MA_PACKET_CONFIRM *pkt_cfm); #endif void uf_resume_data_plane(unifi_priv_t *priv, int queue, CsrWifiMacAddress peer_address, u16 interfaceTag); void uf_free_pending_rx_packets(unifi_priv_t *priv, int queue, - CsrWifiMacAddress peer_address,u16 interfaceTag); + CsrWifiMacAddress peer_address, u16 interfaceTag); int uf_register_netdev(unifi_priv_t *priv, int numOfInterface); void uf_unregister_netdev(unifi_priv_t *priv); diff --git a/drivers/staging/csr/unifi_sme.c b/drivers/staging/csr/unifi_sme.c index 90295035621f..50908822b3c8 100644 --- a/drivers/staging/csr/unifi_sme.c +++ b/drivers/staging/csr/unifi_sme.c @@ -133,7 +133,7 @@ sme_log_event(ul_client_t *pcli, unicastPdu = FALSE; CsrWifiRouterCtrlMicFailureIndSend (priv->CSR_WIFI_SME_IFACEQUEUE, 0, - (ind->VirtualInterfaceIdentifier & 0xff),peerMacAddress, + (ind->VirtualInterfaceIdentifier & 0xff), peerMacAddress, unicastPdu); return; } @@ -143,10 +143,10 @@ sme_log_event(ul_client_t *pcli, { u8 pmBit = (frmCtrl & 0x1000)?0x01:0x00; u16 interfaceTag = (ind->VirtualInterfaceIdentifier & 0xff); - CsrWifiRouterCtrlStaInfo_t *srcStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,taddr,interfaceTag); + CsrWifiRouterCtrlStaInfo_t *srcStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, taddr, interfaceTag); if((srcStaInfo != NULL) && (uf_check_broadcast_bssid(priv, bulkdata)== FALSE)) { - uf_process_pm_bit_for_peer(priv,srcStaInfo,pmBit,interfaceTag); + uf_process_pm_bit_for_peer(priv, srcStaInfo, pmBit, interfaceTag); /* Update station last activity flag */ srcStaInfo->activity_flag = TRUE; @@ -169,7 +169,7 @@ sme_log_event(ul_client_t *pcli, return; } - unifi_trace(priv,UDBG1,"MA-PACKET Confirm (%x, %x)\n", cfm->HostTag, cfm->TransmissionStatus); + unifi_trace(priv, UDBG1, "MA-PACKET Confirm (%x, %x)\n", cfm->HostTag, cfm->TransmissionStatus); interfacePriv = priv->interfacePriv[interfaceTag]; #ifdef CSR_SUPPORT_SME @@ -177,7 +177,7 @@ sme_log_event(ul_client_t *pcli, interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) { if(cfm->HostTag == interfacePriv->multicastPduHostTag){ - uf_process_ma_pkt_cfm_for_ap(priv ,interfaceTag, cfm); + uf_process_ma_pkt_cfm_for_ap(priv, interfaceTag, cfm); } } #endif @@ -395,7 +395,7 @@ uf_multicast_list_wq(struct work_struct *work) interfacePriv->mc_list_count); /* Flush the current list */ - CsrWifiRouterCtrlMulticastAddressIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0, interfaceTag, CSR_WIFI_SME_LIST_ACTION_FLUSH, 0, NULL); + CsrWifiRouterCtrlMulticastAddressIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, CSR_WIFI_SME_LIST_ACTION_FLUSH, 0, NULL); mc_count = interfacePriv->mc_list_count; mc_list = interfacePriv->mc_list; @@ -419,7 +419,7 @@ uf_multicast_list_wq(struct work_struct *work) return; } - CsrWifiRouterCtrlMulticastAddressIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0, + CsrWifiRouterCtrlMulticastAddressIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, CSR_WIFI_SME_LIST_ACTION_ADD, mc_count, multicast_address_list); @@ -950,7 +950,7 @@ int } return i; } -int unifi_cfg_set_ap_config(unifi_priv_t * priv,unsigned char* arg) +int unifi_cfg_set_ap_config(unifi_priv_t * priv, unsigned char* arg) { uf_cfg_ap_config_t cfg_ap_config; char *buffer; @@ -981,7 +981,7 @@ int unifi_cfg_set_ap_config(unifi_priv_t * priv,unsigned char* arg) priv->ap_mac_config.phySupportedBitmap = cfg_ap_config.phySupportedBitmap; priv->ap_mac_config.maxListenInterval=cfg_ap_config.maxListenInterval; - priv->ap_mac_config.supportedRatesCount= uf_configure_supported_rates(priv->ap_mac_config.supportedRates,priv->ap_mac_config.phySupportedBitmap); + priv->ap_mac_config.supportedRatesCount= uf_configure_supported_rates(priv->ap_mac_config.supportedRates, priv->ap_mac_config.phySupportedBitmap); return 0; } @@ -1051,7 +1051,7 @@ uf_ta_ind_wq(struct work_struct *work) u16 interfaceTag = 0; - CsrWifiRouterCtrlTrafficProtocolIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0, + CsrWifiRouterCtrlTrafficProtocolIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, ind->packet_type, ind->direction, @@ -1119,7 +1119,7 @@ uf_ta_sample_ind_wq(struct work_struct *work) } } - CsrWifiRouterCtrlTrafficSampleIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0, interfaceTag, ind->stats); + CsrWifiRouterCtrlTrafficSampleIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0, interfaceTag, ind->stats); ind->in_use = 0; @@ -1219,7 +1219,7 @@ void uf_send_pkt_to_encrypt(struct work_struct *work) kfree(pktBulkData); /* Would have been copied over by the SME Handler */ } else { - unifi_warning(priv, "uf_send_pkt_to_encrypt() is NOT applicable for interface mode - %d\n",interfacePriv->interfaceMode); + unifi_warning(priv, "uf_send_pkt_to_encrypt() is NOT applicable for interface mode - %d\n", interfacePriv->interfaceMode); } }/* uf_send_pkt_to_encrypt() */ #endif diff --git a/drivers/staging/csr/unifi_sme.h b/drivers/staging/csr/unifi_sme.h index b689cfe2b100..aff9aa178124 100644 --- a/drivers/staging/csr/unifi_sme.h +++ b/drivers/staging/csr/unifi_sme.h @@ -210,9 +210,9 @@ int sme_mgt_mib_get(unifi_priv_t *priv, int sme_mgt_mib_set(unifi_priv_t *priv, unsigned char *varbind, int length); #ifdef CSR_SUPPORT_WEXT_AP -int sme_ap_start(unifi_priv_t *priv,u16 interface_tag,CsrWifiSmeApConfig_t *ap_config); -int sme_ap_stop(unifi_priv_t *priv,u16 interface_tag); -int sme_ap_config(unifi_priv_t *priv,CsrWifiSmeApMacConfig *ap_mac_config, CsrWifiNmeApConfig *group_security_config); +int sme_ap_start(unifi_priv_t *priv, u16 interface_tag, CsrWifiSmeApConfig_t *ap_config); +int sme_ap_stop(unifi_priv_t *priv, u16 interface_tag); +int sme_ap_config(unifi_priv_t *priv, CsrWifiSmeApMacConfig *ap_mac_config, CsrWifiNmeApConfig *group_security_config); int uf_configure_supported_rates(u8 * supportedRates, u8 phySupportedBitmap); #endif int unifi_translate_scan(struct net_device *dev, @@ -234,7 +234,7 @@ int unifi_cfg_get_info(unifi_priv_t *priv, unsigned char *arg); int unifi_cfg_strict_draft_n(unifi_priv_t *priv, unsigned char *arg); int unifi_cfg_enable_okc(unifi_priv_t *priv, unsigned char *arg); #ifdef CSR_SUPPORT_WEXT_AP -int unifi_cfg_set_ap_config(unifi_priv_t * priv,unsigned char* arg); +int unifi_cfg_set_ap_config(unifi_priv_t * priv, unsigned char* arg); #endif diff --git a/drivers/staging/cxt1e1/comet.c b/drivers/staging/cxt1e1/comet.c index 52224cdc967d..fabfd779c668 100644 --- a/drivers/staging/cxt1e1/comet.c +++ b/drivers/staging/cxt1e1/comet.c @@ -13,7 +13,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#include +#include #include #include "pmcc4_sysdep.h" #include "sbecom_inline_linux.h" @@ -35,235 +35,253 @@ extern int cxt1e1_log_level; #define COMET_NUM_UNITS 5 /* Number of points per entry in table */ /* forward references */ -STATIC void SetPwrLevel (comet_t * comet); -STATIC void WrtRcvEqualizerTbl (ci_t * ci, comet_t * comet, u_int32_t *table); -STATIC void WrtXmtWaveformTbl (ci_t * ci, comet_t * comet, u_int8_t table[COMET_NUM_SAMPLES][COMET_NUM_UNITS]); +STATIC void SetPwrLevel(comet_t *comet); +STATIC void WrtRcvEqualizerTbl(ci_t *ci, comet_t *comet, u_int32_t *table); +STATIC void WrtXmtWaveformTbl(ci_t *ci, comet_t *comet, u_int8_t table[COMET_NUM_SAMPLES][COMET_NUM_UNITS]); void *TWV_table[12] = { - TWVLongHaul0DB, TWVLongHaul7_5DB, TWVLongHaul15DB, TWVLongHaul22_5DB, - TWVShortHaul0, TWVShortHaul1, TWVShortHaul2, TWVShortHaul3, TWVShortHaul4, - TWVShortHaul5, - TWV_E1_75Ohm, /** PORT POINT - 75 Ohm not supported **/ - TWV_E1_120Ohm + TWVLongHaul0DB, TWVLongHaul7_5DB, TWVLongHaul15DB, TWVLongHaul22_5DB, + TWVShortHaul0, TWVShortHaul1, TWVShortHaul2, TWVShortHaul3, + TWVShortHaul4, TWVShortHaul5, + /** PORT POINT - 75 Ohm not supported **/ + TWV_E1_75Ohm, + TWV_E1_120Ohm }; static int -lbo_tbl_lkup (int t1, int lbo) -{ - if ((lbo < CFG_LBO_LH0) || (lbo > CFG_LBO_E120)) /* error switches to - * default */ - { - if (t1) - lbo = CFG_LBO_LH0; /* default T1 waveform table */ - else - lbo = CFG_LBO_E120; /* default E1 waveform table */ - } - return (lbo - 1); /* make index ZERO relative */ +lbo_tbl_lkup(int t1, int lbo) { + /* error switches to default */ + if ((lbo < CFG_LBO_LH0) || (lbo > CFG_LBO_E120)) { + if (t1) + /* default T1 waveform table */ + lbo = CFG_LBO_LH0; + else + /* default E1 waveform table */ + lbo = CFG_LBO_E120; + } + /* make index ZERO relative */ + return lbo - 1; } - -void -init_comet (void *ci, comet_t * comet, u_int32_t port_mode, int clockmaster, - u_int8_t moreParams) +void init_comet(void *ci, comet_t *comet, u_int32_t port_mode, int clockmaster, + u_int8_t moreParams) { - u_int8_t isT1mode; - u_int8_t tix = CFG_LBO_LH0; /* T1 default */ + u_int8_t isT1mode; + /* T1 default */ + u_int8_t tix = CFG_LBO_LH0; + isT1mode = IS_FRAME_ANY_T1(port_mode); + /* T1 or E1 */ + if (isT1mode) { + /* Select T1 Mode & PIO output enabled */ + pci_write_32((u_int32_t *) &comet->gbl_cfg, 0xa0); + /* default T1 waveform table */ + tix = lbo_tbl_lkup(isT1mode, CFG_LBO_LH0); + } else { + /* Select E1 Mode & PIO output enabled */ + pci_write_32((u_int32_t *) &comet->gbl_cfg, 0x81); + /* default E1 waveform table */ + tix = lbo_tbl_lkup(isT1mode, CFG_LBO_E120); + } - isT1mode = IS_FRAME_ANY_T1 (port_mode); - /* T1 or E1 */ - if (isT1mode) - { - pci_write_32 ((u_int32_t *) &comet->gbl_cfg, 0xa0); /* Select T1 Mode & PIO - * output enabled */ - tix = lbo_tbl_lkup (isT1mode, CFG_LBO_LH0); /* default T1 waveform - * table */ - } else - { - pci_write_32 ((u_int32_t *) &comet->gbl_cfg, 0x81); /* Select E1 Mode & PIO - * output enabled */ - tix = lbo_tbl_lkup (isT1mode, CFG_LBO_E120); /* default E1 waveform - * table */ - } + if (moreParams & CFG_LBO_MASK) + /* dial-in requested waveform table */ + tix = lbo_tbl_lkup(isT1mode, moreParams & CFG_LBO_MASK); + /* Tx line Intfc cfg Set for analog & no special patterns */ + /* Transmit Line Interface Config. */ + pci_write_32((u_int32_t *) &comet->tx_line_cfg, 0x00); + /* master test Ignore Test settings for now */ + /* making sure it's Default value */ + pci_write_32((u_int32_t *) &comet->mtest, 0x00); + /* Turn on Center (CENT) and everything else off */ + /* RJAT cfg */ + pci_write_32((u_int32_t *) &comet->rjat_cfg, 0x10); + /* Set Jitter Attenuation to recommend T1 values */ + if (isT1mode) { + /* RJAT Divider N1 Control */ + pci_write_32((u_int32_t *) &comet->rjat_n1clk, 0x2F); + /* RJAT Divider N2 Control */ + pci_write_32((u_int32_t *) &comet->rjat_n2clk, 0x2F); + } else { + /* RJAT Divider N1 Control */ + pci_write_32((u_int32_t *) &comet->rjat_n1clk, 0xFF); + /* RJAT Divider N2 Control */ + pci_write_32((u_int32_t *) &comet->rjat_n2clk, 0xFF); + } - if (moreParams & CFG_LBO_MASK) - tix = lbo_tbl_lkup (isT1mode, moreParams & CFG_LBO_MASK); /* dial-in requested - * waveform table */ + /* Turn on Center (CENT) and everything else off */ + /* TJAT Config. */ + pci_write_32((u_int32_t *) &comet->tjat_cfg, 0x10); - /* Tx line Intfc cfg ** Set for analog & no special patterns */ - pci_write_32 ((u_int32_t *) &comet->tx_line_cfg, 0x00); /* Transmit Line - * Interface Config. */ + /* Do not bypass jitter attenuation and bypass elastic store */ + /* rx opts */ + pci_write_32((u_int32_t *) &comet->rx_opt, 0x00); - /* master test ** Ignore Test settings for now */ - pci_write_32 ((u_int32_t *) &comet->mtest, 0x00); /* making sure it's - * Default value */ + /* TJAT ctrl & TJAT divider ctrl */ + /* Set Jitter Attenuation to recommended T1 values */ + if (isT1mode) { + /* TJAT Divider N1 Control */ + pci_write_32((u_int32_t *) &comet->tjat_n1clk, 0x2F); + /* TJAT Divider N2 Control */ + pci_write_32((u_int32_t *) &comet->tjat_n2clk, 0x2F); + } else { + /* TJAT Divider N1 Control */ + pci_write_32((u_int32_t *) &comet->tjat_n1clk, 0xFF); + /* TJAT Divider N2 Control */ + pci_write_32((u_int32_t *) &comet->tjat_n2clk, 0xFF); + } - /* Turn on Center (CENT) and everything else off */ - pci_write_32 ((u_int32_t *) &comet->rjat_cfg, 0x10); /* RJAT cfg */ - /* Set Jitter Attenuation to recommend T1 values */ - if (isT1mode) - { - pci_write_32 ((u_int32_t *) &comet->rjat_n1clk, 0x2F); /* RJAT Divider N1 - * Control */ - pci_write_32 ((u_int32_t *) &comet->rjat_n2clk, 0x2F); /* RJAT Divider N2 - * Control */ - } else - { - pci_write_32 ((u_int32_t *) &comet->rjat_n1clk, 0xFF); /* RJAT Divider N1 - * Control */ - pci_write_32 ((u_int32_t *) &comet->rjat_n2clk, 0xFF); /* RJAT Divider N2 - * Control */ - } + /* 1c: rx ELST cfg 20: tx ELST cfg 28&38: rx&tx data link ctrl */ - /* Turn on Center (CENT) and everything else off */ - pci_write_32 ((u_int32_t *) &comet->tjat_cfg, 0x10); /* TJAT Config. */ - - /* Do not bypass jitter attenuation and bypass elastic store */ - pci_write_32 ((u_int32_t *) &comet->rx_opt, 0x00); /* rx opts */ - - /* TJAT ctrl & TJAT divider ctrl */ - /* Set Jitter Attenuation to recommended T1 values */ - if (isT1mode) - { - pci_write_32 ((u_int32_t *) &comet->tjat_n1clk, 0x2F); /* TJAT Divider N1 - * Control */ - pci_write_32 ((u_int32_t *) &comet->tjat_n2clk, 0x2F); /* TJAT Divider N2 - * Control */ - } else - { - pci_write_32 ((u_int32_t *) &comet->tjat_n1clk, 0xFF); /* TJAT Divider N1 - * Control */ - pci_write_32 ((u_int32_t *) &comet->tjat_n2clk, 0xFF); /* TJAT Divider N2 - * Control */ - } - - /* 1c: rx ELST cfg 20: tx ELST cfg 28&38: rx&tx data link ctrl */ - if (isT1mode) - { /* Select 193-bit frame format */ - pci_write_32 ((u_int32_t *) &comet->rx_elst_cfg, 0x00); - pci_write_32 ((u_int32_t *) &comet->tx_elst_cfg, 0x00); - } else - { /* Select 256-bit frame format */ - pci_write_32 ((u_int32_t *) &comet->rx_elst_cfg, 0x03); - pci_write_32 ((u_int32_t *) &comet->tx_elst_cfg, 0x03); - pci_write_32 ((u_int32_t *) &comet->rxce1_ctl, 0x00); /* disable T1 data link - * receive */ - pci_write_32 ((u_int32_t *) &comet->txci1_ctl, 0x00); /* disable T1 data link - * transmit */ - } + /* Select 193-bit frame format */ + if (isT1mode) { + pci_write_32((u_int32_t *) &comet->rx_elst_cfg, 0x00); + pci_write_32((u_int32_t *) &comet->tx_elst_cfg, 0x00); + } else { + /* Select 256-bit frame format */ + pci_write_32((u_int32_t *) &comet->rx_elst_cfg, 0x03); + pci_write_32((u_int32_t *) &comet->tx_elst_cfg, 0x03); + /* disable T1 data link receive */ + pci_write_32((u_int32_t *) &comet->rxce1_ctl, 0x00); + /* disable T1 data link transmit */ + pci_write_32((u_int32_t *) &comet->txci1_ctl, 0x00); + } /* the following is a default value */ /* Enable 8 out of 10 validation */ - pci_write_32 ((u_int32_t *) &comet->t1_rboc_ena, 0x00); /* t1RBOC - * enable(BOC:BitOriented - * Code) */ - if (isT1mode) - { + /* t1RBOC enable(BOC:BitOriented Code) */ + pci_write_32((u_int32_t *) &comet->t1_rboc_ena, 0x00); + if (isT1mode) + { - /* IBCD cfg: aka Inband Code Detection ** loopback code length set to */ - pci_write_32 ((u_int32_t *) &comet->ibcd_cfg, 0x04); /* 6 bit down, 5 bit up - * (assert) */ - pci_write_32 ((u_int32_t *) &comet->ibcd_act, 0x08); /* line loopback - * activate pattern */ - pci_write_32 ((u_int32_t *) &comet->ibcd_deact, 0x24); /* deactivate code - * pattern (i.e.001) */ - } + /* IBCD cfg: aka Inband Code Detection ** loopback code length set to */ + /* 6 bit down, 5 bit up (assert) */ + pci_write_32((u_int32_t *) &comet->ibcd_cfg, 0x04); + /* line loopback activate pattern */ + pci_write_32((u_int32_t *) &comet->ibcd_act, 0x08); + /* deactivate code pattern (i.e.001) */ + pci_write_32((u_int32_t *) &comet->ibcd_deact, 0x24); + } /* 10: CDRC cfg 28&38: rx&tx data link 1 ctrl 48: t1 frmr cfg */ /* 50: SIGX cfg, COSS (change of signaling state) 54: XBAS cfg */ /* 60: t1 ALMI cfg */ /* Configure Line Coding */ - switch (port_mode) - { - case CFG_FRAME_SF: /* 1 - T1 B8ZS */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->t1_frmr_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->t1_xbas_cfg, 0x20); /* 5:B8ZS */ - pci_write_32 ((u_int32_t *) &comet->t1_almi_cfg, 0); - break; - case CFG_FRAME_ESF: /* 2 - T1 B8ZS */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->rxce1_ctl, 0x20); /* Bit 5: T1 DataLink - * Enable */ - pci_write_32 ((u_int32_t *) &comet->txci1_ctl, 0x20); /* 5: T1 DataLink Enable */ - pci_write_32 ((u_int32_t *) &comet->t1_frmr_cfg, 0x30); /* 4:ESF 5:ESFFA */ - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0x04); /* 2:ESF */ - pci_write_32 ((u_int32_t *) &comet->t1_xbas_cfg, 0x30); /* 4:ESF 5:B8ZS */ - pci_write_32 ((u_int32_t *) &comet->t1_almi_cfg, 0x10); /* 4:ESF */ - break; - case CFG_FRAME_E1PLAIN: /* 3 - HDB3 */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->e1_tran_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->e1_frmr_aopts, 0x40); - break; - case CFG_FRAME_E1CAS: /* 4 - HDB3 */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->e1_tran_cfg, 0x60); - pci_write_32 ((u_int32_t *) &comet->e1_frmr_aopts, 0); - break; - case CFG_FRAME_E1CRC: /* 5 - HDB3 */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->e1_tran_cfg, 0x10); - pci_write_32 ((u_int32_t *) &comet->e1_frmr_aopts, 0xc2); - break; - case CFG_FRAME_E1CRC_CAS: /* 6 - HDB3 */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->e1_tran_cfg, 0x70); - pci_write_32 ((u_int32_t *) &comet->e1_frmr_aopts, 0x82); - break; - case CFG_FRAME_SF_AMI: /* 7 - T1 AMI */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0x80); /* Enable AMI Line - * Decoding */ - pci_write_32 ((u_int32_t *) &comet->t1_frmr_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->t1_xbas_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->t1_almi_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0); - break; - case CFG_FRAME_ESF_AMI: /* 8 - T1 AMI */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0x80); /* Enable AMI Line - * Decoding */ - pci_write_32 ((u_int32_t *) &comet->rxce1_ctl, 0x20); /* 5: T1 DataLink Enable */ - pci_write_32 ((u_int32_t *) &comet->txci1_ctl, 0x20); /* 5: T1 DataLink Enable */ - pci_write_32 ((u_int32_t *) &comet->t1_frmr_cfg, 0x30); /* Bit 4:ESF 5:ESFFA */ - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0x04); /* 2:ESF */ - pci_write_32 ((u_int32_t *) &comet->t1_xbas_cfg, 0x10); /* 4:ESF */ - pci_write_32 ((u_int32_t *) &comet->t1_almi_cfg, 0x10); /* 4:ESF */ - break; - case CFG_FRAME_E1PLAIN_AMI: /* 9 - AMI */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0x80); /* Enable AMI Line - * Decoding */ - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->e1_tran_cfg, 0x80); - pci_write_32 ((u_int32_t *) &comet->e1_frmr_aopts, 0x40); - break; - case CFG_FRAME_E1CAS_AMI: /* 10 - AMI */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0x80); /* Enable AMI Line - * Decoding */ - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->e1_tran_cfg, 0xe0); - pci_write_32 ((u_int32_t *) &comet->e1_frmr_aopts, 0); - break; - case CFG_FRAME_E1CRC_AMI: /* 11 - AMI */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0x80); /* Enable AMI Line - * Decoding */ - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->e1_tran_cfg, 0x90); - pci_write_32 ((u_int32_t *) &comet->e1_frmr_aopts, 0xc2); - break; - case CFG_FRAME_E1CRC_CAS_AMI: /* 12 - AMI */ - pci_write_32 ((u_int32_t *) &comet->cdrc_cfg, 0x80); /* Enable AMI Line - * Decoding */ - pci_write_32 ((u_int32_t *) &comet->sigx_cfg, 0); - pci_write_32 ((u_int32_t *) &comet->e1_tran_cfg, 0xf0); - pci_write_32 ((u_int32_t *) &comet->e1_frmr_aopts, 0x82); - break; - } /* end switch */ + switch (port_mode) + { + /* 1 - T1 B8ZS */ + case CFG_FRAME_SF: + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0); + pci_write_32((u_int32_t *) &comet->t1_frmr_cfg, 0); + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0); + /* 5:B8ZS */ + pci_write_32((u_int32_t *) &comet->t1_xbas_cfg, 0x20); + pci_write_32((u_int32_t *) &comet->t1_almi_cfg, 0); + break; + /* 2 - T1 B8ZS */ + case CFG_FRAME_ESF: + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0); + /* Bit 5: T1 DataLink Enable */ + pci_write_32((u_int32_t *) &comet->rxce1_ctl, 0x20); + /* 5: T1 DataLink Enable */ + pci_write_32((u_int32_t *) &comet->txci1_ctl, 0x20); + /* 4:ESF 5:ESFFA */ + pci_write_32((u_int32_t *) &comet->t1_frmr_cfg, 0x30); + /* 2:ESF */ + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0x04); + /* 4:ESF 5:B8ZS */ + pci_write_32((u_int32_t *) &comet->t1_xbas_cfg, 0x30); + /* 4:ESF */ + pci_write_32((u_int32_t *) &comet->t1_almi_cfg, 0x10); + break; + /* 3 - HDB3 */ + case CFG_FRAME_E1PLAIN: + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0); + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0); + pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0); + pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0x40); + break; + /* 4 - HDB3 */ + case CFG_FRAME_E1CAS: + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0); + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0); + pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0x60); + pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0); + break; + /* 5 - HDB3 */ + case CFG_FRAME_E1CRC: + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0); + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0); + pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0x10); + pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0xc2); + break; + /* 6 - HDB3 */ + case CFG_FRAME_E1CRC_CAS: + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0); + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0); + pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0x70); + pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0x82); + break; + /* 7 - T1 AMI */ + case CFG_FRAME_SF_AMI: + /* Enable AMI Line Decoding */ + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80); + pci_write_32((u_int32_t *) &comet->t1_frmr_cfg, 0); + pci_write_32((u_int32_t *) &comet->t1_xbas_cfg, 0); + pci_write_32((u_int32_t *) &comet->t1_almi_cfg, 0); + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0); + break; + /* 8 - T1 AMI */ + case CFG_FRAME_ESF_AMI: + /* Enable AMI Line Decoding */ + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80); + /* 5: T1 DataLink Enable */ + pci_write_32((u_int32_t *) &comet->rxce1_ctl, 0x20); + /* 5: T1 DataLink Enable */ + pci_write_32((u_int32_t *) &comet->txci1_ctl, 0x20); + /* Bit 4:ESF 5:ESFFA */ + pci_write_32((u_int32_t *) &comet->t1_frmr_cfg, 0x30); + /* 2:ESF */ + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0x04); + /* 4:ESF */ + pci_write_32((u_int32_t *) &comet->t1_xbas_cfg, 0x10); + /* 4:ESF */ + pci_write_32((u_int32_t *) &comet->t1_almi_cfg, 0x10); + break; + /* 9 - AMI */ + case CFG_FRAME_E1PLAIN_AMI: + /* Enable AMI Line Decoding */ + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80); + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0); + pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0x80); + pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0x40); + break; + /* 10 - AMI */ + case CFG_FRAME_E1CAS_AMI: + /* Enable AMI Line Decoding */ + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80); + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0); + pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0xe0); + pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0); + break; + /* 11 - AMI */ + case CFG_FRAME_E1CRC_AMI: + /* Enable AMI Line Decoding */ + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80); + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0); + pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0x90); + pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0xc2); + break; + /* 12 - AMI */ + case CFG_FRAME_E1CRC_CAS_AMI: + /* Enable AMI Line Decoding */ + pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80); + pci_write_32((u_int32_t *) &comet->sigx_cfg, 0); + pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0xf0); + pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0x82); + break; + } /* end switch */ /*** * Set Full Frame mode (NXDSO[1] = 0, NXDSO[0] = 0) @@ -277,101 +295,109 @@ init_comet (void *ci, comet_t * comet, u_int32_t port_mode, int clockmaster, /* 0x30: "BRIF cfg"; 0x20 is 'CMODE', 0x03 is (bit) rate */ /* note "rate bits can only be set once after reset" */ - if (clockmaster) - { /* CMODE == clockMode, 0=clock master (so - * all 3 others should be slave) */ - if (isT1mode) /* rate = 1.544 Mb/s */ - pci_write_32 ((u_int32_t *) &comet->brif_cfg, 0x00); /* Comet 0 Master - * Mode(CMODE=0) */ - else /* rate = 2.048 Mb/s */ - pci_write_32 ((u_int32_t *) &comet->brif_cfg, 0x01); /* Comet 0 Master - * Mode(CMODE=0) */ + if (clockmaster) + { + /* CMODE == clockMode, 0=clock master (so all 3 others should be slave) */ + /* rate = 1.544 Mb/s */ + if (isT1mode) + /* Comet 0 Master Mode(CMODE=0) */ + pci_write_32((u_int32_t *) &comet->brif_cfg, 0x00); + /* rate = 2.048 Mb/s */ + else + /* Comet 0 Master Mode(CMODE=0) */ + pci_write_32((u_int32_t *) &comet->brif_cfg, 0x01); - /* 31: BRIF frame pulse cfg 06: tx timing options */ - pci_write_32 ((u_int32_t *) &comet->brif_fpcfg, 0x00); /* Master Mode - * i.e.FPMODE=0 (@0x20) */ - if ((moreParams & CFG_CLK_PORT_MASK) == CFG_CLK_PORT_INTERNAL) - { - if (cxt1e1_log_level >= LOG_SBEBUG12) - pr_info(">> %s: clockmaster internal clock\n", __func__); - pci_write_32 ((u_int32_t *) &comet->tx_time, 0x0d); /* internal oscillator */ - } else /* external clock source */ - { - if (cxt1e1_log_level >= LOG_SBEBUG12) - pr_info(">> %s: clockmaster external clock\n", __func__); - pci_write_32 ((u_int32_t *) &comet->tx_time, 0x09); /* loop timing - * (external) */ - } + /* 31: BRIF frame pulse cfg 06: tx timing options */ - } else /* slave */ - { - if (isT1mode) - pci_write_32 ((u_int32_t *) &comet->brif_cfg, 0x20); /* Slave Mode(CMODE=1, - * see above) */ - else - pci_write_32 ((u_int32_t *) &comet->brif_cfg, 0x21); /* Slave Mode (CMODE=1) */ - pci_write_32 ((u_int32_t *) &comet->brif_fpcfg, 0x20); /* Slave Mode i.e. - * FPMODE=1 (@0x20) */ - if (cxt1e1_log_level >= LOG_SBEBUG12) - pr_info(">> %s: clockslave internal clock\n", __func__); - pci_write_32 ((u_int32_t *) &comet->tx_time, 0x0d); /* oscillator timing */ - } + /* Master Mode i.e.FPMODE=0 (@0x20) */ + pci_write_32((u_int32_t *) &comet->brif_fpcfg, 0x00); + if ((moreParams & CFG_CLK_PORT_MASK) == CFG_CLK_PORT_INTERNAL) + { + if (cxt1e1_log_level >= LOG_SBEBUG12) + pr_info(">> %s: clockmaster internal clock\n", __func__); + /* internal oscillator */ + pci_write_32((u_int32_t *) &comet->tx_time, 0x0d); + } else { + /* external clock source */ + if (cxt1e1_log_level >= LOG_SBEBUG12) + pr_info(">> %s: clockmaster external clock\n", __func__); + /* loop timing(external) */ + pci_write_32((u_int32_t *) &comet->tx_time, 0x09); + } - /* 32: BRIF parity F-bit cfg */ - /* Totem-pole operation */ - pci_write_32 ((u_int32_t *) &comet->brif_pfcfg, 0x01); /* Receive Backplane - * Parity/F-bit */ + } else { + /* slave */ + if (isT1mode) + /* Slave Mode(CMODE=1, see above) */ + pci_write_32((u_int32_t *) &comet->brif_cfg, 0x20); + else + /* Slave Mode(CMODE=1)*/ + pci_write_32((u_int32_t *) &comet->brif_cfg, 0x21); + /* Slave Mode i.e. FPMODE=1 (@0x20) */ + pci_write_32((u_int32_t *) &comet->brif_fpcfg, 0x20); + if (cxt1e1_log_level >= LOG_SBEBUG12) + pr_info(">> %s: clockslave internal clock\n", __func__); + /* oscillator timing */ + pci_write_32((u_int32_t *) &comet->tx_time, 0x0d); + } + + /* 32: BRIF parity F-bit cfg */ + /* Totem-pole operation */ + /* Receive Backplane Parity/F-bit */ + pci_write_32((u_int32_t *) &comet->brif_pfcfg, 0x01); /* dc: RLPS equalizer V ref */ /* Configuration */ - if (isT1mode) - pci_write_32 ((u_int32_t *) &comet->rlps_eqvr, 0x2c); /* RLPS Equalizer - * Voltage */ - else - pci_write_32 ((u_int32_t *) &comet->rlps_eqvr, 0x34); /* RLPS Equalizer - * Voltage */ + if (isT1mode) + /* RLPS Equalizer Voltage */ + pci_write_32((u_int32_t *) &comet->rlps_eqvr, 0x2c); + else + /* RLPS Equalizer Voltage */ + pci_write_32((u_int32_t *) &comet->rlps_eqvr, 0x34); /* Reserved bit set and SQUELCH enabled */ /* f8: RLPS cfg & status f9: RLPS ALOS detect/clear threshold */ - pci_write_32 ((u_int32_t *) &comet->rlps_cfgsts, 0x11); /* RLPS Configuration - * Status */ - if (isT1mode) - pci_write_32 ((u_int32_t *) &comet->rlps_alos_thresh, 0x55); /* ? */ - else - pci_write_32 ((u_int32_t *) &comet->rlps_alos_thresh, 0x22); /* ? */ + /* RLPS Configuration Status */ + pci_write_32((u_int32_t *) &comet->rlps_cfgsts, 0x11); + if (isT1mode) + /* ? */ + pci_write_32((u_int32_t *) &comet->rlps_alos_thresh, 0x55); + else + /* ? */ + pci_write_32((u_int32_t *) &comet->rlps_alos_thresh, 0x22); /* Set Full Frame mode (NXDSO[1] = 0, NXDSO[0] = 0) */ /* CMODE=0: Clock slave mode with BTCLK as an input, DE=1: Use rising */ /* edge of BTCLK for data, FE=1: Use rising edge of BTCLK for frame, */ /* CMS=0: Use backplane freq, RATE[1:0]=0,0: T1 */ -/*** Transmit side is always an Input, Slave Clock*/ - /* 40: BTIF cfg 41: BTIF frame pulse cfg */ - if (isT1mode) - pci_write_32 ((u_int32_t *) &comet->btif_cfg, 0x38); /* BTIF Configuration - * Reg. */ - else - pci_write_32 ((u_int32_t *) &comet->btif_cfg, 0x39); /* BTIF Configuration - * Reg. */ - - pci_write_32 ((u_int32_t *) &comet->btif_fpcfg, 0x01); /* BTIF Frame Pulse - * Config. */ + /*** Transmit side is always an Input, Slave Clock*/ + /* 40: BTIF cfg 41: loop timing(external) */ + /*BTIF frame pulse cfg */ + if (isT1mode) + /* BTIF Configuration Reg. */ + pci_write_32((u_int32_t *) &comet->btif_cfg, 0x38); + else + /* BTIF Configuration Reg. */ + pci_write_32((u_int32_t *) &comet->btif_cfg, 0x39); + /* BTIF Frame Pulse Config. */ + pci_write_32((u_int32_t *) &comet->btif_fpcfg, 0x01); /* 0a: master diag 06: tx timing options */ /* if set Comet to loop back */ /* Comets set to normal */ - pci_write_32 ((u_int32_t *) &comet->mdiag, 0x00); + pci_write_32((u_int32_t *) &comet->mdiag, 0x00); /* BTCLK driven by TCLKI internally (crystal driven) and Xmt Elasted */ /* Store is enabled. */ - WrtXmtWaveformTbl (ci, comet, TWV_table[tix]); - if (isT1mode) - WrtRcvEqualizerTbl ((ci_t *) ci, comet, &T1_Equalizer[0]); - else - WrtRcvEqualizerTbl ((ci_t *) ci, comet, &E1_Equalizer[0]); - SetPwrLevel (comet); + WrtXmtWaveformTbl(ci, comet, TWV_table[tix]); + if (isT1mode) + WrtRcvEqualizerTbl((ci_t *) ci, comet, &T1_Equalizer[0]); + else + WrtRcvEqualizerTbl((ci_t *) ci, comet, &E1_Equalizer[0]); + SetPwrLevel(comet); } /* @@ -382,15 +408,15 @@ init_comet (void *ci, comet_t * comet, u_int32_t port_mode, int clockmaster, ** Returns: Nothing */ STATIC void -WrtXmtWaveform (ci_t * ci, comet_t * comet, u_int32_t sample, u_int32_t unit, u_int8_t data) +WrtXmtWaveform(ci_t *ci, comet_t *comet, u_int32_t sample, u_int32_t unit, u_int8_t data) { - u_int8_t WaveformAddr; + u_int8_t WaveformAddr; - WaveformAddr = (sample << 3) + (unit & 7); - pci_write_32 ((u_int32_t *) &comet->xlpg_pwave_addr, WaveformAddr); - pci_flush_write (ci); /* for write order preservation when - * Optimizing driver */ - pci_write_32 ((u_int32_t *) &comet->xlpg_pwave_data, 0x7F & data); + WaveformAddr = (sample << 3) + (unit & 7); + pci_write_32((u_int32_t *) &comet->xlpg_pwave_addr, WaveformAddr); + /* for write order preservation when Optimizing driver */ + pci_flush_write(ci); + pci_write_32((u_int32_t *) &comet->xlpg_pwave_data, 0x7F & data); } /* @@ -400,19 +426,19 @@ WrtXmtWaveform (ci_t * ci, comet_t * comet, u_int32_t sample, u_int32_t unit, u_ ** Returns: Nothing */ STATIC void -WrtXmtWaveformTbl (ci_t * ci, comet_t * comet, - u_int8_t table[COMET_NUM_SAMPLES][COMET_NUM_UNITS]) +WrtXmtWaveformTbl(ci_t *ci, comet_t *comet, + u_int8_t table[COMET_NUM_SAMPLES][COMET_NUM_UNITS]) { - u_int32_t sample, unit; + u_int32_t sample, unit; - for (sample = 0; sample < COMET_NUM_SAMPLES; sample++) - { - for (unit = 0; unit < COMET_NUM_UNITS; unit++) - WrtXmtWaveform (ci, comet, sample, unit, table[sample][unit]); - } + for (sample = 0; sample < COMET_NUM_SAMPLES; sample++) + { + for (unit = 0; unit < COMET_NUM_UNITS; unit++) + WrtXmtWaveform(ci, comet, sample, unit, table[sample][unit]); + } /* Enable transmitter and set output amplitude */ - pci_write_32 ((u_int32_t *) &comet->xlpg_cfg, table[COMET_NUM_SAMPLES][0]); + pci_write_32((u_int32_t *) &comet->xlpg_cfg, table[COMET_NUM_SAMPLES][0]); } @@ -427,60 +453,60 @@ WrtXmtWaveformTbl (ci_t * ci, comet_t * comet, */ STATIC void -WrtRcvEqualizerTbl (ci_t * ci, comet_t * comet, u_int32_t *table) +WrtRcvEqualizerTbl(ci_t *ci, comet_t *comet, u_int32_t *table) { - u_int32_t ramaddr; - volatile u_int32_t value; + u_int32_t ramaddr; + volatile u_int32_t value; - for (ramaddr = 0; ramaddr < 256; ramaddr++) - { - /*** the following lines are per Errata 7, 2.5 ***/ - { - pci_write_32 ((u_int32_t *) &comet->rlps_eq_rwsel, 0x80); /* Set up for a read - * operation */ - pci_flush_write (ci); /* for write order preservation when - * Optimizing driver */ - pci_write_32 ((u_int32_t *) &comet->rlps_eq_iaddr, (u_int8_t) ramaddr); /* write the addr, - * initiate a read */ - pci_flush_write (ci); /* for write order preservation when - * Optimizing driver */ - /* - * wait 3 line rate clock cycles to ensure address bits are - * captured by T1/E1 clock - */ - OS_uwait (4, "wret"); /* 683ns * 3 = 1366 ns, approx 2us (but - * use 4us) */ - } + for (ramaddr = 0; ramaddr < 256; ramaddr++) { + /*** the following lines are per Errata 7, 2.5 ***/ + { + /* Set up for a read operation */ + pci_write_32((u_int32_t *) &comet->rlps_eq_rwsel, 0x80); + /* for write order preservation when Optimizing driver */ + pci_flush_write(ci); + /* write the addr, initiate a read */ + pci_write_32((u_int32_t *) &comet->rlps_eq_iaddr, (u_int8_t) ramaddr); + /* for write order preservation when Optimizing driver */ + pci_flush_write(ci); + /* + * wait 3 line rate clock cycles to ensure address bits are + * captured by T1/E1 clock + */ - value = *table++; - pci_write_32 ((u_int32_t *) &comet->rlps_idata3, (u_int8_t) (value >> 24)); - pci_write_32 ((u_int32_t *) &comet->rlps_idata2, (u_int8_t) (value >> 16)); - pci_write_32 ((u_int32_t *) &comet->rlps_idata1, (u_int8_t) (value >> 8)); - pci_write_32 ((u_int32_t *) &comet->rlps_idata0, (u_int8_t) value); - pci_flush_write (ci); /* for write order preservation when - * Optimizing driver */ + /* 683ns * 3 = 1366 ns, approx 2us (but use 4us) */ + OS_uwait(4, "wret"); + } - /* Storing RAM address, causes RAM to be updated */ + value = *table++; + pci_write_32((u_int32_t *) &comet->rlps_idata3, (u_int8_t) (value >> 24)); + pci_write_32((u_int32_t *) &comet->rlps_idata2, (u_int8_t) (value >> 16)); + pci_write_32((u_int32_t *) &comet->rlps_idata1, (u_int8_t) (value >> 8)); + pci_write_32((u_int32_t *) &comet->rlps_idata0, (u_int8_t) value); + /* for write order preservation when Optimizing driver */ + pci_flush_write(ci); - pci_write_32 ((u_int32_t *) &comet->rlps_eq_rwsel, 0); /* Set up for a write - * operation */ - pci_flush_write (ci); /* for write order preservation when - * Optimizing driver */ - pci_write_32 ((u_int32_t *) &comet->rlps_eq_iaddr, (u_int8_t) ramaddr); /* write the addr, - * initiate a read */ - pci_flush_write (ci); /* for write order preservation when - * Optimizing driver */ - /* - * wait 3 line rate clock cycles to ensure address bits are captured - * by T1/E1 clock - */ - OS_uwait (4, "wret"); /* 683ns * 3 = 1366 ns, approx 2us (but - * use 4us) */ - } + /* Storing RAM address, causes RAM to be updated */ - pci_write_32 ((u_int32_t *) &comet->rlps_eq_cfg, 0xCB); /* Enable Equalizer & - * set it to use 256 - * periods */ + /* Set up for a write operation */ + pci_write_32((u_int32_t *) &comet->rlps_eq_rwsel, 0); + /* for write order preservation when optimizing driver */ + pci_flush_write(ci); + /* write the addr, initiate a read */ + pci_write_32((u_int32_t *) &comet->rlps_eq_iaddr, (u_int8_t) ramaddr); + /* for write order preservation when optimizing driver */ + pci_flush_write(ci); + + /* + * wait 3 line rate clock cycles to ensure address bits are captured + * by T1/E1 clock + */ + /* 683ns * 3 = 1366 ns, approx 2us (but use 4us) */ + OS_uwait(4, "wret"); + } + + /* Enable Equalizer & set it to use 256 periods */ + pci_write_32((u_int32_t *) &comet->rlps_eq_cfg, 0xCB); } @@ -491,9 +517,9 @@ WrtRcvEqualizerTbl (ci_t * ci, comet_t * comet, u_int32_t *table) */ STATIC void -SetPwrLevel (comet_t * comet) +SetPwrLevel(comet_t *comet) { - volatile u_int32_t temp; + volatile u_int32_t temp; /* ** Algorithm to Balance the Power Distribution of Ttip Tring @@ -507,22 +533,20 @@ SetPwrLevel (comet_t * comet) ** Repeat these steps for register F5 ** Write 0x01 to register F6 */ - pci_write_32 ((u_int32_t *) &comet->xlpg_fdata_sel, 0x00); /* XLPG Fuse Data Select */ - - pci_write_32 ((u_int32_t *) &comet->xlpg_atest_pctl, 0x01); /* XLPG Analog Test - * Positive control */ - pci_write_32 ((u_int32_t *) &comet->xlpg_atest_pctl, 0x01); - - temp = pci_read_32 ((u_int32_t *) &comet->xlpg_atest_pctl) & 0xfe; - pci_write_32 ((u_int32_t *) &comet->xlpg_atest_pctl, temp); - - pci_write_32 ((u_int32_t *) &comet->xlpg_atest_nctl, 0x01); /* XLPG Analog Test - * Negative control */ - pci_write_32 ((u_int32_t *) &comet->xlpg_atest_nctl, 0x01); - - temp = pci_read_32 ((u_int32_t *) &comet->xlpg_atest_nctl) & 0xfe; - pci_write_32 ((u_int32_t *) &comet->xlpg_atest_nctl, temp); - pci_write_32 ((u_int32_t *) &comet->xlpg_fdata_sel, 0x01); /* XLPG */ + /* XLPG Fuse Data Select */ + pci_write_32((u_int32_t *) &comet->xlpg_fdata_sel, 0x00); + /* XLPG Analog Test Positive control */ + pci_write_32((u_int32_t *) &comet->xlpg_atest_pctl, 0x01); + pci_write_32((u_int32_t *) &comet->xlpg_atest_pctl, 0x01); + temp = pci_read_32((u_int32_t *) &comet->xlpg_atest_pctl) & 0xfe; + pci_write_32((u_int32_t *) &comet->xlpg_atest_pctl, temp); + pci_write_32((u_int32_t *) &comet->xlpg_atest_nctl, 0x01); + pci_write_32((u_int32_t *) &comet->xlpg_atest_nctl, 0x01); + /* XLPG Analog Test Negative control */ + temp = pci_read_32((u_int32_t *) &comet->xlpg_atest_nctl) & 0xfe; + pci_write_32((u_int32_t *) &comet->xlpg_atest_nctl, temp); + /* XLPG */ + pci_write_32((u_int32_t *) &comet->xlpg_fdata_sel, 0x01); } @@ -535,33 +559,30 @@ SetPwrLevel (comet_t * comet) */ #if 0 STATIC void -SetCometOps (comet_t * comet) +SetCometOps(comet_t *comet) { - volatile u_int8_t rd_value; + volatile u_int8_t rd_value; - if (comet == mConfig.C4Func1Base + (COMET0_OFFSET >> 2)) - { - rd_value = (u_int8_t) pci_read_32 ((u_int32_t *) &comet->brif_cfg); /* read the BRIF - * Configuration */ - rd_value &= ~0x20; - pci_write_32 ((u_int32_t *) &comet->brif_cfg, (u_int32_t) rd_value); - - rd_value = (u_int8_t) pci_read_32 ((u_int32_t *) &comet->brif_fpcfg); /* read the BRIF Frame - * Pulse Configuration */ - rd_value &= ~0x20; - pci_write_32 ((u_int32_t *) &comet->brif_fpcfg, (u_int8_t) rd_value); - } else - { - rd_value = (u_int8_t) pci_read_32 ((u_int32_t *) &comet->brif_cfg); /* read the BRIF - * Configuration */ - rd_value |= 0x20; - pci_write_32 ((u_int32_t *) &comet->brif_cfg, (u_int32_t) rd_value); - - rd_value = (u_int8_t) pci_read_32 ((u_int32_t *) &comet->brif_fpcfg); /* read the BRIF Frame - * Pulse Configuration */ - rd_value |= 0x20; - pci_write_32 ((u_int32_t *) &comet->brif_fpcfg, (u_int8_t) rd_value); - } + if (comet == mConfig.C4Func1Base + (COMET0_OFFSET >> 2)) + { + /* read the BRIF Configuration */ + rd_value = (u_int8_t) pci_read_32((u_int32_t *) &comet->brif_cfg); + rd_value &= ~0x20; + pci_write_32((u_int32_t *) &comet->brif_cfg, (u_int32_t) rd_value); + /* read the BRIF Frame Pulse Configuration */ + rd_value = (u_int8_t) pci_read_32((u_int32_t *) &comet->brif_fpcfg); + rd_value &= ~0x20; + pci_write_32((u_int32_t *) &comet->brif_fpcfg, (u_int8_t) rd_value); + } else { + /* read the BRIF Configuration */ + rd_value = (u_int8_t) pci_read_32((u_int32_t *) &comet->brif_cfg); + rd_value |= 0x20; + pci_write_32((u_int32_t *) &comet->brif_cfg, (u_int32_t) rd_value); + /* read the BRIF Frame Pulse Configuration */ + rd_value = (u_int8_t) pci_read_32((u_int32_t *) &comet->brif_fpcfg); + rd_value |= 0x20; + pci_write_32(u_int32_t *) & comet->brif_fpcfg, (u_int8_t) rd_value); + } } #endif diff --git a/drivers/staging/cxt1e1/functions.c b/drivers/staging/cxt1e1/functions.c index d9a9aa3571d9..6167dc574577 100644 --- a/drivers/staging/cxt1e1/functions.c +++ b/drivers/staging/cxt1e1/functions.c @@ -14,7 +14,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include -#include +#include #include #include #include @@ -97,7 +97,7 @@ pci_write_32 (u_int32_t *p, u_int32_t v) void -pci_flush_write (ci_t * ci) +pci_flush_write (ci_t *ci) { volatile u_int32_t v; @@ -202,7 +202,7 @@ sd_line_is_ok (void *user) { struct net_device *ndev = (struct net_device *) user; - return (netif_carrier_ok (ndev)); + return netif_carrier_ok (ndev); } void @@ -246,7 +246,7 @@ sd_queue_stopped (void *user) { struct net_device *ndev = (struct net_device *) user; - return (netif_queue_stopped (ndev)); + return netif_queue_stopped (ndev); } void sd_recv_consume(void *token, size_t len, void *user) @@ -279,7 +279,7 @@ VMETRO_TRACE (void *x) void -VMETRO_TRIGGER (ci_t * ci, int x) +VMETRO_TRIGGER (ci_t *ci, int x) { comet_t *comet; volatile u_int32_t data; diff --git a/drivers/staging/cxt1e1/hwprobe.c b/drivers/staging/cxt1e1/hwprobe.c index de8ac0bc24fb..110c252d38d7 100644 --- a/drivers/staging/cxt1e1/hwprobe.c +++ b/drivers/staging/cxt1e1/hwprobe.c @@ -50,7 +50,7 @@ struct s_hdw_info hdw_info[MAX_BOARDS]; void __init -show_two (hdw_info_t * hi, int brdno) +show_two (hdw_info_t *hi, int brdno) { ci_t *ci; struct pci_dev *pdev; @@ -102,7 +102,7 @@ show_two (hdw_info_t * hi, int brdno) void __init -hdw_sn_get (hdw_info_t * hi, int brdno) +hdw_sn_get (hdw_info_t *hi, int brdno) { /* obtain hardware EEPROM information */ long addr; @@ -222,7 +222,7 @@ cleanup_devs (void) STATIC int __init -c4_hdw_init (struct pci_dev * pdev, int found) +c4_hdw_init (struct pci_dev *pdev, int found) { hdw_info_t *hi; int i; diff --git a/drivers/staging/cxt1e1/linux.c b/drivers/staging/cxt1e1/linux.c index a829b6231a66..e5889ef190a2 100644 --- a/drivers/staging/cxt1e1/linux.c +++ b/drivers/staging/cxt1e1/linux.c @@ -144,7 +144,7 @@ getuserbychan (int channum) char * -get_hdlc_name (hdlc_device * hdlc) +get_hdlc_name (hdlc_device *hdlc) { struct c4_priv *priv = hdlc->priv; struct net_device *dev = getuserbychan (priv->channum); @@ -185,7 +185,7 @@ mkret (int bsd) * within a port's group. */ void -c4_wk_chan_restart (mch_t * ch) +c4_wk_chan_restart (mch_t *ch) { mpi_t *pi = ch->up; @@ -203,7 +203,7 @@ c4_wk_chan_restart (mch_t * ch) } status_t -c4_wk_chan_init (mpi_t * pi, mch_t * ch) +c4_wk_chan_init (mpi_t *pi, mch_t *ch) { /* * this will be used to restart a stopped channel @@ -218,7 +218,7 @@ c4_wk_chan_init (mpi_t * pi, mch_t * ch) } status_t -c4_wq_port_init (mpi_t * pi) +c4_wq_port_init (mpi_t *pi) { char name[16], *np; /* NOTE: name of the queue limited by system @@ -241,7 +241,7 @@ c4_wq_port_init (mpi_t * pi) } void -c4_wq_port_cleanup (mpi_t * pi) +c4_wq_port_cleanup (mpi_t *pi) { /* * PORT POINT: cannot call this if WQ is statically allocated w/in @@ -278,7 +278,7 @@ c4_ebus_interrupt (int irq, void *dev_instance) static int -void_open (struct net_device * ndev) +void_open (struct net_device *ndev) { pr_info("%s: trying to open master device !\n", ndev->name); return -1; @@ -286,7 +286,7 @@ void_open (struct net_device * ndev) STATIC int -chan_open (struct net_device * ndev) +chan_open (struct net_device *ndev) { hdlc_device *hdlc = dev_to_hdlc (ndev); const struct c4_priv *priv = hdlc->priv; @@ -306,7 +306,7 @@ chan_open (struct net_device * ndev) STATIC int -chan_close (struct net_device * ndev) +chan_close (struct net_device *ndev) { hdlc_device *hdlc = dev_to_hdlc (ndev); const struct c4_priv *priv = hdlc->priv; @@ -320,14 +320,14 @@ chan_close (struct net_device * ndev) STATIC int -chan_dev_ioctl (struct net_device * dev, struct ifreq * ifr, int cmd) +chan_dev_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd) { return hdlc_ioctl (dev, ifr, cmd); } STATIC int -chan_attach_noop (struct net_device * ndev, unsigned short foo_1, unsigned short foo_2) +chan_attach_noop (struct net_device *ndev, unsigned short foo_1, unsigned short foo_2) { return 0; /* our driver has nothing to do here, show's * over, go home */ @@ -335,7 +335,7 @@ chan_attach_noop (struct net_device * ndev, unsigned short foo_1, unsigned short STATIC struct net_device_stats * -chan_get_stats (struct net_device * ndev) +chan_get_stats (struct net_device *ndev) { mch_t *ch; struct net_device_stats *nstats; @@ -388,14 +388,14 @@ chan_get_stats (struct net_device * ndev) static ci_t * -get_ci_by_dev (struct net_device * ndev) +get_ci_by_dev (struct net_device *ndev) { return (ci_t *)(netdev_priv(ndev)); } STATIC int -c4_linux_xmit (struct sk_buff * skb, struct net_device * ndev) +c4_linux_xmit (struct sk_buff *skb, struct net_device *ndev) { const struct c4_priv *priv; int rval; @@ -417,8 +417,8 @@ static const struct net_device_ops chan_ops = { }; STATIC struct net_device * -create_chan (struct net_device * ndev, ci_t * ci, - struct sbecom_chan_param * cp) +create_chan (struct net_device *ndev, ci_t *ci, + struct sbecom_chan_param *cp) { hdlc_device *hdlc; struct net_device *dev; @@ -510,7 +510,7 @@ create_chan (struct net_device * ndev, ci_t * ci, /* the idea here is to get port information and pass it back (using pointer) */ STATIC status_t -do_get_port (struct net_device * ndev, void *data) +do_get_port (struct net_device *ndev, void *data) { int ret; ci_t *ci; /* ci stands for card information */ @@ -535,7 +535,7 @@ do_get_port (struct net_device * ndev, void *data) /* this function copys the user data and then calls the real action function */ STATIC status_t -do_set_port (struct net_device * ndev, void *data) +do_set_port (struct net_device *ndev, void *data) { ci_t *ci; /* ci stands for card information */ struct sbecom_port_param pp;/* copy data to kernel land */ @@ -557,7 +557,7 @@ do_set_port (struct net_device * ndev, void *data) /* work the port loopback mode as per directed */ STATIC status_t -do_port_loop (struct net_device * ndev, void *data) +do_port_loop (struct net_device *ndev, void *data) { struct sbecom_port_param pp; ci_t *ci; @@ -572,7 +572,7 @@ do_port_loop (struct net_device * ndev, void *data) /* set the specified register with the given value / or just read it */ STATIC status_t -do_framer_rw (struct net_device * ndev, void *data) +do_framer_rw (struct net_device *ndev, void *data) { struct sbecom_port_param pp; ci_t *ci; @@ -593,7 +593,7 @@ do_framer_rw (struct net_device * ndev, void *data) /* set the specified register with the given value / or just read it */ STATIC status_t -do_pld_rw (struct net_device * ndev, void *data) +do_pld_rw (struct net_device *ndev, void *data) { struct sbecom_port_param pp; ci_t *ci; @@ -614,7 +614,7 @@ do_pld_rw (struct net_device * ndev, void *data) /* set the specified register with the given value / or just read it */ STATIC status_t -do_musycc_rw (struct net_device * ndev, void *data) +do_musycc_rw (struct net_device *ndev, void *data) { struct c4_musycc_param mp; ci_t *ci; @@ -634,7 +634,7 @@ do_musycc_rw (struct net_device * ndev, void *data) } STATIC status_t -do_get_chan (struct net_device * ndev, void *data) +do_get_chan (struct net_device *ndev, void *data) { struct sbecom_chan_param cp; int ret; @@ -652,7 +652,7 @@ do_get_chan (struct net_device * ndev, void *data) } STATIC status_t -do_set_chan (struct net_device * ndev, void *data) +do_set_chan (struct net_device *ndev, void *data) { struct sbecom_chan_param cp; int ret; @@ -673,7 +673,7 @@ do_set_chan (struct net_device * ndev, void *data) } STATIC status_t -do_create_chan (struct net_device * ndev, void *data) +do_create_chan (struct net_device *ndev, void *data) { ci_t *ci; struct net_device *dev; @@ -700,7 +700,7 @@ do_create_chan (struct net_device * ndev, void *data) } STATIC status_t -do_get_chan_stats (struct net_device * ndev, void *data) +do_get_chan_stats (struct net_device *ndev, void *data) { struct c4_chan_stats_wrap ccs; int ret; @@ -721,7 +721,7 @@ do_get_chan_stats (struct net_device * ndev, void *data) return 0; } STATIC status_t -do_set_loglevel (struct net_device * ndev, void *data) +do_set_loglevel (struct net_device *ndev, void *data) { unsigned int cxt1e1_log_level; @@ -732,7 +732,7 @@ do_set_loglevel (struct net_device * ndev, void *data) } STATIC status_t -do_deluser (struct net_device * ndev, int lockit) +do_deluser (struct net_device *ndev, int lockit) { if (ndev->flags & IFF_UP) return -EBUSY; @@ -763,7 +763,7 @@ do_deluser (struct net_device * ndev, int lockit) } int -do_del_chan (struct net_device * musycc_dev, void *data) +do_del_chan (struct net_device *musycc_dev, void *data) { struct sbecom_chan_param cp; char buf[sizeof (CHANNAME) + 3]; @@ -787,7 +787,7 @@ do_del_chan (struct net_device * musycc_dev, void *data) int c4_reset_board (void *); int -do_reset (struct net_device * musycc_dev, void *data) +do_reset (struct net_device *musycc_dev, void *data) { const struct c4_priv *priv; int i; @@ -816,7 +816,7 @@ do_reset (struct net_device * musycc_dev, void *data) } int -do_reset_chan_stats (struct net_device * musycc_dev, void *data) +do_reset_chan_stats (struct net_device *musycc_dev, void *data) { struct sbecom_chan_param cp; @@ -827,7 +827,7 @@ do_reset_chan_stats (struct net_device * musycc_dev, void *data) } STATIC status_t -c4_ioctl (struct net_device * ndev, struct ifreq * ifr, int cmd) +c4_ioctl (struct net_device *ndev, struct ifreq *ifr, int cmd) { ci_t *ci; void *data; @@ -954,7 +954,7 @@ static void c4_setup(struct net_device *dev) } struct net_device *__init -c4_add_dev (hdw_info_t * hi, int brdno, unsigned long f0, unsigned long f1, +c4_add_dev (hdw_info_t *hi, int brdno, unsigned long f0, unsigned long f1, int irq0, int irq1) { struct net_device *ndev; diff --git a/drivers/staging/cxt1e1/musycc.c b/drivers/staging/cxt1e1/musycc.c index b2cc68a1fe87..1037086d00a7 100644 --- a/drivers/staging/cxt1e1/musycc.c +++ b/drivers/staging/cxt1e1/musycc.c @@ -74,7 +74,7 @@ void musycc_update_timeslots(mpi_t *); #if 1 STATIC int -musycc_dump_rxbuffer_ring(mch_t * ch, int lockit) +musycc_dump_rxbuffer_ring(mch_t *ch, int lockit) { struct mdesc *m; unsigned long flags = 0; @@ -140,7 +140,7 @@ musycc_dump_rxbuffer_ring(mch_t * ch, int lockit) #if 1 STATIC int -musycc_dump_txbuffer_ring(mch_t * ch, int lockit) +musycc_dump_txbuffer_ring(mch_t *ch, int lockit) { struct mdesc *m; unsigned long flags = 0; @@ -205,7 +205,7 @@ musycc_dump_txbuffer_ring(mch_t * ch, int lockit) */ status_t -musycc_dump_ring(ci_t * ci, unsigned int chan) +musycc_dump_ring(ci_t *ci, unsigned int chan) { mch_t *ch; @@ -248,7 +248,7 @@ musycc_dump_ring(ci_t * ci, unsigned int chan) status_t -musycc_dump_rings(ci_t * ci, unsigned int start_chan) +musycc_dump_rings(ci_t *ci, unsigned int start_chan) { unsigned int chan; @@ -264,7 +264,7 @@ musycc_dump_rings(ci_t * ci, unsigned int start_chan) */ void -musycc_init_mdt(mpi_t * pi) +musycc_init_mdt(mpi_t *pi) { u_int32_t *addr, cfg; int i; @@ -288,7 +288,7 @@ musycc_init_mdt(mpi_t * pi) /* Set TX thp to the next unprocessed md */ void -musycc_update_tx_thp(mch_t * ch) +musycc_update_tx_thp(mch_t *ch) { struct mdesc *md; unsigned long flags; @@ -443,7 +443,7 @@ musycc_wq_chan_restart(void *arg) /* channel private structure */ */ void -musycc_chan_restart(mch_t * ch) +musycc_chan_restart(mch_t *ch) { #ifdef RLD_RESTART_DEBUG pr_info("++ musycc_chan_restart[%d]: txd_irq_srv @ %p = sts %x\n", @@ -461,7 +461,7 @@ musycc_chan_restart(mch_t * ch) void -rld_put_led(mpi_t * pi, u_int32_t ledval) +rld_put_led(mpi_t *pi, u_int32_t ledval) { static u_int32_t led = 0; @@ -477,7 +477,7 @@ rld_put_led(mpi_t * pi, u_int32_t ledval) #define MUSYCC_SR_RETRY_CNT 9 void -musycc_serv_req(mpi_t * pi, u_int32_t req) +musycc_serv_req(mpi_t *pi, u_int32_t req) { volatile u_int32_t r; int rcnt; @@ -578,7 +578,7 @@ rewrite: #ifdef SBE_PMCC4_ENABLE void -musycc_update_timeslots(mpi_t * pi) +musycc_update_timeslots(mpi_t *pi) { int i, ch; char e1mode = IS_FRAME_ANY_E1(pi->p.port_mode); @@ -640,7 +640,7 @@ musycc_update_timeslots(mpi_t * pi) #ifdef SBE_WAN256T3_ENABLE void -musycc_update_timeslots(mpi_t * pi) +musycc_update_timeslots(mpi_t *pi) { mch_t *ch; @@ -703,7 +703,7 @@ musycc_chan_proto(int proto) #ifdef SBE_WAN256T3_ENABLE STATIC void __init -musycc_init_port(mpi_t * pi) +musycc_init_port(mpi_t *pi) { pci_write_32((u_int32_t *) &pi->reg->gbp, OS_vtophys(pi->regram)); @@ -737,7 +737,7 @@ musycc_init_port(mpi_t * pi) status_t __init -musycc_init(ci_t * ci) +musycc_init(ci_t *ci) { char *regaddr; /* temp for address boundary calculations */ int i, gchan; @@ -832,7 +832,7 @@ musycc_init(ci_t * ci) void -musycc_bh_tx_eom(mpi_t * pi, int gchan) +musycc_bh_tx_eom(mpi_t *pi, int gchan) { mch_t *ch; struct mdesc *md; @@ -1010,7 +1010,7 @@ musycc_bh_tx_eom(mpi_t * pi, int gchan) STATIC void -musycc_bh_rx_eom(mpi_t * pi, int gchan) +musycc_bh_rx_eom(mpi_t *pi, int gchan) { mch_t *ch; void *m, *m2; @@ -1229,7 +1229,7 @@ unsigned long #else void #endif -musycc_intr_bh_tasklet(ci_t * ci) +musycc_intr_bh_tasklet(ci_t *ci) { mpi_t *pi; mch_t *ch; @@ -1517,7 +1517,7 @@ musycc_intr_bh_tasklet(ci_t * ci) #if 0 int __init -musycc_new_chan(ci_t * ci, int channum, void *user) +musycc_new_chan(ci_t *ci, int channum, void *user) { mch_t *ch; @@ -1546,7 +1546,7 @@ musycc_new_chan(ci_t * ci, int channum, void *user) #ifdef SBE_PMCC4_ENABLE status_t -musycc_chan_down(ci_t * dummy, int channum) +musycc_chan_down(ci_t *dummy, int channum) { mpi_t *pi; mch_t *ch; @@ -1597,7 +1597,7 @@ musycc_chan_down(ci_t * dummy, int channum) int -musycc_del_chan(ci_t * ci, int channum) +musycc_del_chan(ci_t *ci, int channum) { mch_t *ch; @@ -1613,7 +1613,7 @@ musycc_del_chan(ci_t * ci, int channum) int -musycc_del_chan_stats(ci_t * ci, int channum) +musycc_del_chan_stats(ci_t *ci, int channum) { mch_t *ch; @@ -1628,7 +1628,7 @@ musycc_del_chan_stats(ci_t * ci, int channum) int -musycc_start_xmit(ci_t * ci, int channum, void *mem_token) +musycc_start_xmit(ci_t *ci, int channum, void *mem_token) { mch_t *ch; struct mdesc *md; diff --git a/drivers/staging/cxt1e1/pmcc4.h b/drivers/staging/cxt1e1/pmcc4.h index b0ed4ad13011..003eb8690190 100644 --- a/drivers/staging/cxt1e1/pmcc4.h +++ b/drivers/staging/cxt1e1/pmcc4.h @@ -85,15 +85,15 @@ void c4_cleanup (void); status_t c4_chan_up (ci_t *, int channum); status_t c4_del_chan_stats (int channum); status_t c4_del_chan (int channum); -status_t c4_get_iidinfo (ci_t * ci, struct sbe_iid_info * iip); +status_t c4_get_iidinfo (ci_t *ci, struct sbe_iid_info *iip); int c4_is_chan_up (int channum); void *getuserbychan (int channum); -void pci_flush_write (ci_t * ci); +void pci_flush_write (ci_t *ci); void sbecom_set_loglevel (int debuglevel); -char *sbeid_get_bdname (ci_t * ci); -void sbeid_set_bdtype (ci_t * ci); -void sbeid_set_hdwbid (ci_t * ci); +char *sbeid_get_bdname (ci_t *ci); +void sbeid_set_bdtype (ci_t *ci); +void sbeid_set_hdwbid (ci_t *ci); u_int32_t sbeCrc (u_int8_t *, u_int32_t, u_int32_t, u_int32_t *); void VMETRO_TRACE (void *); /* put data into 8 LEDs */ diff --git a/drivers/staging/cxt1e1/pmcc4_drv.c b/drivers/staging/cxt1e1/pmcc4_drv.c index 8d8a22be5b2e..32d7a216a419 100644 --- a/drivers/staging/cxt1e1/pmcc4_drv.c +++ b/drivers/staging/cxt1e1/pmcc4_drv.c @@ -28,7 +28,7 @@ #include /* include for timer */ #include /* include for timer */ #include -#include +#include #include "sbecom_inline_linux.h" #include "libsbew.h" @@ -123,7 +123,7 @@ c4_find_chan (int channum) { if ((ch->state != UNASSIGNED) && (ch->channum == channum)) - return (ch); + return ch; } } return 0; @@ -193,7 +193,7 @@ c4_new (void *hi) #define COMET_LBCMD_READ 0x80 /* read only (do not set, return read value) */ void -checkPorts (ci_t * ci) +checkPorts (ci_t *ci) { #ifndef CONFIG_SBE_PMCC4_NCOMM /* @@ -459,7 +459,7 @@ checkPorts (ci_t * ci) STATIC void -c4_watchdog (ci_t * ci) +c4_watchdog (ci_t *ci) { if (drvr_state != SBE_DRVR_AVAILABLE) { @@ -512,7 +512,7 @@ c4_cleanup (void) */ int -c4_get_portcfg (ci_t * ci) +c4_get_portcfg (ci_t *ci) { comet_t *comet; int portnum, mask; @@ -536,7 +536,7 @@ c4_get_portcfg (ci_t * ci) /* nothing herein should generate interrupts */ status_t __init -c4_init (ci_t * ci, u_char *func0, u_char *func1) +c4_init (ci_t *ci, u_char *func0, u_char *func1) { mpi_t *pi; mch_t *ch; @@ -670,7 +670,7 @@ c4_init (ci_t * ci, u_char *func0, u_char *func1) /* better be fully setup to handle interrupts when you call this */ status_t __init -c4_init2 (ci_t * ci) +c4_init2 (ci_t *ci) { status_t ret; @@ -698,7 +698,7 @@ c4_init2 (ci_t * ci) /* This function sets the loopback mode (or clears it, as the case may be). */ int -c4_loop_port (ci_t * ci, int portnum, u_int8_t cmd) +c4_loop_port (ci_t *ci, int portnum, u_int8_t cmd) { comet_t *comet; volatile u_int32_t loopValue; @@ -757,7 +757,7 @@ c4_loop_port (ci_t * ci, int portnum, u_int8_t cmd) */ status_t -c4_frame_rw (ci_t * ci, struct sbecom_port_param * pp) +c4_frame_rw (ci_t *ci, struct sbecom_port_param *pp) { comet_t *comet; volatile u_int32_t data; @@ -796,7 +796,7 @@ c4_frame_rw (ci_t * ci, struct sbecom_port_param * pp) */ status_t -c4_pld_rw (ci_t * ci, struct sbecom_port_param * pp) +c4_pld_rw (ci_t *ci, struct sbecom_port_param *pp) { volatile u_int32_t *regaddr; volatile u_int32_t data; @@ -834,7 +834,7 @@ c4_pld_rw (ci_t * ci, struct sbecom_port_param * pp) */ status_t -c4_musycc_rw (ci_t * ci, struct c4_musycc_param * mcp) +c4_musycc_rw (ci_t *ci, struct c4_musycc_param *mcp) { mpi_t *pi; volatile u_int32_t *dph; /* hardware implemented register */ @@ -898,7 +898,7 @@ c4_musycc_rw (ci_t * ci, struct c4_musycc_param * mcp) } status_t -c4_get_port (ci_t * ci, int portnum) +c4_get_port (ci_t *ci, int portnum) { if (portnum >= ci->max_port) /* sanity check */ return ENXIO; @@ -913,7 +913,7 @@ c4_get_port (ci_t * ci, int portnum) } status_t -c4_set_port (ci_t * ci, int portnum) +c4_set_port (ci_t *ci, int portnum) { mpi_t *pi; struct sbecom_port_param *pp; @@ -942,7 +942,7 @@ c4_set_port (ci_t * ci, int portnum) if ((ret = c4_wq_port_init (pi))) /* create/init * workqueue_struct */ - return (ret); + return ret; } init_comet (ci, pi->cometbase, pp->port_mode, 1 /* clockmaster == true */ , pp->portP); @@ -1018,7 +1018,7 @@ c4_set_port (ci_t * ci, int portnum) unsigned int max_int = 0; status_t -c4_new_chan (ci_t * ci, int portnum, int channum, void *user) +c4_new_chan (ci_t *ci, int portnum, int channum, void *user) { mpi_t *pi; mch_t *ch; @@ -1111,7 +1111,7 @@ c4_del_chan_stats (int channum) status_t -c4_set_chan (int channum, struct sbecom_chan_param * p) +c4_set_chan (int channum, struct sbecom_chan_param *p) { mch_t *ch; int i, x = 0; @@ -1162,7 +1162,7 @@ c4_set_chan (int channum, struct sbecom_chan_param * p) status_t -c4_get_chan (int channum, struct sbecom_chan_param * p) +c4_get_chan (int channum, struct sbecom_chan_param *p) { mch_t *ch; @@ -1173,7 +1173,7 @@ c4_get_chan (int channum, struct sbecom_chan_param * p) } status_t -c4_get_chan_stats (int channum, struct sbecom_chan_stats * p) +c4_get_chan_stats (int channum, struct sbecom_chan_stats *p) { mch_t *ch; @@ -1185,7 +1185,7 @@ c4_get_chan_stats (int channum, struct sbecom_chan_stats * p) } STATIC int -c4_fifo_alloc (mpi_t * pi, int chan, int *len) +c4_fifo_alloc (mpi_t *pi, int chan, int *len) { int i, l = 0, start = 0, max = 0, maxstart = 0; @@ -1222,7 +1222,7 @@ c4_fifo_alloc (mpi_t * pi, int chan, int *len) } void -c4_fifo_free (mpi_t * pi, int chan) +c4_fifo_free (mpi_t *pi, int chan) { int i; @@ -1236,7 +1236,7 @@ c4_fifo_free (mpi_t * pi, int chan) status_t -c4_chan_up (ci_t * ci, int channum) +c4_chan_up (ci_t *ci, int channum) { mpi_t *pi; mch_t *ch; @@ -1467,7 +1467,7 @@ errfree: /* stop the hardware from servicing & interrupting */ void -c4_stopwd (ci_t * ci) +c4_stopwd (ci_t *ci) { OS_stop_watchdog (&ci->wd); SD_SEM_TAKE (&ci->sem_wdbusy, "_stop_"); /* ensure WD not running */ @@ -1476,7 +1476,7 @@ c4_stopwd (ci_t * ci) void -sbecom_get_brdinfo (ci_t * ci, struct sbe_brd_info * bip, u_int8_t *bsn) +sbecom_get_brdinfo (ci_t *ci, struct sbe_brd_info *bip, u_int8_t *bsn) { char *np; u_int32_t sn = 0; @@ -1485,7 +1485,7 @@ sbecom_get_brdinfo (ci_t * ci, struct sbe_brd_info * bip, u_int8_t *bsn) bip->brdno = ci->brdno; /* our board number */ bip->brd_id = ci->brd_id; bip->brd_hdw_id = ci->hdw_bid; - bip->brd_chan_cnt = MUSYCC_NCHANS * ci->max_port; /* number of channels + bip->brd_chan_cnt = MUSYCC_NCHANS *ci->max_port; /* number of channels * being used */ bip->brd_port_cnt = ci->max_port; /* number of ports being used */ bip->brd_pci_speed = BINFO_PCI_SPEED_unk; /* PCI speed not yet @@ -1535,7 +1535,7 @@ sbecom_get_brdinfo (ci_t * ci, struct sbe_brd_info * bip, u_int8_t *bsn) status_t -c4_get_iidinfo (ci_t * ci, struct sbe_iid_info * iip) +c4_get_iidinfo (ci_t *ci, struct sbe_iid_info *iip) { struct net_device *dev; char *np; @@ -1624,7 +1624,7 @@ wanpmcC4T1E1_getBaseAddress (int cardID, int deviceID) } ci = ci->next; /* next board, if any */ } - return (base); + return base; } #endif /*** CONFIG_SBE_PMCC4_NCOMM ***/ diff --git a/drivers/staging/cxt1e1/sbecom_inline_linux.h b/drivers/staging/cxt1e1/sbecom_inline_linux.h index 68ed445ab0cb..3c6d1c0fc6d6 100644 --- a/drivers/staging/cxt1e1/sbecom_inline_linux.h +++ b/drivers/staging/cxt1e1/sbecom_inline_linux.h @@ -177,7 +177,7 @@ struct watchdog static inline int -OS_start_watchdog (struct watchdog * wd) +OS_start_watchdog (struct watchdog *wd) { wd->h.expires = jiffies + wd->ticks; add_timer (&wd->h); @@ -186,7 +186,7 @@ OS_start_watchdog (struct watchdog * wd) static inline int -OS_stop_watchdog (struct watchdog * wd) +OS_stop_watchdog (struct watchdog *wd) { del_timer_sync (&wd->h); return 0; @@ -194,7 +194,7 @@ OS_stop_watchdog (struct watchdog * wd) static inline int -OS_free_watchdog (struct watchdog * wd) +OS_free_watchdog (struct watchdog *wd) { OS_stop_watchdog (wd); OS_kfree (wd); diff --git a/drivers/staging/cxt1e1/sbeid.c b/drivers/staging/cxt1e1/sbeid.c index a2243b10ef05..0f9bd5f8136c 100644 --- a/drivers/staging/cxt1e1/sbeid.c +++ b/drivers/staging/cxt1e1/sbeid.c @@ -27,7 +27,7 @@ char * -sbeid_get_bdname (ci_t * ci) +sbeid_get_bdname (ci_t *ci) { char *np = 0; @@ -73,7 +73,7 @@ sbeid_get_bdname (ci_t * ci) /* given the presetting of brd_id, set the corresponding hdw_id */ void -sbeid_set_hdwbid (ci_t * ci) +sbeid_set_hdwbid (ci_t *ci) { /* * set SBE's unique hardware identification (for legacy boards might not @@ -170,7 +170,7 @@ sbeid_set_hdwbid (ci_t * ci) /* given the presetting of hdw_bid, set the corresponding brd_id */ void -sbeid_set_bdtype (ci_t * ci) +sbeid_set_bdtype (ci_t *ci) { /* set SBE's unique PCI VENDOR/DEVID */ switch (ci->hdw_bid) diff --git a/drivers/staging/cxt1e1/sbeproc.h b/drivers/staging/cxt1e1/sbeproc.h index e5c072cf1952..37285df359c1 100644 --- a/drivers/staging/cxt1e1/sbeproc.h +++ b/drivers/staging/cxt1e1/sbeproc.h @@ -28,11 +28,11 @@ int __init sbecom_proc_brd_init (ci_t *); #else -static inline void sbecom_proc_brd_cleanup(ci_t * ci) +static inline void sbecom_proc_brd_cleanup(ci_t *ci) { } -static inline int __init sbecom_proc_brd_init(ci_t * ci) +static inline int __init sbecom_proc_brd_init(ci_t *ci) { return 0; } diff --git a/drivers/staging/dgrp/dgrp_dpa_ops.c b/drivers/staging/dgrp/dgrp_dpa_ops.c index 114799cddd85..69bfe309376d 100644 --- a/drivers/staging/dgrp/dgrp_dpa_ops.c +++ b/drivers/staging/dgrp/dgrp_dpa_ops.c @@ -392,7 +392,7 @@ static long dgrp_dpa_ioctl(struct file *file, unsigned int cmd, getnode.nd_rx_byte = nd->nd_rx_byte; memset(&getnode.nd_ps_desc, 0, MAX_DESC_LEN); - strncpy(getnode.nd_ps_desc, nd->nd_ps_desc, MAX_DESC_LEN); + strlcpy(getnode.nd_ps_desc, nd->nd_ps_desc, MAX_DESC_LEN); if (copy_to_user(uarg, &getnode, sizeof(struct digi_node))) return -EFAULT; diff --git a/drivers/staging/dgrp/dgrp_net_ops.c b/drivers/staging/dgrp/dgrp_net_ops.c index 5b7833f593ff..33ac7fb88cbd 100644 --- a/drivers/staging/dgrp/dgrp_net_ops.c +++ b/drivers/staging/dgrp/dgrp_net_ops.c @@ -278,7 +278,7 @@ static void parity_scan(struct ch_struct *ch, unsigned char *cbuf, switch (ch->ch_pscan_state) { default: /* reset to sanity and fall through */ - ch->ch_pscan_state = 0 ; + ch->ch_pscan_state = 0; case 0: /* No FF seen yet */ @@ -1607,7 +1607,7 @@ static int dgrp_send(struct nd_struct *nd, long tmax) if ((ch->ch_pun.un_flag & UN_LOW) != 0 ? (n <= TBUF_LOW) : (ch->ch_pun.un_flag & UN_TIME) != 0 ? - ((jiffies - ch->ch_waketime) >= 0) : + time_is_before_jiffies(ch->ch_waketime) : (n == 0 && ch->ch_s_tpos == ch->ch_s_tin) && ((ch->ch_pun.un_flag & UN_EMPTY) != 0 || ((ch->ch_tun.un_open_count && @@ -3083,7 +3083,7 @@ check_query: nd->nd_hw_ver = (b[8] << 8) | b[9]; nd->nd_sw_ver = (b[10] << 8) | b[11]; nd->nd_hw_id = b[6]; - desclen = ((plen - 12) > MAX_DESC_LEN) ? MAX_DESC_LEN : + desclen = (plen - 12 > MAX_DESC_LEN - 1) ? MAX_DESC_LEN - 1 : plen - 12; if (desclen <= 0) { diff --git a/drivers/staging/dgrp/drp.h b/drivers/staging/dgrp/drp.h index 84a1e7be4899..4024b488eba9 100644 --- a/drivers/staging/dgrp/drp.h +++ b/drivers/staging/dgrp/drp.h @@ -674,7 +674,7 @@ struct nd_struct { ushort nd_hw_ver; /* HW version returned from PS */ ushort nd_sw_ver; /* SW version returned from PS */ uint nd_hw_id; /* HW ID returned from PS */ - u8 nd_ps_desc[MAX_DESC_LEN+1]; /* Description from PS */ + u8 nd_ps_desc[MAX_DESC_LEN]; /* Description from PS */ uint nd_vpd_len; /* VPD len, if any */ u8 nd_vpd[VPDSIZE]; /* VPD, if any */ diff --git a/drivers/staging/dwc2/core.c b/drivers/staging/dwc2/core.c index 3177db2380bf..e3a0e770301d 100644 --- a/drivers/staging/dwc2/core.c +++ b/drivers/staging/dwc2/core.c @@ -506,8 +506,7 @@ static void dwc2_config_fifos(struct dwc2_hsotg *hsotg) struct dwc2_core_params *params = hsotg->core_params; u32 rxfsiz, nptxfsiz, ptxfsiz, hptxfsiz, dfifocfg; - if (!(hsotg->hwcfg2 & GHWCFG2_DYNAMIC_FIFO) || - !params->enable_dynamic_fifo) + if (!params->enable_dynamic_fifo) return; dev_dbg(hsotg->dev, "Total FIFO Size=%d\n", hsotg->total_fifo_size); @@ -1146,16 +1145,10 @@ void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) static void dwc2_hc_set_even_odd_frame(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, u32 *hcchar) { - u32 hfnum, frnum; - if (chan->ep_type == USB_ENDPOINT_XFER_INT || chan->ep_type == USB_ENDPOINT_XFER_ISOC) { - hfnum = readl(hsotg->regs + HFNUM); - frnum = hfnum >> HFNUM_FRNUM_SHIFT & - HFNUM_FRNUM_MASK >> HFNUM_FRNUM_SHIFT; - /* 1 if _next_ frame is odd, 0 if it's even */ - if (frnum & 0x1) + if (!(dwc2_hcd_get_frame_number(hsotg) & 0x1)) *hcchar |= HCCHAR_ODDFRM; } } @@ -1696,7 +1689,7 @@ u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg) GHWCFG2_FS_PHY_TYPE_DEDICATED) clock = 48; - if ((hprt0 & HPRT0_SPD_MASK) == 0) + if ((hprt0 & HPRT0_SPD_MASK) == HPRT0_SPD_HIGH_SPEED) /* High speed case */ return 125 * clock; else @@ -1815,8 +1808,6 @@ void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg) { #ifdef DEBUG u32 __iomem *addr; - int i, ep_num; - char *txfsiz; dev_dbg(hsotg->dev, "Core Global Registers\n"); addr = hsotg->regs + GOTGCTL; @@ -1892,23 +1883,6 @@ void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg) dev_dbg(hsotg->dev, "HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr, readl(addr)); - if (hsotg->core_params->en_multiple_tx_fifo <= 0) { - ep_num = hsotg->hwcfg4 >> GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT & - GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK >> - GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT; - txfsiz = "DPTXFSIZ"; - } else { - ep_num = hsotg->hwcfg4 >> GHWCFG4_NUM_IN_EPS_SHIFT & - GHWCFG4_NUM_IN_EPS_MASK >> GHWCFG4_NUM_IN_EPS_SHIFT; - txfsiz = "DIENPTXF"; - } - - for (i = 0; i < ep_num; i++) { - addr = hsotg->regs + DPTXFSIZN(i + 1); - dev_dbg(hsotg->dev, "%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1, - (unsigned long)addr, readl(addr)); - } - addr = hsotg->regs + PCGCTL; dev_dbg(hsotg->dev, "PCGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr, readl(addr)); @@ -2298,7 +2272,7 @@ int dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val) #ifndef NO_FS_PHY_HW_CHECKS valid = 0; #else - val = 0; + val = DWC2_PHY_TYPE_PARAM_FS; dev_dbg(hsotg->dev, "Setting phy_type to %d\n", val); retval = -EINVAL; #endif @@ -2325,7 +2299,7 @@ int dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val) dev_err(hsotg->dev, "%d invalid for phy_type. Check HW configuration.\n", val); - val = 0; + val = DWC2_PHY_TYPE_PARAM_FS; if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) { if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI) @@ -2360,8 +2334,8 @@ int dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val) valid = 0; } - if (val == 0 && dwc2_get_param_phy_type(hsotg) == - DWC2_PHY_TYPE_PARAM_FS) + if (val == DWC2_SPEED_PARAM_HIGH && + dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS) valid = 0; if (!valid) { @@ -2370,7 +2344,7 @@ int dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val) "%d invalid for speed parameter. Check HW configuration.\n", val); val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS ? - 1 : 0; + DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH; dev_dbg(hsotg->dev, "Setting speed to %d\n", val); retval = -EINVAL; } @@ -2668,7 +2642,7 @@ int dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val) * for the DWC_otg core. It returns non-0 if any parameters are invalid. */ int dwc2_set_parameters(struct dwc2_hsotg *hsotg, - struct dwc2_core_params *params) + const struct dwc2_core_params *params) { int retval = 0; diff --git a/drivers/staging/dwc2/core_intr.c b/drivers/staging/dwc2/core_intr.c index 4c9ad14e90ec..98c51bba6622 100644 --- a/drivers/staging/dwc2/core_intr.c +++ b/drivers/staging/dwc2/core_intr.c @@ -403,8 +403,7 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg) #define GINTMSK_COMMON (GINTSTS_WKUPINT | GINTSTS_SESSREQINT | \ GINTSTS_CONIDSTSCHNG | GINTSTS_OTGINT | \ GINTSTS_MODEMIS | GINTSTS_DISCONNINT | \ - GINTSTS_USBSUSP | GINTSTS_RESTOREDONE | \ - GINTSTS_PRTINT) + GINTSTS_USBSUSP | GINTSTS_PRTINT) /* * This function returns the Core Interrupt register @@ -450,7 +449,7 @@ irqreturn_t dwc2_handle_common_intr(int irq, void *dev) { struct dwc2_hsotg *hsotg = dev; u32 gintsts; - int retval = 0; + irqreturn_t retval = IRQ_NONE; if (dwc2_check_core_status(hsotg) < 0) { dev_warn(hsotg->dev, "Controller is disconnected\n"); @@ -461,7 +460,7 @@ irqreturn_t dwc2_handle_common_intr(int irq, void *dev) gintsts = dwc2_read_common_intr(hsotg); if (gintsts & ~GINTSTS_PRTINT) - retval = 1; + retval = IRQ_HANDLED; if (gintsts & GINTSTS_MODEMIS) dwc2_handle_mode_mismatch_intr(hsotg); @@ -478,12 +477,6 @@ irqreturn_t dwc2_handle_common_intr(int irq, void *dev) if (gintsts & GINTSTS_USBSUSP) dwc2_handle_usb_suspend_intr(hsotg); - if (gintsts & GINTSTS_RESTOREDONE) { - gintsts = GINTSTS_RESTOREDONE; - writel(gintsts, hsotg->regs + GINTSTS); - dev_dbg(hsotg->dev, " --Restore done interrupt received--\n"); - } - if (gintsts & GINTSTS_PRTINT) { /* * The port interrupt occurs while in device mode with HPRT0 @@ -500,6 +493,6 @@ irqreturn_t dwc2_handle_common_intr(int irq, void *dev) spin_unlock(&hsotg->lock); out: - return IRQ_RETVAL(retval); + return retval; } EXPORT_SYMBOL_GPL(dwc2_handle_common_intr); diff --git a/drivers/staging/dwc2/hcd.c b/drivers/staging/dwc2/hcd.c index 8551ccedf037..2ed54b172a3b 100644 --- a/drivers/staging/dwc2/hcd.c +++ b/drivers/staging/dwc2/hcd.c @@ -1563,9 +1563,9 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, break; case GetPortStatus: - dev_dbg(hsotg->dev, - "GetPortStatus wIndex=0x%04x flags=0x%08x\n", windex, - hsotg->flags.d32); + dev_vdbg(hsotg->dev, + "GetPortStatus wIndex=0x%04x flags=0x%08x\n", windex, + hsotg->flags.d32); if (!windex || windex > 1) goto error; @@ -1598,7 +1598,7 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, } hprt0 = readl(hsotg->regs + HPRT0); - dev_dbg(hsotg->dev, " HPRT0: 0x%08x\n", hprt0); + dev_vdbg(hsotg->dev, " HPRT0: 0x%08x\n", hprt0); if (hprt0 & HPRT0_CONNSTS) port_status |= USB_PORT_STAT_CONNECTION; @@ -1623,7 +1623,7 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, port_status |= USB_PORT_STAT_TEST; /* USB_PORT_FEAT_INDICATOR unsupported always 0 */ - dev_dbg(hsotg->dev, "port_status=%08x\n", port_status); + dev_vdbg(hsotg->dev, "port_status=%08x\n", port_status); *(__le32 *)buf = cpu_to_le32(port_status); break; @@ -2533,9 +2533,8 @@ static void _dwc2_hcd_endpoint_reset(struct usb_hcd *hcd, static irqreturn_t _dwc2_hcd_irq(struct usb_hcd *hcd) { struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); - int retval = dwc2_hcd_intr(hsotg); - return IRQ_RETVAL(retval); + return dwc2_handle_hcd_intr(hsotg); } /* @@ -2702,7 +2701,7 @@ EXPORT_SYMBOL_GPL(dwc2_set_all_params); * a negative error on failure. */ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, - struct dwc2_core_params *params) + const struct dwc2_core_params *params) { struct usb_hcd *hcd; struct dwc2_host_chan *channel; @@ -2919,7 +2918,7 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, * allocates the DMA buffer pool, registers the USB bus, requests the * IRQ line, and calls hcd_start method. */ - retval = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED); + retval = usb_add_hcd(hcd, irq, IRQF_SHARED); if (retval < 0) goto error3; diff --git a/drivers/staging/dwc2/hcd.h b/drivers/staging/dwc2/hcd.h index d071f1a05df1..cf6c055aec8d 100644 --- a/drivers/staging/dwc2/hcd.h +++ b/drivers/staging/dwc2/hcd.h @@ -448,10 +448,10 @@ static inline u8 dwc2_hcd_is_pipe_out(struct dwc2_hcd_pipe_info *pipe) } extern int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, - struct dwc2_core_params *params); + const struct dwc2_core_params *params); extern void dwc2_hcd_remove(struct dwc2_hsotg *hsotg); extern int dwc2_set_parameters(struct dwc2_hsotg *hsotg, - struct dwc2_core_params *params); + const struct dwc2_core_params *params); extern void dwc2_set_all_params(struct dwc2_core_params *params, int value); /* Transaction Execution Functions */ @@ -646,14 +646,14 @@ extern void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg, /* HCD Core API */ /** - * dwc2_hcd_intr() - Called on every hardware interrupt + * dwc2_handle_hcd_intr() - Called on every hardware interrupt * * @hsotg: The DWC2 HCD * - * Returns non zero if interrupt is handled - * Return 0 if interrupt is not handled + * Returns IRQ_HANDLED if interrupt is handled + * Return IRQ_NONE if interrupt is not handled */ -extern int dwc2_hcd_intr(struct dwc2_hsotg *hsotg); +extern irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg); /** * dwc2_hcd_stop() - Halts the DWC_otg host mode operation diff --git a/drivers/staging/dwc2/hcd_intr.c b/drivers/staging/dwc2/hcd_intr.c index e24062f0a49e..e75dccb3b80b 100644 --- a/drivers/staging/dwc2/hcd_intr.c +++ b/drivers/staging/dwc2/hcd_intr.c @@ -115,16 +115,13 @@ static void dwc2_sof_intr(struct dwc2_hsotg *hsotg) { struct list_head *qh_entry; struct dwc2_qh *qh; - u32 hfnum; enum dwc2_transaction_type tr_type; #ifdef DEBUG_SOF dev_vdbg(hsotg->dev, "--Start of Frame Interrupt--\n"); #endif - hfnum = readl(hsotg->regs + HFNUM); - hsotg->frame_number = hfnum >> HFNUM_FRNUM_SHIFT & - HFNUM_FRNUM_MASK >> HFNUM_FRNUM_SHIFT; + hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg); dwc2_track_missed_sofs(hsotg); @@ -244,6 +241,7 @@ static void dwc2_hprt0_enable(struct dwc2_hsotg *hsotg, u32 hprt0, u32 usbcfg; u32 prtspd; u32 hcfg; + u32 fslspclksel; u32 hfir; dev_vdbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); @@ -275,6 +273,7 @@ static void dwc2_hprt0_enable(struct dwc2_hsotg *hsotg, u32 hprt0, } hcfg = readl(hsotg->regs + HCFG); + fslspclksel = hcfg & HCFG_FSLSPCLKSEL_MASK; if (prtspd == HPRT0_SPD_LOW_SPEED && params->host_ls_low_power_phy_clk == @@ -282,8 +281,7 @@ static void dwc2_hprt0_enable(struct dwc2_hsotg *hsotg, u32 hprt0, /* 6 MHZ */ dev_vdbg(hsotg->dev, "FS_PHY programming HCFG to 6 MHz\n"); - if ((hcfg & HCFG_FSLSPCLKSEL_MASK) != - HCFG_FSLSPCLKSEL_6_MHZ) { + if (fslspclksel != HCFG_FSLSPCLKSEL_6_MHZ) { hcfg &= ~HCFG_FSLSPCLKSEL_MASK; hcfg |= HCFG_FSLSPCLKSEL_6_MHZ; writel(hcfg, hsotg->regs + HCFG); @@ -293,8 +291,7 @@ static void dwc2_hprt0_enable(struct dwc2_hsotg *hsotg, u32 hprt0, /* 48 MHZ */ dev_vdbg(hsotg->dev, "FS_PHY programming HCFG to 48 MHz\n"); - if ((hcfg & HCFG_FSLSPCLKSEL_MASK) != - HCFG_FSLSPCLKSEL_48_MHZ) { + if (fslspclksel != HCFG_FSLSPCLKSEL_48_MHZ) { hcfg &= ~HCFG_FSLSPCLKSEL_MASK; hcfg |= HCFG_FSLSPCLKSEL_48_MHZ; writel(hcfg, hsotg->regs + HCFG); @@ -2060,14 +2057,14 @@ static void dwc2_hc_intr(struct dwc2_hsotg *hsotg) } /* This function handles interrupts for the HCD */ -int dwc2_hcd_intr(struct dwc2_hsotg *hsotg) +irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg) { u32 gintsts, dbg_gintsts; - int retval = 0; + irqreturn_t retval = IRQ_NONE; if (dwc2_check_core_status(hsotg) < 0) { dev_warn(hsotg->dev, "Controller is disconnected\n"); - return 0; + return retval; } spin_lock(&hsotg->lock); @@ -2077,10 +2074,10 @@ int dwc2_hcd_intr(struct dwc2_hsotg *hsotg) gintsts = dwc2_read_core_intr(hsotg); if (!gintsts) { spin_unlock(&hsotg->lock); - return 0; + return retval; } - retval = 1; + retval = IRQ_HANDLED; dbg_gintsts = gintsts; #ifndef DEBUG_SOF @@ -2102,9 +2099,6 @@ int dwc2_hcd_intr(struct dwc2_hsotg *hsotg) dwc2_rx_fifo_level_intr(hsotg); if (gintsts & GINTSTS_NPTXFEMP) dwc2_np_tx_fifo_empty_intr(hsotg); - if (gintsts & GINTSTS_I2CINT) - /* Todo: Implement i2cintr handler */ - writel(GINTSTS_I2CINT, hsotg->regs + GINTSTS); if (gintsts & GINTSTS_PRTINT) dwc2_port_intr(hsotg); if (gintsts & GINTSTS_HCHINT) diff --git a/drivers/staging/dwc2/pci.c b/drivers/staging/dwc2/pci.c index 69c65eb8683f..3ca54d6782fd 100644 --- a/drivers/staging/dwc2/pci.c +++ b/drivers/staging/dwc2/pci.c @@ -59,7 +59,7 @@ static const char dwc2_driver_name[] = "dwc2"; -static struct dwc2_core_params dwc2_module_params = { +static const struct dwc2_core_params dwc2_module_params = { .otg_cap = -1, .otg_ver = -1, .dma_enable = -1, @@ -101,8 +101,6 @@ static void dwc2_driver_remove(struct pci_dev *dev) { struct dwc2_hsotg *hsotg = pci_get_drvdata(dev); - dev_dbg(&dev->dev, "%s(%p)\n", __func__, dev); - dwc2_hcd_remove(hsotg); pci_disable_device(dev); } @@ -125,18 +123,14 @@ static int dwc2_driver_probe(struct pci_dev *dev, struct dwc2_hsotg *hsotg; int retval; - dev_dbg(&dev->dev, "%s(%p)\n", __func__, dev); - hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); if (!hsotg) return -ENOMEM; - pci_set_power_state(dev, PCI_D0); - hsotg->dev = &dev->dev; - hsotg->regs = devm_request_and_ioremap(&dev->dev, &dev->resource[0]); - if (!hsotg->regs) - return -ENOMEM; + hsotg->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]); + if (IS_ERR(hsotg->regs)) + return PTR_ERR(hsotg->regs); dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", (unsigned long)pci_resource_start(dev, 0), hsotg->regs); @@ -153,7 +147,6 @@ static int dwc2_driver_probe(struct pci_dev *dev, } pci_set_drvdata(dev, hsotg); - dev_dbg(&dev->dev, "hsotg=%p\n", hsotg); return retval; } @@ -162,6 +155,10 @@ static DEFINE_PCI_DEVICE_TABLE(dwc2_pci_ids) = { { PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG), }, + { + PCI_DEVICE(PCI_VENDOR_ID_STMICRO, + PCI_DEVICE_ID_STMICRO_USB_OTG), + }, { /* end: all zeroes */ } }; MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); diff --git a/drivers/staging/echo/echo.c b/drivers/staging/echo/echo.c index 5882139d49af..9597e9523cac 100644 --- a/drivers/staging/echo/echo.c +++ b/drivers/staging/echo/echo.c @@ -267,13 +267,13 @@ struct oslec_state *oslec_create(int len, int adaption_mode) goto error_snap; ec->cond_met = 0; - ec->Pstates = 0; - ec->Ltxacc = ec->Lrxacc = ec->Lcleanacc = ec->Lclean_bgacc = 0; - ec->Ltx = ec->Lrx = ec->Lclean = ec->Lclean_bg = 0; + ec->pstates = 0; + ec->ltxacc = ec->lrxacc = ec->lcleanacc = ec->lclean_bgacc = 0; + ec->ltx = ec->lrx = ec->lclean = ec->lclean_bg = 0; ec->tx_1 = ec->tx_2 = ec->rx_1 = ec->rx_2 = 0; - ec->Lbgn = ec->Lbgn_acc = 0; - ec->Lbgn_upper = 200; - ec->Lbgn_upper_acc = ec->Lbgn_upper << 13; + ec->lbgn = ec->lbgn_acc = 0; + ec->lbgn_upper = 200; + ec->lbgn_upper_acc = ec->lbgn_upper << 13; return ec; @@ -314,13 +314,13 @@ void oslec_flush(struct oslec_state *ec) { int i; - ec->Ltxacc = ec->Lrxacc = ec->Lcleanacc = ec->Lclean_bgacc = 0; - ec->Ltx = ec->Lrx = ec->Lclean = ec->Lclean_bg = 0; + ec->ltxacc = ec->lrxacc = ec->lcleanacc = ec->lclean_bgacc = 0; + ec->ltx = ec->lrx = ec->lclean = ec->lclean_bg = 0; ec->tx_1 = ec->tx_2 = ec->rx_1 = ec->rx_2 = 0; - ec->Lbgn = ec->Lbgn_acc = 0; - ec->Lbgn_upper = 200; - ec->Lbgn_upper_acc = ec->Lbgn_upper << 13; + ec->lbgn = ec->lbgn_acc = 0; + ec->lbgn_upper = 200; + ec->lbgn_upper_acc = ec->lbgn_upper << 13; ec->nonupdate_dwell = 0; @@ -332,7 +332,7 @@ void oslec_flush(struct oslec_state *ec) memset(ec->fir_taps16[i], 0, ec->taps * sizeof(int16_t)); ec->curr_pos = ec->taps - 1; - ec->Pstates = 0; + ec->pstates = 0; } EXPORT_SYMBOL_GPL(oslec_flush); @@ -418,33 +418,33 @@ int16_t oslec_update(struct oslec_state *ec, int16_t tx, int16_t rx) new = (int)tx * (int)tx; old = (int)ec->fir_state.history[ec->fir_state.curr_pos] * (int)ec->fir_state.history[ec->fir_state.curr_pos]; - ec->Pstates += + ec->pstates += ((new - old) + (1 << (ec->log2taps - 1))) >> ec->log2taps; - if (ec->Pstates < 0) - ec->Pstates = 0; + if (ec->pstates < 0) + ec->pstates = 0; } /* Calculate short term average levels using simple single pole IIRs */ - ec->Ltxacc += abs(tx) - ec->Ltx; - ec->Ltx = (ec->Ltxacc + (1 << 4)) >> 5; - ec->Lrxacc += abs(rx) - ec->Lrx; - ec->Lrx = (ec->Lrxacc + (1 << 4)) >> 5; + ec->ltxacc += abs(tx) - ec->ltx; + ec->ltx = (ec->ltxacc + (1 << 4)) >> 5; + ec->lrxacc += abs(rx) - ec->lrx; + ec->lrx = (ec->lrxacc + (1 << 4)) >> 5; /* Foreground filter */ ec->fir_state.coeffs = ec->fir_taps16[0]; echo_value = fir16(&ec->fir_state, tx); ec->clean = rx - echo_value; - ec->Lcleanacc += abs(ec->clean) - ec->Lclean; - ec->Lclean = (ec->Lcleanacc + (1 << 4)) >> 5; + ec->lcleanacc += abs(ec->clean) - ec->lclean; + ec->lclean = (ec->lcleanacc + (1 << 4)) >> 5; /* Background filter */ echo_value = fir16(&ec->fir_state_bg, tx); clean_bg = rx - echo_value; - ec->Lclean_bgacc += abs(clean_bg) - ec->Lclean_bg; - ec->Lclean_bg = (ec->Lclean_bgacc + (1 << 4)) >> 5; + ec->lclean_bgacc += abs(clean_bg) - ec->lclean_bg; + ec->lclean_bg = (ec->lclean_bgacc + (1 << 4)) >> 5; /* Background Filter adaption */ @@ -455,7 +455,7 @@ int16_t oslec_update(struct oslec_state *ec, int16_t tx, int16_t rx) ec->factor = 0; ec->shift = 0; if ((ec->nonupdate_dwell == 0)) { - int P, logP, shift; + int p, logp, shift; /* Determine: @@ -490,9 +490,9 @@ int16_t oslec_update(struct oslec_state *ec, int16_t tx, int16_t rx) for a divide versus a top_bit() implementation. */ - P = MIN_TX_POWER_FOR_ADAPTION + ec->Pstates; - logP = top_bit(P) + ec->log2taps; - shift = 30 - 2 - logP; + p = MIN_TX_POWER_FOR_ADAPTION + ec->pstates; + logp = top_bit(p) + ec->log2taps; + shift = 30 - 2 - logp; ec->shift = shift; lms_adapt_bg(ec, clean_bg, shift); @@ -502,7 +502,7 @@ int16_t oslec_update(struct oslec_state *ec, int16_t tx, int16_t rx) near end speech */ ec->adapt = 0; - if ((ec->Lrx > MIN_RX_POWER_FOR_ADAPTION) && (ec->Lrx > ec->Ltx)) + if ((ec->lrx > MIN_RX_POWER_FOR_ADAPTION) && (ec->lrx > ec->ltx)) ec->nonupdate_dwell = DTD_HANGOVER; if (ec->nonupdate_dwell) ec->nonupdate_dwell--; @@ -515,9 +515,9 @@ int16_t oslec_update(struct oslec_state *ec, int16_t tx, int16_t rx) if ((ec->adaption_mode & ECHO_CAN_USE_ADAPTION) && (ec->nonupdate_dwell == 0) && /* (ec->Lclean_bg < 0.875*ec->Lclean) */ - (8 * ec->Lclean_bg < 7 * ec->Lclean) && + (8 * ec->lclean_bg < 7 * ec->lclean) && /* (ec->Lclean_bg < 0.125*ec->Ltx) */ - (8 * ec->Lclean_bg < ec->Ltx)) { + (8 * ec->lclean_bg < ec->ltx)) { if (ec->cond_met == 6) { /* * BG filter has had better results for 6 consecutive @@ -541,14 +541,14 @@ int16_t oslec_update(struct oslec_state *ec, int16_t tx, int16_t rx) * non-linearity in the channel.". */ - if ((16 * ec->Lclean < ec->Ltx)) { + if ((16 * ec->lclean < ec->ltx)) { /* * Our e/c has improved echo by at least 24 dB (each * factor of 2 is 6dB, so 2*2*2*2=16 is the same as * 6+6+6+6=24dB) */ if (ec->adaption_mode & ECHO_CAN_USE_CNG) { - ec->cng_level = ec->Lbgn; + ec->cng_level = ec->lbgn; /* * Very elementary comfort noise generation. @@ -571,10 +571,10 @@ int16_t oslec_update(struct oslec_state *ec, int16_t tx, int16_t rx) } else if (ec->adaption_mode & ECHO_CAN_USE_CLIP) { /* This sounds much better than CNG */ - if (ec->clean_nlp > ec->Lbgn) - ec->clean_nlp = ec->Lbgn; - if (ec->clean_nlp < -ec->Lbgn) - ec->clean_nlp = -ec->Lbgn; + if (ec->clean_nlp > ec->lbgn) + ec->clean_nlp = ec->lbgn; + if (ec->clean_nlp < -ec->lbgn) + ec->clean_nlp = -ec->lbgn; } else { /* * just mute the residual, doesn't sound very @@ -593,9 +593,9 @@ int16_t oslec_update(struct oslec_state *ec, int16_t tx, int16_t rx) * level signals like near end speech. When combined * with CNG or especially CLIP seems to work OK. */ - if (ec->Lclean < 40) { - ec->Lbgn_acc += abs(ec->clean) - ec->Lbgn; - ec->Lbgn = (ec->Lbgn_acc + (1 << 11)) >> 12; + if (ec->lclean < 40) { + ec->lbgn_acc += abs(ec->clean) - ec->lbgn; + ec->lbgn = (ec->lbgn_acc + (1 << 11)) >> 12; } } } diff --git a/drivers/staging/echo/echo.h b/drivers/staging/echo/echo.h index 32ca9dedeca4..9b08c63e6369 100644 --- a/drivers/staging/echo/echo.h +++ b/drivers/staging/echo/echo.h @@ -139,24 +139,24 @@ struct oslec_state { int adaption_mode; int cond_met; - int32_t Pstates; + int32_t pstates; int16_t adapt; int32_t factor; int16_t shift; /* Average levels and averaging filter states */ - int Ltxacc; - int Lrxacc; - int Lcleanacc; - int Lclean_bgacc; - int Ltx; - int Lrx; - int Lclean; - int Lclean_bg; - int Lbgn; - int Lbgn_acc; - int Lbgn_upper; - int Lbgn_upper_acc; + int ltxacc; + int lrxacc; + int lcleanacc; + int lclean_bgacc; + int ltx; + int lrx; + int lclean; + int lclean_bg; + int lbgn; + int lbgn_acc; + int lbgn_upper; + int lbgn_upper_acc; /* foreground and background filter states */ struct fir16_state_t fir_state; diff --git a/drivers/staging/frontier/alphatrack.c b/drivers/staging/frontier/alphatrack.c index ea9362d7e589..5590ebf1da15 100644 --- a/drivers/staging/frontier/alphatrack.c +++ b/drivers/staging/frontier/alphatrack.c @@ -24,13 +24,14 @@ * raw interrupt reports. */ -/* Note: this currently uses a dumb ringbuffer for reads and writes. +/* + * Note: this currently uses a dumb ringbuffer for reads and writes. * A more optimal driver would cache and kill off outstanding urbs that are * now invalid, and ignore ones that already were in the queue but valid * as we only have 30 commands for the alphatrack. In particular this is * key for getting lights to flash in time as otherwise many commands * can be buffered up before the light change makes it to the interface. -*/ + */ #include #include @@ -100,7 +101,8 @@ static int debug = ALPHATRACK_DEBUG; module_param(debug, int, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(debug, "Debug enabled or not"); -/* All interrupt in transfers are collected in a ring buffer to +/* + * All interrupt in transfers are collected in a ring buffer to * avoid racing conditions and get better performance of the driver. */ @@ -109,8 +111,7 @@ static int ring_buffer_size = RING_BUFFER_SIZE; module_param(ring_buffer_size, int, S_IRUGO); MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size"); -/* The write_buffer can one day contain more than one interrupt out transfer. - */ +/* The write_buffer can one day contain more than one interrupt out transfer.*/ static int write_buffer_size = WRITE_BUFFER_SIZE; module_param(write_buffer_size, int, S_IRUGO); @@ -199,9 +200,7 @@ static void usb_alphatrack_abort_transfers(struct usb_alphatrack *dev) usb_kill_urb(dev->interrupt_out_urb); } -/** - * usb_alphatrack_delete - */ +/** usb_alphatrack_delete */ static void usb_alphatrack_delete(struct usb_alphatrack *dev) { usb_alphatrack_abort_transfers(dev); @@ -213,9 +212,7 @@ static void usb_alphatrack_delete(struct usb_alphatrack *dev) kfree(dev); /* fixme oldi_buffer */ } -/** - * usb_alphatrack_interrupt_in_callback - */ +/** usb_alphatrack_interrupt_in_callback */ static void usb_alphatrack_interrupt_in_callback(struct urb *urb) { @@ -296,9 +293,7 @@ exit: wake_up_interruptible(&dev->read_wait); } -/** - * usb_alphatrack_interrupt_out_callback - */ +/** usb_alphatrack_interrupt_out_callback */ static void usb_alphatrack_interrupt_out_callback(struct urb *urb) { struct usb_alphatrack *dev = urb->context; @@ -315,9 +310,7 @@ static void usb_alphatrack_interrupt_out_callback(struct urb *urb) wake_up_interruptible(&dev->write_wait); } -/** - * usb_alphatrack_open - */ +/** usb_alphatrack_open */ static int usb_alphatrack_open(struct inode *inode, struct file *file) { struct usb_alphatrack *dev; @@ -398,9 +391,7 @@ unlock_disconnect_exit: return retval; } -/** - * usb_alphatrack_release - */ +/** usb_alphatrack_release */ static int usb_alphatrack_release(struct inode *inode, struct file *file) { struct usb_alphatrack *dev; @@ -447,9 +438,7 @@ exit: return retval; } -/** - * usb_alphatrack_poll - */ +/** usb_alphatrack_poll */ static unsigned int usb_alphatrack_poll(struct file *file, poll_table *wait) { struct usb_alphatrack *dev; @@ -468,9 +457,7 @@ static unsigned int usb_alphatrack_poll(struct file *file, poll_table *wait) return mask; } -/** - * usb_alphatrack_read - */ +/** usb_alphatrack_read */ static ssize_t usb_alphatrack_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) { @@ -539,9 +526,7 @@ exit: return retval; } -/** - * usb_alphatrack_write - */ +/** usb_alphatrack_write */ static ssize_t usb_alphatrack_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) @@ -601,7 +586,7 @@ static ssize_t usb_alphatrack_write(struct file *file, } if (dev->interrupt_out_endpoint == NULL) { - dev_err(&dev->intf->dev, "Endpoint should not be be null!\n"); + dev_err(&dev->intf->dev, "Endpoint should not be null!\n"); goto unlock_exit; } @@ -718,8 +703,10 @@ static int usb_alphatrack_probe(struct usb_interface *intf, true_size = min(ring_buffer_size, RING_BUFFER_SIZE); - /* FIXME - there are more usb_alloc routines for dma correctness. - Needed? */ + /* + * FIXME - there are more usb_alloc routines for dma correctness. + * Needed? + */ dev->ring_buffer = kmalloc_array(true_size, sizeof(struct alphatrack_icmd), GFP_KERNEL); diff --git a/drivers/staging/frontier/alphatrack.h b/drivers/staging/frontier/alphatrack.h index 10a797263594..418c6053c027 100644 --- a/drivers/staging/frontier/alphatrack.h +++ b/drivers/staging/frontier/alphatrack.h @@ -6,7 +6,8 @@ struct alphatrack_ocmd { unsigned char cmd[8]; }; -/* These are unused by the present driver but provide documentation for the +/* + * These are unused by the present driver but provide documentation for the * userspace API. */ enum LightID { @@ -58,7 +59,8 @@ enum LightID { #define BUTTONMASK_PRESS2 0x00008010 #define BUTTONMASK_PRESS3 0x00002020 -/* last 3 bytes are the slider position +/* + * last 3 bytes are the slider position * 40 is the actual slider moving, the most sig bits, and 3 lsb */ diff --git a/drivers/staging/frontier/tranzport.c b/drivers/staging/frontier/tranzport.c index 04b5e66d9861..6cbf9c7c1d38 100644 --- a/drivers/staging/frontier/tranzport.c +++ b/drivers/staging/frontier/tranzport.c @@ -86,7 +86,8 @@ static int debug = TRANZPORT_DEBUG; module_param(debug, int, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(debug, "Debug enabled or not"); -/* All interrupt in transfers are collected in a ring buffer to +/* + * All interrupt in transfers are collected in a ring buffer to * avoid racing conditions and get better performance of the driver. */ @@ -95,7 +96,8 @@ static int ring_buffer_size = RING_BUFFER_SIZE; module_param(ring_buffer_size, int, S_IRUGO); MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size in reports"); -/* The write_buffer can one day contain more than one interrupt out transfer. +/* + * The write_buffer can one day contain more than one interrupt out transfer. */ static int write_buffer_size = WRITE_BUFFER_SIZE; module_param(write_buffer_size, int, S_IRUGO); @@ -565,9 +567,9 @@ static ssize_t usb_tranzport_read(struct file *file, char __user *buffer, newwheel = (*dev->ring_buffer)[next_tail].cmd[6]; oldwheel = (*dev->ring_buffer)[dev->ring_tail].cmd[6]; /* if both are wheel events, and - no buttons have changes (FIXME, do I have to check?), - and we are the same sign, we can compress +- 7F - */ + * no buttons have changes (FIXME, do I have to check?), + * and we are the same sign, we can compress +- 7F + */ dbg_info(&dev->intf->dev, "%s: trying to compress: " "%02x%02x%02x%02x%02x%02x%02x%02x\n", @@ -729,7 +731,7 @@ static ssize_t usb_tranzport_write(struct file *file, } if (dev->interrupt_out_endpoint == NULL) { - dev_err(&dev->intf->dev, "Endpoint should not be be null!\n"); + dev_err(&dev->intf->dev, "Endpoint should not be null!\n"); goto unlock_exit; } @@ -842,8 +844,10 @@ static int usb_tranzport_probe(struct usb_interface *intf, ring_buffer_size = RING_BUFFER_SIZE; true_size = min(ring_buffer_size, RING_BUFFER_SIZE); - /* FIXME - there are more usb_alloc routines for dma correctness. - Needed? */ + /* + * FIXME - there are more usb_alloc routines for dma correctness. + * Needed? + */ dev->ring_buffer = kmalloc((true_size * sizeof(struct tranzport_cmd)) + 8, GFP_KERNEL); diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c index 47cc365c630b..6311b2ff5816 100644 --- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c +++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c @@ -132,16 +132,16 @@ void card_bootload(struct net_device *dev) pdata = (u32 *) bootimage; size = sizeof(bootimage); - // check for odd word - if (size & 0x0003) { + /* check for odd word */ + if (size & 0x0003) size += 4; - } - // Provide mutual exclusive access while reading ASIC registers. + + /* Provide mutual exclusive access while reading ASIC registers. */ spin_lock_irqsave(&info->dpram_lock, flags); - // need to set i/o base address initially and hardware will autoincrement + /* need to set i/o base address initially and hardware will autoincrement */ ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, FT1000_DPRAM_BASE); - // write bytes + /* write bytes */ for (i = 0; i < (size >> 2); i++) { templong = *pdata++; outl(templong, dev->base_addr + FT1000_REG_MAG_DPDATA); @@ -345,11 +345,10 @@ int card_download(struct net_device *dev, const u8 *pFileStart, handshake = get_handshake(dev, HANDSHAKE_DSP_BL_READY); - if (handshake == HANDSHAKE_DSP_BL_READY) { + if (handshake == HANDSHAKE_DSP_BL_READY) put_handshake(dev, HANDSHAKE_DRIVER_READY); - } else { + else Status = FAILURE; - } uiState = STATE_BOOT_DWNLD; @@ -391,7 +390,7 @@ int card_download(struct net_device *dev, const u8 *pFileStart, Status = FAILURE; break; } - // Provide mutual exclusive access while reading ASIC registers. + /* Provide mutual exclusive access while reading ASIC registers. */ spin_lock_irqsave(&info->dpram_lock, flags); /* @@ -505,15 +504,15 @@ int card_download(struct net_device *dev, const u8 *pFileStart, break; case REQUEST_MAILBOX_DATA: - // Convert length from byte count to word count. Make sure we round up. + /* Convert length from byte count to word count. Make sure we round up. */ word_length = (long)(info->DSPInfoBlklen + 1) / 2; put_request_value(dev, word_length); pMailBoxData = - (struct drv_msg *) & info->DSPInfoBlk[0]; + (struct drv_msg *) &info->DSPInfoBlk[0]; pUsData = - (u16 *) & pMailBoxData->data[0]; - // Provide mutual exclusive access while reading ASIC registers. + (u16 *) &pMailBoxData->data[0]; + /* Provide mutual exclusive access while reading ASIC registers. */ spin_lock_irqsave(&info->dpram_lock, flags); if (file_version == 5) { @@ -538,9 +537,9 @@ int card_download(struct net_device *dev, const u8 *pFileStart, outw(DWNLD_MAG_PS_HDR_LOC, dev->base_addr + FT1000_REG_DPRAM_ADDR); - if (word_length & 0x01) { + if (word_length & 0x01) word_length++; - } + word_length = word_length / 2; for (; word_length > 0; word_length--) { /* In words */ @@ -565,7 +564,7 @@ int card_download(struct net_device *dev, const u8 *pFileStart, (u16 *) ((long)pFileStart + pFileHdr5-> version_data_offset); - // Provide mutual exclusive access while reading ASIC registers. + /* Provide mutual exclusive access while reading ASIC registers. */ spin_lock_irqsave(&info->dpram_lock, flags); /* @@ -692,7 +691,7 @@ int card_download(struct net_device *dev, const u8 *pFileStart, if (pHdr->portdest == 0x80 /* DspOAM */ && (pHdr->portsrc == 0x00 /* Driver */ - || pHdr->portsrc == 0x10 /* FMM */ )) { + || pHdr->portsrc == 0x10 /* FMM */)) { uiState = STATE_SECTION_PROV; } else { DEBUG(1, @@ -711,13 +710,13 @@ int card_download(struct net_device *dev, const u8 *pFileStart, pHdr = (struct pseudo_hdr *) pUcFile; if (pHdr->checksum == hdr_checksum(pHdr)) { - if (pHdr->portdest != 0x80 /* Dsp OAM */ ) { + if (pHdr->portdest != 0x80 /* Dsp OAM */) { uiState = STATE_DONE_PROV; break; } usHdrLength = ntohs(pHdr->length); /* Byte length for PROV records */ - // Get buffer for provisioning data + /* Get buffer for provisioning data */ pbuffer = kmalloc((usHdrLength + sizeof(struct pseudo_hdr)), GFP_ATOMIC); @@ -725,7 +724,7 @@ int card_download(struct net_device *dev, const u8 *pFileStart, memcpy(pbuffer, (void *)pUcFile, (u32) (usHdrLength + sizeof(struct pseudo_hdr))); - // link provisioning data + /* link provisioning data */ pprov_record = kmalloc(sizeof(struct prov_record), GFP_ATOMIC); @@ -735,7 +734,7 @@ int card_download(struct net_device *dev, const u8 *pFileStart, list_add_tail(&pprov_record-> list, &info->prov_list); - // Move to next entry if available + /* Move to next entry if available */ pUcFile = (u8 *) ((unsigned long) pUcFile + (unsigned long) ((usHdrLength + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr)); diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c index 3251d2e073b5..68a55ce69200 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c @@ -1,29 +1,31 @@ -//--------------------------------------------------------------------------- -// FT1000 driver for Flarion Flash OFDM NIC Device -// -// Copyright (C) 2006 Flarion Technologies, All rights reserved. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 2 of the License, or (at your option) any -// later version. This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -// more details. You should have received a copy of the GNU General Public -// License along with this program; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - -// Suite 330, Boston, MA 02111-1307, USA. -//--------------------------------------------------------------------------- -// -// File: ft1000_chdev.c -// -// Description: Custom character device dispatch routines. -// -// History: -// 8/29/02 Whc Ported to Linux. -// 6/05/06 Whc Porting to Linux 2.6.9 -// -//--------------------------------------------------------------------------- +/* +*--------------------------------------------------------------------------- +* FT1000 driver for Flarion Flash OFDM NIC Device +* +* Copyright (C) 2006 Flarion Technologies, All rights reserved. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) any +* later version. This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - +* Suite 330, Boston, MA 02111-1307, USA. +*--------------------------------------------------------------------------- +* +* File: ft1000_chdev.c +* +* Description: Custom character device dispatch routines. +* +* History: +* 8/29/02 Whc Ported to Linux. +* 6/05/06 Whc Porting to Linux 2.6.9 +* +*--------------------------------------------------------------------------- +*/ #include #include #include @@ -38,25 +40,24 @@ static int ft1000_flarion_cnt = 0; -static int ft1000_open (struct inode *inode, struct file *file); +static int ft1000_open(struct inode *inode, struct file *file); static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait); static long ft1000_ioctl(struct file *file, unsigned int command, unsigned long argument); -static int ft1000_release (struct inode *inode, struct file *file); +static int ft1000_release(struct inode *inode, struct file *file); -// List to free receive command buffer pool +/* List to free receive command buffer pool */ struct list_head freercvpool; -// lock to arbitrate free buffer list for receive command data +/* lock to arbitrate free buffer list for receive command data */ spinlock_t free_buff_lock; int numofmsgbuf = 0; -// -// Table of entry-point routines for char device -// -static const struct file_operations ft1000fops = -{ +/* +* Table of entry-point routines for char device +*/ +static const struct file_operations ft1000fops = { .unlocked_ioctl = ft1000_ioctl, .poll = ft1000_poll_dev, .open = ft1000_open, @@ -64,34 +65,35 @@ static const struct file_operations ft1000fops = .llseek = no_llseek, }; -//--------------------------------------------------------------------------- -// Function: ft1000_get_buffer -// -// Parameters: -// -// Returns: -// -// Description: -// -// Notes: -// -//--------------------------------------------------------------------------- +/* +--------------------------------------------------------------------------- +* Function: ft1000_get_buffer +* +* Parameters: +* +* Returns: +* +* Description: +* +* Notes: +* +*--------------------------------------------------------------------------- +*/ struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist) { unsigned long flags; struct dpram_blk *ptr; spin_lock_irqsave(&free_buff_lock, flags); - // Check if buffer is available - if ( list_empty(bufflist) ) { + /* Check if buffer is available */ + if (list_empty(bufflist)) { DEBUG("ft1000_get_buffer: No more buffer - %d\n", numofmsgbuf); ptr = NULL; - } - else { + } else { numofmsgbuf--; ptr = list_entry(bufflist->next, struct dpram_blk, list); list_del(&ptr->list); - //DEBUG("ft1000_get_buffer: number of free msg buffers = %d\n", numofmsgbuf); + /* DEBUG("ft1000_get_buffer: number of free msg buffers = %d\n", numofmsgbuf); */ } spin_unlock_irqrestore(&free_buff_lock, flags); @@ -101,42 +103,46 @@ struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist) -//--------------------------------------------------------------------------- -// Function: ft1000_free_buffer -// -// Parameters: -// -// Returns: -// -// Description: -// -// Notes: -// -//--------------------------------------------------------------------------- +/* +*--------------------------------------------------------------------------- +* Function: ft1000_free_buffer +* +* Parameters: +* +* Returns: +* +* Description: +* +* Notes: +* +*--------------------------------------------------------------------------- +*/ void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist) { unsigned long flags; spin_lock_irqsave(&free_buff_lock, flags); - // Put memory back to list + /* Put memory back to list */ list_add_tail(&pdpram_blk->list, plist); numofmsgbuf++; - //DEBUG("ft1000_free_buffer: number of free msg buffers = %d\n", numofmsgbuf); + /*DEBUG("ft1000_free_buffer: number of free msg buffers = %d\n", numofmsgbuf); */ spin_unlock_irqrestore(&free_buff_lock, flags); } -//--------------------------------------------------------------------------- -// Function: ft1000_CreateDevice -// -// Parameters: dev - pointer to adapter object -// -// Returns: 0 if successful -// -// Description: Creates a private char device. -// -// Notes: Only called by init_module(). -// -//--------------------------------------------------------------------------- +/* +*--------------------------------------------------------------------------- +* Function: ft1000_CreateDevice +* +* Parameters: dev - pointer to adapter object +* +* Returns: 0 if successful +* +* Description: Creates a private char device. +* +* Notes: Only called by init_module(). +* +*--------------------------------------------------------------------------- +*/ int ft1000_create_dev(struct ft1000_usb *dev) { int result; @@ -144,20 +150,19 @@ int ft1000_create_dev(struct ft1000_usb *dev) struct dentry *dir, *file; struct ft1000_debug_dirs *tmp; - // make a new device name + /* make a new device name */ sprintf(dev->DeviceName, "%s%d", "FT1000_", dev->CardNumber); DEBUG("%s: number of instance = %d\n", __func__, ft1000_flarion_cnt); DEBUG("DeviceCreated = %x\n", dev->DeviceCreated); - if (dev->DeviceCreated) - { + if (dev->DeviceCreated) { DEBUG("%s: \"%s\" already registered\n", __func__, dev->DeviceName); return -EIO; } - // register the device + /* register the device */ DEBUG("%s: \"%s\" debugfs device registration\n", __func__, dev->DeviceName); tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL); @@ -186,7 +191,7 @@ int ft1000_create_dev(struct ft1000_usb *dev) DEBUG("%s: registered debugfs directory \"%s\"\n", __func__, dev->DeviceName); - // initialize application information + /* initialize application information */ dev->appcnt = 0; for (i=0; iapp_info[i].nTxMsg = 0; @@ -198,7 +203,7 @@ int ft1000_create_dev(struct ft1000_usb *dev) dev->app_info[i].DspBCMsgFlag = 0; dev->app_info[i].NumOfMsg = 0; init_waitqueue_head(&dev->app_info[i].wait_dpram_msg); - INIT_LIST_HEAD (&dev->app_info[i].app_sqlist); + INIT_LIST_HEAD(&dev->app_info[i].app_sqlist); } dev->DeviceCreated = TRUE; @@ -214,16 +219,18 @@ fail: return result; } -//--------------------------------------------------------------------------- -// Function: ft1000_DestroyDeviceDEBUG -// -// Parameters: dev - pointer to adapter object -// -// Description: Destroys a private char device. -// -// Notes: Only called by cleanup_module(). -// -//--------------------------------------------------------------------------- +/* +*--------------------------------------------------------------------------- +* Function: ft1000_DestroyDeviceDEBUG +* +* Parameters: dev - pointer to adapter object +* +* Description: Destroys a private char device. +* +* Notes: Only called by cleanup_module(). +* +*--------------------------------------------------------------------------- +*/ void ft1000_destroy_dev(struct net_device *netdev) { struct ft1000_info *info = netdev_priv(netdev); @@ -238,8 +245,7 @@ void ft1000_destroy_dev(struct net_device *netdev) - if (dev->DeviceCreated) - { + if (dev->DeviceCreated) { ft1000_flarion_cnt--; list_for_each_safe(pos, q, &dev->nodes.list) { dir = list_entry(pos, struct ft1000_debug_dirs, list); @@ -253,7 +259,7 @@ void ft1000_destroy_dev(struct net_device *netdev) DEBUG("%s: unregistered device \"%s\"\n", __func__, dev->DeviceName); - // Make sure we free any memory reserve for slow Queue + /* Make sure we free any memory reserve for slow Queue */ for (i=0; iapp_info[i].app_sqlist) == 0) { pdpram_blk = list_entry(dev->app_info[i].app_sqlist.next, struct dpram_blk, list); @@ -264,7 +270,7 @@ void ft1000_destroy_dev(struct net_device *netdev) wake_up_interruptible(&dev->app_info[i].wait_dpram_msg); } - // Remove buffer allocated for receive command data + /* Remove buffer allocated for receive command data */ if (ft1000_flarion_cnt == 0) { while (list_empty(&freercvpool) == 0) { ptr = list_entry(freercvpool.next, struct dpram_blk, list); @@ -279,17 +285,19 @@ void ft1000_destroy_dev(struct net_device *netdev) } -//--------------------------------------------------------------------------- -// Function: ft1000_open -// -// Parameters: -// -// Description: -// -// Notes: -// -//--------------------------------------------------------------------------- -static int ft1000_open (struct inode *inode, struct file *file) +/* +*--------------------------------------------------------------------------- +* Function: ft1000_open +* +* Parameters: +* +* Description: +* +* Notes: +* +*--------------------------------------------------------------------------- +*/ +static int ft1000_open(struct inode *inode, struct file *file) { struct ft1000_info *info; struct ft1000_usb *dev = (struct ft1000_usb *)inode->i_private; @@ -301,22 +309,22 @@ static int ft1000_open (struct inode *inode, struct file *file) info = file->private_data = netdev_priv(dev->net); - DEBUG("f_owner = %p number of application = %d\n", (&file->f_owner), dev->appcnt ); + DEBUG("f_owner = %p number of application = %d\n", (&file->f_owner), dev->appcnt); - // Check if maximum number of application exceeded + /* Check if maximum number of application exceeded */ if (dev->appcnt > MAX_NUM_APP) { DEBUG("Maximum number of application exceeded\n"); return -EACCES; } - // Search for available application info block + /* Search for available application info block */ for (i=0; iapp_info[i].fileobject == NULL) ) { + if ((dev->app_info[i].fileobject == NULL)) { break; } } - // Fail due to lack of application info block + /* Fail due to lack of application info block */ if (i == MAX_NUM_APP) { DEBUG("Could not find an application info block\n"); return -EACCES; @@ -334,16 +342,18 @@ static int ft1000_open (struct inode *inode, struct file *file) } -//--------------------------------------------------------------------------- -// Function: ft1000_poll_dev -// -// Parameters: -// -// Description: -// -// Notes: -// -//--------------------------------------------------------------------------- +/* +*--------------------------------------------------------------------------- +* Function: ft1000_poll_dev +* +* Parameters: +* +* Description: +* +* Notes: +* +*--------------------------------------------------------------------------- +*/ static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait) { @@ -352,24 +362,24 @@ static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait) struct ft1000_usb *dev = info->priv; int i; - //DEBUG("ft1000_poll_dev called\n"); + /* DEBUG("ft1000_poll_dev called\n"); */ if (ft1000_flarion_cnt == 0) { DEBUG("FT1000:ft1000_poll_dev called when ft1000_flarion_cnt is zero\n"); return (-EBADF); } - // Search for matching file object + /* Search for matching file object */ for (i=0; iapp_info[i].fileobject == &file->f_owner) { - //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", dev->app_info[i].app_id); + if (dev->app_info[i].fileobject == &file->f_owner) { + /* DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", dev->app_info[i].app_id); */ break; } } - // Could not find application info block + /* Could not find application info block */ if (i == MAX_NUM_APP) { DEBUG("FT1000:ft1000_ioctl:Could not find application info block\n"); - return ( -EACCES ); + return (-EACCES); } if (list_empty(&dev->app_info[i].app_sqlist) == 0) { @@ -377,23 +387,25 @@ static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait) return(POLLIN | POLLRDNORM | POLLPRI); } - poll_wait (file, &dev->app_info[i].wait_dpram_msg, wait); - //DEBUG("FT1000:ft1000_poll_dev:Polling for data from DSP\n"); + poll_wait(file, &dev->app_info[i].wait_dpram_msg, wait); + /* DEBUG("FT1000:ft1000_poll_dev:Polling for data from DSP\n"); */ return (0); } -//--------------------------------------------------------------------------- -// Function: ft1000_ioctl -// -// Parameters: -// -// Description: -// -// Notes: -// -//--------------------------------------------------------------------------- -static long ft1000_ioctl (struct file *file, unsigned int command, +/* +*--------------------------------------------------------------------------- +* Function: ft1000_ioctl +* +* Parameters: +* +* Description: +* +* Notes: +* +*--------------------------------------------------------------------------- +*/ +static long ft1000_ioctl(struct file *file, unsigned int command, unsigned long argument) { void __user *argp = (void __user *)argument; @@ -417,21 +429,21 @@ static long ft1000_ioctl (struct file *file, unsigned int command, unsigned short ledStat=0; unsigned short conStat=0; - //DEBUG("ft1000_ioctl called\n"); + /* DEBUG("ft1000_ioctl called\n"); */ if (ft1000_flarion_cnt == 0) { DEBUG("FT1000:ft1000_ioctl called when ft1000_flarion_cnt is zero\n"); return (-EBADF); } - //DEBUG("FT1000:ft1000_ioctl:command = 0x%x argument = 0x%8x\n", command, (u32)argument); + /* DEBUG("FT1000:ft1000_ioctl:command = 0x%x argument = 0x%8x\n", command, (u32)argument); */ info = file->private_data; ft1000dev = info->priv; cmd = _IOC_NR(command); - //DEBUG("FT1000:ft1000_ioctl:cmd = 0x%x\n", cmd); + /* DEBUG("FT1000:ft1000_ioctl:cmd = 0x%x\n", cmd); */ - // process the command + /* process the command */ switch (cmd) { case IOCTL_REGISTER_CMD: DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_REGISTER called\n"); @@ -441,7 +453,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command, break; } if (tempword == DSPBCMSGID) { - // Search for matching file object + /* Search for matching file object */ for (i=0; iapp_info[i].fileobject == &file->f_owner) { ft1000dev->app_info[i].DspBCMsgFlag = 1; @@ -457,7 +469,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command, get_ver_data.drv_ver = FT1000_DRV_VER; - if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data)) ) { + if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data))) { DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n"); result = -EFAULT; break; @@ -467,20 +479,20 @@ static long ft1000_ioctl (struct file *file, unsigned int command, break; case IOCTL_CONNECT: - // Connect Message + /* Connect Message */ DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_CONNECT\n"); ConnectionMsg[79] = 0xfc; card_send_command(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c); break; case IOCTL_DISCONNECT: - // Disconnect Message + /* Disconnect Message */ DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_DISCONNECT\n"); ConnectionMsg[79] = 0xfd; card_send_command(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c); break; case IOCTL_GET_DSP_STAT_CMD: - //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DSP_STAT called\n"); + /* DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DSP_STAT called\n"); */ memset(&get_stat_data, 0, sizeof(get_stat_data)); memcpy(get_stat_data.DspVer, info->DspVer, DSPVERSZ); memcpy(get_stat_data.HwSerNum, info->HwSerNum, HWSERNUMSZ); @@ -494,8 +506,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command, ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE, (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX); get_stat_data.ConStat = ntohs(conStat); DEBUG("FT1000:ft1000_ioctl: ConStat = 0x%x\n", get_stat_data.ConStat); - } - else { + } else { get_stat_data.ConStat = 0x0f; } @@ -504,10 +515,10 @@ static long ft1000_ioctl (struct file *file, unsigned int command, get_stat_data.nRxPkts = info->stats.rx_packets; get_stat_data.nTxBytes = info->stats.tx_bytes; get_stat_data.nRxBytes = info->stats.rx_bytes; - do_gettimeofday ( &tv ); + do_gettimeofday(&tv); get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm); DEBUG("Connection Time = %d\n", (int)get_stat_data.ConTm); - if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data)) ) { + if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data))) { DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n"); result = -EFAULT; break; @@ -517,7 +528,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command, case IOCTL_SET_DPRAM_CMD: { IOCTL_DPRAM_BLK *dpram_data = NULL; - //IOCTL_DPRAM_COMMAND dpram_command; + /* IOCTL_DPRAM_COMMAND dpram_command; */ u16 qtype; u16 msgsz; struct pseudo_hdr *ppseudo_hdr; @@ -526,7 +537,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command, u16 app_index; u16 status; - //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_SET_DPRAM called\n"); + /* DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_SET_DPRAM called\n");*/ if (ft1000_flarion_cnt == 0) { @@ -545,12 +556,12 @@ static long ft1000_ioctl (struct file *file, unsigned int command, if (info->CardReady) { - //DEBUG("FT1000:ft1000_ioctl: try to SET_DPRAM \n"); + /* DEBUG("FT1000:ft1000_ioctl: try to SET_DPRAM \n"); */ - // Get the length field to see how many bytes to copy + /* Get the length field to see how many bytes to copy */ result = get_user(msgsz, (__u16 __user *)argp); - msgsz = ntohs (msgsz); - //DEBUG("FT1000:ft1000_ioctl: length of message = %d\n", msgsz); + msgsz = ntohs(msgsz); + /* DEBUG("FT1000:ft1000_ioctl: length of message = %d\n", msgsz); */ if (msgsz > MAX_CMD_SQSIZE) { DEBUG("FT1000:ft1000_ioctl: bad message length = %d\n", msgsz); @@ -563,12 +574,11 @@ static long ft1000_ioctl (struct file *file, unsigned int command, if (!dpram_data) break; - if ( copy_from_user(dpram_data, argp, msgsz+2) ) { + if (copy_from_user(dpram_data, argp, msgsz+2)) { DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n"); result = -EFAULT; - } - else { - // Check if this message came from a registered application + } else { + /* Check if this message came from a registered application */ for (i=0; iapp_info[i].fileobject == &file->f_owner) { break; @@ -582,28 +592,27 @@ static long ft1000_ioctl (struct file *file, unsigned int command, } app_index = i; - // Check message qtype type which is the lower byte within qos_class + /* Check message qtype type which is the lower byte within qos_class */ qtype = ntohs(dpram_data->pseudohdr.qos_class) & 0xff; - //DEBUG("FT1000_ft1000_ioctl: qtype = %d\n", qtype); + /* DEBUG("FT1000_ft1000_ioctl: qtype = %d\n", qtype); */ if (qtype) { - } - else { - // Put message into Slow Queue - // Only put a message into the DPRAM if msg doorbell is available + } else { + /* Put message into Slow Queue */ + /* Only put a message into the DPRAM if msg doorbell is available */ status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); - //DEBUG("FT1000_ft1000_ioctl: READ REGISTER tempword=%x\n", tempword); + /* DEBUG("FT1000_ft1000_ioctl: READ REGISTER tempword=%x\n", tempword); */ if (tempword & FT1000_DB_DPRAM_TX) { - // Suspend for 2ms and try again due to DSP doorbell busy + /* Suspend for 2ms and try again due to DSP doorbell busy */ mdelay(2); status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); if (tempword & FT1000_DB_DPRAM_TX) { - // Suspend for 1ms and try again due to DSP doorbell busy + /* Suspend for 1ms and try again due to DSP doorbell busy */ mdelay(1); status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); if (tempword & FT1000_DB_DPRAM_TX) { status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); if (tempword & FT1000_DB_DPRAM_TX) { - // Suspend for 3ms and try again due to DSP doorbell busy + /* Suspend for 3ms and try again due to DSP doorbell busy */ mdelay(3); status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); if (tempword & FT1000_DB_DPRAM_TX) { @@ -617,11 +626,11 @@ static long ft1000_ioctl (struct file *file, unsigned int command, } } - //DEBUG("FT1000_ft1000_ioctl: finished reading register\n"); + /*DEBUG("FT1000_ft1000_ioctl: finished reading register\n"); */ - // Make sure we are within the limits of the slow queue memory limitation - if ( (msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ) ) { - // Need to put sequence number plus new checksum for message + /* Make sure we are within the limits of the slow queue memory limitation */ + if ((msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ)) { + /* Need to put sequence number plus new checksum for message */ pmsg = (u16 *)&dpram_data->pseudohdr; ppseudo_hdr = (struct pseudo_hdr *)pmsg; total_len = msgsz+2; @@ -629,15 +638,15 @@ static long ft1000_ioctl (struct file *file, unsigned int command, total_len++; } - // Insert slow queue sequence number + /* Insert slow queue sequence number */ ppseudo_hdr->seq_num = info->squeseqnum++; ppseudo_hdr->portsrc = ft1000dev->app_info[app_index].app_id; - // Calculate new checksum + /* Calculate new checksum */ ppseudo_hdr->checksum = *pmsg++; - //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); + /* DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); */ for (i=1; i<7; i++) { ppseudo_hdr->checksum ^= *pmsg++; - //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); + /* DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); */ } pmsg++; ppseudo_hdr = (struct pseudo_hdr *)pmsg; @@ -645,14 +654,12 @@ static long ft1000_ioctl (struct file *file, unsigned int command, ft1000dev->app_info[app_index].nTxMsg++; - } - else { + } else { result = -EINVAL; } } } - } - else { + } else { DEBUG("FT1000:ft1000_ioctl: Card not ready take messages\n"); result = -EACCES; } @@ -666,21 +673,21 @@ static long ft1000_ioctl (struct file *file, unsigned int command, IOCTL_DPRAM_BLK __user *pioctl_dpram; int msglen; - //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DPRAM called\n"); + /* DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DPRAM called\n"); */ if (ft1000_flarion_cnt == 0) { return (-EBADF); } - // Search for matching file object + /* Search for matching file object */ for (i=0; iapp_info[i].fileobject == &file->f_owner) { - //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); + /*DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); */ break; } } - // Could not find application info block + /* Could not find application info block */ if (i == MAX_NUM_APP) { DEBUG("FT1000:ft1000_ioctl:Could not find application info block\n"); result = -EBADF; @@ -690,30 +697,29 @@ static long ft1000_ioctl (struct file *file, unsigned int command, result = 0; pioctl_dpram = argp; if (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) { - //DEBUG("FT1000:ft1000_ioctl:Message detected in slow queue\n"); + /* DEBUG("FT1000:ft1000_ioctl:Message detected in slow queue\n"); */ spin_lock_irqsave(&free_buff_lock, flags); pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next, struct dpram_blk, list); list_del(&pdpram_blk->list); ft1000dev->app_info[i].NumOfMsg--; - //DEBUG("FT1000:ft1000_ioctl:NumOfMsg for app %d = %d\n", i, ft1000dev->app_info[i].NumOfMsg); + /* DEBUG("FT1000:ft1000_ioctl:NumOfMsg for app %d = %d\n", i, ft1000dev->app_info[i].NumOfMsg); */ spin_unlock_irqrestore(&free_buff_lock, flags); msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ; result = get_user(msglen, &pioctl_dpram->total_len); if (result) break; msglen = htons(msglen); - //DEBUG("FT1000:ft1000_ioctl:msg length = %x\n", msglen); - if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen)) - { + /* DEBUG("FT1000:ft1000_ioctl:msg length = %x\n", msglen); */ + if (copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen)) { DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n"); - result = -EFAULT; - break; + result = -EFAULT; + break; } ft1000_free_buffer(pdpram_blk, &freercvpool); result = msglen; } - //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DPRAM no message\n"); + /* DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DPRAM no message\n"); */ } break; @@ -726,17 +732,19 @@ static long ft1000_ioctl (struct file *file, unsigned int command, return result; } -//--------------------------------------------------------------------------- -// Function: ft1000_release -// -// Parameters: -// -// Description: -// -// Notes: -// -//--------------------------------------------------------------------------- -static int ft1000_release (struct inode *inode, struct file *file) +/* +*--------------------------------------------------------------------------- +* Function: ft1000_release +* +* Parameters: +* +* Description: +* +* Notes: +* +*--------------------------------------------------------------------------- +*/ +static int ft1000_release(struct inode *inode, struct file *file) { struct ft1000_info *info; struct net_device *dev; @@ -755,10 +763,10 @@ static int ft1000_release (struct inode *inode, struct file *file) return (-EBADF); } - // Search for matching file object + /* Search for matching file object */ for (i=0; iapp_info[i].fileobject == &file->f_owner) { - //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); + if (ft1000dev->app_info[i].fileobject == &file->f_owner) { + /* DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); */ break; } } @@ -773,11 +781,10 @@ static int ft1000_release (struct inode *inode, struct file *file) ft1000_free_buffer(pdpram_blk, &freercvpool); } - // initialize application information + /* initialize application information */ ft1000dev->appcnt--; DEBUG("ft1000_chdev:%s:appcnt = %d\n", __FUNCTION__, ft1000dev->appcnt); ft1000dev->app_info[i].fileobject = NULL; return 0; } - diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h b/drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h index 3f4207fd1597..24b8d77a132c 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h @@ -1,91 +1,89 @@ -//--------------------------------------------------------------------------- -// FT1000 driver for Flarion Flash OFDM NIC Device -// -// Copyright (C) 2002 Flarion Technologies, All rights reserved. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 2 of the License, or (at your option) any -// later version. This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -// more details. You should have received a copy of the GNU General Public -// License along with this program; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - -// Suite 330, Boston, MA 02111-1307, USA. -//--------------------------------------------------------------------------- -// -// File: ft1000_ioctl.h -// -// Description: Common structures and defines relating to IOCTL -// -// History: -// 11/5/02 Whc Created. -// -//---------------------------------------------------------------------------//--------------------------------------------------------------------------- +/* +*--------------------------------------------------------------------------- +* FT1000 driver for Flarion Flash OFDM NIC Device +* +* Copyright (C) 2002 Flarion Technologies, All rights reserved. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) any +* later version. This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - +* Suite 330, Boston, MA 02111-1307, USA. +*--------------------------------------------------------------------------- +* +* File: ft1000_ioctl.h +* +* Description: Common structures and defines relating to IOCTL +* +* History: +* 11/5/02 Whc Created. +* +*---------------------------------------------------------------------------//--------------------------------------------------------------------------- +*/ #ifndef _FT1000IOCTLH_ #define _FT1000IOCTLH_ -typedef struct _IOCTL_GET_VER -{ +typedef struct _IOCTL_GET_VER { unsigned long drv_ver; } __attribute__ ((packed)) IOCTL_GET_VER, *PIOCTL_GET_VER; -//Data structure for Dsp statistics -typedef struct _IOCTL_GET_DSP_STAT -{ - unsigned char DspVer[DSPVERSZ]; // DSP version number - unsigned char HwSerNum[HWSERNUMSZ]; // Hardware Serial Number - unsigned char Sku[SKUSZ]; // SKU - unsigned char eui64[EUISZ]; // EUI64 - unsigned short ConStat; // Connection Status - // Bits 0-3 = Connection Status Field - // 0000=Idle (Disconnect) - // 0001=Searching - // 0010=Active (Connected) - // 0011=Waiting for L2 down - // 0100=Sleep - unsigned short LedStat; // Led Status - // Bits 0-3 = Signal Strength Field - // 0000 = -105dBm to -92dBm - // 0001 = -92dBm to -85dBm - // 0011 = -85dBm to -75dBm - // 0111 = -75dBm to -50dBm - // 1111 = -50dBm to 0dBm - // Bits 4-7 = Reserved - // Bits 8-11 = SNR Field - // 0000 = <2dB - // 0001 = 2dB to 8dB - // 0011 = 8dB to 15dB - // 0111 = 15dB to 22dB - // 1111 = >22dB - // Bits 12-15 = Reserved - unsigned long nTxPkts; // Number of packets transmitted from host to dsp - unsigned long nRxPkts; // Number of packets received from dsp to host - unsigned long nTxBytes; // Number of bytes transmitted from host to dsp - unsigned long nRxBytes; // Number of bytes received from dsp to host - unsigned long ConTm; // Current session connection time in seconds - unsigned char CalVer[CALVERSZ]; // Proprietary Calibration Version - unsigned char CalDate[CALDATESZ]; // Proprietary Calibration Date +/* Data structure for Dsp statistics */ +typedef struct _IOCTL_GET_DSP_STAT { + unsigned char DspVer[DSPVERSZ]; /* DSP version number */ + unsigned char HwSerNum[HWSERNUMSZ]; /* Hardware Serial Number */ + unsigned char Sku[SKUSZ]; /* SKU */ + unsigned char eui64[EUISZ]; /* EUI64 */ + unsigned short ConStat; /* Connection Status */ + /* Bits 0-3 = Connection Status Field */ + /* 0000=Idle (Disconnect) */ + /* 0001=Searching */ + /* 0010=Active (Connected) */ + /* 0011=Waiting for L2 down */ + /* 0100=Sleep */ + unsigned short LedStat; /* Led Status */ + /* Bits 0-3 = Signal Strength Field */ + /* 0000 = -105dBm to -92dBm */ + /* 0001 = -92dBm to -85dBm */ + /* 0011 = -85dBm to -75dBm */ + /* 0111 = -75dBm to -50dBm */ + /* 1111 = -50dBm to 0dBm */ + /* Bits 4-7 = Reserved */ + /* Bits 8-11 = SNR Field */ + /* 0000 = <2dB */ + /* 0001 = 2dB to 8dB */ + /* 0011 = 8dB to 15dB */ + /* 0111 = 15dB to 22dB */ + /* 1111 = >22dB */ + /* Bits 12-15 = Reserved */ + unsigned long nTxPkts; /* Number of packets transmitted from host to dsp */ + unsigned long nRxPkts; /* Number of packets received from dsp to host */ + unsigned long nTxBytes; /* Number of bytes transmitted from host to dsp */ + unsigned long nRxBytes; /* Number of bytes received from dsp to host */ + unsigned long ConTm; /* Current session connection time in seconds */ + unsigned char CalVer[CALVERSZ]; /* Proprietary Calibration Version */ + unsigned char CalDate[CALDATESZ]; /* Proprietary Calibration Date */ } __attribute__ ((packed)) IOCTL_GET_DSP_STAT, *PIOCTL_GET_DSP_STAT; -//Data structure for Dual Ported RAM messaging between Host and Dsp -typedef struct _IOCTL_DPRAM_BLK -{ +/* Data structure for Dual Ported RAM messaging between Host and Dsp */ +typedef struct _IOCTL_DPRAM_BLK { unsigned short total_len; struct pseudo_hdr pseudohdr; unsigned char buffer[1780]; } __attribute__ ((packed)) IOCTL_DPRAM_BLK, *PIOCTL_DPRAM_BLK; -typedef struct _IOCTL_DPRAM_COMMAND -{ +typedef struct _IOCTL_DPRAM_COMMAND { unsigned short extra; IOCTL_DPRAM_BLK dpram_blk; } __attribute__ ((packed)) IOCTL_DPRAM_COMMAND, *PIOCTL_DPRAM_COMMAND; -// -// Custom IOCTL command codes -// +/* +* Custom IOCTL command codes +*/ #define FT1000_MAGIC_CODE 'F' #define IOCTL_REGISTER_CMD 0 @@ -96,12 +94,12 @@ typedef struct _IOCTL_DPRAM_COMMAND #define IOCTL_CONNECT 10 #define IOCTL_DISCONNECT 11 -#define IOCTL_FT1000_GET_DSP_STAT _IOR (FT1000_MAGIC_CODE, IOCTL_GET_DSP_STAT_CMD, sizeof(IOCTL_GET_DSP_STAT) ) -#define IOCTL_FT1000_GET_VER _IOR (FT1000_MAGIC_CODE, IOCTL_GET_VER_CMD, sizeof(IOCTL_GET_VER) ) -#define IOCTL_FT1000_CONNECT _IOW (FT1000_MAGIC_CODE, IOCTL_CONNECT, 0 ) -#define IOCTL_FT1000_DISCONNECT _IOW (FT1000_MAGIC_CODE, IOCTL_DISCONNECT, 0 ) -#define IOCTL_FT1000_SET_DPRAM _IOW (FT1000_MAGIC_CODE, IOCTL_SET_DPRAM_CMD, sizeof(IOCTL_DPRAM_BLK) ) -#define IOCTL_FT1000_GET_DPRAM _IOR (FT1000_MAGIC_CODE, IOCTL_GET_DPRAM_CMD, sizeof(IOCTL_DPRAM_BLK) ) -#define IOCTL_FT1000_REGISTER _IOW (FT1000_MAGIC_CODE, IOCTL_REGISTER_CMD, sizeof(unsigned short *) ) -#endif // _FT1000IOCTLH_ +#define IOCTL_FT1000_GET_DSP_STAT _IOR(FT1000_MAGIC_CODE, IOCTL_GET_DSP_STAT_CMD, sizeof(IOCTL_GET_DSP_STAT) +#define IOCTL_FT1000_GET_VER _IOR(FT1000_MAGIC_CODE, IOCTL_GET_VER_CMD, sizeof(IOCTL_GET_VER) +#define IOCTL_FT1000_CONNECT _IOW(FT1000_MAGIC_CODE, IOCTL_CONNECT, 0 +#define IOCTL_FT1000_DISCONNECT _IOW(FT1000_MAGIC_CODE, IOCTL_DISCONNECT, 0 +#define IOCTL_FT1000_SET_DPRAM _IOW(FT1000_MAGIC_CODE, IOCTL_SET_DPRAM_CMD, sizeof(IOCTL_DPRAM_BLK) +#define IOCTL_FT1000_GET_DPRAM _IOR(FT1000_MAGIC_CODE, IOCTL_GET_DPRAM_CMD, sizeof(IOCTL_DPRAM_BLK) +#define IOCTL_FT1000_REGISTER _IOW(FT1000_MAGIC_CODE, IOCTL_REGISTER_CMD, sizeof(unsigned short *) +#endif /* _FT1000IOCTLH_ */ diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c index 614db55a8171..29a7cd23845d 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c @@ -79,8 +79,12 @@ static int ft1000_probe(struct usb_interface *interface, ft1000dev->dev = dev; ft1000dev->status = 0; ft1000dev->net = NULL; - ft1000dev->tx_urb = usb_alloc_urb(0, GFP_ATOMIC); - ft1000dev->rx_urb = usb_alloc_urb(0, GFP_ATOMIC); + ft1000dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL); + ft1000dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL); + if (!ft1000dev->tx_urb || !ft1000dev->rx_urb) { + ret = -ENOMEM; + goto err_fw; + } DEBUG("ft1000_probe is called\n"); numaltsetting = interface->num_altsetting; @@ -209,6 +213,8 @@ err_thread: err_load: kfree(pFileStart); err_fw: + usb_free_urb(ft1000dev->rx_urb); + usb_free_urb(ft1000dev->tx_urb); kfree(ft1000dev); return ret; } diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index e5818a1c2262..4e1cd5e9ea37 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -18,6 +18,8 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -101,13 +103,16 @@ struct fwtty_transaction { }; #define to_device(a, b) (a->b) -#define fwtty_err(p, s, v...) dev_err(to_device(p, device), s, ##v) -#define fwtty_info(p, s, v...) dev_info(to_device(p, device), s, ##v) -#define fwtty_notice(p, s, v...) dev_notice(to_device(p, device), s, ##v) -#define fwtty_dbg(p, s, v...) \ - dev_dbg(to_device(p, device), "%s: " s, __func__, ##v) -#define fwtty_err_ratelimited(p, s, v...) \ - dev_err_ratelimited(to_device(p, device), s, ##v) +#define fwtty_err(p, fmt, ...) \ + dev_err(to_device(p, device), fmt, ##__VA_ARGS__) +#define fwtty_info(p, fmt, ...) \ + dev_info(to_device(p, device), fmt, ##__VA_ARGS__) +#define fwtty_notice(p, fmt, ...) \ + dev_notice(to_device(p, device), fmt, ##__VA_ARGS__) +#define fwtty_dbg(p, fmt, ...) \ + dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__) +#define fwtty_err_ratelimited(p, fmt, ...) \ + dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__) #ifdef DEBUG static inline void debug_short_write(struct fwtty_port *port, int c, int n) @@ -118,7 +123,7 @@ static inline void debug_short_write(struct fwtty_port *port, int c, int n) spin_lock_bh(&port->lock); avail = dma_fifo_avail(&port->tx_fifo); spin_unlock_bh(&port->lock); - fwtty_dbg(port, "short write: avail:%d req:%d wrote:%d", + fwtty_dbg(port, "short write: avail:%d req:%d wrote:%d\n", avail, c, n); } } @@ -197,22 +202,22 @@ static void fwtty_log_tx_error(struct fwtty_port *port, int rcode) { switch (rcode) { case RCODE_SEND_ERROR: - fwtty_err_ratelimited(port, "card busy"); + fwtty_err_ratelimited(port, "card busy\n"); break; case RCODE_ADDRESS_ERROR: - fwtty_err_ratelimited(port, "bad unit addr or write length"); + fwtty_err_ratelimited(port, "bad unit addr or write length\n"); break; case RCODE_DATA_ERROR: - fwtty_err_ratelimited(port, "failed rx"); + fwtty_err_ratelimited(port, "failed rx\n"); break; case RCODE_NO_ACK: - fwtty_err_ratelimited(port, "missing ack"); + fwtty_err_ratelimited(port, "missing ack\n"); break; case RCODE_BUSY: - fwtty_err_ratelimited(port, "remote busy"); + fwtty_err_ratelimited(port, "remote busy\n"); break; default: - fwtty_err_ratelimited(port, "failed tx: %d", rcode); + fwtty_err_ratelimited(port, "failed tx: %d\n", rcode); } } @@ -287,7 +292,7 @@ static void __fwtty_restart_tx(struct fwtty_port *port) schedule_delayed_work(&port->drain, 0); avail = dma_fifo_avail(&port->tx_fifo); - fwtty_dbg(port, "fifo len: %d avail: %d", len, avail); + fwtty_dbg(port, "fifo len: %d avail: %d\n", len, avail); } static void fwtty_restart_tx(struct fwtty_port *port) @@ -323,7 +328,7 @@ static void fwtty_update_port_status(struct fwtty_port *port, unsigned status) if (delta & TIOCM_CTS) ++port->icount.cts; - fwtty_dbg(port, "status: %x delta: %x", status, delta); + fwtty_dbg(port, "status: %x delta: %x\n", status, delta); if (delta & TIOCM_CAR) { tty = tty_port_tty_get(&port->port); @@ -509,7 +514,7 @@ static void fwtty_emit_breaks(struct work_struct *work) n = (elapsed * port->cps) / HZ + 1; port->break_last = now; - fwtty_dbg(port, "sending %d brks", n); + fwtty_dbg(port, "sending %d brks\n", n); while (n) { t = min(n, 16); @@ -570,7 +575,7 @@ static int fwtty_buffer_rx(struct fwtty_port *port, unsigned char *d, size_t n) size_t size = (n + sizeof(struct buffered_rx) + 0xFF) & ~0xFF; if (port->buffered + n > HIGH_WATERMARK) { - fwtty_err_ratelimited(port, "overflowed rx buffer: buffered: %d new: %zu wtrmk: %d", + fwtty_err_ratelimited(port, "overflowed rx buffer: buffered: %d new: %zu wtrmk: %d\n", port->buffered, n, HIGH_WATERMARK); return 0; } @@ -599,7 +604,7 @@ static int fwtty_rx(struct fwtty_port *port, unsigned char *data, size_t len) unsigned lsr; int err = 0; - fwtty_dbg(port, "%d", n); + fwtty_dbg(port, "%d\n", n); profile_size_distrib(port->stats.reads, n); if (port->write_only) { @@ -689,7 +694,7 @@ static void fwtty_port_handler(struct fw_card *card, rcu_read_unlock(); if (!peer || peer != rcu_access_pointer(port->peer)) { rcode = RCODE_ADDRESS_ERROR; - fwtty_err_ratelimited(port, "ignoring unauthenticated data"); + fwtty_err_ratelimited(port, "ignoring unauthenticated data\n"); goto respond; } @@ -746,7 +751,7 @@ static void fwtty_tx_complete(struct fw_card *card, int rcode, struct fwtty_port *port = txn->port; int len; - fwtty_dbg(port, "rcode: %d", rcode); + fwtty_dbg(port, "rcode: %d\n", rcode); switch (rcode) { case RCODE_COMPLETE: @@ -809,7 +814,7 @@ static int fwtty_tx(struct fwtty_port *port, bool drain) n = dma_fifo_out_pend(&port->tx_fifo, &txn->dma_pended); spin_unlock_bh(&port->lock); - fwtty_dbg(port, "out: %u rem: %d", txn->dma_pended.len, n); + fwtty_dbg(port, "out: %u rem: %d\n", txn->dma_pended.len, n); if (n < 0) { kmem_cache_free(fwtty_txn_cache, txn); @@ -819,7 +824,8 @@ static int fwtty_tx(struct fwtty_port *port, bool drain) profile_size_distrib(port->stats.txns, 0); else { ++port->stats.fifo_errs; - fwtty_err_ratelimited(port, "fifo err: %d", n); + fwtty_err_ratelimited(port, "fifo err: %d\n", + n); } break; } @@ -877,7 +883,7 @@ static void fwtty_write_xchar(struct fwtty_port *port, char ch) ++port->stats.xchars; - fwtty_dbg(port, "%02x", ch); + fwtty_dbg(port, "%02x\n", ch); rcu_read_lock(); peer = rcu_dereference(port->peer); @@ -964,7 +970,7 @@ static void fwtty_port_dtr_rts(struct tty_port *tty_port, int on) { struct fwtty_port *port = to_port(tty_port, port); - fwtty_dbg(port, "on/off: %d", on); + fwtty_dbg(port, "on/off: %d\n", on); spin_lock_bh(&port->lock); /* Don't change carrier state if this is a console */ @@ -992,7 +998,7 @@ static int fwtty_port_carrier_raised(struct tty_port *tty_port) rc = (port->mstatus & TIOCM_CAR); - fwtty_dbg(port, "%d", rc); + fwtty_dbg(port, "%d\n", rc); return rc; } @@ -1177,7 +1183,7 @@ static int fwtty_write(struct tty_struct *tty, const unsigned char *buf, int c) struct fwtty_port *port = tty->driver_data; int n, len; - fwtty_dbg(port, "%d", c); + fwtty_dbg(port, "%d\n", c); profile_size_distrib(port->stats.writes, c); spin_lock_bh(&port->lock); @@ -1204,7 +1210,7 @@ static int fwtty_write_room(struct tty_struct *tty) n = dma_fifo_avail(&port->tx_fifo); spin_unlock_bh(&port->lock); - fwtty_dbg(port, "%d", n); + fwtty_dbg(port, "%d\n", n); return n; } @@ -1218,7 +1224,7 @@ static int fwtty_chars_in_buffer(struct tty_struct *tty) n = dma_fifo_level(&port->tx_fifo); spin_unlock_bh(&port->lock); - fwtty_dbg(port, "%d", n); + fwtty_dbg(port, "%d\n", n); return n; } @@ -1227,7 +1233,7 @@ static void fwtty_send_xchar(struct tty_struct *tty, char ch) { struct fwtty_port *port = tty->driver_data; - fwtty_dbg(port, "%02x", ch); + fwtty_dbg(port, "%02x\n", ch); fwtty_write_xchar(port, ch); } @@ -1254,7 +1260,7 @@ static void fwtty_unthrottle(struct tty_struct *tty) { struct fwtty_port *port = tty->driver_data; - fwtty_dbg(port, "CRTSCTS: %d", (C_CRTSCTS(tty) != 0)); + fwtty_dbg(port, "CRTSCTS: %d\n", (C_CRTSCTS(tty) != 0)); profile_fifo_avail(port, port->stats.unthrottle); @@ -1409,7 +1415,7 @@ static int fwtty_break_ctl(struct tty_struct *tty, int state) struct fwtty_port *port = tty->driver_data; long ret; - fwtty_dbg(port, "%d", state); + fwtty_dbg(port, "%d\n", state); if (state == -1) { set_bit(STOP_TX, &port->flags); @@ -1446,7 +1452,7 @@ static int fwtty_tiocmget(struct tty_struct *tty) tiocm = (port->mctrl & MCTRL_MASK) | (port->mstatus & ~MCTRL_MASK); spin_unlock_bh(&port->lock); - fwtty_dbg(port, "%x", tiocm); + fwtty_dbg(port, "%x\n", tiocm); return tiocm; } @@ -1455,7 +1461,7 @@ static int fwtty_tiocmset(struct tty_struct *tty, unsigned set, unsigned clear) { struct fwtty_port *port = tty->driver_data; - fwtty_dbg(port, "set: %x clear: %x", set, clear); + fwtty_dbg(port, "set: %x clear: %x\n", set, clear); /* TODO: simulate loopback if TIOCM_LOOP set */ @@ -1775,7 +1781,7 @@ static void fwserial_virt_plug_complete(struct fwtty_peer *peer, if (port->port.console && port->fwcon_ops->notify != NULL) (*port->fwcon_ops->notify)(FWCON_NOTIFY_ATTACH, port->con_data); - fwtty_info(&peer->unit, "peer (guid:%016llx) connected on %s", + fwtty_info(&peer->unit, "peer (guid:%016llx) connected on %s\n", (unsigned long long)peer->guid, dev_name(port->device)); } @@ -1797,7 +1803,7 @@ static inline int fwserial_send_mgmt_sync(struct fwtty_peer *peer, pkt, be16_to_cpu(pkt->hdr.len)); if (rcode == RCODE_BUSY || rcode == RCODE_SEND_ERROR || rcode == RCODE_GENERATION) { - fwtty_dbg(&peer->unit, "mgmt write error: %d", rcode); + fwtty_dbg(&peer->unit, "mgmt write error: %d\n", rcode); continue; } else break; @@ -1918,7 +1924,7 @@ static int fwserial_connect_peer(struct fwtty_peer *peer) port = fwserial_find_port(peer); if (!port) { - fwtty_err(&peer->unit, "avail ports in use"); + fwtty_err(&peer->unit, "avail ports in use\n"); err = -EBUSY; goto free_pkt; } @@ -2056,7 +2062,7 @@ static struct fwtty_peer *__fwserial_peer_by_node_id(struct fw_card *card, * has created its remote unit device before this driver has * been probed for any unit devices... */ - fwtty_err(card, "unknown card (guid %016llx)", + fwtty_err(card, "unknown card (guid %016llx)\n", (unsigned long long) card->guid); return NULL; } @@ -2084,8 +2090,8 @@ static void __dump_peer_list(struct fw_card *card) list_for_each_entry_rcu(peer, &serial->peer_list, list) { int g = peer->generation; smp_rmb(); - fwtty_dbg(card, "peer(%d:%x) guid: %016llx\n", g, - peer->node_id, (unsigned long long) peer->guid); + fwtty_dbg(card, "peer(%d:%x) guid: %016llx\n", + g, peer->node_id, (unsigned long long) peer->guid); } } #else @@ -2173,7 +2179,7 @@ static int fwserial_add_peer(struct fw_serial *serial, struct fw_unit *unit) peer->serial = serial; list_add_rcu(&peer->list, &serial->peer_list); - fwtty_info(&peer->unit, "peer added (guid:%016llx)", + fwtty_info(&peer->unit, "peer added (guid:%016llx)\n", (unsigned long long)peer->guid); /* identify the local unit & virt cable to loopback port */ @@ -2236,7 +2242,7 @@ static void fwserial_remove_peer(struct fwtty_peer *peer) list_del_rcu(&peer->list); - fwtty_info(&peer->unit, "peer removed (guid:%016llx)", + fwtty_info(&peer->unit, "peer removed (guid:%016llx)\n", (unsigned long long)peer->guid); spin_unlock_bh(&peer->lock); @@ -2324,7 +2330,7 @@ static int fwserial_create(struct fw_unit *unit) err = fwtty_ports_add(serial); if (err) { - fwtty_err(&unit, "no space in port table"); + fwtty_err(&unit, "no space in port table\n"); goto free_ports; } @@ -2335,7 +2341,8 @@ static int fwserial_create(struct fw_unit *unit) card->device); if (IS_ERR(tty_dev)) { err = PTR_ERR(tty_dev); - fwtty_err(&unit, "register tty device error (%d)", err); + fwtty_err(&unit, "register tty device error (%d)\n", + err); goto unregister_ttys; } @@ -2352,7 +2359,8 @@ static int fwserial_create(struct fw_unit *unit) card->device); if (IS_ERR(loop_dev)) { err = PTR_ERR(loop_dev); - fwtty_err(&unit, "create loop device failed (%d)", err); + fwtty_err(&unit, "create loop device failed (%d)\n", + err); goto unregister_ttys; } serial->ports[j]->device = loop_dev; @@ -2372,14 +2380,14 @@ static int fwserial_create(struct fw_unit *unit) list_add_rcu(&serial->list, &fwserial_list); - fwtty_notice(&unit, "TTY over FireWire on device %s (guid %016llx)", + fwtty_notice(&unit, "TTY over FireWire on device %s (guid %016llx)\n", dev_name(card->device), (unsigned long long) card->guid); err = fwserial_add_peer(serial, unit); if (!err) return 0; - fwtty_err(&unit, "unable to add peer unit device (%d)", err); + fwtty_err(&unit, "unable to add peer unit device (%d)\n", err); /* fall-through to error processing */ debugfs_remove_recursive(serial->debugfs); @@ -2621,7 +2629,7 @@ static void fwserial_handle_plug_req(struct work_struct *work) switch (peer->state) { case FWPS_NOT_ATTACHED: if (!port) { - fwtty_err(&peer->unit, "no more ports avail"); + fwtty_err(&peer->unit, "no more ports avail\n"); fill_plug_rsp_nack(pkt); } else { peer->port = port; @@ -2663,7 +2671,7 @@ static void fwserial_handle_plug_req(struct work_struct *work) fwtty_write_port_status(tmp); spin_lock_bh(&peer->lock); } else { - fwtty_err(&peer->unit, "PLUG_RSP error (%d)", rcode); + fwtty_err(&peer->unit, "PLUG_RSP error (%d)\n", rcode); port = peer_revert_state(peer); } } @@ -2715,7 +2723,8 @@ static void fwserial_handle_unplug_req(struct work_struct *work) spin_lock_bh(&peer->lock); if (peer->state == FWPS_UNPLUG_RESPONDING) { if (rcode != RCODE_COMPLETE) - fwtty_err(&peer->unit, "UNPLUG_RSP error (%d)", rcode); + fwtty_err(&peer->unit, "UNPLUG_RSP error (%d)\n", + rcode); port = peer_revert_state(peer); } cleanup: @@ -2750,19 +2759,19 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer, * already removed from the bus -- and the removal was * processed before we rec'd this transaction */ - fwtty_err(&peer->unit, "peer already removed"); + fwtty_err(&peer->unit, "peer already removed\n"); spin_unlock_bh(&peer->lock); return RCODE_ADDRESS_ERROR; } rcode = RCODE_COMPLETE; - fwtty_dbg(&peer->unit, "mgmt: hdr.code: %04hx", pkt->hdr.code); + fwtty_dbg(&peer->unit, "mgmt: hdr.code: %04hx\n", pkt->hdr.code); switch (be16_to_cpu(pkt->hdr.code) & FWSC_CODE_MASK) { case FWSC_VIRT_CABLE_PLUG: if (work_pending(&peer->work)) { - fwtty_err(&peer->unit, "plug req: busy"); + fwtty_err(&peer->unit, "plug req: busy\n"); rcode = RCODE_CONFLICT_ERROR; } else { @@ -2777,7 +2786,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer, rcode = RCODE_CONFLICT_ERROR; } else if (be16_to_cpu(pkt->hdr.code) & FWSC_RSP_NACK) { - fwtty_notice(&peer->unit, "NACK plug rsp"); + fwtty_notice(&peer->unit, "NACK plug rsp\n"); port = peer_revert_state(peer); } else { @@ -2793,7 +2802,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer, case FWSC_VIRT_CABLE_UNPLUG: if (work_pending(&peer->work)) { - fwtty_err(&peer->unit, "unplug req: busy"); + fwtty_err(&peer->unit, "unplug req: busy\n"); rcode = RCODE_CONFLICT_ERROR; } else { PREPARE_WORK(&peer->work, fwserial_handle_unplug_req); @@ -2806,14 +2815,14 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer, rcode = RCODE_CONFLICT_ERROR; else { if (be16_to_cpu(pkt->hdr.code) & FWSC_RSP_NACK) - fwtty_notice(&peer->unit, "NACK unplug?"); + fwtty_notice(&peer->unit, "NACK unplug?\n"); port = peer_revert_state(peer); reset = true; } break; default: - fwtty_err(&peer->unit, "unknown mgmt code %d", + fwtty_err(&peer->unit, "unknown mgmt code %d\n", be16_to_cpu(pkt->hdr.code)); rcode = RCODE_DATA_ERROR; } @@ -2847,7 +2856,7 @@ static void fwserial_mgmt_handler(struct fw_card *card, rcu_read_lock(); peer = __fwserial_peer_by_node_id(card, generation, source); if (!peer) { - fwtty_dbg(card, "peer(%d:%x) not found", generation, source); + fwtty_dbg(card, "peer(%d:%x) not found\n", generation, source); __dump_peer_list(card); rcode = RCODE_CONFLICT_ERROR; @@ -2897,7 +2906,7 @@ static int __init fwserial_init(void) err = tty_register_driver(fwtty_driver); if (err) { - driver_err("register tty driver failed (%d)", err); + pr_err("register tty driver failed (%d)\n", err); goto put_tty; } @@ -2922,7 +2931,7 @@ static int __init fwserial_init(void) err = tty_register_driver(fwloop_driver); if (err) { - driver_err("register loop driver failed (%d)", err); + pr_err("register loop driver failed (%d)\n", err); goto put_loop; } } @@ -2948,7 +2957,7 @@ static int __init fwserial_init(void) err = fw_core_add_address_handler(&fwserial_mgmt_addr_handler, &fwserial_mgmt_addr_region); if (err) { - driver_err("add management handler failed (%d)", err); + pr_err("add management handler failed (%d)\n", err); goto destroy_cache; } @@ -2956,13 +2965,13 @@ static int __init fwserial_init(void) FW_UNIT_ADDRESS(fwserial_mgmt_addr_handler.offset); err = fw_core_add_descriptor(&fwserial_unit_directory); if (err) { - driver_err("add unit descriptor failed (%d)", err); + pr_err("add unit descriptor failed (%d)\n", err); goto remove_handler; } err = driver_register(&fwserial_driver.driver); if (err) { - driver_err("register fwserial driver failed (%d)", err); + pr_err("register fwserial driver failed (%d)\n", err); goto remove_descriptor; } diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h index 514f57173259..24635014a2ac 100644 --- a/drivers/staging/fwserial/fwserial.h +++ b/drivers/staging/fwserial/fwserial.h @@ -356,8 +356,6 @@ static const char loop_dev_name[] = "fwloop"; extern struct tty_driver *fwtty_driver; -#define driver_err(s, v...) pr_err(KBUILD_MODNAME ": " s, ##v) - struct fwtty_port *fwtty_port_get(unsigned index); void fwtty_port_put(struct fwtty_port *port); diff --git a/drivers/staging/gdm72xx/Kconfig b/drivers/staging/gdm72xx/Kconfig index 69059138de4a..dd8a3913f6b9 100644 --- a/drivers/staging/gdm72xx/Kconfig +++ b/drivers/staging/gdm72xx/Kconfig @@ -4,7 +4,7 @@ menuconfig WIMAX_GDM72XX tristate "GCT GDM72xx WiMAX support" - depends on NET + depends on NET && (USB || MMC) help Support for the GCT GDM72xx WiMAX chip @@ -19,7 +19,7 @@ config WIMAX_GDM72XX_K_MODE default n config WIMAX_GDM72XX_WIMAX2 - bool "Enable WIMAX2 support" + bool "Enable WiMAX2 support" default n choice @@ -27,18 +27,18 @@ choice config WIMAX_GDM72XX_USB bool "USB interface" - depends on USB + depends on (USB = y || USB = WIMAX_GDM72XX) config WIMAX_GDM72XX_SDIO bool "SDIO interface" - depends on MMC + depends on (MMC = y || MMC = WIMAX_GDM72XX) endchoice if WIMAX_GDM72XX_USB config WIMAX_GDM72XX_USB_PM - bool "Enable power managerment support" + bool "Enable power management support" depends on PM_RUNTIME endif # WIMAX_GDM72XX_USB diff --git a/drivers/staging/gdm72xx/gdm_wimax.c b/drivers/staging/gdm72xx/gdm_wimax.c index 41efbeeb62f1..dd854975db7d 100644 --- a/drivers/staging/gdm72xx/gdm_wimax.c +++ b/drivers/staging/gdm72xx/gdm_wimax.c @@ -939,8 +939,7 @@ int register_wimax_device(struct phy_dev *phy_dev, struct device *pdev) struct net_device *dev; int ret; - dev = (struct net_device *)alloc_netdev(sizeof(*nic), - "wm%d", ether_setup); + dev = alloc_netdev(sizeof(*nic), "wm%d", ether_setup); if (dev == NULL) { pr_err("alloc_etherdev failed\n"); diff --git a/drivers/staging/goldfish/goldfish_audio.c b/drivers/staging/goldfish/goldfish_audio.c index d3bed21f4072..f96dcec740ae 100644 --- a/drivers/staging/goldfish/goldfish_audio.c +++ b/drivers/staging/goldfish/goldfish_audio.c @@ -1,4 +1,5 @@ -/* drivers/misc/goldfish_audio.c +/* + * drivers/misc/goldfish_audio.c * * Copyright (C) 2007 Google, Inc. * Copyright (C) 2012 Intel, Inc. @@ -47,10 +48,11 @@ struct goldfish_audio { int read_supported; /* true if we have audio input support */ }; -/* We will allocate two read buffers and two write buffers. - Having two read buffers facilitate stereo -> mono conversion. - Having two write buffers facilitate interleaved IO. -*/ +/* + * We will allocate two read buffers and two write buffers. + * Having two read buffers facilitate stereo -> mono conversion. + * Having two write buffers facilitate interleaved IO. + */ #define READ_BUFFER_SIZE 16384 #define WRITE_BUFFER_SIZE 16384 #define COMBINED_BUFFER_SIZE ((2 * READ_BUFFER_SIZE) + \ @@ -59,8 +61,10 @@ struct goldfish_audio { #define AUDIO_READ(data, addr) (readl(data->reg_base + addr)) #define AUDIO_WRITE(data, addr, x) (writel(x, data->reg_base + addr)) -/* temporary variable used between goldfish_audio_probe() and - goldfish_audio_open() */ +/* + * temporary variable used between goldfish_audio_probe() and + * goldfish_audio_open() + */ static struct goldfish_audio *audio_data; enum { @@ -161,8 +165,10 @@ static ssize_t goldfish_audio_write(struct file *fp, const char __user *buf, } spin_lock_irqsave(&data->lock, irq_flags); - /* clear the buffer empty flag, and signal the emulator - * to start writing the buffer */ + /* + * clear the buffer empty flag, and signal the emulator + * to start writing the buffer + */ if (kbuf == data->write_buffer1) { data->buffer_status &= ~AUDIO_INT_WRITE_BUFFER_1_EMPTY; AUDIO_WRITE(data, AUDIO_WRITE_BUFFER_1, copy); @@ -225,8 +231,10 @@ static irqreturn_t goldfish_audio_interrupt(int irq, void *dev_id) /* read buffer status flags */ status = AUDIO_READ(data, AUDIO_INT_STATUS); status &= AUDIO_INT_MASK; - /* if buffers are newly empty, wake up blocked - goldfish_audio_write() call */ + /* + * if buffers are newly empty, wake up blocked + * goldfish_audio_write() call + */ if (status) { data->buffer_status = status; wake_up(&data->wait); diff --git a/drivers/staging/goldfish/goldfish_nand.c b/drivers/staging/goldfish/goldfish_nand.c index ab1f01952b48..81e2ad4038fe 100644 --- a/drivers/staging/goldfish/goldfish_nand.c +++ b/drivers/staging/goldfish/goldfish_nand.c @@ -326,9 +326,10 @@ static int goldfish_nand_init_device(struct platform_device *pdev, (mtd->writesize + mtd->oobsize) * mtd->writesize; do_div(mtd->size, mtd->writesize + mtd->oobsize); mtd->size *= mtd->writesize; - dev_dbg(&pdev->dev, + dev_dbg(&pdev->dev, "goldfish nand dev%d: size %llx, page %d, extra %d, erase %d\n", - id, mtd->size, mtd->writesize, mtd->oobsize, mtd->erasesize); + id, mtd->size, mtd->writesize, + mtd->oobsize, mtd->erasesize); spin_unlock_irqrestore(&nand->lock, irq_flags); mtd->priv = nand; @@ -340,7 +341,7 @@ static int goldfish_nand_init_device(struct platform_device *pdev, result = goldfish_nand_cmd(mtd, NAND_CMD_GET_DEV_NAME, 0, name_len, name); if (result != name_len) { - dev_err(&pdev->dev, + dev_err(&pdev->dev, "goldfish_nand_init_device failed to get dev name %d != %d\n", result, name_len); return -ENODEV; @@ -391,7 +392,7 @@ static int goldfish_nand_probe(struct platform_device *pdev) version = readl(base + NAND_VERSION); if (version != NAND_VERSION_CURRENT) { - dev_err(&pdev->dev, + dev_err(&pdev->dev, "goldfish_nand_init: version mismatch, got %d, expected %d\n", version, NAND_VERSION_CURRENT); return -ENODEV; @@ -400,7 +401,7 @@ static int goldfish_nand_probe(struct platform_device *pdev) if (num_dev == 0) return -ENODEV; - nand = devm_kzalloc(&pdev->dev, sizeof(*nand) + + nand = devm_kzalloc(&pdev->dev, sizeof(*nand) + sizeof(struct mtd_info) * num_dev, GFP_KERNEL); if (nand == NULL) return -ENOMEM; diff --git a/drivers/staging/goldfish/goldfish_nand_reg.h b/drivers/staging/goldfish/goldfish_nand_reg.h index 956c6c304b6e..ddfda71ab27a 100644 --- a/drivers/staging/goldfish/goldfish_nand_reg.h +++ b/drivers/staging/goldfish/goldfish_nand_reg.h @@ -1,27 +1,30 @@ -/* drivers/mtd/devices/goldfish_nand_reg.h -** -** Copyright (C) 2007 Google, Inc. -** -** This software is licensed under the terms of the GNU General Public -** License version 2, as published by the Free Software Foundation, and -** may be copied, distributed, and modified under those terms. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -*/ +/* + * drivers/mtd/devices/goldfish_nand_reg.h + * + * Copyright (C) 2007 Google, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ #ifndef GOLDFISH_NAND_REG_H #define GOLDFISH_NAND_REG_H enum nand_cmd { - NAND_CMD_GET_DEV_NAME, /* Write device name for NAND_DEV to NAND_DATA (vaddr) */ + /* Write device name for NAND_DEV to NAND_DATA (vaddr) */ + NAND_CMD_GET_DEV_NAME, NAND_CMD_READ, NAND_CMD_WRITE, NAND_CMD_ERASE, - NAND_CMD_BLOCK_BAD_GET, /* NAND_RESULT is 1 if block is bad, 0 if it is not */ + /* NAND_RESULT is 1 if block is bad, 0 if it is not */ + NAND_CMD_BLOCK_BAD_GET, NAND_CMD_BLOCK_BAD_SET, NAND_CMD_READ_WITH_PARAMS, NAND_CMD_WRITE_WITH_PARAMS, diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index 504701940585..3283e2829536 100644 --- a/drivers/staging/iio/adc/ad7192.c +++ b/drivers/staging/iio/adc/ad7192.c @@ -326,7 +326,7 @@ static ssize_t ad7192_write_frequency(struct device *dev, unsigned long lval; int div, ret; - ret = strict_strtoul(buf, 10, &lval); + ret = kstrtoul(buf, 10, &lval); if (ret) return ret; if (lval == 0) diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index 2fd6ee3c1902..c19618bc37c4 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -632,7 +632,7 @@ static ssize_t ad7280_write_channel_config(struct device *dev, long val; int ret; - ret = strict_strtol(buf, 10, &val); + ret = kstrtol(buf, 10, &val); if (ret) return ret; diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c index d088c662d5cd..3fc79e582750 100644 --- a/drivers/staging/iio/adc/ad7291.c +++ b/drivers/staging/iio/adc/ad7291.c @@ -21,6 +21,8 @@ #include #include +#include "ad7291.h" + /* * Simplified handling * @@ -39,33 +41,9 @@ #define AD7291_VOLTAGE 0x01 #define AD7291_T_SENSE 0x02 #define AD7291_T_AVERAGE 0x03 -#define AD7291_CH0_DATA_HIGH 0x04 -#define AD7291_CH0_DATA_LOW 0x05 -#define AD7291_CH0_HYST 0x06 -#define AD7291_CH1_DATA_HIGH 0x07 -#define AD7291_CH1_DATA_LOW 0x08 -#define AD7291_CH1_HYST 0x09 -#define AD7291_CH2_DATA_HIGH 0x0A -#define AD7291_CH2_DATA_LOW 0x0B -#define AD7291_CH2_HYST 0x0C -#define AD7291_CH3_DATA_HIGH 0x0D -#define AD7291_CH3_DATA_LOW 0x0E -#define AD7291_CH3_HYST 0x0F -#define AD7291_CH4_DATA_HIGH 0x10 -#define AD7291_CH4_DATA_LOW 0x11 -#define AD7291_CH4_HYST 0x12 -#define AD7291_CH5_DATA_HIGH 0x13 -#define AD7291_CH5_DATA_LOW 0x14 -#define AD7291_CH5_HYST 0x15 -#define AD7291_CH6_DATA_HIGH 0x16 -#define AD7291_CH6_DATA_LOW 0x17 -#define AD7291_CH6_HYST 0x18 -#define AD7291_CH7_DATA_HIGH 0x19 -#define AD7291_CH7_DATA_LOW 0x1A -#define AD7291_CH7_HYST 0x2B -#define AD7291_T_SENSE_HIGH 0x1C -#define AD7291_T_SENSE_LOW 0x1D -#define AD7291_T_SENSE_HYST 0x1E +#define AD7291_DATA_HIGH(x) ((x) * 3 + 0x4) +#define AD7291_DATA_LOW(x) ((x) * 3 + 0x5) +#define AD7291_HYST(x) ((x) * 3 + 0x6) #define AD7291_VOLTAGE_ALERT_STATUS 0x1F #define AD7291_T_ALERT_STATUS 0x20 @@ -100,7 +78,6 @@ struct ad7291_chip_info { struct i2c_client *client; struct regulator *reg; - u16 int_vref_mv; u16 command; u16 c_mask; /* Active voltage channels for events */ struct mutex state_lock; @@ -111,45 +88,22 @@ static int ad7291_i2c_read(struct ad7291_chip_info *chip, u8 reg, u16 *data) struct i2c_client *client = chip->client; int ret = 0; - ret = i2c_smbus_read_word_data(client, reg); + ret = i2c_smbus_read_word_swapped(client, reg); if (ret < 0) { dev_err(&client->dev, "I2C read error\n"); return ret; } - *data = swab16((u16)ret); + *data = ret; return 0; } static int ad7291_i2c_write(struct ad7291_chip_info *chip, u8 reg, u16 data) { - return i2c_smbus_write_word_data(chip->client, reg, swab16(data)); + return i2c_smbus_write_word_swapped(chip->client, reg, data); } -static ssize_t ad7291_store_reset(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7291_chip_info *chip = iio_priv(indio_dev); - - return ad7291_i2c_write(chip, AD7291_COMMAND, - chip->command | AD7291_RESET); -} - -static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, ad7291_store_reset, 0); - -static struct attribute *ad7291_attributes[] = { - &iio_dev_attr_reset.dev_attr.attr, - NULL, -}; - -static const struct attribute_group ad7291_attribute_group = { - .attrs = ad7291_attributes, -}; - static irqreturn_t ad7291_event_handler(int irq, void *private) { struct iio_dev *indio_dev = private; @@ -255,31 +209,31 @@ static inline ssize_t ad7291_set_hyst(struct device *dev, static IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad7291_show_hyst, ad7291_set_hyst, - AD7291_T_SENSE_HYST); + AD7291_HYST(8)); static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, - ad7291_show_hyst, ad7291_set_hyst, AD7291_CH0_HYST); + ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(0)); static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, - ad7291_show_hyst, ad7291_set_hyst, AD7291_CH1_HYST); + ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(1)); static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, - ad7291_show_hyst, ad7291_set_hyst, AD7291_CH2_HYST); + ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(2)); static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, - ad7291_show_hyst, ad7291_set_hyst, AD7291_CH3_HYST); + ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(3)); static IIO_DEVICE_ATTR(in_voltage4_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, - ad7291_show_hyst, ad7291_set_hyst, AD7291_CH4_HYST); + ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(4)); static IIO_DEVICE_ATTR(in_voltage5_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, - ad7291_show_hyst, ad7291_set_hyst, AD7291_CH5_HYST); + ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(5)); static IIO_DEVICE_ATTR(in_voltage6_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, - ad7291_show_hyst, ad7291_set_hyst, AD7291_CH6_HYST); + ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(6)); static IIO_DEVICE_ATTR(in_voltage7_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, - ad7291_show_hyst, ad7291_set_hyst, AD7291_CH7_HYST); + ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(7)); static struct attribute *ad7291_event_attributes[] = { &iio_dev_attr_in_temp0_thresh_both_hyst_raw.dev_attr.attr, @@ -294,53 +248,45 @@ static struct attribute *ad7291_event_attributes[] = { NULL, }; -/* high / low */ -static u8 ad7291_limit_regs[9][2] = { - { AD7291_CH0_DATA_HIGH, AD7291_CH0_DATA_LOW }, - { AD7291_CH1_DATA_HIGH, AD7291_CH1_DATA_LOW }, - { AD7291_CH2_DATA_HIGH, AD7291_CH2_DATA_LOW }, - { AD7291_CH3_DATA_HIGH, AD7291_CH3_DATA_LOW }, /* FIXME: ? */ - { AD7291_CH4_DATA_HIGH, AD7291_CH4_DATA_LOW }, - { AD7291_CH5_DATA_HIGH, AD7291_CH5_DATA_LOW }, - { AD7291_CH6_DATA_HIGH, AD7291_CH6_DATA_LOW }, - { AD7291_CH7_DATA_HIGH, AD7291_CH7_DATA_LOW }, - /* temp */ - { AD7291_T_SENSE_HIGH, AD7291_T_SENSE_LOW }, -}; +static unsigned int ad7291_threshold_reg(u64 event_code) +{ + unsigned int offset; + + switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) { + case IIO_VOLTAGE: + offset = IIO_EVENT_CODE_EXTRACT_CHAN(event_code); + break; + case IIO_TEMP: + offset = 8; + break; + default: + return 0; + } + + if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING) + return AD7291_DATA_LOW(offset); + else + return AD7291_DATA_HIGH(offset); +} static int ad7291_read_event_value(struct iio_dev *indio_dev, u64 event_code, int *val) { struct ad7291_chip_info *chip = iio_priv(indio_dev); - int ret; - u8 reg; u16 uval; - s16 signval; + + ret = ad7291_i2c_read(chip, ad7291_threshold_reg(event_code), &uval); + if (ret < 0) + return ret; switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) { case IIO_VOLTAGE: - reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)] - [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == - IIO_EV_DIR_RISING)]; - - ret = ad7291_i2c_read(chip, reg, &uval); - if (ret < 0) - return ret; *val = uval & AD7291_VALUE_MASK; return 0; - case IIO_TEMP: - reg = ad7291_limit_regs[8] - [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == - IIO_EV_DIR_RISING)]; - - ret = ad7291_i2c_read(chip, reg, &signval); - if (ret < 0) - return ret; - signval = (s16)((signval & AD7291_VALUE_MASK) << 4) >> 4; - *val = signval; + *val = sign_extend32(uval, 11); return 0; default: return -EINVAL; @@ -352,28 +298,21 @@ static int ad7291_write_event_value(struct iio_dev *indio_dev, int val) { struct ad7291_chip_info *chip = iio_priv(indio_dev); - u8 reg; - s16 signval; switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) { case IIO_VOLTAGE: if (val > AD7291_VALUE_MASK || val < 0) return -EINVAL; - reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)] - [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == - IIO_EV_DIR_RISING)]; - return ad7291_i2c_write(chip, reg, val); + break; case IIO_TEMP: if (val > 2047 || val < -2048) return -EINVAL; - reg = ad7291_limit_regs[8] - [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == - IIO_EV_DIR_RISING)]; - signval = val; - return ad7291_i2c_write(chip, reg, *(u16 *)&signval); + break; default: return -EINVAL; - }; + } + + return ad7291_i2c_write(chip, ad7291_threshold_reg(event_code), val); } static int ad7291_read_event_config(struct iio_dev *indio_dev, @@ -456,9 +395,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev, { int ret; struct ad7291_chip_info *chip = iio_priv(indio_dev); - unsigned int scale_uv; u16 regval; - s16 signval; switch (mask) { case IIO_CHAN_INFO_RAW: @@ -479,44 +416,47 @@ static int ad7291_read_raw(struct iio_dev *indio_dev, return ret; } /* Read voltage */ - ret = i2c_smbus_read_word_data(chip->client, + ret = i2c_smbus_read_word_swapped(chip->client, AD7291_VOLTAGE); if (ret < 0) { mutex_unlock(&chip->state_lock); return ret; } - *val = swab16((u16)ret) & AD7291_VALUE_MASK; + *val = ret & AD7291_VALUE_MASK; mutex_unlock(&chip->state_lock); return IIO_VAL_INT; case IIO_TEMP: /* Assumes tsense bit of command register always set */ - ret = i2c_smbus_read_word_data(chip->client, + ret = i2c_smbus_read_word_swapped(chip->client, AD7291_T_SENSE); if (ret < 0) return ret; - signval = (s16)((swab16((u16)ret) & - AD7291_VALUE_MASK) << 4) >> 4; - *val = signval; + *val = sign_extend32(ret, 11); return IIO_VAL_INT; default: return -EINVAL; } case IIO_CHAN_INFO_AVERAGE_RAW: - ret = i2c_smbus_read_word_data(chip->client, + ret = i2c_smbus_read_word_swapped(chip->client, AD7291_T_AVERAGE); if (ret < 0) return ret; - signval = (s16)((swab16((u16)ret) & - AD7291_VALUE_MASK) << 4) >> 4; - *val = signval; + *val = sign_extend32(ret, 11); return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: - scale_uv = (chip->int_vref_mv * 1000) >> AD7291_BITS; - *val = scale_uv / 1000; - *val2 = (scale_uv % 1000) * 1000; - return IIO_VAL_INT_PLUS_MICRO; + if (chip->reg) { + int vref; + vref = regulator_get_voltage(chip->reg); + if (vref < 0) + return vref; + *val = vref / 1000; + } else { + *val = 2500; + } + *val2 = AD7291_BITS; + return IIO_VAL_FRACTIONAL_LOG2; case IIO_TEMP: /* * One LSB of the ADC corresponds to 0.25 deg C. @@ -571,7 +511,6 @@ static struct attribute_group ad7291_event_attribute_group = { }; static const struct iio_info ad7291_info = { - .attrs = &ad7291_attribute_group, .read_raw = &ad7291_read_raw, .read_event_config = &ad7291_read_event_config, .write_event_config = &ad7291_write_event_config, @@ -583,9 +522,10 @@ static const struct iio_info ad7291_info = { static int ad7291_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct ad7291_platform_data *pdata = client->dev.platform_data; struct ad7291_chip_info *chip; struct iio_dev *indio_dev; - int ret = 0, voltage_uv = 0; + int ret = 0; indio_dev = iio_device_alloc(sizeof(*chip)); if (indio_dev == NULL) { @@ -594,12 +534,14 @@ static int ad7291_probe(struct i2c_client *client, } chip = iio_priv(indio_dev); - chip->reg = regulator_get(&client->dev, "vcc"); - if (!IS_ERR(chip->reg)) { + if (pdata && pdata->use_external_ref) { + chip->reg = regulator_get(&client->dev, "vref"); + if (IS_ERR(chip->reg)) + goto error_free; + ret = regulator_enable(chip->reg); if (ret) goto error_put_reg; - voltage_uv = regulator_get_voltage(chip->reg); } mutex_init(&chip->state_lock); @@ -612,12 +554,8 @@ static int ad7291_probe(struct i2c_client *client, AD7291_T_SENSE_MASK | /* Tsense always enabled */ AD7291_ALERT_POLARITY; /* set irq polarity low level */ - if (voltage_uv) { - chip->int_vref_mv = voltage_uv / 1000; + if (pdata && pdata->use_external_ref) chip->command |= AD7291_EXT_REF; - } else { - chip->int_vref_mv = 2500; /* Build-in ref */ - } indio_dev->name = id->name; indio_dev->channels = ad7291_channels; @@ -654,21 +592,18 @@ static int ad7291_probe(struct i2c_client *client, if (ret) goto error_unreg_irq; - dev_info(&client->dev, "%s ADC registered.\n", - id->name); - return 0; error_unreg_irq: if (client->irq) free_irq(client->irq, indio_dev); error_disable_reg: - if (!IS_ERR(chip->reg)) + if (chip->reg) regulator_disable(chip->reg); error_put_reg: - if (!IS_ERR(chip->reg)) + if (chip->reg) regulator_put(chip->reg); - +error_free: iio_device_free(indio_dev); error_ret: return ret; @@ -684,7 +619,7 @@ static int ad7291_remove(struct i2c_client *client) if (client->irq) free_irq(client->irq, indio_dev); - if (!IS_ERR(chip->reg)) { + if (chip->reg) { regulator_disable(chip->reg); regulator_put(chip->reg); } diff --git a/drivers/staging/iio/adc/ad7291.h b/drivers/staging/iio/adc/ad7291.h new file mode 100644 index 000000000000..bbd89fa51188 --- /dev/null +++ b/drivers/staging/iio/adc/ad7291.h @@ -0,0 +1,12 @@ +#ifndef __IIO_AD7291_H__ +#define __IIO_AD7291_H__ + +/** + * struct ad7291_platform_data - AD7291 platform data + * @use_external_ref: Whether to use an external or internal reference voltage + */ +struct ad7291_platform_data { + bool use_external_ref; +}; + +#endif diff --git a/drivers/staging/iio/adc/ad7606_core.c b/drivers/staging/iio/adc/ad7606_core.c index d104b4378424..72868ceda360 100644 --- a/drivers/staging/iio/adc/ad7606_core.c +++ b/drivers/staging/iio/adc/ad7606_core.c @@ -125,9 +125,12 @@ static ssize_t ad7606_store_range(struct device *dev, struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ad7606_state *st = iio_priv(indio_dev); unsigned long lval; + int ret; + + ret = kstrtoul(buf, 10, &lval); + if (ret) + return ret; - if (strict_strtoul(buf, 10, &lval)) - return -EINVAL; if (!(lval == 5000 || lval == 10000)) { dev_err(dev, "range is not supported\n"); return -EINVAL; @@ -173,8 +176,9 @@ static ssize_t ad7606_store_oversampling_ratio(struct device *dev, unsigned long lval; int ret; - if (strict_strtoul(buf, 10, &lval)) - return -EINVAL; + ret = kstrtoul(buf, 10, &lval); + if (ret) + return ret; ret = ad7606_oversampling_get_index(lval); if (ret < 0) { diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c index 58cfddea9637..8a48d18de788 100644 --- a/drivers/staging/iio/adc/ad7606_par.c +++ b/drivers/staging/iio/adc/ad7606_par.c @@ -112,8 +112,6 @@ static int ad7606_par_remove(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); release_mem_region(res->start, resource_size(res)); - platform_set_drvdata(pdev, NULL); - return 0; } diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index 928477146c2f..8470036a3378 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -175,9 +175,9 @@ static ssize_t ad7816_store_channel(struct device *dev, unsigned long data; int ret; - ret = strict_strtoul(buf, 10, &data); + ret = kstrtoul(buf, 10, &data); if (ret) - return -EINVAL; + return ret; if (data > AD7816_CS_MAX && data != AD7816_CS_MASK) { dev_err(&chip->spi_dev->dev, "Invalid channel id %lu for %s.\n", @@ -290,7 +290,9 @@ static inline ssize_t ad7816_set_oti(struct device *dev, u8 data; int ret; - ret = strict_strtol(buf, 10, &value); + ret = kstrtol(buf, 10, &value); + if (ret) + return ret; if (chip->channel_id > AD7816_CS_MAX) { dev_err(dev, "Invalid oti channel id %d.\n", chip->channel_id); diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c index 8dc97b36e05a..2b2049c8bc6b 100644 --- a/drivers/staging/iio/adc/ad799x_core.c +++ b/drivers/staging/iio/adc/ad799x_core.c @@ -226,7 +226,7 @@ static ssize_t ad799x_write_frequency(struct device *dev, int ret, i; u8 t; - ret = strict_strtol(buf, 10, &val); + ret = kstrtol(buf, 10, &val); if (ret) return ret; @@ -337,7 +337,7 @@ static ssize_t ad799x_write_channel_config(struct device *dev, long val; int ret; - ret = strict_strtol(buf, 10, &val); + ret = kstrtol(buf, 10, &val); if (ret) return ret; diff --git a/drivers/staging/iio/adc/lpc32xx_adc.c b/drivers/staging/iio/adc/lpc32xx_adc.c index 2f2f7fdd0691..9a4bb0999b51 100644 --- a/drivers/staging/iio/adc/lpc32xx_adc.c +++ b/drivers/staging/iio/adc/lpc32xx_adc.c @@ -215,7 +215,6 @@ static int lpc32xx_adc_remove(struct platform_device *pdev) iio_device_unregister(iodev); free_irq(irq, info); - platform_set_drvdata(pdev, NULL); clk_put(info->clk); iounmap(info->adc_base); iio_device_free(iodev); diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c index 163c638e4095..d92c97a59d61 100644 --- a/drivers/staging/iio/adc/mxs-lradc.c +++ b/drivers/staging/iio/adc/mxs-lradc.c @@ -620,7 +620,7 @@ static irqreturn_t mxs_lradc_trigger_handler(int irq, void *p) ((LRADC_DELAY_TIMER_LOOP - 1) << LRADC_CH_NUM_SAMPLES_OFFSET); unsigned int i, j = 0; - for_each_set_bit(i, iio->active_scan_mask, iio->masklength) { + for_each_set_bit(i, iio->active_scan_mask, LRADC_MAX_TOTAL_CHANS) { lradc->buffer[j] = readl(lradc->base + LRADC_CH(j)); writel(chan_value, lradc->base + LRADC_CH(j)); lradc->buffer[j] &= LRADC_CH_VALUE_MASK; @@ -774,8 +774,7 @@ static bool mxs_lradc_validate_scan_mask(struct iio_dev *iio, const unsigned long *mask) { struct mxs_lradc *lradc = iio_priv(iio); - const int len = iio->masklength; - const int map_chans = bitmap_weight(mask, len); + const int map_chans = bitmap_weight(mask, LRADC_MAX_TOTAL_CHANS); int rsvd_chans = 0; unsigned long rsvd_mask = 0; @@ -792,7 +791,7 @@ static bool mxs_lradc_validate_scan_mask(struct iio_dev *iio, rsvd_chans++; /* Test for attempts to map channels with special mode of operation. */ - if (bitmap_intersects(mask, &rsvd_mask, len)) + if (bitmap_intersects(mask, &rsvd_mask, LRADC_MAX_TOTAL_CHANS)) return false; /* Test for attempts to map more channels then available slots. */ @@ -968,6 +967,7 @@ static int mxs_lradc_probe(struct platform_device *pdev) iio->modes = INDIO_DIRECT_MODE; iio->channels = mxs_lradc_chan_spec; iio->num_channels = ARRAY_SIZE(mxs_lradc_chan_spec); + iio->masklength = LRADC_MAX_TOTAL_CHANS; ret = iio_triggered_buffer_setup(iio, &iio_pollfunc_store_time, &mxs_lradc_trigger_handler, diff --git a/drivers/staging/iio/adc/spear_adc.c b/drivers/staging/iio/adc/spear_adc.c index f45da4266950..736219c30308 100644 --- a/drivers/staging/iio/adc/spear_adc.c +++ b/drivers/staging/iio/adc/spear_adc.c @@ -407,7 +407,6 @@ static int spear_adc_remove(struct platform_device *pdev) struct spear_adc_info *info = iio_priv(iodev); iio_device_unregister(iodev); - platform_set_drvdata(pdev, NULL); clk_disable_unprepare(info->clk); clk_put(info->clk); iounmap(info->adc_base_spear6xx); @@ -416,11 +415,13 @@ static int spear_adc_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_OF static const struct of_device_id spear_adc_dt_ids[] = { { .compatible = "st,spear600-adc", }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, spear_adc_dt_ids); +#endif static struct platform_driver spear_adc_driver = { .probe = spear_adc_probe, diff --git a/drivers/staging/iio/gyro/Kconfig b/drivers/staging/iio/gyro/Kconfig index 836066287192..b4333715536e 100644 --- a/drivers/staging/iio/gyro/Kconfig +++ b/drivers/staging/iio/gyro/Kconfig @@ -10,13 +10,6 @@ config ADIS16060 Say yes here to build support for Analog Devices adis16060 wide bandwidth yaw rate gyroscope with SPI. -config ADIS16130 - tristate "Analog Devices ADIS16130 High Precision Angular Rate Sensor driver" - depends on SPI - help - Say yes here to build support for Analog Devices ADIS16130 High Precision - Angular Rate Sensor driver. - config ADIS16260 tristate "Analog Devices ADIS16260 Digital Gyroscope Sensor SPI driver" depends on SPI diff --git a/drivers/staging/iio/gyro/Makefile b/drivers/staging/iio/gyro/Makefile index 98e650061a3a..975f95b141da 100644 --- a/drivers/staging/iio/gyro/Makefile +++ b/drivers/staging/iio/gyro/Makefile @@ -5,8 +5,5 @@ adis16060-y := adis16060_core.o obj-$(CONFIG_ADIS16060) += adis16060.o -adis16130-y := adis16130_core.o -obj-$(CONFIG_ADIS16130) += adis16130.o - adis16260-y := adis16260_core.o obj-$(CONFIG_ADIS16260) += adis16260.o diff --git a/drivers/staging/iio/trigger/Kconfig b/drivers/staging/iio/trigger/Kconfig index 1a051da62505..2fd18c60323d 100644 --- a/drivers/staging/iio/trigger/Kconfig +++ b/drivers/staging/iio/trigger/Kconfig @@ -12,23 +12,6 @@ config IIO_PERIODIC_RTC_TRIGGER Provides support for using periodic capable real time clocks as IIO triggers. -config IIO_GPIO_TRIGGER - tristate "GPIO trigger" - depends on GPIOLIB - help - Provides support for using GPIO pins as IIO triggers. - -config IIO_SYSFS_TRIGGER - tristate "SYSFS trigger" - depends on SYSFS - select IRQ_WORK - help - Provides support for using SYSFS entry as IIO triggers. - If unsure, say N (but it's safe to say "Y"). - - To compile this driver as a module, choose M here: the - module will be called iio-trig-sysfs. - config IIO_BFIN_TMR_TRIGGER tristate "Blackfin TIMER trigger" depends on BLACKFIN diff --git a/drivers/staging/iio/trigger/Makefile b/drivers/staging/iio/trigger/Makefile index b088b57da335..238481b78e72 100644 --- a/drivers/staging/iio/trigger/Makefile +++ b/drivers/staging/iio/trigger/Makefile @@ -3,6 +3,4 @@ # obj-$(CONFIG_IIO_PERIODIC_RTC_TRIGGER) += iio-trig-periodic-rtc.o -obj-$(CONFIG_IIO_GPIO_TRIGGER) += iio-trig-gpio.o -obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o obj-$(CONFIG_IIO_BFIN_TMR_TRIGGER) += iio-trig-bfin-timer.o diff --git a/drivers/staging/iio/trigger/iio-trig-gpio.c b/drivers/staging/iio/trigger/iio-trig-gpio.c deleted file mode 100644 index 7c593d18a910..000000000000 --- a/drivers/staging/iio/trigger/iio-trig-gpio.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Industrial I/O - gpio based trigger support - * - * Copyright (c) 2008 Jonathan Cameron - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published by - * the Free Software Foundation. - * - * Currently this is more of a functioning proof of concept than a full - * fledged trigger driver. - * - * TODO: - * - * Add board config elements to allow specification of startup settings. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -static LIST_HEAD(iio_gpio_trigger_list); -static DEFINE_MUTEX(iio_gpio_trigger_list_lock); - -struct iio_gpio_trigger_info { - struct mutex in_use; - unsigned int irq; -}; -/* - * Need to reference count these triggers and only enable gpio interrupts - * as appropriate. - */ - -/* So what functionality do we want in here?... */ -/* set high / low as interrupt type? */ - -static irqreturn_t iio_gpio_trigger_poll(int irq, void *private) -{ - /* Timestamp not currently provided */ - iio_trigger_poll(private, 0); - return IRQ_HANDLED; -} - -static const struct iio_trigger_ops iio_gpio_trigger_ops = { - .owner = THIS_MODULE, -}; - -static int iio_gpio_trigger_probe(struct platform_device *pdev) -{ - struct iio_gpio_trigger_info *trig_info; - struct iio_trigger *trig, *trig2; - unsigned long irqflags; - struct resource *irq_res; - int irq, ret = 0, irq_res_cnt = 0; - - do { - irq_res = platform_get_resource(pdev, - IORESOURCE_IRQ, irq_res_cnt); - - if (irq_res == NULL) { - if (irq_res_cnt == 0) - dev_err(&pdev->dev, "No GPIO IRQs specified"); - break; - } - irqflags = (irq_res->flags & IRQF_TRIGGER_MASK) | IRQF_SHARED; - - for (irq = irq_res->start; irq <= irq_res->end; irq++) { - - trig = iio_trigger_alloc("irqtrig%d", irq); - if (!trig) { - ret = -ENOMEM; - goto error_free_completed_registrations; - } - - trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL); - if (!trig_info) { - ret = -ENOMEM; - goto error_put_trigger; - } - iio_trigger_set_drvdata(trig, trig_info); - trig_info->irq = irq; - trig->ops = &iio_gpio_trigger_ops; - ret = request_irq(irq, iio_gpio_trigger_poll, - irqflags, trig->name, trig); - if (ret) { - dev_err(&pdev->dev, - "request IRQ-%d failed", irq); - goto error_free_trig_info; - } - - ret = iio_trigger_register(trig); - if (ret) - goto error_release_irq; - - list_add_tail(&trig->alloc_list, - &iio_gpio_trigger_list); - } - - irq_res_cnt++; - } while (irq_res != NULL); - - - return 0; - -/* First clean up the partly allocated trigger */ -error_release_irq: - free_irq(irq, trig); -error_free_trig_info: - kfree(trig_info); -error_put_trigger: - iio_trigger_put(trig); -error_free_completed_registrations: - /* The rest should have been added to the iio_gpio_trigger_list */ - list_for_each_entry_safe(trig, - trig2, - &iio_gpio_trigger_list, - alloc_list) { - trig_info = iio_trigger_get_drvdata(trig); - free_irq(gpio_to_irq(trig_info->irq), trig); - kfree(trig_info); - iio_trigger_unregister(trig); - } - - return ret; -} - -static int iio_gpio_trigger_remove(struct platform_device *pdev) -{ - struct iio_trigger *trig, *trig2; - struct iio_gpio_trigger_info *trig_info; - - mutex_lock(&iio_gpio_trigger_list_lock); - list_for_each_entry_safe(trig, - trig2, - &iio_gpio_trigger_list, - alloc_list) { - trig_info = iio_trigger_get_drvdata(trig); - iio_trigger_unregister(trig); - free_irq(trig_info->irq, trig); - kfree(trig_info); - iio_trigger_put(trig); - } - mutex_unlock(&iio_gpio_trigger_list_lock); - - return 0; -} - -static struct platform_driver iio_gpio_trigger_driver = { - .probe = iio_gpio_trigger_probe, - .remove = iio_gpio_trigger_remove, - .driver = { - .name = "iio_gpio_trigger", - .owner = THIS_MODULE, - }, -}; - -module_platform_driver(iio_gpio_trigger_driver); - -MODULE_AUTHOR("Jonathan Cameron "); -MODULE_DESCRIPTION("Example gpio trigger for the iio subsystem"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/imx-drm/Kconfig b/drivers/staging/imx-drm/Kconfig index ef699f753186..22339059837f 100644 --- a/drivers/staging/imx-drm/Kconfig +++ b/drivers/staging/imx-drm/Kconfig @@ -30,6 +30,14 @@ config DRM_IMX_TVE Choose this to enable the internal Television Encoder (TVe) found on i.MX53 processors. +config DRM_IMX_LDB + tristate "Support for LVDS displays" + depends on DRM_IMX + select OF_VIDEOMODE + help + Choose this to enable the internal LVDS Display Bridge (LDB) + found on i.MX53 and i.MX6 processors. + config DRM_IMX_IPUV3_CORE tristate "IPUv3 core support" depends on DRM_IMX diff --git a/drivers/staging/imx-drm/Makefile b/drivers/staging/imx-drm/Makefile index 7e50184523c4..bfaf69378ac2 100644 --- a/drivers/staging/imx-drm/Makefile +++ b/drivers/staging/imx-drm/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_IMX) += imxdrm.o obj-$(CONFIG_DRM_IMX_PARALLEL_DISPLAY) += parallel-display.o obj-$(CONFIG_DRM_IMX_TVE) += imx-tve.o +obj-$(CONFIG_DRM_IMX_LDB) += imx-ldb.o obj-$(CONFIG_DRM_IMX_FB_HELPER) += imx-fbdev.o obj-$(CONFIG_DRM_IMX_IPUV3_CORE) += ipu-v3/ obj-$(CONFIG_DRM_IMX_IPUV3) += ipuv3-crtc.o diff --git a/drivers/staging/imx-drm/TODO b/drivers/staging/imx-drm/TODO index 123acbe9b379..f80641528f75 100644 --- a/drivers/staging/imx-drm/TODO +++ b/drivers/staging/imx-drm/TODO @@ -6,7 +6,6 @@ TODO: - Factor out more code to common helper functions - decide where to put the base driver. It is not specific to a subsystem and would be used by DRM/KMS and media/V4L2 -- convert irq driver to irq_domain_add_linear Missing features (not necessarily for moving out of staging): diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c index 64553058b67e..9854a1daf606 100644 --- a/drivers/staging/imx-drm/imx-drm-core.c +++ b/drivers/staging/imx-drm/imx-drm-core.c @@ -144,7 +144,7 @@ int imx_drm_crtc_panel_format(struct drm_crtc *crtc, u32 encoder_type, u32 interface_pix_fmt) { return imx_drm_crtc_panel_format_pins(crtc, encoder_type, - interface_pix_fmt, 0, 0); + interface_pix_fmt, 2, 3); } EXPORT_SYMBOL_GPL(imx_drm_crtc_panel_format); @@ -491,7 +491,6 @@ int imx_drm_add_crtc(struct drm_crtc *crtc, { struct imx_drm_device *imxdrm = __imx_drm_device(); struct imx_drm_crtc *imx_drm_crtc; - const struct drm_crtc_funcs *crtc_funcs; int ret; mutex_lock(&imxdrm->mutex); @@ -512,8 +511,6 @@ int imx_drm_add_crtc(struct drm_crtc *crtc, imx_drm_crtc->cookie.cookie = cookie; imx_drm_crtc->cookie.id = id; - crtc_funcs = imx_drm_helper_funcs->crtc_funcs; - imx_drm_crtc->crtc = crtc; imx_drm_crtc->imxdrm = imxdrm; diff --git a/drivers/staging/imx-drm/imx-ldb.c b/drivers/staging/imx-drm/imx-ldb.c new file mode 100644 index 000000000000..8af7f3b40bae --- /dev/null +++ b/drivers/staging/imx-drm/imx-ldb.c @@ -0,0 +1,625 @@ +/* + * i.MX drm driver - LVDS display bridge + * + * Copyright (C) 2012 Sascha Hauer, Pengutronix + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include