diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio index 42d360fe66a5..0439c2aaf741 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio +++ b/Documentation/ABI/testing/sysfs-bus-iio @@ -581,6 +581,7 @@ What: /sys/.../iio:deviceX/events/in_voltageY_supply_thresh_rising_en What: /sys/.../iio:deviceX/events/in_voltageY_supply_thresh_falling_en What: /sys/.../iio:deviceX/events/in_voltageY_thresh_rising_en What: /sys/.../iio:deviceX/events/in_voltageY_thresh_falling_en +What: /sys/.../iio:deviceX/events/in_voltageY_thresh_either_en What: /sys/.../iio:deviceX/events/in_tempY_thresh_rising_en What: /sys/.../iio:deviceX/events/in_tempY_thresh_falling_en KernelVersion: 2.6.37 @@ -1459,3 +1460,34 @@ Description: measurements and return the average value as output data. Each value resulted from [_name]_oversampling_ratio measurements is considered as one sample for [_name]_sampling_frequency. + +What: /sys/bus/iio/devices/iio:deviceX/in_concentration_raw +What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_raw +What: /sys/bus/iio/devices/iio:deviceX/in_concentration_co2_raw +What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_co2_raw +What: /sys/bus/iio/devices/iio:deviceX/in_concentration_voc_raw +What: /sys/bus/iio/devices/iio:deviceX/in_concentrationX_voc_raw +KernelVersion: 4.3 +Contact: linux-iio@vger.kernel.org +Description: + Raw (unscaled no offset etc.) percentage reading of a substance. + +What: /sys/bus/iio/devices/iio:deviceX/in_resistance_raw +What: /sys/bus/iio/devices/iio:deviceX/in_resistanceX_raw +What: /sys/bus/iio/devices/iio:deviceX/out_resistance_raw +What: /sys/bus/iio/devices/iio:deviceX/out_resistanceX_raw +KernelVersion: 4.3 +Contact: linux-iio@vger.kernel.org +Description: + Raw (unscaled no offset etc.) resistance reading that can be processed + into an ohm value. + +What: /sys/bus/iio/devices/iio:deviceX/heater_enable +KernelVersion: 4.1.0 +Contact: linux-iio@vger.kernel.org +Description: + '1' (enable) or '0' (disable) specifying the enable + of heater function. Same reading values apply + This ABI is especially applicable for humidity sensors + to heatup the device and get rid of any condensation + in some humidity environment diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-hi8435 b/Documentation/ABI/testing/sysfs-bus-iio-adc-hi8435 new file mode 100644 index 000000000000..f30b4c424fb6 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-hi8435 @@ -0,0 +1,43 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_sensing_mode +Date: August 2015 +KernelVersion: 4.2.0 +Contact: source@cogentembedded.com +Description: + Program sensor type for threshold detector inputs. + Could be either "GND-Open" or "Supply-Open" mode. Y is a + threshold detector input channel. Channels 0..7, 8..15, 16..23 + and 24..31 has common sensor types. + +What: /sys/bus/iio/devices/iio:deviceX/events/in_voltageY_thresh_falling_value +Date: August 2015 +KernelVersion: 4.2.0 +Contact: source@cogentembedded.com +Description: + Channel Y low voltage threshold. If sensor input voltage goes lower then + this value then the threshold falling event is pushed. + Depending on in_voltageY_sensing_mode the low voltage threshold + is separately set for "GND-Open" and "Supply-Open" modes. + Channels 0..31 have common low threshold values, but could have different + sensing_modes. + The low voltage threshold range is between 2..21V. + Hysteresis between low and high thresholds can not be lower then 2 and + can not be odd. + If falling threshold results hysteresis to odd value then rising + threshold is automatically subtracted by one. + +What: /sys/bus/iio/devices/iio:deviceX/events/in_voltageY_thresh_rising_value +Date: August 2015 +KernelVersion: 4.2.0 +Contact: source@cogentembedded.com +Description: + Channel Y high voltage threshold. If sensor input voltage goes higher then + this value then the threshold rising event is pushed. + Depending on in_voltageY_sensing_mode the high voltage threshold + is separately set for "GND-Open" and "Supply-Open" modes. + Channels 0..31 have common high threshold values, but could have different + sensing_modes. + The high voltage threshold range is between 3..22V. + Hysteresis between low and high thresholds can not be lower then 2 and + can not be odd. + If rising threshold results hysteresis to odd value then falling + threshold is automatically appended by one. diff --git a/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x new file mode 100644 index 000000000000..c0c1ea924535 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x @@ -0,0 +1,7 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_concentration_VOC_short_raw +Date: September 2015 +KernelVersion: 4.3 +Contact: Matt Ranostay +Description: + Get the raw calibration VOC value from the sensor. + This value has little application outside of calibration. diff --git a/Documentation/ABI/testing/sysfs-bus-iio-humidity-hdc100x b/Documentation/ABI/testing/sysfs-bus-iio-humidity-hdc100x new file mode 100644 index 000000000000..b72bb62552cf --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-iio-humidity-hdc100x @@ -0,0 +1,9 @@ +What: /sys/bus/iio/devices/iio:deviceX/out_current_heater_raw +What: /sys/bus/iio/devices/iio:deviceX/out_current_heater_raw_available +KernelVersion: 4.3 +Contact: linux-iio@vger.kernel.org +Description: + Controls the heater device within the humidity sensor to get + rid of excess condensation. + + Valid control values are 0 = OFF, and 1 = ON. diff --git a/Documentation/ABI/testing/sysfs-bus-iio-meas-spec b/Documentation/ABI/testing/sysfs-bus-iio-meas-spec new file mode 100644 index 000000000000..1a6265e92e2f --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-iio-meas-spec @@ -0,0 +1,8 @@ +What: /sys/bus/iio/devices/iio:deviceX/battery_low +KernelVersion: 4.1.0 +Contact: linux-iio@vger.kernel.org +Description: + Reading returns either '1' or '0'. '1' means that the + battery level supplied to sensor is below 2.25V. + This ABI is available for tsys02d, htu21, ms8607 + This ABI is available for htu21, ms8607 diff --git a/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs b/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs index bbb039237a25..04ac62305018 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs +++ b/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs @@ -18,3 +18,25 @@ Description: trigger. In order to associate the trigger with an IIO device one should write this name string to /sys/bus/iio/devices/iio:deviceY/trigger/current_trigger. + +What: /sys/bus/iio/devices/iio_sysfs_trigger/add_trigger +KernelVersion: 2.6.39 +Contact: linux-iio@vger.kernel.org +Description: + This attribute is provided by the iio-trig-sysfs stand-alone + driver and it is used to activate the creation of a new trigger. + In order to achieve this, one should write a positive integer + into the associated file, which will serve as the id of the + trigger. If the trigger with the specified id is already present + in the system, an invalid argument message will be returned. + +What: /sys/bus/iio/devices/iio_sysfs_trigger/remove_trigger +KernelVersion: 2.6.39 +Contact: linux-iio@vger.kernel.org +Description: + This attribute is used to unregister and delete a previously + created trigger from the list of available triggers. In order to + achieve this, one should write a positive integer into the + associated file, representing the id of the trigger that needs + to be removed. If the trigger can't be found, an invalid + argument message will be returned to the user. diff --git a/Documentation/DocBook/iio.tmpl b/Documentation/DocBook/iio.tmpl index 06bb53de5a47..98be322673da 100644 --- a/Documentation/DocBook/iio.tmpl +++ b/Documentation/DocBook/iio.tmpl @@ -578,7 +578,7 @@ work together. IIO triggered buffer setup -!Edrivers/iio/industrialio-triggered-buffer.c +!Edrivers/iio/buffer/industrialio-triggered-buffer.c !Finclude/linux/iio/iio.h iio_buffer_setup_ops diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt index d77d412cbc68..c50cf13c852e 100644 --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt @@ -54,7 +54,6 @@ epson,rx8581 I2C-BUS INTERFACE REAL TIME CLOCK MODULE fsl,mag3110 MAG3110: Xtrinsic High Accuracy, 3D Magnetometer fsl,mc13892 MC13892: Power Management Integrated Circuit (PMIC) for i.MX35/51 fsl,mma8450 MMA8450Q: Xtrinsic Low-power, 3-axis Xtrinsic Accelerometer -fsl,mma8452 MMA8452Q: 3-axis 12-bit / 8-bit Digital Accelerometer fsl,mpr121 MPR121: Proximity Capacitive Touch Sensor Controller fsl,sgtl5000 SGTL5000: Ultra Low-Power Audio Codec gmt,g751 G751: Digital Temperature Sensor and Thermal Watchdog with Two-Wire Interface @@ -80,6 +79,7 @@ oki,ml86v7667 OKI ML86V7667 video decoder ovti,ov5642 OV5642: Color CMOS QSXGA (5-megapixel) Image Sensor with OmniBSI and Embedded TrueFocus pericom,pt7c4338 Real-time Clock Module plx,pex8648 48-Lane, 12-Port PCI Express Gen 2 (5.0 GT/s) Switch +pulsedlight,lidar-lite-v2 Pulsedlight LIDAR range-finding sensor ramtron,24c64 i2c serial eeprom (24cxx) ricoh,r2025sd I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC ricoh,r2221tl I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC @@ -88,6 +88,7 @@ ricoh,rs5c372b I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC ricoh,rv5c386 I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC ricoh,rv5c387a I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC samsung,24ad0xd1 S524AD0XF1 (128K/256K-bit Serial EEPROM for Low Power) +sgx,vz89x SGX Sensortech VZ89X Sensors sii,s35390a 2-wire CMOS real-time clock skyworks,sky81452 Skyworks SKY81452: Six-Channel White LED Driver with Touch Panel Bias Supply st-micro,24c256 i2c serial eeprom (24cxx) diff --git a/Documentation/devicetree/bindings/iio/accel/mma8452.txt b/Documentation/devicetree/bindings/iio/accel/mma8452.txt new file mode 100644 index 000000000000..e3c37467d7da --- /dev/null +++ b/Documentation/devicetree/bindings/iio/accel/mma8452.txt @@ -0,0 +1,24 @@ +Freescale MMA8452Q, MMA8453Q, MMA8652FC or MMA8653FC triaxial accelerometer + +Required properties: + + - compatible: should contain one of + * "fsl,mma8452" + * "fsl,mma8453" + * "fsl,mma8652" + * "fsl,mma8653" + - reg: the I2C address of the chip + +Optional properties: + + - interrupt-parent: should be the phandle for the interrupt controller + - interrupts: interrupt mapping for GPIO IRQ + +Example: + + mma8453fc@1d { + compatible = "fsl,mma8453"; + reg = <0x1d>; + interrupt-parent = <&gpio1>; + interrupts = <5 0>; + }; diff --git a/Documentation/devicetree/bindings/iio/adc/hi8435.txt b/Documentation/devicetree/bindings/iio/adc/hi8435.txt new file mode 100644 index 000000000000..3b0348c5e516 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/hi8435.txt @@ -0,0 +1,21 @@ +Holt Integrated Circuits HI-8435 threshold detector bindings + +Required properties: + - compatible: should be "holt,hi8435" + - reg: spi chip select number for the device + +Recommended properties: + - spi-max-frequency: definition as per + Documentation/devicetree/bindings/spi/spi-bus.txt + +Optional properties: + - gpios: GPIO used for controlling the reset pin + +Example: +sensor@0 { + compatible = "holt,hi8435"; + reg = <0>; + gpios = <&gpio6 1 0>; + + spi-max-frequency = <1000000>; +}; diff --git a/Documentation/devicetree/bindings/iio/light/apds9960.txt b/Documentation/devicetree/bindings/iio/light/apds9960.txt new file mode 100644 index 000000000000..174b709f16db --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/apds9960.txt @@ -0,0 +1,22 @@ +* Avago APDS9960 gesture/RGB/ALS/proximity sensor + +http://www.avagotech.com/docs/AV02-4191EN + +Required properties: + + - compatible: must be "avago,apds9960" + - reg: the I2c address of the sensor + - interrupt-parent: should be the phandle for the interrupt controller + - interrupts : the sole interrupt generated by the device + + Refer to interrupt-controller/interrupts.txt for generic interrupt client + node bindings. + +Example: + +apds9960@39 { + compatible = "avago,apds9960"; + reg = <0x39>; + interrupt-parent = <&gpio1>; + interrupts = <16 1>; +}; diff --git a/Documentation/devicetree/bindings/iio/light/us5182d.txt b/Documentation/devicetree/bindings/iio/light/us5182d.txt new file mode 100644 index 000000000000..6f0a530144fd --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/us5182d.txt @@ -0,0 +1,34 @@ +* UPISEMI us5182d I2C ALS and Proximity sensor + +Required properties: +- compatible: must be "upisemi,usd5182" +- reg: the I2C address of the device + +Optional properties: +- upisemi,glass-coef: glass attenuation factor - compensation factor of + resolution 1000 for material transmittance. +- upisemi,dark-ths: array of 8 elements containing 16-bit thresholds (adc + counts) corresponding to every scale. +- upisemi,upper-dark-gain: 8-bit dark gain compensation factor(4 int and 4 + fractional bits - Q4.4) applied when light > threshold +- upisemi,lower-dark-gain: 8-bit dark gain compensation factor(4 int and 4 + fractional bits - Q4.4) applied when light < threshold + +If the optional properties are not specified these factors will default to the +values in the below example. +The glass-coef defaults to no compensation for the covering material. +The threshold array defaults to experimental values that work with US5182D +sensor on evaluation board - roughly between 12-32 lux. +There will be no dark-gain compensation by default when ALS > thresh +(0 * dark-gain), and a 1.35 compensation factor when ALS < thresh. + +Example: + + usd5182@39 { + compatible = "upisemi,usd5182"; + reg = <0x39>; + upisemi,glass-coef = < 1000 >; + upisemi,dark-ths = /bits/ 16 <170 200 512 512 800 2000 4000 8000>; + upisemi,upper-dark-gain = /bits/ 8 <0x00>; + upisemi,lower-dark-gain = /bits/ 8 <0x16>; + }; diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 82d2ac97af74..13e54a0e78b9 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -101,6 +101,7 @@ himax Himax Technologies, Inc. hisilicon Hisilicon Limited. hit Hitachi Ltd. hitex Hitex Development Tools +holt Holt Integrated Circuits, Inc. honeywell Honeywell hp Hewlett Packard i2se I2SE GmbH @@ -169,6 +170,7 @@ phytec PHYTEC Messtechnik GmbH picochip Picochip Ltd plathome Plat'Home Co., Ltd. pixcir PIXCIR MICROELECTRONICS Co., Ltd +pulsedlight PulsedLight, Inc powervr PowerVR (deprecated, use img) qca Qualcomm Atheros, Inc. qcom Qualcomm Technologies, Inc @@ -191,6 +193,7 @@ sbs Smart Battery System schindler Schindler seagate Seagate Technology PLC semtech Semtech Corporation +sgx SGX Sensortech sharp Sharp Corporation sil Silicon Image silabs Silicon Laboratories @@ -223,6 +226,7 @@ toshiba Toshiba Corporation toumaz Toumaz tplink TP-LINK Technologies Co., Ltd. truly Truly Semiconductors Limited +upisemi uPI Semiconductor Corp. usi Universal Scientific Industrial Co., Ltd. v3 V3 Semiconductor variscite Variscite Ltd. diff --git a/MAINTAINERS b/MAINTAINERS index 94a97bc8a073..68468bf0c3bf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6740,6 +6740,12 @@ W: http://linuxtv.org S: Maintained F: drivers/media/radio/radio-maxiradio* +MCP4531 MICROCHIP DIGITAL POTENTIOMETER DRIVER +M: Peter Rosin +L: linux-iio@vger.kernel.org +S: Maintained +F: drivers/iio/potentiometer/mcp4531.c + MEDIA DRIVERS FOR RENESAS - VSP1 M: Laurent Pinchart L: linux-media@vger.kernel.org @@ -6975,6 +6981,13 @@ S: Supported F: include/linux/mlx5/ F: drivers/infiniband/hw/mlx5/ +MELEXIS MLX90614 DRIVER +M: Crt Mori +L: linux-iio@vger.kernel.org +W: http://www.melexis.com +S: Supported +F: drivers/iio/temperature/mlx90614.c + MN88472 MEDIA DRIVER M: Antti Palosaari L: linux-media@vger.kernel.org @@ -10069,9 +10082,11 @@ F: drivers/staging/vt665?/ STAGING - WILC1000 WIFI DRIVER M: Johnny Kim -M: Rachel Kim -M: Dean Lee +M: Austin Shin M: Chris Park +M: Tony Cho +M: Glen Lee +M: Leo Kim L: linux-wireless@vger.kernel.org S: Supported F: drivers/staging/wilc1000/ diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig index 4011effe4c05..66792e707d74 100644 --- a/drivers/iio/Kconfig +++ b/drivers/iio/Kconfig @@ -19,27 +19,7 @@ config IIO_BUFFER acquisition methods. if IIO_BUFFER - -config IIO_BUFFER_CB - bool "IIO callback buffer used for push in-kernel interfaces" - help - Should be selected by any drivers that do in-kernel push - usage. That is, those where the data is pushed to the consumer. - -config IIO_KFIFO_BUF - tristate "Industrial I/O buffering based on kfifo" - help - A simple fifo based on kfifo. Note that this currently provides - no buffer events so it is up to userspace to work out how - often to read from the buffer. - -config IIO_TRIGGERED_BUFFER - tristate - select IIO_TRIGGER - select IIO_KFIFO_BUF - help - Provides helper functions for setting up triggered buffers. - + source "drivers/iio/buffer/Kconfig" endif # IIO_BUFFER config IIO_TRIGGER @@ -58,9 +38,16 @@ config IIO_CONSUMERS_PER_TRIGGER This value controls the maximum number of consumers that a given trigger may handle. Default is 2. +config IIO_TRIGGERED_EVENT + tristate + select IIO_TRIGGER + help + Provides helper functions for setting up triggered events. + source "drivers/iio/accel/Kconfig" source "drivers/iio/adc/Kconfig" source "drivers/iio/amplifiers/Kconfig" +source "drivers/iio/chemical/Kconfig" source "drivers/iio/common/Kconfig" source "drivers/iio/dac/Kconfig" source "drivers/iio/frequency/Kconfig" @@ -73,6 +60,7 @@ source "drivers/iio/orientation/Kconfig" if IIO_TRIGGER source "drivers/iio/trigger/Kconfig" endif #IIO_TRIGGER +source "drivers/iio/potentiometer/Kconfig" source "drivers/iio/pressure/Kconfig" source "drivers/iio/proximity/Kconfig" source "drivers/iio/temperature/Kconfig" diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile index 698afc2d17ce..aeca7269fe44 100644 --- a/drivers/iio/Makefile +++ b/drivers/iio/Makefile @@ -6,14 +6,14 @@ obj-$(CONFIG_IIO) += industrialio.o industrialio-y := industrialio-core.o industrialio-event.o inkern.o industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o -industrialio-$(CONFIG_IIO_BUFFER_CB) += buffer_cb.o -obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o -obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o +obj-$(CONFIG_IIO_TRIGGERED_EVENT) += industrialio-triggered-event.o obj-y += accel/ obj-y += adc/ obj-y += amplifiers/ +obj-y += buffer/ +obj-y += chemical/ obj-y += common/ obj-y += dac/ obj-y += gyro/ @@ -23,6 +23,7 @@ obj-y += imu/ obj-y += light/ obj-y += magnetometer/ obj-y += orientation/ +obj-y += potentiometer/ obj-y += pressure/ obj-y += proximity/ obj-y += temperature/ diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index a59047d7657e..969428dd6329 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -19,19 +19,27 @@ config BMA180 config BMC150_ACCEL tristate "Bosch BMC150 Accelerometer Driver" - depends on I2C select IIO_BUFFER select IIO_TRIGGERED_BUFFER + select REGMAP + select BMC150_ACCEL_I2C if I2C + select BMC150_ACCEL_SPI if SPI help Say yes here to build support for the following Bosch accelerometers: BMC150, BMI055, BMA250E, BMA222E, BMA255, BMA280. - Currently this only supports the device via an i2c interface. - This is a combo module with both accelerometer and magnetometer. This driver is only implementing accelerometer part, which has its own address and register map. +config BMC150_ACCEL_I2C + tristate + select REGMAP_I2C + +config BMC150_ACCEL_SPI + tristate + select REGMAP_SPI + config HID_SENSOR_ACCEL_3D depends on HID_SENSOR_HUB select IIO_BUFFER @@ -100,13 +108,13 @@ config KXCJK1013 be called kxcjk-1013. config MMA8452 - tristate "Freescale MMA8452Q Accelerometer Driver" + tristate "Freescale MMA8452Q and similar Accelerometers Driver" depends on I2C select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - Say yes here to build support for the Freescale MMA8452Q 3-axis - accelerometer. + Say yes here to build support for the following Freescale 3-axis + accelerometers: MMA8452Q, MMA8453Q, MMA8652FC, MMA8653FC. To compile this driver as a module, choose M here: the module will be called mma8452. @@ -137,6 +145,19 @@ config MMA9553 To compile this driver as a module, choose M here: the module will be called mma9553. +config MXC4005 + tristate "Memsic MXC4005XC 3-Axis Accelerometer Driver" + depends on I2C + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + select REGMAP_I2C + help + Say yes here to build support for the Memsic MXC4005XC 3-axis + accelerometer. + + To compile this driver as a module, choose M. The module will be + called mxc4005. + config STK8312 tristate "Sensortek STK8312 3-Axis Accelerometer Driver" depends on I2C diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index ebd2675b2a02..7925f166e6e9 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile @@ -4,7 +4,9 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_BMA180) += bma180.o -obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel.o +obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o +obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o +obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o obj-$(CONFIG_KXSD9) += kxsd9.o @@ -14,6 +16,8 @@ obj-$(CONFIG_MMA9551_CORE) += mma9551_core.o obj-$(CONFIG_MMA9551) += mma9551.o obj-$(CONFIG_MMA9553) += mma9553.o +obj-$(CONFIG_MXC4005) += mxc4005.o + obj-$(CONFIG_STK8312) += stk8312.o obj-$(CONFIG_STK8BA50) += stk8ba50.o diff --git a/drivers/iio/accel/bmc150-accel.c b/drivers/iio/accel/bmc150-accel-core.c similarity index 81% rename from drivers/iio/accel/bmc150-accel.c rename to drivers/iio/accel/bmc150-accel-core.c index 0104cdef8709..2d33f1e821db 100644 --- a/drivers/iio/accel/bmc150-accel.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -35,10 +35,12 @@ #include #include #include +#include + +#include "bmc150-accel.h" #define BMC150_ACCEL_DRV_NAME "bmc150_accel" #define BMC150_ACCEL_IRQ_NAME "bmc150_accel_event" -#define BMC150_ACCEL_GPIO_NAME "bmc150_accel_int" #define BMC150_ACCEL_REG_CHIP_ID 0x00 @@ -185,7 +187,9 @@ enum bmc150_accel_trigger_id { }; struct bmc150_accel_data { - struct i2c_client *client; + struct regmap *regmap; + struct device *dev; + int irq; struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS]; atomic_t active_intr; struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS]; @@ -242,6 +246,12 @@ static const struct { {500000, BMC150_ACCEL_SLEEP_500_MS}, {1000000, BMC150_ACCEL_SLEEP_1_SEC} }; +static const struct regmap_config bmc150_i2c_regmap_conf = { + .reg_bits = 8, + .val_bits = 8, + .max_register = 0x3f, +}; + static int bmc150_accel_set_mode(struct bmc150_accel_data *data, enum bmc150_power_modes mode, int dur_us) @@ -269,12 +279,11 @@ static int bmc150_accel_set_mode(struct bmc150_accel_data *data, lpw_bits = mode << BMC150_ACCEL_PMU_MODE_SHIFT; lpw_bits |= (dur_val << BMC150_ACCEL_PMU_BIT_SLEEP_DUR_SHIFT); - dev_dbg(&data->client->dev, "Set Mode bits %x\n", lpw_bits); + dev_dbg(data->dev, "Set Mode bits %x\n", lpw_bits); - ret = i2c_smbus_write_byte_data(data->client, - BMC150_ACCEL_REG_PMU_LPW, lpw_bits); + ret = regmap_write(data->regmap, BMC150_ACCEL_REG_PMU_LPW, lpw_bits); if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_pmu_lpw\n"); + dev_err(data->dev, "Error writing reg_pmu_lpw\n"); return ret; } @@ -290,8 +299,7 @@ static int bmc150_accel_set_bw(struct bmc150_accel_data *data, int val, for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) { if (bmc150_accel_samp_freq_table[i].val == val && bmc150_accel_samp_freq_table[i].val2 == val2) { - ret = i2c_smbus_write_byte_data( - data->client, + ret = regmap_write(data->regmap, BMC150_ACCEL_REG_PMU_BW, bmc150_accel_samp_freq_table[i].bw_bits); if (ret < 0) @@ -308,30 +316,23 @@ static int bmc150_accel_set_bw(struct bmc150_accel_data *data, int val, static int bmc150_accel_update_slope(struct bmc150_accel_data *data) { - int ret, val; + int ret; - ret = i2c_smbus_write_byte_data(data->client, BMC150_ACCEL_REG_INT_6, + ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_6, data->slope_thres); if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_int_6\n"); + dev_err(data->dev, "Error writing reg_int_6\n"); return ret; } - ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_INT_5); + ret = regmap_update_bits(data->regmap, BMC150_ACCEL_REG_INT_5, + BMC150_ACCEL_SLOPE_DUR_MASK, data->slope_dur); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_int_5\n"); + dev_err(data->dev, "Error updating reg_int_5\n"); return ret; } - val = (ret & ~BMC150_ACCEL_SLOPE_DUR_MASK) | data->slope_dur; - ret = i2c_smbus_write_byte_data(data->client, BMC150_ACCEL_REG_INT_5, - val); - if (ret < 0) { - dev_err(&data->client->dev, "Error write reg_int_5\n"); - return ret; - } - - dev_dbg(&data->client->dev, "%s: %x %x\n", __func__, data->slope_thres, + dev_dbg(data->dev, "%s: %x %x\n", __func__, data->slope_thres, data->slope_dur); return ret; @@ -380,17 +381,17 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on) int ret; if (on) { - ret = pm_runtime_get_sync(&data->client->dev); + ret = pm_runtime_get_sync(data->dev); } else { - pm_runtime_mark_last_busy(&data->client->dev); - ret = pm_runtime_put_autosuspend(&data->client->dev); + pm_runtime_mark_last_busy(data->dev); + ret = pm_runtime_put_autosuspend(data->dev); } if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Failed: bmc150_accel_set_power_state for %d\n", on); if (on) - pm_runtime_put_noidle(&data->client->dev); + pm_runtime_put_noidle(data->dev); return ret; } @@ -470,38 +471,18 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i, return ret; /* map the interrupt to the appropriate pins */ - ret = i2c_smbus_read_byte_data(data->client, info->map_reg); + ret = regmap_update_bits(data->regmap, info->map_reg, info->map_bitmask, + (state ? info->map_bitmask : 0)); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_int_map\n"); - goto out_fix_power_state; - } - if (state) - ret |= info->map_bitmask; - else - ret &= ~info->map_bitmask; - - ret = i2c_smbus_write_byte_data(data->client, info->map_reg, - ret); - if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_int_map\n"); + dev_err(data->dev, "Error updating reg_int_map\n"); goto out_fix_power_state; } /* enable/disable the interrupt */ - ret = i2c_smbus_read_byte_data(data->client, info->en_reg); + ret = regmap_update_bits(data->regmap, info->en_reg, info->en_bitmask, + (state ? info->en_bitmask : 0)); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_int_en\n"); - goto out_fix_power_state; - } - - if (state) - ret |= info->en_bitmask; - else - ret &= ~info->en_bitmask; - - ret = i2c_smbus_write_byte_data(data->client, info->en_reg, ret); - if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_int_en\n"); + dev_err(data->dev, "Error updating reg_int_en\n"); goto out_fix_power_state; } @@ -523,12 +504,11 @@ static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val) for (i = 0; i < ARRAY_SIZE(data->chip_info->scale_table); ++i) { if (data->chip_info->scale_table[i].scale == val) { - ret = i2c_smbus_write_byte_data( - data->client, + ret = regmap_write(data->regmap, BMC150_ACCEL_REG_PMU_RANGE, data->chip_info->scale_table[i].reg_range); if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Error writing pmu_range\n"); return ret; } @@ -544,16 +524,17 @@ static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val) static int bmc150_accel_get_temp(struct bmc150_accel_data *data, int *val) { int ret; + unsigned int value; mutex_lock(&data->mutex); - ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_TEMP); + ret = regmap_read(data->regmap, BMC150_ACCEL_REG_TEMP, &value); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_temp\n"); + dev_err(data->dev, "Error reading reg_temp\n"); mutex_unlock(&data->mutex); return ret; } - *val = sign_extend32(ret, 7); + *val = sign_extend32(value, 7); mutex_unlock(&data->mutex); @@ -566,6 +547,7 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data, { int ret; int axis = chan->scan_index; + unsigned int raw_val; mutex_lock(&data->mutex); ret = bmc150_accel_set_power_state(data, true); @@ -574,15 +556,15 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data, return ret; } - ret = i2c_smbus_read_word_data(data->client, - BMC150_ACCEL_AXIS_TO_REG(axis)); + ret = regmap_bulk_read(data->regmap, BMC150_ACCEL_AXIS_TO_REG(axis), + &raw_val, 2); if (ret < 0) { - dev_err(&data->client->dev, "Error reading axis %d\n", axis); + dev_err(data->dev, "Error reading axis %d\n", axis); bmc150_accel_set_power_state(data, false); mutex_unlock(&data->mutex); return ret; } - *val = sign_extend32(ret >> chan->scan_type.shift, + *val = sign_extend32(raw_val >> chan->scan_type.shift, chan->scan_type.realbits - 1); ret = bmc150_accel_set_power_state(data, false); mutex_unlock(&data->mutex); @@ -846,52 +828,34 @@ static int bmc150_accel_set_watermark(struct iio_dev *indio_dev, unsigned val) * We must read at least one full frame in one burst, otherwise the rest of the * frame data is discarded. */ -static int bmc150_accel_fifo_transfer(const struct i2c_client *client, +static int bmc150_accel_fifo_transfer(struct bmc150_accel_data *data, char *buffer, int samples) { int sample_length = 3 * 2; - u8 reg_fifo_data = BMC150_ACCEL_REG_FIFO_DATA; - int ret = -EIO; + int ret; + int total_length = samples * sample_length; + int i; + size_t step = regmap_get_raw_read_max(data->regmap); - if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - struct i2c_msg msg[2] = { - { - .addr = client->addr, - .flags = 0, - .buf = ®_fifo_data, - .len = sizeof(reg_fifo_data), - }, - { - .addr = client->addr, - .flags = I2C_M_RD, - .buf = (u8 *)buffer, - .len = samples * sample_length, - } - }; + if (!step || step > total_length) + step = total_length; + else if (step < total_length) + step = sample_length; - ret = i2c_transfer(client->adapter, msg, 2); - if (ret != 2) - ret = -EIO; - else - ret = 0; - } else { - int i, step = I2C_SMBUS_BLOCK_MAX / sample_length; - - for (i = 0; i < samples * sample_length; i += step) { - ret = i2c_smbus_read_i2c_block_data(client, - reg_fifo_data, step, - &buffer[i]); - if (ret != step) { - ret = -EIO; - break; - } - - ret = 0; - } + /* + * Seems we have a bus with size limitation so we have to execute + * multiple reads + */ + for (i = 0; i < total_length; i += step) { + ret = regmap_raw_read(data->regmap, BMC150_ACCEL_REG_FIFO_DATA, + &buffer[i], step); + if (ret) + break; } if (ret) - dev_err(&client->dev, "Error transferring data from fifo\n"); + dev_err(data->dev, "Error transferring data from fifo in single steps of %zu\n", + step); return ret; } @@ -905,15 +869,15 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev, u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3]; int64_t tstamp; uint64_t sample_period; + unsigned int val; - ret = i2c_smbus_read_byte_data(data->client, - BMC150_ACCEL_REG_FIFO_STATUS); + ret = regmap_read(data->regmap, BMC150_ACCEL_REG_FIFO_STATUS, &val); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_fifo_status\n"); + dev_err(data->dev, "Error reading reg_fifo_status\n"); return ret; } - count = ret & 0x7F; + count = val & 0x7F; if (!count) return 0; @@ -952,7 +916,7 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev, if (samples && count > samples) count = samples; - ret = bmc150_accel_fifo_transfer(data->client, (u8 *)buffer, count); + ret = bmc150_accel_fifo_transfer(data, (u8 *)buffer, count); if (ret) return ret; @@ -1052,15 +1016,6 @@ static const struct iio_chan_spec bmc150_accel_channels[] = static const struct iio_chan_spec bma280_accel_channels[] = BMC150_ACCEL_CHANNELS(14); -enum { - bmc150, - bmi055, - bma255, - bma250e, - bma222e, - bma280, -}; - static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = { [bmc150] = { .name = "BMC150A", @@ -1155,17 +1110,19 @@ static irqreturn_t bmc150_accel_trigger_handler(int irq, void *p) struct iio_dev *indio_dev = pf->indio_dev; struct bmc150_accel_data *data = iio_priv(indio_dev); int bit, ret, i = 0; + unsigned int raw_val; mutex_lock(&data->mutex); for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->masklength) { - ret = i2c_smbus_read_word_data(data->client, - BMC150_ACCEL_AXIS_TO_REG(bit)); + ret = regmap_bulk_read(data->regmap, + BMC150_ACCEL_AXIS_TO_REG(bit), &raw_val, + 2); if (ret < 0) { mutex_unlock(&data->mutex); goto err_read; } - data->buffer[i++] = ret; + data->buffer[i++] = raw_val; } mutex_unlock(&data->mutex); @@ -1189,13 +1146,12 @@ static int bmc150_accel_trig_try_reen(struct iio_trigger *trig) mutex_lock(&data->mutex); /* clear any latched interrupt */ - ret = i2c_smbus_write_byte_data(data->client, - BMC150_ACCEL_REG_INT_RST_LATCH, - BMC150_ACCEL_INT_MODE_LATCH_INT | - BMC150_ACCEL_INT_MODE_LATCH_RESET); + ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH, + BMC150_ACCEL_INT_MODE_LATCH_INT | + BMC150_ACCEL_INT_MODE_LATCH_RESET); mutex_unlock(&data->mutex); if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Error writing reg_int_rst_latch\n"); return ret; } @@ -1249,20 +1205,20 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev) struct bmc150_accel_data *data = iio_priv(indio_dev); int dir; int ret; + unsigned int val; - ret = i2c_smbus_read_byte_data(data->client, - BMC150_ACCEL_REG_INT_STATUS_2); + ret = regmap_read(data->regmap, BMC150_ACCEL_REG_INT_STATUS_2, &val); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_int_status_2\n"); + dev_err(data->dev, "Error reading reg_int_status_2\n"); return ret; } - if (ret & BMC150_ACCEL_ANY_MOTION_BIT_SIGN) + if (val & BMC150_ACCEL_ANY_MOTION_BIT_SIGN) dir = IIO_EV_DIR_FALLING; else dir = IIO_EV_DIR_RISING; - if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X) + if (val & BMC150_ACCEL_ANY_MOTION_BIT_X) iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, @@ -1271,7 +1227,7 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev) dir), data->timestamp); - if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y) + if (val & BMC150_ACCEL_ANY_MOTION_BIT_Y) iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, @@ -1280,7 +1236,7 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev) dir), data->timestamp); - if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z) + if (val & BMC150_ACCEL_ANY_MOTION_BIT_Z) iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, @@ -1315,13 +1271,11 @@ static irqreturn_t bmc150_accel_irq_thread_handler(int irq, void *private) } if (ack) { - ret = i2c_smbus_write_byte_data(data->client, - BMC150_ACCEL_REG_INT_RST_LATCH, - BMC150_ACCEL_INT_MODE_LATCH_INT | - BMC150_ACCEL_INT_MODE_LATCH_RESET); + ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH, + BMC150_ACCEL_INT_MODE_LATCH_INT | + BMC150_ACCEL_INT_MODE_LATCH_RESET); if (ret) - dev_err(&data->client->dev, - "Error writing reg_int_rst_latch\n"); + dev_err(data->dev, "Error writing reg_int_rst_latch\n"); ret = IRQ_HANDLED; } else { @@ -1360,32 +1314,6 @@ static irqreturn_t bmc150_accel_irq_handler(int irq, void *private) return IRQ_NONE; } -static int bmc150_accel_gpio_probe(struct i2c_client *client, - struct bmc150_accel_data *data) -{ - struct device *dev; - struct gpio_desc *gpio; - int ret; - - if (!client) - return -EINVAL; - - dev = &client->dev; - - /* data ready gpio interrupt pin */ - gpio = devm_gpiod_get_index(dev, BMC150_ACCEL_GPIO_NAME, 0, GPIOD_IN); - if (IS_ERR(gpio)) { - dev_err(dev, "Failed: gpio get index\n"); - return PTR_ERR(gpio); - } - - ret = gpiod_to_irq(gpio); - - dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); - - return ret; -} - static const struct { int intr; const char *name; @@ -1423,7 +1351,7 @@ static int bmc150_accel_triggers_setup(struct iio_dev *indio_dev, for (i = 0; i < BMC150_ACCEL_TRIGGERS; i++) { struct bmc150_accel_trigger *t = &data->triggers[i]; - t->indio_trig = devm_iio_trigger_alloc(&data->client->dev, + t->indio_trig = devm_iio_trigger_alloc(data->dev, bmc150_accel_triggers[i].name, indio_dev->name, indio_dev->id); @@ -1432,7 +1360,7 @@ static int bmc150_accel_triggers_setup(struct iio_dev *indio_dev, break; } - t->indio_trig->dev.parent = &data->client->dev; + t->indio_trig->dev.parent = data->dev; t->indio_trig->ops = &bmc150_accel_trigger_ops; t->intr = bmc150_accel_triggers[i].intr; t->data = data; @@ -1459,20 +1387,19 @@ static int bmc150_accel_fifo_set_mode(struct bmc150_accel_data *data) u8 reg = BMC150_ACCEL_REG_FIFO_CONFIG1; int ret; - ret = i2c_smbus_write_byte_data(data->client, reg, data->fifo_mode); + ret = regmap_write(data->regmap, reg, data->fifo_mode); if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_fifo_config1\n"); + dev_err(data->dev, "Error writing reg_fifo_config1\n"); return ret; } if (!data->fifo_mode) return 0; - ret = i2c_smbus_write_byte_data(data->client, - BMC150_ACCEL_REG_FIFO_CONFIG0, - data->watermark); + ret = regmap_write(data->regmap, BMC150_ACCEL_REG_FIFO_CONFIG0, + data->watermark); if (ret < 0) - dev_err(&data->client->dev, "Error writing reg_fifo_config0\n"); + dev_err(data->dev, "Error writing reg_fifo_config0\n"); return ret; } @@ -1557,23 +1484,25 @@ static const struct iio_buffer_setup_ops bmc150_accel_buffer_ops = { static int bmc150_accel_chip_init(struct bmc150_accel_data *data) { int ret, i; + unsigned int val; - ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_CHIP_ID); + ret = regmap_read(data->regmap, BMC150_ACCEL_REG_CHIP_ID, &val); if (ret < 0) { - dev_err(&data->client->dev, "Error: Reading chip id\n"); + dev_err(data->dev, + "Error: Reading chip id\n"); return ret; } - dev_dbg(&data->client->dev, "Chip Id %x\n", ret); + dev_dbg(data->dev, "Chip Id %x\n", val); for (i = 0; i < ARRAY_SIZE(bmc150_accel_chip_info_tbl); i++) { - if (bmc150_accel_chip_info_tbl[i].chip_id == ret) { + if (bmc150_accel_chip_info_tbl[i].chip_id == val) { data->chip_info = &bmc150_accel_chip_info_tbl[i]; break; } } if (!data->chip_info) { - dev_err(&data->client->dev, "Unsupported chip %x\n", ret); + dev_err(data->dev, "Invalid chip %x\n", val); return -ENODEV; } @@ -1587,11 +1516,11 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data) return ret; /* Set Default Range */ - ret = i2c_smbus_write_byte_data(data->client, - BMC150_ACCEL_REG_PMU_RANGE, - BMC150_ACCEL_DEF_RANGE_4G); + ret = regmap_write(data->regmap, BMC150_ACCEL_REG_PMU_RANGE, + BMC150_ACCEL_DEF_RANGE_4G); if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_pmu_range\n"); + dev_err(data->dev, + "Error writing reg_pmu_range\n"); return ret; } @@ -1605,12 +1534,11 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data) return ret; /* Set default as latched interrupts */ - ret = i2c_smbus_write_byte_data(data->client, - BMC150_ACCEL_REG_INT_RST_LATCH, - BMC150_ACCEL_INT_MODE_LATCH_INT | - BMC150_ACCEL_INT_MODE_LATCH_RESET); + ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH, + BMC150_ACCEL_INT_MODE_LATCH_INT | + BMC150_ACCEL_INT_MODE_LATCH_RESET); if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Error writing reg_int_rst_latch\n"); return ret; } @@ -1618,24 +1546,23 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data) return 0; } -static int bmc150_accel_probe(struct i2c_client *client, - const struct i2c_device_id *id) +int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, + const char *name, bool block_supported) { struct bmc150_accel_data *data; struct iio_dev *indio_dev; int ret; - const char *name = NULL; - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; data = iio_priv(indio_dev); - i2c_set_clientdata(client, indio_dev); - data->client = client; + dev_set_drvdata(dev, indio_dev); + data->dev = dev; + data->irq = irq; - if (id) - name = id->name; + data->regmap = regmap; ret = bmc150_accel_chip_init(data); if (ret < 0) @@ -1643,7 +1570,7 @@ static int bmc150_accel_probe(struct i2c_client *client, mutex_init(&data->mutex); - indio_dev->dev.parent = &client->dev; + indio_dev->dev.parent = dev; indio_dev->channels = data->chip_info->channels; indio_dev->num_channels = data->chip_info->num_channels; indio_dev->name = name ? name : data->chip_info->name; @@ -1655,16 +1582,13 @@ static int bmc150_accel_probe(struct i2c_client *client, bmc150_accel_trigger_handler, &bmc150_accel_buffer_ops); if (ret < 0) { - dev_err(&client->dev, "Failed: iio triggered buffer setup\n"); + dev_err(data->dev, "Failed: iio triggered buffer setup\n"); return ret; } - if (client->irq < 0) - client->irq = bmc150_accel_gpio_probe(client, data); - - if (client->irq > 0) { + if (data->irq > 0) { ret = devm_request_threaded_irq( - &client->dev, client->irq, + data->dev, data->irq, bmc150_accel_irq_handler, bmc150_accel_irq_thread_handler, IRQF_TRIGGER_RISING, @@ -1679,11 +1603,10 @@ static int bmc150_accel_probe(struct i2c_client *client, * want to use latch mode when we can to prevent interrupt * flooding. */ - ret = i2c_smbus_write_byte_data(data->client, - BMC150_ACCEL_REG_INT_RST_LATCH, - BMC150_ACCEL_INT_MODE_LATCH_RESET); + ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH, + BMC150_ACCEL_INT_MODE_LATCH_RESET); if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_int_rst_latch\n"); + dev_err(data->dev, "Error writing reg_int_rst_latch\n"); goto err_buffer_cleanup; } @@ -1693,9 +1616,7 @@ static int bmc150_accel_probe(struct i2c_client *client, if (ret) goto err_buffer_cleanup; - if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) || - i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { + if (block_supported) { indio_dev->modes |= INDIO_BUFFER_SOFTWARE; indio_dev->info = &bmc150_accel_info_fifo; indio_dev->buffer->attrs = bmc150_accel_fifo_attributes; @@ -1704,18 +1625,17 @@ static int bmc150_accel_probe(struct i2c_client *client, ret = iio_device_register(indio_dev); if (ret < 0) { - dev_err(&client->dev, "Unable to register iio device\n"); + dev_err(dev, "Unable to register iio device\n"); goto err_trigger_unregister; } - ret = pm_runtime_set_active(&client->dev); + ret = pm_runtime_set_active(dev); if (ret) goto err_iio_unregister; - pm_runtime_enable(&client->dev); - pm_runtime_set_autosuspend_delay(&client->dev, - BMC150_AUTO_SUSPEND_DELAY_MS); - pm_runtime_use_autosuspend(&client->dev); + pm_runtime_enable(dev); + pm_runtime_set_autosuspend_delay(dev, BMC150_AUTO_SUSPEND_DELAY_MS); + pm_runtime_use_autosuspend(dev); return 0; @@ -1728,15 +1648,16 @@ err_buffer_cleanup: return ret; } +EXPORT_SYMBOL_GPL(bmc150_accel_core_probe); -static int bmc150_accel_remove(struct i2c_client *client) +int bmc150_accel_core_remove(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(client); + struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmc150_accel_data *data = iio_priv(indio_dev); - pm_runtime_disable(&client->dev); - pm_runtime_set_suspended(&client->dev); - pm_runtime_put_noidle(&client->dev); + pm_runtime_disable(data->dev); + pm_runtime_set_suspended(data->dev); + pm_runtime_put_noidle(data->dev); iio_device_unregister(indio_dev); @@ -1750,11 +1671,12 @@ static int bmc150_accel_remove(struct i2c_client *client) return 0; } +EXPORT_SYMBOL_GPL(bmc150_accel_core_remove); #ifdef CONFIG_PM_SLEEP static int bmc150_accel_suspend(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmc150_accel_data *data = iio_priv(indio_dev); mutex_lock(&data->mutex); @@ -1766,7 +1688,7 @@ static int bmc150_accel_suspend(struct device *dev) static int bmc150_accel_resume(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmc150_accel_data *data = iio_priv(indio_dev); mutex_lock(&data->mutex); @@ -1782,11 +1704,11 @@ static int bmc150_accel_resume(struct device *dev) #ifdef CONFIG_PM static int bmc150_accel_runtime_suspend(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmc150_accel_data *data = iio_priv(indio_dev); int ret; - dev_dbg(&data->client->dev, __func__); + dev_dbg(data->dev, __func__); ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_SUSPEND, 0); if (ret < 0) return -EAGAIN; @@ -1796,12 +1718,12 @@ static int bmc150_accel_runtime_suspend(struct device *dev) static int bmc150_accel_runtime_resume(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmc150_accel_data *data = iio_priv(indio_dev); int ret; int sleep_val; - dev_dbg(&data->client->dev, __func__); + dev_dbg(data->dev, __func__); ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0); if (ret < 0) @@ -1820,47 +1742,12 @@ static int bmc150_accel_runtime_resume(struct device *dev) } #endif -static const struct dev_pm_ops bmc150_accel_pm_ops = { +const struct dev_pm_ops bmc150_accel_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(bmc150_accel_suspend, bmc150_accel_resume) SET_RUNTIME_PM_OPS(bmc150_accel_runtime_suspend, bmc150_accel_runtime_resume, NULL) }; - -static const struct acpi_device_id bmc150_accel_acpi_match[] = { - {"BSBA0150", bmc150}, - {"BMC150A", bmc150}, - {"BMI055A", bmi055}, - {"BMA0255", bma255}, - {"BMA250E", bma250e}, - {"BMA222E", bma222e}, - {"BMA0280", bma280}, - { }, -}; -MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match); - -static const struct i2c_device_id bmc150_accel_id[] = { - {"bmc150_accel", bmc150}, - {"bmi055_accel", bmi055}, - {"bma255", bma255}, - {"bma250e", bma250e}, - {"bma222e", bma222e}, - {"bma280", bma280}, - {} -}; - -MODULE_DEVICE_TABLE(i2c, bmc150_accel_id); - -static struct i2c_driver bmc150_accel_driver = { - .driver = { - .name = BMC150_ACCEL_DRV_NAME, - .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match), - .pm = &bmc150_accel_pm_ops, - }, - .probe = bmc150_accel_probe, - .remove = bmc150_accel_remove, - .id_table = bmc150_accel_id, -}; -module_i2c_driver(bmc150_accel_driver); +EXPORT_SYMBOL_GPL(bmc150_accel_pm_ops); MODULE_AUTHOR("Srinivas Pandruvada "); MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c new file mode 100644 index 000000000000..b41404ba32fc --- /dev/null +++ b/drivers/iio/accel/bmc150-accel-i2c.c @@ -0,0 +1,102 @@ +/* + * 3-axis accelerometer driver supporting following I2C Bosch-Sensortec chips: + * - BMC150 + * - BMI055 + * - BMA255 + * - BMA250E + * - BMA222E + * - BMA280 + * + * Copyright (c) 2014, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 +#include +#include +#include + +#include "bmc150-accel.h" + +static const struct regmap_config bmc150_i2c_regmap_conf = { + .reg_bits = 8, + .val_bits = 8, +}; + +static int bmc150_accel_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct regmap *regmap; + const char *name = NULL; + bool block_supported = + i2c_check_functionality(client->adapter, I2C_FUNC_I2C) || + i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_READ_I2C_BLOCK); + + regmap = devm_regmap_init_i2c(client, &bmc150_i2c_regmap_conf); + if (IS_ERR(regmap)) { + dev_err(&client->dev, "Failed to initialize i2c regmap\n"); + return PTR_ERR(regmap); + } + + if (id) + name = id->name; + + return bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, + block_supported); +} + +static int bmc150_accel_remove(struct i2c_client *client) +{ + return bmc150_accel_core_remove(&client->dev); +} + +static const struct acpi_device_id bmc150_accel_acpi_match[] = { + {"BSBA0150", bmc150}, + {"BMC150A", bmc150}, + {"BMI055A", bmi055}, + {"BMA0255", bma255}, + {"BMA250E", bma250e}, + {"BMA222E", bma222e}, + {"BMA0280", bma280}, + { }, +}; +MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match); + +static const struct i2c_device_id bmc150_accel_id[] = { + {"bmc150_accel", bmc150}, + {"bmi055_accel", bmi055}, + {"bma255", bma255}, + {"bma250e", bma250e}, + {"bma222e", bma222e}, + {"bma280", bma280}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, bmc150_accel_id); + +static struct i2c_driver bmc150_accel_driver = { + .driver = { + .name = "bmc150_accel_i2c", + .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match), + .pm = &bmc150_accel_pm_ops, + }, + .probe = bmc150_accel_probe, + .remove = bmc150_accel_remove, + .id_table = bmc150_accel_id, +}; +module_i2c_driver(bmc150_accel_driver); + +MODULE_AUTHOR("Srinivas Pandruvada "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("BMC150 I2C accelerometer driver"); diff --git a/drivers/iio/accel/bmc150-accel-spi.c b/drivers/iio/accel/bmc150-accel-spi.c new file mode 100644 index 000000000000..16b66f2a7204 --- /dev/null +++ b/drivers/iio/accel/bmc150-accel-spi.c @@ -0,0 +1,91 @@ +/* + * 3-axis accelerometer driver supporting SPI Bosch-Sensortec accelerometer chip + * Copyright © 2015 Pengutronix, Markus Pargmann + * + * 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, see . + */ + +#include +#include +#include +#include +#include +#include + +#include "bmc150-accel.h" + +static const struct regmap_config bmc150_spi_regmap_conf = { + .reg_bits = 8, + .val_bits = 8, + .max_register = 0x3f, +}; + +static int bmc150_accel_probe(struct spi_device *spi) +{ + struct regmap *regmap; + const struct spi_device_id *id = spi_get_device_id(spi); + + regmap = devm_regmap_init_spi(spi, &bmc150_spi_regmap_conf); + if (IS_ERR(regmap)) { + dev_err(&spi->dev, "Failed to initialize spi regmap\n"); + return PTR_ERR(regmap); + } + + return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name, + true); +} + +static int bmc150_accel_remove(struct spi_device *spi) +{ + return bmc150_accel_core_remove(&spi->dev); +} + +static const struct acpi_device_id bmc150_accel_acpi_match[] = { + {"BSBA0150", bmc150}, + {"BMC150A", bmc150}, + {"BMI055A", bmi055}, + {"BMA0255", bma255}, + {"BMA250E", bma250e}, + {"BMA222E", bma222e}, + {"BMA0280", bma280}, + { }, +}; +MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match); + +static const struct spi_device_id bmc150_accel_id[] = { + {"bmc150_accel", bmc150}, + {"bmi055_accel", bmi055}, + {"bma255", bma255}, + {"bma250e", bma250e}, + {"bma222e", bma222e}, + {"bma280", bma280}, + {} +}; +MODULE_DEVICE_TABLE(spi, bmc150_accel_id); + +static struct spi_driver bmc150_accel_driver = { + .driver = { + .name = "bmc150_accel_spi", + .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match), + .pm = &bmc150_accel_pm_ops, + }, + .probe = bmc150_accel_probe, + .remove = bmc150_accel_remove, + .id_table = bmc150_accel_id, +}; +module_spi_driver(bmc150_accel_driver); + +MODULE_AUTHOR("Markus Pargmann "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("BMC150 SPI accelerometer driver"); diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h new file mode 100644 index 000000000000..ba0335987f94 --- /dev/null +++ b/drivers/iio/accel/bmc150-accel.h @@ -0,0 +1,20 @@ +#ifndef _BMC150_ACCEL_H_ +#define _BMC150_ACCEL_H_ + +struct regmap; + +enum { + bmc150, + bmi055, + bma255, + bma250e, + bma222e, + bma280, +}; + +int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, + const char *name, bool block_supported); +int bmc150_accel_core_remove(struct device *dev); +extern const struct dev_pm_ops bmc150_accel_pm_ops; + +#endif /* _BMC150_ACCEL_H_ */ diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c index 3292bc0c1d0e..18c1b06684c1 100644 --- a/drivers/iio/accel/kxcjk-1013.c +++ b/drivers/iio/accel/kxcjk-1013.c @@ -1162,35 +1162,6 @@ static const char *kxcjk1013_match_acpi_device(struct device *dev, return dev_name(dev); } -static int kxcjk1013_gpio_probe(struct i2c_client *client, - struct kxcjk1013_data *data) -{ - struct device *dev; - struct gpio_desc *gpio; - int ret; - - if (!client) - return -EINVAL; - - if (data->is_smo8500_device) - return -ENOTSUPP; - - dev = &client->dev; - - /* data ready gpio interrupt pin */ - gpio = devm_gpiod_get_index(dev, "kxcjk1013_int", 0, GPIOD_IN); - if (IS_ERR(gpio)) { - dev_err(dev, "acpi gpio get index failed\n"); - return PTR_ERR(gpio); - } - - ret = gpiod_to_irq(gpio); - - dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); - - return ret; -} - static int kxcjk1013_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1237,10 +1208,7 @@ static int kxcjk1013_probe(struct i2c_client *client, indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &kxcjk1013_info; - if (client->irq < 0) - client->irq = kxcjk1013_gpio_probe(client, data); - - if (client->irq > 0) { + if (client->irq > 0 && !data->is_smo8500_device) { ret = devm_request_threaded_irq(&client->dev, client->irq, kxcjk1013_data_rdy_trig_poll, kxcjk1013_event_handler, diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c index b921d84c1be6..1eccc2dcf14c 100644 --- a/drivers/iio/accel/mma8452.c +++ b/drivers/iio/accel/mma8452.c @@ -1,6 +1,12 @@ /* - * mma8452.c - Support for Freescale MMA8452Q 3-axis 12-bit accelerometer + * mma8452.c - Support for following Freescale 3-axis accelerometers: * + * MMA8452Q (12 bit) + * MMA8453Q (10 bit) + * MMA8652FC (12 bit) + * MMA8653FC (10 bit) + * + * Copyright 2015 Martin Kepplinger * Copyright 2014 Peter Meerwald * * This file is subject to the terms and conditions of version 2 of @@ -22,10 +28,11 @@ #include #include #include +#include #define MMA8452_STATUS 0x00 #define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0)) -#define MMA8452_OUT_X 0x01 /* MSB first, 12-bit */ +#define MMA8452_OUT_X 0x01 /* MSB first */ #define MMA8452_OUT_Y 0x03 #define MMA8452_OUT_Z 0x05 #define MMA8452_INT_SRC 0x0c @@ -38,6 +45,16 @@ #define MMA8452_DATA_CFG_HPF_MASK BIT(4) #define MMA8452_HP_FILTER_CUTOFF 0x0f #define MMA8452_HP_FILTER_CUTOFF_SEL_MASK GENMASK(1, 0) +#define MMA8452_FF_MT_CFG 0x15 +#define MMA8452_FF_MT_CFG_OAE BIT(6) +#define MMA8452_FF_MT_CFG_ELE BIT(7) +#define MMA8452_FF_MT_SRC 0x16 +#define MMA8452_FF_MT_SRC_XHE BIT(1) +#define MMA8452_FF_MT_SRC_YHE BIT(3) +#define MMA8452_FF_MT_SRC_ZHE BIT(5) +#define MMA8452_FF_MT_THS 0x17 +#define MMA8452_FF_MT_THS_MASK 0x7f +#define MMA8452_FF_MT_COUNT 0x18 #define MMA8452_TRANSIENT_CFG 0x1d #define MMA8452_TRANSIENT_CFG_HPF_BYP BIT(0) #define MMA8452_TRANSIENT_CFG_CHAN(chan) BIT(chan + 1) @@ -65,15 +82,65 @@ #define MMA8452_MAX_REG 0x31 #define MMA8452_INT_DRDY BIT(0) +#define MMA8452_INT_FF_MT BIT(2) #define MMA8452_INT_TRANS BIT(5) #define MMA8452_DEVICE_ID 0x2a +#define MMA8453_DEVICE_ID 0x3a +#define MMA8652_DEVICE_ID 0x4a +#define MMA8653_DEVICE_ID 0x5a struct mma8452_data { struct i2c_client *client; struct mutex lock; u8 ctrl_reg1; u8 data_cfg; + const struct mma_chip_info *chip_info; +}; + +/** + * struct mma_chip_info - chip specific data for Freescale's accelerometers + * @chip_id: WHO_AM_I register's value + * @channels: struct iio_chan_spec matching the device's + * capabilities + * @num_channels: number of channels + * @mma_scales: scale factors for converting register values + * to m/s^2; 3 modes: 2g, 4g, 8g; 2 integers + * per mode: m/s^2 and micro m/s^2 + * @ev_cfg: event config register address + * @ev_cfg_ele: latch bit in event config register + * @ev_cfg_chan_shift: number of the bit to enable events in X + * direction; in event config register + * @ev_src: event source register address + * @ev_src_xe: bit in event source register that indicates + * an event in X direction + * @ev_src_ye: bit in event source register that indicates + * an event in Y direction + * @ev_src_ze: bit in event source register that indicates + * an event in Z direction + * @ev_ths: event threshold register address + * @ev_ths_mask: mask for the threshold value + * @ev_count: event count (period) register address + * + * Since not all chips supported by the driver support comparing high pass + * filtered data for events (interrupts), different interrupt sources are + * used for different chips and the relevant registers are included here. + */ +struct mma_chip_info { + u8 chip_id; + const struct iio_chan_spec *channels; + int num_channels; + const int mma_scales[3][2]; + u8 ev_cfg; + u8 ev_cfg_ele; + u8 ev_cfg_chan_shift; + u8 ev_src; + u8 ev_src_xe; + u8 ev_src_ye; + u8 ev_src_ze; + u8 ev_ths; + u8 ev_ths_mask; + u8 ev_count; }; static int mma8452_drdy(struct mma8452_data *data) @@ -143,16 +210,6 @@ static const int mma8452_samp_freq[8][2] = { {6, 250000}, {1, 560000} }; -/* - * Hardware has fullscale of -2G, -4G, -8G corresponding to raw value -2048 - * The userspace interface uses m/s^2 and we declare micro units - * So scale factor is given by: - * g * N * 1000000 / 2048 for N = 2, 4, 8 and g = 9.80665 - */ -static const int mma8452_scales[3][2] = { - {0, 9577}, {0, 19154}, {0, 38307} -}; - /* Datasheet table 35 (step time vs sample frequency) */ static const int mma8452_transient_time_step_us[8] = { 1250, @@ -189,8 +246,11 @@ static ssize_t mma8452_show_scale_avail(struct device *dev, struct device_attribute *attr, char *buf) { - return mma8452_show_int_plus_micros(buf, mma8452_scales, - ARRAY_SIZE(mma8452_scales)); + struct mma8452_data *data = iio_priv(i2c_get_clientdata( + to_i2c_client(dev))); + + return mma8452_show_int_plus_micros(buf, data->chip_info->mma_scales, + ARRAY_SIZE(data->chip_info->mma_scales)); } static ssize_t mma8452_show_hp_cutoff_avail(struct device *dev, @@ -221,9 +281,8 @@ static int mma8452_get_samp_freq_index(struct mma8452_data *data, static int mma8452_get_scale_index(struct mma8452_data *data, int val, int val2) { - return mma8452_get_int_plus_micros_index(mma8452_scales, - ARRAY_SIZE(mma8452_scales), - val, val2); + return mma8452_get_int_plus_micros_index(data->chip_info->mma_scales, + ARRAY_SIZE(data->chip_info->mma_scales), val, val2); } static int mma8452_get_hp_filter_index(struct mma8452_data *data, @@ -270,14 +329,15 @@ static int mma8452_read_raw(struct iio_dev *indio_dev, if (ret < 0) return ret; - *val = sign_extend32(be16_to_cpu(buffer[chan->scan_index]) >> 4, - 11); + *val = sign_extend32(be16_to_cpu( + buffer[chan->scan_index]) >> chan->scan_type.shift, + chan->scan_type.realbits - 1); return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: i = data->data_cfg & MMA8452_DATA_CFG_FS_MASK; - *val = mma8452_scales[i][0]; - *val2 = mma8452_scales[i][1]; + *val = data->chip_info->mma_scales[i][0]; + *val2 = data->chip_info->mma_scales[i][1]; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_SAMP_FREQ: @@ -439,17 +499,17 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev, switch (info) { case IIO_EV_INFO_VALUE: ret = i2c_smbus_read_byte_data(data->client, - MMA8452_TRANSIENT_THS); + data->chip_info->ev_ths); if (ret < 0) return ret; - *val = ret & MMA8452_TRANSIENT_THS_MASK; + *val = ret & data->chip_info->ev_ths_mask; return IIO_VAL_INT; case IIO_EV_INFO_PERIOD: ret = i2c_smbus_read_byte_data(data->client, - MMA8452_TRANSIENT_COUNT); + data->chip_info->ev_count); if (ret < 0) return ret; @@ -497,7 +557,8 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev, if (val < 0 || val > MMA8452_TRANSIENT_THS_MASK) return -EINVAL; - return mma8452_change_config(data, MMA8452_TRANSIENT_THS, val); + return mma8452_change_config(data, data->chip_info->ev_ths, + val); case IIO_EV_INFO_PERIOD: steps = (val * USEC_PER_SEC + val2) / @@ -507,7 +568,7 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev, if (steps < 0 || steps > 0xff) return -EINVAL; - return mma8452_change_config(data, MMA8452_TRANSIENT_COUNT, + return mma8452_change_config(data, data->chip_info->ev_count, steps); case IIO_EV_INFO_HIGH_PASS_FILTER_3DB: @@ -538,13 +599,15 @@ static int mma8452_read_event_config(struct iio_dev *indio_dev, enum iio_event_direction dir) { struct mma8452_data *data = iio_priv(indio_dev); + const struct mma_chip_info *chip = data->chip_info; int ret; - ret = i2c_smbus_read_byte_data(data->client, MMA8452_TRANSIENT_CFG); + ret = i2c_smbus_read_byte_data(data->client, + data->chip_info->ev_cfg); if (ret < 0) return ret; - return ret & MMA8452_TRANSIENT_CFG_CHAN(chan->scan_index) ? 1 : 0; + return !!(ret & BIT(chan->scan_index + chip->ev_cfg_chan_shift)); } static int mma8452_write_event_config(struct iio_dev *indio_dev, @@ -554,20 +617,22 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev, int state) { struct mma8452_data *data = iio_priv(indio_dev); + const struct mma_chip_info *chip = data->chip_info; int val; - val = i2c_smbus_read_byte_data(data->client, MMA8452_TRANSIENT_CFG); + val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg); if (val < 0) return val; if (state) - val |= MMA8452_TRANSIENT_CFG_CHAN(chan->scan_index); + val |= BIT(chan->scan_index + chip->ev_cfg_chan_shift); else - val &= ~MMA8452_TRANSIENT_CFG_CHAN(chan->scan_index); + val &= ~BIT(chan->scan_index + chip->ev_cfg_chan_shift); - val |= MMA8452_TRANSIENT_CFG_ELE; + val |= chip->ev_cfg_ele; + val |= MMA8452_FF_MT_CFG_OAE; - return mma8452_change_config(data, MMA8452_TRANSIENT_CFG, val); + return mma8452_change_config(data, chip->ev_cfg, val); } static void mma8452_transient_interrupt(struct iio_dev *indio_dev) @@ -576,25 +641,25 @@ static void mma8452_transient_interrupt(struct iio_dev *indio_dev) s64 ts = iio_get_time_ns(); int src; - src = i2c_smbus_read_byte_data(data->client, MMA8452_TRANSIENT_SRC); + src = i2c_smbus_read_byte_data(data->client, data->chip_info->ev_src); if (src < 0) return; - if (src & MMA8452_TRANSIENT_SRC_XTRANSE) + if (src & data->chip_info->ev_src_xe) iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X, IIO_EV_TYPE_MAG, IIO_EV_DIR_RISING), ts); - if (src & MMA8452_TRANSIENT_SRC_YTRANSE) + if (src & data->chip_info->ev_src_ye) iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_Y, IIO_EV_TYPE_MAG, IIO_EV_DIR_RISING), ts); - if (src & MMA8452_TRANSIENT_SRC_ZTRANSE) + if (src & data->chip_info->ev_src_ze) iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_Z, IIO_EV_TYPE_MAG, @@ -606,6 +671,7 @@ static irqreturn_t mma8452_interrupt(int irq, void *p) { struct iio_dev *indio_dev = p; struct mma8452_data *data = iio_priv(indio_dev); + const struct mma_chip_info *chip = data->chip_info; int ret = IRQ_NONE; int src; @@ -618,7 +684,10 @@ static irqreturn_t mma8452_interrupt(int irq, void *p) ret = IRQ_HANDLED; } - if (src & MMA8452_INT_TRANS) { + if ((src & MMA8452_INT_TRANS && + chip->ev_src == MMA8452_TRANSIENT_SRC) || + (src & MMA8452_INT_FF_MT && + chip->ev_src == MMA8452_FF_MT_SRC)) { mma8452_transient_interrupt(indio_dev); ret = IRQ_HANDLED; } @@ -680,6 +749,16 @@ static const struct iio_event_spec mma8452_transient_event[] = { }, }; +static const struct iio_event_spec mma8452_motion_event[] = { + { + .type = IIO_EV_TYPE_MAG, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_ENABLE), + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_PERIOD) + }, +}; + /* * Threshold is configured in fixed 8G/127 steps regardless of * currently selected scale for measurement. @@ -693,10 +772,9 @@ static struct attribute *mma8452_event_attributes[] = { static struct attribute_group mma8452_event_attribute_group = { .attrs = mma8452_event_attributes, - .name = "events", }; -#define MMA8452_CHANNEL(axis, idx) { \ +#define MMA8452_CHANNEL(axis, idx, bits) { \ .type = IIO_ACCEL, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ @@ -708,22 +786,144 @@ static struct attribute_group mma8452_event_attribute_group = { .scan_index = idx, \ .scan_type = { \ .sign = 's', \ - .realbits = 12, \ + .realbits = (bits), \ .storagebits = 16, \ - .shift = 4, \ + .shift = 16 - (bits), \ .endianness = IIO_BE, \ }, \ .event_spec = mma8452_transient_event, \ .num_event_specs = ARRAY_SIZE(mma8452_transient_event), \ } +#define MMA8652_CHANNEL(axis, idx, bits) { \ + .type = IIO_ACCEL, \ + .modified = 1, \ + .channel2 = IIO_MOD_##axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_CALIBBIAS), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = idx, \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + .shift = 16 - (bits), \ + .endianness = IIO_BE, \ + }, \ + .event_spec = mma8452_motion_event, \ + .num_event_specs = ARRAY_SIZE(mma8452_motion_event), \ +} + static const struct iio_chan_spec mma8452_channels[] = { - MMA8452_CHANNEL(X, 0), - MMA8452_CHANNEL(Y, 1), - MMA8452_CHANNEL(Z, 2), + MMA8452_CHANNEL(X, 0, 12), + MMA8452_CHANNEL(Y, 1, 12), + MMA8452_CHANNEL(Z, 2, 12), IIO_CHAN_SOFT_TIMESTAMP(3), }; +static const struct iio_chan_spec mma8453_channels[] = { + MMA8452_CHANNEL(X, 0, 10), + MMA8452_CHANNEL(Y, 1, 10), + MMA8452_CHANNEL(Z, 2, 10), + IIO_CHAN_SOFT_TIMESTAMP(3), +}; + +static const struct iio_chan_spec mma8652_channels[] = { + MMA8652_CHANNEL(X, 0, 12), + MMA8652_CHANNEL(Y, 1, 12), + MMA8652_CHANNEL(Z, 2, 12), + IIO_CHAN_SOFT_TIMESTAMP(3), +}; + +static const struct iio_chan_spec mma8653_channels[] = { + MMA8652_CHANNEL(X, 0, 10), + MMA8652_CHANNEL(Y, 1, 10), + MMA8652_CHANNEL(Z, 2, 10), + IIO_CHAN_SOFT_TIMESTAMP(3), +}; + +enum { + mma8452, + mma8453, + mma8652, + mma8653, +}; + +static const struct mma_chip_info mma_chip_info_table[] = { + [mma8452] = { + .chip_id = MMA8452_DEVICE_ID, + .channels = mma8452_channels, + .num_channels = ARRAY_SIZE(mma8452_channels), + /* + * Hardware has fullscale of -2G, -4G, -8G corresponding to + * raw value -2048 for 12 bit or -512 for 10 bit. + * The userspace interface uses m/s^2 and we declare micro units + * So scale factor for 12 bit here is given by: + * g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665 + */ + .mma_scales = { {0, 9577}, {0, 19154}, {0, 38307} }, + .ev_cfg = MMA8452_TRANSIENT_CFG, + .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE, + .ev_cfg_chan_shift = 1, + .ev_src = MMA8452_TRANSIENT_SRC, + .ev_src_xe = MMA8452_TRANSIENT_SRC_XTRANSE, + .ev_src_ye = MMA8452_TRANSIENT_SRC_YTRANSE, + .ev_src_ze = MMA8452_TRANSIENT_SRC_ZTRANSE, + .ev_ths = MMA8452_TRANSIENT_THS, + .ev_ths_mask = MMA8452_TRANSIENT_THS_MASK, + .ev_count = MMA8452_TRANSIENT_COUNT, + }, + [mma8453] = { + .chip_id = MMA8453_DEVICE_ID, + .channels = mma8453_channels, + .num_channels = ARRAY_SIZE(mma8453_channels), + .mma_scales = { {0, 38307}, {0, 76614}, {0, 153228} }, + .ev_cfg = MMA8452_TRANSIENT_CFG, + .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE, + .ev_cfg_chan_shift = 1, + .ev_src = MMA8452_TRANSIENT_SRC, + .ev_src_xe = MMA8452_TRANSIENT_SRC_XTRANSE, + .ev_src_ye = MMA8452_TRANSIENT_SRC_YTRANSE, + .ev_src_ze = MMA8452_TRANSIENT_SRC_ZTRANSE, + .ev_ths = MMA8452_TRANSIENT_THS, + .ev_ths_mask = MMA8452_TRANSIENT_THS_MASK, + .ev_count = MMA8452_TRANSIENT_COUNT, + }, + [mma8652] = { + .chip_id = MMA8652_DEVICE_ID, + .channels = mma8652_channels, + .num_channels = ARRAY_SIZE(mma8652_channels), + .mma_scales = { {0, 9577}, {0, 19154}, {0, 38307} }, + .ev_cfg = MMA8452_FF_MT_CFG, + .ev_cfg_ele = MMA8452_FF_MT_CFG_ELE, + .ev_cfg_chan_shift = 3, + .ev_src = MMA8452_FF_MT_SRC, + .ev_src_xe = MMA8452_FF_MT_SRC_XHE, + .ev_src_ye = MMA8452_FF_MT_SRC_YHE, + .ev_src_ze = MMA8452_FF_MT_SRC_ZHE, + .ev_ths = MMA8452_FF_MT_THS, + .ev_ths_mask = MMA8452_FF_MT_THS_MASK, + .ev_count = MMA8452_FF_MT_COUNT, + }, + [mma8653] = { + .chip_id = MMA8653_DEVICE_ID, + .channels = mma8653_channels, + .num_channels = ARRAY_SIZE(mma8653_channels), + .mma_scales = { {0, 38307}, {0, 76614}, {0, 153228} }, + .ev_cfg = MMA8452_FF_MT_CFG, + .ev_cfg_ele = MMA8452_FF_MT_CFG_ELE, + .ev_cfg_chan_shift = 3, + .ev_src = MMA8452_FF_MT_SRC, + .ev_src_xe = MMA8452_FF_MT_SRC_XHE, + .ev_src_ye = MMA8452_FF_MT_SRC_YHE, + .ev_src_ze = MMA8452_FF_MT_SRC_ZHE, + .ev_ths = MMA8452_FF_MT_THS, + .ev_ths_mask = MMA8452_FF_MT_THS_MASK, + .ev_count = MMA8452_FF_MT_COUNT, + }, +}; + static struct attribute *mma8452_attributes[] = { &iio_dev_attr_sampling_frequency_available.dev_attr.attr, &iio_dev_attr_in_accel_scale_available.dev_attr.attr, @@ -841,18 +1041,28 @@ static int mma8452_reset(struct i2c_client *client) return -ETIMEDOUT; } +static const struct of_device_id mma8452_dt_ids[] = { + { .compatible = "fsl,mma8452", .data = &mma_chip_info_table[mma8452] }, + { .compatible = "fsl,mma8453", .data = &mma_chip_info_table[mma8453] }, + { .compatible = "fsl,mma8652", .data = &mma_chip_info_table[mma8652] }, + { .compatible = "fsl,mma8653", .data = &mma_chip_info_table[mma8653] }, + { } +}; +MODULE_DEVICE_TABLE(of, mma8452_dt_ids); + static int mma8452_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct mma8452_data *data; struct iio_dev *indio_dev; int ret; + const struct of_device_id *match; - ret = i2c_smbus_read_byte_data(client, MMA8452_WHO_AM_I); - if (ret < 0) - return ret; - if (ret != MMA8452_DEVICE_ID) + match = of_match_device(mma8452_dt_ids, &client->dev); + if (!match) { + dev_err(&client->dev, "unknown device model\n"); return -ENODEV; + } indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) @@ -861,14 +1071,33 @@ static int mma8452_probe(struct i2c_client *client, data = iio_priv(indio_dev); data->client = client; mutex_init(&data->lock); + data->chip_info = match->data; + + ret = i2c_smbus_read_byte_data(client, MMA8452_WHO_AM_I); + if (ret < 0) + return ret; + + switch (ret) { + case MMA8452_DEVICE_ID: + case MMA8453_DEVICE_ID: + case MMA8652_DEVICE_ID: + case MMA8653_DEVICE_ID: + if (ret == data->chip_info->chip_id) + break; + default: + return -ENODEV; + } + + dev_info(&client->dev, "registering %s accelerometer; ID 0x%x\n", + match->compatible, data->chip_info->chip_id); i2c_set_clientdata(client, indio_dev); indio_dev->info = &mma8452_info; indio_dev->name = id->name; indio_dev->dev.parent = &client->dev; indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = mma8452_channels; - indio_dev->num_channels = ARRAY_SIZE(mma8452_channels); + indio_dev->channels = data->chip_info->channels; + indio_dev->num_channels = data->chip_info->num_channels; indio_dev->available_scan_masks = mma8452_scan_masks; ret = mma8452_reset(client); @@ -892,13 +1121,15 @@ static int mma8452_probe(struct i2c_client *client, if (client->irq) { /* - * Although we enable the transient interrupt source once and - * for all here the transient event detection itself is not - * enabled until userspace asks for it by - * mma8452_write_event_config() + * Although we enable the interrupt sources once and for + * all here the event detection itself is not enabled until + * userspace asks for it by mma8452_write_event_config() */ - int supported_interrupts = MMA8452_INT_DRDY | MMA8452_INT_TRANS; - int enabled_interrupts = MMA8452_INT_TRANS; + int supported_interrupts = MMA8452_INT_DRDY | + MMA8452_INT_TRANS | + MMA8452_INT_FF_MT; + int enabled_interrupts = MMA8452_INT_TRANS | + MMA8452_INT_FF_MT; /* Assume wired to INT1 pin */ ret = i2c_smbus_write_byte_data(client, @@ -987,17 +1218,14 @@ static SIMPLE_DEV_PM_OPS(mma8452_pm_ops, mma8452_suspend, mma8452_resume); #endif static const struct i2c_device_id mma8452_id[] = { - { "mma8452", 0 }, + { "mma8452", mma8452 }, + { "mma8453", mma8453 }, + { "mma8652", mma8652 }, + { "mma8653", mma8653 }, { } }; MODULE_DEVICE_TABLE(i2c, mma8452_id); -static const struct of_device_id mma8452_dt_ids[] = { - { .compatible = "fsl,mma8452" }, - { } -}; -MODULE_DEVICE_TABLE(of, mma8452_dt_ids); - static struct i2c_driver mma8452_driver = { .driver = { .name = "mma8452", diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c index 771858cb67a1..9408ef3add58 100644 --- a/drivers/iio/accel/mma9553.c +++ b/drivers/iio/accel/mma9553.c @@ -26,7 +26,6 @@ #define MMA9553_DRV_NAME "mma9553" #define MMA9553_IRQ_NAME "mma9553_event" -#define MMA9553_GPIO_NAME "mma9553_int" /* Pedometer configuration registers (R/W) */ #define MMA9553_REG_CONF_SLEEPMIN 0x00 @@ -1073,31 +1072,6 @@ static irqreturn_t mma9553_event_handler(int irq, void *private) return IRQ_HANDLED; } -static int mma9553_gpio_probe(struct i2c_client *client) -{ - struct device *dev; - struct gpio_desc *gpio; - int ret; - - if (!client) - return -EINVAL; - - dev = &client->dev; - - /* data ready GPIO interrupt pin */ - gpio = devm_gpiod_get_index(dev, MMA9553_GPIO_NAME, 0, GPIOD_IN); - if (IS_ERR(gpio)) { - dev_err(dev, "ACPI GPIO get index failed\n"); - return PTR_ERR(gpio); - } - - ret = gpiod_to_irq(gpio); - - dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); - - return ret; -} - static const char *mma9553_match_acpi_device(struct device *dev) { const struct acpi_device_id *id; @@ -1146,9 +1120,6 @@ static int mma9553_probe(struct i2c_client *client, indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &mma9553_info; - if (client->irq < 0) - client->irq = mma9553_gpio_probe(client); - if (client->irq > 0) { ret = devm_request_threaded_irq(&client->dev, client->irq, mma9553_irq_handler, diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c new file mode 100644 index 000000000000..e72e218c2696 --- /dev/null +++ b/drivers/iio/accel/mxc4005.c @@ -0,0 +1,567 @@ +/* + * 3-axis accelerometer driver for MXC4005XC Memsic sensor + * + * Copyright (c) 2014, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#define MXC4005_DRV_NAME "mxc4005" +#define MXC4005_IRQ_NAME "mxc4005_event" +#define MXC4005_REGMAP_NAME "mxc4005_regmap" + +#define MXC4005_REG_XOUT_UPPER 0x03 +#define MXC4005_REG_XOUT_LOWER 0x04 +#define MXC4005_REG_YOUT_UPPER 0x05 +#define MXC4005_REG_YOUT_LOWER 0x06 +#define MXC4005_REG_ZOUT_UPPER 0x07 +#define MXC4005_REG_ZOUT_LOWER 0x08 + +#define MXC4005_REG_INT_MASK1 0x0B +#define MXC4005_REG_INT_MASK1_BIT_DRDYE 0x01 + +#define MXC4005_REG_INT_CLR1 0x01 +#define MXC4005_REG_INT_CLR1_BIT_DRDYC 0x01 + +#define MXC4005_REG_CONTROL 0x0D +#define MXC4005_REG_CONTROL_MASK_FSR GENMASK(6, 5) +#define MXC4005_CONTROL_FSR_SHIFT 5 + +#define MXC4005_REG_DEVICE_ID 0x0E + +enum mxc4005_axis { + AXIS_X, + AXIS_Y, + AXIS_Z, +}; + +enum mxc4005_range { + MXC4005_RANGE_2G, + MXC4005_RANGE_4G, + MXC4005_RANGE_8G, +}; + +struct mxc4005_data { + struct device *dev; + struct mutex mutex; + struct regmap *regmap; + struct iio_trigger *dready_trig; + __be16 buffer[8]; + bool trigger_enabled; +}; + +/* + * MXC4005 can operate in the following ranges: + * +/- 2G, 4G, 8G (the default +/-2G) + * + * (2 + 2) * 9.81 / (2^12 - 1) = 0.009582 + * (4 + 4) * 9.81 / (2^12 - 1) = 0.019164 + * (8 + 8) * 9.81 / (2^12 - 1) = 0.038329 + */ +static const struct { + u8 range; + int scale; +} mxc4005_scale_table[] = { + {MXC4005_RANGE_2G, 9582}, + {MXC4005_RANGE_4G, 19164}, + {MXC4005_RANGE_8G, 38329}, +}; + + +static IIO_CONST_ATTR(in_accel_scale_available, "0.009582 0.019164 0.038329"); + +static struct attribute *mxc4005_attributes[] = { + &iio_const_attr_in_accel_scale_available.dev_attr.attr, + NULL, +}; + +static const struct attribute_group mxc4005_attrs_group = { + .attrs = mxc4005_attributes, +}; + +static bool mxc4005_is_readable_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case MXC4005_REG_XOUT_UPPER: + case MXC4005_REG_XOUT_LOWER: + case MXC4005_REG_YOUT_UPPER: + case MXC4005_REG_YOUT_LOWER: + case MXC4005_REG_ZOUT_UPPER: + case MXC4005_REG_ZOUT_LOWER: + case MXC4005_REG_DEVICE_ID: + case MXC4005_REG_CONTROL: + return true; + default: + return false; + } +} + +static bool mxc4005_is_writeable_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case MXC4005_REG_INT_CLR1: + case MXC4005_REG_INT_MASK1: + case MXC4005_REG_CONTROL: + return true; + default: + return false; + } +} + +static const struct regmap_config mxc4005_regmap_config = { + .name = MXC4005_REGMAP_NAME, + + .reg_bits = 8, + .val_bits = 8, + + .max_register = MXC4005_REG_DEVICE_ID, + + .readable_reg = mxc4005_is_readable_reg, + .writeable_reg = mxc4005_is_writeable_reg, +}; + +static int mxc4005_read_xyz(struct mxc4005_data *data) +{ + int ret; + + ret = regmap_bulk_read(data->regmap, MXC4005_REG_XOUT_UPPER, + (u8 *) data->buffer, sizeof(data->buffer)); + if (ret < 0) { + dev_err(data->dev, "failed to read axes\n"); + return ret; + } + + return 0; +} + +static int mxc4005_read_axis(struct mxc4005_data *data, + unsigned int addr) +{ + __be16 reg; + int ret; + + ret = regmap_bulk_read(data->regmap, addr, (u8 *) ®, sizeof(reg)); + if (ret < 0) { + dev_err(data->dev, "failed to read reg %02x\n", addr); + return ret; + } + + return be16_to_cpu(reg); +} + +static int mxc4005_read_scale(struct mxc4005_data *data) +{ + unsigned int reg; + int ret; + int i; + + ret = regmap_read(data->regmap, MXC4005_REG_CONTROL, ®); + if (ret < 0) { + dev_err(data->dev, "failed to read reg_control\n"); + return ret; + } + + i = reg >> MXC4005_CONTROL_FSR_SHIFT; + + if (i < 0 || i >= ARRAY_SIZE(mxc4005_scale_table)) + return -EINVAL; + + return mxc4005_scale_table[i].scale; +} + +static int mxc4005_set_scale(struct mxc4005_data *data, int val) +{ + unsigned int reg; + int i; + int ret; + + for (i = 0; i < ARRAY_SIZE(mxc4005_scale_table); i++) { + if (mxc4005_scale_table[i].scale == val) { + reg = i << MXC4005_CONTROL_FSR_SHIFT; + ret = regmap_update_bits(data->regmap, + MXC4005_REG_CONTROL, + MXC4005_REG_CONTROL_MASK_FSR, + reg); + if (ret < 0) + dev_err(data->dev, + "failed to write reg_control\n"); + return ret; + } + } + + return -EINVAL; +} + +static int mxc4005_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct mxc4005_data *data = iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + switch (chan->type) { + case IIO_ACCEL: + if (iio_buffer_enabled(indio_dev)) + return -EBUSY; + + ret = mxc4005_read_axis(data, chan->address); + if (ret < 0) + return ret; + *val = sign_extend32(ret >> chan->scan_type.shift, + chan->scan_type.realbits - 1); + return IIO_VAL_INT; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_SCALE: + ret = mxc4005_read_scale(data); + if (ret < 0) + return ret; + + *val = 0; + *val2 = ret; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } +} + +static int mxc4005_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct mxc4005_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + if (val != 0) + return -EINVAL; + + return mxc4005_set_scale(data, val2); + default: + return -EINVAL; + } +} + +static const struct iio_info mxc4005_info = { + .driver_module = THIS_MODULE, + .read_raw = mxc4005_read_raw, + .write_raw = mxc4005_write_raw, + .attrs = &mxc4005_attrs_group, +}; + +static const unsigned long mxc4005_scan_masks[] = { + BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z), + 0 +}; + +#define MXC4005_CHANNEL(_axis, _addr) { \ + .type = IIO_ACCEL, \ + .modified = 1, \ + .channel2 = IIO_MOD_##_axis, \ + .address = _addr, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = AXIS_##_axis, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 12, \ + .storagebits = 16, \ + .shift = 4, \ + .endianness = IIO_BE, \ + }, \ +} + +static const struct iio_chan_spec mxc4005_channels[] = { + MXC4005_CHANNEL(X, MXC4005_REG_XOUT_UPPER), + MXC4005_CHANNEL(Y, MXC4005_REG_YOUT_UPPER), + MXC4005_CHANNEL(Z, MXC4005_REG_ZOUT_UPPER), + IIO_CHAN_SOFT_TIMESTAMP(3), +}; + +static irqreturn_t mxc4005_trigger_handler(int irq, void *private) +{ + struct iio_poll_func *pf = private; + struct iio_dev *indio_dev = pf->indio_dev; + struct mxc4005_data *data = iio_priv(indio_dev); + int ret; + + ret = mxc4005_read_xyz(data); + if (ret < 0) + goto err; + + iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, + pf->timestamp); + +err: + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + +static int mxc4005_clr_intr(struct mxc4005_data *data) +{ + int ret; + + /* clear interrupt */ + ret = regmap_write(data->regmap, MXC4005_REG_INT_CLR1, + MXC4005_REG_INT_CLR1_BIT_DRDYC); + if (ret < 0) { + dev_err(data->dev, "failed to write to reg_int_clr1\n"); + return ret; + } + + return 0; +} + +static int mxc4005_set_trigger_state(struct iio_trigger *trig, + bool state) +{ + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); + struct mxc4005_data *data = iio_priv(indio_dev); + int ret; + + mutex_lock(&data->mutex); + if (state) { + ret = regmap_write(data->regmap, MXC4005_REG_INT_MASK1, + MXC4005_REG_INT_MASK1_BIT_DRDYE); + } else { + ret = regmap_write(data->regmap, MXC4005_REG_INT_MASK1, + ~MXC4005_REG_INT_MASK1_BIT_DRDYE); + } + + if (ret < 0) { + mutex_unlock(&data->mutex); + dev_err(data->dev, "failed to update reg_int_mask1"); + return ret; + } + + data->trigger_enabled = state; + mutex_unlock(&data->mutex); + + return 0; +} + +static int mxc4005_trigger_try_reen(struct iio_trigger *trig) +{ + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); + struct mxc4005_data *data = iio_priv(indio_dev); + + if (!data->dready_trig) + return 0; + + return mxc4005_clr_intr(data); +} + +static const struct iio_trigger_ops mxc4005_trigger_ops = { + .set_trigger_state = mxc4005_set_trigger_state, + .try_reenable = mxc4005_trigger_try_reen, + .owner = THIS_MODULE, +}; + +static int mxc4005_gpio_probe(struct i2c_client *client, + struct mxc4005_data *data) +{ + struct device *dev; + struct gpio_desc *gpio; + int ret; + + if (!client) + return -EINVAL; + + dev = &client->dev; + + gpio = devm_gpiod_get_index(dev, "mxc4005_int", 0, GPIOD_IN); + if (IS_ERR(gpio)) { + dev_err(dev, "failed to get acpi gpio index\n"); + return PTR_ERR(gpio); + } + + ret = gpiod_to_irq(gpio); + + dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); + + return ret; +} + +static int mxc4005_chip_init(struct mxc4005_data *data) +{ + int ret; + unsigned int reg; + + ret = regmap_read(data->regmap, MXC4005_REG_DEVICE_ID, ®); + if (ret < 0) { + dev_err(data->dev, "failed to read chip id\n"); + return ret; + } + + dev_dbg(data->dev, "MXC4005 chip id %02x\n", reg); + + return 0; +} + +static int mxc4005_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct mxc4005_data *data; + struct iio_dev *indio_dev; + struct regmap *regmap; + int ret; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + regmap = devm_regmap_init_i2c(client, &mxc4005_regmap_config); + if (IS_ERR(regmap)) { + dev_err(&client->dev, "failed to initialize regmap\n"); + return PTR_ERR(regmap); + } + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->dev = &client->dev; + data->regmap = regmap; + + ret = mxc4005_chip_init(data); + if (ret < 0) { + dev_err(&client->dev, "failed to initialize chip\n"); + return ret; + } + + mutex_init(&data->mutex); + + indio_dev->dev.parent = &client->dev; + indio_dev->channels = mxc4005_channels; + indio_dev->num_channels = ARRAY_SIZE(mxc4005_channels); + indio_dev->available_scan_masks = mxc4005_scan_masks; + indio_dev->name = MXC4005_DRV_NAME; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &mxc4005_info; + + ret = iio_triggered_buffer_setup(indio_dev, + iio_pollfunc_store_time, + mxc4005_trigger_handler, + NULL); + if (ret < 0) { + dev_err(&client->dev, + "failed to setup iio triggered buffer\n"); + return ret; + } + + if (client->irq < 0) + client->irq = mxc4005_gpio_probe(client, data); + + if (client->irq > 0) { + data->dready_trig = devm_iio_trigger_alloc(&client->dev, + "%s-dev%d", + indio_dev->name, + indio_dev->id); + if (!data->dready_trig) + return -ENOMEM; + + ret = devm_request_threaded_irq(&client->dev, client->irq, + iio_trigger_generic_data_rdy_poll, + NULL, + IRQF_TRIGGER_FALLING | + IRQF_ONESHOT, + MXC4005_IRQ_NAME, + data->dready_trig); + if (ret) { + dev_err(&client->dev, + "failed to init threaded irq\n"); + goto err_buffer_cleanup; + } + + data->dready_trig->dev.parent = &client->dev; + data->dready_trig->ops = &mxc4005_trigger_ops; + iio_trigger_set_drvdata(data->dready_trig, indio_dev); + indio_dev->trig = data->dready_trig; + iio_trigger_get(indio_dev->trig); + ret = iio_trigger_register(data->dready_trig); + if (ret) { + dev_err(&client->dev, + "failed to register trigger\n"); + goto err_trigger_unregister; + } + } + + ret = iio_device_register(indio_dev); + if (ret < 0) { + dev_err(&client->dev, + "unable to register iio device %d\n", ret); + goto err_buffer_cleanup; + } + + return 0; + +err_trigger_unregister: + iio_trigger_unregister(data->dready_trig); +err_buffer_cleanup: + iio_triggered_buffer_cleanup(indio_dev); + + return ret; +} + +static int mxc4005_remove(struct i2c_client *client) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(client); + struct mxc4005_data *data = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + + iio_triggered_buffer_cleanup(indio_dev); + if (data->dready_trig) + iio_trigger_unregister(data->dready_trig); + + return 0; +} + +static const struct acpi_device_id mxc4005_acpi_match[] = { + {"MXC4005", 0}, + { }, +}; +MODULE_DEVICE_TABLE(acpi, mxc4005_acpi_match); + +static const struct i2c_device_id mxc4005_id[] = { + {"mxc4005", 0}, + { }, +}; +MODULE_DEVICE_TABLE(i2c, mxc4005_id); + +static struct i2c_driver mxc4005_driver = { + .driver = { + .name = MXC4005_DRV_NAME, + .acpi_match_table = ACPI_PTR(mxc4005_acpi_match), + }, + .probe = mxc4005_probe, + .remove = mxc4005_remove, + .id_table = mxc4005_id, +}; + +module_i2c_driver(mxc4005_driver); + +MODULE_AUTHOR("Teodora Baluta "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("MXC4005 3-axis accelerometer driver"); diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index fb9311110424..197a08b4e2f3 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c @@ -612,6 +612,7 @@ static const struct iio_info accel_info = { .attrs = &st_accel_attribute_group, .read_raw = &st_accel_read_raw, .write_raw = &st_accel_write_raw, + .debugfs_reg_access = &st_sensors_debugfs_reg_access, }; #ifdef CONFIG_IIO_TRIGGER diff --git a/drivers/iio/accel/stk8312.c b/drivers/iio/accel/stk8312.c index c764af284c94..85fe7f7247c1 100644 --- a/drivers/iio/accel/stk8312.c +++ b/drivers/iio/accel/stk8312.c @@ -50,7 +50,6 @@ #define STK8312_ALL_CHANNEL_SIZE 3 #define STK8312_DRIVER_NAME "stk8312" -#define STK8312_GPIO "stk8312_gpio" #define STK8312_IRQ_NAME "stk8312_event" /* @@ -504,30 +503,6 @@ static const struct iio_buffer_setup_ops stk8312_buffer_setup_ops = { .postdisable = stk8312_buffer_postdisable, }; -static int stk8312_gpio_probe(struct i2c_client *client) -{ - struct device *dev; - struct gpio_desc *gpio; - int ret; - - if (!client) - return -EINVAL; - - dev = &client->dev; - - /* data ready gpio interrupt pin */ - gpio = devm_gpiod_get_index(dev, STK8312_GPIO, 0, GPIOD_IN); - if (IS_ERR(gpio)) { - dev_err(dev, "acpi gpio get index failed\n"); - return PTR_ERR(gpio); - } - - ret = gpiod_to_irq(gpio); - dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); - - return ret; -} - static int stk8312_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -569,10 +544,7 @@ static int stk8312_probe(struct i2c_client *client, if (ret < 0) return ret; - if (client->irq < 0) - client->irq = stk8312_gpio_probe(client); - - if (client->irq >= 0) { + if (client->irq > 0) { ret = devm_request_threaded_irq(&client->dev, client->irq, stk8312_data_rdy_trig_poll, NULL, diff --git a/drivers/iio/accel/stk8ba50.c b/drivers/iio/accel/stk8ba50.c index 80f77d8704b5..5709d9eb8f34 100644 --- a/drivers/iio/accel/stk8ba50.c +++ b/drivers/iio/accel/stk8ba50.c @@ -45,7 +45,6 @@ #define STK8BA50_ALL_CHANNEL_SIZE 6 #define STK8BA50_DRIVER_NAME "stk8ba50" -#define STK8BA50_GPIO "stk8ba50_gpio" #define STK8BA50_IRQ_NAME "stk8ba50_event" #define STK8BA50_SCALE_AVAIL "0.0384 0.0767 0.1534 0.3069" @@ -388,30 +387,6 @@ static const struct iio_buffer_setup_ops stk8ba50_buffer_setup_ops = { .postdisable = stk8ba50_buffer_postdisable, }; -static int stk8ba50_gpio_probe(struct i2c_client *client) -{ - struct device *dev; - struct gpio_desc *gpio; - int ret; - - if (!client) - return -EINVAL; - - dev = &client->dev; - - /* data ready gpio interrupt pin */ - gpio = devm_gpiod_get_index(dev, STK8BA50_GPIO, 0, GPIOD_IN); - if (IS_ERR(gpio)) { - dev_err(dev, "acpi gpio get index failed\n"); - return PTR_ERR(gpio); - } - - ret = gpiod_to_irq(gpio); - dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); - - return ret; -} - static int stk8ba50_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -465,10 +440,7 @@ static int stk8ba50_probe(struct i2c_client *client, goto err_power_off; } - if (client->irq < 0) - client->irq = stk8ba50_gpio_probe(client); - - if (client->irq >= 0) { + if (client->irq > 0) { ret = devm_request_threaded_irq(&client->dev, client->irq, stk8ba50_data_rdy_trig_poll, NULL, diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 50c103d75af9..7868c744fd4b 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -149,6 +149,17 @@ config BERLIN2_ADC Marvell Berlin2 ADC driver. This ADC has 8 channels, with one used for temperature measurement. +config CC10001_ADC + tristate "Cosmic Circuits 10001 ADC driver" + depends on HAS_IOMEM && HAVE_CLK && REGULATOR + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + Say yes here to build support for Cosmic Circuits 10001 ADC. + + This driver can also be built as a module. If so, the module will be + called cc10001_adc. + config DA9150_GPADC tristate "Dialog DA9150 GPADC driver support" depends on MFD_DA9150 @@ -161,17 +172,6 @@ config DA9150_GPADC To compile this driver as a module, choose M here: the module will be called berlin2-adc. -config CC10001_ADC - tristate "Cosmic Circuits 10001 ADC driver" - depends on HAS_IOMEM && HAVE_CLK && REGULATOR - select IIO_BUFFER - select IIO_TRIGGERED_BUFFER - help - Say yes here to build support for Cosmic Circuits 10001 ADC. - - This driver can also be built as a module. If so, the module will be - called cc10001_adc. - config EXYNOS_ADC tristate "Exynos ADC driver support" depends on ARCH_EXYNOS || ARCH_S3C24XX || ARCH_S3C64XX || (OF && COMPILE_TEST) @@ -183,6 +183,17 @@ config EXYNOS_ADC To compile this driver as a module, choose M here: the module will be called exynos_adc. +config HI8435 + tristate "Holt Integrated Circuits HI-8435 threshold detector" + select IIO_TRIGGERED_EVENT + depends on SPI + help + If you say yes here you get support for Holt Integrated Circuits + HI-8435 chip. + + This driver can also be built as a module. If so, the module will be + called hi8435. + config LP8788_ADC tristate "LP8788 ADC driver" depends on MFD_LP8788 @@ -361,6 +372,8 @@ config TWL6030_GPADC config VF610_ADC tristate "Freescale vf610 ADC driver" depends on OF + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER help Say yes here to support for Vybrid board analog-to-digital converter. Since the IP is used for i.MX6SLX, the driver also support i.MX6SLX. diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index a0962103e866..99b37a963a1e 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -16,9 +16,10 @@ obj-$(CONFIG_AD799X) += ad799x.o obj-$(CONFIG_AT91_ADC) += at91_adc.o obj-$(CONFIG_AXP288_ADC) += axp288_adc.o obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o -obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o +obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o +obj-$(CONFIG_HI8435) += hi8435.o obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o obj-$(CONFIG_MAX1027) += max1027.o obj-$(CONFIG_MAX1363) += max1363.o diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c index b99de00e57b8..01d71588d752 100644 --- a/drivers/iio/adc/ad799x.c +++ b/drivers/iio/adc/ad799x.c @@ -528,7 +528,6 @@ static struct attribute *ad799x_event_attributes[] = { static struct attribute_group ad799x_event_attrs_group = { .attrs = ad799x_event_attributes, - .name = "events", }; static const struct iio_info ad7991_info = { diff --git a/drivers/iio/adc/berlin2-adc.c b/drivers/iio/adc/berlin2-adc.c index 4946d9bf1764..71c806ecc722 100644 --- a/drivers/iio/adc/berlin2-adc.c +++ b/drivers/iio/adc/berlin2-adc.c @@ -27,13 +27,13 @@ #define BERLIN2_SM_CTRL_SM_SOC_INT BIT(1) #define BERLIN2_SM_CTRL_SOC_SM_INT BIT(2) #define BERLIN2_SM_CTRL_ADC_SEL(x) ((x) << 5) /* 0-15 */ -#define BERLIN2_SM_CTRL_ADC_SEL_MASK (0xf << 5) +#define BERLIN2_SM_CTRL_ADC_SEL_MASK GENMASK(8, 5) #define BERLIN2_SM_CTRL_ADC_POWER BIT(9) #define BERLIN2_SM_CTRL_ADC_CLKSEL_DIV2 (0x0 << 10) #define BERLIN2_SM_CTRL_ADC_CLKSEL_DIV3 (0x1 << 10) #define BERLIN2_SM_CTRL_ADC_CLKSEL_DIV4 (0x2 << 10) #define BERLIN2_SM_CTRL_ADC_CLKSEL_DIV8 (0x3 << 10) -#define BERLIN2_SM_CTRL_ADC_CLKSEL_MASK (0x3 << 10) +#define BERLIN2_SM_CTRL_ADC_CLKSEL_MASK GENMASK(11, 10) #define BERLIN2_SM_CTRL_ADC_START BIT(12) #define BERLIN2_SM_CTRL_ADC_RESET BIT(13) #define BERLIN2_SM_CTRL_ADC_BANDGAP_RDY BIT(14) @@ -50,7 +50,7 @@ #define BERLIN2_SM_CTRL_TSEN_MODE_10_50 (0x1 << 22) /* 10-50 C */ #define BERLIN2_SM_CTRL_TSEN_RESET BIT(29) #define BERLIN2_SM_ADC_DATA 0x20 -#define BERLIN2_SM_ADC_MASK 0x3ff +#define BERLIN2_SM_ADC_MASK GENMASK(9, 0) #define BERLIN2_SM_ADC_STATUS 0x1c #define BERLIN2_SM_ADC_STATUS_DATA_RDY(x) BIT(x) /* 0-15 */ #define BERLIN2_SM_ADC_STATUS_DATA_RDY_MASK GENMASK(15, 0) @@ -65,9 +65,9 @@ #define BERLIN2_SM_TSEN_CTRL_START BIT(8) #define BERLIN2_SM_TSEN_CTRL_SETTLING_4 (0x0 << 21) /* 4 us */ #define BERLIN2_SM_TSEN_CTRL_SETTLING_12 (0x1 << 21) /* 12 us */ -#define BERLIN2_SM_TSEN_CTRL_SETTLING_MASK (0x1 << 21) +#define BERLIN2_SM_TSEN_CTRL_SETTLING_MASK BIT(21) #define BERLIN2_SM_TSEN_CTRL_TRIM(x) ((x) << 22) -#define BERLIN2_SM_TSEN_CTRL_TRIM_MASK (0xf << 22) +#define BERLIN2_SM_TSEN_CTRL_TRIM_MASK GENMASK(25, 22) struct berlin2_adc_priv { struct regmap *regmap; @@ -78,13 +78,13 @@ struct berlin2_adc_priv { }; #define BERLIN2_ADC_CHANNEL(n, t) \ - { \ - .channel = n, \ - .datasheet_name = "channel"#n, \ - .type = t, \ - .indexed = 1, \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ - } + { \ + .channel = n, \ + .datasheet_name = "channel"#n, \ + .type = t, \ + .indexed = 1, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + } static const struct iio_chan_spec berlin2_adc_channels[] = { BERLIN2_ADC_CHANNEL(0, IIO_VOLTAGE), /* external input */ @@ -111,18 +111,24 @@ static int berlin2_adc_read(struct iio_dev *indio_dev, int channel) mutex_lock(&priv->lock); + /* Enable the interrupts */ + regmap_write(priv->regmap, BERLIN2_SM_ADC_STATUS, + BERLIN2_SM_ADC_STATUS_INT_EN(channel)); + /* Configure the ADC */ regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL, - BERLIN2_SM_CTRL_ADC_RESET | BERLIN2_SM_CTRL_ADC_SEL_MASK - | BERLIN2_SM_CTRL_ADC_START, - BERLIN2_SM_CTRL_ADC_SEL(channel) | BERLIN2_SM_CTRL_ADC_START); + BERLIN2_SM_CTRL_ADC_RESET | + BERLIN2_SM_CTRL_ADC_SEL_MASK | + BERLIN2_SM_CTRL_ADC_START, + BERLIN2_SM_CTRL_ADC_SEL(channel) | + BERLIN2_SM_CTRL_ADC_START); ret = wait_event_interruptible_timeout(priv->wq, priv->data_available, - msecs_to_jiffies(1000)); + msecs_to_jiffies(1000)); /* Disable the interrupts */ regmap_update_bits(priv->regmap, BERLIN2_SM_ADC_STATUS, - BERLIN2_SM_ADC_STATUS_INT_EN(channel), 0); + BERLIN2_SM_ADC_STATUS_INT_EN(channel), 0); if (ret == 0) ret = -ETIMEDOUT; @@ -132,7 +138,7 @@ static int berlin2_adc_read(struct iio_dev *indio_dev, int channel) } regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL, - BERLIN2_SM_CTRL_ADC_START, 0); + BERLIN2_SM_CTRL_ADC_START, 0); data = priv->data; priv->data_available = false; @@ -149,24 +155,31 @@ static int berlin2_adc_tsen_read(struct iio_dev *indio_dev) mutex_lock(&priv->lock); + /* Enable interrupts */ + regmap_write(priv->regmap, BERLIN2_SM_TSEN_STATUS, + BERLIN2_SM_TSEN_STATUS_INT_EN); + /* Configure the ADC */ regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL, - BERLIN2_SM_CTRL_TSEN_RESET | BERLIN2_SM_CTRL_ADC_ROTATE, - BERLIN2_SM_CTRL_ADC_ROTATE); + BERLIN2_SM_CTRL_TSEN_RESET | + BERLIN2_SM_CTRL_ADC_ROTATE, + BERLIN2_SM_CTRL_ADC_ROTATE); /* Configure the temperature sensor */ regmap_update_bits(priv->regmap, BERLIN2_SM_TSEN_CTRL, - BERLIN2_SM_TSEN_CTRL_TRIM_MASK | BERLIN2_SM_TSEN_CTRL_SETTLING_MASK - | BERLIN2_SM_TSEN_CTRL_START, - BERLIN2_SM_TSEN_CTRL_TRIM(3) | BERLIN2_SM_TSEN_CTRL_SETTLING_12 - | BERLIN2_SM_TSEN_CTRL_START); + BERLIN2_SM_TSEN_CTRL_TRIM_MASK | + BERLIN2_SM_TSEN_CTRL_SETTLING_MASK | + BERLIN2_SM_TSEN_CTRL_START, + BERLIN2_SM_TSEN_CTRL_TRIM(3) | + BERLIN2_SM_TSEN_CTRL_SETTLING_12 | + BERLIN2_SM_TSEN_CTRL_START); ret = wait_event_interruptible_timeout(priv->wq, priv->data_available, - msecs_to_jiffies(1000)); + msecs_to_jiffies(1000)); /* Disable interrupts */ regmap_update_bits(priv->regmap, BERLIN2_SM_TSEN_STATUS, - BERLIN2_SM_TSEN_STATUS_INT_EN, 0); + BERLIN2_SM_TSEN_STATUS_INT_EN, 0); if (ret == 0) ret = -ETIMEDOUT; @@ -176,7 +189,7 @@ static int berlin2_adc_tsen_read(struct iio_dev *indio_dev) } regmap_update_bits(priv->regmap, BERLIN2_SM_TSEN_CTRL, - BERLIN2_SM_TSEN_CTRL_START, 0); + BERLIN2_SM_TSEN_CTRL_START, 0); data = priv->data; priv->data_available = false; @@ -187,10 +200,9 @@ static int berlin2_adc_tsen_read(struct iio_dev *indio_dev) } static int berlin2_adc_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, int *val, int *val2, - long mask) + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) { - struct berlin2_adc_priv *priv = iio_priv(indio_dev); int temp; switch (mask) { @@ -198,10 +210,6 @@ static int berlin2_adc_read_raw(struct iio_dev *indio_dev, if (chan->type != IIO_VOLTAGE) return -EINVAL; - /* Enable the interrupts */ - regmap_write(priv->regmap, BERLIN2_SM_ADC_STATUS, - BERLIN2_SM_ADC_STATUS_INT_EN(chan->channel)); - *val = berlin2_adc_read(indio_dev, chan->channel); if (*val < 0) return *val; @@ -211,10 +219,6 @@ static int berlin2_adc_read_raw(struct iio_dev *indio_dev, if (chan->type != IIO_TEMP) return -EINVAL; - /* Enable interrupts */ - regmap_write(priv->regmap, BERLIN2_SM_TSEN_STATUS, - BERLIN2_SM_TSEN_STATUS_INT_EN); - temp = berlin2_adc_tsen_read(indio_dev); if (temp < 0) return temp; @@ -306,12 +310,12 @@ static int berlin2_adc_probe(struct platform_device *pdev) return tsen_irq; ret = devm_request_irq(&pdev->dev, irq, berlin2_adc_irq, 0, - pdev->dev.driver->name, indio_dev); + pdev->dev.driver->name, indio_dev); if (ret) return ret; ret = devm_request_irq(&pdev->dev, tsen_irq, berlin2_adc_tsen_irq, - 0, pdev->dev.driver->name, indio_dev); + 0, pdev->dev.driver->name, indio_dev); if (ret) return ret; @@ -328,13 +332,14 @@ static int berlin2_adc_probe(struct platform_device *pdev) /* Power up the ADC */ regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL, - BERLIN2_SM_CTRL_ADC_POWER, BERLIN2_SM_CTRL_ADC_POWER); + BERLIN2_SM_CTRL_ADC_POWER, + BERLIN2_SM_CTRL_ADC_POWER); ret = iio_device_register(indio_dev); if (ret) { /* Power down the ADC */ regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL, - BERLIN2_SM_CTRL_ADC_POWER, 0); + BERLIN2_SM_CTRL_ADC_POWER, 0); return ret; } @@ -350,7 +355,7 @@ static int berlin2_adc_remove(struct platform_device *pdev) /* Power down the ADC */ regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL, - BERLIN2_SM_CTRL_ADC_POWER, 0); + BERLIN2_SM_CTRL_ADC_POWER, 0); return 0; } diff --git a/drivers/iio/adc/hi8435.c b/drivers/iio/adc/hi8435.c new file mode 100644 index 000000000000..c73c6c62a6ac --- /dev/null +++ b/drivers/iio/adc/hi8435.c @@ -0,0 +1,534 @@ +/* + * Holt Integrated Circuits HI-8435 threshold detector driver + * + * Copyright (C) 2015 Zodiac Inflight Innovations + * Copyright (C) 2015 Cogent Embedded, Inc. + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRV_NAME "hi8435" + +/* Register offsets for HI-8435 */ +#define HI8435_CTRL_REG 0x02 +#define HI8435_PSEN_REG 0x04 +#define HI8435_TMDATA_REG 0x1E +#define HI8435_GOCENHYS_REG 0x3A +#define HI8435_SOCENHYS_REG 0x3C +#define HI8435_SO7_0_REG 0x10 +#define HI8435_SO15_8_REG 0x12 +#define HI8435_SO23_16_REG 0x14 +#define HI8435_SO31_24_REG 0x16 +#define HI8435_SO31_0_REG 0x78 + +#define HI8435_WRITE_OPCODE 0x00 +#define HI8435_READ_OPCODE 0x80 + +/* CTRL register bits */ +#define HI8435_CTRL_TEST 0x01 +#define HI8435_CTRL_SRST 0x02 + +struct hi8435_priv { + struct spi_device *spi; + struct mutex lock; + + unsigned long event_scan_mask; /* soft mask/unmask channels events */ + unsigned int event_prev_val; + + unsigned threshold_lo[2]; /* GND-Open and Supply-Open thresholds */ + unsigned threshold_hi[2]; /* GND-Open and Supply-Open thresholds */ + u8 reg_buffer[3] ____cacheline_aligned; +}; + +static int hi8435_readb(struct hi8435_priv *priv, u8 reg, u8 *val) +{ + reg |= HI8435_READ_OPCODE; + return spi_write_then_read(priv->spi, ®, 1, val, 1); +} + +static int hi8435_readw(struct hi8435_priv *priv, u8 reg, u16 *val) +{ + int ret; + __be16 be_val; + + reg |= HI8435_READ_OPCODE; + ret = spi_write_then_read(priv->spi, ®, 1, &be_val, 2); + *val = be16_to_cpu(be_val); + + return ret; +} + +static int hi8435_readl(struct hi8435_priv *priv, u8 reg, u32 *val) +{ + int ret; + __be32 be_val; + + reg |= HI8435_READ_OPCODE; + ret = spi_write_then_read(priv->spi, ®, 1, &be_val, 4); + *val = be32_to_cpu(be_val); + + return ret; +} + +static int hi8435_writeb(struct hi8435_priv *priv, u8 reg, u8 val) +{ + priv->reg_buffer[0] = reg | HI8435_WRITE_OPCODE; + priv->reg_buffer[1] = val; + + return spi_write(priv->spi, priv->reg_buffer, 2); +} + +static int hi8435_writew(struct hi8435_priv *priv, u8 reg, u16 val) +{ + priv->reg_buffer[0] = reg | HI8435_WRITE_OPCODE; + priv->reg_buffer[1] = (val >> 8) & 0xff; + priv->reg_buffer[2] = val & 0xff; + + return spi_write(priv->spi, priv->reg_buffer, 3); +} + +static int hi8435_read_event_config(struct iio_dev *idev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) +{ + struct hi8435_priv *priv = iio_priv(idev); + + return !!(priv->event_scan_mask & BIT(chan->channel)); +} + +static int hi8435_write_event_config(struct iio_dev *idev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, int state) +{ + struct hi8435_priv *priv = iio_priv(idev); + + priv->event_scan_mask &= ~BIT(chan->channel); + if (state) + priv->event_scan_mask |= BIT(chan->channel); + + return 0; +} + +static int hi8435_read_event_value(struct iio_dev *idev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int *val, int *val2) +{ + struct hi8435_priv *priv = iio_priv(idev); + int ret; + u8 mode, psen; + u16 reg; + + ret = hi8435_readb(priv, HI8435_PSEN_REG, &psen); + if (ret < 0) + return ret; + + /* Supply-Open or GND-Open sensing mode */ + mode = !!(psen & BIT(chan->channel / 8)); + + ret = hi8435_readw(priv, mode ? HI8435_SOCENHYS_REG : + HI8435_GOCENHYS_REG, ®); + if (ret < 0) + return ret; + + if (dir == IIO_EV_DIR_FALLING) + *val = ((reg & 0xff) - (reg >> 8)) / 2; + else if (dir == IIO_EV_DIR_RISING) + *val = ((reg & 0xff) + (reg >> 8)) / 2; + + return IIO_VAL_INT; +} + +static int hi8435_write_event_value(struct iio_dev *idev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int val, int val2) +{ + struct hi8435_priv *priv = iio_priv(idev); + int ret; + u8 mode, psen; + u16 reg; + + ret = hi8435_readb(priv, HI8435_PSEN_REG, &psen); + if (ret < 0) + return ret; + + /* Supply-Open or GND-Open sensing mode */ + mode = !!(psen & BIT(chan->channel / 8)); + + ret = hi8435_readw(priv, mode ? HI8435_SOCENHYS_REG : + HI8435_GOCENHYS_REG, ®); + if (ret < 0) + return ret; + + if (dir == IIO_EV_DIR_FALLING) { + /* falling threshold range 2..21V, hysteresis minimum 2V */ + if (val < 2 || val > 21 || (val + 2) > priv->threshold_hi[mode]) + return -EINVAL; + + if (val == priv->threshold_lo[mode]) + return 0; + + priv->threshold_lo[mode] = val; + + /* hysteresis must not be odd */ + if ((priv->threshold_hi[mode] - priv->threshold_lo[mode]) % 2) + priv->threshold_hi[mode]--; + } else if (dir == IIO_EV_DIR_RISING) { + /* rising threshold range 3..22V, hysteresis minimum 2V */ + if (val < 3 || val > 22 || val < (priv->threshold_lo[mode] + 2)) + return -EINVAL; + + if (val == priv->threshold_hi[mode]) + return 0; + + priv->threshold_hi[mode] = val; + + /* hysteresis must not be odd */ + if ((priv->threshold_hi[mode] - priv->threshold_lo[mode]) % 2) + priv->threshold_lo[mode]++; + } + + /* program thresholds */ + mutex_lock(&priv->lock); + + ret = hi8435_readw(priv, mode ? HI8435_SOCENHYS_REG : + HI8435_GOCENHYS_REG, ®); + if (ret < 0) { + mutex_unlock(&priv->lock); + return ret; + } + + /* hysteresis */ + reg = priv->threshold_hi[mode] - priv->threshold_lo[mode]; + reg <<= 8; + /* threshold center */ + reg |= (priv->threshold_hi[mode] + priv->threshold_lo[mode]); + + ret = hi8435_writew(priv, mode ? HI8435_SOCENHYS_REG : + HI8435_GOCENHYS_REG, reg); + + mutex_unlock(&priv->lock); + + return ret; +} + +static int hi8435_debugfs_reg_access(struct iio_dev *idev, + unsigned reg, unsigned writeval, + unsigned *readval) +{ + struct hi8435_priv *priv = iio_priv(idev); + int ret; + u8 val; + + if (readval != NULL) { + ret = hi8435_readb(priv, reg, &val); + *readval = val; + } else { + val = (u8)writeval; + ret = hi8435_writeb(priv, reg, val); + } + + return ret; +} + +static const struct iio_event_spec hi8435_events[] = { + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_VALUE), + }, { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_FALLING, + .mask_separate = BIT(IIO_EV_INFO_VALUE), + }, { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_EITHER, + .mask_separate = BIT(IIO_EV_INFO_ENABLE), + }, +}; + +static int hi8435_get_sensing_mode(struct iio_dev *idev, + const struct iio_chan_spec *chan) +{ + struct hi8435_priv *priv = iio_priv(idev); + int ret; + u8 reg; + + ret = hi8435_readb(priv, HI8435_PSEN_REG, ®); + if (ret < 0) + return ret; + + return !!(reg & BIT(chan->channel / 8)); +} + +static int hi8435_set_sensing_mode(struct iio_dev *idev, + const struct iio_chan_spec *chan, + unsigned int mode) +{ + struct hi8435_priv *priv = iio_priv(idev); + int ret; + u8 reg; + + mutex_lock(&priv->lock); + + ret = hi8435_readb(priv, HI8435_PSEN_REG, ®); + if (ret < 0) { + mutex_unlock(&priv->lock); + return ret; + } + + reg &= ~BIT(chan->channel / 8); + if (mode) + reg |= BIT(chan->channel / 8); + + ret = hi8435_writeb(priv, HI8435_PSEN_REG, reg); + + mutex_unlock(&priv->lock); + + return ret; +} + +static const char * const hi8435_sensing_modes[] = { "GND-Open", + "Supply-Open" }; + +static const struct iio_enum hi8435_sensing_mode = { + .items = hi8435_sensing_modes, + .num_items = ARRAY_SIZE(hi8435_sensing_modes), + .get = hi8435_get_sensing_mode, + .set = hi8435_set_sensing_mode, +}; + +static const struct iio_chan_spec_ext_info hi8435_ext_info[] = { + IIO_ENUM("sensing_mode", IIO_SEPARATE, &hi8435_sensing_mode), + {}, +}; + +#define HI8435_VOLTAGE_CHANNEL(num) \ +{ \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = num, \ + .event_spec = hi8435_events, \ + .num_event_specs = ARRAY_SIZE(hi8435_events), \ + .ext_info = hi8435_ext_info, \ +} + +static const struct iio_chan_spec hi8435_channels[] = { + HI8435_VOLTAGE_CHANNEL(0), + HI8435_VOLTAGE_CHANNEL(1), + HI8435_VOLTAGE_CHANNEL(2), + HI8435_VOLTAGE_CHANNEL(3), + HI8435_VOLTAGE_CHANNEL(4), + HI8435_VOLTAGE_CHANNEL(5), + HI8435_VOLTAGE_CHANNEL(6), + HI8435_VOLTAGE_CHANNEL(7), + HI8435_VOLTAGE_CHANNEL(8), + HI8435_VOLTAGE_CHANNEL(9), + HI8435_VOLTAGE_CHANNEL(10), + HI8435_VOLTAGE_CHANNEL(11), + HI8435_VOLTAGE_CHANNEL(12), + HI8435_VOLTAGE_CHANNEL(13), + HI8435_VOLTAGE_CHANNEL(14), + HI8435_VOLTAGE_CHANNEL(15), + HI8435_VOLTAGE_CHANNEL(16), + HI8435_VOLTAGE_CHANNEL(17), + HI8435_VOLTAGE_CHANNEL(18), + HI8435_VOLTAGE_CHANNEL(19), + HI8435_VOLTAGE_CHANNEL(20), + HI8435_VOLTAGE_CHANNEL(21), + HI8435_VOLTAGE_CHANNEL(22), + HI8435_VOLTAGE_CHANNEL(23), + HI8435_VOLTAGE_CHANNEL(24), + HI8435_VOLTAGE_CHANNEL(25), + HI8435_VOLTAGE_CHANNEL(26), + HI8435_VOLTAGE_CHANNEL(27), + HI8435_VOLTAGE_CHANNEL(28), + HI8435_VOLTAGE_CHANNEL(29), + HI8435_VOLTAGE_CHANNEL(30), + HI8435_VOLTAGE_CHANNEL(31), + IIO_CHAN_SOFT_TIMESTAMP(32), +}; + +static const struct iio_info hi8435_info = { + .driver_module = THIS_MODULE, + .read_event_config = &hi8435_read_event_config, + .write_event_config = hi8435_write_event_config, + .read_event_value = &hi8435_read_event_value, + .write_event_value = &hi8435_write_event_value, + .debugfs_reg_access = &hi8435_debugfs_reg_access, +}; + +static void hi8435_iio_push_event(struct iio_dev *idev, unsigned int val) +{ + struct hi8435_priv *priv = iio_priv(idev); + enum iio_event_direction dir; + unsigned int i; + unsigned int status = priv->event_prev_val ^ val; + + if (!status) + return; + + for_each_set_bit(i, &priv->event_scan_mask, 32) { + if (status & BIT(i)) { + dir = val & BIT(i) ? IIO_EV_DIR_RISING : + IIO_EV_DIR_FALLING; + iio_push_event(idev, + IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, i, + IIO_EV_TYPE_THRESH, dir), + iio_get_time_ns()); + } + } + + priv->event_prev_val = val; +} + +static irqreturn_t hi8435_trigger_handler(int irq, void *private) +{ + struct iio_poll_func *pf = private; + struct iio_dev *idev = pf->indio_dev; + struct hi8435_priv *priv = iio_priv(idev); + u32 val; + int ret; + + ret = hi8435_readl(priv, HI8435_SO31_0_REG, &val); + if (ret < 0) + goto err_read; + + hi8435_iio_push_event(idev, val); + +err_read: + iio_trigger_notify_done(idev->trig); + + return IRQ_HANDLED; +} + +static int hi8435_probe(struct spi_device *spi) +{ + struct iio_dev *idev; + struct hi8435_priv *priv; + struct gpio_desc *reset_gpio; + int ret; + + idev = devm_iio_device_alloc(&spi->dev, sizeof(*priv)); + if (!idev) + return -ENOMEM; + + priv = iio_priv(idev); + priv->spi = spi; + + reset_gpio = devm_gpiod_get(&spi->dev, NULL, GPIOD_OUT_LOW); + if (IS_ERR(reset_gpio)) { + /* chip s/w reset if h/w reset failed */ + hi8435_writeb(priv, HI8435_CTRL_REG, HI8435_CTRL_SRST); + hi8435_writeb(priv, HI8435_CTRL_REG, 0); + } else { + udelay(5); + gpiod_set_value(reset_gpio, 1); + } + + spi_set_drvdata(spi, idev); + mutex_init(&priv->lock); + + idev->dev.parent = &spi->dev; + idev->name = spi_get_device_id(spi)->name; + idev->modes = INDIO_DIRECT_MODE; + idev->info = &hi8435_info; + idev->channels = hi8435_channels; + idev->num_channels = ARRAY_SIZE(hi8435_channels); + + /* unmask all events */ + priv->event_scan_mask = ~(0); + /* + * There is a restriction in the chip - the hysteresis can not be odd. + * If the hysteresis is set to odd value then chip gets into lock state + * and not functional anymore. + * After chip reset the thresholds are in undefined state, so we need to + * initialize thresholds to some initial values and then prevent + * userspace setting odd hysteresis. + * + * Set threshold low voltage to 2V, threshold high voltage to 4V + * for both GND-Open and Supply-Open sensing modes. + */ + priv->threshold_lo[0] = priv->threshold_lo[1] = 2; + priv->threshold_hi[0] = priv->threshold_hi[1] = 4; + hi8435_writew(priv, HI8435_GOCENHYS_REG, 0x206); + hi8435_writew(priv, HI8435_SOCENHYS_REG, 0x206); + + ret = iio_triggered_event_setup(idev, NULL, hi8435_trigger_handler); + if (ret) + return ret; + + ret = iio_device_register(idev); + if (ret < 0) { + dev_err(&spi->dev, "unable to register device\n"); + goto unregister_triggered_event; + } + + return 0; + +unregister_triggered_event: + iio_triggered_event_cleanup(idev); + return ret; +} + +static int hi8435_remove(struct spi_device *spi) +{ + struct iio_dev *idev = spi_get_drvdata(spi); + + iio_device_unregister(idev); + iio_triggered_event_cleanup(idev); + + return 0; +} + +static const struct of_device_id hi8435_dt_ids[] = { + { .compatible = "holt,hi8435" }, + {}, +}; +MODULE_DEVICE_TABLE(of, hi8435_dt_ids); + +static const struct spi_device_id hi8435_id[] = { + { "hi8435", 0}, + { } +}; +MODULE_DEVICE_TABLE(spi, hi8435_id); + +static struct spi_driver hi8435_driver = { + .driver = { + .name = DRV_NAME, + .of_match_table = of_match_ptr(hi8435_dt_ids), + }, + .probe = hi8435_probe, + .remove = hi8435_remove, + .id_table = hi8435_id, +}; +module_spi_driver(hi8435_driver); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Vladimir Barinov"); +MODULE_DESCRIPTION("HI-8435 threshold detector"); diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c index 44bf815adb6c..54a8302aaace 100644 --- a/drivers/iio/adc/max1027.c +++ b/drivers/iio/adc/max1027.c @@ -508,6 +508,7 @@ static int max1027_remove(struct spi_device *spi) static struct spi_driver max1027_driver = { .driver = { .name = "max1027", + .of_match_table = of_match_ptr(max1027_adc_dt_ids), .owner = THIS_MODULE, }, .probe = max1027_probe, diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 1b3b74be5c20..929508e5266c 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -1007,7 +1007,6 @@ static struct attribute *max1363_event_attributes[] = { static struct attribute_group max1363_event_attribute_group = { .attrs = max1363_event_attributes, - .name = "events", }; static int max1363_update_scan_mode(struct iio_dev *indio_dev, diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c index b19e4f9d16e0..41a21e986c1a 100644 --- a/drivers/iio/adc/mcp320x.c +++ b/drivers/iio/adc/mcp320x.c @@ -404,6 +404,7 @@ MODULE_DEVICE_TABLE(spi, mcp320x_id); static struct spi_driver mcp320x_driver = { .driver = { .name = "mcp320x", + .of_match_table = of_match_ptr(mcp320x_dt_ids), .owner = THIS_MODULE, }, .probe = mcp320x_probe, diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c index 915be6b60097..98c0d2b444bf 100644 --- a/drivers/iio/adc/ti-adc128s052.c +++ b/drivers/iio/adc/ti-adc128s052.c @@ -174,6 +174,13 @@ static int adc128_remove(struct spi_device *spi) return 0; } +static const struct of_device_id adc128_of_match[] = { + { .compatible = "ti,adc128s052", }, + { .compatible = "ti,adc122s021", }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, adc128_of_match); + static const struct spi_device_id adc128_id[] = { { "adc128s052", 0}, /* index into adc128_config */ { "adc122s021", 1}, @@ -184,6 +191,7 @@ MODULE_DEVICE_TABLE(spi, adc128_id); static struct spi_driver adc128_driver = { .driver = { .name = "adc128s052", + .of_match_table = of_match_ptr(adc128_of_match), .owner = THIS_MODULE, }, .probe = adc128_probe, diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c index df12c57e6ce0..becbb0aef232 100644 --- a/drivers/iio/adc/twl6030-gpadc.c +++ b/drivers/iio/adc/twl6030-gpadc.c @@ -875,6 +875,7 @@ static const struct of_device_id of_twl6030_match_tbl[] = { }, { /* end */ } }; +MODULE_DEVICE_TABLE(of, of_twl6030_match_tbl); static int twl6030_gpadc_probe(struct platform_device *pdev) { diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c index 6bf4c20eb231..599cde3d03a1 100644 --- a/drivers/iio/adc/vf610_adc.c +++ b/drivers/iio/adc/vf610_adc.c @@ -34,8 +34,11 @@ #include #include +#include #include -#include +#include +#include +#include /* This will be the driver name the kernel reports */ #define DRIVER_NAME "vf610-adc" @@ -170,6 +173,7 @@ struct vf610_adc { u32 sample_freq_avail[5]; struct completion completion; + u16 buffer[8]; }; static const u32 vf610_hw_avgs[] = { 1, 4, 8, 16, 32 }; @@ -505,12 +509,24 @@ static const struct iio_chan_spec_ext_info vf610_ext_info[] = { .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .ext_info = vf610_ext_info, \ + .scan_index = (_idx), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = 12, \ + .storagebits = 16, \ + }, \ } #define VF610_ADC_TEMPERATURE_CHAN(_idx, _chan_type) { \ .type = (_chan_type), \ .channel = (_idx), \ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ + .scan_index = (_idx), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = 12, \ + .storagebits = 16, \ + }, \ } static const struct iio_chan_spec vf610_adc_iio_channels[] = { @@ -531,6 +547,7 @@ static const struct iio_chan_spec vf610_adc_iio_channels[] = { VF610_ADC_CHAN(14, IIO_VOLTAGE), VF610_ADC_CHAN(15, IIO_VOLTAGE), VF610_ADC_TEMPERATURE_CHAN(26, IIO_TEMP), + IIO_CHAN_SOFT_TIMESTAMP(32), /* sentinel */ }; @@ -559,13 +576,20 @@ static int vf610_adc_read_data(struct vf610_adc *info) static irqreturn_t vf610_adc_isr(int irq, void *dev_id) { - struct vf610_adc *info = (struct vf610_adc *)dev_id; + struct iio_dev *indio_dev = (struct iio_dev *)dev_id; + struct vf610_adc *info = iio_priv(indio_dev); int coco; coco = readl(info->regs + VF610_REG_ADC_HS); if (coco & VF610_ADC_HS_COCO0) { info->value = vf610_adc_read_data(info); - complete(&info->completion); + if (iio_buffer_enabled(indio_dev)) { + info->buffer[0] = info->value; + iio_push_to_buffers_with_timestamp(indio_dev, + info->buffer, iio_get_time_ns()); + iio_trigger_notify_done(indio_dev->trig); + } else + complete(&info->completion); } return IRQ_HANDLED; @@ -613,8 +637,12 @@ static int vf610_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_PROCESSED: mutex_lock(&indio_dev->mlock); - reinit_completion(&info->completion); + if (iio_buffer_enabled(indio_dev)) { + mutex_unlock(&indio_dev->mlock); + return -EBUSY; + } + reinit_completion(&info->completion); hc_cfg = VF610_ADC_ADCHC(chan->channel); hc_cfg |= VF610_ADC_AIEN; writel(hc_cfg, info->regs + VF610_REG_ADC_HC0); @@ -694,6 +722,56 @@ static int vf610_write_raw(struct iio_dev *indio_dev, return -EINVAL; } +static int vf610_adc_buffer_postenable(struct iio_dev *indio_dev) +{ + struct vf610_adc *info = iio_priv(indio_dev); + unsigned int channel; + int ret; + int val; + + ret = iio_triggered_buffer_postenable(indio_dev); + if (ret) + return ret; + + val = readl(info->regs + VF610_REG_ADC_GC); + val |= VF610_ADC_ADCON; + writel(val, info->regs + VF610_REG_ADC_GC); + + channel = find_first_bit(indio_dev->active_scan_mask, + indio_dev->masklength); + + val = VF610_ADC_ADCHC(channel); + val |= VF610_ADC_AIEN; + + writel(val, info->regs + VF610_REG_ADC_HC0); + + return 0; +} + +static int vf610_adc_buffer_predisable(struct iio_dev *indio_dev) +{ + struct vf610_adc *info = iio_priv(indio_dev); + unsigned int hc_cfg = 0; + int val; + + val = readl(info->regs + VF610_REG_ADC_GC); + val &= ~VF610_ADC_ADCON; + writel(val, info->regs + VF610_REG_ADC_GC); + + hc_cfg |= VF610_ADC_CONV_DISABLE; + hc_cfg &= ~VF610_ADC_AIEN; + + writel(hc_cfg, info->regs + VF610_REG_ADC_HC0); + + return iio_triggered_buffer_predisable(indio_dev); +} + +static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = { + .postenable = &vf610_adc_buffer_postenable, + .predisable = &vf610_adc_buffer_predisable, + .validate_scan_mask = &iio_validate_scan_mask_onehot, +}; + static int vf610_adc_reg_access(struct iio_dev *indio_dev, unsigned reg, unsigned writeval, unsigned *readval) @@ -753,7 +831,7 @@ static int vf610_adc_probe(struct platform_device *pdev) ret = devm_request_irq(info->dev, irq, vf610_adc_isr, 0, - dev_name(&pdev->dev), info); + dev_name(&pdev->dev), indio_dev); if (ret < 0) { dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq); return ret; @@ -806,15 +884,23 @@ static int vf610_adc_probe(struct platform_device *pdev) vf610_adc_cfg_init(info); vf610_adc_hw_init(info); + ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, + NULL, &iio_triggered_buffer_setup_ops); + if (ret < 0) { + dev_err(&pdev->dev, "Couldn't initialise the buffer\n"); + goto error_iio_device_register; + } + ret = iio_device_register(indio_dev); if (ret) { dev_err(&pdev->dev, "Couldn't register the device.\n"); - goto error_iio_device_register; + goto error_adc_buffer_init; } return 0; - +error_adc_buffer_init: + iio_triggered_buffer_cleanup(indio_dev); error_iio_device_register: clk_disable_unprepare(info->clk); error_adc_clk_enable: @@ -829,6 +915,7 @@ static int vf610_adc_remove(struct platform_device *pdev) struct vf610_adc *info = iio_priv(indio_dev); iio_device_unregister(indio_dev); + iio_triggered_buffer_cleanup(indio_dev); regulator_disable(info->vref); clk_disable_unprepare(info->clk); diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index ce93bd8e3f68..0370624a35db 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -273,33 +273,13 @@ static void xadc_zynq_unmask_worker(struct work_struct *work) schedule_delayed_work(&xadc->zynq_unmask_work, msecs_to_jiffies(XADC_ZYNQ_UNMASK_TIMEOUT)); } -} -static irqreturn_t xadc_zynq_threaded_interrupt_handler(int irq, void *devid) -{ - struct iio_dev *indio_dev = devid; - struct xadc *xadc = iio_priv(indio_dev); - unsigned int alarm; - - spin_lock_irq(&xadc->lock); - alarm = xadc->zynq_alarm; - xadc->zynq_alarm = 0; - spin_unlock_irq(&xadc->lock); - - xadc_handle_events(indio_dev, xadc_zynq_transform_alarm(alarm)); - - /* unmask the required interrupts in timer. */ - schedule_delayed_work(&xadc->zynq_unmask_work, - msecs_to_jiffies(XADC_ZYNQ_UNMASK_TIMEOUT)); - - return IRQ_HANDLED; } static irqreturn_t xadc_zynq_interrupt_handler(int irq, void *devid) { struct iio_dev *indio_dev = devid; struct xadc *xadc = iio_priv(indio_dev); - irqreturn_t ret = IRQ_HANDLED; uint32_t status; xadc_read_reg(xadc, XADC_ZYNQ_REG_INTSTS, &status); @@ -321,18 +301,23 @@ static irqreturn_t xadc_zynq_interrupt_handler(int irq, void *devid) status &= XADC_ZYNQ_INT_ALARM_MASK; if (status) { - xadc->zynq_alarm |= status; xadc->zynq_masked_alarm |= status; /* * mask the current event interrupt, * unmask it when the interrupt is no more active. */ xadc_zynq_update_intmsk(xadc, 0, 0); - ret = IRQ_WAKE_THREAD; + + xadc_handle_events(indio_dev, + xadc_zynq_transform_alarm(status)); + + /* unmask the required interrupts in timer. */ + schedule_delayed_work(&xadc->zynq_unmask_work, + msecs_to_jiffies(XADC_ZYNQ_UNMASK_TIMEOUT)); } spin_unlock(&xadc->lock); - return ret; + return IRQ_HANDLED; } #define XADC_ZYNQ_TCK_RATE_MAX 50000000 @@ -437,7 +422,6 @@ static const struct xadc_ops xadc_zynq_ops = { .setup = xadc_zynq_setup, .get_dclk_rate = xadc_zynq_get_dclk_rate, .interrupt_handler = xadc_zynq_interrupt_handler, - .threaded_interrupt_handler = xadc_zynq_threaded_interrupt_handler, .update_alarm = xadc_zynq_update_alarm, }; @@ -1225,9 +1209,8 @@ static int xadc_probe(struct platform_device *pdev) if (ret) goto err_free_samplerate_trigger; - ret = request_threaded_irq(irq, xadc->ops->interrupt_handler, - xadc->ops->threaded_interrupt_handler, - 0, dev_name(&pdev->dev), indio_dev); + ret = request_irq(irq, xadc->ops->interrupt_handler, 0, + dev_name(&pdev->dev), indio_dev); if (ret) goto err_clk_disable_unprepare; diff --git a/drivers/iio/adc/xilinx-xadc.h b/drivers/iio/adc/xilinx-xadc.h index 54adc5087210..f6f081965647 100644 --- a/drivers/iio/adc/xilinx-xadc.h +++ b/drivers/iio/adc/xilinx-xadc.h @@ -60,7 +60,6 @@ struct xadc { enum xadc_external_mux_mode external_mux_mode; - unsigned int zynq_alarm; unsigned int zynq_masked_alarm; unsigned int zynq_intmask; struct delayed_work zynq_unmask_work; @@ -79,7 +78,6 @@ struct xadc_ops { void (*update_alarm)(struct xadc *, unsigned int); unsigned long (*get_dclk_rate)(struct xadc *); irqreturn_t (*interrupt_handler)(int, void *); - irqreturn_t (*threaded_interrupt_handler)(int, void *); unsigned int flags; }; diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c index c0d364ebaea8..32b82a2dc894 100644 --- a/drivers/iio/amplifiers/ad8366.c +++ b/drivers/iio/amplifiers/ad8366.c @@ -195,6 +195,7 @@ static const struct spi_device_id ad8366_id[] = { {"ad8366", 0}, {} }; +MODULE_DEVICE_TABLE(spi, ad8366_id); static struct spi_driver ad8366_driver = { .driver = { diff --git a/drivers/iio/buffer/Kconfig b/drivers/iio/buffer/Kconfig new file mode 100644 index 000000000000..0a7b2fd3699b --- /dev/null +++ b/drivers/iio/buffer/Kconfig @@ -0,0 +1,24 @@ +# +# Industrial I/O generic buffer implementations +# +# When adding new entries keep the list in alphabetical order + +config IIO_BUFFER_CB + tristate "IIO callback buffer used for push in-kernel interfaces" + help + Should be selected by any drivers that do in-kernel push + usage. That is, those where the data is pushed to the consumer. + +config IIO_KFIFO_BUF + tristate "Industrial I/O buffering based on kfifo" + help + A simple fifo based on kfifo. Note that this currently provides + no buffer events so it is up to userspace to work out how + often to read from the buffer. + +config IIO_TRIGGERED_BUFFER + tristate + select IIO_TRIGGER + select IIO_KFIFO_BUF + help + Provides helper functions for setting up triggered buffers. diff --git a/drivers/iio/buffer/Makefile b/drivers/iio/buffer/Makefile new file mode 100644 index 000000000000..4d193b9a9123 --- /dev/null +++ b/drivers/iio/buffer/Makefile @@ -0,0 +1,8 @@ +# +# Makefile for the industrial I/O buffer implementations +# + +# When adding new entries keep the list in alphabetical order +obj-$(CONFIG_IIO_BUFFER_CB) += industrialio-buffer-cb.o +obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o +obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o diff --git a/drivers/iio/buffer_cb.c b/drivers/iio/buffer/industrialio-buffer-cb.c similarity index 89% rename from drivers/iio/buffer_cb.c rename to drivers/iio/buffer/industrialio-buffer-cb.c index 1648e6e5a848..323079c3ccce 100644 --- a/drivers/iio/buffer_cb.c +++ b/drivers/iio/buffer/industrialio-buffer-cb.c @@ -1,4 +1,12 @@ +/* The industrial I/O callback buffer + * + * 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 @@ -124,3 +132,7 @@ struct iio_channel return cb_buffer->channels; } EXPORT_SYMBOL_GPL(iio_channel_cb_get_channels); + +MODULE_AUTHOR("Jonathan Cameron "); +MODULE_DESCRIPTION("Industrial I/O callback buffer"); +MODULE_LICENSE("GPL"); diff --git a/drivers/iio/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c similarity index 100% rename from drivers/iio/industrialio-triggered-buffer.c rename to drivers/iio/buffer/industrialio-triggered-buffer.c diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c similarity index 100% rename from drivers/iio/kfifo_buf.c rename to drivers/iio/buffer/kfifo_buf.c diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig new file mode 100644 index 000000000000..3061b7299f0f --- /dev/null +++ b/drivers/iio/chemical/Kconfig @@ -0,0 +1,15 @@ +# +# Chemical sensors +# + +menu "Chemical Sensors" + +config VZ89X + tristate "SGX Sensortech MiCS VZ89X VOC sensor" + depends on I2C + help + Say Y here to build I2C interface support for the SGX + Sensortech MiCS VZ89X VOC (Volatile Organic Compounds) + sensors + +endmenu diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile new file mode 100644 index 000000000000..7292f2ded587 --- /dev/null +++ b/drivers/iio/chemical/Makefile @@ -0,0 +1,6 @@ +# +# Makefile for IIO chemical sensors +# + +# When adding new entries keep the list in alphabetical order +obj-$(CONFIG_VZ89X) += vz89x.o diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c new file mode 100644 index 000000000000..11e59a5a5112 --- /dev/null +++ b/drivers/iio/chemical/vz89x.c @@ -0,0 +1,256 @@ +/* + * vz89x.c - Support for SGX Sensortech MiCS VZ89X VOC sensors + * + * Copyright (C) 2015 Matt Ranostay + * + * 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 +#include + +#include +#include + +#define VZ89X_REG_MEASUREMENT 0x09 +#define VZ89X_REG_MEASUREMENT_SIZE 6 + +#define VZ89X_VOC_CO2_IDX 0 +#define VZ89X_VOC_SHORT_IDX 1 +#define VZ89X_VOC_TVOC_IDX 2 +#define VZ89X_VOC_RESISTANCE_IDX 3 + +struct vz89x_data { + struct i2c_client *client; + struct mutex lock; + unsigned long last_update; + + u8 buffer[VZ89X_REG_MEASUREMENT_SIZE]; +}; + +static const struct iio_chan_spec vz89x_channels[] = { + { + .type = IIO_CONCENTRATION, + .channel2 = IIO_MOD_CO2, + .modified = 1, + .info_mask_separate = + BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW), + .address = VZ89X_VOC_CO2_IDX, + }, + { + .type = IIO_CONCENTRATION, + .channel2 = IIO_MOD_VOC, + .modified = 1, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .address = VZ89X_VOC_SHORT_IDX, + .extend_name = "short", + }, + { + .type = IIO_CONCENTRATION, + .channel2 = IIO_MOD_VOC, + .modified = 1, + .info_mask_separate = + BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW), + .address = VZ89X_VOC_TVOC_IDX, + }, + { + .type = IIO_RESISTANCE, + .info_mask_separate = + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + .address = VZ89X_VOC_RESISTANCE_IDX, + }, +}; + +static IIO_CONST_ATTR(in_concentration_co2_scale, "0.00000698689"); +static IIO_CONST_ATTR(in_concentration_voc_scale, "0.00000000436681223"); + +static struct attribute *vz89x_attributes[] = { + &iio_const_attr_in_concentration_co2_scale.dev_attr.attr, + &iio_const_attr_in_concentration_voc_scale.dev_attr.attr, + NULL, +}; + +static const struct attribute_group vz89x_attrs_group = { + .attrs = vz89x_attributes, +}; + +/* + * Chipset sometime updates in the middle of a reading causing it to reset the + * data pointer, and causing invalid reading of previous data. + * We can check for this by reading MSB of the resistance reading that is + * always zero, and by also confirming the VOC_short isn't zero. + */ + +static int vz89x_measurement_is_valid(struct vz89x_data *data) +{ + if (data->buffer[VZ89X_VOC_SHORT_IDX] == 0) + return 1; + + return !!(data->buffer[VZ89X_REG_MEASUREMENT_SIZE - 1] > 0); +} + +static int vz89x_get_measurement(struct vz89x_data *data) +{ + int ret; + int i; + + /* sensor can only be polled once a second max per datasheet */ + if (!time_after(jiffies, data->last_update + HZ)) + return 0; + + ret = i2c_smbus_write_word_data(data->client, + VZ89X_REG_MEASUREMENT, 0); + if (ret < 0) + return ret; + + for (i = 0; i < VZ89X_REG_MEASUREMENT_SIZE; i++) { + ret = i2c_smbus_read_byte(data->client); + if (ret < 0) + return ret; + data->buffer[i] = ret; + } + + ret = vz89x_measurement_is_valid(data); + if (ret) + return -EAGAIN; + + data->last_update = jiffies; + + return 0; +} + +static int vz89x_get_resistance_reading(struct vz89x_data *data) +{ + u8 *buf = &data->buffer[VZ89X_VOC_RESISTANCE_IDX]; + + return buf[0] | (buf[1] << 8); +} + +static int vz89x_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + struct vz89x_data *data = iio_priv(indio_dev); + int ret = -EINVAL; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + mutex_lock(&data->lock); + ret = vz89x_get_measurement(data); + mutex_unlock(&data->lock); + + if (ret) + return ret; + + switch (chan->address) { + case VZ89X_VOC_CO2_IDX: + case VZ89X_VOC_SHORT_IDX: + case VZ89X_VOC_TVOC_IDX: + *val = data->buffer[chan->address]; + return IIO_VAL_INT; + case VZ89X_VOC_RESISTANCE_IDX: + *val = vz89x_get_resistance_reading(data); + return IIO_VAL_INT; + default: + return -EINVAL; + } + break; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_RESISTANCE: + *val = 10; + return IIO_VAL_INT; + default: + return -EINVAL; + } + break; + case IIO_CHAN_INFO_OFFSET: + switch (chan->address) { + case VZ89X_VOC_CO2_IDX: + *val = 44; + *val2 = 250000; + return IIO_VAL_INT_PLUS_MICRO; + case VZ89X_VOC_TVOC_IDX: + *val = -13; + return IIO_VAL_INT; + default: + return -EINVAL; + } + } + + return ret; +} + +static const struct iio_info vz89x_info = { + .attrs = &vz89x_attrs_group, + .read_raw = vz89x_read_raw, + .driver_module = THIS_MODULE, +}; + +static int vz89x_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct iio_dev *indio_dev; + struct vz89x_data *data; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA | + I2C_FUNC_SMBUS_BYTE)) + return -ENODEV; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->client = client; + data->last_update = jiffies - HZ; + mutex_init(&data->lock); + + indio_dev->dev.parent = &client->dev; + indio_dev->info = &vz89x_info, + indio_dev->name = dev_name(&client->dev); + indio_dev->modes = INDIO_DIRECT_MODE; + + indio_dev->channels = vz89x_channels; + indio_dev->num_channels = ARRAY_SIZE(vz89x_channels); + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static const struct i2c_device_id vz89x_id[] = { + { "vz89x", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, vz89x_id); + +static const struct of_device_id vz89x_dt_ids[] = { + { .compatible = "sgx,vz89x" }, + { } +}; +MODULE_DEVICE_TABLE(of, vz89x_dt_ids); + +static struct i2c_driver vz89x_driver = { + .driver = { + .name = "vz89x", + .of_match_table = of_match_ptr(vz89x_dt_ids), + }, + .probe = vz89x_probe, + .id_table = vz89x_id, +}; +module_i2c_driver(vz89x_driver); + +MODULE_AUTHOR("Matt Ranostay "); +MODULE_DESCRIPTION("SGX Sensortech MiCS VZ89X VOC sensors"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/common/Kconfig b/drivers/iio/common/Kconfig index 790f106d719c..26a6026de614 100644 --- a/drivers/iio/common/Kconfig +++ b/drivers/iio/common/Kconfig @@ -3,5 +3,6 @@ # source "drivers/iio/common/hid-sensors/Kconfig" +source "drivers/iio/common/ms_sensors/Kconfig" source "drivers/iio/common/ssp_sensors/Kconfig" source "drivers/iio/common/st_sensors/Kconfig" diff --git a/drivers/iio/common/Makefile b/drivers/iio/common/Makefile index b1e4d9c9591c..585da6a1b188 100644 --- a/drivers/iio/common/Makefile +++ b/drivers/iio/common/Makefile @@ -8,5 +8,6 @@ # When adding new entries keep the list in alphabetical order obj-y += hid-sensors/ +obj-y += ms_sensors/ obj-y += ssp_sensors/ obj-y += st_sensors/ diff --git a/drivers/iio/common/ms_sensors/Kconfig b/drivers/iio/common/ms_sensors/Kconfig new file mode 100644 index 000000000000..b28a92b97cf9 --- /dev/null +++ b/drivers/iio/common/ms_sensors/Kconfig @@ -0,0 +1,6 @@ +# +# Measurements Specialties sensors common library +# + +config IIO_MS_SENSORS_I2C + tristate diff --git a/drivers/iio/common/ms_sensors/Makefile b/drivers/iio/common/ms_sensors/Makefile new file mode 100644 index 000000000000..7846428abe06 --- /dev/null +++ b/drivers/iio/common/ms_sensors/Makefile @@ -0,0 +1,5 @@ +# +# Makefile for the Measurement Specialties sensor common modules. +# + +obj-$(CONFIG_IIO_MS_SENSORS_I2C) += ms_sensors_i2c.o diff --git a/drivers/iio/common/ms_sensors/ms_sensors_i2c.c b/drivers/iio/common/ms_sensors/ms_sensors_i2c.c new file mode 100644 index 000000000000..669dc7c270f5 --- /dev/null +++ b/drivers/iio/common/ms_sensors/ms_sensors_i2c.c @@ -0,0 +1,652 @@ +/* + * Measurements Specialties driver common i2c functions + * + * Copyright (c) 2015 Measurement-Specialties + * + * Licensed under the GPL-2. + */ + +#include +#include +#include +#include + +#include "ms_sensors_i2c.h" + +/* Conversion times in us */ +static const u16 ms_sensors_ht_t_conversion_time[] = { 50000, 25000, + 13000, 7000 }; +static const u16 ms_sensors_ht_h_conversion_time[] = { 16000, 3000, + 5000, 8000 }; +static const u16 ms_sensors_tp_conversion_time[] = { 500, 1100, 2100, + 4100, 8220, 16440 }; + +#define MS_SENSORS_SERIAL_READ_MSB 0xFA0F +#define MS_SENSORS_SERIAL_READ_LSB 0xFCC9 +#define MS_SENSORS_CONFIG_REG_WRITE 0xE6 +#define MS_SENSORS_CONFIG_REG_READ 0xE7 +#define MS_SENSORS_HT_T_CONVERSION_START 0xF3 +#define MS_SENSORS_HT_H_CONVERSION_START 0xF5 + +#define MS_SENSORS_TP_PROM_READ 0xA0 +#define MS_SENSORS_TP_T_CONVERSION_START 0x50 +#define MS_SENSORS_TP_P_CONVERSION_START 0x40 +#define MS_SENSORS_TP_ADC_READ 0x00 + +#define MS_SENSORS_NO_READ_CMD 0xFF + +/** + * ms_sensors_reset() - Reset function + * @cli: pointer to device client + * @cmd: reset cmd. Depends on device in use + * @delay: usleep minimal delay after reset command is issued + * + * Generic I2C reset function for Measurement Specialties devices. + * + * Return: 0 on success, negative errno otherwise. + */ +int ms_sensors_reset(void *cli, u8 cmd, unsigned int delay) +{ + int ret; + struct i2c_client *client = cli; + + ret = i2c_smbus_write_byte(client, cmd); + if (ret) { + dev_err(&client->dev, "Failed to reset device\n"); + return ret; + } + usleep_range(delay, delay + 1000); + + return 0; +} +EXPORT_SYMBOL(ms_sensors_reset); + +/** + * ms_sensors_read_prom_word() - PROM word read function + * @cli: pointer to device client + * @cmd: PROM read cmd. Depends on device and prom id + * @word: pointer to word destination value + * + * Generic i2c prom word read function for Measurement Specialties devices. + * + * Return: 0 on success, negative errno otherwise. + */ +int ms_sensors_read_prom_word(void *cli, int cmd, u16 *word) +{ + int ret; + struct i2c_client *client = (struct i2c_client *)cli; + + ret = i2c_smbus_read_word_swapped(client, cmd); + if (ret < 0) { + dev_err(&client->dev, "Failed to read prom word\n"); + return ret; + } + *word = ret; + + return 0; +} +EXPORT_SYMBOL(ms_sensors_read_prom_word); + +/** + * ms_sensors_convert_and_read() - ADC conversion & read function + * @cli: pointer to device client + * @conv: ADC conversion command. Depends on device in use + * @rd: ADC read command. Depends on device in use + * @delay: usleep minimal delay after conversion command is issued + * @adc: pointer to ADC destination value + * + * Generic ADC conversion & read function for Measurement Specialties + * devices. + * The function will issue conversion command, sleep appopriate delay, and + * issue command to read ADC. + * + * Return: 0 on success, negative errno otherwise. + */ +int ms_sensors_convert_and_read(void *cli, u8 conv, u8 rd, + unsigned int delay, u32 *adc) +{ + int ret; + __be32 buf = 0; + struct i2c_client *client = (struct i2c_client *)cli; + + /* Trigger conversion */ + ret = i2c_smbus_write_byte(client, conv); + if (ret) + goto err; + usleep_range(delay, delay + 1000); + + /* Retrieve ADC value */ + if (rd != MS_SENSORS_NO_READ_CMD) + ret = i2c_smbus_read_i2c_block_data(client, rd, 3, (u8 *)&buf); + else + ret = i2c_master_recv(client, (u8 *)&buf, 3); + if (ret < 0) + goto err; + + dev_dbg(&client->dev, "ADC raw value : %x\n", be32_to_cpu(buf) >> 8); + *adc = be32_to_cpu(buf) >> 8; + + return 0; +err: + dev_err(&client->dev, "Unable to make sensor adc conversion\n"); + return ret; +} +EXPORT_SYMBOL(ms_sensors_convert_and_read); + +/** + * ms_sensors_crc_valid() - CRC check function + * @value: input and CRC compare value + * + * Cyclic Redundancy Check function used in TSYS02D, HTU21, MS8607. + * This function performs a x^8 + x^5 + x^4 + 1 polynomial CRC. + * The argument contains CRC value in LSB byte while the bytes 1 and 2 + * are used for CRC computation. + * + * Return: 1 if CRC is valid, 0 otherwise. + */ +static bool ms_sensors_crc_valid(u32 value) +{ + u32 polynom = 0x988000; /* x^8 + x^5 + x^4 + 1 */ + u32 msb = 0x800000; + u32 mask = 0xFF8000; + u32 result = value & 0xFFFF00; + u8 crc = value & 0xFF; + + while (msb != 0x80) { + if (result & msb) + result = ((result ^ polynom) & mask) + | (result & ~mask); + msb >>= 1; + mask >>= 1; + polynom >>= 1; + } + + return result == crc; +} + +/** + * ms_sensors_read_serial() - Serial number read function + * @cli: pointer to i2c client + * @sn: pointer to 64-bits destination value + * + * Generic i2c serial number read function for Measurement Specialties devices. + * This function is used for TSYS02d, HTU21, MS8607 chipset. + * Refer to datasheet: + * http://www.meas-spec.com/downloads/HTU2X_Serial_Number_Reading.pdf + * + * Sensor raw MSB serial number format is the following : + * [ SNB3, CRC, SNB2, CRC, SNB1, CRC, SNB0, CRC] + * Sensor raw LSB serial number format is the following : + * [ X, X, SNC1, SNC0, CRC, SNA1, SNA0, CRC] + * The resulting serial number is following : + * [ SNA1, SNA0, SNB3, SNB2, SNB1, SNB0, SNC1, SNC0] + * + * Return: 0 on success, negative errno otherwise. + */ +int ms_sensors_read_serial(struct i2c_client *client, u64 *sn) +{ + u8 i; + __be64 rcv_buf = 0; + u64 rcv_val; + __be16 send_buf; + int ret; + + struct i2c_msg msg[2] = { + { + .addr = client->addr, + .flags = client->flags, + .len = 2, + .buf = (__u8 *)&send_buf, + }, + { + .addr = client->addr, + .flags = client->flags | I2C_M_RD, + .buf = (__u8 *)&rcv_buf, + }, + }; + + /* Read MSB part of serial number */ + send_buf = cpu_to_be16(MS_SENSORS_SERIAL_READ_MSB); + msg[1].len = 8; + ret = i2c_transfer(client->adapter, msg, 2); + if (ret < 0) { + dev_err(&client->dev, "Unable to read device serial number"); + return ret; + } + + rcv_val = be64_to_cpu(rcv_buf); + dev_dbg(&client->dev, "Serial MSB raw : %llx\n", rcv_val); + + for (i = 0; i < 64; i += 16) { + if (!ms_sensors_crc_valid((rcv_val >> i) & 0xFFFF)) + return -ENODEV; + } + + *sn = (((rcv_val >> 32) & 0xFF000000) | + ((rcv_val >> 24) & 0x00FF0000) | + ((rcv_val >> 16) & 0x0000FF00) | + ((rcv_val >> 8) & 0x000000FF)) << 16; + + /* Read LSB part of serial number */ + send_buf = cpu_to_be16(MS_SENSORS_SERIAL_READ_LSB); + msg[1].len = 6; + rcv_buf = 0; + ret = i2c_transfer(client->adapter, msg, 2); + if (ret < 0) { + dev_err(&client->dev, "Unable to read device serial number"); + return ret; + } + + rcv_val = be64_to_cpu(rcv_buf) >> 16; + dev_dbg(&client->dev, "Serial MSB raw : %llx\n", rcv_val); + + for (i = 0; i < 48; i += 24) { + if (!ms_sensors_crc_valid((rcv_val >> i) & 0xFFFFFF)) + return -ENODEV; + } + + *sn |= (rcv_val & 0xFFFF00) << 40 | (rcv_val >> 32); + + return 0; +} +EXPORT_SYMBOL(ms_sensors_read_serial); + +static int ms_sensors_read_config_reg(struct i2c_client *client, + u8 *config_reg) +{ + int ret; + + ret = i2c_smbus_write_byte(client, MS_SENSORS_CONFIG_REG_READ); + if (ret) { + dev_err(&client->dev, "Unable to read config register"); + return ret; + } + + ret = i2c_master_recv(client, config_reg, 1); + if (ret < 0) { + dev_err(&client->dev, "Unable to read config register"); + return ret; + } + dev_dbg(&client->dev, "Config register :%x\n", *config_reg); + + return 0; +} + +/** + * ms_sensors_write_resolution() - Set resolution function + * @dev_data: pointer to temperature/humidity device data + * @i: resolution index to set + * + * This function will program the appropriate resolution based on the index + * provided when user space will set samp_freq channel. + * This function is used for TSYS02D, HTU21 and MS8607 chipsets. + * + * Return: 0 on success, negative errno otherwise. + */ +ssize_t ms_sensors_write_resolution(struct ms_ht_dev *dev_data, + u8 i) +{ + u8 config_reg; + int ret; + + ret = ms_sensors_read_config_reg(dev_data->client, &config_reg); + if (ret) + return ret; + + config_reg &= 0x7E; + config_reg |= ((i & 1) << 7) + ((i & 2) >> 1); + + return i2c_smbus_write_byte_data(dev_data->client, + MS_SENSORS_CONFIG_REG_WRITE, + config_reg); +} +EXPORT_SYMBOL(ms_sensors_write_resolution); + +/** + * ms_sensors_show_battery_low() - Show device battery low indicator + * @dev_data: pointer to temperature/humidity device data + * @buf: pointer to char buffer to write result + * + * This function will read battery indicator value in the device and + * return 1 if the device voltage is below 2.25V. + * This function is used for TSYS02D, HTU21 and MS8607 chipsets. + * + * Return: length of sprintf on success, negative errno otherwise. + */ +ssize_t ms_sensors_show_battery_low(struct ms_ht_dev *dev_data, + char *buf) +{ + int ret; + u8 config_reg; + + mutex_lock(&dev_data->lock); + ret = ms_sensors_read_config_reg(dev_data->client, &config_reg); + mutex_unlock(&dev_data->lock); + if (ret) + return ret; + + return sprintf(buf, "%d\n", (config_reg & 0x40) >> 6); +} +EXPORT_SYMBOL(ms_sensors_show_battery_low); + +/** + * ms_sensors_show_heater() - Show device heater + * @dev_data: pointer to temperature/humidity device data + * @buf: pointer to char buffer to write result + * + * This function will read heater enable value in the device and + * return 1 if the heater is enabled. + * This function is used for HTU21 and MS8607 chipsets. + * + * Return: length of sprintf on success, negative errno otherwise. + */ +ssize_t ms_sensors_show_heater(struct ms_ht_dev *dev_data, + char *buf) +{ + u8 config_reg; + int ret; + + mutex_lock(&dev_data->lock); + ret = ms_sensors_read_config_reg(dev_data->client, &config_reg); + mutex_unlock(&dev_data->lock); + if (ret) + return ret; + + return sprintf(buf, "%d\n", (config_reg & 0x4) >> 2); +} +EXPORT_SYMBOL(ms_sensors_show_heater); + +/** + * ms_sensors_write_heater() - Write device heater + * @dev_data: pointer to temperature/humidity device data + * @buf: pointer to char buffer from user space + * @len: length of buf + * + * This function will write 1 or 0 value in the device + * to enable or disable heater. + * This function is used for HTU21 and MS8607 chipsets. + * + * Return: length of buffer, negative errno otherwise. + */ +ssize_t ms_sensors_write_heater(struct ms_ht_dev *dev_data, + const char *buf, size_t len) +{ + u8 val, config_reg; + int ret; + + ret = kstrtou8(buf, 10, &val); + if (ret) + return ret; + + if (val > 1) + return -EINVAL; + + mutex_lock(&dev_data->lock); + ret = ms_sensors_read_config_reg(dev_data->client, &config_reg); + if (ret) { + mutex_unlock(&dev_data->lock); + return ret; + } + + config_reg &= 0xFB; + config_reg |= val << 2; + + ret = i2c_smbus_write_byte_data(dev_data->client, + MS_SENSORS_CONFIG_REG_WRITE, + config_reg); + mutex_unlock(&dev_data->lock); + if (ret) { + dev_err(&dev_data->client->dev, "Unable to write config register\n"); + return ret; + } + + return len; +} +EXPORT_SYMBOL(ms_sensors_write_heater); + +/** + * ms_sensors_ht_read_temperature() - Read temperature + * @dev_data: pointer to temperature/humidity device data + * @temperature:pointer to temperature destination value + * + * This function will get temperature ADC value from the device, + * check the CRC and compute the temperature value. + * This function is used for TSYS02D, HTU21 and MS8607 chipsets. + * + * Return: 0 on success, negative errno otherwise. + */ +int ms_sensors_ht_read_temperature(struct ms_ht_dev *dev_data, + s32 *temperature) +{ + int ret; + u32 adc; + u16 delay; + + mutex_lock(&dev_data->lock); + delay = ms_sensors_ht_t_conversion_time[dev_data->res_index]; + ret = ms_sensors_convert_and_read(dev_data->client, + MS_SENSORS_HT_T_CONVERSION_START, + MS_SENSORS_NO_READ_CMD, + delay, &adc); + mutex_unlock(&dev_data->lock); + if (ret) + return ret; + + if (!ms_sensors_crc_valid(adc)) { + dev_err(&dev_data->client->dev, + "Temperature read crc check error\n"); + return -ENODEV; + } + + /* Temperature algorithm */ + *temperature = (((s64)(adc >> 8) * 175720) >> 16) - 46850; + + return 0; +} +EXPORT_SYMBOL(ms_sensors_ht_read_temperature); + +/** + * ms_sensors_ht_read_humidity() - Read humidity + * @dev_data: pointer to temperature/humidity device data + * @humidity: pointer to humidity destination value + * + * This function will get humidity ADC value from the device, + * check the CRC and compute the temperature value. + * This function is used for HTU21 and MS8607 chipsets. + * + * Return: 0 on success, negative errno otherwise. + */ +int ms_sensors_ht_read_humidity(struct ms_ht_dev *dev_data, + u32 *humidity) +{ + int ret; + u32 adc; + u16 delay; + + mutex_lock(&dev_data->lock); + delay = ms_sensors_ht_h_conversion_time[dev_data->res_index]; + ret = ms_sensors_convert_and_read(dev_data->client, + MS_SENSORS_HT_H_CONVERSION_START, + MS_SENSORS_NO_READ_CMD, + delay, &adc); + mutex_unlock(&dev_data->lock); + if (ret) + return ret; + + if (!ms_sensors_crc_valid(adc)) { + dev_err(&dev_data->client->dev, + "Humidity read crc check error\n"); + return -ENODEV; + } + + /* Humidity algorithm */ + *humidity = (((s32)(adc >> 8) * 12500) >> 16) * 10 - 6000; + if (*humidity >= 100000) + *humidity = 100000; + + return 0; +} +EXPORT_SYMBOL(ms_sensors_ht_read_humidity); + +/** + * ms_sensors_tp_crc_valid() - CRC check function for + * Temperature and pressure devices. + * This function is only used when reading PROM coefficients + * + * @prom: pointer to PROM coefficients array + * @len: length of PROM coefficients array + * + * Return: True if CRC is ok. + */ +static bool ms_sensors_tp_crc_valid(u16 *prom, u8 len) +{ + unsigned int cnt, n_bit; + u16 n_rem = 0x0000, crc_read = prom[0], crc = (*prom & 0xF000) >> 12; + + prom[len - 1] = 0; + prom[0] &= 0x0FFF; /* Clear the CRC computation part */ + + for (cnt = 0; cnt < len * 2; cnt++) { + if (cnt % 2 == 1) + n_rem ^= prom[cnt >> 1] & 0x00FF; + else + n_rem ^= prom[cnt >> 1] >> 8; + + for (n_bit = 8; n_bit > 0; n_bit--) { + if (n_rem & 0x8000) + n_rem = (n_rem << 1) ^ 0x3000; + else + n_rem <<= 1; + } + } + n_rem >>= 12; + prom[0] = crc_read; + + return n_rem == crc; +} + +/** + * ms_sensors_tp_read_prom() - prom coeff read function + * @dev_data: pointer to temperature/pressure device data + * + * This function will read prom coefficients and check CRC. + * This function is used for MS5637 and MS8607 chipsets. + * + * Return: 0 on success, negative errno otherwise. + */ +int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) +{ + int i, ret; + + for (i = 0; i < MS_SENSORS_TP_PROM_WORDS_NB; i++) { + ret = ms_sensors_read_prom_word( + dev_data->client, + MS_SENSORS_TP_PROM_READ + (i << 1), + &dev_data->prom[i]); + + if (ret) + return ret; + } + + if (!ms_sensors_tp_crc_valid(dev_data->prom, + MS_SENSORS_TP_PROM_WORDS_NB + 1)) { + dev_err(&dev_data->client->dev, + "Calibration coefficients crc check error\n"); + return -ENODEV; + } + + return 0; +} +EXPORT_SYMBOL(ms_sensors_tp_read_prom); + +/** + * ms_sensors_read_temp_and_pressure() - read temp and pressure + * @dev_data: pointer to temperature/pressure device data + * @temperature:pointer to temperature destination value + * @pressure: pointer to pressure destination value + * + * This function will read ADC and compute pressure and temperature value. + * This function is used for MS5637 and MS8607 chipsets. + * + * Return: 0 on success, negative errno otherwise. + */ +int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data, + int *temperature, + unsigned int *pressure) +{ + int ret; + u32 t_adc, p_adc; + s32 dt, temp; + s64 off, sens, t2, off2, sens2; + u16 *prom = dev_data->prom, delay; + + mutex_lock(&dev_data->lock); + delay = ms_sensors_tp_conversion_time[dev_data->res_index]; + + ret = ms_sensors_convert_and_read( + dev_data->client, + MS_SENSORS_TP_T_CONVERSION_START + + dev_data->res_index * 2, + MS_SENSORS_TP_ADC_READ, + delay, &t_adc); + if (ret) { + mutex_unlock(&dev_data->lock); + return ret; + } + + ret = ms_sensors_convert_and_read( + dev_data->client, + MS_SENSORS_TP_P_CONVERSION_START + + dev_data->res_index * 2, + MS_SENSORS_TP_ADC_READ, + delay, &p_adc); + mutex_unlock(&dev_data->lock); + if (ret) + return ret; + + dt = (s32)t_adc - (prom[5] << 8); + + /* Actual temperature = 2000 + dT * TEMPSENS */ + temp = 2000 + (((s64)dt * prom[6]) >> 23); + + /* Second order temperature compensation */ + if (temp < 2000) { + s64 tmp = (s64)temp - 2000; + + t2 = (3 * ((s64)dt * (s64)dt)) >> 33; + off2 = (61 * tmp * tmp) >> 4; + sens2 = (29 * tmp * tmp) >> 4; + + if (temp < -1500) { + s64 tmp = (s64)temp + 1500; + + off2 += 17 * tmp * tmp; + sens2 += 9 * tmp * tmp; + } + } else { + t2 = (5 * ((s64)dt * (s64)dt)) >> 38; + off2 = 0; + sens2 = 0; + } + + /* OFF = OFF_T1 + TCO * dT */ + off = (((s64)prom[2]) << 17) + ((((s64)prom[4]) * (s64)dt) >> 6); + off -= off2; + + /* Sensitivity at actual temperature = SENS_T1 + TCS * dT */ + sens = (((s64)prom[1]) << 16) + (((s64)prom[3] * dt) >> 7); + sens -= sens2; + + /* Temperature compensated pressure = D1 * SENS - OFF */ + *temperature = (temp - t2) * 10; + *pressure = (u32)(((((s64)p_adc * sens) >> 21) - off) >> 15); + + return 0; +} +EXPORT_SYMBOL(ms_sensors_read_temp_and_pressure); + +MODULE_DESCRIPTION("Measurement-Specialties common i2c driver"); +MODULE_AUTHOR("William Markezana "); +MODULE_AUTHOR("Ludovic Tancerel "); +MODULE_LICENSE("GPL v2"); + diff --git a/drivers/iio/common/ms_sensors/ms_sensors_i2c.h b/drivers/iio/common/ms_sensors/ms_sensors_i2c.h new file mode 100644 index 000000000000..7b614adc5cae --- /dev/null +++ b/drivers/iio/common/ms_sensors/ms_sensors_i2c.h @@ -0,0 +1,66 @@ +/* + * Measurements Specialties common sensor driver + * + * Copyright (c) 2015 Measurement-Specialties + * + * 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. + */ + +#ifndef _MS_SENSORS_I2C_H +#define _MS_SENSORS_I2C_H + +#include +#include + +#define MS_SENSORS_TP_PROM_WORDS_NB 7 + +/** + * struct ms_ht_dev - Humidity/Temperature sensor device structure + * @client: i2c client + * @lock: lock protecting the i2c conversion + * @res_index: index to selected sensor resolution + */ +struct ms_ht_dev { + struct i2c_client *client; + struct mutex lock; + u8 res_index; +}; + +/** + * struct ms_tp_dev - Temperature/Pressure sensor device structure + * @client: i2c client + * @lock: lock protecting the i2c conversion + * @prom: array of PROM coefficients used for conversion. Added element + * for CRC computation + * @res_index: index to selected sensor resolution + */ +struct ms_tp_dev { + struct i2c_client *client; + struct mutex lock; + u16 prom[MS_SENSORS_TP_PROM_WORDS_NB + 1]; + u8 res_index; +}; + +int ms_sensors_reset(void *cli, u8 cmd, unsigned int delay); +int ms_sensors_read_prom_word(void *cli, int cmd, u16 *word); +int ms_sensors_convert_and_read(void *cli, u8 conv, u8 rd, + unsigned int delay, u32 *adc); +int ms_sensors_read_serial(struct i2c_client *client, u64 *sn); +ssize_t ms_sensors_show_serial(struct ms_ht_dev *dev_data, char *buf); +ssize_t ms_sensors_write_resolution(struct ms_ht_dev *dev_data, u8 i); +ssize_t ms_sensors_show_battery_low(struct ms_ht_dev *dev_data, char *buf); +ssize_t ms_sensors_show_heater(struct ms_ht_dev *dev_data, char *buf); +ssize_t ms_sensors_write_heater(struct ms_ht_dev *dev_data, + const char *buf, size_t len); +int ms_sensors_ht_read_temperature(struct ms_ht_dev *dev_data, + s32 *temperature); +int ms_sensors_ht_read_humidity(struct ms_ht_dev *dev_data, + u32 *humidity); +int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data); +int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data, + int *temperature, + unsigned int *pressure); + +#endif /* _MS_SENSORS_I2C_H */ diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c index 2e7fdb502645..25258e2c1a82 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -44,6 +44,28 @@ st_sensors_write_data_with_mask_error: return err; } +int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev, + unsigned reg, unsigned writeval, + unsigned *readval) +{ + struct st_sensor_data *sdata = iio_priv(indio_dev); + u8 readdata; + int err; + + if (!readval) + return sdata->tf->write_byte(&sdata->tb, sdata->dev, + (u8)reg, (u8)writeval); + + err = sdata->tf->read_byte(&sdata->tb, sdata->dev, (u8)reg, &readdata); + if (err < 0) + return err; + + *readval = (unsigned)readdata; + + return 0; +} +EXPORT_SYMBOL(st_sensors_debugfs_reg_access); + static int st_sensors_match_odr(struct st_sensor_settings *sensor_settings, unsigned int odr, struct st_sensor_odr_avl *odr_out) { diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c index 581ec141de3d..e6e9756580af 100644 --- a/drivers/iio/dac/ad5504.c +++ b/drivers/iio/dac/ad5504.c @@ -214,7 +214,6 @@ static struct attribute *ad5504_ev_attributes[] = { static struct attribute_group ad5504_ev_attribute_group = { .attrs = ad5504_ev_attributes, - .name = "events", }; static irqreturn_t ad5504_event_handler(int irq, void *private) diff --git a/drivers/iio/dac/ad7303.c b/drivers/iio/dac/ad7303.c index fa2810032968..18a4ad5ff8c5 100644 --- a/drivers/iio/dac/ad7303.c +++ b/drivers/iio/dac/ad7303.c @@ -281,6 +281,12 @@ static int ad7303_remove(struct spi_device *spi) return 0; } +static const struct of_device_id ad7303_spi_of_match[] = { + { .compatible = "adi,ad7303", }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, ad7303_spi_of_match); + static const struct spi_device_id ad7303_spi_ids[] = { { "ad7303", 0 }, {} @@ -290,6 +296,7 @@ MODULE_DEVICE_TABLE(spi, ad7303_spi_ids); static struct spi_driver ad7303_driver = { .driver = { .name = "ad7303", + .of_match_table = of_match_ptr(ad7303_spi_of_match), .owner = THIS_MODULE, }, .probe = ad7303_probe, diff --git a/drivers/iio/dac/m62332.c b/drivers/iio/dac/m62332.c index c23d7fa889ee..76e8b044b979 100644 --- a/drivers/iio/dac/m62332.c +++ b/drivers/iio/dac/m62332.c @@ -31,7 +31,6 @@ struct m62332_data { struct i2c_client *client; - u16 vref_mv; struct regulator *vcc; struct mutex mutex; u8 raw[M62332_CHANNELS]; @@ -40,8 +39,7 @@ struct m62332_data { #endif }; -static int m62332_set_value(struct iio_dev *indio_dev, - u8 val, int channel) +static int m62332_set_value(struct iio_dev *indio_dev, u8 val, int channel) { struct m62332_data *data = iio_priv(indio_dev); struct i2c_client *client = data->client; @@ -62,8 +60,8 @@ static int m62332_set_value(struct iio_dev *indio_dev, goto out; } - res = i2c_master_send(client, outbuf, 2); - if (res >= 0 && res != 2) + res = i2c_master_send(client, outbuf, ARRAY_SIZE(outbuf)); + if (res >= 0 && res != ARRAY_SIZE(outbuf)) res = -EIO; if (res < 0) goto out; @@ -87,46 +85,52 @@ static int m62332_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, - long m) + long mask) { struct m62332_data *data = iio_priv(indio_dev); + int ret; - switch (m) { + switch (mask) { case IIO_CHAN_INFO_SCALE: /* Corresponds to Vref / 2^(bits) */ - *val = data->vref_mv; + ret = regulator_get_voltage(data->vcc); + if (ret < 0) + return ret; + + *val = ret / 1000; /* mV */ *val2 = 8; + return IIO_VAL_FRACTIONAL_LOG2; case IIO_CHAN_INFO_RAW: *val = data->raw[chan->channel]; + return IIO_VAL_INT; case IIO_CHAN_INFO_OFFSET: *val = 1; + return IIO_VAL_INT; default: break; } + return -EINVAL; } static int m62332_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, int val, int val2, long mask) + struct iio_chan_spec const *chan, int val, int val2, + long mask) { - int ret; - switch (mask) { case IIO_CHAN_INFO_RAW: if (val < 0 || val > 255) return -EINVAL; - ret = m62332_set_value(indio_dev, val, chan->channel); - break; + return m62332_set_value(indio_dev, val, chan->channel); default: - ret = -EINVAL; break; } - return ret; + return -EINVAL; } #ifdef CONFIG_PM_SLEEP @@ -173,15 +177,15 @@ static const struct iio_info m62332_info = { .driver_module = THIS_MODULE, }; -#define M62332_CHANNEL(chan) { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .output = 1, \ - .channel = (chan), \ - .datasheet_name = "CH" #chan, \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_SCALE) | \ - BIT(IIO_CHAN_INFO_OFFSET), \ +#define M62332_CHANNEL(chan) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .output = 1, \ + .channel = (chan), \ + .datasheet_name = "CH" #chan, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_OFFSET), \ } static const struct iio_chan_spec m62332_channels[M62332_CHANNELS] = { @@ -199,6 +203,7 @@ static int m62332_probe(struct i2c_client *client, indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; + data = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); data->client = client; @@ -212,16 +217,11 @@ static int m62332_probe(struct i2c_client *client, /* establish that the iio_dev is a child of the i2c device */ indio_dev->dev.parent = &client->dev; - indio_dev->num_channels = M62332_CHANNELS; + indio_dev->num_channels = ARRAY_SIZE(m62332_channels); indio_dev->channels = m62332_channels; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &m62332_info; - ret = regulator_get_voltage(data->vcc); - if (ret < 0) - return ret; - data->vref_mv = ret / 1000; /* mV */ - ret = iio_map_array_register(indio_dev, client->dev.platform_data); if (ret < 0) return ret; @@ -234,6 +234,7 @@ static int m62332_probe(struct i2c_client *client, err: iio_map_array_unregister(indio_dev); + return ret; } @@ -243,6 +244,8 @@ static int m62332_remove(struct i2c_client *client) iio_device_unregister(indio_dev); iio_map_array_unregister(indio_dev); + m62332_set_value(indio_dev, 0, 0); + m62332_set_value(indio_dev, 0, 1); return 0; } diff --git a/drivers/iio/dac/max5821.c b/drivers/iio/dac/max5821.c index 28b8748ea824..86e9e112f554 100644 --- a/drivers/iio/dac/max5821.c +++ b/drivers/iio/dac/max5821.c @@ -387,6 +387,7 @@ static const struct of_device_id max5821_of_match[] = { { .compatible = "maxim,max5821" }, { } }; +MODULE_DEVICE_TABLE(of, max5821_of_match); static struct i2c_driver max5821_driver = { .driver = { diff --git a/drivers/iio/frequency/adf4350.c b/drivers/iio/frequency/adf4350.c index 9890c81c027d..73f27e0a08dd 100644 --- a/drivers/iio/frequency/adf4350.c +++ b/drivers/iio/frequency/adf4350.c @@ -616,15 +616,24 @@ static int adf4350_remove(struct spi_device *spi) return 0; } +static const struct of_device_id adf4350_of_match[] = { + { .compatible = "adi,adf4350", }, + { .compatible = "adi,adf4351", }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, adf4350_of_match); + static const struct spi_device_id adf4350_id[] = { {"adf4350", 4350}, {"adf4351", 4351}, {} }; +MODULE_DEVICE_TABLE(spi, adf4350_id); static struct spi_driver adf4350_driver = { .driver = { .name = "adf4350", + .of_match_table = of_match_ptr(adf4350_of_match), .owner = THIS_MODULE, }, .probe = adf4350_probe, diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig index 8d2439345673..e816d29d6a62 100644 --- a/drivers/iio/gyro/Kconfig +++ b/drivers/iio/gyro/Kconfig @@ -52,15 +52,26 @@ config ADXRS450 config BMG160 tristate "BOSCH BMG160 Gyro Sensor" - depends on I2C + depends on (I2C || SPI_MASTER) select IIO_BUFFER select IIO_TRIGGERED_BUFFER + select BMG160_I2C if (I2C) + select BMG160_SPI if (SPI) help - Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor - driver. This driver also supports BMI055 gyroscope. + Say yes here to build support for BOSCH BMG160 Tri-axis Gyro Sensor + driver connected via I2C or SPI. This driver also supports BMI055 + gyroscope. This driver can also be built as a module. If so, the module - will be called bmg160. + will be called bmg160_i2c or bmg160_spi. + +config BMG160_I2C + tristate + select REGMAP_I2C + +config BMG160_SPI + tristate + select REGMAP_SPI config HID_SENSOR_GYRO_3D depends on HID_SENSOR_HUB diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile index f46341b39139..f866a4be0667 100644 --- a/drivers/iio/gyro/Makefile +++ b/drivers/iio/gyro/Makefile @@ -8,7 +8,9 @@ obj-$(CONFIG_ADIS16130) += adis16130.o obj-$(CONFIG_ADIS16136) += adis16136.o obj-$(CONFIG_ADIS16260) += adis16260.o obj-$(CONFIG_ADXRS450) += adxrs450.o -obj-$(CONFIG_BMG160) += bmg160.o +obj-$(CONFIG_BMG160) += bmg160_core.o +obj-$(CONFIG_BMG160_I2C) += bmg160_i2c.o +obj-$(CONFIG_BMG160_SPI) += bmg160_spi.o obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o diff --git a/drivers/iio/gyro/bmg160.h b/drivers/iio/gyro/bmg160.h new file mode 100644 index 000000000000..72db723c8fb6 --- /dev/null +++ b/drivers/iio/gyro/bmg160.h @@ -0,0 +1,10 @@ +#ifndef BMG160_H_ +#define BMG160_H_ + +extern const struct dev_pm_ops bmg160_pm_ops; + +int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, + const char *name); +void bmg160_core_remove(struct device *dev); + +#endif /* BMG160_H_ */ diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160_core.c similarity index 75% rename from drivers/iio/gyro/bmg160.c rename to drivers/iio/gyro/bmg160_core.c index 460bf715d541..02ff789852a0 100644 --- a/drivers/iio/gyro/bmg160.c +++ b/drivers/iio/gyro/bmg160_core.c @@ -13,7 +13,6 @@ */ #include -#include #include #include #include @@ -28,8 +27,9 @@ #include #include #include +#include +#include "bmg160.h" -#define BMG160_DRV_NAME "bmg160" #define BMG160_IRQ_NAME "bmg160_event" #define BMG160_GPIO_NAME "gpio_int" @@ -97,7 +97,8 @@ #define BMG160_AUTO_SUSPEND_DELAY_MS 2000 struct bmg160_data { - struct i2c_client *client; + struct device *dev; + struct regmap *regmap; struct iio_trigger *dready_trig; struct iio_trigger *motion_trig; struct mutex mutex; @@ -108,6 +109,7 @@ struct bmg160_data { int slope_thres; bool dready_trigger_on; bool motion_trigger_on; + int irq; }; enum bmg160_axis { @@ -138,10 +140,9 @@ static int bmg160_set_mode(struct bmg160_data *data, u8 mode) { int ret; - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_PMU_LPW, mode); + ret = regmap_write(data->regmap, BMG160_REG_PMU_LPW, mode); if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_pmu_lpw\n"); + dev_err(data->dev, "Error writing reg_pmu_lpw\n"); return ret; } @@ -169,10 +170,9 @@ static int bmg160_set_bw(struct bmg160_data *data, int val) if (bw_bits < 0) return bw_bits; - ret = i2c_smbus_write_byte_data(data->client, BMG160_REG_PMU_BW, - bw_bits); + ret = regmap_write(data->regmap, BMG160_REG_PMU_BW, bw_bits); if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_pmu_bw\n"); + dev_err(data->dev, "Error writing reg_pmu_bw\n"); return ret; } @@ -184,16 +184,17 @@ static int bmg160_set_bw(struct bmg160_data *data, int val) static int bmg160_chip_init(struct bmg160_data *data) { int ret; + unsigned int val; - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_CHIP_ID); + ret = regmap_read(data->regmap, BMG160_REG_CHIP_ID, &val); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_chip_id\n"); + dev_err(data->dev, "Error reading reg_chip_id\n"); return ret; } - dev_dbg(&data->client->dev, "Chip Id %x\n", ret); - if (ret != BMG160_CHIP_ID_VAL) { - dev_err(&data->client->dev, "invalid chip %x\n", ret); + dev_dbg(data->dev, "Chip Id %x\n", val); + if (val != BMG160_CHIP_ID_VAL) { + dev_err(data->dev, "invalid chip %x\n", val); return -ENODEV; } @@ -210,42 +211,33 @@ static int bmg160_chip_init(struct bmg160_data *data) return ret; /* Set Default Range */ - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_RANGE, - BMG160_RANGE_500DPS); + ret = regmap_write(data->regmap, BMG160_REG_RANGE, BMG160_RANGE_500DPS); if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_range\n"); + dev_err(data->dev, "Error writing reg_range\n"); return ret; } data->dps_range = BMG160_RANGE_500DPS; - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_SLOPE_THRES); + ret = regmap_read(data->regmap, BMG160_REG_SLOPE_THRES, &val); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_slope_thres\n"); + dev_err(data->dev, "Error reading reg_slope_thres\n"); return ret; } - data->slope_thres = ret; + data->slope_thres = val; /* Set default interrupt mode */ - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_EN_1); + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_EN_1, + BMG160_INT1_BIT_OD, 0); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_int_en_1\n"); - return ret; - } - ret &= ~BMG160_INT1_BIT_OD; - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_EN_1, ret); - if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_int_en_1\n"); + dev_err(data->dev, "Error updating bits in reg_int_en_1\n"); return ret; } - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_RST_LATCH, - BMG160_INT_MODE_LATCH_INT | - BMG160_INT_MODE_LATCH_RESET); + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH, + BMG160_INT_MODE_LATCH_INT | + BMG160_INT_MODE_LATCH_RESET); if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Error writing reg_motion_intr\n"); return ret; } @@ -259,17 +251,17 @@ static int bmg160_set_power_state(struct bmg160_data *data, bool on) int ret; if (on) - ret = pm_runtime_get_sync(&data->client->dev); + ret = pm_runtime_get_sync(data->dev); else { - pm_runtime_mark_last_busy(&data->client->dev); - ret = pm_runtime_put_autosuspend(&data->client->dev); + pm_runtime_mark_last_busy(data->dev); + ret = pm_runtime_put_autosuspend(data->dev); } if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Failed: bmg160_set_power_state for %d\n", on); if (on) - pm_runtime_put_noidle(&data->client->dev); + pm_runtime_put_noidle(data->dev); return ret; } @@ -284,43 +276,30 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data, int ret; /* Enable/Disable INT_MAP0 mapping */ - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_MAP_0); + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_0, + BMG160_INT_MAP_0_BIT_ANY, + (status ? BMG160_INT_MAP_0_BIT_ANY : 0)); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_int_map0\n"); - return ret; - } - if (status) - ret |= BMG160_INT_MAP_0_BIT_ANY; - else - ret &= ~BMG160_INT_MAP_0_BIT_ANY; - - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_MAP_0, - ret); - if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_int_map0\n"); + dev_err(data->dev, "Error updating bits reg_int_map0\n"); return ret; } /* Enable/Disable slope interrupts */ if (status) { /* Update slope thres */ - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_SLOPE_THRES, - data->slope_thres); + ret = regmap_write(data->regmap, BMG160_REG_SLOPE_THRES, + data->slope_thres); if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Error writing reg_slope_thres\n"); return ret; } - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_MOTION_INTR, - BMG160_INT_MOTION_X | - BMG160_INT_MOTION_Y | - BMG160_INT_MOTION_Z); + ret = regmap_write(data->regmap, BMG160_REG_MOTION_INTR, + BMG160_INT_MOTION_X | BMG160_INT_MOTION_Y | + BMG160_INT_MOTION_Z); if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Error writing reg_motion_intr\n"); return ret; } @@ -331,28 +310,26 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data, * to set latched mode, we will be flooded anyway with INTR */ if (!data->dready_trigger_on) { - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_RST_LATCH, - BMG160_INT_MODE_LATCH_INT | - BMG160_INT_MODE_LATCH_RESET); + ret = regmap_write(data->regmap, + BMG160_REG_INT_RST_LATCH, + BMG160_INT_MODE_LATCH_INT | + BMG160_INT_MODE_LATCH_RESET); if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Error writing reg_rst_latch\n"); return ret; } } - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_EN_0, - BMG160_DATA_ENABLE_INT); + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, + BMG160_DATA_ENABLE_INT); - } else - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_EN_0, - 0); + } else { + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0); + } if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_int_en0\n"); + dev_err(data->dev, "Error writing reg_int_en0\n"); return ret; } @@ -365,59 +342,43 @@ static int bmg160_setup_new_data_interrupt(struct bmg160_data *data, int ret; /* Enable/Disable INT_MAP1 mapping */ - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_MAP_1); + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_1, + BMG160_INT_MAP_1_BIT_NEW_DATA, + (status ? BMG160_INT_MAP_1_BIT_NEW_DATA : 0)); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_int_map1\n"); - return ret; - } - - if (status) - ret |= BMG160_INT_MAP_1_BIT_NEW_DATA; - else - ret &= ~BMG160_INT_MAP_1_BIT_NEW_DATA; - - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_MAP_1, - ret); - if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_int_map1\n"); + dev_err(data->dev, "Error updating bits in reg_int_map1\n"); return ret; } if (status) { - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_RST_LATCH, - BMG160_INT_MODE_NON_LATCH_INT | - BMG160_INT_MODE_LATCH_RESET); + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH, + BMG160_INT_MODE_NON_LATCH_INT | + BMG160_INT_MODE_LATCH_RESET); if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Error writing reg_rst_latch\n"); return ret; } - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_EN_0, - BMG160_DATA_ENABLE_INT); + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, + BMG160_DATA_ENABLE_INT); } else { /* Restore interrupt mode */ - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_RST_LATCH, - BMG160_INT_MODE_LATCH_INT | - BMG160_INT_MODE_LATCH_RESET); + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH, + BMG160_INT_MODE_LATCH_INT | + BMG160_INT_MODE_LATCH_RESET); if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Error writing reg_rst_latch\n"); return ret; } - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_EN_0, - 0); + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0); } if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_int_en0\n"); + dev_err(data->dev, "Error writing reg_int_en0\n"); return ret; } @@ -444,12 +405,10 @@ static int bmg160_set_scale(struct bmg160_data *data, int val) for (i = 0; i < ARRAY_SIZE(bmg160_scale_table); ++i) { if (bmg160_scale_table[i].scale == val) { - ret = i2c_smbus_write_byte_data( - data->client, - BMG160_REG_RANGE, - bmg160_scale_table[i].dps_range); + ret = regmap_write(data->regmap, BMG160_REG_RANGE, + bmg160_scale_table[i].dps_range); if (ret < 0) { - dev_err(&data->client->dev, + dev_err(data->dev, "Error writing reg_range\n"); return ret; } @@ -464,6 +423,7 @@ static int bmg160_set_scale(struct bmg160_data *data, int val) static int bmg160_get_temp(struct bmg160_data *data, int *val) { int ret; + unsigned int raw_val; mutex_lock(&data->mutex); ret = bmg160_set_power_state(data, true); @@ -472,15 +432,15 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val) return ret; } - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_TEMP); + ret = regmap_read(data->regmap, BMG160_REG_TEMP, &raw_val); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_temp\n"); + dev_err(data->dev, "Error reading reg_temp\n"); bmg160_set_power_state(data, false); mutex_unlock(&data->mutex); return ret; } - *val = sign_extend32(ret, 7); + *val = sign_extend32(raw_val, 7); ret = bmg160_set_power_state(data, false); mutex_unlock(&data->mutex); if (ret < 0) @@ -492,6 +452,7 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val) static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val) { int ret; + unsigned int raw_val; mutex_lock(&data->mutex); ret = bmg160_set_power_state(data, true); @@ -500,15 +461,16 @@ static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val) return ret; } - ret = i2c_smbus_read_word_data(data->client, BMG160_AXIS_TO_REG(axis)); + ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(axis), &raw_val, + 2); if (ret < 0) { - dev_err(&data->client->dev, "Error reading axis %d\n", axis); + dev_err(data->dev, "Error reading axis %d\n", axis); bmg160_set_power_state(data, false); mutex_unlock(&data->mutex); return ret; } - *val = sign_extend32(ret, 15); + *val = sign_extend32(raw_val, 15); ret = bmg160_set_power_state(data, false); mutex_unlock(&data->mutex); if (ret < 0) @@ -807,12 +769,13 @@ static irqreturn_t bmg160_trigger_handler(int irq, void *p) struct iio_dev *indio_dev = pf->indio_dev; struct bmg160_data *data = iio_priv(indio_dev); int bit, ret, i = 0; + unsigned int val; mutex_lock(&data->mutex); for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->masklength) { - ret = i2c_smbus_read_word_data(data->client, - BMG160_AXIS_TO_REG(bit)); + ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(bit), + &val, 2); if (ret < 0) { mutex_unlock(&data->mutex); goto err; @@ -840,12 +803,11 @@ static int bmg160_trig_try_reen(struct iio_trigger *trig) return 0; /* Set latched mode interrupt and clear any latched interrupt */ - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_RST_LATCH, - BMG160_INT_MODE_LATCH_INT | - BMG160_INT_MODE_LATCH_RESET); + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH, + BMG160_INT_MODE_LATCH_INT | + BMG160_INT_MODE_LATCH_RESET); if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_rst_latch\n"); + dev_err(data->dev, "Error writing reg_rst_latch\n"); return ret; } @@ -907,33 +869,34 @@ static irqreturn_t bmg160_event_handler(int irq, void *private) struct bmg160_data *data = iio_priv(indio_dev); int ret; int dir; + unsigned int val; - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_STATUS_2); + ret = regmap_read(data->regmap, BMG160_REG_INT_STATUS_2, &val); if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_int_status2\n"); + dev_err(data->dev, "Error reading reg_int_status2\n"); goto ack_intr_status; } - if (ret & 0x08) + if (val & 0x08) dir = IIO_EV_DIR_RISING; else dir = IIO_EV_DIR_FALLING; - if (ret & BMG160_ANY_MOTION_BIT_X) + if (val & BMG160_ANY_MOTION_BIT_X) iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL, 0, IIO_MOD_X, IIO_EV_TYPE_ROC, dir), iio_get_time_ns()); - if (ret & BMG160_ANY_MOTION_BIT_Y) + if (val & BMG160_ANY_MOTION_BIT_Y) iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL, 0, IIO_MOD_Y, IIO_EV_TYPE_ROC, dir), iio_get_time_ns()); - if (ret & BMG160_ANY_MOTION_BIT_Z) + if (val & BMG160_ANY_MOTION_BIT_Z) iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL, 0, IIO_MOD_Z, @@ -943,12 +906,11 @@ static irqreturn_t bmg160_event_handler(int irq, void *private) ack_intr_status: if (!data->dready_trigger_on) { - ret = i2c_smbus_write_byte_data(data->client, - BMG160_REG_INT_RST_LATCH, - BMG160_INT_MODE_LATCH_INT | - BMG160_INT_MODE_LATCH_RESET); + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH, + BMG160_INT_MODE_LATCH_INT | + BMG160_INT_MODE_LATCH_RESET); if (ret < 0) - dev_err(&data->client->dev, + dev_err(data->dev, "Error writing reg_rst_latch\n"); } @@ -993,18 +955,13 @@ static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = { .postdisable = bmg160_buffer_postdisable, }; -static int bmg160_gpio_probe(struct i2c_client *client, - struct bmg160_data *data) +static int bmg160_gpio_probe(struct bmg160_data *data) { struct device *dev; struct gpio_desc *gpio; - int ret; - if (!client) - return -EINVAL; - - dev = &client->dev; + dev = data->dev; /* data ready gpio interrupt pin */ gpio = devm_gpiod_get_index(dev, BMG160_GPIO_NAME, 0, GPIOD_IN); @@ -1013,11 +970,12 @@ static int bmg160_gpio_probe(struct i2c_client *client, return PTR_ERR(gpio); } - ret = gpiod_to_irq(gpio); + data->irq = gpiod_to_irq(gpio); - dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); + dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), + data->irq); - return ret; + return 0; } static const char *bmg160_match_acpi_device(struct device *dev) @@ -1031,21 +989,22 @@ static const char *bmg160_match_acpi_device(struct device *dev) return dev_name(dev); } -static int bmg160_probe(struct i2c_client *client, - const struct i2c_device_id *id) +int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, + const char *name) { struct bmg160_data *data; struct iio_dev *indio_dev; int ret; - const char *name = NULL; - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; data = iio_priv(indio_dev); - i2c_set_clientdata(client, indio_dev); - data->client = client; + dev_set_drvdata(dev, indio_dev); + data->dev = dev; + data->irq = irq; + data->regmap = regmap; ret = bmg160_chip_init(data); if (ret < 0) @@ -1053,25 +1012,22 @@ static int bmg160_probe(struct i2c_client *client, mutex_init(&data->mutex); - if (id) - name = id->name; + if (ACPI_HANDLE(dev)) + name = bmg160_match_acpi_device(dev); - if (ACPI_HANDLE(&client->dev)) - name = bmg160_match_acpi_device(&client->dev); - - indio_dev->dev.parent = &client->dev; + indio_dev->dev.parent = dev; indio_dev->channels = bmg160_channels; indio_dev->num_channels = ARRAY_SIZE(bmg160_channels); indio_dev->name = name; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &bmg160_info; - if (client->irq <= 0) - client->irq = bmg160_gpio_probe(client, data); + if (data->irq <= 0) + bmg160_gpio_probe(data); - if (client->irq > 0) { - ret = devm_request_threaded_irq(&client->dev, - client->irq, + if (data->irq > 0) { + ret = devm_request_threaded_irq(dev, + data->irq, bmg160_data_rdy_trig_poll, bmg160_event_handler, IRQF_TRIGGER_RISING, @@ -1080,28 +1036,28 @@ static int bmg160_probe(struct i2c_client *client, if (ret) return ret; - data->dready_trig = devm_iio_trigger_alloc(&client->dev, + data->dready_trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id); if (!data->dready_trig) return -ENOMEM; - data->motion_trig = devm_iio_trigger_alloc(&client->dev, + data->motion_trig = devm_iio_trigger_alloc(dev, "%s-any-motion-dev%d", indio_dev->name, indio_dev->id); if (!data->motion_trig) return -ENOMEM; - data->dready_trig->dev.parent = &client->dev; + data->dready_trig->dev.parent = dev; data->dready_trig->ops = &bmg160_trigger_ops; iio_trigger_set_drvdata(data->dready_trig, indio_dev); ret = iio_trigger_register(data->dready_trig); if (ret) return ret; - data->motion_trig->dev.parent = &client->dev; + data->motion_trig->dev.parent = dev; data->motion_trig->ops = &bmg160_trigger_ops; iio_trigger_set_drvdata(data->motion_trig, indio_dev); ret = iio_trigger_register(data->motion_trig); @@ -1116,25 +1072,25 @@ static int bmg160_probe(struct i2c_client *client, bmg160_trigger_handler, &bmg160_buffer_setup_ops); if (ret < 0) { - dev_err(&client->dev, + dev_err(dev, "iio triggered buffer setup failed\n"); goto err_trigger_unregister; } ret = iio_device_register(indio_dev); if (ret < 0) { - dev_err(&client->dev, "unable to register iio device\n"); + dev_err(dev, "unable to register iio device\n"); goto err_buffer_cleanup; } - ret = pm_runtime_set_active(&client->dev); + ret = pm_runtime_set_active(dev); if (ret) goto err_iio_unregister; - pm_runtime_enable(&client->dev); - pm_runtime_set_autosuspend_delay(&client->dev, + pm_runtime_enable(dev); + pm_runtime_set_autosuspend_delay(dev, BMG160_AUTO_SUSPEND_DELAY_MS); - pm_runtime_use_autosuspend(&client->dev); + pm_runtime_use_autosuspend(dev); return 0; @@ -1150,15 +1106,16 @@ err_trigger_unregister: return ret; } +EXPORT_SYMBOL_GPL(bmg160_core_probe); -static int bmg160_remove(struct i2c_client *client) +void bmg160_core_remove(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(client); + struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmg160_data *data = iio_priv(indio_dev); - pm_runtime_disable(&client->dev); - pm_runtime_set_suspended(&client->dev); - pm_runtime_put_noidle(&client->dev); + pm_runtime_disable(dev); + pm_runtime_set_suspended(dev); + pm_runtime_put_noidle(dev); iio_device_unregister(indio_dev); iio_triggered_buffer_cleanup(indio_dev); @@ -1171,14 +1128,13 @@ static int bmg160_remove(struct i2c_client *client) mutex_lock(&data->mutex); bmg160_set_mode(data, BMG160_MODE_DEEP_SUSPEND); mutex_unlock(&data->mutex); - - return 0; } +EXPORT_SYMBOL_GPL(bmg160_core_remove); #ifdef CONFIG_PM_SLEEP static int bmg160_suspend(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmg160_data *data = iio_priv(indio_dev); mutex_lock(&data->mutex); @@ -1190,7 +1146,7 @@ static int bmg160_suspend(struct device *dev) static int bmg160_resume(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmg160_data *data = iio_priv(indio_dev); mutex_lock(&data->mutex); @@ -1206,13 +1162,13 @@ static int bmg160_resume(struct device *dev) #ifdef CONFIG_PM static int bmg160_runtime_suspend(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmg160_data *data = iio_priv(indio_dev); int ret; ret = bmg160_set_mode(data, BMG160_MODE_SUSPEND); if (ret < 0) { - dev_err(&data->client->dev, "set mode failed\n"); + dev_err(data->dev, "set mode failed\n"); return -EAGAIN; } @@ -1221,7 +1177,7 @@ static int bmg160_runtime_suspend(struct device *dev) static int bmg160_runtime_resume(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmg160_data *data = iio_priv(indio_dev); int ret; @@ -1235,39 +1191,12 @@ static int bmg160_runtime_resume(struct device *dev) } #endif -static const struct dev_pm_ops bmg160_pm_ops = { +const struct dev_pm_ops bmg160_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(bmg160_suspend, bmg160_resume) SET_RUNTIME_PM_OPS(bmg160_runtime_suspend, bmg160_runtime_resume, NULL) }; - -static const struct acpi_device_id bmg160_acpi_match[] = { - {"BMG0160", 0}, - {"BMI055B", 0}, - {}, -}; - -MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match); - -static const struct i2c_device_id bmg160_id[] = { - {"bmg160", 0}, - {"bmi055_gyro", 0}, - {} -}; - -MODULE_DEVICE_TABLE(i2c, bmg160_id); - -static struct i2c_driver bmg160_driver = { - .driver = { - .name = BMG160_DRV_NAME, - .acpi_match_table = ACPI_PTR(bmg160_acpi_match), - .pm = &bmg160_pm_ops, - }, - .probe = bmg160_probe, - .remove = bmg160_remove, - .id_table = bmg160_id, -}; -module_i2c_driver(bmg160_driver); +EXPORT_SYMBOL_GPL(bmg160_pm_ops); MODULE_AUTHOR("Srinivas Pandruvada "); MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/gyro/bmg160_i2c.c b/drivers/iio/gyro/bmg160_i2c.c new file mode 100644 index 000000000000..90126a5a7663 --- /dev/null +++ b/drivers/iio/gyro/bmg160_i2c.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include + +#include "bmg160.h" + +static const struct regmap_config bmg160_regmap_i2c_conf = { + .reg_bits = 8, + .val_bits = 8, + .max_register = 0x3f +}; + +static int bmg160_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct regmap *regmap; + const char *name = NULL; + + regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf); + if (IS_ERR(regmap)) { + dev_err(&client->dev, "Failed to register i2c regmap %d\n", + (int)PTR_ERR(regmap)); + return PTR_ERR(regmap); + } + + if (id) + name = id->name; + + return bmg160_core_probe(&client->dev, regmap, client->irq, name); +} + +static int bmg160_i2c_remove(struct i2c_client *client) +{ + bmg160_core_remove(&client->dev); + + return 0; +} + +static const struct acpi_device_id bmg160_acpi_match[] = { + {"BMG0160", 0}, + {"BMI055B", 0}, + {}, +}; + +MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match); + +static const struct i2c_device_id bmg160_i2c_id[] = { + {"bmg160", 0}, + {"bmi055_gyro", 0}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, bmg160_i2c_id); + +static struct i2c_driver bmg160_i2c_driver = { + .driver = { + .name = "bmg160_i2c", + .acpi_match_table = ACPI_PTR(bmg160_acpi_match), + .pm = &bmg160_pm_ops, + }, + .probe = bmg160_i2c_probe, + .remove = bmg160_i2c_remove, + .id_table = bmg160_i2c_id, +}; +module_i2c_driver(bmg160_i2c_driver); + +MODULE_AUTHOR("Srinivas Pandruvada "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("BMG160 I2C Gyro driver"); diff --git a/drivers/iio/gyro/bmg160_spi.c b/drivers/iio/gyro/bmg160_spi.c new file mode 100644 index 000000000000..021ea5fe6a37 --- /dev/null +++ b/drivers/iio/gyro/bmg160_spi.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include "bmg160.h" + +static const struct regmap_config bmg160_regmap_spi_conf = { + .reg_bits = 8, + .val_bits = 8, + .max_register = 0x3f, +}; + +static int bmg160_spi_probe(struct spi_device *spi) +{ + struct regmap *regmap; + const struct spi_device_id *id = spi_get_device_id(spi); + + regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf); + if (IS_ERR(regmap)) { + dev_err(&spi->dev, "Failed to register spi regmap %d\n", + (int)PTR_ERR(regmap)); + return PTR_ERR(regmap); + } + + return bmg160_core_probe(&spi->dev, regmap, spi->irq, id->name); +} + +static int bmg160_spi_remove(struct spi_device *spi) +{ + bmg160_core_remove(&spi->dev); + + return 0; +} + +static const struct spi_device_id bmg160_spi_id[] = { + {"bmg160", 0}, + {"bmi055_gyro", 0}, + {} +}; + +MODULE_DEVICE_TABLE(spi, bmg160_spi_id); + +static struct spi_driver bmg160_spi_driver = { + .driver = { + .name = "bmg160_spi", + .pm = &bmg160_pm_ops, + }, + .probe = bmg160_spi_probe, + .remove = bmg160_spi_remove, + .id_table = bmg160_spi_id, +}; +module_spi_driver(bmg160_spi_driver); + +MODULE_AUTHOR("Markus Pargmann "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("BMG160 SPI Gyro driver"); diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c index 4b993a5bc9a1..02eddcebeea3 100644 --- a/drivers/iio/gyro/st_gyro_core.c +++ b/drivers/iio/gyro/st_gyro_core.c @@ -383,6 +383,7 @@ static const struct iio_info gyro_info = { .attrs = &st_gyro_attribute_group, .read_raw = &st_gyro_read_raw, .write_raw = &st_gyro_write_raw, + .debugfs_reg_access = &st_sensors_debugfs_reg_access, }; #ifdef CONFIG_IIO_TRIGGER diff --git a/drivers/iio/humidity/Kconfig b/drivers/iio/humidity/Kconfig index 688c0d1cb47d..6a23698d347c 100644 --- a/drivers/iio/humidity/Kconfig +++ b/drivers/iio/humidity/Kconfig @@ -12,6 +12,29 @@ config DHT11 Other sensors should work as well as long as they speak the same protocol. +config HDC100X + tristate "TI HDC100x relative humidity and temperature sensor" + depends on I2C + help + Say yes here to build support for the TI HDC100x series of + relative humidity and temperature sensors. + + To compile this driver as a module, choose M here: the module + will be called hdc100x. + +config HTU21 + tristate "Measurement Specialties HTU21 humidity & temperature sensor" + depends on I2C + select IIO_MS_SENSORS_I2C + help + If you say yes here you get support for the Measurement Specialties + HTU21 humidity and temperature sensor. + This driver is also used for MS8607 temperature, pressure & humidity + sensor + + This driver can also be built as a module. If so, the module will + be called htu21. + config SI7005 tristate "SI7005 relative humidity and temperature sensor" depends on I2C diff --git a/drivers/iio/humidity/Makefile b/drivers/iio/humidity/Makefile index 86e2d26e9f4d..c9f089a9a6b8 100644 --- a/drivers/iio/humidity/Makefile +++ b/drivers/iio/humidity/Makefile @@ -3,5 +3,7 @@ # obj-$(CONFIG_DHT11) += dht11.o +obj-$(CONFIG_HDC100X) += hdc100x.o +obj-$(CONFIG_HTU21) += htu21.o obj-$(CONFIG_SI7005) += si7005.o obj-$(CONFIG_SI7020) += si7020.o diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c new file mode 100644 index 000000000000..a7f61e881a49 --- /dev/null +++ b/drivers/iio/humidity/hdc100x.c @@ -0,0 +1,320 @@ +/* + * hdc100x.c - Support for the TI HDC100x temperature + humidity sensors + * + * Copyright (C) 2015 Matt Ranostay + * + * 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 +#include + +#include +#include + +#define HDC100X_REG_TEMP 0x00 +#define HDC100X_REG_HUMIDITY 0x01 + +#define HDC100X_REG_CONFIG 0x02 +#define HDC100X_REG_CONFIG_HEATER_EN BIT(13) + +struct hdc100x_data { + struct i2c_client *client; + struct mutex lock; + u16 config; + + /* integration time of the sensor */ + int adc_int_us[2]; +}; + +/* integration time in us */ +static const int hdc100x_int_time[][3] = { + { 6350, 3650, 0 }, /* IIO_TEMP channel*/ + { 6500, 3850, 2500 }, /* IIO_HUMIDITYRELATIVE channel */ +}; + +/* HDC100X_REG_CONFIG shift and mask values */ +static const struct { + int shift; + int mask; +} hdc100x_resolution_shift[2] = { + { /* IIO_TEMP channel */ + .shift = 10, + .mask = 1 + }, + { /* IIO_HUMIDITYRELATIVE channel */ + .shift = 8, + .mask = 2, + }, +}; + +static IIO_CONST_ATTR(temp_integration_time_available, + "0.00365 0.00635"); + +static IIO_CONST_ATTR(humidityrelative_integration_time_available, + "0.0025 0.00385 0.0065"); + +static IIO_CONST_ATTR(out_current_heater_raw_available, + "0 1"); + +static struct attribute *hdc100x_attributes[] = { + &iio_const_attr_temp_integration_time_available.dev_attr.attr, + &iio_const_attr_humidityrelative_integration_time_available.dev_attr.attr, + &iio_const_attr_out_current_heater_raw_available.dev_attr.attr, + NULL +}; + +static struct attribute_group hdc100x_attribute_group = { + .attrs = hdc100x_attributes, +}; + +static const struct iio_chan_spec hdc100x_channels[] = { + { + .type = IIO_TEMP, + .address = HDC100X_REG_TEMP, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_INT_TIME) | + BIT(IIO_CHAN_INFO_OFFSET), + }, + { + .type = IIO_HUMIDITYRELATIVE, + .address = HDC100X_REG_HUMIDITY, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_INT_TIME) + }, + { + .type = IIO_CURRENT, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .extend_name = "heater", + .output = 1, + }, +}; + +static int hdc100x_update_config(struct hdc100x_data *data, int mask, int val) +{ + int tmp = (~mask & data->config) | val; + int ret; + + ret = i2c_smbus_write_word_swapped(data->client, + HDC100X_REG_CONFIG, tmp); + if (!ret) + data->config = tmp; + + return ret; +} + +static int hdc100x_set_it_time(struct hdc100x_data *data, int chan, int val2) +{ + int shift = hdc100x_resolution_shift[chan].shift; + int ret = -EINVAL; + int i; + + for (i = 0; i < ARRAY_SIZE(hdc100x_int_time[chan]); i++) { + if (val2 && val2 == hdc100x_int_time[chan][i]) { + ret = hdc100x_update_config(data, + hdc100x_resolution_shift[chan].mask << shift, + i << shift); + if (!ret) + data->adc_int_us[chan] = val2; + break; + } + } + + return ret; +} + +static int hdc100x_get_measurement(struct hdc100x_data *data, + struct iio_chan_spec const *chan) +{ + struct i2c_client *client = data->client; + int delay = data->adc_int_us[chan->address]; + int ret; + int val; + + /* start measurement */ + ret = i2c_smbus_write_byte(client, chan->address); + if (ret < 0) { + dev_err(&client->dev, "cannot start measurement"); + return ret; + } + + /* wait for integration time to pass */ + usleep_range(delay, delay + 1000); + + /* + * i2c_smbus_read_word_data cannot() be used here due to the command + * value not being understood and causes NAKs preventing any reading + * from being accessed. + */ + ret = i2c_smbus_read_byte(client); + if (ret < 0) { + dev_err(&client->dev, "cannot read high byte measurement"); + return ret; + } + val = ret << 6; + + ret = i2c_smbus_read_byte(client); + if (ret < 0) { + dev_err(&client->dev, "cannot read low byte measurement"); + return ret; + } + val |= ret >> 2; + + return val; +} + +static int hdc100x_get_heater_status(struct hdc100x_data *data) +{ + return !!(data->config & HDC100X_REG_CONFIG_HEATER_EN); +} + +static int hdc100x_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + struct hdc100x_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: { + int ret; + + mutex_lock(&data->lock); + if (chan->type == IIO_CURRENT) { + *val = hdc100x_get_heater_status(data); + ret = IIO_VAL_INT; + } else { + ret = hdc100x_get_measurement(data, chan); + if (ret >= 0) { + *val = ret; + ret = IIO_VAL_INT; + } + } + mutex_unlock(&data->lock); + return ret; + } + case IIO_CHAN_INFO_INT_TIME: + *val = 0; + *val2 = data->adc_int_us[chan->address]; + return IIO_VAL_INT_PLUS_MICRO; + case IIO_CHAN_INFO_SCALE: + if (chan->type == IIO_TEMP) { + *val = 165; + *val2 = 65536 >> 2; + return IIO_VAL_FRACTIONAL; + } else { + *val = 0; + *val2 = 10000; + return IIO_VAL_INT_PLUS_MICRO; + } + break; + case IIO_CHAN_INFO_OFFSET: + *val = -3971; + *val2 = 879096; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } +} + +static int hdc100x_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct hdc100x_data *data = iio_priv(indio_dev); + int ret = -EINVAL; + + switch (mask) { + case IIO_CHAN_INFO_INT_TIME: + if (val != 0) + return -EINVAL; + + mutex_lock(&data->lock); + ret = hdc100x_set_it_time(data, chan->address, val2); + mutex_unlock(&data->lock); + return ret; + case IIO_CHAN_INFO_RAW: + if (chan->type != IIO_CURRENT || val2 != 0) + return -EINVAL; + + mutex_lock(&data->lock); + ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_HEATER_EN, + val ? HDC100X_REG_CONFIG_HEATER_EN : 0); + mutex_unlock(&data->lock); + return ret; + default: + return -EINVAL; + } +} + +static const struct iio_info hdc100x_info = { + .read_raw = hdc100x_read_raw, + .write_raw = hdc100x_write_raw, + .attrs = &hdc100x_attribute_group, + .driver_module = THIS_MODULE, +}; + +static int hdc100x_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct iio_dev *indio_dev; + struct hdc100x_data *data; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BYTE)) + return -ENODEV; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->client = client; + mutex_init(&data->lock); + + indio_dev->dev.parent = &client->dev; + indio_dev->name = dev_name(&client->dev); + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &hdc100x_info; + + indio_dev->channels = hdc100x_channels; + indio_dev->num_channels = ARRAY_SIZE(hdc100x_channels); + + /* be sure we are in a known state */ + hdc100x_set_it_time(data, 0, hdc100x_int_time[0][0]); + hdc100x_set_it_time(data, 1, hdc100x_int_time[1][0]); + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static const struct i2c_device_id hdc100x_id[] = { + { "hdc100x", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, hdc100x_id); + +static struct i2c_driver hdc100x_driver = { + .driver = { + .name = "hdc100x", + }, + .probe = hdc100x_probe, + .id_table = hdc100x_id, +}; +module_i2c_driver(hdc100x_driver); + +MODULE_AUTHOR("Matt Ranostay "); +MODULE_DESCRIPTION("TI HDC100x humidity and temperature sensor driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/iio/humidity/htu21.c b/drivers/iio/humidity/htu21.c new file mode 100644 index 000000000000..d1636a74980e --- /dev/null +++ b/drivers/iio/humidity/htu21.c @@ -0,0 +1,253 @@ +/* + * htu21.c - Support for Measurement-Specialties + * htu21 temperature & humidity sensor + * and humidity part of MS8607 sensor + * + * Copyright (c) 2014 Measurement-Specialties + * + * Licensed under the GPL-2. + * + * (7-bit I2C slave address 0x40) + * + * Datasheet: + * http://www.meas-spec.com/downloads/HTU21D.pdf + * Datasheet: + * http://www.meas-spec.com/downloads/MS8607-02BA01.pdf + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "../common/ms_sensors/ms_sensors_i2c.h" + +#define HTU21_RESET 0xFE + +enum { + HTU21, + MS8607 +}; + +static const int htu21_samp_freq[4] = { 20, 40, 70, 120 }; +/* String copy of the above const for readability purpose */ +static const char htu21_show_samp_freq[] = "20 40 70 120"; + +static int htu21_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, int *val, + int *val2, long mask) +{ + int ret, temperature; + unsigned int humidity; + struct ms_ht_dev *dev_data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_PROCESSED: + switch (channel->type) { + case IIO_TEMP: /* in milli °C */ + ret = ms_sensors_ht_read_temperature(dev_data, + &temperature); + if (ret) + return ret; + *val = temperature; + + return IIO_VAL_INT; + case IIO_HUMIDITYRELATIVE: /* in milli %RH */ + ret = ms_sensors_ht_read_humidity(dev_data, + &humidity); + if (ret) + return ret; + *val = humidity; + + return IIO_VAL_INT; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_SAMP_FREQ: + *val = htu21_samp_freq[dev_data->res_index]; + + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int htu21_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct ms_ht_dev *dev_data = iio_priv(indio_dev); + int i, ret; + + switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: + i = ARRAY_SIZE(htu21_samp_freq); + while (i-- > 0) + if (val == htu21_samp_freq[i]) + break; + if (i < 0) + return -EINVAL; + mutex_lock(&dev_data->lock); + dev_data->res_index = i; + ret = ms_sensors_write_resolution(dev_data, i); + mutex_unlock(&dev_data->lock); + + return ret; + default: + return -EINVAL; + } +} + +static const struct iio_chan_spec htu21_channels[] = { + { + .type = IIO_TEMP, + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + }, + { + .type = IIO_HUMIDITYRELATIVE, + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + } +}; + +/* + * Meas Spec recommendation is to not read temperature + * on this driver part for MS8607 + */ +static const struct iio_chan_spec ms8607_channels[] = { + { + .type = IIO_HUMIDITYRELATIVE, + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + } +}; + +static ssize_t htu21_show_battery_low(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct ms_ht_dev *dev_data = iio_priv(indio_dev); + + return ms_sensors_show_battery_low(dev_data, buf); +} + +static ssize_t htu21_show_heater(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct ms_ht_dev *dev_data = iio_priv(indio_dev); + + return ms_sensors_show_heater(dev_data, buf); +} + +static ssize_t htu21_write_heater(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct ms_ht_dev *dev_data = iio_priv(indio_dev); + + return ms_sensors_write_heater(dev_data, buf, len); +} + +static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(htu21_show_samp_freq); +static IIO_DEVICE_ATTR(battery_low, S_IRUGO, + htu21_show_battery_low, NULL, 0); +static IIO_DEVICE_ATTR(heater_enable, S_IRUGO | S_IWUSR, + htu21_show_heater, htu21_write_heater, 0); + +static struct attribute *htu21_attributes[] = { + &iio_const_attr_sampling_frequency_available.dev_attr.attr, + &iio_dev_attr_battery_low.dev_attr.attr, + &iio_dev_attr_heater_enable.dev_attr.attr, + NULL, +}; + +static const struct attribute_group htu21_attribute_group = { + .attrs = htu21_attributes, +}; + +static const struct iio_info htu21_info = { + .read_raw = htu21_read_raw, + .write_raw = htu21_write_raw, + .attrs = &htu21_attribute_group, + .driver_module = THIS_MODULE, +}; + +static int htu21_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct ms_ht_dev *dev_data; + struct iio_dev *indio_dev; + int ret; + u64 serial_number; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WRITE_BYTE_DATA | + I2C_FUNC_SMBUS_WRITE_BYTE | + I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { + dev_err(&client->dev, + "Adapter does not support some i2c transaction\n"); + return -ENODEV; + } + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data)); + if (!indio_dev) + return -ENOMEM; + + dev_data = iio_priv(indio_dev); + dev_data->client = client; + dev_data->res_index = 0; + mutex_init(&dev_data->lock); + + indio_dev->info = &htu21_info; + indio_dev->name = id->name; + indio_dev->dev.parent = &client->dev; + indio_dev->modes = INDIO_DIRECT_MODE; + + if (id->driver_data == MS8607) { + indio_dev->channels = ms8607_channels; + indio_dev->num_channels = ARRAY_SIZE(ms8607_channels); + } else { + indio_dev->channels = htu21_channels; + indio_dev->num_channels = ARRAY_SIZE(htu21_channels); + } + + i2c_set_clientdata(client, indio_dev); + + ret = ms_sensors_reset(client, HTU21_RESET, 15000); + if (ret) + return ret; + + ret = ms_sensors_read_serial(client, &serial_number); + if (ret) + return ret; + dev_info(&client->dev, "Serial number : %llx", serial_number); + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static const struct i2c_device_id htu21_id[] = { + {"htu21", HTU21}, + {"ms8607-humidity", MS8607}, + {} +}; + +static struct i2c_driver htu21_driver = { + .probe = htu21_probe, + .id_table = htu21_id, + .driver = { + .name = "htu21", + }, +}; + +module_i2c_driver(htu21_driver); + +MODULE_DESCRIPTION("Measurement-Specialties htu21 temperature and humidity driver"); +MODULE_AUTHOR("William Markezana "); +MODULE_AUTHOR("Ludovic Tancerel "); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c index fa3b809aff5e..12128d1ca570 100644 --- a/drivers/iio/humidity/si7020.c +++ b/drivers/iio/humidity/si7020.c @@ -57,8 +57,12 @@ static int si7020_read_raw(struct iio_dev *indio_dev, if (ret < 0) return ret; *val = ret >> 2; + /* + * Humidity values can slightly exceed the 0-100%RH + * range and should be corrected by software + */ if (chan->type == IIO_HUMIDITYRELATIVE) - *val &= GENMASK(11, 0); + *val = clamp_val(*val, 786, 13893); return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: if (chan->type == IIO_TEMP) diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c index 82cdf5090fa7..dbf5e9936635 100644 --- a/drivers/iio/imu/kmx61.c +++ b/drivers/iio/imu/kmx61.c @@ -27,7 +27,6 @@ #include #define KMX61_DRV_NAME "kmx61" -#define KMX61_GPIO_NAME "kmx61_int" #define KMX61_IRQ_NAME "kmx61_event" #define KMX61_REG_WHO_AM_I 0x00 @@ -1243,30 +1242,6 @@ static const char *kmx61_match_acpi_device(struct device *dev) return dev_name(dev); } -static int kmx61_gpio_probe(struct i2c_client *client, struct kmx61_data *data) -{ - struct device *dev; - struct gpio_desc *gpio; - int ret; - - if (!client) - return -EINVAL; - - dev = &client->dev; - - /* data ready gpio interrupt pin */ - gpio = devm_gpiod_get_index(dev, KMX61_GPIO_NAME, 0, GPIOD_IN); - if (IS_ERR(gpio)) { - dev_err(dev, "acpi gpio get index failed\n"); - return PTR_ERR(gpio); - } - - ret = gpiod_to_irq(gpio); - - dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); - return ret; -} - static struct iio_dev *kmx61_indiodev_setup(struct kmx61_data *data, const struct iio_info *info, const struct iio_chan_spec *chan, @@ -1360,9 +1335,6 @@ static int kmx61_probe(struct i2c_client *client, if (ret < 0) return ret; - if (client->irq < 0) - client->irq = kmx61_gpio_probe(client, data); - if (client->irq > 0) { ret = devm_request_threaded_irq(&client->dev, client->irq, kmx61_data_rdy_trig_poll, diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index b3fcc2c449d8..208358f9e7e3 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -75,6 +75,8 @@ static const char * const iio_chan_type_name_spec[] = { [IIO_ENERGY] = "energy", [IIO_DISTANCE] = "distance", [IIO_VELOCITY] = "velocity", + [IIO_CONCENTRATION] = "concentration", + [IIO_RESISTANCE] = "resistance", }; static const char * const iio_modifier_names[] = { @@ -111,6 +113,8 @@ static const char * const iio_modifier_names[] = { [IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z] = "sqrt(x^2+y^2+z^2)", [IIO_MOD_I] = "i", [IIO_MOD_Q] = "q", + [IIO_MOD_CO2] = "co2", + [IIO_MOD_VOC] = "voc", }; /* relies on pairs of these shared then separate */ @@ -962,7 +966,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev) static void iio_dev_release(struct device *device) { struct iio_dev *indio_dev = dev_to_iio_dev(device); - if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) + if (indio_dev->modes & (INDIO_BUFFER_TRIGGERED | INDIO_EVENT_TRIGGERED)) iio_device_unregister_trigger_consumer(indio_dev); iio_device_unregister_eventset(indio_dev); iio_device_unregister_sysfs(indio_dev); @@ -1153,6 +1157,8 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (cmd == IIO_GET_EVENT_FD_IOCTL) { fd = iio_event_getfd(indio_dev); + if (fd < 0) + return fd; if (copy_to_user(ip, &fd, sizeof(fd))) return -EFAULT; return 0; @@ -1241,7 +1247,7 @@ int iio_device_register(struct iio_dev *indio_dev) "Failed to register event set\n"); goto error_free_sysfs; } - if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) + if (indio_dev->modes & (INDIO_BUFFER_TRIGGERED | INDIO_EVENT_TRIGGERED)) iio_device_register_trigger_consumer(indio_dev); if ((indio_dev->modes & INDIO_ALL_BUFFER_MODES) && diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index 570606c2adbd..ae2806aafb72 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -366,10 +366,18 @@ static ssize_t iio_trigger_write_current(struct device *dev, indio_dev->trig = trig; - if (oldtrig) + if (oldtrig) { + if (indio_dev->modes & INDIO_EVENT_TRIGGERED) + iio_trigger_detach_poll_func(oldtrig, + indio_dev->pollfunc_event); iio_trigger_put(oldtrig); - if (indio_dev->trig) + } + if (indio_dev->trig) { iio_trigger_get(indio_dev->trig); + if (indio_dev->modes & INDIO_EVENT_TRIGGERED) + iio_trigger_attach_poll_func(indio_dev->trig, + indio_dev->pollfunc_event); + } return len; } diff --git a/drivers/iio/industrialio-triggered-event.c b/drivers/iio/industrialio-triggered-event.c new file mode 100644 index 000000000000..8cc254fac16a --- /dev/null +++ b/drivers/iio/industrialio-triggered-event.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2015 Cogent Embedded, Inc. + * + * 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. + */ + +#include +#include +#include +#include +#include +#include + +/** + * iio_triggered_event_setup() - Setup pollfunc_event for triggered event + * @indio_dev: IIO device structure + * @h: Function which will be used as pollfunc_event top half + * @thread: Function which will be used as pollfunc_event bottom half + * + * This function combines some common tasks which will normally be performed + * when setting up a triggered event. It will allocate the pollfunc_event and + * set mode to use it for triggered event. + * + * Before calling this function the indio_dev structure should already be + * completely initialized, but not yet registered. In practice this means that + * this function should be called right before iio_device_register(). + * + * To free the resources allocated by this function call + * iio_triggered_event_cleanup(). + */ +int iio_triggered_event_setup(struct iio_dev *indio_dev, + irqreturn_t (*h)(int irq, void *p), + irqreturn_t (*thread)(int irq, void *p)) +{ + indio_dev->pollfunc_event = iio_alloc_pollfunc(h, + thread, + IRQF_ONESHOT, + indio_dev, + "%s_consumer%d", + indio_dev->name, + indio_dev->id); + if (indio_dev->pollfunc_event == NULL) + return -ENOMEM; + + /* Flag that events polling is possible */ + indio_dev->modes |= INDIO_EVENT_TRIGGERED; + + return 0; +} +EXPORT_SYMBOL(iio_triggered_event_setup); + +/** + * iio_triggered_event_cleanup() - Free resources allocated by iio_triggered_event_setup() + * @indio_dev: IIO device structure + */ +void iio_triggered_event_cleanup(struct iio_dev *indio_dev) +{ + indio_dev->modes &= ~INDIO_EVENT_TRIGGERED; + iio_dealloc_pollfunc(indio_dev->pollfunc_event); +} +EXPORT_SYMBOL(iio_triggered_event_cleanup); + +MODULE_AUTHOR("Vladimir Barinov"); +MODULE_DESCRIPTION("IIO helper functions for setting up triggered events"); +MODULE_LICENSE("GPL"); diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 7ed859a700c4..cfd3df8416bb 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -50,6 +50,19 @@ config APDS9300 To compile this driver as a module, choose M here: the module will be called apds9300. +config APDS9960 + tristate "Avago APDS9960 gesture/RGB/ALS/proximity sensor" + select REGMAP_I2C + select IIO_BUFFER + select IIO_KFIFO_BUF + depends on I2C + help + Say Y here to build I2C interface support for the Avago + APDS9960 gesture/RGB/ALS/proximity sensor. + + To compile this driver as a module, choose M here: the + module will be called apds9960 + config BH1750 tristate "ROHM BH1750 ambient light sensor" depends on I2C @@ -287,6 +300,16 @@ config TSL4531 To compile this driver as a module, choose M here: the module will be called tsl4531. +config US5182D + tristate "UPISEMI light and proximity sensor" + depends on I2C + help + If you say yes here you get support for the UPISEMI US5182D + ambient light and proximity sensor. + + This driver can also be built as a module. If so, the module + will be called us5182d. + config VCNL4000 tristate "VCNL4000 combined ALS and proximity sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 91c74c014b6f..b2c31053db0c 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_ACPI_ALS) += acpi-als.o obj-$(CONFIG_ADJD_S311) += adjd_s311.o obj-$(CONFIG_AL3320A) += al3320a.o obj-$(CONFIG_APDS9300) += apds9300.o +obj-$(CONFIG_APDS9960) += apds9960.o obj-$(CONFIG_BH1750) += bh1750.o obj-$(CONFIG_CM32181) += cm32181.o obj-$(CONFIG_CM3232) += cm3232.o @@ -27,4 +28,5 @@ obj-$(CONFIG_STK3310) += stk3310.o obj-$(CONFIG_TCS3414) += tcs3414.o obj-$(CONFIG_TCS3472) += tcs3472.o obj-$(CONFIG_TSL4531) += tsl4531.o +obj-$(CONFIG_US5182D) += us5182d.o obj-$(CONFIG_VCNL4000) += vcnl4000.o diff --git a/drivers/iio/light/apds9960.c b/drivers/iio/light/apds9960.c new file mode 100644 index 000000000000..7d269ef9e062 --- /dev/null +++ b/drivers/iio/light/apds9960.c @@ -0,0 +1,1130 @@ +/* + * apds9960.c - Support for Avago APDS9960 gesture/RGB/ALS/proximity sensor + * + * Copyright (C) 2015 Matt Ranostay + * + * 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. + * + * TODO: gesture + proximity calib offsets + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define APDS9960_REGMAP_NAME "apds9960_regmap" +#define APDS9960_DRV_NAME "apds9960" + +#define APDS9960_REG_RAM_START 0x00 +#define APDS9960_REG_RAM_END 0x7f + +#define APDS9960_REG_ENABLE 0x80 +#define APDS9960_REG_ATIME 0x81 +#define APDS9960_REG_WTIME 0x83 + +#define APDS9960_REG_AILTL 0x84 +#define APDS9960_REG_AILTH 0x85 +#define APDS9960_REG_AIHTL 0x86 +#define APDS9960_REG_AIHTH 0x87 + +#define APDS9960_REG_PILT 0x89 +#define APDS9960_REG_PIHT 0x8b +#define APDS9960_REG_PERS 0x8c + +#define APDS9960_REG_CONFIG_1 0x8d +#define APDS9960_REG_PPULSE 0x8e + +#define APDS9960_REG_CONTROL 0x8f +#define APDS9960_REG_CONTROL_AGAIN_MASK 0x03 +#define APDS9960_REG_CONTROL_PGAIN_MASK 0x0c +#define APDS9960_REG_CONTROL_AGAIN_MASK_SHIFT 0 +#define APDS9960_REG_CONTROL_PGAIN_MASK_SHIFT 2 + +#define APDS9960_REG_CONFIG_2 0x90 +#define APDS9960_REG_CONFIG_2_GGAIN_MASK 0x60 +#define APDS9960_REG_CONFIG_2_GGAIN_MASK_SHIFT 5 + +#define APDS9960_REG_ID 0x92 + +#define APDS9960_REG_STATUS 0x93 +#define APDS9960_REG_STATUS_PS_INT BIT(5) +#define APDS9960_REG_STATUS_ALS_INT BIT(4) +#define APDS9960_REG_STATUS_GINT BIT(2) + +#define APDS9960_REG_PDATA 0x9c +#define APDS9960_REG_POFFSET_UR 0x9d +#define APDS9960_REG_POFFSET_DL 0x9e +#define APDS9960_REG_CONFIG_3 0x9f + +#define APDS9960_REG_GPENTH 0xa0 +#define APDS9960_REG_GEXTH 0xa1 + +#define APDS9960_REG_GCONF_1 0xa2 +#define APDS9960_REG_GCONF_1_GFIFO_THRES_MASK 0xc0 +#define APDS9960_REG_GCONF_1_GFIFO_THRES_MASK_SHIFT 6 + +#define APDS9960_REG_GCONF_2 0xa3 +#define APDS9960_REG_GOFFSET_U 0xa4 +#define APDS9960_REG_GOFFSET_D 0xa5 +#define APDS9960_REG_GPULSE 0xa6 +#define APDS9960_REG_GOFFSET_L 0xa7 +#define APDS9960_REG_GOFFSET_R 0xa9 +#define APDS9960_REG_GCONF_3 0xaa + +#define APDS9960_REG_GCONF_4 0xab +#define APDS9960_REG_GFLVL 0xae +#define APDS9960_REG_GSTATUS 0xaf + +#define APDS9960_REG_IFORCE 0xe4 +#define APDS9960_REG_PICLEAR 0xe5 +#define APDS9960_REG_CICLEAR 0xe6 +#define APDS9960_REG_AICLEAR 0xe7 + +#define APDS9960_DEFAULT_PERS 0x33 +#define APDS9960_DEFAULT_GPENTH 0x50 +#define APDS9960_DEFAULT_GEXTH 0x40 + +#define APDS9960_MAX_PXS_THRES_VAL 255 +#define APDS9960_MAX_ALS_THRES_VAL 0xffff +#define APDS9960_MAX_INT_TIME_IN_US 1000000 + +enum apds9960_als_channel_idx { + IDX_ALS_CLEAR, IDX_ALS_RED, IDX_ALS_GREEN, IDX_ALS_BLUE, +}; + +#define APDS9960_REG_ALS_BASE 0x94 +#define APDS9960_REG_ALS_CHANNEL(_colour) \ + (APDS9960_REG_ALS_BASE + (IDX_ALS_##_colour * 2)) + +enum apds9960_gesture_channel_idx { + IDX_DIR_UP, IDX_DIR_DOWN, IDX_DIR_LEFT, IDX_DIR_RIGHT, +}; + +#define APDS9960_REG_GFIFO_BASE 0xfc +#define APDS9960_REG_GFIFO_DIR(_dir) \ + (APDS9960_REG_GFIFO_BASE + IDX_DIR_##_dir) + +struct apds9960_data { + struct i2c_client *client; + struct iio_dev *indio_dev; + struct mutex lock; + + /* regmap fields */ + struct regmap *regmap; + struct regmap_field *reg_int_als; + struct regmap_field *reg_int_ges; + struct regmap_field *reg_int_pxs; + + struct regmap_field *reg_enable_als; + struct regmap_field *reg_enable_ges; + struct regmap_field *reg_enable_pxs; + + /* state */ + int als_int; + int pxs_int; + int gesture_mode_running; + + /* gain values */ + int als_gain; + int pxs_gain; + + /* integration time value in us */ + int als_adc_int_us; + + /* gesture buffer */ + u8 buffer[4]; /* 4 8-bit channels */ +}; + +static const struct reg_default apds9960_reg_defaults[] = { + /* Default ALS integration time = 2.48ms */ + { APDS9960_REG_ATIME, 0xff }, +}; + +static const struct regmap_range apds9960_volatile_ranges[] = { + regmap_reg_range(APDS9960_REG_STATUS, + APDS9960_REG_PDATA), + regmap_reg_range(APDS9960_REG_GFLVL, + APDS9960_REG_GSTATUS), + regmap_reg_range(APDS9960_REG_GFIFO_DIR(UP), + APDS9960_REG_GFIFO_DIR(RIGHT)), + regmap_reg_range(APDS9960_REG_IFORCE, + APDS9960_REG_AICLEAR), +}; + +static const struct regmap_access_table apds9960_volatile_table = { + .yes_ranges = apds9960_volatile_ranges, + .n_yes_ranges = ARRAY_SIZE(apds9960_volatile_ranges), +}; + +static const struct regmap_range apds9960_precious_ranges[] = { + regmap_reg_range(APDS9960_REG_RAM_START, APDS9960_REG_RAM_END), +}; + +static const struct regmap_access_table apds9960_precious_table = { + .yes_ranges = apds9960_precious_ranges, + .n_yes_ranges = ARRAY_SIZE(apds9960_precious_ranges), +}; + +static const struct regmap_range apds9960_readable_ranges[] = { + regmap_reg_range(APDS9960_REG_ENABLE, + APDS9960_REG_GSTATUS), + regmap_reg_range(APDS9960_REG_GFIFO_DIR(UP), + APDS9960_REG_GFIFO_DIR(RIGHT)), +}; + +static const struct regmap_access_table apds9960_readable_table = { + .yes_ranges = apds9960_readable_ranges, + .n_yes_ranges = ARRAY_SIZE(apds9960_readable_ranges), +}; + +static const struct regmap_range apds9960_writeable_ranges[] = { + regmap_reg_range(APDS9960_REG_ENABLE, APDS9960_REG_CONFIG_2), + regmap_reg_range(APDS9960_REG_POFFSET_UR, APDS9960_REG_GCONF_4), + regmap_reg_range(APDS9960_REG_IFORCE, APDS9960_REG_AICLEAR), +}; + +static const struct regmap_access_table apds9960_writeable_table = { + .yes_ranges = apds9960_writeable_ranges, + .n_yes_ranges = ARRAY_SIZE(apds9960_writeable_ranges), +}; + +static const struct regmap_config apds9960_regmap_config = { + .name = APDS9960_REGMAP_NAME, + .reg_bits = 8, + .val_bits = 8, + .use_single_rw = 1, + + .volatile_table = &apds9960_volatile_table, + .precious_table = &apds9960_precious_table, + .rd_table = &apds9960_readable_table, + .wr_table = &apds9960_writeable_table, + + .reg_defaults = apds9960_reg_defaults, + .num_reg_defaults = ARRAY_SIZE(apds9960_reg_defaults), + .max_register = APDS9960_REG_GFIFO_DIR(RIGHT), + .cache_type = REGCACHE_RBTREE, +}; + +static const struct iio_event_spec apds9960_pxs_event_spec[] = { + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_ENABLE), + }, + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_FALLING, + .mask_separate = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_ENABLE), + }, +}; + +static const struct iio_event_spec apds9960_als_event_spec[] = { + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_ENABLE), + }, + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_FALLING, + .mask_separate = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_ENABLE), + }, +}; + +#define APDS9960_GESTURE_CHANNEL(_dir, _si) { \ + .type = IIO_PROXIMITY, \ + .channel = _si + 1, \ + .scan_index = _si, \ + .indexed = 1, \ + .scan_type = { \ + .sign = 'u', \ + .realbits = 8, \ + .storagebits = 8, \ + }, \ +} + +#define APDS9960_INTENSITY_CHANNEL(_colour) { \ + .type = IIO_INTENSITY, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_INT_TIME), \ + .channel2 = IIO_MOD_LIGHT_##_colour, \ + .address = APDS9960_REG_ALS_CHANNEL(_colour), \ + .modified = 1, \ + .scan_index = -1, \ +} + +static const unsigned long apds9960_scan_masks[] = {0xf, 0}; + +static const struct iio_chan_spec apds9960_channels[] = { + { + .type = IIO_PROXIMITY, + .address = APDS9960_REG_PDATA, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .channel = 0, + .indexed = 0, + .scan_index = -1, + + .event_spec = apds9960_pxs_event_spec, + .num_event_specs = ARRAY_SIZE(apds9960_pxs_event_spec), + }, + /* Gesture Sensor */ + APDS9960_GESTURE_CHANNEL(UP, 0), + APDS9960_GESTURE_CHANNEL(DOWN, 1), + APDS9960_GESTURE_CHANNEL(LEFT, 2), + APDS9960_GESTURE_CHANNEL(RIGHT, 3), + /* ALS */ + { + .type = IIO_INTENSITY, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_INT_TIME), + .channel2 = IIO_MOD_LIGHT_CLEAR, + .address = APDS9960_REG_ALS_CHANNEL(CLEAR), + .modified = 1, + .scan_index = -1, + + .event_spec = apds9960_als_event_spec, + .num_event_specs = ARRAY_SIZE(apds9960_als_event_spec), + }, + /* RGB Sensor */ + APDS9960_INTENSITY_CHANNEL(RED), + APDS9960_INTENSITY_CHANNEL(GREEN), + APDS9960_INTENSITY_CHANNEL(BLUE), +}; + +/* integration time in us */ +static const int apds9960_int_time[][2] = + { {28000, 246}, {100000, 219}, {200000, 182}, {700000, 0} }; + +/* gain mapping */ +static const int apds9960_pxs_gain_map[] = {1, 2, 4, 8}; +static const int apds9960_als_gain_map[] = {1, 4, 16, 64}; + +static IIO_CONST_ATTR(proximity_scale_available, "1 2 4 8"); +static IIO_CONST_ATTR(intensity_scale_available, "1 4 16 64"); +static IIO_CONST_ATTR_INT_TIME_AVAIL("0.028 0.1 0.2 0.7"); + +static struct attribute *apds9960_attributes[] = { + &iio_const_attr_proximity_scale_available.dev_attr.attr, + &iio_const_attr_intensity_scale_available.dev_attr.attr, + &iio_const_attr_integration_time_available.dev_attr.attr, + NULL, +}; + +static struct attribute_group apds9960_attribute_group = { + .attrs = apds9960_attributes, +}; + +static const struct reg_field apds9960_reg_field_int_als = + REG_FIELD(APDS9960_REG_ENABLE, 4, 4); + +static const struct reg_field apds9960_reg_field_int_ges = + REG_FIELD(APDS9960_REG_GCONF_4, 1, 1); + +static const struct reg_field apds9960_reg_field_int_pxs = + REG_FIELD(APDS9960_REG_ENABLE, 5, 5); + +static const struct reg_field apds9960_reg_field_enable_als = + REG_FIELD(APDS9960_REG_ENABLE, 1, 1); + +static const struct reg_field apds9960_reg_field_enable_ges = + REG_FIELD(APDS9960_REG_ENABLE, 6, 6); + +static const struct reg_field apds9960_reg_field_enable_pxs = + REG_FIELD(APDS9960_REG_ENABLE, 2, 2); + +static int apds9960_set_it_time(struct apds9960_data *data, int val2) +{ + int ret = -EINVAL; + int idx; + + for (idx = 0; idx < ARRAY_SIZE(apds9960_int_time); idx++) { + if (apds9960_int_time[idx][0] == val2) { + mutex_lock(&data->lock); + ret = regmap_write(data->regmap, APDS9960_REG_ATIME, + apds9960_int_time[idx][1]); + if (!ret) + data->als_adc_int_us = val2; + mutex_unlock(&data->lock); + break; + } + } + + return ret; +} + +static int apds9960_set_pxs_gain(struct apds9960_data *data, int val) +{ + int ret = -EINVAL; + int idx; + + for (idx = 0; idx < ARRAY_SIZE(apds9960_pxs_gain_map); idx++) { + if (apds9960_pxs_gain_map[idx] == val) { + /* pxs + gesture gains are mirrored */ + mutex_lock(&data->lock); + ret = regmap_update_bits(data->regmap, + APDS9960_REG_CONTROL, + APDS9960_REG_CONTROL_PGAIN_MASK, + idx << APDS9960_REG_CONTROL_PGAIN_MASK_SHIFT); + if (ret) { + mutex_unlock(&data->lock); + break; + } + + ret = regmap_update_bits(data->regmap, + APDS9960_REG_CONFIG_2, + APDS9960_REG_CONFIG_2_GGAIN_MASK, + idx << APDS9960_REG_CONFIG_2_GGAIN_MASK_SHIFT); + if (!ret) + data->pxs_gain = idx; + mutex_unlock(&data->lock); + break; + } + } + + return ret; +} + +static int apds9960_set_als_gain(struct apds9960_data *data, int val) +{ + int ret = -EINVAL; + int idx; + + for (idx = 0; idx < ARRAY_SIZE(apds9960_als_gain_map); idx++) { + if (apds9960_als_gain_map[idx] == val) { + mutex_lock(&data->lock); + ret = regmap_update_bits(data->regmap, + APDS9960_REG_CONTROL, + APDS9960_REG_CONTROL_AGAIN_MASK, idx); + if (!ret) + data->als_gain = idx; + mutex_unlock(&data->lock); + break; + } + } + + return ret; +} + +#ifdef CONFIG_PM +static int apds9960_set_power_state(struct apds9960_data *data, bool on) +{ + struct device *dev = &data->client->dev; + int ret = 0; + + mutex_lock(&data->lock); + + if (on) { + int suspended; + + suspended = pm_runtime_suspended(dev); + ret = pm_runtime_get_sync(dev); + + /* Allow one integration cycle before allowing a reading */ + if (suspended) + usleep_range(data->als_adc_int_us, + APDS9960_MAX_INT_TIME_IN_US); + } else { + ret = pm_runtime_put_autosuspend(dev); + } + + mutex_unlock(&data->lock); + + return ret; +} +#else +static int apds9960_set_power_state(struct apds9960_data *data, bool on) +{ + return 0; +} +#endif + +static int apds9960_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct apds9960_data *data = iio_priv(indio_dev); + __le16 buf; + int ret = -EINVAL; + + if (data->gesture_mode_running) + return -EBUSY; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + apds9960_set_power_state(data, true); + switch (chan->type) { + case IIO_PROXIMITY: + ret = regmap_read(data->regmap, chan->address, val); + if (!ret) + ret = IIO_VAL_INT; + break; + case IIO_INTENSITY: + ret = regmap_bulk_read(data->regmap, chan->address, + &buf, 2); + if (!ret) + ret = IIO_VAL_INT; + *val = le16_to_cpu(buf); + break; + default: + ret = -EINVAL; + } + apds9960_set_power_state(data, false); + break; + case IIO_CHAN_INFO_INT_TIME: + /* RGB + ALS sensors only have integration time */ + mutex_lock(&data->lock); + switch (chan->type) { + case IIO_INTENSITY: + *val = 0; + *val2 = data->als_adc_int_us; + ret = IIO_VAL_INT_PLUS_MICRO; + break; + default: + ret = -EINVAL; + } + mutex_unlock(&data->lock); + break; + case IIO_CHAN_INFO_SCALE: + mutex_lock(&data->lock); + switch (chan->type) { + case IIO_PROXIMITY: + *val = apds9960_pxs_gain_map[data->pxs_gain]; + ret = IIO_VAL_INT; + break; + case IIO_INTENSITY: + *val = apds9960_als_gain_map[data->als_gain]; + ret = IIO_VAL_INT; + break; + default: + ret = -EINVAL; + } + mutex_unlock(&data->lock); + break; + } + + return ret; +}; + +static int apds9960_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct apds9960_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_INT_TIME: + /* RGB + ALS sensors only have int time */ + switch (chan->type) { + case IIO_INTENSITY: + if (val != 0) + return -EINVAL; + return apds9960_set_it_time(data, val2); + default: + return -EINVAL; + } + case IIO_CHAN_INFO_SCALE: + if (val2 != 0) + return -EINVAL; + switch (chan->type) { + case IIO_PROXIMITY: + return apds9960_set_pxs_gain(data, val); + case IIO_INTENSITY: + return apds9960_set_als_gain(data, val); + default: + return -EINVAL; + } + default: + return -EINVAL; + }; + + return 0; +} + +static inline int apds9960_get_thres_reg(const struct iio_chan_spec *chan, + enum iio_event_direction dir, + u8 *reg) +{ + switch (dir) { + case IIO_EV_DIR_RISING: + switch (chan->type) { + case IIO_PROXIMITY: + *reg = APDS9960_REG_PIHT; + break; + case IIO_INTENSITY: + *reg = APDS9960_REG_AIHTL; + break; + default: + return -EINVAL; + } + break; + case IIO_EV_DIR_FALLING: + switch (chan->type) { + case IIO_PROXIMITY: + *reg = APDS9960_REG_PILT; + break; + case IIO_INTENSITY: + *reg = APDS9960_REG_AILTL; + break; + default: + return -EINVAL; + } + break; + default: + return -EINVAL; + } + + return 0; +} + +static int apds9960_read_event(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int *val, int *val2) +{ + u8 reg; + __le16 buf; + int ret = 0; + struct apds9960_data *data = iio_priv(indio_dev); + + if (info != IIO_EV_INFO_VALUE) + return -EINVAL; + + ret = apds9960_get_thres_reg(chan, dir, ®); + if (ret < 0) + return ret; + + if (chan->type == IIO_PROXIMITY) { + ret = regmap_read(data->regmap, reg, val); + if (ret < 0) + return ret; + } else if (chan->type == IIO_INTENSITY) { + ret = regmap_bulk_read(data->regmap, reg, &buf, 2); + if (ret < 0) + return ret; + *val = le16_to_cpu(buf); + } else + return -EINVAL; + + *val2 = 0; + + return IIO_VAL_INT; +} + +static int apds9960_write_event(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int val, int val2) +{ + u8 reg; + __le16 buf; + int ret = 0; + struct apds9960_data *data = iio_priv(indio_dev); + + if (info != IIO_EV_INFO_VALUE) + return -EINVAL; + + ret = apds9960_get_thres_reg(chan, dir, ®); + if (ret < 0) + return ret; + + if (chan->type == IIO_PROXIMITY) { + if (val < 0 || val > APDS9960_MAX_PXS_THRES_VAL) + return -EINVAL; + ret = regmap_write(data->regmap, reg, val); + if (ret < 0) + return ret; + } else if (chan->type == IIO_INTENSITY) { + if (val < 0 || val > APDS9960_MAX_ALS_THRES_VAL) + return -EINVAL; + buf = cpu_to_le16(val); + ret = regmap_bulk_write(data->regmap, reg, &buf, 2); + if (ret < 0) + return ret; + } else + return -EINVAL; + + return 0; +} + +static int apds9960_read_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) +{ + struct apds9960_data *data = iio_priv(indio_dev); + + switch (chan->type) { + case IIO_PROXIMITY: + return data->pxs_int; + case IIO_INTENSITY: + return data->als_int; + default: + return -EINVAL; + } + + return 0; +} + +static int apds9960_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + int state) +{ + struct apds9960_data *data = iio_priv(indio_dev); + int ret; + + state = !!state; + + switch (chan->type) { + case IIO_PROXIMITY: + if (data->pxs_int == state) + return -EINVAL; + + ret = regmap_field_write(data->reg_int_pxs, state); + if (ret) + return ret; + data->pxs_int = state; + apds9960_set_power_state(data, state); + break; + case IIO_INTENSITY: + if (data->als_int == state) + return -EINVAL; + + ret = regmap_field_write(data->reg_int_als, state); + if (ret) + return ret; + data->als_int = state; + apds9960_set_power_state(data, state); + break; + default: + return -EINVAL; + } + + return 0; +} + +static const struct iio_info apds9960_info = { + .driver_module = THIS_MODULE, + .attrs = &apds9960_attribute_group, + .read_raw = apds9960_read_raw, + .write_raw = apds9960_write_raw, + .read_event_value = apds9960_read_event, + .write_event_value = apds9960_write_event, + .read_event_config = apds9960_read_event_config, + .write_event_config = apds9960_write_event_config, + +}; + +static inline int apds9660_fifo_is_empty(struct apds9960_data *data) +{ + int cnt; + int ret; + + ret = regmap_read(data->regmap, APDS9960_REG_GFLVL, &cnt); + if (ret) + return ret; + + return cnt; +} + +static void apds9960_read_gesture_fifo(struct apds9960_data *data) +{ + int ret, cnt = 0; + + mutex_lock(&data->lock); + data->gesture_mode_running = 1; + + while (cnt-- || (cnt = apds9660_fifo_is_empty(data) > 0)) { + ret = regmap_bulk_read(data->regmap, APDS9960_REG_GFIFO_BASE, + &data->buffer, 4); + + if (ret) + goto err_read; + + iio_push_to_buffers(data->indio_dev, data->buffer); + } + +err_read: + data->gesture_mode_running = 0; + mutex_unlock(&data->lock); +} + +static irqreturn_t apds9960_interrupt_handler(int irq, void *private) +{ + struct iio_dev *indio_dev = private; + struct apds9960_data *data = iio_priv(indio_dev); + int ret, status; + + ret = regmap_read(data->regmap, APDS9960_REG_STATUS, &status); + if (ret < 0) { + dev_err(&data->client->dev, "irq status reg read failed\n"); + return IRQ_HANDLED; + } + + if ((status & APDS9960_REG_STATUS_ALS_INT) && data->als_int) { + iio_push_event(indio_dev, + IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, 0, + IIO_EV_TYPE_THRESH, + IIO_EV_DIR_EITHER), + iio_get_time_ns()); + regmap_write(data->regmap, APDS9960_REG_CICLEAR, 1); + } + + if ((status & APDS9960_REG_STATUS_PS_INT) && data->pxs_int) { + iio_push_event(indio_dev, + IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0, + IIO_EV_TYPE_THRESH, + IIO_EV_DIR_EITHER), + iio_get_time_ns()); + regmap_write(data->regmap, APDS9960_REG_PICLEAR, 1); + } + + if (status & APDS9960_REG_STATUS_GINT) + apds9960_read_gesture_fifo(data); + + return IRQ_HANDLED; +} + +static int apds9960_set_powermode(struct apds9960_data *data, bool state) +{ + return regmap_update_bits(data->regmap, APDS9960_REG_ENABLE, 1, state); +} + +static int apds9960_buffer_postenable(struct iio_dev *indio_dev) +{ + struct apds9960_data *data = iio_priv(indio_dev); + int ret; + + ret = regmap_field_write(data->reg_int_ges, 1); + if (ret) + return ret; + + ret = regmap_field_write(data->reg_enable_ges, 1); + if (ret) + return ret; + + pm_runtime_get_sync(&data->client->dev); + + return 0; +} + +static int apds9960_buffer_predisable(struct iio_dev *indio_dev) +{ + struct apds9960_data *data = iio_priv(indio_dev); + int ret; + + ret = regmap_field_write(data->reg_enable_ges, 0); + if (ret) + return ret; + + ret = regmap_field_write(data->reg_int_ges, 0); + if (ret) + return ret; + + pm_runtime_put_autosuspend(&data->client->dev); + + return 0; +} + +static const struct iio_buffer_setup_ops apds9960_buffer_setup_ops = { + .postenable = apds9960_buffer_postenable, + .predisable = apds9960_buffer_predisable, +}; + +static int apds9960_regfield_init(struct apds9960_data *data) +{ + struct device *dev = &data->client->dev; + struct regmap *regmap = data->regmap; + + data->reg_int_als = devm_regmap_field_alloc(dev, regmap, + apds9960_reg_field_int_als); + if (IS_ERR(data->reg_int_als)) { + dev_err(dev, "INT ALS reg field init failed\n"); + return PTR_ERR(data->reg_int_als); + } + + data->reg_int_ges = devm_regmap_field_alloc(dev, regmap, + apds9960_reg_field_int_ges); + if (IS_ERR(data->reg_int_ges)) { + dev_err(dev, "INT gesture reg field init failed\n"); + return PTR_ERR(data->reg_int_ges); + } + + data->reg_int_pxs = devm_regmap_field_alloc(dev, regmap, + apds9960_reg_field_int_pxs); + if (IS_ERR(data->reg_int_pxs)) { + dev_err(dev, "INT pxs reg field init failed\n"); + return PTR_ERR(data->reg_int_pxs); + } + + data->reg_enable_als = devm_regmap_field_alloc(dev, regmap, + apds9960_reg_field_enable_als); + if (IS_ERR(data->reg_enable_als)) { + dev_err(dev, "Enable ALS reg field init failed\n"); + return PTR_ERR(data->reg_enable_als); + } + + data->reg_enable_ges = devm_regmap_field_alloc(dev, regmap, + apds9960_reg_field_enable_ges); + if (IS_ERR(data->reg_enable_ges)) { + dev_err(dev, "Enable gesture reg field init failed\n"); + return PTR_ERR(data->reg_enable_ges); + } + + data->reg_enable_pxs = devm_regmap_field_alloc(dev, regmap, + apds9960_reg_field_enable_pxs); + if (IS_ERR(data->reg_enable_pxs)) { + dev_err(dev, "Enable PXS reg field init failed\n"); + return PTR_ERR(data->reg_enable_pxs); + } + + return 0; +} + +static int apds9960_chip_init(struct apds9960_data *data) +{ + int ret; + + /* Default IT for ALS of 28 ms */ + ret = apds9960_set_it_time(data, 28000); + if (ret) + return ret; + + /* Ensure gesture interrupt is OFF */ + ret = regmap_field_write(data->reg_int_ges, 0); + if (ret) + return ret; + + /* Disable gesture sensor, since polling is useless from user-space */ + ret = regmap_field_write(data->reg_enable_ges, 0); + if (ret) + return ret; + + /* Ensure proximity interrupt is OFF */ + ret = regmap_field_write(data->reg_int_pxs, 0); + if (ret) + return ret; + + /* Enable proximity sensor for polling */ + ret = regmap_field_write(data->reg_enable_pxs, 1); + if (ret) + return ret; + + /* Ensure ALS interrupt is OFF */ + ret = regmap_field_write(data->reg_int_als, 0); + if (ret) + return ret; + + /* Enable ALS sensor for polling */ + ret = regmap_field_write(data->reg_enable_als, 1); + if (ret) + return ret; + /* + * When enabled trigger an interrupt after 3 readings + * outside threshold for ALS + PXS + */ + ret = regmap_write(data->regmap, APDS9960_REG_PERS, + APDS9960_DEFAULT_PERS); + if (ret) + return ret; + + /* + * Wait for 4 event outside gesture threshold to prevent interrupt + * flooding. + */ + ret = regmap_update_bits(data->regmap, APDS9960_REG_GCONF_1, + APDS9960_REG_GCONF_1_GFIFO_THRES_MASK, + BIT(0) << APDS9960_REG_GCONF_1_GFIFO_THRES_MASK_SHIFT); + if (ret) + return ret; + + /* Default ENTER and EXIT thresholds for the GESTURE engine. */ + ret = regmap_write(data->regmap, APDS9960_REG_GPENTH, + APDS9960_DEFAULT_GPENTH); + if (ret) + return ret; + + ret = regmap_write(data->regmap, APDS9960_REG_GEXTH, + APDS9960_DEFAULT_GEXTH); + if (ret) + return ret; + + return apds9960_set_powermode(data, 1); +} + +static int apds9960_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct apds9960_data *data; + struct iio_buffer *buffer; + struct iio_dev *indio_dev; + int ret; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + buffer = devm_iio_kfifo_allocate(&client->dev); + if (!buffer) + return -ENOMEM; + + iio_device_attach_buffer(indio_dev, buffer); + + indio_dev->info = &apds9960_info; + indio_dev->name = APDS9960_DRV_NAME; + indio_dev->channels = apds9960_channels; + indio_dev->num_channels = ARRAY_SIZE(apds9960_channels); + indio_dev->available_scan_masks = apds9960_scan_masks; + indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE); + indio_dev->setup_ops = &apds9960_buffer_setup_ops; + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + + data->regmap = devm_regmap_init_i2c(client, &apds9960_regmap_config); + if (IS_ERR(data->regmap)) { + dev_err(&client->dev, "regmap initialization failed.\n"); + return PTR_ERR(data->regmap); + } + + data->client = client; + data->indio_dev = indio_dev; + mutex_init(&data->lock); + + ret = pm_runtime_set_active(&client->dev); + if (ret) + goto error_power_down; + + pm_runtime_enable(&client->dev); + pm_runtime_set_autosuspend_delay(&client->dev, 5000); + pm_runtime_use_autosuspend(&client->dev); + + apds9960_set_power_state(data, true); + + ret = apds9960_regfield_init(data); + if (ret) + goto error_power_down; + + ret = apds9960_chip_init(data); + if (ret) + goto error_power_down; + + if (client->irq <= 0) { + dev_err(&client->dev, "no valid irq defined\n"); + ret = -EINVAL; + goto error_power_down; + } + ret = devm_request_threaded_irq(&client->dev, client->irq, + NULL, apds9960_interrupt_handler, + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, + "apds9960_event", + indio_dev); + if (ret) { + dev_err(&client->dev, "request irq (%d) failed\n", client->irq); + goto error_power_down; + } + + ret = iio_device_register(indio_dev); + if (ret) + goto error_power_down; + + apds9960_set_power_state(data, false); + + return 0; + +error_power_down: + apds9960_set_power_state(data, false); + + return ret; +} + +static int apds9960_remove(struct i2c_client *client) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(client); + struct apds9960_data *data = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + pm_runtime_disable(&client->dev); + pm_runtime_set_suspended(&client->dev); + apds9960_set_powermode(data, 0); + + return 0; +} + +#ifdef CONFIG_PM +static int apds9960_runtime_suspend(struct device *dev) +{ + struct apds9960_data *data = + iio_priv(i2c_get_clientdata(to_i2c_client(dev))); + + return apds9960_set_powermode(data, 0); +} + +static int apds9960_runtime_resume(struct device *dev) +{ + struct apds9960_data *data = + iio_priv(i2c_get_clientdata(to_i2c_client(dev))); + + return apds9960_set_powermode(data, 1); +} +#endif + +static const struct dev_pm_ops apds9960_pm_ops = { + SET_RUNTIME_PM_OPS(apds9960_runtime_suspend, + apds9960_runtime_resume, NULL) +}; + +static const struct i2c_device_id apds9960_id[] = { + { "apds9960", 0 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, apds9960_id); + +static struct i2c_driver apds9960_driver = { + .driver = { + .name = APDS9960_DRV_NAME, + .pm = &apds9960_pm_ops, + }, + .probe = apds9960_probe, + .remove = apds9960_remove, + .id_table = apds9960_id, +}; +module_i2c_driver(apds9960_driver); + +MODULE_AUTHOR("Matt Ranostay "); +MODULE_DESCRIPTION("ADPS9960 Gesture/RGB/ALS/Proximity sensor"); +MODULE_LICENSE("GPL"); diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c index 923aa6aef0ed..01e111e72d4b 100644 --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -793,7 +793,6 @@ static struct i2c_driver opt3001_driver = { .driver = { .name = "opt3001", .of_match_table = of_match_ptr(opt3001_of_match), - .owner = THIS_MODULE, }, }; diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index 993eb201148e..42d334ba612e 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -35,8 +35,8 @@ #define STK3310_REG_ID 0x3E #define STK3310_MAX_REG 0x80 -#define STK3310_STATE_EN_PS 0x01 -#define STK3310_STATE_EN_ALS 0x02 +#define STK3310_STATE_EN_PS BIT(0) +#define STK3310_STATE_EN_ALS BIT(1) #define STK3310_STATE_STANDBY 0x00 #define STK3310_CHIP_ID_VAL 0x13 @@ -47,7 +47,6 @@ #define STK3310_DRIVER_NAME "stk3310" #define STK3310_REGMAP_NAME "stk3310_regmap" #define STK3310_EVENT "stk3310_event" -#define STK3310_GPIO "stk3310_gpio" #define STK3310_SCALE_AVAILABLE "6.4 1.6 0.4 0.1" @@ -241,8 +240,11 @@ static int stk3310_write_event(struct iio_dev *indio_dev, struct stk3310_data *data = iio_priv(indio_dev); struct i2c_client *client = data->client; - regmap_field_read(data->reg_ps_gain, &index); - if (val > stk3310_ps_max[index]) + ret = regmap_field_read(data->reg_ps_gain, &index); + if (ret < 0) + return ret; + + if (val < 0 || val > stk3310_ps_max[index]) return -EINVAL; if (dir == IIO_EV_DIR_RISING) @@ -266,9 +268,12 @@ static int stk3310_read_event_config(struct iio_dev *indio_dev, enum iio_event_direction dir) { unsigned int event_val; + int ret; struct stk3310_data *data = iio_priv(indio_dev); - regmap_field_read(data->reg_int_ps, &event_val); + ret = regmap_field_read(data->reg_int_ps, &event_val); + if (ret < 0) + return ret; return event_val; } @@ -307,14 +312,16 @@ static int stk3310_read_raw(struct iio_dev *indio_dev, struct stk3310_data *data = iio_priv(indio_dev); struct i2c_client *client = data->client; + if (chan->type != IIO_LIGHT && chan->type != IIO_PROXIMITY) + return -EINVAL; + switch (mask) { case IIO_CHAN_INFO_RAW: if (chan->type == IIO_LIGHT) reg = STK3310_REG_ALS_DATA_MSB; - else if (chan->type == IIO_PROXIMITY) - reg = STK3310_REG_PS_DATA_MSB; else - return -EINVAL; + reg = STK3310_REG_PS_DATA_MSB; + mutex_lock(&data->lock); ret = regmap_bulk_read(data->regmap, reg, &buf, 2); if (ret < 0) { @@ -327,17 +334,23 @@ static int stk3310_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_INT_TIME: if (chan->type == IIO_LIGHT) - regmap_field_read(data->reg_als_it, &index); + ret = regmap_field_read(data->reg_als_it, &index); else - regmap_field_read(data->reg_ps_it, &index); + ret = regmap_field_read(data->reg_ps_it, &index); + if (ret < 0) + return ret; + *val = stk3310_it_table[index][0]; *val2 = stk3310_it_table[index][1]; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_SCALE: if (chan->type == IIO_LIGHT) - regmap_field_read(data->reg_als_gain, &index); + ret = regmap_field_read(data->reg_als_gain, &index); else - regmap_field_read(data->reg_ps_gain, &index); + ret = regmap_field_read(data->reg_ps_gain, &index); + if (ret < 0) + return ret; + *val = stk3310_scale_table[index][0]; *val2 = stk3310_scale_table[index][1]; return IIO_VAL_INT_PLUS_MICRO; @@ -354,6 +367,9 @@ static int stk3310_write_raw(struct iio_dev *indio_dev, int index; struct stk3310_data *data = iio_priv(indio_dev); + if (chan->type != IIO_LIGHT && chan->type != IIO_PROXIMITY) + return -EINVAL; + switch (mask) { case IIO_CHAN_INFO_INT_TIME: index = stk3310_get_index(stk3310_it_table, @@ -368,7 +384,7 @@ static int stk3310_write_raw(struct iio_dev *indio_dev, ret = regmap_field_write(data->reg_ps_it, index); if (ret < 0) dev_err(&data->client->dev, - "sensor configuration failed\n"); + "sensor configuration failed\n"); mutex_unlock(&data->lock); return ret; @@ -385,7 +401,7 @@ static int stk3310_write_raw(struct iio_dev *indio_dev, ret = regmap_field_write(data->reg_ps_gain, index); if (ret < 0) dev_err(&data->client->dev, - "sensor configuration failed\n"); + "sensor configuration failed\n"); mutex_unlock(&data->lock); return ret; } @@ -419,8 +435,8 @@ static int stk3310_set_state(struct stk3310_data *data, u8 state) dev_err(&client->dev, "failed to change sensor state\n"); } else if (state != STK3310_STATE_STANDBY) { /* Don't reset the 'enabled' flags if we're going in standby */ - data->ps_enabled = !!(state & 0x01); - data->als_enabled = !!(state & 0x02); + data->ps_enabled = !!(state & STK3310_STATE_EN_PS); + data->als_enabled = !!(state & STK3310_STATE_EN_ALS); } mutex_unlock(&data->lock); @@ -435,7 +451,10 @@ static int stk3310_init(struct iio_dev *indio_dev) struct stk3310_data *data = iio_priv(indio_dev); struct i2c_client *client = data->client; - regmap_read(data->regmap, STK3310_REG_ID, &chipid); + ret = regmap_read(data->regmap, STK3310_REG_ID, &chipid); + if (ret < 0) + return ret; + if (chipid != STK3310_CHIP_ID_VAL && chipid != STK3311_CHIP_ID_VAL) { dev_err(&client->dev, "invalid chip id: 0x%x\n", chipid); @@ -457,30 +476,6 @@ static int stk3310_init(struct iio_dev *indio_dev) return ret; } -static int stk3310_gpio_probe(struct i2c_client *client) -{ - struct device *dev; - struct gpio_desc *gpio; - int ret; - - if (!client) - return -EINVAL; - - dev = &client->dev; - - /* gpio interrupt pin */ - gpio = devm_gpiod_get_index(dev, STK3310_GPIO, 0, GPIOD_IN); - if (IS_ERR(gpio)) { - dev_err(dev, "acpi gpio get index failed\n"); - return PTR_ERR(gpio); - } - - ret = gpiod_to_irq(gpio); - dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); - - return ret; -} - static bool stk3310_is_volatile_reg(struct device *dev, unsigned int reg) { switch (reg) { @@ -604,27 +599,30 @@ static int stk3310_probe(struct i2c_client *client, if (ret < 0) return ret; - if (client->irq < 0) - client->irq = stk3310_gpio_probe(client); - - if (client->irq >= 0) { + if (client->irq > 0) { ret = devm_request_threaded_irq(&client->dev, client->irq, stk3310_irq_handler, stk3310_irq_event_handler, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, STK3310_EVENT, indio_dev); - if (ret < 0) + if (ret < 0) { dev_err(&client->dev, "request irq %d failed\n", - client->irq); + client->irq); + goto err_standby; + } } ret = iio_device_register(indio_dev); if (ret < 0) { dev_err(&client->dev, "device_register failed\n"); - stk3310_set_state(data, STK3310_STATE_STANDBY); + goto err_standby; } + return 0; + +err_standby: + stk3310_set_state(data, STK3310_STATE_STANDBY); return ret; } @@ -648,7 +646,7 @@ static int stk3310_suspend(struct device *dev) static int stk3310_resume(struct device *dev) { - int state = 0; + u8 state = 0; struct stk3310_data *data; data = iio_priv(i2c_get_clientdata(to_i2c_client(dev))); diff --git a/drivers/iio/light/tsl4531.c b/drivers/iio/light/tsl4531.c index 26979183d27c..cf94ec72b181 100644 --- a/drivers/iio/light/tsl4531.c +++ b/drivers/iio/light/tsl4531.c @@ -158,9 +158,9 @@ static int tsl4531_check_id(struct i2c_client *client) case TSL45313_ID: case TSL45315_ID: case TSL45317_ID: - return 1; - default: return 0; + default: + return -ENODEV; } } @@ -180,9 +180,10 @@ static int tsl4531_probe(struct i2c_client *client, data->client = client; mutex_init(&data->lock); - if (!tsl4531_check_id(client)) { + ret = tsl4531_check_id(client); + if (ret) { dev_err(&client->dev, "no TSL4531 sensor\n"); - return -ENODEV; + return ret; } ret = i2c_smbus_write_byte_data(data->client, TSL4531_CONTROL, diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c new file mode 100644 index 000000000000..49dab3cb3e23 --- /dev/null +++ b/drivers/iio/light/us5182d.c @@ -0,0 +1,507 @@ +/* + * Copyright (c) 2015 Intel Corporation + * + * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor. + * + * 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. + * + * This program is distributed in the hope 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. + * + * To do: Interrupt support. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define US5182D_REG_CFG0 0x00 +#define US5182D_CFG0_ONESHOT_EN BIT(6) +#define US5182D_CFG0_SHUTDOWN_EN BIT(7) +#define US5182D_CFG0_WORD_ENABLE BIT(0) + +#define US5182D_REG_CFG1 0x01 +#define US5182D_CFG1_ALS_RES16 BIT(4) +#define US5182D_CFG1_AGAIN_DEFAULT 0x00 + +#define US5182D_REG_CFG2 0x02 +#define US5182D_CFG2_PX_RES16 BIT(4) +#define US5182D_CFG2_PXGAIN_DEFAULT BIT(2) + +#define US5182D_REG_CFG3 0x03 +#define US5182D_CFG3_LED_CURRENT100 (BIT(4) | BIT(5)) + +#define US5182D_REG_CFG4 0x10 + +/* + * Registers for tuning the auto dark current cancelling feature. + * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling. + * when ALS > DARK_TH --> ALS_Code = ALS - Upper(0x2A) * Dark + * when ALS < DARK_TH --> ALS_Code = ALS - Lower(0x29) * Dark + */ +#define US5182D_REG_UDARK_TH 0x27 +#define US5182D_REG_DARK_AUTO_EN 0x2b +#define US5182D_REG_AUTO_LDARK_GAIN 0x29 +#define US5182D_REG_AUTO_HDARK_GAIN 0x2a + +#define US5182D_OPMODE_ALS 0x01 +#define US5182D_OPMODE_PX 0x02 +#define US5182D_OPMODE_SHIFT 4 + +#define US5182D_REG_DARK_AUTO_EN_DEFAULT 0x80 +#define US5182D_REG_AUTO_LDARK_GAIN_DEFAULT 0x16 +#define US5182D_REG_AUTO_HDARK_GAIN_DEFAULT 0x00 + +#define US5182D_REG_ADL 0x0c +#define US5182D_REG_PDL 0x0e + +#define US5182D_REG_MODE_STORE 0x21 +#define US5182D_STORE_MODE 0x01 + +#define US5182D_REG_CHIPID 0xb2 + +#define US5182D_OPMODE_MASK GENMASK(5, 4) +#define US5182D_AGAIN_MASK 0x07 +#define US5182D_RESET_CHIP 0x01 + +#define US5182D_CHIPID 0x26 +#define US5182D_DRV_NAME "us5182d" + +#define US5182D_GA_RESOLUTION 1000 + +#define US5182D_READ_BYTE 1 +#define US5182D_READ_WORD 2 +#define US5182D_OPSTORE_SLEEP_TIME 20 /* ms */ + +/* Available ranges: [12354, 7065, 3998, 2202, 1285, 498, 256, 138] lux */ +static const int us5182d_scales[] = {188500, 107800, 61000, 33600, 19600, 7600, + 3900, 2100}; + +/* + * Experimental thresholds that work with US5182D sensor on evaluation board + * roughly between 12-32 lux + */ +static u16 us5182d_dark_ths_vals[] = {170, 200, 512, 512, 800, 2000, 4000, + 8000}; + +enum mode { + US5182D_ALS_PX, + US5182D_ALS_ONLY, + US5182D_PX_ONLY +}; + +struct us5182d_data { + struct i2c_client *client; + struct mutex lock; + + /* Glass attenuation factor */ + u32 ga; + + /* Dark gain tuning */ + u8 lower_dark_gain; + u8 upper_dark_gain; + u16 *us5182d_dark_ths; + + u8 opmode; +}; + +static IIO_CONST_ATTR(in_illuminance_scale_available, + "0.0021 0.0039 0.0076 0.0196 0.0336 0.061 0.1078 0.1885"); + +static struct attribute *us5182d_attrs[] = { + &iio_const_attr_in_illuminance_scale_available.dev_attr.attr, + NULL +}; + +static const struct attribute_group us5182d_attr_group = { + .attrs = us5182d_attrs, +}; + +static const struct { + u8 reg; + u8 val; +} us5182d_regvals[] = { + {US5182D_REG_CFG0, (US5182D_CFG0_SHUTDOWN_EN | + US5182D_CFG0_WORD_ENABLE)}, + {US5182D_REG_CFG1, US5182D_CFG1_ALS_RES16}, + {US5182D_REG_CFG2, (US5182D_CFG2_PX_RES16 | + US5182D_CFG2_PXGAIN_DEFAULT)}, + {US5182D_REG_CFG3, US5182D_CFG3_LED_CURRENT100}, + {US5182D_REG_MODE_STORE, US5182D_STORE_MODE}, + {US5182D_REG_CFG4, 0x00}, +}; + +static const struct iio_chan_spec us5182d_channels[] = { + { + .type = IIO_LIGHT, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + }, + { + .type = IIO_PROXIMITY, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + } +}; + +static int us5182d_get_als(struct us5182d_data *data) +{ + int ret; + unsigned long result; + + ret = i2c_smbus_read_word_data(data->client, + US5182D_REG_ADL); + if (ret < 0) + return ret; + + result = ret * data->ga / US5182D_GA_RESOLUTION; + if (result > 0xffff) + result = 0xffff; + + return result; +} + +static int us5182d_set_opmode(struct us5182d_data *data, u8 mode) +{ + int ret; + + ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG0); + if (ret < 0) + return ret; + + /* + * In oneshot mode the chip will power itself down after taking the + * required measurement. + */ + ret = ret | US5182D_CFG0_ONESHOT_EN; + + /* update mode */ + ret = ret & ~US5182D_OPMODE_MASK; + ret = ret | (mode << US5182D_OPMODE_SHIFT); + + /* + * After updating the operating mode, the chip requires that + * the operation is stored, by writing 1 in the STORE_MODE + * register (auto-clearing). + */ + ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, ret); + if (ret < 0) + return ret; + + if (mode == data->opmode) + return 0; + + ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_MODE_STORE, + US5182D_STORE_MODE); + if (ret < 0) + return ret; + + data->opmode = mode; + msleep(US5182D_OPSTORE_SLEEP_TIME); + + return 0; +} + +static int us5182d_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + struct us5182d_data *data = iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + switch (chan->type) { + case IIO_LIGHT: + mutex_lock(&data->lock); + ret = us5182d_set_opmode(data, US5182D_OPMODE_ALS); + if (ret < 0) + goto out_err; + + ret = us5182d_get_als(data); + if (ret < 0) + goto out_err; + mutex_unlock(&data->lock); + *val = ret; + return IIO_VAL_INT; + case IIO_PROXIMITY: + mutex_lock(&data->lock); + ret = us5182d_set_opmode(data, US5182D_OPMODE_PX); + if (ret < 0) + goto out_err; + + ret = i2c_smbus_read_word_data(data->client, + US5182D_REG_PDL); + if (ret < 0) + goto out_err; + mutex_unlock(&data->lock); + *val = ret; + return IIO_VAL_INT; + default: + return -EINVAL; + } + + case IIO_CHAN_INFO_SCALE: + ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG1); + if (ret < 0) + return ret; + + *val = 0; + *val2 = us5182d_scales[ret & US5182D_AGAIN_MASK]; + + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } + + return -EINVAL; +out_err: + mutex_unlock(&data->lock); + return ret; +} + +/** + * us5182d_update_dark_th - update Darh_Th registers + * @data us5182d_data structure + * @index index in us5182d_dark_ths array to use for the updated value + * + * Function needs to be called with a lock held because it needs two i2c write + * byte operations as these registers (0x27 0x28) don't work in word mode + * accessing. + */ +static int us5182d_update_dark_th(struct us5182d_data *data, int index) +{ + __be16 dark_th = cpu_to_be16(data->us5182d_dark_ths[index]); + int ret; + + ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_UDARK_TH, + ((u8 *)&dark_th)[0]); + if (ret < 0) + return ret; + + return i2c_smbus_write_byte_data(data->client, US5182D_REG_UDARK_TH + 1, + ((u8 *)&dark_th)[1]); +} + +/** + * us5182d_apply_scale - update the ALS scale + * @data us5182d_data structure + * @index index in us5182d_scales array to use for the updated value + * + * Function needs to be called with a lock held as we're having more than one + * i2c operation. + */ +static int us5182d_apply_scale(struct us5182d_data *data, int index) +{ + int ret; + + ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG1); + if (ret < 0) + return ret; + + ret = ret & (~US5182D_AGAIN_MASK); + ret |= index; + + ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG1, ret); + if (ret < 0) + return ret; + + return us5182d_update_dark_th(data, index); +} + +static int us5182d_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, + int val2, long mask) +{ + struct us5182d_data *data = iio_priv(indio_dev); + int ret, i; + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + if (val != 0) + return -EINVAL; + for (i = 0; i < ARRAY_SIZE(us5182d_scales); i++) + if (val2 == us5182d_scales[i]) { + mutex_lock(&data->lock); + ret = us5182d_apply_scale(data, i); + mutex_unlock(&data->lock); + return ret; + } + break; + default: + return -EINVAL; + } + + return -EINVAL; +} + +static const struct iio_info us5182d_info = { + .driver_module = THIS_MODULE, + .read_raw = us5182d_read_raw, + .write_raw = us5182d_write_raw, + .attrs = &us5182d_attr_group, +}; + +static int us5182d_reset(struct iio_dev *indio_dev) +{ + struct us5182d_data *data = iio_priv(indio_dev); + + return i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG3, + US5182D_RESET_CHIP); +} + +static int us5182d_init(struct iio_dev *indio_dev) +{ + struct us5182d_data *data = iio_priv(indio_dev); + int i, ret; + + ret = us5182d_reset(indio_dev); + if (ret < 0) + return ret; + + data->opmode = 0; + for (i = 0; i < ARRAY_SIZE(us5182d_regvals); i++) { + ret = i2c_smbus_write_byte_data(data->client, + us5182d_regvals[i].reg, + us5182d_regvals[i].val); + if (ret < 0) + return ret; + } + + return 0; +} + +static void us5182d_get_platform_data(struct iio_dev *indio_dev) +{ + struct us5182d_data *data = iio_priv(indio_dev); + + if (device_property_read_u32(&data->client->dev, "upisemi,glass-coef", + &data->ga)) + data->ga = US5182D_GA_RESOLUTION; + if (device_property_read_u16_array(&data->client->dev, + "upisemi,dark-ths", + data->us5182d_dark_ths, + ARRAY_SIZE(us5182d_dark_ths_vals))) + data->us5182d_dark_ths = us5182d_dark_ths_vals; + if (device_property_read_u8(&data->client->dev, + "upisemi,upper-dark-gain", + &data->upper_dark_gain)) + data->upper_dark_gain = US5182D_REG_AUTO_HDARK_GAIN_DEFAULT; + if (device_property_read_u8(&data->client->dev, + "upisemi,lower-dark-gain", + &data->lower_dark_gain)) + data->lower_dark_gain = US5182D_REG_AUTO_LDARK_GAIN_DEFAULT; +} + +static int us5182d_dark_gain_config(struct iio_dev *indio_dev) +{ + struct us5182d_data *data = iio_priv(indio_dev); + int ret; + + ret = us5182d_update_dark_th(data, US5182D_CFG1_AGAIN_DEFAULT); + if (ret < 0) + return ret; + + ret = i2c_smbus_write_byte_data(data->client, + US5182D_REG_AUTO_LDARK_GAIN, + data->lower_dark_gain); + if (ret < 0) + return ret; + + ret = i2c_smbus_write_byte_data(data->client, + US5182D_REG_AUTO_HDARK_GAIN, + data->upper_dark_gain); + if (ret < 0) + return ret; + + return i2c_smbus_write_byte_data(data->client, US5182D_REG_DARK_AUTO_EN, + US5182D_REG_DARK_AUTO_EN_DEFAULT); +} + +static int us5182d_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct us5182d_data *data; + struct iio_dev *indio_dev; + int ret; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->client = client; + + mutex_init(&data->lock); + + indio_dev->dev.parent = &client->dev; + indio_dev->info = &us5182d_info; + indio_dev->name = US5182D_DRV_NAME; + indio_dev->channels = us5182d_channels; + indio_dev->num_channels = ARRAY_SIZE(us5182d_channels); + indio_dev->modes = INDIO_DIRECT_MODE; + + ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CHIPID); + if (ret != US5182D_CHIPID) { + dev_err(&data->client->dev, + "Failed to detect US5182 light chip\n"); + return (ret < 0) ? ret : -ENODEV; + } + + us5182d_get_platform_data(indio_dev); + ret = us5182d_init(indio_dev); + if (ret < 0) + return ret; + + ret = us5182d_dark_gain_config(indio_dev); + if (ret < 0) + return ret; + + return iio_device_register(indio_dev); +} + +static int us5182d_remove(struct i2c_client *client) +{ + iio_device_unregister(i2c_get_clientdata(client)); + return i2c_smbus_write_byte_data(client, US5182D_REG_CFG0, + US5182D_CFG0_SHUTDOWN_EN); +} + +static const struct acpi_device_id us5182d_acpi_match[] = { + { "USD5182", 0}, + {} +}; + +MODULE_DEVICE_TABLE(acpi, us5182d_acpi_match); + +static const struct i2c_device_id us5182d_id[] = { + {"usd5182", 0}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, us5182d_id); + +static struct i2c_driver us5182d_driver = { + .driver = { + .name = US5182D_DRV_NAME, + .acpi_match_table = ACPI_PTR(us5182d_acpi_match), + }, + .probe = us5182d_probe, + .remove = us5182d_remove, + .id_table = us5182d_id, + +}; +module_i2c_driver(us5182d_driver); + +MODULE_AUTHOR("Adriana Reus "); +MODULE_DESCRIPTION("Driver for us5182d Proximity and Light Sensor"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig index efb9350b0d76..868abada3409 100644 --- a/drivers/iio/magnetometer/Kconfig +++ b/drivers/iio/magnetometer/Kconfig @@ -24,6 +24,24 @@ config AK09911 help Deprecated: AK09911 is now supported by AK8975 driver. +config BMC150_MAGN + tristate "Bosch BMC150 Magnetometer Driver" + depends on I2C + select REGMAP_I2C + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + Say yes here to build support for the BMC150 magnetometer. + + Currently this only supports the device via an i2c interface. + + This is a combo module with both accelerometer and magnetometer. + This driver is only implementing magnetometer part, which has + its own address and register map. + + To compile this driver as a module, choose M here: the module will be + called bmc150_magn. + config MAG3110 tristate "Freescale MAG3110 3-Axis Magnetometer" depends on I2C @@ -87,19 +105,4 @@ config IIO_ST_MAGN_SPI_3AXIS depends on IIO_ST_MAGN_3AXIS depends on IIO_ST_SENSORS_SPI -config BMC150_MAGN - tristate "Bosch BMC150 Magnetometer Driver" - depends on I2C - select REGMAP_I2C - select IIO_BUFFER - select IIO_TRIGGERED_BUFFER - help - Say yes here to build support for the BMC150 magnetometer. - - Currently this only supports the device via an i2c interface. - - This is a combo module with both accelerometer and magnetometer. - This driver is only implementing magnetometer part, which has - its own address and register map. - endmenu diff --git a/drivers/iio/magnetometer/Makefile b/drivers/iio/magnetometer/Makefile index 33b1d4d54ee7..2c72df458ec2 100644 --- a/drivers/iio/magnetometer/Makefile +++ b/drivers/iio/magnetometer/Makefile @@ -4,6 +4,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AK8975) += ak8975.o +obj-$(CONFIG_BMC150_MAGN) += bmc150_magn.o obj-$(CONFIG_MAG3110) += mag3110.o obj-$(CONFIG_HID_SENSOR_MAGNETOMETER_3D) += hid-sensor-magn-3d.o obj-$(CONFIG_MMC35240) += mmc35240.o @@ -14,5 +15,3 @@ st_magn-$(CONFIG_IIO_BUFFER) += st_magn_buffer.o obj-$(CONFIG_IIO_ST_MAGN_I2C_3AXIS) += st_magn_i2c.o obj-$(CONFIG_IIO_ST_MAGN_SPI_3AXIS) += st_magn_spi.o - -obj-$(CONFIG_BMC150_MAGN) += bmc150_magn.o diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c index d8e614ca069f..1615b23d7b2a 100644 --- a/drivers/iio/magnetometer/bmc150_magn.c +++ b/drivers/iio/magnetometer/bmc150_magn.c @@ -37,7 +37,6 @@ #define BMC150_MAGN_DRV_NAME "bmc150_magn" #define BMC150_MAGN_IRQ_NAME "bmc150_magn_event" -#define BMC150_MAGN_GPIO_INT "interrupt" #define BMC150_MAGN_REG_CHIP_ID 0x40 #define BMC150_MAGN_CHIP_ID_VAL 0x32 @@ -833,31 +832,6 @@ static const struct iio_buffer_setup_ops bmc150_magn_buffer_setup_ops = { .postdisable = bmc150_magn_buffer_postdisable, }; -static int bmc150_magn_gpio_probe(struct i2c_client *client) -{ - struct device *dev; - struct gpio_desc *gpio; - int ret; - - if (!client) - return -EINVAL; - - dev = &client->dev; - - /* data ready GPIO interrupt pin */ - gpio = devm_gpiod_get_index(dev, BMC150_MAGN_GPIO_INT, 0, GPIOD_IN); - if (IS_ERR(gpio)) { - dev_err(dev, "ACPI GPIO get index failed\n"); - return PTR_ERR(gpio); - } - - ret = gpiod_to_irq(gpio); - - dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); - - return ret; -} - static const char *bmc150_magn_match_acpi_device(struct device *dev) { const struct acpi_device_id *id; @@ -911,9 +885,6 @@ static int bmc150_magn_probe(struct i2c_client *client, indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &bmc150_magn_info; - if (client->irq <= 0) - client->irq = bmc150_magn_gpio_probe(client); - if (client->irq > 0) { data->dready_trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d", diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c index f8dc4b85d70c..b27f0146647b 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -560,6 +560,7 @@ static const struct iio_info magn_info = { .attrs = &st_magn_attribute_group, .read_raw = &st_magn_read_raw, .write_raw = &st_magn_write_raw, + .debugfs_reg_access = &st_sensors_debugfs_reg_access, }; #ifdef CONFIG_IIO_TRIGGER diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig new file mode 100644 index 000000000000..fd75db73e582 --- /dev/null +++ b/drivers/iio/potentiometer/Kconfig @@ -0,0 +1,20 @@ +# +# Potentiometer drivers +# +# When adding new entries keep the list in alphabetical order + +menu "Digital potentiometers" + +config MCP4531 + tristate "Microchip MCP45xx/MCP46xx Digital Potentiometer driver" + depends on I2C + help + Say yes here to build support for the Microchip + MCP4531, MCP4532, MCP4551, MCP4552, + MCP4631, MCP4632, MCP4651, MCP4652 + digital potentiomenter chips. + + To compile this driver as a module, choose M here: the + module will be called mcp4531. + +endmenu diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile new file mode 100644 index 000000000000..8afe49227012 --- /dev/null +++ b/drivers/iio/potentiometer/Makefile @@ -0,0 +1,6 @@ +# +# Makefile for industrial I/O potentiometer drivers +# + +# When adding new entries keep the list in alphabetical order +obj-$(CONFIG_MCP4531) += mcp4531.o diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c new file mode 100644 index 000000000000..a3f66874ee2e --- /dev/null +++ b/drivers/iio/potentiometer/mcp4531.c @@ -0,0 +1,231 @@ +/* + * Industrial I/O driver for Microchip digital potentiometers + * Copyright (c) 2015 Axentia Technologies AB + * Author: Peter Rosin + * + * Datasheet: http://www.microchip.com/downloads/en/DeviceDoc/22096b.pdf + * + * DEVID #Wipers #Positions Resistor Opts (kOhm) i2c address + * mcp4531 1 129 5, 10, 50, 100 010111x + * mcp4532 1 129 5, 10, 50, 100 01011xx + * mcp4551 1 257 5, 10, 50, 100 010111x + * mcp4552 1 257 5, 10, 50, 100 01011xx + * mcp4631 2 129 5, 10, 50, 100 0101xxx + * mcp4632 2 129 5, 10, 50, 100 01011xx + * mcp4651 2 257 5, 10, 50, 100 0101xxx + * mcp4652 2 257 5, 10, 50, 100 01011xx + * + * 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 + +struct mcp4531_cfg { + int wipers; + int max_pos; + int kohms; +}; + +enum mcp4531_type { + MCP453x_502, + MCP453x_103, + MCP453x_503, + MCP453x_104, + MCP455x_502, + MCP455x_103, + MCP455x_503, + MCP455x_104, + MCP463x_502, + MCP463x_103, + MCP463x_503, + MCP463x_104, + MCP465x_502, + MCP465x_103, + MCP465x_503, + MCP465x_104, +}; + +static const struct mcp4531_cfg mcp4531_cfg[] = { + [MCP453x_502] = { .wipers = 1, .max_pos = 128, .kohms = 5, }, + [MCP453x_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, }, + [MCP453x_503] = { .wipers = 1, .max_pos = 128, .kohms = 50, }, + [MCP453x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, }, + [MCP455x_502] = { .wipers = 1, .max_pos = 256, .kohms = 5, }, + [MCP455x_103] = { .wipers = 1, .max_pos = 256, .kohms = 10, }, + [MCP455x_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, }, + [MCP455x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, }, + [MCP463x_502] = { .wipers = 2, .max_pos = 128, .kohms = 5, }, + [MCP463x_103] = { .wipers = 2, .max_pos = 128, .kohms = 10, }, + [MCP463x_503] = { .wipers = 2, .max_pos = 128, .kohms = 50, }, + [MCP463x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, }, + [MCP465x_502] = { .wipers = 2, .max_pos = 256, .kohms = 5, }, + [MCP465x_103] = { .wipers = 2, .max_pos = 256, .kohms = 10, }, + [MCP465x_503] = { .wipers = 2, .max_pos = 256, .kohms = 50, }, + [MCP465x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, }, +}; + +#define MCP4531_WRITE (0 << 2) +#define MCP4531_INCR (1 << 2) +#define MCP4531_DECR (2 << 2) +#define MCP4531_READ (3 << 2) + +#define MCP4531_WIPER_SHIFT (4) + +struct mcp4531_data { + struct i2c_client *client; + unsigned long devid; +}; + +#define MCP4531_CHANNEL(ch) { \ + .type = IIO_RESISTANCE, \ + .indexed = 1, \ + .output = 1, \ + .channel = (ch), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ +} + +static const struct iio_chan_spec mcp4531_channels[] = { + MCP4531_CHANNEL(0), + MCP4531_CHANNEL(1), +}; + +static int mcp4531_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct mcp4531_data *data = iio_priv(indio_dev); + int address = chan->channel << MCP4531_WIPER_SHIFT; + s32 ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = i2c_smbus_read_word_swapped(data->client, + MCP4531_READ | address); + if (ret < 0) + return ret; + *val = ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 1000 * mcp4531_cfg[data->devid].kohms; + *val2 = mcp4531_cfg[data->devid].max_pos; + return IIO_VAL_FRACTIONAL; + } + + return -EINVAL; +} + +static int mcp4531_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct mcp4531_data *data = iio_priv(indio_dev); + int address = chan->channel << MCP4531_WIPER_SHIFT; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + if (val > mcp4531_cfg[data->devid].max_pos || val < 0) + return -EINVAL; + break; + default: + return -EINVAL; + } + + return i2c_smbus_write_byte_data(data->client, + MCP4531_WRITE | address | (val >> 8), + val & 0xff); +} + +static const struct iio_info mcp4531_info = { + .read_raw = mcp4531_read_raw, + .write_raw = mcp4531_write_raw, + .driver_module = THIS_MODULE, +}; + +static int mcp4531_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct device *dev = &client->dev; + unsigned long devid = id->driver_data; + struct mcp4531_data *data; + struct iio_dev *indio_dev; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WORD_DATA)) { + dev_err(dev, "SMBUS Word Data not supported\n"); + return -EIO; + } + + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->client = client; + data->devid = devid; + + indio_dev->dev.parent = dev; + indio_dev->info = &mcp4531_info; + indio_dev->channels = mcp4531_channels; + indio_dev->num_channels = mcp4531_cfg[devid].wipers; + indio_dev->name = client->name; + + return devm_iio_device_register(dev, indio_dev); +} + +static const struct i2c_device_id mcp4531_id[] = { + { "mcp4531-502", MCP453x_502 }, + { "mcp4531-103", MCP453x_103 }, + { "mcp4531-503", MCP453x_503 }, + { "mcp4531-104", MCP453x_104 }, + { "mcp4532-502", MCP453x_502 }, + { "mcp4532-103", MCP453x_103 }, + { "mcp4532-503", MCP453x_503 }, + { "mcp4532-104", MCP453x_104 }, + { "mcp4551-502", MCP455x_502 }, + { "mcp4551-103", MCP455x_103 }, + { "mcp4551-503", MCP455x_503 }, + { "mcp4551-104", MCP455x_104 }, + { "mcp4552-502", MCP455x_502 }, + { "mcp4552-103", MCP455x_103 }, + { "mcp4552-503", MCP455x_503 }, + { "mcp4552-104", MCP455x_104 }, + { "mcp4631-502", MCP463x_502 }, + { "mcp4631-103", MCP463x_103 }, + { "mcp4631-503", MCP463x_503 }, + { "mcp4631-104", MCP463x_104 }, + { "mcp4632-502", MCP463x_502 }, + { "mcp4632-103", MCP463x_103 }, + { "mcp4632-503", MCP463x_503 }, + { "mcp4632-104", MCP463x_104 }, + { "mcp4651-502", MCP465x_502 }, + { "mcp4651-103", MCP465x_103 }, + { "mcp4651-503", MCP465x_503 }, + { "mcp4651-104", MCP465x_104 }, + { "mcp4652-502", MCP465x_502 }, + { "mcp4652-103", MCP465x_103 }, + { "mcp4652-503", MCP465x_503 }, + { "mcp4652-104", MCP465x_104 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, mcp4531_id); + +static struct i2c_driver mcp4531_driver = { + .driver = { + .name = "mcp4531", + }, + .probe = mcp4531_probe, + .id_table = mcp4531_id, +}; + +module_i2c_driver(mcp4531_driver); + +MODULE_AUTHOR("Peter Rosin "); +MODULE_DESCRIPTION("MCP4531 digital potentiometer"); +MODULE_LICENSE("GPL"); diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig index 4745179ff64b..6f2e7c9ac23e 100644 --- a/drivers/iio/pressure/Kconfig +++ b/drivers/iio/pressure/Kconfig @@ -79,6 +79,19 @@ config MS5611_SPI To compile this driver as a module, choose M here: the module will be called ms5611_spi. +config MS5637 + tristate "Measurement Specialties MS5637 pressure & temperature sensor" + depends on I2C + select IIO_MS_SENSORS_I2C + help + If you say yes here you get support for the Measurement Specialties + MS5637 pressure and temperature sensor. + This driver is also used for MS8607 temperature, pressure & humidity + sensor + + This driver can also be built as a module. If so, the module will + be called ms5637. + config IIO_ST_PRESS tristate "STMicroelectronics pressure sensor Driver" depends on (I2C || SPI_MASTER) && SYSFS diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile index a4f98f8d90ed..46571c96823f 100644 --- a/drivers/iio/pressure/Makefile +++ b/drivers/iio/pressure/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_MPL3115) += mpl3115.o obj-$(CONFIG_MS5611) += ms5611_core.o obj-$(CONFIG_MS5611_I2C) += ms5611_i2c.o obj-$(CONFIG_MS5611_SPI) += ms5611_spi.o +obj-$(CONFIG_MS5637) += ms5637.o obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o st_pressure-y := st_pressure_core.o st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o diff --git a/drivers/iio/pressure/ms5637.c b/drivers/iio/pressure/ms5637.c new file mode 100644 index 000000000000..e8d0e0da938d --- /dev/null +++ b/drivers/iio/pressure/ms5637.c @@ -0,0 +1,190 @@ +/* + * ms5637.c - Support for Measurement-Specialties ms5637 and ms8607 + * pressure & temperature sensor + * + * Copyright (c) 2015 Measurement-Specialties + * + * Licensed under the GPL-2. + * + * (7-bit I2C slave address 0x76) + * + * Datasheet: + * http://www.meas-spec.com/downloads/MS5637-02BA03.pdf + * Datasheet: + * http://www.meas-spec.com/downloads/MS8607-02BA01.pdf + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../common/ms_sensors/ms_sensors_i2c.h" + +static const int ms5637_samp_freq[6] = { 960, 480, 240, 120, 60, 30 }; +/* String copy of the above const for readability purpose */ +static const char ms5637_show_samp_freq[] = "960 480 240 120 60 30"; + +static int ms5637_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, int *val, + int *val2, long mask) +{ + int ret; + int temperature; + unsigned int pressure; + struct ms_tp_dev *dev_data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_PROCESSED: + ret = ms_sensors_read_temp_and_pressure(dev_data, + &temperature, + &pressure); + if (ret) + return ret; + + switch (channel->type) { + case IIO_TEMP: /* in milli °C */ + *val = temperature; + + return IIO_VAL_INT; + case IIO_PRESSURE: /* in kPa */ + *val = pressure / 1000; + *val2 = (pressure % 1000) * 1000; + + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_SAMP_FREQ: + *val = ms5637_samp_freq[dev_data->res_index]; + + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int ms5637_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct ms_tp_dev *dev_data = iio_priv(indio_dev); + int i; + + switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: + i = ARRAY_SIZE(ms5637_samp_freq); + while (i-- > 0) + if (val == ms5637_samp_freq[i]) + break; + if (i < 0) + return -EINVAL; + dev_data->res_index = i; + + return 0; + default: + return -EINVAL; + } +} + +static const struct iio_chan_spec ms5637_channels[] = { + { + .type = IIO_TEMP, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + }, + { + .type = IIO_PRESSURE, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + } +}; + +static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(ms5637_show_samp_freq); + +static struct attribute *ms5637_attributes[] = { + &iio_const_attr_sampling_frequency_available.dev_attr.attr, + NULL, +}; + +static const struct attribute_group ms5637_attribute_group = { + .attrs = ms5637_attributes, +}; + +static const struct iio_info ms5637_info = { + .read_raw = ms5637_read_raw, + .write_raw = ms5637_write_raw, + .attrs = &ms5637_attribute_group, + .driver_module = THIS_MODULE, +}; + +static int ms5637_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct ms_tp_dev *dev_data; + struct iio_dev *indio_dev; + int ret; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_READ_WORD_DATA | + I2C_FUNC_SMBUS_WRITE_BYTE | + I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { + dev_err(&client->dev, + "Adapter does not support some i2c transaction\n"); + return -ENODEV; + } + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data)); + if (!indio_dev) + return -ENOMEM; + + dev_data = iio_priv(indio_dev); + dev_data->client = client; + dev_data->res_index = 5; + mutex_init(&dev_data->lock); + + indio_dev->info = &ms5637_info; + indio_dev->name = id->name; + indio_dev->dev.parent = &client->dev; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = ms5637_channels; + indio_dev->num_channels = ARRAY_SIZE(ms5637_channels); + + i2c_set_clientdata(client, indio_dev); + + ret = ms_sensors_reset(client, 0x1E, 3000); + if (ret) + return ret; + + ret = ms_sensors_tp_read_prom(dev_data); + if (ret) + return ret; + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static const struct i2c_device_id ms5637_id[] = { + {"ms5637", 0}, + {"ms8607-temppressure", 1}, + {} +}; + +static struct i2c_driver ms5637_driver = { + .probe = ms5637_probe, + .id_table = ms5637_id, + .driver = { + .name = "ms5637" + }, +}; + +module_i2c_driver(ms5637_driver); + +MODULE_DESCRIPTION("Measurement-Specialties ms5637 temperature & pressure driver"); +MODULE_AUTHOR("William Markezana "); +MODULE_AUTHOR("Ludovic Tancerel "); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c index eb41d2b92c24..b39a2fb0671c 100644 --- a/drivers/iio/pressure/st_pressure_core.c +++ b/drivers/iio/pressure/st_pressure_core.c @@ -400,6 +400,7 @@ static const struct iio_info press_info = { .attrs = &st_press_attribute_group, .read_raw = &st_press_read_raw, .write_raw = &st_press_write_raw, + .debugfs_reg_access = &st_sensors_debugfs_reg_access, }; #ifdef CONFIG_IIO_TRIGGER diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig index 41a8d8ffa0de..ef4c73db5b53 100644 --- a/drivers/iio/proximity/Kconfig +++ b/drivers/iio/proximity/Kconfig @@ -20,6 +20,18 @@ endmenu menu "Proximity sensors" +config LIDAR_LITE_V2 + tristate "PulsedLight LIDAR sensor" + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + depends on I2C + help + Say Y to build a driver for PulsedLight LIDAR range finding + sensor. + + To compile this driver as a module, choose M here: the + module will be called pulsedlight-lite-v2 + config SX9500 tristate "SX9500 Semtech proximity sensor" select IIO_BUFFER diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile index 9818dc562abd..9aadd9a8ee99 100644 --- a/drivers/iio/proximity/Makefile +++ b/drivers/iio/proximity/Makefile @@ -4,4 +4,5 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AS3935) += as3935.o +obj-$(CONFIG_LIDAR_LITE_V2) += pulsedlight-lidar-lite-v2.o obj-$(CONFIG_SX9500) += sx9500.o diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c index bc0d68efd455..e95035136889 100644 --- a/drivers/iio/proximity/as3935.c +++ b/drivers/iio/proximity/as3935.c @@ -434,6 +434,12 @@ static int as3935_remove(struct spi_device *spi) return 0; } +static const struct of_device_id as3935_of_match[] = { + { .compatible = "ams,as3935", }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, as3935_of_match); + static const struct spi_device_id as3935_id[] = { {"as3935", 0}, {}, @@ -443,6 +449,7 @@ MODULE_DEVICE_TABLE(spi, as3935_id); static struct spi_driver as3935_driver = { .driver = { .name = "as3935", + .of_match_table = of_match_ptr(as3935_of_match), .owner = THIS_MODULE, .pm = AS3935_PM_OPS, }, diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c new file mode 100644 index 000000000000..961f9f990faf --- /dev/null +++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c @@ -0,0 +1,289 @@ +/* + * pulsedlight-lidar-lite-v2.c - Support for PulsedLight LIDAR sensor + * + * Copyright (C) 2015 Matt Ranostay + * + * 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. + * + * TODO: runtime pm, interrupt mode, and signal strength reporting + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LIDAR_REG_CONTROL 0x00 +#define LIDAR_REG_CONTROL_ACQUIRE BIT(2) + +#define LIDAR_REG_STATUS 0x01 +#define LIDAR_REG_STATUS_INVALID BIT(3) +#define LIDAR_REG_STATUS_READY BIT(0) + +#define LIDAR_REG_DATA_HBYTE 0x0f +#define LIDAR_REG_DATA_LBYTE 0x10 + +#define LIDAR_DRV_NAME "lidar" + +struct lidar_data { + struct iio_dev *indio_dev; + struct i2c_client *client; + + u16 buffer[8]; /* 2 byte distance + 8 byte timestamp */ +}; + +static const struct iio_chan_spec lidar_channels[] = { + { + .type = IIO_DISTANCE, + .info_mask_separate = + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + .scan_index = 0, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + }, + }, + IIO_CHAN_SOFT_TIMESTAMP(1), +}; + +static int lidar_read_byte(struct lidar_data *data, int reg) +{ + struct i2c_client *client = data->client; + int ret; + + /* + * Device needs a STOP condition between address write, and data read + * so in turn i2c_smbus_read_byte_data cannot be used + */ + + ret = i2c_smbus_write_byte(client, reg); + if (ret < 0) { + dev_err(&client->dev, "cannot write addr value"); + return ret; + } + + ret = i2c_smbus_read_byte(client); + if (ret < 0) + dev_err(&client->dev, "cannot read data value"); + + return ret; +} + +static inline int lidar_write_control(struct lidar_data *data, int val) +{ + return i2c_smbus_write_byte_data(data->client, LIDAR_REG_CONTROL, val); +} + +static int lidar_read_measurement(struct lidar_data *data, u16 *reg) +{ + int ret; + int val; + + ret = lidar_read_byte(data, LIDAR_REG_DATA_HBYTE); + if (ret < 0) + return ret; + val = ret << 8; + + ret = lidar_read_byte(data, LIDAR_REG_DATA_LBYTE); + if (ret < 0) + return ret; + + val |= ret; + *reg = val; + + return 0; +} + +static int lidar_get_measurement(struct lidar_data *data, u16 *reg) +{ + struct i2c_client *client = data->client; + int tries = 10; + int ret; + + /* start sample */ + ret = lidar_write_control(data, LIDAR_REG_CONTROL_ACQUIRE); + if (ret < 0) { + dev_err(&client->dev, "cannot send start measurement command"); + return ret; + } + + while (tries--) { + usleep_range(1000, 2000); + + ret = lidar_read_byte(data, LIDAR_REG_STATUS); + if (ret < 0) + break; + + /* return 0 since laser is likely pointed out of range */ + if (ret & LIDAR_REG_STATUS_INVALID) { + *reg = 0; + ret = 0; + break; + } + + /* sample ready to read */ + if (!(ret & LIDAR_REG_STATUS_READY)) { + ret = lidar_read_measurement(data, reg); + break; + } + ret = -EIO; + } + + return ret; +} + +static int lidar_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct lidar_data *data = iio_priv(indio_dev); + int ret = -EINVAL; + + mutex_lock(&indio_dev->mlock); + + if (iio_buffer_enabled(indio_dev) && mask == IIO_CHAN_INFO_RAW) { + ret = -EBUSY; + goto error_busy; + } + + switch (mask) { + case IIO_CHAN_INFO_RAW: { + u16 reg; + + ret = lidar_get_measurement(data, ®); + if (!ret) { + *val = reg; + ret = IIO_VAL_INT; + } + break; + } + case IIO_CHAN_INFO_SCALE: + *val = 0; + *val2 = 10000; + ret = IIO_VAL_INT_PLUS_MICRO; + break; + } + +error_busy: + mutex_unlock(&indio_dev->mlock); + + return ret; +} + +static irqreturn_t lidar_trigger_handler(int irq, void *private) +{ + struct iio_poll_func *pf = private; + struct iio_dev *indio_dev = pf->indio_dev; + struct lidar_data *data = iio_priv(indio_dev); + int ret; + + ret = lidar_get_measurement(data, data->buffer); + if (!ret) { + iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, + iio_get_time_ns()); + } else { + dev_err(&data->client->dev, "cannot read LIDAR measurement"); + } + + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + +static const struct iio_info lidar_info = { + .driver_module = THIS_MODULE, + .read_raw = lidar_read_raw, +}; + +static int lidar_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct lidar_data *data; + struct iio_dev *indio_dev; + int ret; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + indio_dev->info = &lidar_info; + indio_dev->name = LIDAR_DRV_NAME; + indio_dev->channels = lidar_channels; + indio_dev->num_channels = ARRAY_SIZE(lidar_channels); + indio_dev->modes = INDIO_DIRECT_MODE; + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + + data->client = client; + data->indio_dev = indio_dev; + + ret = iio_triggered_buffer_setup(indio_dev, NULL, + lidar_trigger_handler, NULL); + if (ret) + return ret; + + ret = iio_device_register(indio_dev); + if (ret) + goto error_unreg_buffer; + + return 0; + +error_unreg_buffer: + iio_triggered_buffer_cleanup(indio_dev); + + return ret; +} + +static int lidar_remove(struct i2c_client *client) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(client); + + iio_device_unregister(indio_dev); + iio_triggered_buffer_cleanup(indio_dev); + + return 0; +} + +static const struct i2c_device_id lidar_id[] = { + {"lidar-lite-v2", 0}, + { }, +}; +MODULE_DEVICE_TABLE(i2c, lidar_id); + +static const struct of_device_id lidar_dt_ids[] = { + { .compatible = "pulsedlight,lidar-lite-v2" }, + { } +}; +MODULE_DEVICE_TABLE(of, lidar_dt_ids); + +static struct i2c_driver lidar_driver = { + .driver = { + .name = LIDAR_DRV_NAME, + .of_match_table = of_match_ptr(lidar_dt_ids), + }, + .probe = lidar_probe, + .remove = lidar_remove, + .id_table = lidar_id, +}; +module_i2c_driver(lidar_driver); + +MODULE_AUTHOR("Matt Ranostay "); +MODULE_DESCRIPTION("PulsedLight LIDAR sensor"); +MODULE_LICENSE("GPL"); diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c index 3d756bd8c703..66cd09a18786 100644 --- a/drivers/iio/proximity/sx9500.c +++ b/drivers/iio/proximity/sx9500.c @@ -868,21 +868,12 @@ static void sx9500_gpio_probe(struct i2c_client *client, struct sx9500_data *data) { struct device *dev; - struct gpio_desc *gpio; if (!client) return; dev = &client->dev; - if (client->irq <= 0) { - gpio = devm_gpiod_get_index(dev, SX9500_GPIO_INT, 0, GPIOD_IN); - if (IS_ERR(gpio)) - dev_err(dev, "gpio get irq failed\n"); - else - client->irq = gpiod_to_irq(gpio); - } - data->gpiod_rst = devm_gpiod_get_index(dev, SX9500_GPIO_RESET, 0, GPIOD_OUT_HIGH); if (IS_ERR(data->gpiod_rst)) { diff --git a/drivers/iio/temperature/Kconfig b/drivers/iio/temperature/Kconfig index 21feaa4661b4..c4664e5de791 100644 --- a/drivers/iio/temperature/Kconfig +++ b/drivers/iio/temperature/Kconfig @@ -23,4 +23,26 @@ config TMP006 This driver can also be built as a module. If so, the module will be called tmp006. +config TSYS01 + tristate "Measurement Specialties TSYS01 temperature sensor using I2C bus connection" + depends on I2C + select IIO_MS_SENSORS_I2C + help + If you say yes here you get support for the Measurement Specialties + TSYS01 I2C temperature sensor. + + This driver can also be built as a module. If so, the module will + be called tsys01. + +config TSYS02D + tristate "Measurement Specialties TSYS02D temperature sensor" + depends on I2C + select IIO_MS_SENSORS_I2C + help + If you say yes here you get support for the Measurement Specialties + TSYS02D temperature sensor. + + This driver can also be built as a module. If so, the module will + be called tsys02d. + endmenu diff --git a/drivers/iio/temperature/Makefile b/drivers/iio/temperature/Makefile index 40710a81158e..02bc79d49b24 100644 --- a/drivers/iio/temperature/Makefile +++ b/drivers/iio/temperature/Makefile @@ -4,3 +4,5 @@ obj-$(CONFIG_MLX90614) += mlx90614.o obj-$(CONFIG_TMP006) += tmp006.o +obj-$(CONFIG_TSYS01) += tsys01.o +obj-$(CONFIG_TSYS02D) += tsys02d.o diff --git a/drivers/iio/temperature/mlx90614.c b/drivers/iio/temperature/mlx90614.c index 5d033a5af615..a570c2e2aac3 100644 --- a/drivers/iio/temperature/mlx90614.c +++ b/drivers/iio/temperature/mlx90614.c @@ -3,6 +3,7 @@ * * Copyright (c) 2014 Peter Meerwald * Copyright (c) 2015 Essensium NV + * Copyright (c) 2015 Melexis * * This file is subject to the terms and conditions of version 2 of * the GNU General Public License. See the file COPYING in the main @@ -20,7 +21,6 @@ * always has a pull-up so we do not need an extra GPIO to drive it high. If * the "wakeup" GPIO is not given, power management will be disabled. * - * TODO: filter configuration */ #include @@ -32,6 +32,7 @@ #include #include +#include #define MLX90614_OP_RAM 0x00 #define MLX90614_OP_EEPROM 0x20 @@ -71,6 +72,7 @@ #define MLX90614_CONST_SCALE 20 /* Scale in milliKelvin (0.02 * 1000) */ #define MLX90614_CONST_RAW_EMISSIVITY_MAX 65535 /* max value for emissivity */ #define MLX90614_CONST_EMISSIVITY_RESOLUTION 15259 /* 1/65535 ~ 0.000015259 */ +#define MLX90614_CONST_FIR 0x7 /* Fixed value for FIR part of low pass filter */ struct mlx90614_data { struct i2c_client *client; @@ -79,6 +81,20 @@ struct mlx90614_data { unsigned long ready_timestamp; /* in jiffies */ }; +/* Bandwidth values for IIR filtering */ +static const int mlx90614_iir_values[] = {77, 31, 20, 15, 723, 153, 110, 86}; +static IIO_CONST_ATTR(in_temp_object_filter_low_pass_3db_frequency_available, + "0.15 0.20 0.31 0.77 0.86 1.10 1.53 7.23"); + +static struct attribute *mlx90614_attributes[] = { + &iio_const_attr_in_temp_object_filter_low_pass_3db_frequency_available.dev_attr.attr, + NULL, +}; + +static const struct attribute_group mlx90614_attr_group = { + .attrs = mlx90614_attributes, +}; + /* * Erase an address and write word. * The mutex must be locked before calling. @@ -117,6 +133,43 @@ static s32 mlx90614_write_word(const struct i2c_client *client, u8 command, return ret; } +/* + * Find the IIR value inside mlx90614_iir_values array and return its position + * which is equivalent to the bit value in sensor register + */ +static inline s32 mlx90614_iir_search(const struct i2c_client *client, + int value) +{ + int i; + s32 ret; + + for (i = 0; i < ARRAY_SIZE(mlx90614_iir_values); ++i) { + if (value == mlx90614_iir_values[i]) + break; + } + + if (i == ARRAY_SIZE(mlx90614_iir_values)) + return -EINVAL; + + /* + * CONFIG register values must not be changed so + * we must read them before we actually write + * changes + */ + ret = i2c_smbus_read_word_data(client, MLX90614_CONFIG); + if (ret < 0) + return ret; + + ret &= ~MLX90614_CONFIG_FIR_MASK; + ret |= MLX90614_CONST_FIR << MLX90614_CONFIG_FIR_SHIFT; + ret &= ~MLX90614_CONFIG_IIR_MASK; + ret |= i << MLX90614_CONFIG_IIR_SHIFT; + + /* Write changed values */ + ret = mlx90614_write_word(client, MLX90614_CONFIG, ret); + return ret; +} + #ifdef CONFIG_PM /* * If @startup is true, make sure MLX90614_TIMING_STARTUP ms have elapsed since @@ -236,6 +289,21 @@ static int mlx90614_read_raw(struct iio_dev *indio_dev, *val2 = ret * MLX90614_CONST_EMISSIVITY_RESOLUTION; } return IIO_VAL_INT_PLUS_NANO; + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: /* IIR setting with + FIR = 1024 */ + mlx90614_power_get(data, false); + mutex_lock(&data->lock); + ret = i2c_smbus_read_word_data(data->client, MLX90614_CONFIG); + mutex_unlock(&data->lock); + mlx90614_power_put(data); + + if (ret < 0) + return ret; + + *val = mlx90614_iir_values[ret & MLX90614_CONFIG_IIR_MASK] / 100; + *val2 = (mlx90614_iir_values[ret & MLX90614_CONFIG_IIR_MASK] % 100) * + 10000; + return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; } @@ -262,6 +330,18 @@ static int mlx90614_write_raw(struct iio_dev *indio_dev, mutex_unlock(&data->lock); mlx90614_power_put(data); + return ret; + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: /* IIR Filter setting */ + if (val < 0 || val2 < 0) + return -EINVAL; + + mlx90614_power_get(data, false); + mutex_lock(&data->lock); + ret = mlx90614_iir_search(data->client, + val * 100 + val2 / 10000); + mutex_unlock(&data->lock); + mlx90614_power_put(data); + return ret; default: return -EINVAL; @@ -275,6 +355,8 @@ static int mlx90614_write_raw_get_fmt(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_CALIBEMISSIVITY: return IIO_VAL_INT_PLUS_NANO; + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; } @@ -294,7 +376,8 @@ static const struct iio_chan_spec mlx90614_channels[] = { .modified = 1, .channel2 = IIO_MOD_TEMP_OBJECT, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_CALIBEMISSIVITY), + BIT(IIO_CHAN_INFO_CALIBEMISSIVITY) | + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_SCALE), }, @@ -305,7 +388,8 @@ static const struct iio_chan_spec mlx90614_channels[] = { .channel = 1, .channel2 = IIO_MOD_TEMP_OBJECT, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_CALIBEMISSIVITY), + BIT(IIO_CHAN_INFO_CALIBEMISSIVITY) | + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_SCALE), }, @@ -315,6 +399,7 @@ static const struct iio_info mlx90614_info = { .read_raw = mlx90614_read_raw, .write_raw = mlx90614_write_raw, .write_raw_get_fmt = mlx90614_write_raw_get_fmt, + .attrs = &mlx90614_attr_group, .driver_module = THIS_MODULE, }; @@ -569,5 +654,6 @@ module_i2c_driver(mlx90614_driver); MODULE_AUTHOR("Peter Meerwald "); MODULE_AUTHOR("Vianney le Clément de Saint-Marcq "); +MODULE_AUTHOR("Crt Mori "); MODULE_DESCRIPTION("Melexis MLX90614 contactless IR temperature sensor driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/iio/temperature/tsys01.c b/drivers/iio/temperature/tsys01.c new file mode 100644 index 000000000000..05c12060ce8d --- /dev/null +++ b/drivers/iio/temperature/tsys01.c @@ -0,0 +1,230 @@ +/* + * tsys01.c - Support for Measurement-Specialties tsys01 temperature sensor + * + * Copyright (c) 2015 Measurement-Specialties + * + * Licensed under the GPL-2. + * + * Datasheet: + * http://www.meas-spec.com/downloads/TSYS01_Digital_Temperature_Sensor.pdf + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "../common/ms_sensors/ms_sensors_i2c.h" + +/* TSYS01 Commands */ +#define TSYS01_RESET 0x1E +#define TSYS01_CONVERSION_START 0x48 +#define TSYS01_ADC_READ 0x00 +#define TSYS01_PROM_READ 0xA0 + +#define TSYS01_PROM_WORDS_NB 8 + +struct tsys01_dev { + void *client; + struct mutex lock; /* lock during conversion */ + + int (*reset)(void *cli, u8 cmd, unsigned int delay); + int (*convert_and_read)(void *cli, u8 conv, u8 rd, + unsigned int delay, u32 *adc); + int (*read_prom_word)(void *cli, int cmd, u16 *word); + + u16 prom[TSYS01_PROM_WORDS_NB]; +}; + +/* Multiplication coefficients for temperature computation */ +static const int coeff_mul[] = { -1500000, 1000000, -2000000, + 4000000, -2000000 }; + +static int tsys01_read_temperature(struct iio_dev *indio_dev, + s32 *temperature) +{ + int ret, i; + u32 adc; + s64 temp = 0; + struct tsys01_dev *dev_data = iio_priv(indio_dev); + + mutex_lock(&dev_data->lock); + ret = dev_data->convert_and_read(dev_data->client, + TSYS01_CONVERSION_START, + TSYS01_ADC_READ, 9000, &adc); + mutex_unlock(&dev_data->lock); + if (ret) + return ret; + + adc >>= 8; + + /* Temperature algorithm */ + for (i = 4; i > 0; i--) { + temp += coeff_mul[i] * + (s64)dev_data->prom[5 - i]; + temp *= (s64)adc; + temp = div64_s64(temp, 100000); + } + temp *= 10; + temp += coeff_mul[0] * (s64)dev_data->prom[5]; + temp = div64_s64(temp, 100000); + + *temperature = temp; + + return 0; +} + +static int tsys01_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, int *val, + int *val2, long mask) +{ + int ret; + s32 temperature; + + switch (mask) { + case IIO_CHAN_INFO_PROCESSED: + switch (channel->type) { + case IIO_TEMP: /* in milli °C */ + ret = tsys01_read_temperature(indio_dev, &temperature); + if (ret) + return ret; + *val = temperature; + + return IIO_VAL_INT; + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + +static const struct iio_chan_spec tsys01_channels[] = { + { + .type = IIO_TEMP, + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED), + } +}; + +static const struct iio_info tsys01_info = { + .read_raw = tsys01_read_raw, + .driver_module = THIS_MODULE, +}; + +static bool tsys01_crc_valid(u16 *n_prom) +{ + u8 cnt; + u8 sum = 0; + + for (cnt = 0; cnt < TSYS01_PROM_WORDS_NB; cnt++) + sum += ((n_prom[0] >> 8) + (n_prom[0] & 0xFF)); + + return (sum == 0); +} + +static int tsys01_read_prom(struct iio_dev *indio_dev) +{ + int i, ret; + struct tsys01_dev *dev_data = iio_priv(indio_dev); + char buf[7 * TSYS01_PROM_WORDS_NB + 1]; + char *ptr = buf; + + for (i = 0; i < TSYS01_PROM_WORDS_NB; i++) { + ret = dev_data->read_prom_word(dev_data->client, + TSYS01_PROM_READ + (i << 1), + &dev_data->prom[i]); + if (ret) + return ret; + + ret = sprintf(ptr, "0x%04x ", dev_data->prom[i]); + ptr += ret; + } + + if (!tsys01_crc_valid(dev_data->prom)) { + dev_err(&indio_dev->dev, "prom crc check error\n"); + return -ENODEV; + } + *ptr = 0; + dev_info(&indio_dev->dev, "PROM coefficients : %s\n", buf); + + return 0; +} + +static int tsys01_probe(struct iio_dev *indio_dev, struct device *dev) +{ + int ret; + struct tsys01_dev *dev_data = iio_priv(indio_dev); + + mutex_init(&dev_data->lock); + + indio_dev->info = &tsys01_info; + indio_dev->name = dev->driver->name; + indio_dev->dev.parent = dev; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = tsys01_channels; + indio_dev->num_channels = ARRAY_SIZE(tsys01_channels); + + ret = dev_data->reset(dev_data->client, TSYS01_RESET, 3000); + if (ret) + return ret; + + ret = tsys01_read_prom(indio_dev); + if (ret) + return ret; + + return devm_iio_device_register(dev, indio_dev); +} + +static int tsys01_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct tsys01_dev *dev_data; + struct iio_dev *indio_dev; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WORD_DATA | + I2C_FUNC_SMBUS_WRITE_BYTE | + I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { + dev_err(&client->dev, + "Adapter does not support some i2c transaction\n"); + return -ENODEV; + } + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data)); + if (!indio_dev) + return -ENOMEM; + + dev_data = iio_priv(indio_dev); + dev_data->client = client; + dev_data->reset = ms_sensors_reset; + dev_data->read_prom_word = ms_sensors_read_prom_word; + dev_data->convert_and_read = ms_sensors_convert_and_read; + + i2c_set_clientdata(client, indio_dev); + + return tsys01_probe(indio_dev, &client->dev); +} + +static const struct i2c_device_id tsys01_id[] = { + {"tsys01", 0}, + {} +}; +MODULE_DEVICE_TABLE(i2c, tsys01_id); + +static struct i2c_driver tsys01_driver = { + .probe = tsys01_i2c_probe, + .id_table = tsys01_id, + .driver = { + .name = "tsys01", + }, +}; + +module_i2c_driver(tsys01_driver); + +MODULE_DESCRIPTION("Measurement-Specialties tsys01 temperature driver"); +MODULE_AUTHOR("William Markezana "); +MODULE_AUTHOR("Ludovic Tancerel "); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/temperature/tsys02d.c b/drivers/iio/temperature/tsys02d.c new file mode 100644 index 000000000000..4c1fbd52ea08 --- /dev/null +++ b/drivers/iio/temperature/tsys02d.c @@ -0,0 +1,191 @@ +/* + * tsys02d.c - Support for Measurement-Specialties tsys02d temperature sensor + * + * Copyright (c) 2015 Measurement-Specialties + * + * Licensed under the GPL-2. + * + * (7-bit I2C slave address 0x40) + * + * Datasheet: + * http://www.meas-spec.com/downloads/Digital_Sensor_TSYS02D.pdf + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "../common/ms_sensors/ms_sensors_i2c.h" + +#define TSYS02D_RESET 0xFE + +static const int tsys02d_samp_freq[4] = { 20, 40, 70, 140 }; +/* String copy of the above const for readability purpose */ +static const char tsys02d_show_samp_freq[] = "20 40 70 140"; + +static int tsys02d_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, int *val, + int *val2, long mask) +{ + int ret; + s32 temperature; + struct ms_ht_dev *dev_data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_PROCESSED: + switch (channel->type) { + case IIO_TEMP: /* in milli °C */ + ret = ms_sensors_ht_read_temperature(dev_data, + &temperature); + if (ret) + return ret; + *val = temperature; + + return IIO_VAL_INT; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_SAMP_FREQ: + *val = tsys02d_samp_freq[dev_data->res_index]; + + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int tsys02d_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct ms_ht_dev *dev_data = iio_priv(indio_dev); + int i, ret; + + switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: + i = ARRAY_SIZE(tsys02d_samp_freq); + while (i-- > 0) + if (val == tsys02d_samp_freq[i]) + break; + if (i < 0) + return -EINVAL; + mutex_lock(&dev_data->lock); + dev_data->res_index = i; + ret = ms_sensors_write_resolution(dev_data, i); + mutex_unlock(&dev_data->lock); + + return ret; + default: + return -EINVAL; + } +} + +static const struct iio_chan_spec tsys02d_channels[] = { + { + .type = IIO_TEMP, + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + } +}; + +static ssize_t tsys02_read_battery_low(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct ms_ht_dev *dev_data = iio_priv(indio_dev); + + return ms_sensors_show_battery_low(dev_data, buf); +} + +static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(tsys02d_show_samp_freq); +static IIO_DEVICE_ATTR(battery_low, S_IRUGO, + tsys02_read_battery_low, NULL, 0); + +static struct attribute *tsys02d_attributes[] = { + &iio_const_attr_sampling_frequency_available.dev_attr.attr, + &iio_dev_attr_battery_low.dev_attr.attr, + NULL, +}; + +static const struct attribute_group tsys02d_attribute_group = { + .attrs = tsys02d_attributes, +}; + +static const struct iio_info tsys02d_info = { + .read_raw = tsys02d_read_raw, + .write_raw = tsys02d_write_raw, + .attrs = &tsys02d_attribute_group, + .driver_module = THIS_MODULE, +}; + +static int tsys02d_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct ms_ht_dev *dev_data; + struct iio_dev *indio_dev; + int ret; + u64 serial_number; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WRITE_BYTE_DATA | + I2C_FUNC_SMBUS_WRITE_BYTE | + I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { + dev_err(&client->dev, + "Adapter does not support some i2c transaction\n"); + return -ENODEV; + } + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data)); + if (!indio_dev) + return -ENOMEM; + + dev_data = iio_priv(indio_dev); + dev_data->client = client; + dev_data->res_index = 0; + mutex_init(&dev_data->lock); + + indio_dev->info = &tsys02d_info; + indio_dev->name = id->name; + indio_dev->dev.parent = &client->dev; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = tsys02d_channels; + indio_dev->num_channels = ARRAY_SIZE(tsys02d_channels); + + i2c_set_clientdata(client, indio_dev); + + ret = ms_sensors_reset(client, TSYS02D_RESET, 15000); + if (ret) + return ret; + + ret = ms_sensors_read_serial(client, &serial_number); + if (ret) + return ret; + dev_info(&client->dev, "Serial number : %llx", serial_number); + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static const struct i2c_device_id tsys02d_id[] = { + {"tsys02d", 0}, + {} +}; + +static struct i2c_driver tsys02d_driver = { + .probe = tsys02d_probe, + .id_table = tsys02d_id, + .driver = { + .name = "tsys02d", + }, +}; + +module_i2c_driver(tsys02d_driver); + +MODULE_DESCRIPTION("Measurement-Specialties tsys02d temperature driver"); +MODULE_AUTHOR("William Markezana "); +MODULE_AUTHOR("Ludovic Tancerel "); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index 39d950584c9f..5d3b86a33857 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -62,8 +62,6 @@ source "drivers/staging/xgifb/Kconfig" source "drivers/staging/emxx_udc/Kconfig" -source "drivers/staging/ft1000/Kconfig" - source "drivers/staging/speakup/Kconfig" source "drivers/staging/ste_rmi4/Kconfig" diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index e4f33d91872b..30918edef5e3 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -25,7 +25,6 @@ obj-$(CONFIG_IIO) += iio/ obj-$(CONFIG_FB_SM750) += sm750fb/ obj-$(CONFIG_FB_XGI) += xgifb/ obj-$(CONFIG_USB_EMXX) += emxx_udc/ -obj-$(CONFIG_FT1000) += ft1000/ obj-$(CONFIG_SPEAKUP) += speakup/ obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4) += ste_rmi4/ obj-$(CONFIG_MFD_NVEC) += nvec/ diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig index 68307121c9c1..42b15126aa06 100644 --- a/drivers/staging/android/Kconfig +++ b/drivers/staging/android/Kconfig @@ -54,7 +54,7 @@ config SW_SYNC depends on SYNC ---help--- A sync object driver that uses a 32bit counter to coordinate - syncrhronization. Useful when there is no hardware primitive backing + synchronization. Useful when there is no hardware primitive backing the synchronization. config SW_SYNC_USER diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c index 60200a3da821..3f2a3d611e4b 100644 --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -18,7 +18,8 @@ #define pr_fmt(fmt) "ashmem: " fmt -#include +#include +#include #include #include #include @@ -43,7 +44,7 @@ * @unpinned_list: The list of all ashmem areas * @file: The shmem-based backing file * @size: The size of the mapping, in bytes - * @prot_masks: The allowed protection bits, as vm_flags + * @prot_mask: The allowed protection bits, as vm_flags * * The lifecycle of this structure is from our parent file's open() until * its release(). It is also protected by 'ashmem_mutex' @@ -82,14 +83,14 @@ struct ashmem_range { /* LRU list of unpinned pages, protected by ashmem_mutex */ static LIST_HEAD(ashmem_lru_list); -/** +/* * long lru_count - The count of pages on our LRU list. * * This is protected by ashmem_mutex. */ static unsigned long lru_count; -/** +/* * ashmem_mutex - protects the list of and each individual ashmem_area * * Lock Ordering: ashmex_mutex -> i_mutex -> i_alloc_sem @@ -311,10 +312,9 @@ static ssize_t ashmem_read(struct file *file, char __user *buf, * ashmem_release is called. */ ret = __vfs_read(asma->file, buf, len, pos); - if (ret >= 0) { + if (ret >= 0) /** Update backing file pos, since f_ops->read() doesn't */ asma->file->f_pos = *pos; - } return ret; out_unlock: @@ -618,7 +618,8 @@ static int ashmem_pin(struct ashmem_area *asma, size_t pgstart, size_t pgend) /* Case #3: We overlap from the rear, so adjust it */ if (range->pgend <= pgend) { - range_shrink(range, range->pgstart, pgstart-1); + range_shrink(range, range->pgstart, + pgstart - 1); continue; } @@ -715,7 +716,7 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd, if (unlikely((pin.offset | pin.len) & ~PAGE_MASK)) return -EINVAL; - if (unlikely(((__u32) -1) - pin.offset < pin.len)) + if (unlikely(((__u32)-1) - pin.offset < pin.len)) return -EINVAL; if (unlikely(PAGE_ALIGN(asma->size) < pin.offset + pin.len)) @@ -759,7 +760,7 @@ static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ret = -EINVAL; if (!asma->file) { ret = 0; - asma->size = (size_t) arg; + asma->size = (size_t)arg; } break; case ASHMEM_GET_SIZE: @@ -833,16 +834,16 @@ static int __init ashmem_init(void) int ret; ashmem_area_cachep = kmem_cache_create("ashmem_area_cache", - sizeof(struct ashmem_area), - 0, 0, NULL); + sizeof(struct ashmem_area), + 0, 0, NULL); if (unlikely(!ashmem_area_cachep)) { pr_err("failed to create slab cache\n"); return -ENOMEM; } ashmem_range_cachep = kmem_cache_create("ashmem_range_cache", - sizeof(struct ashmem_range), - 0, 0, NULL); + sizeof(struct ashmem_range), + 0, 0, NULL); if (unlikely(!ashmem_range_cachep)) { pr_err("failed to create slab cache\n"); return -ENOMEM; @@ -860,19 +861,4 @@ static int __init ashmem_init(void) return 0; } - -static void __exit ashmem_exit(void) -{ - unregister_shrinker(&ashmem_shrinker); - - misc_deregister(&ashmem_misc); - kmem_cache_destroy(ashmem_range_cachep); - kmem_cache_destroy(ashmem_area_cachep); - - pr_info("unloaded\n"); -} - -module_init(ashmem_init); -module_exit(ashmem_exit); - -MODULE_LICENSE("GPL"); +device_initcall(ashmem_init); diff --git a/drivers/staging/android/ion/compat_ion.h b/drivers/staging/android/ion/compat_ion.h index c2ad5893dfda..9da8f917670b 100644 --- a/drivers/staging/android/ion/compat_ion.h +++ b/drivers/staging/android/ion/compat_ion.h @@ -1,5 +1,4 @@ /* - * drivers/staging/android/ion/compat_ion.h * * Copyright (C) 2013 Google, Inc. diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 6e8d8392ca38..e237e9f3312d 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -1,5 +1,5 @@ /* - + * * drivers/staging/android/ion/ion.c * * Copyright (C) 2011 Google, Inc. @@ -213,10 +213,10 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, "heap->ops->map_dma should return ERR_PTR on error")) table = ERR_PTR(-EINVAL); if (IS_ERR(table)) { - heap->ops->free(buffer); - kfree(buffer); - return ERR_CAST(table); + ret = -EINVAL; + goto err1; } + buffer->sg_table = table; if (ion_buffer_fault_user_mappings(buffer)) { int num_pages = PAGE_ALIGN(buffer->size) / PAGE_SIZE; @@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, buffer->pages = vmalloc(sizeof(struct page *) * num_pages); if (!buffer->pages) { ret = -ENOMEM; - goto err1; + goto err; } for_each_sg(table->sgl, sg, table->nents, i) { @@ -235,23 +235,22 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, for (j = 0; j < sg->length / PAGE_SIZE; j++) buffer->pages[k++] = page++; } - - if (ret) - goto err; } buffer->dev = dev; buffer->size = len; INIT_LIST_HEAD(&buffer->vmas); mutex_init(&buffer->lock); - /* this will set up dma addresses for the sglist -- it is not - technically correct as per the dma api -- a specific - device isn't really taking ownership here. However, in practice on - our systems the only dma_address space is physical addresses. - Additionally, we can't afford the overhead of invalidating every - allocation via dma_map_sg. The implicit contract here is that - memory coming from the heaps is ready for dma, ie if it has a - cached mapping that mapping has been invalidated */ + /* + * this will set up dma addresses for the sglist -- it is not + * technically correct as per the dma api -- a specific + * device isn't really taking ownership here. However, in practice on + * our systems the only dma_address space is physical addresses. + * Additionally, we can't afford the overhead of invalidating every + * allocation via dma_map_sg. The implicit contract here is that + * memory coming from the heaps is ready for dma, ie if it has a + * cached mapping that mapping has been invalidated + */ for_each_sg(buffer->sg_table->sgl, sg, buffer->sg_table->nents, i) sg_dma_address(sg) = sg_phys(sg); mutex_lock(&dev->buffer_lock); @@ -261,9 +260,8 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, err: heap->ops->unmap_dma(heap, buffer); - heap->ops->free(buffer); err1: - vfree(buffer->pages); + heap->ops->free(buffer); err2: kfree(buffer); return ERR_PTR(ret); @@ -753,8 +751,10 @@ struct ion_client *ion_client_create(struct ion_device *dev, get_task_struct(current->group_leader); task_lock(current->group_leader); pid = task_pid_nr(current->group_leader); - /* don't bother to store task struct for kernel threads, - they can't be killed anyway */ + /* + * don't bother to store task struct for kernel threads, + * they can't be killed anyway + */ if (current->group_leader->flags & PF_KTHREAD) { put_task_struct(current->group_leader); task = NULL; @@ -1521,8 +1521,10 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap) heap->dev = dev; down_write(&dev->lock); - /* use negative heap->id to reverse the priority -- when traversing - the list later attempt higher id numbers first */ + /* + * use negative heap->id to reverse the priority -- when traversing + * the list later attempt higher id numbers first + */ plist_node_init(&heap->node, -heap->id); plist_add(&heap->node, &dev->heaps); debug_file = debugfs_create_file(heap->name, 0664, @@ -1555,6 +1557,7 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap) up_write(&dev->lock); } +EXPORT_SYMBOL(ion_device_add_heap); struct ion_device *ion_device_create(long (*custom_ioctl) (struct ion_client *client, @@ -1604,6 +1607,7 @@ debugfs_done: idev->clients = RB_ROOT; return idev; } +EXPORT_SYMBOL(ion_device_create); void ion_device_destroy(struct ion_device *dev) { @@ -1612,6 +1616,7 @@ void ion_device_destroy(struct ion_device *dev) /* XXX need to free the heaps and clients ? */ kfree(dev); } +EXPORT_SYMBOL(ion_device_destroy); void __init ion_reserve(struct ion_platform_data *data) { diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 443db8459a9e..b860c5f579f5 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -28,10 +28,12 @@ struct ion_mapper; struct ion_client; struct ion_buffer; -/* This should be removed some day when phys_addr_t's are fully - plumbed in the kernel, and all instances of ion_phys_addr_t should - be converted to phys_addr_t. For the time being many kernel interfaces - do not accept phys_addr_t's that would have to */ +/* + * This should be removed some day when phys_addr_t's are fully + * plumbed in the kernel, and all instances of ion_phys_addr_t should + * be converted to phys_addr_t. For the time being many kernel interfaces + * do not accept phys_addr_t's that would have to + */ #define ion_phys_addr_t unsigned long /** diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c index 0b2448c32495..a3446da4fdc2 100644 --- a/drivers/staging/android/ion/ion_cma_heap.c +++ b/drivers/staging/android/ion/ion_cma_heap.c @@ -180,8 +180,10 @@ struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *data) return ERR_PTR(-ENOMEM); cma_heap->heap.ops = &ion_cma_ops; - /* get device from private heaps data, later it will be - * used to make the link with reserved CMA memory */ + /* + * get device from private heaps data, later it will be + * used to make the link with reserved CMA memory + */ cma_heap->dev = data->priv; cma_heap->heap.type = ION_HEAP_TYPE_DMA; return &cma_heap->heap; diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c index fd13d05b538a..ca15a87f6fd3 100644 --- a/drivers/staging/android/ion/ion_heap.c +++ b/drivers/staging/android/ion/ion_heap.c @@ -56,7 +56,7 @@ void *ion_heap_map_kernel(struct ion_heap *heap, vaddr = vmap(pages, npages, VM_MAP, pgprot); vfree(pages); - if (vaddr == NULL) + if (!vaddr) return ERR_PTR(-ENOMEM); return vaddr; @@ -352,6 +352,7 @@ struct ion_heap *ion_heap_create(struct ion_platform_heap *heap_data) heap->id = heap_data->id; return heap; } +EXPORT_SYMBOL(ion_heap_create); void ion_heap_destroy(struct ion_heap *heap) { @@ -379,3 +380,4 @@ void ion_heap_destroy(struct ion_heap *heap) heap->type); } } +EXPORT_SYMBOL(ion_heap_destroy); diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c index 19ad3aba499a..fd7e23e0c06e 100644 --- a/drivers/staging/android/ion/ion_page_pool.c +++ b/drivers/staging/android/ion/ion_page_pool.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include "ion_priv.h" @@ -174,10 +174,4 @@ static int __init ion_page_pool_init(void) { return 0; } - -static void __exit ion_page_pool_exit(void) -{ -} - -module_init(ion_page_pool_init); -module_exit(ion_page_pool_exit); +device_initcall(ion_page_pool_init); diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 52f1cd1a67ed..0239883bffb7 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -346,7 +346,8 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, * to keep a pool of pre allocated memory to use from your heap. Keeping * a pool of memory that is ready for dma, ie any cached mapping have been * invalidated from the cache, provides a significant performance benefit on - * many systems */ + * many systems + */ /** * struct ion_page_pool - pagepool struct diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 7a7a9a047230..ada724aab3d5 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -185,8 +185,11 @@ static void ion_system_heap_free(struct ion_buffer *buffer) struct scatterlist *sg; int i; - /* uncached pages come from the page pools, zero them before returning - for security purposes (other allocations are zerod at alloc time */ + /* + * uncached pages come from the page pools, zero them before returning + * for security purposes (other allocations are zerod at + * alloc time + */ if (!cached && !(buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE)) ion_heap_buffer_zero(buffer); diff --git a/drivers/staging/android/ion/tegra/Makefile b/drivers/staging/android/ion/tegra/Makefile index 11cd003fb08f..808f1f53f11a 100644 --- a/drivers/staging/android/ion/tegra/Makefile +++ b/drivers/staging/android/ion/tegra/Makefile @@ -1 +1 @@ -obj-y += tegra_ion.o +obj-$(CONFIG_ION_TEGRA) += tegra_ion.o diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c index 872bd603fd0d..e679d8432810 100644 --- a/drivers/staging/android/lowmemorykiller.c +++ b/drivers/staging/android/lowmemorykiller.c @@ -32,7 +32,8 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#include +#include +#include #include #include #include @@ -157,26 +158,22 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc) } if (selected) { task_lock(selected); - if (!selected->mm) { - /* Already exited, cannot do mark_tsk_oom_victim() */ - task_unlock(selected); - goto out; - } + send_sig(SIGKILL, selected, 0); /* * FIXME: lowmemorykiller shouldn't abuse global OOM killer * infrastructure. There is no real reason why the selected * task should have access to the memory reserves. */ - mark_oom_victim(selected); + if (selected->mm) + mark_oom_victim(selected); task_unlock(selected); lowmem_print(1, "send sigkill to %d (%s), adj %hd, size %d\n", selected->pid, selected->comm, selected_oom_score_adj, selected_tasksize); lowmem_deathpending_timeout = jiffies + HZ; - send_sig(SIGKILL, selected, 0); rem += selected_tasksize; } -out: + lowmem_print(4, "lowmem_scan %lu, %x, return %lu\n", sc->nr_to_scan, sc->gfp_mask, rem); rcu_read_unlock(); @@ -194,12 +191,12 @@ static int __init lowmem_init(void) register_shrinker(&lowmem_shrinker); return 0; } +device_initcall(lowmem_init); -static void __exit lowmem_exit(void) -{ - unregister_shrinker(&lowmem_shrinker); -} - +/* + * not really modular, but the easiest way to keep compat with existing + * bootargs behaviour is to continue using module_param here. + */ module_param_named(cost, lowmem_shrinker.seeks, int, S_IRUGO | S_IWUSR); module_param_array_named(adj, lowmem_adj, short, &lowmem_adj_size, S_IRUGO | S_IWUSR); @@ -207,8 +204,3 @@ module_param_array_named(minfree, lowmem_minfree, uint, &lowmem_minfree_size, S_IRUGO | S_IWUSR); module_param_named(debug_level, lowmem_debug_level, uint, S_IRUGO | S_IWUSR); -module_init(lowmem_init); -module_exit(lowmem_exit); - -MODULE_LICENSE("GPL"); - diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c index c90838d36953..c4ff1679ebbc 100644 --- a/drivers/staging/android/sw_sync.c +++ b/drivers/staging/android/sw_sync.c @@ -15,11 +15,11 @@ */ #include +#include #include #include #include #include -#include #include #include @@ -145,7 +145,7 @@ static int sw_sync_open(struct inode *inode, struct file *file) get_task_comm(task_comm, current); obj = sw_sync_timeline_create(task_comm); - if (obj == NULL) + if (!obj) return -ENOMEM; file->private_data = obj; @@ -179,14 +179,14 @@ static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj, } pt = sw_sync_pt_create(obj, data.value); - if (pt == NULL) { + if (!pt) { err = -ENOMEM; goto err; } data.name[sizeof(data.name) - 1] = '\0'; fence = sync_fence_create(data.name, pt); - if (fence == NULL) { + if (!fence) { sync_pt_free(pt); err = -ENOMEM; goto err; @@ -255,13 +255,6 @@ static int __init sw_sync_device_init(void) { return misc_register(&sw_sync_dev); } - -static void __exit sw_sync_device_remove(void) -{ - misc_deregister(&sw_sync_dev); -} - -module_init(sw_sync_device_init); -module_exit(sw_sync_device_remove); +device_initcall(sw_sync_device_init); #endif /* CONFIG_SW_SYNC_USER */ diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c index b41429f379fe..aff9cdb007e5 100644 --- a/drivers/staging/android/timed_output.c +++ b/drivers/staging/android/timed_output.c @@ -16,7 +16,8 @@ #define pr_fmt(fmt) "timed_output: " fmt -#include +#include +#include #include #include #include @@ -106,15 +107,4 @@ static int __init timed_output_init(void) { return create_timed_output_class(); } - -static void __exit timed_output_exit(void) -{ - class_destroy(timed_output_class); -} - -module_init(timed_output_init); -module_exit(timed_output_exit); - -MODULE_AUTHOR("Mike Lockwood "); -MODULE_DESCRIPTION("timed output class driver"); -MODULE_LICENSE("GPL"); +device_initcall(timed_output_init); diff --git a/drivers/staging/android/uapi/ion.h b/drivers/staging/android/uapi/ion.h index 68a14b4e21cb..0a8e40f92cd7 100644 --- a/drivers/staging/android/uapi/ion.h +++ b/drivers/staging/android/uapi/ion.h @@ -40,8 +40,10 @@ enum ion_heap_type { ION_HEAP_TYPE_CARVEOUT, ION_HEAP_TYPE_CHUNK, ION_HEAP_TYPE_DMA, - ION_HEAP_TYPE_CUSTOM, /* must be last so device specific heaps always - are at the end of this enum */ + ION_HEAP_TYPE_CUSTOM, /* + * must be last so device specific heaps always + * are at the end of this enum + */ ION_NUM_HEAPS = 16, }; @@ -56,13 +58,18 @@ enum ion_heap_type { * allocation flags - the lower 16 bits are used by core ion, the upper 16 * bits are reserved for use by the heaps themselves. */ -#define ION_FLAG_CACHED 1 /* mappings of this buffer should be - cached, ion will do cache - maintenance when the buffer is - mapped for dma */ -#define ION_FLAG_CACHED_NEEDS_SYNC 2 /* mappings of this buffer will created - at mmap time, if this is set - caches must be managed manually */ +#define ION_FLAG_CACHED 1 /* + * mappings of this buffer should be + * cached, ion will do cache + * maintenance when the buffer is + * mapped for dma + */ +#define ION_FLAG_CACHED_NEEDS_SYNC 2 /* + * mappings of this buffer will created + * at mmap time, if this is set + * caches must be managed + * manually + */ /** * DOC: Ion Userspace API diff --git a/drivers/staging/board/board.c b/drivers/staging/board/board.c index 3eb5eb8f069c..965afc79aadd 100644 --- a/drivers/staging/board/board.c +++ b/drivers/staging/board/board.c @@ -187,6 +187,9 @@ int __init board_staging_register_device(const struct board_staging_dev *dev) for (i = 0; i < dev->nclocks; i++) board_staging_register_clock(&dev->clocks[i]); + if (dev->domain) + board_staging_add_dev_domain(pdev, dev->domain); + error = platform_device_register(pdev); if (error) { pr_err("Failed to register device %s (%d)\n", pdev->name, @@ -194,9 +197,6 @@ int __init board_staging_register_device(const struct board_staging_dev *dev) return error; } - if (dev->domain) - board_staging_add_dev_domain(pdev, dev->domain); - return error; } diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 57e71f9f14a2..ac0f01007abd 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -400,14 +400,6 @@ config COMEDI_DMM32AT To compile this driver as a module, choose M here: the module will be called dmm32at. -config COMEDI_UNIOXX5 - tristate "Fastwel UNIOxx-5 analog and digital io board support" - ---help--- - Enable support for Fastwel UNIOxx-5 (analog and digital i/o) boards - - To compile this driver as a module, choose M here: the module will be - called unioxx5. - config COMEDI_FL512 tristate "FL512 ISA card support" ---help--- @@ -418,6 +410,7 @@ config COMEDI_FL512 config COMEDI_AIO_AIO12_8 tristate "I/O Products PC/104 AIO12-8 Analog I/O Board support" + select COMEDI_8254 select COMEDI_8255 ---help--- Enable support for I/O Products PC/104 AIO12-8 Analog I/O Board @@ -1072,6 +1065,7 @@ config COMEDI_NI_PCIMIO config COMEDI_RTD520 tristate "Real Time Devices PCI4520/DM7520 support" + select COMEDI_8254 ---help--- Enable support for Real Time Devices PCI4520/DM7520 diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index 19e7b229d15e..90c28016c6c1 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -245,7 +245,7 @@ void comedi_buf_reset(struct comedi_subdevice *s) async->events = 0; } -static unsigned int comedi_buf_write_n_available(struct comedi_subdevice *s) +static unsigned int comedi_buf_write_n_unalloc(struct comedi_subdevice *s) { struct comedi_async *async = s->async; unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; @@ -253,15 +253,33 @@ static unsigned int comedi_buf_write_n_available(struct comedi_subdevice *s) return free_end - async->buf_write_alloc_count; } -/* allocates chunk for the writer from free buffer space */ +unsigned int comedi_buf_write_n_available(struct comedi_subdevice *s) +{ + struct comedi_async *async = s->async; + unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; + + return free_end - async->buf_write_count; +} + +/** + * comedi_buf_write_alloc() - Reserve buffer space for writing + * @s: COMEDI subdevice. + * @nbytes: Maximum space to reserve in bytes. + * + * Reserve up to @nbytes bytes of space to be written in the COMEDI acquisition + * data buffer associated with the subdevice. The amount reserved is limited + * by the space available. + * + * Return: The amount of space reserved in bytes. + */ unsigned int comedi_buf_write_alloc(struct comedi_subdevice *s, unsigned int nbytes) { struct comedi_async *async = s->async; - unsigned int available = comedi_buf_write_n_available(s); + unsigned int unalloc = comedi_buf_write_n_unalloc(s); - if (nbytes > available) - nbytes = available; + if (nbytes > unalloc) + nbytes = unalloc; async->buf_write_alloc_count += nbytes; @@ -329,7 +347,21 @@ unsigned int comedi_buf_write_n_allocated(struct comedi_subdevice *s) return async->buf_write_alloc_count - async->buf_write_count; } -/* transfers a chunk from writer to filled buffer space */ +/** + * comedi_buf_write_free() - Free buffer space after it is written + * @s: COMEDI subdevice. + * @nbytes: Maximum space to free in bytes. + * + * Free up to @nbytes bytes of space previously reserved for writing in the + * COMEDI acquisition data buffer associated with the subdevice. The amount of + * space freed is limited to the amount that was reserved. The freed space is + * assumed to have been filled with sample data by the writer. + * + * If the samples in the freed space need to be "munged", do so here. The + * freed space becomes available for allocation by the reader. + * + * Return: The amount of space freed in bytes. + */ unsigned int comedi_buf_write_free(struct comedi_subdevice *s, unsigned int nbytes) { @@ -349,6 +381,17 @@ unsigned int comedi_buf_write_free(struct comedi_subdevice *s, } EXPORT_SYMBOL_GPL(comedi_buf_write_free); +/** + * comedi_buf_read_n_available() - Determine amount of readable buffer space + * @s: COMEDI subdevice. + * + * Determine the amount of readable buffer space in the COMEDI acquisition data + * buffer associated with the subdevice. The readable buffer space is that + * which has been freed by the writer and "munged" to the sample data format + * expected by COMEDI if necessary. + * + * Return: The amount of readable buffer space. + */ unsigned int comedi_buf_read_n_available(struct comedi_subdevice *s) { struct comedi_async *async = s->async; @@ -369,7 +412,21 @@ unsigned int comedi_buf_read_n_available(struct comedi_subdevice *s) } EXPORT_SYMBOL_GPL(comedi_buf_read_n_available); -/* allocates a chunk for the reader from filled (and munged) buffer space */ +/** + * comedi_buf_read_alloc() - Reserve buffer space for reading + * @s: COMEDI subdevice. + * @nbytes: Maximum space to reserve in bytes. + * + * Reserve up to @nbytes bytes of previously written and "munged" buffer space + * for reading in the COMEDI acquisition data buffer associated with the + * subdevice. The amount reserved is limited to the space available. The + * reader can read from the reserved space and then free it. A reader is also + * allowed to read from the space before reserving it as long as it determines + * the amount of readable data available, but the space needs to be marked as + * reserved before it can be freed. + * + * Return: The amount of space reserved in bytes. + */ unsigned int comedi_buf_read_alloc(struct comedi_subdevice *s, unsigned int nbytes) { @@ -397,7 +454,19 @@ static unsigned int comedi_buf_read_n_allocated(struct comedi_async *async) return async->buf_read_alloc_count - async->buf_read_count; } -/* transfers control of a chunk from reader to free buffer space */ +/** + * comedi_buf_read_free() - Free buffer space after it has been read + * @s: COMEDI subdevice. + * @nbytes: Maximum space to free in bytes. + * + * Free up to @nbytes bytes of buffer space previously reserved for reading in + * the COMEDI acquisition data buffer associated with the subdevice. The + * amount of space freed is limited to the amount that was reserved. + * + * The freed space becomes available for allocation by the writer. + * + * Return: The amount of space freed in bytes. + */ unsigned int comedi_buf_read_free(struct comedi_subdevice *s, unsigned int nbytes) { @@ -469,15 +538,21 @@ static void comedi_buf_memcpy_from(struct comedi_subdevice *s, } /** - * comedi_buf_write_samples - write sample data to comedi buffer - * @s: comedi_subdevice struct - * @data: samples - * @nsamples: number of samples + * comedi_buf_write_samples() - Write sample data to COMEDI buffer + * @s: COMEDI subdevice. + * @data: Pointer to source samples. + * @nsamples: Number of samples to write. * - * Writes nsamples to the comedi buffer associated with the subdevice, marks - * it as written and updates the acquisition scan progress. + * Write up to @nsamples samples to the COMEDI acquisition data buffer + * associated with the subdevice, mark it as written and update the + * acquisition scan progress. If there is not enough room for the specified + * number of samples, the number of samples written is limited to the number + * that will fit and the %COMEDI_CB_OVERFLOW event flag is set to cause the + * acquisition to terminate with an overrun error. Set the %COMEDI_CB_BLOCK + * event flag if any samples are written to cause waiting tasks to be woken + * when the event flags are processed. * - * Returns the amount of data written in bytes. + * Return: The amount of data written in bytes. */ unsigned int comedi_buf_write_samples(struct comedi_subdevice *s, const void *data, unsigned int nsamples) @@ -490,8 +565,7 @@ unsigned int comedi_buf_write_samples(struct comedi_subdevice *s, * If not, clamp the nsamples to the number that will fit, flag the * buffer overrun and add the samples that fit. */ - max_samples = comedi_bytes_to_samples(s, - comedi_buf_write_n_available(s)); + max_samples = comedi_bytes_to_samples(s, comedi_buf_write_n_unalloc(s)); if (nsamples > max_samples) { dev_warn(s->device->class_dev, "buffer overrun\n"); s->async->events |= COMEDI_CB_OVERFLOW; @@ -513,15 +587,18 @@ unsigned int comedi_buf_write_samples(struct comedi_subdevice *s, EXPORT_SYMBOL_GPL(comedi_buf_write_samples); /** - * comedi_buf_read_samples - read sample data from comedi buffer - * @s: comedi_subdevice struct - * @data: destination - * @nsamples: maximum number of samples to read + * comedi_buf_read_samples() - Read sample data from COMEDI buffer + * @s: COMEDI subdevice. + * @data: Pointer to destination. + * @nsamples: Maximum number of samples to read. * - * Reads up to nsamples from the comedi buffer associated with the subdevice, - * marks it as read and updates the acquisition scan progress. + * Read up to @nsamples samples from the COMEDI acquisition data buffer + * associated with the subdevice, mark it as read and update the acquisition + * scan progress. Limit the number of samples read to the number available. + * Set the %COMEDI_CB_BLOCK event flag if any samples are read to cause waiting + * tasks to be woken when the event flags are processed. * - * Returns the amount of data read in bytes. + * Return: The amount of data read in bytes. */ unsigned int comedi_buf_read_samples(struct comedi_subdevice *s, void *data, unsigned int nsamples) diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 0e8a45102933..7b4af519e17e 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -43,15 +43,15 @@ #include "comedi_internal.h" -/** +/* * comedi_subdevice "runflags" - * @COMEDI_SRF_RT: DEPRECATED: command is running real-time - * @COMEDI_SRF_ERROR: indicates an COMEDI_CB_ERROR event has occurred + * COMEDI_SRF_RT: DEPRECATED: command is running real-time + * COMEDI_SRF_ERROR: indicates an COMEDI_CB_ERROR event has occurred * since the last command was started - * @COMEDI_SRF_RUNNING: command is running - * @COMEDI_SRF_FREE_SPRIV: free s->private on detach + * COMEDI_SRF_RUNNING: command is running + * COMEDI_SRF_FREE_SPRIV: free s->private on detach * - * @COMEDI_SRF_BUSY_MASK: runflags that indicate the subdevice is "busy" + * COMEDI_SRF_BUSY_MASK: runflags that indicate the subdevice is "busy" */ #define COMEDI_SRF_RT BIT(1) #define COMEDI_SRF_ERROR BIT(2) @@ -61,12 +61,12 @@ #define COMEDI_SRF_BUSY_MASK (COMEDI_SRF_ERROR | COMEDI_SRF_RUNNING) /** - * struct comedi_file - per-file private data for comedi device - * @dev: comedi_device struct - * @read_subdev: current "read" subdevice - * @write_subdev: current "write" subdevice - * @last_detach_count: last known detach count - * @last_attached: last known attached/detached state + * struct comedi_file - Per-file private data for COMEDI device + * @dev: COMEDI device. + * @read_subdev: Current "read" subdevice. + * @write_subdev: Current "write" subdevice. + * @last_detach_count: Last known detach count. + * @last_attached: Last known attached/detached state. */ struct comedi_file { struct comedi_device *dev; @@ -131,15 +131,15 @@ static void comedi_dev_kref_release(struct kref *kref) } /** - * comedi_dev_put - release a use of a comedi device structure - * @dev: comedi_device struct + * comedi_dev_put() - Release a use of a COMEDI device + * @dev: COMEDI device. * - * Must be called when a user of a comedi device is finished with it. - * When the last user of the comedi device calls this function, the - * comedi device is destroyed. + * Must be called when a user of a COMEDI device is finished with it. + * When the last user of the COMEDI device calls this function, the + * COMEDI device is destroyed. * - * Return 1 if the comedi device is destroyed by this call or dev is - * NULL, otherwise return 0. Callers must not assume the comedi + * Return: 1 if the COMEDI device is destroyed by this call or @dev is + * NULL, otherwise return 0. Callers must not assume the COMEDI * device is still valid if this function returns 0. */ int comedi_dev_put(struct comedi_device *dev) @@ -247,15 +247,15 @@ static struct comedi_device *comedi_dev_get_from_subdevice_minor(unsigned minor) } /** - * comedi_dev_get_from_minor - get comedi device by minor device number - * @minor: minor device number + * comedi_dev_get_from_minor() - Get COMEDI device by minor device number + * @minor: Minor device number. * - * Finds the comedi device associated by the minor device number, if any, - * and increments its reference count. The comedi device is prevented from + * Finds the COMEDI device associated with the minor device number, if any, + * and increments its reference count. The COMEDI device is prevented from * being freed until a matching call is made to comedi_dev_put(). * - * Return a pointer to the comedi device if it exists, with its usage - * reference incremented. Return NULL if no comedi device exists with the + * Return: A pointer to the COMEDI device if it exists, with its usage + * reference incremented. Return NULL if no COMEDI device exists with the * specified minor device number. */ struct comedi_device *comedi_dev_get_from_minor(unsigned minor) @@ -665,11 +665,11 @@ static bool comedi_is_runflags_in_error(unsigned runflags) } /** - * comedi_is_subdevice_running - check if async command running on subdevice - * @s: comedi_subdevice struct + * comedi_is_subdevice_running() - Check if async command running on subdevice + * @s: COMEDI subdevice. * - * Return true if an asynchronous comedi command is active on the comedi - * subdevice, else return false. + * Return: %true if an asynchronous COMEDI command is active on the + * subdevice, else %false. */ bool comedi_is_subdevice_running(struct comedi_subdevice *s) { @@ -701,11 +701,12 @@ bool comedi_can_auto_free_spriv(struct comedi_subdevice *s) } /** - * comedi_set_spriv_auto_free - mark subdevice private data as freeable - * @s: comedi_subdevice struct + * comedi_set_spriv_auto_free() - Mark subdevice private data as freeable + * @s: COMEDI subdevice. * * Mark the subdevice as having a pointer to private data that can be - * automatically freed by the comedi core during the detach. + * automatically freed when the COMEDI device is detached from the low-level + * driver. */ void comedi_set_spriv_auto_free(struct comedi_subdevice *s) { @@ -714,12 +715,16 @@ void comedi_set_spriv_auto_free(struct comedi_subdevice *s) EXPORT_SYMBOL_GPL(comedi_set_spriv_auto_free); /** - * comedi_alloc_spriv - Allocate memory for the subdevice private data. - * @s: comedi_subdevice struct - * @size: size of the memory to allocate + * comedi_alloc_spriv - Allocate memory for the subdevice private data + * @s: COMEDI subdevice. + * @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. + * Allocate memory for the subdevice private data and point @s->private + * to it. The memory will be freed automatically when the COMEDI device + * is detached from the low-level driver. + * + * Return: A pointer to the allocated memory @s->private on success. + * Return NULL on failure. */ void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size) { @@ -1141,7 +1146,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev, comedi_buf_read_free(s, bi.bytes_read); if (comedi_is_subdevice_idle(s) && - comedi_buf_n_bytes_ready(s) == 0) { + comedi_buf_read_n_available(s) == 0) { do_become_nonbusy(dev, s); } } @@ -1336,7 +1341,7 @@ static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn, goto out; } /* This looks arbitrary. It is. */ - s->busy = &parse_insn; + s->busy = parse_insn; switch (insn->insn) { case INSN_READ: ret = s->insn_read(dev, s, insn, data); @@ -2257,9 +2262,9 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) unsigned int mask = 0; struct comedi_file *cfp = file->private_data; struct comedi_device *dev = cfp->dev; - struct comedi_subdevice *s; + struct comedi_subdevice *s, *s_read; - mutex_lock(&dev->mutex); + down_read(&dev->attach_lock); if (!dev->attached) { dev_dbg(dev->class_dev, "no driver attached\n"); @@ -2267,9 +2272,10 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) } s = comedi_file_read_subdevice(file); + s_read = s; if (s && s->async) { poll_wait(file, &s->async->wait_head, wait); - if (!s->busy || !comedi_is_subdevice_running(s) || + if (s->busy != file || !comedi_is_subdevice_running(s) || (s->async->cmd.flags & CMDF_WRITE) || comedi_buf_read_n_available(s) > 0) mask |= POLLIN | POLLRDNORM; @@ -2279,16 +2285,16 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait) if (s && s->async) { unsigned int bps = comedi_bytes_per_sample(s); - poll_wait(file, &s->async->wait_head, wait); - comedi_buf_write_alloc(s, s->async->prealloc_bufsz); - if (!s->busy || !comedi_is_subdevice_running(s) || + if (s != s_read) + poll_wait(file, &s->async->wait_head, wait); + if (s->busy != file || !comedi_is_subdevice_running(s) || !(s->async->cmd.flags & CMDF_WRITE) || - comedi_buf_write_n_allocated(s) >= bps) + comedi_buf_write_n_available(s) >= bps) mask |= POLLOUT | POLLWRNORM; } done: - mutex_unlock(&dev->mutex); + up_read(&dev->attach_lock); return mask; } @@ -2444,7 +2450,9 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, { struct comedi_subdevice *s; struct comedi_async *async; - int n, m, count = 0, retval = 0; + unsigned int n, m; + ssize_t count = 0; + int retval = 0; DECLARE_WAITQUEUE(wait, current); struct comedi_file *cfp = file->private_data; struct comedi_device *dev = cfp->dev; @@ -2470,28 +2478,19 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, } async = s->async; - if (!s->busy || !nbytes) - goto out; - if (s->busy != file) { - retval = -EACCES; - goto out; - } - if (async->cmd.flags & CMDF_WRITE) { + if (s->busy != file || (async->cmd.flags & CMDF_WRITE)) { retval = -EINVAL; goto out; } add_wait_queue(&async->wait_head, &wait); - while (nbytes > 0 && !retval) { + while (count == 0 && !retval) { + unsigned int rp, n1, n2; + set_current_state(TASK_INTERRUPTIBLE); - n = nbytes; - m = comedi_buf_read_n_available(s); - if (async->buf_read_ptr + m > async->prealloc_bufsz) - m = async->prealloc_bufsz - async->buf_read_ptr; - if (m < n) - n = m; + n = min_t(size_t, m, nbytes); if (n == 0) { unsigned runflags = comedi_get_subdevice_runflags(s); @@ -2499,11 +2498,12 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, if (!comedi_is_runflags_running(runflags)) { if (comedi_is_runflags_in_error(runflags)) retval = -EPIPE; - else - retval = 0; - become_nonbusy = true; + if (retval || nbytes) + become_nonbusy = true; break; } + if (nbytes == 0) + break; if (file->f_flags & O_NONBLOCK) { retval = -EAGAIN; break; @@ -2513,22 +2513,21 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, retval = -ERESTARTSYS; break; } - if (!s->busy) { - retval = 0; - break; - } - if (s->busy != file) { - retval = -EACCES; - break; - } - if (async->cmd.flags & CMDF_WRITE) { + if (s->busy != file || + (async->cmd.flags & CMDF_WRITE)) { retval = -EINVAL; break; } continue; } - m = copy_to_user(buf, async->prealloc_buf + - async->buf_read_ptr, n); + rp = async->buf_read_ptr; + n1 = min(n, async->prealloc_bufsz - rp); + n2 = n - n1; + m = copy_to_user(buf, async->prealloc_buf + rp, n1); + if (m) + m += n2; + else if (n2) + m = copy_to_user(buf + n1, async->prealloc_buf, n2); if (m) { n -= m; retval = -EFAULT; @@ -2541,11 +2540,10 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, nbytes -= n; buf += n; - break; /* makes device work like a pipe */ } remove_wait_queue(&async->wait_head, &wait); set_current_state(TASK_RUNNING); - if (become_nonbusy || comedi_is_subdevice_idle(s)) { + if (become_nonbusy && count == 0) { struct comedi_subdevice *new_s; /* @@ -2561,13 +2559,17 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes, * sufficient (unless there have been 2**32 detaches in the * meantime!), but check the subdevice pointer as well just in * case. + * + * Also check the subdevice is still in a suitable state to + * become non-busy in case it changed behind our back. */ new_s = comedi_file_read_subdevice(file); if (dev->attached && old_detach_count == dev->detach_count && - s == new_s && new_s->async == async) { - if (become_nonbusy || comedi_buf_n_bytes_ready(s) == 0) - do_become_nonbusy(dev, s); - } + s == new_s && new_s->async == async && s->busy == file && + !(async->cmd.flags & CMDF_WRITE) && + !comedi_is_subdevice_running(s) && + comedi_buf_read_n_available(s) == 0) + do_become_nonbusy(dev, s); mutex_unlock(&dev->mutex); } out: @@ -2686,15 +2688,15 @@ static const struct file_operations comedi_fops = { }; /** - * comedi_event - handle events for asynchronous comedi command - * @dev: comedi_device struct - * @s: comedi_subdevice struct associated with dev - * Context: interrupt (usually), s->spin_lock spin-lock not held + * comedi_event() - Handle events for asynchronous COMEDI command + * @dev: COMEDI device. + * @s: COMEDI subdevice. + * Context: in_interrupt() (usually), @s->spin_lock spin-lock not held. * - * If an asynchronous comedi command is active on the subdevice, process - * any COMEDI_CB_... event flags that have been set, usually by an + * If an asynchronous COMEDI command is active on the subdevice, process + * any %COMEDI_CB_... event flags that have been set, usually by an * interrupt handler. These may change the run state of the asynchronous - * command, wake a task, and/or send a SIGIO signal. + * command, wake a task, and/or send a %SIGIO signal. */ void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s) { diff --git a/drivers/staging/comedi/comedi_internal.h b/drivers/staging/comedi/comedi_internal.h index cd9437f72c35..3f2c88ae6470 100644 --- a/drivers/staging/comedi/comedi_internal.h +++ b/drivers/staging/comedi/comedi_internal.h @@ -31,6 +31,7 @@ void comedi_buf_map_get(struct comedi_buf_map *bm); int comedi_buf_map_put(struct comedi_buf_map *bm); struct comedi_buf_map *comedi_buf_map_from_subdev_get( struct comedi_subdevice *s); +unsigned int comedi_buf_write_n_available(struct comedi_subdevice *s); unsigned int comedi_buf_write_n_allocated(struct comedi_subdevice *s); void comedi_device_cancel_all(struct comedi_device *dev); bool comedi_can_auto_free_spriv(struct comedi_subdevice *s); diff --git a/drivers/staging/comedi/comedi_pci.c b/drivers/staging/comedi/comedi_pci.c index 027f0f4e59c1..51e023a1c0ee 100644 --- a/drivers/staging/comedi/comedi_pci.c +++ b/drivers/staging/comedi/comedi_pci.c @@ -22,8 +22,14 @@ #include "comedi_pci.h" /** - * comedi_to_pci_dev() - comedi_device pointer to pci_dev pointer. - * @dev: comedi_device struct + * comedi_to_pci_dev() - Return PCI device attached to COMEDI device + * @dev: COMEDI device. + * + * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a + * a &struct device embedded in a &struct pci_dev. + * + * Return: Attached PCI device if @dev->hw_dev is non-%NULL. + * Return %NULL if @dev->hw_dev is %NULL. */ struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) { @@ -32,8 +38,22 @@ struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) EXPORT_SYMBOL_GPL(comedi_to_pci_dev); /** - * comedi_pci_enable() - Enable the PCI device and request the regions. - * @dev: comedi_device struct + * comedi_pci_enable() - Enable the PCI device and request the regions + * @dev: COMEDI device. + * + * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a + * a &struct device embedded in a &struct pci_dev. Enable the PCI device + * and request its regions. Set @dev->ioenabled to %true if successful, + * otherwise undo what was done. + * + * Calls to comedi_pci_enable() and comedi_pci_disable() cannot be nested. + * + * Return: + * 0 on success, + * -%ENODEV if @dev->hw_dev is %NULL, + * -%EBUSY if regions busy, + * or some negative error number if failed to enable PCI device. + * */ int comedi_pci_enable(struct comedi_device *dev) { @@ -58,8 +78,13 @@ int comedi_pci_enable(struct comedi_device *dev) EXPORT_SYMBOL_GPL(comedi_pci_enable); /** - * comedi_pci_disable() - Release the regions and disable the PCI device. - * @dev: comedi_device struct + * comedi_pci_disable() - Release the regions and disable the PCI device + * @dev: COMEDI device. + * + * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a + * a &struct device embedded in a &struct pci_dev. If the earlier call + * to comedi_pci_enable() was successful, release the PCI device's regions + * and disable it. Reset @dev->ioenabled back to %false. */ void comedi_pci_disable(struct comedi_device *dev) { @@ -74,8 +99,18 @@ void comedi_pci_disable(struct comedi_device *dev) EXPORT_SYMBOL_GPL(comedi_pci_disable); /** - * comedi_pci_detach() - A generic (*detach) function for PCI drivers. - * @dev: comedi_device struct + * comedi_pci_detach() - A generic "detach" handler for PCI COMEDI drivers + * @dev: COMEDI device. + * + * COMEDI drivers for PCI devices that need no special clean-up of private data + * and have no ioremapped regions other than that pointed to by @dev->mmio may + * use this function as its "detach" handler called by the COMEDI core when a + * COMEDI device is being detached from the low-level driver. It may be also + * called from a more specific "detach" handler that does additional clean-up. + * + * Free the IRQ if @dev->irq is non-zero, iounmap @dev->mmio if it is + * non-%NULL, and call comedi_pci_disable() to release the PCI device's regions + * and disable it. */ void comedi_pci_detach(struct comedi_device *dev) { @@ -97,12 +132,19 @@ void comedi_pci_detach(struct comedi_device *dev) EXPORT_SYMBOL_GPL(comedi_pci_detach); /** - * comedi_pci_auto_config() - Configure/probe a comedi PCI driver. - * @pcidev: pci_dev struct - * @driver: comedi_driver struct - * @context: driver specific data, passed to comedi_auto_config() + * comedi_pci_auto_config() - Configure/probe a PCI COMEDI device + * @pcidev: PCI device. + * @driver: Registered COMEDI driver. + * @context: Driver specific data, passed to comedi_auto_config(). * - * Typically called from the pci_driver (*probe) function. + * Typically called from the pci_driver (*probe) function. Auto-configure + * a COMEDI device, using the &struct device embedded in *@pcidev as the + * hardware device. The @context value gets passed through to @driver's + * "auto_attach" handler. The "auto_attach" handler may call + * comedi_to_pci_dev() on the passed in COMEDI device to recover @pcidev. + * + * Return: The result of calling comedi_auto_config() (0 on success, or + * a negative error number on failure). */ int comedi_pci_auto_config(struct pci_dev *pcidev, struct comedi_driver *driver, @@ -113,10 +155,18 @@ int comedi_pci_auto_config(struct pci_dev *pcidev, EXPORT_SYMBOL_GPL(comedi_pci_auto_config); /** - * comedi_pci_auto_unconfig() - Unconfigure/remove a comedi PCI driver. - * @pcidev: pci_dev struct + * comedi_pci_auto_unconfig() - Unconfigure/remove a PCI COMEDI device + * @pcidev: PCI device. * - * Typically called from the pci_driver (*remove) function. + * Typically called from the pci_driver (*remove) function. Auto-unconfigure + * a COMEDI device attached to this PCI device, using a pointer to the + * &struct device embedded in *@pcidev as the hardware device. The COMEDI + * driver's "detach" handler will be called during unconfiguration of the + * COMEDI device. + * + * Note that the COMEDI device may have already been unconfigured using the + * %COMEDI_DEVCONFIG ioctl, in which case this attempt to unconfigure it + * again should be ignored. */ void comedi_pci_auto_unconfig(struct pci_dev *pcidev) { @@ -125,13 +175,15 @@ void comedi_pci_auto_unconfig(struct pci_dev *pcidev) EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig); /** - * comedi_pci_driver_register() - Register a comedi PCI driver. - * @comedi_driver: comedi_driver struct - * @pci_driver: pci_driver struct + * comedi_pci_driver_register() - Register a PCI COMEDI driver + * @comedi_driver: COMEDI driver to be registered. + * @pci_driver: PCI driver to be registered. * - * This function is used for the module_init() of comedi PCI drivers. - * Do not call it directly, use the module_comedi_pci_driver() helper - * macro instead. + * This function is called from the module_init() of PCI COMEDI driver modules + * to register the COMEDI driver and the PCI driver. Do not call it directly, + * use the module_comedi_pci_driver() helper macro instead. + * + * Return: 0 on success, or a negative error number on failure. */ int comedi_pci_driver_register(struct comedi_driver *comedi_driver, struct pci_driver *pci_driver) @@ -153,13 +205,13 @@ int comedi_pci_driver_register(struct comedi_driver *comedi_driver, EXPORT_SYMBOL_GPL(comedi_pci_driver_register); /** - * comedi_pci_driver_unregister() - Unregister a comedi PCI driver. - * @comedi_driver: comedi_driver struct - * @pci_driver: pci_driver struct + * comedi_pci_driver_unregister() - Unregister a PCI COMEDI driver + * @comedi_driver: COMEDI driver to be unregistered. + * @pci_driver: PCI driver to be unregistered. * - * This function is used for the module_exit() of comedi PCI drivers. - * Do not call it directly, use the module_comedi_pci_driver() helper - * macro instead. + * This function is called from the module_exit() of PCI COMEDI driver modules + * to unregister the PCI driver and the COMEDI driver. Do not call it + * directly, use the module_comedi_pci_driver() helper macro instead. */ void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver, struct pci_driver *pci_driver) diff --git a/drivers/staging/comedi/comedi_pcmcia.c b/drivers/staging/comedi/comedi_pcmcia.c index 7e784399a16f..d7072a5c1647 100644 --- a/drivers/staging/comedi/comedi_pcmcia.c +++ b/drivers/staging/comedi/comedi_pcmcia.c @@ -22,8 +22,14 @@ #include "comedi_pcmcia.h" /** - * comedi_to_pcmcia_dev() - comedi_device pointer to pcmcia_device pointer. - * @dev: comedi_device struct + * comedi_to_pcmcia_dev() - Return PCMCIA device attached to COMEDI device + * @dev: COMEDI device. + * + * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a + * a &struct device embedded in a &struct pcmcia_device. + * + * Return: Attached PCMCIA device if @dev->hw_dev is non-%NULL. + * Return %NULL if @dev->hw_dev is %NULL. */ struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *dev) { @@ -41,13 +47,35 @@ static int comedi_pcmcia_conf_check(struct pcmcia_device *link, } /** - * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device. - * @dev: comedi_device struct - * @conf_check: optional callback to check the pcmcia_device configuration + * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device + * @dev: COMEDI device. + * @conf_check: Optional callback to check each configuration option of the + * PCMCIA device and request I/O regions. * - * The comedi PCMCIA driver needs to set the link->config_flags, as - * appropriate for that driver, before calling this function in order - * to allow pcmcia_loop_config() to do its internal autoconfiguration. + * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a a + * &struct device embedded in a &struct pcmcia_device. The comedi PCMCIA + * driver needs to set the 'config_flags' member in the &struct pcmcia_device, + * as appropriate for that driver, before calling this function in order to + * allow pcmcia_loop_config() to do its internal autoconfiguration. + * + * If @conf_check is %NULL it is set to a default function. If is + * passed to pcmcia_loop_config() and should return %0 if the configuration + * is valid and I/O regions requested successfully, otherwise it should return + * a negative error value. The default function returns -%EINVAL if the + * 'config_index' member is %0, otherwise it calls pcmcia_request_io() and + * returns the result. + * + * If the above configuration check passes, pcmcia_enable_device() is called + * to set up and activate the PCMCIA device. + * + * If this function returns an error, comedi_pcmcia_disable() should be called + * to release requested resources. + * + * Return: + * 0 on success, + * -%ENODEV id @dev->hw_dev is %NULL, + * a negative error number from pcmcia_loop_config() if it fails, + * or a negative error number from pcmcia_enable_device() if it fails. */ int comedi_pcmcia_enable(struct comedi_device *dev, int (*conf_check)(struct pcmcia_device *, void *)) @@ -70,8 +98,12 @@ int comedi_pcmcia_enable(struct comedi_device *dev, EXPORT_SYMBOL_GPL(comedi_pcmcia_enable); /** - * comedi_pcmcia_disable() - Disable the PCMCIA device and release the regions. - * @dev: comedi_device struct + * comedi_pcmcia_disable() - Disable the PCMCIA device and release the regions + * @dev: COMEDI device. + * + * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a + * a &struct device embedded in a &struct pcmcia_device. Call + * pcmcia_disable_device() to disable and clean up the PCMCIA device. */ void comedi_pcmcia_disable(struct comedi_device *dev) { @@ -83,11 +115,17 @@ void comedi_pcmcia_disable(struct comedi_device *dev) EXPORT_SYMBOL_GPL(comedi_pcmcia_disable); /** - * comedi_pcmcia_auto_config() - Configure/probe a comedi PCMCIA driver. - * @link: pcmcia_device struct - * @driver: comedi_driver struct + * comedi_pcmcia_auto_config() - Configure/probe a PCMCIA COMEDI device + * @link: PCMCIA device. + * @driver: Registered COMEDI driver. * - * Typically called from the pcmcia_driver (*probe) function. + * Typically called from the pcmcia_driver (*probe) function. Auto-configure + * a COMEDI device, using a pointer to the &struct device embedded in *@link + * as the hardware device. The @driver's "auto_attach" handler may call + * comedi_to_pcmcia_dev() on the passed in COMEDI device to recover @link. + * + * Return: The result of calling comedi_auto_config() (0 on success, or a + * negative error number on failure). */ int comedi_pcmcia_auto_config(struct pcmcia_device *link, struct comedi_driver *driver) @@ -97,10 +135,18 @@ int comedi_pcmcia_auto_config(struct pcmcia_device *link, EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_config); /** - * comedi_pcmcia_auto_unconfig() - Unconfigure/remove a comedi PCMCIA driver. - * @link: pcmcia_device struct + * comedi_pcmcia_auto_unconfig() - Unconfigure/remove a PCMCIA COMEDI device + * @link: PCMCIA device. * * Typically called from the pcmcia_driver (*remove) function. + * Auto-unconfigure a COMEDI device attached to this PCMCIA device, using a + * pointer to the &struct device embedded in *@link as the hardware device. + * The COMEDI driver's "detach" handler will be called during unconfiguration + * of the COMEDI device. + * + * Note that the COMEDI device may have already been unconfigured using the + * %COMEDI_DEVCONFIG ioctl, in which case this attempt to unconfigure it + * again should be ignored. */ void comedi_pcmcia_auto_unconfig(struct pcmcia_device *link) { @@ -109,13 +155,15 @@ void comedi_pcmcia_auto_unconfig(struct pcmcia_device *link) EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_unconfig); /** - * comedi_pcmcia_driver_register() - Register a comedi PCMCIA driver. - * @comedi_driver: comedi_driver struct - * @pcmcia_driver: pcmcia_driver struct + * comedi_pcmcia_driver_register() - Register a PCMCIA COMEDI driver + * @comedi_driver: COMEDI driver to be registered. + * @pcmcia_driver: PCMCIA driver to be registered. * - * This function is used for the module_init() of comedi USB drivers. - * Do not call it directly, use the module_comedi_pcmcia_driver() helper - * macro instead. + * This function is used for the module_init() of PCMCIA COMEDI driver modules + * to register the COMEDI driver and the PCMCIA driver. Do not call it + * directly, use the module_comedi_pcmcia_driver() helper macro instead. + * + * Return: 0 on success, or a negative error number on failure. */ int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver, struct pcmcia_driver *pcmcia_driver) @@ -137,13 +185,13 @@ int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver, EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register); /** - * comedi_pcmcia_driver_unregister() - Unregister a comedi PCMCIA driver. - * @comedi_driver: comedi_driver struct - * @pcmcia_driver: pcmcia_driver struct + * comedi_pcmcia_driver_unregister() - Unregister a PCMCIA COMEDI driver + * @comedi_driver: COMEDI driver to be registered. + * @pcmcia_driver: PCMCIA driver to be registered. * - * This function is used for the module_exit() of comedi PCMCIA drivers. - * Do not call it directly, use the module_comedi_pcmcia_driver() helper - * macro instead. + * This function is called from the module_exit() of PCMCIA COMEDI driver + * modules to unregister the PCMCIA driver and the COMEDI driver. Do not call + * it directly, use the module_comedi_pcmcia_driver() helper macro instead. */ void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver, struct pcmcia_driver *pcmcia_driver) diff --git a/drivers/staging/comedi/comedi_usb.c b/drivers/staging/comedi/comedi_usb.c index 68b75e8feec0..9c946d40b894 100644 --- a/drivers/staging/comedi/comedi_usb.c +++ b/drivers/staging/comedi/comedi_usb.c @@ -21,8 +21,14 @@ #include "comedi_usb.h" /** - * comedi_to_usb_interface() - comedi_device pointer to usb_interface pointer. - * @dev: comedi_device struct + * comedi_to_usb_interface() - Return USB interface attached to COMEDI device + * @dev: COMEDI device. + * + * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a + * a &struct device embedded in a &struct usb_interface. + * + * Return: Attached USB interface if @dev->hw_dev is non-%NULL. + * Return %NULL if @dev->hw_dev is %NULL. */ struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev) { @@ -31,8 +37,14 @@ 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 + * comedi_to_usb_dev() - Return USB device attached to COMEDI device + * @dev: COMEDI device. + * + * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a + * a &struct device embedded in a &struct usb_interface. + * + * Return: USB device to which the USB interface belongs if @dev->hw_dev is + * non-%NULL. Return %NULL if @dev->hw_dev is %NULL. */ struct usb_device *comedi_to_usb_dev(struct comedi_device *dev) { @@ -43,12 +55,19 @@ struct usb_device *comedi_to_usb_dev(struct comedi_device *dev) EXPORT_SYMBOL_GPL(comedi_to_usb_dev); /** - * comedi_usb_auto_config() - Configure/probe a comedi USB driver. - * @intf: usb_interface struct - * @driver: comedi_driver struct - * @context: driver specific data, passed to comedi_auto_config() + * comedi_usb_auto_config() - Configure/probe a USB COMEDI driver + * @intf: USB interface. + * @driver: Registered COMEDI driver. + * @context: Driver specific data, passed to comedi_auto_config(). * - * Typically called from the usb_driver (*probe) function. + * Typically called from the usb_driver (*probe) function. Auto-configure a + * COMEDI device, using a pointer to the &struct device embedded in *@intf as + * the hardware device. The @context value gets passed through to @driver's + * "auto_attach" handler. The "auto_attach" handler may call + * comedi_to_usb_interface() on the passed in COMEDI device to recover @intf. + * + * Return: The result of calling comedi_auto_config() (%0 on success, or + * a negative error number on failure). */ int comedi_usb_auto_config(struct usb_interface *intf, struct comedi_driver *driver, @@ -59,10 +78,18 @@ int comedi_usb_auto_config(struct usb_interface *intf, EXPORT_SYMBOL_GPL(comedi_usb_auto_config); /** - * comedi_pci_auto_unconfig() - Unconfigure/disconnect a comedi USB driver. - * @intf: usb_interface struct + * comedi_usb_auto_unconfig() - Unconfigure/disconnect a USB COMEDI device + * @intf: USB interface. * * Typically called from the usb_driver (*disconnect) function. + * Auto-unconfigure a COMEDI device attached to this USB interface, using a + * pointer to the &struct device embedded in *@intf as the hardware device. + * The COMEDI driver's "detach" handler will be called during unconfiguration + * of the COMEDI device. + * + * Note that the COMEDI device may have already been unconfigured using the + * %COMEDI_DEVCONFIG ioctl, in which case this attempt to unconfigure it + * again should be ignored. */ void comedi_usb_auto_unconfig(struct usb_interface *intf) { @@ -71,13 +98,15 @@ void comedi_usb_auto_unconfig(struct usb_interface *intf) EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig); /** - * comedi_usb_driver_register() - Register a comedi USB driver. - * @comedi_driver: comedi_driver struct - * @usb_driver: usb_driver struct + * comedi_usb_driver_register() - Register a USB COMEDI driver + * @comedi_driver: COMEDI driver to be registered. + * @usb_driver: USB driver to be registered. * - * This function is used for the module_init() of comedi USB drivers. - * Do not call it directly, use the module_comedi_usb_driver() helper - * macro instead. + * This function is called from the module_init() of USB COMEDI driver modules + * to register the COMEDI driver and the USB driver. Do not call it directly, + * use the module_comedi_usb_driver() helper macro instead. + * + * Return: %0 on success, or a negative error number on failure. */ int comedi_usb_driver_register(struct comedi_driver *comedi_driver, struct usb_driver *usb_driver) @@ -99,13 +128,13 @@ int comedi_usb_driver_register(struct comedi_driver *comedi_driver, EXPORT_SYMBOL_GPL(comedi_usb_driver_register); /** - * comedi_usb_driver_unregister() - Unregister a comedi USB driver. - * @comedi_driver: comedi_driver struct - * @usb_driver: usb_driver struct + * comedi_usb_driver_unregister() - Unregister a USB COMEDI driver + * @comedi_driver: COMEDI driver to be registered. + * @usb_driver: USB driver to be registered. * - * This function is used for the module_exit() of comedi USB drivers. - * Do not call it directly, use the module_comedi_usb_driver() helper - * macro instead. + * This function is called from the module_exit() of USB COMEDI driver modules + * to unregister the USB driver and the COMEDI driver. Do not call it + * directly, use the module_comedi_usb_driver() helper macro instead. */ void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver, struct usb_driver *usb_driver) diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 28a5d3a037a1..115807215484 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -1,20 +1,20 @@ /* - include/linux/comedidev.h - header file for kernel-only structures, variables, and constants - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 1997-2000 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. -*/ + * comedidev.h + * header file for kernel-only structures, variables, and constants + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1997-2000 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. + */ #ifndef _COMEDIDEV_H #define _COMEDIDEV_H @@ -34,6 +34,131 @@ #define COMEDI_NUM_BOARD_MINORS 0x30 +/** + * struct comedi_subdevice - Working data for a COMEDI subdevice + * @device: COMEDI device to which this subdevice belongs. (Initialized by + * comedi_alloc_subdevices().) + * @index: Index of this subdevice within device's array of subdevices. + * (Initialized by comedi_alloc_subdevices().) + * @type: Type of subdevice from &enum comedi_subdevice_type. (Initialized by + * the low-level driver.) + * @n_chan: Number of channels the subdevice supports. (Initialized by the + * low-level driver.) + * @subdev_flags: Various "SDF" flags indicating aspects of the subdevice to + * the COMEDI core and user application. (Initialized by the low-level + * driver.) + * @len_chanlist: Maximum length of a channel list if the subdevice supports + * asynchronous acquisition commands. (Optionally initialized by the + * low-level driver, or changed from 0 to 1 during post-configuration.) + * @private: Private data pointer which is either set by the low-level driver + * itself, or by a call to comedi_alloc_spriv() which allocates storage. + * In the latter case, the storage is automatically freed after the + * low-level driver's "detach" handler is called for the device. + * (Initialized by the low-level driver.) + * @async: Pointer to &struct comedi_async id the subdevice supports + * asynchronous acquisition commands. (Allocated and initialized during + * post-configuration if needed.) + * @lock: Pointer to a file object that performed a %COMEDI_LOCK ioctl on the + * subdevice. (Initially NULL.) + * @busy: Pointer to a file object that is performing an asynchronous + * acquisition command on the subdevice. (Initially NULL.) + * @runflags: Internal flags for use by COMEDI core, mostly indicating whether + * an asynchronous acquisition command is running. + * @spin_lock: Generic spin-lock for use by the COMEDI core and the low-level + * driver. (Initialized by comedi_alloc_subdevices().) + * @io_bits: Bit-mask indicating the channel directions for a DIO subdevice + * with no more than 32 channels. A '1' at a bit position indicates the + * corresponding channel is configured as an output. (Initialized by the + * low-level driver for a DIO subdevice. Forced to all-outputs during + * post-configuration for a digital output subdevice.) + * @maxdata: If non-zero, this is the maximum raw data value of each channel. + * If zero, the maximum data value is channel-specific. (Initialized by + * the low-level driver.) + * @maxdata_list: If the maximum data value is channel-specific, this points + * to an array of maximum data values indexed by channel index. + * (Initialized by the low-level driver.) + * @range_table: If non-NULL, this points to a COMEDI range table for the + * subdevice. If NULL, the range table is channel-specific. (Initialized + * by the low-level driver, will be set to an "invalid" range table during + * post-configuration if @range_table and @range_table_list are both + * NULL.) + * @range_table_list: If the COMEDI range table is channel-specific, this + * points to an array of pointers to COMEDI range tables indexed by + * channel number. (Initialized by the low-level driver.) + * @chanlist: Not used. + * @insn_read: Optional pointer to a handler for the %INSN_READ instruction. + * (Initialized by the low-level driver, or set to a default handler + * during post-configuration.) + * @insn_write: Optional pointer to a handler for the %INSN_WRITE instruction. + * (Initialized by the low-level driver, or set to a default handler + * during post-configuration.) + * @insn_bits: Optional pointer to a handler for the %INSN_BITS instruction + * for a digital input, digital output or digital input/output subdevice. + * (Initialized by the low-level driver, or set to a default handler + * during post-configuration.) + * @insn_config: Optional pointer to a handler for the %INSN_CONFIG + * instruction. (Initialized by the low-level driver, or set to a default + * handler during post-configuration.) + * @do_cmd: If the subdevice supports asynchronous acquisition commands, this + * points to a handler to set it up in hardware. (Initialized by the + * low-level driver.) + * @do_cmdtest: If the subdevice supports asynchronous acquisition commands, + * this points to a handler used to check and possibly tweak a prospective + * acquisition command without setting it up in hardware. (Initialized by + * the low-level driver.) + * @poll: If the subdevice supports asynchronous acquisition commands, this + * is an optional pointer to a handler for the %COMEDI_POLL ioctl which + * instructs the low-level driver to synchronize buffers. (Initialized by + * the low-level driver if needed.) + * @cancel: If the subdevice supports asynchronous acquisition commands, this + * points to a handler used to terminate a running command. (Initialized + * by the low-level driver.) + * @buf_change: If the subdevice supports asynchronous acquisition commands, + * this is an optional pointer to a handler that is called when the data + * buffer for handling asynchronous commands is allocated or reallocated. + * (Initialized by the low-level driver if needed.) + * @munge: If the subdevice supports asynchronous acquisition commands and + * uses DMA to transfer data from the hardware to the acquisition buffer, + * this points to a function used to "munge" the data values from the + * hardware into the format expected by COMEDI. (Initialized by the + * low-level driver if needed.) + * @async_dma_dir: If the subdevice supports asynchronous acquisition commands + * and uses DMA to transfer data from the hardware to the acquisition + * buffer, this sets the DMA direction for the buffer. (initialized to + * %DMA_NONE by comedi_alloc_subdevices() and changed by the low-level + * driver if necessary.) + * @state: Handy bit-mask indicating the output states for a DIO or digital + * output subdevice with no more than 32 channels. (Initialized by the + * low-level driver.) + * @class_dev: If the subdevice supports asynchronous acquisition commands, + * this points to a sysfs comediX_subdY device where X is the minor device + * number of the COMEDI device and Y is the subdevice number. The minor + * device number for the sysfs device is allocated dynamically in the + * range 48 to 255. This is used to allow the COMEDI device to be opened + * with a different default read or write subdevice. (Allocated during + * post-configuration if needed.) + * @minor: If @class_dev is set, this is its dynamically allocated minor + * device number. (Set during post-configuration if necessary.) + * @readback: Optional pointer to memory allocated by + * comedi_alloc_subdev_readback() used to hold the values written to + * analog output channels so they can be read back. The storage is + * automatically freed after the low-level driver's "detach" handler is + * called for the device. (Initialized by the low-level driver.) + * + * This is the main control structure for a COMEDI subdevice. If the subdevice + * supports asynchronous acquisition commands, additional information is stored + * in the &struct comedi_async pointed to by @async. + * + * Most of the subdevice is initialized by the low-level driver's "attach" or + * "auto_attach" handlers but parts of it are initialized by + * comedi_alloc_subdevices(), and other parts are initialized during + * post-configuration on return from that handler. + * + * A low-level driver that sets @insn_bits for a digital input, digital output, + * or DIO subdevice may leave @insn_read and @insn_write uninitialized, in + * which case they will be set to a default handler during post-configuration + * that uses @insn_bits to emulate the %INSN_READ and %INSN_WRITE instructions. + */ struct comedi_subdevice { struct comedi_device *device; int index; @@ -49,7 +174,7 @@ struct comedi_subdevice { void *lock; void *busy; unsigned runflags; - spinlock_t spin_lock; + spinlock_t spin_lock; /* generic spin-lock for COMEDI and drivers */ unsigned int io_bits; @@ -92,11 +217,40 @@ struct comedi_subdevice { unsigned int *readback; }; +/** + * struct comedi_buf_page - Describe a page of a COMEDI buffer + * @virt_addr: Kernel address of page. + * @dma_addr: DMA address of page if in DMA coherent memory. + */ struct comedi_buf_page { void *virt_addr; dma_addr_t dma_addr; }; +/** + * struct comedi_buf_map - Describe pages in a COMEDI buffer + * @dma_hw_dev: Low-level hardware &struct device pointer copied from the + * COMEDI device's hw_dev member. + * @page_list: Pointer to array of &struct comedi_buf_page, one for each + * page in the buffer. + * @n_pages: Number of pages in the buffer. + * @dma_dir: DMA direction used to allocate pages of DMA coherent memory, + * or %DMA_NONE if pages allocated from regular memory. + * @refcount: &struct kref reference counter used to free the buffer. + * + * A COMEDI data buffer is allocated as individual pages, either in + * conventional memory or DMA coherent memory, depending on the attached, + * low-level hardware device. (The buffer pages also get mapped into the + * kernel's contiguous virtual address space pointed to by the 'prealloc_buf' + * member of &struct comedi_async.) + * + * The buffer is normally freed when the COMEDI device is detached from the + * low-level driver (which may happen due to device removal), but if it happens + * to be mmapped at the time, the pages cannot be freed until the buffer has + * been munmapped. That is what the reference counter is for. (The virtual + * address space pointed by 'prealloc_buf' is freed when the COMEDI device is + * detached.) + */ struct comedi_buf_map { struct device *dma_hw_dev; struct comedi_buf_page *page_list; @@ -106,61 +260,66 @@ struct comedi_buf_map { }; /** - * struct comedi_async - control data for asynchronous comedi commands - * @prealloc_buf: preallocated buffer - * @prealloc_bufsz: buffer size (in bytes) - * @buf_map: map of buffer pages - * @max_bufsize: maximum buffer size (in bytes) - * @buf_write_count: "write completed" count (in bytes, modulo 2**32) - * @buf_write_alloc_count: "allocated for writing" count (in bytes, - * modulo 2**32) - * @buf_read_count: "read completed" count (in bytes, modulo 2**32) - * @buf_read_alloc_count: "allocated for reading" count (in bytes, - * modulo 2**32) - * @buf_write_ptr: buffer position for writer - * @buf_read_ptr: buffer position for reader - * @cur_chan: current position in chanlist for scan (for those - * drivers that use it) - * @scans_done: the number of scans completed (COMEDI_CB_EOS) - * @scan_progress: amount received or sent for current scan (in bytes) - * @munge_chan: current position in chanlist for "munging" - * @munge_count: "munge" count (in bytes, modulo 2**32) - * @munge_ptr: buffer position for "munging" - * @events: bit-vector of events that have occurred - * @cmd: details of comedi command in progress - * @wait_head: task wait queue for file reader or writer - * @cb_mask: bit-vector of events that should wake waiting tasks - * @inttrig: software trigger function for command, or NULL + * struct comedi_async - Control data for asynchronous COMEDI commands + * @prealloc_buf: Kernel virtual address of allocated acquisition buffer. + * @prealloc_bufsz: Buffer size (in bytes). + * @buf_map: Map of buffer pages. + * @max_bufsize: Maximum allowed buffer size (in bytes). + * @buf_write_count: "Write completed" count (in bytes, modulo 2**32). + * @buf_write_alloc_count: "Allocated for writing" count (in bytes, + * modulo 2**32). + * @buf_read_count: "Read completed" count (in bytes, modulo 2**32). + * @buf_read_alloc_count: "Allocated for reading" count (in bytes, + * modulo 2**32). + * @buf_write_ptr: Buffer position for writer. + * @buf_read_ptr: Buffer position for reader. + * @cur_chan: Current position in chanlist for scan (for those drivers that + * use it). + * @scans_done: The number of scans completed. + * @scan_progress: Amount received or sent for current scan (in bytes). + * @munge_chan: Current position in chanlist for "munging". + * @munge_count: "Munge" count (in bytes, modulo 2**32). + * @munge_ptr: Buffer position for "munging". + * @events: Bit-vector of events that have occurred. + * @cmd: Details of comedi command in progress. + * @wait_head: Task wait queue for file reader or writer. + * @cb_mask: Bit-vector of events that should wake waiting tasks. + * @inttrig: Software trigger function for command, or NULL. * * Note about the ..._count and ..._ptr members: * * Think of the _Count values being integers of unlimited size, indexing * into a buffer of infinite length (though only an advancing portion - * of the buffer of fixed length prealloc_bufsz is accessible at any time). - * Then: + * of the buffer of fixed length prealloc_bufsz is accessible at any + * time). Then: * * Buf_Read_Count <= Buf_Read_Alloc_Count <= Munge_Count <= * Buf_Write_Count <= Buf_Write_Alloc_Count <= * (Buf_Read_Count + prealloc_bufsz) * - * (Those aren't the actual members, apart from prealloc_bufsz.) When - * the buffer is reset, those _Count values start at 0 and only increase - * in value, maintaining the above inequalities until the next time the - * buffer is reset. The buffer is divided into the following regions by - * the inequalities: + * (Those aren't the actual members, apart from prealloc_bufsz.) When the + * buffer is reset, those _Count values start at 0 and only increase in value, + * maintaining the above inequalities until the next time the buffer is + * reset. The buffer is divided into the following regions by the inequalities: * * [0, Buf_Read_Count): * old region no longer accessible + * * [Buf_Read_Count, Buf_Read_Alloc_Count): * filled and munged region allocated for reading but not yet read + * * [Buf_Read_Alloc_Count, Munge_Count): * filled and munged region not yet allocated for reading + * * [Munge_Count, Buf_Write_Count): * filled region not yet munged + * * [Buf_Write_Count, Buf_Write_Alloc_Count): * unfilled region allocated for writing but not yet written + * * [Buf_Write_Alloc_Count, Buf_Read_Count + prealloc_bufsz): * unfilled region not yet allocated for writing + * * [Buf_Read_Count + prealloc_bufsz, infinity): * unfilled region not yet accessible * @@ -216,43 +375,153 @@ struct comedi_async { }; /** - * comedi_async callback "events" + * enum comedi_cb - &struct comedi_async callback "events" * @COMEDI_CB_EOS: end-of-scan * @COMEDI_CB_EOA: end-of-acquisition/output * @COMEDI_CB_BLOCK: data has arrived, wakes up read() / write() * @COMEDI_CB_EOBUF: DEPRECATED: end of buffer * @COMEDI_CB_ERROR: card error during acquisition * @COMEDI_CB_OVERFLOW: buffer overflow/underflow - * * @COMEDI_CB_ERROR_MASK: events that indicate an error has occurred * @COMEDI_CB_CANCEL_MASK: events that will cancel an async command */ -#define COMEDI_CB_EOS BIT(0) -#define COMEDI_CB_EOA BIT(1) -#define COMEDI_CB_BLOCK BIT(2) -#define COMEDI_CB_EOBUF BIT(3) -#define COMEDI_CB_ERROR BIT(4) -#define COMEDI_CB_OVERFLOW BIT(5) - -#define COMEDI_CB_ERROR_MASK (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW) -#define COMEDI_CB_CANCEL_MASK (COMEDI_CB_EOA | COMEDI_CB_ERROR_MASK) +enum comedi_cb { + COMEDI_CB_EOS = BIT(0), + COMEDI_CB_EOA = BIT(1), + COMEDI_CB_BLOCK = BIT(2), + COMEDI_CB_EOBUF = BIT(3), + COMEDI_CB_ERROR = BIT(4), + COMEDI_CB_OVERFLOW = BIT(5), + /* masks */ + COMEDI_CB_ERROR_MASK = (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW), + COMEDI_CB_CANCEL_MASK = (COMEDI_CB_EOA | COMEDI_CB_ERROR_MASK) +}; +/** + * struct comedi_driver - COMEDI driver registration + * @driver_name: Name of driver. + * @module: Owning module. + * @attach: The optional "attach" handler for manually configured COMEDI + * devices. + * @detach: The "detach" handler for deconfiguring COMEDI devices. + * @auto_attach: The optional "auto_attach" handler for automatically + * configured COMEDI devices. + * @num_names: Optional number of "board names" supported. + * @board_name: Optional pointer to a pointer to a board name. The pointer + * to a board name is embedded in an element of a driver-defined array + * of static, read-only board type information. + * @offset: Optional size of each element of the driver-defined array of + * static, read-only board type information, i.e. the offset between each + * pointer to a board name. + * + * This is used with comedi_driver_register() and comedi_driver_unregister() to + * register and unregister a low-level COMEDI driver with the COMEDI core. + * + * If @num_names is non-zero, @board_name should be non-NULL, and @offset + * should be at least sizeof(*board_name). These are used by the handler for + * the %COMEDI_DEVCONFIG ioctl to match a hardware device and its driver by + * board name. If @num_names is zero, the %COMEDI_DEVCONFIG ioctl matches a + * hardware device and its driver by driver name. This is only useful if the + * @attach handler is set. If @num_names is non-zero, the driver's @attach + * handler will be called with the COMEDI device structure's board_ptr member + * pointing to the matched pointer to a board name within the driver's private + * array of static, read-only board type information. + */ struct comedi_driver { - struct comedi_driver *next; - + /* private: */ + struct comedi_driver *next; /* Next in list of COMEDI drivers. */ + /* public: */ const char *driver_name; struct module *module; int (*attach)(struct comedi_device *, struct comedi_devconfig *); void (*detach)(struct comedi_device *); int (*auto_attach)(struct comedi_device *, unsigned long); - - /* number of elements in board_name and board_id arrays */ unsigned int num_names; const char *const *board_name; - /* offset in bytes from one board name pointer to the next */ int offset; }; +/** + * struct comedi_device - Working data for a COMEDI device + * @use_count: Number of open file objects. + * @driver: Low-level COMEDI driver attached to this COMEDI device. + * @pacer: Optional pointer to a dynamically allocated acquisition pacer + * control. It is freed automatically after the COMEDI device is + * detached from the low-level driver. + * @private: Optional pointer to private data allocated by the low-level + * driver. It is freed automatically after the COMEDI device is + * detached from the low-level driver. + * @class_dev: Sysfs comediX device. + * @minor: Minor device number of COMEDI char device (0-47). + * @detach_count: Counter incremented every time the COMEDI device is detached. + * Used for checking a previous attachment is still valid. + * @hw_dev: Optional pointer to the low-level hardware &struct device. It is + * required for automatically configured COMEDI devices and optional for + * COMEDI devices configured by the %COMEDI_DEVCONFIG ioctl, although + * the bus-specific COMEDI functions only work if it is set correctly. + * It is also passed to dma_alloc_coherent() for COMEDI subdevices that + * have their 'async_dma_dir' member set to something other than + * %DMA_NONE. + * @board_name: Pointer to a COMEDI board name or a COMEDI driver name. When + * the low-level driver's "attach" handler is called by the handler for + * the %COMEDI_DEVCONFIG ioctl, it either points to a matched board name + * string if the 'num_names' member of the &struct comedi_driver is + * non-zero, otherwise it points to the low-level driver name string. + * When the low-lever driver's "auto_attach" handler is called for an + * automatically configured COMEDI device, it points to the low-level + * driver name string. The low-level driver is free to change it in its + * "attach" or "auto_attach" handler if it wishes. + * @board_ptr: Optional pointer to private, read-only board type information in + * the low-level driver. If the 'num_names' member of the &struct + * comedi_driver is non-zero, the handler for the %COMEDI_DEVCONFIG ioctl + * will point it to a pointer to a matched board name string within the + * driver's private array of static, read-only board type information when + * calling the driver's "attach" handler. The low-level driver is free to + * change it. + * @attached: Flag indicating that the COMEDI device is attached to a low-level + * driver. + * @ioenabled: Flag used to indicate that a PCI device has been enabled and + * its regions requested. + * @spinlock: Generic spin-lock for use by the low-level driver. + * @mutex: Generic mutex for use by the COMEDI core module. + * @attach_lock: &struct rw_semaphore used to guard against the COMEDI device + * being detached while an operation is in progress. The down_write() + * operation is only allowed while @mutex is held and is used when + * changing @attached and @detach_count and calling the low-level driver's + * "detach" handler. The down_read() operation is generally used without + * holding @mutex. + * @refcount: &struct kref reference counter for freeing COMEDI device. + * @n_subdevices: Number of COMEDI subdevices allocated by the low-level + * driver for this device. + * @subdevices: Dynamically allocated array of COMEDI subdevices. + * @mmio: Optional pointer to a remapped MMIO region set by the low-level + * driver. + * @iobase: Optional base of an I/O port region requested by the low-level + * driver. + * @iolen: Length of I/O port region requested at @iobase. + * @irq: Optional IRQ number requested by the low-level driver. + * @read_subdev: Optional pointer to a default COMEDI subdevice operated on by + * the read() file operation. Set by the low-level driver. + * @write_subdev: Optional pointer to a default COMEDI subdevice operated on by + * the write() file operation. Set by the low-level driver. + * @async_queue: Storage for fasync_helper(). + * @open: Optional pointer to a function set by the low-level driver to be + * called when @use_count changes from 0 to 1. + * @close: Optional pointer to a function set by the low-level driver to be + * called when @use_count changed from 1 to 0. + * + * This is the main control data structure for a COMEDI device (as far as the + * COMEDI core is concerned). There are two groups of COMEDI devices - + * "legacy" devices that are configured by the handler for the + * %COMEDI_DEVCONFIG ioctl, and automatically configured devices resulting + * from a call to comedi_auto_config() as a result of a bus driver probe in + * a low-level COMEDI driver. The "legacy" COMEDI devices are allocated + * during module initialization if the "comedi_num_legacy_minors" module + * parameter is non-zero and use minor device numbers from 0 to + * comedi_num_legacy_minors minus one. The automatically configured COMEDI + * devices are allocated on demand and use minor device numbers from + * comedi_num_legacy_minors to 47. + */ struct comedi_device { int use_count; struct comedi_driver *driver; @@ -262,17 +531,14 @@ struct comedi_device { struct device *class_dev; int minor; unsigned int detach_count; - /* hw_dev is passed to dma_alloc_coherent when allocating async buffers - * for subdevices that have async_dma_dir set to something other than - * DMA_NONE */ struct device *hw_dev; const char *board_name; const void *board_ptr; bool attached:1; bool ioenabled:1; - spinlock_t spinlock; - struct mutex mutex; + spinlock_t spinlock; /* generic spin-lock for low-level driver */ + struct mutex mutex; /* generic mutex for COMEDI core */ struct rw_semaphore attach_lock; struct kref refcount; @@ -314,12 +580,12 @@ int comedi_check_chanlist(struct comedi_subdevice *s, /* range stuff */ -#define RANGE(a, b) {(a)*1e6, (b)*1e6, 0} -#define RANGE_ext(a, b) {(a)*1e6, (b)*1e6, RF_EXTERNAL} -#define RANGE_mA(a, b) {(a)*1e6, (b)*1e6, UNIT_mA} -#define RANGE_unitless(a, b) {(a)*1e6, (b)*1e6, 0} -#define BIP_RANGE(a) {-(a)*1e6, (a)*1e6, 0} -#define UNI_RANGE(a) {0, (a)*1e6, 0} +#define RANGE(a, b) {(a) * 1e6, (b) * 1e6, 0} +#define RANGE_ext(a, b) {(a) * 1e6, (b) * 1e6, RF_EXTERNAL} +#define RANGE_mA(a, b) {(a) * 1e6, (b) * 1e6, UNIT_mA} +#define RANGE_unitless(a, b) {(a) * 1e6, (b) * 1e6, 0} +#define BIP_RANGE(a) {-(a) * 1e6, (a) * 1e6, 0} +#define UNI_RANGE(a) {0, (a) * 1e6, 0} extern const struct comedi_lrange range_bipolar10; extern const struct comedi_lrange range_bipolar5; @@ -340,29 +606,101 @@ extern const struct comedi_lrange range_unknown; #define GCC_ZERO_LENGTH_ARRAY 0 #endif +/** + * struct comedi_lrange - Describes a COMEDI range table + * @length: Number of entries in the range table. + * @range: Array of &struct comedi_krange, one for each range. + * + * Each element of @range[] describes the minimum and maximum physical range + * range and the type of units. Typically, the type of unit is %UNIT_volt + * (i.e. volts) and the minimum and maximum are in millionths of a volt. + * There may also be a flag that indicates the minimum and maximum are merely + * scale factors for an unknown, external reference. + */ struct comedi_lrange { int length; struct comedi_krange range[GCC_ZERO_LENGTH_ARRAY]; }; +/** + * comedi_range_is_bipolar() - Test if subdevice range is bipolar + * @s: COMEDI subdevice. + * @range: Index of range within a range table. + * + * Tests whether a range is bipolar by checking whether its minimum value + * is negative. + * + * Assumes @range is valid. Does not work for subdevices using a + * channel-specific range table list. + * + * Return: + * %true if the range is bipolar. + * %false if the range is unipolar. + */ static inline bool comedi_range_is_bipolar(struct comedi_subdevice *s, unsigned int range) { return s->range_table->range[range].min < 0; } +/** + * comedi_range_is_unipolar() - Test if subdevice range is unipolar + * @s: COMEDI subdevice. + * @range: Index of range within a range table. + * + * Tests whether a range is unipolar by checking whether its minimum value + * is at least 0. + * + * Assumes @range is valid. Does not work for subdevices using a + * channel-specific range table list. + * + * Return: + * %true if the range is unipolar. + * %false if the range is bipolar. + */ static inline bool comedi_range_is_unipolar(struct comedi_subdevice *s, unsigned int range) { return s->range_table->range[range].min >= 0; } +/** + * comedi_range_is_external() - Test if subdevice range is external + * @s: COMEDI subdevice. + * @range: Index of range within a range table. + * + * Tests whether a range is externally reference by checking whether its + * %RF_EXTERNAL flag is set. + * + * Assumes @range is valid. Does not work for subdevices using a + * channel-specific range table list. + * + * Return: + * %true if the range is external. + * %false if the range is internal. + */ static inline bool comedi_range_is_external(struct comedi_subdevice *s, unsigned int range) { return !!(s->range_table->range[range].flags & RF_EXTERNAL); } +/** + * comedi_chan_range_is_bipolar() - Test if channel-specific range is bipolar + * @s: COMEDI subdevice. + * @chan: The channel number. + * @range: Index of range within a range table. + * + * Tests whether a range is bipolar by checking whether its minimum value + * is negative. + * + * Assumes @chan and @range are valid. Only works for subdevices with a + * channel-specific range table list. + * + * Return: + * %true if the range is bipolar. + * %false if the range is unipolar. + */ static inline bool comedi_chan_range_is_bipolar(struct comedi_subdevice *s, unsigned int chan, unsigned int range) @@ -370,6 +708,22 @@ static inline bool comedi_chan_range_is_bipolar(struct comedi_subdevice *s, return s->range_table_list[chan]->range[range].min < 0; } +/** + * comedi_chan_range_is_unipolar() - Test if channel-specific range is unipolar + * @s: COMEDI subdevice. + * @chan: The channel number. + * @range: Index of range within a range table. + * + * Tests whether a range is unipolar by checking whether its minimum value + * is at least 0. + * + * Assumes @chan and @range are valid. Only works for subdevices with a + * channel-specific range table list. + * + * Return: + * %true if the range is unipolar. + * %false if the range is bipolar. + */ static inline bool comedi_chan_range_is_unipolar(struct comedi_subdevice *s, unsigned int chan, unsigned int range) @@ -377,6 +731,22 @@ static inline bool comedi_chan_range_is_unipolar(struct comedi_subdevice *s, return s->range_table_list[chan]->range[range].min >= 0; } +/** + * comedi_chan_range_is_external() - Test if channel-specific range is external + * @s: COMEDI subdevice. + * @chan: The channel number. + * @range: Index of range within a range table. + * + * Tests whether a range is externally reference by checking whether its + * %RF_EXTERNAL flag is set. + * + * Assumes @chan and @range are valid. Only works for subdevices with a + * channel-specific range table list. + * + * Return: + * %true if the range is bipolar. + * %false if the range is unipolar. + */ static inline bool comedi_chan_range_is_external(struct comedi_subdevice *s, unsigned int chan, unsigned int range) @@ -384,7 +754,16 @@ static inline bool comedi_chan_range_is_external(struct comedi_subdevice *s, return !!(s->range_table_list[chan]->range[range].flags & RF_EXTERNAL); } -/* munge between offset binary and two's complement values */ +/** + * comedi_offset_munge() - Convert between offset binary and 2's complement + * @s: COMEDI subdevice. + * @val: Value to be converted. + * + * Toggles the highest bit of a sample value to toggle between offset binary + * and 2's complement. Assumes that @s->maxdata is a power of 2 minus 1. + * + * Return: The converted value. + */ static inline unsigned int comedi_offset_munge(struct comedi_subdevice *s, unsigned int val) { @@ -392,13 +771,13 @@ static inline unsigned int comedi_offset_munge(struct comedi_subdevice *s, } /** - * comedi_bytes_per_sample - determine subdevice sample size - * @s: comedi_subdevice struct + * comedi_bytes_per_sample() - Determine subdevice sample size + * @s: COMEDI subdevice. * * The sample size will be 4 (sizeof int) or 2 (sizeof short) depending on - * whether the SDF_LSAMPL subdevice flag is set or not. + * whether the %SDF_LSAMPL subdevice flag is set or not. * - * Returns the subdevice sample size. + * Return: The subdevice sample size. */ static inline unsigned int comedi_bytes_per_sample(struct comedi_subdevice *s) { @@ -406,15 +785,15 @@ static inline unsigned int comedi_bytes_per_sample(struct comedi_subdevice *s) } /** - * comedi_sample_shift - determine log2 of subdevice sample size - * @s: comedi_subdevice struct + * comedi_sample_shift() - Determine log2 of subdevice sample size + * @s: COMEDI subdevice. * * The sample size will be 4 (sizeof int) or 2 (sizeof short) depending on - * whether the SDF_LSAMPL subdevice flag is set or not. The log2 of the + * whether the %SDF_LSAMPL subdevice flag is set or not. The log2 of the * sample size will be 2 or 1 and can be used as the right operand of a * bit-shift operator to multiply or divide something by the sample size. * - * Returns log2 of the subdevice sample size. + * Return: log2 of the subdevice sample size. */ static inline unsigned int comedi_sample_shift(struct comedi_subdevice *s) { @@ -422,11 +801,11 @@ static inline unsigned int comedi_sample_shift(struct comedi_subdevice *s) } /** - * comedi_bytes_to_samples - converts a number of bytes to a number of samples - * @s: comedi_subdevice struct - * @nbytes: number of bytes + * comedi_bytes_to_samples() - Convert a number of bytes to a number of samples + * @s: COMEDI subdevice. + * @nbytes: Number of bytes * - * Returns the number of bytes divided by the subdevice sample size. + * Return: The number of bytes divided by the subdevice sample size. */ static inline unsigned int comedi_bytes_to_samples(struct comedi_subdevice *s, unsigned int nbytes) @@ -435,12 +814,12 @@ static inline unsigned int comedi_bytes_to_samples(struct comedi_subdevice *s, } /** - * comedi_samples_to_bytes - converts a number of samples to a number of bytes - * @s: comedi_subdevice struct - * @nsamples: number of samples + * comedi_samples_to_bytes() - Convert a number of samples to a number of bytes + * @s: COMEDI subdevice. + * @nsamples: Number of samples. * - * Returns the number of samples multiplied by the subdevice sample size. - * Does not check for arithmetic overflow. + * Return: The number of samples multiplied by the subdevice sample size. + * (Does not check for arithmetic overflow.) */ static inline unsigned int comedi_samples_to_bytes(struct comedi_subdevice *s, unsigned int nsamples) @@ -449,14 +828,18 @@ static inline unsigned int comedi_samples_to_bytes(struct comedi_subdevice *s, } /** - * comedi_check_trigger_src() - trivially validate a comedi_cmd trigger source - * @src: pointer to the trigger source to validate - * @flags: bitmask of valid TRIG_* for the trigger + * comedi_check_trigger_src() - Trivially validate a comedi_cmd trigger source + * @src: Pointer to the trigger source to validate. + * @flags: Bitmask of valid %TRIG_* for the trigger. * * This is used in "step 1" of the do_cmdtest functions of comedi drivers - * to vaildate the comedi_cmd triggers. The mask of the @src against the + * to validate the comedi_cmd triggers. The mask of the @src against the * @flags allows the userspace comedilib to pass all the comedi_cmd - * triggers as TRIG_ANY and get back a bitmask of the valid trigger sources. + * triggers as %TRIG_ANY and get back a bitmask of the valid trigger sources. + * + * Return: + * 0 if trigger sources in *@src are all supported. + * -EINVAL if any trigger source in *@src is unsupported. */ static inline int comedi_check_trigger_src(unsigned int *src, unsigned int flags) @@ -470,8 +853,12 @@ static inline int comedi_check_trigger_src(unsigned int *src, } /** - * comedi_check_trigger_is_unique() - make sure a trigger source is unique - * @src: the trigger source to check + * comedi_check_trigger_is_unique() - Make sure a trigger source is unique + * @src: The trigger source to check. + * + * Return: + * 0 if no more than one trigger source is set. + * -EINVAL if more than one trigger source is set. */ static inline int comedi_check_trigger_is_unique(unsigned int src) { @@ -482,9 +869,15 @@ static inline int comedi_check_trigger_is_unique(unsigned int src) } /** - * comedi_check_trigger_arg_is() - trivially validate a trigger argument - * @arg: pointer to the trigger arg to validate - * @val: the value the argument should be + * comedi_check_trigger_arg_is() - Trivially validate a trigger argument + * @arg: Pointer to the trigger arg to validate. + * @val: The value the argument should be. + * + * Forces *@arg to be @val. + * + * Return: + * 0 if *@arg was already @val. + * -EINVAL if *@arg differed from @val. */ static inline int comedi_check_trigger_arg_is(unsigned int *arg, unsigned int val) @@ -497,9 +890,15 @@ static inline int comedi_check_trigger_arg_is(unsigned int *arg, } /** - * comedi_check_trigger_arg_min() - trivially validate a trigger argument - * @arg: pointer to the trigger arg to validate - * @val: the minimum value the argument should be + * comedi_check_trigger_arg_min() - Trivially validate a trigger argument min + * @arg: Pointer to the trigger arg to validate. + * @val: The minimum value the argument should be. + * + * Forces *@arg to be at least @val, setting it to @val if necessary. + * + * Return: + * 0 if *@arg was already at least @val. + * -EINVAL if *@arg was less than @val. */ static inline int comedi_check_trigger_arg_min(unsigned int *arg, unsigned int val) @@ -512,9 +911,15 @@ static inline int comedi_check_trigger_arg_min(unsigned int *arg, } /** - * comedi_check_trigger_arg_max() - trivially validate a trigger argument - * @arg: pointer to the trigger arg to validate - * @val: the maximum value the argument should be + * comedi_check_trigger_arg_max() - Trivially validate a trigger argument max + * @arg: Pointer to the trigger arg to validate. + * @val: The maximum value the argument should be. + * + * Forces *@arg to be no more than @val, setting it to @val if necessary. + * + * Return: + * 0 if*@arg was already no more than @val. + * -EINVAL if *@arg was greater than @val. */ static inline int comedi_check_trigger_arg_max(unsigned int *arg, unsigned int val) @@ -534,6 +939,16 @@ static inline int comedi_check_trigger_arg_max(unsigned int *arg, */ int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev); +/** + * comedi_buf_n_bytes_ready - Determine amount of unread data in buffer + * @s: COMEDI subdevice. + * + * Determines the number of bytes of unread data in the asynchronous + * acquisition data buffer for a subdevice. The data in question might not + * have been fully "munged" yet. + * + * Returns: The amount of unread data in bytes. + */ static inline unsigned int comedi_buf_n_bytes_ready(struct comedi_subdevice *s) { return s->async->buf_write_count - s->async->buf_read_count; diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index b03bc6639f79..b63dd2ef78b5 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -1,37 +1,29 @@ /* - module/drivers.c - functions for manipulating drivers - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 1997-2000 David A. Schleef - Copyright (C) 2002 Frank Mori Hess - - 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. + * module/drivers.c + * functions for manipulating drivers + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1997-2000 David A. Schleef + * Copyright (C) 2002 Frank Mori Hess + * + * 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 -#include #include -#include -#include #include -#include #include -#include /* for SuSE brokenness */ -#include -#include -#include -#include +#include #include #include @@ -42,6 +34,28 @@ struct comedi_driver *comedi_drivers; /* protects access to comedi_drivers */ DEFINE_MUTEX(comedi_drivers_list_lock); +/** + * comedi_set_hw_dev() - Set hardware device associated with COMEDI device + * @dev: COMEDI device. + * @hw_dev: Hardware device. + * + * For automatically configured COMEDI devices (resulting from a call to + * comedi_auto_config() or one of its wrappers from the low-level COMEDI + * driver), comedi_set_hw_dev() is called automatically by the COMEDI core + * to associate the COMEDI device with the hardware device. It can also be + * called directly by "legacy" low-level COMEDI drivers that rely on the + * %COMEDI_DEVCONFIG ioctl to configure the hardware as long as the hardware + * has a &struct device. + * + * If @dev->hw_dev is NULL, it gets a reference to @hw_dev and sets + * @dev->hw_dev, otherwise, it does nothing. Calling it multiple times + * with the same hardware device is not considered an error. If it gets + * a reference to the hardware device, it will be automatically 'put' when + * the device is detached from COMEDI. + * + * Returns 0 if @dev->hw_dev was NULL or the same as @hw_dev, otherwise + * returns -EEXIST. + */ int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev) { if (hw_dev == dev->hw_dev) @@ -60,9 +74,15 @@ static void comedi_clear_hw_dev(struct comedi_device *dev) } /** - * comedi_alloc_devpriv() - Allocate memory for the device private data. - * @dev: comedi_device struct - * @size: size of the memory to allocate + * comedi_alloc_devpriv() - Allocate memory for the device private data + * @dev: COMEDI device. + * @size: Size of the memory to allocate. + * + * The allocated memory is zero-filled. @dev->private points to it on + * return. The memory will be automatically freed when the COMEDI device is + * "detached". + * + * Returns a pointer to the allocated memory, or NULL on failure. */ void *comedi_alloc_devpriv(struct comedi_device *dev, size_t size) { @@ -71,6 +91,18 @@ void *comedi_alloc_devpriv(struct comedi_device *dev, size_t size) } EXPORT_SYMBOL_GPL(comedi_alloc_devpriv); +/** + * comedi_alloc_subdevices() - Allocate subdevices for COMEDI device + * @dev: COMEDI device. + * @num_subdevices: Number of subdevices to allocate. + * + * Allocates and initializes an array of &struct comedi_subdevice for the + * COMEDI device. If successful, sets @dev->subdevices to point to the + * first one and @dev->n_subdevices to the number. + * + * Returns 0 on success, -EINVAL if @num_subdevices is < 1, or -ENOMEM if + * failed to allocate the memory. + */ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) { struct comedi_subdevice *s; @@ -98,8 +130,22 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) EXPORT_SYMBOL_GPL(comedi_alloc_subdevices); /** - * comedi_alloc_subdev_readback() - Allocate memory for the subdevice readback. - * @s: comedi_subdevice struct + * comedi_alloc_subdev_readback() - Allocate memory for the subdevice readback + * @s: COMEDI subdevice. + * + * This is called by low-level COMEDI drivers to allocate an array to record + * the last values written to a subdevice's analog output channels (at least + * by the %INSN_WRITE instruction), to allow them to be read back by an + * %INSN_READ instruction. It also provides a default handler for the + * %INSN_READ instruction unless one has already been set. + * + * On success, @s->readback points to the first element of the array, which + * is zero-filled. The low-level driver is responsible for updating its + * contents. @s->insn_read will be set to comedi_readback_insn_read() + * unless it is already non-NULL. + * + * Returns 0 on success, -EINVAL if the subdevice has no channels, or + * -ENOMEM on allocation failure. */ int comedi_alloc_subdev_readback(struct comedi_subdevice *s) { @@ -182,10 +228,20 @@ int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s, /** * comedi_readback_insn_read() - A generic (*insn_read) for subdevice readback. - * @dev: comedi_device struct - * @s: comedi_subdevice struct - * @insn: comedi_insn struct - * @data: pointer to return the readback data + * @dev: COMEDI device. + * @s: COMEDI subdevice. + * @insn: COMEDI instruction. + * @data: Pointer to return the readback data. + * + * Handles the %INSN_READ instruction for subdevices that use the readback + * array allocated by comedi_alloc_subdev_readback(). It may be used + * directly as the subdevice's handler (@s->insn_read) or called via a + * wrapper. + * + * @insn->n is normally 1, which will read a single value. If higher, the + * same element of the readback array will be read multiple times. + * + * Returns @insn->n on success, or -EINVAL if @s->readback is NULL. */ int comedi_readback_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, @@ -206,12 +262,21 @@ int comedi_readback_insn_read(struct comedi_device *dev, EXPORT_SYMBOL_GPL(comedi_readback_insn_read); /** - * comedi_timeout() - busy-wait for a driver condition to occur. - * @dev: comedi_device struct - * @s: comedi_subdevice struct - * @insn: comedi_insn struct - * @cb: callback to check for the condition - * @context: private context from the driver + * comedi_timeout() - Busy-wait for a driver condition to occur + * @dev: COMEDI device. + * @s: COMEDI subdevice. + * @insn: COMEDI instruction. + * @cb: Callback to check for the condition. + * @context: Private context from the driver. + * + * Busy-waits for up to a second (%COMEDI_TIMEOUT_MS) for the condition or + * some error (other than -EBUSY) to occur. The parameters @dev, @s, @insn, + * and @context are passed to the callback function, which returns -EBUSY to + * continue waiting or some other value to stop waiting (generally 0 if the + * condition occurred, or some error value). + * + * Returns -ETIMEDOUT if timed out, otherwise the return value from the + * callback function. */ int comedi_timeout(struct comedi_device *dev, struct comedi_subdevice *s, @@ -236,12 +301,30 @@ int comedi_timeout(struct comedi_device *dev, EXPORT_SYMBOL_GPL(comedi_timeout); /** - * comedi_dio_insn_config() - boilerplate (*insn_config) for DIO subdevices. - * @dev: comedi_device struct - * @s: comedi_subdevice struct - * @insn: comedi_insn struct - * @data: parameters for the @insn - * @mask: io_bits mask for grouped channels + * comedi_dio_insn_config() - Boilerplate (*insn_config) for DIO subdevices + * @dev: COMEDI device. + * @s: COMEDI subdevice. + * @insn: COMEDI instruction. + * @data: Instruction parameters and return data. + * @mask: io_bits mask for grouped channels, or 0 for single channel. + * + * If @mask is 0, it is replaced with a single-bit mask corresponding to the + * channel number specified by @insn->chanspec. Otherwise, @mask + * corresponds to a group of channels (which should include the specified + * channel) that are always configured together as inputs or outputs. + * + * Partially handles the %INSN_CONFIG_DIO_INPUT, %INSN_CONFIG_DIO_OUTPUTS, + * and %INSN_CONFIG_DIO_QUERY instructions. The first two update + * @s->io_bits to record the directions of the masked channels. The last + * one sets @data[1] to the current direction of the group of channels + * (%COMEDI_INPUT) or %COMEDI_OUTPUT) as recorded in @s->io_bits. + * + * The caller is responsible for updating the DIO direction in the hardware + * registers if this function returns 0. + * + * Returns 0 for a %INSN_CONFIG_DIO_INPUT or %INSN_CONFIG_DIO_OUTPUT + * instruction, @insn->n (> 0) for a %INSN_CONFIG_DIO_QUERY instruction, or + * -EINVAL for some other instruction. */ int comedi_dio_insn_config(struct comedi_device *dev, struct comedi_subdevice *s, @@ -276,9 +359,18 @@ int comedi_dio_insn_config(struct comedi_device *dev, EXPORT_SYMBOL_GPL(comedi_dio_insn_config); /** - * comedi_dio_update_state() - update the internal state of DIO subdevices. - * @s: comedi_subdevice struct - * @data: the channel mask and bits to update + * comedi_dio_update_state() - Update the internal state of DIO subdevices + * @s: COMEDI subdevice. + * @data: The channel mask and bits to update. + * + * Updates @s->state which holds the internal state of the outputs for DIO + * or DO subdevices (up to 32 channels). @data[0] contains a bit-mask of + * the channels to be updated. @data[1] contains a bit-mask of those + * channels to be set to '1'. The caller is responsible for updating the + * outputs in hardware according to @s->state. As a minimum, the channels + * in the returned bit-mask need to be updated. + * + * Returns @mask with non-existent channels removed. */ unsigned int comedi_dio_update_state(struct comedi_subdevice *s, unsigned int *data) @@ -298,17 +390,17 @@ unsigned int comedi_dio_update_state(struct comedi_subdevice *s, EXPORT_SYMBOL_GPL(comedi_dio_update_state); /** - * comedi_bytes_per_scan - get length of asynchronous command "scan" in bytes - * @s: comedi_subdevice struct + * comedi_bytes_per_scan() - Get length of asynchronous command "scan" in bytes + * @s: COMEDI subdevice. * * Determines the overall scan length according to the subdevice type and the * number of channels in the scan. * - * For digital input, output or input/output subdevices, samples for multiple - * channels are assumed to be packed into one or more unsigned short or - * unsigned int values according to the subdevice's SDF_LSAMPL flag. For other - * types of subdevice, samples are assumed to occupy a whole unsigned short or - * unsigned int according to the SDF_LSAMPL flag. + * For digital input, output or input/output subdevices, samples for + * multiple channels are assumed to be packed into one or more unsigned + * short or unsigned int values according to the subdevice's %SDF_LSAMPL + * flag. For other types of subdevice, samples are assumed to occupy a + * whole unsigned short or unsigned int according to the %SDF_LSAMPL flag. * * Returns the overall scan length in bytes. */ @@ -333,32 +425,12 @@ unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s) } EXPORT_SYMBOL_GPL(comedi_bytes_per_scan); -/** - * comedi_nscans_left - return the number of scans left in the command - * @s: comedi_subdevice struct - * @nscans: the expected number of scans - * - * If nscans is 0, the number of scans available in the async buffer will be - * used. Otherwise the expected number of scans will be used. - * - * If the async command has a stop_src of TRIG_COUNT, the nscans will be - * checked against the number of scans left in the command. - * - * The return value will then be either the expected number of scans or the - * number of scans remaining in the command. - */ -unsigned int comedi_nscans_left(struct comedi_subdevice *s, - unsigned int nscans) +static unsigned int __comedi_nscans_left(struct comedi_subdevice *s, + unsigned int nscans) { struct comedi_async *async = s->async; struct comedi_cmd *cmd = &async->cmd; - if (nscans == 0) { - unsigned int nbytes = comedi_buf_read_n_available(s); - - nscans = nbytes / comedi_bytes_per_scan(s); - } - if (cmd->stop_src == TRIG_COUNT) { unsigned int scans_left = 0; @@ -370,15 +442,40 @@ unsigned int comedi_nscans_left(struct comedi_subdevice *s, } return nscans; } + +/** + * comedi_nscans_left() - Return the number of scans left in the command + * @s: COMEDI subdevice. + * @nscans: The expected number of scans or 0 for all available scans. + * + * If @nscans is 0, it is set to the number of scans available in the + * async buffer. + * + * If the async command has a stop_src of %TRIG_COUNT, the @nscans will be + * checked against the number of scans remaining to complete the command. + * + * The return value will then be either the expected number of scans or the + * number of scans remaining to complete the command, whichever is fewer. + */ +unsigned int comedi_nscans_left(struct comedi_subdevice *s, + unsigned int nscans) +{ + if (nscans == 0) { + unsigned int nbytes = comedi_buf_read_n_available(s); + + nscans = nbytes / comedi_bytes_per_scan(s); + } + return __comedi_nscans_left(s, nscans); +} EXPORT_SYMBOL_GPL(comedi_nscans_left); /** - * comedi_nsamples_left - return the number of samples left in the command - * @s: comedi_subdevice struct - * @nsamples: the expected number of samples + * comedi_nsamples_left() - Return the number of samples left in the command + * @s: COMEDI subdevice. + * @nsamples: The expected number of samples. * - * Returns the expected number of samples of the number of samples remaining - * in the command. + * Returns the number of samples remaining to complete the command, or the + * specified expected number of samples (@nsamples), whichever is fewer. */ unsigned int comedi_nsamples_left(struct comedi_subdevice *s, unsigned int nsamples) @@ -387,9 +484,8 @@ unsigned int comedi_nsamples_left(struct comedi_subdevice *s, struct comedi_cmd *cmd = &async->cmd; if (cmd->stop_src == TRIG_COUNT) { - /* +1 to force comedi_nscans_left() to return the scans left */ - unsigned int nscans = (nsamples / cmd->scan_end_arg) + 1; - unsigned int scans_left = comedi_nscans_left(s, nscans); + unsigned int nscans = nsamples / cmd->scan_end_arg; + unsigned int scans_left = __comedi_nscans_left(s, nscans); unsigned int scan_pos = comedi_bytes_to_samples(s, async->scan_progress); unsigned long long samples_left = 0; @@ -407,14 +503,14 @@ unsigned int comedi_nsamples_left(struct comedi_subdevice *s, EXPORT_SYMBOL_GPL(comedi_nsamples_left); /** - * comedi_inc_scan_progress - update scan progress in asynchronous command - * @s: comedi_subdevice struct - * @num_bytes: amount of data in bytes to increment scan progress + * comedi_inc_scan_progress() - Update scan progress in asynchronous command + * @s: COMEDI subdevice. + * @num_bytes: Amount of data in bytes to increment scan progress. * - * Increments the scan progress by the number of bytes specified by num_bytes. + * Increments the scan progress by the number of bytes specified by @num_bytes. * If the scan progress reaches or exceeds the scan length in bytes, reduce * it modulo the scan length in bytes and set the "end of scan" asynchronous - * event flag to be processed later. + * event flag (%COMEDI_CB_EOS) to be processed later. */ void comedi_inc_scan_progress(struct comedi_subdevice *s, unsigned int num_bytes) @@ -445,12 +541,12 @@ void comedi_inc_scan_progress(struct comedi_subdevice *s, EXPORT_SYMBOL_GPL(comedi_inc_scan_progress); /** - * comedi_handle_events - handle events and possibly stop acquisition - * @dev: comedi_device struct - * @s: comedi_subdevice struct + * comedi_handle_events() - Handle events and possibly stop acquisition + * @dev: COMEDI device. + * @s: COMEDI subdevice. * * Handles outstanding asynchronous acquisition event flags associated - * with the subdevice. Call the subdevice's "->cancel()" handler if the + * with the subdevice. Call the subdevice's @s->cancel() handler if the * "end of acquisition", "error" or "overflow" event flags are set in order * to stop the acquisition at the driver level. * @@ -685,12 +781,19 @@ static void comedi_report_boards(struct comedi_driver *driv) } /** - * 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 + * comedi_load_firmware() - Request and load firmware for a device + * @dev: COMEDI device. + * @device: Hardware device. + * @name: The name of the firmware image. + * @cb: Callback to the upload the firmware image. + * @context: Private context from the driver. + * + * Sends a firmware request for the hardware device and waits for it. Calls + * the callback function to upload the firmware to the device, them releases + * the firmware. + * + * Returns 0 on success, -EINVAL if @cb is NULL, or a negative error number + * from the firmware request or the callback function. */ int comedi_load_firmware(struct comedi_device *dev, struct device *device, @@ -717,10 +820,16 @@ int comedi_load_firmware(struct comedi_device *dev, EXPORT_SYMBOL_GPL(comedi_load_firmware); /** - * __comedi_request_region() - Request an I/O reqion for a legacy driver. - * @dev: comedi_device struct - * @start: base address of the I/O reqion - * @len: length of the I/O region + * __comedi_request_region() - Request an I/O region for a legacy driver + * @dev: COMEDI device. + * @start: Base address of the I/O region. + * @len: Length of the I/O region. + * + * Requests the specified I/O port region which must start at a non-zero + * address. + * + * Returns 0 on success, -EINVAL if @start is 0, or -EIO if the request + * fails. */ int __comedi_request_region(struct comedi_device *dev, unsigned long start, unsigned long len) @@ -743,10 +852,19 @@ int __comedi_request_region(struct comedi_device *dev, EXPORT_SYMBOL_GPL(__comedi_request_region); /** - * comedi_request_region() - Request an I/O reqion for a legacy driver. - * @dev: comedi_device struct - * @start: base address of the I/O reqion - * @len: length of the I/O region + * comedi_request_region() - Request an I/O region for a legacy driver + * @dev: COMEDI device. + * @start: Base address of the I/O region. + * @len: Length of the I/O region. + * + * Requests the specified I/O port region which must start at a non-zero + * address. + * + * On success, @dev->iobase is set to the base address of the region and + * @dev->iolen is set to its length. + * + * Returns 0 on success, -EINVAL if @start is 0, or -EIO if the request + * fails. */ int comedi_request_region(struct comedi_device *dev, unsigned long start, unsigned long len) @@ -764,8 +882,16 @@ int comedi_request_region(struct comedi_device *dev, EXPORT_SYMBOL_GPL(comedi_request_region); /** - * comedi_legacy_detach() - A generic (*detach) function for legacy drivers. - * @dev: comedi_device struct + * comedi_legacy_detach() - A generic (*detach) function for legacy drivers + * @dev: COMEDI device. + * + * This is a simple, generic 'detach' handler for legacy COMEDI devices that + * just use a single I/O port region and possibly an IRQ and that don't need + * any special clean-up for their private device or subdevice storage. It + * can also be called by a driver-specific 'detach' handler. + * + * If @dev->irq is non-zero, the IRQ will be freed. If @dev->iobase and + * @dev->iolen are both non-zero, the I/O port region will be released. */ void comedi_legacy_detach(struct comedi_device *dev) { @@ -839,6 +965,29 @@ out: return ret; } +/** + * comedi_auto_config() - Create a COMEDI device for a hardware device + * @hardware_device: Hardware device. + * @driver: COMEDI low-level driver for the hardware device. + * @context: Driver context for the auto_attach handler. + * + * Allocates a new COMEDI device for the hardware device and calls the + * low-level driver's 'auto_attach' handler to set-up the hardware and + * allocate the COMEDI subdevices. Additional "post-configuration" setting + * up is performed on successful return from the 'auto_attach' handler. + * If the 'auto_attach' handler fails, the low-level driver's 'detach' + * handler will be called as part of the clean-up. + * + * This is usually called from a wrapper function in a bus-specific COMEDI + * module, which in turn is usually called from a bus device 'probe' + * function in the low-level driver. + * + * Returns 0 on success, -EINVAL if the parameters are invalid or the + * post-configuration determines the driver has set the COMEDI device up + * incorrectly, -ENOMEM if failed to allocate memory, -EBUSY if run out of + * COMEDI minor device numbers, or some negative error number returned by + * the driver's 'auto_attach' handler. + */ int comedi_auto_config(struct device *hardware_device, struct comedi_driver *driver, unsigned long context) { @@ -896,6 +1045,22 @@ int comedi_auto_config(struct device *hardware_device, } EXPORT_SYMBOL_GPL(comedi_auto_config); +/** + * comedi_auto_unconfig() - Unconfigure auto-allocated COMEDI device + * @hardware_device: Hardware device previously passed to + * comedi_auto_config(). + * + * Cleans up and eventually destroys the COMEDI device allocated by + * comedi_auto_config() for the same hardware device. As part of this + * clean-up, the low-level COMEDI driver's 'detach' handler will be called. + * (The COMEDI device itself will persist in an unattached state if it is + * still open, until it is released, and any mmapped buffers will persist + * until they are munmapped.) + * + * This is usually called from a wrapper module in a bus-specific COMEDI + * module, which in turn is usually set as the bus device 'remove' function + * in the low-level COMEDI driver. + */ void comedi_auto_unconfig(struct device *hardware_device) { if (!hardware_device) @@ -904,6 +1069,17 @@ void comedi_auto_unconfig(struct device *hardware_device) } EXPORT_SYMBOL_GPL(comedi_auto_unconfig); +/** + * comedi_driver_register() - Register a low-level COMEDI driver + * @driver: Low-level COMEDI driver. + * + * The low-level COMEDI driver is added to the list of registered COMEDI + * drivers. This is used by the handler for the "/proc/comedi" file and is + * also used by the handler for the %COMEDI_DEVCONFIG ioctl to configure + * "legacy" COMEDI devices (for those low-level drivers that support it). + * + * Returns 0. + */ int comedi_driver_register(struct comedi_driver *driver) { mutex_lock(&comedi_drivers_list_lock); @@ -915,6 +1091,15 @@ int comedi_driver_register(struct comedi_driver *driver) } EXPORT_SYMBOL_GPL(comedi_driver_register); +/** + * comedi_driver_unregister() - Unregister a low-level COMEDI driver + * @driver: Low-level COMEDI driver. + * + * The low-level COMEDI driver is removed from the list of registered COMEDI + * drivers. Detaches any COMEDI devices attached to the driver, which will + * result in the low-level driver's 'detach' handler being called for those + * devices before this function returns. + */ void comedi_driver_unregister(struct comedi_driver *driver) { struct comedi_driver *prev; diff --git a/drivers/staging/comedi/drivers/8255.h b/drivers/staging/comedi/drivers/8255.h index 41823de69b77..55a67af5152d 100644 --- a/drivers/staging/comedi/drivers/8255.h +++ b/drivers/staging/comedi/drivers/8255.h @@ -25,13 +25,13 @@ #define I8255_DATA_B_REG 0x01 #define I8255_DATA_C_REG 0x02 #define I8255_CTRL_REG 0x03 -#define I8255_CTRL_C_LO_IO (1 << 0) -#define I8255_CTRL_B_IO (1 << 1) -#define I8255_CTRL_B_MODE (1 << 2) -#define I8255_CTRL_C_HI_IO (1 << 3) -#define I8255_CTRL_A_IO (1 << 4) +#define I8255_CTRL_C_LO_IO BIT(0) +#define I8255_CTRL_B_IO BIT(1) +#define I8255_CTRL_B_MODE BIT(2) +#define I8255_CTRL_C_HI_IO BIT(3) +#define I8255_CTRL_A_IO BIT(4) #define I8255_CTRL_A_MODE(x) ((x) << 5) -#define I8255_CTRL_CW (1 << 7) +#define I8255_CTRL_CW BIT(7) struct comedi_device; struct comedi_subdevice; diff --git a/drivers/staging/comedi/drivers/8255_pci.c b/drivers/staging/comedi/drivers/8255_pci.c index bb9854b56807..38c05d1ec647 100644 --- a/drivers/staging/comedi/drivers/8255_pci.c +++ b/drivers/staging/comedi/drivers/8255_pci.c @@ -178,8 +178,8 @@ static const struct pci_8255_boardinfo pci_8255_boards[] = { }; /* ripped from mite.h and mite_setup2() to avoid mite dependency */ -#define MITE_IODWBSR 0xc0 /* IO Device Window Base Size Register */ -#define WENAB (1 << 7) /* window enable */ +#define MITE_IODWBSR 0xc0 /* IO Device Window Base Size Register */ +#define WENAB BIT(7) /* window enable */ static int pci_8255_mite_init(struct pci_dev *pcidev) { diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile index 5764dc9a6893..c3b8f2d7611b 100644 --- a/drivers/staging/comedi/drivers/Makefile +++ b/drivers/staging/comedi/drivers/Makefile @@ -90,7 +90,6 @@ obj-$(CONFIG_COMEDI_CONTEC_PCI_DIO) += contec_pci_dio.o obj-$(CONFIG_COMEDI_DAS08_PCI) += das08_pci.o obj-$(CONFIG_COMEDI_DT3000) += dt3000.o obj-$(CONFIG_COMEDI_DYNA_PCI10XX) += dyna_pci10xx.o -obj-$(CONFIG_COMEDI_UNIOXX5) += unioxx5.o obj-$(CONFIG_COMEDI_GSC_HPDI) += gsc_hpdi.o obj-$(CONFIG_COMEDI_ICP_MULTI) += icp_multi.o obj-$(CONFIG_COMEDI_DAQBOARD2000) += daqboard2000.o diff --git a/drivers/staging/comedi/drivers/addi_apci_1032.c b/drivers/staging/comedi/drivers/addi_apci_1032.c index b37166d57b64..ccd1a91290bf 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1032.c +++ b/drivers/staging/comedi/drivers/addi_apci_1032.c @@ -84,9 +84,10 @@ #define APCI1032_MODE2_REG 0x08 #define APCI1032_STATUS_REG 0x0c #define APCI1032_CTRL_REG 0x10 -#define APCI1032_CTRL_INT_OR (0 << 1) -#define APCI1032_CTRL_INT_AND (1 << 1) -#define APCI1032_CTRL_INT_ENA (1 << 2) +#define APCI1032_CTRL_INT_MODE(x) (((x) & 0x1) << 1) +#define APCI1032_CTRL_INT_OR APCI1032_CTRL_INT_MODE(0) +#define APCI1032_CTRL_INT_AND APCI1032_CTRL_INT_MODE(1) +#define APCI1032_CTRL_INT_ENA BIT(2) struct apci1032_private { unsigned long amcc_iobase; /* base of AMCC I/O registers */ diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index ad715253bdcc..50f9eb25d7cb 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -34,19 +34,19 @@ */ #define APCI2032_DO_REG 0x00 #define APCI2032_INT_CTRL_REG 0x04 -#define APCI2032_INT_CTRL_VCC_ENA (1 << 0) -#define APCI2032_INT_CTRL_CC_ENA (1 << 1) +#define APCI2032_INT_CTRL_VCC_ENA BIT(0) +#define APCI2032_INT_CTRL_CC_ENA BIT(1) #define APCI2032_INT_STATUS_REG 0x08 -#define APCI2032_INT_STATUS_VCC (1 << 0) -#define APCI2032_INT_STATUS_CC (1 << 1) +#define APCI2032_INT_STATUS_VCC BIT(0) +#define APCI2032_INT_STATUS_CC BIT(1) #define APCI2032_STATUS_REG 0x0c -#define APCI2032_STATUS_IRQ (1 << 0) +#define APCI2032_STATUS_IRQ BIT(0) #define APCI2032_WDOG_REG 0x10 struct apci2032_int_private { - spinlock_t spinlock; - bool active; - unsigned char enabled_isns; + spinlock_t spinlock; /* protects the following members */ + bool active; /* an async command is running */ + unsigned char enabled_isns; /* mask of enabled interrupt channels */ }; static int apci2032_do_insn_bits(struct comedi_device *dev, diff --git a/drivers/staging/comedi/drivers/addi_apci_3120.c b/drivers/staging/comedi/drivers/addi_apci_3120.c index 5bfd43d5c889..3630d75e36e8 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3120.c +++ b/drivers/staging/comedi/drivers/addi_apci_3120.c @@ -31,33 +31,33 @@ * PCI BAR 0 register map (devpriv->amcc) * see amcc_s5933.h for register and bit defines */ -#define APCI3120_FIFO_ADVANCE_ON_BYTE_2 (1 << 29) +#define APCI3120_FIFO_ADVANCE_ON_BYTE_2 BIT(29) /* * PCI BAR 1 register map (dev->iobase) */ #define APCI3120_AI_FIFO_REG 0x00 #define APCI3120_CTRL_REG 0x00 -#define APCI3120_CTRL_EXT_TRIG (1 << 15) -#define APCI3120_CTRL_GATE(x) (1 << (12 + (x))) +#define APCI3120_CTRL_EXT_TRIG BIT(15) +#define APCI3120_CTRL_GATE(x) BIT(12 + (x)) #define APCI3120_CTRL_PR(x) (((x) & 0xf) << 8) #define APCI3120_CTRL_PA(x) (((x) & 0xf) << 0) #define APCI3120_AI_SOFTTRIG_REG 0x02 #define APCI3120_STATUS_REG 0x02 -#define APCI3120_STATUS_EOC_INT (1 << 15) -#define APCI3120_STATUS_AMCC_INT (1 << 14) -#define APCI3120_STATUS_EOS_INT (1 << 13) -#define APCI3120_STATUS_TIMER2_INT (1 << 12) +#define APCI3120_STATUS_EOC_INT BIT(15) +#define APCI3120_STATUS_AMCC_INT BIT(14) +#define APCI3120_STATUS_EOS_INT BIT(13) +#define APCI3120_STATUS_TIMER2_INT BIT(12) #define APCI3120_STATUS_INT_MASK (0xf << 12) #define APCI3120_STATUS_TO_DI_BITS(x) (((x) >> 8) & 0xf) #define APCI3120_STATUS_TO_VERSION(x) (((x) >> 4) & 0xf) -#define APCI3120_STATUS_FIFO_FULL (1 << 2) -#define APCI3120_STATUS_FIFO_EMPTY (1 << 1) -#define APCI3120_STATUS_DA_READY (1 << 0) +#define APCI3120_STATUS_FIFO_FULL BIT(2) +#define APCI3120_STATUS_FIFO_EMPTY BIT(1) +#define APCI3120_STATUS_DA_READY BIT(0) #define APCI3120_TIMER_REG 0x04 #define APCI3120_CHANLIST_REG 0x06 #define APCI3120_CHANLIST_INDEX(x) (((x) & 0xf) << 8) -#define APCI3120_CHANLIST_UNIPOLAR (1 << 7) +#define APCI3120_CHANLIST_UNIPOLAR BIT(7) #define APCI3120_CHANLIST_GAIN(x) (((x) & 0x3) << 4) #define APCI3120_CHANLIST_MUX(x) (((x) & 0xf) << 0) #define APCI3120_AO_REG(x) (0x08 + (((x) / 4) * 2)) @@ -74,19 +74,21 @@ #define APCI3120_CTR0_DO_BITS(x) ((x) << 4) #define APCI3120_CTR0_TIMER_SEL(x) ((x) << 0) #define APCI3120_MODE_REG 0x0e -#define APCI3120_MODE_TIMER2_CLK_OSC (0 << 6) -#define APCI3120_MODE_TIMER2_CLK_OUT1 (1 << 6) -#define APCI3120_MODE_TIMER2_CLK_EOC (2 << 6) -#define APCI3120_MODE_TIMER2_CLK_EOS (3 << 6) -#define APCI3120_MODE_TIMER2_CLK_MASK (3 << 6) -#define APCI3120_MODE_TIMER2_AS_TIMER (0 << 4) -#define APCI3120_MODE_TIMER2_AS_COUNTER (1 << 4) -#define APCI3120_MODE_TIMER2_AS_WDOG (2 << 4) -#define APCI3120_MODE_TIMER2_AS_MASK (3 << 4) /* sets AS_TIMER */ -#define APCI3120_MODE_SCAN_ENA (1 << 3) -#define APCI3120_MODE_TIMER2_IRQ_ENA (1 << 2) -#define APCI3120_MODE_EOS_IRQ_ENA (1 << 1) -#define APCI3120_MODE_EOC_IRQ_ENA (1 << 0) +#define APCI3120_MODE_TIMER2_CLK(x) (((x) & 0x3) << 6) +#define APCI3120_MODE_TIMER2_CLK_OSC APCI3120_MODE_TIMER2_CLK(0) +#define APCI3120_MODE_TIMER2_CLK_OUT1 APCI3120_MODE_TIMER2_CLK(1) +#define APCI3120_MODE_TIMER2_CLK_EOC APCI3120_MODE_TIMER2_CLK(2) +#define APCI3120_MODE_TIMER2_CLK_EOS APCI3120_MODE_TIMER2_CLK(3) +#define APCI3120_MODE_TIMER2_CLK_MASK APCI3120_MODE_TIMER2_CLK(3) +#define APCI3120_MODE_TIMER2_AS(x) (((x) & 0x3) << 4) +#define APCI3120_MODE_TIMER2_AS_TIMER APCI3120_MODE_TIMER2_AS(0) +#define APCI3120_MODE_TIMER2_AS_COUNTER APCI3120_MODE_TIMER2_AS(1) +#define APCI3120_MODE_TIMER2_AS_WDOG APCI3120_MODE_TIMER2_AS(2) +#define APCI3120_MODE_TIMER2_AS_MASK APCI3120_MODE_TIMER2_AS(3) +#define APCI3120_MODE_SCAN_ENA BIT(3) +#define APCI3120_MODE_TIMER2_IRQ_ENA BIT(2) +#define APCI3120_MODE_EOS_IRQ_ENA BIT(1) +#define APCI3120_MODE_EOC_IRQ_ENA BIT(0) /* * PCI BAR 2 register map (devpriv->addon) @@ -94,8 +96,8 @@ #define APCI3120_ADDON_ADDR_REG 0x00 #define APCI3120_ADDON_DATA_REG 0x02 #define APCI3120_ADDON_CTRL_REG 0x04 -#define APCI3120_ADDON_CTRL_AMWEN_ENA (1 << 1) -#define APCI3120_ADDON_CTRL_A2P_FIFO_ENA (1 << 0) +#define APCI3120_ADDON_CTRL_AMWEN_ENA BIT(1) +#define APCI3120_ADDON_CTRL_A2P_FIFO_ENA BIT(0) /* * Board revisions @@ -502,11 +504,6 @@ static irqreturn_t apci3120_interrupt(int irq, void *d) if (int_amcc & TARGET_ABORT_INT) dev_err(dev->class_dev, "AMCC IRQ - TARGET DMA ABORT!\n"); - if ((status & APCI3120_STATUS_EOC_INT) == 0 && - (devpriv->mode & APCI3120_MODE_EOC_IRQ_ENA)) { - /* nothing to do... EOC mode is not currently used */ - } - if ((status & APCI3120_STATUS_EOS_INT) && (devpriv->mode & APCI3120_MODE_EOS_IRQ_ENA)) { unsigned short val; diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c index bef6efc84efd..995096c78844 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c +++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c @@ -27,9 +27,9 @@ #include "../comedi_pci.h" -#define CONV_UNIT_NS (1 << 0) -#define CONV_UNIT_US (1 << 1) -#define CONV_UNIT_MS (1 << 2) +#define CONV_UNIT_NS BIT(0) +#define CONV_UNIT_US BIT(1) +#define CONV_UNIT_MS BIT(2) static const struct comedi_lrange apci3xxx_ai_range = { 8, { diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c b/drivers/staging/comedi/drivers/adl_pci6208.c index 7ed3fd6fbd3e..ad7e7c4a5232 100644 --- a/drivers/staging/comedi/drivers/adl_pci6208.c +++ b/drivers/staging/comedi/drivers/adl_pci6208.c @@ -41,7 +41,7 @@ */ #define PCI6208_AO_CONTROL(x) (0x00 + (2 * (x))) #define PCI6208_AO_STATUS 0x00 -#define PCI6208_AO_STATUS_DATA_SEND (1 << 0) +#define PCI6208_AO_STATUS_DATA_SEND BIT(0) #define PCI6208_DIO 0x40 #define PCI6208_DIO_DO_MASK (0x0f) #define PCI6208_DIO_DO_SHIFT (0) diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c index c9df3afe97f6..01d2ee931b28 100644 --- a/drivers/staging/comedi/drivers/adl_pci9111.c +++ b/drivers/staging/comedi/drivers/adl_pci9111.c @@ -1,68 +1,52 @@ /* - -comedi/drivers/adl_pci9111.c - -Hardware driver for PCI9111 ADLink cards: - -PCI-9111HR - -Copyright (C) 2002-2005 Emmanuel Pacaud - -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. -*/ + * adl_pci9111.c + * Hardware driver for PCI9111 ADLink cards: PCI-9111HR + * Copyright (C) 2002-2005 Emmanuel Pacaud + * + * 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: adl_pci9111 -Description: Adlink PCI-9111HR -Author: Emmanuel Pacaud -Devices: [ADLink] PCI-9111HR (adl_pci9111) -Status: experimental - -Supports: - - - ai_insn read - - ao_insn read/write - - di_insn read - - do_insn read/write - - ai_do_cmd mode with the following sources: - - - start_src TRIG_NOW - - scan_begin_src TRIG_FOLLOW TRIG_TIMER TRIG_EXT - - convert_src TRIG_TIMER TRIG_EXT - - scan_end_src TRIG_COUNT - - stop_src TRIG_COUNT TRIG_NONE - -The scanned channels must be consecutive and start from 0. They must -all have the same range and aref. - -Configuration options: not applicable, uses PCI auto config -*/ + * Driver: adl_pci9111 + * Description: Adlink PCI-9111HR + * Devices: [ADLink] PCI-9111HR (adl_pci9111) + * Author: Emmanuel Pacaud + * Status: experimental + * + * Configuration options: not applicable, uses PCI auto config + * + * Supports: + * - ai_insn read + * - ao_insn read/write + * - di_insn read + * - do_insn read/write + * - ai_do_cmd mode with the following sources: + * - start_src TRIG_NOW + * - scan_begin_src TRIG_FOLLOW TRIG_TIMER TRIG_EXT + * - convert_src TRIG_TIMER TRIG_EXT + * - scan_end_src TRIG_COUNT + * - stop_src TRIG_COUNT TRIG_NONE + * + * The scanned channels must be consecutive and start from 0. They must + * all have the same range and aref. + */ /* -CHANGELOG: - -2005/02/17 Extend AI streaming capabilities. Now, scan_begin_arg can be -a multiple of chanlist_len*convert_arg. -2002/02/19 Fixed the two's complement conversion in pci9111_(hr_)ai_get_data. -2002/02/18 Added external trigger support for analog input. - -TODO: - - - Really test implemented functionality. - - Add support for the PCI-9111DG with a probe routine to identify - the card type (perhaps with the help of the channel number readback - of the A/D Data register). - - Add external multiplexer support. - -*/ + * TODO: + * - Really test implemented functionality. + * - Add support for the PCI-9111DG with a probe routine to identify + * the card type (perhaps with the help of the channel number readback + * of the A/D Data register). + * - Add external multiplexer support. + */ #include #include @@ -89,23 +73,24 @@ TODO: #define PCI9111_EDIO_REG 0x04 #define PCI9111_AI_CHANNEL_REG 0x06 #define PCI9111_AI_RANGE_STAT_REG 0x08 -#define PCI9111_AI_STAT_AD_BUSY (1 << 7) -#define PCI9111_AI_STAT_FF_FF (1 << 6) -#define PCI9111_AI_STAT_FF_HF (1 << 5) -#define PCI9111_AI_STAT_FF_EF (1 << 4) -#define PCI9111_AI_RANGE_MASK (7 << 0) +#define PCI9111_AI_STAT_AD_BUSY BIT(7) +#define PCI9111_AI_STAT_FF_FF BIT(6) +#define PCI9111_AI_STAT_FF_HF BIT(5) +#define PCI9111_AI_STAT_FF_EF BIT(4) +#define PCI9111_AI_RANGE(x) (((x) & 0x7) << 0) +#define PCI9111_AI_RANGE_MASK PCI9111_AI_RANGE(7) #define PCI9111_AI_TRIG_CTRL_REG 0x0a -#define PCI9111_AI_TRIG_CTRL_TRGEVENT (1 << 5) -#define PCI9111_AI_TRIG_CTRL_POTRG (1 << 4) -#define PCI9111_AI_TRIG_CTRL_PTRG (1 << 3) -#define PCI9111_AI_TRIG_CTRL_ETIS (1 << 2) -#define PCI9111_AI_TRIG_CTRL_TPST (1 << 1) -#define PCI9111_AI_TRIG_CTRL_ASCAN (1 << 0) +#define PCI9111_AI_TRIG_CTRL_TRGEVENT BIT(5) +#define PCI9111_AI_TRIG_CTRL_POTRG BIT(4) +#define PCI9111_AI_TRIG_CTRL_PTRG BIT(3) +#define PCI9111_AI_TRIG_CTRL_ETIS BIT(2) +#define PCI9111_AI_TRIG_CTRL_TPST BIT(1) +#define PCI9111_AI_TRIG_CTRL_ASCAN BIT(0) #define PCI9111_INT_CTRL_REG 0x0c -#define PCI9111_INT_CTRL_ISC2 (1 << 3) -#define PCI9111_INT_CTRL_FFEN (1 << 2) -#define PCI9111_INT_CTRL_ISC1 (1 << 1) -#define PCI9111_INT_CTRL_ISC0 (1 << 0) +#define PCI9111_INT_CTRL_ISC2 BIT(3) +#define PCI9111_INT_CTRL_FFEN BIT(2) +#define PCI9111_INT_CTRL_ISC1 BIT(1) +#define PCI9111_INT_CTRL_ISC0 BIT(0) #define PCI9111_SOFT_TRIG_REG 0x0e #define PCI9111_8254_BASE_REG 0x40 #define PCI9111_INT_CLR_REG 0x48 @@ -139,21 +124,21 @@ struct pci9111_private_data { }; static void plx9050_interrupt_control(unsigned long io_base, - bool LINTi1_enable, - bool LINTi1_active_high, - bool LINTi2_enable, - bool LINTi2_active_high, + bool int1_enable, + bool int1_active_high, + bool int2_enable, + bool int2_active_high, bool interrupt_enable) { int flags = 0; - if (LINTi1_enable) + if (int1_enable) flags |= PLX9052_INTCSR_LI1ENAB; - if (LINTi1_active_high) + if (int1_active_high) flags |= PLX9052_INTCSR_LI1POL; - if (LINTi2_enable) + if (int2_enable) flags |= PLX9052_INTCSR_LI2ENAB; - if (LINTi2_active_high) + if (int2_active_high) flags |= PLX9052_INTCSR_LI2POL; if (interrupt_enable) @@ -363,6 +348,7 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev, struct pci9111_private_data *dev_private = dev->private; struct comedi_cmd *cmd = &s->async->cmd; unsigned int last_chan = CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]); + unsigned int range0 = CR_RANGE(cmd->chanlist[0]); unsigned int trig = 0; /* Set channel scan limit */ @@ -374,11 +360,8 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev, outb(last_chan, dev->iobase + PCI9111_AI_CHANNEL_REG); - /* Set gain */ - /* This is the same gain on every channel */ - - outb(CR_RANGE(cmd->chanlist[0]) & PCI9111_AI_RANGE_MASK, - dev->iobase + PCI9111_AI_RANGE_STAT_REG); + /* Set gain - all channels use the same range */ + outb(PCI9111_AI_RANGE(range0), dev->iobase + PCI9111_AI_RANGE_STAT_REG); /* Set timer pacer */ dev_private->scan_delay = 0; @@ -434,14 +417,14 @@ static void pci9111_handle_fifo_half_full(struct comedi_device *dev, { struct pci9111_private_data *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; + unsigned short *buf = devpriv->ai_bounce_buffer; unsigned int samples; samples = comedi_nsamples_left(s, PCI9111_FIFO_HALF_SIZE); - insw(dev->iobase + PCI9111_AI_FIFO_REG, - devpriv->ai_bounce_buffer, samples); + insw(dev->iobase + PCI9111_AI_FIFO_REG, buf, samples); if (devpriv->scan_delay < 1) { - comedi_buf_write_samples(s, devpriv->ai_bounce_buffer, samples); + comedi_buf_write_samples(s, buf, samples); } else { unsigned int pos = 0; unsigned int to_read; @@ -454,9 +437,7 @@ static void pci9111_handle_fifo_half_full(struct comedi_device *dev, if (to_read > samples - pos) to_read = samples - pos; - comedi_buf_write_samples(s, - devpriv->ai_bounce_buffer + pos, - to_read); + comedi_buf_write_samples(s, buf + pos, to_read); } else { to_read = devpriv->chunk_num_samples - devpriv->chunk_counter; @@ -571,7 +552,7 @@ static int pci9111_ai_insn_read(struct comedi_device *dev, status = inb(dev->iobase + PCI9111_AI_RANGE_STAT_REG); if ((status & PCI9111_AI_RANGE_MASK) != range) { - outb(range & PCI9111_AI_RANGE_MASK, + outb(PCI9111_AI_RANGE(range), dev->iobase + PCI9111_AI_RANGE_STAT_REG); } diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c index fb3043dcfff1..0dff1dbb53fb 100644 --- a/drivers/staging/comedi/drivers/adl_pci9118.c +++ b/drivers/staging/comedi/drivers/adl_pci9118.c @@ -83,12 +83,6 @@ #include "amcc_s5933.h" #include "comedi_8254.h" -#define IORANGE_9118 64 /* I hope */ -#define PCI9118_CHANLEN 255 /* - * len of chanlist, some source say 256, - * but reality looks like 255 :-( - */ - /* * PCI BAR2 Register map (dev->iobase) */ @@ -96,24 +90,24 @@ #define PCI9118_AI_FIFO_REG 0x10 #define PCI9118_AO_REG(x) (0x10 + ((x) * 4)) #define PCI9118_AI_STATUS_REG 0x18 -#define PCI9118_AI_STATUS_NFULL (1 << 8) /* 0=FIFO full (fatal) */ -#define PCI9118_AI_STATUS_NHFULL (1 << 7) /* 0=FIFO half full */ -#define PCI9118_AI_STATUS_NEPTY (1 << 6) /* 0=FIFO empty */ -#define PCI9118_AI_STATUS_ACMP (1 << 5) /* 1=about trigger complete */ -#define PCI9118_AI_STATUS_DTH (1 << 4) /* 1=ext. digital trigger */ -#define PCI9118_AI_STATUS_BOVER (1 << 3) /* 1=burst overrun (fatal) */ -#define PCI9118_AI_STATUS_ADOS (1 << 2) /* 1=A/D over speed (warn) */ -#define PCI9118_AI_STATUS_ADOR (1 << 1) /* 1=A/D overrun (fatal) */ -#define PCI9118_AI_STATUS_ADRDY (1 << 0) /* 1=A/D ready */ +#define PCI9118_AI_STATUS_NFULL BIT(8) /* 0=FIFO full (fatal) */ +#define PCI9118_AI_STATUS_NHFULL BIT(7) /* 0=FIFO half full */ +#define PCI9118_AI_STATUS_NEPTY BIT(6) /* 0=FIFO empty */ +#define PCI9118_AI_STATUS_ACMP BIT(5) /* 1=about trigger complete */ +#define PCI9118_AI_STATUS_DTH BIT(4) /* 1=ext. digital trigger */ +#define PCI9118_AI_STATUS_BOVER BIT(3) /* 1=burst overrun (fatal) */ +#define PCI9118_AI_STATUS_ADOS BIT(2) /* 1=A/D over speed (warn) */ +#define PCI9118_AI_STATUS_ADOR BIT(1) /* 1=A/D overrun (fatal) */ +#define PCI9118_AI_STATUS_ADRDY BIT(0) /* 1=A/D ready */ #define PCI9118_AI_CTRL_REG 0x18 -#define PCI9118_AI_CTRL_UNIP (1 << 7) /* 1=unipolar */ -#define PCI9118_AI_CTRL_DIFF (1 << 6) /* 1=differential inputs */ -#define PCI9118_AI_CTRL_SOFTG (1 << 5) /* 1=8254 software gate */ -#define PCI9118_AI_CTRL_EXTG (1 << 4) /* 1=8254 TGIN(pin 46) gate */ -#define PCI9118_AI_CTRL_EXTM (1 << 3) /* 1=ext. trigger (pin 44) */ -#define PCI9118_AI_CTRL_TMRTR (1 << 2) /* 1=8254 is trigger source */ -#define PCI9118_AI_CTRL_INT (1 << 1) /* 1=enable interrupt */ -#define PCI9118_AI_CTRL_DMA (1 << 0) /* 1=enable DMA */ +#define PCI9118_AI_CTRL_UNIP BIT(7) /* 1=unipolar */ +#define PCI9118_AI_CTRL_DIFF BIT(6) /* 1=differential inputs */ +#define PCI9118_AI_CTRL_SOFTG BIT(5) /* 1=8254 software gate */ +#define PCI9118_AI_CTRL_EXTG BIT(4) /* 1=8254 TGIN(pin 46) gate */ +#define PCI9118_AI_CTRL_EXTM BIT(3) /* 1=ext. trigger (pin 44) */ +#define PCI9118_AI_CTRL_TMRTR BIT(2) /* 1=8254 is trigger source */ +#define PCI9118_AI_CTRL_INT BIT(1) /* 1=enable interrupt */ +#define PCI9118_AI_CTRL_DMA BIT(0) /* 1=enable DMA */ #define PCI9118_DIO_REG 0x1c #define PCI9118_SOFTTRG_REG 0x20 #define PCI9118_AI_CHANLIST_REG 0x24 @@ -122,27 +116,25 @@ #define PCI9118_AI_BURST_NUM_REG 0x28 #define PCI9118_AI_AUTOSCAN_MODE_REG 0x2c #define PCI9118_AI_CFG_REG 0x30 -#define PCI9118_AI_CFG_PDTRG (1 << 7) /* 1=positive trigger */ -#define PCI9118_AI_CFG_PETRG (1 << 6) /* 1=positive ext. trigger */ -#define PCI9118_AI_CFG_BSSH (1 << 5) /* 1=with sample & hold */ -#define PCI9118_AI_CFG_BM (1 << 4) /* 1=burst mode */ -#define PCI9118_AI_CFG_BS (1 << 3) /* 1=burst mode start */ -#define PCI9118_AI_CFG_PM (1 << 2) /* 1=post trigger */ -#define PCI9118_AI_CFG_AM (1 << 1) /* 1=about trigger */ -#define PCI9118_AI_CFG_START (1 << 0) /* 1=trigger start */ +#define PCI9118_AI_CFG_PDTRG BIT(7) /* 1=positive trigger */ +#define PCI9118_AI_CFG_PETRG BIT(6) /* 1=positive ext. trigger */ +#define PCI9118_AI_CFG_BSSH BIT(5) /* 1=with sample & hold */ +#define PCI9118_AI_CFG_BM BIT(4) /* 1=burst mode */ +#define PCI9118_AI_CFG_BS BIT(3) /* 1=burst mode start */ +#define PCI9118_AI_CFG_PM BIT(2) /* 1=post trigger */ +#define PCI9118_AI_CFG_AM BIT(1) /* 1=about trigger */ +#define PCI9118_AI_CFG_START BIT(0) /* 1=trigger start */ #define PCI9118_FIFO_RESET_REG 0x34 #define PCI9118_INT_CTRL_REG 0x38 -#define PCI9118_INT_CTRL_TIMER (1 << 3) /* timer interrupt */ -#define PCI9118_INT_CTRL_ABOUT (1 << 2) /* about trigger complete */ -#define PCI9118_INT_CTRL_HFULL (1 << 1) /* A/D FIFO half full */ -#define PCI9118_INT_CTRL_DTRG (1 << 0) /* ext. digital trigger */ +#define PCI9118_INT_CTRL_TIMER BIT(3) /* timer interrupt */ +#define PCI9118_INT_CTRL_ABOUT BIT(2) /* about trigger complete */ +#define PCI9118_INT_CTRL_HFULL BIT(1) /* A/D FIFO half full */ +#define PCI9118_INT_CTRL_DTRG BIT(0) /* ext. digital trigger */ #define START_AI_EXT 0x01 /* start measure on external trigger */ #define STOP_AI_EXT 0x02 /* stop measure on external trigger */ #define STOP_AI_INT 0x08 /* stop measure on internal trigger */ -#define PCI9118_HALF_FIFO_SZ (1024 / 2) - static const struct comedi_lrange pci9118_ai_range = { 8, { BIP_RANGE(5), @@ -169,11 +161,6 @@ static const struct comedi_lrange pci9118hg_ai_range = { } }; -#define PCI9118_BIPOLAR_RANGES 4 /* - * used for test on mixture - * of BIP/UNI ranges - */ - enum pci9118_boardid { BOARD_PCI9118DG, BOARD_PCI9118HG, @@ -296,51 +283,44 @@ static void pci9118_ai_reset_fifo(struct comedi_device *dev) outl(0, dev->iobase + PCI9118_FIFO_RESET_REG); } -static int check_channel_list(struct comedi_device *dev, - struct comedi_subdevice *s, int n_chan, - unsigned int *chanlist, int frontadd, int backadd) +static int pci9118_ai_check_chanlist(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_cmd *cmd) { struct pci9118_private *devpriv = dev->private; - unsigned int i, differencial = 0, bipolar = 0; + unsigned int range0 = CR_RANGE(cmd->chanlist[0]); + unsigned int aref0 = CR_AREF(cmd->chanlist[0]); + int i; - /* correct channel and range number check itself comedi/range.c */ - if (n_chan < 1) { - dev_err(dev->class_dev, "range/channel list is empty!\n"); + /* single channel scans are always ok */ + if (cmd->chanlist_len == 1) return 0; - } - if ((frontadd + n_chan + backadd) > s->len_chanlist) { - dev_err(dev->class_dev, - "range/channel list is too long for actual configuration!\n"); - return 0; - } - if (CR_AREF(chanlist[0]) == AREF_DIFF) - differencial = 1; /* all input must be diff */ - if (CR_RANGE(chanlist[0]) < PCI9118_BIPOLAR_RANGES) - bipolar = 1; /* all input must be bipolar */ - if (n_chan > 1) - for (i = 1; i < n_chan; i++) { /* check S.E/diff */ - if ((CR_AREF(chanlist[i]) == AREF_DIFF) != - (differencial)) { - dev_err(dev->class_dev, - "Differential and single ended inputs can't be mixed!\n"); - return 0; - } - if ((CR_RANGE(chanlist[i]) < PCI9118_BIPOLAR_RANGES) != - (bipolar)) { - dev_err(dev->class_dev, - "Bipolar and unipolar ranges can't be mixed!\n"); - return 0; - } - if (!devpriv->usemux && differencial && - (CR_CHAN(chanlist[i]) >= (s->n_chan / 2))) { - dev_err(dev->class_dev, - "AREF_DIFF is only available for the first 8 channels!\n"); - return 0; - } + for (i = 1; i < cmd->chanlist_len; i++) { + unsigned int chan = CR_CHAN(cmd->chanlist[i]); + unsigned int range = CR_RANGE(cmd->chanlist[i]); + unsigned int aref = CR_AREF(cmd->chanlist[i]); + + if (aref != aref0) { + dev_err(dev->class_dev, + "Differential and single ended inputs can't be mixed!\n"); + return -EINVAL; } + if (comedi_range_is_bipolar(s, range) != + comedi_range_is_bipolar(s, range0)) { + dev_err(dev->class_dev, + "Bipolar and unipolar ranges can't be mixed!\n"); + return -EINVAL; + } + if (!devpriv->usemux && aref == AREF_DIFF && + (chan >= (s->n_chan / 2))) { + dev_err(dev->class_dev, + "AREF_DIFF is only available for the first 8 channels!\n"); + return -EINVAL; + } + } - return 1; + return 0; } static void pci9118_set_chanlist(struct comedi_device *dev, @@ -406,8 +386,8 @@ static void pci9118_set_chanlist(struct comedi_device *dev, /* udelay(100); important delay, or first sample will be crippled */ } -static void interrupt_pci9118_ai_mode4_switch(struct comedi_device *dev, - unsigned int next_buf) +static void pci9118_ai_mode4_switch(struct comedi_device *dev, + unsigned int next_buf) { struct pci9118_private *devpriv = dev->private; struct pci9118_dmabuf *dmabuf = &devpriv->dmabuf[next_buf]; @@ -421,9 +401,9 @@ static void interrupt_pci9118_ai_mode4_switch(struct comedi_device *dev, outl(devpriv->ai_cfg, dev->iobase + PCI9118_AI_CFG_REG); } -static unsigned int valid_samples_in_act_dma_buf(struct comedi_device *dev, - struct comedi_subdevice *s, - unsigned int n_raw_samples) +static unsigned int pci9118_ai_samples_ready(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned int n_raw_samples) { struct pci9118_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; @@ -477,7 +457,7 @@ static unsigned int valid_samples_in_act_dma_buf(struct comedi_device *dev, return n_samples; } -static void move_block_from_dma(struct comedi_device *dev, +static void pci9118_ai_dma_xfer(struct comedi_device *dev, struct comedi_subdevice *s, unsigned short *dma_buffer, unsigned int n_raw_samples) @@ -634,8 +614,8 @@ static void pci9118_ai_munge(struct comedi_device *dev, } } -static void interrupt_pci9118_ai_onesample(struct comedi_device *dev, - struct comedi_subdevice *s) +static void pci9118_ai_get_onesample(struct comedi_device *dev, + struct comedi_subdevice *s) { struct pci9118_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; @@ -651,8 +631,8 @@ static void interrupt_pci9118_ai_onesample(struct comedi_device *dev, } } -static void interrupt_pci9118_ai_dma(struct comedi_device *dev, - struct comedi_subdevice *s) +static void pci9118_ai_get_dma(struct comedi_device *dev, + struct comedi_subdevice *s) { struct pci9118_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; @@ -662,21 +642,19 @@ static void interrupt_pci9118_ai_dma(struct comedi_device *dev, bool more_dma; /* determine whether more DMA buffers to do after this one */ - n_valid = valid_samples_in_act_dma_buf(dev, s, n_all); + n_valid = pci9118_ai_samples_ready(dev, s, n_all); more_dma = n_valid < comedi_nsamples_left(s, n_valid + 1); /* switch DMA buffers and restart DMA if double buffering */ if (more_dma && devpriv->dma_doublebuf) { devpriv->dma_actbuf = 1 - devpriv->dma_actbuf; pci9118_amcc_setup_dma(dev, devpriv->dma_actbuf); - if (devpriv->ai_do == 4) { - interrupt_pci9118_ai_mode4_switch(dev, - devpriv->dma_actbuf); - } + if (devpriv->ai_do == 4) + pci9118_ai_mode4_switch(dev, devpriv->dma_actbuf); } if (n_all) - move_block_from_dma(dev, s, dmabuf->virt, n_all); + pci9118_ai_dma_xfer(dev, s, dmabuf->virt, n_all); if (!devpriv->ai_neverending) { if (s->async->scans_done >= cmd->stop_arg) @@ -690,7 +668,7 @@ static void interrupt_pci9118_ai_dma(struct comedi_device *dev, if (more_dma && !devpriv->dma_doublebuf) { pci9118_amcc_setup_dma(dev, 0); if (devpriv->ai_do == 4) - interrupt_pci9118_ai_mode4_switch(dev, 0); + pci9118_ai_mode4_switch(dev, 0); } } @@ -779,9 +757,9 @@ static irqreturn_t pci9118_interrupt(int irq, void *d) } if (devpriv->usedma) - interrupt_pci9118_ai_dma(dev, s); + pci9118_ai_get_dma(dev, s); else - interrupt_pci9118_ai_onesample(dev, s); + pci9118_ai_get_onesample(dev, s); interrupt_exit: comedi_handle_events(dev, s); @@ -816,17 +794,18 @@ static int pci9118_ai_inttrig(struct comedi_device *dev, return 1; } -static int Compute_and_setup_dma(struct comedi_device *dev, - struct comedi_subdevice *s) +static int pci9118_ai_setup_dma(struct comedi_device *dev, + struct comedi_subdevice *s) { struct pci9118_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; struct pci9118_dmabuf *dmabuf0 = &devpriv->dmabuf[0]; struct pci9118_dmabuf *dmabuf1 = &devpriv->dmabuf[1]; - unsigned int dmalen0, dmalen1, i; + unsigned int dmalen0 = dmabuf0->size; + unsigned int dmalen1 = dmabuf1->size; + unsigned int scan_bytes = devpriv->ai_n_realscanlen * + comedi_bytes_per_sample(s); - dmalen0 = dmabuf0->size; - dmalen1 = dmabuf1->size; /* isn't output buff smaller that our DMA buff? */ if (dmalen0 > s->async->prealloc_bufsz) { /* align to 32bit down */ @@ -839,15 +818,15 @@ static int Compute_and_setup_dma(struct comedi_device *dev, /* we want wake up every scan? */ if (devpriv->ai_flags & CMDF_WAKE_EOS) { - if (dmalen0 < (devpriv->ai_n_realscanlen << 1)) { + if (dmalen0 < scan_bytes) { /* uff, too short DMA buffer, disable EOS support! */ devpriv->ai_flags &= (~CMDF_WAKE_EOS); dev_info(dev->class_dev, "WAR: DMA0 buf too short, can't support CMDF_WAKE_EOS (%d<%d)\n", - dmalen0, devpriv->ai_n_realscanlen << 1); + dmalen0, scan_bytes); } else { /* short first DMA buffer to one scan */ - dmalen0 = devpriv->ai_n_realscanlen << 1; + dmalen0 = scan_bytes; if (dmalen0 < 4) { dev_info(dev->class_dev, "ERR: DMA0 buf len bug? (%d<4)\n", @@ -857,15 +836,15 @@ static int Compute_and_setup_dma(struct comedi_device *dev, } } if (devpriv->ai_flags & CMDF_WAKE_EOS) { - if (dmalen1 < (devpriv->ai_n_realscanlen << 1)) { + if (dmalen1 < scan_bytes) { /* uff, too short DMA buffer, disable EOS support! */ devpriv->ai_flags &= (~CMDF_WAKE_EOS); dev_info(dev->class_dev, "WAR: DMA1 buf too short, can't support CMDF_WAKE_EOS (%d<%d)\n", - dmalen1, devpriv->ai_n_realscanlen << 1); + dmalen1, scan_bytes); } else { /* short second DMA buffer to one scan */ - dmalen1 = devpriv->ai_n_realscanlen << 1; + dmalen1 = scan_bytes; if (dmalen1 < 4) { dev_info(dev->class_dev, "ERR: DMA1 buf len bug? (%d<4)\n", @@ -877,45 +856,39 @@ static int Compute_and_setup_dma(struct comedi_device *dev, /* transfer without CMDF_WAKE_EOS */ if (!(devpriv->ai_flags & CMDF_WAKE_EOS)) { + unsigned int tmp; + /* if it's possible then align DMA buffers to length of scan */ - i = dmalen0; - dmalen0 = - (dmalen0 / (devpriv->ai_n_realscanlen << 1)) * - (devpriv->ai_n_realscanlen << 1); + tmp = dmalen0; + dmalen0 = (dmalen0 / scan_bytes) * scan_bytes; dmalen0 &= ~3L; if (!dmalen0) - dmalen0 = i; /* uff. very long scan? */ - i = dmalen1; - dmalen1 = - (dmalen1 / (devpriv->ai_n_realscanlen << 1)) * - (devpriv->ai_n_realscanlen << 1); + dmalen0 = tmp; /* uff. very long scan? */ + tmp = dmalen1; + dmalen1 = (dmalen1 / scan_bytes) * scan_bytes; dmalen1 &= ~3L; if (!dmalen1) - dmalen1 = i; /* uff. very long scan? */ + dmalen1 = tmp; /* uff. very long scan? */ /* * if measure isn't neverending then test, if it fits whole * into one or two DMA buffers */ if (!devpriv->ai_neverending) { + unsigned long long scanlen; + + scanlen = (unsigned long long)scan_bytes * + cmd->stop_arg; + /* fits whole measure into one DMA buffer? */ - if (dmalen0 > - ((devpriv->ai_n_realscanlen << 1) * - cmd->stop_arg)) { - dmalen0 = - (devpriv->ai_n_realscanlen << 1) * - cmd->stop_arg; + if (dmalen0 > scanlen) { + dmalen0 = scanlen; dmalen0 &= ~3L; - } else { /* - * fits whole measure into - * two DMA buffer? - */ - if (dmalen1 > - ((devpriv->ai_n_realscanlen << 1) * - cmd->stop_arg - dmalen0)) - dmalen1 = - (devpriv->ai_n_realscanlen << 1) * - cmd->stop_arg - dmalen0; - dmalen1 &= ~3L; + } else { + /* fits whole measure into two DMA buffer? */ + if (dmalen1 > (scanlen - dmalen0)) { + dmalen1 = scanlen - dmalen0; + dmalen1 &= ~3L; + } } } } @@ -945,6 +918,7 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) struct comedi_8254 *pacer = dev->pacer; struct comedi_cmd *cmd = &s->async->cmd; unsigned int addchans = 0; + unsigned int scanlen; devpriv->ai12_startstop = 0; devpriv->ai_flags = cmd->flags; @@ -1030,19 +1004,20 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) } } /* well, we now know what must be all added */ - devpriv->ai_n_realscanlen = /* - * what we must take from card in real - * to have cmd->scan_end_arg on output? - */ - (devpriv->ai_add_front + cmd->chanlist_len + - devpriv->ai_add_back) * (cmd->scan_end_arg / - cmd->chanlist_len); + scanlen = devpriv->ai_add_front + cmd->chanlist_len + + devpriv->ai_add_back; + /* + * what we must take from card in real to have cmd->scan_end_arg + * on output? + */ + devpriv->ai_n_realscanlen = scanlen * + (cmd->scan_end_arg / cmd->chanlist_len); - /* check and setup channel list */ - if (!check_channel_list(dev, s, cmd->chanlist_len, - cmd->chanlist, devpriv->ai_add_front, - devpriv->ai_add_back)) + if (scanlen > s->len_chanlist) { + dev_err(dev->class_dev, + "range/channel list is too long for actual configuration!\n"); return -EINVAL; + } /* * Configure analog input and load the chanlist. @@ -1141,7 +1116,7 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) devpriv->ai_act_dmapos = 0; if (devpriv->usedma) { - Compute_and_setup_dma(dev, s); + pci9118_ai_setup_dma(dev, s); outl(0x02000000 | AINT_WRITE_COMPL, devpriv->iobase_a + AMCC_OP_REG_INTCSR); @@ -1205,9 +1180,6 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev, if (cmd->start_src == TRIG_EXT && cmd->scan_begin_src == TRIG_EXT) err |= -EINVAL; - if (cmd->start_src == TRIG_INT && cmd->scan_begin_src == TRIG_INT) - err |= -EINVAL; - if ((cmd->scan_begin_src & (TRIG_TIMER | TRIG_EXT)) && (!(cmd->convert_src & (TRIG_TIMER | TRIG_NOW)))) err |= -EINVAL; @@ -1315,10 +1287,13 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev, if (err) return 4; + /* Step 5: check channel list if it exists */ + if (cmd->chanlist) - if (!check_channel_list(dev, s, cmd->chanlist_len, - cmd->chanlist, 0, 0)) - return 5; /* incorrect channels list */ + err |= pci9118_ai_check_chanlist(dev, s, cmd); + + if (err) + return 5; return 0; } @@ -1608,7 +1583,7 @@ static int pci9118_common_attach(struct comedi_device *dev, if (dev->irq) { dev->read_subdev = s; s->subdev_flags |= SDF_CMD_READ; - s->len_chanlist = PCI9118_CHANLEN; + s->len_chanlist = 255; s->do_cmdtest = pci9118_ai_cmdtest; s->do_cmd = pci9118_ai_cmd; s->cancel = pci9118_ai_cancel; diff --git a/drivers/staging/comedi/drivers/adq12b.c b/drivers/staging/comedi/drivers/adq12b.c index bc5f97f50f9a..315050454c26 100644 --- a/drivers/staging/comedi/drivers/adq12b.c +++ b/drivers/staging/comedi/drivers/adq12b.c @@ -1,75 +1,59 @@ /* - comedi/drivers/adq12b.c - driver for MicroAxial ADQ12-B data acquisition and control card + * adq12b.c + * Driver for MicroAxial ADQ12-B data acquisition and control card + * written by jeremy theler + * instituto balseiro + * commission nacional de energia atomica + * universidad nacional de cuyo + * argentina + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000 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 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. -*/ /* -Driver: adq12b -Description: driver for MicroAxial ADQ12-B data acquisition and control card -Devices: [MicroAxial] ADQ12-B (adq12b) -Author: jeremy theler -Updated: Thu, 21 Feb 2008 02:56:27 -0300 -Status: works - -Driver for the acquisition card ADQ12-B (without any add-on). - - - Analog input is subdevice 0 (16 channels single-ended or 8 differential) - - Digital input is subdevice 1 (5 channels) - - Digital output is subdevice 1 (8 channels) - - The PACER is not supported in this version - -If you do not specify any options, they will default to - - # comedi_config /dev/comedi0 adq12b 0x300,0,0 - - option 1: I/O base address. The following table is provided as a help - of the hardware jumpers. - - address jumper JADR - 0x300 1 (factory default) - 0x320 2 - 0x340 3 - 0x360 4 - 0x380 5 - 0x3A0 6 - - option 2: unipolar/bipolar ADC selection: 0 -> bipolar, 1 -> unipolar - - selection comedi_config option JUB - bipolar 0 2-3 (factory default) - unipolar 1 1-2 - - option 3: single-ended/differential AI selection: 0 -> SE, 1 -> differential - - selection comedi_config option JCHA JCHB - single-ended 0 1-2 1-2 (factory default) - differential 1 2-3 2-3 - - written by jeremy theler - - instituto balseiro - commission nacional de energia atomica - universidad nacional de cuyo - argentina - - 21-feb-2008 - + changed supported devices string (missused the [] and ()) - - 13-oct-2007 - + first try -*/ + * Driver: adq12b + * Description: Driver for MicroAxial ADQ12-B data acquisition and control card + * Devices: [MicroAxial] ADQ12-B (adq12b) + * Author: jeremy theler + * Updated: Thu, 21 Feb 2008 02:56:27 -0300 + * Status: works + * + * Configuration options: + * [0] - I/O base address (set with hardware jumpers) + * address jumper JADR + * 0x300 1 (factory default) + * 0x320 2 + * 0x340 3 + * 0x360 4 + * 0x380 5 + * 0x3A0 6 + * [1] - Analog Input unipolar/bipolar selection + * selection option JUB + * bipolar 0 2-3 (factory default) + * unipolar 1 1-2 + * [2] - Analog Input single-ended/differential selection + * selection option JCHA JCHB + * single-ended 0 1-2 1-2 (factory default) + * differential 1 2-3 2-3 + * + * Driver for the acquisition card ADQ12-B (without any add-on). + * + * - Analog input is subdevice 0 (16 channels single-ended or 8 differential) + * - Digital input is subdevice 1 (5 channels) + * - Digital output is subdevice 1 (8 channels) + * - The PACER is not supported in this version + */ #include #include @@ -78,14 +62,14 @@ If you do not specify any options, they will default to /* address scheme (page 2.17 of the manual) */ #define ADQ12B_CTREG 0x00 -#define ADQ12B_CTREG_MSKP (1 << 7) /* enable pacer interrupt */ -#define ADQ12B_CTREG_GTP (1 << 6) /* enable pacer */ +#define ADQ12B_CTREG_MSKP BIT(7) /* enable pacer interrupt */ +#define ADQ12B_CTREG_GTP BIT(6) /* enable pacer */ #define ADQ12B_CTREG_RANGE(x) ((x) << 4) #define ADQ12B_CTREG_CHAN(x) ((x) << 0) #define ADQ12B_STINR 0x00 -#define ADQ12B_STINR_OUT2 (1 << 7) /* timer 2 output state */ -#define ADQ12B_STINR_OUTP (1 << 6) /* pacer output state */ -#define ADQ12B_STINR_EOC (1 << 5) /* A/D end-of-conversion */ +#define ADQ12B_STINR_OUT2 BIT(7) /* timer 2 output state */ +#define ADQ12B_STINR_OUTP BIT(6) /* pacer output state */ +#define ADQ12B_STINR_EOC BIT(5) /* A/D end-of-conversion */ #define ADQ12B_STINR_IN_MASK (0x1f << 0) #define ADQ12B_OUTBR 0x04 #define ADQ12B_ADLOW 0x08 @@ -145,7 +129,7 @@ static int adq12b_ai_insn_read(struct comedi_device *dev, if (val != devpriv->last_ctreg) { outb(val, dev->iobase + ADQ12B_CTREG); devpriv->last_ctreg = val; - udelay(50); /* wait for the mux to settle */ + usleep_range(50, 100); /* wait for the mux to settle */ } val = inb(dev->iobase + ADQ12B_ADLOW); /* trigger A/D */ diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c index 0c6aa964c884..399c511cfe0a 100644 --- a/drivers/staging/comedi/drivers/adv_pci1710.c +++ b/drivers/staging/comedi/drivers/adv_pci1710.c @@ -1,45 +1,30 @@ /* - * comedi/drivers/adv_pci1710.c - * + * adv_pci1710.c + * Comedi driver for Advantech PCI-1710 series boards * Author: Michal Dobes * * Thanks to ZhenGang Shang * for testing and information. - * - * hardware driver for Advantech cards: - * card: PCI-1710, PCI-1710HG, PCI-1711, PCI-1713, PCI-1720, PCI-1731 - * driver: pci1710, pci1710hg, pci1711, pci1713, pci1720, pci1731 - * - * Options: - * [0] - PCI bus number - if bus number and slot number are 0, - * then driver search for first unused card - * [1] - PCI slot number - * -*/ + */ + /* -Driver: adv_pci1710 -Description: Advantech PCI-1710, PCI-1710HG, PCI-1711, PCI-1713, - Advantech PCI-1720, PCI-1731 -Author: Michal Dobes -Devices: [Advantech] PCI-1710 (adv_pci1710), PCI-1710HG (pci1710hg), - PCI-1711 (adv_pci1710), PCI-1713, PCI-1720, - PCI-1731 -Status: works - -This driver supports AI, AO, DI and DO subdevices. -AI subdevice supports cmd and insn interface, -other subdevices support only insn interface. - -The PCI-1710 and PCI-1710HG have the same PCI device ID, so the -driver cannot distinguish between them, as would be normal for a -PCI driver. - -Configuration options: - [0] - PCI bus of device (optional) - [1] - PCI slot of device (optional) - If bus/slot is not specified, the first available PCI - device will be used. -*/ + * Driver: adv_pci1710 + * Description: Comedi driver for Advantech PCI-1710 series boards + * Devices: [Advantech] PCI-1710 (adv_pci1710), PCI-1710HG, PCI-1711, + * PCI-1713, PCI-1720, PCI-1731 + * Author: Michal Dobes + * Status: works + * + * Configuration options: not applicable, uses PCI auto config + * + * This driver supports AI, AO, DI and DO subdevices. + * AI subdevice supports cmd and insn interface, + * other subdevices support only insn interface. + * + * The PCI-1710 and PCI-1710HG have the same PCI device ID, so the + * driver cannot distinguish between them, as would be normal for a + * PCI driver. + */ #include #include @@ -49,48 +34,43 @@ Configuration options: #include "comedi_8254.h" #include "amcc_s5933.h" -#define PCI171x_AD_DATA 0 /* R: A/D data */ -#define PCI171x_SOFTTRG 0 /* W: soft trigger for A/D */ -#define PCI171x_RANGE 2 /* W: A/D gain/range register */ -#define PCI171x_MUX 4 /* W: A/D multiplexor control */ -#define PCI171x_STATUS 6 /* R: status register */ -#define PCI171x_CONTROL 6 /* W: control register */ -#define PCI171x_CLRINT 8 /* W: clear interrupts request */ -#define PCI171x_CLRFIFO 9 /* W: clear FIFO */ -#define PCI171x_DA1 10 /* W: D/A register */ -#define PCI171x_DA2 12 /* W: D/A register */ -#define PCI171x_DAREF 14 /* W: D/A reference control */ -#define PCI171x_DI 16 /* R: digi inputs */ -#define PCI171x_DO 16 /* R: digi inputs */ +/* + * PCI BAR2 Register map (dev->iobase) + */ +#define PCI171X_AD_DATA_REG 0x00 /* R: A/D data */ +#define PCI171X_SOFTTRG_REG 0x00 /* W: soft trigger for A/D */ +#define PCI171X_RANGE_REG 0x02 /* W: A/D gain/range register */ +#define PCI171X_MUX_REG 0x04 /* W: A/D multiplexor control */ +#define PCI171X_STATUS_REG 0x06 /* R: status register */ +#define PCI171X_STATUS_IRQ BIT(11) /* 1=IRQ occurred */ +#define PCI171X_STATUS_FF BIT(10) /* 1=FIFO is full, fatal error */ +#define PCI171X_STATUS_FH BIT(9) /* 1=FIFO is half full */ +#define PCI171X_STATUS_FE BIT(8) /* 1=FIFO is empty */ +#define PCI171X_CTRL_REG 0x06 /* W: control register */ +#define PCI171X_CTRL_CNT0 BIT(6) /* 1=ext. clk, 0=int. 100kHz clk */ +#define PCI171X_CTRL_ONEFH BIT(5) /* 1=on FIFO half full, 0=on sample */ +#define PCI171X_CTRL_IRQEN BIT(4) /* 1=enable IRQ */ +#define PCI171X_CTRL_GATE BIT(3) /* 1=enable ext. trigger GATE (8254?) */ +#define PCI171X_CTRL_EXT BIT(2) /* 1=enable ext. trigger source */ +#define PCI171X_CTRL_PACER BIT(1) /* 1=enable int. 8254 trigger source */ +#define PCI171X_CTRL_SW BIT(0) /* 1=enable software trigger source */ +#define PCI171X_CLRINT_REG 0x08 /* W: clear interrupts request */ +#define PCI171X_CLRFIFO_REG 0x09 /* W: clear FIFO */ +#define PCI171X_DA_REG(x) (0x0a + ((x) * 2)) /* W: D/A register */ +#define PCI171X_DAREF_REG 0x0e /* W: D/A reference control */ +#define PCI171X_DI_REG 0x10 /* R: digital inputs */ +#define PCI171X_DO_REG 0x10 /* W: digital outputs */ +#define PCI171X_TIMER_BASE 0x18 /* R/W: 8254 timer */ -#define PCI171X_TIMER_BASE 0x18 - -/* upper bits from status register (PCI171x_STATUS) (lower is same with control - * reg) */ -#define Status_FE 0x0100 /* 1=FIFO is empty */ -#define Status_FH 0x0200 /* 1=FIFO is half full */ -#define Status_FF 0x0400 /* 1=FIFO is full, fatal error */ -#define Status_IRQ 0x0800 /* 1=IRQ occurred */ -/* bits from control register (PCI171x_CONTROL) */ -#define Control_CNT0 0x0040 /* 1=CNT0 have external source, - * 0=have internal 100kHz source */ -#define Control_ONEFH 0x0020 /* 1=IRQ on FIFO is half full, 0=every sample */ -#define Control_IRQEN 0x0010 /* 1=enable IRQ */ -#define Control_GATE 0x0008 /* 1=enable external trigger GATE (8254?) */ -#define Control_EXT 0x0004 /* 1=external trigger source */ -#define Control_PACER 0x0002 /* 1=enable internal 8254 trigger source */ -#define Control_SW 0x0001 /* 1=enable software trigger source */ - -#define PCI1720_DA0 0 /* W: D/A register 0 */ -#define PCI1720_DA1 2 /* W: D/A register 1 */ -#define PCI1720_DA2 4 /* W: D/A register 2 */ -#define PCI1720_DA3 6 /* W: D/A register 3 */ -#define PCI1720_RANGE 8 /* R/W: D/A range register */ -#define PCI1720_SYNCOUT 9 /* W: D/A synchronized output register */ -#define PCI1720_SYNCONT 15 /* R/W: D/A synchronized control */ - -/* D/A synchronized control (PCI1720_SYNCONT) */ -#define Syncont_SC0 1 /* set synchronous output mode */ +/* + * PCI-1720 only has analog outputs and has a different + * register map (dev->iobase) + */ +#define PCI1720_DA_REG(x) (0x00 + ((x) * 2)) /* W: D/A registers */ +#define PCI1720_RANGE_REG 0x08 /* R/W: D/A range register */ +#define PCI1720_SYNC_REG 0x09 /* W: D/A synchronized output */ +#define PCI1720_SYNC_CTRL_REG 0x0f /* R/W: D/A synchronized control */ +#define PCI1720_SYNC_CTRL_SC0 BIT(0) /* set synchronous output mode */ static const struct comedi_lrange range_pci1710_3 = { 9, { @@ -244,10 +224,10 @@ static const struct boardtype boardtypes[] = { struct pci1710_private { unsigned int max_samples; - unsigned int CntrlReg; /* Control register */ + unsigned int ctrl; /* control register value */ + unsigned int ctrl_ext; /* used to switch from TRIG_EXT to TRIG_xxx */ + unsigned int mux_ext; /* used to set the channel interval to scan */ unsigned char ai_et; - unsigned int ai_et_CntrlReg; - unsigned int ai_et_MuxVal; unsigned int act_chanlist[32]; /* list of scanned channel */ unsigned char saved_seglen; /* len of the non-repeating chanlist */ unsigned char da_ranges; /* copy of D/A outpit range register */ @@ -342,8 +322,8 @@ static void pci171x_ai_setup_chanlist(struct comedi_device *dev, rangeval |= 0x0020; /* select channel and set range */ - outw(chan | (chan << 8), dev->iobase + PCI171x_MUX); - outw(rangeval, dev->iobase + PCI171x_RANGE); + outw(chan | (chan << 8), dev->iobase + PCI171X_MUX_REG); + outw(rangeval, dev->iobase + PCI171X_RANGE_REG); devpriv->act_chanlist[i] = chan; } @@ -351,8 +331,8 @@ static void pci171x_ai_setup_chanlist(struct comedi_device *dev, devpriv->act_chanlist[i] = CR_CHAN(chanlist[i]); /* select channel interval to scan */ - devpriv->ai_et_MuxVal = first_chan | (last_chan << 8); - outw(devpriv->ai_et_MuxVal, dev->iobase + PCI171x_MUX); + devpriv->mux_ext = first_chan | (last_chan << 8); + outw(devpriv->mux_ext, dev->iobase + PCI171X_MUX_REG); } static int pci171x_ai_eoc(struct comedi_device *dev, @@ -362,8 +342,8 @@ static int pci171x_ai_eoc(struct comedi_device *dev, { unsigned int status; - status = inw(dev->iobase + PCI171x_STATUS); - if ((status & Status_FE) == 0) + status = inw(dev->iobase + PCI171X_STATUS_REG); + if ((status & PCI171X_STATUS_FE) == 0) return 0; return -EBUSY; } @@ -378,7 +358,7 @@ static int pci171x_ai_read_sample(struct comedi_device *dev, unsigned int sample; unsigned int chan; - sample = inw(dev->iobase + PCI171x_AD_DATA); + sample = inw(dev->iobase + PCI171X_AD_DATA_REG); if (!board->is_pci1713) { /* * The upper 4 bits of the 16-bit sample are the channel number @@ -406,18 +386,19 @@ static int pci171x_ai_insn_read(struct comedi_device *dev, int ret = 0; int i; - devpriv->CntrlReg &= Control_CNT0; - devpriv->CntrlReg |= Control_SW; /* set software trigger */ - outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); - outb(0, dev->iobase + PCI171x_CLRFIFO); - outb(0, dev->iobase + PCI171x_CLRINT); + devpriv->ctrl &= PCI171X_CTRL_CNT0; + devpriv->ctrl |= PCI171X_CTRL_SW; /* set software trigger */ + outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); + outb(0, dev->iobase + PCI171X_CLRFIFO_REG); + outb(0, dev->iobase + PCI171X_CLRINT_REG); pci171x_ai_setup_chanlist(dev, s, &insn->chanspec, 1, 1); for (i = 0; i < insn->n; i++) { unsigned int val; - outw(0, dev->iobase + PCI171x_SOFTTRG); /* start conversion */ + /* start conversion */ + outw(0, dev->iobase + PCI171X_SOFTTRG_REG); ret = comedi_timeout(dev, s, insn, pci171x_ai_eoc, 0); if (ret) @@ -430,8 +411,8 @@ static int pci171x_ai_insn_read(struct comedi_device *dev, data[i] = val; } - outb(0, dev->iobase + PCI171x_CLRFIFO); - outb(0, dev->iobase + PCI171x_CLRINT); + outb(0, dev->iobase + PCI171X_CLRFIFO_REG); + outb(0, dev->iobase + PCI171X_CLRINT_REG); return ret ? ret : insn->n; } @@ -444,17 +425,16 @@ static int pci171x_ao_insn_write(struct comedi_device *dev, struct pci1710_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec); - unsigned int reg = chan ? PCI171x_DA2 : PCI171x_DA1; unsigned int val = s->readback[chan]; int i; devpriv->da_ranges &= ~(1 << (chan << 1)); devpriv->da_ranges |= (range << (chan << 1)); - outw(devpriv->da_ranges, dev->iobase + PCI171x_DAREF); + outw(devpriv->da_ranges, dev->iobase + PCI171X_DAREF_REG); for (i = 0; i < insn->n; i++) { val = data[i]; - outw(val, dev->iobase + reg); + outw(val, dev->iobase + PCI171X_DA_REG(chan)); } s->readback[chan] = val; @@ -467,7 +447,7 @@ static int pci171x_di_insn_bits(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - data[1] = inw(dev->iobase + PCI171x_DI); + data[1] = inw(dev->iobase + PCI171X_DI_REG); return insn->n; } @@ -478,7 +458,7 @@ static int pci171x_do_insn_bits(struct comedi_device *dev, unsigned int *data) { if (comedi_dio_update_state(s, data)) - outw(s->state, dev->iobase + PCI171x_DO); + outw(s->state, dev->iobase + PCI171X_DO_REG); data[1] = s->state; @@ -499,15 +479,15 @@ static int pci1720_ao_insn_write(struct comedi_device *dev, val = devpriv->da_ranges & (~(0x03 << (chan << 1))); val |= (range << (chan << 1)); if (val != devpriv->da_ranges) { - outb(val, dev->iobase + PCI1720_RANGE); + outb(val, dev->iobase + PCI1720_RANGE_REG); devpriv->da_ranges = val; } val = s->readback[chan]; for (i = 0; i < insn->n; i++) { val = data[i]; - outw(val, dev->iobase + PCI1720_DA0 + (chan << 1)); - outb(0, dev->iobase + PCI1720_SYNCOUT); /* update outputs */ + outw(val, dev->iobase + PCI1720_DA_REG(chan)); + outb(0, dev->iobase + PCI1720_SYNC_REG); /* update outputs */ } s->readback[chan] = val; @@ -520,13 +500,13 @@ static int pci171x_ai_cancel(struct comedi_device *dev, { struct pci1710_private *devpriv = dev->private; - devpriv->CntrlReg &= Control_CNT0; - devpriv->CntrlReg |= Control_SW; + devpriv->ctrl &= PCI171X_CTRL_CNT0; + devpriv->ctrl |= PCI171X_CTRL_SW; /* reset any operations */ - outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); + outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); comedi_8254_pacer_enable(dev->pacer, 1, 2, false); - outb(0, dev->iobase + PCI171x_CLRFIFO); - outb(0, dev->iobase + PCI171x_CLRINT); + outb(0, dev->iobase + PCI171X_CLRFIFO_REG); + outb(0, dev->iobase + PCI171X_CLRINT_REG); return 0; } @@ -539,22 +519,22 @@ static void pci1710_handle_every_sample(struct comedi_device *dev, unsigned int val; int ret; - status = inw(dev->iobase + PCI171x_STATUS); - if (status & Status_FE) { + status = inw(dev->iobase + PCI171X_STATUS_REG); + if (status & PCI171X_STATUS_FE) { dev_dbg(dev->class_dev, "A/D FIFO empty (%4x)\n", status); s->async->events |= COMEDI_CB_ERROR; return; } - if (status & Status_FF) { + if (status & PCI171X_STATUS_FF) { dev_dbg(dev->class_dev, "A/D FIFO Full status (Fatal Error!) (%4x)\n", status); s->async->events |= COMEDI_CB_ERROR; return; } - outb(0, dev->iobase + PCI171x_CLRINT); /* clear our INT request */ + outb(0, dev->iobase + PCI171X_CLRINT_REG); - for (; !(inw(dev->iobase + PCI171x_STATUS) & Status_FE);) { + for (; !(inw(dev->iobase + PCI171X_STATUS_REG) & PCI171X_STATUS_FE);) { ret = pci171x_ai_read_sample(dev, s, s->async->cur_chan, &val); if (ret) { s->async->events |= COMEDI_CB_ERROR; @@ -570,7 +550,7 @@ static void pci1710_handle_every_sample(struct comedi_device *dev, } } - outb(0, dev->iobase + PCI171x_CLRINT); /* clear our INT request */ + outb(0, dev->iobase + PCI171X_CLRINT_REG); } static void pci1710_handle_fifo(struct comedi_device *dev, @@ -582,13 +562,13 @@ static void pci1710_handle_fifo(struct comedi_device *dev, unsigned int status; int i; - status = inw(dev->iobase + PCI171x_STATUS); - if (!(status & Status_FH)) { + status = inw(dev->iobase + PCI171X_STATUS_REG); + if (!(status & PCI171X_STATUS_FH)) { dev_dbg(dev->class_dev, "A/D FIFO not half full!\n"); async->events |= COMEDI_CB_ERROR; return; } - if (status & Status_FF) { + if (status & PCI171X_STATUS_FF) { dev_dbg(dev->class_dev, "A/D FIFO Full status (Fatal Error!)\n"); async->events |= COMEDI_CB_ERROR; @@ -615,7 +595,7 @@ static void pci1710_handle_fifo(struct comedi_device *dev, } } - outb(0, dev->iobase + PCI171x_CLRINT); /* clear our INT request */ + outb(0, dev->iobase + PCI171X_CLRINT_REG); } static irqreturn_t interrupt_service_pci1710(int irq, void *d) @@ -632,19 +612,20 @@ static irqreturn_t interrupt_service_pci1710(int irq, void *d) cmd = &s->async->cmd; /* is this interrupt from our board? */ - if (!(inw(dev->iobase + PCI171x_STATUS) & Status_IRQ)) + if (!(inw(dev->iobase + PCI171X_STATUS_REG) & PCI171X_STATUS_IRQ)) return IRQ_NONE; /* no, exit */ if (devpriv->ai_et) { /* Switch from initial TRIG_EXT to TRIG_xxx. */ devpriv->ai_et = 0; - devpriv->CntrlReg &= Control_CNT0; - devpriv->CntrlReg |= Control_SW; /* set software trigger */ - outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); - devpriv->CntrlReg = devpriv->ai_et_CntrlReg; - outb(0, dev->iobase + PCI171x_CLRFIFO); - outb(0, dev->iobase + PCI171x_CLRINT); - outw(devpriv->ai_et_MuxVal, dev->iobase + PCI171x_MUX); - outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); + devpriv->ctrl &= PCI171X_CTRL_CNT0; + devpriv->ctrl |= PCI171X_CTRL_SW; /* set software trigger */ + outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); + devpriv->ctrl = devpriv->ctrl_ext; + outb(0, dev->iobase + PCI171X_CLRFIFO_REG); + outb(0, dev->iobase + PCI171X_CLRINT_REG); + /* no sample on this interrupt; reset the channel interval */ + outw(devpriv->mux_ext, dev->iobase + PCI171X_MUX_REG); + outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); comedi_8254_pacer_enable(dev->pacer, 1, 2, true); return IRQ_HANDLED; } @@ -667,33 +648,34 @@ static int pci171x_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) pci171x_ai_setup_chanlist(dev, s, cmd->chanlist, cmd->chanlist_len, devpriv->saved_seglen); - outb(0, dev->iobase + PCI171x_CLRFIFO); - outb(0, dev->iobase + PCI171x_CLRINT); + outb(0, dev->iobase + PCI171X_CLRFIFO_REG); + outb(0, dev->iobase + PCI171X_CLRINT_REG); - devpriv->CntrlReg &= Control_CNT0; + devpriv->ctrl &= PCI171X_CTRL_CNT0; if ((cmd->flags & CMDF_WAKE_EOS) == 0) - devpriv->CntrlReg |= Control_ONEFH; + devpriv->ctrl |= PCI171X_CTRL_ONEFH; if (cmd->convert_src == TRIG_TIMER) { comedi_8254_update_divisors(dev->pacer); - devpriv->CntrlReg |= Control_PACER | Control_IRQEN; + devpriv->ctrl |= PCI171X_CTRL_PACER | PCI171X_CTRL_IRQEN; if (cmd->start_src == TRIG_EXT) { - devpriv->ai_et_CntrlReg = devpriv->CntrlReg; - devpriv->CntrlReg &= - ~(Control_PACER | Control_ONEFH | Control_GATE); - devpriv->CntrlReg |= Control_EXT; + devpriv->ctrl_ext = devpriv->ctrl; + devpriv->ctrl &= ~(PCI171X_CTRL_PACER | + PCI171X_CTRL_ONEFH | + PCI171X_CTRL_GATE); + devpriv->ctrl |= PCI171X_CTRL_EXT; devpriv->ai_et = 1; } else { /* TRIG_NOW */ devpriv->ai_et = 0; } - outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); + outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); if (cmd->start_src == TRIG_NOW) comedi_8254_pacer_enable(dev->pacer, 1, 2, true); } else { /* TRIG_EXT */ - devpriv->CntrlReg |= Control_EXT | Control_IRQEN; - outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); + devpriv->ctrl |= PCI171X_CTRL_EXT | PCI171X_CTRL_IRQEN; + outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); } return 0; @@ -782,18 +764,18 @@ static int pci171x_insn_counter_config(struct comedi_device *dev, case INSN_CONFIG_SET_CLOCK_SRC: switch (data[1]) { case 0: /* internal */ - devpriv->ai_et_CntrlReg &= ~Control_CNT0; + devpriv->ctrl_ext &= ~PCI171X_CTRL_CNT0; break; case 1: /* external */ - devpriv->ai_et_CntrlReg |= Control_CNT0; + devpriv->ctrl_ext |= PCI171X_CTRL_CNT0; break; default: return -EINVAL; } - outw(devpriv->ai_et_CntrlReg, dev->iobase + PCI171x_CONTROL); + outw(devpriv->ctrl_ext, dev->iobase + PCI171X_CTRL_REG); break; case INSN_CONFIG_GET_CLOCK_SRC: - if (devpriv->ai_et_CntrlReg & Control_CNT0) { + if (devpriv->ctrl_ext & PCI171X_CTRL_CNT0) { data[1] = 1; data[2] = 0; } else { @@ -814,21 +796,21 @@ static int pci171x_reset(struct comedi_device *dev) struct pci1710_private *devpriv = dev->private; /* Software trigger, CNT0=external */ - devpriv->CntrlReg = Control_SW | Control_CNT0; + devpriv->ctrl = PCI171X_CTRL_SW | PCI171X_CTRL_CNT0; /* reset any operations */ - outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); - outb(0, dev->iobase + PCI171x_CLRFIFO); /* clear FIFO */ - outb(0, dev->iobase + PCI171x_CLRINT); /* clear INT request */ + outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG); + outb(0, dev->iobase + PCI171X_CLRFIFO_REG); + outb(0, dev->iobase + PCI171X_CLRINT_REG); devpriv->da_ranges = 0; if (board->has_ao) { - /* set DACs to 0..5V */ - outb(devpriv->da_ranges, dev->iobase + PCI171x_DAREF); - outw(0, dev->iobase + PCI171x_DA1); /* set DA outputs to 0V */ - outw(0, dev->iobase + PCI171x_DA2); + /* set DACs to 0..5V and outputs to 0V */ + outb(devpriv->da_ranges, dev->iobase + PCI171X_DAREF_REG); + outw(0, dev->iobase + PCI171X_DA_REG(0)); + outw(0, dev->iobase + PCI171X_DA_REG(1)); } - outw(0, dev->iobase + PCI171x_DO); /* digital outputs to 0 */ - outb(0, dev->iobase + PCI171x_CLRFIFO); /* clear FIFO */ - outb(0, dev->iobase + PCI171x_CLRINT); /* clear INT request */ + outw(0, dev->iobase + PCI171X_DO_REG); /* digital outputs to 0 */ + outb(0, dev->iobase + PCI171X_CLRFIFO_REG); + outb(0, dev->iobase + PCI171X_CLRINT_REG); return 0; } @@ -837,15 +819,15 @@ static int pci1720_reset(struct comedi_device *dev) { struct pci1710_private *devpriv = dev->private; /* set synchronous output mode */ - outb(Syncont_SC0, dev->iobase + PCI1720_SYNCONT); + outb(PCI1720_SYNC_CTRL_SC0, dev->iobase + PCI1720_SYNC_CTRL_REG); devpriv->da_ranges = 0xAA; - /* set all ranges to +/-5V */ - outb(devpriv->da_ranges, dev->iobase + PCI1720_RANGE); - outw(0x0800, dev->iobase + PCI1720_DA0); /* set outputs to 0V */ - outw(0x0800, dev->iobase + PCI1720_DA1); - outw(0x0800, dev->iobase + PCI1720_DA2); - outw(0x0800, dev->iobase + PCI1720_DA3); - outb(0, dev->iobase + PCI1720_SYNCOUT); /* update outputs */ + /* set all ranges to +/-5V and outputs to 0V */ + outb(devpriv->da_ranges, dev->iobase + PCI1720_RANGE_REG); + outw(0x0800, dev->iobase + PCI1720_DA_REG(0)); + outw(0x0800, dev->iobase + PCI1720_DA_REG(1)); + outw(0x0800, dev->iobase + PCI1720_DA_REG(2)); + outw(0x0800, dev->iobase + PCI1720_DA_REG(3)); + outb(0, dev->iobase + PCI1720_SYNC_REG); /* update outputs */ return 0; } diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c b/drivers/staging/comedi/drivers/adv_pci1723.c index 1921a97cc5ca..f82afd947310 100644 --- a/drivers/staging/comedi/drivers/adv_pci1723.c +++ b/drivers/staging/comedi/drivers/adv_pci1723.c @@ -51,25 +51,27 @@ #define PCI1723_BOARD_ID_REG 0x10 #define PCI1723_BOARD_ID_MASK (0xf << 0) #define PCI1723_SYNC_CTRL_REG 0x12 -#define PCI1723_SYNC_CTRL_ASYNC (0 << 0) -#define PCI1723_SYNC_CTRL_SYNC (1 << 0) +#define PCI1723_SYNC_CTRL(x) (((x) & 0x1) << 0) +#define PCI1723_SYNC_CTRL_ASYNC PCI1723_SYNC_CTRL(0) +#define PCI1723_SYNC_CTRL_SYNC PCI1723_SYNC_CTRL(1) #define PCI1723_CTRL_REG 0x14 -#define PCI1723_CTRL_BUSY (1 << 15) -#define PCI1723_CTRL_INIT (1 << 14) -#define PCI1723_CTRL_SELF (1 << 8) +#define PCI1723_CTRL_BUSY BIT(15) +#define PCI1723_CTRL_INIT BIT(14) +#define PCI1723_CTRL_SELF BIT(8) #define PCI1723_CTRL_IDX(x) (((x) & 0x3) << 6) #define PCI1723_CTRL_RANGE(x) (((x) & 0x3) << 4) -#define PCI1723_CTRL_GAIN (0 << 3) -#define PCI1723_CTRL_OFFSET (1 << 3) +#define PCI1723_CTRL_SEL(x) (((x) & 0x1) << 3) +#define PCI1723_CTRL_GAIN PCI1723_CTRL_SEL(0) +#define PCI1723_CTRL_OFFSET PCI1723_CTRL_SEL(1) #define PCI1723_CTRL_CHAN(x) (((x) & 0x7) << 0) #define PCI1723_CALIB_CTRL_REG 0x16 -#define PCI1723_CALIB_CTRL_CS (1 << 2) -#define PCI1723_CALIB_CTRL_DAT (1 << 1) -#define PCI1723_CALIB_CTRL_CLK (1 << 0) +#define PCI1723_CALIB_CTRL_CS BIT(2) +#define PCI1723_CALIB_CTRL_DAT BIT(1) +#define PCI1723_CALIB_CTRL_CLK BIT(0) #define PCI1723_CALIB_STROBE_REG 0x18 #define PCI1723_DIO_CTRL_REG 0x1a -#define PCI1723_DIO_CTRL_HDIO (1 << 1) -#define PCI1723_DIO_CTRL_LDIO (1 << 0) +#define PCI1723_DIO_CTRL_HDIO BIT(1) +#define PCI1723_DIO_CTRL_LDIO BIT(0) #define PCI1723_DIO_DATA_REG 0x1c #define PCI1723_CALIB_DATA_REG 0x1e #define PCI1723_SYNC_STROBE_REG 0x20 @@ -77,9 +79,10 @@ #define PCI1723_RESET_CALIB_STROBE_REG 0x24 #define PCI1723_RANGE_STROBE_REG 0x26 #define PCI1723_VREF_REG 0x28 -#define PCI1723_VREF_NEG10V (0 << 0) -#define PCI1723_VREF_0V (1 << 0) -#define PCI1723_VREF_POS10V (3 << 0) +#define PCI1723_VREF(x) (((x) & 0x3) << 0) +#define PCI1723_VREF_NEG10V PCI1723_VREF(0) +#define PCI1723_VREF_0V PCI1723_VREF(1) +#define PCI1723_VREF_POS10V PCI1723_VREF(3) static int pci1723_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, diff --git a/drivers/staging/comedi/drivers/adv_pci1724.c b/drivers/staging/comedi/drivers/adv_pci1724.c index 9677111f9ab2..bf6a8f10118c 100644 --- a/drivers/staging/comedi/drivers/adv_pci1724.c +++ b/drivers/staging/comedi/drivers/adv_pci1724.c @@ -54,16 +54,17 @@ * PCI bar 2 Register I/O map (dev->iobase) */ #define PCI1724_DAC_CTRL_REG 0x00 -#define PCI1724_DAC_CTRL_GX(x) (1 << (20 + ((x) / 8))) +#define PCI1724_DAC_CTRL_GX(x) BIT(20 + ((x) / 8)) #define PCI1724_DAC_CTRL_CX(x) (((x) % 8) << 16) -#define PCI1724_DAC_CTRL_MODE_GAIN (1 << 14) -#define PCI1724_DAC_CTRL_MODE_OFFSET (2 << 14) -#define PCI1724_DAC_CTRL_MODE_NORMAL (3 << 14) -#define PCI1724_DAC_CTRL_MODE_MASK (3 << 14) +#define PCI1724_DAC_CTRL_MODE(x) (((x) & 0x3) << 14) +#define PCI1724_DAC_CTRL_MODE_GAIN PCI1724_DAC_CTRL_MODE(1) +#define PCI1724_DAC_CTRL_MODE_OFFSET PCI1724_DAC_CTRL_MODE(2) +#define PCI1724_DAC_CTRL_MODE_NORMAL PCI1724_DAC_CTRL_MODE(3) +#define PCI1724_DAC_CTRL_MODE_MASK PCI1724_DAC_CTRL_MODE(3) #define PCI1724_DAC_CTRL_DATA(x) (((x) & 0x3fff) << 0) #define PCI1724_SYNC_CTRL_REG 0x04 -#define PCI1724_SYNC_CTRL_DACSTAT (1 << 1) -#define PCI1724_SYNC_CTRL_SYN (1 << 0) +#define PCI1724_SYNC_CTRL_DACSTAT BIT(1) +#define PCI1724_SYNC_CTRL_SYN BIT(0) #define PCI1724_EEPROM_CTRL_REG 0x08 #define PCI1724_SYNC_TRIG_REG 0x0c /* any value works */ #define PCI1724_BOARD_ID_REG 0x10 diff --git a/drivers/staging/comedi/drivers/aio_aio12_8.c b/drivers/staging/comedi/drivers/aio_aio12_8.c index fbc3e5aa94cb..43a0ce5721d3 100644 --- a/drivers/staging/comedi/drivers/aio_aio12_8.c +++ b/drivers/staging/comedi/drivers/aio_aio12_8.c @@ -1,99 +1,107 @@ /* - - comedi/drivers/aio_aio12_8.c - - Driver for Access I/O Products PC-104 AIO12-8 Analog I/O Board - Copyright (C) 2006 C&C Technologies, Inc. - - 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. -*/ + * aio_aio12_8.c + * Driver for Access I/O Products PC-104 AIO12-8 Analog I/O Board + * Copyright (C) 2006 C&C Technologies, Inc. + * + * 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: aio_aio12_8 -Description: Access I/O Products PC-104 AIO12-8 Analog I/O Board -Author: Pablo Mejia -Devices: [Access I/O] PC-104 AIO12-8 (aio_aio12_8) - [Access I/O] PC-104 AI12-8 (aio_ai12_8) - [Access I/O] PC-104 AO12-8 (aio_ao12_8) -Status: experimental - -Configuration Options: - [0] - I/O port base address - -Notes: - - Only synchronous operations are supported. - -*/ + * Driver: aio_aio12_8 + * Description: Access I/O Products PC-104 AIO12-8 Analog I/O Board + * Author: Pablo Mejia + * Devices: [Access I/O] PC-104 AIO12-8 (aio_aio12_8), + * [Access I/O] PC-104 AI12-8 (aio_ai12_8), + * [Access I/O] PC-104 AO12-4 (aio_ao12_4) + * Status: experimental + * + * Configuration Options: + * [0] - I/O port base address + * + * Notes: + * Only synchronous operations are supported. + */ #include #include "../comedidev.h" + +#include "comedi_8254.h" #include "8255.h" /* * Register map */ #define AIO12_8_STATUS_REG 0x00 -#define AIO12_8_STATUS_ADC_EOC (1 << 7) -#define AIO12_8_STATUS_PORT_C_COS (1 << 6) -#define AIO12_8_STATUS_IRQ_ENA (1 << 2) +#define AIO12_8_STATUS_ADC_EOC BIT(7) +#define AIO12_8_STATUS_PORT_C_COS BIT(6) +#define AIO12_8_STATUS_IRQ_ENA BIT(2) #define AIO12_8_INTERRUPT_REG 0x01 -#define AIO12_8_INTERRUPT_ADC (1 << 7) -#define AIO12_8_INTERRUPT_COS (1 << 6) -#define AIO12_8_INTERRUPT_COUNTER1 (1 << 5) -#define AIO12_8_INTERRUPT_PORT_C3 (1 << 4) -#define AIO12_8_INTERRUPT_PORT_C0 (1 << 3) -#define AIO12_8_INTERRUPT_ENA (1 << 2) +#define AIO12_8_INTERRUPT_ADC BIT(7) +#define AIO12_8_INTERRUPT_COS BIT(6) +#define AIO12_8_INTERRUPT_COUNTER1 BIT(5) +#define AIO12_8_INTERRUPT_PORT_C3 BIT(4) +#define AIO12_8_INTERRUPT_PORT_C0 BIT(3) +#define AIO12_8_INTERRUPT_ENA BIT(2) #define AIO12_8_ADC_REG 0x02 -#define AIO12_8_ADC_MODE_NORMAL (0 << 6) -#define AIO12_8_ADC_MODE_INT_CLK (1 << 6) -#define AIO12_8_ADC_MODE_STANDBY (2 << 6) -#define AIO12_8_ADC_MODE_POWERDOWN (3 << 6) -#define AIO12_8_ADC_ACQ_3USEC (0 << 5) -#define AIO12_8_ADC_ACQ_PROGRAM (1 << 5) +#define AIO12_8_ADC_MODE(x) (((x) & 0x3) << 6) +#define AIO12_8_ADC_MODE_NORMAL AIO12_8_ADC_MODE(0) +#define AIO12_8_ADC_MODE_INT_CLK AIO12_8_ADC_MODE(1) +#define AIO12_8_ADC_MODE_STANDBY AIO12_8_ADC_MODE(2) +#define AIO12_8_ADC_MODE_POWERDOWN AIO12_8_ADC_MODE(3) +#define AIO12_8_ADC_ACQ(x) (((x) & 0x1) << 5) +#define AIO12_8_ADC_ACQ_3USEC AIO12_8_ADC_ACQ(0) +#define AIO12_8_ADC_ACQ_PROGRAM AIO12_8_ADC_ACQ(1) #define AIO12_8_ADC_RANGE(x) ((x) << 3) #define AIO12_8_ADC_CHAN(x) ((x) << 0) #define AIO12_8_DAC_REG(x) (0x04 + (x) * 2) #define AIO12_8_8254_BASE_REG 0x0c #define AIO12_8_8255_BASE_REG 0x10 #define AIO12_8_DIO_CONTROL_REG 0x14 -#define AIO12_8_DIO_CONTROL_TST (1 << 0) +#define AIO12_8_DIO_CONTROL_TST BIT(0) #define AIO12_8_ADC_TRIGGER_REG 0x15 #define AIO12_8_ADC_TRIGGER_RANGE(x) ((x) << 3) #define AIO12_8_ADC_TRIGGER_CHAN(x) ((x) << 0) #define AIO12_8_TRIGGER_REG 0x16 -#define AIO12_8_TRIGGER_ADTRIG (1 << 1) -#define AIO12_8_TRIGGER_DACTRIG (1 << 0) +#define AIO12_8_TRIGGER_ADTRIG BIT(1) +#define AIO12_8_TRIGGER_DACTRIG BIT(0) #define AIO12_8_COS_REG 0x17 #define AIO12_8_DAC_ENABLE_REG 0x18 -#define AIO12_8_DAC_ENABLE_REF_ENA (1 << 0) +#define AIO12_8_DAC_ENABLE_REF_ENA BIT(0) + +static const struct comedi_lrange aio_aio12_8_range = { + 4, { + UNI_RANGE(5), + BIP_RANGE(5), + UNI_RANGE(10), + BIP_RANGE(10) + } +}; struct aio12_8_boardtype { const char *name; - int ai_nchan; - int ao_nchan; + unsigned int has_ai:1; + unsigned int has_ao:1; }; static const struct aio12_8_boardtype board_types[] = { { .name = "aio_aio12_8", - .ai_nchan = 8, - .ao_nchan = 4, + .has_ai = 1, + .has_ao = 1, }, { .name = "aio_ai12_8", - .ai_nchan = 8, + .has_ai = 1, }, { - .name = "aio_ao12_8", - .ao_nchan = 4, + .name = "aio_ao12_4", + .has_ao = 1, }, }; @@ -112,13 +120,15 @@ static int aio_aio12_8_ai_eoc(struct comedi_device *dev, static int aio_aio12_8_ai_read(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { unsigned int chan = CR_CHAN(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec); + unsigned int val; unsigned char control; int ret; - int n; + int i; /* * Setup the control byte for internal 2MHz clock, 3uS conversion, @@ -130,7 +140,7 @@ static int aio_aio12_8_ai_read(struct comedi_device *dev, /* Read status to clear EOC latch */ inb(dev->iobase + AIO12_8_STATUS_REG); - for (n = 0; n < insn->n; n++) { + for (i = 0; i < insn->n; i++) { /* Setup and start conversion */ outb(control, dev->iobase + AIO12_8_ADC_REG); @@ -139,7 +149,13 @@ static int aio_aio12_8_ai_read(struct comedi_device *dev, if (ret) return ret; - data[n] = inw(dev->iobase + AIO12_8_ADC_REG) & s->maxdata; + val = inw(dev->iobase + AIO12_8_ADC_REG) & s->maxdata; + + /* munge bipolar 2's complement data to offset binary */ + if (comedi_range_is_bipolar(s, range)) + val = comedi_offset_munge(s, val); + + data[i] = val; } return insn->n; @@ -166,14 +182,28 @@ static int aio_aio12_8_ao_insn_write(struct comedi_device *dev, return insn->n; } -static const struct comedi_lrange range_aio_aio12_8 = { - 4, { - UNI_RANGE(5), - BIP_RANGE(5), - UNI_RANGE(10), - BIP_RANGE(10) +static int aio_aio12_8_counter_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int chan = CR_CHAN(insn->chanspec); + + switch (data[0]) { + case INSN_CONFIG_GET_CLOCK_SRC: + /* + * Channels 0 and 2 have external clock sources. + * Channel 1 has a fixed 1 MHz clock source. + */ + data[0] = 0; + data[1] = (chan == 1) ? I8254_OSC_BASE_1MHZ : 0; + break; + default: + return -EINVAL; } -}; + + return insn->n; +} static int aio_aio12_8_attach(struct comedi_device *dev, struct comedi_devconfig *it) @@ -186,31 +216,36 @@ static int aio_aio12_8_attach(struct comedi_device *dev, if (ret) return ret; + dev->pacer = comedi_8254_init(dev->iobase + AIO12_8_8254_BASE_REG, + 0, I8254_IO8, 0); + if (!dev->pacer) + return -ENOMEM; + ret = comedi_alloc_subdevices(dev, 4); if (ret) return ret; + /* Analog Input subdevice */ s = &dev->subdevices[0]; - if (board->ai_nchan) { - /* Analog input subdevice */ + if (board->has_ai) { s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF; - s->n_chan = board->ai_nchan; + s->n_chan = 8; s->maxdata = 0x0fff; - s->range_table = &range_aio_aio12_8; + s->range_table = &aio_aio12_8_range; s->insn_read = aio_aio12_8_ai_read; } else { s->type = COMEDI_SUBD_UNUSED; } + /* Analog Output subdevice */ s = &dev->subdevices[1]; - if (board->ao_nchan) { - /* Analog output subdevice */ + if (board->has_ao) { s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_DIFF; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND; s->n_chan = 4; s->maxdata = 0x0fff; - s->range_table = &range_aio_aio12_8; + s->range_table = &aio_aio12_8_range; s->insn_write = aio_aio12_8_ao_insn_write; ret = comedi_alloc_subdev_readback(s); @@ -220,15 +255,17 @@ static int aio_aio12_8_attach(struct comedi_device *dev, s->type = COMEDI_SUBD_UNUSED; } + /* Digital I/O subdevice (8255) */ s = &dev->subdevices[2]; - /* 8255 Digital i/o subdevice */ ret = subdev_8255_init(dev, s, NULL, AIO12_8_8255_BASE_REG); if (ret) return ret; + /* Counter subdevice (8254) */ s = &dev->subdevices[3]; - /* 8254 counter/timer subdevice */ - s->type = COMEDI_SUBD_UNUSED; + comedi_8254_subdevice_init(s, dev->pacer); + + dev->pacer->insn_config = aio_aio12_8_counter_insn_config; return 0; } @@ -245,5 +282,5 @@ static struct comedi_driver aio_aio12_8_driver = { module_comedi_driver(aio_aio12_8_driver); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_DESCRIPTION("Comedi driver for Access I/O AIO12-8 Analog I/O Board"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c index 5c5c4e2ec3d5..4b39f6960c0a 100644 --- a/drivers/staging/comedi/drivers/amplc_pci230.c +++ b/drivers/staging/comedi/drivers/amplc_pci230.c @@ -2275,7 +2275,7 @@ static int pci230_ai_cancel(struct comedi_device *dev, static irqreturn_t pci230_interrupt(int irq, void *d) { unsigned char status_int, valid_status_int, temp_ier; - struct comedi_device *dev = (struct comedi_device *)d; + struct comedi_device *dev = d; struct pci230_private *devpriv = dev->private; struct comedi_subdevice *s_ao = dev->write_subdev; struct comedi_subdevice *s_ai = dev->read_subdev; diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c index ae84f2c0cc9c..78d098f9e1f2 100644 --- a/drivers/staging/comedi/drivers/cb_das16_cs.c +++ b/drivers/staging/comedi/drivers/cb_das16_cs.c @@ -1,36 +1,37 @@ /* - comedi/drivers/das16cs.c - Driver for Computer Boards PC-CARD DAS16/16. + * cb_das16_cs.c + * Driver for Computer Boards PC-CARD DAS16/16. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000, 2001, 2002 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. + * + * 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. + */ - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 2000, 2001, 2002 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. - - 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: cb_das16_cs -Description: Computer Boards PC-CARD DAS16/16 -Devices: [ComputerBoards] PC-CARD DAS16/16 (cb_das16_cs), PC-CARD DAS16/16-AO -Author: ds -Updated: Mon, 04 Nov 2002 20:04:21 -0800 -Status: experimental -*/ + * Driver: cb_das16_cs + * Description: Computer Boards PC-CARD DAS16/16 + * Devices: [ComputerBoards] PC-CARD DAS16/16 (cb_das16_cs), + * PC-CARD DAS16/16-AO + * Author: ds + * Updated: Mon, 04 Nov 2002 20:04:21 -0800 + * Status: experimental + */ #include #include @@ -40,38 +41,86 @@ Status: experimental #include "comedi_8254.h" -#define DAS16CS_ADC_DATA 0 -#define DAS16CS_DIO_MUX 2 -#define DAS16CS_MISC1 4 -#define DAS16CS_MISC2 6 -#define DAS16CS_TIMER_BASE 8 -#define DAS16CS_DIO 16 +/* + * Register I/O map + */ +#define DAS16CS_AI_DATA_REG 0x00 +#define DAS16CS_AI_MUX_REG 0x02 +#define DAS16CS_AI_MUX_HI_CHAN(x) (((x) & 0xf) << 4) +#define DAS16CS_AI_MUX_LO_CHAN(x) (((x) & 0xf) << 0) +#define DAS16CS_AI_MUX_SINGLE_CHAN(x) (DAS16CS_AI_MUX_HI_CHAN(x) | \ + DAS16CS_AI_MUX_LO_CHAN(x)) +#define DAS16CS_MISC1_REG 0x04 +#define DAS16CS_MISC1_INTE BIT(15) /* 1=enable; 0=disable */ +#define DAS16CS_MISC1_INT_SRC(x) (((x) & 0x7) << 12) /* interrupt src */ +#define DAS16CS_MISC1_INT_SRC_NONE DAS16CS_MISC1_INT_SRC(0) +#define DAS16CS_MISC1_INT_SRC_PACER DAS16CS_MISC1_INT_SRC(1) +#define DAS16CS_MISC1_INT_SRC_EXT DAS16CS_MISC1_INT_SRC(2) +#define DAS16CS_MISC1_INT_SRC_FNE DAS16CS_MISC1_INT_SRC(3) +#define DAS16CS_MISC1_INT_SRC_FHF DAS16CS_MISC1_INT_SRC(4) +#define DAS16CS_MISC1_INT_SRC_EOS DAS16CS_MISC1_INT_SRC(5) +#define DAS16CS_MISC1_INT_SRC_MASK DAS16CS_MISC1_INT_SRC(7) +#define DAS16CS_MISC1_OVR BIT(10) /* ro - 1=FIFO overflow */ +#define DAS16CS_MISC1_AI_CONV(x) (((x) & 0x3) << 8) /* AI convert src */ +#define DAS16CS_MISC1_AI_CONV_SW DAS16CS_MISC1_AI_CONV(0) +#define DAS16CS_MISC1_AI_CONV_EXT_NEG DAS16CS_MISC1_AI_CONV(1) +#define DAS16CS_MISC1_AI_CONV_EXT_POS DAS16CS_MISC1_AI_CONV(2) +#define DAS16CS_MISC1_AI_CONV_PACER DAS16CS_MISC1_AI_CONV(3) +#define DAS16CS_MISC1_AI_CONV_MASK DAS16CS_MISC1_AI_CONV(3) +#define DAS16CS_MISC1_EOC BIT(7) /* ro - 0=busy; 1=ready */ +#define DAS16CS_MISC1_SEDIFF BIT(5) /* 0=diff; 1=se */ +#define DAS16CS_MISC1_INTB BIT(4) /* ro - 0=latched; 1=cleared */ +#define DAS16CS_MISC1_MA_MASK (0xf << 0) /* ro - current ai mux */ +#define DAS16CS_MISC1_DAC1CS BIT(3) /* wo - DAC1 chip select */ +#define DAS16CS_MISC1_DACCLK BIT(2) /* wo - Serial DAC clock */ +#define DAS16CS_MISC1_DACSD BIT(1) /* wo - Serial DAC data */ +#define DAS16CS_MISC1_DAC0CS BIT(0) /* wo - DAC0 chip select */ +#define DAS16CS_MISC1_DAC_MASK (0x0f << 0) +#define DAS16CS_MISC2_REG 0x06 +#define DAS16CS_MISC2_BME BIT(14) /* 1=burst enable; 0=disable */ +#define DAS16CS_MISC2_AI_GAIN(x) (((x) & 0xf) << 8) /* AI gain */ +#define DAS16CS_MISC2_AI_GAIN_1 DAS16CS_MISC2_AI_GAIN(4) /* +/-10V */ +#define DAS16CS_MISC2_AI_GAIN_2 DAS16CS_MISC2_AI_GAIN(0) /* +/-5V */ +#define DAS16CS_MISC2_AI_GAIN_4 DAS16CS_MISC2_AI_GAIN(1) /* +/-2.5V */ +#define DAS16CS_MISC2_AI_GAIN_8 DAS16CS_MISC2_AI_GAIN(2) /* +-1.25V */ +#define DAS16CS_MISC2_AI_GAIN_MASK DAS16CS_MISC2_AI_GAIN(0xf) +#define DAS16CS_MISC2_UDIR BIT(7) /* 1=dio7:4 output; 0=input */ +#define DAS16CS_MISC2_LDIR BIT(6) /* 1=dio3:0 output; 0=input */ +#define DAS16CS_MISC2_TRGPOL BIT(5) /* 1=active lo; 0=hi */ +#define DAS16CS_MISC2_TRGSEL BIT(4) /* 1=edge; 0=level */ +#define DAS16CS_MISC2_FFNE BIT(3) /* ro - 1=FIFO not empty */ +#define DAS16CS_MISC2_TRGCLR BIT(3) /* wo - 1=clr (monstable) */ +#define DAS16CS_MISC2_CLK2 BIT(2) /* 1=10 MHz; 0=1 MHz */ +#define DAS16CS_MISC2_CTR1 BIT(1) /* 1=int. 100 kHz; 0=ext. clk */ +#define DAS16CS_MISC2_TRG0 BIT(0) /* 1=enable; 0=disable */ +#define DAS16CS_TIMER_BASE 0x08 +#define DAS16CS_DIO_REG 0x10 struct das16cs_board { const char *name; int device_id; - int n_ao_chans; + unsigned int has_ao:1; + unsigned int has_4dio:1; }; static const struct das16cs_board das16cs_boards[] = { { .name = "PC-CARD DAS16/16-AO", .device_id = 0x0039, - .n_ao_chans = 2, + .has_ao = 1, + .has_4dio = 1, }, { .name = "PCM-DAS16s/16", .device_id = 0x4009, - .n_ao_chans = 0, }, { .name = "PC-CARD DAS16/16", .device_id = 0x0000, /* unknown */ - .n_ao_chans = 0, }, }; struct das16cs_private { - unsigned short status1; - unsigned short status2; + unsigned short misc1; + unsigned short misc2; }; static const struct comedi_lrange das16cs_ai_range = { @@ -90,15 +139,16 @@ static int das16cs_ai_eoc(struct comedi_device *dev, { unsigned int status; - status = inw(dev->iobase + DAS16CS_MISC1); - if (status & 0x0080) + status = inw(dev->iobase + DAS16CS_MISC1_REG); + if (status & DAS16CS_MISC1_EOC) return 0; return -EBUSY; } -static int das16cs_ai_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int das16cs_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct das16cs_private *devpriv = dev->private; int chan = CR_CHAN(insn->chanspec); @@ -107,37 +157,43 @@ static int das16cs_ai_rinsn(struct comedi_device *dev, int ret; int i; - outw(chan, dev->iobase + DAS16CS_DIO_MUX); + outw(DAS16CS_AI_MUX_SINGLE_CHAN(chan), + dev->iobase + DAS16CS_AI_MUX_REG); - devpriv->status1 &= ~0xf320; - devpriv->status1 |= (aref == AREF_DIFF) ? 0 : 0x0020; - outw(devpriv->status1, dev->iobase + DAS16CS_MISC1); + /* disable interrupts, software convert */ + devpriv->misc1 &= ~(DAS16CS_MISC1_INTE | DAS16CS_MISC1_INT_SRC_MASK | + DAS16CS_MISC1_AI_CONV_MASK); + if (aref == AREF_DIFF) + devpriv->misc1 &= ~DAS16CS_MISC1_SEDIFF; + else + devpriv->misc1 |= DAS16CS_MISC1_SEDIFF; + outw(devpriv->misc1, dev->iobase + DAS16CS_MISC1_REG); - devpriv->status2 &= ~0xff00; + devpriv->misc2 &= ~(DAS16CS_MISC2_BME | DAS16CS_MISC2_AI_GAIN_MASK); switch (range) { case 0: - devpriv->status2 |= 0x800; + devpriv->misc2 |= DAS16CS_MISC2_AI_GAIN_1; break; case 1: - devpriv->status2 |= 0x000; + devpriv->misc2 |= DAS16CS_MISC2_AI_GAIN_2; break; case 2: - devpriv->status2 |= 0x100; + devpriv->misc2 |= DAS16CS_MISC2_AI_GAIN_4; break; case 3: - devpriv->status2 |= 0x200; + devpriv->misc2 |= DAS16CS_MISC2_AI_GAIN_8; break; } - outw(devpriv->status2, dev->iobase + DAS16CS_MISC2); + outw(devpriv->misc2, dev->iobase + DAS16CS_MISC2_REG); for (i = 0; i < insn->n; i++) { - outw(0, dev->iobase + DAS16CS_ADC_DATA); + outw(0, dev->iobase + DAS16CS_AI_DATA_REG); ret = comedi_timeout(dev, s, insn, das16cs_ai_eoc, 0); if (ret) return ret; - data[i] = inw(dev->iobase + DAS16CS_ADC_DATA); + data[i] = inw(dev->iobase + DAS16CS_AI_DATA_REG); } return i; @@ -151,39 +207,43 @@ static int das16cs_ao_insn_write(struct comedi_device *dev, struct das16cs_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); unsigned int val = s->readback[chan]; - unsigned short status1; + unsigned short misc1; int bit; int i; for (i = 0; i < insn->n; i++) { val = data[i]; - outw(devpriv->status1, dev->iobase + DAS16CS_MISC1); + outw(devpriv->misc1, dev->iobase + DAS16CS_MISC1_REG); udelay(1); - status1 = devpriv->status1 & ~0xf; + /* raise the DACxCS line for the non-selected channel */ + misc1 = devpriv->misc1 & ~DAS16CS_MISC1_DAC_MASK; if (chan) - status1 |= 0x0001; + misc1 |= DAS16CS_MISC1_DAC0CS; else - status1 |= 0x0008; + misc1 |= DAS16CS_MISC1_DAC1CS; - outw(status1, dev->iobase + DAS16CS_MISC1); + outw(misc1, dev->iobase + DAS16CS_MISC1_REG); udelay(1); for (bit = 15; bit >= 0; bit--) { - int b = (val >> bit) & 0x1; - - b <<= 1; - outw(status1 | b | 0x0000, dev->iobase + DAS16CS_MISC1); + if ((val >> bit) & 0x1) + misc1 |= DAS16CS_MISC1_DACSD; + else + misc1 &= ~DAS16CS_MISC1_DACSD; + outw(misc1, dev->iobase + DAS16CS_MISC1_REG); udelay(1); - outw(status1 | b | 0x0004, dev->iobase + DAS16CS_MISC1); + outw(misc1 | DAS16CS_MISC1_DACCLK, + dev->iobase + DAS16CS_MISC1_REG); udelay(1); } /* * Make both DAC0CS and DAC1CS high to load * the new data and update analog the output */ - outw(status1 | 0x9, dev->iobase + DAS16CS_MISC1); + outw(misc1 | DAS16CS_MISC1_DAC0CS | DAS16CS_MISC1_DAC1CS, + dev->iobase + DAS16CS_MISC1_REG); } s->readback[chan] = val; @@ -196,9 +256,9 @@ static int das16cs_dio_insn_bits(struct comedi_device *dev, unsigned int *data) { if (comedi_dio_update_state(s, data)) - outw(s->state, dev->iobase + DAS16CS_DIO); + outw(s->state, dev->iobase + DAS16CS_DIO_REG); - data[1] = inw(dev->iobase + DAS16CS_DIO); + data[1] = inw(dev->iobase + DAS16CS_DIO_REG); return insn->n; } @@ -222,11 +282,52 @@ static int das16cs_dio_insn_config(struct comedi_device *dev, if (ret) return ret; - devpriv->status2 &= ~0x00c0; - devpriv->status2 |= (s->io_bits & 0xf0) ? 0x0080 : 0; - devpriv->status2 |= (s->io_bits & 0x0f) ? 0x0040 : 0; + if (s->io_bits & 0xf0) + devpriv->misc2 |= DAS16CS_MISC2_UDIR; + else + devpriv->misc2 &= ~DAS16CS_MISC2_UDIR; + if (s->io_bits & 0x0f) + devpriv->misc2 |= DAS16CS_MISC2_LDIR; + else + devpriv->misc2 &= ~DAS16CS_MISC2_LDIR; + outw(devpriv->misc2, dev->iobase + DAS16CS_MISC2_REG); - outw(devpriv->status2, dev->iobase + DAS16CS_MISC2); + return insn->n; +} + +static int das16cs_counter_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct das16cs_private *devpriv = dev->private; + + switch (data[0]) { + case INSN_CONFIG_SET_CLOCK_SRC: + switch (data[1]) { + case 0: /* internal 100 kHz */ + devpriv->misc2 |= DAS16CS_MISC2_CTR1; + break; + case 1: /* external */ + devpriv->misc2 &= ~DAS16CS_MISC2_CTR1; + break; + default: + return -EINVAL; + } + outw(devpriv->misc2, dev->iobase + DAS16CS_MISC2_REG); + break; + case INSN_CONFIG_GET_CLOCK_SRC: + if (devpriv->misc2 & DAS16CS_MISC2_CTR1) { + data[1] = 0; + data[2] = I8254_OSC_BASE_100KHZ; + } else { + data[1] = 1; + data[2] = 0; /* unknown */ + } + break; + default: + return -EINVAL; + } return insn->n; } @@ -278,26 +379,25 @@ static int das16cs_auto_attach(struct comedi_device *dev, if (!dev->pacer) return -ENOMEM; - ret = comedi_alloc_subdevices(dev, 3); + ret = comedi_alloc_subdevices(dev, 4); if (ret) return ret; + /* Analog Input subdevice */ s = &dev->subdevices[0]; - /* analog input subdevice */ s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF; s->n_chan = 16; s->maxdata = 0xffff; s->range_table = &das16cs_ai_range; - s->len_chanlist = 16; - s->insn_read = das16cs_ai_rinsn; + s->insn_read = das16cs_ai_insn_read; + /* Analog Output subdevice */ s = &dev->subdevices[1]; - /* analog output subdevice */ - if (board->n_ao_chans) { + if (board->has_ao) { s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITABLE; - s->n_chan = board->n_ao_chans; + s->n_chan = 2; s->maxdata = 0xffff; s->range_table = &range_bipolar10; s->insn_write = &das16cs_ao_insn_write; @@ -309,16 +409,26 @@ static int das16cs_auto_attach(struct comedi_device *dev, s->type = COMEDI_SUBD_UNUSED; } + /* Digital I/O subdevice */ s = &dev->subdevices[2]; - /* digital i/o subdevice */ s->type = COMEDI_SUBD_DIO; s->subdev_flags = SDF_READABLE | SDF_WRITABLE; - s->n_chan = 8; + s->n_chan = board->has_4dio ? 4 : 8; s->maxdata = 1; s->range_table = &range_digital; s->insn_bits = das16cs_dio_insn_bits; s->insn_config = das16cs_dio_insn_config; + /* Counter subdevice (8254) */ + s = &dev->subdevices[3]; + comedi_8254_subdevice_init(s, dev->pacer); + + dev->pacer->insn_config = das16cs_counter_insn_config; + + /* counters 1 and 2 are used internally for the pacer */ + comedi_8254_set_busy(dev->pacer, 1, true); + comedi_8254_set_busy(dev->pacer, 2, true); + return 0; } diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c index b43e836575fd..3cd008acb657 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas.c +++ b/drivers/staging/comedi/drivers/cb_pcidas.c @@ -1,65 +1,64 @@ /* - comedi/drivers/cb_pcidas.c + * cb_pcidas.c + * Developed by Ivan Martinez and Frank Mori Hess, with valuable help from + * David Schleef and the rest of the Comedi developers comunity. + * + * Copyright (C) 2001-2003 Ivan Martinez + * Copyright (C) 2001,2002 Frank Mori Hess + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1997-8 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. + */ - Developed by Ivan Martinez and Frank Mori Hess, with valuable help from - David Schleef and the rest of the Comedi developers comunity. - - Copyright (C) 2001-2003 Ivan Martinez - Copyright (C) 2001,2002 Frank Mori Hess - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 1997-8 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. -*/ /* -Driver: cb_pcidas -Description: MeasurementComputing PCI-DAS series - with the AMCC S5933 PCI controller -Author: Ivan Martinez , - Frank Mori Hess -Updated: 2003-3-11 -Devices: [Measurement Computing] PCI-DAS1602/16 (cb_pcidas), - PCI-DAS1602/16jr, PCI-DAS1602/12, PCI-DAS1200, PCI-DAS1200jr, - PCI-DAS1000, PCI-DAS1001, PCI_DAS1002 + * Driver: cb_pcidas + * Description: MeasurementComputing PCI-DAS series + * with the AMCC S5933 PCI controller + * Devices: [Measurement Computing] PCI-DAS1602/16 (cb_pcidas), + * PCI-DAS1602/16jr, PCI-DAS1602/12, PCI-DAS1200, PCI-DAS1200jr, + * PCI-DAS1000, PCI-DAS1001, PCI_DAS1002 + * Author: Ivan Martinez , + * Frank Mori Hess + * Updated: 2003-3-11 + * + * Status: + * There are many reports of the driver being used with most of the + * supported cards. Despite no detailed log is maintained, it can + * be said that the driver is quite tested and stable. + * + * The boards may be autocalibrated using the comedi_calibrate + * utility. + * + * Configuration options: not applicable, uses PCI auto config + * + * For commands, the scanned channels must be consecutive + * (i.e. 4-5-6-7, 2-3-4,...), and must all have the same + * range and aref. + * + * AI Triggering: + * For start_src == TRIG_EXT, the A/D EXTERNAL TRIGGER IN (pin 45) is used. + * For 1602 series, the start_arg is interpreted as follows: + * start_arg == 0 => gated trigger (level high) + * start_arg == CR_INVERT => gated trigger (level low) + * start_arg == CR_EDGE => Rising edge + * start_arg == CR_EDGE | CR_INVERT => Falling edge + * For the other boards the trigger will be done on rising edge + */ -Status: - There are many reports of the driver being used with most of the - supported cards. Despite no detailed log is maintained, it can - be said that the driver is quite tested and stable. - - The boards may be autocalibrated using the comedi_calibrate - utility. - -Configuration options: not applicable, uses PCI auto config - -For commands, the scanned channels must be consecutive -(i.e. 4-5-6-7, 2-3-4,...), and must all have the same -range and aref. - -AI Triggering: - For start_src == TRIG_EXT, the A/D EXTERNAL TRIGGER IN (pin 45) is used. - For 1602 series, the start_arg is interpreted as follows: - start_arg == 0 => gated trigger (level high) - start_arg == CR_INVERT => gated trigger (level low) - start_arg == CR_EDGE => Rising edge - start_arg == CR_EDGE | CR_INVERT => Falling edge - For the other boards the trigger will be done on rising edge -*/ /* - -TODO: - -analog triggering on 1602 series -*/ + * TODO: + * analog triggering on 1602 series + */ #include #include @@ -73,109 +72,107 @@ analog triggering on 1602 series #define AI_BUFFER_SIZE 1024 /* max ai fifo size */ #define AO_BUFFER_SIZE 1024 /* max ao fifo size */ -#define NUM_CHANNELS_8800 8 -#define NUM_CHANNELS_7376 1 -#define NUM_CHANNELS_8402 2 -#define NUM_CHANNELS_DAC08 1 -/* Control/Status registers */ -#define INT_ADCFIFO 0 /* INTERRUPT / ADC FIFO register */ -#define INT_EOS 0x1 /* int end of scan */ -#define INT_FHF 0x2 /* int fifo half full */ -#define INT_FNE 0x3 /* int fifo not empty */ -#define INT_MASK 0x3 /* mask of int select bits */ -#define INTE 0x4 /* int enable */ -#define DAHFIE 0x8 /* dac half full int enable */ -#define EOAIE 0x10 /* end of acq. int enable */ -#define DAHFI 0x20 /* dac half full status / clear */ -#define EOAI 0x40 /* end of acq. int status / clear */ -#define INT 0x80 /* int status / clear */ -#define EOBI 0x200 /* end of burst int status */ -#define ADHFI 0x400 /* half-full int status */ -#define ADNEI 0x800 /* fifo not empty int status (latch) */ -#define ADNE 0x1000 /* fifo not empty status (realtime) */ -#define DAEMIE 0x1000 /* dac empty int enable */ -#define LADFUL 0x2000 /* fifo overflow / clear */ -#define DAEMI 0x4000 /* dac fifo empty int status / clear */ +/* + * PCI BAR1 Register map (devpriv->pcibar1) + */ +#define PCIDAS_CTRL_REG 0x00 /* INTERRUPT / ADC FIFO register */ +#define PCIDAS_CTRL_INT(x) (((x) & 0x3) << 0) +#define PCIDAS_CTRL_INT_NONE PCIDAS_CTRL_INT(0) /* no int selected */ +#define PCIDAS_CTRL_INT_EOS PCIDAS_CTRL_INT(1) /* int on end of scan */ +#define PCIDAS_CTRL_INT_FHF PCIDAS_CTRL_INT(2) /* int on fifo half full */ +#define PCIDAS_CTRL_INT_FNE PCIDAS_CTRL_INT(3) /* int on fifo not empty */ +#define PCIDAS_CTRL_INT_MASK PCIDAS_CTRL_INT(3) /* mask of int select bits */ +#define PCIDAS_CTRL_INTE BIT(2) /* int enable */ +#define PCIDAS_CTRL_DAHFIE BIT(3) /* dac half full int enable */ +#define PCIDAS_CTRL_EOAIE BIT(4) /* end of acq. int enable */ +#define PCIDAS_CTRL_DAHFI BIT(5) /* dac half full status / clear */ +#define PCIDAS_CTRL_EOAI BIT(6) /* end of acq. int status / clear */ +#define PCIDAS_CTRL_INT_CLR BIT(7) /* int status / clear */ +#define PCIDAS_CTRL_EOBI BIT(9) /* end of burst int status */ +#define PCIDAS_CTRL_ADHFI BIT(10) /* half-full int status */ +#define PCIDAS_CTRL_ADNEI BIT(11) /* fifo not empty int status (latch) */ +#define PCIDAS_CTRL_ADNE BIT(12) /* fifo not empty status (realtime) */ +#define PCIDAS_CTRL_DAEMIE BIT(12) /* dac empty int enable */ +#define PCIDAS_CTRL_LADFUL BIT(13) /* fifo overflow / clear */ +#define PCIDAS_CTRL_DAEMI BIT(14) /* dac fifo empty int status / clear */ -#define ADCMUX_CONT 2 /* ADC CHANNEL MUX AND CONTROL reg */ -#define BEGIN_SCAN(x) ((x) & 0xf) -#define END_SCAN(x) (((x) & 0xf) << 4) -#define GAIN_BITS(x) (((x) & 0x3) << 8) -#define UNIP 0x800 /* Analog front-end unipolar mode */ -#define SE 0x400 /* Inputs in single-ended mode */ -#define PACER_MASK 0x3000 /* pacer source bits */ -#define PACER_INT 0x1000 /* int. pacer */ -#define PACER_EXT_FALL 0x2000 /* ext. falling edge */ -#define PACER_EXT_RISE 0x3000 /* ext. rising edge */ -#define EOC 0x4000 /* adc not busy */ +#define PCIDAS_CTRL_AI_INT (PCIDAS_CTRL_EOAI | PCIDAS_CTRL_EOBI | \ + PCIDAS_CTRL_ADHFI | PCIDAS_CTRL_ADNEI | \ + PCIDAS_CTRL_LADFUL) +#define PCIDAS_CTRL_AO_INT (PCIDAS_CTRL_DAHFI | PCIDAS_CTRL_DAEMI) -#define TRIG_CONTSTAT 4 /* TRIGGER CONTROL/STATUS register */ -#define SW_TRIGGER 0x1 /* software start trigger */ -#define EXT_TRIGGER 0x2 /* ext. start trigger */ -#define ANALOG_TRIGGER 0x3 /* ext. analog trigger */ -#define TRIGGER_MASK 0x3 /* start trigger mask */ -#define TGPOL 0x04 /* invert trigger (1602 only) */ -#define TGSEL 0x08 /* edge/level trigerred (1602 only) */ -#define TGEN 0x10 /* enable external start trigger */ -#define BURSTE 0x20 /* burst mode enable */ -#define XTRCL 0x80 /* clear external trigger */ +#define PCIDAS_AI_REG 0x02 /* ADC CHANNEL MUX AND CONTROL reg */ +#define PCIDAS_AI_FIRST(x) ((x) & 0xf) +#define PCIDAS_AI_LAST(x) (((x) & 0xf) << 4) +#define PCIDAS_AI_CHAN(x) (PCIDAS_AI_FIRST(x) | PCIDAS_AI_LAST(x)) +#define PCIDAS_AI_GAIN(x) (((x) & 0x3) << 8) +#define PCIDAS_AI_SE BIT(10) /* Inputs in single-ended mode */ +#define PCIDAS_AI_UNIP BIT(11) /* Analog front-end unipolar mode */ +#define PCIDAS_AI_PACER(x) (((x) & 0x3) << 12) +#define PCIDAS_AI_PACER_SW PCIDAS_AI_PACER(0) /* software pacer */ +#define PCIDAS_AI_PACER_INT PCIDAS_AI_PACER(1) /* int. pacer */ +#define PCIDAS_AI_PACER_EXTN PCIDAS_AI_PACER(2) /* ext. falling edge */ +#define PCIDAS_AI_PACER_EXTP PCIDAS_AI_PACER(3) /* ext. rising edge */ +#define PCIDAS_AI_PACER_MASK PCIDAS_AI_PACER(3) /* pacer source bits */ +#define PCIDAS_AI_EOC BIT(14) /* adc not busy */ -#define CALIBRATION_REG 6 /* CALIBRATION register */ -#define SELECT_8800_BIT 0x100 /* select 8800 caldac */ -#define SELECT_TRIMPOT_BIT 0x200 /* select ad7376 trim pot */ -#define SELECT_DAC08_BIT 0x400 /* select dac08 caldac */ -#define CAL_SRC_BITS(x) (((x) & 0x7) << 11) -#define CAL_EN_BIT 0x4000 /* calibration source enable */ -#define SERIAL_DATA_IN_BIT 0x8000 /* serial data bit going to caldac */ +#define PCIDAS_TRIG_REG 0x04 /* TRIGGER CONTROL/STATUS register */ +#define PCIDAS_TRIG_SEL(x) (((x) & 0x3) << 0) +#define PCIDAS_TRIG_SEL_NONE PCIDAS_TRIG_SEL(0) /* no start trigger */ +#define PCIDAS_TRIG_SEL_SW PCIDAS_TRIG_SEL(1) /* software start trigger */ +#define PCIDAS_TRIG_SEL_EXT PCIDAS_TRIG_SEL(2) /* ext. start trigger */ +#define PCIDAS_TRIG_SEL_ANALOG PCIDAS_TRIG_SEL(3) /* ext. analog trigger */ +#define PCIDAS_TRIG_SEL_MASK PCIDAS_TRIG_SEL(3) /* start trigger mask */ +#define PCIDAS_TRIG_POL BIT(2) /* invert trigger (1602 only) */ +#define PCIDAS_TRIG_MODE BIT(3) /* edge/level trigerred (1602 only) */ +#define PCIDAS_TRIG_EN BIT(4) /* enable external start trigger */ +#define PCIDAS_TRIG_BURSTE BIT(5) /* burst mode enable */ +#define PCIDAS_TRIG_CLR BIT(7) /* clear external trigger */ -#define DAC_CSR 0x8 /* dac control and status register */ -#define DACEN 0x02 /* dac enable */ -#define DAC_MODE_UPDATE_BOTH 0x80 /* update both dacs */ +#define PCIDAS_CALIB_REG 0x06 /* CALIBRATION register */ +#define PCIDAS_CALIB_8800_SEL BIT(8) /* select 8800 caldac */ +#define PCIDAS_CALIB_TRIM_SEL BIT(9) /* select ad7376 trim pot */ +#define PCIDAS_CALIB_DAC08_SEL BIT(10) /* select dac08 caldac */ +#define PCIDAS_CALIB_SRC(x) (((x) & 0x7) << 11) +#define PCIDAS_CALIB_EN BIT(14) /* calibration source enable */ +#define PCIDAS_CALIB_DATA BIT(15) /* serial data bit going to caldac */ -static inline unsigned int DAC_RANGE(unsigned int channel, unsigned int range) -{ - return (range & 0x3) << (8 + 2 * (channel & 0x1)); -} +#define PCIDAS_AO_REG 0x08 /* dac control and status register */ +#define PCIDAS_AO_EMPTY BIT(0) /* fifo empty, write clear (1602) */ +#define PCIDAS_AO_DACEN BIT(1) /* dac enable */ +#define PCIDAS_AO_START BIT(2) /* start/arm fifo (1602) */ +#define PCIDAS_AO_PACER(x) (((x) & 0x3) << 3) /* (1602) */ +#define PCIDAS_AO_PACER_SW PCIDAS_AO_PACER(0) /* software pacer */ +#define PCIDAS_AO_PACER_INT PCIDAS_AO_PACER(1) /* int. pacer */ +#define PCIDAS_AO_PACER_EXTN PCIDAS_AO_PACER(2) /* ext. falling edge */ +#define PCIDAS_AO_PACER_EXTP PCIDAS_AO_PACER(3) /* ext. rising edge */ +#define PCIDAS_AO_PACER_MASK PCIDAS_AO_PACER(3) /* pacer source bits */ +#define PCIDAS_AO_CHAN_EN(c) BIT(5 + ((c) & 0x1)) +#define PCIDAS_AO_CHAN_MASK (PCIDAS_AO_CHAN_EN(0) | PCIDAS_AO_CHAN_EN(1)) +#define PCIDAS_AO_UPDATE_BOTH BIT(7) /* update both dacs */ +#define PCIDAS_AO_RANGE(c, r) (((r) & 0x3) << (8 + 2 * ((c) & 0x1))) +#define PCIDAS_AO_RANGE_MASK(c) PCIDAS_AO_RANGE((c), 0x3) -static inline unsigned int DAC_RANGE_MASK(unsigned int channel) -{ - return 0x3 << (8 + 2 * (channel & 0x1)); -}; +/* + * PCI BAR2 Register map (devpriv->pcibar2) + */ +#define PCIDAS_AI_DATA_REG 0x00 +#define PCIDAS_AI_FIFO_CLR_REG 0x02 -/* bits for 1602 series only */ -#define DAC_EMPTY 0x1 /* fifo empty, read, write clear */ -#define DAC_START 0x4 /* start/arm fifo operations */ -#define DAC_PACER_MASK 0x18 /* bits that set pacer source */ -#define DAC_PACER_INT 0x8 /* int. pacing */ -#define DAC_PACER_EXT_FALL 0x10 /* ext. pacing, falling edge */ -#define DAC_PACER_EXT_RISE 0x18 /* ext. pacing, rising edge */ +/* + * PCI BAR3 Register map (dev->iobase) + */ +#define PCIDAS_AI_8254_BASE 0x00 +#define PCIDAS_8255_BASE 0x04 +#define PCIDAS_AO_8254_BASE 0x08 -static inline unsigned int DAC_CHAN_EN(unsigned int channel) -{ - return 1 << (5 + (channel & 0x1)); /* enable channel 0 or 1 */ -}; - -/* analog input fifo */ -#define ADCDATA 0 /* ADC DATA register */ -#define ADCFIFOCLR 2 /* ADC FIFO CLEAR */ - -/* pacer, counter, dio registers */ -#define ADC8254 0 -#define DIO_8255 4 -#define DAC8254 8 - -/* analog output registers for 100x, 1200 series */ -static inline unsigned int DAC_DATA_REG(unsigned int channel) -{ - return 2 * (channel & 0x1); -} - -/* analog output registers for 1602 series*/ -#define DACDATA 0 /* DAC DATA register */ -#define DACFIFOCLR 2 /* DAC FIFO CLEAR */ - -#define IS_UNIPOLAR 0x4 /* unipolar range mask */ +/* + * PCI BAR4 Register map (devpriv->pcibar4) + */ +#define PCIDAS_AO_DATA_REG(x) (0x00 + ((x) * 2)) +#define PCIDAS_AO_FIFO_REG 0x00 +#define PCIDAS_AO_FIFO_CLR_REG 0x02 /* analog input ranges for most boards */ static const struct comedi_lrange cb_pcidas_ranges = { @@ -215,11 +212,6 @@ static const struct comedi_lrange cb_pcidas_ao_ranges = { } }; -enum trimpot_model { - AD7376, - AD8402, -}; - enum cb_pcidas_boardid { BOARD_PCIDAS1602_16, BOARD_PCIDAS1200, @@ -233,132 +225,97 @@ enum cb_pcidas_boardid { struct cb_pcidas_board { const char *name; - int ai_nchan; /* Inputs in single-ended mode */ - int ai_bits; /* analog input resolution */ int ai_speed; /* fastest conversion period in ns */ - int ao_nchan; /* number of analog out channels */ - int has_ao_fifo; /* analog output has fifo */ int ao_scan_speed; /* analog output scan speed for 1602 series */ int fifo_size; /* number of samples fifo can hold */ - const struct comedi_lrange *ranges; - enum trimpot_model trimpot; - unsigned has_dac08:1; - unsigned is_1602:1; + unsigned int is_16bit; /* ai/ao is 1=16-bit; 0=12-bit */ + unsigned int use_alt_range:1; /* use alternate ai range table */ + unsigned int has_ao:1; /* has 2 analog output channels */ + unsigned int has_ao_fifo:1; /* analog output has fifo */ + unsigned int has_ad8402:1; /* trimpot type 1=AD8402; 0=AD7376 */ + unsigned int has_dac08:1; + unsigned int is_1602:1; }; static const struct cb_pcidas_board cb_pcidas_boards[] = { [BOARD_PCIDAS1602_16] = { .name = "pci-das1602/16", - .ai_nchan = 16, - .ai_bits = 16, .ai_speed = 5000, - .ao_nchan = 2, - .has_ao_fifo = 1, .ao_scan_speed = 10000, .fifo_size = 512, - .ranges = &cb_pcidas_ranges, - .trimpot = AD8402, + .is_16bit = 1, + .has_ao = 1, + .has_ao_fifo = 1, + .has_ad8402 = 1, .has_dac08 = 1, .is_1602 = 1, }, [BOARD_PCIDAS1200] = { .name = "pci-das1200", - .ai_nchan = 16, - .ai_bits = 12, .ai_speed = 3200, - .ao_nchan = 2, .fifo_size = 1024, - .ranges = &cb_pcidas_ranges, - .trimpot = AD7376, + .has_ao = 1, }, [BOARD_PCIDAS1602_12] = { .name = "pci-das1602/12", - .ai_nchan = 16, - .ai_bits = 12, .ai_speed = 3200, - .ao_nchan = 2, - .has_ao_fifo = 1, .ao_scan_speed = 4000, .fifo_size = 1024, - .ranges = &cb_pcidas_ranges, - .trimpot = AD7376, + .has_ao = 1, + .has_ao_fifo = 1, .is_1602 = 1, }, [BOARD_PCIDAS1200_JR] = { .name = "pci-das1200/jr", - .ai_nchan = 16, - .ai_bits = 12, .ai_speed = 3200, .fifo_size = 1024, - .ranges = &cb_pcidas_ranges, - .trimpot = AD7376, }, [BOARD_PCIDAS1602_16_JR] = { .name = "pci-das1602/16/jr", - .ai_nchan = 16, - .ai_bits = 16, .ai_speed = 5000, .fifo_size = 512, - .ranges = &cb_pcidas_ranges, - .trimpot = AD8402, + .is_16bit = 1, + .has_ad8402 = 1, .has_dac08 = 1, .is_1602 = 1, }, [BOARD_PCIDAS1000] = { .name = "pci-das1000", - .ai_nchan = 16, - .ai_bits = 12, .ai_speed = 4000, .fifo_size = 1024, - .ranges = &cb_pcidas_ranges, - .trimpot = AD7376, }, [BOARD_PCIDAS1001] = { .name = "pci-das1001", - .ai_nchan = 16, - .ai_bits = 12, .ai_speed = 6800, - .ao_nchan = 2, .fifo_size = 1024, - .ranges = &cb_pcidas_alt_ranges, - .trimpot = AD7376, + .use_alt_range = 1, + .has_ao = 1, }, [BOARD_PCIDAS1002] = { .name = "pci-das1002", - .ai_nchan = 16, - .ai_bits = 12, .ai_speed = 6800, - .ao_nchan = 2, .fifo_size = 1024, - .ranges = &cb_pcidas_ranges, - .trimpot = AD7376, + .has_ao = 1, }, }; struct cb_pcidas_private { struct comedi_8254 *ao_pacer; /* base addresses */ - unsigned long s5933_config; - unsigned long control_status; - unsigned long adc_fifo; - unsigned long ao_registers; + unsigned long amcc; /* pcibar0 */ + unsigned long pcibar1; + unsigned long pcibar2; + unsigned long pcibar4; /* bits to write to registers */ - unsigned int adc_fifo_bits; - unsigned int s5933_intcsr_bits; - unsigned int ao_control_bits; + unsigned int ctrl; + unsigned int amcc_intcsr; + unsigned int ao_ctrl; /* fifo buffers */ unsigned short ai_buffer[AI_BUFFER_SIZE]; unsigned short ao_buffer[AO_BUFFER_SIZE]; - unsigned int calibration_source; + unsigned int calib_src; }; -static inline unsigned int cal_enable_bits(struct comedi_device *dev) -{ - struct cb_pcidas_private *devpriv = dev->private; - - return CAL_EN_BIT | CAL_SRC_BITS(devpriv->calibration_source); -} - static int cb_pcidas_ai_eoc(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -367,15 +324,16 @@ static int cb_pcidas_ai_eoc(struct comedi_device *dev, struct cb_pcidas_private *devpriv = dev->private; unsigned int status; - status = inw(devpriv->control_status + ADCMUX_CONT); - if (status & EOC) + status = inw(devpriv->pcibar1 + PCIDAS_AI_REG); + if (status & PCIDAS_AI_EOC) return 0; return -EBUSY; } -static int cb_pcidas_ai_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int cb_pcidas_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct cb_pcidas_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); @@ -387,30 +345,30 @@ static int cb_pcidas_ai_rinsn(struct comedi_device *dev, /* enable calibration input if appropriate */ if (insn->chanspec & CR_ALT_SOURCE) { - outw(cal_enable_bits(dev), - devpriv->control_status + CALIBRATION_REG); + outw(PCIDAS_CALIB_EN | PCIDAS_CALIB_SRC(devpriv->calib_src), + devpriv->pcibar1 + PCIDAS_CALIB_REG); chan = 0; } else { - outw(0, devpriv->control_status + CALIBRATION_REG); + outw(0, devpriv->pcibar1 + PCIDAS_CALIB_REG); } /* set mux limits and gain */ - bits = BEGIN_SCAN(chan) | END_SCAN(chan) | GAIN_BITS(range); + bits = PCIDAS_AI_CHAN(chan) | PCIDAS_AI_GAIN(range); /* set unipolar/bipolar */ - if (range & IS_UNIPOLAR) - bits |= UNIP; + if (comedi_range_is_unipolar(s, range)) + bits |= PCIDAS_AI_UNIP; /* set single-ended/differential */ if (aref != AREF_DIFF) - bits |= SE; - outw(bits, devpriv->control_status + ADCMUX_CONT); + bits |= PCIDAS_AI_SE; + outw(bits, devpriv->pcibar1 + PCIDAS_AI_REG); /* clear fifo */ - outw(0, devpriv->adc_fifo + ADCFIFOCLR); + outw(0, devpriv->pcibar2 + PCIDAS_AI_FIFO_CLR_REG); /* convert n samples */ for (n = 0; n < insn->n; n++) { /* trigger conversion */ - outw(0, devpriv->adc_fifo + ADCDATA); + outw(0, devpriv->pcibar2 + PCIDAS_AI_DATA_REG); /* wait for conversion to end */ ret = comedi_timeout(dev, s, insn, cb_pcidas_ai_eoc, 0); @@ -418,15 +376,17 @@ static int cb_pcidas_ai_rinsn(struct comedi_device *dev, return ret; /* read data */ - data[n] = inw(devpriv->adc_fifo + ADCDATA); + data[n] = inw(devpriv->pcibar2 + PCIDAS_AI_DATA_REG); } /* return the number of samples read/written */ return n; } -static int ai_config_insn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int cb_pcidas_ai_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct cb_pcidas_private *devpriv = dev->private; int id = data[0]; @@ -440,7 +400,7 @@ static int ai_config_insn(struct comedi_device *dev, struct comedi_subdevice *s, source); return -EINVAL; } - devpriv->calibration_source = source; + devpriv->calib_src = source; break; default: return -EINVAL; @@ -449,155 +409,160 @@ static int ai_config_insn(struct comedi_device *dev, struct comedi_subdevice *s, } /* analog output insn for pcidas-1000 and 1200 series */ -static int cb_pcidas_ao_nofifo_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) +static int cb_pcidas_ao_nofifo_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct cb_pcidas_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec); + unsigned int val = s->readback[chan]; unsigned long flags; + int i; /* set channel and range */ spin_lock_irqsave(&dev->spinlock, flags); - devpriv->ao_control_bits &= (~DAC_MODE_UPDATE_BOTH & - ~DAC_RANGE_MASK(chan)); - devpriv->ao_control_bits |= (DACEN | DAC_RANGE(chan, range)); - outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR); + devpriv->ao_ctrl &= ~(PCIDAS_AO_UPDATE_BOTH | + PCIDAS_AO_RANGE_MASK(chan)); + devpriv->ao_ctrl |= PCIDAS_AO_DACEN | PCIDAS_AO_RANGE(chan, range); + outw(devpriv->ao_ctrl, devpriv->pcibar1 + PCIDAS_AO_REG); spin_unlock_irqrestore(&dev->spinlock, flags); - /* remember value for readback */ - s->readback[chan] = data[0]; + for (i = 0; i < insn->n; i++) { + val = data[i]; + outw(val, devpriv->pcibar4 + PCIDAS_AO_DATA_REG(chan)); + } - /* send data */ - outw(data[0], devpriv->ao_registers + DAC_DATA_REG(chan)); + s->readback[chan] = val; return insn->n; } /* analog output insn for pcidas-1602 series */ -static int cb_pcidas_ao_fifo_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int cb_pcidas_ao_fifo_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct cb_pcidas_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec); + unsigned int val = s->readback[chan]; unsigned long flags; + int i; /* clear dac fifo */ - outw(0, devpriv->ao_registers + DACFIFOCLR); + outw(0, devpriv->pcibar4 + PCIDAS_AO_FIFO_CLR_REG); /* set channel and range */ spin_lock_irqsave(&dev->spinlock, flags); - devpriv->ao_control_bits &= (~DAC_CHAN_EN(0) & ~DAC_CHAN_EN(1) & - ~DAC_RANGE_MASK(chan) & ~DAC_PACER_MASK); - devpriv->ao_control_bits |= (DACEN | DAC_RANGE(chan, range) | - DAC_CHAN_EN(chan) | DAC_START); - outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR); + devpriv->ao_ctrl &= ~(PCIDAS_AO_CHAN_MASK | PCIDAS_AO_RANGE_MASK(chan) | + PCIDAS_AO_PACER_MASK); + devpriv->ao_ctrl |= PCIDAS_AO_DACEN | PCIDAS_AO_RANGE(chan, range) | + PCIDAS_AO_CHAN_EN(chan) | PCIDAS_AO_START; + outw(devpriv->ao_ctrl, devpriv->pcibar1 + PCIDAS_AO_REG); spin_unlock_irqrestore(&dev->spinlock, flags); - /* remember value for readback */ - s->readback[chan] = data[0]; + for (i = 0; i < insn->n; i++) { + val = data[i]; + outw(val, devpriv->pcibar4 + PCIDAS_AO_FIFO_REG); + } - /* send data */ - outw(data[0], devpriv->ao_registers + DACDATA); + s->readback[chan] = val; return insn->n; } -static int wait_for_nvram_ready(unsigned long s5933_base_addr) +static int cb_pcidas_eeprom_ready(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned long context) { - static const int timeout = 1000; - unsigned int i; + struct cb_pcidas_private *devpriv = dev->private; + unsigned int status; - for (i = 0; i < timeout; i++) { - if ((inb(s5933_base_addr + - AMCC_OP_REG_MCSR_NVCMD) & MCSR_NV_BUSY) - == 0) - return 0; - udelay(1); + status = inb(devpriv->amcc + AMCC_OP_REG_MCSR_NVCMD); + if ((status & MCSR_NV_BUSY) == 0) + return 0; + return -EBUSY; +} + +static int cb_pcidas_eeprom_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct cb_pcidas_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + int ret; + int i; + + for (i = 0; i < insn->n; i++) { + /* make sure eeprom is ready */ + ret = comedi_timeout(dev, s, insn, cb_pcidas_eeprom_ready, 0); + if (ret) + return ret; + + /* set address (chan) and read operation */ + outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_LOW_ADDR, + devpriv->amcc + AMCC_OP_REG_MCSR_NVCMD); + outb(chan & 0xff, devpriv->amcc + AMCC_OP_REG_MCSR_NVDATA); + outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_HIGH_ADDR, + devpriv->amcc + AMCC_OP_REG_MCSR_NVCMD); + outb((chan >> 8) & 0xff, + devpriv->amcc + AMCC_OP_REG_MCSR_NVDATA); + outb(MCSR_NV_ENABLE | MCSR_NV_READ, + devpriv->amcc + AMCC_OP_REG_MCSR_NVCMD); + + /* wait for data to be returned */ + ret = comedi_timeout(dev, s, insn, cb_pcidas_eeprom_ready, 0); + if (ret) + return ret; + + data[i] = inb(devpriv->amcc + AMCC_OP_REG_MCSR_NVDATA); } - return -1; + + return insn->n; } -static int nvram_read(struct comedi_device *dev, unsigned int address, - uint8_t *data) +static void cb_pcidas_calib_write(struct comedi_device *dev, + unsigned int val, unsigned int len, + bool trimpot) { struct cb_pcidas_private *devpriv = dev->private; - unsigned long iobase = devpriv->s5933_config; - - if (wait_for_nvram_ready(iobase) < 0) - return -ETIMEDOUT; - - outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_LOW_ADDR, - iobase + AMCC_OP_REG_MCSR_NVCMD); - outb(address & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA); - outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_HIGH_ADDR, - iobase + AMCC_OP_REG_MCSR_NVCMD); - outb((address >> 8) & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA); - outb(MCSR_NV_ENABLE | MCSR_NV_READ, iobase + AMCC_OP_REG_MCSR_NVCMD); - - if (wait_for_nvram_ready(iobase) < 0) - return -ETIMEDOUT; - - *data = inb(iobase + AMCC_OP_REG_MCSR_NVDATA); - - return 0; -} - -static int eeprom_read_insn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - uint8_t nvram_data; - int retval; - - retval = nvram_read(dev, CR_CHAN(insn->chanspec), &nvram_data); - if (retval < 0) - return retval; - - data[0] = nvram_data; - - return 1; -} - -static void write_calibration_bitstream(struct comedi_device *dev, - unsigned int register_bits, - unsigned int bitstream, - unsigned int bitstream_length) -{ - struct cb_pcidas_private *devpriv = dev->private; - static const int write_delay = 1; + unsigned int calib_bits; unsigned int bit; - for (bit = 1 << (bitstream_length - 1); bit; bit >>= 1) { - if (bitstream & bit) - register_bits |= SERIAL_DATA_IN_BIT; - else - register_bits &= ~SERIAL_DATA_IN_BIT; - udelay(write_delay); - outw(register_bits, devpriv->control_status + CALIBRATION_REG); + calib_bits = PCIDAS_CALIB_EN | PCIDAS_CALIB_SRC(devpriv->calib_src); + if (trimpot) { + /* select trimpot */ + calib_bits |= PCIDAS_CALIB_TRIM_SEL; + outw(calib_bits, devpriv->pcibar1 + PCIDAS_CALIB_REG); } -} -static void caldac_8800_write(struct comedi_device *dev, - unsigned int chan, uint8_t val) -{ - struct cb_pcidas_private *devpriv = dev->private; - static const int bitstream_length = 11; - unsigned int bitstream = ((chan & 0x7) << 8) | val; - static const int caldac_8800_udelay = 1; + /* write bitstream to calibration device */ + for (bit = 1 << (len - 1); bit; bit >>= 1) { + if (val & bit) + calib_bits |= PCIDAS_CALIB_DATA; + else + calib_bits &= ~PCIDAS_CALIB_DATA; + udelay(1); + outw(calib_bits, devpriv->pcibar1 + PCIDAS_CALIB_REG); + } + udelay(1); - write_calibration_bitstream(dev, cal_enable_bits(dev), bitstream, - bitstream_length); + calib_bits = PCIDAS_CALIB_EN | PCIDAS_CALIB_SRC(devpriv->calib_src); - udelay(caldac_8800_udelay); - outw(cal_enable_bits(dev) | SELECT_8800_BIT, - devpriv->control_status + CALIBRATION_REG); - udelay(caldac_8800_udelay); - outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG); + if (!trimpot) { + /* select caldac */ + outw(calib_bits | PCIDAS_CALIB_8800_SEL, + devpriv->pcibar1 + PCIDAS_CALIB_REG); + udelay(1); + } + + /* latch value to trimpot/caldac */ + outw(calib_bits, devpriv->pcibar1 + PCIDAS_CALIB_REG); } static int cb_pcidas_caldac_insn_write(struct comedi_device *dev, @@ -611,7 +576,9 @@ static int cb_pcidas_caldac_insn_write(struct comedi_device *dev, unsigned int val = data[insn->n - 1]; if (s->readback[chan] != val) { - caldac_8800_write(dev, chan, val); + /* write 11-bit channel/value to caldac */ + cb_pcidas_calib_write(dev, (chan << 8) | val, 11, + false); s->readback[chan] = val; } } @@ -619,21 +586,19 @@ static int cb_pcidas_caldac_insn_write(struct comedi_device *dev, return insn->n; } -/* 1602/16 pregain offset */ -static void dac08_write(struct comedi_device *dev, unsigned int value) +static void cb_pcidas_dac08_write(struct comedi_device *dev, unsigned int val) { struct cb_pcidas_private *devpriv = dev->private; - value &= 0xff; - value |= cal_enable_bits(dev); + val |= PCIDAS_CALIB_EN | PCIDAS_CALIB_SRC(devpriv->calib_src); /* latch the new value into the caldac */ - outw(value, devpriv->control_status + CALIBRATION_REG); + outw(val, devpriv->pcibar1 + PCIDAS_CALIB_REG); udelay(1); - outw(value | SELECT_DAC08_BIT, - devpriv->control_status + CALIBRATION_REG); + outw(val | PCIDAS_CALIB_DAC08_SEL, + devpriv->pcibar1 + PCIDAS_CALIB_REG); udelay(1); - outw(value, devpriv->control_status + CALIBRATION_REG); + outw(val, devpriv->pcibar1 + PCIDAS_CALIB_REG); udelay(1); } @@ -648,7 +613,7 @@ static int cb_pcidas_dac08_insn_write(struct comedi_device *dev, unsigned int val = data[insn->n - 1]; if (s->readback[chan] != val) { - dac08_write(dev, val); + cb_pcidas_dac08_write(dev, val); s->readback[chan] = val; } } @@ -656,67 +621,17 @@ static int cb_pcidas_dac08_insn_write(struct comedi_device *dev, return insn->n; } -static int trimpot_7376_write(struct comedi_device *dev, uint8_t value) -{ - struct cb_pcidas_private *devpriv = dev->private; - static const int bitstream_length = 7; - unsigned int bitstream = value & 0x7f; - unsigned int register_bits; - static const int ad7376_udelay = 1; - - register_bits = cal_enable_bits(dev) | SELECT_TRIMPOT_BIT; - udelay(ad7376_udelay); - outw(register_bits, devpriv->control_status + CALIBRATION_REG); - - write_calibration_bitstream(dev, register_bits, bitstream, - bitstream_length); - - udelay(ad7376_udelay); - outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG); - - return 0; -} - -/* For 1602/16 only - * ch 0 : adc gain - * ch 1 : adc postgain offset */ -static int trimpot_8402_write(struct comedi_device *dev, unsigned int channel, - uint8_t value) -{ - struct cb_pcidas_private *devpriv = dev->private; - static const int bitstream_length = 10; - unsigned int bitstream = ((channel & 0x3) << 8) | (value & 0xff); - unsigned int register_bits; - static const int ad8402_udelay = 1; - - register_bits = cal_enable_bits(dev) | SELECT_TRIMPOT_BIT; - udelay(ad8402_udelay); - outw(register_bits, devpriv->control_status + CALIBRATION_REG); - - write_calibration_bitstream(dev, register_bits, bitstream, - bitstream_length); - - udelay(ad8402_udelay); - outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG); - - return 0; -} - static void cb_pcidas_trimpot_write(struct comedi_device *dev, unsigned int chan, unsigned int val) { const struct cb_pcidas_board *board = dev->board_ptr; - switch (board->trimpot) { - case AD7376: - trimpot_7376_write(dev, val); - break; - case AD8402: - trimpot_8402_write(dev, chan, val); - break; - default: - dev_err(dev->class_dev, "driver bug?\n"); - break; + if (board->has_ad8402) { + /* write 10-bit channel/value to AD8402 trimpot */ + cb_pcidas_calib_write(dev, (chan << 8) | val, 10, true); + } else { + /* write 7-bit value to AD7376 trimpot */ + cb_pcidas_calib_write(dev, val, 7, true); } } @@ -883,32 +798,33 @@ static int cb_pcidas_ai_cmd(struct comedi_device *dev, struct cb_pcidas_private *devpriv = dev->private; struct comedi_async *async = s->async; struct comedi_cmd *cmd = &async->cmd; + unsigned int range0 = CR_RANGE(cmd->chanlist[0]); unsigned int bits; unsigned long flags; - /* make sure CAL_EN_BIT is disabled */ - outw(0, devpriv->control_status + CALIBRATION_REG); + /* make sure PCIDAS_CALIB_EN is disabled */ + outw(0, devpriv->pcibar1 + PCIDAS_CALIB_REG); /* initialize before settings pacer source and count values */ - outw(0, devpriv->control_status + TRIG_CONTSTAT); + outw(PCIDAS_TRIG_SEL_NONE, devpriv->pcibar1 + PCIDAS_TRIG_REG); /* clear fifo */ - outw(0, devpriv->adc_fifo + ADCFIFOCLR); + outw(0, devpriv->pcibar2 + PCIDAS_AI_FIFO_CLR_REG); /* set mux limits, gain and pacer source */ - bits = BEGIN_SCAN(CR_CHAN(cmd->chanlist[0])) | - END_SCAN(CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1])) | - GAIN_BITS(CR_RANGE(cmd->chanlist[0])); + bits = PCIDAS_AI_FIRST(CR_CHAN(cmd->chanlist[0])) | + PCIDAS_AI_LAST(CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1])) | + PCIDAS_AI_GAIN(range0); /* set unipolar/bipolar */ - if (CR_RANGE(cmd->chanlist[0]) & IS_UNIPOLAR) - bits |= UNIP; + if (comedi_range_is_unipolar(s, range0)) + bits |= PCIDAS_AI_UNIP; /* set singleended/differential */ if (CR_AREF(cmd->chanlist[0]) != AREF_DIFF) - bits |= SE; + bits |= PCIDAS_AI_SE; /* set pacer source */ if (cmd->convert_src == TRIG_EXT || cmd->scan_begin_src == TRIG_EXT) - bits |= PACER_EXT_RISE; + bits |= PCIDAS_AI_PACER_EXTP; else - bits |= PACER_INT; - outw(bits, devpriv->control_status + ADCMUX_CONT); + bits |= PCIDAS_AI_PACER_INT; + outw(bits, devpriv->pcibar1 + PCIDAS_AI_REG); /* load counters */ if (cmd->scan_begin_src == TRIG_TIMER || @@ -919,42 +835,43 @@ static int cb_pcidas_ai_cmd(struct comedi_device *dev, /* enable interrupts */ spin_lock_irqsave(&dev->spinlock, flags); - devpriv->adc_fifo_bits |= INTE; - devpriv->adc_fifo_bits &= ~INT_MASK; + devpriv->ctrl |= PCIDAS_CTRL_INTE; + devpriv->ctrl &= ~PCIDAS_CTRL_INT_MASK; if (cmd->flags & CMDF_WAKE_EOS) { if (cmd->convert_src == TRIG_NOW && cmd->chanlist_len > 1) { /* interrupt end of burst */ - devpriv->adc_fifo_bits |= INT_EOS; + devpriv->ctrl |= PCIDAS_CTRL_INT_EOS; } else { /* interrupt fifo not empty */ - devpriv->adc_fifo_bits |= INT_FNE; + devpriv->ctrl |= PCIDAS_CTRL_INT_FNE; } } else { /* interrupt fifo half full */ - devpriv->adc_fifo_bits |= INT_FHF; + devpriv->ctrl |= PCIDAS_CTRL_INT_FHF; } /* enable (and clear) interrupts */ - outw(devpriv->adc_fifo_bits | EOAI | INT | LADFUL, - devpriv->control_status + INT_ADCFIFO); + outw(devpriv->ctrl | + PCIDAS_CTRL_EOAI | PCIDAS_CTRL_INT_CLR | PCIDAS_CTRL_LADFUL, + devpriv->pcibar1 + PCIDAS_CTRL_REG); spin_unlock_irqrestore(&dev->spinlock, flags); /* set start trigger and burst mode */ bits = 0; if (cmd->start_src == TRIG_NOW) { - bits |= SW_TRIGGER; + bits |= PCIDAS_TRIG_SEL_SW; } else { /* TRIG_EXT */ - bits |= EXT_TRIGGER | TGEN | XTRCL; + bits |= PCIDAS_TRIG_SEL_EXT | PCIDAS_TRIG_EN | PCIDAS_TRIG_CLR; if (board->is_1602) { if (cmd->start_arg & CR_INVERT) - bits |= TGPOL; + bits |= PCIDAS_TRIG_POL; if (cmd->start_arg & CR_EDGE) - bits |= TGSEL; + bits |= PCIDAS_TRIG_MODE; } } if (cmd->convert_src == TRIG_NOW && cmd->chanlist_len > 1) - bits |= BURSTE; - outw(bits, devpriv->control_status + TRIG_CONTSTAT); + bits |= PCIDAS_TRIG_BURSTE; + outw(bits, devpriv->pcibar1 + PCIDAS_TRIG_REG); return 0; } @@ -1051,23 +968,21 @@ static int cb_pcidas_ao_cmdtest(struct comedi_device *dev, return 0; } -/* cancel analog input command */ -static int cb_pcidas_cancel(struct comedi_device *dev, - struct comedi_subdevice *s) +static int cb_pcidas_ai_cancel(struct comedi_device *dev, + struct comedi_subdevice *s) { struct cb_pcidas_private *devpriv = dev->private; unsigned long flags; spin_lock_irqsave(&dev->spinlock, flags); /* disable interrupts */ - devpriv->adc_fifo_bits &= ~INTE & ~EOAIE; - outw(devpriv->adc_fifo_bits, devpriv->control_status + INT_ADCFIFO); + devpriv->ctrl &= ~(PCIDAS_CTRL_INTE | PCIDAS_CTRL_EOAIE); + outw(devpriv->ctrl, devpriv->pcibar1 + PCIDAS_CTRL_REG); spin_unlock_irqrestore(&dev->spinlock, flags); /* disable start trigger source and burst mode */ - outw(0, devpriv->control_status + TRIG_CONTSTAT); - /* software pacer source */ - outw(0, devpriv->control_status + ADCMUX_CONT); + outw(PCIDAS_TRIG_SEL_NONE, devpriv->pcibar1 + PCIDAS_TRIG_REG); + outw(PCIDAS_AI_PACER_SW, devpriv->pcibar1 + PCIDAS_AI_REG); return 0; } @@ -1083,7 +998,8 @@ static void cb_pcidas_ao_load_fifo(struct comedi_device *dev, nbytes = comedi_buf_read_samples(s, devpriv->ao_buffer, nsamples); nsamples = comedi_bytes_to_samples(s, nbytes); - outsw(devpriv->ao_registers + DACDATA, devpriv->ao_buffer, nsamples); + outsw(devpriv->pcibar4 + PCIDAS_AO_FIFO_REG, + devpriv->ao_buffer, nsamples); } static int cb_pcidas_ao_inttrig(struct comedi_device *dev, @@ -1103,15 +1019,15 @@ static int cb_pcidas_ao_inttrig(struct comedi_device *dev, /* enable dac half-full and empty interrupts */ spin_lock_irqsave(&dev->spinlock, flags); - devpriv->adc_fifo_bits |= DAEMIE | DAHFIE; + devpriv->ctrl |= PCIDAS_CTRL_DAEMIE | PCIDAS_CTRL_DAHFIE; /* enable and clear interrupts */ - outw(devpriv->adc_fifo_bits | DAEMI | DAHFI, - devpriv->control_status + INT_ADCFIFO); + outw(devpriv->ctrl | PCIDAS_CTRL_DAEMI | PCIDAS_CTRL_DAHFI, + devpriv->pcibar1 + PCIDAS_CTRL_REG); /* start dac */ - devpriv->ao_control_bits |= DAC_START | DACEN | DAC_EMPTY; - outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR); + devpriv->ao_ctrl |= PCIDAS_AO_START | PCIDAS_AO_DACEN | PCIDAS_AO_EMPTY; + outw(devpriv->ao_ctrl, devpriv->pcibar1 + PCIDAS_AO_REG); spin_unlock_irqrestore(&dev->spinlock, flags); @@ -1132,21 +1048,21 @@ static int cb_pcidas_ao_cmd(struct comedi_device *dev, /* set channel limits, gain */ spin_lock_irqsave(&dev->spinlock, flags); for (i = 0; i < cmd->chanlist_len; i++) { + unsigned int chan = CR_CHAN(cmd->chanlist[i]); + unsigned int range = CR_RANGE(cmd->chanlist[i]); + /* enable channel */ - devpriv->ao_control_bits |= - DAC_CHAN_EN(CR_CHAN(cmd->chanlist[i])); + devpriv->ao_ctrl |= PCIDAS_AO_CHAN_EN(chan); /* set range */ - devpriv->ao_control_bits |= DAC_RANGE(CR_CHAN(cmd->chanlist[i]), - CR_RANGE(cmd-> - chanlist[i])); + devpriv->ao_ctrl |= PCIDAS_AO_RANGE(chan, range); } /* disable analog out before settings pacer source and count values */ - outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR); + outw(devpriv->ao_ctrl, devpriv->pcibar1 + PCIDAS_AO_REG); spin_unlock_irqrestore(&dev->spinlock, flags); /* clear fifo */ - outw(0, devpriv->ao_registers + DACFIFOCLR); + outw(0, devpriv->pcibar4 + PCIDAS_AO_FIFO_CLR_REG); /* load counters */ if (cmd->scan_begin_src == TRIG_TIMER) { @@ -1158,10 +1074,10 @@ static int cb_pcidas_ao_cmd(struct comedi_device *dev, spin_lock_irqsave(&dev->spinlock, flags); switch (cmd->scan_begin_src) { case TRIG_TIMER: - devpriv->ao_control_bits |= DAC_PACER_INT; + devpriv->ao_ctrl |= PCIDAS_AO_PACER_INT; break; case TRIG_EXT: - devpriv->ao_control_bits |= DAC_PACER_EXT_RISE; + devpriv->ao_ctrl |= PCIDAS_AO_PACER_EXTP; break; default: spin_unlock_irqrestore(&dev->spinlock, flags); @@ -1175,7 +1091,6 @@ static int cb_pcidas_ao_cmd(struct comedi_device *dev, return 0; } -/* cancel analog output command */ static int cb_pcidas_ao_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { @@ -1184,33 +1099,31 @@ static int cb_pcidas_ao_cancel(struct comedi_device *dev, spin_lock_irqsave(&dev->spinlock, flags); /* disable interrupts */ - devpriv->adc_fifo_bits &= ~DAHFIE & ~DAEMIE; - outw(devpriv->adc_fifo_bits, devpriv->control_status + INT_ADCFIFO); + devpriv->ctrl &= ~(PCIDAS_CTRL_DAHFIE | PCIDAS_CTRL_DAEMIE); + outw(devpriv->ctrl, devpriv->pcibar1 + PCIDAS_CTRL_REG); /* disable output */ - devpriv->ao_control_bits &= ~DACEN & ~DAC_PACER_MASK; - outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR); + devpriv->ao_ctrl &= ~(PCIDAS_AO_DACEN | PCIDAS_AO_PACER_MASK); + outw(devpriv->ao_ctrl, devpriv->pcibar1 + PCIDAS_AO_REG); spin_unlock_irqrestore(&dev->spinlock, flags); return 0; } -static void handle_ao_interrupt(struct comedi_device *dev, unsigned int status) +static unsigned int cb_pcidas_ao_interrupt(struct comedi_device *dev, + unsigned int status) { const struct cb_pcidas_board *board = dev->board_ptr; struct cb_pcidas_private *devpriv = dev->private; struct comedi_subdevice *s = dev->write_subdev; struct comedi_async *async = s->async; struct comedi_cmd *cmd = &async->cmd; - unsigned long flags; + unsigned int irq_clr = 0; - if (status & DAEMI) { - /* clear dac empty interrupt latch */ - spin_lock_irqsave(&dev->spinlock, flags); - outw(devpriv->adc_fifo_bits | DAEMI, - devpriv->control_status + INT_ADCFIFO); - spin_unlock_irqrestore(&dev->spinlock, flags); - if (inw(devpriv->ao_registers + DAC_CSR) & DAC_EMPTY) { + if (status & PCIDAS_CTRL_DAEMI) { + irq_clr |= PCIDAS_CTRL_DAEMI; + + if (inw(devpriv->pcibar4 + PCIDAS_AO_REG) & PCIDAS_AO_EMPTY) { if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg) { async->events |= COMEDI_CB_EOA; @@ -1219,83 +1132,55 @@ static void handle_ao_interrupt(struct comedi_device *dev, unsigned int status) async->events |= COMEDI_CB_ERROR; } } - } else if (status & DAHFI) { - cb_pcidas_ao_load_fifo(dev, s, board->fifo_size / 2); + } else if (status & PCIDAS_CTRL_DAHFI) { + irq_clr |= PCIDAS_CTRL_DAHFI; - /* clear half-full interrupt latch */ - spin_lock_irqsave(&dev->spinlock, flags); - outw(devpriv->adc_fifo_bits | DAHFI, - devpriv->control_status + INT_ADCFIFO); - spin_unlock_irqrestore(&dev->spinlock, flags); + cb_pcidas_ao_load_fifo(dev, s, board->fifo_size / 2); } comedi_handle_events(dev, s); + + return irq_clr; } -static irqreturn_t cb_pcidas_interrupt(int irq, void *d) +static unsigned int cb_pcidas_ai_interrupt(struct comedi_device *dev, + unsigned int status) { - struct comedi_device *dev = (struct comedi_device *)d; const struct cb_pcidas_board *board = dev->board_ptr; struct cb_pcidas_private *devpriv = dev->private; struct comedi_subdevice *s = dev->read_subdev; - struct comedi_async *async; - struct comedi_cmd *cmd; - int status, s5933_status; - int half_fifo = board->fifo_size / 2; - unsigned int num_samples, i; - static const int timeout = 10000; - unsigned long flags; + struct comedi_async *async = s->async; + struct comedi_cmd *cmd = &async->cmd; + unsigned int irq_clr = 0; - if (!dev->attached) - return IRQ_NONE; + if (status & PCIDAS_CTRL_ADHFI) { + unsigned int num_samples; - async = s->async; - cmd = &async->cmd; + irq_clr |= PCIDAS_CTRL_INT_CLR; - s5933_status = inl(devpriv->s5933_config + AMCC_OP_REG_INTCSR); - - if ((INTCSR_INTR_ASSERTED & s5933_status) == 0) - return IRQ_NONE; - - /* make sure mailbox 4 is empty */ - inl_p(devpriv->s5933_config + AMCC_OP_REG_IMB4); - /* clear interrupt on amcc s5933 */ - outl(devpriv->s5933_intcsr_bits | INTCSR_INBOX_INTR_STATUS, - devpriv->s5933_config + AMCC_OP_REG_INTCSR); - - status = inw(devpriv->control_status + INT_ADCFIFO); - - /* check for analog output interrupt */ - if (status & (DAHFI | DAEMI)) - handle_ao_interrupt(dev, status); - /* check for analog input interrupts */ - /* if fifo half-full */ - if (status & ADHFI) { - /* read data */ - num_samples = comedi_nsamples_left(s, half_fifo); - insw(devpriv->adc_fifo + ADCDATA, devpriv->ai_buffer, - num_samples); + /* FIFO is half-full - read data */ + num_samples = comedi_nsamples_left(s, board->fifo_size / 2); + insw(devpriv->pcibar2 + PCIDAS_AI_DATA_REG, + devpriv->ai_buffer, num_samples); comedi_buf_write_samples(s, devpriv->ai_buffer, num_samples); if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg) async->events |= COMEDI_CB_EOA; + } else if (status & (PCIDAS_CTRL_ADNEI | PCIDAS_CTRL_EOBI)) { + unsigned int i; - /* clear half-full interrupt latch */ - spin_lock_irqsave(&dev->spinlock, flags); - outw(devpriv->adc_fifo_bits | INT, - devpriv->control_status + INT_ADCFIFO); - spin_unlock_irqrestore(&dev->spinlock, flags); - /* else if fifo not empty */ - } else if (status & (ADNEI | EOBI)) { - for (i = 0; i < timeout; i++) { + irq_clr |= PCIDAS_CTRL_INT_CLR; + + /* FIFO is not empty - read data until empty or timeoout */ + for (i = 0; i < 10000; i++) { unsigned short val; /* break if fifo is empty */ - if ((ADNE & inw(devpriv->control_status + - INT_ADCFIFO)) == 0) + if ((inw(devpriv->pcibar1 + PCIDAS_CTRL_REG) & + PCIDAS_CTRL_ADNE) == 0) break; - val = inw(devpriv->adc_fifo); + val = inw(devpriv->pcibar2 + PCIDAS_AI_DATA_REG); comedi_buf_write_samples(s, &val, 1); if (cmd->stop_src == TRIG_COUNT && @@ -1304,33 +1189,67 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d) break; } } - /* clear not-empty interrupt latch */ - spin_lock_irqsave(&dev->spinlock, flags); - outw(devpriv->adc_fifo_bits | INT, - devpriv->control_status + INT_ADCFIFO); - spin_unlock_irqrestore(&dev->spinlock, flags); - } else if (status & EOAI) { + } else if (status & PCIDAS_CTRL_EOAI) { + irq_clr |= PCIDAS_CTRL_EOAI; + dev_err(dev->class_dev, "bug! encountered end of acquisition interrupt?\n"); - /* clear EOA interrupt latch */ - spin_lock_irqsave(&dev->spinlock, flags); - outw(devpriv->adc_fifo_bits | EOAI, - devpriv->control_status + INT_ADCFIFO); - spin_unlock_irqrestore(&dev->spinlock, flags); } + /* check for fifo overflow */ - if (status & LADFUL) { + if (status & PCIDAS_CTRL_LADFUL) { + irq_clr |= PCIDAS_CTRL_LADFUL; + dev_err(dev->class_dev, "fifo overflow\n"); - /* clear overflow interrupt latch */ - spin_lock_irqsave(&dev->spinlock, flags); - outw(devpriv->adc_fifo_bits | LADFUL, - devpriv->control_status + INT_ADCFIFO); - spin_unlock_irqrestore(&dev->spinlock, flags); async->events |= COMEDI_CB_ERROR; } comedi_handle_events(dev, s); + return irq_clr; +} + +static irqreturn_t cb_pcidas_interrupt(int irq, void *d) +{ + struct comedi_device *dev = d; + struct cb_pcidas_private *devpriv = dev->private; + unsigned int irq_clr = 0; + unsigned int amcc_status; + unsigned int status; + + if (!dev->attached) + return IRQ_NONE; + + amcc_status = inl(devpriv->amcc + AMCC_OP_REG_INTCSR); + + if ((INTCSR_INTR_ASSERTED & amcc_status) == 0) + return IRQ_NONE; + + /* make sure mailbox 4 is empty */ + inl_p(devpriv->amcc + AMCC_OP_REG_IMB4); + /* clear interrupt on amcc s5933 */ + outl(devpriv->amcc_intcsr | INTCSR_INBOX_INTR_STATUS, + devpriv->amcc + AMCC_OP_REG_INTCSR); + + status = inw(devpriv->pcibar1 + PCIDAS_CTRL_REG); + + /* handle analog output interrupts */ + if (status & PCIDAS_CTRL_AO_INT) + irq_clr |= cb_pcidas_ao_interrupt(dev, status); + + /* handle analog input interrupts */ + if (status & PCIDAS_CTRL_AI_INT) + irq_clr |= cb_pcidas_ai_interrupt(dev, status); + + if (irq_clr) { + unsigned long flags; + + spin_lock_irqsave(&dev->spinlock, flags); + outw(devpriv->ctrl | irq_clr, + devpriv->pcibar1 + PCIDAS_CTRL_REG); + spin_unlock_irqrestore(&dev->spinlock, flags); + } + return IRQ_HANDLED; } @@ -1359,16 +1278,16 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev, if (ret) return ret; - devpriv->s5933_config = pci_resource_start(pcidev, 0); - devpriv->control_status = pci_resource_start(pcidev, 1); - devpriv->adc_fifo = pci_resource_start(pcidev, 2); + devpriv->amcc = pci_resource_start(pcidev, 0); + devpriv->pcibar1 = pci_resource_start(pcidev, 1); + devpriv->pcibar2 = pci_resource_start(pcidev, 2); dev->iobase = pci_resource_start(pcidev, 3); - if (board->ao_nchan) - devpriv->ao_registers = pci_resource_start(pcidev, 4); + if (board->has_ao) + devpriv->pcibar4 = pci_resource_start(pcidev, 4); /* disable and clear interrupts on amcc s5933 */ outl(INTCSR_INBOX_INTR_STATUS, - devpriv->s5933_config + AMCC_OP_REG_INTCSR); + devpriv->amcc + AMCC_OP_REG_INTCSR); ret = request_irq(pcidev->irq, cb_pcidas_interrupt, IRQF_SHARED, dev->board_name, dev); @@ -1379,12 +1298,12 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev, } dev->irq = pcidev->irq; - dev->pacer = comedi_8254_init(dev->iobase + ADC8254, + dev->pacer = comedi_8254_init(dev->iobase + PCIDAS_AI_8254_BASE, I8254_OSC_BASE_10MHZ, I8254_IO8, 0); if (!dev->pacer) return -ENOMEM; - devpriv->ao_pacer = comedi_8254_init(dev->iobase + DAC8254, + devpriv->ao_pacer = comedi_8254_init(dev->iobase + PCIDAS_AO_8254_BASE, I8254_OSC_BASE_10MHZ, I8254_IO8, 0); if (!devpriv->ao_pacer) @@ -1394,97 +1313,104 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev, if (ret) return ret; + /* Analog Input subdevice */ s = &dev->subdevices[0]; - /* analog input subdevice */ - dev->read_subdev = s; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; - /* WARNING: Number of inputs in differential mode is ignored */ - s->n_chan = board->ai_nchan; - s->len_chanlist = board->ai_nchan; - s->maxdata = (1 << board->ai_bits) - 1; - s->range_table = board->ranges; - s->insn_read = cb_pcidas_ai_rinsn; - s->insn_config = ai_config_insn; - s->do_cmd = cb_pcidas_ai_cmd; - s->do_cmdtest = cb_pcidas_ai_cmdtest; - s->cancel = cb_pcidas_cancel; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF; + s->n_chan = 16; + s->maxdata = board->is_16bit ? 0xffff : 0x0fff; + s->range_table = board->use_alt_range ? &cb_pcidas_alt_ranges + : &cb_pcidas_ranges; + s->insn_read = cb_pcidas_ai_insn_read; + s->insn_config = cb_pcidas_ai_insn_config; + if (dev->irq) { + dev->read_subdev = s; + s->subdev_flags |= SDF_CMD_READ; + s->len_chanlist = s->n_chan; + s->do_cmd = cb_pcidas_ai_cmd; + s->do_cmdtest = cb_pcidas_ai_cmdtest; + s->cancel = cb_pcidas_ai_cancel; + } - /* analog output subdevice */ + /* Analog Output subdevice */ s = &dev->subdevices[1]; - if (board->ao_nchan) { - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND; - s->n_chan = board->ao_nchan; - /* - * analog out resolution is the same as - * analog input resolution, so use ai_bits - */ - s->maxdata = (1 << board->ai_bits) - 1; - s->range_table = &cb_pcidas_ao_ranges; - /* default to no fifo (*insn_write) */ - s->insn_write = cb_pcidas_ao_nofifo_winsn; + if (board->has_ao) { + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND; + s->n_chan = 2; + s->maxdata = board->is_16bit ? 0xffff : 0x0fff; + s->range_table = &cb_pcidas_ao_ranges; + s->insn_write = (board->has_ao_fifo) + ? cb_pcidas_ao_fifo_insn_write + : cb_pcidas_ao_nofifo_insn_write; ret = comedi_alloc_subdev_readback(s); if (ret) return ret; - if (board->has_ao_fifo) { + if (dev->irq && board->has_ao_fifo) { dev->write_subdev = s; - s->subdev_flags |= SDF_CMD_WRITE; - /* use fifo (*insn_write) instead */ - s->insn_write = cb_pcidas_ao_fifo_winsn; - s->do_cmdtest = cb_pcidas_ao_cmdtest; - s->do_cmd = cb_pcidas_ao_cmd; - s->cancel = cb_pcidas_ao_cancel; + s->subdev_flags |= SDF_CMD_WRITE; + s->do_cmdtest = cb_pcidas_ao_cmdtest; + s->do_cmd = cb_pcidas_ao_cmd; + s->cancel = cb_pcidas_ao_cancel; } } else { - s->type = COMEDI_SUBD_UNUSED; + s->type = COMEDI_SUBD_UNUSED; } /* 8255 */ s = &dev->subdevices[2]; - ret = subdev_8255_init(dev, s, NULL, DIO_8255); + ret = subdev_8255_init(dev, s, NULL, PCIDAS_8255_BASE); if (ret) return ret; - /* serial EEPROM, */ + /* Memory subdevice - serial EEPROM */ s = &dev->subdevices[3]; - s->type = COMEDI_SUBD_MEMORY; - s->subdev_flags = SDF_READABLE | SDF_INTERNAL; - s->n_chan = 256; - s->maxdata = 0xff; - s->insn_read = eeprom_read_insn; + s->type = COMEDI_SUBD_MEMORY; + s->subdev_flags = SDF_READABLE | SDF_INTERNAL; + s->n_chan = 256; + s->maxdata = 0xff; + s->insn_read = cb_pcidas_eeprom_insn_read; - /* 8800 caldac */ + /* Calibration subdevice - 8800 caldac */ s = &dev->subdevices[4]; - s->type = COMEDI_SUBD_CALIB; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; - s->n_chan = NUM_CHANNELS_8800; - s->maxdata = 0xff; - s->insn_write = cb_pcidas_caldac_insn_write; + s->type = COMEDI_SUBD_CALIB; + s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL; + s->n_chan = 8; + s->maxdata = 0xff; + s->insn_write = cb_pcidas_caldac_insn_write; ret = comedi_alloc_subdev_readback(s); if (ret) return ret; for (i = 0; i < s->n_chan; i++) { - caldac_8800_write(dev, i, s->maxdata / 2); - s->readback[i] = s->maxdata / 2; + unsigned int val = s->maxdata / 2; + + /* write 11-bit channel/value to caldac */ + cb_pcidas_calib_write(dev, (i << 8) | val, 11, false); + s->readback[i] = val; } - /* trim potentiometer */ + /* Calibration subdevice - trim potentiometer */ s = &dev->subdevices[5]; - s->type = COMEDI_SUBD_CALIB; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; - if (board->trimpot == AD7376) { - s->n_chan = NUM_CHANNELS_7376; - s->maxdata = 0x7f; + s->type = COMEDI_SUBD_CALIB; + s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL; + if (board->has_ad8402) { + /* + * pci-das1602/16 have an AD8402 trimpot: + * chan 0 : adc gain + * chan 1 : adc postgain offset + */ + s->n_chan = 2; + s->maxdata = 0xff; } else { - s->n_chan = NUM_CHANNELS_8402; - s->maxdata = 0xff; + /* all other boards have an AD7376 trimpot */ + s->n_chan = 1; + s->maxdata = 0x7f; } - s->insn_write = cb_pcidas_trimpot_insn_write; + s->insn_write = cb_pcidas_trimpot_insn_write; ret = comedi_alloc_subdev_readback(s); if (ret) @@ -1495,36 +1421,35 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev, s->readback[i] = s->maxdata / 2; } - /* dac08 caldac */ + /* Calibration subdevice - pci-das1602/16 pregain offset (dac08) */ s = &dev->subdevices[6]; if (board->has_dac08) { - s->type = COMEDI_SUBD_CALIB; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; - s->n_chan = NUM_CHANNELS_DAC08; - s->maxdata = 0xff; - s->insn_write = cb_pcidas_dac08_insn_write; + s->type = COMEDI_SUBD_CALIB; + s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL; + s->n_chan = 1; + s->maxdata = 0xff; + s->insn_write = cb_pcidas_dac08_insn_write; ret = comedi_alloc_subdev_readback(s); if (ret) return ret; for (i = 0; i < s->n_chan; i++) { - dac08_write(dev, s->maxdata / 2); + cb_pcidas_dac08_write(dev, s->maxdata / 2); s->readback[i] = s->maxdata / 2; } } else { - s->type = COMEDI_SUBD_UNUSED; + s->type = COMEDI_SUBD_UNUSED; } /* make sure mailbox 4 is empty */ - inl(devpriv->s5933_config + AMCC_OP_REG_IMB4); + inl(devpriv->amcc + AMCC_OP_REG_IMB4); /* Set bits to enable incoming mailbox interrupts on amcc s5933. */ - devpriv->s5933_intcsr_bits = - INTCSR_INBOX_BYTE(3) | INTCSR_INBOX_SELECT(3) | - INTCSR_INBOX_FULL_INT; + devpriv->amcc_intcsr = INTCSR_INBOX_BYTE(3) | INTCSR_INBOX_SELECT(3) | + INTCSR_INBOX_FULL_INT; /* clear and enable interrupt on amcc s5933 */ - outl(devpriv->s5933_intcsr_bits | INTCSR_INBOX_INTR_STATUS, - devpriv->s5933_config + AMCC_OP_REG_INTCSR); + outl(devpriv->amcc_intcsr | INTCSR_INBOX_INTR_STATUS, + devpriv->amcc + AMCC_OP_REG_INTCSR); return 0; } @@ -1534,9 +1459,9 @@ static void cb_pcidas_detach(struct comedi_device *dev) struct cb_pcidas_private *devpriv = dev->private; if (devpriv) { - if (devpriv->s5933_config) + if (devpriv->amcc) outl(INTCSR_INBOX_INTR_STATUS, - devpriv->s5933_config + AMCC_OP_REG_INTCSR); + devpriv->amcc + AMCC_OP_REG_INTCSR); kfree(devpriv->ao_pacer); } comedi_pci_detach(dev); @@ -1578,5 +1503,5 @@ static struct pci_driver cb_pcidas_pci_driver = { module_comedi_pci_driver(cb_pcidas_driver, cb_pcidas_pci_driver); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_DESCRIPTION("Comedi driver for MeasurementComputing PCI-DAS series"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c index 80d613c0fbc6..4ab186669f0c 100644 --- a/drivers/staging/comedi/drivers/comedi_test.c +++ b/drivers/staging/comedi/drivers/comedi_test.c @@ -1,49 +1,49 @@ /* - comedi/drivers/comedi_test.c + * comedi/drivers/comedi_test.c + * + * Generates fake waveform signals that can be read through + * the command interface. It does _not_ read from any board; + * it just generates deterministic waveforms. + * Useful for various testing purposes. + * + * Copyright (C) 2002 Joachim Wuttke + * Copyright (C) 2002 Frank Mori Hess + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000 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. + */ - Generates fake waveform signals that can be read through - the command interface. It does _not_ read from any board; - it just generates deterministic waveforms. - Useful for various testing purposes. - - Copyright (C) 2002 Joachim Wuttke - Copyright (C) 2002 Frank Mori Hess - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 2000 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. -*/ /* -Driver: comedi_test -Description: generates fake waveforms -Author: Joachim Wuttke , Frank Mori Hess - , ds -Devices: -Status: works -Updated: Sat, 16 Mar 2002 17:34:48 -0800 - -This driver is mainly for testing purposes, but can also be used to -generate sample waveforms on systems that don't have data acquisition -hardware. - -Configuration options: - [0] - Amplitude in microvolts for fake waveforms (default 1 volt) - [1] - Period in microseconds for fake waveforms (default 0.1 sec) - -Generates a sawtooth wave on channel 0, square wave on channel 1, additional -waveforms could be added to other channels (currently they return flatline -zero volts). - -*/ + * Driver: comedi_test + * Description: generates fake waveforms + * Author: Joachim Wuttke , Frank Mori Hess + * , ds + * Devices: + * Status: works + * Updated: Sat, 16 Mar 2002 17:34:48 -0800 + * + * This driver is mainly for testing purposes, but can also be used to + * generate sample waveforms on systems that don't have data acquisition + * hardware. + * + * Configuration options: + * [0] - Amplitude in microvolts for fake waveforms (default 1 volt) + * [1] - Period in microseconds for fake waveforms (default 0.1 sec) + * + * Generates a sawtooth wave on channel 0, square wave on channel 1, additional + * waveforms could be added to other channels (currently they return flatline + * zero volts). + */ #include #include "../comedidev.h" @@ -52,30 +52,31 @@ zero volts). #include #include +#include #define N_CHANS 8 enum waveform_state_bits { - WAVEFORM_AI_RUNNING = 0 + WAVEFORM_AI_RUNNING, + WAVEFORM_AO_RUNNING }; /* Data unique to this driver */ struct waveform_private { - struct timer_list timer; - ktime_t last; /* time last timer interrupt occurred */ - unsigned int uvolt_amplitude; /* waveform amplitude in microvolts */ - unsigned long usec_period; /* waveform period in microseconds */ - unsigned long usec_current; /* current time (mod waveform period) */ - unsigned long usec_remainder; /* usec since last scan */ + struct timer_list ai_timer; /* timer for AI commands */ + u64 ai_convert_time; /* time of next AI conversion in usec */ + unsigned int wf_amplitude; /* waveform amplitude in microvolts */ + unsigned int wf_period; /* waveform period in microseconds */ + unsigned int wf_current; /* current time in waveform period */ unsigned long state_bits; - unsigned int scan_period; /* scan period in usec */ - unsigned int convert_period; /* conversion period in usec */ - unsigned int ao_loopbacks[N_CHANS]; + unsigned int ai_scan_period; /* AI scan period in usec */ + unsigned int ai_convert_period; /* AI conversion period in usec */ + struct timer_list ao_timer; /* timer for AO commands */ + u64 ao_last_scan_time; /* time of previous AO scan in usec */ + unsigned int ao_scan_period; /* AO scan period in usec */ + unsigned short ao_loopbacks[N_CHANS]; }; -/* 1000 nanosec in a microsec */ -static const int nano_per_micro = 1000; - /* fake analog input ranges */ static const struct comedi_lrange waveform_ai_ranges = { 2, { @@ -86,7 +87,7 @@ static const struct comedi_lrange waveform_ai_ranges = { static unsigned short fake_sawtooth(struct comedi_device *dev, unsigned int range_index, - unsigned long current_time) + unsigned int current_time) { struct waveform_private *devpriv = dev->private; struct comedi_subdevice *s = dev->read_subdev; @@ -97,21 +98,28 @@ static unsigned short fake_sawtooth(struct comedi_device *dev, u64 binary_amplitude; binary_amplitude = s->maxdata; - binary_amplitude *= devpriv->uvolt_amplitude; + binary_amplitude *= devpriv->wf_amplitude; do_div(binary_amplitude, krange->max - krange->min); - current_time %= devpriv->usec_period; value = current_time; value *= binary_amplitude * 2; - do_div(value, devpriv->usec_period); - value -= binary_amplitude; /* get rid of sawtooth's dc offset */ + do_div(value, devpriv->wf_period); + value += offset; + /* get rid of sawtooth's dc offset and clamp value */ + if (value < binary_amplitude) { + value = 0; /* negative saturation */ + } else { + value -= binary_amplitude; + if (value > s->maxdata) + value = s->maxdata; /* positive saturation */ + } - return offset + value; + return value; } static unsigned short fake_squarewave(struct comedi_device *dev, unsigned int range_index, - unsigned long current_time) + unsigned int current_time) { struct waveform_private *devpriv = dev->private; struct comedi_subdevice *s = dev->read_subdev; @@ -119,21 +127,29 @@ static unsigned short fake_squarewave(struct comedi_device *dev, u64 value; const struct comedi_krange *krange = &s->range_table->range[range_index]; - current_time %= devpriv->usec_period; value = s->maxdata; - value *= devpriv->uvolt_amplitude; + value *= devpriv->wf_amplitude; do_div(value, krange->max - krange->min); - if (current_time < devpriv->usec_period / 2) - value *= -1; + /* get one of two values for square-wave and clamp */ + if (current_time < devpriv->wf_period / 2) { + if (offset < value) + value = 0; /* negative saturation */ + else + value = offset - value; + } else { + value += offset; + if (value > s->maxdata) + value = s->maxdata; /* positive saturation */ + } - return offset + value; + return value; } static unsigned short fake_flatline(struct comedi_device *dev, unsigned int range_index, - unsigned long current_time) + unsigned int current_time) { return dev->read_subdev->maxdata / 2; } @@ -141,7 +157,7 @@ static unsigned short fake_flatline(struct comedi_device *dev, /* generates a different waveform depending on what channel is read */ static unsigned short fake_waveform(struct comedi_device *dev, unsigned int channel, unsigned int range, - unsigned long current_time) + unsigned int current_time) { enum { SAWTOOTH_CHAN, @@ -160,58 +176,62 @@ static unsigned short fake_waveform(struct comedi_device *dev, } /* - This is the background routine used to generate arbitrary data. - It should run in the background; therefore it is scheduled by - a timer mechanism. -*/ -static void waveform_ai_interrupt(unsigned long arg) + * This is the background routine used to generate arbitrary data. + * It should run in the background; therefore it is scheduled by + * a timer mechanism. + */ +static void waveform_ai_timer(unsigned long arg) { struct comedi_device *dev = (struct comedi_device *)arg; struct waveform_private *devpriv = dev->private; struct comedi_subdevice *s = dev->read_subdev; struct comedi_async *async = s->async; struct comedi_cmd *cmd = &async->cmd; - unsigned int i, j; - /* all times in microsec */ - unsigned long elapsed_time; - unsigned int num_scans; - ktime_t now; + u64 now; + unsigned int nsamples; + unsigned int time_increment; /* check command is still active */ if (!test_bit(WAVEFORM_AI_RUNNING, &devpriv->state_bits)) return; - now = ktime_get(); + now = ktime_to_us(ktime_get()); + nsamples = comedi_nsamples_left(s, UINT_MAX); - elapsed_time = ktime_to_us(ktime_sub(now, devpriv->last)); - devpriv->last = now; - num_scans = - (devpriv->usec_remainder + elapsed_time) / devpriv->scan_period; - devpriv->usec_remainder = - (devpriv->usec_remainder + elapsed_time) % devpriv->scan_period; + while (nsamples && devpriv->ai_convert_time < now) { + unsigned int chanspec = cmd->chanlist[async->cur_chan]; + unsigned short sample; - num_scans = comedi_nscans_left(s, num_scans); - for (i = 0; i < num_scans; i++) { - for (j = 0; j < cmd->chanlist_len; j++) { - unsigned short sample; - - sample = fake_waveform(dev, CR_CHAN(cmd->chanlist[j]), - CR_RANGE(cmd->chanlist[j]), - devpriv->usec_current + - i * devpriv->scan_period + - j * devpriv->convert_period); - comedi_buf_write_samples(s, &sample, 1); + sample = fake_waveform(dev, CR_CHAN(chanspec), + CR_RANGE(chanspec), devpriv->wf_current); + if (comedi_buf_write_samples(s, &sample, 1) == 0) + goto overrun; + time_increment = devpriv->ai_convert_period; + if (async->scan_progress == 0) { + /* done last conversion in scan, so add dead time */ + time_increment += devpriv->ai_scan_period - + devpriv->ai_convert_period * + cmd->scan_end_arg; } + devpriv->wf_current += time_increment; + if (devpriv->wf_current >= devpriv->wf_period) + devpriv->wf_current %= devpriv->wf_period; + devpriv->ai_convert_time += time_increment; + nsamples--; } - devpriv->usec_current += elapsed_time; - devpriv->usec_current %= devpriv->usec_period; - - if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg) + if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg) { async->events |= COMEDI_CB_EOA; - else - mod_timer(&devpriv->timer, jiffies + 1); + } else { + if (devpriv->ai_convert_time > now) + time_increment = devpriv->ai_convert_time - now; + else + time_increment = 1; + mod_timer(&devpriv->ai_timer, + jiffies + usecs_to_jiffies(time_increment)); + } +overrun: comedi_handle_events(dev, s); } @@ -220,12 +240,13 @@ static int waveform_ai_cmdtest(struct comedi_device *dev, struct comedi_cmd *cmd) { int err = 0; - unsigned int arg; + unsigned int arg, limit; /* Step 1 : check if triggers are trivially valid */ err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW); - err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER); + err |= comedi_check_trigger_src(&cmd->scan_begin_src, + TRIG_FOLLOW | TRIG_TIMER); err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_NOW | TRIG_TIMER); err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); @@ -241,6 +262,9 @@ static int waveform_ai_cmdtest(struct comedi_device *dev, /* Step 2b : and mutually compatible */ + if (cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_NOW) + err |= -EINVAL; /* scan period would be 0 */ + if (err) return 2; @@ -248,27 +272,29 @@ static int waveform_ai_cmdtest(struct comedi_device *dev, err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0); - if (cmd->convert_src == TRIG_NOW) + if (cmd->convert_src == TRIG_NOW) { err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0); - - if (cmd->scan_begin_src == TRIG_TIMER) { - err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg, - nano_per_micro); - if (cmd->convert_src == TRIG_TIMER) { - err |= comedi_check_trigger_arg_min(&cmd-> - scan_begin_arg, - cmd->convert_arg * - cmd->chanlist_len); + } else { /* cmd->convert_src == TRIG_TIMER */ + if (cmd->scan_begin_src == TRIG_FOLLOW) { + err |= comedi_check_trigger_arg_min(&cmd->convert_arg, + NSEC_PER_USEC); } } + if (cmd->scan_begin_src == TRIG_FOLLOW) { + err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0); + } else { /* cmd->scan_begin_src == TRIG_TIMER */ + err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg, + NSEC_PER_USEC); + } + err |= comedi_check_trigger_arg_min(&cmd->chanlist_len, 1); err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); if (cmd->stop_src == TRIG_COUNT) err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1); - else /* TRIG_NONE */ + else /* cmd->stop_src == TRIG_NONE */ err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0); if (err) @@ -276,21 +302,34 @@ static int waveform_ai_cmdtest(struct comedi_device *dev, /* step 4: fix up any arguments */ - if (cmd->scan_begin_src == TRIG_TIMER) { - arg = cmd->scan_begin_arg; - /* round to nearest microsec */ - arg = nano_per_micro * - ((arg + (nano_per_micro / 2)) / nano_per_micro); - err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg); - } if (cmd->convert_src == TRIG_TIMER) { + /* round convert_arg to nearest microsecond */ arg = cmd->convert_arg; - /* round to nearest microsec */ - arg = nano_per_micro * - ((arg + (nano_per_micro / 2)) / nano_per_micro); + arg = min(arg, + rounddown(UINT_MAX, (unsigned int)NSEC_PER_USEC)); + arg = NSEC_PER_USEC * DIV_ROUND_CLOSEST(arg, NSEC_PER_USEC); + if (cmd->scan_begin_arg == TRIG_TIMER) { + /* limit convert_arg to keep scan_begin_arg in range */ + limit = UINT_MAX / cmd->scan_end_arg; + limit = rounddown(limit, (unsigned int)NSEC_PER_SEC); + arg = min(arg, limit); + } err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg); } + if (cmd->scan_begin_src == TRIG_TIMER) { + /* round scan_begin_arg to nearest microsecond */ + arg = cmd->scan_begin_arg; + arg = min(arg, + rounddown(UINT_MAX, (unsigned int)NSEC_PER_USEC)); + arg = NSEC_PER_USEC * DIV_ROUND_CLOSEST(arg, NSEC_PER_USEC); + if (cmd->convert_src == TRIG_TIMER) { + /* but ensure scan_begin_arg is large enough */ + arg = max(arg, cmd->convert_arg * cmd->scan_end_arg); + } + err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg); + } + if (err) return 4; @@ -302,6 +341,8 @@ static int waveform_ai_cmd(struct comedi_device *dev, { struct waveform_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; + unsigned int first_convert_time; + u64 wf_current; if (cmd->flags & CMDF_PRIORITY) { dev_err(dev->class_dev, @@ -309,24 +350,48 @@ static int waveform_ai_cmd(struct comedi_device *dev, return -1; } - devpriv->scan_period = cmd->scan_begin_arg / nano_per_micro; - if (cmd->convert_src == TRIG_NOW) - devpriv->convert_period = 0; - else /* TRIG_TIMER */ - devpriv->convert_period = cmd->convert_arg / nano_per_micro; + devpriv->ai_convert_period = 0; + else /* cmd->convert_src == TRIG_TIMER */ + devpriv->ai_convert_period = cmd->convert_arg / NSEC_PER_USEC; - devpriv->last = ktime_get(); - devpriv->usec_current = - ((u32)ktime_to_us(devpriv->last)) % devpriv->usec_period; - devpriv->usec_remainder = 0; + if (cmd->scan_begin_src == TRIG_FOLLOW) { + devpriv->ai_scan_period = devpriv->ai_convert_period * + cmd->scan_end_arg; + } else { /* cmd->scan_begin_src == TRIG_TIMER */ + devpriv->ai_scan_period = cmd->scan_begin_arg / NSEC_PER_USEC; + } + + /* + * Simulate first conversion to occur at convert period after + * conversion timer starts. If scan_begin_src is TRIG_FOLLOW, assume + * the conversion timer starts immediately. If scan_begin_src is + * TRIG_TIMER, assume the conversion timer starts after the scan + * period. + */ + first_convert_time = devpriv->ai_convert_period; + if (cmd->scan_begin_src == TRIG_TIMER) + first_convert_time += devpriv->ai_scan_period; + devpriv->ai_convert_time = ktime_to_us(ktime_get()) + + first_convert_time; + + /* Determine time within waveform period at time of conversion. */ + wf_current = devpriv->ai_convert_time; + devpriv->wf_current = do_div(wf_current, devpriv->wf_period); + + /* + * Schedule timer to expire just after first conversion time. + * Seem to need an extra jiffy here, otherwise timer expires slightly + * early! + */ + devpriv->ai_timer.expires = + jiffies + usecs_to_jiffies(devpriv->ai_convert_period) + 1; - devpriv->timer.expires = jiffies + 1; /* mark command as active */ smp_mb__before_atomic(); set_bit(WAVEFORM_AI_RUNNING, &devpriv->state_bits); smp_mb__after_atomic(); - add_timer(&devpriv->timer); + add_timer(&devpriv->ai_timer); return 0; } @@ -339,7 +404,7 @@ static int waveform_ai_cancel(struct comedi_device *dev, clear_bit(WAVEFORM_AI_RUNNING, &devpriv->state_bits); smp_mb__after_atomic(); /* cannot call del_timer_sync() as may be called from timer routine */ - del_timer(&devpriv->timer); + del_timer(&devpriv->ai_timer); return 0; } @@ -356,6 +421,201 @@ static int waveform_ai_insn_read(struct comedi_device *dev, return insn->n; } +/* + * This is the background routine to handle AO commands, scheduled by + * a timer mechanism. + */ +static void waveform_ao_timer(unsigned long arg) +{ + struct comedi_device *dev = (struct comedi_device *)arg; + struct waveform_private *devpriv = dev->private; + struct comedi_subdevice *s = dev->write_subdev; + struct comedi_async *async = s->async; + struct comedi_cmd *cmd = &async->cmd; + u64 now; + u64 scans_since; + unsigned int scans_avail = 0; + + /* check command is still active */ + if (!test_bit(WAVEFORM_AO_RUNNING, &devpriv->state_bits)) + return; + + /* determine number of scan periods since last time */ + now = ktime_to_us(ktime_get()); + scans_since = now - devpriv->ao_last_scan_time; + do_div(scans_since, devpriv->ao_scan_period); + if (scans_since) { + unsigned int i; + + /* determine scans in buffer, limit to scans to do this time */ + scans_avail = comedi_nscans_left(s, 0); + if (scans_avail > scans_since) + scans_avail = scans_since; + if (scans_avail) { + /* skip all but the last scan to save processing time */ + if (scans_avail > 1) { + unsigned int skip_bytes, nbytes; + + skip_bytes = + comedi_samples_to_bytes(s, cmd->scan_end_arg * + (scans_avail - 1)); + nbytes = comedi_buf_read_alloc(s, skip_bytes); + comedi_buf_read_free(s, nbytes); + comedi_inc_scan_progress(s, nbytes); + if (nbytes < skip_bytes) { + /* unexpected underrun! (cancelled?) */ + async->events |= COMEDI_CB_OVERFLOW; + goto underrun; + } + } + /* output the last scan */ + for (i = 0; i < cmd->scan_end_arg; i++) { + unsigned int chan = CR_CHAN(cmd->chanlist[i]); + + if (comedi_buf_read_samples(s, + &devpriv-> + ao_loopbacks[chan], + 1) == 0) { + /* unexpected underrun! (cancelled?) */ + async->events |= COMEDI_CB_OVERFLOW; + goto underrun; + } + } + /* advance time of last scan */ + devpriv->ao_last_scan_time += + (u64)scans_avail * devpriv->ao_scan_period; + } + } + if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg) { + async->events |= COMEDI_CB_EOA; + } else if (scans_avail < scans_since) { + async->events |= COMEDI_CB_OVERFLOW; + } else { + unsigned int time_inc = devpriv->ao_last_scan_time + + devpriv->ao_scan_period - now; + + mod_timer(&devpriv->ao_timer, + jiffies + usecs_to_jiffies(time_inc)); + } + +underrun: + comedi_handle_events(dev, s); +} + +static int waveform_ao_inttrig_start(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned int trig_num) +{ + struct waveform_private *devpriv = dev->private; + struct comedi_async *async = s->async; + struct comedi_cmd *cmd = &async->cmd; + + if (trig_num != cmd->start_arg) + return -EINVAL; + + async->inttrig = NULL; + + devpriv->ao_last_scan_time = ktime_to_us(ktime_get()); + devpriv->ao_timer.expires = + jiffies + usecs_to_jiffies(devpriv->ao_scan_period); + + /* mark command as active */ + smp_mb__before_atomic(); + set_bit(WAVEFORM_AO_RUNNING, &devpriv->state_bits); + smp_mb__after_atomic(); + add_timer(&devpriv->ao_timer); + + return 1; +} + +static int waveform_ao_cmdtest(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_cmd *cmd) +{ + int err = 0; + unsigned int arg; + + /* Step 1 : check if triggers are trivially valid */ + + err |= comedi_check_trigger_src(&cmd->start_src, TRIG_INT); + err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER); + err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_NOW); + err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); + err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); + + if (err) + return 1; + + /* Step 2a : make sure trigger sources are unique */ + + err |= comedi_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 |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg, + NSEC_PER_USEC); + err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0); + err |= comedi_check_trigger_arg_min(&cmd->chanlist_len, 1); + err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, + cmd->chanlist_len); + if (cmd->stop_src == TRIG_COUNT) + err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1); + else /* cmd->stop_src == TRIG_NONE */ + err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0); + + if (err) + return 3; + + /* step 4: fix up any arguments */ + + /* round scan_begin_arg to nearest microsecond */ + arg = cmd->scan_begin_arg; + arg = min(arg, rounddown(UINT_MAX, (unsigned int)NSEC_PER_USEC)); + arg = NSEC_PER_USEC * DIV_ROUND_CLOSEST(arg, NSEC_PER_USEC); + err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg); + + if (err) + return 4; + + return 0; +} + +static int waveform_ao_cmd(struct comedi_device *dev, + struct comedi_subdevice *s) +{ + struct waveform_private *devpriv = dev->private; + struct comedi_cmd *cmd = &s->async->cmd; + + if (cmd->flags & CMDF_PRIORITY) { + dev_err(dev->class_dev, + "commands at RT priority not supported in this driver\n"); + return -1; + } + + devpriv->ao_scan_period = cmd->scan_begin_arg / NSEC_PER_USEC; + s->async->inttrig = waveform_ao_inttrig_start; + return 0; +} + +static int waveform_ao_cancel(struct comedi_device *dev, + struct comedi_subdevice *s) +{ + struct waveform_private *devpriv = dev->private; + + s->async->inttrig = NULL; + /* mark command as no longer active */ + clear_bit(WAVEFORM_AO_RUNNING, &devpriv->state_bits); + smp_mb__after_atomic(); + /* cannot call del_timer_sync() as may be called from timer routine */ + del_timer(&devpriv->ao_timer); + return 0; +} + static int waveform_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) @@ -389,8 +649,8 @@ static int waveform_attach(struct comedi_device *dev, if (period <= 0) period = 100000; /* 0.1 sec */ - devpriv->uvolt_amplitude = amplitude; - devpriv->usec_period = period; + devpriv->wf_amplitude = amplitude; + devpriv->wf_period = period; ret = comedi_alloc_subdevices(dev, 2); if (ret) @@ -414,23 +674,28 @@ static int waveform_attach(struct comedi_device *dev, dev->write_subdev = s; /* analog output subdevice (loopback) */ s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE | SDF_GROUND; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_CMD_WRITE; s->n_chan = N_CHANS; s->maxdata = 0xffff; s->range_table = &waveform_ai_ranges; + s->len_chanlist = s->n_chan; s->insn_write = waveform_ao_insn_write; + s->insn_read = waveform_ai_insn_read; /* do same as AI insn_read */ + s->do_cmd = waveform_ao_cmd; + s->do_cmdtest = waveform_ao_cmdtest; + s->cancel = waveform_ao_cancel; /* Our default loopback value is just a 0V flatline */ for (i = 0; i < s->n_chan; i++) devpriv->ao_loopbacks[i] = s->maxdata / 2; - setup_timer(&devpriv->timer, waveform_ai_interrupt, - (unsigned long)dev); + setup_timer(&devpriv->ai_timer, waveform_ai_timer, (unsigned long)dev); + setup_timer(&devpriv->ao_timer, waveform_ao_timer, (unsigned long)dev); dev_info(dev->class_dev, - "%s: %i microvolt, %li microsecond waveform attached\n", + "%s: %u microvolt, %u microsecond waveform attached\n", dev->board_name, - devpriv->uvolt_amplitude, devpriv->usec_period); + devpriv->wf_amplitude, devpriv->wf_period); return 0; } @@ -439,8 +704,10 @@ static void waveform_detach(struct comedi_device *dev) { struct waveform_private *devpriv = dev->private; - if (devpriv) - del_timer_sync(&devpriv->timer); + if (devpriv) { + del_timer_sync(&devpriv->ai_timer); + del_timer_sync(&devpriv->ao_timer); + } } static struct comedi_driver waveform_driver = { diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c index 611b0a3ef5d7..57ab6680e3ae 100644 --- a/drivers/staging/comedi/drivers/daqboard2000.c +++ b/drivers/staging/comedi/drivers/daqboard2000.c @@ -713,12 +713,8 @@ static int daqboard2000_auto_attach(struct comedi_device *dev, return result; s = &dev->subdevices[2]; - result = subdev_8255_init(dev, s, daqboard2000_8255_cb, - dioP2ExpansionIO8Bit); - if (result) - return result; - - return 0; + return subdev_8255_init(dev, s, daqboard2000_8255_cb, + dioP2ExpansionIO8Bit); } static void daqboard2000_detach(struct comedi_device *dev) diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c index 8c4f284d1919..ab7a332fbcc4 100644 --- a/drivers/staging/comedi/drivers/dt3000.c +++ b/drivers/staging/comedi/drivers/dt3000.c @@ -1,52 +1,53 @@ /* - comedi/drivers/dt3000.c - Data Translation DT3000 series driver - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 1999 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. -*/ -/* -Driver: dt3000 -Description: Data Translation DT3000 series -Author: ds -Devices: [Data Translation] DT3001 (dt3000), DT3001-PGL, DT3002, DT3003, - DT3003-PGL, DT3004, DT3005, DT3004-200 -Updated: Mon, 14 Apr 2008 15:41:24 +0100 -Status: works - -Configuration Options: not applicable, uses PCI auto config - -There is code to support AI commands, but it may not work. - -AO commands are not supported. -*/ + * dt3000.c + * Data Translation DT3000 series driver + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1999 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. + */ /* - The DT3000 series is Data Translation's attempt to make a PCI - data acquisition board. The design of this series is very nice, - since each board has an on-board DSP (Texas Instruments TMS320C52). - However, a few details are a little annoying. The boards lack - bus-mastering DMA, which eliminates them from serious work. - They also are not capable of autocalibration, which is a common - feature in modern hardware. The default firmware is pretty bad, - making it nearly impossible to write an RT compatible driver. - It would make an interesting project to write a decent firmware - for these boards. + * Driver: dt3000 + * Description: Data Translation DT3000 series + * Devices: [Data Translation] DT3001 (dt3000), DT3001-PGL, DT3002, DT3003, + * DT3003-PGL, DT3004, DT3005, DT3004-200 + * Author: ds + * Updated: Mon, 14 Apr 2008 15:41:24 +0100 + * Status: works + * + * Configuration Options: not applicable, uses PCI auto config + * + * There is code to support AI commands, but it may not work. + * + * AO commands are not supported. + */ - Data Translation originally wanted an NDA for the documentation - for the 3k series. However, if you ask nicely, they might send - you the docs without one, also. -*/ +/* + * The DT3000 series is Data Translation's attempt to make a PCI + * data acquisition board. The design of this series is very nice, + * since each board has an on-board DSP (Texas Instruments TMS320C52). + * However, a few details are a little annoying. The boards lack + * bus-mastering DMA, which eliminates them from serious work. + * They also are not capable of autocalibration, which is a common + * feature in modern hardware. The default firmware is pretty bad, + * making it nearly impossible to write an RT compatible driver. + * It would make an interesting project to write a decent firmware + * for these boards. + * + * Data Translation originally wanted an NDA for the documentation + * for the 3k series. However, if you ask nicely, they might send + * you the docs without one, also. + */ #include #include @@ -54,6 +55,88 @@ AO commands are not supported. #include "../comedi_pci.h" +/* + * PCI BAR0 - dual-ported RAM location definitions (dev->mmio) + */ +#define DPR_DAC_BUFFER (4 * 0x000) +#define DPR_ADC_BUFFER (4 * 0x800) +#define DPR_COMMAND (4 * 0xfd3) +#define DPR_SUBSYS (4 * 0xfd3) +#define DPR_SUBSYS_AI 0 +#define DPR_SUBSYS_AO 1 +#define DPR_SUBSYS_DIN 2 +#define DPR_SUBSYS_DOUT 3 +#define DPR_SUBSYS_MEM 4 +#define DPR_SUBSYS_CT 5 +#define DPR_ENCODE (4 * 0xfd4) +#define DPR_PARAMS(x) (4 * (0xfd5 + (x))) +#define DPR_TICK_REG_LO (4 * 0xff5) +#define DPR_TICK_REG_HI (4 * 0xff6) +#define DPR_DA_BUF_FRONT (4 * 0xff7) +#define DPR_DA_BUF_REAR (4 * 0xff8) +#define DPR_AD_BUF_FRONT (4 * 0xff9) +#define DPR_AD_BUF_REAR (4 * 0xffa) +#define DPR_INT_MASK (4 * 0xffb) +#define DPR_INTR_FLAG (4 * 0xffc) +#define DPR_INTR_CMDONE BIT(7) +#define DPR_INTR_CTDONE BIT(6) +#define DPR_INTR_DAHWERR BIT(5) +#define DPR_INTR_DASWERR BIT(4) +#define DPR_INTR_DAEMPTY BIT(3) +#define DPR_INTR_ADHWERR BIT(2) +#define DPR_INTR_ADSWERR BIT(1) +#define DPR_INTR_ADFULL BIT(0) +#define DPR_RESPONSE_MBX (4 * 0xffe) +#define DPR_CMD_MBX (4 * 0xfff) +#define DPR_CMD_COMPLETION(x) ((x) << 8) +#define DPR_CMD_NOTPROCESSED DPR_CMD_COMPLETION(0x00) +#define DPR_CMD_NOERROR DPR_CMD_COMPLETION(0x55) +#define DPR_CMD_ERROR DPR_CMD_COMPLETION(0xaa) +#define DPR_CMD_NOTSUPPORTED DPR_CMD_COMPLETION(0xff) +#define DPR_CMD_COMPLETION_MASK DPR_CMD_COMPLETION(0xff) +#define DPR_CMD(x) ((x) << 0) +#define DPR_CMD_GETBRDINFO DPR_CMD(0) +#define DPR_CMD_CONFIG DPR_CMD(1) +#define DPR_CMD_GETCONFIG DPR_CMD(2) +#define DPR_CMD_START DPR_CMD(3) +#define DPR_CMD_STOP DPR_CMD(4) +#define DPR_CMD_READSINGLE DPR_CMD(5) +#define DPR_CMD_WRITESINGLE DPR_CMD(6) +#define DPR_CMD_CALCCLOCK DPR_CMD(7) +#define DPR_CMD_READEVENTS DPR_CMD(8) +#define DPR_CMD_WRITECTCTRL DPR_CMD(16) +#define DPR_CMD_READCTCTRL DPR_CMD(17) +#define DPR_CMD_WRITECT DPR_CMD(18) +#define DPR_CMD_READCT DPR_CMD(19) +#define DPR_CMD_WRITEDATA DPR_CMD(32) +#define DPR_CMD_READDATA DPR_CMD(33) +#define DPR_CMD_WRITEIO DPR_CMD(34) +#define DPR_CMD_READIO DPR_CMD(35) +#define DPR_CMD_WRITECODE DPR_CMD(36) +#define DPR_CMD_READCODE DPR_CMD(37) +#define DPR_CMD_EXECUTE DPR_CMD(38) +#define DPR_CMD_HALT DPR_CMD(48) +#define DPR_CMD_MASK DPR_CMD(0xff) + +#define DPR_PARAM5_AD_TRIG(x) (((x) & 0x7) << 2) +#define DPR_PARAM5_AD_TRIG_INT DPR_PARAM5_AD_TRIG(0) +#define DPR_PARAM5_AD_TRIG_EXT DPR_PARAM5_AD_TRIG(1) +#define DPR_PARAM5_AD_TRIG_INT_RETRIG DPR_PARAM5_AD_TRIG(2) +#define DPR_PARAM5_AD_TRIG_EXT_RETRIG DPR_PARAM5_AD_TRIG(3) +#define DPR_PARAM5_AD_TRIG_INT_RETRIG2 DPR_PARAM5_AD_TRIG(4) + +#define DPR_PARAM6_AD_DIFF BIT(0) + +#define DPR_AI_FIFO_DEPTH 2003 +#define DPR_AO_FIFO_DEPTH 2048 + +#define DPR_EXTERNAL_CLOCK 1 +#define DPR_RISING_EDGE 2 + +#define DPR_TMODE_MASK 0x1c + +#define DPR_CMD_TIMEOUT 100 + static const struct comedi_lrange range_dt3000_ai = { 4, { BIP_RANGE(10), @@ -85,184 +168,87 @@ enum dt3k_boardid { struct dt3k_boardtype { const char *name; int adchan; - int adbits; int ai_speed; const struct comedi_lrange *adrange; - int dachan; - int dabits; + unsigned int ai_is_16bit:1; + unsigned int has_ao:1; }; static const struct dt3k_boardtype dt3k_boardtypes[] = { [BOARD_DT3001] = { .name = "dt3001", .adchan = 16, - .adbits = 12, .adrange = &range_dt3000_ai, .ai_speed = 3000, - .dachan = 2, - .dabits = 12, + .has_ao = 1, }, [BOARD_DT3001_PGL] = { .name = "dt3001-pgl", .adchan = 16, - .adbits = 12, .adrange = &range_dt3000_ai_pgl, .ai_speed = 3000, - .dachan = 2, - .dabits = 12, + .has_ao = 1, }, [BOARD_DT3002] = { .name = "dt3002", .adchan = 32, - .adbits = 12, .adrange = &range_dt3000_ai, .ai_speed = 3000, }, [BOARD_DT3003] = { .name = "dt3003", .adchan = 64, - .adbits = 12, .adrange = &range_dt3000_ai, .ai_speed = 3000, - .dachan = 2, - .dabits = 12, + .has_ao = 1, }, [BOARD_DT3003_PGL] = { .name = "dt3003-pgl", .adchan = 64, - .adbits = 12, .adrange = &range_dt3000_ai_pgl, .ai_speed = 3000, - .dachan = 2, - .dabits = 12, + .has_ao = 1, }, [BOARD_DT3004] = { .name = "dt3004", .adchan = 16, - .adbits = 16, .adrange = &range_dt3000_ai, .ai_speed = 10000, - .dachan = 2, - .dabits = 12, + .ai_is_16bit = 1, + .has_ao = 1, }, [BOARD_DT3005] = { .name = "dt3005", /* a.k.a. 3004-200 */ .adchan = 16, - .adbits = 16, .adrange = &range_dt3000_ai, .ai_speed = 5000, - .dachan = 2, - .dabits = 12, + .ai_is_16bit = 1, + .has_ao = 1, }, }; -/* dual-ported RAM location definitions */ - -#define DPR_DAC_buffer (4*0x000) -#define DPR_ADC_buffer (4*0x800) -#define DPR_Command (4*0xfd3) -#define DPR_SubSys (4*0xfd3) -#define DPR_Encode (4*0xfd4) -#define DPR_Params(a) (4*(0xfd5+(a))) -#define DPR_Tick_Reg_Lo (4*0xff5) -#define DPR_Tick_Reg_Hi (4*0xff6) -#define DPR_DA_Buf_Front (4*0xff7) -#define DPR_DA_Buf_Rear (4*0xff8) -#define DPR_AD_Buf_Front (4*0xff9) -#define DPR_AD_Buf_Rear (4*0xffa) -#define DPR_Int_Mask (4*0xffb) -#define DPR_Intr_Flag (4*0xffc) -#define DPR_Response_Mbx (4*0xffe) -#define DPR_Command_Mbx (4*0xfff) - -#define AI_FIFO_DEPTH 2003 -#define AO_FIFO_DEPTH 2048 - -/* command list */ - -#define CMD_GETBRDINFO 0 -#define CMD_CONFIG 1 -#define CMD_GETCONFIG 2 -#define CMD_START 3 -#define CMD_STOP 4 -#define CMD_READSINGLE 5 -#define CMD_WRITESINGLE 6 -#define CMD_CALCCLOCK 7 -#define CMD_READEVENTS 8 -#define CMD_WRITECTCTRL 16 -#define CMD_READCTCTRL 17 -#define CMD_WRITECT 18 -#define CMD_READCT 19 -#define CMD_WRITEDATA 32 -#define CMD_READDATA 33 -#define CMD_WRITEIO 34 -#define CMD_READIO 35 -#define CMD_WRITECODE 36 -#define CMD_READCODE 37 -#define CMD_EXECUTE 38 -#define CMD_HALT 48 - -#define SUBS_AI 0 -#define SUBS_AO 1 -#define SUBS_DIN 2 -#define SUBS_DOUT 3 -#define SUBS_MEM 4 -#define SUBS_CT 5 - -/* interrupt flags */ -#define DT3000_CMDONE 0x80 -#define DT3000_CTDONE 0x40 -#define DT3000_DAHWERR 0x20 -#define DT3000_DASWERR 0x10 -#define DT3000_DAEMPTY 0x08 -#define DT3000_ADHWERR 0x04 -#define DT3000_ADSWERR 0x02 -#define DT3000_ADFULL 0x01 - -#define DT3000_COMPLETION_MASK 0xff00 -#define DT3000_COMMAND_MASK 0x00ff -#define DT3000_NOTPROCESSED 0x0000 -#define DT3000_NOERROR 0x5500 -#define DT3000_ERROR 0xaa00 -#define DT3000_NOTSUPPORTED 0xff00 - -#define DT3000_EXTERNAL_CLOCK 1 -#define DT3000_RISING_EDGE 2 - -#define TMODE_MASK 0x1c - -#define DT3000_AD_TRIG_INTERNAL (0<<2) -#define DT3000_AD_TRIG_EXTERNAL (1<<2) -#define DT3000_AD_RETRIG_INTERNAL (2<<2) -#define DT3000_AD_RETRIG_EXTERNAL (3<<2) -#define DT3000_AD_EXTRETRIG (4<<2) - -#define DT3000_CHANNEL_MODE_SE 0 -#define DT3000_CHANNEL_MODE_DI 1 - struct dt3k_private { unsigned int lock; unsigned int ai_front; unsigned int ai_rear; }; -#define TIMEOUT 100 - static void dt3k_send_cmd(struct comedi_device *dev, unsigned int cmd) { int i; unsigned int status = 0; - writew(cmd, dev->mmio + DPR_Command_Mbx); + writew(cmd, dev->mmio + DPR_CMD_MBX); - for (i = 0; i < TIMEOUT; i++) { - status = readw(dev->mmio + DPR_Command_Mbx); - if ((status & DT3000_COMPLETION_MASK) != DT3000_NOTPROCESSED) + for (i = 0; i < DPR_CMD_TIMEOUT; i++) { + status = readw(dev->mmio + DPR_CMD_MBX); + status &= DPR_CMD_COMPLETION_MASK; + if (status != DPR_CMD_NOTPROCESSED) break; udelay(1); } - if ((status & DT3000_COMPLETION_MASK) != DT3000_NOERROR) + if (status != DPR_CMD_NOERROR) dev_dbg(dev->class_dev, "%s: timeout/error status=0x%04x\n", __func__, status); } @@ -271,26 +257,26 @@ static unsigned int dt3k_readsingle(struct comedi_device *dev, unsigned int subsys, unsigned int chan, unsigned int gain) { - writew(subsys, dev->mmio + DPR_SubSys); + writew(subsys, dev->mmio + DPR_SUBSYS); - writew(chan, dev->mmio + DPR_Params(0)); - writew(gain, dev->mmio + DPR_Params(1)); + writew(chan, dev->mmio + DPR_PARAMS(0)); + writew(gain, dev->mmio + DPR_PARAMS(1)); - dt3k_send_cmd(dev, CMD_READSINGLE); + dt3k_send_cmd(dev, DPR_CMD_READSINGLE); - return readw(dev->mmio + DPR_Params(2)); + return readw(dev->mmio + DPR_PARAMS(2)); } static void dt3k_writesingle(struct comedi_device *dev, unsigned int subsys, unsigned int chan, unsigned int data) { - writew(subsys, dev->mmio + DPR_SubSys); + writew(subsys, dev->mmio + DPR_SUBSYS); - writew(chan, dev->mmio + DPR_Params(0)); - writew(0, dev->mmio + DPR_Params(1)); - writew(data, dev->mmio + DPR_Params(2)); + writew(chan, dev->mmio + DPR_PARAMS(0)); + writew(0, dev->mmio + DPR_PARAMS(1)); + writew(data, dev->mmio + DPR_PARAMS(2)); - dt3k_send_cmd(dev, CMD_WRITESINGLE); + dt3k_send_cmd(dev, DPR_CMD_WRITESINGLE); } static void dt3k_ai_empty_fifo(struct comedi_device *dev, @@ -303,32 +289,32 @@ static void dt3k_ai_empty_fifo(struct comedi_device *dev, int i; unsigned short data; - front = readw(dev->mmio + DPR_AD_Buf_Front); + front = readw(dev->mmio + DPR_AD_BUF_FRONT); count = front - devpriv->ai_front; if (count < 0) - count += AI_FIFO_DEPTH; + count += DPR_AI_FIFO_DEPTH; rear = devpriv->ai_rear; for (i = 0; i < count; i++) { - data = readw(dev->mmio + DPR_ADC_buffer + rear); + data = readw(dev->mmio + DPR_ADC_BUFFER + rear); comedi_buf_write_samples(s, &data, 1); rear++; - if (rear >= AI_FIFO_DEPTH) + if (rear >= DPR_AI_FIFO_DEPTH) rear = 0; } devpriv->ai_rear = rear; - writew(rear, dev->mmio + DPR_AD_Buf_Rear); + writew(rear, dev->mmio + DPR_AD_BUF_REAR); } static int dt3k_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { - writew(SUBS_AI, dev->mmio + DPR_SubSys); - dt3k_send_cmd(dev, CMD_STOP); + writew(DPR_SUBSYS_AI, dev->mmio + DPR_SUBSYS); + dt3k_send_cmd(dev, DPR_CMD_STOP); - writew(0, dev->mmio + DPR_Int_Mask); + writew(0, dev->mmio + DPR_INT_MASK); return 0; } @@ -346,12 +332,12 @@ static irqreturn_t dt3k_interrupt(int irq, void *d) if (!dev->attached) return IRQ_NONE; - status = readw(dev->mmio + DPR_Intr_Flag); + status = readw(dev->mmio + DPR_INTR_FLAG); - if (status & DT3000_ADFULL) + if (status & DPR_INTR_ADFULL) dt3k_ai_empty_fifo(dev, s); - if (status & (DT3000_ADSWERR | DT3000_ADHWERR)) + if (status & (DPR_INTR_ADSWERR | DPR_INTR_ADHWERR)) s->async->events |= COMEDI_CB_ERROR; debug_n_ints++; @@ -486,46 +472,49 @@ static int dt3k_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) chan = CR_CHAN(cmd->chanlist[i]); range = CR_RANGE(cmd->chanlist[i]); - writew((range << 6) | chan, dev->mmio + DPR_ADC_buffer + i); + writew((range << 6) | chan, dev->mmio + DPR_ADC_BUFFER + i); } aref = CR_AREF(cmd->chanlist[0]); - writew(cmd->scan_end_arg, dev->mmio + DPR_Params(0)); + writew(cmd->scan_end_arg, dev->mmio + DPR_PARAMS(0)); if (cmd->convert_src == TRIG_TIMER) { divider = dt3k_ns_to_timer(50, &cmd->convert_arg, cmd->flags); - writew((divider >> 16), dev->mmio + DPR_Params(1)); - writew((divider & 0xffff), dev->mmio + DPR_Params(2)); + writew((divider >> 16), dev->mmio + DPR_PARAMS(1)); + writew((divider & 0xffff), dev->mmio + DPR_PARAMS(2)); } if (cmd->scan_begin_src == TRIG_TIMER) { tscandiv = dt3k_ns_to_timer(100, &cmd->scan_begin_arg, cmd->flags); - writew((tscandiv >> 16), dev->mmio + DPR_Params(3)); - writew((tscandiv & 0xffff), dev->mmio + DPR_Params(4)); + writew((tscandiv >> 16), dev->mmio + DPR_PARAMS(3)); + writew((tscandiv & 0xffff), dev->mmio + DPR_PARAMS(4)); } - writew(DT3000_AD_RETRIG_INTERNAL, dev->mmio + DPR_Params(5)); - writew(aref == AREF_DIFF, dev->mmio + DPR_Params(6)); + writew(DPR_PARAM5_AD_TRIG_INT_RETRIG, dev->mmio + DPR_PARAMS(5)); + writew((aref == AREF_DIFF) ? DPR_PARAM6_AD_DIFF : 0, + dev->mmio + DPR_PARAMS(6)); - writew(AI_FIFO_DEPTH / 2, dev->mmio + DPR_Params(7)); + writew(DPR_AI_FIFO_DEPTH / 2, dev->mmio + DPR_PARAMS(7)); - writew(SUBS_AI, dev->mmio + DPR_SubSys); - dt3k_send_cmd(dev, CMD_CONFIG); + writew(DPR_SUBSYS_AI, dev->mmio + DPR_SUBSYS); + dt3k_send_cmd(dev, DPR_CMD_CONFIG); - writew(DT3000_ADFULL | DT3000_ADSWERR | DT3000_ADHWERR, - dev->mmio + DPR_Int_Mask); + writew(DPR_INTR_ADFULL | DPR_INTR_ADSWERR | DPR_INTR_ADHWERR, + dev->mmio + DPR_INT_MASK); debug_n_ints = 0; - writew(SUBS_AI, dev->mmio + DPR_SubSys); - dt3k_send_cmd(dev, CMD_START); + writew(DPR_SUBSYS_AI, dev->mmio + DPR_SUBSYS); + dt3k_send_cmd(dev, DPR_CMD_START); return 0; } -static int dt3k_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int dt3k_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { int i; unsigned int chan, gain, aref; @@ -536,7 +525,7 @@ static int dt3k_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s, aref = CR_AREF(insn->chanspec); for (i = 0; i < insn->n; i++) - data[i] = dt3k_readsingle(dev, SUBS_AI, chan, gain); + data[i] = dt3k_readsingle(dev, DPR_SUBSYS_AI, chan, gain); return i; } @@ -552,7 +541,7 @@ static int dt3k_ao_insn_write(struct comedi_device *dev, for (i = 0; i < insn->n; i++) { val = data[i]; - dt3k_writesingle(dev, SUBS_AO, chan, val); + dt3k_writesingle(dev, DPR_SUBSYS_AO, chan, val); } s->readback[chan] = val; @@ -562,16 +551,13 @@ static int dt3k_ao_insn_write(struct comedi_device *dev, static void dt3k_dio_config(struct comedi_device *dev, int bits) { /* XXX */ - writew(SUBS_DOUT, dev->mmio + DPR_SubSys); + writew(DPR_SUBSYS_DOUT, dev->mmio + DPR_SUBSYS); - writew(bits, dev->mmio + DPR_Params(0)); -#if 0 - /* don't know */ - writew(0, dev->mmio + DPR_Params(1)); - writew(0, dev->mmio + DPR_Params(2)); -#endif + writew(bits, dev->mmio + DPR_PARAMS(0)); - dt3k_send_cmd(dev, CMD_CONFIG); + /* XXX write 0 to DPR_PARAMS(1) and DPR_PARAMS(2) ? */ + + dt3k_send_cmd(dev, DPR_CMD_CONFIG); } static int dt3k_dio_insn_config(struct comedi_device *dev, @@ -603,9 +589,9 @@ static int dt3k_dio_insn_bits(struct comedi_device *dev, unsigned int *data) { if (comedi_dio_update_state(s, data)) - dt3k_writesingle(dev, SUBS_DOUT, 0, s->state); + dt3k_writesingle(dev, DPR_SUBSYS_DOUT, 0, s->state); - data[1] = dt3k_readsingle(dev, SUBS_DIN, 0, 0); + data[1] = dt3k_readsingle(dev, DPR_SUBSYS_DIN, 0, 0); return insn->n; } @@ -619,13 +605,13 @@ static int dt3k_mem_insn_read(struct comedi_device *dev, int i; for (i = 0; i < insn->n; i++) { - writew(SUBS_MEM, dev->mmio + DPR_SubSys); - writew(addr, dev->mmio + DPR_Params(0)); - writew(1, dev->mmio + DPR_Params(1)); + writew(DPR_SUBSYS_MEM, dev->mmio + DPR_SUBSYS); + writew(addr, dev->mmio + DPR_PARAMS(0)); + writew(1, dev->mmio + DPR_PARAMS(1)); - dt3k_send_cmd(dev, CMD_READCODE); + dt3k_send_cmd(dev, DPR_CMD_READCODE); - data[i] = readw(dev->mmio + DPR_Params(2)); + data[i] = readw(dev->mmio + DPR_PARAMS(2)); } return i; @@ -670,14 +656,14 @@ static int dt3000_auto_attach(struct comedi_device *dev, if (ret) return ret; + /* Analog Input subdevice */ s = &dev->subdevices[0]; - /* ai subdevice */ s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF; s->n_chan = board->adchan; - s->insn_read = dt3k_ai_insn; - s->maxdata = (1 << board->adbits) - 1; + s->maxdata = board->ai_is_16bit ? 0xffff : 0x0fff; s->range_table = &range_dt3000_ai; /* XXX */ + s->insn_read = dt3k_ai_insn_read; if (dev->irq) { dev->read_subdev = s; s->subdev_flags |= SDF_CMD_READ; @@ -687,46 +673,42 @@ static int dt3000_auto_attach(struct comedi_device *dev, s->cancel = dt3k_ai_cancel; } + /* Analog Output subdevice */ s = &dev->subdevices[1]; - /* ao subsystem */ - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 2; - s->maxdata = (1 << board->dabits) - 1; - s->len_chanlist = 1; - s->range_table = &range_bipolar10; - s->insn_write = dt3k_ao_insn_write; + if (board->has_ao) { + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 2; + s->maxdata = 0x0fff; + s->range_table = &range_bipolar10; + s->insn_write = dt3k_ao_insn_write; - ret = comedi_alloc_subdev_readback(s); - if (ret) - return ret; + ret = comedi_alloc_subdev_readback(s); + if (ret) + return ret; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* Digital I/O subdevice */ s = &dev->subdevices[2]; - /* dio subsystem */ s->type = COMEDI_SUBD_DIO; s->subdev_flags = SDF_READABLE | SDF_WRITABLE; s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; s->insn_config = dt3k_dio_insn_config; s->insn_bits = dt3k_dio_insn_bits; - s->maxdata = 1; - s->len_chanlist = 8; - s->range_table = &range_digital; + /* Memory subdevice */ s = &dev->subdevices[3]; - /* mem subsystem */ s->type = COMEDI_SUBD_MEMORY; s->subdev_flags = SDF_READABLE; s->n_chan = 0x1000; - s->insn_read = dt3k_mem_insn_read; s->maxdata = 0xff; - s->len_chanlist = 1; s->range_table = &range_unknown; - -#if 0 - s = &dev->subdevices[4]; - /* proc subsystem */ - s->type = COMEDI_SUBD_PROC; -#endif + s->insn_read = dt3k_mem_insn_read; return 0; } @@ -765,5 +747,5 @@ static struct pci_driver dt3000_pci_driver = { module_comedi_pci_driver(dt3000_driver, dt3000_pci_driver); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_DESCRIPTION("Comedi driver for Data Translation DT3000 series boards"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c index e11c216a4c85..3295bb4ac8c4 100644 --- a/drivers/staging/comedi/drivers/dt9812.c +++ b/drivers/staging/comedi/drivers/dt9812.c @@ -18,17 +18,17 @@ */ /* -Driver: dt9812 -Description: Data Translation DT9812 USB module -Author: anders.blomdell@control.lth.se (Anders Blomdell) -Status: in development -Devices: [Data Translation] DT9812 (dt9812) -Updated: Sun Nov 20 20:18:34 EST 2005 - -This driver works, but bulk transfers not implemented. Might be a starting point -for someone else. I found out too late that USB has too high latencies (>1 ms) -for my needs. -*/ + * Driver: dt9812 + * Description: Data Translation DT9812 USB module + * Devices: [Data Translation] DT9812 (dt9812) + * Author: anders.blomdell@control.lth.se (Anders Blomdell) + * Status: in development + * Updated: Sun Nov 20 20:18:34 EST 2005 + * + * This driver works, but bulk transfers not implemented. Might be a + * starting point for someone else. I found out too late that USB has + * too high latencies (>1 ms) for my needs. + */ /* * Nota Bene: @@ -80,7 +80,7 @@ for my needs. #define F020_MASK_ADC0CN_AD0INT 0x20 #define F020_MASK_ADC0CN_AD0BUSY 0x10 -#define F020_MASK_DACxCN_DACxEN 0x80 +#define F020_MASK_DACXCN_DACXEN 0x80 enum { /* A/D D/A DI DO CT */ @@ -233,7 +233,7 @@ struct dt9812_usb_cmd { }; struct dt9812_private { - struct semaphore sem; + struct mutex mut; struct { __u8 addr; size_t size; @@ -335,7 +335,7 @@ static int dt9812_digital_in(struct comedi_device *dev, u8 *bits) u8 value[2]; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); ret = dt9812_read_multiple_registers(dev, 2, reg, value); if (ret == 0) { /* @@ -345,7 +345,7 @@ static int dt9812_digital_in(struct comedi_device *dev, u8 *bits) */ *bits = (value[0] & 0x7f) | ((value[1] & 0x08) << 4); } - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -357,9 +357,9 @@ static int dt9812_digital_out(struct comedi_device *dev, u8 bits) u8 value[1] = { bits }; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); ret = dt9812_write_multiple_registers(dev, 1, reg, value); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -444,7 +444,7 @@ static int dt9812_analog_in(struct comedi_device *dev, u8 val[3]; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); /* 1 select the gain */ dt9812_configure_gain(dev, &rmw[0], gain); @@ -493,7 +493,7 @@ static int dt9812_analog_in(struct comedi_device *dev, } exit: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -504,22 +504,21 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value) struct dt9812_rmw_byte rmw[3]; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); 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; + rmw[0].or_value = F020_MASK_DACXCN_DACXEN; - /* 2 load low byte of DAC value first */ + /* 2. load lsb 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 */ + /* 3. load msb 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; @@ -529,15 +528,14 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value) /* 1. Set DAC mode */ rmw[0].address = F020_SFR_DAC1CN; rmw[0].and_mask = 0xff; - rmw[0].or_value = F020_MASK_DACxCN_DACxEN; + rmw[0].or_value = F020_MASK_DACXCN_DACXEN; - /* 2 load low byte of DAC value first */ + /* 2. load lsb 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 */ + /* 3. load msb 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; @@ -545,7 +543,7 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value) } ret = dt9812_rmw_multiple_registers(dev, 3, rmw); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -608,9 +606,9 @@ static int dt9812_ao_insn_read(struct comedi_device *dev, struct dt9812_private *devpriv = dev->private; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); ret = comedi_readback_insn_read(dev, s, insn, data); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -774,7 +772,7 @@ static int dt9812_auto_attach(struct comedi_device *dev, if (!devpriv) return -ENOMEM; - sema_init(&devpriv->sem, 1); + mutex_init(&devpriv->mut); usb_set_intfdata(intf, devpriv); ret = dt9812_find_endpoints(dev); @@ -846,11 +844,11 @@ static void dt9812_detach(struct comedi_device *dev) if (!devpriv) return; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); usb_set_intfdata(intf, NULL); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); } static struct comedi_driver dt9812_driver = { diff --git a/drivers/staging/comedi/drivers/fl512.c b/drivers/staging/comedi/drivers/fl512.c index 55cae61458cb..0f278ffdad76 100644 --- a/drivers/staging/comedi/drivers/fl512.c +++ b/drivers/staging/comedi/drivers/fl512.c @@ -71,7 +71,7 @@ static int fl512_ai_insn_read(struct comedi_device *dev, outb(0, dev->iobase + FL512_AI_START_CONV_REG); /* XXX should test "done" flag instead of delay */ - udelay(30); + usleep_range(30, 100); val = inb(dev->iobase + FL512_AI_LSB_REG); val |= (inb(dev->iobase + FL512_AI_MSB_REG) << 8); diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c b/drivers/staging/comedi/drivers/gsc_hpdi.c index e9296182236e..46ca5d938d5b 100644 --- a/drivers/staging/comedi/drivers/gsc_hpdi.c +++ b/drivers/staging/comedi/drivers/gsc_hpdi.c @@ -125,7 +125,7 @@ struct hpdi_private { void __iomem *plx9080_mmio; - uint32_t *dio_buffer[NUM_DMA_BUFFERS]; /* dma buffers */ + u32 *dio_buffer[NUM_DMA_BUFFERS]; /* dma buffers */ /* physical addresses of dma buffers */ dma_addr_t dio_buffer_phys_addr[NUM_DMA_BUFFERS]; /* @@ -137,7 +137,7 @@ struct hpdi_private { dma_addr_t dma_desc_phys_addr; unsigned int num_dma_descriptors; /* pointer to start of buffers indexed by descriptor */ - uint32_t *desc_dio_buffer[NUM_DMA_DESCRIPTORS]; + u32 *desc_dio_buffer[NUM_DMA_DESCRIPTORS]; /* index of the dma descriptor that is currently being used */ unsigned int dma_desc_index; unsigned int tx_fifo_size; @@ -169,7 +169,7 @@ static void gsc_hpdi_drain_dma(struct comedi_device *dev, unsigned int channel) for (desc = 0; (next < start || next >= start + devpriv->block_size) && desc < devpriv->num_dma_descriptors; desc++) { /* transfer data from dma buffer to comedi buffer */ - size = devpriv->block_size / sizeof(uint32_t); + size = devpriv->block_size / sizeof(u32); if (cmd->stop_src == TRIG_COUNT) { if (size > devpriv->dio_count) size = devpriv->dio_count; @@ -192,10 +192,10 @@ static irqreturn_t gsc_hpdi_interrupt(int irq, void *d) struct hpdi_private *devpriv = dev->private; struct comedi_subdevice *s = dev->read_subdev; struct comedi_async *async = s->async; - uint32_t hpdi_intr_status, hpdi_board_status; - uint32_t plx_status; - uint32_t plx_bits; - uint8_t dma0_status, dma1_status; + u32 hpdi_intr_status, hpdi_board_status; + u32 plx_status; + u32 plx_bits; + u8 dma0_status, dma1_status; unsigned long flags; if (!dev->attached) @@ -290,7 +290,7 @@ static int gsc_hpdi_cmd(struct comedi_device *dev, struct comedi_async *async = s->async; struct comedi_cmd *cmd = &async->cmd; unsigned long flags; - uint32_t bits; + u32 bits; if (s->io_bits) return -EINVAL; @@ -424,15 +424,15 @@ static int gsc_hpdi_setup_dma_descriptors(struct comedi_device *dev, { struct hpdi_private *devpriv = dev->private; dma_addr_t phys_addr = devpriv->dma_desc_phys_addr; - uint32_t next_bits = PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT | - PLX_XFER_LOCAL_TO_PCI; + u32 next_bits = PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT | + PLX_XFER_LOCAL_TO_PCI; unsigned int offset = 0; unsigned int idx = 0; unsigned int i; if (len > DMA_BUFFER_SIZE) len = DMA_BUFFER_SIZE; - len -= len % sizeof(uint32_t); + len -= len % sizeof(u32); if (len == 0) return -EINVAL; @@ -445,7 +445,7 @@ static int gsc_hpdi_setup_dma_descriptors(struct comedi_device *dev, (i + 1) * sizeof(devpriv->dma_desc[0])) | next_bits); devpriv->desc_dio_buffer[i] = devpriv->dio_buffer[idx] + - (offset / sizeof(uint32_t)); + (offset / sizeof(u32)); offset += len; if (len + offset > DMA_BUFFER_SIZE) { @@ -516,7 +516,7 @@ static void gsc_hpdi_free_dma(struct comedi_device *dev) static int gsc_hpdi_init(struct comedi_device *dev) { struct hpdi_private *devpriv = dev->private; - uint32_t plx_intcsr_bits; + u32 plx_intcsr_bits; /* wait 10usec after reset before accessing fifos */ writel(BOARD_RESET_BIT, dev->mmio + BOARD_CONTROL_REG); @@ -546,7 +546,7 @@ static int gsc_hpdi_init(struct comedi_device *dev) static void gsc_hpdi_init_plx9080(struct comedi_device *dev) { struct hpdi_private *devpriv = dev->private; - uint32_t bits; + u32 bits; void __iomem *plx_iobase = devpriv->plx9080_mmio; #ifdef __BIG_ENDIAN diff --git a/drivers/staging/comedi/drivers/icp_multi.c b/drivers/staging/comedi/drivers/icp_multi.c index 1e104ebf8057..28cf53e48b8d 100644 --- a/drivers/staging/comedi/drivers/icp_multi.c +++ b/drivers/staging/comedi/drivers/icp_multi.c @@ -1,94 +1,89 @@ /* - comedi/drivers/icp_multi.c - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 1997-2002 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. -*/ + * icp_multi.c + * Comedi driver for Inova ICP_MULTI board + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1997-2002 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. + */ /* -Driver: icp_multi -Description: Inova ICP_MULTI -Author: Anne Smorthit -Devices: [Inova] ICP_MULTI (icp_multi) -Status: works - -The driver works for analog input and output and digital input and output. -It does not work with interrupts or with the counters. Currently no support -for DMA. - -It has 16 single-ended or 8 differential Analogue Input channels with 12-bit -resolution. Ranges : 5V, 10V, +/-5V, +/-10V, 0..20mA and 4..20mA. Input -ranges can be individually programmed for each channel. Voltage or current -measurement is selected by jumper. - -There are 4 x 12-bit Analogue Outputs. Ranges : 5V, 10V, +/-5V, +/-10V - -16 x Digital Inputs, 24V - -8 x Digital Outputs, 24V, 1A - -4 x 16-bit counters - -Configuration options: not applicable, uses PCI auto config -*/ + * Driver: icp_multi + * Description: Inova ICP_MULTI + * Devices: [Inova] ICP_MULTI (icp_multi) + * Author: Anne Smorthit + * Status: works + * + * Configuration options: not applicable, uses PCI auto config + * + * The driver works for analog input and output and digital input and + * output. It does not work with interrupts or with the counters. Currently + * no support for DMA. + * + * It has 16 single-ended or 8 differential Analogue Input channels with + * 12-bit resolution. Ranges : 5V, 10V, +/-5V, +/-10V, 0..20mA and 4..20mA. + * Input ranges can be individually programmed for each channel. Voltage or + * current measurement is selected by jumper. + * + * There are 4 x 12-bit Analogue Outputs. Ranges : 5V, 10V, +/-5V, +/-10V + * + * 16 x Digital Inputs, 24V + * + * 8 x Digital Outputs, 24V, 1A + * + * 4 x 16-bit counters - not implemented + */ #include #include -#include #include "../comedi_pci.h" -#define ICP_MULTI_ADC_CSR 0 /* R/W: ADC command/status register */ +#define ICP_MULTI_ADC_CSR 0x00 /* R/W: ADC command/status register */ +#define ICP_MULTI_ADC_CSR_ST BIT(0) /* Start ADC */ +#define ICP_MULTI_ADC_CSR_BSY BIT(0) /* ADC busy */ +#define ICP_MULTI_ADC_CSR_BI BIT(4) /* Bipolar input range */ +#define ICP_MULTI_ADC_CSR_RA BIT(5) /* Input range 0 = 5V, 1 = 10V */ +#define ICP_MULTI_ADC_CSR_DI BIT(6) /* Input mode 1 = differential */ +#define ICP_MULTI_ADC_CSR_DI_CHAN(x) (((x) & 0x7) << 9) +#define ICP_MULTI_ADC_CSR_SE_CHAN(x) (((x) & 0xf) << 8) #define ICP_MULTI_AI 2 /* R: Analogue input data */ -#define ICP_MULTI_DAC_CSR 4 /* R/W: DAC command/status register */ +#define ICP_MULTI_DAC_CSR 0x04 /* R/W: DAC command/status register */ +#define ICP_MULTI_DAC_CSR_ST BIT(0) /* Start DAC */ +#define ICP_MULTI_DAC_CSR_BSY BIT(0) /* DAC busy */ +#define ICP_MULTI_DAC_CSR_BI BIT(4) /* Bipolar output range */ +#define ICP_MULTI_DAC_CSR_RA BIT(5) /* Output range 0 = 5V, 1 = 10V */ +#define ICP_MULTI_DAC_CSR_CHAN(x) (((x) & 0x3) << 8) #define ICP_MULTI_AO 6 /* R/W: Analogue output data */ #define ICP_MULTI_DI 8 /* R/W: Digital inputs */ #define ICP_MULTI_DO 0x0A /* R/W: Digital outputs */ -#define ICP_MULTI_INT_EN 0x0C /* R/W: Interrupt enable register */ -#define ICP_MULTI_INT_STAT 0x0E /* R/W: Interrupt status register */ +#define ICP_MULTI_INT_EN 0x0c /* R/W: Interrupt enable register */ +#define ICP_MULTI_INT_STAT 0x0e /* R/W: Interrupt status register */ +#define ICP_MULTI_INT_ADC_RDY BIT(0) /* A/D conversion ready interrupt */ +#define ICP_MULTI_INT_DAC_RDY BIT(1) /* D/A conversion ready interrupt */ +#define ICP_MULTI_INT_DOUT_ERR BIT(2) /* Digital output error interrupt */ +#define ICP_MULTI_INT_DIN_STAT BIT(3) /* Digital input status change int. */ +#define ICP_MULTI_INT_CIE0 BIT(4) /* Counter 0 overrun interrupt */ +#define ICP_MULTI_INT_CIE1 BIT(5) /* Counter 1 overrun interrupt */ +#define ICP_MULTI_INT_CIE2 BIT(6) /* Counter 2 overrun interrupt */ +#define ICP_MULTI_INT_CIE3 BIT(7) /* Counter 3 overrun interrupt */ +#define ICP_MULTI_INT_MASK 0xff /* All interrupts */ #define ICP_MULTI_CNTR0 0x10 /* R/W: Counter 0 */ #define ICP_MULTI_CNTR1 0x12 /* R/W: counter 1 */ #define ICP_MULTI_CNTR2 0x14 /* R/W: Counter 2 */ #define ICP_MULTI_CNTR3 0x16 /* R/W: Counter 3 */ -/* Define bits from ADC command/status register */ -#define ADC_ST 0x0001 /* Start ADC */ -#define ADC_BSY 0x0001 /* ADC busy */ -#define ADC_BI 0x0010 /* Bipolar input range 1 = bipolar */ -#define ADC_RA 0x0020 /* Input range 0 = 5V, 1 = 10V */ -#define ADC_DI 0x0040 /* Differential input mode 1 = differential */ - -/* Define bits from DAC command/status register */ -#define DAC_ST 0x0001 /* Start DAC */ -#define DAC_BSY 0x0001 /* DAC busy */ -#define DAC_BI 0x0010 /* Bipolar input range 1 = bipolar */ -#define DAC_RA 0x0020 /* Input range 0 = 5V, 1 = 10V */ - -/* Define bits from interrupt enable/status registers */ -#define ADC_READY 0x0001 /* A/d conversion ready interrupt */ -#define DAC_READY 0x0002 /* D/a conversion ready interrupt */ -#define DOUT_ERROR 0x0004 /* Digital output error interrupt */ -#define DIN_STATUS 0x0008 /* Digital input status change interrupt */ -#define CIE0 0x0010 /* Counter 0 overrun interrupt */ -#define CIE1 0x0020 /* Counter 1 overrun interrupt */ -#define CIE2 0x0040 /* Counter 2 overrun interrupt */ -#define CIE3 0x0080 /* Counter 3 overrun interrupt */ - -/* Useful definitions */ -#define Status_IRQ 0x00ff /* All interrupts */ - -/* Define analogue range */ -static const struct comedi_lrange range_analog = { +/* analog input and output have the same range options */ +static const struct comedi_lrange icp_multi_ranges = { 4, { UNI_RANGE(5), UNI_RANGE(10), @@ -99,71 +94,6 @@ static const struct comedi_lrange range_analog = { static const char range_codes_analog[] = { 0x00, 0x20, 0x10, 0x30 }; -/* -============================================================================== - Data & Structure declarations -============================================================================== -*/ - -struct icp_multi_private { - unsigned int AdcCmdStatus; /* ADC Command/Status register */ - unsigned int DacCmdStatus; /* DAC Command/Status register */ - unsigned int IntEnable; /* Interrupt Enable register */ - unsigned int IntStatus; /* Interrupt Status register */ - unsigned int act_chanlist[32]; /* list of scanned channel */ - unsigned char act_chanlist_len; /* len of scanlist */ - unsigned char act_chanlist_pos; /* actual position in MUX list */ - unsigned int *ai_chanlist; /* actaul chanlist */ - unsigned int do_data; /* Remember digital output data */ -}; - -static void setup_channel_list(struct comedi_device *dev, - struct comedi_subdevice *s, - unsigned int *chanlist, unsigned int n_chan) -{ - struct icp_multi_private *devpriv = dev->private; - unsigned int i, range, chanprog; - unsigned int diff; - - devpriv->act_chanlist_len = n_chan; - devpriv->act_chanlist_pos = 0; - - for (i = 0; i < n_chan; i++) { - /* Get channel */ - chanprog = CR_CHAN(chanlist[i]); - - /* Determine if it is a differential channel (Bit 15 = 1) */ - if (CR_AREF(chanlist[i]) == AREF_DIFF) { - diff = 1; - chanprog &= 0x0007; - } else { - diff = 0; - chanprog &= 0x000f; - } - - /* Clear channel, range and input mode bits - * in A/D command/status register */ - devpriv->AdcCmdStatus &= 0xf00f; - - /* Set channel number and differential mode status bit */ - if (diff) { - /* Set channel number, bits 9-11 & mode, bit 6 */ - devpriv->AdcCmdStatus |= (chanprog << 9); - devpriv->AdcCmdStatus |= ADC_DI; - } else - /* Set channel number, bits 8-11 */ - devpriv->AdcCmdStatus |= (chanprog << 8); - - /* Get range for current channel */ - range = range_codes_analog[CR_RANGE(chanlist[i])]; - /* Set range. bits 4-5 */ - devpriv->AdcCmdStatus |= range; - - /* Output channel, range, mode to ICP Multi */ - writew(devpriv->AdcCmdStatus, dev->mmio + ICP_MULTI_ADC_CSR); - } -} - static int icp_multi_ai_eoc(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -172,36 +102,37 @@ static int icp_multi_ai_eoc(struct comedi_device *dev, unsigned int status; status = readw(dev->mmio + ICP_MULTI_ADC_CSR); - if ((status & ADC_BSY) == 0) + if ((status & ICP_MULTI_ADC_CSR_BSY) == 0) return 0; return -EBUSY; } -static int icp_multi_insn_read_ai(struct comedi_device *dev, +static int icp_multi_ai_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct icp_multi_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int range = CR_RANGE(insn->chanspec); + unsigned int aref = CR_AREF(insn->chanspec); + unsigned int adc_csr; int ret = 0; int n; - /* Disable A/D conversion ready interrupt */ - devpriv->IntEnable &= ~ADC_READY; - writew(devpriv->IntEnable, dev->mmio + ICP_MULTI_INT_EN); - - /* Clear interrupt status */ - devpriv->IntStatus |= ADC_READY; - writew(devpriv->IntStatus, dev->mmio + ICP_MULTI_INT_STAT); - - /* Set up appropriate channel, mode and range data, for specified ch */ - setup_channel_list(dev, s, &insn->chanspec, 1); + /* Set mode and range data for specified channel */ + if (aref == AREF_DIFF) { + adc_csr = ICP_MULTI_ADC_CSR_DI_CHAN(chan) | + ICP_MULTI_ADC_CSR_DI; + } else { + adc_csr = ICP_MULTI_ADC_CSR_SE_CHAN(chan); + } + adc_csr |= range_codes_analog[range]; + writew(adc_csr, dev->mmio + ICP_MULTI_ADC_CSR); for (n = 0; n < insn->n; n++) { /* Set start ADC bit */ - devpriv->AdcCmdStatus |= ADC_ST; - writew(devpriv->AdcCmdStatus, dev->mmio + ICP_MULTI_ADC_CSR); - devpriv->AdcCmdStatus &= ~ADC_ST; + writew(adc_csr | ICP_MULTI_ADC_CSR_ST, + dev->mmio + ICP_MULTI_ADC_CSR); udelay(1); @@ -213,26 +144,18 @@ static int icp_multi_insn_read_ai(struct comedi_device *dev, data[n] = (readw(dev->mmio + ICP_MULTI_AI) >> 4) & 0x0fff; } - /* Disable interrupt */ - devpriv->IntEnable &= ~ADC_READY; - writew(devpriv->IntEnable, dev->mmio + ICP_MULTI_INT_EN); - - /* Clear interrupt status */ - devpriv->IntStatus |= ADC_READY; - writew(devpriv->IntStatus, dev->mmio + ICP_MULTI_INT_STAT); - return ret ? ret : n; } -static int icp_multi_ao_eoc(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned long context) +static int icp_multi_ao_ready(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned long context) { unsigned int status; status = readw(dev->mmio + ICP_MULTI_DAC_CSR); - if ((status & DAC_BSY) == 0) + if ((status & ICP_MULTI_DAC_CSR_BSY) == 0) return 0; return -EBUSY; } @@ -242,57 +165,30 @@ static int icp_multi_ao_insn_write(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct icp_multi_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec); + unsigned int dac_csr; int i; - /* Disable D/A conversion ready interrupt */ - devpriv->IntEnable &= ~DAC_READY; - writew(devpriv->IntEnable, dev->mmio + ICP_MULTI_INT_EN); - - /* Clear interrupt status */ - devpriv->IntStatus |= DAC_READY; - writew(devpriv->IntStatus, dev->mmio + ICP_MULTI_INT_STAT); - - /* Set up range and channel data */ - /* Bit 4 = 1 : Bipolar */ - /* Bit 5 = 0 : 5V */ - /* Bit 5 = 1 : 10V */ - /* Bits 8-9 : Channel number */ - devpriv->DacCmdStatus &= 0xfccf; - devpriv->DacCmdStatus |= range_codes_analog[range]; - devpriv->DacCmdStatus |= (chan << 8); - - writew(devpriv->DacCmdStatus, dev->mmio + ICP_MULTI_DAC_CSR); + /* Select channel and range */ + dac_csr = ICP_MULTI_DAC_CSR_CHAN(chan); + dac_csr |= range_codes_analog[range]; + writew(dac_csr, dev->mmio + ICP_MULTI_DAC_CSR); for (i = 0; i < insn->n; i++) { unsigned int val = data[i]; int ret; - /* Wait for analogue output data register to be - * ready for new data, or get fed up waiting */ - ret = comedi_timeout(dev, s, insn, icp_multi_ao_eoc, 0); - if (ret) { - /* Disable interrupt */ - devpriv->IntEnable &= ~DAC_READY; - writew(devpriv->IntEnable, - dev->mmio + ICP_MULTI_INT_EN); - - /* Clear interrupt status */ - devpriv->IntStatus |= DAC_READY; - writew(devpriv->IntStatus, - dev->mmio + ICP_MULTI_INT_STAT); - + /* Wait for analog output to be ready for new data */ + ret = comedi_timeout(dev, s, insn, icp_multi_ao_ready, 0); + if (ret) return ret; - } writew(val, dev->mmio + ICP_MULTI_AO); - /* Set DAC_ST bit to write the data to selected channel */ - devpriv->DacCmdStatus |= DAC_ST; - writew(devpriv->DacCmdStatus, dev->mmio + ICP_MULTI_DAC_CSR); - devpriv->DacCmdStatus &= ~DAC_ST; + /* Set start conversion bit to write data to channel */ + writew(dac_csr | ICP_MULTI_DAC_CSR_ST, + dev->mmio + ICP_MULTI_DAC_CSR); s->readback[chan] = val; } @@ -300,7 +196,7 @@ static int icp_multi_ao_insn_write(struct comedi_device *dev, return insn->n; } -static int icp_multi_insn_bits_di(struct comedi_device *dev, +static int icp_multi_di_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) @@ -310,7 +206,7 @@ static int icp_multi_insn_bits_di(struct comedi_device *dev, return insn->n; } -static int icp_multi_insn_bits_do(struct comedi_device *dev, +static int icp_multi_do_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) @@ -323,116 +219,27 @@ static int icp_multi_insn_bits_do(struct comedi_device *dev, return insn->n; } -static int icp_multi_insn_read_ctr(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - return 0; -} - -static int icp_multi_insn_write_ctr(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - return 0; -} - -static irqreturn_t interrupt_service_icp_multi(int irq, void *d) -{ - struct comedi_device *dev = d; - int int_no; - - /* Is this interrupt from our board? */ - int_no = readw(dev->mmio + ICP_MULTI_INT_STAT) & Status_IRQ; - if (!int_no) - /* No, exit */ - return IRQ_NONE; - - /* Determine which interrupt is active & handle it */ - switch (int_no) { - case ADC_READY: - break; - case DAC_READY: - break; - case DOUT_ERROR: - break; - case DIN_STATUS: - break; - case CIE0: - break; - case CIE1: - break; - case CIE2: - break; - case CIE3: - break; - default: - break; - } - - return IRQ_HANDLED; -} - -#if 0 -static int check_channel_list(struct comedi_device *dev, - struct comedi_subdevice *s, - unsigned int *chanlist, unsigned int n_chan) -{ - unsigned int i; - - /* Check that we at least have one channel to check */ - if (n_chan < 1) { - dev_err(dev->class_dev, "range/channel list is empty!\n"); - return 0; - } - /* Check all channels */ - for (i = 0; i < n_chan; i++) { - /* Check that channel number is < maximum */ - if (CR_AREF(chanlist[i]) == AREF_DIFF) { - if (CR_CHAN(chanlist[i]) > (s->nchan / 2)) { - dev_err(dev->class_dev, - "Incorrect differential ai ch-nr\n"); - return 0; - } - } else { - if (CR_CHAN(chanlist[i]) > s->n_chan) { - dev_err(dev->class_dev, - "Incorrect ai channel number\n"); - return 0; - } - } - } - return 1; -} -#endif - static int icp_multi_reset(struct comedi_device *dev) { - struct icp_multi_private *devpriv = dev->private; - unsigned int i; + int i; - /* Clear INT enables and requests */ + /* Disable all interrupts and clear any requests */ writew(0, dev->mmio + ICP_MULTI_INT_EN); - writew(0x00ff, dev->mmio + ICP_MULTI_INT_STAT); + writew(ICP_MULTI_INT_MASK, dev->mmio + ICP_MULTI_INT_STAT); - /* Set DACs to 0..5V range and 0V output */ + /* Reset the analog output channels to 0V */ for (i = 0; i < 4; i++) { - devpriv->DacCmdStatus &= 0xfcce; + unsigned int dac_csr = ICP_MULTI_DAC_CSR_CHAN(i); - /* Set channel number */ - devpriv->DacCmdStatus |= (i << 8); + /* Select channel and 0..5V range */ + writew(dac_csr, dev->mmio + ICP_MULTI_DAC_CSR); - /* Output 0V */ + /* Output 0V */ writew(0, dev->mmio + ICP_MULTI_AO); - /* Set start conversion bit */ - devpriv->DacCmdStatus |= DAC_ST; - - /* Output to command / status register */ - writew(devpriv->DacCmdStatus, dev->mmio + ICP_MULTI_DAC_CSR); - - /* Delay to allow DAC time to recover */ + /* Set start conversion bit to write data to channel */ + writew(dac_csr | ICP_MULTI_DAC_CSR_ST, + dev->mmio + ICP_MULTI_DAC_CSR); udelay(1); } @@ -446,14 +253,9 @@ static int icp_multi_auto_attach(struct comedi_device *dev, unsigned long context_unused) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - struct icp_multi_private *devpriv; struct comedi_subdevice *s; int ret; - devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); - if (!devpriv) - return -ENOMEM; - ret = comedi_pci_enable(dev); if (ret) return ret; @@ -462,85 +264,60 @@ static int icp_multi_auto_attach(struct comedi_device *dev, if (!dev->mmio) return -ENOMEM; - ret = comedi_alloc_subdevices(dev, 5); + ret = comedi_alloc_subdevices(dev, 4); if (ret) return ret; icp_multi_reset(dev); - if (pcidev->irq) { - ret = request_irq(pcidev->irq, interrupt_service_icp_multi, - IRQF_SHARED, dev->board_name, dev); - if (ret == 0) - dev->irq = pcidev->irq; - } - + /* Analog Input subdevice */ s = &dev->subdevices[0]; - dev->read_subdev = s; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF; - s->n_chan = 16; - s->maxdata = 0x0fff; - s->len_chanlist = 16; - s->range_table = &range_analog; - s->insn_read = icp_multi_insn_read_ai; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF; + s->n_chan = 16; + s->maxdata = 0x0fff; + s->range_table = &icp_multi_ranges; + s->insn_read = icp_multi_ai_insn_read; + /* Analog Output subdevice */ s = &dev->subdevices[1]; - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = 4; - s->maxdata = 0x0fff; - s->len_chanlist = 4; - s->range_table = &range_analog; - s->insn_write = icp_multi_ao_insn_write; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = 4; + s->maxdata = 0x0fff; + s->range_table = &icp_multi_ranges; + s->insn_write = icp_multi_ao_insn_write; ret = comedi_alloc_subdev_readback(s); if (ret) return ret; + /* Digital Input subdevice */ s = &dev->subdevices[2]; - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->n_chan = 16; - s->maxdata = 1; - s->len_chanlist = 16; - s->range_table = &range_digital; - s->insn_bits = icp_multi_insn_bits_di; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 16; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = icp_multi_di_insn_bits; + /* Digital Output subdevice */ s = &dev->subdevices[3]; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 8; - s->maxdata = 1; - s->len_chanlist = 8; - s->range_table = &range_digital; - s->insn_bits = icp_multi_insn_bits_do; - - s = &dev->subdevices[4]; - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 4; - s->maxdata = 0xffff; - s->len_chanlist = 4; - s->state = 0; - s->insn_read = icp_multi_insn_read_ctr; - s->insn_write = icp_multi_insn_write_ctr; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = icp_multi_do_insn_bits; return 0; } -static void icp_multi_detach(struct comedi_device *dev) -{ - if (dev->mmio) - icp_multi_reset(dev); - comedi_pci_detach(dev); -} - static struct comedi_driver icp_multi_driver = { .driver_name = "icp_multi", .module = THIS_MODULE, .auto_attach = icp_multi_auto_attach, - .detach = icp_multi_detach, + .detach = comedi_pci_detach, }; static int icp_multi_pci_probe(struct pci_dev *dev, @@ -564,5 +341,5 @@ static struct pci_driver icp_multi_pci_driver = { module_comedi_pci_driver(icp_multi_driver, icp_multi_pci_driver); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_DESCRIPTION("Comedi driver for Inova ICP_MULTI board"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/ii_pci20kc.c b/drivers/staging/comedi/drivers/ii_pci20kc.c index 14ef1f67dd42..77e1d891f232 100644 --- a/drivers/staging/comedi/drivers/ii_pci20kc.c +++ b/drivers/staging/comedi/drivers/ii_pci20kc.c @@ -37,37 +37,37 @@ #define II20K_SIZE 0x400 #define II20K_MOD_OFFSET 0x100 #define II20K_ID_REG 0x00 -#define II20K_ID_MOD1_EMPTY (1 << 7) -#define II20K_ID_MOD2_EMPTY (1 << 6) -#define II20K_ID_MOD3_EMPTY (1 << 5) +#define II20K_ID_MOD1_EMPTY BIT(7) +#define II20K_ID_MOD2_EMPTY BIT(6) +#define II20K_ID_MOD3_EMPTY BIT(5) #define II20K_ID_MASK 0x1f #define II20K_ID_PCI20001C_1A 0x1b /* no on-board DIO */ #define II20K_ID_PCI20001C_2A 0x1d /* on-board DIO */ #define II20K_MOD_STATUS_REG 0x40 -#define II20K_MOD_STATUS_IRQ_MOD1 (1 << 7) -#define II20K_MOD_STATUS_IRQ_MOD2 (1 << 6) -#define II20K_MOD_STATUS_IRQ_MOD3 (1 << 5) +#define II20K_MOD_STATUS_IRQ_MOD1 BIT(7) +#define II20K_MOD_STATUS_IRQ_MOD2 BIT(6) +#define II20K_MOD_STATUS_IRQ_MOD3 BIT(5) #define II20K_DIO0_REG 0x80 #define II20K_DIO1_REG 0x81 #define II20K_DIR_ENA_REG 0x82 -#define II20K_DIR_DIO3_OUT (1 << 7) -#define II20K_DIR_DIO2_OUT (1 << 6) -#define II20K_BUF_DISAB_DIO3 (1 << 5) -#define II20K_BUF_DISAB_DIO2 (1 << 4) -#define II20K_DIR_DIO1_OUT (1 << 3) -#define II20K_DIR_DIO0_OUT (1 << 2) -#define II20K_BUF_DISAB_DIO1 (1 << 1) -#define II20K_BUF_DISAB_DIO0 (1 << 0) +#define II20K_DIR_DIO3_OUT BIT(7) +#define II20K_DIR_DIO2_OUT BIT(6) +#define II20K_BUF_DISAB_DIO3 BIT(5) +#define II20K_BUF_DISAB_DIO2 BIT(4) +#define II20K_DIR_DIO1_OUT BIT(3) +#define II20K_DIR_DIO0_OUT BIT(2) +#define II20K_BUF_DISAB_DIO1 BIT(1) +#define II20K_BUF_DISAB_DIO0 BIT(0) #define II20K_CTRL01_REG 0x83 -#define II20K_CTRL01_SET (1 << 7) -#define II20K_CTRL01_DIO0_IN (1 << 4) -#define II20K_CTRL01_DIO1_IN (1 << 1) +#define II20K_CTRL01_SET BIT(7) +#define II20K_CTRL01_DIO0_IN BIT(4) +#define II20K_CTRL01_DIO1_IN BIT(1) #define II20K_DIO2_REG 0xc0 #define II20K_DIO3_REG 0xc1 #define II20K_CTRL23_REG 0xc3 -#define II20K_CTRL23_SET (1 << 7) -#define II20K_CTRL23_DIO2_IN (1 << 4) -#define II20K_CTRL23_DIO3_IN (1 << 1) +#define II20K_CTRL23_SET BIT(7) +#define II20K_CTRL23_DIO2_IN BIT(4) +#define II20K_CTRL23_DIO3_IN BIT(1) #define II20K_ID_PCI20006M_1 0xe2 /* 1 AO channels */ #define II20K_ID_PCI20006M_2 0xe3 /* 2 AO channels */ @@ -78,27 +78,27 @@ #define II20K_ID_PCI20341M_1 0x77 /* 4 AI channels */ #define II20K_AI_STATUS_CMD_REG 0x01 -#define II20K_AI_STATUS_CMD_BUSY (1 << 7) -#define II20K_AI_STATUS_CMD_HW_ENA (1 << 1) -#define II20K_AI_STATUS_CMD_EXT_START (1 << 0) +#define II20K_AI_STATUS_CMD_BUSY BIT(7) +#define II20K_AI_STATUS_CMD_HW_ENA BIT(1) +#define II20K_AI_STATUS_CMD_EXT_START BIT(0) #define II20K_AI_LSB_REG 0x02 #define II20K_AI_MSB_REG 0x03 #define II20K_AI_PACER_RESET_REG 0x04 #define II20K_AI_16BIT_DATA_REG 0x06 #define II20K_AI_CONF_REG 0x10 -#define II20K_AI_CONF_ENA (1 << 2) +#define II20K_AI_CONF_ENA BIT(2) #define II20K_AI_OPT_REG 0x11 -#define II20K_AI_OPT_TRIG_ENA (1 << 5) -#define II20K_AI_OPT_TRIG_INV (1 << 4) +#define II20K_AI_OPT_TRIG_ENA BIT(5) +#define II20K_AI_OPT_TRIG_INV BIT(4) #define II20K_AI_OPT_TIMEBASE(x) (((x) & 0x3) << 1) -#define II20K_AI_OPT_BURST_MODE (1 << 0) +#define II20K_AI_OPT_BURST_MODE BIT(0) #define II20K_AI_STATUS_REG 0x12 -#define II20K_AI_STATUS_INT (1 << 7) -#define II20K_AI_STATUS_TRIG (1 << 6) -#define II20K_AI_STATUS_TRIG_ENA (1 << 5) -#define II20K_AI_STATUS_PACER_ERR (1 << 2) -#define II20K_AI_STATUS_DATA_ERR (1 << 1) -#define II20K_AI_STATUS_SET_TIME_ERR (1 << 0) +#define II20K_AI_STATUS_INT BIT(7) +#define II20K_AI_STATUS_TRIG BIT(6) +#define II20K_AI_STATUS_TRIG_ENA BIT(5) +#define II20K_AI_STATUS_PACER_ERR BIT(2) +#define II20K_AI_STATUS_DATA_ERR BIT(1) +#define II20K_AI_STATUS_SET_TIME_ERR BIT(0) #define II20K_AI_LAST_CHAN_ADDR_REG 0x13 #define II20K_AI_CUR_ADDR_REG 0x14 #define II20K_AI_SET_TIME_REG 0x15 @@ -109,9 +109,9 @@ #define II20K_AI_START_TRIG_REG 0x1a #define II20K_AI_COUNT_RESET_REG 0x1b #define II20K_AI_CHANLIST_REG 0x80 -#define II20K_AI_CHANLIST_ONBOARD_ONLY (1 << 5) +#define II20K_AI_CHANLIST_ONBOARD_ONLY BIT(5) #define II20K_AI_CHANLIST_GAIN(x) (((x) & 0x3) << 3) -#define II20K_AI_CHANLIST_MUX_ENA (1 << 2) +#define II20K_AI_CHANLIST_MUX_ENA BIT(2) #define II20K_AI_CHANLIST_CHAN(x) (((x) & 0x3) << 0) #define II20K_AI_CHANLIST_LEN 0x80 @@ -153,9 +153,8 @@ static int ii20k_ao_insn_write(struct comedi_device *dev, s->readback[chan] = val; - /* munge data */ - val += ((s->maxdata + 1) >> 1); - val &= s->maxdata; + /* munge the offset binary data to 2's complement */ + val = comedi_offset_munge(s, val); writeb(val & 0xff, iobase + II20K_AO_LSB_REG(chan)); writeb((val >> 8) & 0xff, iobase + II20K_AO_MSB_REG(chan)); @@ -243,11 +242,8 @@ static int ii20k_ai_insn_read(struct comedi_device *dev, val = readb(iobase + II20K_AI_LSB_REG); val |= (readb(iobase + II20K_AI_MSB_REG) << 8); - /* munge two's complement data */ - val += ((s->maxdata + 1) >> 1); - val &= s->maxdata; - - data[i] = val; + /* munge the 2's complement data to offset binary */ + data[i] = comedi_offset_munge(s, val); } return insn->n; @@ -523,5 +519,5 @@ static struct comedi_driver ii20k_driver = { module_comedi_driver(ii20k_driver); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_DESCRIPTION("Comedi driver for Intelligent Instruments PCI-20001C"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/ke_counter.c b/drivers/staging/comedi/drivers/ke_counter.c index dc642edf4f65..93198abf0ee5 100644 --- a/drivers/staging/comedi/drivers/ke_counter.c +++ b/drivers/staging/comedi/drivers/ke_counter.c @@ -41,9 +41,10 @@ #define KE_MSB_REG(x) (0x0c + ((x) * 0x20)) #define KE_SIGN_REG(x) (0x10 + ((x) * 0x20)) #define KE_OSC_SEL_REG 0xf8 -#define KE_OSC_SEL_EXT (1 << 0) -#define KE_OSC_SEL_4MHZ (2 << 0) -#define KE_OSC_SEL_20MHZ (3 << 0) +#define KE_OSC_SEL_CLK(x) (((x) & 0x3) << 0) +#define KE_OSC_SEL_EXT KE_OSC_SEL_CLK(1) +#define KE_OSC_SEL_4MHZ KE_OSC_SEL_CLK(2) +#define KE_OSC_SEL_20MHZ KE_OSC_SEL_CLK(3) #define KE_DO_REG 0xfc static int ke_counter_insn_write(struct comedi_device *dev, diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c index 9ea1ba4b1b6f..3bf0caa18ab0 100644 --- a/drivers/staging/comedi/drivers/me_daq.c +++ b/drivers/staging/comedi/drivers/me_daq.c @@ -41,84 +41,63 @@ #define XILINX_DOWNLOAD_RESET 0x42 /* Xilinx registers */ -#define ME_CONTROL_1 0x0000 /* - | W */ -#define INTERRUPT_ENABLE (1<<15) -#define COUNTER_B_IRQ (1<<12) -#define COUNTER_A_IRQ (1<<11) -#define CHANLIST_READY_IRQ (1<<10) -#define EXT_IRQ (1<<9) -#define ADFIFO_HALFFULL_IRQ (1<<8) -#define SCAN_COUNT_ENABLE (1<<5) -#define SIMULTANEOUS_ENABLE (1<<4) -#define TRIGGER_FALLING_EDGE (1<<3) -#define CONTINUOUS_MODE (1<<2) -#define DISABLE_ADC (0<<0) -#define SOFTWARE_TRIGGERED_ADC (1<<0) -#define SCAN_TRIGGERED_ADC (2<<0) -#define EXT_TRIGGERED_ADC (3<<0) -#define ME_ADC_START 0x0000 /* R | - */ -#define ME_CONTROL_2 0x0002 /* - | W */ -#define ENABLE_ADFIFO (1<<10) -#define ENABLE_CHANLIST (1<<9) -#define ENABLE_PORT_B (1<<7) -#define ENABLE_PORT_A (1<<6) -#define ENABLE_COUNTER_B (1<<4) -#define ENABLE_COUNTER_A (1<<3) -#define ENABLE_DAC (1<<1) -#define BUFFERED_DAC (1<<0) -#define ME_DAC_UPDATE 0x0002 /* R | - */ -#define ME_STATUS 0x0004 /* R | - */ -#define COUNTER_B_IRQ_PENDING (1<<12) -#define COUNTER_A_IRQ_PENDING (1<<11) -#define CHANLIST_READY_IRQ_PENDING (1<<10) -#define EXT_IRQ_PENDING (1<<9) -#define ADFIFO_HALFFULL_IRQ_PENDING (1<<8) -#define ADFIFO_FULL (1<<4) -#define ADFIFO_HALFFULL (1<<3) -#define ADFIFO_EMPTY (1<<2) -#define CHANLIST_FULL (1<<1) -#define FST_ACTIVE (1<<0) -#define ME_RESET_INTERRUPT 0x0004 /* - | W */ -#define ME_DIO_PORT_A 0x0006 /* R | W */ -#define ME_DIO_PORT_B 0x0008 /* R | W */ -#define ME_TIMER_DATA_0 0x000A /* - | W */ -#define ME_TIMER_DATA_1 0x000C /* - | W */ -#define ME_TIMER_DATA_2 0x000E /* - | W */ -#define ME_CHANNEL_LIST 0x0010 /* - | W */ -#define ADC_UNIPOLAR (1<<6) -#define ADC_GAIN_0 (0<<4) -#define ADC_GAIN_1 (1<<4) -#define ADC_GAIN_2 (2<<4) -#define ADC_GAIN_3 (3<<4) -#define ME_READ_AD_FIFO 0x0010 /* R | - */ -#define ME_DAC_CONTROL 0x0012 /* - | W */ -#define DAC_UNIPOLAR_D (0<<4) -#define DAC_BIPOLAR_D (1<<4) -#define DAC_UNIPOLAR_C (0<<5) -#define DAC_BIPOLAR_C (1<<5) -#define DAC_UNIPOLAR_B (0<<6) -#define DAC_BIPOLAR_B (1<<6) -#define DAC_UNIPOLAR_A (0<<7) -#define DAC_BIPOLAR_A (1<<7) -#define DAC_GAIN_0_D (0<<8) -#define DAC_GAIN_1_D (1<<8) -#define DAC_GAIN_0_C (0<<9) -#define DAC_GAIN_1_C (1<<9) -#define DAC_GAIN_0_B (0<<10) -#define DAC_GAIN_1_B (1<<10) -#define DAC_GAIN_0_A (0<<11) -#define DAC_GAIN_1_A (1<<11) -#define ME_DAC_CONTROL_UPDATE 0x0012 /* R | - */ -#define ME_DAC_DATA_A 0x0014 /* - | W */ -#define ME_DAC_DATA_B 0x0016 /* - | W */ -#define ME_DAC_DATA_C 0x0018 /* - | W */ -#define ME_DAC_DATA_D 0x001A /* - | W */ -#define ME_COUNTER_ENDDATA_A 0x001C /* - | W */ -#define ME_COUNTER_ENDDATA_B 0x001E /* - | W */ -#define ME_COUNTER_STARTDATA_A 0x0020 /* - | W */ -#define ME_COUNTER_VALUE_A 0x0020 /* R | - */ -#define ME_COUNTER_STARTDATA_B 0x0022 /* - | W */ -#define ME_COUNTER_VALUE_B 0x0022 /* R | - */ +/* + * PCI BAR2 Memory map (dev->mmio) + */ +#define ME_CTRL1_REG 0x00 /* R (ai start) | W */ +#define ME_CTRL1_INT_ENA BIT(15) +#define ME_CTRL1_COUNTER_B_IRQ BIT(12) +#define ME_CTRL1_COUNTER_A_IRQ BIT(11) +#define ME_CTRL1_CHANLIST_READY_IRQ BIT(10) +#define ME_CTRL1_EXT_IRQ BIT(9) +#define ME_CTRL1_ADFIFO_HALFFULL_IRQ BIT(8) +#define ME_CTRL1_SCAN_COUNT_ENA BIT(5) +#define ME_CTRL1_SIMULTANEOUS_ENA BIT(4) +#define ME_CTRL1_TRIGGER_FALLING_EDGE BIT(3) +#define ME_CTRL1_CONTINUOUS_MODE BIT(2) +#define ME_CTRL1_ADC_MODE(x) (((x) & 0x3) << 0) +#define ME_CTRL1_ADC_MODE_DISABLE ME_CTRL1_ADC_MODE(0) +#define ME_CTRL1_ADC_MODE_SOFT_TRIG ME_CTRL1_ADC_MODE(1) +#define ME_CTRL1_ADC_MODE_SCAN_TRIG ME_CTRL1_ADC_MODE(2) +#define ME_CTRL1_ADC_MODE_EXT_TRIG ME_CTRL1_ADC_MODE(3) +#define ME_CTRL1_ADC_MODE_MASK ME_CTRL1_ADC_MODE(3) +#define ME_CTRL2_REG 0x02 /* R (dac update) | W */ +#define ME_CTRL2_ADFIFO_ENA BIT(10) +#define ME_CTRL2_CHANLIST_ENA BIT(9) +#define ME_CTRL2_PORT_B_ENA BIT(7) +#define ME_CTRL2_PORT_A_ENA BIT(6) +#define ME_CTRL2_COUNTER_B_ENA BIT(4) +#define ME_CTRL2_COUNTER_A_ENA BIT(3) +#define ME_CTRL2_DAC_ENA BIT(1) +#define ME_CTRL2_BUFFERED_DAC BIT(0) +#define ME_STATUS_REG 0x04 /* R | W (clears interrupts) */ +#define ME_STATUS_COUNTER_B_IRQ BIT(12) +#define ME_STATUS_COUNTER_A_IRQ BIT(11) +#define ME_STATUS_CHANLIST_READY_IRQ BIT(10) +#define ME_STATUS_EXT_IRQ BIT(9) +#define ME_STATUS_ADFIFO_HALFFULL_IRQ BIT(8) +#define ME_STATUS_ADFIFO_FULL BIT(4) +#define ME_STATUS_ADFIFO_HALFFULL BIT(3) +#define ME_STATUS_ADFIFO_EMPTY BIT(2) +#define ME_STATUS_CHANLIST_FULL BIT(1) +#define ME_STATUS_FST_ACTIVE BIT(0) +#define ME_DIO_PORT_A_REG 0x06 /* R | W */ +#define ME_DIO_PORT_B_REG 0x08 /* R | W */ +#define ME_TIMER_DATA_REG(x) (0x0a + ((x) * 2)) /* - | W */ +#define ME_AI_FIFO_REG 0x10 /* R (fifo) | W (chanlist) */ +#define ME_AI_FIFO_CHANLIST_DIFF BIT(7) +#define ME_AI_FIFO_CHANLIST_UNIPOLAR BIT(6) +#define ME_AI_FIFO_CHANLIST_GAIN(x) (((x) & 0x3) << 4) +#define ME_AI_FIFO_CHANLIST_CHAN(x) (((x) & 0xf) << 0) +#define ME_DAC_CTRL_REG 0x12 /* R (updates) | W */ +#define ME_DAC_CTRL_BIPOLAR(x) BIT(7 - ((x) & 0x3)) +#define ME_DAC_CTRL_GAIN(x) BIT(11 - ((x) & 0x3)) +#define ME_DAC_CTRL_MASK(x) (ME_DAC_CTRL_BIPOLAR(x) | \ + ME_DAC_CTRL_GAIN(x)) +#define ME_AO_DATA_REG(x) (0x14 + ((x) * 2)) /* - | W */ +#define ME_COUNTER_ENDDATA_REG(x) (0x1c + ((x) * 2)) /* - | W */ +#define ME_COUNTER_STARTDATA_REG(x) (0x20 + ((x) * 2)) /* - | W */ +#define ME_COUNTER_VALUE_REG(x) (0x20 + ((x) * 2)) /* R | - */ static const struct comedi_lrange me_ai_range = { 8, { @@ -166,9 +145,9 @@ static const struct me_board me_boards[] = { struct me_private_data { void __iomem *plx_regbase; /* PLX configuration base address */ - unsigned short control_1; /* Mirror of CONTROL_1 register */ - unsigned short control_2; /* Mirror of CONTROL_2 register */ - unsigned short dac_control; /* Mirror of the DAC_CONTROL register */ + unsigned short ctrl1; /* Mirror of CONTROL_1 register */ + unsigned short ctrl2; /* Mirror of CONTROL_2 register */ + unsigned short dac_ctrl; /* Mirror of the DAC_CONTROL register */ }; static inline void sleep(unsigned sec) @@ -196,15 +175,15 @@ static int me_dio_insn_config(struct comedi_device *dev, return ret; if (s->io_bits & 0x0000ffff) - devpriv->control_2 |= ENABLE_PORT_A; + devpriv->ctrl2 |= ME_CTRL2_PORT_A_ENA; else - devpriv->control_2 &= ~ENABLE_PORT_A; + devpriv->ctrl2 &= ~ME_CTRL2_PORT_A_ENA; if (s->io_bits & 0xffff0000) - devpriv->control_2 |= ENABLE_PORT_B; + devpriv->ctrl2 |= ME_CTRL2_PORT_B_ENA; else - devpriv->control_2 &= ~ENABLE_PORT_B; + devpriv->ctrl2 &= ~ME_CTRL2_PORT_B_ENA; - writew(devpriv->control_2, dev->mmio + ME_CONTROL_2); + writew(devpriv->ctrl2, dev->mmio + ME_CTRL2_REG); return insn->n; } @@ -214,8 +193,8 @@ static int me_dio_insn_bits(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - void __iomem *mmio_porta = dev->mmio + ME_DIO_PORT_A; - void __iomem *mmio_portb = dev->mmio + ME_DIO_PORT_B; + void __iomem *mmio_porta = dev->mmio + ME_DIO_PORT_A_REG; + void __iomem *mmio_portb = dev->mmio + ME_DIO_PORT_B_REG; unsigned int mask; unsigned int val; @@ -249,8 +228,8 @@ static int me_ai_eoc(struct comedi_device *dev, { unsigned int status; - status = readw(dev->mmio + ME_STATUS); - if ((status & 0x0004) == 0) + status = readw(dev->mmio + ME_STATUS_REG); + if ((status & ME_STATUS_ADFIFO_EMPTY) == 0) return 0; return -EBUSY; } @@ -260,57 +239,66 @@ static int me_ai_insn_read(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct me_private_data *dev_private = dev->private; + struct me_private_data *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); - unsigned int rang = CR_RANGE(insn->chanspec); + unsigned int range = CR_RANGE(insn->chanspec); unsigned int aref = CR_AREF(insn->chanspec); - unsigned short val; - int ret; + unsigned int val; + int ret = 0; + int i; - /* stop any running conversion */ - dev_private->control_1 &= 0xFFFC; - writew(dev_private->control_1, dev->mmio + ME_CONTROL_1); + /* + * For differential operation, there are only 8 input channels + * and only bipolar ranges are available. + */ + if (aref & AREF_DIFF) { + if (chan > 7 || comedi_range_is_unipolar(s, range)) + return -EINVAL; + } /* clear chanlist and ad fifo */ - dev_private->control_2 &= ~(ENABLE_ADFIFO | ENABLE_CHANLIST); - writew(dev_private->control_2, dev->mmio + ME_CONTROL_2); + devpriv->ctrl2 &= ~(ME_CTRL2_ADFIFO_ENA | ME_CTRL2_CHANLIST_ENA); + writew(devpriv->ctrl2, dev->mmio + ME_CTRL2_REG); - /* reset any pending interrupt */ - writew(0x00, dev->mmio + ME_RESET_INTERRUPT); + writew(0x00, dev->mmio + ME_STATUS_REG); /* clear interrupts */ /* enable the chanlist and ADC fifo */ - dev_private->control_2 |= (ENABLE_ADFIFO | ENABLE_CHANLIST); - writew(dev_private->control_2, dev->mmio + ME_CONTROL_2); + devpriv->ctrl2 |= (ME_CTRL2_ADFIFO_ENA | ME_CTRL2_CHANLIST_ENA); + writew(devpriv->ctrl2, dev->mmio + ME_CTRL2_REG); /* write to channel list fifo */ - val = chan & 0x0f; /* b3:b0 channel */ - val |= (rang & 0x03) << 4; /* b5:b4 gain */ - val |= (rang & 0x04) << 4; /* b6 polarity */ - val |= ((aref & AREF_DIFF) ? 0x80 : 0); /* b7 differential */ - writew(val & 0xff, dev->mmio + ME_CHANNEL_LIST); + val = ME_AI_FIFO_CHANLIST_CHAN(chan) | ME_AI_FIFO_CHANLIST_GAIN(range); + if (comedi_range_is_unipolar(s, range)) + val |= ME_AI_FIFO_CHANLIST_UNIPOLAR; + if (aref & AREF_DIFF) + val |= ME_AI_FIFO_CHANLIST_DIFF; + writew(val, dev->mmio + ME_AI_FIFO_REG); /* set ADC mode to software trigger */ - dev_private->control_1 |= SOFTWARE_TRIGGERED_ADC; - writew(dev_private->control_1, dev->mmio + ME_CONTROL_1); + devpriv->ctrl1 |= ME_CTRL1_ADC_MODE_SOFT_TRIG; + writew(devpriv->ctrl1, dev->mmio + ME_CTRL1_REG); - /* start conversion by reading from ADC_START */ - readw(dev->mmio + ME_ADC_START); + for (i = 0; i < insn->n; i++) { + /* start ai conversion */ + readw(dev->mmio + ME_CTRL1_REG); - /* wait for ADC fifo not empty flag */ - ret = comedi_timeout(dev, s, insn, me_ai_eoc, 0); - if (ret) - return ret; + /* wait for ADC fifo not empty flag */ + ret = comedi_timeout(dev, s, insn, me_ai_eoc, 0); + if (ret) + break; - /* get value from ADC fifo */ - val = readw(dev->mmio + ME_READ_AD_FIFO); - val = (val ^ 0x800) & 0x0fff; - data[0] = val; + /* get value from ADC fifo */ + val = readw(dev->mmio + ME_AI_FIFO_REG) & s->maxdata; + + /* munge 2's complement value to offset binary */ + data[i] = comedi_offset_munge(s, val); + } /* stop any running conversion */ - dev_private->control_1 &= 0xFFFC; - writew(dev_private->control_1, dev->mmio + ME_CONTROL_1); + devpriv->ctrl1 &= ~ME_CTRL1_ADC_MODE_MASK; + writew(devpriv->ctrl1, dev->mmio + ME_CTRL1_REG); - return 1; + return ret ? ret : insn->n; } static int me_ao_insn_write(struct comedi_device *dev, @@ -318,46 +306,41 @@ static int me_ao_insn_write(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - struct me_private_data *dev_private = dev->private; + struct me_private_data *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); - unsigned int rang = CR_RANGE(insn->chanspec); + unsigned int range = CR_RANGE(insn->chanspec); unsigned int val = s->readback[chan]; int i; /* Enable all DAC */ - dev_private->control_2 |= ENABLE_DAC; - writew(dev_private->control_2, dev->mmio + ME_CONTROL_2); + devpriv->ctrl2 |= ME_CTRL2_DAC_ENA; + writew(devpriv->ctrl2, dev->mmio + ME_CTRL2_REG); /* and set DAC to "buffered" mode */ - dev_private->control_2 |= BUFFERED_DAC; - writew(dev_private->control_2, dev->mmio + ME_CONTROL_2); + devpriv->ctrl2 |= ME_CTRL2_BUFFERED_DAC; + writew(devpriv->ctrl2, dev->mmio + ME_CTRL2_REG); /* Set dac-control register */ - for (i = 0; i < insn->n; i++) { - /* clear bits for this channel */ - dev_private->dac_control &= ~(0x0880 >> chan); - if (rang == 0) - dev_private->dac_control |= - ((DAC_BIPOLAR_A | DAC_GAIN_1_A) >> chan); - else if (rang == 1) - dev_private->dac_control |= - ((DAC_BIPOLAR_A | DAC_GAIN_0_A) >> chan); - } - writew(dev_private->dac_control, dev->mmio + ME_DAC_CONTROL); + devpriv->dac_ctrl &= ~ME_DAC_CTRL_MASK(chan); + if (range == 0) + devpriv->dac_ctrl |= ME_DAC_CTRL_GAIN(chan); + if (comedi_range_is_bipolar(s, range)) + devpriv->dac_ctrl |= ME_DAC_CTRL_BIPOLAR(chan); + writew(devpriv->dac_ctrl, dev->mmio + ME_DAC_CTRL_REG); /* Update dac-control register */ - readw(dev->mmio + ME_DAC_CONTROL_UPDATE); + readw(dev->mmio + ME_DAC_CTRL_REG); /* Set data register */ for (i = 0; i < insn->n; i++) { val = data[i]; - writew(val, dev->mmio + ME_DAC_DATA_A + (chan << 1)); + writew(val, dev->mmio + ME_AO_DATA_REG(chan)); } s->readback[chan] = val; /* Update dac with data registers */ - readw(dev->mmio + ME_DAC_UPDATE); + readw(dev->mmio + ME_CTRL2_REG); return insn->n; } @@ -366,13 +349,13 @@ static int me2600_xilinx_download(struct comedi_device *dev, const u8 *data, size_t size, unsigned long context) { - struct me_private_data *dev_private = dev->private; + struct me_private_data *devpriv = dev->private; unsigned int value; unsigned int file_length; unsigned int i; /* disable irq's on PLX */ - writel(0x00, dev_private->plx_regbase + PLX9052_INTCSR); + writel(0x00, devpriv->plx_regbase + PLX9052_INTCSR); /* First, make a dummy read to reset xilinx */ value = readw(dev->mmio + XILINX_DOWNLOAD_RESET); @@ -412,10 +395,10 @@ static int me2600_xilinx_download(struct comedi_device *dev, writeb(0x00, dev->mmio + 0x0); /* Test if there was an error during download -> INTB was thrown */ - value = readl(dev_private->plx_regbase + PLX9052_INTCSR); + value = readl(devpriv->plx_regbase + PLX9052_INTCSR); if (value & PLX9052_INTCSR_LI2STAT) { /* Disable interrupt */ - writel(0x00, dev_private->plx_regbase + PLX9052_INTCSR); + writel(0x00, devpriv->plx_regbase + PLX9052_INTCSR); dev_err(dev->class_dev, "Xilinx download failed\n"); return -EIO; } @@ -427,25 +410,25 @@ static int me2600_xilinx_download(struct comedi_device *dev, writel(PLX9052_INTCSR_LI1ENAB | PLX9052_INTCSR_LI1POL | PLX9052_INTCSR_PCIENAB, - dev_private->plx_regbase + PLX9052_INTCSR); + devpriv->plx_regbase + PLX9052_INTCSR); return 0; } static int me_reset(struct comedi_device *dev) { - struct me_private_data *dev_private = dev->private; + struct me_private_data *devpriv = dev->private; /* Reset board */ - writew(0x00, dev->mmio + ME_CONTROL_1); - writew(0x00, dev->mmio + ME_CONTROL_2); - writew(0x00, dev->mmio + ME_RESET_INTERRUPT); - writew(0x00, dev->mmio + ME_DAC_CONTROL); + writew(0x00, dev->mmio + ME_CTRL1_REG); + writew(0x00, dev->mmio + ME_CTRL2_REG); + writew(0x00, dev->mmio + ME_STATUS_REG); /* clear interrupts */ + writew(0x00, dev->mmio + ME_DAC_CTRL_REG); /* Save values in the board context */ - dev_private->dac_control = 0; - dev_private->control_1 = 0; - dev_private->control_2 = 0; + devpriv->dac_ctrl = 0; + devpriv->ctrl1 = 0; + devpriv->ctrl2 = 0; return 0; } @@ -455,7 +438,7 @@ static int me_auto_attach(struct comedi_device *dev, { struct pci_dev *pcidev = comedi_to_pci_dev(dev); const struct me_board *board = NULL; - struct me_private_data *dev_private; + struct me_private_data *devpriv; struct comedi_subdevice *s; int ret; @@ -466,16 +449,16 @@ static int me_auto_attach(struct comedi_device *dev, dev->board_ptr = board; dev->board_name = board->name; - dev_private = comedi_alloc_devpriv(dev, sizeof(*dev_private)); - if (!dev_private) + devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); + if (!devpriv) return -ENOMEM; ret = comedi_pci_enable(dev); if (ret) return ret; - dev_private->plx_regbase = pci_ioremap_bar(pcidev, 0); - if (!dev_private->plx_regbase) + devpriv->plx_regbase = pci_ioremap_bar(pcidev, 0); + if (!devpriv->plx_regbase) return -ENOMEM; dev->mmio = pci_ioremap_bar(pcidev, 2); @@ -498,7 +481,7 @@ static int me_auto_attach(struct comedi_device *dev, s = &dev->subdevices[0]; s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_COMMON; + s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_DIFF; s->n_chan = 16; s->maxdata = 0x0fff; s->len_chanlist = 16; @@ -537,13 +520,13 @@ static int me_auto_attach(struct comedi_device *dev, static void me_detach(struct comedi_device *dev) { - struct me_private_data *dev_private = dev->private; + struct me_private_data *devpriv = dev->private; - if (dev_private) { + if (devpriv) { if (dev->mmio) me_reset(dev); - if (dev_private->plx_regbase) - iounmap(dev_private->plx_regbase); + if (devpriv->plx_regbase) + iounmap(devpriv->plx_regbase); } comedi_pci_detach(dev); } diff --git a/drivers/staging/comedi/drivers/mf6x4.c b/drivers/staging/comedi/drivers/mf6x4.c index a675e2ef9b45..fbdf181d8ccc 100644 --- a/drivers/staging/comedi/drivers/mf6x4.c +++ b/drivers/staging/comedi/drivers/mf6x4.c @@ -31,36 +31,24 @@ #include "../comedi_pci.h" /* Registers present in BAR0 memory region */ -#define MF624_GPIOC_R 0x54 +#define MF624_GPIOC_REG 0x54 -#define MF6X4_GPIOC_EOLC /* End Of Last Conversion */ (1 << 17) -#define MF6X4_GPIOC_LDAC /* Load DACs */ (1 << 23) -#define MF6X4_GPIOC_DACEN (1 << 26) +#define MF6X4_GPIOC_EOLC BIT(17) /* End Of Last Conversion */ +#define MF6X4_GPIOC_LDAC BIT(23) /* Load DACs */ +#define MF6X4_GPIOC_DACEN BIT(26) /* BAR1 registers */ -#define MF6X4_DIN_R 0x10 -#define MF6X4_DIN_M 0xff -#define MF6X4_DOUT_R 0x10 -#define MF6X4_DOUT_M 0xff - -#define MF6X4_ADSTART_R 0x20 -#define MF6X4_ADDATA_R 0x00 -#define MF6X4_ADCTRL_R 0x00 -#define MF6X4_ADCTRL_M 0xff - -#define MF6X4_DA0_R 0x20 -#define MF6X4_DA1_R 0x22 -#define MF6X4_DA2_R 0x24 -#define MF6X4_DA3_R 0x26 -#define MF6X4_DA4_R 0x28 -#define MF6X4_DA5_R 0x2a -#define MF6X4_DA6_R 0x2c -#define MF6X4_DA7_R 0x2e -/* Map DAC cahnnel id to real HW-dependent offset value */ -#define MF6X4_DAC_R(x) (0x20 + ((x) * 2)) +#define MF6X4_ADDATA_REG 0x00 +#define MF6X4_ADCTRL_REG 0x00 +#define MF6X4_ADCTRL_CHAN(x) BIT(chan) +#define MF6X4_DIN_REG 0x10 +#define MF6X4_DIN_MASK 0xff +#define MF6X4_DOUT_REG 0x10 +#define MF6X4_ADSTART_REG 0x20 +#define MF6X4_DAC_REG(x) (0x20 + ((x) * 2)) /* BAR2 registers */ -#define MF634_GPIOC_R 0x68 +#define MF634_GPIOC_REG 0x68 enum mf6x4_boardid { BOARD_MF634, @@ -69,8 +57,8 @@ enum mf6x4_boardid { struct mf6x4_board { const char *name; - unsigned int bar_nums[3]; /* We need to keep track of the - order of BARs used by the cards */ + /* We need to keep track of the order of BARs used by the cards */ + unsigned int bar_nums[3]; }; static const struct mf6x4_board mf6x4_boards[] = { @@ -99,7 +87,7 @@ struct mf6x4_private { * for both cards however it lies in different BARs on different * offsets -- this variable makes the access easier */ - void __iomem *gpioc_R; + void __iomem *gpioc_reg; }; static int mf6x4_di_insn_bits(struct comedi_device *dev, @@ -107,7 +95,7 @@ static int mf6x4_di_insn_bits(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - data[1] = ioread16(dev->mmio + MF6X4_DIN_R) & MF6X4_DIN_M; + data[1] = ioread16(dev->mmio + MF6X4_DIN_REG) & MF6X4_DIN_MASK; return insn->n; } @@ -118,7 +106,7 @@ static int mf6x4_do_insn_bits(struct comedi_device *dev, unsigned int *data) { if (comedi_dio_update_state(s, data)) - iowrite16(s->state & MF6X4_DOUT_M, dev->mmio + MF6X4_DOUT_R); + iowrite16(s->state, dev->mmio + MF6X4_DOUT_REG); data[1] = s->state; @@ -133,7 +121,7 @@ static int mf6x4_ai_eoc(struct comedi_device *dev, struct mf6x4_private *devpriv = dev->private; unsigned int status; - status = ioread32(devpriv->gpioc_R); + status = ioread32(devpriv->gpioc_reg); if (status & MF6X4_GPIOC_EOLC) return 0; return -EBUSY; @@ -144,29 +132,30 @@ static int mf6x4_ai_insn_read(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - int chan = CR_CHAN(insn->chanspec); + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int d; int ret; int i; - int d; /* Set the ADC channel number in the scan list */ - iowrite16((1 << chan) & MF6X4_ADCTRL_M, dev->mmio + MF6X4_ADCTRL_R); + iowrite16(MF6X4_ADCTRL_CHAN(chan), dev->mmio + MF6X4_ADCTRL_REG); for (i = 0; i < insn->n; i++) { /* Trigger ADC conversion by reading ADSTART */ - ioread16(dev->mmio + MF6X4_ADSTART_R); + ioread16(dev->mmio + MF6X4_ADSTART_REG); ret = comedi_timeout(dev, s, insn, mf6x4_ai_eoc, 0); if (ret) return ret; /* Read the actual value */ - d = ioread16(dev->mmio + MF6X4_ADDATA_R); + d = ioread16(dev->mmio + MF6X4_ADDATA_REG); d &= s->maxdata; - data[i] = d; + /* munge the 2's complement data to offset binary */ + data[i] = comedi_offset_munge(s, d); } - iowrite16(0x0, dev->mmio + MF6X4_ADCTRL_R); + iowrite16(0x0, dev->mmio + MF6X4_ADCTRL_REG); return insn->n; } @@ -179,17 +168,17 @@ static int mf6x4_ao_insn_write(struct comedi_device *dev, struct mf6x4_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); unsigned int val = s->readback[chan]; - uint32_t gpioc; + unsigned int gpioc; int i; /* Enable instantaneous update of converters outputs + Enable DACs */ - gpioc = ioread32(devpriv->gpioc_R); + gpioc = ioread32(devpriv->gpioc_reg); iowrite32((gpioc & ~MF6X4_GPIOC_LDAC) | MF6X4_GPIOC_DACEN, - devpriv->gpioc_R); + devpriv->gpioc_reg); for (i = 0; i < insn->n; i++) { val = data[i]; - iowrite16(val, dev->mmio + MF6X4_DAC_R(chan)); + iowrite16(val, dev->mmio + MF6X4_DAC_REG(chan)); } s->readback[chan] = val; @@ -233,53 +222,53 @@ static int mf6x4_auto_attach(struct comedi_device *dev, unsigned long context) return -ENODEV; if (board == &mf6x4_boards[BOARD_MF634]) - devpriv->gpioc_R = devpriv->bar2_mem + MF634_GPIOC_R; + devpriv->gpioc_reg = devpriv->bar2_mem + MF634_GPIOC_REG; else - devpriv->gpioc_R = devpriv->bar0_mem + MF624_GPIOC_R; + devpriv->gpioc_reg = devpriv->bar0_mem + MF624_GPIOC_REG; ret = comedi_alloc_subdevices(dev, 4); if (ret) return ret; - /* ADC */ + /* Analog Input subdevice */ s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_GROUND; - s->n_chan = 8; - s->maxdata = 0x3fff; /* 14 bits ADC */ - s->range_table = &range_bipolar10; - s->insn_read = mf6x4_ai_insn_read; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = 8; + s->maxdata = 0x3fff; + s->range_table = &range_bipolar10; + s->insn_read = mf6x4_ai_insn_read; - /* DAC */ + /* Analog Output subdevice */ s = &dev->subdevices[1]; - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 8; - s->maxdata = 0x3fff; /* 14 bits DAC */ - s->range_table = &range_bipolar10; - s->insn_write = mf6x4_ao_insn_write; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 0x3fff; + s->range_table = &range_bipolar10; + s->insn_write = mf6x4_ao_insn_write; ret = comedi_alloc_subdev_readback(s); if (ret) return ret; - /* DIN */ + /* Digital Input subdevice */ s = &dev->subdevices[2]; - 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 = mf6x4_di_insn_bits; + 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 = mf6x4_di_insn_bits; - /* DOUT */ + /* Digital Output subdevice */ s = &dev->subdevices[3]; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 8; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_bits = mf6x4_do_insn_bits; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = mf6x4_do_insn_bits; return 0; } diff --git a/drivers/staging/comedi/drivers/mpc624.c b/drivers/staging/comedi/drivers/mpc624.c index 0207b8edfcb4..826e4399c87e 100644 --- a/drivers/staging/comedi/drivers/mpc624.c +++ b/drivers/staging/comedi/drivers/mpc624.c @@ -1,55 +1,56 @@ /* - comedi/drivers/mpc624.c - Hardware driver for a Micro/sys inc. MPC-624 PC/104 board + * mpc624.c + * Hardware driver for a Micro/sys inc. MPC-624 PC/104 board + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000 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 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. -*/ /* -Driver: mpc624 -Description: Micro/sys MPC-624 PC/104 board -Devices: [Micro/sys] MPC-624 (mpc624) -Author: Stanislaw Raczynski -Updated: Thu, 15 Sep 2005 12:01:18 +0200 -Status: working - - The Micro/sys MPC-624 board is based on the LTC2440 24-bit sigma-delta - ADC chip. - - Subdevices supported by the driver: - - Analog In: supported - - Digital I/O: not supported - - LEDs: not supported - - EEPROM: not supported - -Configuration Options: - [0] - I/O base address - [1] - conversion rate - Conversion rate RMS noise Effective Number Of Bits - 0 3.52kHz 23uV 17 - 1 1.76kHz 3.5uV 20 - 2 880Hz 2uV 21.3 - 3 440Hz 1.4uV 21.8 - 4 220Hz 1uV 22.4 - 5 110Hz 750uV 22.9 - 6 55Hz 510nV 23.4 - 7 27.5Hz 375nV 24 - 8 13.75Hz 250nV 24.4 - 9 6.875Hz 200nV 24.6 - [2] - voltage range - 0 -1.01V .. +1.01V - 1 -10.1V .. +10.1V -*/ + * Driver: mpc624 + * Description: Micro/sys MPC-624 PC/104 board + * Devices: [Micro/sys] MPC-624 (mpc624) + * Author: Stanislaw Raczynski + * Updated: Thu, 15 Sep 2005 12:01:18 +0200 + * Status: working + * + * The Micro/sys MPC-624 board is based on the LTC2440 24-bit sigma-delta + * ADC chip. + * + * Subdevices supported by the driver: + * - Analog In: supported + * - Digital I/O: not supported + * - LEDs: not supported + * - EEPROM: not supported + * + * Configuration Options: + * [0] - I/O base address + * [1] - conversion rate + * Conversion rate RMS noise Effective Number Of Bits + * 0 3.52kHz 23uV 17 + * 1 1.76kHz 3.5uV 20 + * 2 880Hz 2uV 21.3 + * 3 440Hz 1.4uV 21.8 + * 4 220Hz 1uV 22.4 + * 5 110Hz 750uV 22.9 + * 6 55Hz 510nV 23.4 + * 7 27.5Hz 375nV 24 + * 8 13.75Hz 250nV 24.4 + * 9 6.875Hz 200nV 24.6 + * [2] - voltage range + * 0 -1.01V .. +1.01V + * 1 -10.1V .. +10.1V + */ #include #include "../comedidev.h" @@ -58,65 +59,41 @@ Configuration Options: /* Offsets of different ports */ #define MPC624_MASTER_CONTROL 0 /* not used */ -#define MPC624_GNMUXCH 1 /* Gain, Mux, Channel of ADC */ -#define MPC624_ADC 2 /* read/write to/from ADC */ -#define MPC624_EE 3 /* read/write to/from serial EEPROM via I2C */ -#define MPC624_LEDS 4 /* write to LEDs */ -#define MPC624_DIO 5 /* read/write to/from digital I/O ports */ -#define MPC624_IRQ_MASK 6 /* IRQ masking enable/disable */ +#define MPC624_GNMUXCH 1 /* Gain, Mux, Channel of ADC */ +#define MPC624_ADC 2 /* read/write to/from ADC */ +#define MPC624_EE 3 /* read/write to/from serial EEPROM via I2C */ +#define MPC624_LEDS 4 /* write to LEDs */ +#define MPC624_DIO 5 /* read/write to/from digital I/O ports */ +#define MPC624_IRQ_MASK 6 /* IRQ masking enable/disable */ /* Register bits' names */ -#define MPC624_ADBUSY (1<<5) -#define MPC624_ADSDO (1<<4) -#define MPC624_ADFO (1<<3) -#define MPC624_ADCS (1<<2) -#define MPC624_ADSCK (1<<1) -#define MPC624_ADSDI (1<<0) - -/* SDI Speed/Resolution Programming bits */ -#define MPC624_OSR4 (1<<31) -#define MPC624_OSR3 (1<<30) -#define MPC624_OSR2 (1<<29) -#define MPC624_OSR1 (1<<28) -#define MPC624_OSR0 (1<<27) +#define MPC624_ADBUSY BIT(5) +#define MPC624_ADSDO BIT(4) +#define MPC624_ADFO BIT(3) +#define MPC624_ADCS BIT(2) +#define MPC624_ADSCK BIT(1) +#define MPC624_ADSDI BIT(0) /* 32-bit output value bits' names */ -#define MPC624_EOC_BIT (1<<31) -#define MPC624_DMY_BIT (1<<30) -#define MPC624_SGN_BIT (1<<29) +#define MPC624_EOC_BIT BIT(31) +#define MPC624_DMY_BIT BIT(30) +#define MPC624_SGN_BIT BIT(29) -/* Conversion speeds */ -/* OSR4 OSR3 OSR2 OSR1 OSR0 Conversion rate RMS noise ENOB^ - * X 0 0 0 1 3.52kHz 23uV 17 - * X 0 0 1 0 1.76kHz 3.5uV 20 - * X 0 0 1 1 880Hz 2uV 21.3 - * X 0 1 0 0 440Hz 1.4uV 21.8 - * X 0 1 0 1 220Hz 1uV 22.4 - * X 0 1 1 0 110Hz 750uV 22.9 - * X 0 1 1 1 55Hz 510nV 23.4 - * X 1 0 0 0 27.5Hz 375nV 24 - * X 1 0 0 1 13.75Hz 250nV 24.4 - * X 1 1 1 1 6.875Hz 200nV 24.6 - * - * ^ - Effective Number Of Bits - */ +/* SDI Speed/Resolution Programming bits */ +#define MPC624_OSR(x) (((x) & 0x1f) << 27) +#define MPC624_SPEED_3_52_KHZ MPC624_OSR(0x11) +#define MPC624_SPEED_1_76_KHZ MPC624_OSR(0x12) +#define MPC624_SPEED_880_HZ MPC624_OSR(0x13) +#define MPC624_SPEED_440_HZ MPC624_OSR(0x14) +#define MPC624_SPEED_220_HZ MPC624_OSR(0x15) +#define MPC624_SPEED_110_HZ MPC624_OSR(0x16) +#define MPC624_SPEED_55_HZ MPC624_OSR(0x17) +#define MPC624_SPEED_27_5_HZ MPC624_OSR(0x18) +#define MPC624_SPEED_13_75_HZ MPC624_OSR(0x19) +#define MPC624_SPEED_6_875_HZ MPC624_OSR(0x1f) -#define MPC624_SPEED_3_52_kHz (MPC624_OSR4 | MPC624_OSR0) -#define MPC624_SPEED_1_76_kHz (MPC624_OSR4 | MPC624_OSR1) -#define MPC624_SPEED_880_Hz (MPC624_OSR4 | MPC624_OSR1 | MPC624_OSR0) -#define MPC624_SPEED_440_Hz (MPC624_OSR4 | MPC624_OSR2) -#define MPC624_SPEED_220_Hz (MPC624_OSR4 | MPC624_OSR2 | MPC624_OSR0) -#define MPC624_SPEED_110_Hz (MPC624_OSR4 | MPC624_OSR2 | MPC624_OSR1) -#define MPC624_SPEED_55_Hz \ - (MPC624_OSR4 | MPC624_OSR2 | MPC624_OSR1 | MPC624_OSR0) -#define MPC624_SPEED_27_5_Hz (MPC624_OSR4 | MPC624_OSR3) -#define MPC624_SPEED_13_75_Hz (MPC624_OSR4 | MPC624_OSR3 | MPC624_OSR0) -#define MPC624_SPEED_6_875_Hz \ - (MPC624_OSR4 | MPC624_OSR3 | MPC624_OSR2 | MPC624_OSR1 | MPC624_OSR0) -/* -------------------------------------------------------------------------- */ struct mpc624_private { - /* set by mpc624_attach() from driver's parameters */ - unsigned long int ulConvertionRate; + unsigned int ai_speed; }; /* -------------------------------------------------------------------------- */ @@ -138,6 +115,85 @@ static const struct comedi_lrange range_mpc624_bipolar10 = { } }; +static unsigned int mpc624_ai_get_sample(struct comedi_device *dev, + struct comedi_subdevice *s) +{ + struct mpc624_private *devpriv = dev->private; + unsigned int data_out = devpriv->ai_speed; + unsigned int data_in = 0; + unsigned int bit; + int i; + + /* Start reading data */ + udelay(1); + for (i = 0; i < 32; i++) { + /* Set the clock low */ + outb(0, dev->iobase + MPC624_ADC); + udelay(1); + + /* Set the ADSDI line for the next bit (send to MPC624) */ + bit = (data_out & BIT(31)) ? MPC624_ADSDI : 0; + outb(bit, dev->iobase + MPC624_ADC); + udelay(1); + + /* Set the clock high */ + outb(MPC624_ADSCK | bit, dev->iobase + MPC624_ADC); + udelay(1); + + /* Read ADSDO on high clock (receive from MPC624) */ + data_in <<= 1; + data_in |= (inb(dev->iobase + MPC624_ADC) & MPC624_ADSDO) >> 4; + udelay(1); + + data_out <<= 1; + } + + /* + * Received 32-bit long value consist of: + * 31: EOC - (End Of Transmission) bit - should be 0 + * 30: DMY - (Dummy) bit - should be 0 + * 29: SIG - (Sign) bit - 1 if positive, 0 if negative + * 28: MSB - (Most Significant Bit) - the first bit of the + * conversion result + * .... + * 05: LSB - (Least Significant Bit)- the last bit of the + * conversion result + * 04-00: sub-LSB - sub-LSBs are basically noise, but when + * averaged properly, they can increase + * conversion precision up to 29 bits; + * they can be discarded without loss of + * resolution. + */ + if (data_in & MPC624_EOC_BIT) + dev_dbg(dev->class_dev, "EOC bit is set!"); + if (data_in & MPC624_DMY_BIT) + dev_dbg(dev->class_dev, "DMY bit is set!"); + + if (data_in & MPC624_SGN_BIT) { + /* + * Voltage is positive + * + * comedi operates on unsigned numbers, so mask off EOC + * and DMY and don't clear the SGN bit + */ + data_in &= 0x3fffffff; + } else { + /* + * The voltage is negative + * + * data_in contains a number in 30-bit two's complement + * code and we must deal with it + */ + data_in |= MPC624_SGN_BIT; + data_in = ~data_in; + data_in += 1; + /* clear EOC and DMY bits */ + data_in &= ~(MPC624_EOC_BIT | MPC624_DMY_BIT); + data_in = 0x20000000 - data_in; + } + return data_in; +} + static int mpc624_ai_eoc(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -151,14 +207,13 @@ static int mpc624_ai_eoc(struct comedi_device *dev, return -EBUSY; } -static int mpc624_ai_rinsn(struct comedi_device *dev, - struct comedi_subdevice *s, struct comedi_insn *insn, - unsigned int *data) +static int mpc624_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - struct mpc624_private *devpriv = dev->private; - int n, i; - unsigned long int data_in, data_out; int ret; + int i; /* * WARNING: @@ -166,7 +221,7 @@ static int mpc624_ai_rinsn(struct comedi_device *dev, */ outb(insn->chanspec, dev->iobase + MPC624_GNMUXCH); - for (n = 0; n < insn->n; n++) { + for (i = 0; i < insn->n; i++) { /* Trigger the conversion */ outb(MPC624_ADSCK, dev->iobase + MPC624_ADC); udelay(1); @@ -180,93 +235,10 @@ static int mpc624_ai_rinsn(struct comedi_device *dev, if (ret) return ret; - /* Start reading data */ - data_in = 0; - data_out = devpriv->ulConvertionRate; - udelay(1); - for (i = 0; i < 32; i++) { - /* Set the clock low */ - outb(0, dev->iobase + MPC624_ADC); - udelay(1); - - if (data_out & (1 << 31)) { /* the next bit is a 1 */ - /* Set the ADSDI line (send to MPC624) */ - outb(MPC624_ADSDI, dev->iobase + MPC624_ADC); - udelay(1); - /* Set the clock high */ - outb(MPC624_ADSCK | MPC624_ADSDI, - dev->iobase + MPC624_ADC); - } else { /* the next bit is a 0 */ - - /* Set the ADSDI line (send to MPC624) */ - outb(0, dev->iobase + MPC624_ADC); - udelay(1); - /* Set the clock high */ - outb(MPC624_ADSCK, dev->iobase + MPC624_ADC); - } - /* Read ADSDO on high clock (receive from MPC624) */ - udelay(1); - data_in <<= 1; - data_in |= - (inb(dev->iobase + MPC624_ADC) & MPC624_ADSDO) >> 4; - udelay(1); - - data_out <<= 1; - } - - /* - * Received 32-bit long value consist of: - * 31: EOC - - * (End Of Transmission) bit - should be 0 - * 30: DMY - * (Dummy) bit - should be 0 - * 29: SIG - * (Sign) bit- 1 if the voltage is positive, - * 0 if negative - * 28: MSB - * (Most Significant Bit) - the first bit of - * the conversion result - * .... - * 05: LSB - * (Least Significant Bit)- the last bit of the - * conversion result - * 04-00: sub-LSB - * - sub-LSBs are basically noise, but when - * averaged properly, they can increase conversion - * precision up to 29 bits; they can be discarded - * without loss of resolution. - */ - - if (data_in & MPC624_EOC_BIT) - dev_dbg(dev->class_dev, - "EOC bit is set (data_in=%lu)!", data_in); - if (data_in & MPC624_DMY_BIT) - dev_dbg(dev->class_dev, - "DMY bit is set (data_in=%lu)!", data_in); - if (data_in & MPC624_SGN_BIT) { /* Volatge is positive */ - /* - * comedi operates on unsigned numbers, so mask off EOC - * and DMY and don't clear the SGN bit - */ - data_in &= 0x3FFFFFFF; - data[n] = data_in; - } else { /* The voltage is negative */ - /* - * data_in contains a number in 30-bit two's complement - * code and we must deal with it - */ - data_in |= MPC624_SGN_BIT; - data_in = ~data_in; - data_in += 1; - data_in &= ~(MPC624_EOC_BIT | MPC624_DMY_BIT); - /* clear EOC and DMY bits */ - data_in = 0x20000000 - data_in; - data[n] = data_in; - } + data[i] = mpc624_ai_get_sample(dev, s); } - /* Return the number of samples read/written */ - return n; + return insn->n; } static int mpc624_attach(struct comedi_device *dev, struct comedi_devconfig *it) @@ -285,61 +257,52 @@ static int mpc624_attach(struct comedi_device *dev, struct comedi_devconfig *it) switch (it->options[1]) { case 0: - devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz; + devpriv->ai_speed = MPC624_SPEED_3_52_KHZ; break; case 1: - devpriv->ulConvertionRate = MPC624_SPEED_1_76_kHz; + devpriv->ai_speed = MPC624_SPEED_1_76_KHZ; break; case 2: - devpriv->ulConvertionRate = MPC624_SPEED_880_Hz; + devpriv->ai_speed = MPC624_SPEED_880_HZ; break; case 3: - devpriv->ulConvertionRate = MPC624_SPEED_440_Hz; + devpriv->ai_speed = MPC624_SPEED_440_HZ; break; case 4: - devpriv->ulConvertionRate = MPC624_SPEED_220_Hz; + devpriv->ai_speed = MPC624_SPEED_220_HZ; break; case 5: - devpriv->ulConvertionRate = MPC624_SPEED_110_Hz; + devpriv->ai_speed = MPC624_SPEED_110_HZ; break; case 6: - devpriv->ulConvertionRate = MPC624_SPEED_55_Hz; + devpriv->ai_speed = MPC624_SPEED_55_HZ; break; case 7: - devpriv->ulConvertionRate = MPC624_SPEED_27_5_Hz; + devpriv->ai_speed = MPC624_SPEED_27_5_HZ; break; case 8: - devpriv->ulConvertionRate = MPC624_SPEED_13_75_Hz; + devpriv->ai_speed = MPC624_SPEED_13_75_HZ; break; case 9: - devpriv->ulConvertionRate = MPC624_SPEED_6_875_Hz; + devpriv->ai_speed = MPC624_SPEED_6_875_HZ; break; default: - devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz; + devpriv->ai_speed = MPC624_SPEED_3_52_KHZ; } ret = comedi_alloc_subdevices(dev, 1); if (ret) return ret; + /* Analog Input subdevice */ s = &dev->subdevices[0]; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_DIFF; - s->n_chan = 8; - switch (it->options[1]) { - default: - s->maxdata = 0x3FFFFFFF; - } - - switch (it->options[1]) { - case 0: - s->range_table = &range_mpc624_bipolar1; - break; - default: - s->range_table = &range_mpc624_bipolar10; - } - s->len_chanlist = 1; - s->insn_read = mpc624_ai_rinsn; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_DIFF; + s->n_chan = 4; + s->maxdata = 0x3fffffff; + s->range_table = (it->options[1] == 0) ? &range_mpc624_bipolar1 + : &range_mpc624_bipolar10; + s->insn_read = mpc624_ai_insn_read; return 0; } @@ -353,5 +316,5 @@ static struct comedi_driver mpc624_driver = { module_comedi_driver(mpc624_driver); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_DESCRIPTION("Comedi driver for Micro/sys MPC-624 PC/104 board"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/multiq3.c b/drivers/staging/comedi/drivers/multiq3.c index 8471219210b6..b5a26f7b4332 100644 --- a/drivers/staging/comedi/drivers/multiq3.c +++ b/drivers/staging/comedi/drivers/multiq3.c @@ -1,79 +1,91 @@ /* - comedi/drivers/multiq3.c - Hardware driver for Quanser Consulting MultiQ-3 board - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 1999 Anders Blomdell - - 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. + * multiq3.c + * Hardware driver for Quanser Consulting MultiQ-3 board + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1999 Anders Blomdell + * + * 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: multiq3 -Description: Quanser Consulting MultiQ-3 -Author: Anders Blomdell -Status: works -Devices: [Quanser Consulting] MultiQ-3 (multiq3) -*/ +/* + * Driver: multiq3 + * Description: Quanser Consulting MultiQ-3 + * Devices: [Quanser Consulting] MultiQ-3 (multiq3) + * Author: Anders Blomdell + * Status: works + * + * Configuration Options: + * [0] - I/O port base address + * [1] - IRQ (not used) + * [2] - Number of optional encoder chips installed on board + * 0 = none + * 1 = 2 inputs (Model -2E) + * 2 = 4 inputs (Model -4E) + * 3 = 6 inputs (Model -6E) + * 4 = 8 inputs (Model -8E) + */ #include -#include + #include "../comedidev.h" /* - * MULTIQ-3 port offsets + * Register map */ -#define MULTIQ3_DIGIN_PORT 0 -#define MULTIQ3_DIGOUT_PORT 0 -#define MULTIQ3_DAC_DATA 2 -#define MULTIQ3_AD_DATA 4 -#define MULTIQ3_AD_CS 4 -#define MULTIQ3_STATUS 6 -#define MULTIQ3_CONTROL 6 -#define MULTIQ3_CLK_DATA 8 -#define MULTIQ3_ENC_DATA 12 -#define MULTIQ3_ENC_CONTROL 14 +#define MULTIQ3_DI_REG 0x00 +#define MULTIQ3_DO_REG 0x00 +#define MULTIQ3_AO_REG 0x02 +#define MULTIQ3_AI_REG 0x04 +#define MULTIQ3_AI_CONV_REG 0x04 +#define MULTIQ3_STATUS_REG 0x06 +#define MULTIQ3_STATUS_EOC BIT(3) +#define MULTIQ3_STATUS_EOC_I BIT(4) +#define MULTIQ3_CTRL_REG 0x06 +#define MULTIQ3_CTRL_AO_CHAN(x) (((x) & 0x7) << 0) +#define MULTIQ3_CTRL_RC(x) (((x) & 0x3) << 0) +#define MULTIQ3_CTRL_AI_CHAN(x) (((x) & 0x7) << 3) +#define MULTIQ3_CTRL_E_CHAN(x) (((x) & 0x7) << 3) +#define MULTIQ3_CTRL_EN BIT(6) +#define MULTIQ3_CTRL_AZ BIT(7) +#define MULTIQ3_CTRL_CAL BIT(8) +#define MULTIQ3_CTRL_SH BIT(9) +#define MULTIQ3_CTRL_CLK BIT(10) +#define MULTIQ3_CTRL_LD (3 << 11) +#define MULTIQ3_CLK_REG 0x08 +#define MULTIQ3_ENC_DATA_REG 0x0c +#define MULTIQ3_ENC_CTRL_REG 0x0e /* - * flags for CONTROL register + * Encoder chip commands (from the programming manual) */ -#define MULTIQ3_AD_MUX_EN 0x0040 -#define MULTIQ3_AD_AUTOZ 0x0080 -#define MULTIQ3_AD_AUTOCAL 0x0100 -#define MULTIQ3_AD_SH 0x0200 -#define MULTIQ3_AD_CLOCK_4M 0x0400 -#define MULTIQ3_DA_LOAD 0x1800 +#define MULTIQ3_CLOCK_DATA 0x00 /* FCK frequency divider */ +#define MULTIQ3_CLOCK_SETUP 0x18 /* xfer PR0 to PSC */ +#define MULTIQ3_INPUT_SETUP 0x41 /* enable inputs A and B */ +#define MULTIQ3_QUAD_X4 0x38 /* quadrature */ +#define MULTIQ3_BP_RESET 0x01 /* reset byte pointer */ +#define MULTIQ3_CNTR_RESET 0x02 /* reset counter */ +#define MULTIQ3_TRSFRPR_CTR 0x08 /* xfre preset reg to counter */ +#define MULTIQ3_TRSFRCNTR_OL 0x10 /* xfer CNTR to OL (x and y) */ +#define MULTIQ3_EFLAG_RESET 0x06 /* reset E bit of flag reg */ -#define MULTIQ3_CONTROL_MUST 0x0600 - -/* - * flags for STATUS register - */ -#define MULTIQ3_STATUS_EOC 0x008 -#define MULTIQ3_STATUS_EOC_I 0x010 - -/* - * flags for encoder control - */ -#define MULTIQ3_CLOCK_DATA 0x00 -#define MULTIQ3_CLOCK_SETUP 0x18 -#define MULTIQ3_INPUT_SETUP 0x41 -#define MULTIQ3_QUAD_X4 0x38 -#define MULTIQ3_BP_RESET 0x01 -#define MULTIQ3_CNTR_RESET 0x02 -#define MULTIQ3_TRSFRPR_CTR 0x08 -#define MULTIQ3_TRSFRCNTR_OL 0x10 -#define MULTIQ3_EFLAG_RESET 0x06 - -#define MULTIQ3_TIMEOUT 30 +static void multiq3_set_ctrl(struct comedi_device *dev, unsigned int bits) +{ + /* + * According to the programming manual, the SH and CLK bits should + * be kept high at all times. + */ + outw(MULTIQ3_CTRL_SH | MULTIQ3_CTRL_CLK | bits, + dev->iobase + MULTIQ3_CTRL_REG); +} static int multiq3_ai_status(struct comedi_device *dev, struct comedi_subdevice *s, @@ -82,7 +94,7 @@ static int multiq3_ai_status(struct comedi_device *dev, { unsigned int status; - status = inw(dev->iobase + MULTIQ3_STATUS); + status = inw(dev->iobase + MULTIQ3_STATUS_REG); if (status & context) return 0; return -EBUSY; @@ -90,36 +102,39 @@ static int multiq3_ai_status(struct comedi_device *dev, static int multiq3_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) { - int n; - int chan; - unsigned int hi, lo; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int val; int ret; + int i; - chan = CR_CHAN(insn->chanspec); - outw(MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan << 3), - dev->iobase + MULTIQ3_CONTROL); + multiq3_set_ctrl(dev, MULTIQ3_CTRL_EN | MULTIQ3_CTRL_AI_CHAN(chan)); ret = comedi_timeout(dev, s, insn, multiq3_ai_status, MULTIQ3_STATUS_EOC); if (ret) return ret; - for (n = 0; n < insn->n; n++) { - outw(0, dev->iobase + MULTIQ3_AD_CS); + for (i = 0; i < insn->n; i++) { + outw(0, dev->iobase + MULTIQ3_AI_CONV_REG); ret = comedi_timeout(dev, s, insn, multiq3_ai_status, MULTIQ3_STATUS_EOC_I); if (ret) return ret; - hi = inb(dev->iobase + MULTIQ3_AD_CS); - lo = inb(dev->iobase + MULTIQ3_AD_CS); - data[n] = (((hi << 8) | lo) + 0x1000) & 0x1fff; + /* get a 16-bit sample; mask it to the subdevice resolution */ + val = inb(dev->iobase + MULTIQ3_AI_REG) << 8; + val |= inb(dev->iobase + MULTIQ3_AI_REG); + val &= s->maxdata; + + /* munge the 2's complement value to offset binary */ + data[i] = comedi_offset_munge(s, val); } - return n; + return insn->n; } static int multiq3_ao_insn_write(struct comedi_device *dev, @@ -133,10 +148,10 @@ static int multiq3_ao_insn_write(struct comedi_device *dev, for (i = 0; i < insn->n; i++) { val = data[i]; - outw(MULTIQ3_CONTROL_MUST | MULTIQ3_DA_LOAD | chan, - dev->iobase + MULTIQ3_CONTROL); - outw(val, dev->iobase + MULTIQ3_DAC_DATA); - outw(MULTIQ3_CONTROL_MUST, dev->iobase + MULTIQ3_CONTROL); + multiq3_set_ctrl(dev, MULTIQ3_CTRL_LD | + MULTIQ3_CTRL_AO_CHAN(chan)); + outw(val, dev->iobase + MULTIQ3_AO_REG); + multiq3_set_ctrl(dev, 0); } s->readback[chan] = val; @@ -147,7 +162,7 @@ static int multiq3_di_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - data[1] = inw(dev->iobase + MULTIQ3_DIGIN_PORT); + data[1] = inw(dev->iobase + MULTIQ3_DI_REG); return insn->n; } @@ -158,7 +173,7 @@ static int multiq3_do_insn_bits(struct comedi_device *dev, unsigned int *data) { if (comedi_dio_update_state(s, data)) - outw(s->state, dev->iobase + MULTIQ3_DIGOUT_PORT); + outw(s->state, dev->iobase + MULTIQ3_DO_REG); data[1] = s->state; @@ -170,41 +185,76 @@ static int multiq3_encoder_insn_read(struct comedi_device *dev, struct comedi_insn *insn, unsigned int *data) { - int chan = CR_CHAN(insn->chanspec); - int control = MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan << 3); - int value; - int n; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int val; + int i; - for (n = 0; n < insn->n; n++) { - outw(control, dev->iobase + MULTIQ3_CONTROL); - outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_TRSFRCNTR_OL, dev->iobase + MULTIQ3_ENC_CONTROL); - value = inb(dev->iobase + MULTIQ3_ENC_DATA); - value |= (inb(dev->iobase + MULTIQ3_ENC_DATA) << 8); - value |= (inb(dev->iobase + MULTIQ3_ENC_DATA) << 16); - data[n] = (value + 0x800000) & 0xffffff; + for (i = 0; i < insn->n; i++) { + /* select encoder channel */ + multiq3_set_ctrl(dev, MULTIQ3_CTRL_EN | + MULTIQ3_CTRL_E_CHAN(chan)); + + /* reset the byte pointer */ + outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG); + + /* latch the data */ + outb(MULTIQ3_TRSFRCNTR_OL, dev->iobase + MULTIQ3_ENC_CTRL_REG); + + /* read the 24-bit encoder data (lsb/mid/msb) */ + val = inb(dev->iobase + MULTIQ3_ENC_DATA_REG); + val |= (inb(dev->iobase + MULTIQ3_ENC_DATA_REG) << 8); + val |= (inb(dev->iobase + MULTIQ3_ENC_DATA_REG) << 16); + + /* + * Munge the data so that the reset value is in the middle + * of the maxdata range, i.e.: + * + * real value comedi value + * 0xffffff 0x7fffff 1 negative count + * 0x000000 0x800000 reset value + * 0x000001 0x800001 1 positive count + * + * It's possible for the 24-bit counter to overflow but it + * would normally take _quite_ a few turns. A 2000 line + * encoder in quadrature results in 8000 counts/rev. So about + * 1048 turns in either direction can be measured without + * an overflow. + */ + data[i] = (val + ((s->maxdata + 1) >> 1)) & s->maxdata; } - return n; + return insn->n; } -static void encoder_reset(struct comedi_device *dev) +static void multiq3_encoder_reset(struct comedi_device *dev, + unsigned int chan) { - struct comedi_subdevice *s = &dev->subdevices[4]; - int chan; + multiq3_set_ctrl(dev, MULTIQ3_CTRL_EN | MULTIQ3_CTRL_E_CHAN(chan)); + outb(MULTIQ3_EFLAG_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG); + outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG); + outb(MULTIQ3_CLOCK_DATA, dev->iobase + MULTIQ3_ENC_DATA_REG); + outb(MULTIQ3_CLOCK_SETUP, dev->iobase + MULTIQ3_ENC_CTRL_REG); + outb(MULTIQ3_INPUT_SETUP, dev->iobase + MULTIQ3_ENC_CTRL_REG); + outb(MULTIQ3_QUAD_X4, dev->iobase + MULTIQ3_ENC_CTRL_REG); + outb(MULTIQ3_CNTR_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG); +} - for (chan = 0; chan < s->n_chan; chan++) { - int control = - MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan << 3); - outw(control, dev->iobase + MULTIQ3_CONTROL); - outb(MULTIQ3_EFLAG_RESET, dev->iobase + MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_CLOCK_DATA, dev->iobase + MULTIQ3_ENC_DATA); - outb(MULTIQ3_CLOCK_SETUP, dev->iobase + MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_INPUT_SETUP, dev->iobase + MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_QUAD_X4, dev->iobase + MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_CNTR_RESET, dev->iobase + MULTIQ3_ENC_CONTROL); +static int multiq3_encoder_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int chan = CR_CHAN(insn->chanspec); + + switch (data[0]) { + case INSN_CONFIG_RESET: + multiq3_encoder_reset(dev, chan); + break; + default: + return -EINVAL; } + + return insn->n; } static int multiq3_attach(struct comedi_device *dev, @@ -212,6 +262,7 @@ static int multiq3_attach(struct comedi_device *dev, { struct comedi_subdevice *s; int ret; + int i; ret = comedi_request_region(dev, it->options[0], 0x10); if (ret) @@ -221,57 +272,58 @@ static int multiq3_attach(struct comedi_device *dev, if (ret) return ret; + /* Analog Input subdevice */ s = &dev->subdevices[0]; - /* ai subdevice */ - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_GROUND; - s->n_chan = 8; - s->insn_read = multiq3_ai_insn_read; - s->maxdata = 0x1fff; - s->range_table = &range_bipolar5; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = 8; + s->maxdata = 0x1fff; + s->range_table = &range_bipolar5; + s->insn_read = multiq3_ai_insn_read; + /* Analog Output subdevice */ s = &dev->subdevices[1]; - /* ao subdevice */ - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 8; - s->maxdata = 0xfff; - s->range_table = &range_bipolar5; - s->insn_write = multiq3_ao_insn_write; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 0x0fff; + s->range_table = &range_bipolar5; + s->insn_write = multiq3_ao_insn_write; ret = comedi_alloc_subdev_readback(s); if (ret) return ret; + /* Digital Input subdevice */ s = &dev->subdevices[2]; - /* di subdevice */ - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->n_chan = 16; - s->insn_bits = multiq3_di_insn_bits; - s->maxdata = 1; - s->range_table = &range_digital; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 16; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = multiq3_di_insn_bits; + /* Digital Output subdevice */ s = &dev->subdevices[3]; - /* do subdevice */ - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 16; - s->insn_bits = multiq3_do_insn_bits; - s->maxdata = 1; - s->range_table = &range_digital; - s->state = 0; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 16; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = multiq3_do_insn_bits; + /* Encoder (Counter) subdevice */ s = &dev->subdevices[4]; - /* encoder (counter) subdevice */ - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE | SDF_LSAMPL; - s->n_chan = it->options[2] * 2; - s->insn_read = multiq3_encoder_insn_read; - s->maxdata = 0xffffff; - s->range_table = &range_unknown; + s->type = COMEDI_SUBD_COUNTER; + s->subdev_flags = SDF_READABLE | SDF_LSAMPL; + s->n_chan = it->options[2] * 2; + s->maxdata = 0x00ffffff; + s->range_table = &range_unknown; + s->insn_read = multiq3_encoder_insn_read; + s->insn_config = multiq3_encoder_insn_config; - encoder_reset(dev); + for (i = 0; i < s->n_chan; i++) + multiq3_encoder_reset(dev, i); return 0; } @@ -285,5 +337,5 @@ static struct comedi_driver multiq3_driver = { module_comedi_driver(multiq3_driver); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_DESCRIPTION("Comedi driver for Quanser Consulting MultiQ-3 board"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c index c20c51bef3e7..b74e44ec521a 100644 --- a/drivers/staging/comedi/drivers/ni_tio.c +++ b/drivers/staging/comedi/drivers/ni_tio.c @@ -167,15 +167,15 @@ static inline unsigned GI_HW_ARM_SEL_MASK(enum ni_gpct_variant variant) } } -static int ni_tio_has_gate2_registers(const struct ni_gpct_device *counter_dev) +static bool ni_tio_has_gate2_registers(const struct ni_gpct_device *counter_dev) { switch (counter_dev->variant) { case ni_gpct_variant_e_series: default: - return 0; + return false; case ni_gpct_variant_m_series: case ni_gpct_variant_660x: - return 1; + return true; } } diff --git a/drivers/staging/comedi/drivers/ni_tiocmd.c b/drivers/staging/comedi/drivers/ni_tiocmd.c index 9b124b09e914..437f723bb34d 100644 --- a/drivers/staging/comedi/drivers/ni_tiocmd.c +++ b/drivers/staging/comedi/drivers/ni_tiocmd.c @@ -157,12 +157,6 @@ static int ni_tio_output_cmd(struct comedi_subdevice *s) dev_err(counter->counter_dev->dev->class_dev, "output commands not yet implemented.\n"); return -ENOTSUPP; - - counter->mite_chan->dir = COMEDI_OUTPUT; - mite_prep_dma(counter->mite_chan, 32, 32); - ni_tio_configure_dma(counter, true, false); - mite_dma_arm(counter->mite_chan); - return ni_tio_arm(counter, 1, NI_GPCT_ARM_IMMEDIATE); } static int ni_tio_cmd_setup(struct comedi_subdevice *s) diff --git a/drivers/staging/comedi/drivers/ni_usb6501.c b/drivers/staging/comedi/drivers/ni_usb6501.c index 88de8da3eff3..95b537a8ecdb 100644 --- a/drivers/staging/comedi/drivers/ni_usb6501.c +++ b/drivers/staging/comedi/drivers/ni_usb6501.c @@ -166,7 +166,7 @@ enum commands { struct ni6501_private { struct usb_endpoint_descriptor *ep_rx; struct usb_endpoint_descriptor *ep_tx; - struct semaphore sem; + struct mutex mut; u8 *usb_rx_buf; u8 *usb_tx_buf; }; @@ -183,7 +183,7 @@ static int ni6501_port_command(struct comedi_device *dev, int command, if (command != SET_PORT_DIR && !bitmap) return -EINVAL; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); switch (command) { case READ_PORT: @@ -248,7 +248,7 @@ static int ni6501_port_command(struct comedi_device *dev, int command, ret = -EINVAL; } end: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -265,7 +265,7 @@ static int ni6501_counter_command(struct comedi_device *dev, int command, if ((command == READ_COUNTER || command == WRITE_COUNTER) && !val) return -EINVAL; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); switch (command) { case START_COUNTER: @@ -338,7 +338,7 @@ static int ni6501_counter_command(struct comedi_device *dev, int command, ret = -EINVAL; } end: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -535,7 +535,7 @@ static int ni6501_auto_attach(struct comedi_device *dev, if (ret) return ret; - sema_init(&devpriv->sem, 1); + mutex_init(&devpriv->mut); usb_set_intfdata(intf, devpriv); ret = comedi_alloc_subdevices(dev, 2); @@ -573,14 +573,14 @@ static void ni6501_detach(struct comedi_device *dev) if (!devpriv) return; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); usb_set_intfdata(intf, NULL); kfree(devpriv->usb_rx_buf); kfree(devpriv->usb_tx_buf); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); } static struct comedi_driver ni6501_driver = { diff --git a/drivers/staging/comedi/drivers/pcl711.c b/drivers/staging/comedi/drivers/pcl711.c index cfc3a627d0ca..3774daa9d661 100644 --- a/drivers/staging/comedi/drivers/pcl711.c +++ b/drivers/staging/comedi/drivers/pcl711.c @@ -49,7 +49,7 @@ #define PCL711_TIMER_BASE 0x00 #define PCL711_AI_LSB_REG 0x04 #define PCL711_AI_MSB_REG 0x05 -#define PCL711_AI_MSB_DRDY (1 << 4) +#define PCL711_AI_MSB_DRDY BIT(4) #define PCL711_AO_LSB_REG(x) (0x04 + ((x) * 2)) #define PCL711_AO_MSB_REG(x) (0x05 + ((x) * 2)) #define PCL711_DI_LSB_REG 0x06 @@ -60,16 +60,17 @@ #define PCL711_AI_GAIN(x) (((x) & 0xf) << 0) #define PCL711_MUX_REG 0x0a #define PCL711_MUX_CHAN(x) (((x) & 0xf) << 0) -#define PCL711_MUX_CS0 (1 << 4) -#define PCL711_MUX_CS1 (1 << 5) +#define PCL711_MUX_CS0 BIT(4) +#define PCL711_MUX_CS1 BIT(5) #define PCL711_MUX_DIFF (PCL711_MUX_CS0 | PCL711_MUX_CS1) #define PCL711_MODE_REG 0x0b -#define PCL711_MODE_DEFAULT (0 << 0) -#define PCL711_MODE_SOFTTRIG (1 << 0) -#define PCL711_MODE_EXT (2 << 0) -#define PCL711_MODE_EXT_IRQ (3 << 0) -#define PCL711_MODE_PACER (4 << 0) -#define PCL711_MODE_PACER_IRQ (6 << 0) +#define PCL711_MODE(x) (((x) & 0x7) << 0) +#define PCL711_MODE_DEFAULT PCL711_MODE(0) +#define PCL711_MODE_SOFTTRIG PCL711_MODE(1) +#define PCL711_MODE_EXT PCL711_MODE(2) +#define PCL711_MODE_EXT_IRQ PCL711_MODE(3) +#define PCL711_MODE_PACER PCL711_MODE(4) +#define PCL711_MODE_PACER_IRQ PCL711_MODE(6) #define PCL711_MODE_IRQ(x) (((x) & 0x7) << 4) #define PCL711_SOFTTRIG_REG 0x0c #define PCL711_SOFTTRIG (0 << 0) /* any value will work */ diff --git a/drivers/staging/comedi/drivers/pcl812.c b/drivers/staging/comedi/drivers/pcl812.c index 48f6cdf440b9..9c75065dd26a 100644 --- a/drivers/staging/comedi/drivers/pcl812.c +++ b/drivers/staging/comedi/drivers/pcl812.c @@ -119,40 +119,30 @@ #include "comedi_isadma.h" #include "comedi_8254.h" -/* hardware types of the cards */ -#define boardPCL812PG 0 /* and ACL-8112PG */ -#define boardPCL813B 1 -#define boardPCL812 2 -#define boardPCL813 3 -#define boardISO813 5 -#define boardACL8113 6 -#define boardACL8112 7 /* ACL-8112DG/HG, A-822PGL/PGH, A-823PGL/PGH */ -#define boardACL8216 8 /* and ICP DAS A-826PG */ -#define boardA821 9 /* PGH, PGL, PGL/NDA versions */ - /* * Register I/O map */ #define PCL812_TIMER_BASE 0x00 #define PCL812_AI_LSB_REG 0x04 #define PCL812_AI_MSB_REG 0x05 -#define PCL812_AI_MSB_DRDY (1 << 4) +#define PCL812_AI_MSB_DRDY BIT(4) #define PCL812_AO_LSB_REG(x) (0x04 + ((x) * 2)) #define PCL812_AO_MSB_REG(x) (0x05 + ((x) * 2)) #define PCL812_DI_LSB_REG 0x06 #define PCL812_DI_MSB_REG 0x07 #define PCL812_STATUS_REG 0x08 -#define PCL812_STATUS_DRDY (1 << 5) +#define PCL812_STATUS_DRDY BIT(5) #define PCL812_RANGE_REG 0x09 #define PCL812_MUX_REG 0x0a #define PCL812_MUX_CHAN(x) ((x) << 0) -#define PCL812_MUX_CS0 (1 << 4) -#define PCL812_MUX_CS1 (1 << 5) +#define PCL812_MUX_CS0 BIT(4) +#define PCL812_MUX_CS1 BIT(5) #define PCL812_CTRL_REG 0x0b -#define PCL812_CTRL_DISABLE_TRIG (0 << 0) -#define PCL812_CTRL_SOFT_TRIG (1 << 0) -#define PCL812_CTRL_PACER_DMA_TRIG (2 << 0) -#define PCL812_CTRL_PACER_EOC_TRIG (6 << 0) +#define PCL812_CTRL_TRIG(x) (((x) & 0x7) << 0) +#define PCL812_CTRL_DISABLE_TRIG PCL812_CTRL_TRIG(0) +#define PCL812_CTRL_SOFT_TRIG PCL812_CTRL_TRIG(1) +#define PCL812_CTRL_PACER_DMA_TRIG PCL812_CTRL_TRIG(2) +#define PCL812_CTRL_PACER_EOC_TRIG PCL812_CTRL_TRIG(6) #define PCL812_SOFTTRIG_REG 0x0c #define PCL812_DO_LSB_REG 0x0d #define PCL812_DO_MSB_REG 0x0e @@ -327,14 +317,26 @@ static const struct comedi_lrange range_a821pgh_ai = { } }; +enum pcl812_boardtype { + BOARD_PCL812PG = 0, /* and ACL-8112PG */ + BOARD_PCL813B = 1, + BOARD_PCL812 = 2, + BOARD_PCL813 = 3, + BOARD_ISO813 = 5, + BOARD_ACL8113 = 6, + BOARD_ACL8112 = 7, /* ACL-8112DG/HG, A-822PGL/PGH, A-823PGL/PGH */ + BOARD_ACL8216 = 8, /* and ICP DAS A-826PG */ + BOARD_A821 = 9, /* PGH, PGL, PGL/NDA versions */ +}; + struct pcl812_board { const char *name; - int board_type; + enum pcl812_boardtype board_type; int n_aichan; int n_aochan; unsigned int ai_ns_min; const struct comedi_lrange *rangelist_ai; - unsigned int IRQbits; + unsigned int irq_bits; unsigned int has_dma:1; unsigned int has_16bit_ai:1; unsigned int has_mpc508_mux:1; @@ -344,161 +346,161 @@ struct pcl812_board { static const struct pcl812_board boardtypes[] = { { .name = "pcl812", - .board_type = boardPCL812, + .board_type = BOARD_PCL812, .n_aichan = 16, .n_aochan = 2, .ai_ns_min = 33000, .rangelist_ai = &range_bipolar10, - .IRQbits = 0xdcfc, + .irq_bits = 0xdcfc, .has_dma = 1, .has_dio = 1, }, { .name = "pcl812pg", - .board_type = boardPCL812PG, + .board_type = BOARD_PCL812PG, .n_aichan = 16, .n_aochan = 2, .ai_ns_min = 33000, .rangelist_ai = &range_pcl812pg_ai, - .IRQbits = 0xdcfc, + .irq_bits = 0xdcfc, .has_dma = 1, .has_dio = 1, }, { .name = "acl8112pg", - .board_type = boardPCL812PG, + .board_type = BOARD_PCL812PG, .n_aichan = 16, .n_aochan = 2, .ai_ns_min = 10000, .rangelist_ai = &range_pcl812pg_ai, - .IRQbits = 0xdcfc, + .irq_bits = 0xdcfc, .has_dma = 1, .has_dio = 1, }, { .name = "acl8112dg", - .board_type = boardACL8112, + .board_type = BOARD_ACL8112, .n_aichan = 16, /* 8 differential */ .n_aochan = 2, .ai_ns_min = 10000, .rangelist_ai = &range_acl8112dg_ai, - .IRQbits = 0xdcfc, + .irq_bits = 0xdcfc, .has_dma = 1, .has_mpc508_mux = 1, .has_dio = 1, }, { .name = "acl8112hg", - .board_type = boardACL8112, + .board_type = BOARD_ACL8112, .n_aichan = 16, /* 8 differential */ .n_aochan = 2, .ai_ns_min = 10000, .rangelist_ai = &range_acl8112hg_ai, - .IRQbits = 0xdcfc, + .irq_bits = 0xdcfc, .has_dma = 1, .has_mpc508_mux = 1, .has_dio = 1, }, { .name = "a821pgl", - .board_type = boardA821, + .board_type = BOARD_A821, .n_aichan = 16, /* 8 differential */ .n_aochan = 1, .ai_ns_min = 10000, .rangelist_ai = &range_pcl813b_ai, - .IRQbits = 0x000c, + .irq_bits = 0x000c, .has_dio = 1, }, { .name = "a821pglnda", - .board_type = boardA821, + .board_type = BOARD_A821, .n_aichan = 16, /* 8 differential */ .ai_ns_min = 10000, .rangelist_ai = &range_pcl813b_ai, - .IRQbits = 0x000c, + .irq_bits = 0x000c, }, { .name = "a821pgh", - .board_type = boardA821, + .board_type = BOARD_A821, .n_aichan = 16, /* 8 differential */ .n_aochan = 1, .ai_ns_min = 10000, .rangelist_ai = &range_a821pgh_ai, - .IRQbits = 0x000c, + .irq_bits = 0x000c, .has_dio = 1, }, { .name = "a822pgl", - .board_type = boardACL8112, + .board_type = BOARD_ACL8112, .n_aichan = 16, /* 8 differential */ .n_aochan = 2, .ai_ns_min = 10000, .rangelist_ai = &range_acl8112dg_ai, - .IRQbits = 0xdcfc, + .irq_bits = 0xdcfc, .has_dma = 1, .has_dio = 1, }, { .name = "a822pgh", - .board_type = boardACL8112, + .board_type = BOARD_ACL8112, .n_aichan = 16, /* 8 differential */ .n_aochan = 2, .ai_ns_min = 10000, .rangelist_ai = &range_acl8112hg_ai, - .IRQbits = 0xdcfc, + .irq_bits = 0xdcfc, .has_dma = 1, .has_dio = 1, }, { .name = "a823pgl", - .board_type = boardACL8112, + .board_type = BOARD_ACL8112, .n_aichan = 16, /* 8 differential */ .n_aochan = 2, .ai_ns_min = 8000, .rangelist_ai = &range_acl8112dg_ai, - .IRQbits = 0xdcfc, + .irq_bits = 0xdcfc, .has_dma = 1, .has_dio = 1, }, { .name = "a823pgh", - .board_type = boardACL8112, + .board_type = BOARD_ACL8112, .n_aichan = 16, /* 8 differential */ .n_aochan = 2, .ai_ns_min = 8000, .rangelist_ai = &range_acl8112hg_ai, - .IRQbits = 0xdcfc, + .irq_bits = 0xdcfc, .has_dma = 1, .has_dio = 1, }, { .name = "pcl813", - .board_type = boardPCL813, + .board_type = BOARD_PCL813, .n_aichan = 32, .rangelist_ai = &range_pcl813b_ai, }, { .name = "pcl813b", - .board_type = boardPCL813B, + .board_type = BOARD_PCL813B, .n_aichan = 32, .rangelist_ai = &range_pcl813b_ai, }, { .name = "acl8113", - .board_type = boardACL8113, + .board_type = BOARD_ACL8113, .n_aichan = 32, .rangelist_ai = &range_acl8113_1_ai, }, { .name = "iso813", - .board_type = boardISO813, + .board_type = BOARD_ISO813, .n_aichan = 32, .rangelist_ai = &range_iso813_1_ai, }, { .name = "acl8216", - .board_type = boardACL8216, + .board_type = BOARD_ACL8216, .n_aichan = 16, /* 8 differential */ .n_aochan = 2, .ai_ns_min = 10000, .rangelist_ai = &range_pcl813b2_ai, - .IRQbits = 0xdcfc, + .irq_bits = 0xdcfc, .has_dma = 1, .has_16bit_ai = 1, .has_mpc508_mux = 1, .has_dio = 1, }, { .name = "a826pg", - .board_type = boardACL8216, + .board_type = BOARD_ACL8216, .n_aichan = 16, /* 8 differential */ .n_aochan = 2, .ai_ns_min = 10000, .rangelist_ai = &range_pcl813b2_ai, - .IRQbits = 0xdcfc, + .irq_bits = 0xdcfc, .has_dma = 1, .has_16bit_ai = 1, .has_dio = 1, @@ -1017,16 +1019,14 @@ static void pcl812_set_ai_range_table(struct comedi_device *dev, const struct pcl812_board *board = dev->board_ptr; struct pcl812_private *devpriv = dev->private; - /* default to the range table from the boardinfo */ - s->range_table = board->rangelist_ai; - - /* now check the user config option based on the boardtype */ switch (board->board_type) { - case boardPCL812PG: + case BOARD_PCL812PG: if (it->options[4] == 1) s->range_table = &range_pcl812pg2_ai; + else + s->range_table = board->rangelist_ai; break; - case boardPCL812: + case BOARD_PCL812: switch (it->options[4]) { case 0: s->range_table = &range_bipolar10; @@ -1051,11 +1051,13 @@ static void pcl812_set_ai_range_table(struct comedi_device *dev, break; } break; - case boardPCL813B: + case BOARD_PCL813B: if (it->options[1] == 1) s->range_table = &range_pcl813b2_ai; + else + s->range_table = board->rangelist_ai; break; - case boardISO813: + case BOARD_ISO813: switch (it->options[1]) { case 0: s->range_table = &range_iso813_1_ai; @@ -1076,7 +1078,7 @@ static void pcl812_set_ai_range_table(struct comedi_device *dev, break; } break; - case boardACL8113: + case BOARD_ACL8113: switch (it->options[1]) { case 0: s->range_table = &range_acl8113_1_ai; @@ -1097,6 +1099,9 @@ static void pcl812_set_ai_range_table(struct comedi_device *dev, break; } break; + default: + s->range_table = board->rangelist_ai; + break; } } @@ -1138,14 +1143,14 @@ static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it) if (ret) return ret; - if (board->IRQbits) { + if (board->irq_bits) { dev->pacer = comedi_8254_init(dev->iobase + PCL812_TIMER_BASE, I8254_OSC_BASE_2MHZ, I8254_IO8, 0); if (!dev->pacer) return -ENOMEM; - if ((1 << it->options[1]) & board->IRQbits) { + if ((1 << it->options[1]) & board->irq_bits) { ret = request_irq(it->options[1], pcl812_interrupt, 0, dev->board_name, dev); if (ret == 0) @@ -1159,15 +1164,17 @@ static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it) /* differential analog inputs? */ switch (board->board_type) { - case boardA821: + case BOARD_A821: if (it->options[2] == 1) devpriv->use_diff = 1; break; - case boardACL8112: - case boardACL8216: + case BOARD_ACL8112: + case BOARD_ACL8216: if (it->options[4] == 1) devpriv->use_diff = 1; break; + default: + break; } n_subdevices = 1; /* all boardtypes have analog inputs */ @@ -1220,20 +1227,31 @@ static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it) s->subdev_flags = SDF_WRITABLE | SDF_GROUND; s->n_chan = board->n_aochan; s->maxdata = 0xfff; - s->range_table = &range_unipolar5; switch (board->board_type) { - case boardA821: + case BOARD_A821: if (it->options[3] == 1) s->range_table = &range_unipolar10; + else + s->range_table = &range_unipolar5; break; - case boardPCL812: - case boardACL8112: - case boardPCL812PG: - case boardACL8216: - if (it->options[5] == 1) + case BOARD_PCL812: + case BOARD_ACL8112: + case BOARD_PCL812PG: + case BOARD_ACL8216: + switch (it->options[5]) { + case 1: s->range_table = &range_unipolar10; - if (it->options[5] == 2) + break; + case 2: s->range_table = &range_unknown; + break; + default: + s->range_table = &range_unipolar5; + break; + } + break; + default: + s->range_table = &range_unipolar5; break; } s->insn_write = pcl812_ao_insn_write; @@ -1268,23 +1286,23 @@ static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it) } switch (board->board_type) { - case boardACL8216: - case boardPCL812PG: - case boardPCL812: - case boardACL8112: + case BOARD_ACL8216: + case BOARD_PCL812PG: + case BOARD_PCL812: + case BOARD_ACL8112: devpriv->max_812_ai_mode0_rangewait = 1; if (it->options[3] > 0) /* we use external trigger */ devpriv->use_ext_trg = 1; break; - case boardA821: + case BOARD_A821: devpriv->max_812_ai_mode0_rangewait = 1; devpriv->mode_reg_int = (dev->irq << 4) & 0xf0; break; - case boardPCL813B: - case boardPCL813: - case boardISO813: - case boardACL8113: + case BOARD_PCL813B: + case BOARD_PCL813: + case BOARD_ISO813: + case BOARD_ACL8113: /* maybe there must by greatest timeout */ devpriv->max_812_ai_mode0_rangewait = 5; break; diff --git a/drivers/staging/comedi/drivers/pcl816.c b/drivers/staging/comedi/drivers/pcl816.c index a353d1b155bb..c00a71f538ef 100644 --- a/drivers/staging/comedi/drivers/pcl816.c +++ b/drivers/staging/comedi/drivers/pcl816.c @@ -1,36 +1,33 @@ /* - comedi/drivers/pcl816.c + * pcl816.c + * Comedi driver for Advantech PCL-816 cards + * + * Author: Juan Grigera + * based on pcl818 by Michal Dobes and bits of pcl812 + */ - Author: Juan Grigera - based on pcl818 by Michal Dobes and bits of pcl812 - - hardware driver for Advantech cards: - card: PCL-816, PCL814B - driver: pcl816 -*/ /* -Driver: pcl816 -Description: Advantech PCL-816 cards, PCL-814 -Author: Juan Grigera -Devices: [Advantech] PCL-816 (pcl816), PCL-814B (pcl814b) -Status: works -Updated: Tue, 2 Apr 2002 23:15:21 -0800 - -PCL 816 and 814B have 16 SE/DIFF ADCs, 16 DACs, 16 DI and 16 DO. -Differences are at resolution (16 vs 12 bits). - -The driver support AI command mode, other subdevices not written. - -Analog output and digital input and output are not supported. - -Configuration Options: - [0] - IO Base - [1] - IRQ (0=disable, 2, 3, 4, 5, 6, 7) - [2] - DMA (0=disable, 1, 3) - [3] - 0, 10=10MHz clock for 8254 - 1= 1MHz clock for 8254 - -*/ + * Driver: pcl816 + * Description: Advantech PCL-816 cards, PCL-814 + * Devices: [Advantech] PCL-816 (pcl816), PCL-814B (pcl814b) + * Author: Juan Grigera + * Status: works + * Updated: Tue, 2 Apr 2002 23:15:21 -0800 + * + * PCL 816 and 814B have 16 SE/DIFF ADCs, 16 DACs, 16 DI and 16 DO. + * Differences are at resolution (16 vs 12 bits). + * + * The driver support AI command mode, other subdevices not written. + * + * Analog output and digital input and output are not supported. + * + * Configuration Options: + * [0] - IO Base + * [1] - IRQ (0=disable, 2, 3, 4, 5, 6, 7) + * [2] - DMA (0=disable, 1, 3) + * [3] - 0, 10=10MHz clock for 8254 + * 1= 1MHz clock for 8254 + */ #include #include @@ -56,25 +53,20 @@ Configuration Options: #define PCL816_MUX_REG 0x0b #define PCL816_MUX_SCAN(_first, _last) (((_last) << 4) | (_first)) #define PCL816_CTRL_REG 0x0c -#define PCL816_CTRL_DISABLE_TRIG (0 << 0) -#define PCL816_CTRL_SOFT_TRIG (1 << 0) -#define PCL816_CTRL_PACER_TRIG (1 << 1) -#define PCL816_CTRL_EXT_TRIG (1 << 2) -#define PCL816_CTRL_POE (1 << 3) -#define PCL816_CTRL_DMAEN (1 << 4) -#define PCL816_CTRL_INTEN (1 << 5) -#define PCL816_CTRL_DMASRC_SLOT0 (0 << 6) -#define PCL816_CTRL_DMASRC_SLOT1 (1 << 6) -#define PCL816_CTRL_DMASRC_SLOT2 (2 << 6) +#define PCL816_CTRL_SOFT_TRIG BIT(0) +#define PCL816_CTRL_PACER_TRIG BIT(1) +#define PCL816_CTRL_EXT_TRIG BIT(2) +#define PCL816_CTRL_POE BIT(3) +#define PCL816_CTRL_DMAEN BIT(4) +#define PCL816_CTRL_INTEN BIT(5) +#define PCL816_CTRL_DMASRC_SLOT(x) (((x) & 0x3) << 6) #define PCL816_STATUS_REG 0x0d #define PCL816_STATUS_NEXT_CHAN_MASK (0xf << 0) -#define PCL816_STATUS_INTSRC_MASK (3 << 4) -#define PCL816_STATUS_INTSRC_SLOT0 (0 << 4) -#define PCL816_STATUS_INTSRC_SLOT1 (1 << 4) -#define PCL816_STATUS_INTSRC_SLOT2 (2 << 4) -#define PCL816_STATUS_INTSRC_DMA (3 << 4) -#define PCL816_STATUS_INTACT (1 << 6) -#define PCL816_STATUS_DRDY (1 << 7) +#define PCL816_STATUS_INTSRC_SLOT(x) (((x) & 0x3) << 4) +#define PCL816_STATUS_INTSRC_DMA PCL816_STATUS_INTSRC_SLOT(3) +#define PCL816_STATUS_INTSRC_MASK PCL816_STATUS_INTSRC_SLOT(3) +#define PCL816_STATUS_INTACT BIT(6) +#define PCL816_STATUS_DRDY BIT(7) #define MAGIC_DMA_WORD 0x5a5a @@ -94,7 +86,6 @@ static const struct comedi_lrange range_pcl816 = { struct pcl816_board { const char *name; int ai_maxdata; - int ao_maxdata; int ai_chanlist; }; @@ -102,12 +93,10 @@ static const struct pcl816_board boardtypes[] = { { .name = "pcl816", .ai_maxdata = 0xffff, - .ao_maxdata = 0xffff, .ai_chanlist = 1024, }, { .name = "pcl814b", .ai_maxdata = 0x3fff, - .ao_maxdata = 0x3fff, .ai_chanlist = 1024, }, }; @@ -443,7 +432,8 @@ static int pcl816_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) comedi_8254_update_divisors(dev->pacer); comedi_8254_pacer_enable(dev->pacer, 1, 2, true); - ctrl = PCL816_CTRL_INTEN | PCL816_CTRL_DMAEN | PCL816_CTRL_DMASRC_SLOT0; + ctrl = PCL816_CTRL_INTEN | PCL816_CTRL_DMAEN | + PCL816_CTRL_DMASRC_SLOT(0); if (cmd->convert_src == TRIG_TIMER) ctrl |= PCL816_CTRL_PACER_TRIG; else /* TRIG_EXT */ @@ -497,7 +487,7 @@ static int pcl816_ai_cancel(struct comedi_device *dev, if (!devpriv->ai_cmd_running) return 0; - outb(PCL816_CTRL_DISABLE_TRIG, dev->iobase + PCL816_CTRL_REG); + outb(0, dev->iobase + PCL816_CTRL_REG); pcl816_ai_clear_eoc(dev); comedi_8254_pacer_enable(dev->pacer, 1, 2, false); @@ -533,7 +523,7 @@ static int pcl816_ai_insn_read(struct comedi_device *dev, data[i] = pcl816_ai_get_sample(dev, s); } - outb(PCL816_CTRL_DISABLE_TRIG, dev->iobase + PCL816_CTRL_REG); + outb(0, dev->iobase + PCL816_CTRL_REG); pcl816_ai_clear_eoc(dev); return ret ? ret : insn->n; @@ -567,7 +557,7 @@ static int pcl816_do_insn_bits(struct comedi_device *dev, static void pcl816_reset(struct comedi_device *dev) { - outb(PCL816_CTRL_DISABLE_TRIG, dev->iobase + PCL816_CTRL_REG); + outb(0, dev->iobase + PCL816_CTRL_REG); pcl816_ai_set_chan_range(dev, 0, 0); pcl816_ai_clear_eoc(dev); @@ -652,16 +642,9 @@ static int pcl816_attach(struct comedi_device *dev, struct comedi_devconfig *it) s->cancel = pcl816_ai_cancel; } - /* Analog OUtput subdevice */ - s = &dev->subdevices[2]; + /* Piggyback Slot1 subdevice */ + s = &dev->subdevices[1]; s->type = COMEDI_SUBD_UNUSED; -#if 0 - subdevs[1] = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE | SDF_GROUND; - s->n_chan = 1; - s->maxdata = board->ao_maxdata; - s->range_table = &range_pcl816; -#endif /* Digital Input subdevice */ s = &dev->subdevices[2]; diff --git a/drivers/staging/comedi/drivers/pcl818.c b/drivers/staging/comedi/drivers/pcl818.c index e1bdde977302..5aeed44dff70 100644 --- a/drivers/staging/comedi/drivers/pcl818.c +++ b/drivers/staging/comedi/drivers/pcl818.c @@ -102,15 +102,6 @@ #include "comedi_isadma.h" #include "comedi_8254.h" -/* boards constants */ - -#define boardPCL818L 0 -#define boardPCL818H 1 -#define boardPCL818HD 2 -#define boardPCL818HG 3 -#define boardPCL818 4 -#define boardPCL718 5 - /* * Register I/O map */ @@ -124,23 +115,22 @@ #define PCL818_AO_MSB_REG(x) (0x05 + ((x) * 2)) #define PCL818_STATUS_REG 0x08 #define PCL818_STATUS_NEXT_CHAN_MASK (0xf << 0) -#define PCL818_STATUS_INT (1 << 4) -#define PCL818_STATUS_MUX (1 << 5) -#define PCL818_STATUS_UNI (1 << 6) -#define PCL818_STATUS_EOC (1 << 7) +#define PCL818_STATUS_INT BIT(4) +#define PCL818_STATUS_MUX BIT(5) +#define PCL818_STATUS_UNI BIT(6) +#define PCL818_STATUS_EOC BIT(7) #define PCL818_CTRL_REG 0x09 -#define PCL818_CTRL_DISABLE_TRIG (0 << 0) -#define PCL818_CTRL_SOFT_TRIG (1 << 0) -#define PCL818_CTRL_EXT_TRIG (2 << 0) -#define PCL818_CTRL_PACER_TRIG (3 << 0) -#define PCL818_CTRL_DMAE (1 << 2) +#define PCL818_CTRL_TRIG(x) (((x) & 0x3) << 0) +#define PCL818_CTRL_DISABLE_TRIG PCL818_CTRL_TRIG(0) +#define PCL818_CTRL_SOFT_TRIG PCL818_CTRL_TRIG(1) +#define PCL818_CTRL_EXT_TRIG PCL818_CTRL_TRIG(2) +#define PCL818_CTRL_PACER_TRIG PCL818_CTRL_TRIG(3) +#define PCL818_CTRL_DMAE BIT(2) #define PCL818_CTRL_IRQ(x) ((x) << 4) -#define PCL818_CTRL_INTE (1 << 7) +#define PCL818_CTRL_INTE BIT(7) #define PCL818_CNTENABLE_REG 0x0a -#define PCL818_CNTENABLE_PACER_ENA (0 << 0) -#define PCL818_CNTENABLE_PACER_TRIG0 (1 << 0) -#define PCL818_CNTENABLE_CNT0_EXT_CLK (0 << 1) -#define PCL818_CNTENABLE_CNT0_INT_CLK (1 << 1) +#define PCL818_CNTENABLE_PACER_TRIG0 BIT(0) +#define PCL818_CNTENABLE_CNT0_INT_CLK BIT(1) /* 0=ext clk */ #define PCL818_DO_DI_MSB_REG 0x0b #define PCL818_TIMER_BASE 0x0c @@ -740,7 +730,7 @@ static int pcl818_ai_cmd(struct comedi_device *dev, else ctrl |= PCL818_CTRL_EXT_TRIG; - outb(PCL818_CNTENABLE_PACER_ENA, dev->iobase + PCL818_CNTENABLE_REG); + outb(0, dev->iobase + PCL818_CNTENABLE_REG); if (dma) { /* setup and enable dma for the first buffer */ @@ -902,7 +892,7 @@ static void pcl818_reset(struct comedi_device *dev) pcl818_ai_set_chan_range(dev, 0, 0); /* stop pacer */ - outb(PCL818_CNTENABLE_PACER_ENA, dev->iobase + PCL818_CNTENABLE_REG); + outb(0, dev->iobase + PCL818_CNTENABLE_REG); /* set analog output channels to 0V */ for (chan = 0; chan < board->n_aochan; chan++) { diff --git a/drivers/staging/comedi/drivers/pcm3724.c b/drivers/staging/comedi/drivers/pcm3724.c index 6176dfa24801..588ae5ecec66 100644 --- a/drivers/staging/comedi/drivers/pcm3724.c +++ b/drivers/staging/comedi/drivers/pcm3724.c @@ -1,31 +1,25 @@ /* - comedi/drivers/pcm724.c + * pcm3724.c + * Comedi driver for Advantech PCM-3724 Digital I/O board + * + * Drew Csillag + */ - Drew Csillag - - hardware driver for Advantech card: - card: PCM-3724 - driver: pcm3724 - - Options for PCM-3724 - [0] - IO Base -*/ /* -Driver: pcm3724 -Description: Advantech PCM-3724 -Author: Drew Csillag -Devices: [Advantech] PCM-3724 (pcm724) -Status: tested - -This is driver for digital I/O boards PCM-3724 with 48 DIO. -It needs 8255.o for operations and only immediate mode is supported. -See the source for configuration details. - -Copy/pasted/hacked from pcm724.c -*/ -/* - * check_driver overrides: - * struct comedi_insn + * Driver: pcm3724 + * Description: Advantech PCM-3724 + * Devices: [Advantech] PCM-3724 (pcm3724) + * Author: Drew Csillag + * Status: tested + * + * This is driver for digital I/O boards PCM-3724 with 48 DIO. + * It needs 8255.o for operations and only immediate mode is supported. + * See the source for configuration details. + * + * Copy/pasted/hacked from pcm724.c + * + * Configuration Options: + * [0] - I/O port base address */ #include @@ -33,19 +27,31 @@ Copy/pasted/hacked from pcm724.c #include "8255.h" -#define BUF_C0 0x1 -#define BUF_B0 0x2 -#define BUF_A0 0x4 -#define BUF_C1 0x8 -#define BUF_B1 0x10 -#define BUF_A1 0x20 - -#define GATE_A0 0x4 -#define GATE_B0 0x2 -#define GATE_C0 0x1 -#define GATE_A1 0x20 -#define GATE_B1 0x10 -#define GATE_C1 0x8 +/* + * Register I/O Map + * + * This board has two standard 8255 devices that provide six 8-bit DIO ports + * (48 channels total). Six 74HCT245 chips (one for each port) buffer the + * I/O lines to increase driving capability. Because the 74HCT245 is a + * bidirectional, tri-state line buffer, two additional I/O ports are used + * to control the direction of data and the enable of each port. + */ +#define PCM3724_8255_0_BASE 0x00 +#define PCM3724_8255_1_BASE 0x04 +#define PCM3724_DIO_DIR_REG 0x08 +#define PCM3724_DIO_DIR_C0_OUT BIT(0) +#define PCM3724_DIO_DIR_B0_OUT BIT(1) +#define PCM3724_DIO_DIR_A0_OUT BIT(2) +#define PCM3724_DIO_DIR_C1_OUT BIT(3) +#define PCM3724_DIO_DIR_B1_OUT BIT(4) +#define PCM3724_DIO_DIR_A1_OUT BIT(5) +#define PCM3724_GATE_CTRL_REG 0x09 +#define PCM3724_GATE_CTRL_C0_ENA BIT(0) +#define PCM3724_GATE_CTRL_B0_ENA BIT(1) +#define PCM3724_GATE_CTRL_A0_ENA BIT(2) +#define PCM3724_GATE_CTRL_C1_ENA BIT(3) +#define PCM3724_GATE_CTRL_B1_ENA BIT(4) +#define PCM3724_GATE_CTRL_A1_ENA BIT(5) /* used to track configured dios */ struct priv_pcm3724 { @@ -58,21 +64,21 @@ static int compute_buffer(int config, int devno, struct comedi_subdevice *s) /* 1 in io_bits indicates output */ if (s->io_bits & 0x0000ff) { if (devno == 0) - config |= BUF_A0; + config |= PCM3724_DIO_DIR_A0_OUT; else - config |= BUF_A1; + config |= PCM3724_DIO_DIR_A1_OUT; } if (s->io_bits & 0x00ff00) { if (devno == 0) - config |= BUF_B0; + config |= PCM3724_DIO_DIR_B0_OUT; else - config |= BUF_B1; + config |= PCM3724_DIO_DIR_B1_OUT; } if (s->io_bits & 0xff0000) { if (devno == 0) - config |= BUF_C0; + config |= PCM3724_DIO_DIR_C0_OUT; else - config |= BUF_C1; + config |= PCM3724_DIO_DIR_C1_OUT; } return config; } @@ -107,7 +113,7 @@ static void do_3724_config(struct comedi_device *dev, else port_8255_cfg = dev->iobase + I8255_SIZE + I8255_CTRL_REG; - outb(buffer_config, dev->iobase + 8); /* update buffer register */ + outb(buffer_config, dev->iobase + PCM3724_DIO_DIR_REG); outb(config, port_8255_cfg); } @@ -129,24 +135,24 @@ static void enable_chan(struct comedi_device *dev, struct comedi_subdevice *s, priv->dio_2 |= mask; if (priv->dio_1 & 0xff0000) - gatecfg |= GATE_C0; + gatecfg |= PCM3724_GATE_CTRL_C0_ENA; if (priv->dio_1 & 0xff00) - gatecfg |= GATE_B0; + gatecfg |= PCM3724_GATE_CTRL_B0_ENA; if (priv->dio_1 & 0xff) - gatecfg |= GATE_A0; + gatecfg |= PCM3724_GATE_CTRL_A0_ENA; if (priv->dio_2 & 0xff0000) - gatecfg |= GATE_C1; + gatecfg |= PCM3724_GATE_CTRL_C1_ENA; if (priv->dio_2 & 0xff00) - gatecfg |= GATE_B1; + gatecfg |= PCM3724_GATE_CTRL_B1_ENA; if (priv->dio_2 & 0xff) - gatecfg |= GATE_A1; + gatecfg |= PCM3724_GATE_CTRL_A1_ENA; - outb(gatecfg, dev->iobase + 9); + outb(gatecfg, dev->iobase + PCM3724_GATE_CTRL_REG); } /* overriding the 8255 insn config */ @@ -216,5 +222,5 @@ static struct comedi_driver pcm3724_driver = { module_comedi_driver(pcm3724_driver); MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); +MODULE_DESCRIPTION("Comedi driver for Advantech PCM-3724 Digital I/O board"); MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 152cb146fc16..e9e43139157d 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -1,149 +1,153 @@ -/*====================================================================== - - comedi/drivers/quatech_daqp_cs.c - - Quatech DAQP PCMCIA data capture cards COMEDI client driver - Copyright (C) 2000, 2003 Brent Baccala - The DAQP interface code in this file is released into the public domain. - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 1998 David A. Schleef - http://www.comedi.org/ - - quatech_daqp_cs.c 1.10 - - Documentation for the DAQP PCMCIA cards can be found on Quatech's site: - - ftp://ftp.quatech.com/Manuals/daqp-208.pdf - - This manual is for both the DAQP-208 and the DAQP-308. - - What works: - - - A/D conversion - - 8 channels - - 4 gain ranges - - ground ref or differential - - single-shot and timed both supported - - D/A conversion, single-shot - - digital I/O - - What doesn't: - - - any kind of triggering - external or D/A channel 1 - - the card's optional expansion board - - the card's timer (for anything other than A/D conversion) - - D/A update modes other than immediate (i.e, timed) - - fancier timing modes - - setting card's FIFO buffer thresholds to anything but default - -======================================================================*/ +/* + * quatech_daqp_cs.c + * Quatech DAQP PCMCIA data capture cards COMEDI client driver + * Copyright (C) 2000, 2003 Brent Baccala + * The DAQP interface code in this file is released into the public domain. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1998 David A. Schleef + * http://www.comedi.org/ + * + * Documentation for the DAQP PCMCIA cards can be found on Quatech's site: + * ftp://ftp.quatech.com/Manuals/daqp-208.pdf + * + * This manual is for both the DAQP-208 and the DAQP-308. + * + * What works: + * - A/D conversion + * - 8 channels + * - 4 gain ranges + * - ground ref or differential + * - single-shot and timed both supported + * - D/A conversion, single-shot + * - digital I/O + * + * What doesn't: + * - any kind of triggering - external or D/A channel 1 + * - the card's optional expansion board + * - the card's timer (for anything other than A/D conversion) + * - D/A update modes other than immediate (i.e, timed) + * - fancier timing modes + * - setting card's FIFO buffer thresholds to anything but default + */ /* -Driver: quatech_daqp_cs -Description: Quatech DAQP PCMCIA data capture cards -Author: Brent Baccala -Status: works -Devices: [Quatech] DAQP-208 (daqp), DAQP-308 -*/ + * Driver: quatech_daqp_cs + * Description: Quatech DAQP PCMCIA data capture cards + * Devices: [Quatech] DAQP-208 (daqp), DAQP-308 + * Author: Brent Baccala + * Status: works + */ #include -#include -#include #include "../comedi_pcmcia.h" +/* + * Register I/O map + * + * The D/A and timer registers can be accessed with 16-bit or 8-bit I/O + * instructions. All other registers can only use 8-bit instructions. + * + * The FIFO and scanlist registers require two 8-bit instructions to + * access the 16-bit data. Data is transferred LSB then MSB. + */ +#define DAQP_AI_FIFO_REG 0x00 + +#define DAQP_SCANLIST_REG 0x01 +#define DAQP_SCANLIST_DIFFERENTIAL BIT(14) +#define DAQP_SCANLIST_GAIN(x) (((x) & 0x3) << 12) +#define DAQP_SCANLIST_CHANNEL(x) (((x) & 0xf) << 8) +#define DAQP_SCANLIST_START BIT(7) +#define DAQP_SCANLIST_EXT_GAIN(x) (((x) & 0x3) << 4) +#define DAQP_SCANLIST_EXT_CHANNEL(x) (((x) & 0xf) << 0) + +#define DAQP_CTRL_REG 0x02 +#define DAQP_CTRL_PACER_CLK(x) (((x) & 0x3) << 6) +#define DAQP_CTRL_PACER_CLK_EXT DAQP_CTRL_PACER_CLK(0) +#define DAQP_CTRL_PACER_CLK_5MHZ DAQP_CTRL_PACER_CLK(1) +#define DAQP_CTRL_PACER_CLK_1MHZ DAQP_CTRL_PACER_CLK(2) +#define DAQP_CTRL_PACER_CLK_100KHZ DAQP_CTRL_PACER_CLK(3) +#define DAQP_CTRL_EXPANSION BIT(5) +#define DAQP_CTRL_EOS_INT_ENA BIT(4) +#define DAQP_CTRL_FIFO_INT_ENA BIT(3) +#define DAQP_CTRL_TRIG_MODE BIT(2) /* 0=one-shot; 1=continuous */ +#define DAQP_CTRL_TRIG_SRC BIT(1) /* 0=internal; 1=external */ +#define DAQP_CTRL_TRIG_EDGE BIT(0) /* 0=rising; 1=falling */ + +#define DAQP_STATUS_REG 0x02 +#define DAQP_STATUS_IDLE BIT(7) +#define DAQP_STATUS_RUNNING BIT(6) +#define DAQP_STATUS_DATA_LOST BIT(5) +#define DAQP_STATUS_END_OF_SCAN BIT(4) +#define DAQP_STATUS_FIFO_THRESHOLD BIT(3) +#define DAQP_STATUS_FIFO_FULL BIT(2) +#define DAQP_STATUS_FIFO_NEARFULL BIT(1) +#define DAQP_STATUS_FIFO_EMPTY BIT(0) +/* these bits clear when the status register is read */ +#define DAQP_STATUS_EVENTS (DAQP_STATUS_DATA_LOST | \ + DAQP_STATUS_END_OF_SCAN | \ + DAQP_STATUS_FIFO_THRESHOLD) + +#define DAQP_DI_REG 0x03 +#define DAQP_DO_REG 0x03 + +#define DAQP_PACER_LOW_REG 0x04 +#define DAQP_PACER_MID_REG 0x05 +#define DAQP_PACER_HIGH_REG 0x06 + +#define DAQP_CMD_REG 0x07 +/* the monostable bits are self-clearing after the function is complete */ +#define DAQP_CMD_ARM BIT(7) /* monostable */ +#define DAQP_CMD_RSTF BIT(6) /* monostable */ +#define DAQP_CMD_RSTQ BIT(5) /* monostable */ +#define DAQP_CMD_STOP BIT(4) /* monostable */ +#define DAQP_CMD_LATCH BIT(3) /* monostable */ +#define DAQP_CMD_SCANRATE(x) (((x) & 0x3) << 1) +#define DAQP_CMD_SCANRATE_100KHZ DAQP_CMD_SCANRATE(0) +#define DAQP_CMD_SCANRATE_50KHZ DAQP_CMD_SCANRATE(1) +#define DAQP_CMD_SCANRATE_25KHZ DAQP_CMD_SCANRATE(2) +#define DAQP_CMD_FIFO_DATA BIT(0) + +#define DAQP_AO_REG 0x08 /* and 0x09 (16-bit) */ + +#define DAQP_TIMER_REG 0x0a /* and 0x0b (16-bit) */ + +#define DAQP_AUX_REG 0x0f +/* Auxiliary Control register bits (write) */ +#define DAQP_AUX_EXT_ANALOG_TRIG BIT(7) +#define DAQP_AUX_PRETRIG BIT(6) +#define DAQP_AUX_TIMER_INT_ENA BIT(5) +#define DAQP_AUX_TIMER_MODE(x) (((x) & 0x3) << 3) +#define DAQP_AUX_TIMER_MODE_RELOAD DAQP_AUX_TIMER_MODE(0) +#define DAQP_AUX_TIMER_MODE_PAUSE DAQP_AUX_TIMER_MODE(1) +#define DAQP_AUX_TIMER_MODE_GO DAQP_AUX_TIMER_MODE(2) +#define DAQP_AUX_TIMER_MODE_EXT DAQP_AUX_TIMER_MODE(3) +#define DAQP_AUX_TIMER_CLK_SRC_EXT BIT(2) +#define DAQP_AUX_DA_UPDATE(x) (((x) & 0x3) << 0) +#define DAQP_AUX_DA_UPDATE_DIRECT DAQP_AUX_DA_UPDATE(0) +#define DAQP_AUX_DA_UPDATE_OVERFLOW DAQP_AUX_DA_UPDATE(1) +#define DAQP_AUX_DA_UPDATE_EXTERNAL DAQP_AUX_DA_UPDATE(2) +#define DAQP_AUX_DA_UPDATE_PACER DAQP_AUX_DA_UPDATE(3) +/* Auxiliary Status register bits (read) */ +#define DAQP_AUX_RUNNING BIT(7) +#define DAQP_AUX_TRIGGERED BIT(6) +#define DAQP_AUX_DA_BUFFER BIT(5) +#define DAQP_AUX_TIMER_OVERFLOW BIT(4) +#define DAQP_AUX_CONVERSION BIT(3) +#define DAQP_AUX_DATA_LOST BIT(2) +#define DAQP_AUX_FIFO_NEARFULL BIT(1) +#define DAQP_AUX_FIFO_EMPTY BIT(0) + +#define DAQP_FIFO_SIZE 4096 + +#define DAQP_MAX_TIMER_SPEED 10000 /* 100 kHz in nanoseconds */ + struct daqp_private { + unsigned int pacer_div; int stop; - - enum { semaphore, buffer } interrupt_mode; - - struct completion eos; }; -/* The DAQP communicates with the system through a 16 byte I/O window. */ - -#define DAQP_FIFO_SIZE 4096 - -#define DAQP_FIFO 0 -#define DAQP_SCANLIST 1 -#define DAQP_CONTROL 2 -#define DAQP_STATUS 2 -#define DAQP_DIGITAL_IO 3 -#define DAQP_PACER_LOW 4 -#define DAQP_PACER_MID 5 -#define DAQP_PACER_HIGH 6 -#define DAQP_COMMAND 7 -#define DAQP_DA 8 -#define DAQP_TIMER 10 -#define DAQP_AUX 15 - -#define DAQP_SCANLIST_DIFFERENTIAL 0x4000 -#define DAQP_SCANLIST_GAIN(x) ((x)<<12) -#define DAQP_SCANLIST_CHANNEL(x) ((x)<<8) -#define DAQP_SCANLIST_START 0x0080 -#define DAQP_SCANLIST_EXT_GAIN(x) ((x)<<4) -#define DAQP_SCANLIST_EXT_CHANNEL(x) (x) - -#define DAQP_CONTROL_PACER_100kHz 0xc0 -#define DAQP_CONTROL_PACER_1MHz 0x80 -#define DAQP_CONTROL_PACER_5MHz 0x40 -#define DAQP_CONTROL_PACER_EXTERNAL 0x00 -#define DAQP_CONTORL_EXPANSION 0x20 -#define DAQP_CONTROL_EOS_INT_ENABLE 0x10 -#define DAQP_CONTROL_FIFO_INT_ENABLE 0x08 -#define DAQP_CONTROL_TRIGGER_ONESHOT 0x00 -#define DAQP_CONTROL_TRIGGER_CONTINUOUS 0x04 -#define DAQP_CONTROL_TRIGGER_INTERNAL 0x00 -#define DAQP_CONTROL_TRIGGER_EXTERNAL 0x02 -#define DAQP_CONTROL_TRIGGER_RISING 0x00 -#define DAQP_CONTROL_TRIGGER_FALLING 0x01 - -#define DAQP_STATUS_IDLE 0x80 -#define DAQP_STATUS_RUNNING 0x40 -#define DAQP_STATUS_EVENTS 0x38 -#define DAQP_STATUS_DATA_LOST 0x20 -#define DAQP_STATUS_END_OF_SCAN 0x10 -#define DAQP_STATUS_FIFO_THRESHOLD 0x08 -#define DAQP_STATUS_FIFO_FULL 0x04 -#define DAQP_STATUS_FIFO_NEARFULL 0x02 -#define DAQP_STATUS_FIFO_EMPTY 0x01 - -#define DAQP_COMMAND_ARM 0x80 -#define DAQP_COMMAND_RSTF 0x40 -#define DAQP_COMMAND_RSTQ 0x20 -#define DAQP_COMMAND_STOP 0x10 -#define DAQP_COMMAND_LATCH 0x08 -#define DAQP_COMMAND_100kHz 0x00 -#define DAQP_COMMAND_50kHz 0x02 -#define DAQP_COMMAND_25kHz 0x04 -#define DAQP_COMMAND_FIFO_DATA 0x01 -#define DAQP_COMMAND_FIFO_PROGRAM 0x00 - -#define DAQP_AUX_TRIGGER_TTL 0x00 -#define DAQP_AUX_TRIGGER_ANALOG 0x80 -#define DAQP_AUX_TRIGGER_PRETRIGGER 0x40 -#define DAQP_AUX_TIMER_INT_ENABLE 0x20 -#define DAQP_AUX_TIMER_RELOAD 0x00 -#define DAQP_AUX_TIMER_PAUSE 0x08 -#define DAQP_AUX_TIMER_GO 0x10 -#define DAQP_AUX_TIMER_GO_EXTERNAL 0x18 -#define DAQP_AUX_TIMER_EXTERNAL_SRC 0x04 -#define DAQP_AUX_TIMER_INTERNAL_SRC 0x00 -#define DAQP_AUX_DA_DIRECT 0x00 -#define DAQP_AUX_DA_OVERFLOW 0x01 -#define DAQP_AUX_DA_EXTERNAL 0x02 -#define DAQP_AUX_DA_PACER 0x03 - -#define DAQP_AUX_RUNNING 0x80 -#define DAQP_AUX_TRIGGERED 0x40 -#define DAQP_AUX_DA_BUFFER 0x20 -#define DAQP_AUX_TIMER_OVERFLOW 0x10 -#define DAQP_AUX_CONVERSION 0x08 -#define DAQP_AUX_DATA_LOST 0x04 -#define DAQP_AUX_FIFO_NEARFULL 0x02 -#define DAQP_AUX_FIFO_EMPTY 0x01 - static const struct comedi_lrange range_daqp_ai = { 4, { BIP_RANGE(10), @@ -153,38 +157,59 @@ static const struct comedi_lrange range_daqp_ai = { } }; -/* Cancel a running acquisition */ +static int daqp_clear_events(struct comedi_device *dev, int loops) +{ + unsigned int status; -static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) + /* + * Reset any pending interrupts (my card has a tendency to require + * require multiple reads on the status register to achieve this). + */ + while (--loops) { + status = inb(dev->iobase + DAQP_STATUS_REG); + if ((status & DAQP_STATUS_EVENTS) == 0) + return 0; + } + dev_err(dev->class_dev, "couldn't clear events in status register\n"); + return -EBUSY; +} + +static int daqp_ai_cancel(struct comedi_device *dev, + struct comedi_subdevice *s) { struct daqp_private *devpriv = dev->private; if (devpriv->stop) return -EIO; - outb(DAQP_COMMAND_STOP, dev->iobase + DAQP_COMMAND); - - /* flush any linguring data in FIFO - superfluous here */ - /* outb(DAQP_COMMAND_RSTF, dev->iobase+DAQP_COMMAND); */ - - devpriv->interrupt_mode = semaphore; + /* + * Stop any conversions, disable interrupts, and clear + * the status event flags. + */ + outb(DAQP_CMD_STOP, dev->iobase + DAQP_CMD_REG); + outb(0, dev->iobase + DAQP_CTRL_REG); + inb(dev->iobase + DAQP_STATUS_REG); return 0; } -/* Interrupt handler - * - * Operates in one of two modes. If devpriv->interrupt_mode is - * 'semaphore', just signal the devpriv->eos completion and return - * (one-shot mode). Otherwise (continuous mode), read data in from - * the card, transfer it to the buffer provided by the higher-level - * comedi kernel module, and signal various comedi callback routines, - * which run pretty quick. - */ -static enum irqreturn daqp_interrupt(int irq, void *dev_id) +static unsigned int daqp_ai_get_sample(struct comedi_device *dev, + struct comedi_subdevice *s) +{ + unsigned int val; + + /* + * Get a two's complement sample from the FIFO and + * return the munged offset binary value. + */ + val = inb(dev->iobase + DAQP_AI_FIFO_REG); + val |= inb(dev->iobase + DAQP_AI_FIFO_REG) << 8; + return comedi_offset_munge(s, val); +} + +static irqreturn_t daqp_interrupt(int irq, void *dev_id) { struct comedi_device *dev = dev_id; - struct daqp_private *devpriv = dev->private; struct comedi_subdevice *s = dev->read_subdev; struct comedi_cmd *cmd = &s->async->cmd; int loop_limit = 10000; @@ -193,50 +218,42 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id) if (!dev->attached) return IRQ_NONE; - switch (devpriv->interrupt_mode) { - case semaphore: - complete(&devpriv->eos); - break; + status = inb(dev->iobase + DAQP_STATUS_REG); + if (!(status & DAQP_STATUS_EVENTS)) + return IRQ_NONE; - case buffer: - while (!((status = inb(dev->iobase + DAQP_STATUS)) - & DAQP_STATUS_FIFO_EMPTY)) { - unsigned short data; + while (!(status & DAQP_STATUS_FIFO_EMPTY)) { + unsigned short data; - if (status & DAQP_STATUS_DATA_LOST) { - s->async->events |= COMEDI_CB_OVERFLOW; - dev_warn(dev->class_dev, "data lost\n"); - break; - } - - data = inb(dev->iobase + DAQP_FIFO); - data |= inb(dev->iobase + DAQP_FIFO) << 8; - data ^= 0x8000; - - comedi_buf_write_samples(s, &data, 1); - - /* If there's a limit, decrement it - * and stop conversion if zero - */ - - if (cmd->stop_src == TRIG_COUNT && - s->async->scans_done >= cmd->stop_arg) { - s->async->events |= COMEDI_CB_EOA; - break; - } - - if ((loop_limit--) <= 0) - break; + if (status & DAQP_STATUS_DATA_LOST) { + s->async->events |= COMEDI_CB_OVERFLOW; + dev_warn(dev->class_dev, "data lost\n"); + break; } - if (loop_limit <= 0) { - dev_warn(dev->class_dev, - "loop_limit reached in daqp_interrupt()\n"); - s->async->events |= COMEDI_CB_ERROR; + data = daqp_ai_get_sample(dev, s); + comedi_buf_write_samples(s, &data, 1); + + if (cmd->stop_src == TRIG_COUNT && + s->async->scans_done >= cmd->stop_arg) { + s->async->events |= COMEDI_CB_EOA; + break; } - comedi_handle_events(dev, s); + if ((loop_limit--) <= 0) + break; + + status = inb(dev->iobase + DAQP_STATUS_REG); } + + if (loop_limit <= 0) { + dev_warn(dev->class_dev, + "loop_limit reached in daqp_interrupt()\n"); + s->async->events |= COMEDI_CB_ERROR; + } + + comedi_handle_events(dev, s); + return IRQ_HANDLED; } @@ -257,78 +274,73 @@ static void daqp_ai_set_one_scanlist_entry(struct comedi_device *dev, if (start) val |= DAQP_SCANLIST_START; - outb(val & 0xff, dev->iobase + DAQP_SCANLIST); - outb((val >> 8) & 0xff, dev->iobase + DAQP_SCANLIST); + outb(val & 0xff, dev->iobase + DAQP_SCANLIST_REG); + outb((val >> 8) & 0xff, dev->iobase + DAQP_SCANLIST_REG); } -/* One-shot analog data acquisition routine */ +static int daqp_ai_eos(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned long context) +{ + unsigned int status; + + status = inb(dev->iobase + DAQP_AUX_REG); + if (status & DAQP_AUX_CONVERSION) + return 0; + return -EBUSY; +} static int daqp_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 daqp_private *devpriv = dev->private; + int ret = 0; int i; - int v; - int counter = 10000; if (devpriv->stop) return -EIO; - /* Stop any running conversion */ - daqp_ai_cancel(dev, s); - - outb(0, dev->iobase + DAQP_AUX); + outb(0, dev->iobase + DAQP_AUX_REG); /* Reset scan list queue */ - outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND); + outb(DAQP_CMD_RSTQ, dev->iobase + DAQP_CMD_REG); /* Program one scan list entry */ daqp_ai_set_one_scanlist_entry(dev, insn->chanspec, 1); /* Reset data FIFO (see page 28 of DAQP User's Manual) */ + outb(DAQP_CMD_RSTF, dev->iobase + DAQP_CMD_REG); - outb(DAQP_COMMAND_RSTF, dev->iobase + DAQP_COMMAND); + /* Set trigger - one-shot, internal, no interrupts */ + outb(DAQP_CTRL_PACER_CLK_100KHZ, dev->iobase + DAQP_CTRL_REG); - /* Set trigger */ - - v = DAQP_CONTROL_TRIGGER_ONESHOT | DAQP_CONTROL_TRIGGER_INTERNAL - | DAQP_CONTROL_PACER_100kHz | DAQP_CONTROL_EOS_INT_ENABLE; - - outb(v, dev->iobase + DAQP_CONTROL); - - /* Reset any pending interrupts (my card has a tendency to require - * require multiple reads on the status register to achieve this) - */ - - while (--counter - && (inb(dev->iobase + DAQP_STATUS) & DAQP_STATUS_EVENTS)) - ; - if (!counter) { - dev_err(dev->class_dev, - "couldn't clear interrupts in status register\n"); - return -1; - } - - init_completion(&devpriv->eos); - devpriv->interrupt_mode = semaphore; + ret = daqp_clear_events(dev, 10000); + if (ret) + return ret; for (i = 0; i < insn->n; i++) { /* Start conversion */ - outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA, - dev->iobase + DAQP_COMMAND); + outb(DAQP_CMD_ARM | DAQP_CMD_FIFO_DATA, + dev->iobase + DAQP_CMD_REG); - /* Wait for interrupt service routine to unblock completion */ - /* Maybe could use a timeout here, but it's interruptible */ - if (wait_for_completion_interruptible(&devpriv->eos)) - return -EINTR; + ret = comedi_timeout(dev, s, insn, daqp_ai_eos, 0); + if (ret) + break; - data[i] = inb(dev->iobase + DAQP_FIFO); - data[i] |= inb(dev->iobase + DAQP_FIFO) << 8; - data[i] ^= 0x8000; + /* clear the status event flags */ + inb(dev->iobase + DAQP_STATUS_REG); + + data[i] = daqp_ai_get_sample(dev, s); } - return insn->n; + /* stop any conversions and clear the status event flags */ + outb(DAQP_CMD_STOP, dev->iobase + DAQP_CMD_REG); + inb(dev->iobase + DAQP_STATUS_REG); + + return ret ? ret : insn->n; } /* This function converts ns nanoseconds to a counter value suitable @@ -348,17 +360,18 @@ static int daqp_ns_to_timer(unsigned int *ns, unsigned int flags) return timer; } -/* cmdtest tests a particular command to see if it is valid. - * Using the cmdtest ioctl, a user can create a valid cmd - * and then have it executed by the cmd ioctl. - * - * cmdtest returns 1,2,3,4 or 0, depending on which tests - * the command passes. - */ +static void daqp_set_pacer(struct comedi_device *dev, unsigned int val) +{ + outb(val & 0xff, dev->iobase + DAQP_PACER_LOW_REG); + outb((val >> 8) & 0xff, dev->iobase + DAQP_PACER_MID_REG); + outb((val >> 16) & 0xff, dev->iobase + DAQP_PACER_HIGH_REG); +} static int daqp_ai_cmdtest(struct comedi_device *dev, - struct comedi_subdevice *s, struct comedi_cmd *cmd) + struct comedi_subdevice *s, + struct comedi_cmd *cmd) { + struct daqp_private *devpriv = dev->private; int err = 0; unsigned int arg; @@ -383,6 +396,10 @@ static int daqp_ai_cmdtest(struct comedi_device *dev, /* Step 2b : and mutually compatible */ + /* the async command requires a pacer */ + if (cmd->scan_begin_src != TRIG_TIMER && cmd->convert_src != TRIG_TIMER) + err |= -EINVAL; + if (err) return 2; @@ -390,30 +407,30 @@ static int daqp_ai_cmdtest(struct comedi_device *dev, err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0); -#define MAX_SPEED 10000 /* 100 kHz - in nanoseconds */ + err |= comedi_check_trigger_arg_min(&cmd->chanlist_len, 1); + err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, + cmd->chanlist_len); - if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_src == TRIG_TIMER) err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg, - MAX_SPEED); - } - - /* If both scan_begin and convert are both timer values, the only - * way that can make sense is if the scan time is the number of - * conversions times the convert time - */ - - if (cmd->scan_begin_src == TRIG_TIMER && cmd->convert_src == TRIG_TIMER - && cmd->scan_begin_arg != cmd->convert_arg * cmd->scan_end_arg) { - err |= -EINVAL; - } + DAQP_MAX_TIMER_SPEED); if (cmd->convert_src == TRIG_TIMER) { err |= comedi_check_trigger_arg_min(&cmd->convert_arg, - MAX_SPEED); - } + DAQP_MAX_TIMER_SPEED); - err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, - cmd->chanlist_len); + if (cmd->scan_begin_src == TRIG_TIMER) { + /* + * If both scan_begin and convert are both timer + * values, the only way that can make sense is if + * the scan time is the number of conversions times + * the convert time. + */ + arg = cmd->convert_arg * cmd->scan_end_arg; + err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, + arg); + } + } if (cmd->stop_src == TRIG_COUNT) err |= comedi_check_trigger_arg_max(&cmd->stop_arg, 0x00ffffff); @@ -425,16 +442,14 @@ static int daqp_ai_cmdtest(struct comedi_device *dev, /* step 4: fix up any arguments */ - if (cmd->scan_begin_src == TRIG_TIMER) { - arg = cmd->scan_begin_arg; - daqp_ns_to_timer(&arg, cmd->flags); - err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg); - } - if (cmd->convert_src == TRIG_TIMER) { arg = cmd->convert_arg; - daqp_ns_to_timer(&arg, cmd->flags); + devpriv->pacer_div = daqp_ns_to_timer(&arg, cmd->flags); err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg); + } else if (cmd->scan_begin_src == TRIG_TIMER) { + arg = cmd->scan_begin_arg; + devpriv->pacer_div = daqp_ns_to_timer(&arg, cmd->flags); + err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg); } if (err) @@ -447,23 +462,18 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) { struct daqp_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; - int counter; int scanlist_start_on_every_entry; int threshold; - + int ret; int i; - int v; if (devpriv->stop) return -EIO; - /* Stop any running conversion */ - daqp_ai_cancel(dev, s); - - outb(0, dev->iobase + DAQP_AUX); + outb(0, dev->iobase + DAQP_AUX_REG); /* Reset scan list queue */ - outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND); + outb(DAQP_CMD_RSTQ, dev->iobase + DAQP_CMD_REG); /* Program pacer clock * @@ -477,20 +487,12 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) * each scan, so we program the pacer clock to this frequency * and only set the SCANLIST_START bit on the first entry. */ + daqp_set_pacer(dev, devpriv->pacer_div); - if (cmd->convert_src == TRIG_TIMER) { - counter = daqp_ns_to_timer(&cmd->convert_arg, cmd->flags); - outb(counter & 0xff, dev->iobase + DAQP_PACER_LOW); - outb((counter >> 8) & 0xff, dev->iobase + DAQP_PACER_MID); - outb((counter >> 16) & 0xff, dev->iobase + DAQP_PACER_HIGH); + if (cmd->convert_src == TRIG_TIMER) scanlist_start_on_every_entry = 1; - } else { - counter = daqp_ns_to_timer(&cmd->scan_begin_arg, cmd->flags); - outb(counter & 0xff, dev->iobase + DAQP_PACER_LOW); - outb((counter >> 8) & 0xff, dev->iobase + DAQP_PACER_MID); - outb((counter >> 16) & 0xff, dev->iobase + DAQP_PACER_HIGH); + else scanlist_start_on_every_entry = 0; - } /* Program scan list */ for (i = 0; i < cmd->chanlist_len; i++) { @@ -581,7 +583,7 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) /* Reset data FIFO (see page 28 of DAQP User's Manual) */ - outb(DAQP_COMMAND_RSTF, dev->iobase + DAQP_COMMAND); + outb(DAQP_CMD_RSTF, dev->iobase + DAQP_CMD_REG); /* Set FIFO threshold. First two bytes are near-empty * threshold, which is unused; next two bytes are near-full @@ -591,41 +593,40 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) * when the interrupt is to happen. */ - outb(0x00, dev->iobase + DAQP_FIFO); - outb(0x00, dev->iobase + DAQP_FIFO); + outb(0x00, dev->iobase + DAQP_AI_FIFO_REG); + outb(0x00, dev->iobase + DAQP_AI_FIFO_REG); - outb((DAQP_FIFO_SIZE - threshold) & 0xff, dev->iobase + DAQP_FIFO); - outb((DAQP_FIFO_SIZE - threshold) >> 8, dev->iobase + DAQP_FIFO); + outb((DAQP_FIFO_SIZE - threshold) & 0xff, + dev->iobase + DAQP_AI_FIFO_REG); + outb((DAQP_FIFO_SIZE - threshold) >> 8, dev->iobase + DAQP_AI_FIFO_REG); - /* Set trigger */ + /* Set trigger - continuous, internal */ + outb(DAQP_CTRL_TRIG_MODE | DAQP_CTRL_PACER_CLK_5MHZ | + DAQP_CTRL_FIFO_INT_ENA, dev->iobase + DAQP_CTRL_REG); - v = DAQP_CONTROL_TRIGGER_CONTINUOUS | DAQP_CONTROL_TRIGGER_INTERNAL - | DAQP_CONTROL_PACER_5MHz | DAQP_CONTROL_FIFO_INT_ENABLE; - - outb(v, dev->iobase + DAQP_CONTROL); - - /* Reset any pending interrupts (my card has a tendency to require - * require multiple reads on the status register to achieve this) - */ - counter = 100; - while (--counter - && (inb(dev->iobase + DAQP_STATUS) & DAQP_STATUS_EVENTS)) - ; - if (!counter) { - dev_err(dev->class_dev, - "couldn't clear interrupts in status register\n"); - return -1; - } - - devpriv->interrupt_mode = buffer; + ret = daqp_clear_events(dev, 100); + if (ret) + return ret; /* Start conversion */ - outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA, - dev->iobase + DAQP_COMMAND); + outb(DAQP_CMD_ARM | DAQP_CMD_FIFO_DATA, dev->iobase + DAQP_CMD_REG); return 0; } +static int daqp_ao_empty(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned long context) +{ + unsigned int status; + + status = inb(dev->iobase + DAQP_AUX_REG); + if ((status & DAQP_AUX_DA_BUFFER) == 0) + return 0; + return -EBUSY; +} + static int daqp_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -639,18 +640,22 @@ static int daqp_ao_insn_write(struct comedi_device *dev, return -EIO; /* Make sure D/A update mode is direct update */ - outb(0, dev->iobase + DAQP_AUX); + outb(0, dev->iobase + DAQP_AUX_REG); for (i = 0; i > insn->n; i++) { unsigned val = data[i]; + int ret; + + /* D/A transfer rate is about 8ms */ + ret = comedi_timeout(dev, s, insn, daqp_ao_empty, 0); + if (ret) + return ret; + + /* write the two's complement value to the channel */ + outw((chan << 12) | comedi_offset_munge(s, val), + dev->iobase + DAQP_AO_REG); s->readback[chan] = val; - - val &= 0x0fff; - val ^= 0x0800; /* Flip the sign */ - val |= (chan << 12); - - outw(val, dev->iobase + DAQP_DA); } return insn->n; @@ -666,7 +671,7 @@ static int daqp_di_insn_bits(struct comedi_device *dev, if (devpriv->stop) return -EIO; - data[0] = inb(dev->iobase + DAQP_DIGITAL_IO); + data[0] = inb(dev->iobase + DAQP_DI_REG); return insn->n; } @@ -682,7 +687,7 @@ static int daqp_do_insn_bits(struct comedi_device *dev, return -EIO; if (comedi_dio_update_state(s, data)) - outb(s->state, dev->iobase + DAQP_DIGITAL_IO); + outb(s->state, dev->iobase + DAQP_DO_REG); data[1] = s->state; @@ -709,25 +714,28 @@ static int daqp_auto_attach(struct comedi_device *dev, link->priv = dev; ret = pcmcia_request_irq(link, daqp_interrupt); - if (ret) - return ret; + if (ret == 0) + dev->irq = link->irq; ret = comedi_alloc_subdevices(dev, 4); if (ret) return ret; s = &dev->subdevices[0]; - dev->read_subdev = s; s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF; s->n_chan = 8; - s->len_chanlist = 2048; s->maxdata = 0xffff; s->range_table = &range_daqp_ai; s->insn_read = daqp_ai_insn_read; - s->do_cmdtest = daqp_ai_cmdtest; - s->do_cmd = daqp_ai_cmd; - s->cancel = daqp_ai_cancel; + if (dev->irq) { + dev->read_subdev = s; + s->subdev_flags |= SDF_CMD_READ; + s->len_chanlist = 2048; + s->do_cmdtest = daqp_ai_cmdtest; + s->do_cmd = daqp_ai_cmd; + s->cancel = daqp_ai_cancel; + } s = &dev->subdevices[1]; s->type = COMEDI_SUBD_AO; @@ -741,17 +749,35 @@ static int daqp_auto_attach(struct comedi_device *dev, if (ret) return ret; + /* + * Digital Input subdevice + * NOTE: The digital input lines are shared: + * + * Chan Normal Mode Expansion Mode + * ---- ----------------- ---------------------------- + * 0 DI0, ext. trigger Same as normal mode + * 1 DI1 External gain select, lo bit + * 2 DI2, ext. clock Same as normal mode + * 3 DI3 External gain select, hi bit + */ s = &dev->subdevices[2]; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; - s->n_chan = 1; + s->n_chan = 4; s->maxdata = 1; s->insn_bits = daqp_di_insn_bits; + /* + * Digital Output subdevice + * NOTE: The digital output lines share the same pins on the + * interface connector as the four external channel selection + * bits. If expansion mode is used the digital outputs do not + * work. + */ s = &dev->subdevices[3]; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITABLE; - s->n_chan = 1; + s->n_chan = 4; s->maxdata = 1; s->insn_bits = daqp_do_insn_bits; diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c index 4c13f5eb0c84..68ac02b68cb2 100644 --- a/drivers/staging/comedi/drivers/rtd520.c +++ b/drivers/staging/comedi/drivers/rtd520.c @@ -72,8 +72,6 @@ * As far as I can tell, the About interrupt doesn't work if Sample is * also enabled. It turns out that About really isn't needed, since * we always count down samples read. - * - * There was some timer/counter code, but it didn't follow the right API. */ /* @@ -99,6 +97,7 @@ #include "../comedi_pci.h" +#include "comedi_8254.h" #include "plx9080.h" /* @@ -106,39 +105,38 @@ */ #define LAS0_USER_IO 0x0008 /* User I/O */ #define LAS0_ADC 0x0010 /* FIFO Status/Software A/D Start */ -#define FS_DAC1_NOT_EMPTY (1 << 0) /* DAC1 FIFO not empty */ -#define FS_DAC1_HEMPTY (1 << 1) /* DAC1 FIFO half empty */ -#define FS_DAC1_NOT_FULL (1 << 2) /* DAC1 FIFO not full */ -#define FS_DAC2_NOT_EMPTY (1 << 4) /* DAC2 FIFO not empty */ -#define FS_DAC2_HEMPTY (1 << 5) /* DAC2 FIFO half empty */ -#define FS_DAC2_NOT_FULL (1 << 6) /* DAC2 FIFO not full */ -#define FS_ADC_NOT_EMPTY (1 << 8) /* ADC FIFO not empty */ -#define FS_ADC_HEMPTY (1 << 9) /* ADC FIFO half empty */ -#define FS_ADC_NOT_FULL (1 << 10) /* ADC FIFO not full */ -#define FS_DIN_NOT_EMPTY (1 << 12) /* DIN FIFO not empty */ -#define FS_DIN_HEMPTY (1 << 13) /* DIN FIFO half empty */ -#define FS_DIN_NOT_FULL (1 << 14) /* DIN FIFO not full */ -#define LAS0_DAC1 0x0014 /* Software D/A1 Update (w) */ -#define LAS0_DAC2 0x0018 /* Software D/A2 Update (w) */ +#define FS_DAC1_NOT_EMPTY BIT(0) /* DAC1 FIFO not empty */ +#define FS_DAC1_HEMPTY BIT(1) /* DAC1 FIFO half empty */ +#define FS_DAC1_NOT_FULL BIT(2) /* DAC1 FIFO not full */ +#define FS_DAC2_NOT_EMPTY BIT(4) /* DAC2 FIFO not empty */ +#define FS_DAC2_HEMPTY BIT(5) /* DAC2 FIFO half empty */ +#define FS_DAC2_NOT_FULL BIT(6) /* DAC2 FIFO not full */ +#define FS_ADC_NOT_EMPTY BIT(8) /* ADC FIFO not empty */ +#define FS_ADC_HEMPTY BIT(9) /* ADC FIFO half empty */ +#define FS_ADC_NOT_FULL BIT(10) /* ADC FIFO not full */ +#define FS_DIN_NOT_EMPTY BIT(12) /* DIN FIFO not empty */ +#define FS_DIN_HEMPTY BIT(13) /* DIN FIFO half empty */ +#define FS_DIN_NOT_FULL BIT(14) /* DIN FIFO not full */ +#define LAS0_UPDATE_DAC(x) (0x0014 + ((x) * 0x4)) /* D/Ax Update (w) */ #define LAS0_DAC 0x0024 /* Software Simultaneous Update (w) */ #define LAS0_PACER 0x0028 /* Software Pacer Start/Stop */ #define LAS0_TIMER 0x002c /* Timer Status/HDIN Software Trig. */ #define LAS0_IT 0x0030 /* Interrupt Status/Enable */ -#define IRQM_ADC_FIFO_WRITE (1 << 0) /* ADC FIFO Write */ -#define IRQM_CGT_RESET (1 << 1) /* Reset CGT */ -#define IRQM_CGT_PAUSE (1 << 3) /* Pause CGT */ -#define IRQM_ADC_ABOUT_CNT (1 << 4) /* About Counter out */ -#define IRQM_ADC_DELAY_CNT (1 << 5) /* Delay Counter out */ -#define IRQM_ADC_SAMPLE_CNT (1 << 6) /* ADC Sample Counter */ -#define IRQM_DAC1_UCNT (1 << 7) /* DAC1 Update Counter */ -#define IRQM_DAC2_UCNT (1 << 8) /* DAC2 Update Counter */ -#define IRQM_UTC1 (1 << 9) /* User TC1 out */ -#define IRQM_UTC1_INV (1 << 10) /* User TC1 out, inverted */ -#define IRQM_UTC2 (1 << 11) /* User TC2 out */ -#define IRQM_DIGITAL_IT (1 << 12) /* Digital Interrupt */ -#define IRQM_EXTERNAL_IT (1 << 13) /* External Interrupt */ -#define IRQM_ETRIG_RISING (1 << 14) /* Ext Trigger rising-edge */ -#define IRQM_ETRIG_FALLING (1 << 15) /* Ext Trigger falling-edge */ +#define IRQM_ADC_FIFO_WRITE BIT(0) /* ADC FIFO Write */ +#define IRQM_CGT_RESET BIT(1) /* Reset CGT */ +#define IRQM_CGT_PAUSE BIT(3) /* Pause CGT */ +#define IRQM_ADC_ABOUT_CNT BIT(4) /* About Counter out */ +#define IRQM_ADC_DELAY_CNT BIT(5) /* Delay Counter out */ +#define IRQM_ADC_SAMPLE_CNT BIT(6) /* ADC Sample Counter */ +#define IRQM_DAC1_UCNT BIT(7) /* DAC1 Update Counter */ +#define IRQM_DAC2_UCNT BIT(8) /* DAC2 Update Counter */ +#define IRQM_UTC1 BIT(9) /* User TC1 out */ +#define IRQM_UTC1_INV BIT(10) /* User TC1 out, inverted */ +#define IRQM_UTC2 BIT(11) /* User TC2 out */ +#define IRQM_DIGITAL_IT BIT(12) /* Digital Interrupt */ +#define IRQM_EXTERNAL_IT BIT(13) /* External Interrupt */ +#define IRQM_ETRIG_RISING BIT(14) /* Ext Trigger rising-edge */ +#define IRQM_ETRIG_FALLING BIT(15) /* Ext Trigger falling-edge */ #define LAS0_CLEAR 0x0034 /* Clear/Set Interrupt Clear Mask */ #define LAS0_OVERRUN 0x0038 /* Pending interrupts/Clear Overrun */ #define LAS0_PCLK 0x0040 /* Pacer Clock (24bit) */ @@ -149,10 +147,7 @@ #define LAS0_DCNT 0x0054 /* Delay counter (16 bit) */ #define LAS0_ACNT 0x0058 /* About counter (16 bit) */ #define LAS0_DAC_CLK 0x005c /* DAC clock (16bit) */ -#define LAS0_UTC0 0x0060 /* 8254 TC Counter 0 */ -#define LAS0_UTC1 0x0064 /* 8254 TC Counter 1 */ -#define LAS0_UTC2 0x0068 /* 8254 TC Counter 2 */ -#define LAS0_UTC_CTRL 0x006c /* 8254 TC Control */ +#define LAS0_8254_TIMER_BASE 0x0060 /* 8254 timer/counter base */ #define LAS0_DIO0 0x0070 /* Digital I/O Port 0 */ #define LAS0_DIO1 0x0074 /* Digital I/O Port 1 */ #define LAS0_DIO0_CTRL 0x0078 /* Digital I/O Control */ @@ -177,16 +172,11 @@ #define LAS0_CGT_PAUSE 0x0144 /* Table Pause Enable */ #define LAS0_CGT_RESET 0x0148 /* Reset Channel Gain Table */ #define LAS0_CGT_CLEAR 0x014c /* Clear Channel Gain Table */ -#define LAS0_DAC1_CTRL 0x0150 /* D/A1 output type/range */ -#define LAS0_DAC1_SRC 0x0154 /* D/A1 update source */ -#define LAS0_DAC1_CYCLE 0x0158 /* D/A1 cycle mode */ -#define LAS0_DAC1_RESET 0x015c /* D/A1 FIFO reset */ -#define LAS0_DAC1_FIFO_CLEAR 0x0160 /* D/A1 FIFO clear */ -#define LAS0_DAC2_CTRL 0x0164 /* D/A2 output type/range */ -#define LAS0_DAC2_SRC 0x0168 /* D/A2 update source */ -#define LAS0_DAC2_CYCLE 0x016c /* D/A2 cycle mode */ -#define LAS0_DAC2_RESET 0x0170 /* D/A2 FIFO reset */ -#define LAS0_DAC2_FIFO_CLEAR 0x0174 /* D/A2 FIFO clear */ +#define LAS0_DAC_CTRL(x) (0x0150 + ((x) * 0x14)) /* D/Ax type/range */ +#define LAS0_DAC_SRC(x) (0x0154 + ((x) * 0x14)) /* D/Ax update source */ +#define LAS0_DAC_CYCLE(x) (0x0158 + ((x) * 0x14)) /* D/Ax cycle mode */ +#define LAS0_DAC_RESET(x) (0x015c + ((x) * 0x14)) /* D/Ax FIFO reset */ +#define LAS0_DAC_FIFO_CLEAR(x) (0x0160 + ((x) * 0x14)) /* D/Ax FIFO clear */ #define LAS0_ADC_SCNT_SRC 0x0178 /* A/D Sample Counter Source select */ #define LAS0_PACER_SELECT 0x0180 /* Pacer Clock select */ #define LAS0_SBUS0_SRC 0x0184 /* SyncBus 0 Source select */ @@ -197,12 +187,8 @@ #define LAS0_SBUS2_ENABLE 0x019c /* SyncBus 2 enable */ #define LAS0_ETRG_POLARITY 0x01a4 /* Ext. Trigger polarity select */ #define LAS0_EINT_POLARITY 0x01a8 /* Ext. Interrupt polarity select */ -#define LAS0_UTC0_CLOCK 0x01ac /* UTC0 Clock select */ -#define LAS0_UTC0_GATE 0x01b0 /* UTC0 Gate select */ -#define LAS0_UTC1_CLOCK 0x01b4 /* UTC1 Clock select */ -#define LAS0_UTC1_GATE 0x01b8 /* UTC1 Gate select */ -#define LAS0_UTC2_CLOCK 0x01bc /* UTC2 Clock select */ -#define LAS0_UTC2_GATE 0x01c0 /* UTC2 Gate select */ +#define LAS0_8254_CLK_SEL(x) (0x01ac + ((x) * 0x8)) /* 8254 clock select */ +#define LAS0_8254_GATE_SEL(x) (0x01b0 + ((x) * 0x8)) /* 8254 gate select */ #define LAS0_UOUT0_SELECT 0x01c4 /* User Output 0 source select */ #define LAS0_UOUT1_SELECT 0x01c8 /* User Output 1 source select */ #define LAS0_DMA0_RESET 0x01cc /* DMA0 Request state machine reset */ @@ -213,15 +199,16 @@ */ #define LAS1_ADC_FIFO 0x0000 /* A/D FIFO (16bit) */ #define LAS1_HDIO_FIFO 0x0004 /* HiSpd DI FIFO (16bit) */ -#define LAS1_DAC1_FIFO 0x0008 /* D/A1 FIFO (16bit) */ -#define LAS1_DAC2_FIFO 0x000c /* D/A2 FIFO (16bit) */ +#define LAS1_DAC_FIFO(x) (0x0008 + ((x) * 0x4)) /* D/Ax FIFO (16bit) */ -/*====================================================================== - Driver specific stuff (tunable) -======================================================================*/ +/* + * Driver specific stuff (tunable) + */ -/* We really only need 2 buffers. More than that means being much - smarter about knowing which ones are full. */ +/* + * We really only need 2 buffers. More than that means being much + * smarter about knowing which ones are full. + */ #define DMA_CHAIN_COUNT 2 /* max DMA segments/buffers in a ring (min 2) */ /* Target period for periodic transfers. This sets the user read latency. */ @@ -233,9 +220,9 @@ /* The board support a channel list up to the FIFO length (1K or 8K) */ #define RTD_MAX_CHANLIST 128 /* max channel list that we allow */ -/*====================================================================== - Board specific stuff -======================================================================*/ +/* + * Board specific stuff + */ #define RTD_CLOCK_RATE 8000000 /* 8Mhz onboard clock */ #define RTD_CLOCK_BASE 125 /* clock period in ns */ @@ -264,9 +251,9 @@ /* interrupt at end of block */ | PLX_INTR_TERM_COUNT \ /* from board to PCI */ | PLX_XFER_LOCAL_TO_PCI) -/*====================================================================== - Comedi specific stuff -======================================================================*/ +/* + * Comedi specific stuff + */ /* * The board has 3 input modes and the gains of 1,2,4,...32 (, 64, 128) @@ -352,7 +339,7 @@ struct rtd_boardinfo { const struct comedi_lrange *ai_range; }; -static const struct rtd_boardinfo rtd520Boards[] = { +static const struct rtd_boardinfo rtd520_boards[] = { [BOARD_DM7520] = { .name = "DM7520", .range_bip10 = 6, @@ -376,6 +363,10 @@ struct rtd_private { int xfer_count; /* # to transfer data. 0->1/2FIFO */ int flags; /* flag event modes */ unsigned fifosz; + + /* 8254 Timer/Counter gate and clock sources */ + unsigned char timer_gate_src[3]; + unsigned char timer_clk_src[3]; }; /* bit defines for "flags" */ @@ -384,11 +375,11 @@ struct rtd_private { #define DMA1_ACTIVE 0x04 /* DMA1 is active */ /* - Given a desired period and the clock period (both in ns), - return the proper counter value (divider-1). - Sets the original period to be the true value. - Note: you have to check if the value is larger than the counter range! -*/ + * Given a desired period and the clock period (both in ns), return the + * proper counter value (divider-1). Sets the original period to be the + * true value. + * Note: you have to check if the value is larger than the counter range! + */ static int rtd_ns_to_timer_base(unsigned int *nanosec, unsigned int flags, int base) { @@ -397,38 +388,38 @@ static int rtd_ns_to_timer_base(unsigned int *nanosec, switch (flags & CMDF_ROUND_MASK) { case CMDF_ROUND_NEAREST: default: - divider = (*nanosec + base / 2) / base; + divider = DIV_ROUND_CLOSEST(*nanosec, base); break; case CMDF_ROUND_DOWN: divider = (*nanosec) / base; break; case CMDF_ROUND_UP: - divider = (*nanosec + base - 1) / base; + divider = DIV_ROUND_UP(*nanosec, base); break; } if (divider < 2) divider = 2; /* min is divide by 2 */ - /* Note: we don't check for max, because different timers - have different ranges */ + /* + * Note: we don't check for max, because different timers + * have different ranges + */ *nanosec = base * divider; return divider - 1; /* countdown is divisor+1 */ } /* - Given a desired period (in ns), - return the proper counter value (divider-1) for the internal clock. - Sets the original period to be the true value. -*/ + * Given a desired period (in ns), return the proper counter value + * (divider-1) for the internal clock. Sets the original period to + * be the true value. + */ static int rtd_ns_to_timer(unsigned int *ns, unsigned int flags) { return rtd_ns_to_timer_base(ns, flags, RTD_CLOCK_BASE); } -/* - Convert a single comedi channel-gain entry to a RTD520 table entry -*/ +/* Convert a single comedi channel-gain entry to a RTD520 table entry */ static unsigned short rtd_convert_chan_gain(struct comedi_device *dev, unsigned int chanspec, int index) { @@ -473,9 +464,7 @@ static unsigned short rtd_convert_chan_gain(struct comedi_device *dev, return r; } -/* - Setup the channel-gain table from a comedi list -*/ +/* Setup the channel-gain table from a comedi list */ static void rtd_load_channelgain_list(struct comedi_device *dev, unsigned int n_chan, unsigned int *list) { @@ -495,8 +484,10 @@ static void rtd_load_channelgain_list(struct comedi_device *dev, } } -/* determine fifo size by doing adc conversions until the fifo half -empty status flag clears */ +/* + * Determine fifo size by doing adc conversions until the fifo half + * empty status flag clears. + */ static int rtd520_probe_fifo_depth(struct comedi_device *dev) { unsigned int chanspec = CR_PACK(0, 0, AREF_GROUND); @@ -513,7 +504,7 @@ static int rtd520_probe_fifo_depth(struct comedi_device *dev) unsigned fifo_status; /* trigger conversion */ writew(0, dev->mmio + LAS0_ADC); - udelay(1); + usleep_range(1, 1000); fifo_status = readl(dev->mmio + LAS0_ADC); if ((fifo_status & FS_ADC_HEMPTY) == 0) { fifo_size = 2 * i; @@ -590,12 +581,6 @@ static int rtd_ai_rinsn(struct comedi_device *dev, return n; } -/* - Get what we know is there.... Fast! - This uses 1/2 the bus cycles of read_dregs (below). - - The manual claims that we can do a lword read, but it doesn't work here. -*/ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s, int count) { @@ -608,7 +593,7 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s, unsigned int range = CR_RANGE(cmd->chanlist[async->cur_chan]); unsigned short d; - if (0 == devpriv->ai_count) { /* done */ + if (devpriv->ai_count == 0) { /* done */ d = readw(devpriv->las1 + LAS1_ADC_FIFO); continue; } @@ -630,12 +615,6 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s, return 0; } -/* - Handle all rtd520 interrupts. - Runs atomically and is never re-entered. - This is a "slow handler"; other interrupts may be active. - The data conversion may someday happen in a "bottom half". -*/ static irqreturn_t rtd_interrupt(int irq, void *d) { struct comedi_device *dev = d; @@ -655,7 +634,7 @@ static irqreturn_t rtd_interrupt(int irq, void *d) status = readw(dev->mmio + LAS0_IT); /* if interrupt was not caused by our board, or handled above */ - if (0 == status) + if (status == 0) return IRQ_HANDLED; if (status & IRQM_ADC_ABOUT_CNT) { /* sample count -> read FIFO */ @@ -670,7 +649,7 @@ static irqreturn_t rtd_interrupt(int irq, void *d) if (ai_read_n(dev, s, devpriv->fifosz / 2) < 0) goto xfer_abort; - if (0 == devpriv->ai_count) + if (devpriv->ai_count == 0) goto xfer_done; } else if (devpriv->xfer_count > 0) { if (fifo_status & FS_ADC_NOT_EMPTY) { @@ -678,7 +657,7 @@ static irqreturn_t rtd_interrupt(int irq, void *d) if (ai_read_n(dev, s, devpriv->xfer_count) < 0) goto xfer_abort; - if (0 == devpriv->ai_count) + if (devpriv->ai_count == 0) goto xfer_done; } } @@ -715,15 +694,6 @@ xfer_done: return IRQ_HANDLED; } -/* - cmdtest tests a particular command to see if it is valid. - Using the cmdtest ioctl, a user can create a valid cmd - and then have it executed by the cmd ioctl (asynchronously). - - cmdtest returns 1,2,3,4 or 0, depending on which tests - the command passes. -*/ - static int rtd_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) { @@ -760,7 +730,7 @@ static int rtd_ai_cmdtest(struct comedi_device *dev, if (cmd->scan_begin_src == TRIG_TIMER) { /* Note: these are time periods, not actual rates */ - if (1 == cmd->chanlist_len) { /* no scanning */ + if (cmd->chanlist_len == 1) { /* no scanning */ if (comedi_check_trigger_arg_min(&cmd->scan_begin_arg, RTD_MAX_SPEED_1)) { rtd_ns_to_timer(&cmd->scan_begin_arg, @@ -795,7 +765,7 @@ static int rtd_ai_cmdtest(struct comedi_device *dev, } if (cmd->convert_src == TRIG_TIMER) { - if (1 == cmd->chanlist_len) { /* no scanning */ + if (cmd->chanlist_len == 1) { /* no scanning */ if (comedi_check_trigger_arg_min(&cmd->convert_arg, RTD_MAX_SPEED_1)) { rtd_ns_to_timer(&cmd->convert_arg, @@ -866,12 +836,6 @@ static int rtd_ai_cmdtest(struct comedi_device *dev, return 0; } -/* - Execute a analog in command with many possible triggering options. - The data get stored in the async structure of the subdevice. - This is usually done by an interrupt handler. - Userland gets to the data using read calls. -*/ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) { struct rtd_private *devpriv = dev->private; @@ -907,7 +871,7 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) } writel((devpriv->fifosz / 2 - 1) & 0xffff, dev->mmio + LAS0_ACNT); - if (TRIG_TIMER == cmd->scan_begin_src) { + if (cmd->scan_begin_src == TRIG_TIMER) { /* scan_begin_arg is in nanoseconds */ /* find out how many samples to wait before transferring */ if (cmd->flags & CMDF_WAKE_EOS) { @@ -959,8 +923,8 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) switch (cmd->stop_src) { case TRIG_COUNT: /* stop after N scans */ devpriv->ai_count = cmd->stop_arg * cmd->chanlist_len; - if ((devpriv->xfer_count > 0) - && (devpriv->xfer_count > devpriv->ai_count)) { + if ((devpriv->xfer_count > 0) && + (devpriv->xfer_count > devpriv->ai_count)) { devpriv->xfer_count = devpriv->ai_count; } break; @@ -1006,8 +970,10 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) } /* end configuration */ - /* This doesn't seem to work. There is no way to clear an interrupt - that the priority controller has queued! */ + /* + * This doesn't seem to work. There is no way to clear an interrupt + * that the priority controller has queued! + */ writew(~0, dev->mmio + LAS0_CLEAR); readw(dev->mmio + LAS0_CLEAR); @@ -1021,9 +987,6 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) return 0; } -/* - Stop a running data acquisition. -*/ static int rtd_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { struct rtd_private *devpriv = dev->private; @@ -1053,49 +1016,43 @@ static int rtd_ao_eoc(struct comedi_device *dev, return -EBUSY; } -static int rtd_ao_winsn(struct comedi_device *dev, - struct comedi_subdevice *s, struct comedi_insn *insn, - unsigned int *data) +static int rtd_ao_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct rtd_private *devpriv = dev->private; - int i; - int chan = CR_CHAN(insn->chanspec); - int range = CR_RANGE(insn->chanspec); + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int range = CR_RANGE(insn->chanspec); int ret; + int i; /* Configure the output range (table index matches the range values) */ - writew(range & 7, - dev->mmio + ((chan == 0) ? LAS0_DAC1_CTRL : LAS0_DAC2_CTRL)); + writew(range & 7, dev->mmio + LAS0_DAC_CTRL(chan)); - /* 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) { - int val = data[i] << 3; + unsigned int val = data[i]; - /* VERIFY: comedi range and offset conversions */ - - if ((range > 1) /* bipolar */ - && (data[i] < 2048)) { - /* offset and sign extend */ - val = (((int)data[i]) - 2048) << 3; - } else { /* unipolor */ - val = data[i] << 3; + /* bipolar uses 2's complement values with an extended sign */ + if (comedi_range_is_bipolar(s, range)) { + val = comedi_offset_munge(s, val); + val |= (val & ((s->maxdata + 1) >> 1)) << 1; } - /* a typical programming sequence */ - writew(val, devpriv->las1 + - ((chan == 0) ? LAS1_DAC1_FIFO : LAS1_DAC2_FIFO)); - writew(0, dev->mmio + ((chan == 0) ? LAS0_DAC1 : LAS0_DAC2)); + /* shift the 12-bit data (+ sign) to match the register */ + val <<= 3; - s->readback[chan] = data[i]; + writew(val, devpriv->las1 + LAS1_DAC_FIFO(chan)); + writew(0, dev->mmio + LAS0_UPDATE_DAC(chan)); ret = comedi_timeout(dev, s, insn, rtd_ao_eoc, 0); if (ret) return ret; + + s->readback[chan] = data[i]; } - /* return the number of samples read/written */ - return i; + return insn->n; } static int rtd_dio_insn_bits(struct comedi_device *dev, @@ -1138,12 +1095,87 @@ static int rtd_dio_insn_config(struct comedi_device *dev, return insn->n; } +static int rtd_counter_insn_config(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct rtd_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int max_src; + unsigned int src; + + switch (data[0]) { + case INSN_CONFIG_SET_GATE_SRC: + /* + * 8254 Timer/Counter gate sources: + * + * 0 = Not gated, free running (reset state) + * 1 = Gated, off + * 2 = Ext. TC Gate 1 + * 3 = Ext. TC Gate 2 + * 4 = Previous TC out (chan 1 and 2 only) + */ + src = data[2]; + max_src = (chan == 0) ? 3 : 4; + if (src > max_src) + return -EINVAL; + + devpriv->timer_gate_src[chan] = src; + writeb(src, dev->mmio + LAS0_8254_GATE_SEL(chan)); + break; + case INSN_CONFIG_GET_GATE_SRC: + data[2] = devpriv->timer_gate_src[chan]; + break; + case INSN_CONFIG_SET_CLOCK_SRC: + /* + * 8254 Timer/Counter clock sources: + * + * 0 = 8 MHz (reset state) + * 1 = Ext. TC Clock 1 + * 2 = Ext. TX Clock 2 + * 3 = Ext. Pacer Clock + * 4 = Previous TC out (chan 1 and 2 only) + * 5 = High-Speed Digital Input Sampling signal (chan 1 only) + */ + src = data[1]; + switch (chan) { + case 0: + max_src = 3; + break; + case 1: + max_src = 5; + break; + case 2: + max_src = 4; + break; + default: + return -EINVAL; + } + if (src > max_src) + return -EINVAL; + + devpriv->timer_clk_src[chan] = src; + writeb(src, dev->mmio + LAS0_8254_CLK_SEL(chan)); + break; + case INSN_CONFIG_GET_CLOCK_SRC: + src = devpriv->timer_clk_src[chan]; + data[1] = devpriv->timer_clk_src[chan]; + data[2] = (src == 0) ? RTD_CLOCK_BASE : 0; + break; + default: + return -EINVAL; + } + + return insn->n; +} + static void rtd_reset(struct comedi_device *dev) { struct rtd_private *devpriv = dev->private; writel(0, dev->mmio + LAS0_BOARD_RESET); - udelay(100); /* needed? */ + usleep_range(100, 1000); /* needed? */ writel(0, devpriv->lcfg + PLX_INTRCS_REG); writew(0, dev->mmio + LAS0_IT); writew(~0, dev->mmio + LAS0_CLEAR); @@ -1161,14 +1193,10 @@ static void rtd_init_board(struct comedi_device *dev) writel(0, dev->mmio + LAS0_OVERRUN); writel(0, dev->mmio + LAS0_CGT_CLEAR); writel(0, dev->mmio + LAS0_ADC_FIFO_CLEAR); - writel(0, dev->mmio + LAS0_DAC1_RESET); - writel(0, dev->mmio + LAS0_DAC2_RESET); + writel(0, dev->mmio + LAS0_DAC_RESET(0)); + writel(0, dev->mmio + LAS0_DAC_RESET(1)); /* clear digital IO fifo */ writew(0, dev->mmio + LAS0_DIO_STATUS); - writeb((0 << 6) | 0x30, dev->mmio + LAS0_UTC_CTRL); - writeb((1 << 6) | 0x30, dev->mmio + LAS0_UTC_CTRL); - writeb((2 << 6) | 0x30, dev->mmio + LAS0_UTC_CTRL); - writeb((3 << 6) | 0x00, dev->mmio + LAS0_UTC_CTRL); /* TODO: set user out source ??? */ } @@ -1196,8 +1224,8 @@ static int rtd_auto_attach(struct comedi_device *dev, struct comedi_subdevice *s; int ret; - if (context < ARRAY_SIZE(rtd520Boards)) - board = &rtd520Boards[context]; + if (context < ARRAY_SIZE(rtd520_boards)) + board = &rtd520_boards[context]; if (!board) return -ENODEV; dev->board_ptr = board; @@ -1254,7 +1282,7 @@ static int rtd_auto_attach(struct comedi_device *dev, s->n_chan = 2; s->maxdata = 0x0fff; s->range_table = &rtd_ao_range; - s->insn_write = rtd_ao_winsn; + s->insn_write = rtd_ao_insn_write; ret = comedi_alloc_subdev_readback(s); if (ret) @@ -1271,12 +1299,15 @@ static int rtd_auto_attach(struct comedi_device *dev, s->insn_bits = rtd_dio_insn_bits; s->insn_config = rtd_dio_insn_config; - /* timer/counter subdevices (not currently supported) */ + /* 8254 Timer/Counter subdevice */ s = &dev->subdevices[3]; - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE; - s->n_chan = 3; - s->maxdata = 0xffff; + dev->pacer = comedi_8254_mm_init(dev->mmio + LAS0_8254_TIMER_BASE, + RTD_CLOCK_BASE, I8254_IO8, 2); + if (!dev->pacer) + return -ENOMEM; + + comedi_8254_subdevice_init(s, dev->pacer); + dev->pacer->insn_config = rtd_counter_insn_config; rtd_init_board(dev); diff --git a/drivers/staging/comedi/drivers/rti800.c b/drivers/staging/comedi/drivers/rti800.c index 340ac776e951..cd61d2645af4 100644 --- a/drivers/staging/comedi/drivers/rti800.c +++ b/drivers/staging/comedi/drivers/rti800.c @@ -57,14 +57,14 @@ * Register map */ #define RTI800_CSR 0x00 -#define RTI800_CSR_BUSY (1 << 7) -#define RTI800_CSR_DONE (1 << 6) -#define RTI800_CSR_OVERRUN (1 << 5) -#define RTI800_CSR_TCR (1 << 4) -#define RTI800_CSR_DMA_ENAB (1 << 3) -#define RTI800_CSR_INTR_TC (1 << 2) -#define RTI800_CSR_INTR_EC (1 << 1) -#define RTI800_CSR_INTR_OVRN (1 << 0) +#define RTI800_CSR_BUSY BIT(7) +#define RTI800_CSR_DONE BIT(6) +#define RTI800_CSR_OVERRUN BIT(5) +#define RTI800_CSR_TCR BIT(4) +#define RTI800_CSR_DMA_ENAB BIT(3) +#define RTI800_CSR_INTR_TC BIT(2) +#define RTI800_CSR_INTR_EC BIT(1) +#define RTI800_CSR_INTR_OVRN BIT(0) #define RTI800_MUXGAIN 0x01 #define RTI800_CONVERT 0x02 #define RTI800_ADCLO 0x03 @@ -189,17 +189,21 @@ static int rti800_ai_insn_read(struct comedi_device *dev, } for (i = 0; i < insn->n; i++) { + unsigned int val; + outb(0, dev->iobase + RTI800_CONVERT); ret = comedi_timeout(dev, s, insn, rti800_ai_eoc, 0); if (ret) return ret; - data[i] = inb(dev->iobase + RTI800_ADCLO); - data[i] |= (inb(dev->iobase + RTI800_ADCHI) & 0xf) << 8; + val = inb(dev->iobase + RTI800_ADCLO); + val |= (inb(dev->iobase + RTI800_ADCHI) & 0xf) << 8; if (devpriv->adc_2comp) - data[i] ^= 0x800; + val = comedi_offset_munge(s, val); + + data[i] = val; } return insn->n; @@ -222,7 +226,7 @@ static int rti800_ao_insn_write(struct comedi_device *dev, s->readback[chan] = val; if (devpriv->dac_2comp[chan]) - val ^= 0x800; + val = comedi_offset_munge(s, val); outb(val & 0xff, dev->iobase + reg_lo); outb((val >> 8) & 0xff, dev->iobase + reg_hi); diff --git a/drivers/staging/comedi/drivers/s526.c b/drivers/staging/comedi/drivers/s526.c index 6f3e8a08e75c..d70c97947627 100644 --- a/drivers/staging/comedi/drivers/s526.c +++ b/drivers/staging/comedi/drivers/s526.c @@ -1,79 +1,96 @@ /* - comedi/drivers/s526.c - Sensoray s526 Comedi driver + * s526.c + * Sensoray s526 Comedi driver + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000 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 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. -*/ /* -Driver: s526 -Description: Sensoray 526 driver -Devices: [Sensoray] 526 (s526) -Author: Richie - Everett Wang -Updated: Thu, 14 Sep. 2006 -Status: experimental - -Encoder works -Analog input works -Analog output works -PWM output works -Commands are not supported yet. - -Configuration Options: - -comedi_config /dev/comedi0 s526 0x2C0,0x3 - -*/ + * Driver: s526 + * Description: Sensoray 526 driver + * Devices: [Sensoray] 526 (s526) + * Author: Richie + * Everett Wang + * Updated: Thu, 14 Sep. 2006 + * Status: experimental + * + * Encoder works + * Analog input works + * Analog output works + * PWM output works + * Commands are not supported yet. + * + * Configuration Options: + * [0] - I/O port base address + */ #include #include "../comedidev.h" #include -#define S526_START_AI_CONV 0 -#define S526_AI_READ 0 - -/* Ports */ -#define S526_NUM_PORTS 27 - -/* registers */ -#define REG_TCR 0x00 -#define REG_WDC 0x02 -#define REG_DAC 0x04 -#define REG_ADC 0x06 -#define REG_ADD 0x08 -#define REG_DIO 0x0A -#define REG_IER 0x0C -#define REG_ISR 0x0E -#define REG_MSC 0x10 -#define REG_C0L 0x12 -#define REG_C0H 0x14 -#define REG_C0M 0x16 -#define REG_C0C 0x18 -#define REG_C1L 0x1A -#define REG_C1H 0x1C -#define REG_C1M 0x1E -#define REG_C1C 0x20 -#define REG_C2L 0x22 -#define REG_C2H 0x24 -#define REG_C2M 0x26 -#define REG_C2C 0x28 -#define REG_C3L 0x2A -#define REG_C3H 0x2C -#define REG_C3M 0x2E -#define REG_C3C 0x30 -#define REG_EED 0x32 -#define REG_EEC 0x34 +/* + * Register I/O map + */ +#define S526_TIMER_REG 0x00 +#define S526_TIMER_LOAD(x) (((x) & 0xff) << 8) +#define S526_TIMER_MODE ((x) << 1) +#define S526_TIMER_MANUAL S526_TIMER_MODE(0) +#define S526_TIMER_AUTO S526_TIMER_MODE(1) +#define S526_TIMER_RESTART BIT(0) +#define S526_WDOG_REG 0x02 +#define S526_WDOG_INVERTED BIT(4) +#define S526_WDOG_ENA BIT(3) +#define S526_WDOG_INTERVAL(x) (((x) & 0x7) << 0) +#define S526_AO_CTRL_REG 0x04 +#define S526_AO_CTRL_RESET BIT(3) +#define S526_AO_CTRL_CHAN(x) (((x) & 0x3) << 1) +#define S526_AO_CTRL_START BIT(0) +#define S526_AI_CTRL_REG 0x06 +#define S526_AI_CTRL_DELAY BIT(15) +#define S526_AI_CTRL_CONV(x) (1 << (5 + ((x) & 0x9))) +#define S526_AI_CTRL_READ(x) (((x) & 0xf) << 1) +#define S526_AI_CTRL_START BIT(0) +#define S526_AO_REG 0x08 +#define S526_AI_REG 0x08 +#define S526_DIO_CTRL_REG 0x0a +#define S526_DIO_CTRL_DIO3_NEG BIT(15) /* irq on DIO3 neg/pos edge */ +#define S526_DIO_CTRL_DIO2_NEG BIT(14) /* irq on DIO2 neg/pos edge */ +#define S526_DIO_CTRL_DIO1_NEG BIT(13) /* irq on DIO1 neg/pos edge */ +#define S526_DIO_CTRL_DIO0_NEG BIT(12) /* irq on DIO0 neg/pos edge */ +#define S526_DIO_CTRL_GRP2_OUT BIT(11) +#define S526_DIO_CTRL_GRP1_OUT BIT(10) +#define S526_DIO_CTRL_GRP2_NEG BIT(8) /* irq on DIO[4-7] neg/pos edge */ +#define S526_INT_ENA_REG 0x0c +#define S526_INT_STATUS_REG 0x0e +#define S526_INT_DIO(x) BIT(8 + ((x) & 0x7)) +#define S526_INT_EEPROM BIT(7) /* status only */ +#define S526_INT_CNTR(x) BIT(3 + (3 - ((x) & 0x3))) +#define S526_INT_AI BIT(2) +#define S526_INT_AO BIT(1) +#define S526_INT_TIMER BIT(0) +#define S526_MISC_REG 0x10 +#define S526_MISC_LED_OFF BIT(0) +#define S526_GPCT_LSB_REG(x) (0x12 + ((x) * 8)) +#define S526_GPCT_MSB_REG(x) (0x14 + ((x) * 8)) +#define S526_GPCT_MODE_REG(x) (0x16 + ((x) * 8)) +#define S526_GPCT_CTRL_REG(x) (0x18 + ((x) * 8)) +#define S526_EEPROM_DATA_REG 0x32 +#define S526_EEPROM_CTRL_REG 0x34 +#define S526_EEPROM_CTRL_ADDR(x) (((x) & 0x3f) << 3) +#define S526_EEPROM_CTRL(x) (((x) & 0x3) << 1) +#define S526_EEPROM_CTRL_READ S526_EEPROM_CTRL(2) +#define S526_EEPROM_CTRL_START BIT(0) struct counter_mode_register_t { #if defined(__LITTLE_ENDIAN_BITFIELD) @@ -112,27 +129,39 @@ union cmReg { struct s526_private { unsigned int gpct_config[4]; - unsigned short ai_config; + unsigned short ai_ctrl; }; +static void s526_gpct_write(struct comedi_device *dev, + unsigned int chan, unsigned int val) +{ + /* write high word then low word */ + outw((val >> 16) & 0xffff, dev->iobase + S526_GPCT_MSB_REG(chan)); + outw(val & 0xffff, dev->iobase + S526_GPCT_LSB_REG(chan)); +} + +static unsigned int s526_gpct_read(struct comedi_device *dev, + unsigned int chan) +{ + unsigned int val; + + /* read the low word then high word */ + val = inw(dev->iobase + S526_GPCT_LSB_REG(chan)) & 0xffff; + val |= (inw(dev->iobase + S526_GPCT_MSB_REG(chan)) & 0xff) << 16; + + return val; +} + static int s526_gpct_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { unsigned int chan = CR_CHAN(insn->chanspec); - unsigned long chan_iobase = dev->iobase + chan * 8; - unsigned int lo; - unsigned int hi; int i; - for (i = 0; i < insn->n; i++) { - /* Read the low word first */ - lo = inw(chan_iobase + REG_C0L) & 0xffff; - hi = inw(chan_iobase + REG_C0H) & 0xff; - - data[i] = (hi << 16) | lo; - } + for (i = 0; i < insn->n; i++) + data[i] = s526_gpct_read(dev, chan); return insn->n; } @@ -144,63 +173,34 @@ static int s526_gpct_insn_config(struct comedi_device *dev, { struct s526_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); - unsigned long chan_iobase = dev->iobase + chan * 8; unsigned int val; union cmReg cmReg; - /* Check what type of Counter the user requested, data[0] contains */ - /* the Application type */ + /* + * Check what type of Counter the user requested + * data[0] contains the Application type + */ switch (data[0]) { case INSN_CONFIG_GPCT_QUADRATURE_ENCODER: /* - data[0]: Application Type - data[1]: Counter Mode Register Value - data[2]: Pre-load Register Value - data[3]: Conter Control Register + * data[0]: Application Type + * data[1]: Counter Mode Register Value + * data[2]: Pre-load Register Value + * data[3]: Conter Control Register */ devpriv->gpct_config[chan] = data[0]; -#if 0 - /* Example of Counter Application */ - /* One-shot (software trigger) */ - cmReg.reg.coutSource = 0; /* out RCAP */ - cmReg.reg.coutPolarity = 1; /* Polarity inverted */ - cmReg.reg.autoLoadResetRcap = 0;/* Auto load disabled */ - cmReg.reg.hwCtEnableSource = 3; /* NOT RCAP */ - cmReg.reg.ctEnableCtrl = 2; /* Hardware */ - cmReg.reg.clockSource = 2; /* Internal */ - cmReg.reg.countDir = 1; /* Down */ - cmReg.reg.countDirCtrl = 1; /* Software */ - cmReg.reg.outputRegLatchCtrl = 0; /* latch on read */ - cmReg.reg.preloadRegSel = 0; /* PR0 */ - cmReg.reg.reserved = 0; - - outw(cmReg.value, chan_iobase + REG_C0M); - - outw(0x0001, chan_iobase + REG_C0H); - outw(0x3C68, chan_iobase + REG_C0L); - - /* Reset the counter */ - outw(0x8000, chan_iobase + REG_C0C); - /* Load the counter from PR0 */ - outw(0x4000, chan_iobase + REG_C0C); - - /* Reset RCAP (fires one-shot) */ - outw(0x0008, chan_iobase + REG_C0C); - -#endif - #if 1 /* Set Counter Mode Register */ cmReg.value = data[1] & 0xffff; - outw(cmReg.value, chan_iobase + REG_C0M); + outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); /* Reset the counter if it is software preload */ if (cmReg.reg.autoLoadResetRcap == 0) { /* Reset the counter */ - outw(0x8000, chan_iobase + REG_C0C); + outw(0x8000, dev->iobase + S526_GPCT_CTRL_REG(chan)); /* Load the counter from PR0 - * outw(0x4000, chan_iobase + REG_C0C); + * outw(0x4000, dev->iobase + S526_GPCT_CTRL_REG(chan)); */ } #else @@ -216,11 +216,13 @@ static int s526_gpct_insn_config(struct comedi_device *dev, cmReg.reg.clockSource = 0; /* When to take into account the indexpulse: */ - /*if (data[2] == GPCT_IndexPhaseLowLow) { - } else if (data[2] == GPCT_IndexPhaseLowHigh) { - } else if (data[2] == GPCT_IndexPhaseHighLow) { - } else if (data[2] == GPCT_IndexPhaseHighHigh) { - }*/ + /* + * if (data[2] == GPCT_IndexPhaseLowLow) { + * } else if (data[2] == GPCT_IndexPhaseLowHigh) { + * } else if (data[2] == GPCT_IndexPhaseHighLow) { + * } else if (data[2] == GPCT_IndexPhaseHighHigh) { + * } + */ /* Take into account the index pulse? */ if (data[3] == GPCT_RESET_COUNTER_ON_INDEX) /* Auto load with INDEX^ */ @@ -228,114 +230,89 @@ static int s526_gpct_insn_config(struct comedi_device *dev, /* Set Counter Mode Register */ cmReg.value = data[1] & 0xffff; - outw(cmReg.value, chan_iobase + REG_C0M); + outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); - /* Load the pre-load register high word */ - val = (data[2] >> 16) & 0xffff; - outw(val, chan_iobase + REG_C0H); - - /* Load the pre-load register low word */ - val = data[2] & 0xffff; - outw(val, chan_iobase + REG_C0L); + /* Load the pre-load register */ + s526_gpct_write(dev, chan, data[2]); /* Write the Counter Control Register */ - if (data[3]) { - val = data[3] & 0xffff; - outw(val, chan_iobase + REG_C0C); - } + if (data[3]) + outw(data[3] & 0xffff, + dev->iobase + S526_GPCT_CTRL_REG(chan)); + /* Reset the counter if it is software preload */ if (cmReg.reg.autoLoadResetRcap == 0) { /* Reset the counter */ - outw(0x8000, chan_iobase + REG_C0C); + outw(0x8000, dev->iobase + S526_GPCT_CTRL_REG(chan)); /* Load the counter from PR0 */ - outw(0x4000, chan_iobase + REG_C0C); + outw(0x4000, dev->iobase + S526_GPCT_CTRL_REG(chan)); } #endif break; case INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR: /* - data[0]: Application Type - data[1]: Counter Mode Register Value - data[2]: Pre-load Register 0 Value - data[3]: Pre-load Register 1 Value - data[4]: Conter Control Register + * data[0]: Application Type + * data[1]: Counter Mode Register Value + * data[2]: Pre-load Register 0 Value + * data[3]: Pre-load Register 1 Value + * data[4]: Conter Control Register */ devpriv->gpct_config[chan] = data[0]; /* Set Counter Mode Register */ cmReg.value = data[1] & 0xffff; cmReg.reg.preloadRegSel = 0; /* PR0 */ - outw(cmReg.value, chan_iobase + REG_C0M); + outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); - /* Load the pre-load register 0 high word */ - val = (data[2] >> 16) & 0xffff; - outw(val, chan_iobase + REG_C0H); - - /* Load the pre-load register 0 low word */ - val = data[2] & 0xffff; - outw(val, chan_iobase + REG_C0L); + /* Load the pre-load register 0 */ + s526_gpct_write(dev, chan, data[2]); /* Set Counter Mode Register */ cmReg.value = data[1] & 0xffff; cmReg.reg.preloadRegSel = 1; /* PR1 */ - outw(cmReg.value, chan_iobase + REG_C0M); + outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); - /* Load the pre-load register 1 high word */ - val = (data[3] >> 16) & 0xffff; - outw(val, chan_iobase + REG_C0H); - - /* Load the pre-load register 1 low word */ - val = data[3] & 0xffff; - outw(val, chan_iobase + REG_C0L); + /* Load the pre-load register 1 */ + s526_gpct_write(dev, chan, data[3]); /* Write the Counter Control Register */ if (data[4]) { val = data[4] & 0xffff; - outw(val, chan_iobase + REG_C0C); + outw(val, dev->iobase + S526_GPCT_CTRL_REG(chan)); } break; case INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR: /* - data[0]: Application Type - data[1]: Counter Mode Register Value - data[2]: Pre-load Register 0 Value - data[3]: Pre-load Register 1 Value - data[4]: Conter Control Register + * data[0]: Application Type + * data[1]: Counter Mode Register Value + * data[2]: Pre-load Register 0 Value + * data[3]: Pre-load Register 1 Value + * data[4]: Conter Control Register */ devpriv->gpct_config[chan] = data[0]; /* Set Counter Mode Register */ cmReg.value = data[1] & 0xffff; cmReg.reg.preloadRegSel = 0; /* PR0 */ - outw(cmReg.value, chan_iobase + REG_C0M); + outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); - /* Load the pre-load register 0 high word */ - val = (data[2] >> 16) & 0xffff; - outw(val, chan_iobase + REG_C0H); - - /* Load the pre-load register 0 low word */ - val = data[2] & 0xffff; - outw(val, chan_iobase + REG_C0L); + /* Load the pre-load register 0 */ + s526_gpct_write(dev, chan, data[2]); /* Set Counter Mode Register */ cmReg.value = data[1] & 0xffff; cmReg.reg.preloadRegSel = 1; /* PR1 */ - outw(cmReg.value, chan_iobase + REG_C0M); + outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan)); - /* Load the pre-load register 1 high word */ - val = (data[3] >> 16) & 0xffff; - outw(val, chan_iobase + REG_C0H); - - /* Load the pre-load register 1 low word */ - val = data[3] & 0xffff; - outw(val, chan_iobase + REG_C0L); + /* Load the pre-load register 1 */ + s526_gpct_write(dev, chan, data[3]); /* Write the Counter Control Register */ if (data[4]) { val = data[4] & 0xffff; - outw(val, chan_iobase + REG_C0C); + outw(val, dev->iobase + S526_GPCT_CTRL_REG(chan)); } break; @@ -353,18 +330,18 @@ static int s526_gpct_winsn(struct comedi_device *dev, { struct s526_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); - unsigned long chan_iobase = dev->iobase + chan * 8; - inw(chan_iobase + REG_C0M); /* Is this read required? */ + inw(dev->iobase + S526_GPCT_MODE_REG(chan)); /* Is this required? */ /* Check what Application of Counter this channel is configured for */ switch (devpriv->gpct_config[chan]) { case INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR: - /* data[0] contains the PULSE_WIDTH - data[1] contains the PULSE_PERIOD - @pre PULSE_PERIOD > PULSE_WIDTH > 0 - The above periods must be expressed as a multiple of the - pulse frequency on the selected source + /* + * data[0] contains the PULSE_WIDTH + * data[1] contains the PULSE_PERIOD + * @pre PULSE_PERIOD > PULSE_WIDTH > 0 + * The above periods must be expressed as a multiple of the + * pulse frequency on the selected source */ if ((data[1] <= data[0]) || !data[0]) return -EINVAL; @@ -373,8 +350,7 @@ static int s526_gpct_winsn(struct comedi_device *dev, case INSN_CONFIG_GPCT_QUADRATURE_ENCODER: case INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR: - outw((data[0] >> 16) & 0xffff, chan_iobase + REG_C0H); - outw(data[0] & 0xffff, chan_iobase + REG_C0L); + s526_gpct_write(dev, chan, data[0]); break; default: @@ -384,86 +360,60 @@ static int s526_gpct_winsn(struct comedi_device *dev, return insn->n; } -#define ISR_ADC_DONE 0x4 -static int s526_ai_insn_config(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - struct s526_private *devpriv = dev->private; - int result = -EINVAL; - - if (insn->n < 1) - return result; - - result = insn->n; - - /* data[0] : channels was set in relevant bits. - data[1] : delay - */ - /* COMMENT: abbotti 2008-07-24: I don't know why you'd want to - * enable channels here. The channel should be enabled in the - * INSN_READ handler. */ - - /* Enable ADC interrupt */ - outw(ISR_ADC_DONE, dev->iobase + REG_IER); - devpriv->ai_config = (data[0] & 0x3ff) << 5; - if (data[1] > 0) - devpriv->ai_config |= 0x8000; /* set the delay */ - - devpriv->ai_config |= 0x0001; /* ADC start bit */ - - return result; -} - -static int s526_ai_eoc(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned long context) +static int s526_eoc(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned long context) { unsigned int status; - status = inw(dev->iobase + REG_ISR); - if (status & ISR_ADC_DONE) + status = inw(dev->iobase + S526_INT_STATUS_REG); + if (status & context) { + /* we got our eoc event, clear it */ + outw(context, dev->iobase + S526_INT_STATUS_REG); return 0; + } return -EBUSY; } -static int s526_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int s526_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { struct s526_private *devpriv = dev->private; unsigned int chan = CR_CHAN(insn->chanspec); - int n; - unsigned short value; - unsigned int d; + unsigned int ctrl; + unsigned int val; int ret; + int i; - /* Set configured delay, enable channel for this channel only, - * select "ADC read" channel, set "ADC start" bit. */ - value = (devpriv->ai_config & 0x8000) | - ((1 << 5) << chan) | (chan << 1) | 0x0001; + ctrl = S526_AI_CTRL_CONV(chan) | S526_AI_CTRL_READ(chan) | + S526_AI_CTRL_START; + if (ctrl != devpriv->ai_ctrl) { + /* + * The multiplexor needs to change, enable the 15us + * delay for the first sample. + */ + devpriv->ai_ctrl = ctrl; + ctrl |= S526_AI_CTRL_DELAY; + } - /* convert n samples */ - for (n = 0; n < insn->n; n++) { + for (i = 0; i < insn->n; i++) { /* trigger conversion */ - outw(value, dev->iobase + REG_ADC); + outw(ctrl, dev->iobase + S526_AI_CTRL_REG); + ctrl &= ~S526_AI_CTRL_DELAY; /* wait for conversion to end */ - ret = comedi_timeout(dev, s, insn, s526_ai_eoc, 0); + ret = comedi_timeout(dev, s, insn, s526_eoc, S526_INT_AI); if (ret) return ret; - outw(ISR_ADC_DONE, dev->iobase + REG_ISR); - - /* read data */ - d = inw(dev->iobase + REG_ADD); - - /* munge data */ - data[n] = d ^ 0x8000; + val = inw(dev->iobase + S526_AI_REG); + data[i] = comedi_offset_munge(s, val); } - /* return the number of samples read/written */ - return n; + return insn->n; } static int s526_ao_insn_write(struct comedi_device *dev, @@ -472,16 +422,23 @@ static int s526_ao_insn_write(struct comedi_device *dev, unsigned int *data) { unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int ctrl = S526_AO_CTRL_CHAN(chan); unsigned int val = s->readback[chan]; + int ret; int i; - outw(chan << 1, dev->iobase + REG_DAC); + outw(ctrl, dev->iobase + S526_AO_CTRL_REG); + ctrl |= S526_AO_CTRL_START; for (i = 0; i < insn->n; i++) { val = data[i]; - outw(val, dev->iobase + REG_ADD); - /* starts the D/A conversion */ - outw((chan << 1) | 1, dev->iobase + REG_DAC); + outw(val, dev->iobase + S526_AO_REG); + outw(ctrl, dev->iobase + S526_AO_CTRL_REG); + + /* wait for conversion to end */ + ret = comedi_timeout(dev, s, insn, s526_eoc, S526_INT_AO); + if (ret) + return ret; } s->readback[chan] = val; @@ -494,9 +451,9 @@ static int s526_dio_insn_bits(struct comedi_device *dev, unsigned int *data) { if (comedi_dio_update_state(s, data)) - outw(s->state, dev->iobase + REG_DIO); + outw(s->state, dev->iobase + S526_DIO_CTRL_REG); - data[1] = inw(dev->iobase + REG_DIO) & 0xff; + data[1] = inw(dev->iobase + S526_DIO_CTRL_REG) & 0xff; return insn->n; } @@ -510,6 +467,10 @@ static int s526_dio_insn_config(struct comedi_device *dev, unsigned int mask; int ret; + /* + * Digital I/O can be configured as inputs or outputs in + * groups of 4; DIO group 1 (DIO0-3) and DIO group 2 (DIO4-7). + */ if (chan < 4) mask = 0x0f; else @@ -519,17 +480,16 @@ static int s526_dio_insn_config(struct comedi_device *dev, if (ret) return ret; - /* bit 10/11 set the group 1/2's mode */ if (s->io_bits & 0x0f) - s->state |= (1 << 10); + s->state |= S526_DIO_CTRL_GRP1_OUT; else - s->state &= ~(1 << 10); + s->state &= ~S526_DIO_CTRL_GRP1_OUT; if (s->io_bits & 0xf0) - s->state |= (1 << 11); + s->state |= S526_DIO_CTRL_GRP2_OUT; else - s->state &= ~(1 << 11); + s->state &= ~S526_DIO_CTRL_GRP2_OUT; - outw(s->state, dev->iobase + REG_DIO); + outw(s->state, dev->iobase + S526_DIO_CTRL_REG); return insn->n; } @@ -552,51 +512,53 @@ static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it) if (ret) return ret; + /* General-Purpose Counter/Timer (GPCT) */ s = &dev->subdevices[0]; - /* GENERAL-PURPOSE COUNTER/TIME (GPCT) */ - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL; - s->n_chan = 4; - s->maxdata = 0x00ffffff; /* 24 bit counter */ - s->insn_read = s526_gpct_rinsn; - s->insn_config = s526_gpct_insn_config; - s->insn_write = s526_gpct_winsn; + s->type = COMEDI_SUBD_COUNTER; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL; + s->n_chan = 4; + s->maxdata = 0x00ffffff; + s->insn_read = s526_gpct_rinsn; + s->insn_config = s526_gpct_insn_config; + s->insn_write = s526_gpct_winsn; + /* + * Analog Input subdevice + * channels 0 to 7 are the regular differential inputs + * channel 8 is "reference 0" (+10V) + * channel 9 is "reference 1" (0V) + */ s = &dev->subdevices[1]; - /* analog input subdevice */ - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_DIFF; - /* channels 0 to 7 are the regular differential inputs */ - /* channel 8 is "reference 0" (+10V), channel 9 is "reference 1" (0V) */ - s->n_chan = 10; - s->maxdata = 0xffff; - s->range_table = &range_bipolar10; - s->len_chanlist = 16; - s->insn_read = s526_ai_rinsn; - s->insn_config = s526_ai_insn_config; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_DIFF; + s->n_chan = 10; + s->maxdata = 0xffff; + s->range_table = &range_bipolar10; + s->len_chanlist = 16; + s->insn_read = s526_ai_insn_read; + /* Analog Output subdevice */ s = &dev->subdevices[2]; - /* analog output subdevice */ - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 4; - s->maxdata = 0xffff; - s->range_table = &range_bipolar10; - s->insn_write = s526_ao_insn_write; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 4; + s->maxdata = 0xffff; + s->range_table = &range_bipolar10; + s->insn_write = s526_ao_insn_write; ret = comedi_alloc_subdev_readback(s); if (ret) return ret; + /* Digital I/O subdevice */ s = &dev->subdevices[3]; - /* digital i/o subdevice */ - s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE; - s->n_chan = 8; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_bits = s526_dio_insn_bits; - s->insn_config = s526_dio_insn_config; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = s526_dio_insn_bits; + s->insn_config = s526_dio_insn_config; return 0; } diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c index 5f19374c460d..7a1defcf2102 100644 --- a/drivers/staging/comedi/drivers/serial2002.c +++ b/drivers/staging/comedi/drivers/serial2002.c @@ -1,30 +1,29 @@ /* - comedi/drivers/serial2002.c - Skeleton code for a Comedi driver - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 2002 Anders Blomdell - - 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. -*/ + * serial2002.c + * Comedi driver for serial connected hardware + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2002 Anders Blomdell + * + * 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: serial2002 -Description: Driver for serial connected hardware -Devices: -Author: Anders Blomdell -Updated: Fri, 7 Jun 2002 12:56:45 -0700 -Status: in development - -*/ + * Driver: serial2002 + * Description: Driver for serial connected hardware + * Devices: + * Author: Anders Blomdell + * Updated: Fri, 7 Jun 2002 12:56:45 -0700 + * Status: in development + */ #include #include "../comedidev.h" @@ -102,7 +101,7 @@ static long serial2002_tty_ioctl(struct file *f, unsigned op, if (f->f_op->unlocked_ioctl) return f->f_op->unlocked_ioctl(f, op, param); - return -ENOSYS; + return -ENOTTY; } static int serial2002_tty_write(struct file *f, unsigned char *buf, int count) @@ -176,7 +175,7 @@ static int serial2002_tty_read(struct file *f, int timeout) result = ch; break; } - udelay(100); + usleep_range(100, 1000); } } set_fs(oldfs); diff --git a/drivers/staging/comedi/drivers/ssv_dnp.c b/drivers/staging/comedi/drivers/ssv_dnp.c index acc7f3445c58..f9f634fd53cf 100644 --- a/drivers/staging/comedi/drivers/ssv_dnp.c +++ b/drivers/staging/comedi/drivers/ssv_dnp.c @@ -1,28 +1,29 @@ /* - comedi/drivers/ssv_dnp.c - generic comedi driver for SSV Embedded Systems' DIL/Net-PCs - Copyright (C) 2001 Robert Schwebel + * ssv_dnp.c + * generic comedi driver for SSV Embedded Systems' DIL/Net-PCs + * Copyright (C) 2001 Robert Schwebel + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000 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 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. -*/ /* -Driver: ssv_dnp -Description: SSV Embedded Systems DIL/Net-PC -Author: Robert Schwebel -Devices: [SSV Embedded Systems] DIL/Net-PC 1486 (dnp-1486) -Status: unknown -*/ + * Driver: ssv_dnp + * Description: SSV Embedded Systems DIL/Net-PC + * Author: Robert Schwebel + * Devices: [SSV Embedded Systems] DIL/Net-PC 1486 (dnp-1486) + * Status: unknown + */ /* include files ----------------------------------------------------------- */ @@ -134,6 +135,12 @@ static int dnp_attach(struct comedi_device *dev, struct comedi_devconfig *it) struct comedi_subdevice *s; int ret; + /* + * We use I/O ports 0x22, 0x23 and 0xa3-0xa9, which are always + * allocated for the primary 8259, so we don't need to allocate + * them ourselves. + */ + ret = comedi_alloc_subdevices(dev, 1); if (ret) return ret; @@ -148,10 +155,6 @@ static int dnp_attach(struct comedi_device *dev, struct comedi_devconfig *it) s->insn_bits = dnp_dio_insn_bits; s->insn_config = dnp_dio_insn_config; - /* We use the I/O ports 0x22,0x23 and 0xa3-0xa9, which are always - * allocated for the primary 8259, so we don't need to allocate them - * ourselves. */ - /* configure all ports as input (default) */ outb(PAMR, CSCIR); outb(0x00, CSCDR); diff --git a/drivers/staging/comedi/drivers/unioxx5.c b/drivers/staging/comedi/drivers/unioxx5.c deleted file mode 100644 index 51498b889c6c..000000000000 --- a/drivers/staging/comedi/drivers/unioxx5.c +++ /dev/null @@ -1,506 +0,0 @@ -/*************************************************************************** - * * - * comedi/drivers/unioxx5.c * - * Driver for Fastwel UNIOxx-5 (analog and digital i/o) boards. * - * * - * Copyright (C) 2006 Kruchinin Daniil (asgard) [asgard@etersoft.ru] * - * * - * COMEDI - Linux Control and Measurement Device Interface * - * Copyright (C) 1998,2000 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. * - * * - ***************************************************************************/ -/* - -Driver: unioxx5 -Description: Driver for Fastwel UNIOxx-5 (analog and digital i/o) boards. -Author: Kruchinin Daniil (asgard) -Status: unknown -Updated: 2006-10-09 -Devices: [Fastwel] UNIOxx-5 (unioxx5), - - This card supports digital and analog I/O. It written for g01 - subdevices only. - channels range: 0 .. 23 dio channels - and 0 .. 11 analog modules range - During attaching unioxx5 module displays modules identifiers - (see dmesg after comedi_config) in format: - | [module_number] module_id | - -*/ - -#include -#include -#include "../comedidev.h" - -#define UNIOXX5_SIZE 0x10 -#define UNIOXX5_SUBDEV_BASE 0xA000 /* base addr of first subdev */ -#define UNIOXX5_SUBDEV_ODDS 0x400 - -/* modules types */ -#define MODULE_DIGITAL 0 -#define MODULE_OUTPUT_MASK 0x80 /* analog input/output */ - -/* constants for digital i/o */ -#define UNIOXX5_NUM_OF_CHANS 24 - -/* constants for analog i/o */ -#define TxBE 0x10 /* transmit buffer enable */ -#define RxCA 0x20 /* 1 receive character available */ -#define Rx2CA 0x40 /* 2 receive character available */ -#define Rx4CA 0x80 /* 4 receive character available */ - -/* bytes mask errors */ -#define Rx2CA_ERR_MASK 0x04 /* 2 bytes receiving error */ -#define Rx4CA_ERR_MASK 0x08 /* 4 bytes receiving error */ - -/* channel modes */ -#define ALL_2_INPUT 0 /* config all digital channels to input */ -#define ALL_2_OUTPUT 1 /* config all digital channels to output */ - -/* 'private' structure for each subdevice */ -struct unioxx5_subd_priv { - int usp_iobase; - /* 12 modules. each can be 70L or 73L */ - unsigned char usp_module_type[12]; - /* for saving previous written value for analog modules */ - unsigned char usp_extra_data[12][4]; - unsigned char usp_prev_wr_val[3]; /* previous written value */ - unsigned char usp_prev_cn_val[3]; /* previous channel value */ -}; - -static int __unioxx5_define_chan_offset(int chan_num) -{ - if (chan_num < 0 || chan_num > 23) - return -1; - - return (chan_num >> 3) + 1; -} - -#if 0 /* not used? */ -static void __unioxx5_digital_config(struct comedi_subdevice *s, int mode) -{ - struct unioxx5_subd_priv *usp = s->private; - struct device *csdev = s->device->class_dev; - int i, mask; - - mask = (mode == ALL_2_OUTPUT) ? 0xFF : 0x00; - dev_dbg(csdev, "mode = %d\n", mask); - - outb(1, usp->usp_iobase + 0); - - for (i = 0; i < 3; i++) - outb(mask, usp->usp_iobase + i); - - outb(0, usp->usp_iobase + 0); -} -#endif - -/* configure channels for analog i/o (even to output, odd to input) */ -static void __unioxx5_analog_config(struct unioxx5_subd_priv *usp, int channel) -{ - int chan_a, chan_b, conf, channel_offset; - - channel_offset = __unioxx5_define_chan_offset(channel); - conf = usp->usp_prev_cn_val[channel_offset - 1]; - chan_a = chan_b = 1; - - /* setting channel A and channel B mask */ - if (channel % 2 == 0) { - chan_a <<= channel & 0x07; - chan_b <<= (channel + 1) & 0x07; - } else { - chan_a <<= (channel - 1) & 0x07; - chan_b <<= channel & 0x07; - } - - conf |= chan_a; /* even channel ot output */ - conf &= ~chan_b; /* odd channel to input */ - - outb(1, usp->usp_iobase + 0); - outb(conf, usp->usp_iobase + channel_offset); - outb(0, usp->usp_iobase + 0); - - usp->usp_prev_cn_val[channel_offset - 1] = conf; -} - -static int __unioxx5_digital_read(struct comedi_subdevice *s, - unsigned int *data, int channel, int minor) -{ - struct unioxx5_subd_priv *usp = s->private; - struct device *csdev = s->device->class_dev; - int channel_offset, mask = 1 << (channel & 0x07); - - channel_offset = __unioxx5_define_chan_offset(channel); - if (channel_offset < 0) { - dev_err(csdev, - "undefined channel %d. channel range is 0 .. 23\n", - channel); - return 0; - } - - *data = inb(usp->usp_iobase + channel_offset); - *data &= mask; - - /* correct the read value to 0 or 1 */ - if (channel_offset > 1) - channel -= 2 << channel_offset; - *data >>= channel; - return 1; -} - -static int __unioxx5_analog_read(struct comedi_subdevice *s, - unsigned int *data, int channel, int minor) -{ - struct unioxx5_subd_priv *usp = s->private; - struct device *csdev = s->device->class_dev; - int module_no, read_ch; - char control; - - module_no = channel / 2; - read_ch = channel % 2; /* depend on type of channel (A or B) */ - - /* defining if given module can work on input */ - if (usp->usp_module_type[module_no] & MODULE_OUTPUT_MASK) { - dev_err(csdev, - "module in position %d with id 0x%02x is for output only", - module_no, usp->usp_module_type[module_no]); - return 0; - } - - __unioxx5_analog_config(usp, channel); - /* sends module number to card(1 .. 12) */ - outb(module_no + 1, usp->usp_iobase + 5); - outb('V', usp->usp_iobase + 6); /* sends to module (V)erify command */ - control = inb(usp->usp_iobase); /* get control register byte */ - - /* waits while reading four bytes will be allowed */ - while (!((control = inb(usp->usp_iobase + 0)) & Rx4CA)) - ; - - /* if four bytes readding error occurs - return 0(false) */ - if ((control & Rx4CA_ERR_MASK)) { - dev_err(csdev, "4 bytes error\n"); - return 0; - } - - if (read_ch) - *data = inw(usp->usp_iobase + 6); /* channel B */ - else - *data = inw(usp->usp_iobase + 4); /* channel A */ - - return 1; -} - -static int __unioxx5_digital_write(struct comedi_subdevice *s, - unsigned int *data, int channel, int minor) -{ - struct unioxx5_subd_priv *usp = s->private; - struct device *csdev = s->device->class_dev; - int channel_offset, val; - int mask = 1 << (channel & 0x07); - - channel_offset = __unioxx5_define_chan_offset(channel); - if (channel_offset < 0) { - dev_err(csdev, - "undefined channel %d. channel range is 0 .. 23\n", - channel); - return 0; - } - - /* getting previous written value */ - val = usp->usp_prev_wr_val[channel_offset - 1]; - - if (*data) - val |= mask; - else - val &= ~mask; - - outb(val, usp->usp_iobase + channel_offset); - /* saving new written value */ - usp->usp_prev_wr_val[channel_offset - 1] = val; - - return 1; -} - -static int __unioxx5_analog_write(struct comedi_subdevice *s, - unsigned int *data, int channel, int minor) -{ - struct unioxx5_subd_priv *usp = s->private; - struct device *csdev = s->device->class_dev; - int module, i; - - module = channel / 2; /* definig module number(0 .. 11) */ - i = (channel % 2) << 1; /* depends on type of channel (A or B) */ - - /* defining if given module can work on output */ - if (!(usp->usp_module_type[module] & MODULE_OUTPUT_MASK)) { - dev_err(csdev, - "module in position %d with id 0x%0x is for input only!\n", - module, usp->usp_module_type[module]); - return 0; - } - - __unioxx5_analog_config(usp, channel); - /* saving minor byte */ - usp->usp_extra_data[module][i++] = (unsigned char)(*data & 0x00FF); - /* saving major byte */ - usp->usp_extra_data[module][i] = (unsigned char)((*data & 0xFF00) >> 8); - - /* while(!((inb(usp->usp_iobase + 0)) & TxBE)); */ - /* sending module number to card(1 .. 12) */ - outb(module + 1, usp->usp_iobase + 5); - outb('W', usp->usp_iobase + 6); /* sends (W)rite command to module */ - - /* sending for bytes to module(one byte per cycle iteration) */ - for (i = 0; i < 4; i++) { - while (!((inb(usp->usp_iobase + 0)) & TxBE)) - ; /* waits while writing will be allowed */ - outb(usp->usp_extra_data[module][i], usp->usp_iobase + 6); - } - - return 1; -} - -static int unioxx5_subdev_read(struct comedi_device *dev, - struct comedi_subdevice *subdev, - struct comedi_insn *insn, unsigned int *data) -{ - struct unioxx5_subd_priv *usp = subdev->private; - int channel, type; - - channel = CR_CHAN(insn->chanspec); - /* defining module type(analog or digital) */ - type = usp->usp_module_type[channel / 2]; - - if (type == MODULE_DIGITAL) { - if (!__unioxx5_digital_read(subdev, data, channel, dev->minor)) - return -1; - } else { - if (!__unioxx5_analog_read(subdev, data, channel, dev->minor)) - return -1; - } - - return 1; -} - -static int unioxx5_subdev_write(struct comedi_device *dev, - struct comedi_subdevice *subdev, - struct comedi_insn *insn, unsigned int *data) -{ - struct unioxx5_subd_priv *usp = subdev->private; - int channel, type; - - channel = CR_CHAN(insn->chanspec); - /* defining module type(analog or digital) */ - type = usp->usp_module_type[channel / 2]; - - if (type == MODULE_DIGITAL) { - if (!__unioxx5_digital_write(subdev, data, channel, dev->minor)) - return -1; - } else { - if (!__unioxx5_analog_write(subdev, data, channel, dev->minor)) - return -1; - } - - return 1; -} - -/* for digital modules only */ -static int unioxx5_insn_config(struct comedi_device *dev, - struct comedi_subdevice *subdev, - struct comedi_insn *insn, unsigned int *data) -{ - int channel_offset, flags, channel = CR_CHAN(insn->chanspec), type; - struct unioxx5_subd_priv *usp = subdev->private; - int mask = 1 << (channel & 0x07); - - type = usp->usp_module_type[channel / 2]; - - if (type != MODULE_DIGITAL) { - dev_err(dev->class_dev, - "channel configuration accessible only for digital modules\n"); - return -1; - } - - channel_offset = __unioxx5_define_chan_offset(channel); - if (channel_offset < 0) { - dev_err(dev->class_dev, - "undefined channel %d. channel range is 0 .. 23\n", - channel); - return -1; - } - - /* gets previously written value */ - flags = usp->usp_prev_cn_val[channel_offset - 1]; - - switch (*data) { - case COMEDI_INPUT: - flags &= ~mask; - break; - case COMEDI_OUTPUT: - flags |= mask; - break; - default: - dev_err(dev->class_dev, "unknown flag\n"); - return -1; - } - - /* *\ - * sets channels buffer to 1(after this we are allowed to * - * change channel type on input or output) * - \* */ - outb(1, usp->usp_iobase + 0); - /* changes type of _one_ channel */ - outb(flags, usp->usp_iobase + channel_offset); - /* sets channels bank to 0(allows directly input/output) */ - outb(0, usp->usp_iobase + 0); - /* saves written value */ - usp->usp_prev_cn_val[channel_offset - 1] = flags; - - return 0; -} - -/* initializing subdevice with given address */ -static int __unioxx5_subdev_init(struct comedi_device *dev, - struct comedi_subdevice *s, - int iobase) -{ - struct unioxx5_subd_priv *usp; - int i, to, ndef_flag = 0; - int ret; - - usp = comedi_alloc_spriv(s, sizeof(*usp)); - if (!usp) - return -ENOMEM; - - ret = __comedi_request_region(dev, iobase, UNIOXX5_SIZE); - if (ret) - return ret; - usp->usp_iobase = iobase; - - /* defining modules types */ - for (i = 0; i < 12; i++) { - to = 10000; - - __unioxx5_analog_config(usp, i * 2); - /* sends channel number to card */ - outb(i + 1, iobase + 5); - outb('H', iobase + 6); /* requests EEPROM world */ - while (!(inb(iobase + 0) & TxBE)) - ; /* waits while writing will be allowed */ - outb(0, iobase + 6); - - /* waits while reading of two bytes will be allowed */ - while (!(inb(iobase + 0) & Rx2CA)) { - if (--to <= 0) { - ndef_flag = 1; - break; - } - } - - if (ndef_flag) { - usp->usp_module_type[i] = 0; - ndef_flag = 0; - } else { - usp->usp_module_type[i] = inb(iobase + 6); - } - - udelay(1); - } - - /* initial subdevice for digital or analog i/o */ - s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE; - s->n_chan = UNIOXX5_NUM_OF_CHANS; - s->maxdata = 0xFFF; - s->range_table = &range_digital; - s->insn_read = unioxx5_subdev_read; - s->insn_write = unioxx5_subdev_write; - /* for digital modules only!!! */ - s->insn_config = unioxx5_insn_config; - - return 0; -} - -static int unioxx5_attach(struct comedi_device *dev, - struct comedi_devconfig *it) -{ - struct comedi_subdevice *s; - int iobase, i, n_subd; - int id, num, ba; - int ret; - - iobase = it->options[0]; - - dev->iobase = iobase; - iobase += UNIOXX5_SUBDEV_BASE; - n_subd = 0; - - /* getting number of subdevices with types 'g01' */ - for (i = 0, ba = iobase; i < 4; i++, ba += UNIOXX5_SUBDEV_ODDS) { - id = inb(ba + 0xE); - num = inb(ba + 0xF); - - if (id != 'g' || num != 1) - continue; - - n_subd++; - } - - /* unioxx5 can has from two to four subdevices */ - if (n_subd < 2) { - dev_err(dev->class_dev, - "your card must has at least 2 'g01' subdevices\n"); - return -1; - } - - ret = comedi_alloc_subdevices(dev, n_subd); - if (ret) - return ret; - - /* initializing each of for same subdevices */ - for (i = 0; i < n_subd; i++, iobase += UNIOXX5_SUBDEV_ODDS) { - s = &dev->subdevices[i]; - ret = __unioxx5_subdev_init(dev, s, iobase); - if (ret) - return ret; - } - - return 0; -} - -static void unioxx5_detach(struct comedi_device *dev) -{ - struct comedi_subdevice *s; - struct unioxx5_subd_priv *spriv; - int i; - - for (i = 0; i < dev->n_subdevices; i++) { - s = &dev->subdevices[i]; - spriv = s->private; - if (spriv && spriv->usp_iobase) - release_region(spriv->usp_iobase, UNIOXX5_SIZE); - } -} - -static struct comedi_driver unioxx5_driver = { - .driver_name = "unioxx5", - .module = THIS_MODULE, - .attach = unioxx5_attach, - .detach = unioxx5_detach, -}; -module_comedi_driver(unioxx5_driver); - -MODULE_AUTHOR("Comedi http://www.comedi.org"); -MODULE_DESCRIPTION("Comedi low-level driver"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c index ced05e581620..f4f05d29d30d 100644 --- a/drivers/staging/comedi/drivers/usbdux.c +++ b/drivers/staging/comedi/drivers/usbdux.c @@ -108,55 +108,55 @@ #define BULK_TIMEOUT 1000 /* 300Hz max frequ under PWM */ -#define MIN_PWM_PERIOD ((long)(1E9/300)) +#define MIN_PWM_PERIOD ((long)(1E9 / 300)) /* Default PWM frequency */ -#define PWM_DEFAULT_PERIOD ((long)(1E9/100)) +#define PWM_DEFAULT_PERIOD ((long)(1E9 / 100)) /* Size of one A/D value */ -#define SIZEADIN ((sizeof(uint16_t))) +#define SIZEADIN ((sizeof(u16))) /* * Size of the input-buffer IN BYTES * Always multiple of 8 for 8 microframes which is needed in the highspeed mode */ -#define SIZEINBUF ((8*SIZEADIN)) +#define SIZEINBUF (8 * SIZEADIN) /* 16 bytes. */ -#define SIZEINSNBUF 16 +#define SIZEINSNBUF 16 /* size of one value for the D/A converter: channel and value */ -#define SIZEDAOUT ((sizeof(uint8_t)+sizeof(uint16_t))) +#define SIZEDAOUT ((sizeof(u8) + sizeof(u16))) /* * Size of the output-buffer in bytes * Actually only the first 4 triplets are used but for the * high speed mode we need to pad it to 8 (microframes). */ -#define SIZEOUTBUF ((8*SIZEDAOUT)) +#define SIZEOUTBUF (8 * SIZEDAOUT) /* * Size of the buffer for the dux commands: just now max size is determined * by the analogue out + command byte + panic bytes... */ -#define SIZEOFDUXBUFFER ((8*SIZEDAOUT+2)) +#define SIZEOFDUXBUFFER (8 * SIZEDAOUT + 2) /* Number of in-URBs which receive the data: min=2 */ -#define NUMOFINBUFFERSFULL 5 +#define NUMOFINBUFFERSFULL 5 /* Number of out-URBs which send the data: min=2 */ -#define NUMOFOUTBUFFERSFULL 5 +#define NUMOFOUTBUFFERSFULL 5 /* Number of in-URBs which receive the data: min=5 */ /* must have more buffers due to buggy USB ctr */ -#define NUMOFINBUFFERSHIGH 10 +#define NUMOFINBUFFERSHIGH 10 /* Number of out-URBs which send the data: min=5 */ /* must have more buffers due to buggy USB ctr */ -#define NUMOFOUTBUFFERSHIGH 10 +#define NUMOFOUTBUFFERSHIGH 10 /* number of retries to get the right dux command */ -#define RETRIES 10 +#define RETRIES 10 static const struct comedi_lrange range_usbdux_ai_range = { 4, { @@ -187,7 +187,7 @@ struct usbdux_private { /* PWM period */ unsigned int pwm_period; /* PWM internal delay for the GPIF in the FX2 */ - uint8_t pwm_delay; + u8 pwm_delay; /* size of the PWM buffer which holds the bit pattern */ int pwm_buf_sz; /* input buffer for the ISO-transfer */ @@ -209,8 +209,8 @@ struct usbdux_private { /* interval in frames/uframes */ unsigned int ai_interval; /* commands */ - uint8_t *dux_commands; - struct semaphore sem; + u8 *dux_commands; + struct mutex mut; }; static void usbdux_unlink_urbs(struct urb **urbs, int num_urbs) @@ -237,10 +237,10 @@ static int usbdux_ai_cancel(struct comedi_device *dev, struct usbdux_private *devpriv = dev->private; /* prevent other CPUs from submitting new commands just now */ - down(&devpriv->sem); + mutex_lock(&devpriv->mut); /* unlink only if the urb really has been submitted */ usbdux_ai_stop(dev, devpriv->ai_cmd_running); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return 0; } @@ -262,11 +262,11 @@ static void usbduxsub_ai_handle_urb(struct comedi_device *dev, /* get the data from the USB bus and hand it over to comedi */ for (i = 0; i < cmd->chanlist_len; i++) { unsigned int range = CR_RANGE(cmd->chanlist[i]); - uint16_t val = le16_to_cpu(devpriv->in_buf[i]); + u16 val = le16_to_cpu(devpriv->in_buf[i]); /* bipolar data is two's-complement */ if (comedi_range_is_bipolar(s, range)) - val ^= ((s->maxdata + 1) >> 1); + val = comedi_offset_munge(s, val); /* transfer data */ if (!comedi_buf_write_samples(s, &val, 1)) @@ -365,10 +365,10 @@ static int usbdux_ao_cancel(struct comedi_device *dev, struct usbdux_private *devpriv = dev->private; /* prevent other CPUs from submitting a command just now */ - down(&devpriv->sem); + mutex_lock(&devpriv->mut); /* unlink only if it is really running */ usbdux_ao_stop(dev, devpriv->ao_cmd_running); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return 0; } @@ -380,7 +380,7 @@ static void usbduxsub_ao_handle_urb(struct comedi_device *dev, struct usbdux_private *devpriv = dev->private; struct comedi_async *async = s->async; struct comedi_cmd *cmd = &async->cmd; - uint8_t *datap; + u8 *datap; int ret; int i; @@ -516,9 +516,8 @@ static int usbdux_submit_urbs(struct comedi_device *dev, static int usbdux_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) { - struct usbdux_private *this_usbduxsub = dev->private; - int err = 0, i; - unsigned int tmp_timer; + struct usbdux_private *devpriv = dev->private; + int err = 0; /* Step 1 : check if triggers are trivially valid */ @@ -549,40 +548,31 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev, err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0); if (cmd->scan_begin_src == TRIG_TIMER) { - if (this_usbduxsub->high_speed) { + /* full speed does 1kHz scans every USB frame */ + unsigned int arg = 1000000; + unsigned int min_arg = arg; + + if (devpriv->high_speed) { /* * In high speed mode microframes are possible. * However, during one microframe we can roughly * sample one channel. Thus, the more channels * are in the channel list the more time we need. */ - i = 1; + int i = 1; + /* find a power of 2 for the number of channels */ - while (i < (cmd->chanlist_len)) + while (i < cmd->chanlist_len) i = i * 2; - err |= comedi_check_trigger_arg_min(&cmd-> - scan_begin_arg, - 1000000 / 8 * i); - /* now calc the real sampling rate with all the - * rounding errors */ - tmp_timer = - ((unsigned int)(cmd->scan_begin_arg / 125000)) * - 125000; - } else { - /* full speed */ - /* 1kHz scans every USB frame */ - err |= comedi_check_trigger_arg_min(&cmd-> - scan_begin_arg, - 1000000); - /* - * calc the real sampling rate with the rounding errors - */ - tmp_timer = ((unsigned int)(cmd->scan_begin_arg / - 1000000)) * 1000000; + arg /= 8; + min_arg = arg * i; } - err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, - tmp_timer); + err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg, + min_arg); + /* calc the real sampling rate with the rounding errors */ + arg = (cmd->scan_begin_arg / arg) * arg; + err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg); } err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, @@ -603,10 +593,10 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev, * creates the ADC command for the MAX1271 * range is the range value from comedi */ -static uint8_t create_adc_command(unsigned int chan, unsigned int range) +static u8 create_adc_command(unsigned int chan, unsigned int range) { - uint8_t p = (range <= 1); - uint8_t r = ((range % 2) == 0); + u8 p = (range <= 1); + u8 r = ((range % 2) == 0); return (chan << 4) | ((p == 1) << 2) | ((r == 1) << 3); } @@ -656,7 +646,7 @@ static int usbdux_ai_inttrig(struct comedi_device *dev, if (trig_num != cmd->start_arg) return -EINVAL; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (!devpriv->ai_cmd_running) { devpriv->ai_cmd_running = 1; @@ -672,7 +662,7 @@ static int usbdux_ai_inttrig(struct comedi_device *dev, } ai_trig_exit: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -685,7 +675,7 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) int i; /* block other CPUs from starting an ai_cmd */ - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (devpriv->ai_cmd_running) goto ai_cmd_exit; @@ -746,7 +736,7 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) } ai_cmd_exit: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -764,7 +754,7 @@ static int usbdux_ai_insn_read(struct comedi_device *dev, int ret = -EBUSY; int i; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (devpriv->ai_cmd_running) goto ai_read_exit; @@ -786,13 +776,13 @@ static int usbdux_ai_insn_read(struct comedi_device *dev, /* bipolar data is two's-complement */ if (comedi_range_is_bipolar(s, range)) - val ^= ((s->maxdata + 1) >> 1); + val = comedi_offset_munge(s, val); data[i] = val; } ai_read_exit: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret ? ret : insn->n; } @@ -805,9 +795,9 @@ static int usbdux_ao_insn_read(struct comedi_device *dev, struct usbdux_private *devpriv = dev->private; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); ret = comedi_readback_insn_read(dev, s, insn, data); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -824,7 +814,7 @@ static int usbdux_ao_insn_write(struct comedi_device *dev, int ret = -EBUSY; int i; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (devpriv->ao_cmd_running) goto ao_write_exit; @@ -848,7 +838,7 @@ static int usbdux_ao_insn_write(struct comedi_device *dev, } ao_write_exit: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret ? ret : insn->n; } @@ -864,7 +854,7 @@ static int usbdux_ao_inttrig(struct comedi_device *dev, if (trig_num != cmd->start_arg) return -EINVAL; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (!devpriv->ao_cmd_running) { devpriv->ao_cmd_running = 1; @@ -880,25 +870,21 @@ static int usbdux_ao_inttrig(struct comedi_device *dev, } ao_trig_exit: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } static int usbdux_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) { - struct usbdux_private *this_usbduxsub = dev->private; int err = 0; unsigned int flags; - if (!this_usbduxsub) - return -EFAULT; - /* Step 1 : check if triggers are trivially valid */ err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT); - if (0) { /* (this_usbduxsub->high_speed) */ + if (0) { /* (devpriv->high_speed) */ /* the sampling rate is set by the coversion rate */ flags = TRIG_FOLLOW; } else { @@ -907,7 +893,7 @@ static int usbdux_ao_cmdtest(struct comedi_device *dev, } err |= comedi_check_trigger_src(&cmd->scan_begin_src, flags); - if (0) { /* (this_usbduxsub->high_speed) */ + if (0) { /* (devpriv->high_speed) */ /* * in usb-2.0 only one conversion it transmitted * but with 8kHz/n @@ -974,7 +960,7 @@ static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s) struct comedi_cmd *cmd = &s->async->cmd; int ret = -EBUSY; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (devpriv->ao_cmd_running) goto ao_cmd_exit; @@ -1016,7 +1002,7 @@ static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s) } ao_cmd_exit: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -1047,7 +1033,7 @@ static int usbdux_dio_insn_bits(struct comedi_device *dev, struct usbdux_private *devpriv = dev->private; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); comedi_dio_update_state(s, data); @@ -1069,7 +1055,7 @@ static int usbdux_dio_insn_bits(struct comedi_device *dev, data[1] = le16_to_cpu(devpriv->insn_buf[1]); dio_exit: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret ? ret : insn->n; } @@ -1084,7 +1070,7 @@ static int usbdux_counter_read(struct comedi_device *dev, int ret = 0; int i; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); for (i = 0; i < insn->n; i++) { ret = send_dux_commands(dev, USBDUX_CMD_TIMER_RD); @@ -1098,7 +1084,7 @@ static int usbdux_counter_read(struct comedi_device *dev, } counter_read_exit: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret ? ret : insn->n; } @@ -1114,7 +1100,7 @@ static int usbdux_counter_write(struct comedi_device *dev, int ret = 0; int i; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); devpriv->dux_commands[1] = chan; @@ -1126,7 +1112,7 @@ static int usbdux_counter_write(struct comedi_device *dev, break; } - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret ? ret : insn->n; } @@ -1162,11 +1148,11 @@ static int usbdux_pwm_cancel(struct comedi_device *dev, struct usbdux_private *devpriv = dev->private; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); /* unlink only if it is really running */ usbdux_pwm_stop(dev, devpriv->pwm_cmd_running); ret = send_dux_commands(dev, USBDUX_CMD_PWM_OFF); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -1271,7 +1257,7 @@ static int usbdux_pwm_start(struct comedi_device *dev, struct usbdux_private *devpriv = dev->private; int ret = 0; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (devpriv->pwm_cmd_running) goto pwm_start_exit; @@ -1290,7 +1276,7 @@ static int usbdux_pwm_start(struct comedi_device *dev, devpriv->pwm_cmd_running = 0; pwm_start_exit: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -1391,8 +1377,8 @@ static int usbdux_firmware_upload(struct comedi_device *dev, unsigned long context) { struct usb_device *usb = comedi_to_usb_dev(dev); - uint8_t *buf; - uint8_t *tmp; + u8 *buf; + u8 *tmp; int ret; if (!data) @@ -1590,7 +1576,7 @@ static int usbdux_auto_attach(struct comedi_device *dev, if (!devpriv) return -ENOMEM; - sema_init(&devpriv->sem, 1); + mutex_init(&devpriv->mut); usb_set_intfdata(intf, devpriv); @@ -1705,7 +1691,7 @@ static void usbdux_detach(struct comedi_device *dev) if (!devpriv) return; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); /* force unlink all urbs */ usbdux_pwm_stop(dev, 1); @@ -1714,7 +1700,7 @@ static void usbdux_detach(struct comedi_device *dev) usbdux_free_usb_buffers(dev); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); } static struct comedi_driver usbdux_driver = { diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c index d90dc59982be..10f94ec34536 100644 --- a/drivers/staging/comedi/drivers/usbduxfast.c +++ b/drivers/staging/comedi/drivers/usbduxfast.c @@ -97,7 +97,7 @@ /* * size of one A/D value */ -#define SIZEADIN (sizeof(int16_t)) +#define SIZEADIN (sizeof(s16)) /* * size of the input-buffer IN BYTES @@ -156,12 +156,11 @@ static const struct comedi_lrange range_usbduxfast_ai_range = { */ struct usbduxfast_private { struct urb *urb; /* BULK-transfer handling: urb */ - uint8_t *duxbuf; - int8_t *inbuf; + u8 *duxbuf; + s8 *inbuf; short int ai_cmd_running; /* asynchronous command is running */ - int ignore; /* counter which ignores the first - buffers */ - struct semaphore sem; + int ignore; /* counter which ignores the first buffers */ + struct mutex mut; }; /* @@ -190,8 +189,7 @@ static int usbduxfast_send_cmd(struct comedi_device *dev, int cmd_type) } static void usbduxfast_cmd_data(struct comedi_device *dev, int index, - uint8_t len, uint8_t op, uint8_t out, - uint8_t log) + u8 len, u8 op, u8 out, u8 log) { struct usbduxfast_private *devpriv = dev->private; @@ -223,12 +221,9 @@ static int usbduxfast_ai_cancel(struct comedi_device *dev, struct usbduxfast_private *devpriv = dev->private; int ret; - if (!devpriv) - return -EFAULT; - - down(&devpriv->sem); + mutex_lock(&devpriv->mut); ret = usbduxfast_ai_stop(dev, 1); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -317,9 +312,6 @@ static int usbduxfast_submit_urb(struct comedi_device *dev) struct usbduxfast_private *devpriv = dev->private; int ret; - if (!devpriv) - return -EFAULT; - usb_fill_bulk_urb(devpriv->urb, usb, usb_rcvbulkpipe(usb, BULKINEP), devpriv->inbuf, SIZEINBUF, usbduxfast_ai_interrupt, dev); @@ -332,22 +324,50 @@ static int usbduxfast_submit_urb(struct comedi_device *dev) return 0; } +static int usbduxfast_ai_check_chanlist(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_cmd *cmd) +{ + unsigned int gain0 = CR_RANGE(cmd->chanlist[0]); + int i; + + if (cmd->chanlist_len > 3 && cmd->chanlist_len != 16) { + dev_err(dev->class_dev, "unsupported combination of channels\n"); + return -EINVAL; + } + + for (i = 0; i < cmd->chanlist_len; ++i) { + unsigned int chan = CR_CHAN(cmd->chanlist[i]); + unsigned int gain = CR_RANGE(cmd->chanlist[i]); + + if (chan != i) { + dev_err(dev->class_dev, + "channels are not consecutive\n"); + return -EINVAL; + } + if (gain != gain0 && cmd->chanlist_len > 3) { + dev_err(dev->class_dev, + "gain must be the same for all channels\n"); + return -EINVAL; + } + } + return 0; +} + static int usbduxfast_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) { int err = 0; - long int steps, tmp; - int min_sample_period; + unsigned int steps; + unsigned int arg; /* Step 1 : check if triggers are trivially valid */ err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT | TRIG_INT); - err |= comedi_check_trigger_src(&cmd->scan_begin_src, - TRIG_FOLLOW | TRIG_EXT); - err |= comedi_check_trigger_src(&cmd->convert_src, - TRIG_TIMER | TRIG_EXT); + err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW); + err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_TIMER); err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); @@ -357,16 +377,10 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev, /* Step 2a : make sure trigger sources are unique */ err |= comedi_check_trigger_is_unique(cmd->start_src); - err |= comedi_check_trigger_is_unique(cmd->scan_begin_src); - err |= comedi_check_trigger_is_unique(cmd->convert_src); err |= comedi_check_trigger_is_unique(cmd->stop_src); /* Step 2b : and mutually compatible */ - /* can't have external stop and start triggers at once */ - if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT) - err |= -EINVAL; - if (err) return 2; @@ -377,47 +391,44 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev, if (!cmd->chanlist_len) err |= -EINVAL; + /* external start trigger is only valid for 1 or 16 channels */ + if (cmd->start_src == TRIG_EXT && + cmd->chanlist_len != 1 && cmd->chanlist_len != 16) + err |= -EINVAL; + err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); - if (cmd->chanlist_len == 1) - min_sample_period = 1; - else - min_sample_period = MIN_SAMPLING_PERIOD; + /* + * Validate the conversion timing: + * for 1 channel the timing in 30MHz "steps" is: + * steps <= MAX_SAMPLING_PERIOD + * for all other chanlist_len it is: + * MIN_SAMPLING_PERIOD <= steps <= MAX_SAMPLING_PERIOD + */ + steps = (cmd->convert_arg * 30) / 1000; + if (cmd->chanlist_len != 1) + err |= comedi_check_trigger_arg_min(&steps, + MIN_SAMPLING_PERIOD); + err |= comedi_check_trigger_arg_max(&steps, MAX_SAMPLING_PERIOD); + arg = (steps * 1000) / 30; + err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg); - if (cmd->convert_src == TRIG_TIMER) { - steps = cmd->convert_arg * 30; - if (steps < (min_sample_period * 1000)) - steps = min_sample_period * 1000; - - if (steps > (MAX_SAMPLING_PERIOD * 1000)) - steps = MAX_SAMPLING_PERIOD * 1000; - - /* calc arg again */ - tmp = steps / 30; - err |= comedi_check_trigger_arg_is(&cmd->convert_arg, tmp); - } - - /* stop source */ - switch (cmd->stop_src) { - case TRIG_COUNT: + if (cmd->stop_src == TRIG_COUNT) err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1); - break; - case TRIG_NONE: + else /* TRIG_NONE */ err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0); - break; - /* - * TRIG_EXT doesn't care since it doesn't trigger - * off a numbered channel - */ - default: - break; - } if (err) return 3; - /* step 4: fix up any arguments */ + /* Step 4: fix up any arguments */ + + /* Step 5: check channel list if it exists */ + if (cmd->chanlist && cmd->chanlist_len > 0) + err |= usbduxfast_ai_check_chanlist(dev, s, cmd); + if (err) + return 5; return 0; } @@ -430,13 +441,10 @@ static int usbduxfast_ai_inttrig(struct comedi_device *dev, struct comedi_cmd *cmd = &s->async->cmd; int ret; - if (!devpriv) - return -EFAULT; - if (trig_num != cmd->start_arg) return -EINVAL; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (!devpriv->ai_cmd_running) { devpriv->ai_cmd_running = 1; @@ -444,14 +452,14 @@ static int usbduxfast_ai_inttrig(struct comedi_device *dev, if (ret < 0) { dev_err(dev->class_dev, "urbSubmit: err=%d\n", ret); devpriv->ai_cmd_running = 0; - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } s->async->inttrig = NULL; } else { dev_err(dev->class_dev, "ai is already running\n"); } - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return 1; } @@ -460,19 +468,14 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, { struct usbduxfast_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; - unsigned int chan, gain, rngmask = 0xff; - int i, j, ret; - int result; + unsigned int rngmask = 0xff; + int j, ret; long steps, steps_tmp; - if (!devpriv) - return -EFAULT; - - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (devpriv->ai_cmd_running) { - dev_err(dev->class_dev, "ai_cmd not possible\n"); - up(&devpriv->sem); - return -EBUSY; + ret = -EBUSY; + goto cmd_exit; } /* @@ -481,50 +484,7 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, */ devpriv->ignore = PACKETS_TO_IGNORE; - gain = CR_RANGE(cmd->chanlist[0]); - for (i = 0; i < cmd->chanlist_len; ++i) { - chan = CR_CHAN(cmd->chanlist[i]); - if (chan != i) { - dev_err(dev->class_dev, - "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, - "gain must be the same for all channels\n"); - up(&devpriv->sem); - return -EINVAL; - } - if (i >= NUMCHANNELS) { - dev_err(dev->class_dev, "chanlist too long\n"); - break; - } - } - steps = 0; - if (cmd->convert_src == TRIG_TIMER) - steps = (cmd->convert_arg * 30) / 1000; - - if ((steps < MIN_SAMPLING_PERIOD) && (cmd->chanlist_len != 1)) { - dev_err(dev->class_dev, - "steps=%ld, scan_begin_arg=%d. Not properly tested by cmdtest?\n", - steps, cmd->scan_begin_arg); - up(&devpriv->sem); - return -EINVAL; - } - if (steps > MAX_SAMPLING_PERIOD) { - 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, - "TRIG_EXT only with 1 or 16 channels possible\n"); - up(&devpriv->sem); - return -EINVAL; - } + steps = (cmd->convert_arg * 30) / 1000; switch (cmd->chanlist_len) { case 1: @@ -769,19 +729,12 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, usbduxfast_cmd_data(dev, 4, 0x09, 0x01, rngmask, 0xff); break; - - default: - dev_err(dev->class_dev, "unsupported combination of channels\n"); - up(&devpriv->sem); - return -EFAULT; } /* 0 means that the AD commands are sent */ - result = usbduxfast_send_cmd(dev, SENDADCOMMANDS); - if (result < 0) { - up(&devpriv->sem); - return result; - } + ret = usbduxfast_send_cmd(dev, SENDADCOMMANDS); + if (ret < 0) + goto cmd_exit; if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) { /* enable this acquisition operation */ @@ -790,16 +743,17 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev, if (ret < 0) { devpriv->ai_cmd_running = 0; /* fixme: unlink here?? */ - up(&devpriv->sem); - return ret; + goto cmd_exit; } s->async->inttrig = NULL; } else { /* TRIG_INT */ s->async->inttrig = usbduxfast_ai_inttrig; } - up(&devpriv->sem); - return 0; +cmd_exit: + mutex_unlock(&devpriv->mut); + + return ret; } /* @@ -814,16 +768,16 @@ static int usbduxfast_ai_insn_read(struct comedi_device *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; + u8 rngmask = range ? (0xff - 0x04) : 0xff; int i, j, n, actual_length; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (devpriv->ai_cmd_running) { dev_err(dev->class_dev, "ai_insn_read not possible, async cmd is running\n"); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return -EBUSY; } @@ -845,7 +799,7 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev, ret = usbduxfast_send_cmd(dev, SENDADCOMMANDS); if (ret < 0) { - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -855,7 +809,7 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev, &actual_length, 10000); if (ret < 0) { dev_err(dev->class_dev, "insn timeout, no data\n"); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } } @@ -866,65 +820,32 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev, &actual_length, 10000); if (ret < 0) { dev_err(dev->class_dev, "insn data error: %d\n", ret); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } - n = actual_length / sizeof(uint16_t); + n = actual_length / sizeof(u16); if ((n % 16) != 0) { dev_err(dev->class_dev, "insn data packet corrupted\n"); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return -EINVAL; } for (j = chan; (j < n) && (i < insn->n); j = j + 16) { - data[i] = ((uint16_t *) (devpriv->inbuf))[j]; + data[i] = ((u16 *)(devpriv->inbuf))[j]; i++; } } - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return insn->n; } -static int usbduxfast_attach_common(struct comedi_device *dev) -{ - struct usbduxfast_private *devpriv = dev->private; - struct comedi_subdevice *s; - int ret; - - 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; + u8 *buf; unsigned char *tmp; int ret; @@ -996,6 +917,7 @@ static int usbduxfast_auto_attach(struct comedi_device *dev, struct usb_interface *intf = comedi_to_usb_interface(dev); struct usb_device *usb = comedi_to_usb_dev(dev); struct usbduxfast_private *devpriv; + struct comedi_subdevice *s; int ret; if (usb->speed != USB_SPEED_HIGH) { @@ -1008,7 +930,7 @@ static int usbduxfast_auto_attach(struct comedi_device *dev, if (!devpriv) return -ENOMEM; - sema_init(&devpriv->sem, 1); + mutex_init(&devpriv->mut); usb_set_intfdata(intf, devpriv); devpriv->duxbuf = kmalloc(SIZEOFDUXBUF, GFP_KERNEL); @@ -1038,7 +960,25 @@ static int usbduxfast_auto_attach(struct comedi_device *dev, if (ret) return ret; - return usbduxfast_attach_common(dev); + ret = comedi_alloc_subdevices(dev, 1); + if (ret) + 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->maxdata = 0x1000; /* 12-bit + 1 overflow bit */ + s->range_table = &range_usbduxfast_ai_range; + s->insn_read = usbduxfast_ai_insn_read; + s->len_chanlist = s->n_chan; + s->do_cmdtest = usbduxfast_ai_cmdtest; + s->do_cmd = usbduxfast_ai_cmd; + s->cancel = usbduxfast_ai_cancel; + + return 0; } static void usbduxfast_detach(struct comedi_device *dev) @@ -1049,7 +989,7 @@ static void usbduxfast_detach(struct comedi_device *dev) if (!devpriv) return; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); usb_set_intfdata(intf, NULL); @@ -1058,18 +998,12 @@ static void usbduxfast_detach(struct comedi_device *dev) 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); + mutex_unlock(&devpriv->mut); } static struct comedi_driver usbduxfast_driver = { diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c index 649cf47184a4..456e9f13becb 100644 --- a/drivers/staging/comedi/drivers/usbduxsigma.c +++ b/drivers/staging/comedi/drivers/usbduxsigma.c @@ -66,22 +66,22 @@ #define USBDUXSUB_CPUCS 0xE600 /* 300Hz max frequ under PWM */ -#define MIN_PWM_PERIOD ((long)(1E9/300)) +#define MIN_PWM_PERIOD ((long)(1E9 / 300)) /* Default PWM frequency */ -#define PWM_DEFAULT_PERIOD ((long)(1E9/100)) +#define PWM_DEFAULT_PERIOD ((long)(1E9 / 100)) /* Number of channels (16 AD and offset)*/ #define NUMCHANNELS 16 /* Size of one A/D value */ -#define SIZEADIN ((sizeof(uint32_t))) +#define SIZEADIN ((sizeof(u32))) /* * Size of the async input-buffer IN BYTES, the DIO state is transmitted * as the first byte. */ -#define SIZEINBUF (((NUMCHANNELS+1)*SIZEADIN)) +#define SIZEINBUF (((NUMCHANNELS + 1) * SIZEADIN)) /* 16 bytes. */ #define SIZEINSNBUF 16 @@ -90,20 +90,20 @@ #define NUMOUTCHANNELS 8 /* size of one value for the D/A converter: channel and value */ -#define SIZEDAOUT ((sizeof(uint8_t)+sizeof(uint16_t))) +#define SIZEDAOUT ((sizeof(u8) + sizeof(uint16_t))) /* * Size of the output-buffer in bytes * Actually only the first 4 triplets are used but for the * high speed mode we need to pad it to 8 (microframes). */ -#define SIZEOUTBUF ((8*SIZEDAOUT)) +#define SIZEOUTBUF ((8 * SIZEDAOUT)) /* * Size of the buffer for the dux commands: just now max size is determined * by the analogue out + command byte + panic bytes... */ -#define SIZEOFDUXBUFFER ((8*SIZEDAOUT+2)) +#define SIZEOFDUXBUFFER ((8 * SIZEDAOUT + 2)) /* Number of in-URBs which receive the data: min=2 */ #define NUMOFINBUFFERSFULL 5 @@ -150,13 +150,13 @@ struct usbduxsigma_private { /* PWM period */ unsigned int pwm_period; /* PWM internal delay for the GPIF in the FX2 */ - uint8_t pwm_delay; + u8 pwm_delay; /* size of the PWM buffer which holds the bit pattern */ int pwm_buf_sz; /* input buffer for the ISO-transfer */ __be32 *in_buf; /* input buffer for single insn */ - uint8_t *insn_buf; + u8 *insn_buf; unsigned high_speed:1; unsigned ai_cmd_running:1; @@ -172,8 +172,8 @@ struct usbduxsigma_private { /* interval in frames/uframes */ unsigned int ai_interval; /* commands */ - uint8_t *dux_commands; - struct semaphore sem; + u8 *dux_commands; + struct mutex mut; }; static void usbduxsigma_unlink_urbs(struct urb **urbs, int num_urbs) @@ -199,10 +199,10 @@ static int usbduxsigma_ai_cancel(struct comedi_device *dev, { struct usbduxsigma_private *devpriv = dev->private; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); /* unlink only if it is really running */ usbduxsigma_ai_stop(dev, devpriv->ai_cmd_running); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return 0; } @@ -214,7 +214,7 @@ static void usbduxsigma_ai_handle_urb(struct comedi_device *dev, struct usbduxsigma_private *devpriv = dev->private; struct comedi_async *async = s->async; struct comedi_cmd *cmd = &async->cmd; - uint32_t val; + u32 val; int ret; int i; @@ -223,15 +223,14 @@ static void usbduxsigma_ai_handle_urb(struct comedi_device *dev, if (devpriv->ai_counter == 0) { devpriv->ai_counter = devpriv->ai_timer; - /* get the data from the USB bus - and hand it over to comedi */ + /* + * Get the data from the USB bus and hand it over + * to comedi. Note, first byte is the DIO state. + */ for (i = 0; i < cmd->chanlist_len; i++) { - /* transfer data, - note first byte is the DIO state */ - val = be32_to_cpu(devpriv->in_buf[i+1]); + val = be32_to_cpu(devpriv->in_buf[i + 1]); val &= 0x00ffffff; /* strip status byte */ - val ^= 0x00800000; /* convert to unsigned */ - + val = comedi_offset_munge(s, val); if (!comedi_buf_write_samples(s, &val, 1)) return; } @@ -326,10 +325,10 @@ static int usbduxsigma_ao_cancel(struct comedi_device *dev, { struct usbduxsigma_private *devpriv = dev->private; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); /* unlink only if it is really running */ usbduxsigma_ao_stop(dev, devpriv->ao_cmd_running); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return 0; } @@ -341,7 +340,7 @@ static void usbduxsigma_ao_handle_urb(struct comedi_device *dev, struct usbduxsigma_private *devpriv = dev->private; struct comedi_async *async = s->async; struct comedi_cmd *cmd = &async->cmd; - uint8_t *datap; + u8 *datap; int ret; int i; @@ -553,13 +552,12 @@ static int usbduxsigma_ai_cmdtest(struct comedi_device *dev, * range is the range value from comedi */ static void create_adc_command(unsigned int chan, - uint8_t *muxsg0, - uint8_t *muxsg1) + u8 *muxsg0, u8 *muxsg1) { if (chan < 8) (*muxsg0) = (*muxsg0) | (1 << chan); else if (chan < 16) - (*muxsg1) = (*muxsg1) | (1 << (chan-8)); + (*muxsg1) = (*muxsg1) | (1 << (chan - 8)); } static int usbbuxsigma_send_cmd(struct comedi_device *dev, int cmd_type) @@ -611,19 +609,19 @@ static int usbduxsigma_ai_inttrig(struct comedi_device *dev, if (trig_num != cmd->start_arg) return -EINVAL; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (!devpriv->ai_cmd_running) { devpriv->ai_cmd_running = 1; ret = usbduxsigma_submit_urbs(dev, devpriv->ai_urbs, devpriv->n_ai_urbs, 1); if (ret < 0) { devpriv->ai_cmd_running = 0; - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } s->async->inttrig = NULL; } - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return 1; } @@ -634,13 +632,13 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev, struct usbduxsigma_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; unsigned int len = cmd->chanlist_len; - uint8_t muxsg0 = 0; - uint8_t muxsg1 = 0; - uint8_t sysred = 0; + u8 muxsg0 = 0; + u8 muxsg1 = 0; + u8 sysred = 0; int ret; int i; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (devpriv->high_speed) { /* @@ -675,7 +673,7 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev, ret = usbbuxsigma_send_cmd(dev, USBBUXSIGMA_AD_CMD); if (ret < 0) { - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -688,7 +686,7 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev, devpriv->n_ai_urbs, 1); if (ret < 0) { devpriv->ai_cmd_running = 0; - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } s->async->inttrig = NULL; @@ -696,7 +694,7 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev, s->async->inttrig = usbduxsigma_ai_inttrig; } - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return 0; } @@ -708,15 +706,15 @@ static int usbduxsigma_ai_insn_read(struct comedi_device *dev, { 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; + u8 muxsg0 = 0; + u8 muxsg1 = 0; + u8 sysred = 0; int ret; int i; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (devpriv->ai_cmd_running) { - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return -EBUSY; } @@ -733,16 +731,16 @@ static int usbduxsigma_ai_insn_read(struct comedi_device *dev, /* adc commands */ ret = usbbuxsigma_send_cmd(dev, USBDUXSIGMA_SINGLE_AD_CMD); if (ret < 0) { - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } for (i = 0; i < insn->n; i++) { - uint32_t val; + u32 val; ret = usbduxsigma_receive_cmd(dev, USBDUXSIGMA_SINGLE_AD_CMD); if (ret < 0) { - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -750,11 +748,9 @@ static int usbduxsigma_ai_insn_read(struct comedi_device *dev, val = be32_to_cpu(get_unaligned((__be32 *)(devpriv->insn_buf + 1))); val &= 0x00ffffff; /* strip status byte */ - val ^= 0x00800000; /* convert to unsigned */ - - data[i] = val; + data[i] = comedi_offset_munge(s, val); } - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return insn->n; } @@ -767,9 +763,9 @@ static int usbduxsigma_ao_insn_read(struct comedi_device *dev, struct usbduxsigma_private *devpriv = dev->private; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); ret = comedi_readback_insn_read(dev, s, insn, data); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -784,9 +780,9 @@ static int usbduxsigma_ao_insn_write(struct comedi_device *dev, int ret; int i; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (devpriv->ao_cmd_running) { - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return -EBUSY; } @@ -796,12 +792,12 @@ static int usbduxsigma_ao_insn_write(struct comedi_device *dev, devpriv->dux_commands[3] = chan; /* channel number */ ret = usbbuxsigma_send_cmd(dev, USBDUXSIGMA_DA_CMD); if (ret < 0) { - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } s->readback[chan] = data[i]; } - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return insn->n; } @@ -817,19 +813,19 @@ static int usbduxsigma_ao_inttrig(struct comedi_device *dev, if (trig_num != cmd->start_arg) return -EINVAL; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); if (!devpriv->ao_cmd_running) { devpriv->ao_cmd_running = 1; ret = usbduxsigma_submit_urbs(dev, devpriv->ao_urbs, devpriv->n_ao_urbs, 0); if (ret < 0) { devpriv->ao_cmd_running = 0; - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } s->async->inttrig = NULL; } - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return 1; } @@ -860,7 +856,7 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev, err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); if (err) { - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return 1; } @@ -909,7 +905,7 @@ static int usbduxsigma_ao_cmd(struct comedi_device *dev, struct comedi_cmd *cmd = &s->async->cmd; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); /* * For now, only "scan" timing is supported. A future version may @@ -928,7 +924,7 @@ static int usbduxsigma_ao_cmd(struct comedi_device *dev, devpriv->n_ao_urbs, 0); if (ret < 0) { devpriv->ao_cmd_running = 0; - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } s->async->inttrig = NULL; @@ -936,7 +932,7 @@ static int usbduxsigma_ao_cmd(struct comedi_device *dev, s->async->inttrig = usbduxsigma_ao_inttrig; } - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return 0; } @@ -967,7 +963,7 @@ static int usbduxsigma_dio_insn_bits(struct comedi_device *dev, struct usbduxsigma_private *devpriv = dev->private; int ret; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); comedi_dio_update_state(s, data); @@ -994,7 +990,7 @@ static int usbduxsigma_dio_insn_bits(struct comedi_device *dev, ret = insn->n; done: - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); return ret; } @@ -1220,9 +1216,10 @@ static int usbduxsigma_pwm_config(struct comedi_device *dev, static int usbduxsigma_getstatusinfo(struct comedi_device *dev, int chan) { + struct comedi_subdevice *s = dev->read_subdev; struct usbduxsigma_private *devpriv = dev->private; - uint8_t sysred; - uint32_t val; + u8 sysred; + u32 val; int ret; switch (chan) { @@ -1264,9 +1261,8 @@ static int usbduxsigma_getstatusinfo(struct comedi_device *dev, int chan) /* 32 bits big endian from the A/D converter */ val = be32_to_cpu(get_unaligned((__be32 *)(devpriv->insn_buf + 1))); val &= 0x00ffffff; /* strip status byte */ - val ^= 0x00800000; /* convert to unsigned */ - return (int)val; + return (int)comedi_offset_munge(s, val); } static int usbduxsigma_firmware_upload(struct comedi_device *dev, @@ -1274,8 +1270,8 @@ static int usbduxsigma_firmware_upload(struct comedi_device *dev, unsigned long context) { struct usb_device *usb = comedi_to_usb_dev(dev); - uint8_t *buf; - uint8_t *tmp; + u8 *buf; + u8 *tmp; int ret; if (!data) @@ -1466,7 +1462,7 @@ static int usbduxsigma_auto_attach(struct comedi_device *dev, if (!devpriv) return -ENOMEM; - sema_init(&devpriv->sem, 1); + mutex_init(&devpriv->mut); usb_set_intfdata(intf, devpriv); @@ -1580,7 +1576,7 @@ static void usbduxsigma_detach(struct comedi_device *dev) if (!devpriv) return; - down(&devpriv->sem); + mutex_lock(&devpriv->mut); /* force unlink all urbs */ usbduxsigma_ai_stop(dev, 1); @@ -1589,7 +1585,7 @@ static void usbduxsigma_detach(struct comedi_device *dev) usbduxsigma_free_usb_buffers(dev); - up(&devpriv->sem); + mutex_unlock(&devpriv->mut); } static struct comedi_driver usbduxsigma_driver = { diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 3af075aa3946..8c7393ef762d 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -1,22 +1,23 @@ /* - comedi/drivers/vmk80xx.c - Velleman USB Board Low-Level Driver + * vmk80xx.c + * Velleman USB Board Low-Level Driver + * + * Copyright (C) 2009 Manuel Gebele , Germany + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2000 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. + */ - Copyright (C) 2009 Manuel Gebele , Germany - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 2000 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. -*/ /* * Driver: vmk80xx * Description: Velleman USB Board Low-Level Driver @@ -51,52 +52,52 @@ enum { DEVICE_VMK8061 }; -#define VMK8055_DI_REG 0x00 -#define VMK8055_DO_REG 0x01 -#define VMK8055_AO1_REG 0x02 -#define VMK8055_AO2_REG 0x03 -#define VMK8055_AI1_REG 0x02 -#define VMK8055_AI2_REG 0x03 -#define VMK8055_CNT1_REG 0x04 -#define VMK8055_CNT2_REG 0x06 +#define VMK8055_DI_REG 0x00 +#define VMK8055_DO_REG 0x01 +#define VMK8055_AO1_REG 0x02 +#define VMK8055_AO2_REG 0x03 +#define VMK8055_AI1_REG 0x02 +#define VMK8055_AI2_REG 0x03 +#define VMK8055_CNT1_REG 0x04 +#define VMK8055_CNT2_REG 0x06 -#define VMK8061_CH_REG 0x01 -#define VMK8061_DI_REG 0x01 -#define VMK8061_DO_REG 0x01 -#define VMK8061_PWM_REG1 0x01 -#define VMK8061_PWM_REG2 0x02 -#define VMK8061_CNT_REG 0x02 -#define VMK8061_AO_REG 0x02 -#define VMK8061_AI_REG1 0x02 -#define VMK8061_AI_REG2 0x03 +#define VMK8061_CH_REG 0x01 +#define VMK8061_DI_REG 0x01 +#define VMK8061_DO_REG 0x01 +#define VMK8061_PWM_REG1 0x01 +#define VMK8061_PWM_REG2 0x02 +#define VMK8061_CNT_REG 0x02 +#define VMK8061_AO_REG 0x02 +#define VMK8061_AI_REG1 0x02 +#define VMK8061_AI_REG2 0x03 -#define VMK8055_CMD_RST 0x00 -#define VMK8055_CMD_DEB1_TIME 0x01 -#define VMK8055_CMD_DEB2_TIME 0x02 -#define VMK8055_CMD_RST_CNT1 0x03 -#define VMK8055_CMD_RST_CNT2 0x04 -#define VMK8055_CMD_WRT_AD 0x05 +#define VMK8055_CMD_RST 0x00 +#define VMK8055_CMD_DEB1_TIME 0x01 +#define VMK8055_CMD_DEB2_TIME 0x02 +#define VMK8055_CMD_RST_CNT1 0x03 +#define VMK8055_CMD_RST_CNT2 0x04 +#define VMK8055_CMD_WRT_AD 0x05 -#define VMK8061_CMD_RD_AI 0x00 -#define VMK8061_CMR_RD_ALL_AI 0x01 /* !non-active! */ -#define VMK8061_CMD_SET_AO 0x02 -#define VMK8061_CMD_SET_ALL_AO 0x03 /* !non-active! */ -#define VMK8061_CMD_OUT_PWM 0x04 -#define VMK8061_CMD_RD_DI 0x05 -#define VMK8061_CMD_DO 0x06 /* !non-active! */ -#define VMK8061_CMD_CLR_DO 0x07 -#define VMK8061_CMD_SET_DO 0x08 -#define VMK8061_CMD_RD_CNT 0x09 /* TODO: completely pointless? */ -#define VMK8061_CMD_RST_CNT 0x0a /* TODO: completely pointless? */ -#define VMK8061_CMD_RD_VERSION 0x0b /* internal usage */ -#define VMK8061_CMD_RD_JMP_STAT 0x0c /* TODO: not implemented yet */ -#define VMK8061_CMD_RD_PWR_STAT 0x0d /* internal usage */ -#define VMK8061_CMD_RD_DO 0x0e -#define VMK8061_CMD_RD_AO 0x0f -#define VMK8061_CMD_RD_PWM 0x10 +#define VMK8061_CMD_RD_AI 0x00 +#define VMK8061_CMR_RD_ALL_AI 0x01 /* !non-active! */ +#define VMK8061_CMD_SET_AO 0x02 +#define VMK8061_CMD_SET_ALL_AO 0x03 /* !non-active! */ +#define VMK8061_CMD_OUT_PWM 0x04 +#define VMK8061_CMD_RD_DI 0x05 +#define VMK8061_CMD_DO 0x06 /* !non-active! */ +#define VMK8061_CMD_CLR_DO 0x07 +#define VMK8061_CMD_SET_DO 0x08 +#define VMK8061_CMD_RD_CNT 0x09 /* TODO: completely pointless? */ +#define VMK8061_CMD_RST_CNT 0x0a /* TODO: completely pointless? */ +#define VMK8061_CMD_RD_VERSION 0x0b /* internal usage */ +#define VMK8061_CMD_RD_JMP_STAT 0x0c /* TODO: not implemented yet */ +#define VMK8061_CMD_RD_PWR_STAT 0x0d /* internal usage */ +#define VMK8061_CMD_RD_DO 0x0e +#define VMK8061_CMD_RD_AO 0x0f +#define VMK8061_CMD_RD_PWM 0x10 -#define IC3_VERSION (1 << 0) -#define IC6_VERSION (1 << 1) +#define IC3_VERSION BIT(0) +#define IC6_VERSION BIT(1) enum vmk80xx_model { VMK8055_MODEL, diff --git a/drivers/staging/comedi/kcomedilib/kcomedilib_main.c b/drivers/staging/comedi/kcomedilib/kcomedilib_main.c index 76bf5619fdd5..d0a8a28edd36 100644 --- a/drivers/staging/comedi/kcomedilib/kcomedilib_main.c +++ b/drivers/staging/comedi/kcomedilib/kcomedilib_main.c @@ -1,20 +1,20 @@ /* - kcomedilib/kcomedilib.c - a comedlib interface for kernel modules - - COMEDI - Linux Control and Measurement Device Interface - Copyright (C) 1997-2000 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. -*/ + * kcomedilib/kcomedilib.c + * a comedlib interface for kernel modules + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1997-2000 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. + */ #include diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c index 9112dd2bf4d7..bad355100825 100644 --- a/drivers/staging/dgap/dgap.c +++ b/drivers/staging/dgap/dgap.c @@ -140,21 +140,21 @@ struct board_id { }; static struct board_id dgap_ids[] = { - { PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) }, - { PCX, PCI_DEV_CX_NAME, 128, (T_CX|T_PCIBUS) }, - { PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS) }, - { PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC|T_PCIBUS) }, - { APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR|T_PCLITE|T_PCIBUS) }, - { APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR|T_PCLITE|T_PCIBUS) }, - { APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, - { PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, - { PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, - { PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, - { PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, - { PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, - { PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, - { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) }, - { PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM|T_PCLITE|T_PCIBUS) }, + {PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS)}, + {PCX, PCI_DEV_CX_NAME, 128, (T_CX | T_PCIBUS) }, + {PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX | T_PCIBUS) }, + {PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC | T_PCIBUS) }, + {APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR | T_PCLITE | T_PCIBUS)}, + {APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR | T_PCLITE | T_PCIBUS)}, + {APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)}, + {PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)}, + {PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)}, + {PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)}, + {PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)}, + {PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)}, + {PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)}, + {APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)}, + {PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS)}, {0,} /* 0 terminated list. */ }; @@ -248,7 +248,6 @@ static struct toklist dgap_tlist[] = { { BEGIN, "config_begin" }, { END, "config_end" }, { BOARD, "board" }, - { IO, "io" }, { PCIINFO, "pciinfo" }, { LINE, "line" }, { CONC, "conc" }, @@ -287,28 +286,6 @@ static struct toklist dgap_tlist[] = { { 0, NULL } }; - -/* - * dgap_sindex: much like index(), but it looks for a match of any character in - * the group, and returns that position. - */ -static char *dgap_sindex(char *string, char *group) -{ - char *ptr; - - if (!string || !group) - return NULL; - - for (; *string; string++) { - for (ptr = group; *ptr; ptr++) { - if (*ptr == *string) - return string; - } - } - - return NULL; -} - /* * get a word from the input stream, also keep track of current line number. * words are separated by whitespace. @@ -317,7 +294,7 @@ static char *dgap_getword(char **in) { char *ret_ptr = *in; - char *ptr = dgap_sindex(*in, " \t\n"); + char *ptr = strpbrk(*in, " \t\n"); /* If no word found, return null */ if (!ptr) @@ -349,6 +326,8 @@ static int dgap_gettok(char **in) if (strstr(dgap_cword, "board")) { w = dgap_getword(in); + if (!w) + return 0; snprintf(dgap_cword, MAXCWORD, "%s", w); for (t = dgap_brdtype; t->token != 0; t++) { if (!strcmp(w, t->string)) @@ -535,7 +514,6 @@ static uint dgap_config_get_num_prts(struct board_t *bd) return 0; for (p = bd->bd_config; p; p = p->next) { - switch (p->type) { case BNODE: /* @@ -568,7 +546,6 @@ static char *dgap_create_config_string(struct board_t *bd, char *string) } for (p = bd->bd_config; p; p = p->next) { - switch (p->type) { case LNODE: *ptr = '\0'; @@ -662,7 +639,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; @@ -682,24 +659,6 @@ static int dgap_parsefile(char **in) break; - case IO: /* i/o port */ - if (p->type != BNODE) { - pr_err("IO port only valid for boards"); - return -1; - } - s = dgap_getword(in); - if (!s) { - pr_err("unexpected end of file"); - return -1; - } - p->u.board.portstr = kstrdup(s, GFP_KERNEL); - if (kstrtol(s, 0, &p->u.board.port)) { - pr_err("bad number for IO port"); - return -1; - } - p->u.board.v_port = 1; - break; - case MEM: /* memory address */ if (p->type != BNODE) { pr_err("memory address only valid for boards"); @@ -710,6 +669,7 @@ static int dgap_parsefile(char **in) pr_err("unexpected end of file"); return -1; } + kfree(p->u.board.addrstr); p->u.board.addrstr = kstrdup(s, GFP_KERNEL); if (kstrtoul(s, 0, &p->u.board.addr)) { pr_err("bad number for memory address"); @@ -728,6 +688,7 @@ static int dgap_parsefile(char **in) pr_err("unexpected end of file"); return -1; } + kfree(p->u.board.pcibusstr); p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL); if (kstrtoul(s, 0, &p->u.board.pcibus)) { pr_err("bad number for pci bus"); @@ -739,6 +700,7 @@ static int dgap_parsefile(char **in) pr_err("unexpected end of file"); return -1; } + kfree(p->u.board.pcislotstr); p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL); if (kstrtoul(s, 0, &p->u.board.pcislot)) { pr_err("bad number for pci slot"); @@ -757,6 +719,7 @@ static int dgap_parsefile(char **in) pr_err("unexpected end of file"); return -1; } + kfree(p->u.board.method); p->u.board.method = kstrdup(s, GFP_KERNEL); p->u.board.v_method = 1; break; @@ -771,6 +734,7 @@ static int dgap_parsefile(char **in) pr_err("unexpected end of file"); return -1; } + kfree(p->u.board.status); p->u.board.status = kstrdup(s, GFP_KERNEL); break; @@ -820,13 +784,15 @@ static int dgap_parsefile(char **in) pr_err("unexpected end of file"); return -1; } - + kfree(p->u.board.status); p->u.board.status = kstrdup(s, GFP_KERNEL); if (p->type == CNODE) { + kfree(p->u.conc.id); p->u.conc.id = kstrdup(s, GFP_KERNEL); p->u.conc.v_id = 1; } else if (p->type == MNODE) { + kfree(p->u.module.id); p->u.module.id = kstrdup(s, GFP_KERNEL); p->u.module.v_id = 1; } else { @@ -881,7 +847,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = TNODE; @@ -903,7 +869,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = CUNODE; @@ -934,7 +900,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = LNODE; @@ -953,7 +919,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = CNODE; @@ -965,8 +931,8 @@ static int dgap_parsefile(char **in) brd->u.board.conc1++; conc_type = dgap_gettok(in); - if (conc_type == 0 || (conc_type != CX && - conc_type != EPC)) { + if (conc_type == 0 || + (conc_type != CX && conc_type != EPC)) { pr_err("failed to set a type of concentratros"); return -1; } @@ -995,7 +961,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = MNODE; @@ -1006,8 +972,8 @@ static int dgap_parsefile(char **in) brd->u.board.module1++; module_type = dgap_gettok(in); - if (module_type == 0 || (module_type != PORTS && - module_type != MODEM)) { + if (module_type == 0 || + (module_type != PORTS && module_type != MODEM)) { pr_err("failed to set a type of module"); return -1; } @@ -1023,6 +989,7 @@ static int dgap_parsefile(char **in) pr_err("unexpected end of file"); return -1; } + kfree(p->u.line.cable); p->u.line.cable = kstrdup(s, GFP_KERNEL); p->u.line.v_cable = 1; } @@ -1064,6 +1031,7 @@ static int dgap_parsefile(char **in) pr_err("unexpected end of file"); return -1; } + kfree(p->u.conc.connect); p->u.conc.connect = kstrdup(s, GFP_KERNEL); p->u.conc.v_connect = 1; } @@ -1074,7 +1042,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = PNODE; @@ -1096,7 +1064,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = JNODE; @@ -1118,7 +1086,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = ANODE; @@ -1140,7 +1108,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = INTRNODE; @@ -1161,7 +1129,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = TSNODE; @@ -1183,7 +1151,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = CSNODE; @@ -1205,7 +1173,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = BSNODE; @@ -1227,7 +1195,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = USNODE; @@ -1249,7 +1217,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = FSNODE; @@ -1271,7 +1239,7 @@ static int dgap_parsefile(char **in) p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); if (!p->next) - return -1; + return -ENOMEM; p = p->next; p->type = VSNODE; @@ -1306,7 +1274,6 @@ static void dgap_cleanup_nodes(void) switch (p->type) { case BNODE: - kfree(p->u.board.portstr); kfree(p->u.board.addrstr); kfree(p->u.board.pcibusstr); kfree(p->u.board.pcislotstr); @@ -1384,8 +1351,7 @@ static int dgap_remap(struct board_t *brd) if (!request_mem_region(brd->membase, 0x200000, "dgap")) return -ENOMEM; - if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, - "dgap")) + if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap")) goto err_req_mem; brd->re_map_membase = ioremap(brd->membase, 0x200000); @@ -1423,7 +1389,7 @@ static void dgap_unmap(struct board_t *brd) * the Linux line discipline way. */ static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, - unsigned char *fbuf, int *len) + unsigned char *fbuf, int *len) { int l = *len; int count = 0; @@ -1446,7 +1412,7 @@ static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, case 0: /* No FF seen yet */ - if (c == (unsigned char) '\377') + if (c == (unsigned char)'\377') /* delete this character from stream */ ch->pscan_state = 1; else { @@ -1458,7 +1424,7 @@ static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, case 1: /* first FF seen */ - if (c == (unsigned char) '\377') { + if (c == (unsigned char)'\377') { /* doubled ff, transform to single ff */ *cout++ = c; *fout++ = TTY_NORMAL; @@ -1477,7 +1443,6 @@ static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf, *cout++ = c; if (ch->pscan_savechar == 0x0) { - if (c == 0x0) { ch->ch_err_break++; *fout++ = TTY_BREAK; @@ -1544,15 +1509,15 @@ static void dgap_input(struct channel_t *ch) rmask = ch->ch_rsize - 1; - head = readw(&(bs->rx_head)); + head = readw(&bs->rx_head); head &= rmask; - tail = readw(&(bs->rx_tail)); + tail = readw(&bs->rx_tail); tail &= rmask; data_len = (head - tail) & rmask; if (data_len == 0) { - writeb(1, &(bs->idata)); + writeb(1, &bs->idata); spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); return; @@ -1567,9 +1532,8 @@ static void dgap_input(struct channel_t *ch) !(ch->ch_tun.un_flags & UN_ISOPEN) || !(tp->termios.c_cflag & CREAD) || (ch->ch_tun.un_flags & UN_CLOSING)) { - - writew(head, &(bs->rx_tail)); - writeb(1, &(bs->idata)); + writew(head, &bs->rx_tail); + writeb(1, &bs->idata); spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); return; @@ -1579,7 +1543,7 @@ static void dgap_input(struct channel_t *ch) * If we are throttled, simply don't read any data. */ if (ch->ch_flags & CH_RXBLOCK) { - writeb(1, &(bs->idata)); + writeb(1, &bs->idata); spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); return; @@ -1588,10 +1552,10 @@ static void dgap_input(struct channel_t *ch) /* * Ignore oruns. */ - tmpchar = readb(&(bs->orun)); + tmpchar = readb(&bs->orun); if (tmpchar) { ch->ch_err_overrun++; - writeb(0, &(bs->orun)); + writeb(0, &bs->orun); } /* Decide how much data we can send into the tty layer */ @@ -1626,13 +1590,13 @@ static void dgap_input(struct channel_t *ch) * space to put the data right now. */ if (!ld->ops->receive_buf) { - writew(head, &(bs->rx_tail)); + writew(head, &bs->rx_tail); len = 0; } } if (len <= 0) { - writeb(1, &(bs->idata)); + writeb(1, &bs->idata); spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); if (ld) @@ -1649,7 +1613,6 @@ static void dgap_input(struct channel_t *ch) * of data the card actually has pending... */ while (n) { - s = ((head >= tail) ? head : ch->ch_rsize) - tail; s = min(s, n); @@ -1666,8 +1629,8 @@ static void dgap_input(struct channel_t *ch) tail &= rmask; } - writew(tail, &(bs->rx_tail)); - writeb(1, &(bs->idata)); + writew(tail, &bs->rx_tail); + writeb(1, &bs->idata); ch->ch_rxcount += len; /* @@ -1685,7 +1648,7 @@ static void dgap_input(struct channel_t *ch) len = tty_buffer_request_room(tp->port, len); tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf, - ch->ch_bd->flipflagbuf, len); + ch->ch_bd->flipflagbuf, len); } else { len = tty_buffer_request_room(tp->port, len); tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len); @@ -1699,7 +1662,6 @@ static void dgap_input(struct channel_t *ch) if (ld) tty_ldisc_deref(ld); - } static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch, @@ -1770,7 +1732,6 @@ static void dgap_carrier(struct channel_t *ch) * Test for a VIRTUAL carrier transition to HIGH. */ if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) { - /* * When carrier rises, wake any threads waiting * for carrier in the open routine. @@ -1784,7 +1745,6 @@ static void dgap_carrier(struct channel_t *ch) * Test for a PHYSICAL carrier transition to HIGH. */ if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) { - /* * When carrier rises, wake any threads waiting * for carrier in the open routine. @@ -1806,7 +1766,6 @@ static void dgap_carrier(struct channel_t *ch) if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) && (phys_carrier == 0)) { - /* * When carrier drops: * @@ -1864,7 +1823,6 @@ static int dgap_event(struct board_t *bd) int port; int reason; int modem; - int b1; if (!bd || bd->magic != DGAP_BOARD_MAGIC) return -EIO; @@ -1878,11 +1836,11 @@ static int dgap_event(struct board_t *bd) return -EIO; } - eaddr = (struct ev_t __iomem *) (vaddr + EVBUF); + eaddr = (struct ev_t __iomem *)(vaddr + EVBUF); /* Get our head and tail */ - head = readw(&(eaddr->ev_head)); - tail = readw(&(eaddr->ev_tail)); + head = readw(&eaddr->ev_head); + tail = readw(&eaddr->ev_tail); /* * Forget it if pointers out of range. @@ -1899,7 +1857,6 @@ static int dgap_event(struct board_t *bd) * Loop to process all the events in the buffer. */ while (tail != head) { - /* * Get interrupt information. */ @@ -1909,7 +1866,7 @@ static int dgap_event(struct board_t *bd) port = ioread8(event); reason = ioread8(event + 1); modem = ioread8(event + 2); - b1 = ioread8(event + 3); + ioread8(event + 3); /* * Make sure the interrupt is valid. @@ -1942,7 +1899,6 @@ static int dgap_event(struct board_t *bd) * Process received data. */ if (reason & IFDATA) { - /* * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT! * input could send some data to ld, which in turn @@ -1959,7 +1915,7 @@ static int dgap_event(struct board_t *bd) if (ch->ch_flags & CH_RACTIVE) ch->ch_flags |= CH_RENABLE; else - writeb(1, &(bs->idata)); + writeb(1, &bs->idata); if (ch->ch_flags & CH_RWAIT) { ch->ch_flags &= ~CH_RWAIT; @@ -1981,7 +1937,6 @@ static int dgap_event(struct board_t *bd) * Process break. */ if (reason & IFBREAK) { - if (ch->ch_tun.un_tty) { /* A break has been indicated */ ch->ch_err_break++; @@ -2027,7 +1982,7 @@ next: tail = (tail + 4) & (EVMAX - EVSTART - 4); } - writew(tail, &(eaddr->ev_tail)); + writew(tail, &eaddr->ev_tail); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); return 0; @@ -2038,7 +1993,7 @@ next: */ static void dgap_poll_tasklet(unsigned long data) { - struct board_t *bd = (struct board_t *) data; + struct board_t *bd = (struct board_t *)data; ulong lock_flags; char __iomem *vaddr; u16 head, tail; @@ -2057,7 +2012,6 @@ static void dgap_poll_tasklet(unsigned long data) * If board is ready, parse deeper to see if there is anything to do. */ if (bd->state == BOARD_READY) { - struct ev_t __iomem *eaddr; if (!bd->re_map_membase) { @@ -2072,11 +2026,11 @@ static void dgap_poll_tasklet(unsigned long data) if (!bd->nasync) goto out; - eaddr = (struct ev_t __iomem *) (vaddr + EVBUF); + eaddr = (struct ev_t __iomem *)(vaddr + EVBUF); /* Get our head and tail */ - head = readw(&(eaddr->ev_head)); - tail = readw(&(eaddr->ev_tail)); + head = readw(&eaddr->ev_head); + tail = readw(&eaddr->ev_tail); /* * If there is an event pending. Go service it. @@ -2091,7 +2045,7 @@ out: /* * If board is doing interrupts, ACK the interrupt. */ - if (bd && bd->intr_running) + if (bd->intr_running) readb(bd->re_map_port + 2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); @@ -2206,7 +2160,7 @@ static struct board_t *dgap_found_board(struct pci_dev *pdev, int id, /* init our poll helper tasklet */ tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, - (unsigned long) brd); + (unsigned long)brd); ret = dgap_remap(brd); if (ret) @@ -2301,14 +2255,13 @@ static void dgap_poll_handler(ulong dummy) */ if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) { for (i = 0; i < dgap_numboards; i++) { - brd = dgap_board[i]; if (brd->state == BOARD_FAILED) continue; if (!brd->intr_running) /* Call the real board poller directly */ - dgap_poll_tasklet((unsigned long) brd); + dgap_poll_tasklet((unsigned long)brd); } } else { /* @@ -2361,7 +2314,7 @@ schedule_poller: new_time = dgap_poll_time - jiffies; - if ((ulong) new_time >= 2 * dgap_poll_tick) { + if ((ulong)new_time >= 2 * dgap_poll_tick) { dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick); } @@ -2388,7 +2341,7 @@ schedule_poller: * *=======================================================================*/ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1, - u8 byte2, uint ncmds) + u8 byte2, uint ncmds) { char __iomem *vaddr; struct __iomem cm_t *cm_addr; @@ -2415,8 +2368,8 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1, if (!vaddr) return; - cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF); - head = readw(&(cm_addr->cm_head)); + cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF); + head = readw(&cm_addr->cm_head); /* * Forget it if pointers out of range. @@ -2430,13 +2383,13 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1, * Put the data in the circular command buffer. */ writeb(cmd, (vaddr + head + CMDSTART + 0)); - writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1)); + writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1)); writeb(byte1, (vaddr + head + CMDSTART + 2)); writeb(byte2, (vaddr + head + CMDSTART + 3)); head = (head + 4) & (CMDMAX - CMDSTART - 4); - writew(head, &(cm_addr->cm_head)); + writew(head, &cm_addr->cm_head); /* * Wait if necessary before updating the head @@ -2445,9 +2398,8 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1, * is outlandish, declare the FEP dead. */ for (count = dgap_count ;;) { - - head = readw(&(cm_addr->cm_head)); - tail = readw(&(cm_addr->cm_tail)); + head = readw(&cm_addr->cm_head); + tail = readw(&cm_addr->cm_tail); n = (head - tail) & (CMDMAX - CMDSTART - 4); @@ -2499,8 +2451,8 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds) if (!vaddr) return; - cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF); - head = readw(&(cm_addr->cm_head)); + cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF); + head = readw(&cm_addr->cm_head); /* * Forget it if pointers out of range. @@ -2514,12 +2466,12 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds) * Put the data in the circular command buffer. */ writeb(cmd, (vaddr + head + CMDSTART + 0)); - writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1)); - writew((u16) word, (vaddr + head + CMDSTART + 2)); + writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1)); + writew((u16)word, (vaddr + head + CMDSTART + 2)); head = (head + 4) & (CMDMAX - CMDSTART - 4); - writew(head, &(cm_addr->cm_head)); + writew(head, &cm_addr->cm_head); /* * Wait if necessary before updating the head @@ -2528,9 +2480,8 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds) * is outlandish, declare the FEP dead. */ for (count = dgap_count ;;) { - - head = readw(&(cm_addr->cm_head)); - tail = readw(&(cm_addr->cm_tail)); + head = readw(&cm_addr->cm_head); + tail = readw(&cm_addr->cm_tail); n = (head - tail) & (CMDMAX - CMDSTART - 4); @@ -2582,8 +2533,8 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds) if (!vaddr) return; - cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF); - head = readw(&(cm_addr->cm_head)); + cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF); + head = readw(&cm_addr->cm_head); /* * Forget it if pointers out of range. @@ -2598,23 +2549,23 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds) */ /* Write an FF to tell the FEP that we want an extended command */ - writeb((u8) 0xff, (vaddr + head + CMDSTART + 0)); + writeb((u8)0xff, (vaddr + head + CMDSTART + 0)); - writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1)); - writew((u16) cmd, (vaddr + head + CMDSTART + 2)); + writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1)); + writew((u16)cmd, (vaddr + head + CMDSTART + 2)); /* * If the second part of the command won't fit, * put it at the beginning of the circular buffer. */ if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03))) - writew((u16) word, (vaddr + CMDSTART)); + writew((u16)word, (vaddr + CMDSTART)); else - writew((u16) word, (vaddr + head + CMDSTART + 4)); + writew((u16)word, (vaddr + head + CMDSTART + 4)); head = (head + 8) & (CMDMAX - CMDSTART - 4); - writew(head, &(cm_addr->cm_head)); + writew(head, &cm_addr->cm_head); /* * Wait if necessary before updating the head @@ -2623,9 +2574,8 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds) * is outlandish, declare the FEP dead. */ for (count = dgap_count ;;) { - - head = readw(&(cm_addr->cm_head)); - tail = readw(&(cm_addr->cm_tail)); + head = readw(&cm_addr->cm_head); + tail = readw(&cm_addr->cm_tail); n = (head - tail) & (CMDMAX - CMDSTART - 4); @@ -2663,7 +2613,7 @@ static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt) * Check parameters. */ bs = ch->ch_bs; - head = readw(&(bs->tx_head)); + head = readw(&bs->tx_head); /* * If pointers are out of range, just return. @@ -2695,7 +2645,7 @@ static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt) memcpy_toio(taddr, buf, n); head += cnt; - writew(head, &(bs->tx_head)); + writew(head, &bs->tx_head); } /* @@ -2743,19 +2693,18 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type) * If baud rate is zero, flush queues, and set mval to drop DTR. */ if ((ch->ch_c_cflag & (CBAUD)) == 0) { - /* flush rx */ - head = readw(&(ch->ch_bs->rx_head)); - writew(head, &(ch->ch_bs->rx_tail)); + head = readw(&ch->ch_bs->rx_head); + writew(head, &ch->ch_bs->rx_tail); /* flush tx */ - head = readw(&(ch->ch_bs->tx_head)); - writew(head, &(ch->ch_bs->tx_tail)); + head = readw(&ch->ch_bs->tx_head); + writew(head, &ch->ch_bs->tx_tail); ch->ch_flags |= (CH_BAUD0); /* Drop RTS and DTR */ - ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch)); + ch->ch_mval &= ~(D_RTS(ch) | D_DTR(ch)); mval = D_DTR(ch) | D_RTS(ch); ch->ch_baud_info = 0; @@ -2776,7 +2725,7 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type) /* Handle transition from B0 */ if (ch->ch_flags & CH_BAUD0) { ch->ch_flags &= ~(CH_BAUD0); - ch->ch_mval |= (D_RTS(ch)|D_DTR(ch)); + ch->ch_mval |= (D_RTS(ch) | D_DTR(ch)); } mval = D_DTR(ch) | D_RTS(ch); @@ -2910,19 +2859,19 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type) cflag &= 0xffff; if (cflag != ch->ch_fepcflag) { - ch->ch_fepcflag = (u16) (cflag & 0xffff); + ch->ch_fepcflag = (u16)(cflag & 0xffff); /* * Okay to have channel and board * locks held calling this */ - dgap_cmdw(ch, SCFLAG, (u16) cflag, 0); + dgap_cmdw(ch, SCFLAG, (u16)cflag, 0); } /* Handle transition from B0 */ if (ch->ch_flags & CH_BAUD0) { ch->ch_flags &= ~(CH_BAUD0); - ch->ch_mval |= (D_RTS(ch)|D_DTR(ch)); + ch->ch_mval |= (D_RTS(ch) | D_DTR(ch)); } mval = D_DTR(ch) | D_RTS(ch); } @@ -2957,7 +2906,7 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type) ch->ch_fepiflag = iflag; /* Okay to have channel and board locks held calling this */ - dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0); + dgap_cmdw(ch, SIFLAG, (u16)ch->ch_fepiflag, 0); } /* @@ -2982,7 +2931,7 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type) ch->ch_hflow = hflow; /* Okay to have channel and board locks held calling this */ - dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0); + dgap_cmdb(ch, SHFLOW, (u8)hflow, 0xff, 0); } /* @@ -3010,13 +2959,13 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type) ch->ch_mostat = mval; /* Okay to have channel and board locks held calling this */ - dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0); + dgap_cmdb(ch, SMODEM, (u8)mval, D_RTS(ch) | D_DTR(ch), 0); } /* * Read modem signals, and then call carrier function. */ - ch->ch_mistat = readb(&(ch->ch_bs->m_stat)); + ch->ch_mistat = readb(&ch->ch_bs->m_stat); dgap_carrier(ch); /* @@ -3061,7 +3010,7 @@ static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, int sleep_on_un_flags; if (!tty || tty->magic != TTY_MAGIC || !file || !ch || - ch->magic != DGAP_CHANNEL_MAGIC) + ch->magic != DGAP_CHANNEL_MAGIC) return -EIO; un = tty->driver_data; @@ -3074,7 +3023,6 @@ static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, /* Loop forever */ while (1) { - sleep_on_un_flags = 0; /* @@ -3101,7 +3049,6 @@ static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, */ if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) { - /* * Our conditions to leave cleanly and happily: * 1) NONBLOCKING on the tty is set. @@ -3210,15 +3157,15 @@ static void dgap_tty_flush_buffer(struct tty_struct *tty) spin_lock_irqsave(&ch->ch_lock, lock_flags2); ch->ch_flags &= ~CH_STOP; - head = readw(&(ch->ch_bs->tx_head)); - dgap_cmdw(ch, FLUSHTX, (u16) head, 0); + head = readw(&ch->ch_bs->tx_head); + dgap_cmdw(ch, FLUSHTX, (u16)head, 0); dgap_cmdw(ch, RESUMETX, 0, 0); - if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) { - ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY); + if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) { + ch->ch_tun.un_flags &= ~(UN_LOW | UN_EMPTY); wake_up_interruptible(&ch->ch_tun.un_flags_wait); } - if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) { - ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY); + if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) { + ch->ch_pun.un_flags &= ~(UN_LOW | UN_EMPTY); wake_up_interruptible(&ch->ch_pun.un_flags_wait); } @@ -3304,15 +3251,15 @@ static int dgap_tty_chars_in_buffer(struct tty_struct *tty) tmask = (ch->ch_tsize - 1); /* Get Transmit queue pointers */ - thead = readw(&(bs->tx_head)) & tmask; - ttail = readw(&(bs->tx_tail)) & tmask; + thead = readw(&bs->tx_head) & tmask; + ttail = readw(&bs->tx_tail) & tmask; /* Get tbusy flag */ - tbusy = readb(&(bs->tbusy)); + tbusy = readb(&bs->tbusy); /* Get Command queue pointers */ - chead = readw(&(ch->ch_cm->cm_head)); - ctail = readw(&(ch->ch_cm->cm_tail)); + chead = readw(&ch->ch_cm->cm_head); + ctail = readw(&ch->ch_cm->cm_tail); spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); @@ -3348,7 +3295,7 @@ static int dgap_tty_chars_in_buffer(struct tty_struct *tty) if (tbusy != 0) { spin_lock_irqsave(&ch->ch_lock, lock_flags); un->un_flags |= UN_EMPTY; - writeb(1, &(bs->iempty)); + writeb(1, &bs->iempty); spin_unlock_irqrestore(&ch->ch_lock, lock_flags); } @@ -3385,7 +3332,6 @@ static int dgap_wait_for_drain(struct tty_struct *tty) /* Loop until data is drained */ while (count != 0) { - count = dgap_tty_chars_in_buffer(tty); if (count == 0) @@ -3394,7 +3340,7 @@ static int dgap_wait_for_drain(struct tty_struct *tty) /* Set flag waiting for drain */ spin_lock_irqsave(&ch->ch_lock, lock_flags); un->un_flags |= UN_EMPTY; - writeb(1, &(bs->iempty)); + writeb(1, &bs->iempty); spin_unlock_irqrestore(&ch->ch_lock, lock_flags); /* Go to sleep till we get woken up */ @@ -3473,13 +3419,13 @@ static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event) if ((event & UN_LOW) != 0) { if ((un->un_flags & UN_LOW) == 0) { un->un_flags |= UN_LOW; - writeb(1, &(bs->ilow)); + writeb(1, &bs->ilow); } } if ((event & UN_LOW) != 0) { if ((un->un_flags & UN_EMPTY) == 0) { un->un_flags |= UN_EMPTY; - writeb(1, &(bs->iempty)); + writeb(1, &bs->iempty); } } } @@ -3516,8 +3462,8 @@ static int dgap_tty_write_room(struct tty_struct *tty) spin_lock_irqsave(&ch->ch_lock, lock_flags); tmask = ch->ch_tsize - 1; - head = readw(&(bs->tx_head)) & tmask; - tail = readw(&(bs->tx_tail)) & tmask; + head = readw(&bs->tx_head) & tmask; + tail = readw(&bs->tx_tail) & tmask; ret = tail - head - 1; if (ret < 0) @@ -3562,7 +3508,7 @@ static int dgap_tty_write_room(struct tty_struct *tty) * In here exists all the Transparent Print magic as well. */ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, - int count) + int count) { struct channel_t *ch; struct un_t *un; @@ -3628,8 +3574,8 @@ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, */ if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) { dgap_wmove(ch, ch->ch_digi.digi_onstr, - (int) ch->ch_digi.digi_onlen); - head = readw(&(bs->tx_head)) & tmask; + (int)ch->ch_digi.digi_onlen); + head = readw(&bs->tx_head) & tmask; ch->ch_flags |= CH_PRON; } @@ -3639,8 +3585,8 @@ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, */ if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) { dgap_wmove(ch, ch->ch_digi.digi_offstr, - (int) ch->ch_digi.digi_offlen); - head = readw(&(bs->tx_head)) & tmask; + (int)ch->ch_digi.digi_offlen); + head = readw(&bs->tx_head) & tmask; ch->ch_flags &= ~CH_PRON; } @@ -3657,29 +3603,27 @@ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, n -= remain; vaddr = ch->ch_taddr + head; - memcpy_toio(vaddr, (u8 *) buf, remain); + memcpy_toio(vaddr, (u8 *)buf, remain); head = ch->ch_tstart; buf += remain; } if (n > 0) { - /* * Move rest of data. */ vaddr = ch->ch_taddr + head; remain = n; - memcpy_toio(vaddr, (u8 *) buf, remain); + memcpy_toio(vaddr, (u8 *)buf, remain); head += remain; - } if (count) { ch->ch_txcount += count; head &= tmask; - writew(head, &(bs->tx_head)); + writew(head, &bs->tx_head); } dgap_set_firmware_event(un, UN_LOW | UN_EMPTY); @@ -3692,15 +3636,15 @@ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, * Otherwise turn it off right now. */ if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) { - tail = readw(&(bs->tx_tail)) & tmask; + tail = readw(&bs->tx_tail) & tmask; if (tail != head) { un->un_flags |= UN_EMPTY; - writeb(1, &(bs->iempty)); + writeb(1, &bs->iempty); } else { dgap_wmove(ch, ch->ch_digi.digi_offstr, - (int) ch->ch_digi.digi_offlen); - head = readw(&(bs->tx_head)) & tmask; + (int)ch->ch_digi.digi_offlen); + head = readw(&bs->tx_head) & tmask; ch->ch_flags &= ~CH_PRON; } } @@ -3756,7 +3700,7 @@ static int dgap_tty_tiocmget(struct tty_struct *tty) spin_lock_irqsave(&ch->ch_lock, lock_flags); - mstat = readb(&(ch->ch_bs->m_stat)); + mstat = readb(&ch->ch_bs->m_stat); /* Append any outbound signals that might be pending... */ mstat |= ch->ch_mostat; @@ -3786,7 +3730,7 @@ static int dgap_tty_tiocmget(struct tty_struct *tty) * Set modem signals, called by ld. */ static int dgap_tty_tiocmset(struct tty_struct *tty, - unsigned int set, unsigned int clear) + unsigned int set, unsigned int clear) { struct board_t *bd; struct channel_t *ch; @@ -3885,7 +3829,7 @@ static int dgap_tty_send_break(struct tty_struct *tty, int msec) #if 0 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); #endif - dgap_cmdw(ch, SBREAK, (u16) msec, 0); + dgap_cmdw(ch, SBREAK, (u16)msec, 0); spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); @@ -3967,7 +3911,7 @@ static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value) spin_lock_irqsave(&ch->ch_lock, lock_flags); - mstat = readb(&(ch->ch_bs->m_stat)); + mstat = readb(&ch->ch_bs->m_stat); /* Append any outbound signals that might be pending... */ mstat |= ch->ch_mostat; @@ -4037,7 +3981,7 @@ static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd, break; case TIOCMSET: - ch->ch_mforce = D_DTR(ch)|D_RTS(ch); + ch->ch_mforce = D_DTR(ch) | D_RTS(ch); if (arg & TIOCM_RTS) ch->ch_mval |= D_RTS(ch); @@ -4179,7 +4123,7 @@ static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo) memset(&tmp, 0, sizeof(tmp)); spin_lock_irqsave(&ch->ch_lock, lock_flags); - tmp = readw(&(ch->ch_bs->edelay)); + tmp = readw(&ch->ch_bs->edelay); spin_unlock_irqrestore(&ch->ch_lock, lock_flags); if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) @@ -4207,7 +4151,7 @@ static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd, spin_lock_irqsave(&bd->bd_lock, lock_flags); spin_lock_irqsave(&ch->ch_lock, lock_flags2); - writew((u16) new_digi, &(ch->ch_bs->edelay)); + writew((u16)new_digi, &ch->ch_bs->edelay); dgap_param(ch, bd, un->un_type); @@ -4259,7 +4203,6 @@ static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd, return -EFAULT; if (bd->bd_flags & BD_FEP5PLUS) { - spin_lock_irqsave(&bd->bd_lock, lock_flags); spin_lock_irqsave(&ch->ch_lock, lock_flags2); @@ -4278,7 +4221,7 @@ static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd, * dgap_set_termios() */ static void dgap_tty_set_termios(struct tty_struct *tty, - struct ktermios *old_termios) + struct ktermios *old_termios) { struct board_t *bd; struct channel_t *ch; @@ -4351,7 +4294,6 @@ static void dgap_tty_throttle(struct tty_struct *tty) spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); - } static void dgap_tty_unthrottle(struct tty_struct *tty) @@ -4442,7 +4384,7 @@ static int dgap_tty_open(struct tty_struct *tty, struct file *file) * sleep waiting for it to happen or they cancel the open. */ rc = wait_event_interruptible(brd->state_wait, - (brd->state & BOARD_READY)); + (brd->state & BOARD_READY)); if (rc) return rc; @@ -4510,15 +4452,14 @@ static int dgap_tty_open(struct tty_struct *tty, struct file *file) * Initialize if neither terminal or printer is open. */ if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) { - ch->ch_mforce = 0; ch->ch_mval = 0; /* * Flush input queue. */ - head = readw(&(bs->rx_head)); - writew(head, &(bs->rx_tail)); + head = readw(&bs->rx_head); + writew(head, &bs->rx_tail); ch->ch_flags = 0; ch->pscan_state = 0; @@ -4568,7 +4509,6 @@ static int dgap_tty_open(struct tty_struct *tty, struct file *file) */ static void dgap_tty_close(struct tty_struct *tty, struct file *file) { - struct ktermios *ts; struct board_t *bd; struct channel_t *ch; struct un_t *un; @@ -4589,8 +4529,6 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file) if (!bd || bd->magic != DGAP_BOARD_MAGIC) return; - ts = &tty->termios; - spin_lock_irqsave(&ch->ch_lock, lock_flags); /* @@ -4630,7 +4568,6 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file) */ if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) { - ch->ch_flags &= ~(CH_RXBLOCK); spin_unlock_irqrestore(&ch->ch_lock, lock_flags); @@ -4651,15 +4588,15 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file) * If we have HUPCL set, lower DTR and RTS */ if (ch->ch_c_cflag & HUPCL) { - ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch)); - dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0); + ch->ch_mostat &= ~(D_RTS(ch) | D_DTR(ch)); + dgap_cmdb(ch, SMODEM, 0, D_DTR(ch) | D_RTS(ch), 0); /* * Go to sleep to ensure RTS/DTR * have been dropped for modems to see it. */ spin_unlock_irqrestore(&ch->ch_lock, - lock_flags); + lock_flags); /* .25 second delay for dropping RTS/DTR */ schedule_timeout_interruptible(msecs_to_jiffies(250)); @@ -4670,7 +4607,6 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file) ch->pscan_state = 0; ch->pscan_savechar = 0; ch->ch_baud_info = 0; - } /* @@ -4678,7 +4614,7 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file) */ if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) { dgap_wmove(ch, ch->ch_digi.digi_offstr, - (int) ch->ch_digi.digi_offlen); + (int)ch->ch_digi.digi_offlen); ch->ch_flags &= ~CH_PRON; } @@ -4813,7 +4749,7 @@ static void dgap_tty_flush_chars(struct tty_struct *tty) * The usual assortment of ioctl's */ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, - unsigned long arg) + unsigned long arg) { struct board_t *bd; struct channel_t *ch; @@ -4822,7 +4758,7 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, u16 head; ulong lock_flags = 0; ulong lock_flags2 = 0; - void __user *uarg = (void __user *) arg; + void __user *uarg = (void __user *)arg; if (!tty || tty->magic != TTY_MAGIC) return -ENODEV; @@ -4849,9 +4785,7 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, } switch (cmd) { - /* Here are all the standard ioctl's that we MUST implement */ - case TCSBRK: /* * TCSBRK is SVID version: non-zero arg --> no break @@ -4876,7 +4810,7 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, spin_lock_irqsave(&ch->ch_lock, lock_flags2); if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) - dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); + dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0); spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); @@ -4903,7 +4837,7 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, spin_lock_irqsave(&bd->bd_lock, lock_flags); spin_lock_irqsave(&ch->ch_lock, lock_flags2); - dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); + dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0); spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); @@ -4930,7 +4864,7 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, spin_lock_irqsave(&bd->bd_lock, lock_flags); spin_lock_irqsave(&ch->ch_lock, lock_flags2); - dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0); + dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0); spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); @@ -4954,13 +4888,13 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, spin_unlock_irqrestore(&bd->bd_lock, lock_flags); return put_user(C_CLOCAL(tty) ? 1 : 0, - (unsigned long __user *) arg); + (unsigned long __user *)arg); case TIOCSSOFTCAR: spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); - rc = get_user(arg, (unsigned long __user *) arg); + rc = get_user(arg, (unsigned long __user *)arg); if (rc) return rc; @@ -5009,9 +4943,9 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) { if (!(un->un_type == DGAP_PRINT)) { - head = readw(&(ch->ch_bs->rx_head)); - writew(head, &(ch->ch_bs->rx_tail)); - writeb(0, &(ch->ch_bs->orun)); + head = readw(&ch->ch_bs->rx_head); + writew(head, &ch->ch_bs->rx_tail); + writeb(0, &ch->ch_bs->orun); } } @@ -5024,15 +4958,15 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, } ch->ch_flags &= ~CH_STOP; - head = readw(&(ch->ch_bs->tx_head)); - dgap_cmdw(ch, FLUSHTX, (u16) head, 0); + head = readw(&ch->ch_bs->tx_head); + dgap_cmdw(ch, FLUSHTX, (u16)head, 0); dgap_cmdw(ch, RESUMETX, 0, 0); - if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) { - ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY); + if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) { + ch->ch_tun.un_flags &= ~(UN_LOW | UN_EMPTY); wake_up_interruptible(&ch->ch_tun.un_flags_wait); } - if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) { - ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY); + if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) { + ch->ch_pun.un_flags &= ~(UN_LOW | UN_EMPTY); wake_up_interruptible(&ch->ch_pun.un_flags_wait); } if (waitqueue_active(&tty->write_wait)) @@ -5060,8 +4994,8 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, if (cmd == TCSETSF) { /* flush rx */ ch->ch_flags &= ~CH_STOP; - head = readw(&(ch->ch_bs->rx_head)); - writew(head, &(ch->ch_bs->rx_tail)); + head = readw(&ch->ch_bs->rx_head); + writew(head, &ch->ch_bs->rx_tail); } /* now wait for all the output to drain */ @@ -5101,7 +5035,6 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, } switch (arg) { - case TCOON: spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); @@ -5139,7 +5072,6 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, /* set information for ditty */ if (cmd == (DIGI_SETAW)) { - spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); spin_unlock_irqrestore(&bd->bd_lock, lock_flags); rc = dgap_wait_for_drain(tty); @@ -5874,14 +5806,12 @@ static ssize_t dgap_tty_name_show(struct device *d, cn = ch->ch_portnum; for (cptr = bd->bd_config; cptr; cptr = cptr->next) { - if ((cptr->type == BNODE) && ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) || (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) || (cptr->u.board.type == PAPORT8))) { - found = TRUE; if (cptr->u.board.v_start) starto = cptr->u.board.start; @@ -5910,7 +5840,6 @@ static ssize_t dgap_tty_name_show(struct device *d, } if (cptr->type == CNODE) { - for (i = 0; i < cptr->u.conc.nport; i++) { if (cn != (i + ncount)) continue; @@ -5927,7 +5856,6 @@ static ssize_t dgap_tty_name_show(struct device *d, } if (cptr->type == MNODE) { - for (i = 0; i < cptr->u.module.nport; i++) { if (cn != (i + ncount)) continue; @@ -5971,31 +5899,31 @@ static struct attribute *dgap_sysfs_tty_entries[] = { static void dgap_create_ports_sysfiles(struct board_t *bd) { dev_set_drvdata(&bd->pdev->dev, bd); - device_create_file(&(bd->pdev->dev), &dev_attr_ports_state); - device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud); - device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals); - device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag); - device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag); - device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag); - device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag); - device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag); - device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount); - device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount); + device_create_file(&bd->pdev->dev, &dev_attr_ports_state); + device_create_file(&bd->pdev->dev, &dev_attr_ports_baud); + device_create_file(&bd->pdev->dev, &dev_attr_ports_msignals); + device_create_file(&bd->pdev->dev, &dev_attr_ports_iflag); + device_create_file(&bd->pdev->dev, &dev_attr_ports_cflag); + device_create_file(&bd->pdev->dev, &dev_attr_ports_oflag); + device_create_file(&bd->pdev->dev, &dev_attr_ports_lflag); + device_create_file(&bd->pdev->dev, &dev_attr_ports_digi_flag); + device_create_file(&bd->pdev->dev, &dev_attr_ports_rxcount); + device_create_file(&bd->pdev->dev, &dev_attr_ports_txcount); } /* removes all the sys files created for that port */ static void dgap_remove_ports_sysfiles(struct board_t *bd) { - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_state); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_baud); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_msignals); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_iflag); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_cflag); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_oflag); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_lflag); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_digi_flag); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_rxcount); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_txcount); } /* @@ -6056,7 +5984,7 @@ static int dgap_test_bios(struct board_t *brd) brd->wait_for_bios = 0; while (brd->wait_for_bios < 1000) { /* Check to see if BIOS thinks board is good. (GD). */ - if (word == *(u16 *) "GD") + if (word == *(u16 *)"GD") return 0; msleep_interruptible(10); brd->wait_for_bios++; @@ -6067,7 +5995,7 @@ static int dgap_test_bios(struct board_t *brd) err1 = readw(addr + SEQUENCE); err2 = readw(addr + ERROR); dev_warn(&brd->pdev->dev, "%s failed diagnostics. Error #(%x,%x).\n", - brd->name, err1, err2); + brd->name, err1, err2); brd->state = BOARD_FAILED; brd->dpastatus = BD_NOBIOS; @@ -6117,7 +6045,6 @@ static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len) writel(0xbfc01004, (addr + 0xc34)); writel(0x3, (addr + 0xc30)); - } /* @@ -6143,12 +6070,12 @@ static int dgap_test_fep(struct board_t *brd) brd->wait_for_fep = 0; while (brd->wait_for_fep < 500) { /* Check to see if FEP is up and running now. */ - if (word == *(u16 *) "OS") { + if (word == *(u16 *)"OS") { /* * Check to see if the board can support FEP5+ commands. */ word = readw(addr + FEP5_PLUS); - if (word == *(u16 *) "5A") + if (word == *(u16 *)"5A") brd->bd_flags |= BD_FEP5PLUS; return 0; @@ -6192,7 +6119,6 @@ static void dgap_do_reset_board(struct board_t *brd) if (check == FEPRST) break; udelay(10); - } if (i > 1000) { dev_warn(&brd->pdev->dev, @@ -6235,8 +6161,8 @@ static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len) vaddr = brd->re_map_membase; - offset = readw((u16 *) (vaddr + DOWNREQ)); - to_dp = (struct downld_t *) (vaddr + (int) offset); + offset = readw((u16 *)(vaddr + DOWNREQ)); + to_dp = (struct downld_t *)(vaddr + (int)offset); memcpy_toio(to_dp, uaddr, len); /* Tell card we have data for it */ @@ -6289,7 +6215,6 @@ static void dgap_get_vpd(struct board_t *brd) * the first 2 bytes (header) should be 0x55, 0xAA */ if (byte1 == 0x55 && byte2 == 0xAA) { - base_offset = 0; /* @@ -6297,7 +6222,6 @@ static void dgap_get_vpd(struct board_t *brd) * for the VPD offset. */ while (base_offset <= EXPANSION_ROM_SIZE) { - /* * Lots of magic numbers here. * @@ -6441,7 +6365,6 @@ static void dgap_create_tty_sysfs(struct un_t *un, struct device *c) return; dev_set_drvdata(c, un); - } static void dgap_remove_tty_sysfs(struct device *c) @@ -6477,7 +6400,6 @@ static int dgap_tty_register_ports(struct board_t *brd) ch = brd->channels[0]; for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) { - struct device *classp; classp = tty_port_register_device(&brd->serial_ports[i], @@ -6581,7 +6503,6 @@ static int dgap_request_irq(struct board_t *brd) * Set up our interrupt handler if we are set to do interrupts. */ if (dgap_config_get_useintr(brd) && brd->irq) { - rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd); if (!rc) @@ -6609,7 +6530,7 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type, if (fw_info[card_type].conf_name) { ret = request_firmware(&fw, fw_info[card_type].conf_name, - &pdev->dev); + &pdev->dev); if (ret) { dev_err(&pdev->dev, "config file %s not found\n", fw_info[card_type].conf_name); @@ -6662,7 +6583,7 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type, if (fw_info[card_type].bios_name) { ret = request_firmware(&fw, fw_info[card_type].bios_name, - &pdev->dev); + &pdev->dev); if (ret) { dev_err(&pdev->dev, "bios file %s not found\n", fw_info[card_type].bios_name); @@ -6679,7 +6600,7 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type, if (fw_info[card_type].fep_name) { ret = request_firmware(&fw, fw_info[card_type].fep_name, - &pdev->dev); + &pdev->dev); if (ret) { dev_err(&pdev->dev, "dgap: fep file %s not found\n", fw_info[card_type].fep_name); @@ -6700,7 +6621,7 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type, * is requesting a concentrator image from us. */ if ((bd->type == PCX) || (bd->type == PEPC)) { - chk_addr = (u16 *) (vaddr + DOWNREQ); + chk_addr = (u16 *)(vaddr + DOWNREQ); /* Nonzero if FEP is requesting concentrator image. */ check = readw(chk_addr); vaddr = brd->re_map_membase; @@ -6708,14 +6629,14 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type, if (fw_info[card_type].con_name && check && vaddr) { ret = request_firmware(&fw, fw_info[card_type].con_name, - &pdev->dev); + &pdev->dev); if (ret) { dev_err(&pdev->dev, "conc file %s not found\n", fw_info[card_type].con_name); return ret; } /* Put concentrator firmware loading code here */ - offset = readw((u16 *) (vaddr + DOWNREQ)); + offset = readw((u16 *)(vaddr + DOWNREQ)); memcpy_toio(offset, fw->data, fw->size); dgap_do_conc_load(brd, (char *)fw->data, fw->size) @@ -6798,14 +6719,13 @@ static int dgap_tty_init(struct board_t *brd) ch = brd->channels[0]; vaddr = brd->re_map_membase; - bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF); - cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF); + bs = (struct bs_t __iomem *)((ulong)vaddr + CHANBUF); + cm = (struct cm_t __iomem *)((ulong)vaddr + CMDBUF); brd->bd_bs = bs; /* Set up channel variables */ for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) { - spin_lock_init(&ch->ch_lock); /* Store all our magic numbers */ @@ -6839,12 +6759,12 @@ static int dgap_tty_init(struct board_t *brd) ch->ch_dsr = DM_DSR; } - ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4); - ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4); + ch->ch_taddr = vaddr + (ioread16(&ch->ch_bs->tx_seg) << 4); + ch->ch_raddr = vaddr + (ioread16(&ch->ch_bs->rx_seg) << 4); ch->ch_tx_win = 0; ch->ch_rx_win = 0; - ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1; - ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1; + ch->ch_tsize = readw(&ch->ch_bs->tx_max) + 1; + ch->ch_rsize = readw(&ch->ch_bs->rx_max) + 1; ch->ch_tstart = 0; ch->ch_rstart = 0; @@ -6862,7 +6782,7 @@ static int dgap_tty_init(struct board_t *brd) dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0); - ch->ch_mistat = readb(&(ch->ch_bs->m_stat)); + ch->ch_mistat = readb(&ch->ch_bs->m_stat); init_waitqueue_head(&ch->ch_flags_wait); init_waitqueue_head(&ch->ch_tun.un_flags_wait); @@ -6870,18 +6790,18 @@ static int dgap_tty_init(struct board_t *brd) /* Turn on all modem interrupts for now */ modem = (DM_CD | DM_DSR | DM_CTS | DM_RI); - writeb(modem, &(ch->ch_bs->m_int)); + writeb(modem, &ch->ch_bs->m_int); /* * Set edelay to 0 if interrupts are turned on, * otherwise set edelay to the usual 100. */ if (brd->intr_used) - writew(0, &(ch->ch_bs->edelay)); + writew(0, &ch->ch_bs->edelay); else - writew(100, &(ch->ch_bs->edelay)); + writew(100, &ch->ch_bs->edelay); - writeb(1, &(ch->ch_bs->idata)); + writeb(1, &ch->ch_bs->idata); } return 0; @@ -7073,8 +6993,8 @@ static int dgap_start(void) } device = device_create(dgap_class, NULL, - MKDEV(DIGI_DGAP_MAJOR, 0), - NULL, "dgap_mgmt"); + MKDEV(DIGI_DGAP_MAJOR, 0), + NULL, "dgap_mgmt"); if (IS_ERR(device)) { rc = PTR_ERR(device); goto failed_device; diff --git a/drivers/staging/dgap/dgap.h b/drivers/staging/dgap/dgap.h index e707ed5fe949..c84dbf2a0684 100644 --- a/drivers/staging/dgap/dgap.h +++ b/drivers/staging/dgap/dgap.h @@ -409,7 +409,6 @@ #define ID 76 #define CABLE 77 #define CONNECT 78 -#define IO 79 #define MEM 80 #define DPSZ 81 @@ -1152,8 +1151,6 @@ struct cnode { union { struct { char type; /* Board Type */ - long port; /* I/O Address */ - char *portstr; /* I/O Address in string */ long addr; /* Memory Address */ char *addrstr; /* Memory Address in string */ long pcibus; /* PCI BUS */ @@ -1164,7 +1161,6 @@ struct cnode { char *id; /* tty id */ long start; /* start of tty counting */ char *method; /* Install method */ - char v_port; char v_addr; char v_pcibus; char v_pcislot; diff --git a/drivers/staging/dgnc/dgnc_cls.c b/drivers/staging/dgnc/dgnc_cls.c index a629a78964ce..75040daa40ce 100644 --- a/drivers/staging/dgnc/dgnc_cls.c +++ b/drivers/staging/dgnc/dgnc_cls.c @@ -115,7 +115,6 @@ static inline void cls_set_cts_flow_control(struct channel_t *ch) &ch->ch_cls_uart->isr_fcr); ch->ch_t_tlevel = 16; - } static inline void cls_set_ixon_flow_control(struct channel_t *ch) @@ -161,7 +160,6 @@ static inline void cls_set_ixon_flow_control(struct channel_t *ch) writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 | UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR), &ch->ch_cls_uart->isr_fcr); - } static inline void cls_set_no_output_flow_control(struct channel_t *ch) @@ -205,7 +203,6 @@ static inline void cls_set_no_output_flow_control(struct channel_t *ch) ch->ch_r_watermark = 0; ch->ch_t_tlevel = 16; ch->ch_r_tlevel = 16; - } static inline void cls_set_rts_flow_control(struct channel_t *ch) @@ -244,7 +241,6 @@ static inline void cls_set_rts_flow_control(struct channel_t *ch) ch->ch_r_watermark = 4; ch->ch_r_tlevel = 8; - } static inline void cls_set_ixoff_flow_control(struct channel_t *ch) @@ -286,7 +282,6 @@ static inline void cls_set_ixoff_flow_control(struct channel_t *ch) writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 | UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR), &ch->ch_cls_uart->isr_fcr); - } static inline void cls_set_no_input_flow_control(struct channel_t *ch) @@ -325,7 +320,6 @@ static inline void cls_set_no_input_flow_control(struct channel_t *ch) ch->ch_t_tlevel = 16; ch->ch_r_tlevel = 16; - } /* @@ -384,7 +378,6 @@ static inline void cls_parse_isr(struct dgnc_board *brd, uint port) /* Here we try to figure out what caused the interrupt to happen */ while (1) { - isr = readb(&ch->ch_cls_uart->isr_fcr); /* Bail if no pending interrupt on port */ @@ -445,7 +438,7 @@ static void cls_param(struct tty_struct *tty) if (!tty || tty->magic != TTY_MAGIC) return; - un = (struct un_t *) tty->driver_data; + un = (struct un_t *)tty->driver_data; if (!un || un->magic != DGNC_UNIT_MAGIC) return; @@ -478,7 +471,6 @@ static void cls_param(struct tty_struct *tty) ch->ch_old_baud = 0; return; } else if (ch->ch_custom_speed) { - baud = ch->ch_custom_speed; /* Handle transition from B0 */ if (ch->ch_flags & CH_BAUD0) { @@ -526,7 +518,7 @@ static void cls_param(struct tty_struct *tty) * unit is NOT open */ if (!(ch->ch_tun.un_flags & UN_ISOPEN) && - (un->un_type == DGNC_PRINT)) + (un->un_type == DGNC_PRINT)) baud = C_BAUD(ch->ch_pun.un_tty) & 0xff; else baud = C_BAUD(ch->ch_tun.un_tty) & 0xff; @@ -540,7 +532,7 @@ static void cls_param(struct tty_struct *tty) jindex = baud; if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && - (jindex < 16)) { + (jindex < 16)) { baud = bauds[iindex][jindex]; } else { baud = 0; @@ -628,13 +620,13 @@ static void cls_param(struct tty_struct *tty) * we are in hardware flow control mode, or CLOCAL/FORCEDCD is not set. */ if ((ch->ch_digi.digi_flags & CTSPACE) || - (ch->ch_digi.digi_flags & RTSPACE) || - (ch->ch_c_cflag & CRTSCTS) || - !(ch->ch_digi.digi_flags & DIGI_FORCEDCD) || - !(ch->ch_c_cflag & CLOCAL)) - ier |= UART_IER_MSI; + (ch->ch_digi.digi_flags & RTSPACE) || + (ch->ch_c_cflag & CRTSCTS) || + !(ch->ch_digi.digi_flags & DIGI_FORCEDCD) || + !(ch->ch_c_cflag & CLOCAL)) + ier |= UART_IER_MSI; else - ier &= ~UART_IER_MSI; + ier &= ~UART_IER_MSI; ier |= UART_IER_THRI; @@ -649,7 +641,7 @@ static void cls_param(struct tty_struct *tty) * disable flow control */ if ((ch->ch_startc == _POSIX_VDISABLE) || - (ch->ch_stopc == _POSIX_VDISABLE)) + (ch->ch_stopc == _POSIX_VDISABLE)) cls_set_no_output_flow_control(ch); else cls_set_ixon_flow_control(ch); @@ -665,7 +657,7 @@ static void cls_param(struct tty_struct *tty) * flow control */ if ((ch->ch_startc == _POSIX_VDISABLE) || - (ch->ch_stopc == _POSIX_VDISABLE)) + (ch->ch_stopc == _POSIX_VDISABLE)) cls_set_no_input_flow_control(ch); else cls_set_ixoff_flow_control(ch); @@ -684,7 +676,7 @@ static void cls_param(struct tty_struct *tty) */ static void cls_tasklet(unsigned long data) { - struct dgnc_board *bd = (struct dgnc_board *) data; + struct dgnc_board *bd = (struct dgnc_board *)data; struct channel_t *ch; unsigned long flags; int i; @@ -710,7 +702,6 @@ static void cls_tasklet(unsigned long data) * If board is ready, parse deeper to see if there is anything to do. */ if ((state == BOARD_READY) && (ports > 0)) { - /* Loop on each port */ for (i = 0; i < ports; i++) { ch = bd->channels[i]; @@ -746,7 +737,6 @@ static void cls_tasklet(unsigned long data) } spin_unlock_irqrestore(&bd->bd_intr_lock, flags); - } /* @@ -854,10 +844,8 @@ static void cls_copy_data_from_uart_to_queue(struct channel_t *ch) * Discard character if we are ignoring the error mask. */ if (linestatus & error_mask) { - unsigned char discard; - linestatus = 0; - discard = readb(&ch->ch_cls_uart->txrx); + readb(&ch->ch_cls_uart->txrx); continue; } @@ -916,7 +904,7 @@ static int cls_drain(struct tty_struct *tty, uint seconds) if (!tty || tty->magic != TTY_MAGIC) return -ENXIO; - un = (struct un_t *) tty->driver_data; + un = (struct un_t *)tty->driver_data; if (!un || un->magic != DGNC_UNIT_MAGIC) return -ENXIO; @@ -945,7 +933,7 @@ static void cls_flush_uart_write(struct channel_t *ch) return; writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT), - &ch->ch_cls_uart->isr_fcr); + &ch->ch_cls_uart->isr_fcr); udelay(10); ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); @@ -991,7 +979,7 @@ static void cls_copy_data_from_queue_to_uart(struct channel_t *ch) /* If port is "stopped", don't send any data to the UART */ if ((ch->ch_flags & CH_FORCED_STOP) || - (ch->ch_flags & CH_BREAK_SENDING)) + (ch->ch_flags & CH_BREAK_SENDING)) goto exit_unlock; if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM))) @@ -1008,7 +996,6 @@ static void cls_copy_data_from_queue_to_uart(struct channel_t *ch) n = min(n, qlen); while (n > 0) { - /* * If RTS Toggle mode is on, turn on RTS now if not already set, * and make sure we get an event when the data transfer has @@ -1182,7 +1169,7 @@ static void cls_uart_init(struct channel_t *ch) readb(&ch->ch_cls_uart->txrx); writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), - &ch->ch_cls_uart->isr_fcr); + &ch->ch_cls_uart->isr_fcr); udelay(10); ch->ch_flags |= (CH_FIFO_ENABLED | CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); @@ -1309,6 +1296,5 @@ static void cls_vpd(struct dgnc_board *brd) } pr_info("\n"); - if (re_map_vpdbase) - iounmap(re_map_vpdbase); + iounmap(re_map_vpdbase); } diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c index 7546aff65002..fc6d2989e28f 100644 --- a/drivers/staging/dgnc/dgnc_driver.c +++ b/drivers/staging/dgnc/dgnc_driver.c @@ -13,7 +13,6 @@ * PURPOSE. See the GNU General Public License for more details. */ - #include #include #include @@ -39,7 +38,6 @@ MODULE_SUPPORTED_DEVICE("dgnc"); */ static int dgnc_start(void); static int dgnc_finalize_board_init(struct dgnc_board *brd); -static void dgnc_init_globals(void); static int dgnc_found_board(struct pci_dev *pdev, int id); static void dgnc_cleanup_board(struct dgnc_board *brd); static void dgnc_poll_handler(ulong dummy); @@ -57,13 +55,13 @@ static const struct file_operations dgnc_BoardFops = { .release = dgnc_mgmt_close }; - /* * Globals */ uint dgnc_NumBoards; struct dgnc_board *dgnc_Board[MAXBOARDS]; DEFINE_SPINLOCK(dgnc_global_lock); +DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */ uint dgnc_Major; int dgnc_poll_tick = 20; /* Poll interval - 20 ms */ @@ -75,12 +73,10 @@ static struct class *dgnc_class; /* * Poller stuff */ -static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */ static ulong dgnc_poll_time; /* Time of next poll */ static uint dgnc_poll_stop; /* Used to tell poller to stop */ static struct timer_list dgnc_poll_timer; - static const struct pci_device_id dgnc_pci_tbl[] = { {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_DID), .driver_data = 0}, {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID), .driver_data = 1}, @@ -171,7 +167,7 @@ static void dgnc_cleanup_module(void) */ static int __init dgnc_init_module(void) { - int rc = 0; + int rc; /* * Initialize global stuff @@ -216,8 +212,8 @@ static int dgnc_start(void) unsigned long flags; struct device *dev; - /* make sure that the globals are init'd before we do anything else */ - dgnc_init_globals(); + /* make sure timer is initialized before we do anything else */ + init_timer(&dgnc_poll_timer); /* * Register our base character device into the kernel. @@ -241,7 +237,7 @@ static int dgnc_start(void) } dev = device_create(dgnc_class, NULL, - MKDEV(dgnc_Major, 0), + MKDEV(dgnc_Major, 0), NULL, "dgnc_mgmt"); if (IS_ERR(dev)) { rc = PTR_ERR(dev); @@ -355,13 +351,11 @@ static void dgnc_cleanup_board(struct dgnc_board *brd) } } - dgnc_Board[brd->boardnum] = NULL; kfree(brd); } - /* * dgnc_found_board() * @@ -422,9 +416,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id) pci_irq = pdev->irq; brd->irq = pci_irq; - switch (brd->device) { - case PCI_DEVICE_CLASSIC_4_DID: case PCI_DEVICE_CLASSIC_8_DID: case PCI_DEVICE_CLASSIC_4_422_DID: @@ -442,7 +434,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id) * 4 Memory Mapped UARTs and Status */ - /* get the PCI Base Address Registers */ brd->membase = pci_resource_start(pdev, 4); @@ -461,7 +452,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id) brd->iobase = pci_resource_start(pdev, 1); brd->iobase_end = pci_resource_end(pdev, 1); - brd->iobase = ((unsigned int) (brd->iobase)) & 0xFFFE; + brd->iobase = ((unsigned int)(brd->iobase)) & 0xFFFE; /* Assign the board_ops struct */ brd->bd_ops = &dgnc_cls_ops; @@ -483,7 +474,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id) break; - case PCI_DEVICE_NEO_4_DID: case PCI_DEVICE_NEO_8_DID: case PCI_DEVICE_NEO_2DB9_DID: @@ -525,7 +515,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id) dgnc_do_remap(brd); if (brd->re_map_membase) { - /* Read and store the dvid after remapping */ brd->dvid = readb(brd->re_map_membase + 0x8D); @@ -538,7 +527,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id) dev_err(&brd->pdev->dev, "Didn't find any compatible Neo/Classic PCI boards.\n"); return -ENXIO; - } /* @@ -571,7 +559,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id) /* init our poll helper tasklet */ tasklet_init(&brd->helper_tasklet, brd->bd_ops->tasklet, - (unsigned long) brd); + (unsigned long)brd); spin_lock_irqsave(&dgnc_global_lock, flags); brd->msgbuf = NULL; @@ -590,10 +578,8 @@ failed: brd->dpastatus = BD_NOFEP; return -ENXIO; - } - static int dgnc_finalize_board_init(struct dgnc_board *brd) { int rc = 0; @@ -621,14 +607,12 @@ static int dgnc_finalize_board_init(struct dgnc_board *brd) */ static void dgnc_do_remap(struct dgnc_board *brd) { - if (!brd || brd->magic != DGNC_BOARD_MAGIC) return; brd->re_map_membase = ioremap(brd->membase, 0x1000); } - /***************************************************************************** * * Function: @@ -688,7 +672,7 @@ static void dgnc_poll_handler(ulong dummy) new_time = dgnc_poll_time - jiffies; - if ((ulong) new_time >= 2 * dgnc_poll_tick) + if ((ulong)new_time >= 2 * dgnc_poll_tick) dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick); setup_timer(&dgnc_poll_timer, dgnc_poll_handler, 0); @@ -698,23 +682,3 @@ static void dgnc_poll_handler(ulong dummy) if (!dgnc_poll_stop) add_timer(&dgnc_poll_timer); } - -/* - * dgnc_init_globals() - * - * This is where we initialize the globals from the static insmod - * configuration variables. These are declared near the head of - * this file. - */ -static void dgnc_init_globals(void) -{ - int i = 0; - - dgnc_NumBoards = 0; - - for (i = 0; i < MAXBOARDS; i++) - dgnc_Board[i] = NULL; - - init_timer(&dgnc_poll_timer); -} - diff --git a/drivers/staging/dgnc/dgnc_driver.h b/drivers/staging/dgnc/dgnc_driver.h index 06ece5151fe4..ce7cd9b96542 100644 --- a/drivers/staging/dgnc/dgnc_driver.h +++ b/drivers/staging/dgnc/dgnc_driver.h @@ -61,7 +61,9 @@ #define PORT_NUM(dev) ((dev) & 0x7f) #define IS_PRINT(dev) (((dev) & 0xff) >= 0x80) -/* MAX number of stop characters we will send when our read queue is getting full */ +/* MAX number of stop characters we will send + * when our read queue is getting full + */ #define MAX_STOPS_SENT 5 /* 4 extra for alignment play space */ @@ -165,12 +167,15 @@ struct dgnc_board { uint maxports; /* MAX ports this board can handle */ unsigned char dvid; /* Board specific device id */ unsigned char vpd[128]; /* VPD of board, if found */ - unsigned char serial_num[20]; /* Serial number of board, if found in VPD */ + unsigned char serial_num[20]; /* Serial number of board, + * if found in VPD + */ spinlock_t bd_lock; /* Used to protect board */ - spinlock_t bd_intr_lock; /* Used to protect the poller tasklet and - * the interrupt routine from each other. + spinlock_t bd_intr_lock; /* Used to protect the poller tasklet + * and the interrupt routine from each + * other. */ uint state; /* State of card. */ @@ -189,14 +194,16 @@ struct dgnc_board { ulong membase; /* Start of base memory of the card */ ulong membase_end; /* End of base memory of the card */ - u8 __iomem *re_map_membase;/* Remapped memory of the card */ + u8 __iomem *re_map_membase; /* Remapped memory of the card */ ulong iobase; /* Start of io base of the card */ ulong iobase_end; /* End of io base of the card */ uint bd_uart_offset; /* Space between each UART */ - struct channel_t *channels[MAXPORTS]; /* array of pointers to our channels. */ + struct channel_t *channels[MAXPORTS]; /* array of pointers + * to our channels. + */ struct tty_driver SerialDriver; char SerialName[200]; @@ -211,8 +218,12 @@ struct dgnc_board { uint TtyRefCnt; - u16 dpatype; /* The board "type", as defined by DPA */ - u16 dpastatus; /* The board "status", as defined by DPA */ + u16 dpatype; /* The board "type", + * as defined by DPA + */ + u16 dpastatus; /* The board "status", + * as defined by DPA + */ /* * Mgmt data. @@ -304,7 +315,7 @@ struct un_t { ************************************************************************/ struct channel_t { int magic; /* Channel Magic Number */ - struct dgnc_board *ch_bd; /* Board structure pointer */ + struct dgnc_board *ch_bd; /* Board structure pointer */ struct digi_t ch_digi; /* Transparent Print structure */ struct un_t ch_tun; /* Terminal unit info */ struct un_t ch_pun; /* Printer unit info */ @@ -316,7 +327,9 @@ struct channel_t { uint ch_open_count; /* open count */ uint ch_flags; /* Channel flags */ - ulong ch_close_delay; /* How long we should drop RTS/DTR for */ + ulong ch_close_delay; /* How long we should + * drop RTS/DTR for + */ ulong ch_cpstime; /* Time for CPS calculations */ @@ -332,11 +345,15 @@ struct channel_t { uint ch_wopen; /* Waiting for open process cnt */ - unsigned char ch_mostat; /* FEP output modem status */ - unsigned char ch_mistat; /* FEP input modem status */ + unsigned char ch_mostat; /* FEP output modem status */ + unsigned char ch_mistat; /* FEP input modem status */ - struct neo_uart_struct __iomem *ch_neo_uart; /* Pointer to the "mapped" UART struct */ - struct cls_uart_struct __iomem *ch_cls_uart; /* Pointer to the "mapped" UART struct */ + struct neo_uart_struct __iomem *ch_neo_uart; /* Pointer to the + * "mapped" UART struct + */ + struct cls_uart_struct __iomem *ch_cls_uart; /* Pointer to the + * "mapped" UART struct + */ unsigned char ch_cached_lsr; /* Cached value of the LSR register */ @@ -360,10 +377,13 @@ struct channel_t { unsigned char ch_r_watermark; /* Receive Watermark */ - ulong ch_stop_sending_break; /* Time we should STOP sending a break */ + ulong ch_stop_sending_break; /* Time we should STOP + * sending a break + */ - uint ch_stops_sent; /* How many times I have sent a stop character - * to try to stop the other guy sending. + uint ch_stops_sent; /* How many times I have sent a stop + * character to try to stop the other + * guy sending. */ ulong ch_err_parity; /* Count of parity errors on channel */ ulong ch_err_frame; /* Count of framing errors on channel */ @@ -390,7 +410,10 @@ struct channel_t { extern uint dgnc_Major; /* Our driver/mgmt major */ extern int dgnc_poll_tick; /* Poll interval - 20 ms */ extern spinlock_t dgnc_global_lock; /* Driver global spinlock */ +extern spinlock_t dgnc_poll_lock; /* Poll scheduling lock */ extern uint dgnc_NumBoards; /* Total number of boards */ -extern struct dgnc_board *dgnc_Board[MAXBOARDS]; /* Array of board structs */ +extern struct dgnc_board *dgnc_Board[MAXBOARDS]; /* Array of board + * structs + */ #endif diff --git a/drivers/staging/dgnc/dgnc_mgmt.c b/drivers/staging/dgnc/dgnc_mgmt.c index b13318a82fe1..518fbd5e2d0e 100644 --- a/drivers/staging/dgnc/dgnc_mgmt.c +++ b/drivers/staging/dgnc/dgnc_mgmt.c @@ -32,11 +32,9 @@ #include "dgnc_pci.h" #include "dgnc_mgmt.h" - /* Our "in use" variables, to enforce 1 open only */ static int dgnc_mgmt_in_use[MAXMGMTDEVICES]; - /* * dgnc_mgmt_open() * @@ -67,7 +65,6 @@ int dgnc_mgmt_open(struct inode *inode, struct file *file) return 0; } - /* * dgnc_mgmt_close() * @@ -90,7 +87,6 @@ int dgnc_mgmt_close(struct inode *inode, struct file *file) return 0; } - /* * dgnc_mgmt_ioctl() * @@ -100,10 +96,9 @@ int dgnc_mgmt_close(struct inode *inode, struct file *file) long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { unsigned long flags; - void __user *uarg = (void __user *) arg; + void __user *uarg = (void __user *)arg; switch (cmd) { - case DIGI_GETDD: { /* @@ -115,6 +110,7 @@ long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) spin_lock_irqsave(&dgnc_global_lock, flags); + memset(&ddi, 0, sizeof(ddi)); ddi.dinfo_nboards = dgnc_NumBoards; sprintf(ddi.dinfo_version, "%s", DG_PART); @@ -147,8 +143,9 @@ long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) di.info_bdtype = dgnc_Board[brd]->dpatype; di.info_bdstate = dgnc_Board[brd]->dpastatus; di.info_ioport = 0; - di.info_physaddr = (ulong) dgnc_Board[brd]->membase; - di.info_physsize = (ulong) dgnc_Board[brd]->membase - dgnc_Board[brd]->membase_end; + di.info_physaddr = (ulong)dgnc_Board[brd]->membase; + di.info_physsize = (ulong)dgnc_Board[brd]->membase + - dgnc_Board[brd]->membase_end; if (dgnc_Board[brd]->state != BOARD_FAILED) di.info_nports = dgnc_Board[brd]->nasync; else @@ -254,8 +251,6 @@ long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) break; } - - } return 0; diff --git a/drivers/staging/dgnc/dgnc_neo.c b/drivers/staging/dgnc/dgnc_neo.c index 900e3ae55a38..8106f5234bf5 100644 --- a/drivers/staging/dgnc/dgnc_neo.c +++ b/drivers/staging/dgnc/dgnc_neo.c @@ -13,7 +13,6 @@ * PURPOSE. See the GNU General Public License for more details. */ - #include #include /* For jiffies, task states */ #include /* For tasklet and interrupt structs/defines */ @@ -57,7 +56,6 @@ static uint neo_get_uart_bytes_left(struct channel_t *ch); static void neo_send_immediate_char(struct channel_t *ch, unsigned char c); static irqreturn_t neo_intr(int irq, void *voidbrd); - struct board_ops dgnc_neo_ops = { .tasklet = neo_tasklet, .intr = neo_intr, @@ -81,7 +79,6 @@ struct board_ops dgnc_neo_ops = { static uint dgnc_offset_table[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; - /* * This function allows calls to ensure that all outstanding * PCI writes have been completed, by doing a PCI read against @@ -100,7 +97,6 @@ static inline void neo_set_cts_flow_control(struct channel_t *ch) unsigned char ier = readb(&ch->ch_neo_uart->ier); unsigned char efr = readb(&ch->ch_neo_uart->efr); - /* Turn on auto CTS flow control */ #if 1 ier |= UART_17158_IER_CTSDSR; @@ -131,7 +127,6 @@ static inline void neo_set_cts_flow_control(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); } - static inline void neo_set_rts_flow_control(struct channel_t *ch) { unsigned char ier = readb(&ch->ch_neo_uart->ier); @@ -174,7 +169,6 @@ static inline void neo_set_rts_flow_control(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); } - static inline void neo_set_ixon_flow_control(struct channel_t *ch) { unsigned char ier = readb(&ch->ch_neo_uart->ier); @@ -211,7 +205,6 @@ static inline void neo_set_ixon_flow_control(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); } - static inline void neo_set_ixoff_flow_control(struct channel_t *ch) { unsigned char ier = readb(&ch->ch_neo_uart->ier); @@ -249,7 +242,6 @@ static inline void neo_set_ixoff_flow_control(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); } - static inline void neo_set_no_input_flow_control(struct channel_t *ch) { unsigned char ier = readb(&ch->ch_neo_uart->ier); @@ -266,7 +258,6 @@ static inline void neo_set_no_input_flow_control(struct channel_t *ch) else efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXOFF); - /* Why? Becuz Exar's spec says we have to zero it out before setting it */ writeb(0, &ch->ch_neo_uart->efr); @@ -289,7 +280,6 @@ static inline void neo_set_no_input_flow_control(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); } - static inline void neo_set_no_output_flow_control(struct channel_t *ch) { unsigned char ier = readb(&ch->ch_neo_uart->ier); @@ -327,11 +317,9 @@ static inline void neo_set_no_output_flow_control(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); } - /* change UARTs start/stop chars */ static inline void neo_set_new_start_stop_chars(struct channel_t *ch) { - /* if hardware flow control is set, then skip this whole thing */ if (ch->ch_digi.digi_flags & (CTSPACE | RTSPACE) || ch->ch_c_cflag & CRTSCTS) return; @@ -346,7 +334,6 @@ static inline void neo_set_new_start_stop_chars(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); } - /* * No locks are assumed to be held when calling this function. */ @@ -377,7 +364,6 @@ static inline void neo_clear_break(struct channel_t *ch, int force) spin_unlock_irqrestore(&ch->ch_lock, flags); } - /* * Parse the ISR register. */ @@ -400,7 +386,6 @@ static inline void neo_parse_isr(struct dgnc_board *brd, uint port) /* Here we try to figure out what caused the interrupt to happen */ while (1) { - isr = readb(&ch->ch_neo_uart->isr_fcr); /* Bail if no pending interrupt */ @@ -507,7 +492,6 @@ static inline void neo_parse_isr(struct dgnc_board *brd, uint port) } } - static inline void neo_parse_lsr(struct dgnc_board *brd, uint port) { struct channel_t *ch; @@ -587,7 +571,6 @@ static inline void neo_parse_lsr(struct dgnc_board *brd, uint port) } } - /* * neo_param() * Send any/all changes to the line to the UART. @@ -607,7 +590,7 @@ static void neo_param(struct tty_struct *tty) if (!tty || tty->magic != TTY_MAGIC) return; - un = (struct un_t *) tty->driver_data; + un = (struct un_t *)tty->driver_data; if (!un || un->magic != DGNC_UNIT_MAGIC) return; @@ -641,7 +624,6 @@ static void neo_param(struct tty_struct *tty) return; } else if (ch->ch_custom_speed) { - baud = ch->ch_custom_speed; /* Handle transition from B0 */ if (ch->ch_flags & CH_BAUD0) { @@ -841,13 +823,12 @@ static void neo_param(struct tty_struct *tty) neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr)); } - /* * Our board poller function. */ static void neo_tasklet(unsigned long data) { - struct dgnc_board *bd = (struct dgnc_board *) data; + struct dgnc_board *bd = (struct dgnc_board *)data; struct channel_t *ch; unsigned long flags; int i; @@ -917,10 +898,8 @@ static void neo_tasklet(unsigned long data) /* Allow interrupt routine to access the interrupt register again */ spin_unlock_irqrestore(&bd->bd_intr_lock, flags); - } - /* * dgnc_neo_intr() * @@ -972,7 +951,6 @@ static irqreturn_t neo_intr(int irq, void *voidbrd) /* Loop on each port */ while ((uart_poll & 0xff) != 0) { - tmp = uart_poll; /* Check current port to see if it has interrupt pending */ @@ -995,7 +973,6 @@ static irqreturn_t neo_intr(int irq, void *voidbrd) /* Switch on type of interrupt we have */ switch (type) { - case UART_17158_RXRDY_TIMEOUT: /* * RXRDY Time-out is cleared by reading data in the @@ -1067,7 +1044,6 @@ static irqreturn_t neo_intr(int irq, void *voidbrd) return IRQ_HANDLED; } - /* * Neo specific way of turning off the receiver. * Used as a way to enforce queue flow control when in @@ -1082,7 +1058,6 @@ static void neo_disable_receiver(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); } - /* * Neo specific way of turning on the receiver. * Used as a way to un-enforce queue flow control when in @@ -1097,7 +1072,6 @@ static void neo_enable_receiver(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); } - static void neo_copy_data_from_uart_to_queue(struct channel_t *ch) { int qleft = 0; @@ -1153,7 +1127,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch) total -= 3; } - /* * Finally, bound the copy to make sure we don't overflow * our own queue... @@ -1163,7 +1136,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch) total = min(total, qleft); while (total > 0) { - /* * Grab the linestatus register, we need to check * to see if there are any errors in the FIFO. @@ -1179,7 +1151,7 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch) break; /* Make sure we don't go over the end of our queue */ - n = min(((uint) total), (RQUEUESIZE - (uint) head)); + n = min(((uint)total), (RQUEUESIZE - (uint)head)); /* * Cut down n even further if needed, this is to fix @@ -1228,7 +1200,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch) * Also deal with any possible queue overflow here as well. */ while (1) { - /* * Its possible we have a linestatus from the loop above * this, so we "OR" on any extra bits. @@ -1285,7 +1256,7 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch) } memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1); - ch->ch_equeue[head] = (unsigned char) linestatus; + ch->ch_equeue[head] = (unsigned char)linestatus; /* Ditch any remaining linestatus value. */ linestatus = 0; @@ -1306,7 +1277,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch) spin_unlock_irqrestore(&ch->ch_lock, flags); } - /* * This function basically goes to sleep for secs, or until * it gets signalled that the port has fully drained. @@ -1321,7 +1291,7 @@ static int neo_drain(struct tty_struct *tty, uint seconds) if (!tty || tty->magic != TTY_MAGIC) return -ENXIO; - un = (struct un_t *) tty->driver_data; + un = (struct un_t *)tty->driver_data; if (!un || un->magic != DGNC_UNIT_MAGIC) return -ENXIO; @@ -1345,7 +1315,6 @@ static int neo_drain(struct tty_struct *tty, uint seconds) return rc; } - /* * Flush the WRITE FIFO on the Neo. * @@ -1363,7 +1332,6 @@ static void neo_flush_uart_write(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); for (i = 0; i < 10; i++) { - /* Check to see if the UART feels it completely flushed the FIFO. */ tmp = readb(&ch->ch_neo_uart->isr_fcr); if (tmp & 4) @@ -1375,7 +1343,6 @@ static void neo_flush_uart_write(struct channel_t *ch) ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); } - /* * Flush the READ FIFO on the Neo. * @@ -1393,7 +1360,6 @@ static void neo_flush_uart_read(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); for (i = 0; i < 10; i++) { - /* Check to see if the UART feels it completely flushed the FIFO. */ tmp = readb(&ch->ch_neo_uart->isr_fcr); if (tmp & 2) @@ -1403,7 +1369,6 @@ static void neo_flush_uart_read(struct channel_t *ch) } } - static void neo_copy_data_from_queue_to_uart(struct channel_t *ch) { ushort head; @@ -1425,7 +1390,7 @@ static void neo_copy_data_from_queue_to_uart(struct channel_t *ch) /* If port is "stopped", don't send any data to the UART */ if ((ch->ch_flags & CH_FORCED_STOP) || - (ch->ch_flags & CH_BREAK_SENDING)) + (ch->ch_flags & CH_BREAK_SENDING)) goto exit_unlock; /* @@ -1482,7 +1447,7 @@ static void neo_copy_data_from_queue_to_uart(struct channel_t *ch) n = readb(&ch->ch_neo_uart->tfifo); - if ((unsigned int) n > ch->ch_t_tlevel) + if ((unsigned int)n > ch->ch_t_tlevel) goto exit_unlock; n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel; @@ -1499,7 +1464,6 @@ static void neo_copy_data_from_queue_to_uart(struct channel_t *ch) n = min(n, qlen); while (n > 0) { - s = ((head >= tail) ? head : WQUEUESIZE) - tail; s = min(s, n); @@ -1551,7 +1515,6 @@ exit_unlock: spin_unlock_irqrestore(&ch->ch_lock, flags); } - static void neo_parse_modem(struct channel_t *ch, unsigned char signals) { unsigned char msignals = signals; @@ -1608,7 +1571,6 @@ static void neo_parse_modem(struct channel_t *ch, unsigned char signals) ch->ch_mistat &= ~UART_MSR_CTS; } - /* Make the UART raise any of the output signals we want up */ static void neo_assert_modem_signals(struct channel_t *ch) { @@ -1629,7 +1591,6 @@ static void neo_assert_modem_signals(struct channel_t *ch) udelay(10); } - static void neo_send_start_character(struct channel_t *ch) { if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) @@ -1643,7 +1604,6 @@ static void neo_send_start_character(struct channel_t *ch) } } - static void neo_send_stop_character(struct channel_t *ch) { if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) @@ -1657,18 +1617,15 @@ static void neo_send_stop_character(struct channel_t *ch) } } - /* * neo_uart_init */ static void neo_uart_init(struct channel_t *ch) { - writeb(0, &ch->ch_neo_uart->ier); writeb(0, &ch->ch_neo_uart->efr); writeb(UART_EFR_ECB, &ch->ch_neo_uart->efr); - /* Clear out UART and FIFO */ readb(&ch->ch_neo_uart->txrx); writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr); @@ -1682,7 +1639,6 @@ static void neo_uart_init(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); } - /* * Make the UART completely turn off. */ @@ -1696,7 +1652,6 @@ static void neo_uart_off(struct channel_t *ch) neo_pci_posting_flush(ch->ch_bd); } - static uint neo_get_uart_bytes_left(struct channel_t *ch) { unsigned char left = 0; @@ -1718,7 +1673,6 @@ static uint neo_get_uart_bytes_left(struct channel_t *ch) return left; } - /* Channel lock MUST be held by the calling function! */ static void neo_send_break(struct channel_t *ch, int msecs) { @@ -1754,7 +1708,6 @@ static void neo_send_break(struct channel_t *ch, int msecs) } } - /* * neo_send_immediate_char. * @@ -1772,7 +1725,6 @@ static void neo_send_immediate_char(struct channel_t *ch, unsigned char c) neo_pci_posting_flush(ch->ch_bd); } - static unsigned int neo_read_eeprom(unsigned char __iomem *base, unsigned int address) { unsigned int enable; @@ -1813,7 +1765,6 @@ static unsigned int neo_read_eeprom(unsigned char __iomem *base, unsigned int ad return val; } - static void neo_vpd(struct dgnc_board *brd) { unsigned int i = 0; @@ -1841,6 +1792,6 @@ static void neo_vpd(struct dgnc_board *brd) /* Search for the serial number */ for (i = 0; i < NEO_VPD_IMAGEBYTES - 3; i++) if (brd->vpd[i] == 'S' && brd->vpd[i + 1] == 'N') - strncpy(brd->serial_num, &(brd->vpd[i + 3]), 9); + strncpy(brd->serial_num, &brd->vpd[i + 3], 9); } } diff --git a/drivers/staging/dgnc/dgnc_sysfs.c b/drivers/staging/dgnc/dgnc_sysfs.c index 44db8703eba4..74a072599126 100644 --- a/drivers/staging/dgnc/dgnc_sysfs.c +++ b/drivers/staging/dgnc/dgnc_sysfs.c @@ -13,7 +13,6 @@ * PURPOSE. See the GNU General Public License for more details. */ - #include #include #include @@ -26,28 +25,24 @@ #include "dgnc_driver.h" #include "dgnc_mgmt.h" - static ssize_t dgnc_driver_version_show(struct device_driver *ddp, char *buf) { return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART); } static DRIVER_ATTR(version, S_IRUSR, dgnc_driver_version_show, NULL); - static ssize_t dgnc_driver_boards_show(struct device_driver *ddp, char *buf) { return snprintf(buf, PAGE_SIZE, "%d\n", dgnc_NumBoards); } static DRIVER_ATTR(boards, S_IRUSR, dgnc_driver_boards_show, NULL); - static ssize_t dgnc_driver_maxboards_show(struct device_driver *ddp, char *buf) { return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS); } static DRIVER_ATTR(maxboards, S_IRUSR, dgnc_driver_maxboards_show, NULL); - static ssize_t dgnc_driver_pollrate_show(struct device_driver *ddp, char *buf) { return snprintf(buf, PAGE_SIZE, "%dms\n", dgnc_poll_tick); @@ -56,17 +51,23 @@ static ssize_t dgnc_driver_pollrate_show(struct device_driver *ddp, char *buf) static ssize_t dgnc_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count) { + unsigned long flags; + int tick; int ret; - ret = sscanf(buf, "%d\n", &dgnc_poll_tick); + ret = sscanf(buf, "%d\n", &tick); if (ret != 1) return -EINVAL; + + spin_lock_irqsave(&dgnc_poll_lock, flags); + dgnc_poll_tick = tick; + spin_unlock_irqrestore(&dgnc_poll_lock, flags); + return count; } static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgnc_driver_pollrate_show, dgnc_driver_pollrate_store); - void dgnc_create_driver_sysfiles(struct pci_driver *dgnc_driver) { int rc = 0; @@ -80,7 +81,6 @@ void dgnc_create_driver_sysfiles(struct pci_driver *dgnc_driver) pr_err("DGNC: sysfs driver_create_file failed!\n"); } - void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver) { struct device_driver *driverfs = &dgnc_driver->driver; @@ -91,7 +91,6 @@ void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver) driver_remove_file(driverfs, &driver_attr_pollrate); } - #define DGNC_VERIFY_BOARD(p, bd) \ do { \ if (!p) \ @@ -104,8 +103,6 @@ void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver) return 0; \ } while (0) - - static ssize_t dgnc_vpd_show(struct device *p, struct device_attribute *attr, char *buf) { @@ -145,7 +142,6 @@ static ssize_t dgnc_serial_number_show(struct device *p, } static DEVICE_ATTR(serial_number, S_IRUSR, dgnc_serial_number_show, NULL); - static ssize_t dgnc_ports_state_show(struct device *p, struct device_attribute *attr, char *buf) { @@ -164,7 +160,6 @@ static ssize_t dgnc_ports_state_show(struct device *p, } static DEVICE_ATTR(ports_state, S_IRUSR, dgnc_ports_state_show, NULL); - static ssize_t dgnc_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf) { @@ -183,7 +178,6 @@ static ssize_t dgnc_ports_baud_show(struct device *p, } static DEVICE_ATTR(ports_baud, S_IRUSR, dgnc_ports_baud_show, NULL); - static ssize_t dgnc_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf) @@ -214,7 +208,6 @@ static ssize_t dgnc_ports_msignals_show(struct device *p, } static DEVICE_ATTR(ports_msignals, S_IRUSR, dgnc_ports_msignals_show, NULL); - static ssize_t dgnc_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf) { @@ -233,7 +226,6 @@ static ssize_t dgnc_ports_iflag_show(struct device *p, } static DEVICE_ATTR(ports_iflag, S_IRUSR, dgnc_ports_iflag_show, NULL); - static ssize_t dgnc_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf) { @@ -252,7 +244,6 @@ static ssize_t dgnc_ports_cflag_show(struct device *p, } static DEVICE_ATTR(ports_cflag, S_IRUSR, dgnc_ports_cflag_show, NULL); - static ssize_t dgnc_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf) { @@ -271,7 +262,6 @@ static ssize_t dgnc_ports_oflag_show(struct device *p, } static DEVICE_ATTR(ports_oflag, S_IRUSR, dgnc_ports_oflag_show, NULL); - static ssize_t dgnc_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf) { @@ -290,7 +280,6 @@ static ssize_t dgnc_ports_lflag_show(struct device *p, } static DEVICE_ATTR(ports_lflag, S_IRUSR, dgnc_ports_lflag_show, NULL); - static ssize_t dgnc_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf) @@ -310,7 +299,6 @@ static ssize_t dgnc_ports_digi_flag_show(struct device *p, } static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgnc_ports_digi_flag_show, NULL); - static ssize_t dgnc_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf) { @@ -329,7 +317,6 @@ static ssize_t dgnc_ports_rxcount_show(struct device *p, } static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgnc_ports_rxcount_show, NULL); - static ssize_t dgnc_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf) { @@ -348,7 +335,6 @@ static ssize_t dgnc_ports_txcount_show(struct device *p, } static DEVICE_ATTR(ports_txcount, S_IRUSR, dgnc_ports_txcount_show, NULL); - /* this function creates the sys files that will export each signal status * to sysfs each value will be put in a separate filename */ @@ -357,41 +343,39 @@ void dgnc_create_ports_sysfiles(struct dgnc_board *bd) int rc = 0; dev_set_drvdata(&bd->pdev->dev, bd); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_vpd); - rc |= device_create_file(&(bd->pdev->dev), &dev_attr_serial_number); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_state); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_baud); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_msignals); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_iflag); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_cflag); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_oflag); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_lflag); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_digi_flag); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_rxcount); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_txcount); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_vpd); + rc |= device_create_file(&bd->pdev->dev, &dev_attr_serial_number); if (rc) dev_err(&bd->pdev->dev, "dgnc: sysfs device_create_file failed!\n"); } - /* removes all the sys files created for that port */ void dgnc_remove_ports_sysfiles(struct dgnc_board *bd) { - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount); - device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount); - device_remove_file(&(bd->pdev->dev), &dev_attr_vpd); - device_remove_file(&(bd->pdev->dev), &dev_attr_serial_number); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_state); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_baud); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_msignals); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_iflag); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_cflag); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_oflag); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_lflag); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_digi_flag); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_rxcount); + device_remove_file(&bd->pdev->dev, &dev_attr_ports_txcount); + device_remove_file(&bd->pdev->dev, &dev_attr_vpd); + device_remove_file(&bd->pdev->dev, &dev_attr_serial_number); } - static ssize_t dgnc_tty_state_show(struct device *d, struct device_attribute *attr, char *buf) { @@ -418,7 +402,6 @@ static ssize_t dgnc_tty_state_show(struct device *d, } static DEVICE_ATTR(state, S_IRUSR, dgnc_tty_state_show, NULL); - static ssize_t dgnc_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf) { @@ -444,7 +427,6 @@ static ssize_t dgnc_tty_baud_show(struct device *d, } static DEVICE_ATTR(baud, S_IRUSR, dgnc_tty_baud_show, NULL); - static ssize_t dgnc_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf) { @@ -479,7 +461,6 @@ static ssize_t dgnc_tty_msignals_show(struct device *d, } static DEVICE_ATTR(msignals, S_IRUSR, dgnc_tty_msignals_show, NULL); - static ssize_t dgnc_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf) { @@ -505,7 +486,6 @@ static ssize_t dgnc_tty_iflag_show(struct device *d, } static DEVICE_ATTR(iflag, S_IRUSR, dgnc_tty_iflag_show, NULL); - static ssize_t dgnc_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf) { @@ -531,7 +511,6 @@ static ssize_t dgnc_tty_cflag_show(struct device *d, } static DEVICE_ATTR(cflag, S_IRUSR, dgnc_tty_cflag_show, NULL); - static ssize_t dgnc_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf) { @@ -557,7 +536,6 @@ static ssize_t dgnc_tty_oflag_show(struct device *d, } static DEVICE_ATTR(oflag, S_IRUSR, dgnc_tty_oflag_show, NULL); - static ssize_t dgnc_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf) { @@ -583,7 +561,6 @@ static ssize_t dgnc_tty_lflag_show(struct device *d, } static DEVICE_ATTR(lflag, S_IRUSR, dgnc_tty_lflag_show, NULL); - static ssize_t dgnc_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf) { @@ -609,7 +586,6 @@ static ssize_t dgnc_tty_digi_flag_show(struct device *d, } static DEVICE_ATTR(digi_flag, S_IRUSR, dgnc_tty_digi_flag_show, NULL); - static ssize_t dgnc_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf) { @@ -635,7 +611,6 @@ static ssize_t dgnc_tty_rxcount_show(struct device *d, } static DEVICE_ATTR(rxcount, S_IRUSR, dgnc_tty_rxcount_show, NULL); - static ssize_t dgnc_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf) { @@ -661,7 +636,6 @@ static ssize_t dgnc_tty_txcount_show(struct device *d, } static DEVICE_ATTR(txcount, S_IRUSR, dgnc_tty_txcount_show, NULL); - static ssize_t dgnc_tty_name_show(struct device *d, struct device_attribute *attr, char *buf) { @@ -689,7 +663,6 @@ static ssize_t dgnc_tty_name_show(struct device *d, } static DEVICE_ATTR(custom_name, S_IRUSR, dgnc_tty_name_show, NULL); - static struct attribute *dgnc_sysfs_tty_entries[] = { &dev_attr_state.attr, &dev_attr_baud.attr, @@ -705,13 +678,11 @@ static struct attribute *dgnc_sysfs_tty_entries[] = { NULL }; - static struct attribute_group dgnc_tty_attribute_group = { .name = NULL, .attrs = dgnc_sysfs_tty_entries, }; - void dgnc_create_tty_sysfs(struct un_t *un, struct device *c) { int ret; @@ -724,10 +695,8 @@ void dgnc_create_tty_sysfs(struct un_t *un, struct device *c) } dev_set_drvdata(c, un); - } - void dgnc_remove_tty_sysfs(struct device *c) { sysfs_remove_group(&c->kobj, &dgnc_tty_attribute_group); diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c index fbfe79a70263..48e4b90578c1 100644 --- a/drivers/staging/dgnc/dgnc_tty.c +++ b/drivers/staging/dgnc/dgnc_tty.c @@ -63,7 +63,6 @@ static struct digi_t dgnc_digi_init = { .digi_term = "ansi" /* default terminal type */ }; - /* * Define a local default termios struct. All ports will be created * with this termios initially. @@ -80,14 +79,17 @@ static struct ktermios DgncDefaultTermios = { .c_line = 0, }; - /* Our function prototypes */ static int dgnc_tty_open(struct tty_struct *tty, struct file *file); static void dgnc_tty_close(struct tty_struct *tty, struct file *file); -static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch); -static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg); -static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo); -static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info); +static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, + struct channel_t *ch); +static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, + unsigned long arg); +static int dgnc_tty_digigeta(struct tty_struct *tty, + struct digi_t __user *retinfo); +static int dgnc_tty_digiseta(struct tty_struct *tty, + struct digi_t __user *new_info); static int dgnc_tty_write_room(struct tty_struct *tty); static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c); static int dgnc_tty_chars_in_buffer(struct tty_struct *tty); @@ -98,17 +100,21 @@ static void dgnc_tty_unthrottle(struct tty_struct *tty); static void dgnc_tty_flush_chars(struct tty_struct *tty); static void dgnc_tty_flush_buffer(struct tty_struct *tty); static void dgnc_tty_hangup(struct tty_struct *tty); -static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value); -static int dgnc_get_modem_info(struct channel_t *ch, unsigned int __user *value); +static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, + unsigned int __user *value); +static int dgnc_get_modem_info(struct channel_t *ch, + unsigned int __user *value); static int dgnc_tty_tiocmget(struct tty_struct *tty); -static int dgnc_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); +static int dgnc_tty_tiocmset(struct tty_struct *tty, unsigned int set, + unsigned int clear); static int dgnc_tty_send_break(struct tty_struct *tty, int msec); static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout); -static int dgnc_tty_write(struct tty_struct *tty, const unsigned char *buf, int count); -static void dgnc_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios); +static int dgnc_tty_write(struct tty_struct *tty, const unsigned char *buf, + int count); +static void dgnc_tty_set_termios(struct tty_struct *tty, + struct ktermios *old_termios); static void dgnc_tty_send_xchar(struct tty_struct *tty, char ch); - static const struct tty_operations dgnc_tty_ops = { .open = dgnc_tty_open, .close = dgnc_tty_close, @@ -163,7 +169,6 @@ int dgnc_tty_preinit(void) return 0; } - /* * dgnc_tty_register() * @@ -186,18 +191,24 @@ int dgnc_tty_register(struct dgnc_board *brd) brd->SerialDriver.subtype = SERIAL_TYPE_NORMAL; brd->SerialDriver.init_termios = DgncDefaultTermios; brd->SerialDriver.driver_name = DRVSTR; - brd->SerialDriver.flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK); + brd->SerialDriver.flags = (TTY_DRIVER_REAL_RAW | + TTY_DRIVER_DYNAMIC_DEV | + TTY_DRIVER_HARDWARE_BREAK); /* * The kernel wants space to store pointers to * tty_struct's and termios's. */ - brd->SerialDriver.ttys = kcalloc(brd->maxports, sizeof(*brd->SerialDriver.ttys), GFP_KERNEL); + brd->SerialDriver.ttys = kcalloc(brd->maxports, + sizeof(*brd->SerialDriver.ttys), + GFP_KERNEL); if (!brd->SerialDriver.ttys) return -ENOMEM; kref_init(&brd->SerialDriver.kref); - brd->SerialDriver.termios = kcalloc(brd->maxports, sizeof(*brd->SerialDriver.termios), GFP_KERNEL); + brd->SerialDriver.termios = kcalloc(brd->maxports, + sizeof(*brd->SerialDriver.termios), + GFP_KERNEL); if (!brd->SerialDriver.termios) return -ENOMEM; @@ -235,18 +246,24 @@ int dgnc_tty_register(struct dgnc_board *brd) brd->PrintDriver.subtype = SERIAL_TYPE_NORMAL; brd->PrintDriver.init_termios = DgncDefaultTermios; brd->PrintDriver.driver_name = DRVSTR; - brd->PrintDriver.flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK); + brd->PrintDriver.flags = (TTY_DRIVER_REAL_RAW | + TTY_DRIVER_DYNAMIC_DEV | + TTY_DRIVER_HARDWARE_BREAK); /* * The kernel wants space to store pointers to * tty_struct's and termios's. Must be separated from * the Serial Driver so we don't get confused */ - brd->PrintDriver.ttys = kcalloc(brd->maxports, sizeof(*brd->PrintDriver.ttys), GFP_KERNEL); + brd->PrintDriver.ttys = kcalloc(brd->maxports, + sizeof(*brd->PrintDriver.ttys), + GFP_KERNEL); if (!brd->PrintDriver.ttys) return -ENOMEM; kref_init(&brd->PrintDriver.kref); - brd->PrintDriver.termios = kcalloc(brd->maxports, sizeof(*brd->PrintDriver.termios), GFP_KERNEL); + brd->PrintDriver.termios = kcalloc(brd->maxports, + sizeof(*brd->PrintDriver.termios), + GFP_KERNEL); if (!brd->PrintDriver.termios) return -ENOMEM; @@ -275,7 +292,6 @@ int dgnc_tty_register(struct dgnc_board *brd) return rc; } - /* * dgnc_tty_init() * @@ -349,16 +365,15 @@ int dgnc_tty_init(struct dgnc_board *brd) struct device *classp; classp = tty_register_device(&brd->SerialDriver, i, - &(ch->ch_bd->pdev->dev)); + &ch->ch_bd->pdev->dev); ch->ch_tun.un_sysfs = classp; dgnc_create_tty_sysfs(&ch->ch_tun, classp); classp = tty_register_device(&brd->PrintDriver, i, - &(ch->ch_bd->pdev->dev)); + &ch->ch_bd->pdev->dev); ch->ch_pun.un_sysfs = classp; dgnc_create_tty_sysfs(&ch->ch_pun, classp); } - } return 0; @@ -371,7 +386,6 @@ err_free_channels: return -ENOMEM; } - /* * dgnc_tty_post_uninit() * @@ -383,7 +397,6 @@ void dgnc_tty_post_uninit(void) dgnc_TmpWriteBuf = NULL; } - /* * dgnc_tty_uninit() * @@ -476,9 +489,6 @@ static void dgnc_wmove(struct channel_t *ch, char *buf, uint n) ch->ch_w_head = head; } - - - /*======================================================================= * * dgnc_input - Process received data. @@ -529,9 +539,10 @@ void dgnc_input(struct channel_t *ch) * If the device is not open, or CREAD is off, * flush input data and return immediately. */ - if (!tp || (tp->magic != TTY_MAGIC) || !(ch->ch_tun.un_flags & UN_ISOPEN) || - !(tp->termios.c_cflag & CREAD) || (ch->ch_tun.un_flags & UN_CLOSING)) { - + if (!tp || (tp->magic != TTY_MAGIC) || + !(ch->ch_tun.un_flags & UN_ISOPEN) || + !(tp->termios.c_cflag & CREAD) || + (ch->ch_tun.un_flags & UN_CLOSING)) { ch->ch_r_head = tail; /* Force queue flow control to be released, if needed */ @@ -614,16 +625,28 @@ void dgnc_input(struct channel_t *ch) if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) { for (i = 0; i < s; i++) { if (*(ch->ch_equeue + tail + i) & UART_LSR_BI) - tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_BREAK); - else if (*(ch->ch_equeue + tail + i) & UART_LSR_PE) - tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_PARITY); - else if (*(ch->ch_equeue + tail + i) & UART_LSR_FE) - tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_FRAME); + tty_insert_flip_char(tp->port, + *(ch->ch_rqueue + tail + i), + TTY_BREAK); + else if (*(ch->ch_equeue + tail + i) & + UART_LSR_PE) + tty_insert_flip_char(tp->port, + *(ch->ch_rqueue + tail + i), + TTY_PARITY); + else if (*(ch->ch_equeue + tail + i) & + UART_LSR_FE) + tty_insert_flip_char(tp->port, + *(ch->ch_rqueue + tail + i), + TTY_FRAME); else - tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_NORMAL); + tty_insert_flip_char(tp->port, + *(ch->ch_rqueue + tail + i), + TTY_NORMAL); } } else { - tty_insert_flip_string(tp->port, ch->ch_rqueue + tail, s); + tty_insert_flip_string(tp->port, + ch->ch_rqueue + tail, + s); } tail += s; @@ -650,7 +673,6 @@ exit_unlock: tty_ldisc_deref(ld); } - /************************************************************************ * Determines when CARRIER changes state and takes appropriate * action. @@ -683,13 +705,12 @@ void dgnc_carrier(struct channel_t *ch) * Test for a VIRTUAL carrier transition to HIGH. */ if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) { - /* * When carrier rises, wake any threads waiting * for carrier in the open routine. */ - if (waitqueue_active(&(ch->ch_flags_wait))) + if (waitqueue_active(&ch->ch_flags_wait)) wake_up_interruptible(&ch->ch_flags_wait); } @@ -697,13 +718,12 @@ void dgnc_carrier(struct channel_t *ch) * Test for a PHYSICAL carrier transition to HIGH. */ if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) { - /* * When carrier rises, wake any threads waiting * for carrier in the open routine. */ - if (waitqueue_active(&(ch->ch_flags_wait))) + if (waitqueue_active(&ch->ch_flags_wait)) wake_up_interruptible(&ch->ch_flags_wait); } @@ -718,7 +738,6 @@ void dgnc_carrier(struct channel_t *ch) */ if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) && (phys_carrier == 0)) { - /* * When carrier drops: * @@ -731,7 +750,7 @@ void dgnc_carrier(struct channel_t *ch) * * Enable all select calls. */ - if (waitqueue_active(&(ch->ch_flags_wait))) + if (waitqueue_active(&ch->ch_flags_wait)) wake_up_interruptible(&ch->ch_flags_wait); if (ch->ch_tun.un_open_count > 0) @@ -801,8 +820,8 @@ static void dgnc_set_custom_speed(struct channel_t *ch, uint newrate) */ if (testrate_high != newrate) { /* - * Otherwise, pick the rate that is closer (i.e. whichever rate - * has a smaller delta). + * Otherwise, pick the rate that is closer + * (i.e. whichever rate has a smaller delta). */ deltahigh = testrate_high - newrate; deltalow = newrate - testrate_low; @@ -817,10 +836,9 @@ static void dgnc_set_custom_speed(struct channel_t *ch, uint newrate) ch->ch_custom_speed = newrate; } - void dgnc_check_queue_flow_control(struct channel_t *ch) { - int qleft = 0; + int qleft; /* Store how much space we have left in the queue */ qleft = ch->ch_r_tail - ch->ch_r_head - 1; @@ -844,7 +862,8 @@ void dgnc_check_queue_flow_control(struct channel_t *ch) */ if (qleft < 256) { /* HWFLOW */ - if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) { + if (ch->ch_digi.digi_flags & CTSPACE || + ch->ch_c_cflag & CRTSCTS) { if (!(ch->ch_flags & CH_RECEIVER_OFF)) { ch->ch_bd->bd_ops->disable_receiver(ch); ch->ch_flags |= (CH_RECEIVER_OFF); @@ -876,7 +895,8 @@ void dgnc_check_queue_flow_control(struct channel_t *ch) */ if (qleft > (RQUEUESIZE / 2)) { /* HWFLOW */ - if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) { + if (ch->ch_digi.digi_flags & RTSPACE || + ch->ch_c_cflag & CRTSCTS) { if (ch->ch_flags & CH_RECEIVER_OFF) { ch->ch_bd->bd_ops->enable_receiver(ch); ch->ch_flags &= ~(CH_RECEIVER_OFF); @@ -890,7 +910,6 @@ void dgnc_check_queue_flow_control(struct channel_t *ch) } } - void dgnc_wakeup_writes(struct channel_t *ch) { int qlen = 0; @@ -915,9 +934,9 @@ void dgnc_wakeup_writes(struct channel_t *ch) if (ch->ch_tun.un_flags & UN_ISOPEN) { if ((ch->ch_tun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && - ch->ch_tun.un_tty->ldisc->ops->write_wakeup) { + ch->ch_tun.un_tty->ldisc->ops->write_wakeup) { spin_unlock_irqrestore(&ch->ch_lock, flags); - (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty); + ch->ch_tun.un_tty->ldisc->ops->write_wakeup(ch->ch_tun.un_tty); spin_lock_irqsave(&ch->ch_lock, flags); } @@ -928,7 +947,8 @@ void dgnc_wakeup_writes(struct channel_t *ch) * the queue AND FIFO are both empty. */ if (ch->ch_tun.un_flags & UN_EMPTY) { - if ((qlen == 0) && (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) { + if ((qlen == 0) && + (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) { ch->ch_tun.un_flags &= ~(UN_EMPTY); /* @@ -956,9 +976,9 @@ void dgnc_wakeup_writes(struct channel_t *ch) if (ch->ch_pun.un_flags & UN_ISOPEN) { if ((ch->ch_pun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && - ch->ch_pun.un_tty->ldisc->ops->write_wakeup) { + ch->ch_pun.un_tty->ldisc->ops->write_wakeup) { spin_unlock_irqrestore(&ch->ch_lock, flags); - (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty); + ch->ch_pun.un_tty->ldisc->ops->write_wakeup(ch->ch_pun.un_tty); spin_lock_irqsave(&ch->ch_lock, flags); } @@ -969,7 +989,8 @@ void dgnc_wakeup_writes(struct channel_t *ch) * the queue AND FIFO are both empty. */ if (ch->ch_pun.un_flags & UN_EMPTY) { - if ((qlen == 0) && (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) + if ((qlen == 0) && + (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) ch->ch_pun.un_flags &= ~(UN_EMPTY); } @@ -979,8 +1000,6 @@ void dgnc_wakeup_writes(struct channel_t *ch) spin_unlock_irqrestore(&ch->ch_lock, flags); } - - /************************************************************************ * * TTY Entry points and helper functions @@ -1019,7 +1038,7 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file) * sleep waiting for it to happen or they cancel the open. */ rc = wait_event_interruptible(brd->state_wait, - (brd->state & BOARD_READY)); + (brd->state & BOARD_READY)); if (rc) return rc; @@ -1063,7 +1082,8 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file) */ spin_unlock_irqrestore(&ch->ch_lock, flags); - rc = wait_event_interruptible(ch->ch_flags_wait, ((ch->ch_flags & CH_OPENING) == 0)); + rc = wait_event_interruptible(ch->ch_flags_wait, + ((ch->ch_flags & CH_OPENING) == 0)); /* If ret is non-zero, user ctrl-c'ed us */ if (rc) @@ -1077,7 +1097,8 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file) * ch_flags_wait to wake us back up. */ rc = wait_event_interruptible(ch->ch_flags_wait, - (((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING) == 0)); + (((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & + UN_CLOSING) == 0)); /* If ret is non-zero, user ctrl-c'ed us */ if (rc) @@ -1085,11 +1106,9 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file) spin_lock_irqsave(&ch->ch_lock, flags); - /* Store our unit into driver_data, so we always have it available. */ tty->driver_data = un; - /* * Initialize tty's */ @@ -1100,7 +1119,6 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file) /* Maybe do something here to the TTY struct as well? */ } - /* * Allocate channel buffers for read/write/error. * Set flag, so we don't get trounced on. @@ -1126,7 +1144,6 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file) * Initialize if neither terminal or printer is open. */ if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) { - /* * Flush input queues. */ @@ -1190,13 +1207,14 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file) return rc; } - /* * dgnc_block_til_ready() * * Wait for DCD, if needed. */ -static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch) +static int dgnc_block_til_ready(struct tty_struct *tty, + struct file *file, + struct channel_t *ch) { int retval = 0; struct un_t *un = NULL; @@ -1204,7 +1222,8 @@ static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struc uint old_flags = 0; int sleep_on_un_flags = 0; - if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGNC_CHANNEL_MAGIC) + if (!tty || tty->magic != TTY_MAGIC || !file || !ch || + ch->magic != DGNC_CHANNEL_MAGIC) return -ENXIO; un = tty->driver_data; @@ -1217,11 +1236,11 @@ static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struc /* Loop forever */ while (1) { - sleep_on_un_flags = 0; /* - * If board has failed somehow during our sleep, bail with error. + * If board has failed somehow during our sleep, + * bail with error. */ if (ch->ch_bd->state == BOARD_FAILED) { retval = -ENXIO; @@ -1241,8 +1260,9 @@ static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struc * touched safely, the close routine will signal the * ch_wait_flags to wake us back up. */ - if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) { - + if (!((ch->ch_tun.un_flags | + ch->ch_pun.un_flags) & + UN_CLOSING)) { /* * Our conditions to leave cleanly and happily: * 1) NONBLOCKING on the tty is set. @@ -1294,11 +1314,13 @@ static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struc spin_unlock_irqrestore(&ch->ch_lock, flags); /* - * Wait for something in the flags to change from the current value. + * Wait for something in the flags to change + * from the current value. */ if (sleep_on_un_flags) retval = wait_event_interruptible(un->un_flags_wait, - (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags))); + (old_flags != (ch->ch_tun.un_flags | + ch->ch_pun.un_flags))); else retval = wait_event_interruptible(ch->ch_flags_wait, (old_flags != ch->ch_flags)); @@ -1314,13 +1336,9 @@ static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struc spin_unlock_irqrestore(&ch->ch_lock, flags); - if (retval) - return retval; - - return 0; + return retval; } - /* * dgnc_tty_hangup() * @@ -1339,22 +1357,18 @@ static void dgnc_tty_hangup(struct tty_struct *tty) /* flush the transmit queues */ dgnc_tty_flush_buffer(tty); - } - /* * dgnc_tty_close() * */ static void dgnc_tty_close(struct tty_struct *tty, struct file *file) { - struct ktermios *ts; struct dgnc_board *bd; struct channel_t *ch; struct un_t *un; unsigned long flags; - int rc = 0; if (!tty || tty->magic != TTY_MAGIC) return; @@ -1371,8 +1385,6 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file) if (!bd || bd->magic != DGNC_BOARD_MAGIC) return; - ts = &tty->termios; - spin_lock_irqsave(&ch->ch_lock, flags); /* @@ -1412,13 +1424,12 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file) tty->closing = 1; - /* * Only officially close channel if count is 0 and * DIGI_PRINTER bit is not set. */ - if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) { - + if ((ch->ch_open_count == 0) && + !(ch->ch_digi.digi_flags & DIGI_PRINTER)) { ch->ch_flags &= ~(CH_STOPI | CH_FORCED_STOPI); /* @@ -1426,7 +1437,7 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file) */ if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) { dgnc_wmove(ch, ch->ch_digi.digi_offstr, - (int) ch->ch_digi.digi_offlen); + (int)ch->ch_digi.digi_offlen); ch->ch_flags &= ~CH_PRON; } @@ -1434,7 +1445,7 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file) /* wait for output to drain */ /* This will also return if we take an interrupt */ - rc = bd->bd_ops->drain(tty, 0); + bd->bd_ops->drain(tty, 0); dgnc_tty_flush_buffer(tty); tty_ldisc_flush(tty); @@ -1447,7 +1458,6 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file) * If we have HUPCL set, lower DTR and RTS */ if (ch->ch_c_cflag & HUPCL) { - /* Drop RTS/DTR */ ch->ch_mostat &= ~(UART_MCR_DTR | UART_MCR_RTS); bd->bd_ops->assert_modem_signals(ch); @@ -1474,7 +1484,7 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file) */ if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) { dgnc_wmove(ch, ch->ch_digi.digi_offstr, - (int) ch->ch_digi.digi_offlen); + (int)ch->ch_digi.digi_offlen); ch->ch_flags &= ~CH_PRON; } } @@ -1488,7 +1498,6 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file) spin_unlock_irqrestore(&ch->ch_lock, flags); } - /* * dgnc_tty_chars_in_buffer() * @@ -1507,7 +1516,7 @@ static int dgnc_tty_chars_in_buffer(struct tty_struct *tty) uint chars = 0; unsigned long flags; - if (tty == NULL) + if (!tty) return 0; un = tty->driver_data; @@ -1538,7 +1547,6 @@ static int dgnc_tty_chars_in_buffer(struct tty_struct *tty) return chars; } - /* * dgnc_maxcps_room * @@ -1574,15 +1582,17 @@ static int dgnc_maxcps_room(struct tty_struct *tty, int bytes_available) int cps_limit = 0; unsigned long current_time = jiffies; unsigned long buffer_time = current_time + - (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps; + (HZ * ch->ch_digi.digi_bufsize) / + ch->ch_digi.digi_maxcps; if (ch->ch_cpstime < current_time) { /* buffer is empty */ - ch->ch_cpstime = current_time; /* reset ch_cpstime */ + ch->ch_cpstime = current_time; /* reset ch_cpstime */ cps_limit = ch->ch_digi.digi_bufsize; } else if (ch->ch_cpstime < buffer_time) { /* still room in the buffer */ - cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ; + cps_limit = ((buffer_time - ch->ch_cpstime) * + ch->ch_digi.digi_maxcps) / HZ; } else { /* no room in the buffer */ cps_limit = 0; @@ -1594,7 +1604,6 @@ static int dgnc_maxcps_room(struct tty_struct *tty, int bytes_available) return bytes_available; } - /* * dgnc_tty_write_room() * @@ -1610,7 +1619,7 @@ static int dgnc_tty_write_room(struct tty_struct *tty) int ret = 0; unsigned long flags; - if (tty == NULL || dgnc_TmpWriteBuf == NULL) + if (!tty || !dgnc_TmpWriteBuf) return 0; un = tty->driver_data; @@ -1655,7 +1664,6 @@ static int dgnc_tty_write_room(struct tty_struct *tty) return ret; } - /* * dgnc_tty_put_char() * @@ -1672,7 +1680,6 @@ static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c) return 1; } - /* * dgnc_tty_write() * @@ -1680,19 +1687,18 @@ static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c) * In here exists all the Transparent Print magic as well. */ static int dgnc_tty_write(struct tty_struct *tty, - const unsigned char *buf, int count) + const unsigned char *buf, int count) { struct channel_t *ch = NULL; struct un_t *un = NULL; int bufcount = 0, n = 0; - int orig_count = 0; unsigned long flags; ushort head; ushort tail; ushort tmask; uint remain; - if (tty == NULL || dgnc_TmpWriteBuf == NULL) + if (!tty || !dgnc_TmpWriteBuf) return 0; un = tty->driver_data; @@ -1711,7 +1717,6 @@ static int dgnc_tty_write(struct tty_struct *tty, * This helps to figure out if we should ask the FEP * to send us an event when it has more space available. */ - orig_count = count; spin_lock_irqsave(&ch->ch_lock, flags); @@ -1748,7 +1753,7 @@ static int dgnc_tty_write(struct tty_struct *tty, */ if ((un->un_type == DGNC_PRINT) && !(ch->ch_flags & CH_PRON)) { dgnc_wmove(ch, ch->ch_digi.digi_onstr, - (int) ch->ch_digi.digi_onlen); + (int)ch->ch_digi.digi_onlen); head = (ch->ch_w_head) & tmask; ch->ch_flags |= CH_PRON; } @@ -1759,7 +1764,7 @@ static int dgnc_tty_write(struct tty_struct *tty, */ if ((un->un_type != DGNC_PRINT) && (ch->ch_flags & CH_PRON)) { dgnc_wmove(ch, ch->ch_digi.digi_offstr, - (int) ch->ch_digi.digi_offlen); + (int)ch->ch_digi.digi_offlen); head = (ch->ch_w_head) & tmask; ch->ch_flags &= ~CH_PRON; } @@ -1818,7 +1823,6 @@ exit_retry: return 0; } - /* * Return modem signals to ld. */ @@ -1866,7 +1870,6 @@ static int dgnc_tty_tiocmget(struct tty_struct *tty) return result; } - /* * dgnc_tty_tiocmset() * @@ -1874,7 +1877,7 @@ static int dgnc_tty_tiocmget(struct tty_struct *tty) */ static int dgnc_tty_tiocmset(struct tty_struct *tty, - unsigned int set, unsigned int clear) + unsigned int set, unsigned int clear) { struct dgnc_board *bd; struct channel_t *ch; @@ -1918,7 +1921,6 @@ static int dgnc_tty_tiocmset(struct tty_struct *tty, return 0; } - /* * dgnc_tty_send_break() * @@ -1965,10 +1967,8 @@ static int dgnc_tty_send_break(struct tty_struct *tty, int msec) spin_unlock_irqrestore(&ch->ch_lock, flags); return 0; - } - /* * dgnc_tty_wait_until_sent() * @@ -1979,7 +1979,6 @@ static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout) struct dgnc_board *bd; struct channel_t *ch; struct un_t *un; - int rc; if (!tty || tty->magic != TTY_MAGIC) return; @@ -1996,10 +1995,9 @@ static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout) if (!bd || bd->magic != DGNC_BOARD_MAGIC) return; - rc = bd->bd_ops->drain(tty, 0); + bd->bd_ops->drain(tty, 0); } - /* * dgnc_send_xchar() * @@ -2036,9 +2034,6 @@ static void dgnc_tty_send_xchar(struct tty_struct *tty, char c) dev_dbg(tty->dev, "dgnc_tty_send_xchar finish\n"); } - - - /* * Return modem signals to ld. */ @@ -2075,12 +2070,11 @@ static inline int dgnc_get_mstat(struct channel_t *ch) return result; } - - /* * Return modem signals to ld. */ -static int dgnc_get_modem_info(struct channel_t *ch, unsigned int __user *value) +static int dgnc_get_modem_info(struct channel_t *ch, + unsigned int __user *value) { int result; @@ -2095,13 +2089,14 @@ static int dgnc_get_modem_info(struct channel_t *ch, unsigned int __user *value return put_user(result, value); } - /* * dgnc_set_modem_info() * * Set modem signals, called by ld. */ -static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value) +static int dgnc_set_modem_info(struct tty_struct *tty, + unsigned int command, + unsigned int __user *value) { struct dgnc_board *bd; struct channel_t *ch; @@ -2175,7 +2170,6 @@ static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, uns return 0; } - /* * dgnc_tty_digigeta() * @@ -2184,7 +2178,8 @@ static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, uns * * */ -static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo) +static int dgnc_tty_digigeta(struct tty_struct *tty, + struct digi_t __user *retinfo) { struct channel_t *ch; struct un_t *un; @@ -2217,7 +2212,6 @@ static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retin return 0; } - /* * dgnc_tty_digiseta() * @@ -2226,7 +2220,8 @@ static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retin * * */ -static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info) +static int dgnc_tty_digiseta(struct tty_struct *tty, + struct digi_t __user *new_info) { struct dgnc_board *bd; struct channel_t *ch; @@ -2257,17 +2252,21 @@ static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_i /* * Handle transistions to and from RTS Toggle. */ - if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) && (new_digi.digi_flags & DIGI_RTS_TOGGLE)) + if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) && + (new_digi.digi_flags & DIGI_RTS_TOGGLE)) ch->ch_mostat &= ~(UART_MCR_RTS); - if ((ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) && !(new_digi.digi_flags & DIGI_RTS_TOGGLE)) + if ((ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) && + !(new_digi.digi_flags & DIGI_RTS_TOGGLE)) ch->ch_mostat |= (UART_MCR_RTS); /* * Handle transistions to and from DTR Toggle. */ - if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) && (new_digi.digi_flags & DIGI_DTR_TOGGLE)) + if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) && + (new_digi.digi_flags & DIGI_DTR_TOGGLE)) ch->ch_mostat &= ~(UART_MCR_DTR); - if ((ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) && !(new_digi.digi_flags & DIGI_DTR_TOGGLE)) + if ((ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) && + !(new_digi.digi_flags & DIGI_DTR_TOGGLE)) ch->ch_mostat |= (UART_MCR_DTR); memcpy(&ch->ch_digi, &new_digi, sizeof(new_digi)); @@ -2300,11 +2299,11 @@ static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_i return 0; } - /* * dgnc_set_termios() */ -static void dgnc_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios) +static void dgnc_tty_set_termios(struct tty_struct *tty, + struct ktermios *old_termios) { struct dgnc_board *bd; struct channel_t *ch; @@ -2341,7 +2340,6 @@ static void dgnc_tty_set_termios(struct tty_struct *tty, struct ktermios *old_te spin_unlock_irqrestore(&ch->ch_lock, flags); } - static void dgnc_tty_throttle(struct tty_struct *tty) { struct channel_t *ch; @@ -2366,7 +2364,6 @@ static void dgnc_tty_throttle(struct tty_struct *tty) spin_unlock_irqrestore(&ch->ch_lock, flags); } - static void dgnc_tty_unthrottle(struct tty_struct *tty) { struct channel_t *ch; @@ -2391,7 +2388,6 @@ static void dgnc_tty_unthrottle(struct tty_struct *tty) spin_unlock_irqrestore(&ch->ch_lock, flags); } - static void dgnc_tty_start(struct tty_struct *tty) { struct dgnc_board *bd; @@ -2421,7 +2417,6 @@ static void dgnc_tty_start(struct tty_struct *tty) spin_unlock_irqrestore(&ch->ch_lock, flags); } - static void dgnc_tty_stop(struct tty_struct *tty) { struct dgnc_board *bd; @@ -2451,7 +2446,6 @@ static void dgnc_tty_stop(struct tty_struct *tty) spin_unlock_irqrestore(&ch->ch_lock, flags); } - /* * dgnc_tty_flush_chars() * @@ -2494,8 +2488,6 @@ static void dgnc_tty_flush_chars(struct tty_struct *tty) spin_unlock_irqrestore(&ch->ch_lock, flags); } - - /* * dgnc_tty_flush_buffer() * @@ -2540,8 +2532,6 @@ static void dgnc_tty_flush_buffer(struct tty_struct *tty) spin_unlock_irqrestore(&ch->ch_lock, flags); } - - /***************************************************************************** * * The IOCTL function and all of its helpers @@ -2554,14 +2544,14 @@ static void dgnc_tty_flush_buffer(struct tty_struct *tty) * The usual assortment of ioctl's */ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, - unsigned long arg) + unsigned long arg) { struct dgnc_board *bd; struct channel_t *ch; struct un_t *un; int rc; unsigned long flags; - void __user *uarg = (void __user *) arg; + void __user *uarg = (void __user *)arg; if (!tty || tty->magic != TTY_MAGIC) return -ENODEV; @@ -2586,7 +2576,6 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, } switch (cmd) { - /* Here are all the standard ioctl's that we MUST implement */ case TCSBRK: @@ -2617,7 +2606,6 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, return 0; - case TCSBRKP: /* support for POSIX tcsendbreak() * According to POSIX.1 spec (7.2.2.1.2) breaks should be @@ -2668,18 +2656,20 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, spin_unlock_irqrestore(&ch->ch_lock, flags); - rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg); + rc = put_user(C_CLOCAL(tty) ? 1 : 0, + (unsigned long __user *)arg); return rc; case TIOCSSOFTCAR: spin_unlock_irqrestore(&ch->ch_lock, flags); - rc = get_user(arg, (unsigned long __user *) arg); + rc = get_user(arg, (unsigned long __user *)arg); if (rc) return rc; spin_lock_irqsave(&ch->ch_lock, flags); - tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0)); + tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | + (arg ? CLOCAL : 0)); ch->ch_bd->bd_ops->param(tty); spin_unlock_irqrestore(&ch->ch_lock, flags); @@ -2728,15 +2718,16 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, ch->ch_bd->bd_ops->flush_uart_write(ch); if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) { - ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY); + ch->ch_tun.un_flags &= + ~(UN_LOW|UN_EMPTY); wake_up_interruptible(&ch->ch_tun.un_flags_wait); } if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) { - ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY); + ch->ch_pun.un_flags &= + ~(UN_LOW|UN_EMPTY); wake_up_interruptible(&ch->ch_pun.un_flags_wait); } - } } @@ -2797,7 +2788,6 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, /* set information for ditty */ if (cmd == (DIGI_SETAW)) { - spin_unlock_irqrestore(&ch->ch_lock, flags); rc = ch->ch_bd->bd_ops->drain(tty, 0); @@ -2817,9 +2807,11 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, case DIGI_LOOPBACK: { uint loopback = 0; - /* Let go of locks when accessing user space, could sleep */ + /* Let go of locks when accessing user space, + * could sleep + */ spin_unlock_irqrestore(&ch->ch_lock, flags); - rc = get_user(loopback, (unsigned int __user *) arg); + rc = get_user(loopback, (unsigned int __user *)arg); if (rc) return rc; spin_lock_irqsave(&ch->ch_lock, flags); @@ -2837,7 +2829,7 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, case DIGI_GETCUSTOMBAUD: spin_unlock_irqrestore(&ch->ch_lock, flags); - rc = put_user(ch->ch_custom_speed, (unsigned int __user *) arg); + rc = put_user(ch->ch_custom_speed, (unsigned int __user *)arg); return rc; case DIGI_SETCUSTOMBAUD: @@ -2845,7 +2837,7 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, int new_rate; /* Let go of locks when accessing user space, could sleep */ spin_unlock_irqrestore(&ch->ch_lock, flags); - rc = get_user(new_rate, (int __user *) arg); + rc = get_user(new_rate, (int __user *)arg); if (rc) return rc; spin_lock_irqsave(&ch->ch_lock, flags); @@ -2867,7 +2859,7 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned char c; spin_unlock_irqrestore(&ch->ch_lock, flags); - rc = get_user(c, (unsigned char __user *) arg); + rc = get_user(c, (unsigned char __user *)arg); if (rc) return rc; spin_lock_irqsave(&ch->ch_lock, flags); @@ -2915,14 +2907,16 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, /* NOTE: MORE EVENTS NEEDS TO BE ADDED HERE */ if (ch->ch_flags & CH_BREAK_SENDING) events |= EV_TXB; - if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_FORCED_STOP)) + if ((ch->ch_flags & CH_STOP) || + (ch->ch_flags & CH_FORCED_STOP)) events |= (EV_OPU | EV_OPS); - if ((ch->ch_flags & CH_STOPI) || (ch->ch_flags & CH_FORCED_STOPI)) + if ((ch->ch_flags & CH_STOPI) || + (ch->ch_flags & CH_FORCED_STOPI)) events |= (EV_IPU | EV_IPS); spin_unlock_irqrestore(&ch->ch_lock, flags); - rc = put_user(events, (unsigned int __user *) arg); + rc = put_user(events, (unsigned int __user *)arg); return rc; } diff --git a/drivers/staging/emxx_udc/emxx_udc.c b/drivers/staging/emxx_udc/emxx_udc.c index b6b76ff09657..4e6c16af40fc 100644 --- a/drivers/staging/emxx_udc/emxx_udc.c +++ b/drivers/staging/emxx_udc/emxx_udc.c @@ -12,14 +12,10 @@ * 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, Suite 500, Boston, MA 02110-1335, USA. */ #include -#include +#include #include #include #include @@ -44,11 +40,9 @@ #include "emxx_udc.h" -#define DRIVER_DESC "EMXX UDC driver" #define DMA_ADDR_INVALID (~(dma_addr_t)0) static const char driver_name[] = "emxx_udc"; -static const char driver_desc[] = DRIVER_DESC; /*===========================================================================*/ /* Prototype */ @@ -67,12 +61,10 @@ static void _nbu2ss_fifo_flush(struct nbu2ss_udc *, struct nbu2ss_ep *); #define _nbu2ss_zero_len_pkt(udc, epnum) \ _nbu2ss_ep_in_end(udc, epnum, 0, 0) - /*===========================================================================*/ /* Global */ struct nbu2ss_udc udc_controller; - /*-------------------------------------------------------------------------*/ /* Read */ static inline u32 _nbu2ss_readl(void *address) @@ -114,7 +106,7 @@ static void _nbu2ss_dump_register(struct nbu2ss_udc *udc) pr_info("=== %s()\n", __func__); - if (udc == NULL) { + if (!udc) { pr_err("%s udc == NULL\n", __func__); return; } @@ -155,7 +147,7 @@ static void _nbu2ss_ep0_complete(struct usb_ep *_ep, struct usb_request *_req) struct usb_ctrlrequest *p_ctrl; struct nbu2ss_udc *udc; - if ((_ep == NULL) || (_req == NULL)) + if ((!_ep) || (!_req)) return; udc = (struct nbu2ss_udc *)_req->context; @@ -219,7 +211,7 @@ static u32 _nbu2ss_get_begin_ram_address(struct nbu2ss_udc *udc) } if ((data >> 16) > last_ram_adr) - last_ram_adr = data>>16; + last_ram_adr = data >> 16; } return last_ram_adr + use_ram_size; @@ -595,7 +587,7 @@ static int EP0_out_OverBytes(struct nbu2ss_udc *udc, u8 *pBuf, u32 length) union usb_reg_access Temp32; union usb_reg_access *pBuf32 = (union usb_reg_access *)pBuf; - if ((0 < length) && (length < sizeof(u32))) { + if ((length > 0) && (length < sizeof(u32))) { Temp32.dw = _nbu2ss_readl(&udc->p_regs->EP0_READ); for (i = 0 ; i < length ; i++) pBuf32->byte.DATA[i] = Temp32.byte.DATA[i]; @@ -641,7 +633,7 @@ static int EP0_in_OverBytes(struct nbu2ss_udc *udc, u8 *pBuf, u32 iRemainSize) union usb_reg_access Temp32; union usb_reg_access *pBuf32 = (union usb_reg_access *)pBuf; - if ((0 < iRemainSize) && (iRemainSize < sizeof(u32))) { + if ((iRemainSize > 0) && (iRemainSize < sizeof(u32))) { for (i = 0 ; i < iRemainSize ; i++) Temp32.byte.DATA[i] = pBuf32->byte.DATA[i]; _nbu2ss_ep_in_end(udc, 0, Temp32.dw, iRemainSize); @@ -691,7 +683,6 @@ static int EP0_receive_NULL(struct nbu2ss_udc *udc, bool pid_flag) /*-------------------------------------------------------------------------*/ static int _nbu2ss_ep0_in_transfer( struct nbu2ss_udc *udc, - struct nbu2ss_ep *ep, struct nbu2ss_req *req ) { @@ -749,7 +740,6 @@ static int _nbu2ss_ep0_in_transfer( /*-------------------------------------------------------------------------*/ static int _nbu2ss_ep0_out_transfer( struct nbu2ss_udc *udc, - struct nbu2ss_ep *ep, struct nbu2ss_req *req ) { @@ -778,7 +768,7 @@ static int _nbu2ss_ep0_out_transfer( req->req.actual += result; iRecvLength -= result; - if ((0 < iRecvLength) && (iRecvLength < sizeof(u32))) { + if ((iRecvLength > 0) && (iRecvLength < sizeof(u32))) { pBuffer += result; iRemainSize -= result; @@ -857,11 +847,11 @@ static int _nbu2ss_out_dma( dmacnt = (length / mpkt); lmpkt = (length % mpkt) & ~(u32)0x03; - if (DMA_MAX_COUNT < dmacnt) { + if (dmacnt > DMA_MAX_COUNT) { dmacnt = DMA_MAX_COUNT; lmpkt = 0; - } else if (0 != lmpkt) { - if (0 == dmacnt) + } else if (lmpkt != 0) { + if (dmacnt == 0) burst = 0; /* Burst OFF */ dmacnt++; } @@ -872,7 +862,7 @@ static int _nbu2ss_out_dma( data = ((dmacnt & 0xff) << 16) | DCR1_EPn_DIR0 | DCR1_EPn_REQEN; _nbu2ss_writel(&preg->EP_DCR[num].EP_DCR1, data); - if (0 == burst) { + if (burst == 0) { _nbu2ss_writel(&preg->EP_REGS[num].EP_LEN_DCNT, 0); _nbu2ss_bitclr(&preg->EP_REGS[num].EP_DMA_CTRL, EPn_BURST_SET); } else { @@ -1258,11 +1248,11 @@ static int _nbu2ss_start_transfer( /* EP0 */ switch (udc->ep0state) { case EP0_IN_DATA_PHASE: - nret = _nbu2ss_ep0_in_transfer(udc, ep, req); + nret = _nbu2ss_ep0_in_transfer(udc, req); break; case EP0_OUT_DATA_PHASE: - nret = _nbu2ss_ep0_out_transfer(udc, ep, req); + nret = _nbu2ss_ep0_out_transfer(udc, req); break; case EP0_IN_STATUS_PHASE: @@ -1277,7 +1267,7 @@ static int _nbu2ss_start_transfer( /* EPn */ if (ep->direct == USB_DIR_OUT) { /* OUT */ - if (bflag == FALSE) + if (!bflag) nret = _nbu2ss_epn_out_transfer(udc, ep, req); } else { /* IN */ @@ -1300,7 +1290,7 @@ static void _nbu2ss_restert_transfer(struct nbu2ss_ep *ep) else req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - if (req == NULL) + if (!req) return; if (ep->epnum > 0) { @@ -1398,7 +1388,6 @@ static void _nbu2ss_set_endpoint_stall( } } - /*-------------------------------------------------------------------------*/ /* Device Descriptor */ static struct usb_device_descriptor device_desc = { @@ -1447,7 +1436,7 @@ static int _nbu2ss_set_feature_device( switch (selector) { case USB_DEVICE_REMOTE_WAKEUP: - if (0x0000 == wIndex) { + if (wIndex == 0x0000) { udc->remote_wakeup = U2F_ENABLE; result = 0; } @@ -1504,8 +1493,8 @@ static inline int _nbu2ss_req_feature(struct nbu2ss_udc *udc, bool bset) u8 ep_adrs; int result = -EOPNOTSUPP; - if ((0x0000 != udc->ctrl.wLength) || - (USB_DIR_OUT != direction)) { + if ((udc->ctrl.wLength != 0x0000) || + (direction != USB_DIR_OUT)) { return -EINVAL; } @@ -1518,9 +1507,9 @@ static inline int _nbu2ss_req_feature(struct nbu2ss_udc *udc, bool bset) case USB_RECIP_ENDPOINT: if (0x0000 == (wIndex & 0xFF70)) { - if (USB_ENDPOINT_HALT == selector) { + if (selector == USB_ENDPOINT_HALT) { ep_adrs = wIndex & 0xFF; - if (bset == FALSE) { + if (!bset) { _nbu2ss_endpoint_toggle_reset( udc, ep_adrs); } @@ -1597,8 +1586,8 @@ static int std_req_get_status(struct nbu2ss_udc *udc) u8 ep_adrs; int result = -EINVAL; - if ((0x0000 != udc->ctrl.wValue) - || (USB_DIR_IN != direction)) { + if ((udc->ctrl.wValue != 0x0000) + || (direction != USB_DIR_IN)) { return result; } @@ -1635,7 +1624,7 @@ static int std_req_get_status(struct nbu2ss_udc *udc) if (result >= 0) { memcpy(udc->ep0_buf, &status_data, length); _nbu2ss_create_ep0_packet(udc, udc->ep0_buf, length); - _nbu2ss_ep0_in_transfer(udc, &udc->ep[0], &udc->ep0_req); + _nbu2ss_ep0_in_transfer(udc, &udc->ep0_req); } else { dev_err(udc->dev, " Error GET_STATUS\n"); @@ -1662,9 +1651,9 @@ static int std_req_set_address(struct nbu2ss_udc *udc) int result = 0; u32 wValue = udc->ctrl.wValue; - if ((0x00 != udc->ctrl.bRequestType) || - (0x0000 != udc->ctrl.wIndex) || - (0x0000 != udc->ctrl.wLength)) { + if ((udc->ctrl.bRequestType != 0x00) || + (udc->ctrl.wIndex != 0x0000) || + (udc->ctrl.wLength != 0x0000)) { return -EINVAL; } @@ -1684,9 +1673,9 @@ static int std_req_set_configuration(struct nbu2ss_udc *udc) { u32 ConfigValue = (u32)(udc->ctrl.wValue & 0x00ff); - if ((0x0000 != udc->ctrl.wIndex) || - (0x0000 != udc->ctrl.wLength) || - (0x00 != udc->ctrl.bRequestType)) { + if ((udc->ctrl.wIndex != 0x0000) || + (udc->ctrl.wLength != 0x0000) || + (udc->ctrl.bRequestType != 0x00)) { return -EINVAL; } @@ -1707,7 +1696,7 @@ static int std_req_set_configuration(struct nbu2ss_udc *udc) /*-------------------------------------------------------------------------*/ static inline void _nbu2ss_read_request_data(struct nbu2ss_udc *udc, u32 *pdata) { - if ((udc == NULL) && (pdata == NULL)) + if ((!udc) && (!pdata)) return; *pdata = _nbu2ss_readl(&udc->p_regs->SETUP_DATA0); @@ -1767,7 +1756,7 @@ static inline int _nbu2ss_decode_request(struct nbu2ss_udc *udc) } } - if (bcall_back == FALSE) { + if (!bcall_back) { if (udc->ep0state == EP0_IN_STATUS_PHASE) { if (nret >= 0) { /*--------------------------------------*/ @@ -1800,13 +1789,13 @@ static inline int _nbu2ss_ep0_in_data_stage(struct nbu2ss_udc *udc) else req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - if (req == NULL) + if (!req) req = &udc->ep0_req; req->req.actual += req->div_len; req->div_len = 0; - nret = _nbu2ss_ep0_in_transfer(udc, ep, req); + nret = _nbu2ss_ep0_in_transfer(udc, req); if (nret == 0) { udc->ep0state = EP0_OUT_STATUS_PAHSE; EP0_receive_NULL(udc, TRUE); @@ -1827,10 +1816,10 @@ static inline int _nbu2ss_ep0_out_data_stage(struct nbu2ss_udc *udc) else req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - if (req == NULL) + if (!req) req = &udc->ep0_req; - nret = _nbu2ss_ep0_out_transfer(udc, ep, req); + nret = _nbu2ss_ep0_out_transfer(udc, req); if (nret == 0) { udc->ep0state = EP0_IN_STATUS_PHASE; EP0_send_NULL(udc, TRUE); @@ -1854,7 +1843,7 @@ static inline int _nbu2ss_ep0_status_stage(struct nbu2ss_udc *udc) else req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - if (req == NULL) { + if (!req) { req = &udc->ep0_req; if (req->req.complete) req->req.complete(&ep->ep, &req->req); @@ -2055,7 +2044,7 @@ static inline void _nbu2ss_epn_in_dma_int( preq = &req->req; - if (req->dma_flag == FALSE) + if (!req->dma_flag) return; preq->actual += req->div_len; @@ -2161,7 +2150,7 @@ static inline void _nbu2ss_epn_int(struct nbu2ss_udc *udc, u32 epnum) else req = list_entry(ep->queue.next, struct nbu2ss_req, queue); - if (req == NULL) { + if (!req) { /* pr_warn("=== %s(%d) req == NULL\n", __func__, epnum); */ return; } @@ -2199,7 +2188,6 @@ static void _nbu2ss_ep0_enable(struct nbu2ss_udc *udc) _nbu2ss_writel(&udc->p_regs->EP0_INT_ENA, EP0_INT_EN_BIT); } - /*-------------------------------------------------------------------------*/ static int _nbu2ss_nuke(struct nbu2ss_udc *udc, struct nbu2ss_ep *ep, @@ -2335,7 +2323,6 @@ static int _nbu2ss_enable_controller(struct nbu2ss_udc *udc) return 0; } - /*-------------------------------------------------------------------------*/ static void _nbu2ss_reset_controller(struct nbu2ss_udc *udc) { @@ -2568,13 +2555,13 @@ static int nbu2ss_ep_enable( struct nbu2ss_ep *ep; struct nbu2ss_udc *udc; - if ((_ep == NULL) || (desc == NULL)) { + if ((!_ep) || (!desc)) { pr_err(" *** %s, bad param\n", __func__); return -EINVAL; } ep = container_of(_ep, struct nbu2ss_ep, ep); - if ((ep == NULL) || (ep->udc == NULL)) { + if ((!ep) || (!ep->udc)) { pr_err(" *** %s, ep == NULL !!\n", __func__); return -EINVAL; } @@ -2591,7 +2578,7 @@ static int nbu2ss_ep_enable( if (udc->vbus_active == 0) return -ESHUTDOWN; - if ((udc->driver == NULL) + if ((!udc->driver) || (udc->gadget.speed == USB_SPEED_UNKNOWN)) { dev_err(ep->udc->dev, " *** %s, udc !!\n", __func__); @@ -2628,13 +2615,13 @@ static int nbu2ss_ep_disable(struct usb_ep *_ep) struct nbu2ss_udc *udc; unsigned long flags; - if (_ep == NULL) { + if (!_ep) { pr_err(" *** %s, bad param\n", __func__); return -EINVAL; } ep = container_of(_ep, struct nbu2ss_ep, ep); - if ((ep == NULL) || (ep->udc == NULL)) { + if ((!ep) || (!ep->udc)) { pr_err("udc: *** %s, ep == NULL !!\n", __func__); return -EINVAL; } @@ -2676,7 +2663,7 @@ static void nbu2ss_ep_free_request( { struct nbu2ss_req *req; - if (_req != NULL) { + if (_req) { req = container_of(_req, struct nbu2ss_req, req); kfree(req); @@ -2697,11 +2684,11 @@ static int nbu2ss_ep_queue( int result = -EINVAL; /* catch various bogus parameters */ - if ((_ep == NULL) || (_req == NULL)) { - if (_ep == NULL) + if ((!_ep) || (!_req)) { + if (!_ep) pr_err("udc: %s --- _ep == NULL\n", __func__); - if (_req == NULL) + if (!_req) pr_err("udc: %s --- _req == NULL\n", __func__); return -EINVAL; @@ -2747,7 +2734,7 @@ static int nbu2ss_ep_queue( req->unaligned = FALSE; if (req->unaligned) { - if (ep->virt_buf == NULL) + if (!ep->virt_buf) ep->virt_buf = (u8 *)dma_alloc_coherent( NULL, PAGE_SIZE, &ep->phys_buf, GFP_ATOMIC | GFP_DMA); @@ -2769,7 +2756,7 @@ static int nbu2ss_ep_queue( bflag = list_empty(&ep->queue); list_add_tail(&req->queue, &ep->queue); - if ((bflag != FALSE) && (ep->stalled == FALSE)) { + if (bflag && !ep->stalled) { result = _nbu2ss_start_transfer(udc, ep, req, FALSE); if (result < 0) { @@ -2803,7 +2790,7 @@ static int nbu2ss_ep_dequeue( unsigned long flags; /* catch various bogus parameters */ - if ((_ep == NULL) || (_req == NULL)) { + if ((!_ep) || (!_req)) { /* pr_err("%s, bad param(1)\n", __func__); */ return -EINVAL; } @@ -2815,7 +2802,7 @@ static int nbu2ss_ep_dequeue( } udc = ep->udc; - if (udc == NULL) + if (!udc) return -EINVAL; spin_lock_irqsave(&udc->lock, flags); @@ -2989,7 +2976,6 @@ static struct usb_ep_ops nbu2ss_ep_ops = { .fifo_flush = nbu2ss_ep_fifo_flush, }; - /*-------------------------------------------------------------------------*/ /* usb_gadget_ops */ @@ -2999,13 +2985,13 @@ static int nbu2ss_gad_get_frame(struct usb_gadget *pgadget) u32 data; struct nbu2ss_udc *udc; - if (pgadget == NULL) { + if (!pgadget) { pr_err("udc: %s, bad param\n", __func__); return -EINVAL; } udc = container_of(pgadget, struct nbu2ss_udc, gadget); - if (udc == NULL) { + if (!udc) { dev_err(&pgadget->dev, "%s, udc == NULL\n", __func__); return -EINVAL; } @@ -3027,13 +3013,13 @@ static int nbu2ss_gad_wakeup(struct usb_gadget *pgadget) struct nbu2ss_udc *udc; - if (pgadget == NULL) { + if (!pgadget) { pr_err("%s, bad param\n", __func__); return -EINVAL; } udc = container_of(pgadget, struct nbu2ss_udc, gadget); - if (udc == NULL) { + if (!udc) { dev_err(&pgadget->dev, "%s, udc == NULL\n", __func__); return -EINVAL; } @@ -3065,7 +3051,7 @@ static int nbu2ss_gad_set_selfpowered(struct usb_gadget *pgadget, struct nbu2ss_udc *udc; unsigned long flags; - if (pgadget == NULL) { + if (!pgadget) { pr_err("%s, bad param\n", __func__); return -EINVAL; } @@ -3091,7 +3077,7 @@ static int nbu2ss_gad_vbus_draw(struct usb_gadget *pgadget, unsigned mA) struct nbu2ss_udc *udc; unsigned long flags; - if (pgadget == NULL) { + if (!pgadget) { pr_err("%s, bad param\n", __func__); return -EINVAL; } @@ -3111,14 +3097,14 @@ static int nbu2ss_gad_pullup(struct usb_gadget *pgadget, int is_on) struct nbu2ss_udc *udc; unsigned long flags; - if (pgadget == NULL) { + if (!pgadget) { pr_err("%s, bad param\n", __func__); return -EINVAL; } udc = container_of(pgadget, struct nbu2ss_udc, gadget); - if (udc->driver == NULL) { + if (!udc->driver) { pr_warn("%s, Not Regist Driver\n", __func__); return -EINVAL; } @@ -3142,7 +3128,6 @@ static int nbu2ss_gad_ioctl( return 0; } - static const struct usb_gadget_ops nbu2ss_gadget_ops = { .get_frame = nbu2ss_gad_get_frame, .wakeup = nbu2ss_gad_wakeup, @@ -3295,14 +3280,14 @@ static int nbu2ss_drv_probe(struct platform_device *pdev) /* USB Function Controller Interrupt */ if (status != 0) { dev_err(udc->dev, "request_irq(USB_UDC_IRQ_1) failed\n"); - goto cleanup1; + return status; } /* Driver Initialization */ status = nbu2ss_drv_contest_init(pdev, udc); if (status < 0) { /* Error */ - goto cleanup1; + return status; } /* VBUS Interrupt */ @@ -3315,13 +3300,10 @@ static int nbu2ss_drv_probe(struct platform_device *pdev) if (status != 0) { dev_err(udc->dev, "request_irq(INT_VBUS) failed\n"); - goto cleanup1; + return status; } return status; - -cleanup1: - return status; } /*-------------------------------------------------------------------------*/ @@ -3330,41 +3312,19 @@ static void nbu2ss_drv_shutdown(struct platform_device *pdev) struct nbu2ss_udc *udc; udc = platform_get_drvdata(pdev); - if (udc == NULL) + if (!udc) return; _nbu2ss_disable_controller(udc); } -/*-------------------------------------------------------------------------*/ -static int __exit nbu2ss_drv_remove(struct platform_device *pdev) -{ - struct nbu2ss_udc *udc; - struct nbu2ss_ep *ep; - int i; - - udc = &udc_controller; - - for (i = 0; i < NUM_ENDPOINTS; i++) { - ep = &udc->ep[i]; - if (ep->virt_buf) - dma_free_coherent(NULL, PAGE_SIZE, - (void *)ep->virt_buf, ep->phys_buf); - } - - /* Interrupt Handler - Release */ - free_irq(INT_VBUS, udc); - - return 0; -} - /*-------------------------------------------------------------------------*/ static int nbu2ss_drv_suspend(struct platform_device *pdev, pm_message_t state) { struct nbu2ss_udc *udc; udc = platform_get_drvdata(pdev); - if (udc == NULL) + if (!udc) return 0; if (udc->vbus_active) { @@ -3391,7 +3351,7 @@ static int nbu2ss_drv_resume(struct platform_device *pdev) struct nbu2ss_udc *udc; udc = platform_get_drvdata(pdev); - if (udc == NULL) + if (!udc) return 0; data = gpio_get_value(VBUS_VALUE); @@ -3407,22 +3367,15 @@ static int nbu2ss_drv_resume(struct platform_device *pdev) return 0; } - static struct platform_driver udc_driver = { .probe = nbu2ss_drv_probe, .shutdown = nbu2ss_drv_shutdown, - .remove = __exit_p(nbu2ss_drv_remove), .suspend = nbu2ss_drv_suspend, .resume = nbu2ss_drv_resume, .driver = { - .name = driver_name, + .name = driver_name, + .suppress_bind_attrs = true, }, }; -module_platform_driver(udc_driver); - -MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_AUTHOR("Renesas Electronics Corporation"); -MODULE_LICENSE("GPL"); - - +builtin_platform_driver(udc_driver); diff --git a/drivers/staging/emxx_udc/emxx_udc.h b/drivers/staging/emxx_udc/emxx_udc.h index 0db6b41333ea..4a2cc38de7b3 100644 --- a/drivers/staging/emxx_udc/emxx_udc.h +++ b/drivers/staging/emxx_udc/emxx_udc.h @@ -11,20 +11,11 @@ * 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, Suite 500, Boston, MA 02110-1335, USA. */ - - - #ifndef _LINUX_EMXX_H #define _LINUX_EMXX_H - - /*---------------------------------------------------------------------------*/ /*----------------- Default undef */ #if 0 @@ -36,14 +27,11 @@ #define USE_DMA 1 #define USE_SUSPEND_WAIT 1 - - #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif - /*------------ Board dependence(Resource) */ #define VBUS_VALUE GPIO_VBUS @@ -58,15 +46,11 @@ /* DMA Abort wait time ms */ #define DMA_DISABLE_TIME 10 - - /*------------ Controller dependence */ #define NUM_ENDPOINTS 14 /* Endpoint */ #define REG_EP_NUM 15 /* Endpoint Register */ #define DMA_MAX_COUNT 256 /* DMA Block */ - - #define EPC_RST_DISABLE_TIME 1 /* 1 usec */ #define EPC_DIRPD_DISABLE_TIME 1 /* 1 msec */ #define EPC_PLL_LOCK_COUNT 1000 /* 1000 */ @@ -75,12 +59,10 @@ #define CHATGER_TIME 700 /* 700msec */ #define USB_SUSPEND_TIME 2000 /* 2 sec */ - /* U2F FLAG */ #define U2F_ENABLE 1 #define U2F_DISABLE 0 - /*------- BIT */ #define BIT00 0x00000001 #define BIT01 0x00000002 @@ -460,8 +442,6 @@ /*------- (0x1118:) EPnTADR Register */ #define EPn_TADR 0xFFFFFFFF /* RW */ - - /*===========================================================================*/ /* Struct */ /*------- ep_regs */ @@ -526,13 +506,6 @@ struct fc_regs { u8 Reserved1200[0x1000-0x200]; /* Reserved */ } __aligned(32); - - - - - - - #define EP0_PACKETSIZE 64 #define EP_PACKETSIZE 1024 @@ -543,10 +516,8 @@ struct fc_regs { #define D_FS_RAM_SIZE_BULK 64 #define D_HS_RAM_SIZE_BULK 512 - struct nbu2ss_udc; - enum ep0_state { EP0_IDLE, EP0_IN_DATA_PHASE, @@ -591,7 +562,6 @@ struct nbu2ss_ep { dma_addr_t phys_buf; }; - struct nbu2ss_udc { struct usb_gadget gadget; struct usb_gadget_driver *driver; diff --git a/drivers/staging/fbtft/Kconfig b/drivers/staging/fbtft/Kconfig index d473010fa474..883ff5b8fdab 100644 --- a/drivers/staging/fbtft/Kconfig +++ b/drivers/staging/fbtft/Kconfig @@ -141,6 +141,16 @@ config FB_TFT_ST7735R help Generic Framebuffer support for ST7735R +config FB_TFT_ST7789V + tristate "FB driver for the ST7789V LCD Controller" + depends on FB_TFT + help + This enables generic framebuffer support for the Sitronix ST7789V + display controller. The controller is intended for small color + displays with a resolution of up to 320x240 pixels. + + Say Y if you have such a display that utilizes this controller. + config FB_TFT_TINYLCD tristate "FB driver for tinylcd.com display" depends on FB_TFT diff --git a/drivers/staging/fbtft/Makefile b/drivers/staging/fbtft/Makefile index b26efdc87775..4f9071d96d01 100644 --- a/drivers/staging/fbtft/Makefile +++ b/drivers/staging/fbtft/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_FB_TFT_SSD1306) += fb_ssd1306.o obj-$(CONFIG_FB_TFT_SSD1331) += fb_ssd1331.o obj-$(CONFIG_FB_TFT_SSD1351) += fb_ssd1351.o obj-$(CONFIG_FB_TFT_ST7735R) += fb_st7735r.o +obj-$(CONFIG_FB_TFT_ST7789V) += fb_st7789v.o obj-$(CONFIG_FB_TFT_TINYLCD) += fb_tinylcd.o obj-$(CONFIG_FB_TFT_TLS8204) += fb_tls8204.o obj-$(CONFIG_FB_TFT_UC1611) += fb_uc1611.o diff --git a/drivers/staging/fbtft/fb_agm1264k-fl.c b/drivers/staging/fbtft/fb_agm1264k-fl.c index 94dd49ce18de..2a50cf957101 100644 --- a/drivers/staging/fbtft/fb_agm1264k-fl.c +++ b/drivers/staging/fbtft/fb_agm1264k-fl.c @@ -41,8 +41,7 @@ #define CS0 gpio.aux[0] #define CS1 gpio.aux[1] - -/* diffusing error (“Floyd-Steinberg”) */ +/* diffusing error (Floyd-Steinberg) */ #define DIFFUSING_MATRIX_WIDTH 2 #define DIFFUSING_MATRIX_HEIGHT 2 @@ -75,8 +74,6 @@ static int init_display(struct fbtft_par *par) { u8 i; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); for (i = 0; i < 2; ++i) { @@ -180,7 +177,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...) { va_list args; int i, ret; - u8 *buf = (u8 *)par->buf; + u8 *buf = par->buf; if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) { va_start(args, len); @@ -245,10 +242,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) addr_win.ys_page = ys / 8; addr_win.xe = xe; addr_win.ye_page = ye / 8; - - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys_page=%d, xe=%d, ye_page=%d)\n", __func__, - addr_win.xs, addr_win.ys_page, addr_win.xe, addr_win.ye_page); } static void @@ -273,7 +266,7 @@ construct_line_bitmap(struct fbtft_par *par, u8 *dest, signed short *src, static int write_vmem(struct fbtft_par *par, size_t offset, size_t len) { - u16 *vmem16 = (u16 *)par->info->screen_base; + u16 *vmem16 = (u16 *)par->info->screen_buffer; u8 *buf = par->txbuf.buf; int x, y; int ret = 0; @@ -285,8 +278,6 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len) if (!convert_buf) return -ENOMEM; - fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__); - /* converting to grayscale16 */ for (x = 0; x < par->info->var.xres; ++x) for (y = 0; y < par->info->var.yres; ++y) { @@ -420,7 +411,6 @@ static int write(struct fbtft_par *par, void *buf, size_t len) gpio_set_value(par->RW, 0); /* set write mode */ - while (len--) { u8 i, data; @@ -456,6 +446,7 @@ static struct fbtft_display display = { .write_vmem = write_vmem, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "displaytronic,fb_agm1264k-fl", &display); MODULE_ALIAS("platform:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_bd663474.c b/drivers/staging/fbtft/fb_bd663474.c index 17a2162a7e5b..6010e6cbbd72 100644 --- a/drivers/staging/fbtft/fb_bd663474.c +++ b/drivers/staging/fbtft/fb_bd663474.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 @@ -37,8 +33,6 @@ static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - if (par->gpio.cs != -1) gpio_set_value(par->gpio.cs, 0); /* Activate chip */ @@ -122,8 +116,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); switch (par->info->var.rotate) { /* R200h = Horizontal GRAM Start Address */ /* R201h = Vertical GRAM Start Address */ @@ -149,8 +141,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) static int set_var(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - switch (par->info->var.rotate) { /* AM: GRAM update direction */ case 0: @@ -181,6 +171,7 @@ static struct fbtft_display display = { .set_var = set_var, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "hitachi,bd663474", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_hx8340bn.c b/drivers/staging/fbtft/fb_hx8340bn.c index 54528aa0c0ef..e1ed177f9184 100644 --- a/drivers/staging/fbtft/fb_hx8340bn.c +++ b/drivers/staging/fbtft/fb_hx8340bn.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. */ #include @@ -39,12 +35,10 @@ #define DEFAULT_GAMMA "1 3 0E 5 0 2 09 0 6 1 7 1 0 2 2\n" \ "3 3 17 8 4 7 05 7 6 0 3 1 6 0 0 " - static bool emulate; module_param(emulate, bool, 0); MODULE_PARM_DESC(emulate, "Force emulation in 9-bit mode"); - static int init_display(struct fbtft_par *par) { par->fbtftops.reset(par); @@ -117,9 +111,9 @@ static int set_var(struct fbtft_par *par) { /* MADCTL - Memory data access control */ /* RGB/BGR can be set with H/W pin SRGB and MADCTL BGR bit */ -#define MY (1 << 7) -#define MX (1 << 6) -#define MV (1 << 5) +#define MY BIT(7) +#define MX BIT(6) +#define MV BIT(5) switch (par->info->var.rotate) { case 0: write_reg(par, 0x36, par->bgr << 3); @@ -145,7 +139,7 @@ static int set_var(struct fbtft_par *par) OP0 OP1 CP0 CP1 CP2 CP3 CP4 MP0 MP1 MP2 MP3 MP4 MP5 CGM0 CGM1 ON0 ON1 CN0 CN1 CN2 CN3 CN4 MN0 MN1 MN2 MN3 MN4 MN5 XXXX GC */ -#define CURVE(num, idx) curves[num*par->gamma.num_values + idx] +#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] static int set_gamma(struct fbtft_par *par, unsigned long *curves) { unsigned long mask[] = { @@ -192,7 +186,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) } #undef CURVE - static struct fbtft_display display = { .regwidth = 8, .width = WIDTH, @@ -208,6 +201,7 @@ static struct fbtft_display display = { .set_gamma = set_gamma, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8340bn", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_hx8347d.c b/drivers/staging/fbtft/fb_hx8347d.c index 03ae95b4f79e..6ff76e531a37 100644 --- a/drivers/staging/fbtft/fb_hx8347d.c +++ b/drivers/staging/fbtft/fb_hx8347d.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 @@ -33,11 +29,8 @@ #define DEFAULT_GAMMA "0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" \ "0 0 0 0 0 0 0 0 0 0 0 0 0 0" - static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); /* driving ability */ @@ -92,9 +85,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - write_reg(par, 0x02, (xs >> 8) & 0xFF); write_reg(par, 0x03, xs & 0xFF); write_reg(par, 0x04, (xe >> 8) & 0xFF); @@ -111,7 +101,7 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) VRP0 VRP1 VRP2 VRP3 VRP4 VRP5 PRP0 PRP1 PKP0 PKP1 PKP2 PKP3 PKP4 CGM VRN0 VRN1 VRN2 VRN3 VRN4 VRN5 PRN0 PRN1 PKN0 PKN1 PKN2 PKN3 PKN4 CGM */ -#define CURVE(num, idx) curves[num*par->gamma.num_values + idx] +#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] static int set_gamma(struct fbtft_par *par, unsigned long *curves) { unsigned long mask[] = { @@ -121,8 +111,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) int i, j; int acc = 0; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - /* apply mask */ for (i = 0; i < par->gamma.num_curves; i++) for (j = 0; j < par->gamma.num_values; j++) { @@ -154,7 +142,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) } #undef CURVE - static struct fbtft_display display = { .regwidth = 8, .width = WIDTH, @@ -168,6 +155,7 @@ static struct fbtft_display display = { .set_gamma = set_gamma, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8347d", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_hx8353d.c b/drivers/staging/fbtft/fb_hx8353d.c index d7f4308e1249..8552411695fa 100644 --- a/drivers/staging/fbtft/fb_hx8353d.c +++ b/drivers/staging/fbtft/fb_hx8353d.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 @@ -32,8 +28,6 @@ static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); mdelay(150); @@ -78,9 +72,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - /* column address */ write_reg(par, 0x2a, xs >> 8, xs & 0xff, xe >> 8, xe & 0xff); @@ -91,13 +82,11 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) write_reg(par, 0x2c); } -#define my (1 << 7) -#define mx (1 << 6) -#define mv (1 << 5) +#define my BIT(7) +#define mx BIT(6) +#define mv BIT(5) static int set_var(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - /* madctl - memory data access control rgb/bgr: 1. mode selection pin srgb @@ -127,8 +116,6 @@ static int set_var(struct fbtft_par *par) */ static int set_gamma(struct fbtft_par *par, unsigned long *curves) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - write_reg(par, 0xE0, curves[0], curves[1], curves[2], curves[3], curves[4], curves[5], curves[6], curves[7], @@ -139,7 +126,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) return 0; } - static struct fbtft_display display = { .regwidth = 8, .width = 128, @@ -154,6 +140,7 @@ static struct fbtft_display display = { .set_gamma = set_gamma, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8353d", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_hx8357d.c b/drivers/staging/fbtft/fb_hx8357d.c index 8c7bb3ac8030..a381dbcf5535 100644 --- a/drivers/staging/fbtft/fb_hx8357d.c +++ b/drivers/staging/fbtft/fb_hx8357d.c @@ -16,9 +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, see . */ #include @@ -33,11 +30,8 @@ #define WIDTH 320 #define HEIGHT 480 - static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); /* Reset things like Gamma */ @@ -145,9 +139,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - /* Column addr set */ write_reg(par, HX8357_CASET, xs >> 8, xs & 0xff, /* XSTART */ @@ -173,8 +164,6 @@ static int set_var(struct fbtft_par *par) { u8 val; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - switch (par->info->var.rotate) { case 270: val = HX8357D_MADCTL_MV | HX8357D_MADCTL_MX; @@ -210,6 +199,7 @@ static struct fbtft_display display = { .set_var = set_var, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8357d", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_ili9163.c b/drivers/staging/fbtft/fb_ili9163.c index ed92a64306ff..f31b3f4b9275 100644 --- a/drivers/staging/fbtft/fb_ili9163.c +++ b/drivers/staging/fbtft/fb_ili9163.c @@ -108,8 +108,6 @@ create setup for different displays. static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); if (par->gpio.cs != -1) @@ -149,9 +147,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - switch (par->info->var.rotate) { case 0: write_reg(par, CMD_CLMADRS, xs >> 8, xs & 0xff, xe >> 8, @@ -204,8 +199,6 @@ static int set_var(struct fbtft_par *par) { u8 mactrl_data = 0; /* Avoid compiler warning */ - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - switch (par->info->var.rotate) { case 0: mactrl_data = 0x08; @@ -230,7 +223,7 @@ static int set_var(struct fbtft_par *par) } #ifdef GAMMA_ADJ -#define CURVE(num, idx) curves[num*par->gamma.num_values + idx] +#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] static int gamma_adj(struct fbtft_par *par, unsigned long *curves) { unsigned long mask[] = { @@ -239,11 +232,9 @@ static int gamma_adj(struct fbtft_par *par, unsigned long *curves) 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}; int i, j; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - for (i = 0; i < GAMMA_NUM; i++) for (j = 0; j < GAMMA_LEN; j++) - CURVE(i, j) &= mask[i*par->gamma.num_values + j]; + CURVE(i, j) &= mask[i * par->gamma.num_values + j]; write_reg(par, CMD_PGAMMAC, CURVE(0, 0), diff --git a/drivers/staging/fbtft/fb_ili9320.c b/drivers/staging/fbtft/fb_ili9320.c index ef4fa6b72c79..3ed50febe36f 100644 --- a/drivers/staging/fbtft/fb_ili9320.c +++ b/drivers/staging/fbtft/fb_ili9320.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. */ #include @@ -33,7 +29,6 @@ #define DEFAULT_GAMMA "07 07 6 0 0 0 5 5 4 0\n" \ "07 08 4 7 5 1 2 0 7 7" - static unsigned read_devicecode(struct fbtft_par *par) { int ret; @@ -48,8 +43,6 @@ static int init_display(struct fbtft_par *par) { unsigned devcode; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); devcode = read_devicecode(par); @@ -96,7 +89,6 @@ static int init_display(struct fbtft_par *par) /* RGB interface polarity */ write_reg(par, 0x000F, 0x0000); - /* ***********Power On sequence *************** */ /* SAP, BT[3:0], AP, DSTB, SLP, STB */ write_reg(par, 0x0010, 0x0000); @@ -181,9 +173,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - switch (par->info->var.rotate) { /* R20h = Horizontal GRAM Start Address */ /* R21h = Vertical GRAM Start Address */ @@ -209,8 +198,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) static int set_var(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - switch (par->info->var.rotate) { case 0: write_reg(par, 0x3, (par->bgr << 12) | 0x30); @@ -233,7 +220,7 @@ static int set_var(struct fbtft_par *par) VRP0 VRP1 RP0 RP1 KP0 KP1 KP2 KP3 KP4 KP5 VRN0 VRN1 RN0 RN1 KN0 KN1 KN2 KN3 KN4 KN5 */ -#define CURVE(num, idx) curves[num*par->gamma.num_values + idx] +#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] static int set_gamma(struct fbtft_par *par, unsigned long *curves) { unsigned long mask[] = { @@ -242,12 +229,10 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) }; int i, j; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - /* apply mask */ for (i = 0; i < 2; i++) for (j = 0; j < 10; j++) - CURVE(i, j) &= mask[i*par->gamma.num_values + j]; + CURVE(i, j) &= mask[i * par->gamma.num_values + j]; write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4)); write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6)); @@ -265,7 +250,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) } #undef CURVE - static struct fbtft_display display = { .regwidth = 16, .width = WIDTH, @@ -280,6 +264,7 @@ static struct fbtft_display display = { .set_gamma = set_gamma, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9320", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_ili9325.c b/drivers/staging/fbtft/fb_ili9325.c index 19d254e9a420..3b3a06d8a125 100644 --- a/drivers/staging/fbtft/fb_ili9325.c +++ b/drivers/staging/fbtft/fb_ili9325.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 @@ -36,7 +32,6 @@ #define DEFAULT_GAMMA "0F 00 7 2 0 0 6 5 4 1\n" \ "04 16 2 7 6 3 2 1 7 7" - static unsigned bt = 6; /* VGL=Vci*4 , VGH=Vci*4 */ module_param(bt, uint, 0); MODULE_PARM_DESC(bt, "Sets the factor used in the step-up circuits"); @@ -60,7 +55,6 @@ static unsigned vcm = 0x0a; /* VCOMH=VREG1OUT*0.735 */ module_param(vcm, uint, 0); MODULE_PARM_DESC(vcm, "Set the internal VcomH voltage"); - /* Verify that this configuration is within the Voltage limits @@ -101,8 +95,6 @@ VCOMH - VCOML < 6.0 => 4.79 < 6.0 static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); if (par->gpio.cs != -1) @@ -176,8 +168,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); switch (par->info->var.rotate) { /* R20h = Horizontal GRAM Start Address */ /* R21h = Vertical GRAM Start Address */ @@ -203,8 +193,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) static int set_var(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - switch (par->info->var.rotate) { /* AM: GRAM update direction */ case 0: @@ -229,7 +217,7 @@ static int set_var(struct fbtft_par *par) VRP0 VRP1 RP0 RP1 KP0 KP1 KP2 KP3 KP4 KP5 VRN0 VRN1 RN0 RN1 KN0 KN1 KN2 KN3 KN4 KN5 */ -#define CURVE(num, idx) curves[num*par->gamma.num_values + idx] +#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] static int set_gamma(struct fbtft_par *par, unsigned long *curves) { unsigned long mask[] = { @@ -238,12 +226,10 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) }; int i, j; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - /* apply mask */ for (i = 0; i < 2; i++) for (j = 0; j < 10; j++) - CURVE(i, j) &= mask[i*par->gamma.num_values + j]; + CURVE(i, j) &= mask[i * par->gamma.num_values + j]; write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4)); write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6)); @@ -261,7 +247,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) } #undef CURVE - static struct fbtft_display display = { .regwidth = 16, .width = WIDTH, @@ -278,6 +263,7 @@ static struct fbtft_display display = { .set_gamma = set_gamma, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9325", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_ili9340.c b/drivers/staging/fbtft/fb_ili9340.c index 0f4a42f89e5e..e0e253989271 100644 --- a/drivers/staging/fbtft/fb_ili9340.c +++ b/drivers/staging/fbtft/fb_ili9340.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. */ #include @@ -30,12 +26,9 @@ #define WIDTH 240 #define HEIGHT 320 - /* Init sequence taken from: Arduino Library for the Adafruit 2.2" display */ static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); write_reg(par, 0xEF, 0x03, 0x80, 0x02); @@ -98,9 +91,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - /* Column address */ write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF); @@ -118,8 +108,6 @@ static int set_var(struct fbtft_par *par) { u8 val; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - switch (par->info->var.rotate) { case 270: val = ILI9340_MADCTL_MV; @@ -140,7 +128,6 @@ static int set_var(struct fbtft_par *par) return 0; } - static struct fbtft_display display = { .regwidth = 8, .width = WIDTH, @@ -151,6 +138,7 @@ static struct fbtft_display display = { .set_var = set_var, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9340", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_ili9341.c b/drivers/staging/fbtft/fb_ili9341.c index 709492e560b6..dcee0aff5875 100644 --- a/drivers/staging/fbtft/fb_ili9341.c +++ b/drivers/staging/fbtft/fb_ili9341.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. */ #include @@ -38,11 +34,8 @@ #define DEFAULT_GAMMA "1F 1A 18 0A 0F 06 45 87 32 0A 07 02 07 05 00\n" \ "00 25 27 05 10 09 3A 78 4D 05 18 0D 38 3A 1F" - static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); /* startup sequence for MI0283QT-9A */ @@ -82,9 +75,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - /* Column address set */ write_reg(par, 0x2A, (xs >> 8) & 0xFF, xs & 0xFF, (xe >> 8) & 0xFF, xe & 0xFF); @@ -105,15 +95,13 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) #define MEM_BGR (3) /* RGB-BGR Order */ static int set_var(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - switch (par->info->var.rotate) { case 0: write_reg(par, 0x36, (1 << MEM_X) | (par->bgr << MEM_BGR)); break; case 270: write_reg(par, 0x36, - (1<bgr << MEM_BGR)); + (1 << MEM_V) | (1 << MEM_L) | (par->bgr << MEM_BGR)); break; case 180: write_reg(par, 0x36, (1 << MEM_Y) | (par->bgr << MEM_BGR)); @@ -132,13 +120,11 @@ static int set_var(struct fbtft_par *par) Positive: Par1 Par2 [...] Par15 Negative: Par1 Par2 [...] Par15 */ -#define CURVE(num, idx) curves[num*par->gamma.num_values + idx] +#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] static int set_gamma(struct fbtft_par *par, unsigned long *curves) { int i; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - for (i = 0; i < par->gamma.num_curves; i++) write_reg(par, 0xE0 + i, CURVE(i, 0), CURVE(i, 1), CURVE(i, 2), @@ -151,7 +137,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) } #undef CURVE - static struct fbtft_display display = { .regwidth = 8, .width = WIDTH, @@ -167,6 +152,7 @@ static struct fbtft_display display = { .set_gamma = set_gamma, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9341", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_ili9481.c b/drivers/staging/fbtft/fb_ili9481.c index 8bae09c2d5ce..63684864f309 100644 --- a/drivers/staging/fbtft/fb_ili9481.c +++ b/drivers/staging/fbtft/fb_ili9481.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 @@ -57,9 +53,6 @@ static int default_init_sequence[] = { static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - /* column address */ write_reg(par, 0x2a, xs >> 8, xs & 0xff, xe >> 8, xe & 0xff); @@ -75,8 +68,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) #define ROWxCOL 0x20 static int set_var(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - switch (par->info->var.rotate) { case 270: write_reg(par, 0x36, ROWxCOL | HFLIP | VFLIP | (par->bgr << 3)); @@ -105,6 +96,7 @@ static struct fbtft_display display = { .set_var = set_var, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9481", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_ili9486.c b/drivers/staging/fbtft/fb_ili9486.c index dd4ddca384ad..d9dfff68159b 100644 --- a/drivers/staging/fbtft/fb_ili9486.c +++ b/drivers/staging/fbtft/fb_ili9486.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. */ #include @@ -28,7 +24,6 @@ #define WIDTH 320 #define HEIGHT 480 - /* this init sequence matches PiScreen */ static int default_init_sequence[] = { /* Interface Mode Control */ @@ -61,9 +56,6 @@ static int default_init_sequence[] = { static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - /* Column address */ write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF); @@ -76,8 +68,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) static int set_var(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - switch (par->info->var.rotate) { case 0: write_reg(par, 0x36, 0x80 | (par->bgr << 3)); @@ -98,7 +88,6 @@ static int set_var(struct fbtft_par *par) return 0; } - static struct fbtft_display display = { .regwidth = 8, .width = WIDTH, @@ -109,6 +98,7 @@ static struct fbtft_display display = { .set_var = set_var, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9486", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_pcd8544.c b/drivers/staging/fbtft/fb_pcd8544.c index 15da0ec77513..a6b43323f29a 100644 --- a/drivers/staging/fbtft/fb_pcd8544.c +++ b/drivers/staging/fbtft/fb_pcd8544.c @@ -15,10 +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. */ #include @@ -33,7 +29,7 @@ #define DRVNAME "fb_pcd8544" #define WIDTH 84 #define HEIGHT 48 -#define TXBUFLEN (84*6) +#define TXBUFLEN (84 * 6) #define DEFAULT_GAMMA "40" /* gamma controls the contrast in this driver */ static unsigned tc; @@ -44,11 +40,8 @@ static unsigned bs = 4; module_param(bs, uint, 0); MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)"); - static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); /* Function set @@ -101,9 +94,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", - __func__, xs, ys, xe, ye); - /* H=0 Set X address of RAM * * 7:1 1 @@ -122,25 +112,24 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) static int write_vmem(struct fbtft_par *par, size_t offset, size_t len) { - u16 *vmem16 = (u16 *)par->info->screen_base; + u16 *vmem16 = (u16 *)par->info->screen_buffer; u8 *buf = par->txbuf.buf; int x, y, i; int ret = 0; - fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__); - for (x = 0; x < 84; x++) { for (y = 0; y < 6; y++) { *buf = 0x00; for (i = 0; i < 8; i++) - *buf |= (vmem16[(y*8+i)*84+x] ? 1 : 0) << i; + *buf |= (vmem16[(y * 8 + i) * 84 + x] ? + 1 : 0) << i; buf++; } } /* Write data */ gpio_set_value(par->gpio.dc, 1); - ret = par->fbtftops.write(par, par->txbuf.buf, 6*84); + ret = par->fbtftops.write(par, par->txbuf.buf, 6 * 84); if (ret < 0) dev_err(par->info->device, "write failed and returned: %d\n", ret); @@ -150,8 +139,6 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len) static int set_gamma(struct fbtft_par *par, unsigned long *curves) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - /* apply mask */ curves[0] &= 0x7F; @@ -162,7 +149,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) return 0; } - static struct fbtft_display display = { .regwidth = 8, .width = WIDTH, @@ -179,6 +165,7 @@ static struct fbtft_display display = { }, .backlight = 1, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "philips,pdc8544", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_ra8875.c b/drivers/staging/fbtft/fb_ra8875.c index 54bc566b09fd..b167c5061631 100644 --- a/drivers/staging/fbtft/fb_ra8875.c +++ b/drivers/staging/fbtft/fb_ra8875.c @@ -1,19 +1,7 @@ -/****************************************************************************** - - ProjectName: FBTFT driver ***** ***** - for the RA8875 LCD Controller * * ************ - * ** ** * * - Copyright © by Pf@nne & NOTRO * * * * * **** * - * * * * * * * - Last modification by: * * * * **** * - - Pf@nne (pf@nne-mail.de) * * ***** * - * * * ******* - ***** * * - Date : 10.06.2014 * * - Version : V1.13 ***** - Revision : 5 - -******************************************************************************* +/* + * FBTFT driver for the RA8875 LCD Controller + * Copyright by Pf@nne & NOTRO + * * 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 @@ -23,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. */ #include @@ -197,18 +181,15 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - /* Set_Active_Window */ write_reg(par, 0x30, xs & 0x00FF); write_reg(par, 0x31, (xs & 0xFF00) >> 8); write_reg(par, 0x32, ys & 0x00FF); write_reg(par, 0x33, (ys & 0xFF00) >> 8); - write_reg(par, 0x34, (xs+xe) & 0x00FF); - write_reg(par, 0x35, ((xs+xe) & 0xFF00) >> 8); - write_reg(par, 0x36, (ys+ye) & 0x00FF); - write_reg(par, 0x37, ((ys+ye) & 0xFF00) >> 8); + write_reg(par, 0x34, (xs + xe) & 0x00FF); + write_reg(par, 0x35, ((xs + xe) & 0xFF00) >> 8); + write_reg(par, 0x36, (ys + ye) & 0x00FF); + write_reg(par, 0x37, ((ys + ye) & 0xFF00) >> 8); /* Set_Memory_Write_Cursor */ write_reg(par, 0x46, xs & 0xff); @@ -223,7 +204,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...) { va_list args; int i, ret; - u8 *buf = (u8 *)par->buf; + u8 *buf = par->buf; /* slow down spi-speed for writing registers */ par->fbtftops.write = write_spi; @@ -288,7 +269,7 @@ static int write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len) __func__, offset, len); remain = len / 2; - vmem16 = (u16 *)(par->info->screen_base + offset); + vmem16 = (u16 *)(par->info->screen_buffer + offset); tx_array_size = par->txbuf.len / 2; txbuf16 = (u16 *)(par->txbuf.buf + 1); tx_array_size -= 2; @@ -324,6 +305,7 @@ static struct fbtft_display display = { .write = write_spi, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "raio,ra8875", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_s6d02a1.c b/drivers/staging/fbtft/fb_s6d02a1.c index f3302525ec00..da85057eb3e0 100644 --- a/drivers/staging/fbtft/fb_s6d02a1.c +++ b/drivers/staging/fbtft/fb_s6d02a1.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 @@ -102,9 +98,6 @@ static int default_init_sequence[] = { static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - /* Column address */ write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF); @@ -115,13 +108,11 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) write_reg(par, 0x2C); } -#define MY (1 << 7) -#define MX (1 << 6) -#define MV (1 << 5) +#define MY BIT(7) +#define MX BIT(6) +#define MV BIT(5) static int set_var(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - /* MADCTL - Memory data access control RGB/BGR: 1. Mode selection pin SRGB @@ -156,6 +147,7 @@ static struct fbtft_display display = { .set_var = set_var, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "samsung,s6d02a1", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_s6d1121.c b/drivers/staging/fbtft/fb_s6d1121.c index 2e1b72ad54aa..d6ae76b318ad 100644 --- a/drivers/staging/fbtft/fb_s6d1121.c +++ b/drivers/staging/fbtft/fb_s6d1121.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 @@ -40,8 +36,6 @@ static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); if (par->gpio.cs != -1) @@ -86,8 +80,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); switch (par->info->var.rotate) { /* R20h = Horizontal GRAM Start Address */ /* R21h = Vertical GRAM Start Address */ @@ -113,8 +105,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) static int set_var(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - switch (par->info->var.rotate) { /* AM: GRAM update direction */ case 0: @@ -139,7 +129,7 @@ static int set_var(struct fbtft_par *par) PKP0 PKP1 PKP2 PKP3 PKP4 PKP5 PKP6 PKP7 PKP8 PKP9 PKP10 PKP11 VRP0 VRP1 PKN0 PKN1 PKN2 PKN3 PKN4 PKN5 PKN6 PKN7 PRN8 PRN9 PRN10 PRN11 VRN0 VRN1 */ -#define CURVE(num, idx) curves[num*par->gamma.num_values + idx] +#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] static int set_gamma(struct fbtft_par *par, unsigned long *curves) { unsigned long mask[] = { @@ -149,12 +139,10 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) }; int i, j; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - /* apply mask */ for (i = 0; i < 2; i++) for (j = 0; j < 14; j++) - CURVE(i, j) &= mask[i*par->gamma.num_values + j]; + CURVE(i, j) &= mask[i * par->gamma.num_values + j]; write_reg(par, 0x0030, CURVE(0, 1) << 8 | CURVE(0, 0)); write_reg(par, 0x0031, CURVE(0, 3) << 8 | CURVE(0, 2)); @@ -177,7 +165,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) } #undef CURVE - static struct fbtft_display display = { .regwidth = 16, .width = WIDTH, @@ -194,6 +181,7 @@ static struct fbtft_display display = { .set_gamma = set_gamma, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "samsung,s6d1121", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_ssd1289.c b/drivers/staging/fbtft/fb_ssd1289.c index 17a77e061498..1162c08613fa 100644 --- a/drivers/staging/fbtft/fb_ssd1289.c +++ b/drivers/staging/fbtft/fb_ssd1289.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 @@ -37,11 +33,8 @@ static unsigned reg11 = 0x6040; module_param(reg11, uint, 0); MODULE_PARM_DESC(reg11, "Register 11h value"); - static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); if (par->gpio.cs != -1) @@ -84,9 +77,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - switch (par->info->var.rotate) { /* R4Eh - Set GDDRAM X address counter */ /* R4Fh - Set GDDRAM Y address counter */ @@ -114,8 +104,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) static int set_var(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - if (par->fbtftops.init_display != init_display) { /* don't risk messing up register 11h */ fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, @@ -147,7 +135,7 @@ static int set_var(struct fbtft_par *par) VRP0 VRP1 PRP0 PRP1 PKP0 PKP1 PKP2 PKP3 PKP4 PKP5 VRN0 VRN1 PRN0 PRN1 PKN0 PKN1 PKN2 PKN3 PKN4 PKN5 */ -#define CURVE(num, idx) curves[num*par->gamma.num_values + idx] +#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] static int set_gamma(struct fbtft_par *par, unsigned long *curves) { unsigned long mask[] = { @@ -156,12 +144,10 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) }; int i, j; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - /* apply mask */ for (i = 0; i < 2; i++) for (j = 0; j < 10; j++) - CURVE(i, j) &= mask[i*par->gamma.num_values + j]; + CURVE(i, j) &= mask[i * par->gamma.num_values + j]; write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4)); write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6)); @@ -178,7 +164,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) } #undef CURVE - static struct fbtft_display display = { .regwidth = 16, .width = WIDTH, @@ -193,6 +178,7 @@ static struct fbtft_display display = { .set_gamma = set_gamma, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1289", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_ssd1306.c b/drivers/staging/fbtft/fb_ssd1306.c index 15ee44dd130b..e0b34a42c9c6 100644 --- a/drivers/staging/fbtft/fb_ssd1306.c +++ b/drivers/staging/fbtft/fb_ssd1306.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. */ #include @@ -30,7 +26,6 @@ #define WIDTH 128 #define HEIGHT 64 - /* write_reg() caveat: @@ -45,8 +40,6 @@ /* Init sequence taken from the Adafruit SSD1306 Arduino library */ static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); if (par->gamma.curves[0] == 0) { @@ -132,9 +125,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - /* Set Lower Column Start Address for Page Addressing Mode */ write_reg(par, 0x00 | 0x0); /* Set Higher Column Start Address for Page Addressing Mode */ @@ -158,8 +148,6 @@ static int blank(struct fbtft_par *par, bool on) /* Gamma is used to control Contrast */ static int set_gamma(struct fbtft_par *par, unsigned long *curves) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - /* apply mask */ curves[0] &= 0xFF; @@ -172,18 +160,18 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) static int write_vmem(struct fbtft_par *par, size_t offset, size_t len) { - u16 *vmem16 = (u16 *)par->info->screen_base; + u16 *vmem16 = (u16 *)par->info->screen_buffer; u8 *buf = par->txbuf.buf; int x, y, i; int ret = 0; - fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__); - for (x = 0; x < par->info->var.xres; x++) { for (y = 0; y < par->info->var.yres/8; y++) { *buf = 0x00; for (i = 0; i < 8; i++) - *buf |= (vmem16[(y*8+i)*par->info->var.xres+x] ? 1 : 0) << i; + *buf |= (vmem16[(y * 8 + i) * + par->info->var.xres + x] ? + 1 : 0) << i; buf++; } } @@ -191,7 +179,8 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len) /* Write data */ gpio_set_value(par->gpio.dc, 1); ret = par->fbtftops.write(par, par->txbuf.buf, - par->info->var.xres*par->info->var.yres/8); + par->info->var.xres * par->info->var.yres / + 8); if (ret < 0) dev_err(par->info->device, "write failed and returned: %d\n", ret); @@ -199,7 +188,6 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len) return ret; } - static struct fbtft_display display = { .regwidth = 8, .width = WIDTH, @@ -216,7 +204,6 @@ static struct fbtft_display display = { }, }; - FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1306", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_ssd1331.c b/drivers/staging/fbtft/fb_ssd1331.c index 5bb741046c85..bd294f886c5f 100644 --- a/drivers/staging/fbtft/fb_ssd1331.c +++ b/drivers/staging/fbtft/fb_ssd1331.c @@ -23,8 +23,6 @@ static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - par->fbtftops.reset(par); write_reg(par, 0xae); /* Display Off */ @@ -54,9 +52,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - write_reg(par, 0x15, xs, xe); write_reg(par, 0x75, ys, ye); } @@ -65,7 +60,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...) { va_list args; int i, ret; - u8 *buf = (u8 *)par->buf; + u8 *buf = par->buf; if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) { va_start(args, len); @@ -126,15 +121,12 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...) : Setting of GS63 has to be > Setting of GS62 +1 - */ static int set_gamma(struct fbtft_par *par, unsigned long *curves) { unsigned long tmp[GAMMA_NUM * GAMMA_LEN]; int i, acc = 0; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - for (i = 0; i < 63; i++) { if (i > 0 && curves[i] < 2) { dev_err(par->info->device, @@ -176,7 +168,6 @@ static int blank(struct fbtft_par *par, bool on) return 0; } - static struct fbtft_display display = { .regwidth = 8, .width = WIDTH, diff --git a/drivers/staging/fbtft/fb_ssd1351.c b/drivers/staging/fbtft/fb_ssd1351.c index 9bcd7a0aeed4..cef33e439f46 100644 --- a/drivers/staging/fbtft/fb_ssd1351.c +++ b/drivers/staging/fbtft/fb_ssd1351.c @@ -25,8 +25,6 @@ static void register_onboard_backlight(struct fbtft_par *par); static int init_display(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - if (par->pdata && par->pdata->display.backlight == FBTFT_ONBOARD_BACKLIGHT) { /* module uses onboard GPIO for panel power */ @@ -61,9 +59,6 @@ static int init_display(struct fbtft_par *par) static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - write_reg(par, 0x15, xs, xe); write_reg(par, 0x75, ys, ye); write_reg(par, 0x5c); @@ -73,8 +68,6 @@ static int set_var(struct fbtft_par *par) { unsigned remap; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - if (par->fbtftops.init_display != init_display) { /* don't risk messing up register A0h */ fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, @@ -104,34 +97,31 @@ static int set_var(struct fbtft_par *par) } /* - Grayscale Lookup Table - GS1 - GS63 - The driver Gamma curve contains the relative values between the entries - in the Lookup table. - - From datasheet: - 8.8 Gray Scale Decoder - - there are total 180 Gamma Settings (Setting 0 to Setting 180) - available for the Gray Scale table. - - The gray scale is defined in incremental way, with reference - to the length of previous table entry: - Setting of GS1 has to be >= 0 - Setting of GS2 has to be > Setting of GS1 +1 - Setting of GS3 has to be > Setting of GS2 +1 - : - Setting of GS63 has to be > Setting of GS62 +1 - - -*/ + * Grayscale Lookup Table + * GS1 - GS63 + * The driver Gamma curve contains the relative values between the entries + * in the Lookup table. + * + * From datasheet: + * 8.8 Gray Scale Decoder + * + * there are total 180 Gamma Settings (Setting 0 to Setting 180) + * available for the Gray Scale table. + * + * The gray scale is defined in incremental way, with reference + * to the length of previous table entry: + * Setting of GS1 has to be >= 0 + * Setting of GS2 has to be > Setting of GS1 +1 + * Setting of GS3 has to be > Setting of GS2 +1 + * : + * Setting of GS63 has to be > Setting of GS62 +1 + * + */ static int set_gamma(struct fbtft_par *par, unsigned long *curves) { unsigned long tmp[GAMMA_NUM * GAMMA_LEN]; int i, acc = 0; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - for (i = 0; i < 63; i++) { if (i > 0 && curves[i] < 2) { dev_err(par->info->device, @@ -173,7 +163,6 @@ static int blank(struct fbtft_par *par, bool on) return 0; } - static struct fbtft_display display = { .regwidth = 8, .width = WIDTH, @@ -208,25 +197,20 @@ static int update_onboard_backlight(struct backlight_device *bd) return 0; } +static const struct backlight_ops bl_ops = { + .update_status = update_onboard_backlight, +}; + static void register_onboard_backlight(struct fbtft_par *par) { struct backlight_device *bd; struct backlight_properties bl_props = { 0, }; - struct backlight_ops *bl_ops; - fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__); - - bl_ops = devm_kzalloc(par->info->device, sizeof(struct backlight_ops), - GFP_KERNEL); - if (!bl_ops) - return; - - bl_ops->update_status = update_onboard_backlight; bl_props.type = BACKLIGHT_RAW; bl_props.power = FB_BLANK_POWERDOWN; bd = backlight_device_register(dev_driver_string(par->info->device), - par->info->device, par, bl_ops, &bl_props); + par->info->device, par, &bl_ops, &bl_props); if (IS_ERR(bd)) { dev_err(par->info->device, "cannot register backlight device (%ld)\n", @@ -242,7 +226,6 @@ static void register_onboard_backlight(struct fbtft_par *par) static void register_onboard_backlight(struct fbtft_par *par) { }; #endif - FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1351", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_st7735r.c b/drivers/staging/fbtft/fb_st7735r.c index f65224318610..a92b0d071097 100644 --- a/drivers/staging/fbtft/fb_st7735r.c +++ b/drivers/staging/fbtft/fb_st7735r.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. */ #include @@ -28,7 +24,6 @@ #define DEFAULT_GAMMA "0F 1A 0F 18 2F 28 20 22 1F 1B 23 37 00 07 02 10\n" \ "0F 1B 0F 17 33 2C 29 2E 30 30 39 3F 00 07 03 10" - static int default_init_sequence[] = { /* SWRESET - Software reset */ -1, 0x01, @@ -96,9 +91,6 @@ static int default_init_sequence[] = { static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) { - fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, - "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye); - /* Column address */ write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF); @@ -109,13 +101,11 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) write_reg(par, 0x2C); } -#define MY (1 << 7) -#define MX (1 << 6) -#define MV (1 << 5) +#define MY BIT(7) +#define MX BIT(6) +#define MV BIT(5) static int set_var(struct fbtft_par *par) { - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - /* MADCTL - Memory data access control RGB/BGR: 1. Mode selection pin SRGB @@ -145,13 +135,11 @@ static int set_var(struct fbtft_par *par) VRF0P VOS0P PK0P PK1P PK2P PK3P PK4P PK5P PK6P PK7P PK8P PK9P SELV0P SELV1P SELV62P SELV63P VRF0N VOS0N PK0N PK1N PK2N PK3N PK4N PK5N PK6N PK7N PK8N PK9N SELV0N SELV1N SELV62N SELV63N */ -#define CURVE(num, idx) curves[num*par->gamma.num_values + idx] +#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] static int set_gamma(struct fbtft_par *par, unsigned long *curves) { int i, j; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); - /* apply mask */ for (i = 0; i < par->gamma.num_curves; i++) for (j = 0; j < par->gamma.num_values; j++) @@ -168,7 +156,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves) } #undef CURVE - static struct fbtft_display display = { .regwidth = 8, .width = 128, @@ -183,6 +170,7 @@ static struct fbtft_display display = { .set_gamma = set_gamma, }, }; + FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7735r", &display); MODULE_ALIAS("spi:" DRVNAME); diff --git a/drivers/staging/fbtft/fb_st7789v.c b/drivers/staging/fbtft/fb_st7789v.c new file mode 100644 index 000000000000..085e9872c46d --- /dev/null +++ b/drivers/staging/fbtft/fb_st7789v.c @@ -0,0 +1,265 @@ +/* + * FB driver for the ST7789V LCD Controller + * + * Copyright (C) 2015 Dennis Menschel + * + * 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 +#include +#include +#include