diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-11 13:59:44 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-11 13:59:44 -0800 |
commit | 8966961b31c251b854169e9886394c2a20f2cea7 (patch) | |
tree | 248a625b23335acbd5ca4b55eb136fe0dc8ba0aa /drivers/staging/iio | |
parent | 6a5971d8fea1f4a8c33dfe0cec6a1c490f0c9cde (diff) | |
parent | 7bcb57cde66c19df378f3468ea342166a8a4504d (diff) | |
download | linux-3.10-8966961b31c251b854169e9886394c2a20f2cea7.tar.gz linux-3.10-8966961b31c251b854169e9886394c2a20f2cea7.tar.bz2 linux-3.10-8966961b31c251b854169e9886394c2a20f2cea7.zip |
Merge tag 'staging-3.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging driver tree merge from Greg Kroah-Hartman:
"Here's the big staging tree merge for 3.8-rc1
There's a lot of patches in here, the majority being the comedi
rework/cleanup that has been ongoing and is causing a huge reduction
in overall code size, which is amazing to watch. We also removed some
older drivers (telephony and rts_pstor), and added a new one (fwserial
which also came in through the tty tree due to tty api changes, take
that one if you get merge conflicts.)
The iio and ipack drivers are moving out of the staging area into
their own part of the kernel as they have been cleaned up sufficiently
and are working well.
Overall, again a reduction of code:
768 files changed, 31887 insertions(+), 82166 deletions(-)
All of this has been in the linux-next tree for a while.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>"
* tag 'staging-3.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (1298 commits)
iio: imu: adis16480: remove duplicated include from adis16480.c
iio: gyro: adis16136: remove duplicated include from adis16136.c
iio:imu: adis16480: show_firmware() buffer too small
iio:gyro: adis16136: divide by zero in write_frequency()
iio: adc: Add Texas Instruments ADC081C021/027 support
iio:ad7793: Add support for the ad7796 and ad7797
iio:ad7793: Add support for the ad7798 and ad7799
staging:iio: Move ad7793 driver out of staging
staging:iio:ad7793: Implement stricter id checking
staging:iio:ad7793: Move register definitions from header to source
staging:iio:ad7793: Rework regulator handling
staging:iio:ad7793: Rework platform data
staging:iio:ad7793: Use kstrtol instead of strict_strtol
staging:iio:ad7793: Use usleep_range instead of msleep
staging:iio:ad7793: Fix temperature scale
staging:iio:ad7793: Fix VDD monitor scale
staging: gdm72xx: unlock on error in init_usb()
staging: panel: pass correct lengths to keypad_send_key()
staging: comedi: addi_apci_2032: fix interrupt support
staging: comedi: addi_apci_2032: move i_APCI2032_ConfigDigitalOutput()
...
Diffstat (limited to 'drivers/staging/iio')
112 files changed, 1263 insertions, 9122 deletions
diff --git a/drivers/staging/iio/accel/Kconfig b/drivers/staging/iio/accel/Kconfig index 5ab71670b70..2b54430f2d9 100644 --- a/drivers/staging/iio/accel/Kconfig +++ b/drivers/staging/iio/accel/Kconfig @@ -6,8 +6,8 @@ menu "Accelerometers" config ADIS16201 tristate "Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer" depends on SPI - select IIO_TRIGGER if IIO_BUFFER - select IIO_SW_RING if IIO_BUFFER + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help Say yes here to build support for Analog Devices adis16201 dual-axis digital inclinometer and accelerometer. @@ -15,8 +15,8 @@ config ADIS16201 config ADIS16203 tristate "Analog Devices ADIS16203 Programmable 360 Degrees Inclinometer" depends on SPI - select IIO_TRIGGER if IIO_BUFFER - select IIO_SW_RING if IIO_BUFFER + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help Say yes here to build support for Analog Devices adis16203 Programmable 360 Degrees Inclinometer. @@ -24,8 +24,8 @@ config ADIS16203 config ADIS16204 tristate "Analog Devices ADIS16204 Programmable High-g Digital Impact Sensor and Recorder" depends on SPI - select IIO_TRIGGER if IIO_BUFFER - select IIO_SW_RING if IIO_BUFFER + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help Say yes here to build support for Analog Devices adis16204 Programmable High-g Digital Impact Sensor and Recorder. @@ -33,8 +33,8 @@ config ADIS16204 config ADIS16209 tristate "Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer" depends on SPI - select IIO_TRIGGER if IIO_BUFFER - select IIO_SW_RING if IIO_BUFFER + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help Say yes here to build support for Analog Devices adis16209 dual-axis digital inclinometer and accelerometer. @@ -42,6 +42,7 @@ config ADIS16209 config ADIS16220 tristate "Analog Devices ADIS16220 Programmable Digital Vibration Sensor" depends on SPI + select IIO_ADIS_LIB help Say yes here to build support for Analog Devices adis16220 programmable digital vibration sensor. @@ -49,8 +50,8 @@ config ADIS16220 config ADIS16240 tristate "Analog Devices ADIS16240 Programmable Impact Sensor and Recorder" depends on SPI - select IIO_TRIGGER if IIO_BUFFER - select IIO_SW_RING if IIO_BUFFER + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help Say yes here to build support for Analog Devices adis16240 programmable impact Sensor and recorder. diff --git a/drivers/staging/iio/accel/Makefile b/drivers/staging/iio/accel/Makefile index 95c66661e70..8e7ee036851 100644 --- a/drivers/staging/iio/accel/Makefile +++ b/drivers/staging/iio/accel/Makefile @@ -3,26 +3,21 @@ # adis16201-y := adis16201_core.o -adis16201-$(CONFIG_IIO_BUFFER) += adis16201_ring.o adis16201_trigger.o obj-$(CONFIG_ADIS16201) += adis16201.o adis16203-y := adis16203_core.o -adis16203-$(CONFIG_IIO_BUFFER) += adis16203_ring.o adis16203_trigger.o obj-$(CONFIG_ADIS16203) += adis16203.o adis16204-y := adis16204_core.o -adis16204-$(CONFIG_IIO_BUFFER) += adis16204_ring.o adis16204_trigger.o obj-$(CONFIG_ADIS16204) += adis16204.o adis16209-y := adis16209_core.o -adis16209-$(CONFIG_IIO_BUFFER) += adis16209_ring.o adis16209_trigger.o obj-$(CONFIG_ADIS16209) += adis16209.o adis16220-y := adis16220_core.o obj-$(CONFIG_ADIS16220) += adis16220.o adis16240-y := adis16240_core.o -adis16240-$(CONFIG_IIO_BUFFER) += adis16240_ring.o adis16240_trigger.o obj-$(CONFIG_ADIS16240) += adis16240.o obj-$(CONFIG_KXSD9) += kxsd9.o diff --git a/drivers/staging/iio/accel/adis16201.h b/drivers/staging/iio/accel/adis16201.h index 72750f7f3a8..8747de5a980 100644 --- a/drivers/staging/iio/accel/adis16201.h +++ b/drivers/staging/iio/accel/adis16201.h @@ -3,9 +3,6 @@ #define ADIS16201_STARTUP_DELAY 220 /* ms */ -#define ADIS16201_READ_REG(a) a -#define ADIS16201_WRITE_REG(a) ((a) | 0x80) - #define ADIS16201_FLASH_CNT 0x00 /* Flash memory write count */ #define ADIS16201_SUPPLY_OUT 0x02 /* Output, power supply */ #define ADIS16201_XACCL_OUT 0x04 /* Output, x-axis accelerometer */ @@ -36,8 +33,6 @@ #define ADIS16201_DIAG_STAT 0x3C /* Diagnostics, system status register */ #define ADIS16201_GLOB_CMD 0x3E /* Operation, system command register */ -#define ADIS16201_OUTPUTS 7 - /* MSC_CTRL */ #define ADIS16201_MSC_CTRL_SELF_TEST_EN (1 << 8) /* Self-test enable */ #define ADIS16201_MSC_CTRL_DATA_RDY_EN (1 << 2) /* Data-ready enable: 1 = enabled, 0 = disabled */ @@ -47,95 +42,25 @@ /* DIAG_STAT */ #define ADIS16201_DIAG_STAT_ALARM2 (1<<9) /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ #define ADIS16201_DIAG_STAT_ALARM1 (1<<8) /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ -#define ADIS16201_DIAG_STAT_SPI_FAIL (1<<3) /* SPI communications failure */ -#define ADIS16201_DIAG_STAT_FLASH_UPT (1<<2) /* Flash update failure */ -#define ADIS16201_DIAG_STAT_POWER_HIGH (1<<1) /* Power supply above 3.625 V */ -#define ADIS16201_DIAG_STAT_POWER_LOW (1<<0) /* Power supply below 3.15 V */ +#define ADIS16201_DIAG_STAT_SPI_FAIL_BIT 3 /* SPI communications failure */ +#define ADIS16201_DIAG_STAT_FLASH_UPT_BIT 2 /* Flash update failure */ +#define ADIS16201_DIAG_STAT_POWER_HIGH_BIT 1 /* Power supply above 3.625 V */ +#define ADIS16201_DIAG_STAT_POWER_LOW_BIT 0 /* Power supply below 3.15 V */ /* GLOB_CMD */ #define ADIS16201_GLOB_CMD_SW_RESET (1<<7) #define ADIS16201_GLOB_CMD_FACTORY_CAL (1<<1) -#define ADIS16201_MAX_TX 14 -#define ADIS16201_MAX_RX 14 - #define ADIS16201_ERROR_ACTIVE (1<<14) -/** - * struct adis16201_state - device instance specific data - * @us: actual spi_device - * @trig: data ready trigger registered with iio - * @tx: transmit buffer - * @rx: receive buffer - * @buf_lock: mutex to protect tx and rx - **/ -struct adis16201_state { - struct spi_device *us; - struct iio_trigger *trig; - struct mutex buf_lock; - u8 tx[14] ____cacheline_aligned; - u8 rx[14]; -}; - -int adis16201_set_irq(struct iio_dev *indio_dev, bool enable); - enum adis16201_scan { - ADIS16201_SCAN_SUPPLY, ADIS16201_SCAN_ACC_X, ADIS16201_SCAN_ACC_Y, - ADIS16201_SCAN_AUX_ADC, - ADIS16201_SCAN_TEMP, ADIS16201_SCAN_INCLI_X, ADIS16201_SCAN_INCLI_Y, + ADIS16201_SCAN_SUPPLY, + ADIS16201_SCAN_AUX_ADC, + ADIS16201_SCAN_TEMP, }; -#ifdef CONFIG_IIO_BUFFER -void adis16201_remove_trigger(struct iio_dev *indio_dev); -int adis16201_probe_trigger(struct iio_dev *indio_dev); - -ssize_t adis16201_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf); - -int adis16201_configure_ring(struct iio_dev *indio_dev); -void adis16201_unconfigure_ring(struct iio_dev *indio_dev); - -#else /* CONFIG_IIO_BUFFER */ - -static inline void adis16201_remove_trigger(struct iio_dev *indio_dev) -{ -} - -static inline int adis16201_probe_trigger(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline ssize_t -adis16201_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return 0; -} - -static int adis16201_configure_ring(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline void adis16201_unconfigure_ring(struct iio_dev *indio_dev) -{ -} - -static inline int adis16201_initialize_ring(struct iio_ring_buffer *ring) -{ - return 0; -} - -static inline void adis16201_uninitialize_ring(struct iio_ring_buffer *ring) -{ -} - -#endif /* CONFIG_IIO_BUFFER */ #endif /* SPI_ADIS16201_H_ */ diff --git a/drivers/staging/iio/accel/adis16201_core.c b/drivers/staging/iio/accel/adis16201_core.c index b12ca68cd9e..9e5791ff2a0 100644 --- a/drivers/staging/iio/accel/adis16201_core.c +++ b/drivers/staging/iio/accel/adis16201_core.c @@ -18,258 +18,15 @@ #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16201.h" -enum adis16201_chan { - in_supply, - temp, - accel_x, - accel_y, - incli_x, - incli_y, - in_aux, -}; - -/** - * adis16201_spi_write_reg_8() - write single byte to a register - * @dev: device associated with child of actual device (iio_dev or iio_trig) - * @reg_address: the address of the register to be written - * @val: the value to write - **/ -static int adis16201_spi_write_reg_8(struct iio_dev *indio_dev, - u8 reg_address, - u8 val) -{ - int ret; - struct adis16201_state *st = iio_priv(indio_dev); - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16201_WRITE_REG(reg_address); - st->tx[1] = val; - - ret = spi_write(st->us, st->tx, 2); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16201_spi_write_reg_16() - write 2 bytes to a pair of registers - * @indio_dev: iio device associated with child of actual device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: value to be written - **/ -static int adis16201_spi_write_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 value) -{ - int ret; - struct spi_message msg; - struct adis16201_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - }, { - .tx_buf = st->tx + 2, - .bits_per_word = 8, - .len = 2, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16201_WRITE_REG(lower_reg_address); - st->tx[1] = value & 0xFF; - st->tx[2] = ADIS16201_WRITE_REG(lower_reg_address + 1); - st->tx[3] = (value >> 8) & 0xFF; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16201_spi_read_reg_16() - read 2 bytes from a 16-bit register - * @indio_dev: iio device associated with child of actual device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: somewhere to pass back the value read - **/ -static int adis16201_spi_read_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 *val) -{ - struct spi_message msg; - struct adis16201_state *st = iio_priv(indio_dev); - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 20, - }, { - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 2, - .delay_usecs = 20, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16201_READ_REG(lower_reg_address); - st->tx[1] = 0; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X", - lower_reg_address); - goto error_ret; - } - *val = (st->rx[0] << 8) | st->rx[1]; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -static int adis16201_reset(struct iio_dev *indio_dev) -{ - int ret; - struct adis16201_state *st = iio_priv(indio_dev); - - ret = adis16201_spi_write_reg_8(indio_dev, - ADIS16201_GLOB_CMD, - ADIS16201_GLOB_CMD_SW_RESET); - if (ret) - dev_err(&st->us->dev, "problem resetting device"); - - return ret; -} - -int adis16201_set_irq(struct iio_dev *indio_dev, bool enable) -{ - int ret = 0; - u16 msc; - - ret = adis16201_spi_read_reg_16(indio_dev, ADIS16201_MSC_CTRL, &msc); - if (ret) - goto error_ret; - - msc |= ADIS16201_MSC_CTRL_ACTIVE_HIGH; - msc &= ~ADIS16201_MSC_CTRL_DATA_RDY_DIO1; - if (enable) - msc |= ADIS16201_MSC_CTRL_DATA_RDY_EN; - else - msc &= ~ADIS16201_MSC_CTRL_DATA_RDY_EN; - - ret = adis16201_spi_write_reg_16(indio_dev, ADIS16201_MSC_CTRL, msc); - -error_ret: - return ret; -} - -static int adis16201_check_status(struct iio_dev *indio_dev) -{ - u16 status; - int ret; - - ret = adis16201_spi_read_reg_16(indio_dev, - ADIS16201_DIAG_STAT, &status); - if (ret < 0) { - dev_err(&indio_dev->dev, "Reading status failed\n"); - goto error_ret; - } - ret = status & 0xF; - if (ret) - ret = -EFAULT; - - if (status & ADIS16201_DIAG_STAT_SPI_FAIL) - dev_err(&indio_dev->dev, "SPI failure\n"); - if (status & ADIS16201_DIAG_STAT_FLASH_UPT) - dev_err(&indio_dev->dev, "Flash update failed\n"); - if (status & ADIS16201_DIAG_STAT_POWER_HIGH) - dev_err(&indio_dev->dev, "Power supply above 3.625V\n"); - if (status & ADIS16201_DIAG_STAT_POWER_LOW) - dev_err(&indio_dev->dev, "Power supply below 3.15V\n"); - -error_ret: - return ret; -} - -static int adis16201_self_test(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16201_spi_write_reg_16(indio_dev, - ADIS16201_MSC_CTRL, - ADIS16201_MSC_CTRL_SELF_TEST_EN); - if (ret) { - dev_err(&indio_dev->dev, "problem starting self test"); - goto err_ret; - } - - ret = adis16201_check_status(indio_dev); - -err_ret: - return ret; -} - -static int adis16201_initial_setup(struct iio_dev *indio_dev) -{ - int ret; - struct device *dev = &indio_dev->dev; - - /* Disable IRQ */ - ret = adis16201_set_irq(indio_dev, false); - if (ret) { - dev_err(dev, "disable irq failed"); - goto err_ret; - } - - /* Do self test */ - ret = adis16201_self_test(indio_dev); - if (ret) { - dev_err(dev, "self test failure"); - goto err_ret; - } - - /* Read status register to check the result */ - ret = adis16201_check_status(indio_dev); - if (ret) { - adis16201_reset(indio_dev); - dev_err(dev, "device not playing ball -> reset"); - msleep(ADIS16201_STARTUP_DELAY); - ret = adis16201_check_status(indio_dev); - if (ret) { - dev_err(dev, "giving up"); - goto err_ret; - } - } - -err_ret: - return ret; -} - -static u8 adis16201_addresses[7][2] = { - [in_supply] = { ADIS16201_SUPPLY_OUT, }, - [temp] = { ADIS16201_TEMP_OUT }, - [accel_x] = { ADIS16201_XACCL_OUT, ADIS16201_XACCL_OFFS }, - [accel_y] = { ADIS16201_YACCL_OUT, ADIS16201_YACCL_OFFS }, - [in_aux] = { ADIS16201_AUX_ADC }, - [incli_x] = { ADIS16201_XINCL_OUT }, - [incli_y] = { ADIS16201_YINCL_OUT }, +static const u8 adis16201_addresses[] = { + [ADIS16201_SCAN_ACC_X] = ADIS16201_XACCL_OFFS, + [ADIS16201_SCAN_ACC_Y] = ADIS16201_YACCL_OFFS, + [ADIS16201_SCAN_INCLI_X] = ADIS16201_XINCL_OFFS, + [ADIS16201_SCAN_INCLI_Y] = ADIS16201_YINCL_OFFS, }; static int adis16201_read_raw(struct iio_dev *indio_dev, @@ -277,6 +34,7 @@ static int adis16201_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { + struct adis *st = iio_priv(indio_dev); int ret; int bits; u8 addr; @@ -284,29 +42,8 @@ static int adis16201_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); - addr = adis16201_addresses[chan->address][0]; - ret = adis16201_spi_read_reg_16(indio_dev, addr, &val16); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - - if (val16 & ADIS16201_ERROR_ACTIVE) { - ret = adis16201_check_status(indio_dev); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - } - val16 = val16 & ((1 << chan->scan_type.realbits) - 1); - if (chan->scan_type.sign == 's') - val16 = (s16)(val16 << - (16 - chan->scan_type.realbits)) >> - (16 - chan->scan_type.realbits); - *val = val16; - mutex_unlock(&indio_dev->mlock); - return IIO_VAL_INT; + return adis_single_conversion(indio_dev, chan, + ADIS16201_ERROR_ACTIVE, val); case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: @@ -347,10 +84,10 @@ static int adis16201_read_raw(struct iio_dev *indio_dev, break; default: return -EINVAL; - }; + } mutex_lock(&indio_dev->mlock); - addr = adis16201_addresses[chan->address][1]; - ret = adis16201_spi_read_reg_16(indio_dev, addr, &val16); + addr = adis16201_addresses[chan->scan_index]; + ret = adis_read_reg_16(st, addr, &val16); if (ret) { mutex_unlock(&indio_dev->mlock); return ret; @@ -370,6 +107,7 @@ static int adis16201_write_raw(struct iio_dev *indio_dev, int val2, long mask) { + struct adis *st = iio_priv(indio_dev); int bits; s16 val16; u8 addr; @@ -384,126 +122,63 @@ static int adis16201_write_raw(struct iio_dev *indio_dev, break; default: return -EINVAL; - }; + } val16 = val & ((1 << bits) - 1); - addr = adis16201_addresses[chan->address][1]; - return adis16201_spi_write_reg_16(indio_dev, addr, val16); + addr = adis16201_addresses[chan->scan_index]; + return adis_write_reg_16(st, addr, val16); } return -EINVAL; } static const struct iio_chan_spec adis16201_channels[] = { - { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .extend_name = "supply", - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_supply, - .scan_index = ADIS16201_SCAN_SUPPLY, - .scan_type = { - .sign = 'u', - .realbits = 12, - .storagebits = 16, - }, - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, - .address = temp, - .scan_index = ADIS16201_SCAN_TEMP, - .scan_type = { - .sign = 'u', - .realbits = 12, - .storagebits = 16, - }, - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, - .address = accel_x, - .scan_index = ADIS16201_SCAN_ACC_X, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, - .address = accel_y, - .scan_index = ADIS16201_SCAN_ACC_Y, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_aux, - .scan_index = ADIS16201_SCAN_AUX_ADC, - .scan_type = { - .sign = 'u', - .realbits = 12, - .storagebits = 16, - }, - }, { - .type = IIO_INCLI, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, - .address = incli_x, - .scan_index = ADIS16201_SCAN_INCLI_X, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, { - .type = IIO_INCLI, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, - .address = incli_y, - .scan_index = ADIS16201_SCAN_INCLI_Y, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, + ADIS_SUPPLY_CHAN(ADIS16201_SUPPLY_OUT, ADIS16201_SCAN_SUPPLY, 12), + ADIS_TEMP_CHAN(ADIS16201_TEMP_OUT, ADIS16201_SCAN_TEMP, 12), + ADIS_ACCEL_CHAN(X, ADIS16201_XACCL_OUT, ADIS16201_SCAN_ACC_X, + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14), + ADIS_ACCEL_CHAN(Y, ADIS16201_YACCL_OUT, ADIS16201_SCAN_ACC_Y, + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14), + ADIS_AUX_ADC_CHAN(ADIS16201_AUX_ADC, ADIS16201_SCAN_AUX_ADC, 12), + ADIS_INCLI_CHAN(X, ADIS16201_XINCL_OUT, ADIS16201_SCAN_INCLI_X, + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14), + ADIS_INCLI_CHAN(X, ADIS16201_YINCL_OUT, ADIS16201_SCAN_INCLI_Y, + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14), IIO_CHAN_SOFT_TIMESTAMP(7) }; static const struct iio_info adis16201_info = { .read_raw = &adis16201_read_raw, .write_raw = &adis16201_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module = THIS_MODULE, }; -static int __devinit adis16201_probe(struct spi_device *spi) +static const char * const adis16201_status_error_msgs[] = { + [ADIS16201_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure", + [ADIS16201_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed", + [ADIS16201_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", + [ADIS16201_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 3.15V", +}; + +static const struct adis_data adis16201_data = { + .read_delay = 20, + .msc_ctrl_reg = ADIS16201_MSC_CTRL, + .glob_cmd_reg = ADIS16201_GLOB_CMD, + .diag_stat_reg = ADIS16201_DIAG_STAT, + + .self_test_mask = ADIS16201_MSC_CTRL_SELF_TEST_EN, + .startup_delay = ADIS16201_STARTUP_DELAY, + + .status_error_msgs = adis16201_status_error_msgs, + .status_error_mask = BIT(ADIS16201_DIAG_STAT_SPI_FAIL_BIT) | + BIT(ADIS16201_DIAG_STAT_FLASH_UPT_BIT) | + BIT(ADIS16201_DIAG_STAT_POWER_HIGH_BIT) | + BIT(ADIS16201_DIAG_STAT_POWER_LOW_BIT), +}; + +static int adis16201_probe(struct spi_device *spi) { int ret; - struct adis16201_state *st; + struct adis *st; struct iio_dev *indio_dev; /* setup the industrialio driver allocated elements */ @@ -516,9 +191,6 @@ static int __devinit adis16201_probe(struct spi_device *spi) /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); - st->us = spi; - mutex_init(&st->buf_lock); - indio_dev->name = spi->dev.driver->name; indio_dev->dev.parent = &spi->dev; indio_dev->info = &adis16201_info; @@ -527,54 +199,38 @@ static int __devinit adis16201_probe(struct spi_device *spi) indio_dev->num_channels = ARRAY_SIZE(adis16201_channels); indio_dev->modes = INDIO_DIRECT_MODE; - ret = adis16201_configure_ring(indio_dev); + ret = adis_init(st, indio_dev, spi, &adis16201_data); + if (ret) + goto error_free_dev; + ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); if (ret) goto error_free_dev; - - ret = iio_buffer_register(indio_dev, - adis16201_channels, - ARRAY_SIZE(adis16201_channels)); - if (ret) { - printk(KERN_ERR "failed to initialize the ring\n"); - goto error_unreg_ring_funcs; - } - - if (spi->irq) { - ret = adis16201_probe_trigger(indio_dev); - if (ret) - goto error_uninitialize_ring; - } /* Get the device into a sane initial state */ - ret = adis16201_initial_setup(indio_dev); + ret = adis_initial_startup(st); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; ret = iio_device_register(indio_dev); if (ret < 0) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; return 0; -error_remove_trigger: - adis16201_remove_trigger(indio_dev); -error_uninitialize_ring: - iio_buffer_unregister(indio_dev); -error_unreg_ring_funcs: - adis16201_unconfigure_ring(indio_dev); +error_cleanup_buffer_trigger: + adis_cleanup_buffer_and_trigger(st, indio_dev); error_free_dev: iio_device_free(indio_dev); error_ret: return ret; } -static int __devexit adis16201_remove(struct spi_device *spi) +static int adis16201_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct adis *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); - adis16201_remove_trigger(indio_dev); - iio_buffer_unregister(indio_dev); - adis16201_unconfigure_ring(indio_dev); + adis_cleanup_buffer_and_trigger(st, indio_dev); iio_device_free(indio_dev); return 0; @@ -586,7 +242,7 @@ static struct spi_driver adis16201_driver = { .owner = THIS_MODULE, }, .probe = adis16201_probe, - .remove = __devexit_p(adis16201_remove), + .remove = adis16201_remove, }; module_spi_driver(adis16201_driver); diff --git a/drivers/staging/iio/accel/adis16201_ring.c b/drivers/staging/iio/accel/adis16201_ring.c deleted file mode 100644 index 97c09f0c26a..00000000000 --- a/drivers/staging/iio/accel/adis16201_ring.c +++ /dev/null @@ -1,136 +0,0 @@ -#include <linux/export.h> -#include <linux/interrupt.h> -#include <linux/mutex.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/slab.h> - -#include <linux/iio/iio.h> -#include "../ring_sw.h" -#include <linux/iio/trigger_consumer.h> -#include "adis16201.h" - - -/** - * adis16201_read_ring_data() read data registers which will be placed into ring - * @dev: device associated with child of actual device (iio_dev or iio_trig) - * @rx: somewhere to pass back the value read - **/ -static int adis16201_read_ring_data(struct iio_dev *indio_dev, u8 *rx) -{ - struct spi_message msg; - struct adis16201_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[ADIS16201_OUTPUTS + 1]; - int ret; - int i; - - mutex_lock(&st->buf_lock); - - spi_message_init(&msg); - - memset(xfers, 0, sizeof(xfers)); - for (i = 0; i <= ADIS16201_OUTPUTS; i++) { - xfers[i].bits_per_word = 8; - xfers[i].cs_change = 1; - xfers[i].len = 2; - xfers[i].delay_usecs = 20; - if (i < ADIS16201_OUTPUTS) { - xfers[i].tx_buf = st->tx + 2 * i; - st->tx[2 * i] = ADIS16201_READ_REG(ADIS16201_SUPPLY_OUT + - 2 * i); - st->tx[2 * i + 1] = 0; - } - if (i >= 1) - xfers[i].rx_buf = rx + 2 * (i - 1); - spi_message_add_tail(&xfers[i], &msg); - } - - ret = spi_sync(st->us, &msg); - if (ret) - dev_err(&st->us->dev, "problem when burst reading"); - - mutex_unlock(&st->buf_lock); - - return ret; -} - -/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device - * specific to be rolled into the core. - */ -static irqreturn_t adis16201_trigger_handler(int irq, void *p) -{ - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct adis16201_state *st = iio_priv(indio_dev); - - int i = 0; - s16 *data; - - data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (data == NULL) { - dev_err(&st->us->dev, "memory alloc failed in ring bh"); - goto done; - } - - if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) - && adis16201_read_ring_data(indio_dev, st->rx) >= 0) - for (; i < bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); i++) - data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); - - /* Guaranteed to be aligned with 8 byte boundary */ - if (indio_dev->scan_timestamp) - *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; - - iio_push_to_buffer(indio_dev->buffer, (u8 *)data); - - kfree(data); -done: - iio_trigger_notify_done(indio_dev->trig); - - return IRQ_HANDLED; -} - -void adis16201_unconfigure_ring(struct iio_dev *indio_dev) -{ - iio_dealloc_pollfunc(indio_dev->pollfunc); - iio_sw_rb_free(indio_dev->buffer); -} - -static const struct iio_buffer_setup_ops adis16201_ring_setup_ops = { - .preenable = &iio_sw_buffer_preenable, - .postenable = &iio_triggered_buffer_postenable, - .predisable = &iio_triggered_buffer_predisable, -}; - -int adis16201_configure_ring(struct iio_dev *indio_dev) -{ - int ret = 0; - struct iio_buffer *ring; - - ring = iio_sw_rb_allocate(indio_dev); - if (!ring) { - ret = -ENOMEM; - return ret; - } - indio_dev->buffer = ring; - ring->scan_timestamp = true; - indio_dev->setup_ops = &adis16201_ring_setup_ops; - - indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time, - &adis16201_trigger_handler, - IRQF_ONESHOT, - indio_dev, - "adis16201_consumer%d", - indio_dev->id); - if (indio_dev->pollfunc == NULL) { - ret = -ENOMEM; - goto error_iio_sw_rb_free; - } - - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; - return 0; -error_iio_sw_rb_free: - iio_sw_rb_free(indio_dev->buffer); - return ret; -} diff --git a/drivers/staging/iio/accel/adis16201_trigger.c b/drivers/staging/iio/accel/adis16201_trigger.c deleted file mode 100644 index 96fdabbac20..00000000000 --- a/drivers/staging/iio/accel/adis16201_trigger.c +++ /dev/null @@ -1,71 +0,0 @@ -#include <linux/interrupt.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/export.h> - -#include <linux/iio/iio.h> -#include <linux/iio/trigger.h> -#include "adis16201.h" - -/** - * adis16201_data_rdy_trigger_set_state() set datardy interrupt state - **/ -static int adis16201_data_rdy_trigger_set_state(struct iio_trigger *trig, - bool state) -{ - struct iio_dev *indio_dev = trig->private_data; - - dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); - return adis16201_set_irq(indio_dev, state); -} - -static const struct iio_trigger_ops adis16201_trigger_ops = { - .owner = THIS_MODULE, - .set_trigger_state = &adis16201_data_rdy_trigger_set_state, -}; - -int adis16201_probe_trigger(struct iio_dev *indio_dev) -{ - int ret; - struct adis16201_state *st = iio_priv(indio_dev); - - st->trig = iio_trigger_alloc("adis16201-dev%d", indio_dev->id); - if (st->trig == NULL) { - ret = -ENOMEM; - goto error_ret; - } - ret = request_irq(st->us->irq, - &iio_trigger_generic_data_rdy_poll, - IRQF_TRIGGER_RISING, - "adis16201", - st->trig); - if (ret) - goto error_free_trig; - st->trig->dev.parent = &st->us->dev; - st->trig->ops = &adis16201_trigger_ops; - st->trig->private_data = indio_dev; - ret = iio_trigger_register(st->trig); - - /* select default trigger */ - indio_dev->trig = st->trig; - if (ret) - goto error_free_irq; - - return 0; - -error_free_irq: - free_irq(st->us->irq, st->trig); -error_free_trig: - iio_trigger_free(st->trig); -error_ret: - return ret; -} - -void adis16201_remove_trigger(struct iio_dev *indio_dev) -{ - struct adis16201_state *state = iio_priv(indio_dev); - - iio_trigger_unregister(state->trig); - free_irq(state->us->irq, state->trig); - iio_trigger_free(state->trig); -} diff --git a/drivers/staging/iio/accel/adis16203.h b/drivers/staging/iio/accel/adis16203.h index 3f96ad3bbd6..acc688d7ea9 100644 --- a/drivers/staging/iio/accel/adis16203.h +++ b/drivers/staging/iio/accel/adis16203.h @@ -3,9 +3,6 @@ #define ADIS16203_STARTUP_DELAY 220 /* ms */ -#define ADIS16203_READ_REG(a) a -#define ADIS16203_WRITE_REG(a) ((a) | 0x80) - #define ADIS16203_FLASH_CNT 0x00 /* Flash memory write count */ #define ADIS16203_SUPPLY_OUT 0x02 /* Output, power supply */ #define ADIS16203_AUX_ADC 0x08 /* Output, auxiliary ADC input */ @@ -27,8 +24,6 @@ #define ADIS16203_DIAG_STAT 0x3C /* Diagnostics, system status register */ #define ADIS16203_GLOB_CMD 0x3E /* Operation, system command register */ -#define ADIS16203_OUTPUTS 5 - /* MSC_CTRL */ #define ADIS16203_MSC_CTRL_PWRUP_SELF_TEST (1 << 10) /* Self-test at power-on: 1 = disabled, 0 = enabled */ #define ADIS16203_MSC_CTRL_REVERSE_ROT_EN (1 << 9) /* Reverses rotation of both inclination outputs */ @@ -40,86 +35,25 @@ /* DIAG_STAT */ #define ADIS16203_DIAG_STAT_ALARM2 (1<<9) /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ #define ADIS16203_DIAG_STAT_ALARM1 (1<<8) /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ -#define ADIS16203_DIAG_STAT_SELFTEST_FAIL (1<<5) /* Self-test diagnostic error flag */ -#define ADIS16203_DIAG_STAT_SPI_FAIL (1<<3) /* SPI communications failure */ -#define ADIS16203_DIAG_STAT_FLASH_UPT (1<<2) /* Flash update failure */ -#define ADIS16203_DIAG_STAT_POWER_HIGH (1<<1) /* Power supply above 3.625 V */ -#define ADIS16203_DIAG_STAT_POWER_LOW (1<<0) /* Power supply below 3.15 V */ +#define ADIS16203_DIAG_STAT_SELFTEST_FAIL_BIT 5 /* Self-test diagnostic error flag */ +#define ADIS16203_DIAG_STAT_SPI_FAIL_BIT 3 /* SPI communications failure */ +#define ADIS16203_DIAG_STAT_FLASH_UPT_BIT 2 /* Flash update failure */ +#define ADIS16203_DIAG_STAT_POWER_HIGH_BIT 1 /* Power supply above 3.625 V */ +#define ADIS16203_DIAG_STAT_POWER_LOW_BIT 0 /* Power supply below 3.15 V */ /* GLOB_CMD */ #define ADIS16203_GLOB_CMD_SW_RESET (1<<7) #define ADIS16203_GLOB_CMD_CLEAR_STAT (1<<4) #define ADIS16203_GLOB_CMD_FACTORY_CAL (1<<1) -#define ADIS16203_MAX_TX 12 -#define ADIS16203_MAX_RX 10 - #define ADIS16203_ERROR_ACTIVE (1<<14) -/** - * struct adis16203_state - device instance specific data - * @us: actual spi_device - * @trig: data ready trigger registered with iio - * @tx: transmit buffer - * @rx: receive buffer - * @buf_lock: mutex to protect tx and rx - **/ -struct adis16203_state { - struct spi_device *us; - struct iio_trigger *trig; - struct mutex buf_lock; - u8 tx[ADIS16203_MAX_TX] ____cacheline_aligned; - u8 rx[ADIS16203_MAX_RX]; -}; - -int adis16203_set_irq(struct iio_dev *indio_dev, bool enable); - enum adis16203_scan { + ADIS16203_SCAN_INCLI_X, + ADIS16203_SCAN_INCLI_Y, ADIS16203_SCAN_SUPPLY, ADIS16203_SCAN_AUX_ADC, ADIS16203_SCAN_TEMP, - ADIS16203_SCAN_INCLI_X, - ADIS16203_SCAN_INCLI_Y, }; -#ifdef CONFIG_IIO_BUFFER -void adis16203_remove_trigger(struct iio_dev *indio_dev); -int adis16203_probe_trigger(struct iio_dev *indio_dev); - -ssize_t adis16203_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf); - -int adis16203_configure_ring(struct iio_dev *indio_dev); -void adis16203_unconfigure_ring(struct iio_dev *indio_dev); - -#else /* CONFIG_IIO_BUFFER */ - -static inline void adis16203_remove_trigger(struct iio_dev *indio_dev) -{ -} - -static inline int adis16203_probe_trigger(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline ssize_t -adis16203_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return 0; -} - -static int adis16203_configure_ring(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline void adis16203_unconfigure_ring(struct iio_dev *indio_dev) -{ -} - -#endif /* CONFIG_IIO_BUFFER */ #endif /* SPI_ADIS16203_H_ */ diff --git a/drivers/staging/iio/accel/adis16203_core.c b/drivers/staging/iio/accel/adis16203_core.c index e7b3441115a..8c235273ff1 100644 --- a/drivers/staging/iio/accel/adis16203_core.c +++ b/drivers/staging/iio/accel/adis16203_core.c @@ -1,7 +1,7 @@ /* * ADIS16203 Programmable Digital Vibration Sensor driver * - * Copyright 2010 Analog Devices Inc. + * Copyright 2030 Analog Devices Inc. * * Licensed under the GPL-2 or later. */ @@ -18,254 +18,14 @@ #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16203.h" #define DRIVER_NAME "adis16203" -/** - * adis16203_spi_write_reg_8() - write single byte to a register - * @indio_dev: iio device associated with child of actual device - * @reg_address: the address of the register to be written - * @val: the value to write - **/ -static int adis16203_spi_write_reg_8(struct iio_dev *indio_dev, - u8 reg_address, - u8 val) -{ - int ret; - struct adis16203_state *st = iio_priv(indio_dev); - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16203_WRITE_REG(reg_address); - st->tx[1] = val; - - ret = spi_write(st->us, st->tx, 2); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16203_spi_write_reg_16() - write 2 bytes to a pair of registers - * @indio_dev: iio device associated with child of actual device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: value to be written - **/ -static int adis16203_spi_write_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 value) -{ - int ret; - struct spi_message msg; - struct adis16203_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - }, { - .tx_buf = st->tx + 2, - .bits_per_word = 8, - .len = 2, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16203_WRITE_REG(lower_reg_address); - st->tx[1] = value & 0xFF; - st->tx[2] = ADIS16203_WRITE_REG(lower_reg_address + 1); - st->tx[3] = (value >> 8) & 0xFF; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16203_spi_read_reg_16() - read 2 bytes from a 16-bit register - * @indio_dev: iio device associated with child of actual device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: somewhere to pass back the value read - **/ -static int adis16203_spi_read_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 *val) -{ - struct spi_message msg; - struct adis16203_state *st = iio_priv(indio_dev); - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 20, - }, { - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 2, - .delay_usecs = 20, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16203_READ_REG(lower_reg_address); - st->tx[1] = 0; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X", - lower_reg_address); - goto error_ret; - } - *val = (st->rx[0] << 8) | st->rx[1]; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -static int adis16203_check_status(struct iio_dev *indio_dev) -{ - u16 status; - int ret; - - ret = adis16203_spi_read_reg_16(indio_dev, - ADIS16203_DIAG_STAT, - &status); - if (ret < 0) { - dev_err(&indio_dev->dev, "Reading status failed\n"); - goto error_ret; - } - ret = status & 0x1F; - - if (status & ADIS16203_DIAG_STAT_SELFTEST_FAIL) - dev_err(&indio_dev->dev, "Self test failure\n"); - if (status & ADIS16203_DIAG_STAT_SPI_FAIL) - dev_err(&indio_dev->dev, "SPI failure\n"); - if (status & ADIS16203_DIAG_STAT_FLASH_UPT) - dev_err(&indio_dev->dev, "Flash update failed\n"); - if (status & ADIS16203_DIAG_STAT_POWER_HIGH) - dev_err(&indio_dev->dev, "Power supply above 3.625V\n"); - if (status & ADIS16203_DIAG_STAT_POWER_LOW) - dev_err(&indio_dev->dev, "Power supply below 3.15V\n"); - -error_ret: - return ret; -} - -static int adis16203_reset(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16203_spi_write_reg_8(indio_dev, - ADIS16203_GLOB_CMD, - ADIS16203_GLOB_CMD_SW_RESET); - if (ret) - dev_err(&indio_dev->dev, "problem resetting device"); - - return ret; -} - -int adis16203_set_irq(struct iio_dev *indio_dev, bool enable) -{ - int ret = 0; - u16 msc; - - ret = adis16203_spi_read_reg_16(indio_dev, ADIS16203_MSC_CTRL, &msc); - if (ret) - goto error_ret; - - msc |= ADIS16203_MSC_CTRL_ACTIVE_HIGH; - msc &= ~ADIS16203_MSC_CTRL_DATA_RDY_DIO1; - if (enable) - msc |= ADIS16203_MSC_CTRL_DATA_RDY_EN; - else - msc &= ~ADIS16203_MSC_CTRL_DATA_RDY_EN; - - ret = adis16203_spi_write_reg_16(indio_dev, ADIS16203_MSC_CTRL, msc); - -error_ret: - return ret; -} - -static int adis16203_self_test(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16203_spi_write_reg_16(indio_dev, - ADIS16203_MSC_CTRL, - ADIS16203_MSC_CTRL_SELF_TEST_EN); - if (ret) { - dev_err(&indio_dev->dev, "problem starting self test"); - goto err_ret; - } - - adis16203_check_status(indio_dev); - -err_ret: - return ret; -} - -static int adis16203_initial_setup(struct iio_dev *indio_dev) -{ - int ret; - - /* Disable IRQ */ - ret = adis16203_set_irq(indio_dev, false); - if (ret) { - dev_err(&indio_dev->dev, "disable irq failed"); - goto err_ret; - } - - /* Do self test */ - ret = adis16203_self_test(indio_dev); - if (ret) { - dev_err(&indio_dev->dev, "self test failure"); - goto err_ret; - } - - /* Read status register to check the result */ - ret = adis16203_check_status(indio_dev); - if (ret) { - adis16203_reset(indio_dev); - dev_err(&indio_dev->dev, "device not playing ball -> reset"); - msleep(ADIS16203_STARTUP_DELAY); - ret = adis16203_check_status(indio_dev); - if (ret) { - dev_err(&indio_dev->dev, "giving up"); - goto err_ret; - } - } - -err_ret: - return ret; -} - -enum adis16203_chan { - in_supply, - in_aux, - incli_x, - incli_y, - temp, -}; - -static u8 adis16203_addresses[5][2] = { - [in_supply] = { ADIS16203_SUPPLY_OUT }, - [in_aux] = { ADIS16203_AUX_ADC }, - [incli_x] = { ADIS16203_XINCL_OUT, ADIS16203_INCL_NULL}, - [incli_y] = { ADIS16203_YINCL_OUT }, - [temp] = { ADIS16203_TEMP_OUT } +static const u8 adis16203_addresses[] = { + [ADIS16203_SCAN_INCLI_X] = ADIS16203_INCL_NULL, }; static int adis16203_write_raw(struct iio_dev *indio_dev, @@ -274,9 +34,10 @@ static int adis16203_write_raw(struct iio_dev *indio_dev, int val2, long mask) { + struct adis *st = iio_priv(indio_dev); /* currently only one writable parameter which keeps this simple */ - u8 addr = adis16203_addresses[chan->address][1]; - return adis16203_spi_write_reg_16(indio_dev, addr, val & 0x3FFF); + u8 addr = adis16203_addresses[chan->scan_index]; + return adis_write_reg_16(st, addr, val & 0x3FFF); } static int adis16203_read_raw(struct iio_dev *indio_dev, @@ -284,35 +45,15 @@ static int adis16203_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { + struct adis *st = iio_priv(indio_dev); int ret; int bits; u8 addr; s16 val16; switch (mask) { case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); - addr = adis16203_addresses[chan->address][0]; - ret = adis16203_spi_read_reg_16(indio_dev, addr, &val16); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - - if (val16 & ADIS16203_ERROR_ACTIVE) { - ret = adis16203_check_status(indio_dev); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - } - val16 = val16 & ((1 << chan->scan_type.realbits) - 1); - if (chan->scan_type.sign == 's') - val16 = (s16)(val16 << - (16 - chan->scan_type.realbits)) >> - (16 - chan->scan_type.realbits); - *val = val16; - mutex_unlock(&indio_dev->mlock); - return IIO_VAL_INT; + return adis_single_conversion(indio_dev, chan, + ADIS16203_ERROR_ACTIVE, val); case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: @@ -341,8 +82,8 @@ static int adis16203_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_CALIBBIAS: bits = 14; mutex_lock(&indio_dev->mlock); - addr = adis16203_addresses[chan->address][1]; - ret = adis16203_spi_read_reg_16(indio_dev, addr, &val16); + addr = adis16203_addresses[chan->scan_index]; + ret = adis_read_reg_16(st, addr, &val16); if (ret) { mutex_unlock(&indio_dev->mlock); return ret; @@ -358,89 +99,53 @@ static int adis16203_read_raw(struct iio_dev *indio_dev, } static const struct iio_chan_spec adis16203_channels[] = { - { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .extend_name = "supply", - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_supply, - .scan_index = ADIS16203_SCAN_SUPPLY, - .scan_type = { - .sign = 'u', - .realbits = 12, - .storagebits = 16, - }, - }, { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_aux, - .scan_index = ADIS16203_SCAN_AUX_ADC, - .scan_type = { - .sign = 'u', - .realbits = 12, - .storagebits = 16, - }, - }, { - .type = IIO_INCLI, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, - .address = incli_x, - .scan_index = ADIS16203_SCAN_INCLI_X, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, { /* Fixme: Not what it appears to be - see data sheet */ - .type = IIO_INCLI, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = incli_y, - .scan_index = ADIS16203_SCAN_INCLI_Y, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, - .address = temp, - .scan_index = ADIS16203_SCAN_TEMP, - .scan_type = { - .sign = 'u', - .realbits = 12, - .storagebits = 16, - }, - }, + ADIS_SUPPLY_CHAN(ADIS16203_SUPPLY_OUT, ADIS16203_SCAN_SUPPLY, 12), + ADIS_AUX_ADC_CHAN(ADIS16203_AUX_ADC, ADIS16203_SCAN_AUX_ADC, 12), + ADIS_INCLI_CHAN(X, ADIS16203_XINCL_OUT, ADIS16203_SCAN_INCLI_X, + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14), + /* Fixme: Not what it appears to be - see data sheet */ + ADIS_INCLI_CHAN(Y, ADIS16203_YINCL_OUT, ADIS16203_SCAN_INCLI_Y, 0, 14), + ADIS_TEMP_CHAN(ADIS16203_TEMP_OUT, ADIS16203_SCAN_TEMP, 12), IIO_CHAN_SOFT_TIMESTAMP(5), }; static const struct iio_info adis16203_info = { .read_raw = &adis16203_read_raw, .write_raw = &adis16203_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module = THIS_MODULE, }; -static int __devinit adis16203_probe(struct spi_device *spi) +static const char * const adis16203_status_error_msgs[] = { + [ADIS16203_DIAG_STAT_SELFTEST_FAIL_BIT] = "Self test failure", + [ADIS16203_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure", + [ADIS16203_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed", + [ADIS16203_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", + [ADIS16203_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 3.15V", +}; + +static const struct adis_data adis16203_data = { + .read_delay = 20, + .msc_ctrl_reg = ADIS16203_MSC_CTRL, + .glob_cmd_reg = ADIS16203_GLOB_CMD, + .diag_stat_reg = ADIS16203_DIAG_STAT, + + .self_test_mask = ADIS16203_MSC_CTRL_SELF_TEST_EN, + .startup_delay = ADIS16203_STARTUP_DELAY, + + .status_error_msgs = adis16203_status_error_msgs, + .status_error_mask = BIT(ADIS16203_DIAG_STAT_SELFTEST_FAIL_BIT) | + BIT(ADIS16203_DIAG_STAT_SPI_FAIL_BIT) | + BIT(ADIS16203_DIAG_STAT_FLASH_UPT_BIT) | + BIT(ADIS16203_DIAG_STAT_POWER_HIGH_BIT) | + BIT(ADIS16203_DIAG_STAT_POWER_LOW_BIT), +}; + +static int adis16203_probe(struct spi_device *spi) { int ret; struct iio_dev *indio_dev; - struct adis16203_state *st; + struct adis *st; /* setup the industrialio driver allocated elements */ indio_dev = iio_device_alloc(sizeof(*st)); @@ -451,8 +156,6 @@ static int __devinit adis16203_probe(struct spi_device *spi) st = iio_priv(indio_dev); /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); - st->us = spi; - mutex_init(&st->buf_lock); indio_dev->name = spi->dev.driver->name; indio_dev->dev.parent = &spi->dev; @@ -461,55 +164,40 @@ static int __devinit adis16203_probe(struct spi_device *spi) indio_dev->info = &adis16203_info; indio_dev->modes = INDIO_DIRECT_MODE; - ret = adis16203_configure_ring(indio_dev); + ret = adis_init(st, indio_dev, spi, &adis16203_data); if (ret) goto error_free_dev; - ret = iio_buffer_register(indio_dev, - adis16203_channels, - ARRAY_SIZE(adis16203_channels)); - if (ret) { - printk(KERN_ERR "failed to initialize the ring\n"); - goto error_unreg_ring_funcs; - } - - if (spi->irq) { - ret = adis16203_probe_trigger(indio_dev); - if (ret) - goto error_uninitialize_ring; - } + ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); + if (ret) + goto error_free_dev; /* Get the device into a sane initial state */ - ret = adis16203_initial_setup(indio_dev); + ret = adis_initial_startup(st); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; ret = iio_device_register(indio_dev); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; return 0; -error_remove_trigger: - adis16203_remove_trigger(indio_dev); -error_uninitialize_ring: - iio_buffer_unregister(indio_dev); -error_unreg_ring_funcs: - adis16203_unconfigure_ring(indio_dev); +error_cleanup_buffer_trigger: + adis_cleanup_buffer_and_trigger(st, indio_dev); error_free_dev: iio_device_free(indio_dev); error_ret: return ret; } -static int __devexit adis16203_remove(struct spi_device *spi) +static int adis16203_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct adis *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); - adis16203_remove_trigger(indio_dev); - iio_buffer_unregister(indio_dev); - adis16203_unconfigure_ring(indio_dev); + adis_cleanup_buffer_and_trigger(st, indio_dev); iio_device_free(indio_dev); return 0; @@ -521,7 +209,7 @@ static struct spi_driver adis16203_driver = { .owner = THIS_MODULE, }, .probe = adis16203_probe, - .remove = __devexit_p(adis16203_remove), + .remove = adis16203_remove, }; module_spi_driver(adis16203_driver); diff --git a/drivers/staging/iio/accel/adis16203_ring.c b/drivers/staging/iio/accel/adis16203_ring.c deleted file mode 100644 index 7507e1a0459..00000000000 --- a/drivers/staging/iio/accel/adis16203_ring.c +++ /dev/null @@ -1,136 +0,0 @@ -#include <linux/export.h> -#include <linux/interrupt.h> -#include <linux/mutex.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/slab.h> - -#include <linux/iio/iio.h> -#include "../ring_sw.h" -#include <linux/iio/trigger_consumer.h> -#include "adis16203.h" - -/** - * adis16203_read_ring_data() read data registers which will be placed into ring - * @indio_dev: the IIO device - * @rx: somewhere to pass back the value read - **/ -static int adis16203_read_ring_data(struct iio_dev *indio_dev, u8 *rx) -{ - struct spi_message msg; - struct adis16203_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[ADIS16203_OUTPUTS + 1]; - int ret; - int i; - - mutex_lock(&st->buf_lock); - - spi_message_init(&msg); - - memset(xfers, 0, sizeof(xfers)); - for (i = 0; i <= ADIS16203_OUTPUTS; i++) { - xfers[i].bits_per_word = 8; - xfers[i].cs_change = 1; - xfers[i].len = 2; - xfers[i].delay_usecs = 20; - xfers[i].tx_buf = st->tx + 2 * i; - if (i < 1) /* SUPPLY_OUT: 0x02, AUX_ADC: 0x08 */ - st->tx[2 * i] = ADIS16203_READ_REG(ADIS16203_SUPPLY_OUT + 2 * i); - else - st->tx[2 * i] = ADIS16203_READ_REG(ADIS16203_SUPPLY_OUT + 2 * i + 6); - st->tx[2 * i + 1] = 0; - if (i >= 1) - xfers[i].rx_buf = rx + 2 * (i - 1); - spi_message_add_tail(&xfers[i], &msg); - } - - ret = spi_sync(st->us, &msg); - if (ret) - dev_err(&st->us->dev, "problem when burst reading"); - - mutex_unlock(&st->buf_lock); - - return ret; -} - -/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device - * specific to be rolled into the core. - */ -static irqreturn_t adis16203_trigger_handler(int irq, void *p) -{ - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct adis16203_state *st = iio_priv(indio_dev); - - int i = 0; - s16 *data; - - data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (data == NULL) { - dev_err(&st->us->dev, "memory alloc failed in ring bh"); - goto done; - } - - if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && - adis16203_read_ring_data(indio_dev, st->rx) >= 0) - for (; i < bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); i++) - data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); - - /* Guaranteed to be aligned with 8 byte boundary */ - if (indio_dev->scan_timestamp) - *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; - - iio_push_to_buffer(indio_dev->buffer, (u8 *)data); - - kfree(data); -done: - iio_trigger_notify_done(indio_dev->trig); - - return IRQ_HANDLED; -} - -void adis16203_unconfigure_ring(struct iio_dev *indio_dev) -{ - iio_dealloc_pollfunc(indio_dev->pollfunc); - iio_sw_rb_free(indio_dev->buffer); -} - -static const struct iio_buffer_setup_ops adis16203_ring_setup_ops = { - .preenable = &iio_sw_buffer_preenable, - .postenable = &iio_triggered_buffer_postenable, - .predisable = &iio_triggered_buffer_predisable, -}; - -int adis16203_configure_ring(struct iio_dev *indio_dev) -{ - int ret = 0; - struct iio_buffer *ring; - - ring = iio_sw_rb_allocate(indio_dev); - if (!ring) { - ret = -ENOMEM; - return ret; - } - indio_dev->buffer = ring; - ring->scan_timestamp = true; - indio_dev->setup_ops = &adis16203_ring_setup_ops; - - indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time, - &adis16203_trigger_handler, - IRQF_ONESHOT, - indio_dev, - "adis16203_consumer%d", - indio_dev->id); - if (indio_dev->pollfunc == NULL) { - ret = -ENOMEM; - goto error_iio_sw_rb_free; - } - - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; - return 0; - -error_iio_sw_rb_free: - iio_sw_rb_free(indio_dev->buffer); - return ret; -} diff --git a/drivers/staging/iio/accel/adis16203_trigger.c b/drivers/staging/iio/accel/adis16203_trigger.c deleted file mode 100644 index b8a04073d6d..00000000000 --- a/drivers/staging/iio/accel/adis16203_trigger.c +++ /dev/null @@ -1,73 +0,0 @@ -#include <linux/interrupt.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/export.h> - -#include <linux/iio/iio.h> -#include <linux/iio/trigger.h> -#include "adis16203.h" - -/** - * adis16203_data_rdy_trigger_set_state() set datardy interrupt state - **/ -static int adis16203_data_rdy_trigger_set_state(struct iio_trigger *trig, - bool state) -{ - struct iio_dev *indio_dev = trig->private_data; - - dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); - return adis16203_set_irq(indio_dev, state); -} - -static const struct iio_trigger_ops adis16203_trigger_ops = { - .owner = THIS_MODULE, - .set_trigger_state = &adis16203_data_rdy_trigger_set_state, -}; - -int adis16203_probe_trigger(struct iio_dev *indio_dev) -{ - int ret; - struct adis16203_state *st = iio_priv(indio_dev); - - st->trig = iio_trigger_alloc("adis16203-dev%d", indio_dev->id); - if (st->trig == NULL) { - ret = -ENOMEM; - goto error_ret; - } - - ret = request_irq(st->us->irq, - &iio_trigger_generic_data_rdy_poll, - IRQF_TRIGGER_RISING, - "adis16203", - st->trig); - if (ret) - goto error_free_trig; - - st->trig->dev.parent = &st->us->dev; - st->trig->ops = &adis16203_trigger_ops; - st->trig->private_data = indio_dev; - ret = iio_trigger_register(st->trig); - - /* select default trigger */ - indio_dev->trig = st->trig; - if (ret) - goto error_free_irq; - - return 0; - -error_free_irq: - free_irq(st->us->irq, st->trig); -error_free_trig: - iio_trigger_free(st->trig); -error_ret: - return ret; -} - -void adis16203_remove_trigger(struct iio_dev *indio_dev) -{ - struct adis16203_state *st = iio_priv(indio_dev); - - iio_trigger_unregister(st->trig); - free_irq(st->us->irq, st->trig); - iio_trigger_free(st->trig); -} diff --git a/drivers/staging/iio/accel/adis16204.h b/drivers/staging/iio/accel/adis16204.h index 7cf4e91f83a..9ff950c1e8d 100644 --- a/drivers/staging/iio/accel/adis16204.h +++ b/drivers/staging/iio/accel/adis16204.h @@ -3,9 +3,6 @@ #define ADIS16204_STARTUP_DELAY 220 /* ms */ -#define ADIS16204_READ_REG(a) a -#define ADIS16204_WRITE_REG(a) ((a) | 0x80) - #define ADIS16204_FLASH_CNT 0x00 /* Flash memory write count */ #define ADIS16204_SUPPLY_OUT 0x02 /* Output, power supply */ #define ADIS16204_XACCL_OUT 0x04 /* Output, x-axis accelerometer */ @@ -35,8 +32,6 @@ #define ADIS16204_DIAG_STAT 0x3C /* Diagnostics, system status register */ #define ADIS16204_GLOB_CMD 0x3E /* Operation, system command register */ -#define ADIS16204_OUTPUTS 5 - /* MSC_CTRL */ #define ADIS16204_MSC_CTRL_PWRUP_SELF_TEST (1 << 10) /* Self-test at power-on: 1 = disabled, 0 = enabled */ #define ADIS16204_MSC_CTRL_SELF_TEST_EN (1 << 8) /* Self-test enable */ @@ -47,87 +42,27 @@ /* DIAG_STAT */ #define ADIS16204_DIAG_STAT_ALARM2 (1<<9) /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ #define ADIS16204_DIAG_STAT_ALARM1 (1<<8) /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ -#define ADIS16204_DIAG_STAT_SELFTEST_FAIL (1<<5) /* Self-test diagnostic error flag: 1 = error condition, +#define ADIS16204_DIAG_STAT_SELFTEST_FAIL_BIT 5 /* Self-test diagnostic error flag: 1 = error condition, 0 = normal operation */ -#define ADIS16204_DIAG_STAT_SPI_FAIL (1<<3) /* SPI communications failure */ -#define ADIS16204_DIAG_STAT_FLASH_UPT (1<<2) /* Flash update failure */ -#define ADIS16204_DIAG_STAT_POWER_HIGH (1<<1) /* Power supply above 3.625 V */ -#define ADIS16204_DIAG_STAT_POWER_LOW (1<<0) /* Power supply below 2.975 V */ +#define ADIS16204_DIAG_STAT_SPI_FAIL_BIT 3 /* SPI communications failure */ +#define ADIS16204_DIAG_STAT_FLASH_UPT_BIT 2 /* Flash update failure */ +#define ADIS16204_DIAG_STAT_POWER_HIGH_BIT 1 /* Power supply above 3.625 V */ +#define ADIS16204_DIAG_STAT_POWER_LOW_BIT 0 /* Power supply below 2.975 V */ /* GLOB_CMD */ #define ADIS16204_GLOB_CMD_SW_RESET (1<<7) #define ADIS16204_GLOB_CMD_CLEAR_STAT (1<<4) #define ADIS16204_GLOB_CMD_FACTORY_CAL (1<<1) -#define ADIS16204_MAX_TX 24 -#define ADIS16204_MAX_RX 24 - #define ADIS16204_ERROR_ACTIVE (1<<14) -/** - * struct adis16204_state - device instance specific data - * @us: actual spi_device - * @trig: data ready trigger registered with iio - * @tx: transmit buffer - * @rx: receive buffer - * @buf_lock: mutex to protect tx and rx - **/ -struct adis16204_state { - struct spi_device *us; - struct iio_trigger *trig; - struct mutex buf_lock; - u8 tx[ADIS16204_MAX_TX] ____cacheline_aligned; - u8 rx[ADIS16204_MAX_RX]; -}; - -int adis16204_set_irq(struct iio_dev *indio_dev, bool enable); - enum adis16204_scan { - ADIS16204_SCAN_SUPPLY, ADIS16204_SCAN_ACC_X, ADIS16204_SCAN_ACC_Y, + ADIS16204_SCAN_ACC_XY, + ADIS16204_SCAN_SUPPLY, ADIS16204_SCAN_AUX_ADC, ADIS16204_SCAN_TEMP, }; -#ifdef CONFIG_IIO_BUFFER -void adis16204_remove_trigger(struct iio_dev *indio_dev); -int adis16204_probe_trigger(struct iio_dev *indio_dev); - -ssize_t adis16204_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf); - -int adis16204_configure_ring(struct iio_dev *indio_dev); -void adis16204_unconfigure_ring(struct iio_dev *indio_dev); - -#else /* CONFIG_IIO_BUFFER */ - -static inline void adis16204_remove_trigger(struct iio_dev *indio_dev) -{ -} - -static inline int adis16204_probe_trigger(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline ssize_t -adis16204_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return 0; -} - -static int adis16204_configure_ring(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline void adis16204_unconfigure_ring(struct iio_dev *indio_dev) -{ -} - -#endif /* CONFIG_IIO_BUFFER */ #endif /* SPI_ADIS16204_H_ */ diff --git a/drivers/staging/iio/accel/adis16204_core.c b/drivers/staging/iio/accel/adis16204_core.c index c6234c2f46a..f3592668e06 100644 --- a/drivers/staging/iio/accel/adis16204_core.c +++ b/drivers/staging/iio/accel/adis16204_core.c @@ -21,261 +21,16 @@ #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16204.h" -#define DRIVER_NAME "adis16204" - -/** - * adis16204_spi_write_reg_8() - write single byte to a register - * @dev: device associated with child of actual device (iio_dev or iio_trig) - * @reg_address: the address of the register to be written - * @val: the value to write - **/ -static int adis16204_spi_write_reg_8(struct iio_dev *indio_dev, - u8 reg_address, - u8 val) -{ - int ret; - struct adis16204_state *st = iio_priv(indio_dev); - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16204_WRITE_REG(reg_address); - st->tx[1] = val; - - ret = spi_write(st->us, st->tx, 2); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16204_spi_write_reg_16() - write 2 bytes to a pair of registers - * @indio_dev: iio device associated with child of actual device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: value to be written - **/ -static int adis16204_spi_write_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 value) -{ - int ret; - struct spi_message msg; - struct adis16204_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - }, { - .tx_buf = st->tx + 2, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16204_WRITE_REG(lower_reg_address); - st->tx[1] = value & 0xFF; - st->tx[2] = ADIS16204_WRITE_REG(lower_reg_address + 1); - st->tx[3] = (value >> 8) & 0xFF; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16204_spi_read_reg_16() - read 2 bytes from a 16-bit register - * @indio_dev: iio device associated with child of actual device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: somewhere to pass back the value read - **/ -static int adis16204_spi_read_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 *val) -{ - struct spi_message msg; - struct adis16204_state *st = iio_priv(indio_dev); - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 20, - }, { - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 2, - .delay_usecs = 20, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16204_READ_REG(lower_reg_address); - st->tx[1] = 0; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X", - lower_reg_address); - goto error_ret; - } - *val = (st->rx[0] << 8) | st->rx[1]; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -static int adis16204_check_status(struct iio_dev *indio_dev) -{ - u16 status; - int ret; - - ret = adis16204_spi_read_reg_16(indio_dev, - ADIS16204_DIAG_STAT, &status); - if (ret < 0) { - dev_err(&indio_dev->dev, "Reading status failed\n"); - goto error_ret; - } - ret = status & 0x1F; - - if (status & ADIS16204_DIAG_STAT_SELFTEST_FAIL) - dev_err(&indio_dev->dev, "Self test failure\n"); - if (status & ADIS16204_DIAG_STAT_SPI_FAIL) - dev_err(&indio_dev->dev, "SPI failure\n"); - if (status & ADIS16204_DIAG_STAT_FLASH_UPT) - dev_err(&indio_dev->dev, "Flash update failed\n"); - if (status & ADIS16204_DIAG_STAT_POWER_HIGH) - dev_err(&indio_dev->dev, "Power supply above 3.625V\n"); - if (status & ADIS16204_DIAG_STAT_POWER_LOW) - dev_err(&indio_dev->dev, "Power supply below 2.975V\n"); - -error_ret: - return ret; -} - -static int adis16204_reset(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16204_spi_write_reg_8(indio_dev, - ADIS16204_GLOB_CMD, - ADIS16204_GLOB_CMD_SW_RESET); - if (ret) - dev_err(&indio_dev->dev, "problem resetting device"); - - return ret; -} - -int adis16204_set_irq(struct iio_dev *indio_dev, bool enable) -{ - int ret = 0; - u16 msc; - - ret = adis16204_spi_read_reg_16(indio_dev, ADIS16204_MSC_CTRL, &msc); - if (ret) - goto error_ret; - - msc |= ADIS16204_MSC_CTRL_ACTIVE_HIGH; - msc &= ~ADIS16204_MSC_CTRL_DATA_RDY_DIO2; - if (enable) - msc |= ADIS16204_MSC_CTRL_DATA_RDY_EN; - else - msc &= ~ADIS16204_MSC_CTRL_DATA_RDY_EN; - - ret = adis16204_spi_write_reg_16(indio_dev, ADIS16204_MSC_CTRL, msc); - -error_ret: - return ret; -} - -static int adis16204_self_test(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16204_spi_write_reg_16(indio_dev, - ADIS16204_MSC_CTRL, - ADIS16204_MSC_CTRL_SELF_TEST_EN); - if (ret) { - dev_err(&indio_dev->dev, "problem starting self test"); - goto err_ret; - } - - adis16204_check_status(indio_dev); - -err_ret: - return ret; -} - -static int adis16204_initial_setup(struct iio_dev *indio_dev) -{ - int ret; - - /* Disable IRQ */ - ret = adis16204_set_irq(indio_dev, false); - if (ret) { - dev_err(&indio_dev->dev, "disable irq failed"); - goto err_ret; - } - - /* Do self test */ - ret = adis16204_self_test(indio_dev); - if (ret) { - dev_err(&indio_dev->dev, "self test failure"); - goto err_ret; - } - - /* Read status register to check the result */ - ret = adis16204_check_status(indio_dev); - if (ret) { - adis16204_reset(indio_dev); - dev_err(&indio_dev->dev, "device not playing ball -> reset"); - msleep(ADIS16204_STARTUP_DELAY); - ret = adis16204_check_status(indio_dev); - if (ret) { - dev_err(&indio_dev->dev, "giving up"); - goto err_ret; - } - } - -err_ret: - return ret; -} - /* Unique to this driver currently */ -enum adis16204_channel { - in_supply, - in_aux, - temp, - accel_x, - accel_y, - accel_xy, -}; - -static u8 adis16204_addresses[6][3] = { - [in_supply] = { ADIS16204_SUPPLY_OUT }, - [in_aux] = { ADIS16204_AUX_ADC }, - [temp] = { ADIS16204_TEMP_OUT }, - [accel_x] = { ADIS16204_XACCL_OUT, ADIS16204_XACCL_NULL, - ADIS16204_X_PEAK_OUT }, - [accel_y] = { ADIS16204_XACCL_OUT, ADIS16204_YACCL_NULL, - ADIS16204_Y_PEAK_OUT }, - [accel_xy] = { ADIS16204_XY_RSS_OUT, 0, - ADIS16204_XY_PEAK_OUT }, +static const u8 adis16204_addresses[][2] = { + [ADIS16204_SCAN_ACC_X] = { ADIS16204_XACCL_NULL, ADIS16204_X_PEAK_OUT }, + [ADIS16204_SCAN_ACC_Y] = { ADIS16204_YACCL_NULL, ADIS16204_Y_PEAK_OUT }, + [ADIS16204_SCAN_ACC_XY] = { 0, ADIS16204_XY_PEAK_OUT }, }; static int adis16204_read_raw(struct iio_dev *indio_dev, @@ -283,6 +38,7 @@ static int adis16204_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { + struct adis *st = iio_priv(indio_dev); int ret; int bits; u8 addr; @@ -291,29 +47,8 @@ static int adis16204_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); - addr = adis16204_addresses[chan->address][0]; - ret = adis16204_spi_read_reg_16(indio_dev, addr, &val16); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - - if (val16 & ADIS16204_ERROR_ACTIVE) { - ret = adis16204_check_status(indio_dev); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - } - val16 = val16 & ((1 << chan->scan_type.realbits) - 1); - if (chan->scan_type.sign == 's') - val16 = (s16)(val16 << - (16 - chan->scan_type.realbits)) >> - (16 - chan->scan_type.realbits); - *val = val16; - mutex_unlock(&indio_dev->mlock); - return IIO_VAL_INT; + return adis_single_conversion(indio_dev, chan, + ADIS16204_ERROR_ACTIVE, val); case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: @@ -353,14 +88,14 @@ static int adis16204_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_PEAK: if (mask == IIO_CHAN_INFO_CALIBBIAS) { bits = 12; - addrind = 1; + addrind = 0; } else { /* PEAK_SEPARATE */ bits = 14; - addrind = 2; + addrind = 1; } mutex_lock(&indio_dev->mlock); - addr = adis16204_addresses[chan->address][addrind]; - ret = adis16204_spi_read_reg_16(indio_dev, addr, &val16); + addr = adis16204_addresses[chan->scan_index][addrind]; + ret = adis_read_reg_16(st, addr, &val16); if (ret) { mutex_unlock(&indio_dev->mlock); return ret; @@ -380,6 +115,7 @@ static int adis16204_write_raw(struct iio_dev *indio_dev, int val2, long mask) { + struct adis *st = iio_priv(indio_dev); int bits; s16 val16; u8 addr; @@ -391,114 +127,65 @@ static int adis16204_write_raw(struct iio_dev *indio_dev, break; default: return -EINVAL; - }; + } val16 = val & ((1 << bits) - 1); - addr = adis16204_addresses[chan->address][1]; - return adis16204_spi_write_reg_16(indio_dev, addr, val16); + addr = adis16204_addresses[chan->scan_index][1]; + return adis_write_reg_16(st, addr, val16); } return -EINVAL; } static const struct iio_chan_spec adis16204_channels[] = { - { - .type = IIO_VOLTAGE, - .indexed = 1, /* Note was not previously indexed */ - .channel = 0, - .extend_name = "supply", - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_supply, - .scan_index = ADIS16204_SCAN_SUPPLY, - .scan_type = { - .sign = 'u', - .realbits = 12, - .storagebits = 16, - }, - }, { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_aux, - .scan_index = ADIS16204_SCAN_AUX_ADC, - .scan_type = { - .sign = 'u', - .realbits = 12, - .storagebits = 16, - }, - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, - .address = temp, - .scan_index = ADIS16204_SCAN_TEMP, - .scan_type = { - .sign = 'u', - .realbits = 12, - .storagebits = 16, - }, - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | + ADIS_SUPPLY_CHAN(ADIS16204_SUPPLY_OUT, ADIS16204_SCAN_SUPPLY, 12), + ADIS_AUX_ADC_CHAN(ADIS16204_AUX_ADC, ADIS16204_SCAN_AUX_ADC, 12), + ADIS_TEMP_CHAN(ADIS16204_TEMP_OUT, ADIS16204_SCAN_TEMP, 12), + ADIS_ACCEL_CHAN(X, ADIS16204_XACCL_OUT, ADIS16204_SCAN_ACC_X, IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_PEAK_SEPARATE_BIT, - .address = accel_x, - .scan_index = ADIS16204_SCAN_ACC_X, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | + IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 14), + ADIS_ACCEL_CHAN(Y, ADIS16204_YACCL_OUT, ADIS16204_SCAN_ACC_Y, IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_PEAK_SEPARATE_BIT, - .address = accel_y, - .scan_index = ADIS16204_SCAN_ACC_Y, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, + IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 14), + ADIS_ACCEL_CHAN(ROOT_SUM_SQUARED_X_Y, ADIS16204_XY_RSS_OUT, + ADIS16204_SCAN_ACC_XY, IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 14), IIO_CHAN_SOFT_TIMESTAMP(5), - { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_ROOT_SUM_SQUARED_X_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_PEAK_SEPARATE_BIT, - .address = accel_xy, - .scan_type = { - .sign = 'u', - .realbits = 14, - .storagebits = 16, - }, - } }; static const struct iio_info adis16204_info = { .read_raw = &adis16204_read_raw, .write_raw = &adis16204_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module = THIS_MODULE, }; -static int __devinit adis16204_probe(struct spi_device *spi) +static const char * const adis16204_status_error_msgs[] = { + [ADIS16204_DIAG_STAT_SELFTEST_FAIL_BIT] = "Self test failure", + [ADIS16204_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure", + [ADIS16204_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed", + [ADIS16204_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", + [ADIS16204_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 2.975V", +}; + +static const struct adis_data adis16204_data = { + .read_delay = 20, + .msc_ctrl_reg = ADIS16204_MSC_CTRL, + .glob_cmd_reg = ADIS16204_GLOB_CMD, + .diag_stat_reg = ADIS16204_DIAG_STAT, + + .self_test_mask = ADIS16204_MSC_CTRL_SELF_TEST_EN, + .startup_delay = ADIS16204_STARTUP_DELAY, + + .status_error_msgs = adis16204_status_error_msgs, + .status_error_mask = BIT(ADIS16204_DIAG_STAT_SELFTEST_FAIL_BIT) | + BIT(ADIS16204_DIAG_STAT_SPI_FAIL_BIT) | + BIT(ADIS16204_DIAG_STAT_FLASH_UPT_BIT) | + BIT(ADIS16204_DIAG_STAT_POWER_HIGH_BIT) | + BIT(ADIS16204_DIAG_STAT_POWER_LOW_BIT), +}; + +static int adis16204_probe(struct spi_device *spi) { int ret; - struct adis16204_state *st; + struct adis *st; struct iio_dev *indio_dev; /* setup the industrialio driver allocated elements */ @@ -510,8 +197,6 @@ static int __devinit adis16204_probe(struct spi_device *spi) st = iio_priv(indio_dev); /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); - st->us = spi; - mutex_init(&st->buf_lock); indio_dev->name = spi->dev.driver->name; indio_dev->dev.parent = &spi->dev; @@ -520,54 +205,39 @@ static int __devinit adis16204_probe(struct spi_device *spi) indio_dev->num_channels = ARRAY_SIZE(adis16204_channels); indio_dev->modes = INDIO_DIRECT_MODE; - ret = adis16204_configure_ring(indio_dev); + ret = adis_init(st, indio_dev, spi, &adis16204_data); if (ret) goto error_free_dev; - ret = iio_buffer_register(indio_dev, - adis16204_channels, - 6); - if (ret) { - printk(KERN_ERR "failed to initialize the ring\n"); - goto error_unreg_ring_funcs; - } - - if (spi->irq) { - ret = adis16204_probe_trigger(indio_dev); - if (ret) - goto error_uninitialize_ring; - } + ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); + if (ret) + goto error_free_dev; /* Get the device into a sane initial state */ - ret = adis16204_initial_setup(indio_dev); + ret = adis_initial_startup(st); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; ret = iio_device_register(indio_dev); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; return 0; -error_remove_trigger: - adis16204_remove_trigger(indio_dev); -error_uninitialize_ring: - iio_buffer_unregister(indio_dev); -error_unreg_ring_funcs: - adis16204_unconfigure_ring(indio_dev); +error_cleanup_buffer_trigger: + adis_cleanup_buffer_and_trigger(st, indio_dev); error_free_dev: iio_device_free(indio_dev); error_ret: return ret; } -static int __devexit adis16204_remove(struct spi_device *spi) +static int adis16204_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct adis *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); - adis16204_remove_trigger(indio_dev); - iio_buffer_unregister(indio_dev); - adis16204_unconfigure_ring(indio_dev); + adis_cleanup_buffer_and_trigger(st, indio_dev); iio_device_free(indio_dev); return 0; @@ -579,7 +249,7 @@ static struct spi_driver adis16204_driver = { .owner = THIS_MODULE, }, .probe = adis16204_probe, - .remove = __devexit_p(adis16204_remove), + .remove = adis16204_remove, }; module_spi_driver(adis16204_driver); diff --git a/drivers/staging/iio/accel/adis16204_ring.c b/drivers/staging/iio/accel/adis16204_ring.c deleted file mode 100644 index 4c976bec986..00000000000 --- a/drivers/staging/iio/accel/adis16204_ring.c +++ /dev/null @@ -1,134 +0,0 @@ -#include <linux/export.h> -#include <linux/interrupt.h> -#include <linux/mutex.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/slab.h> - -#include <linux/iio/iio.h> -#include "../ring_sw.h" -#include <linux/iio/trigger_consumer.h> -#include "adis16204.h" - -/** - * adis16204_read_ring_data() read data registers which will be placed into ring - * @indio_dev: the IIO device - * @rx: somewhere to pass back the value read - **/ -static int adis16204_read_ring_data(struct iio_dev *indio_dev, u8 *rx) -{ - struct spi_message msg; - struct adis16204_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[ADIS16204_OUTPUTS + 1]; - int ret; - int i; - - mutex_lock(&st->buf_lock); - - spi_message_init(&msg); - - memset(xfers, 0, sizeof(xfers)); - for (i = 0; i <= ADIS16204_OUTPUTS; i++) { - xfers[i].bits_per_word = 8; - xfers[i].cs_change = 1; - xfers[i].len = 2; - xfers[i].delay_usecs = 20; - xfers[i].tx_buf = st->tx + 2 * i; - st->tx[2 * i] - = ADIS16204_READ_REG(ADIS16204_SUPPLY_OUT + 2 * i); - st->tx[2 * i + 1] = 0; - if (i >= 1) - xfers[i].rx_buf = rx + 2 * (i - 1); - spi_message_add_tail(&xfers[i], &msg); - } - - ret = spi_sync(st->us, &msg); - if (ret) - dev_err(&st->us->dev, "problem when burst reading"); - - mutex_unlock(&st->buf_lock); - - return ret; -} - -/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device - * specific to be rolled into the core. - */ -static irqreturn_t adis16204_trigger_handler(int irq, void *p) -{ - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct adis16204_state *st = iio_priv(indio_dev); - int i = 0; - s16 *data; - - data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (data == NULL) { - dev_err(&st->us->dev, "memory alloc failed in ring bh"); - goto done; - } - - if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && - adis16204_read_ring_data(indio_dev, st->rx) >= 0) - for (; i < bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); i++) - data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); - - /* Guaranteed to be aligned with 8 byte boundary */ - if (indio_dev->scan_timestamp) - *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; - - iio_push_to_buffer(indio_dev->buffer, (u8 *)data); - - kfree(data); -done: - iio_trigger_notify_done(indio_dev->trig); - - return IRQ_HANDLED; -} - -void adis16204_unconfigure_ring(struct iio_dev *indio_dev) -{ - iio_dealloc_pollfunc(indio_dev->pollfunc); - iio_sw_rb_free(indio_dev->buffer); -} - -static const struct iio_buffer_setup_ops adis16204_ring_setup_ops = { - .preenable = &iio_sw_buffer_preenable, - .postenable = &iio_triggered_buffer_postenable, - .predisable = &iio_triggered_buffer_predisable, -}; - -int adis16204_configure_ring(struct iio_dev *indio_dev) -{ - int ret = 0; - struct iio_buffer *ring; - - ring = iio_sw_rb_allocate(indio_dev); - if (!ring) { - ret = -ENOMEM; - return ret; - } - indio_dev->buffer = ring; - ring->scan_timestamp = true; - indio_dev->setup_ops = &adis16204_ring_setup_ops; - - indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time, - &adis16204_trigger_handler, - IRQF_ONESHOT, - indio_dev, - "%s_consumer%d", - indio_dev->name, - indio_dev->id); - if (indio_dev->pollfunc == NULL) { - ret = -ENOMEM; - goto error_iio_sw_rb_free; - } - - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; - return 0; - -error_iio_sw_rb_free: - iio_sw_rb_free(indio_dev->buffer); - return ret; -} diff --git a/drivers/staging/iio/accel/adis16204_trigger.c b/drivers/staging/iio/accel/adis16204_trigger.c deleted file mode 100644 index 408a1682368..00000000000 --- a/drivers/staging/iio/accel/adis16204_trigger.c +++ /dev/null @@ -1,73 +0,0 @@ -#include <linux/interrupt.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/export.h> - -#include <linux/iio/iio.h> -#include <linux/iio/trigger.h> -#include "adis16204.h" - -/** - * adis16204_data_rdy_trigger_set_state() set datardy interrupt state - **/ -static int adis16204_data_rdy_trigger_set_state(struct iio_trigger *trig, - bool state) -{ - struct iio_dev *indio_dev = trig->private_data; - - dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); - return adis16204_set_irq(indio_dev, state); -} - -static const struct iio_trigger_ops adis16204_trigger_ops = { - .owner = THIS_MODULE, - .set_trigger_state = &adis16204_data_rdy_trigger_set_state, -}; - -int adis16204_probe_trigger(struct iio_dev *indio_dev) -{ - int ret; - struct adis16204_state *st = iio_priv(indio_dev); - - st->trig = iio_trigger_alloc("adis16204-dev%d", indio_dev->id); - if (st->trig == NULL) { - ret = -ENOMEM; - goto error_ret; - } - - ret = request_irq(st->us->irq, - &iio_trigger_generic_data_rdy_poll, - IRQF_TRIGGER_RISING, - "adis16204", - st->trig); - if (ret) - goto error_free_trig; - - st->trig->dev.parent = &st->us->dev; - st->trig->ops = &adis16204_trigger_ops; - st->trig->private_data = indio_dev; - ret = iio_trigger_register(st->trig); - - /* select default trigger */ - indio_dev->trig = st->trig; - if (ret) - goto error_free_irq; - - return 0; - -error_free_irq: - free_irq(st->us->irq, st->trig); -error_free_trig: - iio_trigger_free(st->trig); -error_ret: - return ret; -} - -void adis16204_remove_trigger(struct iio_dev *indio_dev) -{ - struct adis16204_state *state = iio_priv(indio_dev); - - iio_trigger_unregister(state->trig); - free_irq(state->us->irq, state->trig); - iio_trigger_free(state->trig); -} diff --git a/drivers/staging/iio/accel/adis16209.h b/drivers/staging/iio/accel/adis16209.h index 3c88b86e7b8..ad3945a0629 100644 --- a/drivers/staging/iio/accel/adis16209.h +++ b/drivers/staging/iio/accel/adis16209.h @@ -3,9 +3,6 @@ #define ADIS16209_STARTUP_DELAY 220 /* ms */ -#define ADIS16209_READ_REG(a) a -#define ADIS16209_WRITE_REG(a) ((a) | 0x80) - /* Flash memory write count */ #define ADIS16209_FLASH_CNT 0x00 /* Output, power supply */ @@ -61,8 +58,6 @@ /* Operation, system command register */ #define ADIS16209_GLOB_CMD 0x3E -#define ADIS16209_OUTPUTS 8 - /* MSC_CTRL */ /* Self-test at power-on: 1 = disabled, 0 = enabled */ #define ADIS16209_MSC_CTRL_PWRUP_SELF_TEST (1 << 10) @@ -81,44 +76,23 @@ /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ #define ADIS16209_DIAG_STAT_ALARM1 (1<<8) /* Self-test diagnostic error flag: 1 = error condition, 0 = normal operation */ -#define ADIS16209_DIAG_STAT_SELFTEST_FAIL (1<<5) +#define ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT 5 /* SPI communications failure */ -#define ADIS16209_DIAG_STAT_SPI_FAIL (1<<3) +#define ADIS16209_DIAG_STAT_SPI_FAIL_BIT 3 /* Flash update failure */ -#define ADIS16209_DIAG_STAT_FLASH_UPT (1<<2) +#define ADIS16209_DIAG_STAT_FLASH_UPT_BIT 2 /* Power supply above 3.625 V */ -#define ADIS16209_DIAG_STAT_POWER_HIGH (1<<1) +#define ADIS16209_DIAG_STAT_POWER_HIGH_BIT 1 /* Power supply below 3.15 V */ -#define ADIS16209_DIAG_STAT_POWER_LOW (1<<0) +#define ADIS16209_DIAG_STAT_POWER_LOW_BIT 0 /* GLOB_CMD */ #define ADIS16209_GLOB_CMD_SW_RESET (1<<7) #define ADIS16209_GLOB_CMD_CLEAR_STAT (1<<4) #define ADIS16209_GLOB_CMD_FACTORY_CAL (1<<1) -#define ADIS16209_MAX_TX 24 -#define ADIS16209_MAX_RX 24 - #define ADIS16209_ERROR_ACTIVE (1<<14) -/** - * struct adis16209_state - device instance specific data - * @us: actual spi_device - * @trig: data ready trigger registered with iio - * @tx: transmit buffer - * @rx: receive buffer - * @buf_lock: mutex to protect tx and rx - **/ -struct adis16209_state { - struct spi_device *us; - struct iio_trigger *trig; - struct mutex buf_lock; - u8 tx[ADIS16209_MAX_TX] ____cacheline_aligned; - u8 rx[ADIS16209_MAX_RX]; -}; - -int adis16209_set_irq(struct iio_dev *indio_dev, bool enable); - #define ADIS16209_SCAN_SUPPLY 0 #define ADIS16209_SCAN_ACC_X 1 #define ADIS16209_SCAN_ACC_Y 2 @@ -128,45 +102,4 @@ int adis16209_set_irq(struct iio_dev *indio_dev, bool enable); #define ADIS16209_SCAN_INCLI_Y 6 #define ADIS16209_SCAN_ROT 7 -#ifdef CONFIG_IIO_BUFFER - -void adis16209_remove_trigger(struct iio_dev *indio_dev); -int adis16209_probe_trigger(struct iio_dev *indio_dev); - -ssize_t adis16209_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf); - -int adis16209_configure_ring(struct iio_dev *indio_dev); -void adis16209_unconfigure_ring(struct iio_dev *indio_dev); - -#else /* CONFIG_IIO_BUFFER */ - -static inline void adis16209_remove_trigger(struct iio_dev *indio_dev) -{ -} - -static inline int adis16209_probe_trigger(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline ssize_t -adis16209_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return 0; -} - -static int adis16209_configure_ring(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline void adis16209_unconfigure_ring(struct iio_dev *indio_dev) -{ -} - -#endif /* CONFIG_IIO_BUFFER */ #endif /* SPI_ADIS16209_H_ */ diff --git a/drivers/staging/iio/accel/adis16209_core.c b/drivers/staging/iio/accel/adis16209_core.c index 7ee974b45d7..69c50ee44ce 100644 --- a/drivers/staging/iio/accel/adis16209_core.c +++ b/drivers/staging/iio/accel/adis16209_core.c @@ -19,262 +19,19 @@ #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16209.h" -#define DRIVER_NAME "adis16209" - -/** - * adis16209_spi_write_reg_8() - write single byte to a register - * @indio_dev: iio device associated with actual device - * @reg_address: the address of the register to be written - * @val: the value to write - **/ -static int adis16209_spi_write_reg_8(struct iio_dev *indio_dev, - u8 reg_address, - u8 val) -{ - int ret; - struct adis16209_state *st = iio_priv(indio_dev); - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16209_WRITE_REG(reg_address); - st->tx[1] = val; - - ret = spi_write(st->us, st->tx, 2); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16209_spi_write_reg_16() - write 2 bytes to a pair of registers - * @indio_dev: iio device associated actual device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: value to be written - **/ -static int adis16209_spi_write_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 value) -{ - int ret; - struct spi_message msg; - struct adis16209_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 30, - }, { - .tx_buf = st->tx + 2, - .bits_per_word = 8, - .len = 2, - .delay_usecs = 30, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16209_WRITE_REG(lower_reg_address); - st->tx[1] = value & 0xFF; - st->tx[2] = ADIS16209_WRITE_REG(lower_reg_address + 1); - st->tx[3] = (value >> 8) & 0xFF; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16209_spi_read_reg_16() - read 2 bytes from a 16-bit register - * @indio_dev: iio device associated with device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: somewhere to pass back the value read - **/ -static int adis16209_spi_read_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 *val) -{ - struct spi_message msg; - struct adis16209_state *st = iio_priv(indio_dev); - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 30, - }, { - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 2, - .delay_usecs = 30, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16209_READ_REG(lower_reg_address); - st->tx[1] = 0; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, - "problem when reading 16 bit register 0x%02X", - lower_reg_address); - goto error_ret; - } - *val = (st->rx[0] << 8) | st->rx[1]; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -static int adis16209_reset(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16209_spi_write_reg_8(indio_dev, - ADIS16209_GLOB_CMD, - ADIS16209_GLOB_CMD_SW_RESET); - if (ret) - dev_err(&indio_dev->dev, "problem resetting device"); - - return ret; -} - -int adis16209_set_irq(struct iio_dev *indio_dev, bool enable) -{ - int ret = 0; - u16 msc; - - ret = adis16209_spi_read_reg_16(indio_dev, ADIS16209_MSC_CTRL, &msc); - if (ret) - goto error_ret; - - msc |= ADIS16209_MSC_CTRL_ACTIVE_HIGH; - msc &= ~ADIS16209_MSC_CTRL_DATA_RDY_DIO2; - if (enable) - msc |= ADIS16209_MSC_CTRL_DATA_RDY_EN; - else - msc &= ~ADIS16209_MSC_CTRL_DATA_RDY_EN; - - ret = adis16209_spi_write_reg_16(indio_dev, ADIS16209_MSC_CTRL, msc); - -error_ret: - return ret; -} - -static int adis16209_check_status(struct iio_dev *indio_dev) -{ - u16 status; - int ret; - - ret = adis16209_spi_read_reg_16(indio_dev, - ADIS16209_DIAG_STAT, &status); - if (ret < 0) { - dev_err(&indio_dev->dev, "Reading status failed\n"); - goto error_ret; - } - ret = status & 0x1F; - - if (status & ADIS16209_DIAG_STAT_SELFTEST_FAIL) - dev_err(&indio_dev->dev, "Self test failure\n"); - if (status & ADIS16209_DIAG_STAT_SPI_FAIL) - dev_err(&indio_dev->dev, "SPI failure\n"); - if (status & ADIS16209_DIAG_STAT_FLASH_UPT) - dev_err(&indio_dev->dev, "Flash update failed\n"); - if (status & ADIS16209_DIAG_STAT_POWER_HIGH) - dev_err(&indio_dev->dev, "Power supply above 3.625V\n"); - if (status & ADIS16209_DIAG_STAT_POWER_LOW) - dev_err(&indio_dev->dev, "Power supply below 3.15V\n"); - -error_ret: - return ret; -} - -static int adis16209_self_test(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16209_spi_write_reg_16(indio_dev, - ADIS16209_MSC_CTRL, - ADIS16209_MSC_CTRL_SELF_TEST_EN); - if (ret) { - dev_err(&indio_dev->dev, "problem starting self test"); - goto err_ret; - } - - adis16209_check_status(indio_dev); - -err_ret: - return ret; -} - -static int adis16209_initial_setup(struct iio_dev *indio_dev) -{ - int ret; - - /* Disable IRQ */ - ret = adis16209_set_irq(indio_dev, false); - if (ret) { - dev_err(&indio_dev->dev, "disable irq failed"); - goto err_ret; - } - - /* Do self test */ - ret = adis16209_self_test(indio_dev); - if (ret) { - dev_err(&indio_dev->dev, "self test failure"); - goto err_ret; - } - - /* Read status register to check the result */ - ret = adis16209_check_status(indio_dev); - if (ret) { - adis16209_reset(indio_dev); - dev_err(&indio_dev->dev, "device not playing ball -> reset"); - msleep(ADIS16209_STARTUP_DELAY); - ret = adis16209_check_status(indio_dev); - if (ret) { - dev_err(&indio_dev->dev, "giving up"); - goto err_ret; - } - } - -err_ret: - return ret; -} - -enum adis16209_chan { - in_supply, - temp, - accel_x, - accel_y, - incli_x, - incli_y, - in_aux, - rot, -}; - -static const u8 adis16209_addresses[8][2] = { - [in_supply] = { ADIS16209_SUPPLY_OUT }, - [in_aux] = { ADIS16209_AUX_ADC }, - [accel_x] = { ADIS16209_XACCL_OUT, ADIS16209_XACCL_NULL }, - [accel_y] = { ADIS16209_YACCL_OUT, ADIS16209_YACCL_NULL }, - [incli_x] = { ADIS16209_XINCL_OUT, ADIS16209_XINCL_NULL }, - [incli_y] = { ADIS16209_YINCL_OUT, ADIS16209_YINCL_NULL }, - [rot] = { ADIS16209_ROT_OUT }, - [temp] = { ADIS16209_TEMP_OUT }, +static const u8 adis16209_addresses[8][1] = { + [ADIS16209_SCAN_SUPPLY] = { }, + [ADIS16209_SCAN_AUX_ADC] = { }, + [ADIS16209_SCAN_ACC_X] = { ADIS16209_XACCL_NULL }, + [ADIS16209_SCAN_ACC_Y] = { ADIS16209_YACCL_NULL }, + [ADIS16209_SCAN_INCLI_X] = { ADIS16209_XINCL_NULL }, + [ADIS16209_SCAN_INCLI_Y] = { ADIS16209_YINCL_NULL }, + [ADIS16209_SCAN_ROT] = { }, + [ADIS16209_SCAN_TEMP] = { }, }; static int adis16209_write_raw(struct iio_dev *indio_dev, @@ -283,6 +40,7 @@ static int adis16209_write_raw(struct iio_dev *indio_dev, int val2, long mask) { + struct adis *st = iio_priv(indio_dev); int bits; s16 val16; u8 addr; @@ -295,10 +53,10 @@ static int adis16209_write_raw(struct iio_dev *indio_dev, break; default: return -EINVAL; - }; + } val16 = val & ((1 << bits) - 1); - addr = adis16209_addresses[chan->address][1]; - return adis16209_spi_write_reg_16(indio_dev, addr, val16); + addr = adis16209_addresses[chan->scan_index][0]; + return adis_write_reg_16(st, addr, val16); } return -EINVAL; } @@ -308,6 +66,7 @@ static int adis16209_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { + struct adis *st = iio_priv(indio_dev); int ret; int bits; u8 addr; @@ -315,29 +74,8 @@ static int adis16209_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); - addr = adis16209_addresses[chan->address][0]; - ret = adis16209_spi_read_reg_16(indio_dev, addr, &val16); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - - if (val16 & ADIS16209_ERROR_ACTIVE) { - ret = adis16209_check_status(indio_dev); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - } - val16 = val16 & ((1 << chan->scan_type.realbits) - 1); - if (chan->scan_type.sign == 's') - val16 = (s16)(val16 << - (16 - chan->scan_type.realbits)) >> - (16 - chan->scan_type.realbits); - *val = val16; - mutex_unlock(&indio_dev->mlock); - return IIO_VAL_INT; + return adis_single_conversion(indio_dev, chan, + ADIS16209_ERROR_ACTIVE, val); case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: @@ -374,10 +112,10 @@ static int adis16209_read_raw(struct iio_dev *indio_dev, break; default: return -EINVAL; - }; + } mutex_lock(&indio_dev->mlock); - addr = adis16209_addresses[chan->address][1]; - ret = adis16209_spi_read_reg_16(indio_dev, addr, &val16); + addr = adis16209_addresses[chan->scan_index][0]; + ret = adis_read_reg_16(st, addr, &val16); if (ret) { mutex_unlock(&indio_dev->mlock); return ret; @@ -392,128 +130,56 @@ static int adis16209_read_raw(struct iio_dev *indio_dev, } static const struct iio_chan_spec adis16209_channels[] = { - { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .extend_name = "supply", - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_supply, - .scan_index = ADIS16209_SCAN_SUPPLY, - .scan_type = { - .sign = 'u', - .realbits = 14, - .storagebits = 16, - }, - }, { - .type = IIO_TEMP, - .indexed = 0, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT | - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, - .address = temp, - .scan_index = ADIS16209_SCAN_TEMP, - .scan_type = { - .sign = 'u', - .realbits = 12, - .storagebits = 16, - }, - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, - .address = accel_x, - .scan_index = ADIS16209_SCAN_ACC_X, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, - .address = accel_y, - .scan_index = ADIS16209_SCAN_ACC_Y, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_aux, - .scan_index = ADIS16209_SCAN_AUX_ADC, - .scan_type = { - .sign = 'u', - .realbits = 12, - .storagebits = 16, - }, - }, { - .type = IIO_INCLI, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = incli_x, - .scan_index = ADIS16209_SCAN_INCLI_X, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, { - .type = IIO_INCLI, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = incli_y, - .scan_index = ADIS16209_SCAN_INCLI_Y, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, { - .type = IIO_ROT, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, - IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = rot, - .scan_index = ADIS16209_SCAN_ROT, - .scan_type = { - .sign = 's', - .realbits = 14, - .storagebits = 16, - }, - }, + ADIS_SUPPLY_CHAN(ADIS16209_SUPPLY_OUT, ADIS16209_SCAN_SUPPLY, 14), + ADIS_TEMP_CHAN(ADIS16209_TEMP_OUT, ADIS16209_SCAN_TEMP, 12), + ADIS_ACCEL_CHAN(X, ADIS16209_XACCL_OUT, ADIS16209_SCAN_ACC_X, + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14), + ADIS_ACCEL_CHAN(Y, ADIS16209_YACCL_OUT, ADIS16209_SCAN_ACC_Y, + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14), + ADIS_AUX_ADC_CHAN(ADIS16209_AUX_ADC, ADIS16209_SCAN_AUX_ADC, 12), + ADIS_INCLI_CHAN(X, ADIS16209_XINCL_OUT, ADIS16209_SCAN_INCLI_X, 0, 14), + ADIS_INCLI_CHAN(Y, ADIS16209_YINCL_OUT, ADIS16209_SCAN_INCLI_Y, 0, 14), + ADIS_ROT_CHAN(X, ADIS16209_ROT_OUT, ADIS16209_SCAN_ROT, 0, 14), IIO_CHAN_SOFT_TIMESTAMP(8) }; static const struct iio_info adis16209_info = { .read_raw = &adis16209_read_raw, .write_raw = &adis16209_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module = THIS_MODULE, }; -static int __devinit adis16209_probe(struct spi_device *spi) +static const char * const adis16209_status_error_msgs[] = { + [ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT] = "Self test failure", + [ADIS16209_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure", + [ADIS16209_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed", + [ADIS16209_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", + [ADIS16209_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 3.15V", +}; + +static const struct adis_data adis16209_data = { + .read_delay = 30, + .msc_ctrl_reg = ADIS16209_MSC_CTRL, + .glob_cmd_reg = ADIS16209_GLOB_CMD, + .diag_stat_reg = ADIS16209_DIAG_STAT, + + .self_test_mask = ADIS16209_MSC_CTRL_SELF_TEST_EN, + .startup_delay = ADIS16209_STARTUP_DELAY, + + .status_error_msgs = adis16209_status_error_msgs, + .status_error_mask = BIT(ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT) | + BIT(ADIS16209_DIAG_STAT_SPI_FAIL_BIT) | + BIT(ADIS16209_DIAG_STAT_FLASH_UPT_BIT) | + BIT(ADIS16209_DIAG_STAT_POWER_HIGH_BIT) | + BIT(ADIS16209_DIAG_STAT_POWER_LOW_BIT), +}; + + +static int adis16209_probe(struct spi_device *spi) { int ret; - struct adis16209_state *st; + struct adis *st; struct iio_dev *indio_dev; /* setup the industrialio driver allocated elements */ @@ -525,8 +191,6 @@ static int __devinit adis16209_probe(struct spi_device *spi) st = iio_priv(indio_dev); /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); - st->us = spi; - mutex_init(&st->buf_lock); indio_dev->name = spi->dev.driver->name; indio_dev->dev.parent = &spi->dev; @@ -535,54 +199,38 @@ static int __devinit adis16209_probe(struct spi_device *spi) indio_dev->num_channels = ARRAY_SIZE(adis16209_channels); indio_dev->modes = INDIO_DIRECT_MODE; - ret = adis16209_configure_ring(indio_dev); + ret = adis_init(st, indio_dev, spi, &adis16209_data); + if (ret) + goto error_free_dev; + ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); if (ret) goto error_free_dev; - - ret = iio_buffer_register(indio_dev, - adis16209_channels, - ARRAY_SIZE(adis16209_channels)); - if (ret) { - printk(KERN_ERR "failed to initialize the ring\n"); - goto error_unreg_ring_funcs; - } - - if (spi->irq) { - ret = adis16209_probe_trigger(indio_dev); - if (ret) - goto error_uninitialize_ring; - } /* Get the device into a sane initial state */ - ret = adis16209_initial_setup(indio_dev); + ret = adis_initial_startup(st); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; ret = iio_device_register(indio_dev); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; return 0; -error_remove_trigger: - adis16209_remove_trigger(indio_dev); -error_uninitialize_ring: - iio_buffer_unregister(indio_dev); -error_unreg_ring_funcs: - adis16209_unconfigure_ring(indio_dev); +error_cleanup_buffer_trigger: + adis_cleanup_buffer_and_trigger(st, indio_dev); error_free_dev: iio_device_free(indio_dev); error_ret: return ret; } -static int __devexit adis16209_remove(struct spi_device *spi) +static int adis16209_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct adis *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); - adis16209_remove_trigger(indio_dev); - iio_buffer_unregister(indio_dev); - adis16209_unconfigure_ring(indio_dev); + adis_cleanup_buffer_and_trigger(st, indio_dev); iio_device_free(indio_dev); return 0; @@ -594,7 +242,7 @@ static struct spi_driver adis16209_driver = { .owner = THIS_MODULE, }, .probe = adis16209_probe, - .remove = __devexit_p(adis16209_remove), + .remove = adis16209_remove, }; module_spi_driver(adis16209_driver); diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging/iio/accel/adis16209_ring.c deleted file mode 100644 index f939e29d6c8..00000000000 --- a/drivers/staging/iio/accel/adis16209_ring.c +++ /dev/null @@ -1,134 +0,0 @@ -#include <linux/export.h> -#include <linux/interrupt.h> -#include <linux/mutex.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/slab.h> - -#include <linux/iio/iio.h> -#include "../ring_sw.h" -#include <linux/iio/trigger_consumer.h> -#include "adis16209.h" - -/** - * adis16209_read_ring_data() read data registers which will be placed into ring - * @indio_dev: the IIO device - * @rx: somewhere to pass back the value read - **/ -static int adis16209_read_ring_data(struct iio_dev *indio_dev, u8 *rx) -{ - struct spi_message msg; - struct adis16209_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[ADIS16209_OUTPUTS + 1]; - int ret; - int i; - - mutex_lock(&st->buf_lock); - - spi_message_init(&msg); - - memset(xfers, 0, sizeof(xfers)); - for (i = 0; i <= ADIS16209_OUTPUTS; i++) { - xfers[i].bits_per_word = 8; - xfers[i].cs_change = 1; - xfers[i].len = 2; - xfers[i].delay_usecs = 30; - xfers[i].tx_buf = st->tx + 2 * i; - st->tx[2 * i] - = ADIS16209_READ_REG(ADIS16209_SUPPLY_OUT + 2 * i); - st->tx[2 * i + 1] = 0; - if (i >= 1) - xfers[i].rx_buf = rx + 2 * (i - 1); - spi_message_add_tail(&xfers[i], &msg); - } - - ret = spi_sync(st->us, &msg); - if (ret) - dev_err(&st->us->dev, "problem when burst reading"); - - mutex_unlock(&st->buf_lock); - - return ret; -} - -/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device - * specific to be rolled into the core. - */ -static irqreturn_t adis16209_trigger_handler(int irq, void *p) -{ - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct adis16209_state *st = iio_priv(indio_dev); - int i = 0; - s16 *data; - - data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (data == NULL) { - dev_err(&st->us->dev, "memory alloc failed in ring bh"); - goto done; - } - - if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && - adis16209_read_ring_data(indio_dev, st->rx) >= 0) - for (; i < bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); i++) - data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); - - /* Guaranteed to be aligned with 8 byte boundary */ - if (indio_dev->scan_timestamp) - *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; - - iio_push_to_buffer(indio_dev->buffer, (u8 *)data); - - kfree(data); -done: - iio_trigger_notify_done(indio_dev->trig); - - return IRQ_HANDLED; -} - -void adis16209_unconfigure_ring(struct iio_dev *indio_dev) -{ - iio_dealloc_pollfunc(indio_dev->pollfunc); - iio_sw_rb_free(indio_dev->buffer); -} - -static const struct iio_buffer_setup_ops adis16209_ring_setup_ops = { - .preenable = &iio_sw_buffer_preenable, - .postenable = &iio_triggered_buffer_postenable, - .predisable = &iio_triggered_buffer_predisable, -}; - -int adis16209_configure_ring(struct iio_dev *indio_dev) -{ - int ret = 0; - struct iio_buffer *ring; - - ring = iio_sw_rb_allocate(indio_dev); - if (!ring) { - ret = -ENOMEM; - return ret; - } - indio_dev->buffer = ring; - ring->scan_timestamp = true; - indio_dev->setup_ops = &adis16209_ring_setup_ops; - - indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time, - &adis16209_trigger_handler, - IRQF_ONESHOT, - indio_dev, - "%s_consumer%d", - indio_dev->name, - indio_dev->id); - if (indio_dev->pollfunc == NULL) { - ret = -ENOMEM; - goto error_iio_sw_rb_free; - } - - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; - return 0; - -error_iio_sw_rb_free: - iio_sw_rb_free(indio_dev->buffer); - return ret; -} diff --git a/drivers/staging/iio/accel/adis16209_trigger.c b/drivers/staging/iio/accel/adis16209_trigger.c deleted file mode 100644 index 2ad93dcaf40..00000000000 --- a/drivers/staging/iio/accel/adis16209_trigger.c +++ /dev/null @@ -1,81 +0,0 @@ -#include <linux/interrupt.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/export.h> - -#include <linux/iio/iio.h> -#include <linux/iio/trigger.h> -#include "adis16209.h" - -/** - * adis16209_data_rdy_trig_poll() the event handler for the data rdy trig - **/ -static irqreturn_t adis16209_data_rdy_trig_poll(int irq, void *trig) -{ - iio_trigger_poll(trig, iio_get_time_ns()); - return IRQ_HANDLED; -} - -/** - * adis16209_data_rdy_trigger_set_state() set datardy interrupt state - **/ -static int adis16209_data_rdy_trigger_set_state(struct iio_trigger *trig, - bool state) -{ - struct iio_dev *indio_dev = trig->private_data; - - dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); - return adis16209_set_irq(indio_dev, state); -} - -static const struct iio_trigger_ops adis16209_trigger_ops = { - .owner = THIS_MODULE, - .set_trigger_state = &adis16209_data_rdy_trigger_set_state, -}; - -int adis16209_probe_trigger(struct iio_dev *indio_dev) -{ - int ret; - struct adis16209_state *st = iio_priv(indio_dev); - - st->trig = iio_trigger_alloc("adis16209-dev%d", indio_dev->id); - if (st->trig == NULL) { - ret = -ENOMEM; - goto error_ret; - } - - ret = request_irq(st->us->irq, - adis16209_data_rdy_trig_poll, - IRQF_TRIGGER_RISING, - "adis16209", - st->trig); - if (ret) - goto error_free_trig; - st->trig->dev.parent = &st->us->dev; - st->trig->ops = &adis16209_trigger_ops; - st->trig->private_data = indio_dev; - ret = iio_trigger_register(st->trig); - - /* select default trigger */ - indio_dev->trig = st->trig; - if (ret) - goto error_free_irq; - - return 0; - -error_free_irq: - free_irq(st->us->irq, st->trig); -error_free_trig: - iio_trigger_free(st->trig); -error_ret: - return ret; -} - -void adis16209_remove_trigger(struct iio_dev *indio_dev) -{ - struct adis16209_state *st = iio_priv(indio_dev); - - iio_trigger_unregister(st->trig); - free_irq(st->us->irq, st->trig); - iio_trigger_free(st->trig); -} diff --git a/drivers/staging/iio/accel/adis16220.h b/drivers/staging/iio/accel/adis16220.h index 024313cf5cf..a894ad7fb26 100644 --- a/drivers/staging/iio/accel/adis16220.h +++ b/drivers/staging/iio/accel/adis16220.h @@ -1,10 +1,9 @@ #ifndef SPI_ADIS16220_H_ #define SPI_ADIS16220_H_ -#define ADIS16220_STARTUP_DELAY 220 /* ms */ +#include <linux/iio/imu/adis.h> -#define ADIS16220_READ_REG(a) a -#define ADIS16220_WRITE_REG(a) ((a) | 0x80) +#define ADIS16220_STARTUP_DELAY 220 /* ms */ /* Flash memory write count */ #define ADIS16220_FLASH_CNT 0x00 @@ -102,15 +101,15 @@ #define ADIS16220_DIAG_STAT_FLASH_CHK (1<<6) #define ADIS16220_DIAG_STAT_SELF_TEST (1<<5) /* Capture period violation/interruption */ -#define ADIS16220_DIAG_STAT_VIOLATION (1<<4) +#define ADIS16220_DIAG_STAT_VIOLATION_BIT 4 /* SPI communications failure */ -#define ADIS16220_DIAG_STAT_SPI_FAIL (1<<3) +#define ADIS16220_DIAG_STAT_SPI_FAIL_BIT 3 /* Flash update failure */ -#define ADIS16220_DIAG_STAT_FLASH_UPT (1<<2) +#define ADIS16220_DIAG_STAT_FLASH_UPT_BIT 2 /* Power supply above 3.625 V */ -#define ADIS16220_DIAG_STAT_POWER_HIGH (1<<1) +#define ADIS16220_DIAG_STAT_POWER_HIGH_BIT 1 /* Power supply below 3.15 V */ -#define ADIS16220_DIAG_STAT_POWER_LOW (1<<0) +#define ADIS16220_DIAG_STAT_POWER_LOW_BIT 0 /* GLOB_CMD */ #define ADIS16220_GLOB_CMD_SW_RESET (1<<7) @@ -125,13 +124,14 @@ /** * struct adis16220_state - device instance specific data - * @us: actual spi_device + * @adis: adis device * @tx: transmit buffer * @rx: receive buffer * @buf_lock: mutex to protect tx and rx **/ struct adis16220_state { - struct spi_device *us; + struct adis adis; + struct mutex buf_lock; u8 tx[ADIS16220_MAX_TX] ____cacheline_aligned; u8 rx[ADIS16220_MAX_RX]; diff --git a/drivers/staging/iio/accel/adis16220_core.c b/drivers/staging/iio/accel/adis16220_core.c index eaadd9df3f7..370b01aa767 100644 --- a/drivers/staging/iio/accel/adis16220_core.c +++ b/drivers/staging/iio/accel/adis16220_core.c @@ -20,138 +20,19 @@ #include "adis16220.h" -#define DRIVER_NAME "adis16220" - -/** - * adis16220_spi_write_reg_8() - write single byte to a register - * @indio_dev: iio device associated with child of actual device - * @reg_address: the address of the register to be written - * @val: the value to write - **/ -static int adis16220_spi_write_reg_8(struct iio_dev *indio_dev, - u8 reg_address, - u8 val) -{ - int ret; - struct adis16220_state *st = iio_priv(indio_dev); - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16220_WRITE_REG(reg_address); - st->tx[1] = val; - - ret = spi_write(st->us, st->tx, 2); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16220_spi_write_reg_16() - write 2 bytes to a pair of registers - * @indio_dev: iio device associated with child of actual device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: value to be written - **/ -static int adis16220_spi_write_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 value) -{ - int ret; - struct spi_message msg; - struct adis16220_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 35, - }, { - .tx_buf = st->tx + 2, - .bits_per_word = 8, - .len = 2, - .delay_usecs = 35, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16220_WRITE_REG(lower_reg_address); - st->tx[1] = value & 0xFF; - st->tx[2] = ADIS16220_WRITE_REG(lower_reg_address + 1); - st->tx[3] = (value >> 8) & 0xFF; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16220_spi_read_reg_16() - read 2 bytes from a 16-bit register - * @indio_dev: iio device associated with child of actual device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: somewhere to pass back the value read - **/ -static int adis16220_spi_read_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 *val) -{ - struct spi_message msg; - struct adis16220_state *st = iio_priv(indio_dev); - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 35, - }, { - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 35, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16220_READ_REG(lower_reg_address); - st->tx[1] = 0; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, - "problem when reading 16 bit register 0x%02X", - lower_reg_address); - goto error_ret; - } - *val = (st->rx[0] << 8) | st->rx[1]; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - static ssize_t adis16220_read_16bit(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adis16220_state *st = iio_priv(indio_dev); ssize_t ret; s16 val = 0; /* Take the iio_dev status lock */ mutex_lock(&indio_dev->mlock); - ret = adis16220_spi_read_reg_16(indio_dev, this_attr->address, + ret = adis_read_reg_16(&st->adis, this_attr->address, (u16 *)&val); mutex_unlock(&indio_dev->mlock); if (ret) @@ -166,13 +47,14 @@ static ssize_t adis16220_write_16bit(struct device *dev, { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); + struct adis16220_state *st = iio_priv(indio_dev); int ret; u16 val; ret = kstrtou16(buf, 10, &val); if (ret) goto error_ret; - ret = adis16220_spi_write_reg_16(indio_dev, this_attr->address, val); + ret = adis_write_reg_16(&st->adis, this_attr->address, val); error_ret: return ret ? ret : len; @@ -180,10 +62,11 @@ error_ret: static int adis16220_capture(struct iio_dev *indio_dev) { + struct adis16220_state *st = iio_priv(indio_dev); int ret; - ret = adis16220_spi_write_reg_16(indio_dev, - ADIS16220_GLOB_CMD, - 0xBF08); /* initiates a manual data capture */ + + /* initiates a manual data capture */ + ret = adis_write_reg_16(&st->adis, ADIS16220_GLOB_CMD, 0xBF08); if (ret) dev_err(&indio_dev->dev, "problem beginning capture"); @@ -192,18 +75,6 @@ static int adis16220_capture(struct iio_dev *indio_dev) return ret; } -static int adis16220_reset(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16220_spi_write_reg_8(indio_dev, - ADIS16220_GLOB_CMD, - ADIS16220_GLOB_CMD_SW_RESET); - if (ret) - dev_err(&indio_dev->dev, "problem resetting device"); - - return ret; -} - static ssize_t adis16220_write_capture(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) @@ -224,81 +95,6 @@ static ssize_t adis16220_write_capture(struct device *dev, return len; } -static int adis16220_check_status(struct iio_dev *indio_dev) -{ - u16 status; - int ret; - - ret = adis16220_spi_read_reg_16(indio_dev, ADIS16220_DIAG_STAT, - &status); - - if (ret < 0) { - dev_err(&indio_dev->dev, "Reading status failed\n"); - goto error_ret; - } - ret = status & 0x7F; - - if (status & ADIS16220_DIAG_STAT_VIOLATION) - dev_err(&indio_dev->dev, - "Capture period violation/interruption\n"); - if (status & ADIS16220_DIAG_STAT_SPI_FAIL) - dev_err(&indio_dev->dev, "SPI failure\n"); - if (status & ADIS16220_DIAG_STAT_FLASH_UPT) - dev_err(&indio_dev->dev, "Flash update failed\n"); - if (status & ADIS16220_DIAG_STAT_POWER_HIGH) - dev_err(&indio_dev->dev, "Power supply above 3.625V\n"); - if (status & ADIS16220_DIAG_STAT_POWER_LOW) - dev_err(&indio_dev->dev, "Power supply below 3.15V\n"); - -error_ret: - return ret; -} - -static int adis16220_self_test(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16220_spi_write_reg_16(indio_dev, - ADIS16220_MSC_CTRL, - ADIS16220_MSC_CTRL_SELF_TEST_EN); - if (ret) { - dev_err(&indio_dev->dev, "problem starting self test"); - goto err_ret; - } - - adis16220_check_status(indio_dev); - -err_ret: - return ret; -} - -static int adis16220_initial_setup(struct iio_dev *indio_dev) -{ - int ret; - - /* Do self test */ - ret = adis16220_self_test(indio_dev); - if (ret) { - dev_err(&indio_dev->dev, "self test failure"); - goto err_ret; - } - - /* Read status register to check the result */ - ret = adis16220_check_status(indio_dev); - if (ret) { - adis16220_reset(indio_dev); - dev_err(&indio_dev->dev, "device not playing ball -> reset"); - msleep(ADIS16220_STARTUP_DELAY); - ret = adis16220_check_status(indio_dev); - if (ret) { - dev_err(&indio_dev->dev, "giving up"); - goto err_ret; - } - } - -err_ret: - return ret; -} - static ssize_t adis16220_capture_buffer_read(struct iio_dev *indio_dev, char *buf, loff_t off, @@ -335,7 +131,7 @@ static ssize_t adis16220_capture_buffer_read(struct iio_dev *indio_dev, count = ADIS16220_CAPTURE_SIZE - off; /* write the begin position of capture buffer */ - ret = adis16220_spi_write_reg_16(indio_dev, + ret = adis_write_reg_16(&st->adis, ADIS16220_CAPT_PNTR, off > 1); if (ret) @@ -344,8 +140,9 @@ static ssize_t adis16220_capture_buffer_read(struct iio_dev *indio_dev, /* read count/2 values from capture buffer */ mutex_lock(&st->buf_lock); + for (i = 0; i < count; i += 2) { - st->tx[i] = ADIS16220_READ_REG(addr); + st->tx[i] = ADIS_READ_REG(addr); st->tx[i + 1] = 0; } xfers[1].len = count; @@ -353,7 +150,7 @@ static ssize_t adis16220_capture_buffer_read(struct iio_dev *indio_dev, spi_message_init(&msg); spi_message_add_tail(&xfers[0], &msg); spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); + ret = spi_sync(st->adis.spi, &msg); if (ret) { mutex_unlock(&st->buf_lock); @@ -474,6 +271,8 @@ static int adis16220_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { + struct adis16220_state *st = iio_priv(indio_dev); + const struct adis16220_address_spec *addr; int ret = -EINVAL; int addrind = 0; u16 uval; @@ -518,28 +317,21 @@ static int adis16220_read_raw(struct iio_dev *indio_dev, default: return -EINVAL; } - if (adis16220_addresses[chan->address][addrind].sign) { - ret = adis16220_spi_read_reg_16(indio_dev, - adis16220_addresses[chan - ->address] - [addrind].addr, - &sval); + addr = &adis16220_addresses[chan->address][addrind]; + if (addr->sign) { + ret = adis_read_reg_16(&st->adis, addr->addr, &sval); if (ret) return ret; - bits = adis16220_addresses[chan->address][addrind].bits; + bits = addr->bits; sval &= (1 << bits) - 1; sval = (s16)(sval << (16 - bits)) >> (16 - bits); *val = sval; return IIO_VAL_INT; } else { - ret = adis16220_spi_read_reg_16(indio_dev, - adis16220_addresses[chan - ->address] - [addrind].addr, - &uval); + ret = adis_read_reg_16(&st->adis, addr->addr, &uval); if (ret) return ret; - bits = adis16220_addresses[chan->address][addrind].bits; + bits = addr->bits; uval &= (1 << bits) - 1; *val = uval; return IIO_VAL_INT; @@ -603,7 +395,33 @@ static const struct iio_info adis16220_info = { .read_raw = &adis16220_read_raw, }; -static int __devinit adis16220_probe(struct spi_device *spi) +static const char * const adis16220_status_error_msgs[] = { + [ADIS16220_DIAG_STAT_VIOLATION_BIT] = "Capture period violation/interruption", + [ADIS16220_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure", + [ADIS16220_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed", + [ADIS16220_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", + [ADIS16220_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 3.15V", +}; + +static const struct adis_data adis16220_data = { + .read_delay = 35, + .write_delay = 35, + .msc_ctrl_reg = ADIS16220_MSC_CTRL, + .glob_cmd_reg = ADIS16220_GLOB_CMD, + .diag_stat_reg = ADIS16220_DIAG_STAT, + + .self_test_mask = ADIS16220_MSC_CTRL_SELF_TEST_EN, + .startup_delay = ADIS16220_STARTUP_DELAY, + + .status_error_msgs = adis16220_status_error_msgs, + .status_error_mask = BIT(ADIS16220_DIAG_STAT_VIOLATION_BIT) | + BIT(ADIS16220_DIAG_STAT_SPI_FAIL_BIT) | + BIT(ADIS16220_DIAG_STAT_FLASH_UPT_BIT) | + BIT(ADIS16220_DIAG_STAT_POWER_HIGH_BIT) | + BIT(ADIS16220_DIAG_STAT_POWER_LOW_BIT), +}; + +static int adis16220_probe(struct spi_device *spi) { int ret; struct adis16220_state *st; @@ -620,9 +438,6 @@ static int __devinit adis16220_probe(struct spi_device *spi) /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); - st->us = spi; - mutex_init(&st->buf_lock); - indio_dev->name = spi->dev.driver->name; indio_dev->dev.parent = &spi->dev; indio_dev->info = &adis16220_info; @@ -646,8 +461,11 @@ static int __devinit adis16220_probe(struct spi_device *spi) if (ret) goto error_rm_adc1_bin; + ret = adis_init(&st->adis, indio_dev, spi, &adis16220_data); + if (ret) + goto error_rm_adc2_bin; /* Get the device into a sane initial state */ - ret = adis16220_initial_setup(indio_dev); + ret = adis_initial_startup(&st->adis); if (ret) goto error_rm_adc2_bin; return 0; @@ -666,7 +484,7 @@ error_ret: return ret; } -static int __devexit adis16220_remove(struct spi_device *spi) +static int adis16220_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); @@ -685,7 +503,7 @@ static struct spi_driver adis16220_driver = { .owner = THIS_MODULE, }, .probe = adis16220_probe, - .remove = __devexit_p(adis16220_remove), + .remove = adis16220_remove, }; module_spi_driver(adis16220_driver); diff --git a/drivers/staging/iio/accel/adis16240.h b/drivers/staging/iio/accel/adis16240.h index 3fabcc0b347..d442d49f51f 100644 --- a/drivers/staging/iio/accel/adis16240.h +++ b/drivers/staging/iio/accel/adis16240.h @@ -3,9 +3,6 @@ #define ADIS16240_STARTUP_DELAY 220 /* ms */ -#define ADIS16240_READ_REG(a) a -#define ADIS16240_WRITE_REG(a) ((a) | 0x80) - /* Flash memory write count */ #define ADIS16240_FLASH_CNT 0x00 /* Output, power supply */ @@ -75,8 +72,6 @@ /* System command */ #define ADIS16240_GLOB_CMD 0x4A -#define ADIS16240_OUTPUTS 6 - /* MSC_CTRL */ /* Enables sum-of-squares output (XYZPEAK_OUT) */ #define ADIS16240_MSC_CTRL_XYZPEAK_OUT_EN (1 << 15) @@ -101,17 +96,17 @@ /* Flash test, checksum flag: 1 = mismatch, 0 = match */ #define ADIS16240_DIAG_STAT_CHKSUM (1<<6) /* Power-on, self-test flag: 1 = failure, 0 = pass */ -#define ADIS16240_DIAG_STAT_PWRON_FAIL (1<<5) +#define ADIS16240_DIAG_STAT_PWRON_FAIL_BIT 5 /* Power-on self-test: 1 = in-progress, 0 = complete */ #define ADIS16240_DIAG_STAT_PWRON_BUSY (1<<4) /* SPI communications failure */ -#define ADIS16240_DIAG_STAT_SPI_FAIL (1<<3) +#define ADIS16240_DIAG_STAT_SPI_FAIL_BIT 3 /* Flash update failure */ -#define ADIS16240_DIAG_STAT_FLASH_UPT (1<<2) +#define ADIS16240_DIAG_STAT_FLASH_UPT_BIT 2 /* Power supply above 3.625 V */ -#define ADIS16240_DIAG_STAT_POWER_HIGH (1<<1) +#define ADIS16240_DIAG_STAT_POWER_HIGH_BIT 1 /* Power supply below 3.15 V */ -#define ADIS16240_DIAG_STAT_POWER_LOW (1<<0) +#define ADIS16240_DIAG_STAT_POWER_LOW_BIT 0 /* GLOB_CMD */ #define ADIS16240_GLOB_CMD_RESUME (1<<8) @@ -120,77 +115,15 @@ #define ADIS16240_ERROR_ACTIVE (1<<14) -#define ADIS16240_MAX_TX 24 -#define ADIS16240_MAX_RX 24 - -/** - * struct adis16240_state - device instance specific data - * @us: actual spi_device - * @trig: data ready trigger registered with iio - * @tx: transmit buffer - * @rx: receive buffer - * @buf_lock: mutex to protect tx and rx - **/ -struct adis16240_state { - struct spi_device *us; - struct iio_trigger *trig; - struct mutex buf_lock; - u8 tx[ADIS16240_MAX_TX] ____cacheline_aligned; - u8 rx[ADIS16240_MAX_RX]; -}; - -int adis16240_set_irq(struct iio_dev *indio_dev, bool enable); - /* At the moment triggers are only used for ring buffer * filling. This may change! */ -#define ADIS16240_SCAN_SUPPLY 0 -#define ADIS16240_SCAN_ACC_X 1 -#define ADIS16240_SCAN_ACC_Y 2 -#define ADIS16240_SCAN_ACC_Z 3 +#define ADIS16240_SCAN_ACC_X 0 +#define ADIS16240_SCAN_ACC_Y 1 +#define ADIS16240_SCAN_ACC_Z 2 +#define ADIS16240_SCAN_SUPPLY 3 #define ADIS16240_SCAN_AUX_ADC 4 #define ADIS16240_SCAN_TEMP 5 -#ifdef CONFIG_IIO_BUFFER -void adis16240_remove_trigger(struct iio_dev *indio_dev); -int adis16240_probe_trigger(struct iio_dev *indio_dev); - -ssize_t adis16240_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf); - - -int adis16240_configure_ring(struct iio_dev *indio_dev); -void adis16240_unconfigure_ring(struct iio_dev *indio_dev); - -#else /* CONFIG_IIO_BUFFER */ - -static inline void adis16240_remove_trigger(struct iio_dev *indio_dev) -{ -} - -static inline int adis16240_probe_trigger(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline ssize_t -adis16240_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return 0; -} - -static int adis16240_configure_ring(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline void adis16240_unconfigure_ring(struct iio_dev *indio_dev) -{ -} - -#endif /* CONFIG_IIO_BUFFER */ #endif /* SPI_ADIS16240_H_ */ diff --git a/drivers/staging/iio/accel/adis16240_core.c b/drivers/staging/iio/accel/adis16240_core.c index 35e093973d5..e97fa0b0233 100644 --- a/drivers/staging/iio/accel/adis16240_core.c +++ b/drivers/staging/iio/accel/adis16240_core.c @@ -22,151 +22,29 @@ #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16240.h" -#define DRIVER_NAME "adis16240" - -static int adis16240_check_status(struct iio_dev *indio_dev); - -/** - * adis16240_spi_write_reg_8() - write single byte to a register - * @indio_dev: iio_dev associated with device - * @reg_address: the address of the register to be written - * @val: the value to write - **/ -static int adis16240_spi_write_reg_8(struct iio_dev *indio_dev, - u8 reg_address, - u8 val) -{ - int ret; - struct adis16240_state *st = iio_priv(indio_dev); - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16240_WRITE_REG(reg_address); - st->tx[1] = val; - - ret = spi_write(st->us, st->tx, 2); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16240_spi_write_reg_16() - write 2 bytes to a pair of registers - * @indio_dev: iio_dev for this device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: value to be written - **/ -static int adis16240_spi_write_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 value) -{ - int ret; - struct spi_message msg; - struct adis16240_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 35, - }, { - .tx_buf = st->tx + 2, - .bits_per_word = 8, - .len = 2, - .delay_usecs = 35, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16240_WRITE_REG(lower_reg_address); - st->tx[1] = value & 0xFF; - st->tx[2] = ADIS16240_WRITE_REG(lower_reg_address + 1); - st->tx[3] = (value >> 8) & 0xFF; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16240_spi_read_reg_16() - read 2 bytes from a 16-bit register - * @indio_dev: iio_dev for this device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: somewhere to pass back the value read - **/ -static int adis16240_spi_read_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 *val) -{ - struct spi_message msg; - struct adis16240_state *st = iio_priv(indio_dev); - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 35, - }, { - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 35, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16240_READ_REG(lower_reg_address); - st->tx[1] = 0; - st->tx[2] = 0; - st->tx[3] = 0; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, - "problem when reading 16 bit register 0x%02X", - lower_reg_address); - goto error_ret; - } - *val = (st->rx[0] << 8) | st->rx[1]; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - static ssize_t adis16240_spi_read_signed(struct device *dev, struct device_attribute *attr, char *buf, unsigned bits) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adis *st = iio_priv(indio_dev); int ret; s16 val = 0; unsigned shift = 16 - bits; struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - ret = adis16240_spi_read_reg_16(indio_dev, + ret = adis_read_reg_16(st, this_attr->address, (u16 *)&val); if (ret) return ret; if (val & ADIS16240_ERROR_ACTIVE) - adis16240_check_status(indio_dev); + adis_check_status(st); val = ((s16)(val << shift) >> shift); return sprintf(buf, "%d\n", val); @@ -187,152 +65,16 @@ static ssize_t adis16240_read_12bit_signed(struct device *dev, return ret; } -static int adis16240_reset(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16240_spi_write_reg_8(indio_dev, - ADIS16240_GLOB_CMD, - ADIS16240_GLOB_CMD_SW_RESET); - if (ret) - dev_err(&indio_dev->dev, "problem resetting device"); - - return ret; -} - -int adis16240_set_irq(struct iio_dev *indio_dev, bool enable) -{ - int ret = 0; - u16 msc; - - ret = adis16240_spi_read_reg_16(indio_dev, - ADIS16240_MSC_CTRL, &msc); - if (ret) - goto error_ret; - - msc |= ADIS16240_MSC_CTRL_ACTIVE_HIGH; - msc &= ~ADIS16240_MSC_CTRL_DATA_RDY_DIO2; - if (enable) - msc |= ADIS16240_MSC_CTRL_DATA_RDY_EN; - else - msc &= ~ADIS16240_MSC_CTRL_DATA_RDY_EN; - - ret = adis16240_spi_write_reg_16(indio_dev, - ADIS16240_MSC_CTRL, msc); - -error_ret: - return ret; -} - -static int adis16240_self_test(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16240_spi_write_reg_16(indio_dev, - ADIS16240_MSC_CTRL, - ADIS16240_MSC_CTRL_SELF_TEST_EN); - if (ret) { - dev_err(&indio_dev->dev, "problem starting self test"); - goto err_ret; - } - - msleep(ADIS16240_STARTUP_DELAY); - - adis16240_check_status(indio_dev); - -err_ret: - return ret; -} - -static int adis16240_check_status(struct iio_dev *indio_dev) -{ - u16 status; - int ret; - struct device *dev = &indio_dev->dev; - - ret = adis16240_spi_read_reg_16(indio_dev, - ADIS16240_DIAG_STAT, &status); - - if (ret < 0) { - dev_err(dev, "Reading status failed\n"); - goto error_ret; - } - - ret = status & 0x2F; - if (status & ADIS16240_DIAG_STAT_PWRON_FAIL) - dev_err(dev, "Power-on, self-test fail\n"); - if (status & ADIS16240_DIAG_STAT_SPI_FAIL) - dev_err(dev, "SPI failure\n"); - if (status & ADIS16240_DIAG_STAT_FLASH_UPT) - dev_err(dev, "Flash update failed\n"); - if (status & ADIS16240_DIAG_STAT_POWER_HIGH) - dev_err(dev, "Power supply above 3.625V\n"); - if (status & ADIS16240_DIAG_STAT_POWER_LOW) - dev_err(dev, "Power supply below 2.225V\n"); - -error_ret: - return ret; -} - -static int adis16240_initial_setup(struct iio_dev *indio_dev) -{ - int ret; - struct device *dev = &indio_dev->dev; - - /* Disable IRQ */ - ret = adis16240_set_irq(indio_dev, false); - if (ret) { - dev_err(dev, "disable irq failed"); - goto err_ret; - } - - /* Do self test */ - ret = adis16240_self_test(indio_dev); - if (ret) { - dev_err(dev, "self test failure"); - goto err_ret; - } - - /* Read status register to check the result */ - ret = adis16240_check_status(indio_dev); - if (ret) { - adis16240_reset(indio_dev); - dev_err(dev, "device not playing ball -> reset"); - msleep(ADIS16240_STARTUP_DELAY); - ret = adis16240_check_status(indio_dev); - if (ret) { - dev_err(dev, "giving up"); - goto err_ret; - } - } - -err_ret: - return ret; -} - static IIO_DEVICE_ATTR(in_accel_xyz_squared_peak_raw, S_IRUGO, adis16240_read_12bit_signed, NULL, ADIS16240_XYZPEAK_OUT); static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("4096"); -enum adis16240_chan { - in_supply, - in_aux, - accel_x, - accel_y, - accel_z, - temp, -}; - -static const u8 adis16240_addresses[6][3] = { - [in_supply] = { ADIS16240_SUPPLY_OUT }, - [in_aux] = { ADIS16240_AUX_ADC }, - [accel_x] = { ADIS16240_XACCL_OUT, ADIS16240_XACCL_OFF, - ADIS16240_XPEAK_OUT }, - [accel_y] = { ADIS16240_YACCL_OUT, ADIS16240_YACCL_OFF, - ADIS16240_YPEAK_OUT }, - [accel_z] = { ADIS16240_ZACCL_OUT, ADIS16240_ZACCL_OFF, - ADIS16240_ZPEAK_OUT }, - [temp] = { ADIS16240_TEMP_OUT }, +static const u8 adis16240_addresses[][2] = { + [ADIS16240_SCAN_ACC_X] = { ADIS16240_XACCL_OFF, ADIS16240_XPEAK_OUT }, + [ADIS16240_SCAN_ACC_Y] = { ADIS16240_YACCL_OFF, ADIS16240_YPEAK_OUT }, + [ADIS16240_SCAN_ACC_Z] = { ADIS16240_ZACCL_OFF, ADIS16240_ZPEAK_OUT }, }; static int adis16240_read_raw(struct iio_dev *indio_dev, @@ -340,6 +82,7 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { + struct adis *st = iio_priv(indio_dev); int ret; int bits; u8 addr; @@ -347,29 +90,8 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); - addr = adis16240_addresses[chan->address][0]; - ret = adis16240_spi_read_reg_16(indio_dev, addr, &val16); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - - if (val16 & ADIS16240_ERROR_ACTIVE) { - ret = adis16240_check_status(indio_dev); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - } - val16 = val16 & ((1 << chan->scan_type.realbits) - 1); - if (chan->scan_type.sign == 's') - val16 = (s16)(val16 << - (16 - chan->scan_type.realbits)) >> - (16 - chan->scan_type.realbits); - *val = val16; - mutex_unlock(&indio_dev->mlock); - return IIO_VAL_INT; + return adis_single_conversion(indio_dev, chan, + ADIS16240_ERROR_ACTIVE, val); case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: @@ -402,8 +124,8 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_CALIBBIAS: bits = 10; mutex_lock(&indio_dev->mlock); - addr = adis16240_addresses[chan->address][1]; - ret = adis16240_spi_read_reg_16(indio_dev, addr, &val16); + addr = adis16240_addresses[chan->scan_index][0]; + ret = adis_read_reg_16(st, addr, &val16); if (ret) { mutex_unlock(&indio_dev->mlock); return ret; @@ -416,8 +138,8 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_PEAK: bits = 10; mutex_lock(&indio_dev->mlock); - addr = adis16240_addresses[chan->address][2]; - ret = adis16240_spi_read_reg_16(indio_dev, addr, &val16); + addr = adis16240_addresses[chan->scan_index][1]; + ret = adis_read_reg_16(st, addr, &val16); if (ret) { mutex_unlock(&indio_dev->mlock); return ret; @@ -437,104 +159,32 @@ static int adis16240_write_raw(struct iio_dev *indio_dev, int val2, long mask) { + struct adis *st = iio_priv(indio_dev); int bits = 10; s16 val16; u8 addr; switch (mask) { case IIO_CHAN_INFO_CALIBBIAS: val16 = val & ((1 << bits) - 1); - addr = adis16240_addresses[chan->address][1]; - return adis16240_spi_write_reg_16(indio_dev, addr, val16); + addr = adis16240_addresses[chan->scan_index][0]; + return adis_write_reg_16(st, addr, val16); } return -EINVAL; } static const struct iio_chan_spec adis16240_channels[] = { - { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .extend_name = "supply", - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = in_supply, - .scan_index = ADIS16240_SCAN_SUPPLY, - .scan_type = { - .sign = 'u', - .realbits = 10, - .storagebits = 16, - }, - }, { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, - .address = in_aux, - .scan_index = ADIS16240_SCAN_AUX_ADC, - .scan_type = { - .sign = 'u', - .realbits = 10, - .storagebits = 16, - }, - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | + ADIS_SUPPLY_CHAN(ADIS16240_SUPPLY_OUT, ADIS16240_SCAN_SUPPLY, 10), + ADIS_AUX_ADC_CHAN(ADIS16240_AUX_ADC, ADIS16240_SCAN_AUX_ADC, 10), + ADIS_ACCEL_CHAN(X, ADIS16240_XACCL_OUT, ADIS16240_SCAN_ACC_X, IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_PEAK_SEPARATE_BIT, - .address = accel_x, - .scan_index = ADIS16240_SCAN_ACC_X, - .scan_type = { - .sign = 's', - .realbits = 10, - .storagebits = 16, - }, - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | + IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 10), + ADIS_ACCEL_CHAN(Y, ADIS16240_YACCL_OUT, ADIS16240_SCAN_ACC_Y, IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_PEAK_SEPARATE_BIT, - .address = accel_y, - .scan_index = ADIS16240_SCAN_ACC_Y, - .scan_type = { - .sign = 's', - .realbits = 10, - .storagebits = 16, - }, - }, { - .type = IIO_ACCEL, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT | + IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 10), + ADIS_ACCEL_CHAN(Z, ADIS16240_ZACCL_OUT, ADIS16240_SCAN_ACC_Z, IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | - IIO_CHAN_INFO_PEAK_SEPARATE_BIT, - .address = accel_z, - .scan_index = ADIS16240_SCAN_ACC_Z, - .scan_type = { - .sign = 's', - .realbits = 10, - .storagebits = 16, - }, - }, { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = temp, - .scan_index = ADIS16240_SCAN_TEMP, - .scan_type = { - .sign = 'u', - .realbits = 10, - .storagebits = 16, - }, - }, + IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 10), + ADIS_TEMP_CHAN(ADIS16240_TEMP_OUT, ADIS16240_SCAN_TEMP, 10), IIO_CHAN_SOFT_TIMESTAMP(6) }; @@ -552,13 +202,40 @@ static const struct iio_info adis16240_info = { .attrs = &adis16240_attribute_group, .read_raw = &adis16240_read_raw, .write_raw = &adis16240_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module = THIS_MODULE, }; -static int __devinit adis16240_probe(struct spi_device *spi) +static const char * const adis16240_status_error_msgs[] = { + [ADIS16240_DIAG_STAT_PWRON_FAIL_BIT] = "Power on, self-test failed", + [ADIS16240_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure", + [ADIS16240_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed", + [ADIS16240_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", + [ADIS16240_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 2.225V", +}; + +static const struct adis_data adis16240_data = { + .write_delay = 35, + .read_delay = 35, + .msc_ctrl_reg = ADIS16240_MSC_CTRL, + .glob_cmd_reg = ADIS16240_GLOB_CMD, + .diag_stat_reg = ADIS16240_DIAG_STAT, + + .self_test_mask = ADIS16240_MSC_CTRL_SELF_TEST_EN, + .startup_delay = ADIS16240_STARTUP_DELAY, + + .status_error_msgs = adis16240_status_error_msgs, + .status_error_mask = BIT(ADIS16240_DIAG_STAT_PWRON_FAIL_BIT) | + BIT(ADIS16240_DIAG_STAT_SPI_FAIL_BIT) | + BIT(ADIS16240_DIAG_STAT_FLASH_UPT_BIT) | + BIT(ADIS16240_DIAG_STAT_POWER_HIGH_BIT) | + BIT(ADIS16240_DIAG_STAT_POWER_LOW_BIT), +}; + +static int adis16240_probe(struct spi_device *spi) { int ret; - struct adis16240_state *st; + struct adis *st; struct iio_dev *indio_dev; /* setup the industrialio driver allocated elements */ @@ -571,9 +248,6 @@ static int __devinit adis16240_probe(struct spi_device *spi) /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); - st->us = spi; - mutex_init(&st->buf_lock); - indio_dev->name = spi->dev.driver->name; indio_dev->dev.parent = &spi->dev; indio_dev->info = &adis16240_info; @@ -581,54 +255,37 @@ static int __devinit adis16240_probe(struct spi_device *spi) indio_dev->num_channels = ARRAY_SIZE(adis16240_channels); indio_dev->modes = INDIO_DIRECT_MODE; - ret = adis16240_configure_ring(indio_dev); + ret = adis_init(st, indio_dev, spi, &adis16240_data); + if (ret) + goto error_free_dev; + ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); if (ret) goto error_free_dev; - - ret = iio_buffer_register(indio_dev, - adis16240_channels, - ARRAY_SIZE(adis16240_channels)); - if (ret) { - printk(KERN_ERR "failed to initialize the ring\n"); - goto error_unreg_ring_funcs; - } - - if (spi->irq) { - ret = adis16240_probe_trigger(indio_dev); - if (ret) - goto error_uninitialize_ring; - } /* Get the device into a sane initial state */ - ret = adis16240_initial_setup(indio_dev); + ret = adis_initial_startup(st); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; ret = iio_device_register(indio_dev); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; return 0; -error_remove_trigger: - adis16240_remove_trigger(indio_dev); -error_uninitialize_ring: - iio_buffer_unregister(indio_dev); -error_unreg_ring_funcs: - adis16240_unconfigure_ring(indio_dev); +error_cleanup_buffer_trigger: + adis_cleanup_buffer_and_trigger(st, indio_dev); error_free_dev: iio_device_free(indio_dev); error_ret: return ret; } -static int __devexit adis16240_remove(struct spi_device *spi) +static int adis16240_remove(struct spi_device *spi) { - struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct adis *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); - adis16240_remove_trigger(indio_dev); - iio_buffer_unregister(indio_dev); - adis16240_unconfigure_ring(indio_dev); + adis_cleanup_buffer_and_trigger(st, indio_dev); iio_device_free(indio_dev); return 0; @@ -640,7 +297,7 @@ static struct spi_driver adis16240_driver = { .owner = THIS_MODULE, }, .probe = adis16240_probe, - .remove = __devexit_p(adis16240_remove), + .remove = adis16240_remove, }; module_spi_driver(adis16240_driver); diff --git a/drivers/staging/iio/accel/adis16240_ring.c b/drivers/staging/iio/accel/adis16240_ring.c deleted file mode 100644 index caff8e25e0a..00000000000 --- a/drivers/staging/iio/accel/adis16240_ring.c +++ /dev/null @@ -1,132 +0,0 @@ -#include <linux/export.h> -#include <linux/interrupt.h> -#include <linux/mutex.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/slab.h> - -#include <linux/iio/iio.h> -#include "../ring_sw.h" -#include <linux/iio/trigger_consumer.h> -#include "adis16240.h" - -/** - * adis16240_read_ring_data() read data registers which will be placed into ring - * @indio_dev: the IIO device - * @rx: somewhere to pass back the value read - **/ -static int adis16240_read_ring_data(struct iio_dev *indio_dev, u8 *rx) -{ - struct spi_message msg; - struct adis16240_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[ADIS16240_OUTPUTS + 1]; - int ret; - int i; - - mutex_lock(&st->buf_lock); - - spi_message_init(&msg); - - memset(xfers, 0, sizeof(xfers)); - for (i = 0; i <= ADIS16240_OUTPUTS; i++) { - xfers[i].bits_per_word = 8; - xfers[i].cs_change = 1; - xfers[i].len = 2; - xfers[i].delay_usecs = 30; - xfers[i].tx_buf = st->tx + 2 * i; - st->tx[2 * i] - = ADIS16240_READ_REG(ADIS16240_SUPPLY_OUT + 2 * i); - st->tx[2 * i + 1] = 0; - if (i >= 1) - xfers[i].rx_buf = rx + 2 * (i - 1); - spi_message_add_tail(&xfers[i], &msg); - } - - ret = spi_sync(st->us, &msg); - if (ret) - dev_err(&st->us->dev, "problem when burst reading"); - - mutex_unlock(&st->buf_lock); - - return ret; -} - -static irqreturn_t adis16240_trigger_handler(int irq, void *p) -{ - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct adis16240_state *st = iio_priv(indio_dev); - - int i = 0; - s16 *data; - - data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (data == NULL) { - dev_err(&st->us->dev, "memory alloc failed in ring bh"); - goto done; - } - - if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && - adis16240_read_ring_data(indio_dev, st->rx) >= 0) - for (; i < bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); i++) - data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); - - /* Guaranteed to be aligned with 8 byte boundary */ - if (indio_dev->scan_timestamp) - *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; - - iio_push_to_buffer(indio_dev->buffer, (u8 *)data); - - kfree(data); -done: - iio_trigger_notify_done(indio_dev->trig); - - return IRQ_HANDLED; -} - -void adis16240_unconfigure_ring(struct iio_dev *indio_dev) -{ - iio_dealloc_pollfunc(indio_dev->pollfunc); - iio_sw_rb_free(indio_dev->buffer); -} - -static const struct iio_buffer_setup_ops adis16240_ring_setup_ops = { - .preenable = &iio_sw_buffer_preenable, - .postenable = &iio_triggered_buffer_postenable, - .predisable = &iio_triggered_buffer_predisable, -}; - -int adis16240_configure_ring(struct iio_dev *indio_dev) -{ - int ret = 0; - struct iio_buffer *ring; - - ring = iio_sw_rb_allocate(indio_dev); - if (!ring) { - ret = -ENOMEM; - return ret; - } - indio_dev->buffer = ring; - ring->scan_timestamp = true; - indio_dev->setup_ops = &adis16240_ring_setup_ops; - - indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time, - &adis16240_trigger_handler, - IRQF_ONESHOT, - indio_dev, - "%s_consumer%d", - indio_dev->name, - indio_dev->id); - if (indio_dev->pollfunc == NULL) { - ret = -ENOMEM; - goto error_iio_sw_rb_free; - } - - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; - return 0; - -error_iio_sw_rb_free: - iio_sw_rb_free(indio_dev->buffer); - return ret; -} diff --git a/drivers/staging/iio/accel/adis16240_trigger.c b/drivers/staging/iio/accel/adis16240_trigger.c deleted file mode 100644 index fa90a22b143..00000000000 --- a/drivers/staging/iio/accel/adis16240_trigger.c +++ /dev/null @@ -1,82 +0,0 @@ -#include <linux/interrupt.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/export.h> - -#include <linux/iio/iio.h> -#include <linux/iio/trigger.h> -#include "adis16240.h" - -/** - * adis16240_data_rdy_trig_poll() the event handler for the data rdy trig - **/ -static irqreturn_t adis16240_data_rdy_trig_poll(int irq, void *trig) -{ - iio_trigger_poll(trig, iio_get_time_ns()); - return IRQ_HANDLED; -} - -/** - * adis16240_data_rdy_trigger_set_state() set datardy interrupt state - **/ -static int adis16240_data_rdy_trigger_set_state(struct iio_trigger *trig, - bool state) -{ - struct iio_dev *indio_dev = trig->private_data; - - dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); - return adis16240_set_irq(indio_dev, state); -} - -static const struct iio_trigger_ops adis16240_trigger_ops = { - .owner = THIS_MODULE, - .set_trigger_state = &adis16240_data_rdy_trigger_set_state, -}; - -int adis16240_probe_trigger(struct iio_dev *indio_dev) -{ - int ret; - struct adis16240_state *st = iio_priv(indio_dev); - - st->trig = iio_trigger_alloc("adis16240-dev%d", indio_dev->id); - if (st->trig == NULL) { - ret = -ENOMEM; - goto error_ret; - } - - ret = request_irq(st->us->irq, - adis16240_data_rdy_trig_poll, - IRQF_TRIGGER_RISING, - "adis16240", - st->trig); - if (ret) - goto error_free_trig; - - st->trig->dev.parent = &st->us->dev; - st->trig->ops = &adis16240_trigger_ops; - st->trig->private_data = indio_dev; - ret = iio_trigger_register(st->trig); - - /* select default trigger */ - indio_dev->trig = st->trig; - if (ret) - goto error_free_irq; - - return 0; - -error_free_irq: - free_irq(st->us->irq, st->trig); -error_free_trig: - iio_trigger_free(st->trig); -error_ret: - return ret; -} - -void adis16240_remove_trigger(struct iio_dev *indio_dev) -{ - struct adis16240_state *st = iio_priv(indio_dev); - - iio_trigger_unregister(st->trig); - free_irq(st->us->irq, st->trig); - iio_trigger_free(st->trig); -} diff --git a/drivers/staging/iio/accel/kxsd9.c b/drivers/staging/iio/accel/kxsd9.c index fdd5fbded66..318331f08d9 100644 --- a/drivers/staging/iio/accel/kxsd9.c +++ b/drivers/staging/iio/accel/kxsd9.c @@ -171,7 +171,7 @@ static int kxsd9_read_raw(struct iio_dev *indio_dev, *val2 = kxsd9_micro_scales[ret & KXSD9_FS_MASK]; ret = IIO_VAL_INT_PLUS_MICRO; break; - }; + } error_ret: return ret; @@ -200,7 +200,7 @@ static const struct attribute_group kxsd9_attribute_group = { .attrs = kxsd9_attributes, }; -static int __devinit kxsd9_power_up(struct kxsd9_state *st) +static int kxsd9_power_up(struct kxsd9_state *st) { int ret; @@ -222,7 +222,7 @@ static const struct iio_info kxsd9_info = { .driver_module = THIS_MODULE, }; -static int __devinit kxsd9_probe(struct spi_device *spi) +static int kxsd9_probe(struct spi_device *spi) { struct iio_dev *indio_dev; struct kxsd9_state *st; @@ -261,7 +261,7 @@ error_ret: return ret; } -static int __devexit kxsd9_remove(struct spi_device *spi) +static int kxsd9_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -281,7 +281,7 @@ static struct spi_driver kxsd9_driver = { .owner = THIS_MODULE, }, .probe = kxsd9_probe, - .remove = __devexit_p(kxsd9_remove), + .remove = kxsd9_remove, .id_table = kxsd9_id, }; module_spi_driver(kxsd9_driver); diff --git a/drivers/staging/iio/accel/lis3l02dq.h b/drivers/staging/iio/accel/lis3l02dq.h index f9bcd41f718..2bac7221837 100644 --- a/drivers/staging/iio/accel/lis3l02dq.h +++ b/drivers/staging/iio/accel/lis3l02dq.h @@ -158,6 +158,7 @@ struct lis3l02dq_state { struct spi_device *us; struct iio_trigger *trig; struct mutex buf_lock; + int gpio; bool trigger_on; u8 tx[LIS3L02DQ_MAX_RX] ____cacheline_aligned; diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c index 21b0469f8bc..37ed1b8ebb6 100644 --- a/drivers/staging/iio/accel/lis3l02dq_core.c +++ b/drivers/staging/iio/accel/lis3l02dq_core.c @@ -15,6 +15,7 @@ #include <linux/interrupt.h> #include <linux/irq.h> #include <linux/gpio.h> +#include <linux/of_gpio.h> #include <linux/mutex.h> #include <linux/device.h> #include <linux/kernel.h> @@ -674,7 +675,7 @@ static const struct iio_info lis3l02dq_info = { .attrs = &lis3l02dq_attribute_group, }; -static int __devinit lis3l02dq_probe(struct spi_device *spi) +static int lis3l02dq_probe(struct spi_device *spi) { int ret; struct lis3l02dq_state *st; @@ -690,6 +691,7 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi) spi_set_drvdata(spi, indio_dev); st->us = spi; + st->gpio = of_get_gpio(spi->dev.of_node, 0); mutex_init(&st->buf_lock); indio_dev->name = spi->dev.driver->name; indio_dev->dev.parent = &spi->dev; @@ -711,7 +713,7 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi) goto error_unreg_buffer_funcs; } - if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) { + if (spi->irq) { ret = request_threaded_irq(st->us->irq, &lis3l02dq_th, &lis3l02dq_event_handler, @@ -738,10 +740,10 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi) return 0; error_remove_trigger: - if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq))) + if (spi->irq) lis3l02dq_remove_trigger(indio_dev); error_free_interrupt: - if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) + if (spi->irq) free_irq(st->us->irq, indio_dev); error_uninitialize_buffer: iio_buffer_unregister(indio_dev); @@ -780,7 +782,7 @@ err_ret: } /* fixme, confirm ordering in this function */ -static int __devexit lis3l02dq_remove(struct spi_device *spi) +static int lis3l02dq_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); struct lis3l02dq_state *st = iio_priv(indio_dev); @@ -790,7 +792,7 @@ static int __devexit lis3l02dq_remove(struct spi_device *spi) lis3l02dq_disable_all_events(indio_dev); lis3l02dq_stop_device(indio_dev); - if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) + if (spi->irq) free_irq(st->us->irq, indio_dev); lis3l02dq_remove_trigger(indio_dev); @@ -808,7 +810,7 @@ static struct spi_driver lis3l02dq_driver = { .owner = THIS_MODULE, }, .probe = lis3l02dq_probe, - .remove = __devexit_p(lis3l02dq_remove), + .remove = lis3l02dq_remove, }; module_spi_driver(lis3l02dq_driver); diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c index fa4190d9624..bc38651c315 100644 --- a/drivers/staging/iio/accel/lis3l02dq_ring.c +++ b/drivers/staging/iio/accel/lis3l02dq_ring.c @@ -154,7 +154,7 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p) if (indio_dev->scan_timestamp) *(s64 *)((u8 *)data + ALIGN(len, sizeof(s64))) = pf->timestamp; - iio_push_to_buffer(indio_dev->buffer, (u8 *)data); + iio_push_to_buffers(indio_dev, (u8 *)data); kfree(data); done: @@ -237,7 +237,7 @@ static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig, u8 t; __lis3l02dq_write_data_ready_config(indio_dev, state); - if (state == false) { + if (!state) { /* * A possible quirk with the handler is currently worked around * by ensuring outstanding read events are cleared. @@ -263,7 +263,7 @@ static int lis3l02dq_trig_try_reen(struct iio_trigger *trig) /* If gpio still high (or high again) * In theory possible we will need to do this several times */ for (i = 0; i < 5; i++) - if (gpio_get_value(irq_to_gpio(st->us->irq))) + if (gpio_get_value(st->gpio)) lis3l02dq_read_all(indio_dev, NULL); else break; diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c index ffd1697a9db..414d3cad55a 100644 --- a/drivers/staging/iio/accel/sca3000_core.c +++ b/drivers/staging/iio/accel/sca3000_core.c @@ -1139,7 +1139,7 @@ static const struct iio_info sca3000_info_with_temp = { .driver_module = THIS_MODULE, }; -static int __devinit sca3000_probe(struct spi_device *spi) +static int sca3000_probe(struct spi_device *spi) { int ret; struct sca3000_state *st; @@ -1233,7 +1233,7 @@ error_ret: return ret; } -static int __devexit sca3000_remove(struct spi_device *spi) +static int sca3000_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); struct sca3000_state *st = iio_priv(indio_dev); @@ -1265,7 +1265,7 @@ static struct spi_driver sca3000_driver = { .owner = THIS_MODULE, }, .probe = sca3000_probe, - .remove = __devexit_p(sca3000_remove), + .remove = sca3000_remove, .id_table = sca3000_id, }; module_spi_driver(sca3000_driver); diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig index a525143ecbe..fb8c239b0c8 100644 --- a/drivers/staging/iio/adc/Kconfig +++ b/drivers/staging/iio/adc/Kconfig @@ -10,17 +10,6 @@ config AD7291 Say yes here to build support for Analog Devices AD7291 8 Channel ADC with temperature sensor. -config AD7298 - tristate "Analog Devices AD7298 ADC driver" - depends on SPI - select IIO_TRIGGERED_BUFFER if IIO_BUFFER - help - Say yes here to build support for Analog Devices AD7298 - 8 Channel ADC with temperature sensor. - - To compile this driver as a module, choose M here: the - module will be called ad7298. - config AD7606 tristate "Analog Devices AD7606 ADC driver" depends on GPIOLIB @@ -68,19 +57,6 @@ config AD799X_RING_BUFFER Say yes here to include ring buffer support in the AD799X ADC driver. -config AD7887 - tristate "Analog Devices AD7887 ADC driver" - depends on SPI - select IIO_BUFFER - select IIO_TRIGGERED_BUFFER - help - Say yes here to build support for Analog Devices - AD7887 SPI analog to digital converter (ADC). - If unsure, say N (but it's safe to say "Y"). - - To compile this driver as a module, choose M here: the - module will be called ad7887. - config AD7780 tristate "Analog Devices AD7780 and similar ADCs driver" depends on SPI @@ -94,18 +70,6 @@ config AD7780 To compile this driver as a module, choose M here: the module will be called ad7780. -config AD7793 - tristate "Analog Devices AD7793 and similar ADCs driver" - depends on SPI - select AD_SIGMA_DELTA - help - Say yes here to build support for Analog Devices AD7785, AD7792, AD7793, - AD7794 and AD7795 SPI analog to digital converters (ADC). - If unsure, say N (but it's safe to say "Y"). - - To compile this driver as a module, choose M here: the - module will be called AD7793. - config AD7816 tristate "Analog Devices AD7816/7/8 temperature sensor and ADC driver" depends on SPI @@ -126,18 +90,11 @@ config AD7192 To compile this driver as a module, choose M here: the module will be called ad7192. -config ADT7310 - tristate "Analog Devices ADT7310 temperature sensor driver" - depends on SPI - help - Say yes here to build support for Analog Devices ADT7310 - temperature sensors. - config ADT7410 - tristate "Analog Devices ADT7410 temperature sensor driver" - depends on I2C + tristate "Analog Devices ADT7310/ADT7410 temperature sensor driver" + depends on I2C || SPI_MASTER help - Say yes here to build support for Analog Devices ADT7410 + Say yes here to build support for Analog Devices ADT7310/ADT7410 temperature sensors. config AD7280 @@ -150,30 +107,6 @@ config AD7280 To compile this driver as a module, choose M here: the module will be called ad7280a -config MAX1363 - tristate "Maxim max1363 ADC driver" - depends on I2C - select IIO_TRIGGER if IIO_BUFFER - select MAX1363_RING_BUFFER - help - Say yes here to build support for many Maxim i2c analog to digital - converters (ADC). (max1361, max1362, max1363, max1364, max1036, - max1037, max1038, max1039, max1136, max1136, max1137, max1138, - max1139, max1236, max1237, max11238, max1239, max11600, max11601, - max11602, max11603, max11604, max11605, max11606, max11607, - max11608, max11609, max11610, max11611, max11612, max11613, - max11614, max11615, max11616, max11617, max11644, max11645, - max11646, max11647) Provides direct access via sysfs. - -config MAX1363_RING_BUFFER - bool "Maxim max1363: use ring buffer" - depends on MAX1363 - select IIO_BUFFER - select IIO_SW_RING - help - Say yes here to include ring buffer support in the MAX1363 - ADC driver. - config LPC32XX_ADC tristate "NXP LPC32XX ADC" depends on ARCH_LPC32XX diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile index 62ee02e80cf..d285596272a 100644 --- a/drivers/staging/iio/adc/Makefile +++ b/drivers/staging/iio/adc/Makefile @@ -2,11 +2,6 @@ # Makefile for industrial I/O ADC drivers # -max1363-y := max1363_core.o -max1363-y += max1363_ring.o - -obj-$(CONFIG_MAX1363) += max1363.o - ad7606-y := ad7606_core.o ad7606-$(CONFIG_IIO_BUFFER) += ad7606_ring.o ad7606-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o @@ -17,20 +12,10 @@ ad799x-y := ad799x_core.o ad799x-$(CONFIG_AD799X_RING_BUFFER) += ad799x_ring.o obj-$(CONFIG_AD799X) += ad799x.o -ad7887-y := ad7887_core.o -ad7887-$(CONFIG_IIO_BUFFER) += ad7887_ring.o -obj-$(CONFIG_AD7887) += ad7887.o - -ad7298-y := ad7298_core.o -ad7298-$(CONFIG_IIO_BUFFER) += ad7298_ring.o -obj-$(CONFIG_AD7298) += ad7298.o - obj-$(CONFIG_AD7291) += ad7291.o obj-$(CONFIG_AD7780) += ad7780.o -obj-$(CONFIG_AD7793) += ad7793.o obj-$(CONFIG_AD7816) += ad7816.o obj-$(CONFIG_AD7192) += ad7192.o -obj-$(CONFIG_ADT7310) += adt7310.o obj-$(CONFIG_ADT7410) += adt7410.o obj-$(CONFIG_AD7280) += ad7280a.o obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index aeaa61d49f5..50470194058 100644 --- a/drivers/staging/iio/adc/ad7192.c +++ b/drivers/staging/iio/adc/ad7192.c @@ -606,7 +606,7 @@ static const struct iio_chan_spec ad7192_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(8), }; -static int __devinit ad7192_probe(struct spi_device *spi) +static int ad7192_probe(struct spi_device *spi) { const struct ad7192_platform_data *pdata = spi->dev.platform_data; struct ad7192_state *st; @@ -686,7 +686,7 @@ error_put_reg: return ret; } -static int __devexit ad7192_remove(struct spi_device *spi) +static int ad7192_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); struct ad7192_state *st = iio_priv(indio_dev); @@ -716,7 +716,7 @@ static struct spi_driver ad7192_driver = { .owner = THIS_MODULE, }, .probe = ad7192_probe, - .remove = __devexit_p(ad7192_remove), + .remove = ad7192_remove, .id_table = ad7192_id, }; module_spi_driver(ad7192_driver); diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index cfc39a70312..fa81a491e79 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -117,7 +117,7 @@ */ #define POLYNOM 0x2F #define POLYNOM_ORDER 8 -#define HIGHBIT 1 << (POLYNOM_ORDER - 1); +#define HIGHBIT (1 << (POLYNOM_ORDER - 1)) struct ad7280_state { struct spi_device *spi; @@ -832,7 +832,7 @@ static const struct ad7280_platform_data ad7793_default_pdata = { .thermistor_term_en = true, }; -static int __devinit ad7280_probe(struct spi_device *spi) +static int ad7280_probe(struct spi_device *spi) { const struct ad7280_platform_data *pdata = spi->dev.platform_data; struct ad7280_state *st; @@ -950,7 +950,7 @@ error_free_device: return ret; } -static int __devexit ad7280_remove(struct spi_device *spi) +static int ad7280_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); struct ad7280_state *st = iio_priv(indio_dev); @@ -981,7 +981,7 @@ static struct spi_driver ad7280_driver = { .owner = THIS_MODULE, }, .probe = ad7280_probe, - .remove = __devexit_p(ad7280_remove), + .remove = ad7280_remove, .id_table = ad7280_id, }; module_spi_driver(ad7280_driver); diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c index 029b39c0ba6..6e58e36d242 100644 --- a/drivers/staging/iio/adc/ad7291.c +++ b/drivers/staging/iio/adc/ad7291.c @@ -580,7 +580,7 @@ static const struct iio_info ad7291_info = { .event_attrs = &ad7291_event_attribute_group, }; -static int __devinit ad7291_probe(struct i2c_client *client, +static int ad7291_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct ad7291_chip_info *chip; @@ -674,7 +674,7 @@ error_ret: return ret; } -static int __devexit ad7291_remove(struct i2c_client *client) +static int ad7291_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); struct ad7291_chip_info *chip = iio_priv(indio_dev); @@ -706,7 +706,7 @@ static struct i2c_driver ad7291_driver = { .name = KBUILD_MODNAME, }, .probe = ad7291_probe, - .remove = __devexit_p(ad7291_remove), + .remove = ad7291_remove, .id_table = ad7291_id, }; module_i2c_driver(ad7291_driver); diff --git a/drivers/staging/iio/adc/ad7298.h b/drivers/staging/iio/adc/ad7298.h deleted file mode 100644 index 18f27872300..00000000000 --- a/drivers/staging/iio/adc/ad7298.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * AD7298 SPI ADC driver - * - * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ - -#ifndef IIO_ADC_AD7298_H_ -#define IIO_ADC_AD7298_H_ - -#define AD7298_WRITE (1 << 15) /* write to the control register */ -#define AD7298_REPEAT (1 << 14) /* repeated conversion enable */ -#define AD7298_CH(x) (1 << (13 - (x))) /* channel select */ -#define AD7298_TSENSE (1 << 5) /* temperature conversion enable */ -#define AD7298_EXTREF (1 << 2) /* external reference enable */ -#define AD7298_TAVG (1 << 1) /* temperature sensor averaging enable */ -#define AD7298_PDD (1 << 0) /* partial power down enable */ - -#define AD7298_MAX_CHAN 8 -#define AD7298_BITS 12 -#define AD7298_STORAGE_BITS 16 -#define AD7298_INTREF_mV 2500 - -#define AD7298_CH_TEMP 9 - -#define RES_MASK(bits) ((1 << (bits)) - 1) - -/* - * TODO: struct ad7298_platform_data needs to go into include/linux/iio - */ - -struct ad7298_platform_data { - /* External Vref voltage applied */ - u16 vref_mv; -}; - -struct ad7298_state { - struct spi_device *spi; - struct regulator *reg; - u16 int_vref_mv; - unsigned ext_ref; - struct spi_transfer ring_xfer[10]; - struct spi_transfer scan_single_xfer[3]; - struct spi_message ring_msg; - struct spi_message scan_single_msg; - /* - * DMA (thus cache coherency maintenance) requires the - * transfer buffers to live in their own cache lines. - */ - unsigned short rx_buf[8] ____cacheline_aligned; - unsigned short tx_buf[2]; -}; - -#ifdef CONFIG_IIO_BUFFER -int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev); -void ad7298_ring_cleanup(struct iio_dev *indio_dev); -int ad7298_update_scan_mode(struct iio_dev *indio_dev, - const unsigned long *active_scan_mask); -#else /* CONFIG_IIO_BUFFER */ - -static inline int -ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline void ad7298_ring_cleanup(struct iio_dev *indio_dev) -{ -} - -#define ad7298_update_scan_mode NULL - -#endif /* CONFIG_IIO_BUFFER */ -#endif /* IIO_ADC_AD7298_H_ */ diff --git a/drivers/staging/iio/adc/ad7298_core.c b/drivers/staging/iio/adc/ad7298_core.c deleted file mode 100644 index 4c75114e7d7..00000000000 --- a/drivers/staging/iio/adc/ad7298_core.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - * AD7298 SPI ADC driver - * - * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ - -#include <linux/device.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/sysfs.h> -#include <linux/spi/spi.h> -#include <linux/regulator/consumer.h> -#include <linux/err.h> -#include <linux/delay.h> -#include <linux/module.h> - -#include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> -#include <linux/iio/buffer.h> - -#include "ad7298.h" - -#define AD7298_V_CHAN(index) \ - { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .channel = index, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT, \ - .address = index, \ - .scan_index = index, \ - .scan_type = { \ - .sign = 'u', \ - .realbits = 12, \ - .storagebits = 16, \ - }, \ - } - -static const struct iio_chan_spec ad7298_channels[] = { - { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, - .address = AD7298_CH_TEMP, - .scan_index = -1, - .scan_type = { - .sign = 's', - .realbits = 32, - .storagebits = 32, - }, - }, - AD7298_V_CHAN(0), - AD7298_V_CHAN(1), - AD7298_V_CHAN(2), - AD7298_V_CHAN(3), - AD7298_V_CHAN(4), - AD7298_V_CHAN(5), - AD7298_V_CHAN(6), - AD7298_V_CHAN(7), - IIO_CHAN_SOFT_TIMESTAMP(8), -}; - -static int ad7298_scan_direct(struct ad7298_state *st, unsigned ch) -{ - int ret; - st->tx_buf[0] = cpu_to_be16(AD7298_WRITE | st->ext_ref | - (AD7298_CH(0) >> ch)); - - ret = spi_sync(st->spi, &st->scan_single_msg); - if (ret) - return ret; - - return be16_to_cpu(st->rx_buf[0]); -} - -static int ad7298_scan_temp(struct ad7298_state *st, int *val) -{ - int tmp, ret; - __be16 buf; - - buf = cpu_to_be16(AD7298_WRITE | AD7298_TSENSE | - AD7298_TAVG | st->ext_ref); - - ret = spi_write(st->spi, (u8 *)&buf, 2); - if (ret) - return ret; - - buf = cpu_to_be16(0); - - ret = spi_write(st->spi, (u8 *)&buf, 2); - if (ret) - return ret; - - usleep_range(101, 1000); /* sleep > 100us */ - - ret = spi_read(st->spi, (u8 *)&buf, 2); - if (ret) - return ret; - - tmp = be16_to_cpu(buf) & RES_MASK(AD7298_BITS); - - /* - * One LSB of the ADC corresponds to 0.25 deg C. - * The temperature reading is in 12-bit twos complement format - */ - - if (tmp & (1 << (AD7298_BITS - 1))) { - tmp = (4096 - tmp) * 250; - tmp -= (2 * tmp); - - } else { - tmp *= 250; /* temperature in milli degrees Celsius */ - } - - *val = tmp; - - return 0; -} - -static int ad7298_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long m) -{ - int ret; - struct ad7298_state *st = iio_priv(indio_dev); - unsigned int scale_uv; - - switch (m) { - case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { - ret = -EBUSY; - } else { - if (chan->address == AD7298_CH_TEMP) - ret = ad7298_scan_temp(st, val); - else - ret = ad7298_scan_direct(st, chan->address); - } - mutex_unlock(&indio_dev->mlock); - - if (ret < 0) - return ret; - - if (chan->address != AD7298_CH_TEMP) - *val = ret & RES_MASK(AD7298_BITS); - - return IIO_VAL_INT; - case IIO_CHAN_INFO_SCALE: - switch (chan->type) { - case IIO_VOLTAGE: - scale_uv = (st->int_vref_mv * 1000) >> AD7298_BITS; - *val = scale_uv / 1000; - *val2 = (scale_uv % 1000) * 1000; - return IIO_VAL_INT_PLUS_MICRO; - case IIO_TEMP: - *val = 1; - *val2 = 0; - return IIO_VAL_INT_PLUS_MICRO; - default: - return -EINVAL; - } - } - return -EINVAL; -} - -static const struct iio_info ad7298_info = { - .read_raw = &ad7298_read_raw, - .update_scan_mode = ad7298_update_scan_mode, - .driver_module = THIS_MODULE, -}; - -static int __devinit ad7298_probe(struct spi_device *spi) -{ - struct ad7298_platform_data *pdata = spi->dev.platform_data; - struct ad7298_state *st; - int ret; - struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); - - if (indio_dev == NULL) - return -ENOMEM; - - st = iio_priv(indio_dev); - - st->reg = regulator_get(&spi->dev, "vcc"); - if (!IS_ERR(st->reg)) { - ret = regulator_enable(st->reg); - if (ret) - goto error_put_reg; - } - - spi_set_drvdata(spi, indio_dev); - - st->spi = spi; - - indio_dev->name = spi_get_device_id(spi)->name; - indio_dev->dev.parent = &spi->dev; - indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = ad7298_channels; - indio_dev->num_channels = ARRAY_SIZE(ad7298_channels); - indio_dev->info = &ad7298_info; - - /* Setup default message */ - - st->scan_single_xfer[0].tx_buf = &st->tx_buf[0]; - st->scan_single_xfer[0].len = 2; - st->scan_single_xfer[0].cs_change = 1; - st->scan_single_xfer[1].tx_buf = &st->tx_buf[1]; - st->scan_single_xfer[1].len = 2; - st->scan_single_xfer[1].cs_change = 1; - st->scan_single_xfer[2].rx_buf = &st->rx_buf[0]; - st->scan_single_xfer[2].len = 2; - - spi_message_init(&st->scan_single_msg); - spi_message_add_tail(&st->scan_single_xfer[0], &st->scan_single_msg); - spi_message_add_tail(&st->scan_single_xfer[1], &st->scan_single_msg); - spi_message_add_tail(&st->scan_single_xfer[2], &st->scan_single_msg); - - if (pdata && pdata->vref_mv) { - st->int_vref_mv = pdata->vref_mv; - st->ext_ref = AD7298_EXTREF; - } else { - st->int_vref_mv = AD7298_INTREF_mV; - } - - ret = ad7298_register_ring_funcs_and_init(indio_dev); - if (ret) - goto error_disable_reg; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_cleanup_ring; - - return 0; - -error_cleanup_ring: - ad7298_ring_cleanup(indio_dev); -error_disable_reg: - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); -error_put_reg: - if (!IS_ERR(st->reg)) - regulator_put(st->reg); - iio_device_free(indio_dev); - - return ret; -} - -static int __devexit ad7298_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7298_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - ad7298_ring_cleanup(indio_dev); - if (!IS_ERR(st->reg)) { - regulator_disable(st->reg); - regulator_put(st->reg); - } - iio_device_free(indio_dev); - - return 0; -} - -static const struct spi_device_id ad7298_id[] = { - {"ad7298", 0}, - {} -}; -MODULE_DEVICE_TABLE(spi, ad7298_id); - -static struct spi_driver ad7298_driver = { - .driver = { - .name = "ad7298", - .owner = THIS_MODULE, - }, - .probe = ad7298_probe, - .remove = __devexit_p(ad7298_remove), - .id_table = ad7298_id, -}; -module_spi_driver(ad7298_driver); - -MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); -MODULE_DESCRIPTION("Analog Devices AD7298 ADC"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/adc/ad7298_ring.c b/drivers/staging/iio/adc/ad7298_ring.c deleted file mode 100644 index c2906a85fed..00000000000 --- a/drivers/staging/iio/adc/ad7298_ring.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * AD7298 SPI ADC driver - * - * Copyright 2011-2012 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ - -#include <linux/interrupt.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/spi/spi.h> - -#include <linux/iio/iio.h> -#include <linux/iio/buffer.h> -#include <linux/iio/trigger_consumer.h> -#include <linux/iio/triggered_buffer.h> - -#include "ad7298.h" - -/** - * ad7298_update_scan_mode() setup the spi transfer buffer for the new scan mask - **/ -int ad7298_update_scan_mode(struct iio_dev *indio_dev, - const unsigned long *active_scan_mask) -{ - struct ad7298_state *st = iio_priv(indio_dev); - int i, m; - unsigned short command; - int scan_count; - - /* Now compute overall size */ - scan_count = bitmap_weight(active_scan_mask, indio_dev->masklength); - - command = AD7298_WRITE | st->ext_ref; - - for (i = 0, m = AD7298_CH(0); i < AD7298_MAX_CHAN; i++, m >>= 1) - if (test_bit(i, active_scan_mask)) - command |= m; - - st->tx_buf[0] = cpu_to_be16(command); - - /* build spi ring message */ - st->ring_xfer[0].tx_buf = &st->tx_buf[0]; - st->ring_xfer[0].len = 2; - st->ring_xfer[0].cs_change = 1; - st->ring_xfer[1].tx_buf = &st->tx_buf[1]; - st->ring_xfer[1].len = 2; - st->ring_xfer[1].cs_change = 1; - - spi_message_init(&st->ring_msg); - spi_message_add_tail(&st->ring_xfer[0], &st->ring_msg); - spi_message_add_tail(&st->ring_xfer[1], &st->ring_msg); - - for (i = 0; i < scan_count; i++) { - st->ring_xfer[i + 2].rx_buf = &st->rx_buf[i]; - st->ring_xfer[i + 2].len = 2; - st->ring_xfer[i + 2].cs_change = 1; - spi_message_add_tail(&st->ring_xfer[i + 2], &st->ring_msg); - } - /* make sure last transfer cs_change is not set */ - st->ring_xfer[i + 1].cs_change = 0; - - return 0; -} - -/** - * ad7298_trigger_handler() bh of trigger launched polling to ring buffer - * - * Currently there is no option in this driver to disable the saving of - * timestamps within the ring. - **/ -static irqreturn_t ad7298_trigger_handler(int irq, void *p) -{ - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct ad7298_state *st = iio_priv(indio_dev); - s64 time_ns = 0; - __u16 buf[16]; - int b_sent, i; - - b_sent = spi_sync(st->spi, &st->ring_msg); - if (b_sent) - goto done; - - if (indio_dev->scan_timestamp) { - time_ns = iio_get_time_ns(); - memcpy((u8 *)buf + indio_dev->scan_bytes - sizeof(s64), - &time_ns, sizeof(time_ns)); - } - - for (i = 0; i < bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); i++) - buf[i] = be16_to_cpu(st->rx_buf[i]); - - iio_push_to_buffer(indio_dev->buffer, (u8 *)buf); - -done: - iio_trigger_notify_done(indio_dev->trig); - - return IRQ_HANDLED; -} - -int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev) -{ - return iio_triggered_buffer_setup(indio_dev, NULL, - &ad7298_trigger_handler, NULL); -} - -void ad7298_ring_cleanup(struct iio_dev *indio_dev) -{ - iio_triggered_buffer_cleanup(indio_dev); -} diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c index a53faafec07..58cfddea963 100644 --- a/drivers/staging/iio/adc/ad7606_par.c +++ b/drivers/staging/iio/adc/ad7606_par.c @@ -47,7 +47,7 @@ static const struct ad7606_bus_ops ad7606_par8_bops = { .read_block = ad7606_par8_read_block, }; -static int __devinit ad7606_par_probe(struct platform_device *pdev) +static int ad7606_par_probe(struct platform_device *pdev) { struct resource *res; struct iio_dev *indio_dev; @@ -100,7 +100,7 @@ out1: return ret; } -static int __devexit ad7606_par_remove(struct platform_device *pdev) +static int ad7606_par_remove(struct platform_device *pdev) { struct iio_dev *indio_dev = platform_get_drvdata(pdev); struct resource *res; @@ -164,7 +164,7 @@ MODULE_DEVICE_TABLE(platform, ad7606_driver_ids); static struct platform_driver ad7606_driver = { .probe = ad7606_par_probe, - .remove = __devexit_p(ad7606_par_remove), + .remove = ad7606_par_remove, .id_table = ad7606_driver_ids, .driver = { .name = "ad7606", diff --git a/drivers/staging/iio/adc/ad7606_ring.c b/drivers/staging/iio/adc/ad7606_ring.c index ba04d0ffd4f..2b25cb07fe4 100644 --- a/drivers/staging/iio/adc/ad7606_ring.c +++ b/drivers/staging/iio/adc/ad7606_ring.c @@ -83,7 +83,7 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s) if (indio_dev->scan_timestamp) *((s64 *)(buf + indio_dev->scan_bytes - sizeof(s64))) = time_ns; - iio_push_to_buffer(indio_dev->buffer, buf); + iio_push_to_buffers(indio_dev, buf); done: gpio_set_value(st->pdata->gpio_convst, 0); iio_trigger_notify_done(indio_dev->trig); diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c index 099d347da52..6a8ecd73a1a 100644 --- a/drivers/staging/iio/adc/ad7606_spi.c +++ b/drivers/staging/iio/adc/ad7606_spi.c @@ -39,7 +39,7 @@ static const struct ad7606_bus_ops ad7606_spi_bops = { .read_block = ad7606_spi_read_block, }; -static int __devinit ad7606_spi_probe(struct spi_device *spi) +static int ad7606_spi_probe(struct spi_device *spi) { struct iio_dev *indio_dev; @@ -55,7 +55,7 @@ static int __devinit ad7606_spi_probe(struct spi_device *spi) return 0; } -static int __devexit ad7606_spi_remove(struct spi_device *spi) +static int ad7606_spi_remove(struct spi_device *spi) { struct iio_dev *indio_dev = dev_get_drvdata(&spi->dev); @@ -106,7 +106,7 @@ static struct spi_driver ad7606_driver = { .pm = AD7606_SPI_PM_OPS, }, .probe = ad7606_spi_probe, - .remove = __devexit_p(ad7606_spi_remove), + .remove = ad7606_spi_remove, .id_table = ad7606_id, }; module_spi_driver(ad7606_driver); diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index 0a1328b8657..e1f88603d7e 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -164,7 +164,7 @@ static const struct iio_info ad7780_info = { .driver_module = THIS_MODULE, }; -static int __devinit ad7780_probe(struct spi_device *spi) +static int ad7780_probe(struct spi_device *spi) { struct ad7780_platform_data *pdata = spi->dev.platform_data; struct ad7780_state *st; @@ -248,7 +248,7 @@ error_put_reg: return ret; } -static int __devexit ad7780_remove(struct spi_device *spi) +static int ad7780_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); struct ad7780_state *st = iio_priv(indio_dev); @@ -283,7 +283,7 @@ static struct spi_driver ad7780_driver = { .owner = THIS_MODULE, }, .probe = ad7780_probe, - .remove = __devexit_p(ad7780_remove), + .remove = ad7780_remove, .id_table = ad7780_id, }; module_spi_driver(ad7780_driver); diff --git a/drivers/staging/iio/adc/ad7793.c b/drivers/staging/iio/adc/ad7793.c deleted file mode 100644 index 691a7be6f5c..00000000000 --- a/drivers/staging/iio/adc/ad7793.c +++ /dev/null @@ -1,566 +0,0 @@ -/* - * AD7785/AD7792/AD7793/AD7794/AD7795 SPI ADC driver - * - * Copyright 2011-2012 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ - -#include <linux/interrupt.h> -#include <linux/device.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/sysfs.h> -#include <linux/spi/spi.h> -#include <linux/regulator/consumer.h> -#include <linux/err.h> -#include <linux/sched.h> -#include <linux/delay.h> -#include <linux/module.h> - -#include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> -#include <linux/iio/buffer.h> -#include <linux/iio/trigger.h> -#include <linux/iio/trigger_consumer.h> -#include <linux/iio/triggered_buffer.h> -#include <linux/iio/adc/ad_sigma_delta.h> - -#include "ad7793.h" - -/* NOTE: - * The AD7792/AD7793 features a dual use data out ready DOUT/RDY output. - * In order to avoid contentions on the SPI bus, it's therefore necessary - * to use spi bus locking. - * - * The DOUT/RDY output must also be wired to an interrupt capable GPIO. - */ - -struct ad7793_chip_info { - const struct iio_chan_spec *channels; - unsigned int num_channels; -}; - -struct ad7793_state { - const struct ad7793_chip_info *chip_info; - struct regulator *reg; - u16 int_vref_mv; - u16 mode; - u16 conf; - u32 scale_avail[8][2]; - - struct ad_sigma_delta sd; - -}; - -enum ad7793_supported_device_ids { - ID_AD7785, - ID_AD7792, - ID_AD7793, - ID_AD7794, - ID_AD7795, -}; - -static struct ad7793_state *ad_sigma_delta_to_ad7793(struct ad_sigma_delta *sd) -{ - return container_of(sd, struct ad7793_state, sd); -} - -static int ad7793_set_channel(struct ad_sigma_delta *sd, unsigned int channel) -{ - struct ad7793_state *st = ad_sigma_delta_to_ad7793(sd); - - st->conf &= ~AD7793_CONF_CHAN_MASK; - st->conf |= AD7793_CONF_CHAN(channel); - - return ad_sd_write_reg(&st->sd, AD7793_REG_CONF, 2, st->conf); -} - -static int ad7793_set_mode(struct ad_sigma_delta *sd, - enum ad_sigma_delta_mode mode) -{ - struct ad7793_state *st = ad_sigma_delta_to_ad7793(sd); - - st->mode &= ~AD7793_MODE_SEL_MASK; - st->mode |= AD7793_MODE_SEL(mode); - - return ad_sd_write_reg(&st->sd, AD7793_REG_MODE, 2, st->mode); -} - -static const struct ad_sigma_delta_info ad7793_sigma_delta_info = { - .set_channel = ad7793_set_channel, - .set_mode = ad7793_set_mode, - .has_registers = true, - .addr_shift = 3, - .read_mask = BIT(6), -}; - -static const struct ad_sd_calib_data ad7793_calib_arr[6] = { - {AD7793_MODE_CAL_INT_ZERO, AD7793_CH_AIN1P_AIN1M}, - {AD7793_MODE_CAL_INT_FULL, AD7793_CH_AIN1P_AIN1M}, - {AD7793_MODE_CAL_INT_ZERO, AD7793_CH_AIN2P_AIN2M}, - {AD7793_MODE_CAL_INT_FULL, AD7793_CH_AIN2P_AIN2M}, - {AD7793_MODE_CAL_INT_ZERO, AD7793_CH_AIN3P_AIN3M}, - {AD7793_MODE_CAL_INT_FULL, AD7793_CH_AIN3P_AIN3M} -}; - -static int ad7793_calibrate_all(struct ad7793_state *st) -{ - return ad_sd_calibrate_all(&st->sd, ad7793_calib_arr, - ARRAY_SIZE(ad7793_calib_arr)); -} - -static int ad7793_setup(struct iio_dev *indio_dev, - const struct ad7793_platform_data *pdata) -{ - struct ad7793_state *st = iio_priv(indio_dev); - int i, ret = -1; - unsigned long long scale_uv; - u32 id; - - /* reset the serial interface */ - ret = spi_write(st->sd.spi, (u8 *)&ret, sizeof(ret)); - if (ret < 0) - goto out; - msleep(1); /* Wait for at least 500us */ - - /* write/read test for device presence */ - ret = ad_sd_read_reg(&st->sd, AD7793_REG_ID, 1, &id); - if (ret) - goto out; - - id &= AD7793_ID_MASK; - - if (!((id == AD7792_ID) || (id == AD7793_ID) || (id == AD7795_ID))) { - dev_err(&st->sd.spi->dev, "device ID query failed\n"); - goto out; - } - - st->mode = pdata->mode; - st->conf = pdata->conf; - - ret = ad7793_set_mode(&st->sd, AD_SD_MODE_IDLE); - if (ret) - goto out; - - ret = ad7793_set_channel(&st->sd, 0); - if (ret) - goto out; - - ret = ad_sd_write_reg(&st->sd, AD7793_REG_IO, - sizeof(pdata->io), pdata->io); - if (ret) - goto out; - - ret = ad7793_calibrate_all(st); - if (ret) - goto out; - - /* Populate available ADC input ranges */ - for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) { - scale_uv = ((u64)st->int_vref_mv * 100000000) - >> (st->chip_info->channels[0].scan_type.realbits - - (!!(st->conf & AD7793_CONF_UNIPOLAR) ? 0 : 1)); - scale_uv >>= i; - - st->scale_avail[i][1] = do_div(scale_uv, 100000000) * 10; - st->scale_avail[i][0] = scale_uv; - } - - return 0; -out: - dev_err(&st->sd.spi->dev, "setup failed\n"); - return ret; -} - -static const u16 sample_freq_avail[16] = {0, 470, 242, 123, 62, 50, 39, 33, 19, - 17, 16, 12, 10, 8, 6, 4}; - -static ssize_t ad7793_read_frequency(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7793_state *st = iio_priv(indio_dev); - - return sprintf(buf, "%d\n", - sample_freq_avail[AD7793_MODE_RATE(st->mode)]); -} - -static ssize_t ad7793_write_frequency(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7793_state *st = iio_priv(indio_dev); - long lval; - int i, ret; - - mutex_lock(&indio_dev->mlock); - if (iio_buffer_enabled(indio_dev)) { - mutex_unlock(&indio_dev->mlock); - return -EBUSY; - } - mutex_unlock(&indio_dev->mlock); - - ret = strict_strtol(buf, 10, &lval); - if (ret) - return ret; - - ret = -EINVAL; - - for (i = 0; i < ARRAY_SIZE(sample_freq_avail); i++) - if (lval == sample_freq_avail[i]) { - mutex_lock(&indio_dev->mlock); - st->mode &= ~AD7793_MODE_RATE(-1); - st->mode |= AD7793_MODE_RATE(i); - ad_sd_write_reg(&st->sd, AD7793_REG_MODE, - sizeof(st->mode), st->mode); - mutex_unlock(&indio_dev->mlock); - ret = 0; - } - - return ret ? ret : len; -} - -static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, - ad7793_read_frequency, - ad7793_write_frequency); - -static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( - "470 242 123 62 50 39 33 19 17 16 12 10 8 6 4"); - -static ssize_t ad7793_show_scale_available(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7793_state *st = iio_priv(indio_dev); - int i, len = 0; - - for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) - len += sprintf(buf + len, "%d.%09u ", st->scale_avail[i][0], - st->scale_avail[i][1]); - - len += sprintf(buf + len, "\n"); - - return len; -} - -static IIO_DEVICE_ATTR_NAMED(in_m_in_scale_available, - in_voltage-voltage_scale_available, S_IRUGO, - ad7793_show_scale_available, NULL, 0); - -static struct attribute *ad7793_attributes[] = { - &iio_dev_attr_sampling_frequency.dev_attr.attr, - &iio_const_attr_sampling_frequency_available.dev_attr.attr, - &iio_dev_attr_in_m_in_scale_available.dev_attr.attr, - NULL -}; - -static const struct attribute_group ad7793_attribute_group = { - .attrs = ad7793_attributes, -}; - -static int ad7793_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long m) -{ - struct ad7793_state *st = iio_priv(indio_dev); - int ret; - unsigned long long scale_uv; - bool unipolar = !!(st->conf & AD7793_CONF_UNIPOLAR); - - switch (m) { - case IIO_CHAN_INFO_RAW: - ret = ad_sigma_delta_single_conversion(indio_dev, chan, val); - if (ret < 0) - return ret; - - return IIO_VAL_INT; - - case IIO_CHAN_INFO_SCALE: - switch (chan->type) { - case IIO_VOLTAGE: - if (chan->differential) { - *val = st-> - scale_avail[(st->conf >> 8) & 0x7][0]; - *val2 = st-> - scale_avail[(st->conf >> 8) & 0x7][1]; - return IIO_VAL_INT_PLUS_NANO; - } else { - /* 1170mV / 2^23 * 6 */ - scale_uv = (1170ULL * 100000000ULL * 6ULL); - } - break; - case IIO_TEMP: - /* 1170mV / 0.81 mV/C / 2^23 */ - scale_uv = 1444444444444ULL; - break; - default: - return -EINVAL; - } - - scale_uv >>= (chan->scan_type.realbits - (unipolar ? 0 : 1)); - *val = 0; - *val2 = scale_uv; - return IIO_VAL_INT_PLUS_NANO; - case IIO_CHAN_INFO_OFFSET: - if (!unipolar) - *val = -(1 << (chan->scan_type.realbits - 1)); - else - *val = 0; - - /* Kelvin to Celsius */ - if (chan->type == IIO_TEMP) { - unsigned long long offset; - unsigned int shift; - - shift = chan->scan_type.realbits - (unipolar ? 0 : 1); - offset = 273ULL << shift; - do_div(offset, 1444); - *val -= offset; - } - return IIO_VAL_INT; - } - return -EINVAL; -} - -static int ad7793_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, - int val2, - long mask) -{ - struct ad7793_state *st = iio_priv(indio_dev); - int ret, i; - unsigned int tmp; - - mutex_lock(&indio_dev->mlock); - if (iio_buffer_enabled(indio_dev)) { - mutex_unlock(&indio_dev->mlock); - return -EBUSY; - } - - switch (mask) { - case IIO_CHAN_INFO_SCALE: - ret = -EINVAL; - for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) - if (val2 == st->scale_avail[i][1]) { - ret = 0; - tmp = st->conf; - st->conf &= ~AD7793_CONF_GAIN(-1); - st->conf |= AD7793_CONF_GAIN(i); - - if (tmp == st->conf) - break; - - ad_sd_write_reg(&st->sd, AD7793_REG_CONF, - sizeof(st->conf), st->conf); - ad7793_calibrate_all(st); - break; - } - break; - default: - ret = -EINVAL; - } - - mutex_unlock(&indio_dev->mlock); - return ret; -} - -static int ad7793_write_raw_get_fmt(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - long mask) -{ - return IIO_VAL_INT_PLUS_NANO; -} - -static const struct iio_info ad7793_info = { - .read_raw = &ad7793_read_raw, - .write_raw = &ad7793_write_raw, - .write_raw_get_fmt = &ad7793_write_raw_get_fmt, - .attrs = &ad7793_attribute_group, - .validate_trigger = ad_sd_validate_trigger, - .driver_module = THIS_MODULE, -}; - -#define DECLARE_AD7793_CHANNELS(_name, _b, _sb, _s) \ -const struct iio_chan_spec _name##_channels[] = { \ - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), (_s)), \ - AD_SD_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), (_s)), \ - AD_SD_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), (_s)), \ - AD_SD_SHORTED_CHANNEL(3, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), (_s)), \ - AD_SD_TEMP_CHANNEL(4, AD7793_CH_TEMP, (_b), (_sb), (_s)), \ - AD_SD_SUPPLY_CHANNEL(5, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), (_s)), \ - IIO_CHAN_SOFT_TIMESTAMP(6), \ -} - -#define DECLARE_AD7795_CHANNELS(_name, _b, _sb) \ -const struct iio_chan_spec _name##_channels[] = { \ - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(1, 1, 1, AD7793_CH_AIN2P_AIN2M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(2, 2, 2, AD7793_CH_AIN3P_AIN3M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(3, 3, 3, AD7795_CH_AIN4P_AIN4M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(4, 4, 4, AD7795_CH_AIN5P_AIN5M, (_b), (_sb), 0), \ - AD_SD_DIFF_CHANNEL(5, 5, 5, AD7795_CH_AIN6P_AIN6M, (_b), (_sb), 0), \ - AD_SD_SHORTED_CHANNEL(6, 0, AD7795_CH_AIN1M_AIN1M, (_b), (_sb), 0), \ - AD_SD_TEMP_CHANNEL(7, AD7793_CH_TEMP, (_b), (_sb), 0), \ - AD_SD_SUPPLY_CHANNEL(8, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \ - IIO_CHAN_SOFT_TIMESTAMP(9), \ -} - -static DECLARE_AD7793_CHANNELS(ad7785, 20, 32, 4); -static DECLARE_AD7793_CHANNELS(ad7792, 16, 32, 0); -static DECLARE_AD7793_CHANNELS(ad7793, 24, 32, 0); -static DECLARE_AD7795_CHANNELS(ad7794, 16, 32); -static DECLARE_AD7795_CHANNELS(ad7795, 24, 32); - -static const struct ad7793_chip_info ad7793_chip_info_tbl[] = { - [ID_AD7785] = { - .channels = ad7785_channels, - .num_channels = ARRAY_SIZE(ad7785_channels), - }, - [ID_AD7792] = { - .channels = ad7792_channels, - .num_channels = ARRAY_SIZE(ad7792_channels), - }, - [ID_AD7793] = { - .channels = ad7793_channels, - .num_channels = ARRAY_SIZE(ad7793_channels), - }, - [ID_AD7794] = { - .channels = ad7794_channels, - .num_channels = ARRAY_SIZE(ad7794_channels), - }, - [ID_AD7795] = { - .channels = ad7795_channels, - .num_channels = ARRAY_SIZE(ad7795_channels), - }, -}; - -static int __devinit ad7793_probe(struct spi_device *spi) -{ - const struct ad7793_platform_data *pdata = spi->dev.platform_data; - struct ad7793_state *st; - struct iio_dev *indio_dev; - int ret, voltage_uv = 0; - - if (!pdata) { - dev_err(&spi->dev, "no platform data?\n"); - return -ENODEV; - } - - if (!spi->irq) { - dev_err(&spi->dev, "no IRQ?\n"); - return -ENODEV; - } - - indio_dev = iio_device_alloc(sizeof(*st)); - if (indio_dev == NULL) - return -ENOMEM; - - st = iio_priv(indio_dev); - - ad_sd_init(&st->sd, indio_dev, spi, &ad7793_sigma_delta_info); - - st->reg = regulator_get(&spi->dev, "vcc"); - if (!IS_ERR(st->reg)) { - ret = regulator_enable(st->reg); - if (ret) - goto error_put_reg; - - voltage_uv = regulator_get_voltage(st->reg); - } - - st->chip_info = - &ad7793_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - - if (pdata && pdata->vref_mv) - st->int_vref_mv = pdata->vref_mv; - else if (voltage_uv) - st->int_vref_mv = voltage_uv / 1000; - else - st->int_vref_mv = 1170; /* Build-in ref */ - - spi_set_drvdata(spi, indio_dev); - - indio_dev->dev.parent = &spi->dev; - indio_dev->name = spi_get_device_id(spi)->name; - indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = st->chip_info->channels; - indio_dev->num_channels = st->chip_info->num_channels; - indio_dev->info = &ad7793_info; - - ret = ad_sd_setup_buffer_and_trigger(indio_dev); - if (ret) - goto error_disable_reg; - - ret = ad7793_setup(indio_dev, pdata); - if (ret) - goto error_remove_trigger; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_remove_trigger; - - return 0; - -error_remove_trigger: - ad_sd_cleanup_buffer_and_trigger(indio_dev); -error_disable_reg: - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); -error_put_reg: - if (!IS_ERR(st->reg)) - regulator_put(st->reg); - - iio_device_free(indio_dev); - - return ret; -} - -static int __devexit ad7793_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7793_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - ad_sd_cleanup_buffer_and_trigger(indio_dev); - - if (!IS_ERR(st->reg)) { - regulator_disable(st->reg); - regulator_put(st->reg); - } - - iio_device_free(indio_dev); - - return 0; -} - -static const struct spi_device_id ad7793_id[] = { - {"ad7785", ID_AD7785}, - {"ad7792", ID_AD7792}, - {"ad7793", ID_AD7793}, - {"ad7794", ID_AD7794}, - {"ad7795", ID_AD7795}, - {} -}; -MODULE_DEVICE_TABLE(spi, ad7793_id); - -static struct spi_driver ad7793_driver = { - .driver = { - .name = "ad7793", - .owner = THIS_MODULE, - }, - .probe = ad7793_probe, - .remove = __devexit_p(ad7793_remove), - .id_table = ad7793_id, -}; -module_spi_driver(ad7793_driver); - -MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); -MODULE_DESCRIPTION("Analog Devices AD7793 and simialr ADCs"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/adc/ad7793.h b/drivers/staging/iio/adc/ad7793.h deleted file mode 100644 index 8fdd450a2cd..00000000000 --- a/drivers/staging/iio/adc/ad7793.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * AD7792/AD7793 SPI ADC driver - * - * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ -#ifndef IIO_ADC_AD7793_H_ -#define IIO_ADC_AD7793_H_ - -/* - * TODO: struct ad7793_platform_data needs to go into include/linux/iio - */ - -/* Registers */ -#define AD7793_REG_COMM 0 /* Communications Register (WO, 8-bit) */ -#define AD7793_REG_STAT 0 /* Status Register (RO, 8-bit) */ -#define AD7793_REG_MODE 1 /* Mode Register (RW, 16-bit */ -#define AD7793_REG_CONF 2 /* Configuration Register (RW, 16-bit) */ -#define AD7793_REG_DATA 3 /* Data Register (RO, 16-/24-bit) */ -#define AD7793_REG_ID 4 /* ID Register (RO, 8-bit) */ -#define AD7793_REG_IO 5 /* IO Register (RO, 8-bit) */ -#define AD7793_REG_OFFSET 6 /* Offset Register (RW, 16-bit - * (AD7792)/24-bit (AD7793)) */ -#define AD7793_REG_FULLSALE 7 /* Full-Scale Register - * (RW, 16-bit (AD7792)/24-bit (AD7793)) */ - -/* Communications Register Bit Designations (AD7793_REG_COMM) */ -#define AD7793_COMM_WEN (1 << 7) /* Write Enable */ -#define AD7793_COMM_WRITE (0 << 6) /* Write Operation */ -#define AD7793_COMM_READ (1 << 6) /* Read Operation */ -#define AD7793_COMM_ADDR(x) (((x) & 0x7) << 3) /* Register Address */ -#define AD7793_COMM_CREAD (1 << 2) /* Continuous Read of Data Register */ - -/* Status Register Bit Designations (AD7793_REG_STAT) */ -#define AD7793_STAT_RDY (1 << 7) /* Ready */ -#define AD7793_STAT_ERR (1 << 6) /* Error (Overrange, Underrange) */ -#define AD7793_STAT_CH3 (1 << 2) /* Channel 3 */ -#define AD7793_STAT_CH2 (1 << 1) /* Channel 2 */ -#define AD7793_STAT_CH1 (1 << 0) /* Channel 1 */ - -/* Mode Register Bit Designations (AD7793_REG_MODE) */ -#define AD7793_MODE_SEL(x) (((x) & 0x7) << 13) /* Operation Mode Select */ -#define AD7793_MODE_SEL_MASK (0x7 << 13) /* Operation Mode Select mask */ -#define AD7793_MODE_CLKSRC(x) (((x) & 0x3) << 6) /* ADC Clock Source Select */ -#define AD7793_MODE_RATE(x) ((x) & 0xF) /* Filter Update Rate Select */ - -#define AD7793_MODE_CONT 0 /* Continuous Conversion Mode */ -#define AD7793_MODE_SINGLE 1 /* Single Conversion Mode */ -#define AD7793_MODE_IDLE 2 /* Idle Mode */ -#define AD7793_MODE_PWRDN 3 /* Power-Down Mode */ -#define AD7793_MODE_CAL_INT_ZERO 4 /* Internal Zero-Scale Calibration */ -#define AD7793_MODE_CAL_INT_FULL 5 /* Internal Full-Scale Calibration */ -#define AD7793_MODE_CAL_SYS_ZERO 6 /* System Zero-Scale Calibration */ -#define AD7793_MODE_CAL_SYS_FULL 7 /* System Full-Scale Calibration */ - -#define AD7793_CLK_INT 0 /* Internal 64 kHz Clock not - * available at the CLK pin */ -#define AD7793_CLK_INT_CO 1 /* Internal 64 kHz Clock available - * at the CLK pin */ -#define AD7793_CLK_EXT 2 /* External 64 kHz Clock */ -#define AD7793_CLK_EXT_DIV2 3 /* External Clock divided by 2 */ - -/* Configuration Register Bit Designations (AD7793_REG_CONF) */ -#define AD7793_CONF_VBIAS(x) (((x) & 0x3) << 14) /* Bias Voltage - * Generator Enable */ -#define AD7793_CONF_BO_EN (1 << 13) /* Burnout Current Enable */ -#define AD7793_CONF_UNIPOLAR (1 << 12) /* Unipolar/Bipolar Enable */ -#define AD7793_CONF_BOOST (1 << 11) /* Boost Enable */ -#define AD7793_CONF_GAIN(x) (((x) & 0x7) << 8) /* Gain Select */ -#define AD7793_CONF_REFSEL (1 << 7) /* INT/EXT Reference Select */ -#define AD7793_CONF_BUF (1 << 4) /* Buffered Mode Enable */ -#define AD7793_CONF_CHAN(x) ((x) & 0xf) /* Channel select */ -#define AD7793_CONF_CHAN_MASK 0xf /* Channel select mask */ - -#define AD7793_CH_AIN1P_AIN1M 0 /* AIN1(+) - AIN1(-) */ -#define AD7793_CH_AIN2P_AIN2M 1 /* AIN2(+) - AIN2(-) */ -#define AD7793_CH_AIN3P_AIN3M 2 /* AIN3(+) - AIN3(-) */ -#define AD7793_CH_AIN1M_AIN1M 3 /* AIN1(-) - AIN1(-) */ -#define AD7793_CH_TEMP 6 /* Temp Sensor */ -#define AD7793_CH_AVDD_MONITOR 7 /* AVDD Monitor */ - -#define AD7795_CH_AIN4P_AIN4M 4 /* AIN4(+) - AIN4(-) */ -#define AD7795_CH_AIN5P_AIN5M 5 /* AIN5(+) - AIN5(-) */ -#define AD7795_CH_AIN6P_AIN6M 6 /* AIN6(+) - AIN6(-) */ -#define AD7795_CH_AIN1M_AIN1M 8 /* AIN1(-) - AIN1(-) */ - -/* ID Register Bit Designations (AD7793_REG_ID) */ -#define AD7792_ID 0xA -#define AD7793_ID 0xB -#define AD7795_ID 0xF -#define AD7793_ID_MASK 0xF - -/* IO (Excitation Current Sources) Register Bit Designations (AD7793_REG_IO) */ -#define AD7793_IO_IEXC1_IOUT1_IEXC2_IOUT2 0 /* IEXC1 connect to IOUT1, - * IEXC2 connect to IOUT2 */ -#define AD7793_IO_IEXC1_IOUT2_IEXC2_IOUT1 1 /* IEXC1 connect to IOUT2, - * IEXC2 connect to IOUT1 */ -#define AD7793_IO_IEXC1_IEXC2_IOUT1 2 /* Both current sources - * IEXC1,2 connect to IOUT1 */ -#define AD7793_IO_IEXC1_IEXC2_IOUT2 3 /* Both current sources - * IEXC1,2 connect to IOUT2 */ - -#define AD7793_IO_IXCEN_10uA (1 << 0) /* Excitation Current 10uA */ -#define AD7793_IO_IXCEN_210uA (2 << 0) /* Excitation Current 210uA */ -#define AD7793_IO_IXCEN_1mA (3 << 0) /* Excitation Current 1mA */ - -struct ad7793_platform_data { - u16 vref_mv; - u16 mode; - u16 conf; - u8 io; -}; - -#endif /* IIO_ADC_AD7793_H_ */ diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index c5fb9476a2d..928477146c2 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -341,7 +341,7 @@ static const struct iio_info ad7816_info = { * device probe and remove */ -static int __devinit ad7816_probe(struct spi_device *spi_dev) +static int ad7816_probe(struct spi_device *spi_dev) { struct ad7816_chip_info *chip; struct iio_dev *indio_dev; @@ -431,7 +431,7 @@ error_ret: return ret; } -static int __devexit ad7816_remove(struct spi_device *spi_dev) +static int ad7816_remove(struct spi_device *spi_dev) { struct iio_dev *indio_dev = dev_get_drvdata(&spi_dev->dev); struct ad7816_chip_info *chip = iio_priv(indio_dev); @@ -463,7 +463,7 @@ static struct spi_driver ad7816_driver = { .owner = THIS_MODULE, }, .probe = ad7816_probe, - .remove = __devexit_p(ad7816_remove), + .remove = ad7816_remove, .id_table = ad7816_id, }; module_spi_driver(ad7816_driver); diff --git a/drivers/staging/iio/adc/ad7887.h b/drivers/staging/iio/adc/ad7887.h deleted file mode 100644 index 2e09e54fc9c..00000000000 --- a/drivers/staging/iio/adc/ad7887.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * AD7887 SPI ADC driver - * - * Copyright 2010 Analog Devices Inc. - * - * Licensed under the GPL-2 or later. - */ -#ifndef IIO_ADC_AD7887_H_ -#define IIO_ADC_AD7887_H_ - -#define AD7887_REF_DIS (1 << 5) /* on-chip reference disable */ -#define AD7887_DUAL (1 << 4) /* dual-channel mode */ -#define AD7887_CH_AIN1 (1 << 3) /* convert on channel 1, DUAL=1 */ -#define AD7887_CH_AIN0 (0 << 3) /* convert on channel 0, DUAL=0,1 */ -#define AD7887_PM_MODE1 (0) /* CS based shutdown */ -#define AD7887_PM_MODE2 (1) /* full on */ -#define AD7887_PM_MODE3 (2) /* auto shutdown after conversion */ -#define AD7887_PM_MODE4 (3) /* standby mode */ - -enum ad7887_channels { - AD7887_CH0, - AD7887_CH0_CH1, - AD7887_CH1, -}; - -#define RES_MASK(bits) ((1 << (bits)) - 1) /* TODO: move this into a common header */ - -/* - * TODO: struct ad7887_platform_data needs to go into include/linux/iio - */ - -struct ad7887_platform_data { - /* External Vref voltage applied */ - u16 vref_mv; - /* - * AD7887: - * In single channel mode en_dual = flase, AIN1/Vref pins assumes its - * Vref function. In dual channel mode en_dual = true, AIN1 becomes the - * second input channel, and Vref is internally connected to Vdd. - */ - bool en_dual; - /* - * AD7887: - * use_onchip_ref = true, the Vref is internally connected to the 2.500V - * Voltage reference. If use_onchip_ref = false, the reference voltage - * is supplied by AIN1/Vref - */ - bool use_onchip_ref; -}; - -/** - * struct ad7887_chip_info - chip specifc information - * @int_vref_mv: the internal reference voltage - * @channel: channel specification - */ - -struct ad7887_chip_info { - u16 int_vref_mv; - struct iio_chan_spec channel[3]; -}; - -struct ad7887_state { - struct spi_device *spi; - const struct ad7887_chip_info *chip_info; - struct regulator *reg; - u16 int_vref_mv; - struct spi_transfer xfer[4]; - struct spi_message msg[3]; - struct spi_message *ring_msg; - unsigned char tx_cmd_buf[8]; - - /* - * DMA (thus cache coherency maintenance) requires the - * transfer buffers to live in their own cache lines. - */ - - unsigned char data[4] ____cacheline_aligned; -}; - -enum ad7887_supported_device_ids { - ID_AD7887 -}; - -#ifdef CONFIG_IIO_BUFFER -int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev); -void ad7887_ring_cleanup(struct iio_dev *indio_dev); -#else /* CONFIG_IIO_BUFFER */ - -static inline int -ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline void ad7887_ring_cleanup(struct iio_dev *indio_dev) -{ -} -#endif /* CONFIG_IIO_BUFFER */ -#endif /* IIO_ADC_AD7887_H_ */ diff --git a/drivers/staging/iio/adc/ad7887_core.c b/drivers/staging/iio/adc/ad7887_core.c deleted file mode 100644 index 551790584a1..00000000000 --- a/drivers/staging/iio/adc/ad7887_core.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * AD7887 SPI ADC driver - * - * Copyright 2010-2011 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ - -#include <linux/device.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/sysfs.h> -#include <linux/spi/spi.h> -#include <linux/regulator/consumer.h> -#include <linux/err.h> -#include <linux/module.h> - -#include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> -#include <linux/iio/buffer.h> - - -#include "ad7887.h" - -static int ad7887_scan_direct(struct ad7887_state *st, unsigned ch) -{ - int ret = spi_sync(st->spi, &st->msg[ch]); - if (ret) - return ret; - - return (st->data[(ch * 2)] << 8) | st->data[(ch * 2) + 1]; -} - -static int ad7887_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long m) -{ - int ret; - struct ad7887_state *st = iio_priv(indio_dev); - unsigned int scale_uv; - - switch (m) { - case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); - if (iio_buffer_enabled(indio_dev)) - ret = -EBUSY; - else - ret = ad7887_scan_direct(st, chan->address); - mutex_unlock(&indio_dev->mlock); - - if (ret < 0) - return ret; - *val = (ret >> st->chip_info->channel[0].scan_type.shift) & - RES_MASK(st->chip_info->channel[0].scan_type.realbits); - return IIO_VAL_INT; - case IIO_CHAN_INFO_SCALE: - scale_uv = (st->int_vref_mv * 1000) - >> st->chip_info->channel[0].scan_type.realbits; - *val = scale_uv/1000; - *val2 = (scale_uv%1000)*1000; - return IIO_VAL_INT_PLUS_MICRO; - } - return -EINVAL; -} - - -static const struct ad7887_chip_info ad7887_chip_info_tbl[] = { - /* - * More devices added in future - */ - [ID_AD7887] = { - .channel[0] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = 1, - .scan_index = 1, - .scan_type = IIO_ST('u', 12, 16, 0), - }, - .channel[1] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | - IIO_CHAN_INFO_SCALE_SHARED_BIT, - .address = 0, - .scan_index = 0, - .scan_type = IIO_ST('u', 12, 16, 0), - }, - .channel[2] = IIO_CHAN_SOFT_TIMESTAMP(2), - .int_vref_mv = 2500, - }, -}; - -static const struct iio_info ad7887_info = { - .read_raw = &ad7887_read_raw, - .driver_module = THIS_MODULE, -}; - -static int __devinit ad7887_probe(struct spi_device *spi) -{ - struct ad7887_platform_data *pdata = spi->dev.platform_data; - struct ad7887_state *st; - int ret, voltage_uv = 0; - struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); - - if (indio_dev == NULL) - return -ENOMEM; - - st = iio_priv(indio_dev); - - st->reg = regulator_get(&spi->dev, "vcc"); - if (!IS_ERR(st->reg)) { - ret = regulator_enable(st->reg); - if (ret) - goto error_put_reg; - - voltage_uv = regulator_get_voltage(st->reg); - } - - st->chip_info = - &ad7887_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - - spi_set_drvdata(spi, indio_dev); - st->spi = spi; - - /* Estabilish that the iio_dev is a child of the spi device */ - indio_dev->dev.parent = &spi->dev; - indio_dev->name = spi_get_device_id(spi)->name; - indio_dev->info = &ad7887_info; - indio_dev->modes = INDIO_DIRECT_MODE; - - /* Setup default message */ - - st->tx_cmd_buf[0] = AD7887_CH_AIN0 | AD7887_PM_MODE4 | - ((pdata && pdata->use_onchip_ref) ? - 0 : AD7887_REF_DIS); - - st->xfer[0].rx_buf = &st->data[0]; - st->xfer[0].tx_buf = &st->tx_cmd_buf[0]; - st->xfer[0].len = 2; - - spi_message_init(&st->msg[AD7887_CH0]); - spi_message_add_tail(&st->xfer[0], &st->msg[AD7887_CH0]); - - if (pdata && pdata->en_dual) { - st->tx_cmd_buf[0] |= AD7887_DUAL | AD7887_REF_DIS; - - st->tx_cmd_buf[2] = AD7887_CH_AIN1 | AD7887_DUAL | - AD7887_REF_DIS | AD7887_PM_MODE4; - st->tx_cmd_buf[4] = AD7887_CH_AIN0 | AD7887_DUAL | - AD7887_REF_DIS | AD7887_PM_MODE4; - st->tx_cmd_buf[6] = AD7887_CH_AIN1 | AD7887_DUAL | - AD7887_REF_DIS | AD7887_PM_MODE4; - - st->xfer[1].rx_buf = &st->data[0]; - st->xfer[1].tx_buf = &st->tx_cmd_buf[2]; - st->xfer[1].len = 2; - - st->xfer[2].rx_buf = &st->data[2]; - st->xfer[2].tx_buf = &st->tx_cmd_buf[4]; - st->xfer[2].len = 2; - - spi_message_init(&st->msg[AD7887_CH0_CH1]); - spi_message_add_tail(&st->xfer[1], &st->msg[AD7887_CH0_CH1]); - spi_message_add_tail(&st->xfer[2], &st->msg[AD7887_CH0_CH1]); - - st->xfer[3].rx_buf = &st->data[0]; - st->xfer[3].tx_buf = &st->tx_cmd_buf[6]; - st->xfer[3].len = 2; - - spi_message_init(&st->msg[AD7887_CH1]); - spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]); - - if (pdata && pdata->vref_mv) - st->int_vref_mv = pdata->vref_mv; - else if (voltage_uv) - st->int_vref_mv = voltage_uv / 1000; - else - dev_warn(&spi->dev, "reference voltage unspecified\n"); - - indio_dev->channels = st->chip_info->channel; - indio_dev->num_channels = 3; - } else { - if (pdata && pdata->vref_mv) - st->int_vref_mv = pdata->vref_mv; - else if (pdata && pdata->use_onchip_ref) - st->int_vref_mv = st->chip_info->int_vref_mv; - else - dev_warn(&spi->dev, "reference voltage unspecified\n"); - - indio_dev->channels = &st->chip_info->channel[1]; - indio_dev->num_channels = 2; - } - - ret = ad7887_register_ring_funcs_and_init(indio_dev); - if (ret) - goto error_disable_reg; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_unregister_ring; - - return 0; -error_unregister_ring: - ad7887_ring_cleanup(indio_dev); -error_disable_reg: - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); -error_put_reg: - if (!IS_ERR(st->reg)) - regulator_put(st->reg); - iio_device_free(indio_dev); - - return ret; -} - -static int __devexit ad7887_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7887_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - ad7887_ring_cleanup(indio_dev); - if (!IS_ERR(st->reg)) { - regulator_disable(st->reg); - regulator_put(st->reg); - } - iio_device_free(indio_dev); - - return 0; -} - -static const struct spi_device_id ad7887_id[] = { - {"ad7887", ID_AD7887}, - {} -}; -MODULE_DEVICE_TABLE(spi, ad7887_id); - -static struct spi_driver ad7887_driver = { - .driver = { - .name = "ad7887", - .owner = THIS_MODULE, - }, - .probe = ad7887_probe, - .remove = __devexit_p(ad7887_remove), - .id_table = ad7887_id, -}; -module_spi_driver(ad7887_driver); - -MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); -MODULE_DESCRIPTION("Analog Devices AD7887 ADC"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c deleted file mode 100644 index b39923bbeed..00000000000 --- a/drivers/staging/iio/adc/ad7887_ring.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2010-2012 Analog Devices Inc. - * Copyright (C) 2008 Jonathan Cameron - * - * Licensed under the GPL-2. - * - * ad7887_ring.c - */ - -#include <linux/interrupt.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/spi/spi.h> - -#include <linux/iio/iio.h> -#include <linux/iio/buffer.h> -#include <linux/iio/trigger_consumer.h> -#include <linux/iio/triggered_buffer.h> - -#include "ad7887.h" - -/** - * ad7887_ring_preenable() setup the parameters of the ring before enabling - * - * The complex nature of the setting of the nuber of bytes per datum is due - * to this driver currently ensuring that the timestamp is stored at an 8 - * byte boundary. - **/ -static int ad7887_ring_preenable(struct iio_dev *indio_dev) -{ - struct ad7887_state *st = iio_priv(indio_dev); - int ret; - - ret = iio_sw_buffer_preenable(indio_dev); - if (ret < 0) - return ret; - - /* We know this is a single long so can 'cheat' */ - switch (*indio_dev->active_scan_mask) { - case (1 << 0): - st->ring_msg = &st->msg[AD7887_CH0]; - break; - case (1 << 1): - st->ring_msg = &st->msg[AD7887_CH1]; - /* Dummy read: push CH1 setting down to hardware */ - spi_sync(st->spi, st->ring_msg); - break; - case ((1 << 1) | (1 << 0)): - st->ring_msg = &st->msg[AD7887_CH0_CH1]; - break; - } - - return 0; -} - -static int ad7887_ring_postdisable(struct iio_dev *indio_dev) -{ - struct ad7887_state *st = iio_priv(indio_dev); - - /* dummy read: restore default CH0 settin */ - return spi_sync(st->spi, &st->msg[AD7887_CH0]); -} - -/** - * ad7887_trigger_handler() bh of trigger launched polling to ring buffer - * - * Currently there is no option in this driver to disable the saving of - * timestamps within the ring. - **/ -static irqreturn_t ad7887_trigger_handler(int irq, void *p) -{ - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct ad7887_state *st = iio_priv(indio_dev); - s64 time_ns; - __u8 *buf; - int b_sent; - - unsigned int bytes = bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength) * - st->chip_info->channel[0].scan_type.storagebits / 8; - - buf = kzalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (buf == NULL) - goto done; - - b_sent = spi_sync(st->spi, st->ring_msg); - if (b_sent) - goto done; - - time_ns = iio_get_time_ns(); - - memcpy(buf, st->data, bytes); - if (indio_dev->scan_timestamp) - memcpy(buf + indio_dev->scan_bytes - sizeof(s64), - &time_ns, sizeof(time_ns)); - - iio_push_to_buffer(indio_dev->buffer, buf); -done: - kfree(buf); - iio_trigger_notify_done(indio_dev->trig); - - return IRQ_HANDLED; -} - -static const struct iio_buffer_setup_ops ad7887_ring_setup_ops = { - .preenable = &ad7887_ring_preenable, - .postenable = &iio_triggered_buffer_postenable, - .predisable = &iio_triggered_buffer_predisable, - .postdisable = &ad7887_ring_postdisable, -}; - -int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev) -{ - return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, - &ad7887_trigger_handler, &ad7887_ring_setup_ops); -} - -void ad7887_ring_cleanup(struct iio_dev *indio_dev) -{ - iio_triggered_buffer_cleanup(indio_dev); -} diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c index 990050700af..077eedbd0a0 100644 --- a/drivers/staging/iio/adc/ad799x_core.c +++ b/drivers/staging/iio/adc/ad799x_core.c @@ -854,7 +854,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { }, }; -static int __devinit ad799x_probe(struct i2c_client *client, +static int ad799x_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret; @@ -932,7 +932,7 @@ error_put_reg: return ret; } -static __devexit int ad799x_remove(struct i2c_client *client) +static int ad799x_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); struct ad799x_state *st = iio_priv(indio_dev); @@ -970,7 +970,7 @@ static struct i2c_driver ad799x_driver = { .name = "ad799x", }, .probe = ad799x_probe, - .remove = __devexit_p(ad799x_remove), + .remove = ad799x_remove, .id_table = ad799x_id, }; module_i2c_driver(ad799x_driver); diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c index 86026d9b20b..2c5f38475a8 100644 --- a/drivers/staging/iio/adc/ad799x_ring.c +++ b/drivers/staging/iio/adc/ad799x_ring.c @@ -77,7 +77,7 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p) memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64), &time_ns, sizeof(time_ns)); - iio_push_to_buffer(indio_dev->buffer, rxbuf); + iio_push_to_buffers(indio_dev, rxbuf); done: kfree(rxbuf); out: diff --git a/drivers/staging/iio/adc/adt7310.c b/drivers/staging/iio/adc/adt7310.c deleted file mode 100644 index 72460b6dc2f..00000000000 --- a/drivers/staging/iio/adc/adt7310.c +++ /dev/null @@ -1,881 +0,0 @@ -/* - * ADT7310 digital temperature sensor driver supporting ADT7310 - * - * Copyright 2010 Analog Devices Inc. - * - * Licensed under the GPL-2 or later. - */ - -#include <linux/interrupt.h> -#include <linux/device.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/sysfs.h> -#include <linux/list.h> -#include <linux/spi/spi.h> -#include <linux/module.h> - -#include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> -#include <linux/iio/events.h> -/* - * ADT7310 registers definition - */ - -#define ADT7310_STATUS 0 -#define ADT7310_CONFIG 1 -#define ADT7310_TEMPERATURE 2 -#define ADT7310_ID 3 -#define ADT7310_T_CRIT 4 -#define ADT7310_T_HYST 5 -#define ADT7310_T_ALARM_HIGH 6 -#define ADT7310_T_ALARM_LOW 7 - -/* - * ADT7310 status - */ -#define ADT7310_STAT_T_LOW 0x10 -#define ADT7310_STAT_T_HIGH 0x20 -#define ADT7310_STAT_T_CRIT 0x40 -#define ADT7310_STAT_NOT_RDY 0x80 - -/* - * ADT7310 config - */ -#define ADT7310_FAULT_QUEUE_MASK 0x3 -#define ADT7310_CT_POLARITY 0x4 -#define ADT7310_INT_POLARITY 0x8 -#define ADT7310_EVENT_MODE 0x10 -#define ADT7310_MODE_MASK 0x60 -#define ADT7310_ONESHOT 0x20 -#define ADT7310_SPS 0x40 -#define ADT7310_PD 0x60 -#define ADT7310_RESOLUTION 0x80 - -/* - * ADT7310 masks - */ -#define ADT7310_T16_VALUE_SIGN 0x8000 -#define ADT7310_T16_VALUE_FLOAT_OFFSET 7 -#define ADT7310_T16_VALUE_FLOAT_MASK 0x7F -#define ADT7310_T13_VALUE_SIGN 0x1000 -#define ADT7310_T13_VALUE_OFFSET 3 -#define ADT7310_T13_VALUE_FLOAT_OFFSET 4 -#define ADT7310_T13_VALUE_FLOAT_MASK 0xF -#define ADT7310_T_HYST_MASK 0xF -#define ADT7310_DEVICE_ID_MASK 0x7 -#define ADT7310_MANUFACTORY_ID_MASK 0xF8 -#define ADT7310_MANUFACTORY_ID_OFFSET 3 - - -#define ADT7310_CMD_REG_MASK 0x28 -#define ADT7310_CMD_REG_OFFSET 3 -#define ADT7310_CMD_READ 0x40 -#define ADT7310_CMD_CON_READ 0x4 - -#define ADT7310_IRQS 2 - -/* - * struct adt7310_chip_info - chip specifc information - */ - -struct adt7310_chip_info { - struct spi_device *spi_dev; - u8 config; -}; - -/* - * adt7310 register access by SPI - */ - -static int adt7310_spi_read_word(struct adt7310_chip_info *chip, u8 reg, u16 *data) -{ - struct spi_device *spi_dev = chip->spi_dev; - u8 command = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK; - int ret = 0; - - command |= ADT7310_CMD_READ; - ret = spi_write(spi_dev, &command, sizeof(command)); - if (ret < 0) { - dev_err(&spi_dev->dev, "SPI write command error\n"); - return ret; - } - - ret = spi_read(spi_dev, (u8 *)data, sizeof(*data)); - if (ret < 0) { - dev_err(&spi_dev->dev, "SPI read word error\n"); - return ret; - } - - *data = be16_to_cpu(*data); - - return 0; -} - -static int adt7310_spi_write_word(struct adt7310_chip_info *chip, u8 reg, u16 data) -{ - struct spi_device *spi_dev = chip->spi_dev; - u8 buf[3]; - int ret = 0; - - buf[0] = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK; - buf[1] = (u8)(data >> 8); - buf[2] = (u8)(data & 0xFF); - - ret = spi_write(spi_dev, buf, 3); - if (ret < 0) { - dev_err(&spi_dev->dev, "SPI write word error\n"); - return ret; - } - - return ret; -} - -static int adt7310_spi_read_byte(struct adt7310_chip_info *chip, u8 reg, u8 *data) -{ - struct spi_device *spi_dev = chip->spi_dev; - u8 command = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK; - int ret = 0; - - command |= ADT7310_CMD_READ; - ret = spi_write(spi_dev, &command, sizeof(command)); - if (ret < 0) { - dev_err(&spi_dev->dev, "SPI write command error\n"); - return ret; - } - - ret = spi_read(spi_dev, data, sizeof(*data)); - if (ret < 0) { - dev_err(&spi_dev->dev, "SPI read byte error\n"); - return ret; - } - - return 0; -} - -static int adt7310_spi_write_byte(struct adt7310_chip_info *chip, u8 reg, u8 data) -{ - struct spi_device *spi_dev = chip->spi_dev; - u8 buf[2]; - int ret = 0; - - buf[0] = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK; - buf[1] = data; - - ret = spi_write(spi_dev, buf, 2); - if (ret < 0) { - dev_err(&spi_dev->dev, "SPI write byte error\n"); - return ret; - } - - return ret; -} - -static ssize_t adt7310_show_mode(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - u8 config; - - config = chip->config & ADT7310_MODE_MASK; - - switch (config) { - case ADT7310_PD: - return sprintf(buf, "power-down\n"); - case ADT7310_ONESHOT: - return sprintf(buf, "one-shot\n"); - case ADT7310_SPS: - return sprintf(buf, "sps\n"); - default: - return sprintf(buf, "full\n"); - } -} - -static ssize_t adt7310_store_mode(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - u16 config; - int ret; - - ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config); - if (ret) - return -EIO; - - config = chip->config & (~ADT7310_MODE_MASK); - if (strcmp(buf, "power-down")) - config |= ADT7310_PD; - else if (strcmp(buf, "one-shot")) - config |= ADT7310_ONESHOT; - else if (strcmp(buf, "sps")) - config |= ADT7310_SPS; - - ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config); - if (ret) - return -EIO; - - chip->config = config; - - return len; -} - -static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, - adt7310_show_mode, - adt7310_store_mode, - 0); - -static ssize_t adt7310_show_available_modes(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return sprintf(buf, "full\none-shot\nsps\npower-down\n"); -} - -static IIO_DEVICE_ATTR(available_modes, S_IRUGO, adt7310_show_available_modes, NULL, 0); - -static ssize_t adt7310_show_resolution(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - int ret; - int bits; - - ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config); - if (ret) - return -EIO; - - if (chip->config & ADT7310_RESOLUTION) - bits = 16; - else - bits = 13; - - return sprintf(buf, "%d bits\n", bits); -} - -static ssize_t adt7310_store_resolution(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - unsigned long data; - u16 config; - int ret; - - ret = strict_strtoul(buf, 10, &data); - if (ret) - return -EINVAL; - - ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config); - if (ret) - return -EIO; - - config = chip->config & (~ADT7310_RESOLUTION); - if (data) - config |= ADT7310_RESOLUTION; - - ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config); - if (ret) - return -EIO; - - chip->config = config; - - return len; -} - -static IIO_DEVICE_ATTR(resolution, S_IRUGO | S_IWUSR, - adt7310_show_resolution, - adt7310_store_resolution, - 0); - -static ssize_t adt7310_show_id(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - u8 id; - int ret; - - ret = adt7310_spi_read_byte(chip, ADT7310_ID, &id); - if (ret) - return -EIO; - - return sprintf(buf, "device id: 0x%x\nmanufactory id: 0x%x\n", - id & ADT7310_DEVICE_ID_MASK, - (id & ADT7310_MANUFACTORY_ID_MASK) >> ADT7310_MANUFACTORY_ID_OFFSET); -} - -static IIO_DEVICE_ATTR(id, S_IRUGO | S_IWUSR, - adt7310_show_id, - NULL, - 0); - -static ssize_t adt7310_convert_temperature(struct adt7310_chip_info *chip, - u16 data, char *buf) -{ - char sign = ' '; - - if (chip->config & ADT7310_RESOLUTION) { - if (data & ADT7310_T16_VALUE_SIGN) { - /* convert supplement to positive value */ - data = (u16)((ADT7310_T16_VALUE_SIGN << 1) - (u32)data); - sign = '-'; - } - return sprintf(buf, "%c%d.%.7d\n", sign, - (data >> ADT7310_T16_VALUE_FLOAT_OFFSET), - (data & ADT7310_T16_VALUE_FLOAT_MASK) * 78125); - } else { - if (data & ADT7310_T13_VALUE_SIGN) { - /* convert supplement to positive value */ - data >>= ADT7310_T13_VALUE_OFFSET; - data = (ADT7310_T13_VALUE_SIGN << 1) - data; - sign = '-'; - } - return sprintf(buf, "%c%d.%.4d\n", sign, - (data >> ADT7310_T13_VALUE_FLOAT_OFFSET), - (data & ADT7310_T13_VALUE_FLOAT_MASK) * 625); - } -} - -static ssize_t adt7310_show_value(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - u8 status; - u16 data; - int ret, i = 0; - - do { - ret = adt7310_spi_read_byte(chip, ADT7310_STATUS, &status); - if (ret) - return -EIO; - i++; - if (i == 10000) - return -EIO; - } while (status & ADT7310_STAT_NOT_RDY); - - ret = adt7310_spi_read_word(chip, ADT7310_TEMPERATURE, &data); - if (ret) - return -EIO; - - return adt7310_convert_temperature(chip, data, buf); -} - -static IIO_DEVICE_ATTR(value, S_IRUGO, adt7310_show_value, NULL, 0); - -static struct attribute *adt7310_attributes[] = { - &iio_dev_attr_available_modes.dev_attr.attr, - &iio_dev_attr_mode.dev_attr.attr, - &iio_dev_attr_resolution.dev_attr.attr, - &iio_dev_attr_id.dev_attr.attr, - &iio_dev_attr_value.dev_attr.attr, - NULL, -}; - -static const struct attribute_group adt7310_attribute_group = { - .attrs = adt7310_attributes, -}; - -static irqreturn_t adt7310_event_handler(int irq, void *private) -{ - struct iio_dev *indio_dev = private; - struct adt7310_chip_info *chip = iio_priv(indio_dev); - s64 timestamp = iio_get_time_ns(); - u8 status; - int ret; - - ret = adt7310_spi_read_byte(chip, ADT7310_STATUS, &status); - if (ret) - goto done; - - if (status & ADT7310_STAT_T_HIGH) - iio_push_event(indio_dev, - IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_RISING), - timestamp); - if (status & ADT7310_STAT_T_LOW) - iio_push_event(indio_dev, - IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_FALLING), - timestamp); - if (status & ADT7310_STAT_T_CRIT) - iio_push_event(indio_dev, - IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_RISING), - timestamp); - -done: - return IRQ_HANDLED; -} - -static ssize_t adt7310_show_event_mode(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - int ret; - - ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config); - if (ret) - return -EIO; - - if (chip->config & ADT7310_EVENT_MODE) - return sprintf(buf, "interrupt\n"); - else - return sprintf(buf, "comparator\n"); -} - -static ssize_t adt7310_set_event_mode(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - u16 config; - int ret; - - ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config); - if (ret) - return -EIO; - - config = chip->config &= ~ADT7310_EVENT_MODE; - if (strcmp(buf, "comparator") != 0) - config |= ADT7310_EVENT_MODE; - - ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config); - if (ret) - return -EIO; - - chip->config = config; - - return len; -} - -static ssize_t adt7310_show_available_event_modes(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return sprintf(buf, "comparator\ninterrupt\n"); -} - -static ssize_t adt7310_show_fault_queue(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - int ret; - - ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config); - if (ret) - return -EIO; - - return sprintf(buf, "%d\n", chip->config & ADT7310_FAULT_QUEUE_MASK); -} - -static ssize_t adt7310_set_fault_queue(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - unsigned long data; - int ret; - u8 config; - - ret = strict_strtoul(buf, 10, &data); - if (ret || data > 3) - return -EINVAL; - - ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config); - if (ret) - return -EIO; - - config = chip->config & ~ADT7310_FAULT_QUEUE_MASK; - config |= data; - ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config); - if (ret) - return -EIO; - - chip->config = config; - - return len; -} - -static inline ssize_t adt7310_show_t_bound(struct device *dev, - struct device_attribute *attr, - u8 bound_reg, - char *buf) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - u16 data; - int ret; - - ret = adt7310_spi_read_word(chip, bound_reg, &data); - if (ret) - return -EIO; - - return adt7310_convert_temperature(chip, data, buf); -} - -static inline ssize_t adt7310_set_t_bound(struct device *dev, - struct device_attribute *attr, - u8 bound_reg, - const char *buf, - size_t len) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - long tmp1, tmp2; - u16 data; - char *pos; - int ret; - - pos = strchr(buf, '.'); - - ret = strict_strtol(buf, 10, &tmp1); - - if (ret || tmp1 > 127 || tmp1 < -128) - return -EINVAL; - - if (pos) { - len = strlen(pos); - - if (chip->config & ADT7310_RESOLUTION) { - if (len > ADT7310_T16_VALUE_FLOAT_OFFSET) - len = ADT7310_T16_VALUE_FLOAT_OFFSET; - pos[len] = 0; - ret = strict_strtol(pos, 10, &tmp2); - - if (!ret) - tmp2 = (tmp2 / 78125) * 78125; - } else { - if (len > ADT7310_T13_VALUE_FLOAT_OFFSET) - len = ADT7310_T13_VALUE_FLOAT_OFFSET; - pos[len] = 0; - ret = strict_strtol(pos, 10, &tmp2); - - if (!ret) - tmp2 = (tmp2 / 625) * 625; - } - } - - if (tmp1 < 0) - data = (u16)(-tmp1); - else - data = (u16)tmp1; - - if (chip->config & ADT7310_RESOLUTION) { - data = (data << ADT7310_T16_VALUE_FLOAT_OFFSET) | - (tmp2 & ADT7310_T16_VALUE_FLOAT_MASK); - - if (tmp1 < 0) - /* convert positive value to supplyment */ - data = (u16)((ADT7310_T16_VALUE_SIGN << 1) - (u32)data); - } else { - data = (data << ADT7310_T13_VALUE_FLOAT_OFFSET) | - (tmp2 & ADT7310_T13_VALUE_FLOAT_MASK); - - if (tmp1 < 0) - /* convert positive value to supplyment */ - data = (ADT7310_T13_VALUE_SIGN << 1) - data; - data <<= ADT7310_T13_VALUE_OFFSET; - } - - ret = adt7310_spi_write_word(chip, bound_reg, data); - if (ret) - return -EIO; - - return len; -} - -static ssize_t adt7310_show_t_alarm_high(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return adt7310_show_t_bound(dev, attr, - ADT7310_T_ALARM_HIGH, buf); -} - -static inline ssize_t adt7310_set_t_alarm_high(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - return adt7310_set_t_bound(dev, attr, - ADT7310_T_ALARM_HIGH, buf, len); -} - -static ssize_t adt7310_show_t_alarm_low(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return adt7310_show_t_bound(dev, attr, - ADT7310_T_ALARM_LOW, buf); -} - -static inline ssize_t adt7310_set_t_alarm_low(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - return adt7310_set_t_bound(dev, attr, - ADT7310_T_ALARM_LOW, buf, len); -} - -static ssize_t adt7310_show_t_crit(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return adt7310_show_t_bound(dev, attr, - ADT7310_T_CRIT, buf); -} - -static inline ssize_t adt7310_set_t_crit(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - return adt7310_set_t_bound(dev, attr, - ADT7310_T_CRIT, buf, len); -} - -static ssize_t adt7310_show_t_hyst(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - int ret; - u8 t_hyst; - - ret = adt7310_spi_read_byte(chip, ADT7310_T_HYST, &t_hyst); - if (ret) - return -EIO; - - return sprintf(buf, "%d\n", t_hyst & ADT7310_T_HYST_MASK); -} - -static inline ssize_t adt7310_set_t_hyst(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *dev_info = dev_to_iio_dev(dev); - struct adt7310_chip_info *chip = iio_priv(dev_info); - int ret; - unsigned long data; - u8 t_hyst; - - ret = strict_strtol(buf, 10, &data); - - if (ret || data > ADT7310_T_HYST_MASK) - return -EINVAL; - - t_hyst = (u8)data; - - ret = adt7310_spi_write_byte(chip, ADT7310_T_HYST, t_hyst); - if (ret) - return -EIO; - - return len; -} - -static IIO_DEVICE_ATTR(event_mode, - S_IRUGO | S_IWUSR, - adt7310_show_event_mode, adt7310_set_event_mode, 0); -static IIO_DEVICE_ATTR(available_event_modes, - S_IRUGO | S_IWUSR, - adt7310_show_available_event_modes, NULL, 0); -static IIO_DEVICE_ATTR(fault_queue, - S_IRUGO | S_IWUSR, - adt7310_show_fault_queue, adt7310_set_fault_queue, 0); -static IIO_DEVICE_ATTR(t_alarm_high, - S_IRUGO | S_IWUSR, - adt7310_show_t_alarm_high, adt7310_set_t_alarm_high, 0); -static IIO_DEVICE_ATTR(t_alarm_low, - S_IRUGO | S_IWUSR, - adt7310_show_t_alarm_low, adt7310_set_t_alarm_low, 0); -static IIO_DEVICE_ATTR(t_crit, - S_IRUGO | S_IWUSR, - adt7310_show_t_crit, adt7310_set_t_crit, 0); -static IIO_DEVICE_ATTR(t_hyst, - S_IRUGO | S_IWUSR, - adt7310_show_t_hyst, adt7310_set_t_hyst, 0); - -static struct attribute *adt7310_event_int_attributes[] = { - &iio_dev_attr_event_mode.dev_attr.attr, - &iio_dev_attr_available_event_modes.dev_attr.attr, - &iio_dev_attr_fault_queue.dev_attr.attr, - &iio_dev_attr_t_alarm_high.dev_attr.attr, - &iio_dev_attr_t_alarm_low.dev_attr.attr, - &iio_dev_attr_t_crit.dev_attr.attr, - &iio_dev_attr_t_hyst.dev_attr.attr, - NULL, -}; - -static struct attribute_group adt7310_event_attribute_group = { - .attrs = adt7310_event_int_attributes, - .name = "events", -}; - -static const struct iio_info adt7310_info = { - .attrs = &adt7310_attribute_group, - .event_attrs = &adt7310_event_attribute_group, - .driver_module = THIS_MODULE, -}; - -/* - * device probe and remove - */ - -static int __devinit adt7310_probe(struct spi_device *spi_dev) -{ - struct adt7310_chip_info *chip; - struct iio_dev *indio_dev; - int ret = 0; - unsigned long *adt7310_platform_data = spi_dev->dev.platform_data; - unsigned long irq_flags; - - indio_dev = iio_device_alloc(sizeof(*chip)); - if (indio_dev == NULL) { - ret = -ENOMEM; - goto error_ret; - } - chip = iio_priv(indio_dev); - /* this is only used for device removal purposes */ - dev_set_drvdata(&spi_dev->dev, indio_dev); - - chip->spi_dev = spi_dev; - - indio_dev->dev.parent = &spi_dev->dev; - indio_dev->name = spi_get_device_id(spi_dev)->name; - indio_dev->info = &adt7310_info; - indio_dev->modes = INDIO_DIRECT_MODE; - - /* CT critcal temperature event. line 0 */ - if (spi_dev->irq) { - if (adt7310_platform_data[2]) - irq_flags = adt7310_platform_data[2]; - else - irq_flags = IRQF_TRIGGER_LOW; - ret = request_threaded_irq(spi_dev->irq, - NULL, - &adt7310_event_handler, - irq_flags | IRQF_ONESHOT, - indio_dev->name, - indio_dev); - if (ret) - goto error_free_dev; - } - - /* INT bound temperature alarm event. line 1 */ - if (adt7310_platform_data[0]) { - ret = request_threaded_irq(adt7310_platform_data[0], - NULL, - &adt7310_event_handler, - adt7310_platform_data[1] | - IRQF_ONESHOT, - indio_dev->name, - indio_dev); - if (ret) - goto error_unreg_ct_irq; - } - - if (spi_dev->irq && adt7310_platform_data[0]) { - ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config); - if (ret) { - ret = -EIO; - goto error_unreg_int_irq; - } - - /* set irq polarity low level */ - chip->config &= ~ADT7310_CT_POLARITY; - - if (adt7310_platform_data[1] & IRQF_TRIGGER_HIGH) - chip->config |= ADT7310_INT_POLARITY; - else - chip->config &= ~ADT7310_INT_POLARITY; - - ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, chip->config); - if (ret) { - ret = -EIO; - goto error_unreg_int_irq; - } - } - - ret = iio_device_register(indio_dev); - if (ret) - goto error_unreg_int_irq; - - dev_info(&spi_dev->dev, "%s temperature sensor registered.\n", - indio_dev->name); - - return 0; - -error_unreg_int_irq: - free_irq(adt7310_platform_data[0], indio_dev); -error_unreg_ct_irq: - free_irq(spi_dev->irq, indio_dev); -error_free_dev: - iio_device_free(indio_dev); -error_ret: - return ret; -} - -static int __devexit adt7310_remove(struct spi_device *spi_dev) -{ - struct iio_dev *indio_dev = dev_get_drvdata(&spi_dev->dev); - unsigned long *adt7310_platform_data = spi_dev->dev.platform_data; - - iio_device_unregister(indio_dev); - dev_set_drvdata(&spi_dev->dev, NULL); - if (adt7310_platform_data[0]) - free_irq(adt7310_platform_data[0], indio_dev); - if (spi_dev->irq) - free_irq(spi_dev->irq, indio_dev); - iio_device_free(indio_dev); - - return 0; -} - -static const struct spi_device_id adt7310_id[] = { - { "adt7310", 0 }, - {} -}; - -MODULE_DEVICE_TABLE(spi, adt7310_id); - -static struct spi_driver adt7310_driver = { - .driver = { - .name = "adt7310", - .owner = THIS_MODULE, - }, - .probe = adt7310_probe, - .remove = __devexit_p(adt7310_remove), - .id_table = adt7310_id, -}; -module_spi_driver(adt7310_driver); - -MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>"); -MODULE_DESCRIPTION("Analog Devices ADT7310 digital" - " temperature sensor driver"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/adc/adt7410.c b/drivers/staging/iio/adc/adt7410.c index 4157596ea3b..35455e16094 100644 --- a/drivers/staging/iio/adc/adt7410.c +++ b/drivers/staging/iio/adc/adt7410.c @@ -1,5 +1,5 @@ /* - * ADT7410 digital temperature sensor driver supporting ADT7410 + * ADT7410 digital temperature sensor driver supporting ADT7310/ADT7410 * * Copyright 2010 Analog Devices Inc. * @@ -13,6 +13,7 @@ #include <linux/sysfs.h> #include <linux/list.h> #include <linux/i2c.h> +#include <linux/spi/spi.h> #include <linux/module.h> #include <linux/iio/iio.h> @@ -34,6 +35,19 @@ #define ADT7410_RESET 0x2F /* + * ADT7310 registers definition + */ + +#define ADT7310_STATUS 0 +#define ADT7310_CONFIG 1 +#define ADT7310_TEMPERATURE 2 +#define ADT7310_ID 3 +#define ADT7310_T_CRIT 4 +#define ADT7310_T_HYST 5 +#define ADT7310_T_ALARM_HIGH 6 +#define ADT7310_T_ALARM_LOW 7 + +/* * ADT7410 status */ #define ADT7410_STAT_T_LOW 0x10 @@ -69,75 +83,52 @@ #define ADT7410_MANUFACTORY_ID_MASK 0xF0 #define ADT7410_MANUFACTORY_ID_OFFSET 4 + +#define ADT7310_CMD_REG_MASK 0x28 +#define ADT7310_CMD_REG_OFFSET 3 +#define ADT7310_CMD_READ 0x40 +#define ADT7310_CMD_CON_READ 0x4 + #define ADT7410_IRQS 2 /* * struct adt7410_chip_info - chip specifc information */ +struct adt7410_chip_info; + +struct adt7410_ops { + int (*read_word)(struct adt7410_chip_info *, u8 reg, u16 *data); + int (*write_word)(struct adt7410_chip_info *, u8 reg, u16 data); + int (*read_byte)(struct adt7410_chip_info *, u8 reg, u8 *data); + int (*write_byte)(struct adt7410_chip_info *, u8 reg, u8 data); +}; + struct adt7410_chip_info { - struct i2c_client *client; + struct device *dev; u8 config; -}; -/* - * adt7410 register access by I2C - */ + const struct adt7410_ops *ops; +}; -static int adt7410_i2c_read_word(struct adt7410_chip_info *chip, u8 reg, u16 *data) +static int adt7410_read_word(struct adt7410_chip_info *chip, u8 reg, u16 *data) { - struct i2c_client *client = chip->client; - int ret = 0; - - ret = i2c_smbus_read_word_data(client, reg); - if (ret < 0) { - dev_err(&client->dev, "I2C read error\n"); - return ret; - } - - *data = swab16((u16)ret); - - return 0; + return chip->ops->read_word(chip, reg, data); } -static int adt7410_i2c_write_word(struct adt7410_chip_info *chip, u8 reg, u16 data) +static int adt7410_write_word(struct adt7410_chip_info *chip, u8 reg, u16 data) { - struct i2c_client *client = chip->client; - int ret = 0; - - ret = i2c_smbus_write_word_data(client, reg, swab16(data)); - if (ret < 0) - dev_err(&client->dev, "I2C write error\n"); - - return ret; + return chip->ops->write_word(chip, reg, data); } -static int adt7410_i2c_read_byte(struct adt7410_chip_info *chip, u8 reg, u8 *data) +static int adt7410_read_byte(struct adt7410_chip_info *chip, u8 reg, u8 *data) { - struct i2c_client *client = chip->client; - int ret = 0; - - ret = i2c_smbus_read_byte_data(client, reg); - if (ret < 0) { - dev_err(&client->dev, "I2C read error\n"); - return ret; - } - - *data = (u8)ret; - - return 0; + return chip->ops->read_byte(chip, reg, data); } -static int adt7410_i2c_write_byte(struct adt7410_chip_info *chip, u8 reg, u8 data) +static int adt7410_write_byte(struct adt7410_chip_info *chip, u8 reg, u8 data) { - struct i2c_client *client = chip->client; - int ret = 0; - - ret = i2c_smbus_write_byte_data(client, reg, data); - if (ret < 0) - dev_err(&client->dev, "I2C write error\n"); - - return ret; + return chip->ops->write_byte(chip, reg, data); } static ssize_t adt7410_show_mode(struct device *dev, @@ -172,7 +163,7 @@ static ssize_t adt7410_store_mode(struct device *dev, u16 config; int ret; - ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config); + ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config); if (ret) return -EIO; @@ -184,13 +175,13 @@ static ssize_t adt7410_store_mode(struct device *dev, else if (strcmp(buf, "sps")) config |= ADT7410_SPS; - ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config); + ret = adt7410_write_byte(chip, ADT7410_CONFIG, config); if (ret) return -EIO; chip->config = config; - return ret; + return len; } static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, @@ -216,7 +207,7 @@ static ssize_t adt7410_show_resolution(struct device *dev, int ret; int bits; - ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config); + ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config); if (ret) return -EIO; @@ -243,7 +234,7 @@ static ssize_t adt7410_store_resolution(struct device *dev, if (ret) return -EINVAL; - ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config); + ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config); if (ret) return -EIO; @@ -251,7 +242,7 @@ static ssize_t adt7410_store_resolution(struct device *dev, if (data) config |= ADT7410_RESOLUTION; - ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config); + ret = adt7410_write_byte(chip, ADT7410_CONFIG, config); if (ret) return -EIO; @@ -274,7 +265,7 @@ static ssize_t adt7410_show_id(struct device *dev, u8 id; int ret; - ret = adt7410_i2c_read_byte(chip, ADT7410_ID, &id); + ret = adt7410_read_byte(chip, ADT7410_ID, &id); if (ret) return -EIO; @@ -317,7 +308,7 @@ static ssize_t adt7410_show_value(struct device *dev, int ret, i = 0; do { - ret = adt7410_i2c_read_byte(chip, ADT7410_STATUS, &status); + ret = adt7410_read_byte(chip, ADT7410_STATUS, &status); if (ret) return -EIO; i++; @@ -325,7 +316,7 @@ static ssize_t adt7410_show_value(struct device *dev, return -EIO; } while (status & ADT7410_STAT_NOT_RDY); - ret = adt7410_i2c_read_word(chip, ADT7410_TEMPERATURE, &data); + ret = adt7410_read_word(chip, ADT7410_TEMPERATURE, &data); if (ret) return -EIO; @@ -354,7 +345,7 @@ static irqreturn_t adt7410_event_handler(int irq, void *private) s64 timestamp = iio_get_time_ns(); u8 status; - if (adt7410_i2c_read_byte(chip, ADT7410_STATUS, &status)) + if (adt7410_read_byte(chip, ADT7410_STATUS, &status)) return IRQ_HANDLED; if (status & ADT7410_STAT_T_HIGH) @@ -387,7 +378,7 @@ static ssize_t adt7410_show_event_mode(struct device *dev, struct adt7410_chip_info *chip = iio_priv(dev_info); int ret; - ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config); + ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config); if (ret) return -EIO; @@ -407,7 +398,7 @@ static ssize_t adt7410_set_event_mode(struct device *dev, u16 config; int ret; - ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config); + ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config); if (ret) return -EIO; @@ -415,7 +406,7 @@ static ssize_t adt7410_set_event_mode(struct device *dev, if (strcmp(buf, "comparator") != 0) config |= ADT7410_EVENT_MODE; - ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config); + ret = adt7410_write_byte(chip, ADT7410_CONFIG, config); if (ret) return -EIO; @@ -439,7 +430,7 @@ static ssize_t adt7410_show_fault_queue(struct device *dev, struct adt7410_chip_info *chip = iio_priv(dev_info); int ret; - ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config); + ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config); if (ret) return -EIO; @@ -461,13 +452,13 @@ static ssize_t adt7410_set_fault_queue(struct device *dev, if (ret || data > 3) return -EINVAL; - ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config); + ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config); if (ret) return -EIO; config = chip->config & ~ADT7410_FAULT_QUEUE_MASK; config |= data; - ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config); + ret = adt7410_write_byte(chip, ADT7410_CONFIG, config); if (ret) return -EIO; @@ -486,7 +477,7 @@ static inline ssize_t adt7410_show_t_bound(struct device *dev, u16 data; int ret; - ret = adt7410_i2c_read_word(chip, bound_reg, &data); + ret = adt7410_read_word(chip, bound_reg, &data); if (ret) return -EIO; @@ -557,7 +548,7 @@ static inline ssize_t adt7410_set_t_bound(struct device *dev, data <<= ADT7410_T13_VALUE_OFFSET; } - ret = adt7410_i2c_write_word(chip, bound_reg, data); + ret = adt7410_write_word(chip, bound_reg, data); if (ret) return -EIO; @@ -624,7 +615,7 @@ static ssize_t adt7410_show_t_hyst(struct device *dev, int ret; u8 t_hyst; - ret = adt7410_i2c_read_byte(chip, ADT7410_T_HYST, &t_hyst); + ret = adt7410_read_byte(chip, ADT7410_T_HYST, &t_hyst); if (ret) return -EIO; @@ -649,7 +640,7 @@ static inline ssize_t adt7410_set_t_hyst(struct device *dev, t_hyst = (u8)data; - ret = adt7410_i2c_write_byte(chip, ADT7410_T_HYST, t_hyst); + ret = adt7410_write_byte(chip, ADT7410_T_HYST, t_hyst); if (ret) return -EIO; @@ -704,14 +695,14 @@ static const struct iio_info adt7410_info = { * device probe and remove */ -static int __devinit adt7410_probe(struct i2c_client *client, - const struct i2c_device_id *id) +static int adt7410_probe(struct device *dev, int irq, + const char *name, const struct adt7410_ops *ops) { + unsigned long *adt7410_platform_data = dev->platform_data; + unsigned long local_pdata[] = {0, 0}; struct adt7410_chip_info *chip; struct iio_dev *indio_dev; int ret = 0; - unsigned long *adt7410_platform_data = client->dev.platform_data; - unsigned long local_pdata[] = {0, 0}; indio_dev = iio_device_alloc(sizeof(*chip)); if (indio_dev == NULL) { @@ -720,12 +711,13 @@ static int __devinit adt7410_probe(struct i2c_client *client, } chip = iio_priv(indio_dev); /* this is only used for device removal purposes */ - i2c_set_clientdata(client, indio_dev); + dev_set_drvdata(dev, indio_dev); - chip->client = client; + chip->dev = dev; + chip->ops = ops; - indio_dev->name = id->name; - indio_dev->dev.parent = &client->dev; + indio_dev->name = name; + indio_dev->dev.parent = dev; indio_dev->info = &adt7410_info; indio_dev->modes = INDIO_DIRECT_MODE; @@ -733,12 +725,12 @@ static int __devinit adt7410_probe(struct i2c_client *client, adt7410_platform_data = local_pdata; /* CT critcal temperature event. line 0 */ - if (client->irq) { - ret = request_threaded_irq(client->irq, + if (irq) { + ret = request_threaded_irq(irq, NULL, &adt7410_event_handler, IRQF_TRIGGER_LOW | IRQF_ONESHOT, - id->name, + name, indio_dev); if (ret) goto error_free_dev; @@ -751,13 +743,13 @@ static int __devinit adt7410_probe(struct i2c_client *client, &adt7410_event_handler, adt7410_platform_data[1] | IRQF_ONESHOT, - id->name, + name, indio_dev); if (ret) goto error_unreg_ct_irq; } - ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config); + ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config); if (ret) { ret = -EIO; goto error_unreg_int_irq; @@ -765,7 +757,7 @@ static int __devinit adt7410_probe(struct i2c_client *client, chip->config |= ADT7410_RESOLUTION; - if (client->irq && adt7410_platform_data[0]) { + if (irq && adt7410_platform_data[0]) { /* set irq polarity low level */ chip->config &= ~ADT7410_CT_POLARITY; @@ -776,7 +768,7 @@ static int __devinit adt7410_probe(struct i2c_client *client, chip->config &= ~ADT7410_INT_POLARITY; } - ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, chip->config); + ret = adt7410_write_byte(chip, ADT7410_CONFIG, chip->config); if (ret) { ret = -EIO; goto error_unreg_int_irq; @@ -785,36 +777,117 @@ static int __devinit adt7410_probe(struct i2c_client *client, if (ret) goto error_unreg_int_irq; - dev_info(&client->dev, "%s temperature sensor registered.\n", - id->name); + dev_info(dev, "%s temperature sensor registered.\n", + name); return 0; error_unreg_int_irq: free_irq(adt7410_platform_data[0], indio_dev); error_unreg_ct_irq: - free_irq(client->irq, indio_dev); + free_irq(irq, indio_dev); error_free_dev: iio_device_free(indio_dev); error_ret: return ret; } -static int __devexit adt7410_remove(struct i2c_client *client) +static int adt7410_remove(struct device *dev, int irq) { - struct iio_dev *indio_dev = i2c_get_clientdata(client); - unsigned long *adt7410_platform_data = client->dev.platform_data; + struct iio_dev *indio_dev = dev_get_drvdata(dev); + unsigned long *adt7410_platform_data = dev->platform_data; iio_device_unregister(indio_dev); if (adt7410_platform_data[0]) free_irq(adt7410_platform_data[0], indio_dev); - if (client->irq) - free_irq(client->irq, indio_dev); + if (irq) + free_irq(irq, indio_dev); iio_device_free(indio_dev); return 0; } +#if IS_ENABLED(CONFIG_I2C) + +static int adt7410_i2c_read_word(struct adt7410_chip_info *chip, u8 reg, + u16 *data) +{ + struct i2c_client *client = to_i2c_client(chip->dev); + int ret = 0; + + ret = i2c_smbus_read_word_data(client, reg); + if (ret < 0) { + dev_err(&client->dev, "I2C read error\n"); + return ret; + } + + *data = swab16((u16)ret); + + return 0; +} + +static int adt7410_i2c_write_word(struct adt7410_chip_info *chip, u8 reg, + u16 data) +{ + struct i2c_client *client = to_i2c_client(chip->dev); + int ret = 0; + + ret = i2c_smbus_write_word_data(client, reg, swab16(data)); + if (ret < 0) + dev_err(&client->dev, "I2C write error\n"); + + return ret; +} + +static int adt7410_i2c_read_byte(struct adt7410_chip_info *chip, u8 reg, + u8 *data) +{ + struct i2c_client *client = to_i2c_client(chip->dev); + int ret = 0; + + ret = i2c_smbus_read_byte_data(client, reg); + if (ret < 0) { + dev_err(&client->dev, "I2C read error\n"); + return ret; + } + + *data = (u8)ret; + + return 0; +} + +static int adt7410_i2c_write_byte(struct adt7410_chip_info *chip, u8 reg, + u8 data) +{ + struct i2c_client *client = to_i2c_client(chip->dev); + int ret = 0; + + ret = i2c_smbus_write_byte_data(client, reg, data); + if (ret < 0) + dev_err(&client->dev, "I2C write error\n"); + + return ret; +} + +static const struct adt7410_ops adt7410_i2c_ops = { + .read_word = adt7410_i2c_read_word, + .write_word = adt7410_i2c_write_word, + .read_byte = adt7410_i2c_read_byte, + .write_byte = adt7410_i2c_write_byte, +}; + +static int adt7410_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + return adt7410_probe(&client->dev, client->irq, id->name, + &adt7410_i2c_ops); +} + +static int adt7410_i2c_remove(struct i2c_client *client) +{ + return adt7410_remove(&client->dev, client->irq); +} + static const struct i2c_device_id adt7410_id[] = { { "adt7410", 0 }, {} @@ -826,13 +899,204 @@ static struct i2c_driver adt7410_driver = { .driver = { .name = "adt7410", }, - .probe = adt7410_probe, - .remove = __devexit_p(adt7410_remove), + .probe = adt7410_i2c_probe, + .remove = adt7410_i2c_remove, .id_table = adt7410_id, }; -module_i2c_driver(adt7410_driver); + +static int __init adt7410_i2c_init(void) +{ + return i2c_add_driver(&adt7410_driver); +} + +static void __exit adt7410_i2c_exit(void) +{ + i2c_del_driver(&adt7410_driver); +} + +#else + +static int __init adt7410_i2c_init(void) { return 0; }; +static void __exit adt7410_i2c_exit(void) {}; + +#endif + +#if IS_ENABLED(CONFIG_SPI_MASTER) + +static const u8 adt7371_reg_table[] = { + [ADT7410_TEMPERATURE] = ADT7310_TEMPERATURE, + [ADT7410_STATUS] = ADT7310_STATUS, + [ADT7410_CONFIG] = ADT7310_CONFIG, + [ADT7410_T_ALARM_HIGH] = ADT7310_T_ALARM_HIGH, + [ADT7410_T_ALARM_LOW] = ADT7310_T_ALARM_LOW, + [ADT7410_T_CRIT] = ADT7310_T_CRIT, + [ADT7410_T_HYST] = ADT7310_T_HYST, + [ADT7410_ID] = ADT7310_ID, +}; + +#define AD7310_COMMAND(reg) (adt7371_reg_table[(reg)] << ADT7310_CMD_REG_OFFSET) + +static int adt7310_spi_read_word(struct adt7410_chip_info *chip, + u8 reg, u16 *data) +{ + struct spi_device *spi = to_spi_device(chip->dev); + u8 command = AD7310_COMMAND(reg); + int ret = 0; + + command |= ADT7310_CMD_READ; + ret = spi_write(spi, &command, sizeof(command)); + if (ret < 0) { + dev_err(&spi->dev, "SPI write command error\n"); + return ret; + } + + ret = spi_read(spi, (u8 *)data, sizeof(*data)); + if (ret < 0) { + dev_err(&spi->dev, "SPI read word error\n"); + return ret; + } + + *data = be16_to_cpu(*data); + + return 0; +} + +static int adt7310_spi_write_word(struct adt7410_chip_info *chip, u8 reg, + u16 data) +{ + struct spi_device *spi = to_spi_device(chip->dev); + u8 buf[3]; + int ret = 0; + + buf[0] = AD7310_COMMAND(reg); + buf[1] = (u8)(data >> 8); + buf[2] = (u8)(data & 0xFF); + + ret = spi_write(spi, buf, 3); + if (ret < 0) { + dev_err(&spi->dev, "SPI write word error\n"); + return ret; + } + + return ret; +} + +static int adt7310_spi_read_byte(struct adt7410_chip_info *chip, u8 reg, + u8 *data) +{ + struct spi_device *spi = to_spi_device(chip->dev); + u8 command = AD7310_COMMAND(reg); + int ret = 0; + + command |= ADT7310_CMD_READ; + ret = spi_write(spi, &command, sizeof(command)); + if (ret < 0) { + dev_err(&spi->dev, "SPI write command error\n"); + return ret; + } + + ret = spi_read(spi, data, sizeof(*data)); + if (ret < 0) { + dev_err(&spi->dev, "SPI read byte error\n"); + return ret; + } + + return 0; +} + +static int adt7310_spi_write_byte(struct adt7410_chip_info *chip, u8 reg, + u8 data) +{ + struct spi_device *spi = to_spi_device(chip->dev); + u8 buf[2]; + int ret = 0; + + buf[0] = AD7310_COMMAND(reg); + buf[1] = data; + + ret = spi_write(spi, buf, 2); + if (ret < 0) { + dev_err(&spi->dev, "SPI write byte error\n"); + return ret; + } + + return ret; +} + +static const struct adt7410_ops adt7310_spi_ops = { + .read_word = adt7310_spi_read_word, + .write_word = adt7310_spi_write_word, + .read_byte = adt7310_spi_read_byte, + .write_byte = adt7310_spi_write_byte, +}; + +static int adt7310_spi_probe(struct spi_device *spi) +{ + return adt7410_probe(&spi->dev, spi->irq, + spi_get_device_id(spi)->name, &adt7310_spi_ops); +} + +static int adt7310_spi_remove(struct spi_device *spi) +{ + return adt7410_remove(&spi->dev, spi->irq); +} + +static const struct spi_device_id adt7310_id[] = { + { "adt7310", 0 }, + {} +}; +MODULE_DEVICE_TABLE(spi, adt7310_id); + +static struct spi_driver adt7310_driver = { + .driver = { + .name = "adt7310", + .owner = THIS_MODULE, + }, + .probe = adt7310_spi_probe, + .remove = adt7310_spi_remove, + .id_table = adt7310_id, +}; + +static int __init adt7310_spi_init(void) +{ + return spi_register_driver(&adt7310_driver); +} + +static void adt7310_spi_exit(void) +{ + spi_unregister_driver(&adt7310_driver); +} + +#else + +static int __init adt7310_spi_init(void) { return 0; }; +static void adt7310_spi_exit(void) {}; + +#endif + +static int __init adt7410_init(void) +{ + int ret; + + ret = adt7310_spi_init(); + if (ret) + return ret; + + ret = adt7410_i2c_init(); + if (ret) + adt7310_spi_exit(); + + return ret; +} +module_init(adt7410_init); + +static void __exit adt7410_exit(void) +{ + adt7410_i2c_exit(); + adt7310_spi_exit(); +} +module_exit(adt7410_exit); MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>"); -MODULE_DESCRIPTION("Analog Devices ADT7410 digital" - " temperature sensor driver"); +MODULE_DESCRIPTION("Analog Devices ADT7310/ADT7410 digital temperature sensor driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/adc/lpc32xx_adc.c b/drivers/staging/iio/adc/lpc32xx_adc.c index 7e9bd0001cc..0bf2a6cc79e 100644 --- a/drivers/staging/iio/adc/lpc32xx_adc.c +++ b/drivers/staging/iio/adc/lpc32xx_adc.c @@ -126,7 +126,7 @@ static irqreturn_t lpc32xx_adc_isr(int irq, void *dev_id) return IRQ_HANDLED; } -static int __devinit lpc32xx_adc_probe(struct platform_device *pdev) +static int lpc32xx_adc_probe(struct platform_device *pdev) { struct lpc32xx_adc_info *info = NULL; struct resource *res; @@ -150,7 +150,7 @@ static int __devinit lpc32xx_adc_probe(struct platform_device *pdev) info = iio_priv(iodev); - info->adc_base = ioremap(res->start, res->end - res->start + 1); + info->adc_base = ioremap(res->start, resource_size(res)); if (!info->adc_base) { dev_err(&pdev->dev, "failed mapping memory\n"); retval = -EBUSY; @@ -207,7 +207,7 @@ errout1: return retval; } -static int __devexit lpc32xx_adc_remove(struct platform_device *pdev) +static int lpc32xx_adc_remove(struct platform_device *pdev) { struct iio_dev *iodev = platform_get_drvdata(pdev); struct lpc32xx_adc_info *info = iio_priv(iodev); @@ -233,7 +233,7 @@ MODULE_DEVICE_TABLE(of, lpc32xx_adc_match); static struct platform_driver lpc32xx_adc_driver = { .probe = lpc32xx_adc_probe, - .remove = __devexit_p(lpc32xx_adc_remove), + .remove = lpc32xx_adc_remove, .driver = { .name = MOD_NAME, .owner = THIS_MODULE, diff --git a/drivers/staging/iio/adc/max1363.h b/drivers/staging/iio/adc/max1363.h deleted file mode 100644 index c746918683f..00000000000 --- a/drivers/staging/iio/adc/max1363.h +++ /dev/null @@ -1,177 +0,0 @@ -#ifndef _MAX1363_H_ -#define _MAX1363_H_ - -#define MAX1363_SETUP_BYTE(a) ((a) | 0x80) - -/* There is a fair bit more defined here than currently - * used, but the intention is to support everything these - * chips do in the long run */ - -/* see data sheets */ -/* max1363 and max1236, max1237, max1238, max1239 */ -#define MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_VDD 0x00 -#define MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF 0x20 -#define MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_INT 0x40 -#define MAX1363_SETUP_AIN3_IS_REF_REF_IS_INT 0x60 -#define MAX1363_SETUP_POWER_UP_INT_REF 0x10 -#define MAX1363_SETUP_POWER_DOWN_INT_REF 0x00 - -/* think about includeing max11600 etc - more settings */ -#define MAX1363_SETUP_EXT_CLOCK 0x08 -#define MAX1363_SETUP_INT_CLOCK 0x00 -#define MAX1363_SETUP_UNIPOLAR 0x00 -#define MAX1363_SETUP_BIPOLAR 0x04 -#define MAX1363_SETUP_RESET 0x00 -#define MAX1363_SETUP_NORESET 0x02 -/* max1363 only - though don't care on others. - * For now monitor modes are not implemented as the relevant - * line is not connected on my test board. - * The definitions are here as I intend to add this soon. - */ -#define MAX1363_SETUP_MONITOR_SETUP 0x01 - -/* Specific to the max1363 */ -#define MAX1363_MON_RESET_CHAN(a) (1 << ((a) + 4)) -#define MAX1363_MON_INT_ENABLE 0x01 - -/* defined for readability reasons */ -/* All chips */ -#define MAX1363_CONFIG_BYTE(a) ((a)) - -#define MAX1363_CONFIG_SE 0x01 -#define MAX1363_CONFIG_DE 0x00 -#define MAX1363_CONFIG_SCAN_TO_CS 0x00 -#define MAX1363_CONFIG_SCAN_SINGLE_8 0x20 -#define MAX1363_CONFIG_SCAN_MONITOR_MODE 0x40 -#define MAX1363_CONFIG_SCAN_SINGLE_1 0x60 -/* max123{6-9} only */ -#define MAX1236_SCAN_MID_TO_CHANNEL 0x40 - -/* max1363 only - merely part of channel selects or don't care for others*/ -#define MAX1363_CONFIG_EN_MON_MODE_READ 0x18 - -#define MAX1363_CHANNEL_SEL(a) ((a) << 1) - -/* max1363 strictly 0x06 - but doesn't matter */ -#define MAX1363_CHANNEL_SEL_MASK 0x1E -#define MAX1363_SCAN_MASK 0x60 -#define MAX1363_SE_DE_MASK 0x01 - -#define MAX1363_MAX_CHANNELS 25 -/** - * struct max1363_mode - scan mode information - * @conf: The corresponding value of the configuration register - * @modemask: Bit mask corresponding to channels enabled in this mode - */ -struct max1363_mode { - int8_t conf; - DECLARE_BITMAP(modemask, MAX1363_MAX_CHANNELS); -}; - -/* This must be maintained along side the max1363_mode_table in max1363_core */ -enum max1363_modes { - /* Single read of a single channel */ - _s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, _s8, _s9, _s10, _s11, - /* Differential single read */ - d0m1, d2m3, d4m5, d6m7, d8m9, d10m11, - d1m0, d3m2, d5m4, d7m6, d9m8, d11m10, - /* Scan to channel and mid to channel where overlapping */ - s0to1, s0to2, s2to3, s0to3, s0to4, s0to5, s0to6, - s6to7, s0to7, s6to8, s0to8, s6to9, - s0to9, s6to10, s0to10, s6to11, s0to11, - /* Differential scan to channel and mid to channel where overlapping */ - d0m1to2m3, d0m1to4m5, d0m1to6m7, d6m7to8m9, - d0m1to8m9, d6m7to10m11, d0m1to10m11, d1m0to3m2, - d1m0to5m4, d1m0to7m6, d7m6to9m8, d1m0to9m8, - d7m6to11m10, d1m0to11m10, -}; - -/** - * struct max1363_chip_info - chip specifc information - * @name: indentification string for chip - * @bits: accuracy of the adc in bits - * @int_vref_mv: the internal reference voltage - * @info: iio core function callbacks structure - * @mode_list: array of available scan modes - * @num_modes: the number of scan modes available - * @default_mode: the scan mode in which the chip starts up - * @channel: channel specification - * @num_channels: number of channels - */ -struct max1363_chip_info { - const struct iio_info *info; - const struct iio_chan_spec *channels; - int num_channels; - const enum max1363_modes *mode_list; - enum max1363_modes default_mode; - u16 int_vref_mv; - u8 num_modes; - u8 bits; -}; - -/** - * struct max1363_state - driver instance specific data - * @client: i2c_client - * @setupbyte: cache of current device setup byte - * @configbyte: cache of current device config byte - * @chip_info: chip model specific constants, available modes etc - * @current_mode: the scan mode of this chip - * @requestedmask: a valid requested set of channels - * @reg: supply regulator - * @monitor_on: whether monitor mode is enabled - * @monitor_speed: parameter corresponding to device monitor speed setting - * @mask_high: bitmask for enabled high thresholds - * @mask_low: bitmask for enabled low thresholds - * @thresh_high: high threshold values - * @thresh_low: low threshold values - */ -struct max1363_state { - struct i2c_client *client; - u8 setupbyte; - u8 configbyte; - const struct max1363_chip_info *chip_info; - const struct max1363_mode *current_mode; - u32 requestedmask; - struct regulator *reg; - - /* Using monitor modes and buffer at the same time is - currently not supported */ - bool monitor_on; - unsigned int monitor_speed:3; - u8 mask_high; - u8 mask_low; - /* 4x unipolar first then the fours bipolar ones */ - s16 thresh_high[8]; - s16 thresh_low[8]; -}; - -const struct max1363_mode -*max1363_match_mode(const unsigned long *mask, - const struct max1363_chip_info *ci); - -int max1363_set_scan_mode(struct max1363_state *st); - -#ifdef CONFIG_MAX1363_RING_BUFFER -int max1363_update_scan_mode(struct iio_dev *indio_dev, - const unsigned long *scan_mask); -int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev); -void max1363_ring_cleanup(struct iio_dev *indio_dev); - -#else /* CONFIG_MAX1363_RING_BUFFER */ -int max1363_update_scan_mode(struct iio_dev *indio_dev, - const long *scan_mask) -{ - return 0; -} - -static inline int -max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline void max1363_ring_cleanup(struct iio_dev *indio_dev) -{ -} -#endif /* CONFIG_MAX1363_RING_BUFFER */ -#endif /* _MAX1363_H_ */ diff --git a/drivers/staging/iio/adc/max1363_core.c b/drivers/staging/iio/adc/max1363_core.c deleted file mode 100644 index d7b4ffcfa05..00000000000 --- a/drivers/staging/iio/adc/max1363_core.c +++ /dev/null @@ -1,1444 +0,0 @@ - /* - * iio/adc/max1363.c - * Copyright (C) 2008-2010 Jonathan Cameron - * - * based on linux/drivers/i2c/chips/max123x - * Copyright (C) 2002-2004 Stefan Eletzhofer - * - * based on linux/drivers/acron/char/pcf8583.c - * Copyright (C) 2000 Russell King - * - * 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. - * - * max1363.c - * - * Partial support for max1363 and similar chips. - * - * Not currently implemented. - * - * - Control of internal reference. - */ - -#include <linux/interrupt.h> -#include <linux/device.h> -#include <linux/kernel.h> -#include <linux/sysfs.h> -#include <linux/list.h> -#include <linux/i2c.h> -#include <linux/regulator/consumer.h> -#include <linux/slab.h> -#include <linux/err.h> -#include <linux/module.h> - -#include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> -#include <linux/iio/events.h> -#include <linux/iio/buffer.h> -#include <linux/iio/driver.h> - -#include "max1363.h" - -#define MAX1363_MODE_SINGLE(_num, _mask) { \ - .conf = MAX1363_CHANNEL_SEL(_num) \ - | MAX1363_CONFIG_SCAN_SINGLE_1 \ - | MAX1363_CONFIG_SE, \ - .modemask[0] = _mask, \ - } - -#define MAX1363_MODE_SCAN_TO_CHANNEL(_num, _mask) { \ - .conf = MAX1363_CHANNEL_SEL(_num) \ - | MAX1363_CONFIG_SCAN_TO_CS \ - | MAX1363_CONFIG_SE, \ - .modemask[0] = _mask, \ - } - -/* note not available for max1363 hence naming */ -#define MAX1236_MODE_SCAN_MID_TO_CHANNEL(_mid, _num, _mask) { \ - .conf = MAX1363_CHANNEL_SEL(_num) \ - | MAX1236_SCAN_MID_TO_CHANNEL \ - | MAX1363_CONFIG_SE, \ - .modemask[0] = _mask \ -} - -#define MAX1363_MODE_DIFF_SINGLE(_nump, _numm, _mask) { \ - .conf = MAX1363_CHANNEL_SEL(_nump) \ - | MAX1363_CONFIG_SCAN_SINGLE_1 \ - | MAX1363_CONFIG_DE, \ - .modemask[0] = _mask \ - } - -/* Can't think how to automate naming so specify for now */ -#define MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(_num, _numvals, _mask) { \ - .conf = MAX1363_CHANNEL_SEL(_num) \ - | MAX1363_CONFIG_SCAN_TO_CS \ - | MAX1363_CONFIG_DE, \ - .modemask[0] = _mask \ - } - -/* note only available for max1363 hence naming */ -#define MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(_num, _numvals, _mask) { \ - .conf = MAX1363_CHANNEL_SEL(_num) \ - | MAX1236_SCAN_MID_TO_CHANNEL \ - | MAX1363_CONFIG_SE, \ - .modemask[0] = _mask \ -} - -static const struct max1363_mode max1363_mode_table[] = { - /* All of the single channel options first */ - MAX1363_MODE_SINGLE(0, 1 << 0), - MAX1363_MODE_SINGLE(1, 1 << 1), - MAX1363_MODE_SINGLE(2, 1 << 2), - MAX1363_MODE_SINGLE(3, 1 << 3), - MAX1363_MODE_SINGLE(4, 1 << 4), - MAX1363_MODE_SINGLE(5, 1 << 5), - MAX1363_MODE_SINGLE(6, 1 << 6), - MAX1363_MODE_SINGLE(7, 1 << 7), - MAX1363_MODE_SINGLE(8, 1 << 8), - MAX1363_MODE_SINGLE(9, 1 << 9), - MAX1363_MODE_SINGLE(10, 1 << 10), - MAX1363_MODE_SINGLE(11, 1 << 11), - - MAX1363_MODE_DIFF_SINGLE(0, 1, 1 << 12), - MAX1363_MODE_DIFF_SINGLE(2, 3, 1 << 13), - MAX1363_MODE_DIFF_SINGLE(4, 5, 1 << 14), - MAX1363_MODE_DIFF_SINGLE(6, 7, 1 << 15), - MAX1363_MODE_DIFF_SINGLE(8, 9, 1 << 16), - MAX1363_MODE_DIFF_SINGLE(10, 11, 1 << 17), - MAX1363_MODE_DIFF_SINGLE(1, 0, 1 << 18), - MAX1363_MODE_DIFF_SINGLE(3, 2, 1 << 19), - MAX1363_MODE_DIFF_SINGLE(5, 4, 1 << 20), - MAX1363_MODE_DIFF_SINGLE(7, 6, 1 << 21), - MAX1363_MODE_DIFF_SINGLE(9, 8, 1 << 22), - MAX1363_MODE_DIFF_SINGLE(11, 10, 1 << 23), - - /* The multichannel scans next */ - MAX1363_MODE_SCAN_TO_CHANNEL(1, 0x003), - MAX1363_MODE_SCAN_TO_CHANNEL(2, 0x007), - MAX1236_MODE_SCAN_MID_TO_CHANNEL(2, 3, 0x00C), - MAX1363_MODE_SCAN_TO_CHANNEL(3, 0x00F), - MAX1363_MODE_SCAN_TO_CHANNEL(4, 0x01F), - MAX1363_MODE_SCAN_TO_CHANNEL(5, 0x03F), - MAX1363_MODE_SCAN_TO_CHANNEL(6, 0x07F), - MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 7, 0x0C0), - MAX1363_MODE_SCAN_TO_CHANNEL(7, 0x0FF), - MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 8, 0x1C0), - MAX1363_MODE_SCAN_TO_CHANNEL(8, 0x1FF), - MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 9, 0x3C0), - MAX1363_MODE_SCAN_TO_CHANNEL(9, 0x3FF), - MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 10, 0x7C0), - MAX1363_MODE_SCAN_TO_CHANNEL(10, 0x7FF), - MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 11, 0xFC0), - MAX1363_MODE_SCAN_TO_CHANNEL(11, 0xFFF), - - MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(2, 2, 0x003000), - MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(4, 3, 0x007000), - MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(6, 4, 0x00F000), - MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(8, 2, 0x018000), - MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(8, 5, 0x01F000), - MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(10, 3, 0x038000), - MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(10, 6, 0x3F000), - MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(3, 2, 0x0C0000), - MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(5, 3, 0x1C0000), - MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(7, 4, 0x3C0000), - MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(9, 2, 0x600000), - MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(9, 5, 0x7C0000), - MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(11, 3, 0xE00000), - MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(11, 6, 0xFC0000), -}; - -const struct max1363_mode -*max1363_match_mode(const unsigned long *mask, -const struct max1363_chip_info *ci) -{ - int i; - if (mask) - for (i = 0; i < ci->num_modes; i++) - if (bitmap_subset(mask, - max1363_mode_table[ci->mode_list[i]]. - modemask, - MAX1363_MAX_CHANNELS)) - return &max1363_mode_table[ci->mode_list[i]]; - return NULL; -} - -static int max1363_write_basic_config(struct i2c_client *client, - unsigned char d1, - unsigned char d2) -{ - u8 tx_buf[2] = {d1, d2}; - - return i2c_master_send(client, tx_buf, 2); -} - -int max1363_set_scan_mode(struct max1363_state *st) -{ - st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK - | MAX1363_SCAN_MASK - | MAX1363_SE_DE_MASK); - st->configbyte |= st->current_mode->conf; - - return max1363_write_basic_config(st->client, - st->setupbyte, - st->configbyte); -} - -static int max1363_read_single_chan(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - long m) -{ - int ret = 0; - s32 data; - char rxbuf[2]; - struct max1363_state *st = iio_priv(indio_dev); - struct i2c_client *client = st->client; - - mutex_lock(&indio_dev->mlock); - /* - * If monitor mode is enabled, the method for reading a single - * channel will have to be rather different and has not yet - * been implemented. - * - * Also, cannot read directly if buffered capture enabled. - */ - if (st->monitor_on || iio_buffer_enabled(indio_dev)) { - ret = -EBUSY; - goto error_ret; - } - - /* Check to see if current scan mode is correct */ - if (st->current_mode != &max1363_mode_table[chan->address]) { - /* Update scan mode if needed */ - st->current_mode = &max1363_mode_table[chan->address]; - ret = max1363_set_scan_mode(st); - if (ret < 0) - goto error_ret; - } - if (st->chip_info->bits != 8) { - /* Get reading */ - data = i2c_master_recv(client, rxbuf, 2); - if (data < 0) { - ret = data; - goto error_ret; - } - data = (s32)(rxbuf[1]) | ((s32)(rxbuf[0] & 0x0F)) << 8; - } else { - /* Get reading */ - data = i2c_master_recv(client, rxbuf, 1); - if (data < 0) { - ret = data; - goto error_ret; - } - data = rxbuf[0]; - } - *val = data; -error_ret: - mutex_unlock(&indio_dev->mlock); - return ret; - -} - -static int max1363_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long m) -{ - struct max1363_state *st = iio_priv(indio_dev); - int ret; - switch (m) { - case IIO_CHAN_INFO_RAW: - ret = max1363_read_single_chan(indio_dev, chan, val, m); - if (ret < 0) - return ret; - return IIO_VAL_INT; - case IIO_CHAN_INFO_SCALE: - if ((1 << (st->chip_info->bits + 1)) > - st->chip_info->int_vref_mv) { - *val = 0; - *val2 = 500000; - return IIO_VAL_INT_PLUS_MICRO; - } else { - *val = (st->chip_info->int_vref_mv) - >> st->chip_info->bits; - return IIO_VAL_INT; - } - default: - return -EINVAL; - } - return 0; -} - -/* Applies to max1363 */ -static const enum max1363_modes max1363_mode_list[] = { - _s0, _s1, _s2, _s3, - s0to1, s0to2, s0to3, - d0m1, d2m3, d1m0, d3m2, - d0m1to2m3, d1m0to3m2, -}; - -#define MAX1363_EV_M \ - (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) \ - | IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)) -#define MAX1363_INFO_MASK (IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT) -#define MAX1363_CHAN_U(num, addr, si, bits, evmask) \ - { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .channel = num, \ - .address = addr, \ - .info_mask = MAX1363_INFO_MASK, \ - .datasheet_name = "AIN"#num, \ - .scan_type = { \ - .sign = 'u', \ - .realbits = bits, \ - .storagebits = (bits > 8) ? 16 : 8, \ - .endianness = IIO_BE, \ - }, \ - .scan_index = si, \ - .event_mask = evmask, \ - } - -/* bipolar channel */ -#define MAX1363_CHAN_B(num, num2, addr, si, bits, evmask) \ - { \ - .type = IIO_VOLTAGE, \ - .differential = 1, \ - .indexed = 1, \ - .channel = num, \ - .channel2 = num2, \ - .address = addr, \ - .info_mask = MAX1363_INFO_MASK, \ - .datasheet_name = "AIN"#num"-AIN"#num2, \ - .scan_type = { \ - .sign = 's', \ - .realbits = bits, \ - .storagebits = (bits > 8) ? 16 : 8, \ - .endianness = IIO_BE, \ - }, \ - .scan_index = si, \ - .event_mask = evmask, \ - } - -#define MAX1363_4X_CHANS(bits, em) { \ - MAX1363_CHAN_U(0, _s0, 0, bits, em), \ - MAX1363_CHAN_U(1, _s1, 1, bits, em), \ - MAX1363_CHAN_U(2, _s2, 2, bits, em), \ - MAX1363_CHAN_U(3, _s3, 3, bits, em), \ - MAX1363_CHAN_B(0, 1, d0m1, 4, bits, em), \ - MAX1363_CHAN_B(2, 3, d2m3, 5, bits, em), \ - MAX1363_CHAN_B(1, 0, d1m0, 6, bits, em), \ - MAX1363_CHAN_B(3, 2, d3m2, 7, bits, em), \ - IIO_CHAN_SOFT_TIMESTAMP(8) \ - } - -static const struct iio_chan_spec max1036_channels[] = MAX1363_4X_CHANS(8, 0); -static const struct iio_chan_spec max1136_channels[] = MAX1363_4X_CHANS(10, 0); -static const struct iio_chan_spec max1236_channels[] = MAX1363_4X_CHANS(12, 0); -static const struct iio_chan_spec max1361_channels[] = - MAX1363_4X_CHANS(10, MAX1363_EV_M); -static const struct iio_chan_spec max1363_channels[] = - MAX1363_4X_CHANS(12, MAX1363_EV_M); - -/* Applies to max1236, max1237 */ -static const enum max1363_modes max1236_mode_list[] = { - _s0, _s1, _s2, _s3, - s0to1, s0to2, s0to3, - d0m1, d2m3, d1m0, d3m2, - d0m1to2m3, d1m0to3m2, - s2to3, -}; - -/* Applies to max1238, max1239 */ -static const enum max1363_modes max1238_mode_list[] = { - _s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, _s8, _s9, _s10, _s11, - s0to1, s0to2, s0to3, s0to4, s0to5, s0to6, - s0to7, s0to8, s0to9, s0to10, s0to11, - d0m1, d2m3, d4m5, d6m7, d8m9, d10m11, - d1m0, d3m2, d5m4, d7m6, d9m8, d11m10, - d0m1to2m3, d0m1to4m5, d0m1to6m7, d0m1to8m9, d0m1to10m11, - d1m0to3m2, d1m0to5m4, d1m0to7m6, d1m0to9m8, d1m0to11m10, - s6to7, s6to8, s6to9, s6to10, s6to11, - d6m7to8m9, d6m7to10m11, d7m6to9m8, d7m6to11m10, -}; - -#define MAX1363_12X_CHANS(bits) { \ - MAX1363_CHAN_U(0, _s0, 0, bits, 0), \ - MAX1363_CHAN_U(1, _s1, 1, bits, 0), \ - MAX1363_CHAN_U(2, _s2, 2, bits, 0), \ - MAX1363_CHAN_U(3, _s3, 3, bits, 0), \ - MAX1363_CHAN_U(4, _s4, 4, bits, 0), \ - MAX1363_CHAN_U(5, _s5, 5, bits, 0), \ - MAX1363_CHAN_U(6, _s6, 6, bits, 0), \ - MAX1363_CHAN_U(7, _s7, 7, bits, 0), \ - MAX1363_CHAN_U(8, _s8, 8, bits, 0), \ - MAX1363_CHAN_U(9, _s9, 9, bits, 0), \ - MAX1363_CHAN_U(10, _s10, 10, bits, 0), \ - MAX1363_CHAN_U(11, _s11, 11, bits, 0), \ - MAX1363_CHAN_B(0, 1, d0m1, 12, bits, 0), \ - MAX1363_CHAN_B(2, 3, d2m3, 13, bits, 0), \ - MAX1363_CHAN_B(4, 5, d4m5, 14, bits, 0), \ - MAX1363_CHAN_B(6, 7, d6m7, 15, bits, 0), \ - MAX1363_CHAN_B(8, 9, d8m9, 16, bits, 0), \ - MAX1363_CHAN_B(10, 11, d10m11, 17, bits, 0), \ - MAX1363_CHAN_B(1, 0, d1m0, 18, bits, 0), \ - MAX1363_CHAN_B(3, 2, d3m2, 19, bits, 0), \ - MAX1363_CHAN_B(5, 4, d5m4, 20, bits, 0), \ - MAX1363_CHAN_B(7, 6, d7m6, 21, bits, 0), \ - MAX1363_CHAN_B(9, 8, d9m8, 22, bits, 0), \ - MAX1363_CHAN_B(11, 10, d11m10, 23, bits, 0), \ - IIO_CHAN_SOFT_TIMESTAMP(24) \ - } -static const struct iio_chan_spec max1038_channels[] = MAX1363_12X_CHANS(8); -static const struct iio_chan_spec max1138_channels[] = MAX1363_12X_CHANS(10); -static const struct iio_chan_spec max1238_channels[] = MAX1363_12X_CHANS(12); - -static const enum max1363_modes max11607_mode_list[] = { - _s0, _s1, _s2, _s3, - s0to1, s0to2, s0to3, - s2to3, - d0m1, d2m3, d1m0, d3m2, - d0m1to2m3, d1m0to3m2, -}; - -static const enum max1363_modes max11608_mode_list[] = { - _s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, - s0to1, s0to2, s0to3, s0to4, s0to5, s0to6, s0to7, - s6to7, - d0m1, d2m3, d4m5, d6m7, - d1m0, d3m2, d5m4, d7m6, - d0m1to2m3, d0m1to4m5, d0m1to6m7, - d1m0to3m2, d1m0to5m4, d1m0to7m6, -}; - -#define MAX1363_8X_CHANS(bits) { \ - MAX1363_CHAN_U(0, _s0, 0, bits, 0), \ - MAX1363_CHAN_U(1, _s1, 1, bits, 0), \ - MAX1363_CHAN_U(2, _s2, 2, bits, 0), \ - MAX1363_CHAN_U(3, _s3, 3, bits, 0), \ - MAX1363_CHAN_U(4, _s4, 4, bits, 0), \ - MAX1363_CHAN_U(5, _s5, 5, bits, 0), \ - MAX1363_CHAN_U(6, _s6, 6, bits, 0), \ - MAX1363_CHAN_U(7, _s7, 7, bits, 0), \ - MAX1363_CHAN_B(0, 1, d0m1, 8, bits, 0), \ - MAX1363_CHAN_B(2, 3, d2m3, 9, bits, 0), \ - MAX1363_CHAN_B(4, 5, d4m5, 10, bits, 0), \ - MAX1363_CHAN_B(6, 7, d6m7, 11, bits, 0), \ - MAX1363_CHAN_B(1, 0, d1m0, 12, bits, 0), \ - MAX1363_CHAN_B(3, 2, d3m2, 13, bits, 0), \ - MAX1363_CHAN_B(5, 4, d5m4, 14, bits, 0), \ - MAX1363_CHAN_B(7, 6, d7m6, 15, bits, 0), \ - IIO_CHAN_SOFT_TIMESTAMP(16) \ -} -static const struct iio_chan_spec max11602_channels[] = MAX1363_8X_CHANS(8); -static const struct iio_chan_spec max11608_channels[] = MAX1363_8X_CHANS(10); -static const struct iio_chan_spec max11614_channels[] = MAX1363_8X_CHANS(12); - -static const enum max1363_modes max11644_mode_list[] = { - _s0, _s1, s0to1, d0m1, d1m0, -}; - -#define MAX1363_2X_CHANS(bits) { \ - MAX1363_CHAN_U(0, _s0, 0, bits, 0), \ - MAX1363_CHAN_U(1, _s1, 1, bits, 0), \ - MAX1363_CHAN_B(0, 1, d0m1, 2, bits, 0), \ - MAX1363_CHAN_B(1, 0, d1m0, 3, bits, 0), \ - IIO_CHAN_SOFT_TIMESTAMP(4) \ - } - -static const struct iio_chan_spec max11646_channels[] = MAX1363_2X_CHANS(10); -static const struct iio_chan_spec max11644_channels[] = MAX1363_2X_CHANS(12); - -enum { max1361, - max1362, - max1363, - max1364, - max1036, - max1037, - max1038, - max1039, - max1136, - max1137, - max1138, - max1139, - max1236, - max1237, - max1238, - max1239, - max11600, - max11601, - max11602, - max11603, - max11604, - max11605, - max11606, - max11607, - max11608, - max11609, - max11610, - max11611, - max11612, - max11613, - max11614, - max11615, - max11616, - max11617, - max11644, - max11645, - max11646, - max11647 -}; - -static const int max1363_monitor_speeds[] = { 133000, 665000, 33300, 16600, - 8300, 4200, 2000, 1000 }; - -static ssize_t max1363_monitor_show_freq(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct max1363_state *st = iio_priv(dev_to_iio_dev(dev)); - return sprintf(buf, "%d\n", max1363_monitor_speeds[st->monitor_speed]); -} - -static ssize_t max1363_monitor_store_freq(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct max1363_state *st = iio_priv(indio_dev); - int i, ret; - unsigned long val; - bool found = false; - - ret = strict_strtoul(buf, 10, &val); - if (ret) - return -EINVAL; - for (i = 0; i < ARRAY_SIZE(max1363_monitor_speeds); i++) - if (val == max1363_monitor_speeds[i]) { - found = true; - break; - } - if (!found) - return -EINVAL; - - mutex_lock(&indio_dev->mlock); - st->monitor_speed = i; - mutex_unlock(&indio_dev->mlock); - - return 0; -} - -static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, - max1363_monitor_show_freq, - max1363_monitor_store_freq); - -static IIO_CONST_ATTR(sampling_frequency_available, - "133000 665000 33300 16600 8300 4200 2000 1000"); - -static int max1363_read_thresh(struct iio_dev *indio_dev, - u64 event_code, - int *val) -{ - struct max1363_state *st = iio_priv(indio_dev); - if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING) - *val = st->thresh_low[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)]; - else - *val = st->thresh_high[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)]; - return 0; -} - -static int max1363_write_thresh(struct iio_dev *indio_dev, - u64 event_code, - int val) -{ - struct max1363_state *st = iio_priv(indio_dev); - /* make it handle signed correctly as well */ - switch (st->chip_info->bits) { - case 10: - if (val > 0x3FF) - return -EINVAL; - break; - case 12: - if (val > 0xFFF) - return -EINVAL; - break; - } - - switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) { - case IIO_EV_DIR_FALLING: - st->thresh_low[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)] = val; - break; - case IIO_EV_DIR_RISING: - st->thresh_high[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)] = val; - break; - } - - return 0; -} - -static const u64 max1363_event_codes[] = { - IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 0, - IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), - IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 1, - IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), - IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 2, - IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), - IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 3, - IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), - IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 0, - IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), - IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 1, - IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), - IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 2, - IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), - IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 3, - IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), -}; - -static irqreturn_t max1363_event_handler(int irq, void *private) -{ - struct iio_dev *indio_dev = private; - struct max1363_state *st = iio_priv(indio_dev); - s64 timestamp = iio_get_time_ns(); - unsigned long mask, loc; - u8 rx; - u8 tx[2] = { st->setupbyte, - MAX1363_MON_INT_ENABLE | (st->monitor_speed << 1) | 0xF0 }; - - i2c_master_recv(st->client, &rx, 1); - mask = rx; - for_each_set_bit(loc, &mask, 8) - iio_push_event(indio_dev, max1363_event_codes[loc], timestamp); - i2c_master_send(st->client, tx, 2); - - return IRQ_HANDLED; -} - -static int max1363_read_event_config(struct iio_dev *indio_dev, - u64 event_code) -{ - struct max1363_state *st = iio_priv(indio_dev); - - int val; - int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code); - mutex_lock(&indio_dev->mlock); - if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING) - val = (1 << number) & st->mask_low; - else - val = (1 << number) & st->mask_high; - mutex_unlock(&indio_dev->mlock); - - return val; -} - -static int max1363_monitor_mode_update(struct max1363_state *st, int enabled) -{ - u8 *tx_buf; - int ret, i = 3, j; - unsigned long numelements; - int len; - const long *modemask; - - if (!enabled) { - /* transition to ring capture is not currently supported */ - st->setupbyte &= ~MAX1363_SETUP_MONITOR_SETUP; - st->configbyte &= ~MAX1363_SCAN_MASK; - st->monitor_on = false; - return max1363_write_basic_config(st->client, - st->setupbyte, - st->configbyte); - } - - /* Ensure we are in the relevant mode */ - st->setupbyte |= MAX1363_SETUP_MONITOR_SETUP; - st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK - | MAX1363_SCAN_MASK - | MAX1363_SE_DE_MASK); - st->configbyte |= MAX1363_CONFIG_SCAN_MONITOR_MODE; - if ((st->mask_low | st->mask_high) & 0x0F) { - st->configbyte |= max1363_mode_table[s0to3].conf; - modemask = max1363_mode_table[s0to3].modemask; - } else if ((st->mask_low | st->mask_high) & 0x30) { - st->configbyte |= max1363_mode_table[d0m1to2m3].conf; - modemask = max1363_mode_table[d0m1to2m3].modemask; - } else { - st->configbyte |= max1363_mode_table[d1m0to3m2].conf; - modemask = max1363_mode_table[d1m0to3m2].modemask; - } - numelements = bitmap_weight(modemask, MAX1363_MAX_CHANNELS); - len = 3 * numelements + 3; - tx_buf = kmalloc(len, GFP_KERNEL); - if (!tx_buf) { - ret = -ENOMEM; - goto error_ret; - } - tx_buf[0] = st->configbyte; - tx_buf[1] = st->setupbyte; - tx_buf[2] = (st->monitor_speed << 1); - - /* - * So we need to do yet another bit of nefarious scan mode - * setup to match what we need. - */ - for (j = 0; j < 8; j++) - if (test_bit(j, modemask)) { - /* Establish the mode is in the scan */ - if (st->mask_low & (1 << j)) { - tx_buf[i] = (st->thresh_low[j] >> 4) & 0xFF; - tx_buf[i + 1] = (st->thresh_low[j] << 4) & 0xF0; - } else if (j < 4) { - tx_buf[i] = 0; - tx_buf[i + 1] = 0; - } else { - tx_buf[i] = 0x80; - tx_buf[i + 1] = 0; - } - if (st->mask_high & (1 << j)) { - tx_buf[i + 1] |= - (st->thresh_high[j] >> 8) & 0x0F; - tx_buf[i + 2] = st->thresh_high[j] & 0xFF; - } else if (j < 4) { - tx_buf[i + 1] |= 0x0F; - tx_buf[i + 2] = 0xFF; - } else { - tx_buf[i + 1] |= 0x07; - tx_buf[i + 2] = 0xFF; - } - i += 3; - } - - - ret = i2c_master_send(st->client, tx_buf, len); - if (ret < 0) - goto error_ret; - if (ret != len) { - ret = -EIO; - goto error_ret; - } - - /* - * Now that we hopefully have sensible thresholds in place it is - * time to turn the interrupts on. - * It is unclear from the data sheet if this should be necessary - * (i.e. whether monitor mode setup is atomic) but it appears to - * be in practice. - */ - tx_buf[0] = st->setupbyte; - tx_buf[1] = MAX1363_MON_INT_ENABLE | (st->monitor_speed << 1) | 0xF0; - ret = i2c_master_send(st->client, tx_buf, 2); - if (ret < 0) - goto error_ret; - if (ret != 2) { - ret = -EIO; - goto error_ret; - } - ret = 0; - st->monitor_on = true; -error_ret: - - kfree(tx_buf); - - return ret; -} - -/* - * To keep this manageable we always use one of 3 scan modes. - * Scan 0...3, 0-1,2-3 and 1-0,3-2 - */ - -static inline int __max1363_check_event_mask(int thismask, int checkmask) -{ - int ret = 0; - /* Is it unipolar */ - if (thismask < 4) { - if (checkmask & ~0x0F) { - ret = -EBUSY; - goto error_ret; - } - } else if (thismask < 6) { - if (checkmask & ~0x30) { - ret = -EBUSY; - goto error_ret; - } - } else if (checkmask & ~0xC0) - ret = -EBUSY; -error_ret: - return ret; -} - -static int max1363_write_event_config(struct iio_dev *indio_dev, - u64 event_code, - int state) -{ - int ret = 0; - struct max1363_state *st = iio_priv(indio_dev); - u16 unifiedmask; - int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code); - - mutex_lock(&indio_dev->mlock); - unifiedmask = st->mask_low | st->mask_high; - if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING) { - - if (state == 0) - st->mask_low &= ~(1 << number); - else { - ret = __max1363_check_event_mask((1 << number), - unifiedmask); - if (ret) - goto error_ret; - st->mask_low |= (1 << number); - } - } else { - if (state == 0) - st->mask_high &= ~(1 << number); - else { - ret = __max1363_check_event_mask((1 << number), - unifiedmask); - if (ret) - goto error_ret; - st->mask_high |= (1 << number); - } - } - - max1363_monitor_mode_update(st, !!(st->mask_high | st->mask_low)); -error_ret: - mutex_unlock(&indio_dev->mlock); - - return ret; -} - -/* - * As with scan_elements, only certain sets of these can - * be combined. - */ -static struct attribute *max1363_event_attributes[] = { - &iio_dev_attr_sampling_frequency.dev_attr.attr, - &iio_const_attr_sampling_frequency_available.dev_attr.attr, - NULL, -}; - -static struct attribute_group max1363_event_attribute_group = { - .attrs = max1363_event_attributes, - .name = "events", -}; - -#define MAX1363_EVENT_FUNCS \ - - -static const struct iio_info max1238_info = { - .read_raw = &max1363_read_raw, - .driver_module = THIS_MODULE, - .update_scan_mode = &max1363_update_scan_mode, -}; - -static const struct iio_info max1363_info = { - .read_event_value = &max1363_read_thresh, - .write_event_value = &max1363_write_thresh, - .read_event_config = &max1363_read_event_config, - .write_event_config = &max1363_write_event_config, - .read_raw = &max1363_read_raw, - .update_scan_mode = &max1363_update_scan_mode, - .driver_module = THIS_MODULE, - .event_attrs = &max1363_event_attribute_group, -}; - -/* max1363 and max1368 tested - rest from data sheet */ -static const struct max1363_chip_info max1363_chip_info_tbl[] = { - [max1361] = { - .bits = 10, - .int_vref_mv = 2048, - .mode_list = max1363_mode_list, - .num_modes = ARRAY_SIZE(max1363_mode_list), - .default_mode = s0to3, - .channels = max1361_channels, - .num_channels = ARRAY_SIZE(max1361_channels), - .info = &max1363_info, - }, - [max1362] = { - .bits = 10, - .int_vref_mv = 4096, - .mode_list = max1363_mode_list, - .num_modes = ARRAY_SIZE(max1363_mode_list), - .default_mode = s0to3, - .channels = max1361_channels, - .num_channels = ARRAY_SIZE(max1361_channels), - .info = &max1363_info, - }, - [max1363] = { - .bits = 12, - .int_vref_mv = 2048, - .mode_list = max1363_mode_list, - .num_modes = ARRAY_SIZE(max1363_mode_list), - .default_mode = s0to3, - .channels = max1363_channels, - .num_channels = ARRAY_SIZE(max1363_channels), - .info = &max1363_info, - }, - [max1364] = { - .bits = 12, - .int_vref_mv = 4096, - .mode_list = max1363_mode_list, - .num_modes = ARRAY_SIZE(max1363_mode_list), - .default_mode = s0to3, - .channels = max1363_channels, - .num_channels = ARRAY_SIZE(max1363_channels), - .info = &max1363_info, - }, - [max1036] = { - .bits = 8, - .int_vref_mv = 4096, - .mode_list = max1236_mode_list, - .num_modes = ARRAY_SIZE(max1236_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1036_channels, - .num_channels = ARRAY_SIZE(max1036_channels), - }, - [max1037] = { - .bits = 8, - .int_vref_mv = 2048, - .mode_list = max1236_mode_list, - .num_modes = ARRAY_SIZE(max1236_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1036_channels, - .num_channels = ARRAY_SIZE(max1036_channels), - }, - [max1038] = { - .bits = 8, - .int_vref_mv = 4096, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1038_channels, - .num_channels = ARRAY_SIZE(max1038_channels), - }, - [max1039] = { - .bits = 8, - .int_vref_mv = 2048, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1038_channels, - .num_channels = ARRAY_SIZE(max1038_channels), - }, - [max1136] = { - .bits = 10, - .int_vref_mv = 4096, - .mode_list = max1236_mode_list, - .num_modes = ARRAY_SIZE(max1236_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1136_channels, - .num_channels = ARRAY_SIZE(max1136_channels), - }, - [max1137] = { - .bits = 10, - .int_vref_mv = 2048, - .mode_list = max1236_mode_list, - .num_modes = ARRAY_SIZE(max1236_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1136_channels, - .num_channels = ARRAY_SIZE(max1136_channels), - }, - [max1138] = { - .bits = 10, - .int_vref_mv = 4096, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1138_channels, - .num_channels = ARRAY_SIZE(max1138_channels), - }, - [max1139] = { - .bits = 10, - .int_vref_mv = 2048, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1138_channels, - .num_channels = ARRAY_SIZE(max1138_channels), - }, - [max1236] = { - .bits = 12, - .int_vref_mv = 4096, - .mode_list = max1236_mode_list, - .num_modes = ARRAY_SIZE(max1236_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1236_channels, - .num_channels = ARRAY_SIZE(max1236_channels), - }, - [max1237] = { - .bits = 12, - .int_vref_mv = 2048, - .mode_list = max1236_mode_list, - .num_modes = ARRAY_SIZE(max1236_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1236_channels, - .num_channels = ARRAY_SIZE(max1236_channels), - }, - [max1238] = { - .bits = 12, - .int_vref_mv = 4096, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1238_channels, - .num_channels = ARRAY_SIZE(max1238_channels), - }, - [max1239] = { - .bits = 12, - .int_vref_mv = 2048, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1238_channels, - .num_channels = ARRAY_SIZE(max1238_channels), - }, - [max11600] = { - .bits = 8, - .int_vref_mv = 4096, - .mode_list = max11607_mode_list, - .num_modes = ARRAY_SIZE(max11607_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1036_channels, - .num_channels = ARRAY_SIZE(max1036_channels), - }, - [max11601] = { - .bits = 8, - .int_vref_mv = 2048, - .mode_list = max11607_mode_list, - .num_modes = ARRAY_SIZE(max11607_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1036_channels, - .num_channels = ARRAY_SIZE(max1036_channels), - }, - [max11602] = { - .bits = 8, - .int_vref_mv = 4096, - .mode_list = max11608_mode_list, - .num_modes = ARRAY_SIZE(max11608_mode_list), - .default_mode = s0to7, - .info = &max1238_info, - .channels = max11602_channels, - .num_channels = ARRAY_SIZE(max11602_channels), - }, - [max11603] = { - .bits = 8, - .int_vref_mv = 2048, - .mode_list = max11608_mode_list, - .num_modes = ARRAY_SIZE(max11608_mode_list), - .default_mode = s0to7, - .info = &max1238_info, - .channels = max11602_channels, - .num_channels = ARRAY_SIZE(max11602_channels), - }, - [max11604] = { - .bits = 8, - .int_vref_mv = 4098, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1238_channels, - .num_channels = ARRAY_SIZE(max1238_channels), - }, - [max11605] = { - .bits = 8, - .int_vref_mv = 2048, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1238_channels, - .num_channels = ARRAY_SIZE(max1238_channels), - }, - [max11606] = { - .bits = 10, - .int_vref_mv = 4096, - .mode_list = max11607_mode_list, - .num_modes = ARRAY_SIZE(max11607_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1136_channels, - .num_channels = ARRAY_SIZE(max1136_channels), - }, - [max11607] = { - .bits = 10, - .int_vref_mv = 2048, - .mode_list = max11607_mode_list, - .num_modes = ARRAY_SIZE(max11607_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1136_channels, - .num_channels = ARRAY_SIZE(max1136_channels), - }, - [max11608] = { - .bits = 10, - .int_vref_mv = 4096, - .mode_list = max11608_mode_list, - .num_modes = ARRAY_SIZE(max11608_mode_list), - .default_mode = s0to7, - .info = &max1238_info, - .channels = max11608_channels, - .num_channels = ARRAY_SIZE(max11608_channels), - }, - [max11609] = { - .bits = 10, - .int_vref_mv = 2048, - .mode_list = max11608_mode_list, - .num_modes = ARRAY_SIZE(max11608_mode_list), - .default_mode = s0to7, - .info = &max1238_info, - .channels = max11608_channels, - .num_channels = ARRAY_SIZE(max11608_channels), - }, - [max11610] = { - .bits = 10, - .int_vref_mv = 4098, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1238_channels, - .num_channels = ARRAY_SIZE(max1238_channels), - }, - [max11611] = { - .bits = 10, - .int_vref_mv = 2048, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1238_channels, - .num_channels = ARRAY_SIZE(max1238_channels), - }, - [max11612] = { - .bits = 12, - .int_vref_mv = 4096, - .mode_list = max11607_mode_list, - .num_modes = ARRAY_SIZE(max11607_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1363_channels, - .num_channels = ARRAY_SIZE(max1363_channels), - }, - [max11613] = { - .bits = 12, - .int_vref_mv = 2048, - .mode_list = max11607_mode_list, - .num_modes = ARRAY_SIZE(max11607_mode_list), - .default_mode = s0to3, - .info = &max1238_info, - .channels = max1363_channels, - .num_channels = ARRAY_SIZE(max1363_channels), - }, - [max11614] = { - .bits = 12, - .int_vref_mv = 4096, - .mode_list = max11608_mode_list, - .num_modes = ARRAY_SIZE(max11608_mode_list), - .default_mode = s0to7, - .info = &max1238_info, - .channels = max11614_channels, - .num_channels = ARRAY_SIZE(max11614_channels), - }, - [max11615] = { - .bits = 12, - .int_vref_mv = 2048, - .mode_list = max11608_mode_list, - .num_modes = ARRAY_SIZE(max11608_mode_list), - .default_mode = s0to7, - .info = &max1238_info, - .channels = max11614_channels, - .num_channels = ARRAY_SIZE(max11614_channels), - }, - [max11616] = { - .bits = 12, - .int_vref_mv = 4098, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1238_channels, - .num_channels = ARRAY_SIZE(max1238_channels), - }, - [max11617] = { - .bits = 12, - .int_vref_mv = 2048, - .mode_list = max1238_mode_list, - .num_modes = ARRAY_SIZE(max1238_mode_list), - .default_mode = s0to11, - .info = &max1238_info, - .channels = max1238_channels, - .num_channels = ARRAY_SIZE(max1238_channels), - }, - [max11644] = { - .bits = 12, - .int_vref_mv = 2048, - .mode_list = max11644_mode_list, - .num_modes = ARRAY_SIZE(max11644_mode_list), - .default_mode = s0to1, - .info = &max1238_info, - .channels = max11644_channels, - .num_channels = ARRAY_SIZE(max11644_channels), - }, - [max11645] = { - .bits = 12, - .int_vref_mv = 4096, - .mode_list = max11644_mode_list, - .num_modes = ARRAY_SIZE(max11644_mode_list), - .default_mode = s0to1, - .info = &max1238_info, - .channels = max11644_channels, - .num_channels = ARRAY_SIZE(max11644_channels), - }, - [max11646] = { - .bits = 10, - .int_vref_mv = 2048, - .mode_list = max11644_mode_list, - .num_modes = ARRAY_SIZE(max11644_mode_list), - .default_mode = s0to1, - .info = &max1238_info, - .channels = max11646_channels, - .num_channels = ARRAY_SIZE(max11646_channels), - }, - [max11647] = { - .bits = 10, - .int_vref_mv = 4096, - .mode_list = max11644_mode_list, - .num_modes = ARRAY_SIZE(max11644_mode_list), - .default_mode = s0to1, - .info = &max1238_info, - .channels = max11646_channels, - .num_channels = ARRAY_SIZE(max11646_channels), - }, -}; - - - -static int max1363_initial_setup(struct max1363_state *st) -{ - st->setupbyte = MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_VDD - | MAX1363_SETUP_POWER_UP_INT_REF - | MAX1363_SETUP_INT_CLOCK - | MAX1363_SETUP_UNIPOLAR - | MAX1363_SETUP_NORESET; - - /* Set scan mode writes the config anyway so wait until then*/ - st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte); - st->current_mode = &max1363_mode_table[st->chip_info->default_mode]; - st->configbyte = MAX1363_CONFIG_BYTE(st->configbyte); - - return max1363_set_scan_mode(st); -} - -static int __devinit max1363_alloc_scan_masks(struct iio_dev *indio_dev) -{ - struct max1363_state *st = iio_priv(indio_dev); - unsigned long *masks; - int i; - - masks = kzalloc(BITS_TO_LONGS(MAX1363_MAX_CHANNELS)*sizeof(long)* - (st->chip_info->num_modes + 1), GFP_KERNEL); - if (!masks) - return -ENOMEM; - - for (i = 0; i < st->chip_info->num_modes; i++) - bitmap_copy(masks + BITS_TO_LONGS(MAX1363_MAX_CHANNELS)*i, - max1363_mode_table[st->chip_info->mode_list[i]] - .modemask, MAX1363_MAX_CHANNELS); - - indio_dev->available_scan_masks = masks; - - return 0; -} - -static int __devinit max1363_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - int ret; - struct max1363_state *st; - struct iio_dev *indio_dev; - struct regulator *reg; - - reg = regulator_get(&client->dev, "vcc"); - if (IS_ERR(reg)) { - ret = PTR_ERR(reg); - goto error_out; - } - - ret = regulator_enable(reg); - if (ret) - goto error_put_reg; - - indio_dev = iio_device_alloc(sizeof(struct max1363_state)); - if (indio_dev == NULL) { - ret = -ENOMEM; - goto error_disable_reg; - } - ret = iio_map_array_register(indio_dev, client->dev.platform_data); - if (ret < 0) - goto error_free_device; - st = iio_priv(indio_dev); - st->reg = reg; - /* this is only used for device removal purposes */ - i2c_set_clientdata(client, indio_dev); - - st->chip_info = &max1363_chip_info_tbl[id->driver_data]; - st->client = client; - - ret = max1363_alloc_scan_masks(indio_dev); - if (ret) - goto error_unregister_map; - - /* Estabilish that the iio_dev is a child of the i2c device */ - indio_dev->dev.parent = &client->dev; - indio_dev->name = id->name; - indio_dev->channels = st->chip_info->channels; - indio_dev->num_channels = st->chip_info->num_channels; - indio_dev->info = st->chip_info->info; - indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = st->chip_info->channels; - indio_dev->num_channels = st->chip_info->num_channels; - ret = max1363_initial_setup(st); - if (ret < 0) - goto error_free_available_scan_masks; - - ret = max1363_register_ring_funcs_and_init(indio_dev); - if (ret) - goto error_free_available_scan_masks; - - ret = iio_buffer_register(indio_dev, - st->chip_info->channels, - st->chip_info->num_channels); - if (ret) - goto error_cleanup_ring; - - if (client->irq) { - ret = request_threaded_irq(st->client->irq, - NULL, - &max1363_event_handler, - IRQF_TRIGGER_RISING | IRQF_ONESHOT, - "max1363_event", - indio_dev); - - if (ret) - goto error_uninit_ring; - } - - ret = iio_device_register(indio_dev); - if (ret < 0) - goto error_free_irq; - - return 0; -error_free_irq: - free_irq(st->client->irq, indio_dev); -error_uninit_ring: - iio_buffer_unregister(indio_dev); -error_cleanup_ring: - max1363_ring_cleanup(indio_dev); -error_free_available_scan_masks: - kfree(indio_dev->available_scan_masks); -error_unregister_map: - iio_map_array_unregister(indio_dev, client->dev.platform_data); -error_free_device: - iio_device_free(indio_dev); -error_disable_reg: - regulator_disable(reg); -error_put_reg: - regulator_put(reg); -error_out: - return ret; -} - -static int __devexit max1363_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - struct max1363_state *st = iio_priv(indio_dev); - struct regulator *reg = st->reg; - - iio_device_unregister(indio_dev); - if (client->irq) - free_irq(st->client->irq, indio_dev); - iio_buffer_unregister(indio_dev); - max1363_ring_cleanup(indio_dev); - kfree(indio_dev->available_scan_masks); - if (!IS_ERR(reg)) { - regulator_disable(reg); - regulator_put(reg); - } - iio_map_array_unregister(indio_dev, client->dev.platform_data); - iio_device_free(indio_dev); - - return 0; -} - -static const struct i2c_device_id max1363_id[] = { - { "max1361", max1361 }, - { "max1362", max1362 }, - { "max1363", max1363 }, - { "max1364", max1364 }, - { "max1036", max1036 }, - { "max1037", max1037 }, - { "max1038", max1038 }, - { "max1039", max1039 }, - { "max1136", max1136 }, - { "max1137", max1137 }, - { "max1138", max1138 }, - { "max1139", max1139 }, - { "max1236", max1236 }, - { "max1237", max1237 }, - { "max1238", max1238 }, - { "max1239", max1239 }, - { "max11600", max11600 }, - { "max11601", max11601 }, - { "max11602", max11602 }, - { "max11603", max11603 }, - { "max11604", max11604 }, - { "max11605", max11605 }, - { "max11606", max11606 }, - { "max11607", max11607 }, - { "max11608", max11608 }, - { "max11609", max11609 }, - { "max11610", max11610 }, - { "max11611", max11611 }, - { "max11612", max11612 }, - { "max11613", max11613 }, - { "max11614", max11614 }, - { "max11615", max11615 }, - { "max11616", max11616 }, - { "max11617", max11617 }, - {} -}; - -MODULE_DEVICE_TABLE(i2c, max1363_id); - -static struct i2c_driver max1363_driver = { - .driver = { - .name = "max1363", - }, - .probe = max1363_probe, - .remove = __devexit_p(max1363_remove), - .id_table = max1363_id, -}; -module_i2c_driver(max1363_driver); - -MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); -MODULE_DESCRIPTION("Maxim 1363 ADC"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/adc/max1363_ring.c b/drivers/staging/iio/adc/max1363_ring.c deleted file mode 100644 index 5f74f3b7671..00000000000 --- a/drivers/staging/iio/adc/max1363_ring.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2008 Jonathan Cameron - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * max1363_ring.c - */ - -#include <linux/interrupt.h> -#include <linux/slab.h> -#include <linux/kernel.h> -#include <linux/i2c.h> -#include <linux/bitops.h> - -#include <linux/iio/iio.h> -#include <linux/iio/buffer.h> -#include "../ring_sw.h" -#include <linux/iio/trigger_consumer.h> - -#include "max1363.h" - -int max1363_update_scan_mode(struct iio_dev *indio_dev, - const unsigned long *scan_mask) -{ - struct max1363_state *st = iio_priv(indio_dev); - - /* - * Need to figure out the current mode based upon the requested - * scan mask in iio_dev - */ - st->current_mode = max1363_match_mode(scan_mask, st->chip_info); - if (!st->current_mode) - return -EINVAL; - max1363_set_scan_mode(st); - return 0; -} - -static irqreturn_t max1363_trigger_handler(int irq, void *p) -{ - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct max1363_state *st = iio_priv(indio_dev); - s64 time_ns; - __u8 *rxbuf; - int b_sent; - size_t d_size; - unsigned long numvals = bitmap_weight(st->current_mode->modemask, - MAX1363_MAX_CHANNELS); - - /* Ensure the timestamp is 8 byte aligned */ - if (st->chip_info->bits != 8) - d_size = numvals*2; - else - d_size = numvals; - if (indio_dev->scan_timestamp) { - d_size += sizeof(s64); - if (d_size % sizeof(s64)) - d_size += sizeof(s64) - (d_size % sizeof(s64)); - } - /* Monitor mode prevents reading. Whilst not currently implemented - * might as well have this test in here in the meantime as it does - * no harm. - */ - if (numvals == 0) - goto done; - - rxbuf = kmalloc(d_size, GFP_KERNEL); - if (rxbuf == NULL) - goto done; - if (st->chip_info->bits != 8) - b_sent = i2c_master_recv(st->client, rxbuf, numvals*2); - else - b_sent = i2c_master_recv(st->client, rxbuf, numvals); - if (b_sent < 0) - goto done_free; - - time_ns = iio_get_time_ns(); - - if (indio_dev->scan_timestamp) - memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns)); - iio_push_to_buffer(indio_dev->buffer, rxbuf); - -done_free: - kfree(rxbuf); -done: - iio_trigger_notify_done(indio_dev->trig); - - return IRQ_HANDLED; -} - -static const struct iio_buffer_setup_ops max1363_ring_setup_ops = { - .postenable = &iio_triggered_buffer_postenable, - .preenable = &iio_sw_buffer_preenable, - .predisable = &iio_triggered_buffer_predisable, -}; - -int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev) -{ - struct max1363_state *st = iio_priv(indio_dev); - int ret = 0; - - indio_dev->buffer = iio_sw_rb_allocate(indio_dev); - if (!indio_dev->buffer) { - ret = -ENOMEM; - goto error_ret; - } - indio_dev->pollfunc = iio_alloc_pollfunc(NULL, - &max1363_trigger_handler, - IRQF_ONESHOT, - indio_dev, - "%s_consumer%d", - st->client->name, - indio_dev->id); - if (indio_dev->pollfunc == NULL) { - ret = -ENOMEM; - goto error_deallocate_sw_rb; - } - /* Ring buffer functions - here trigger setup related */ - indio_dev->setup_ops = &max1363_ring_setup_ops; - - /* Flag that polled ring buffering is possible */ - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; - - return 0; - -error_deallocate_sw_rb: - iio_sw_rb_free(indio_dev->buffer); -error_ret: - return ret; -} - -void max1363_ring_cleanup(struct iio_dev *indio_dev) -{ - /* ensure that the trigger has been detached */ - iio_dealloc_pollfunc(indio_dev->pollfunc); - iio_sw_rb_free(indio_dev->buffer); -} diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c index ca7c1fa88e7..fb31b457a56 100644 --- a/drivers/staging/iio/adc/mxs-lradc.c +++ b/drivers/staging/iio/adc/mxs-lradc.c @@ -237,7 +237,6 @@ static irqreturn_t mxs_lradc_trigger_handler(int irq, void *p) struct iio_poll_func *pf = p; struct iio_dev *iio = pf->indio_dev; struct mxs_lradc *lradc = iio_priv(iio); - struct iio_buffer *buffer = iio->buffer; const uint32_t chan_value = LRADC_CH_ACCUMULATE | ((LRADC_DELAY_TIMER_LOOP - 1) << LRADC_CH_NUM_SAMPLES_OFFSET); int i, j = 0; @@ -256,7 +255,7 @@ static irqreturn_t mxs_lradc_trigger_handler(int irq, void *p) *timestamp = pf->timestamp; } - iio_push_to_buffer(buffer, (u8 *)lradc->buffer); + iio_push_to_buffers(iio, (u8 *)lradc->buffer); iio_trigger_notify_done(iio->trig); @@ -351,7 +350,7 @@ static int mxs_lradc_buffer_preenable(struct iio_dev *iio) writel(chan_value, lradc->base + LRADC_CH(ofs)); enable |= 1 << ofs; ofs++; - }; + } writel(LRADC_DELAY_TRIGGER_LRADCS_MASK | LRADC_DELAY_KICK, lradc->base + LRADC_DELAY(0) + STMP_OFFSET_REG_CLR); @@ -467,7 +466,7 @@ static void mxs_lradc_hw_stop(struct mxs_lradc *lradc) writel(0, lradc->base + LRADC_DELAY(i)); } -static int __devinit mxs_lradc_probe(struct platform_device *pdev) +static int mxs_lradc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct mxs_lradc *lradc; @@ -552,7 +551,7 @@ err_addr: return ret; } -static int __devexit mxs_lradc_remove(struct platform_device *pdev) +static int mxs_lradc_remove(struct platform_device *pdev) { struct iio_dev *iio = platform_get_drvdata(pdev); struct mxs_lradc *lradc = iio_priv(iio); @@ -580,7 +579,7 @@ static struct platform_driver mxs_lradc_driver = { .of_match_table = mxs_lradc_dt_ids, }, .probe = mxs_lradc_probe, - .remove = __devexit_p(mxs_lradc_remove), + .remove = mxs_lradc_remove, }; module_platform_driver(mxs_lradc_driver); diff --git a/drivers/staging/iio/adc/spear_adc.c b/drivers/staging/iio/adc/spear_adc.c index 0b83e2e1f41..13052ceb2f2 100644 --- a/drivers/staging/iio/adc/spear_adc.c +++ b/drivers/staging/iio/adc/spear_adc.c @@ -291,7 +291,7 @@ static const struct iio_info spear_adc_iio_info = { .driver_module = THIS_MODULE, }; -static int __devinit spear_adc_probe(struct platform_device *pdev) +static int spear_adc_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct device *dev = &pdev->dev; @@ -401,7 +401,7 @@ errout1: return ret; } -static int __devexit spear_adc_remove(struct platform_device *pdev) +static int spear_adc_remove(struct platform_device *pdev) { struct iio_dev *iodev = platform_get_drvdata(pdev); struct spear_adc_info *info = iio_priv(iodev); @@ -424,7 +424,7 @@ MODULE_DEVICE_TABLE(of, spear_adc_dt_ids); static struct platform_driver spear_adc_driver = { .probe = spear_adc_probe, - .remove = __devexit_p(spear_adc_remove), + .remove = spear_adc_remove, .driver = { .name = MOD_NAME, .owner = THIS_MODULE, diff --git a/drivers/staging/iio/addac/adt7316-i2c.c b/drivers/staging/iio/addac/adt7316-i2c.c index 9e128dd7d45..ce7d91cb331 100644 --- a/drivers/staging/iio/addac/adt7316-i2c.c +++ b/drivers/staging/iio/addac/adt7316-i2c.c @@ -92,7 +92,7 @@ static int adt7316_i2c_multi_write(void *client, u8 reg, u8 count, u8 *data) * device probe and remove */ -static int __devinit adt7316_i2c_probe(struct i2c_client *client, +static int adt7316_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct adt7316_bus bus = { @@ -108,7 +108,7 @@ static int __devinit adt7316_i2c_probe(struct i2c_client *client, return adt7316_probe(&client->dev, &bus, id->name); } -static int __devexit adt7316_i2c_remove(struct i2c_client *client) +static int adt7316_i2c_remove(struct i2c_client *client) { return adt7316_remove(&client->dev); } @@ -132,7 +132,7 @@ static struct i2c_driver adt7316_driver = { .owner = THIS_MODULE, }, .probe = adt7316_i2c_probe, - .remove = __devexit_p(adt7316_i2c_remove), + .remove = adt7316_i2c_remove, .id_table = adt7316_i2c_id, }; module_i2c_driver(adt7316_driver); diff --git a/drivers/staging/iio/addac/adt7316-spi.c b/drivers/staging/iio/addac/adt7316-spi.c index 985f7d8a6eb..0db8ef5835a 100644 --- a/drivers/staging/iio/addac/adt7316-spi.c +++ b/drivers/staging/iio/addac/adt7316-spi.c @@ -89,7 +89,7 @@ static int adt7316_spi_write(void *client, u8 reg, u8 val) * device probe and remove */ -static int __devinit adt7316_spi_probe(struct spi_device *spi_dev) +static int adt7316_spi_probe(struct spi_device *spi_dev) { struct adt7316_bus bus = { .client = spi_dev, @@ -116,7 +116,7 @@ static int __devinit adt7316_spi_probe(struct spi_device *spi_dev) return adt7316_probe(&spi_dev->dev, &bus, spi_dev->modalias); } -static int __devexit adt7316_spi_remove(struct spi_device *spi_dev) +static int adt7316_spi_remove(struct spi_device *spi_dev) { return adt7316_remove(&spi_dev->dev); } @@ -140,7 +140,7 @@ static struct spi_driver adt7316_driver = { .owner = THIS_MODULE, }, .probe = adt7316_spi_probe, - .remove = __devexit_p(adt7316_spi_remove), + .remove = adt7316_spi_remove, .id_table = adt7316_spi_id, }; module_spi_driver(adt7316_driver); diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c index 8fb014a046a..0b431bc4f62 100644 --- a/drivers/staging/iio/addac/adt7316.c +++ b/drivers/staging/iio/addac/adt7316.c @@ -2125,7 +2125,7 @@ static const struct iio_info adt7516_info = { /* * device probe and remove */ -int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus, +int adt7316_probe(struct device *dev, struct adt7316_bus *bus, const char *name) { struct adt7316_chip_info *chip; @@ -2216,7 +2216,7 @@ error_ret: } EXPORT_SYMBOL(adt7316_probe); -int __devexit adt7316_remove(struct device *dev) +int adt7316_remove(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct adt7316_chip_info *chip = iio_priv(indio_dev); diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 6a4041417d4..3c608c14dd9 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -156,7 +156,7 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev, u64 event_code) return !adaptive && (threshtype == 0x1); else return !adaptive && (threshtype == 0x0); - }; + } return -EINVAL; } @@ -194,7 +194,7 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, u64 event_code) break; default: return -EINVAL; - }; + } ret = i2c_smbus_write_byte_data(chip->client, ad7150_addresses[chan][4], sens); @@ -257,7 +257,7 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev, default: ret = -EINVAL; goto error_ret; - }; + } cfg |= (!adaptive << 7) | (thresh_type << 5); @@ -327,7 +327,7 @@ static int ad7150_write_event_value(struct iio_dev *indio_dev, default: ret = -EINVAL; goto error_ret; - }; + } /* write back if active */ ret = ad7150_write_event_params(indio_dev, event_code); @@ -360,7 +360,7 @@ static ssize_t ad7150_show_timeout(struct device *dev, break; default: return -EINVAL; - }; + } return sprintf(buf, "%d\n", value); } @@ -394,7 +394,7 @@ static ssize_t ad7150_store_timeout(struct device *dev, default: ret = -EINVAL; goto error_ret; - }; + } ret = ad7150_write_event_params(indio_dev, this_attr->address); error_ret: @@ -551,7 +551,7 @@ static const struct iio_info ad7150_info = { * device probe and remove */ -static int __devinit ad7150_probe(struct i2c_client *client, +static int ad7150_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret; @@ -628,7 +628,7 @@ error_ret: return ret; } -static int __devexit ad7150_remove(struct i2c_client *client) +static int ad7150_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); @@ -658,7 +658,7 @@ static struct i2c_driver ad7150_driver = { .name = "ad7150", }, .probe = ad7150_probe, - .remove = __devexit_p(ad7150_remove), + .remove = ad7150_remove, .id_table = ad7150_id, }; module_i2c_driver(ad7150_driver); diff --git a/drivers/staging/iio/cdc/ad7152.c b/drivers/staging/iio/cdc/ad7152.c index 98c3015116a..3c92ba3722a 100644 --- a/drivers/staging/iio/cdc/ad7152.c +++ b/drivers/staging/iio/cdc/ad7152.c @@ -405,7 +405,7 @@ static int ad7152_read_raw(struct iio_dev *indio_dev, break; default: ret = -EINVAL; - }; + } out: mutex_unlock(&indio_dev->mlock); return ret; @@ -474,7 +474,7 @@ static const struct iio_chan_spec ad7152_channels[] = { * device probe and remove */ -static int __devinit ad7152_probe(struct i2c_client *client, +static int ad7152_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = 0; @@ -518,7 +518,7 @@ error_ret: return ret; } -static int __devexit ad7152_remove(struct i2c_client *client) +static int ad7152_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); @@ -541,7 +541,7 @@ static struct i2c_driver ad7152_driver = { .name = KBUILD_MODNAME, }, .probe = ad7152_probe, - .remove = __devexit_p(ad7152_remove), + .remove = ad7152_remove, .id_table = ad7152_id, }; module_i2c_driver(ad7152_driver); diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c index 754e11e8719..466b82ecfbe 100644 --- a/drivers/staging/iio/cdc/ad7746.c +++ b/drivers/staging/iio/cdc/ad7746.c @@ -677,7 +677,7 @@ static int ad7746_read_raw(struct iio_dev *indio_dev, break; default: ret = -EINVAL; - }; + } out: mutex_unlock(&indio_dev->mlock); return ret; @@ -694,7 +694,7 @@ static const struct iio_info ad7746_info = { * device probe and remove */ -static int __devinit ad7746_probe(struct i2c_client *client, +static int ad7746_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct ad7746_platform_data *pdata = client->dev.platform_data; @@ -768,7 +768,7 @@ error_ret: return ret; } -static int __devexit ad7746_remove(struct i2c_client *client) +static int ad7746_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); @@ -792,7 +792,7 @@ static struct i2c_driver ad7746_driver = { .name = KBUILD_MODNAME, }, .probe = ad7746_probe, - .remove = __devexit_p(ad7746_remove), + .remove = ad7746_remove, .id_table = ad7746_id, }; module_i2c_driver(ad7746_driver); diff --git a/drivers/staging/iio/frequency/ad5930.c b/drivers/staging/iio/frequency/ad5930.c index 2d541d0eebe..23777be38b1 100644 --- a/drivers/staging/iio/frequency/ad5930.c +++ b/drivers/staging/iio/frequency/ad5930.c @@ -91,7 +91,7 @@ static const struct iio_info ad5930_info = { .driver_module = THIS_MODULE, }; -static int __devinit ad5930_probe(struct spi_device *spi) +static int ad5930_probe(struct spi_device *spi) { struct ad5930_state *st; struct iio_dev *idev; @@ -127,7 +127,7 @@ error_ret: return ret; } -static int __devexit ad5930_remove(struct spi_device *spi) +static int ad5930_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -141,7 +141,7 @@ static struct spi_driver ad5930_driver = { .owner = THIS_MODULE, }, .probe = ad5930_probe, - .remove = __devexit_p(ad5930_remove), + .remove = ad5930_remove, }; module_spi_driver(ad5930_driver); diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c index fed39404e34..4e18380c514 100644 --- a/drivers/staging/iio/frequency/ad9832.c +++ b/drivers/staging/iio/frequency/ad9832.c @@ -201,7 +201,7 @@ static const struct iio_info ad9832_info = { .driver_module = THIS_MODULE, }; -static int __devinit ad9832_probe(struct spi_device *spi) +static int ad9832_probe(struct spi_device *spi) { struct ad9832_platform_data *pdata = spi->dev.platform_data; struct iio_dev *indio_dev; @@ -324,7 +324,7 @@ error_put_reg: return ret; } -static int __devexit ad9832_remove(struct spi_device *spi) +static int ad9832_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); struct ad9832_state *st = iio_priv(indio_dev); @@ -352,7 +352,7 @@ static struct spi_driver ad9832_driver = { .owner = THIS_MODULE, }, .probe = ad9832_probe, - .remove = __devexit_p(ad9832_remove), + .remove = ad9832_remove, .id_table = ad9832_id, }; module_spi_driver(ad9832_driver); diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c index 1b2dc741d2c..5cba3c01f41 100644 --- a/drivers/staging/iio/frequency/ad9834.c +++ b/drivers/staging/iio/frequency/ad9834.c @@ -314,7 +314,7 @@ static const struct iio_info ad9833_info = { .driver_module = THIS_MODULE, }; -static int __devinit ad9834_probe(struct spi_device *spi) +static int ad9834_probe(struct spi_device *spi) { struct ad9834_platform_data *pdata = spi->dev.platform_data; struct ad9834_state *st; @@ -424,7 +424,7 @@ error_put_reg: return ret; } -static int __devexit ad9834_remove(struct spi_device *spi) +static int ad9834_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); struct ad9834_state *st = iio_priv(indio_dev); @@ -454,7 +454,7 @@ static struct spi_driver ad9834_driver = { .owner = THIS_MODULE, }, .probe = ad9834_probe, - .remove = __devexit_p(ad9834_remove), + .remove = ad9834_remove, .id_table = ad9834_id, }; module_spi_driver(ad9834_driver); diff --git a/drivers/staging/iio/frequency/ad9850.c b/drivers/staging/iio/frequency/ad9850.c index 74abee054ac..104f7a4905a 100644 --- a/drivers/staging/iio/frequency/ad9850.c +++ b/drivers/staging/iio/frequency/ad9850.c @@ -77,7 +77,7 @@ static const struct iio_info ad9850_info = { .driver_module = THIS_MODULE, }; -static int __devinit ad9850_probe(struct spi_device *spi) +static int ad9850_probe(struct spi_device *spi) { struct ad9850_state *st; struct iio_dev *idev; @@ -113,7 +113,7 @@ error_ret: return ret; } -static int __devexit ad9850_remove(struct spi_device *spi) +static int ad9850_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -127,7 +127,7 @@ static struct spi_driver ad9850_driver = { .owner = THIS_MODULE, }, .probe = ad9850_probe, - .remove = __devexit_p(ad9850_remove), + .remove = ad9850_remove, }; module_spi_driver(ad9850_driver); diff --git a/drivers/staging/iio/frequency/ad9852.c b/drivers/staging/iio/frequency/ad9852.c index fd9d14a413a..17ac825b3d2 100644 --- a/drivers/staging/iio/frequency/ad9852.c +++ b/drivers/staging/iio/frequency/ad9852.c @@ -226,7 +226,7 @@ static const struct iio_info ad9852_info = { .driver_module = THIS_MODULE, }; -static int __devinit ad9852_probe(struct spi_device *spi) +static int ad9852_probe(struct spi_device *spi) { struct ad9852_state *st; struct iio_dev *idev; @@ -264,7 +264,7 @@ error_ret: return ret; } -static int __devexit ad9852_remove(struct spi_device *spi) +static int ad9852_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -278,7 +278,7 @@ static struct spi_driver ad9852_driver = { .owner = THIS_MODULE, }, .probe = ad9852_probe, - .remove = __devexit_p(ad9852_remove), + .remove = ad9852_remove, }; module_spi_driver(ad9852_driver); diff --git a/drivers/staging/iio/frequency/ad9910.c b/drivers/staging/iio/frequency/ad9910.c index 5a7ba305b75..e48f874c1fc 100644 --- a/drivers/staging/iio/frequency/ad9910.c +++ b/drivers/staging/iio/frequency/ad9910.c @@ -361,7 +361,7 @@ static const struct iio_info ad9910_info = { .driver_module = THIS_MODULE, }; -static int __devinit ad9910_probe(struct spi_device *spi) +static int ad9910_probe(struct spi_device *spi) { struct ad9910_state *st; struct iio_dev *idev; @@ -397,7 +397,7 @@ error_ret: return ret; } -static int __devexit ad9910_remove(struct spi_device *spi) +static int ad9910_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -411,7 +411,7 @@ static struct spi_driver ad9910_driver = { .owner = THIS_MODULE, }, .probe = ad9910_probe, - .remove = __devexit_p(ad9910_remove), + .remove = ad9910_remove, }; module_spi_driver(ad9910_driver); diff --git a/drivers/staging/iio/frequency/ad9951.c b/drivers/staging/iio/frequency/ad9951.c index ba6f49ff09a..8234e3c915c 100644 --- a/drivers/staging/iio/frequency/ad9951.c +++ b/drivers/staging/iio/frequency/ad9951.c @@ -170,7 +170,7 @@ static const struct iio_info ad9951_info = { .driver_module = THIS_MODULE, }; -static int __devinit ad9951_probe(struct spi_device *spi) +static int ad9951_probe(struct spi_device *spi) { struct ad9951_state *st; struct iio_dev *idev; @@ -208,7 +208,7 @@ error_ret: return ret; } -static int __devexit ad9951_remove(struct spi_device *spi) +static int ad9951_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -222,7 +222,7 @@ static struct spi_driver ad9951_driver = { .owner = THIS_MODULE, }, .probe = ad9951_probe, - .remove = __devexit_p(ad9951_remove), + .remove = ad9951_remove, }; module_spi_driver(ad9951_driver); diff --git a/drivers/staging/iio/gyro/Makefile b/drivers/staging/iio/gyro/Makefile index 9ba5ec15170..1303569e5c8 100644 --- a/drivers/staging/iio/gyro/Makefile +++ b/drivers/staging/iio/gyro/Makefile @@ -12,7 +12,6 @@ adis16130-y := adis16130_core.o obj-$(CONFIG_ADIS16130) += adis16130.o adis16260-y := adis16260_core.o -adis16260-$(CONFIG_IIO_BUFFER) += adis16260_ring.o adis16260_trigger.o obj-$(CONFIG_ADIS16260) += adis16260.o adis16251-y := adis16251_core.o diff --git a/drivers/staging/iio/gyro/adis16060_core.c b/drivers/staging/iio/gyro/adis16060_core.c index 87151a7cff0..687c151f984 100644 --- a/drivers/staging/iio/gyro/adis16060_core.c +++ b/drivers/staging/iio/gyro/adis16060_core.c @@ -145,7 +145,7 @@ static const struct iio_chan_spec adis16060_channels[] = { } }; -static int __devinit adis16060_r_probe(struct spi_device *spi) +static int adis16060_r_probe(struct spi_device *spi) { int ret; struct adis16060_state *st; @@ -184,7 +184,7 @@ error_ret: } /* fixme, confirm ordering in this function */ -static int __devexit adis16060_r_remove(struct spi_device *spi) +static int adis16060_r_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -192,7 +192,7 @@ static int __devexit adis16060_r_remove(struct spi_device *spi) return 0; } -static int __devinit adis16060_w_probe(struct spi_device *spi) +static int adis16060_w_probe(struct spi_device *spi) { int ret; struct iio_dev *indio_dev = adis16060_iio_dev; @@ -210,7 +210,7 @@ error_ret: return ret; } -static int __devexit adis16060_w_remove(struct spi_device *spi) +static int adis16060_w_remove(struct spi_device *spi) { return 0; } @@ -221,7 +221,7 @@ static struct spi_driver adis16060_r_driver = { .owner = THIS_MODULE, }, .probe = adis16060_r_probe, - .remove = __devexit_p(adis16060_r_remove), + .remove = adis16060_r_remove, }; static struct spi_driver adis16060_w_driver = { @@ -230,7 +230,7 @@ static struct spi_driver adis16060_w_driver = { .owner = THIS_MODULE, }, .probe = adis16060_w_probe, - .remove = __devexit_p(adis16060_w_remove), + .remove = adis16060_w_remove, }; static __init int adis16060_init(void) diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c index a73902573f7..3525a68d6a7 100644 --- a/drivers/staging/iio/gyro/adis16080_core.c +++ b/drivers/staging/iio/gyro/adis16080_core.c @@ -138,7 +138,7 @@ static const struct iio_info adis16080_info = { .driver_module = THIS_MODULE, }; -static int __devinit adis16080_probe(struct spi_device *spi) +static int adis16080_probe(struct spi_device *spi) { int ret; struct adis16080_state *st; @@ -177,7 +177,7 @@ error_ret: } /* fixme, confirm ordering in this function */ -static int __devexit adis16080_remove(struct spi_device *spi) +static int adis16080_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -191,7 +191,7 @@ static struct spi_driver adis16080_driver = { .owner = THIS_MODULE, }, .probe = adis16080_probe, - .remove = __devexit_p(adis16080_remove), + .remove = adis16080_remove, }; module_spi_driver(adis16080_driver); diff --git a/drivers/staging/iio/gyro/adis16130_core.c b/drivers/staging/iio/gyro/adis16130_core.c index fbf96b0b6ee..835801ee7e8 100644 --- a/drivers/staging/iio/gyro/adis16130_core.c +++ b/drivers/staging/iio/gyro/adis16130_core.c @@ -116,7 +116,7 @@ static const struct iio_info adis16130_info = { .driver_module = THIS_MODULE, }; -static int __devinit adis16130_probe(struct spi_device *spi) +static int adis16130_probe(struct spi_device *spi) { int ret; struct adis16130_state *st; @@ -154,7 +154,7 @@ error_ret: } /* fixme, confirm ordering in this function */ -static int __devexit adis16130_remove(struct spi_device *spi) +static int adis16130_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -168,7 +168,7 @@ static struct spi_driver adis16130_driver = { .owner = THIS_MODULE, }, .probe = adis16130_probe, - .remove = __devexit_p(adis16130_remove), + .remove = adis16130_remove, }; module_spi_driver(adis16130_driver); diff --git a/drivers/staging/iio/gyro/adis16260.h b/drivers/staging/iio/gyro/adis16260.h index 4c4b25129c6..df3c0b7e954 100644 --- a/drivers/staging/iio/gyro/adis16260.h +++ b/drivers/staging/iio/gyro/adis16260.h @@ -1,12 +1,11 @@ #ifndef SPI_ADIS16260_H_ #define SPI_ADIS16260_H_ + #include "adis16260_platform_data.h" +#include <linux/iio/imu/adis.h> #define ADIS16260_STARTUP_DELAY 220 /* ms */ -#define ADIS16260_READ_REG(a) a -#define ADIS16260_WRITE_REG(a) ((a) | 0x80) - #define ADIS16260_FLASH_CNT 0x00 /* Flash memory write count */ #define ADIS16260_SUPPLY_OUT 0x02 /* Power supply measurement */ #define ADIS16260_GYRO_OUT 0x04 /* X-axis gyroscope output */ @@ -34,8 +33,6 @@ * convert to decimal = 16,265/16,260 */ #define ADIS16260_SERIAL_NUM 0x58 /* Serial number */ -#define ADIS16260_OUTPUTS 5 - #define ADIS16260_ERROR_ACTIVE (1<<14) #define ADIS16260_NEW_DATA (1<<15) @@ -60,13 +57,13 @@ /* DIAG_STAT */ #define ADIS16260_DIAG_STAT_ALARM2 (1<<9) #define ADIS16260_DIAG_STAT_ALARM1 (1<<8) -#define ADIS16260_DIAG_STAT_FLASH_CHK (1<<6) -#define ADIS16260_DIAG_STAT_SELF_TEST (1<<5) -#define ADIS16260_DIAG_STAT_OVERFLOW (1<<4) -#define ADIS16260_DIAG_STAT_SPI_FAIL (1<<3) -#define ADIS16260_DIAG_STAT_FLASH_UPT (1<<2) -#define ADIS16260_DIAG_STAT_POWER_HIGH (1<<1) -#define ADIS16260_DIAG_STAT_POWER_LOW (1<<0) +#define ADIS16260_DIAG_STAT_FLASH_CHK_BIT 6 +#define ADIS16260_DIAG_STAT_SELF_TEST_BIT 5 +#define ADIS16260_DIAG_STAT_OVERFLOW_BIT 4 +#define ADIS16260_DIAG_STAT_SPI_FAIL_BIT 3 +#define ADIS16260_DIAG_STAT_FLASH_UPT_BIT 2 +#define ADIS16260_DIAG_STAT_POWER_HIGH_BIT 1 +#define ADIS16260_DIAG_STAT_POWER_LOW_BIT 0 /* GLOB_CMD */ #define ADIS16260_GLOB_CMD_SW_RESET (1<<7) @@ -75,82 +72,27 @@ #define ADIS16260_GLOB_CMD_FAC_CALIB (1<<1) #define ADIS16260_GLOB_CMD_AUTO_NULL (1<<0) -#define ADIS16260_MAX_TX 24 -#define ADIS16260_MAX_RX 24 - #define ADIS16260_SPI_SLOW (u32)(300 * 1000) #define ADIS16260_SPI_BURST (u32)(1000 * 1000) #define ADIS16260_SPI_FAST (u32)(2000 * 1000) /** * struct adis16260_state - device instance specific data - * @us: actual spi_device - * @trig: data ready trigger registered with iio - * @buf_lock: mutex to protect tx and rx * @negate: negate the scale parameter - * @tx: transmit buffer - * @rx: receive buffer **/ struct adis16260_state { - struct spi_device *us; - struct iio_trigger *trig; - struct mutex buf_lock; - unsigned negate:1; - u8 tx[ADIS16260_MAX_TX] ____cacheline_aligned; - u8 rx[ADIS16260_MAX_RX]; + unsigned negate:1; + struct adis adis; }; -int adis16260_set_irq(struct iio_dev *indio_dev, bool enable); - /* At the moment triggers are only used for ring buffer * filling. This may change! */ -#define ADIS16260_SCAN_SUPPLY 0 -#define ADIS16260_SCAN_GYRO 1 +#define ADIS16260_SCAN_GYRO 0 +#define ADIS16260_SCAN_SUPPLY 1 #define ADIS16260_SCAN_AUX_ADC 2 #define ADIS16260_SCAN_TEMP 3 #define ADIS16260_SCAN_ANGL 4 -#ifdef CONFIG_IIO_BUFFER -void adis16260_remove_trigger(struct iio_dev *indio_dev); -int adis16260_probe_trigger(struct iio_dev *indio_dev); - -ssize_t adis16260_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf); - - -int adis16260_configure_ring(struct iio_dev *indio_dev); -void adis16260_unconfigure_ring(struct iio_dev *indio_dev); - -#else /* CONFIG_IIO_BUFFER */ - -static inline void adis16260_remove_trigger(struct iio_dev *indio_dev) -{ -} - -static inline int adis16260_probe_trigger(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline ssize_t -adis16260_read_data_from_ring(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return 0; -} - -static int adis16260_configure_ring(struct iio_dev *indio_dev) -{ - return 0; -} - -static inline void adis16260_unconfigure_ring(struct iio_dev *indio_dev) -{ -} - -#endif /* CONFIG_IIO_BUFFER */ #endif /* SPI_ADIS16260_H_ */ diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c index aa964a2d829..6e80b8c768a 100644 --- a/drivers/staging/iio/gyro/adis16260_core.c +++ b/drivers/staging/iio/gyro/adis16260_core.c @@ -24,134 +24,13 @@ #include "adis16260.h" -#define DRIVER_NAME "adis16260" - -static int adis16260_check_status(struct iio_dev *indio_dev); - -/** - * adis16260_spi_write_reg_8() - write single byte to a register - * @indio_dev: iio_dev for the device - * @reg_address: the address of the register to be written - * @val: the value to write - **/ -static int adis16260_spi_write_reg_8(struct iio_dev *indio_dev, - u8 reg_address, - u8 val) -{ - int ret; - struct adis16260_state *st = iio_priv(indio_dev); - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16260_WRITE_REG(reg_address); - st->tx[1] = val; - - ret = spi_write(st->us, st->tx, 2); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16260_spi_write_reg_16() - write 2 bytes to a pair of registers - * @indio_dev: iio_dev for the device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: value to be written - **/ -static int adis16260_spi_write_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 value) -{ - int ret; - struct spi_message msg; - struct adis16260_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 20, - }, { - .tx_buf = st->tx + 2, - .bits_per_word = 8, - .len = 2, - .delay_usecs = 20, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16260_WRITE_REG(lower_reg_address); - st->tx[1] = value & 0xFF; - st->tx[2] = ADIS16260_WRITE_REG(lower_reg_address + 1); - st->tx[3] = (value >> 8) & 0xFF; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - mutex_unlock(&st->buf_lock); - - return ret; -} - -/** - * adis16260_spi_read_reg_16() - read 2 bytes from a 16-bit register - * @indio_dev: iio_dev for the device - * @reg_address: the address of the lower of the two registers. Second register - * is assumed to have address one greater. - * @val: somewhere to pass back the value read - **/ -static int adis16260_spi_read_reg_16(struct iio_dev *indio_dev, - u8 lower_reg_address, - u16 *val) -{ - struct spi_message msg; - struct adis16260_state *st = iio_priv(indio_dev); - int ret; - struct spi_transfer xfers[] = { - { - .tx_buf = st->tx, - .bits_per_word = 8, - .len = 2, - .cs_change = 1, - .delay_usecs = 30, - }, { - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 2, - .delay_usecs = 30, - }, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADIS16260_READ_REG(lower_reg_address); - st->tx[1] = 0; - - spi_message_init(&msg); - spi_message_add_tail(&xfers[0], &msg); - spi_message_add_tail(&xfers[1], &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, - "problem when reading 16 bit register 0x%02X", - lower_reg_address); - goto error_ret; - } - *val = (st->rx[0] << 8) | st->rx[1]; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - static ssize_t adis16260_read_frequency_available(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct adis16260_state *st = iio_priv(indio_dev); - if (spi_get_device_id(st->us)->driver_data) + if (spi_get_device_id(st->adis.spi)->driver_data) return sprintf(buf, "%s\n", "0.129 ~ 256"); else return sprintf(buf, "%s\n", "256 2048"); @@ -166,13 +45,11 @@ static ssize_t adis16260_read_frequency(struct device *dev, int ret, len = 0; u16 t; int sps; - ret = adis16260_spi_read_reg_16(indio_dev, - ADIS16260_SMPL_PRD, - &t); + ret = adis_read_reg_16(&st->adis, ADIS16260_SMPL_PRD, &t); if (ret) return ret; - if (spi_get_device_id(st->us)->driver_data) /* If an adis16251 */ + if (spi_get_device_id(st->adis.spi)->driver_data) /* If an adis16251 */ sps = (t & ADIS16260_SMPL_PRD_TIME_BASE) ? 8 : 256; else sps = (t & ADIS16260_SMPL_PRD_TIME_BASE) ? 66 : 2048; @@ -199,7 +76,7 @@ static ssize_t adis16260_write_frequency(struct device *dev, return -EINVAL; mutex_lock(&indio_dev->mlock); - if (spi_get_device_id(st->us)) { + if (spi_get_device_id(st->adis.spi)->driver_data) { t = (256 / val); if (t > 0) t--; @@ -211,10 +88,10 @@ static ssize_t adis16260_write_frequency(struct device *dev, t &= ADIS16260_SMPL_PRD_DIV_MASK; } if ((t & ADIS16260_SMPL_PRD_DIV_MASK) >= 0x0A) - st->us->max_speed_hz = ADIS16260_SPI_SLOW; + st->adis.spi->max_speed_hz = ADIS16260_SPI_SLOW; else - st->us->max_speed_hz = ADIS16260_SPI_FAST; - ret = adis16260_spi_write_reg_8(indio_dev, + st->adis.spi->max_speed_hz = ADIS16260_SPI_FAST; + ret = adis_write_reg_8(&st->adis, ADIS16260_SMPL_PRD, t); @@ -223,140 +100,20 @@ static ssize_t adis16260_write_frequency(struct device *dev, return ret ? ret : len; } -static int adis16260_reset(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16260_spi_write_reg_8(indio_dev, - ADIS16260_GLOB_CMD, - ADIS16260_GLOB_CMD_SW_RESET); - if (ret) - dev_err(&indio_dev->dev, "problem resetting device"); - - return ret; -} - -int adis16260_set_irq(struct iio_dev *indio_dev, bool enable) -{ - int ret; - u16 msc; - ret = adis16260_spi_read_reg_16(indio_dev, ADIS16260_MSC_CTRL, &msc); - if (ret) - goto error_ret; - - msc |= ADIS16260_MSC_CTRL_DATA_RDY_POL_HIGH; - if (enable) - msc |= ADIS16260_MSC_CTRL_DATA_RDY_EN; - else - msc &= ~ADIS16260_MSC_CTRL_DATA_RDY_EN; - - ret = adis16260_spi_write_reg_16(indio_dev, ADIS16260_MSC_CTRL, msc); - if (ret) - goto error_ret; - -error_ret: - return ret; -} - /* Power down the device */ static int adis16260_stop_device(struct iio_dev *indio_dev) { + struct adis16260_state *st = iio_priv(indio_dev); int ret; u16 val = ADIS16260_SLP_CNT_POWER_OFF; - ret = adis16260_spi_write_reg_16(indio_dev, ADIS16260_SLP_CNT, val); + ret = adis_write_reg_16(&st->adis, ADIS16260_SLP_CNT, val); if (ret) dev_err(&indio_dev->dev, "problem with turning device off: SLP_CNT"); return ret; } -static int adis16260_self_test(struct iio_dev *indio_dev) -{ - int ret; - ret = adis16260_spi_write_reg_16(indio_dev, - ADIS16260_MSC_CTRL, - ADIS16260_MSC_CTRL_MEM_TEST); - if (ret) { - dev_err(&indio_dev->dev, "problem starting self test"); - goto err_ret; - } - - adis16260_check_status(indio_dev); - -err_ret: - return ret; -} - -static int adis16260_check_status(struct iio_dev *indio_dev) -{ - u16 status; - int ret; - struct device *dev = &indio_dev->dev; - - ret = adis16260_spi_read_reg_16(indio_dev, - ADIS16260_DIAG_STAT, - &status); - - if (ret < 0) { - dev_err(dev, "Reading status failed\n"); - goto error_ret; - } - ret = status & 0x7F; - if (status & ADIS16260_DIAG_STAT_FLASH_CHK) - dev_err(dev, "Flash checksum error\n"); - if (status & ADIS16260_DIAG_STAT_SELF_TEST) - dev_err(dev, "Self test error\n"); - if (status & ADIS16260_DIAG_STAT_OVERFLOW) - dev_err(dev, "Sensor overrange\n"); - if (status & ADIS16260_DIAG_STAT_SPI_FAIL) - dev_err(dev, "SPI failure\n"); - if (status & ADIS16260_DIAG_STAT_FLASH_UPT) - dev_err(dev, "Flash update failed\n"); - if (status & ADIS16260_DIAG_STAT_POWER_HIGH) - dev_err(dev, "Power supply above 5.25V\n"); - if (status & ADIS16260_DIAG_STAT_POWER_LOW) - dev_err(dev, "Power supply below 4.75V\n"); - -error_ret: - return ret; -} - -static int adis16260_initial_setup(struct iio_dev *indio_dev) -{ - int ret; - struct device *dev = &indio_dev->dev; - - /* Disable IRQ */ - ret = adis16260_set_irq(indio_dev, false); - if (ret) { - dev_err(dev, "disable irq failed"); - goto err_ret; - } - - /* Do self test */ - ret = adis16260_self_test(indio_dev); - if (ret) { - dev_err(dev, "self test failure"); - goto err_ret; - } - - /* Read status register to check the result */ - ret = adis16260_check_status(indio_dev); - if (ret) { - adis16260_reset(indio_dev); - dev_err(dev, "device not playing ball -> reset"); - msleep(ADIS16260_STARTUP_DELAY); - ret = adis16260_check_status(indio_dev); - if (ret) { - dev_err(dev, "giving up"); - goto err_ret; - } - } - -err_ret: - return ret; -} - static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, adis16260_read_frequency, adis16260_write_frequency); @@ -364,100 +121,26 @@ static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, static IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, adis16260_read_frequency_available, NULL, 0); -enum adis16260_channel { - gyro, - temp, - in_supply, - in_aux, - angle, -}; #define ADIS16260_GYRO_CHANNEL_SET(axis, mod) \ - struct iio_chan_spec adis16260_channels_##axis[] = { \ - { \ - .type = IIO_ANGL_VEL, \ - .modified = 1, \ - .channel2 = mod, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \ - IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ - .address = gyro, \ - .scan_index = ADIS16260_SCAN_GYRO, \ - .scan_type = { \ - .sign = 's', \ - .realbits = 14, \ - .storagebits = 16, \ - }, \ - }, { \ - .type = IIO_ANGL, \ - .modified = 1, \ - .channel2 = mod, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, \ - .address = angle, \ - .scan_index = ADIS16260_SCAN_ANGL, \ - .scan_type = { \ - .sign = 'u', \ - .realbits = 14, \ - .storagebits = 16, \ - }, \ - }, { \ - .type = IIO_TEMP, \ - .indexed = 1, \ - .channel = 0, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ - .address = temp, \ - .scan_index = ADIS16260_SCAN_TEMP, \ - .scan_type = { \ - .sign = 'u', \ - .realbits = 12, \ - .storagebits = 16, \ - }, \ - }, { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .channel = 0, \ - .extend_name = "supply", \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ - .address = in_supply, \ - .scan_index = ADIS16260_SCAN_SUPPLY, \ - .scan_type = { \ - .sign = 'u', \ - .realbits = 12, \ - .storagebits = 16, \ - }, \ - }, { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .channel = 1, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ - .address = in_aux, \ - .scan_index = ADIS16260_SCAN_AUX_ADC, \ - .scan_type = { \ - .sign = 'u', \ - .realbits = 12, \ - .storagebits = 16, \ - }, \ - }, \ - IIO_CHAN_SOFT_TIMESTAMP(5), \ - } +struct iio_chan_spec adis16260_channels_##axis[] = { \ + ADIS_GYRO_CHAN(mod, ADIS16260_GYRO_OUT, ADIS16260_SCAN_GYRO, \ + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \ + IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, 14), \ + ADIS_INCLI_CHAN(mod, ADIS16260_ANGL_OUT, ADIS16260_SCAN_ANGL, 0, 14), \ + ADIS_TEMP_CHAN(ADIS16260_TEMP_OUT, ADIS16260_SCAN_TEMP, 12), \ + ADIS_SUPPLY_CHAN(ADIS16260_SUPPLY_OUT, ADIS16260_SCAN_SUPPLY, 12), \ + ADIS_AUX_ADC_CHAN(ADIS16260_AUX_ADC, ADIS16260_SCAN_AUX_ADC, 12), \ + IIO_CHAN_SOFT_TIMESTAMP(5), \ +} + +static const ADIS16260_GYRO_CHANNEL_SET(x, X); +static const ADIS16260_GYRO_CHANNEL_SET(y, Y); +static const ADIS16260_GYRO_CHANNEL_SET(z, Z); -static const ADIS16260_GYRO_CHANNEL_SET(x, IIO_MOD_X); -static const ADIS16260_GYRO_CHANNEL_SET(y, IIO_MOD_Y); -static const ADIS16260_GYRO_CHANNEL_SET(z, IIO_MOD_Z); - -static const u8 adis16260_addresses[5][3] = { - [gyro] = { ADIS16260_GYRO_OUT, - ADIS16260_GYRO_OFF, - ADIS16260_GYRO_SCALE }, - [angle] = { ADIS16260_ANGL_OUT }, - [in_supply] = { ADIS16260_SUPPLY_OUT }, - [in_aux] = { ADIS16260_AUX_ADC }, - [temp] = { ADIS16260_TEMP_OUT }, +static const u8 adis16260_addresses[][2] = { + [ADIS16260_SCAN_GYRO] = { ADIS16260_GYRO_OFF, ADIS16260_GYRO_SCALE }, }; + static int adis16260_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, @@ -471,34 +154,13 @@ static int adis16260_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); - addr = adis16260_addresses[chan->address][0]; - ret = adis16260_spi_read_reg_16(indio_dev, addr, &val16); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - - if (val16 & ADIS16260_ERROR_ACTIVE) { - ret = adis16260_check_status(indio_dev); - if (ret) { - mutex_unlock(&indio_dev->mlock); - return ret; - } - } - val16 = val16 & ((1 << chan->scan_type.realbits) - 1); - if (chan->scan_type.sign == 's') - val16 = (s16)(val16 << - (16 - chan->scan_type.realbits)) >> - (16 - chan->scan_type.realbits); - *val = val16; - mutex_unlock(&indio_dev->mlock); - return IIO_VAL_INT; + return adis_single_conversion(indio_dev, chan, + ADIS16260_ERROR_ACTIVE, val); case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_ANGL_VEL: *val = 0; - if (spi_get_device_id(st->us)->driver_data) { + if (spi_get_device_id(st->adis.spi)->driver_data) { /* 0.01832 degree / sec */ *val2 = IIO_DEGREE_TO_RAD(18320); } else { @@ -533,10 +195,10 @@ static int adis16260_read_raw(struct iio_dev *indio_dev, break; default: return -EINVAL; - }; + } mutex_lock(&indio_dev->mlock); - addr = adis16260_addresses[chan->address][1]; - ret = adis16260_spi_read_reg_16(indio_dev, addr, &val16); + addr = adis16260_addresses[chan->scan_index][0]; + ret = adis_read_reg_16(&st->adis, addr, &val16); if (ret) { mutex_unlock(&indio_dev->mlock); return ret; @@ -553,10 +215,10 @@ static int adis16260_read_raw(struct iio_dev *indio_dev, break; default: return -EINVAL; - }; + } mutex_lock(&indio_dev->mlock); - addr = adis16260_addresses[chan->address][2]; - ret = adis16260_spi_read_reg_16(indio_dev, addr, &val16); + addr = adis16260_addresses[chan->scan_index][1]; + ret = adis_read_reg_16(&st->adis, addr, &val16); if (ret) { mutex_unlock(&indio_dev->mlock); return ret; @@ -574,18 +236,19 @@ static int adis16260_write_raw(struct iio_dev *indio_dev, int val2, long mask) { + struct adis16260_state *st = iio_priv(indio_dev); int bits = 12; s16 val16; u8 addr; switch (mask) { case IIO_CHAN_INFO_CALIBBIAS: val16 = val & ((1 << bits) - 1); - addr = adis16260_addresses[chan->address][1]; - return adis16260_spi_write_reg_16(indio_dev, addr, val16); + addr = adis16260_addresses[chan->scan_index][0]; + return adis_write_reg_16(&st->adis, addr, val16); case IIO_CHAN_INFO_CALIBSCALE: val16 = val & ((1 << bits) - 1); - addr = adis16260_addresses[chan->address][2]; - return adis16260_spi_write_reg_16(indio_dev, addr, val16); + addr = adis16260_addresses[chan->scan_index][1]; + return adis_write_reg_16(&st->adis, addr, val16); } return -EINVAL; } @@ -604,10 +267,41 @@ static const struct iio_info adis16260_info = { .attrs = &adis16260_attribute_group, .read_raw = &adis16260_read_raw, .write_raw = &adis16260_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module = THIS_MODULE, }; -static int __devinit adis16260_probe(struct spi_device *spi) +static const char * const adis1620_status_error_msgs[] = { + [ADIS16260_DIAG_STAT_FLASH_CHK_BIT] = "Flash checksum error", + [ADIS16260_DIAG_STAT_SELF_TEST_BIT] = "Self test error", + [ADIS16260_DIAG_STAT_OVERFLOW_BIT] = "Sensor overrange", + [ADIS16260_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure", + [ADIS16260_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed", + [ADIS16260_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 5.25", + [ADIS16260_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 4.75", +}; + +static const struct adis_data adis16260_data = { + .write_delay = 30, + .read_delay = 30, + .msc_ctrl_reg = ADIS16260_MSC_CTRL, + .glob_cmd_reg = ADIS16260_GLOB_CMD, + .diag_stat_reg = ADIS16260_DIAG_STAT, + + .self_test_mask = ADIS16260_MSC_CTRL_MEM_TEST, + .startup_delay = ADIS16260_STARTUP_DELAY, + + .status_error_msgs = adis1620_status_error_msgs, + .status_error_mask = BIT(ADIS16260_DIAG_STAT_FLASH_CHK_BIT) | + BIT(ADIS16260_DIAG_STAT_SELF_TEST_BIT) | + BIT(ADIS16260_DIAG_STAT_OVERFLOW_BIT) | + BIT(ADIS16260_DIAG_STAT_SPI_FAIL_BIT) | + BIT(ADIS16260_DIAG_STAT_FLASH_UPT_BIT) | + BIT(ADIS16260_DIAG_STAT_POWER_HIGH_BIT) | + BIT(ADIS16260_DIAG_STAT_POWER_LOW_BIT), +}; + +static int adis16260_probe(struct spi_device *spi) { int ret; struct adis16260_platform_data *pd = spi->dev.platform_data; @@ -626,10 +320,7 @@ static int __devinit adis16260_probe(struct spi_device *spi) /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); - st->us = spi; - mutex_init(&st->buf_lock); - - indio_dev->name = spi_get_device_id(st->us)->name; + indio_dev->name = spi_get_device_id(spi)->name; indio_dev->dev.parent = &spi->dev; indio_dev->info = &adis16260_info; indio_dev->num_channels @@ -653,17 +344,14 @@ static int __devinit adis16260_probe(struct spi_device *spi) indio_dev->num_channels = ARRAY_SIZE(adis16260_channels_x); indio_dev->modes = INDIO_DIRECT_MODE; - ret = adis16260_configure_ring(indio_dev); + ret = adis_init(&st->adis, indio_dev, spi, &adis16260_data); + if (ret) + goto error_free_dev; + + ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, NULL); if (ret) goto error_free_dev; - ret = iio_buffer_register(indio_dev, - indio_dev->channels, - ARRAY_SIZE(adis16260_channels_x)); - if (ret) { - printk(KERN_ERR "failed to initialize the ring\n"); - goto error_unreg_ring_funcs; - } if (indio_dev->buffer) { /* Set default scan mode */ iio_scan_mask_set(indio_dev, indio_dev->buffer, @@ -677,43 +365,33 @@ static int __devinit adis16260_probe(struct spi_device *spi) iio_scan_mask_set(indio_dev, indio_dev->buffer, ADIS16260_SCAN_ANGL); } - if (spi->irq) { - ret = adis16260_probe_trigger(indio_dev); - if (ret) - goto error_uninitialize_ring; - } /* Get the device into a sane initial state */ - ret = adis16260_initial_setup(indio_dev); + ret = adis_initial_startup(&st->adis); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; ret = iio_device_register(indio_dev); if (ret) - goto error_remove_trigger; + goto error_cleanup_buffer_trigger; return 0; -error_remove_trigger: - adis16260_remove_trigger(indio_dev); -error_uninitialize_ring: - iio_buffer_unregister(indio_dev); -error_unreg_ring_funcs: - adis16260_unconfigure_ring(indio_dev); +error_cleanup_buffer_trigger: + adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); error_free_dev: iio_device_free(indio_dev); error_ret: return ret; } -static int __devexit adis16260_remove(struct spi_device *spi) +static int adis16260_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct adis16260_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); adis16260_stop_device(indio_dev); - adis16260_remove_trigger(indio_dev); - iio_buffer_unregister(indio_dev); - adis16260_unconfigure_ring(indio_dev); + adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); iio_device_free(indio_dev); return 0; @@ -739,7 +417,7 @@ static struct spi_driver adis16260_driver = { .owner = THIS_MODULE, }, .probe = adis16260_probe, - .remove = __devexit_p(adis16260_remove), + .remove = adis16260_remove, .id_table = adis16260_id, }; module_spi_driver(adis16260_driver); diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c deleted file mode 100644 index e294cb49736..00000000000 --- a/drivers/staging/iio/gyro/adis16260_ring.c +++ /dev/null @@ -1,136 +0,0 @@ -#include <linux/export.h> -#include <linux/interrupt.h> -#include <linux/mutex.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/slab.h> - -#include <linux/iio/iio.h> -#include "../ring_sw.h" -#include <linux/iio/trigger_consumer.h> -#include "adis16260.h" - -/** - * adis16260_read_ring_data() read data registers which will be placed into ring - * @indio_dev: the IIO device - * @rx: somewhere to pass back the value read - **/ -static int adis16260_read_ring_data(struct iio_dev *indio_dev, u8 *rx) -{ - struct spi_message msg; - struct adis16260_state *st = iio_priv(indio_dev); - struct spi_transfer xfers[ADIS16260_OUTPUTS + 1]; - int ret; - int i; - - mutex_lock(&st->buf_lock); - - spi_message_init(&msg); - - memset(xfers, 0, sizeof(xfers)); - for (i = 0; i <= ADIS16260_OUTPUTS; i++) { - xfers[i].bits_per_word = 8; - xfers[i].cs_change = 1; - xfers[i].len = 2; - xfers[i].delay_usecs = 30; - xfers[i].tx_buf = st->tx + 2 * i; - if (i < 2) /* SUPPLY_OUT:0x02 GYRO_OUT:0x04 */ - st->tx[2 * i] - = ADIS16260_READ_REG(ADIS16260_SUPPLY_OUT - + 2 * i); - else /* 0x06 to 0x09 is reserved */ - st->tx[2 * i] - = ADIS16260_READ_REG(ADIS16260_SUPPLY_OUT - + 2 * i + 4); - st->tx[2 * i + 1] = 0; - if (i >= 1) - xfers[i].rx_buf = rx + 2 * (i - 1); - spi_message_add_tail(&xfers[i], &msg); - } - - ret = spi_sync(st->us, &msg); - if (ret) - dev_err(&st->us->dev, "problem when burst reading"); - - mutex_unlock(&st->buf_lock); - - return ret; -} - -static irqreturn_t adis16260_trigger_handler(int irq, void *p) -{ - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; - struct adis16260_state *st = iio_priv(indio_dev); - int i = 0; - s16 *data; - - data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (data == NULL) { - dev_err(&st->us->dev, "memory alloc failed in ring bh"); - goto done; - } - - if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && - adis16260_read_ring_data(indio_dev, st->rx) >= 0) - for (; i < bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); i++) - data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); - - /* Guaranteed to be aligned with 8 byte boundary */ - if (indio_dev->scan_timestamp) - *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; - - iio_push_to_buffer(indio_dev->buffer, (u8 *)data); - - kfree(data); -done: - iio_trigger_notify_done(indio_dev->trig); - - return IRQ_HANDLED; -} - -void adis16260_unconfigure_ring(struct iio_dev *indio_dev) -{ - iio_dealloc_pollfunc(indio_dev->pollfunc); - iio_sw_rb_free(indio_dev->buffer); -} - -static const struct iio_buffer_setup_ops adis16260_ring_setup_ops = { - .preenable = &iio_sw_buffer_preenable, - .postenable = &iio_triggered_buffer_postenable, - .predisable = &iio_triggered_buffer_predisable, -}; - -int adis16260_configure_ring(struct iio_dev *indio_dev) -{ - int ret = 0; - struct iio_buffer *ring; - - ring = iio_sw_rb_allocate(indio_dev); - if (!ring) { - ret = -ENOMEM; - return ret; - } - indio_dev->buffer = ring; - ring->scan_timestamp = true; - indio_dev->setup_ops = &adis16260_ring_setup_ops; - - indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time, - &adis16260_trigger_handler, - IRQF_ONESHOT, - indio_dev, - "adis16260_consumer%d", - indio_dev->id); - if (indio_dev->pollfunc == NULL) { - ret = -ENOMEM; - goto error_iio_sw_rb_free; - } - - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; - return 0; - -error_iio_sw_rb_free: - iio_sw_rb_free(indio_dev->buffer); - return ret; -} diff --git a/drivers/staging/iio/gyro/adis16260_trigger.c b/drivers/staging/iio/gyro/adis16260_trigger.c deleted file mode 100644 index 034559e4d5b..00000000000 --- a/drivers/staging/iio/gyro/adis16260_trigger.c +++ /dev/null @@ -1,75 +0,0 @@ -#include <linux/interrupt.h> -#include <linux/kernel.h> -#include <linux/spi/spi.h> -#include <linux/export.h> - -#include <linux/iio/iio.h> -#include <linux/iio/trigger.h> -#include "adis16260.h" - -/** - * adis16260_data_rdy_trigger_set_state() set datardy interrupt state - **/ -static int adis16260_data_rdy_trigger_set_state(struct iio_trigger *trig, - bool state) -{ - struct iio_dev *indio_dev = trig->private_data; - - dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); - return adis16260_set_irq(indio_dev, state); -} - -static const struct iio_trigger_ops adis16260_trigger_ops = { - .owner = THIS_MODULE, - .set_trigger_state = &adis16260_data_rdy_trigger_set_state, -}; - -int adis16260_probe_trigger(struct iio_dev *indio_dev) -{ - int ret; - struct adis16260_state *st = iio_priv(indio_dev); - - st->trig = iio_trigger_alloc("%s-dev%d", - spi_get_device_id(st->us)->name, - indio_dev->id); - if (st->trig == NULL) { - ret = -ENOMEM; - goto error_ret; - } - - ret = request_irq(st->us->irq, - &iio_trigger_generic_data_rdy_poll, - IRQF_TRIGGER_RISING, - "adis16260", - st->trig); - if (ret) - goto error_free_trig; - - st->trig->dev.parent = &st->us->dev; - st->trig->ops = &adis16260_trigger_ops; - st->trig->private_data = indio_dev; - ret = iio_trigger_register(st->trig); - - /* select default trigger */ - indio_dev->trig = st->trig; - if (ret) - goto error_free_irq; - - return 0; - -error_free_irq: - free_irq(st->us->irq, st->trig); -error_free_trig: - iio_trigger_free(st->trig); -error_ret: - return ret; -} - -void adis16260_remove_trigger(struct iio_dev *indio_dev) -{ - struct adis16260_state *st = iio_priv(indio_dev); - - iio_trigger_unregister(st->trig); - free_irq(st->us->irq, st->trig); - iio_trigger_free(st->trig); -} diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/staging/iio/gyro/adxrs450_core.c index d93527d1591..f0ce81da8ac 100644 --- a/drivers/staging/iio/gyro/adxrs450_core.c +++ b/drivers/staging/iio/gyro/adxrs450_core.c @@ -365,7 +365,7 @@ static const struct iio_info adxrs450_info = { .write_raw = &adxrs450_write_raw, }; -static int __devinit adxrs450_probe(struct spi_device *spi) +static int adxrs450_probe(struct spi_device *spi) { int ret; struct adxrs450_state *st; @@ -409,7 +409,7 @@ error_ret: return ret; } -static int __devexit adxrs450_remove(struct spi_device *spi) +static int adxrs450_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -430,7 +430,7 @@ static struct spi_driver adxrs450_driver = { .owner = THIS_MODULE, }, .probe = adxrs450_probe, - .remove = __devexit_p(adxrs450_remove), + .remove = adxrs450_remove, .id_table = adxrs450_id, }; module_spi_driver(adxrs450_driver); diff --git a/drivers/staging/iio/iio_dummy_evgen.c b/drivers/staging/iio/iio_dummy_evgen.c index 74e24e8aa87..132d278c501 100644 --- a/drivers/staging/iio/iio_dummy_evgen.c +++ b/drivers/staging/iio/iio_dummy_evgen.c @@ -108,7 +108,7 @@ int iio_dummy_evgen_get_irq(void) mutex_lock(&iio_evgen->lock); for (i = 0; i < IIO_EVENTGEN_NO; i++) - if (iio_evgen->inuse[i] == false) { + if (!iio_evgen->inuse[i]) { ret = iio_evgen->base + i; iio_evgen->inuse[i] = true; break; diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c index 5d491227e01..c7a5f97576c 100644 --- a/drivers/staging/iio/iio_hwmon.c +++ b/drivers/staging/iio/iio_hwmon.c @@ -69,7 +69,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st) } } -static int __devinit iio_hwmon_probe(struct platform_device *pdev) +static int iio_hwmon_probe(struct platform_device *pdev) { struct iio_hwmon_state *st; struct sensor_device_attribute *a; @@ -170,7 +170,7 @@ error_ret: return ret; } -static int __devexit iio_hwmon_remove(struct platform_device *pdev) +static int iio_hwmon_remove(struct platform_device *pdev) { struct iio_hwmon_state *st = platform_get_drvdata(pdev); @@ -189,7 +189,7 @@ static struct platform_driver __refdata iio_hwmon_driver = { .owner = THIS_MODULE, }, .probe = iio_hwmon_probe, - .remove = __devexit_p(iio_hwmon_remove), + .remove = iio_hwmon_remove, }; module_platform_driver(iio_hwmon_driver); diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c index dc6c728ea47..a865adf8193 100644 --- a/drivers/staging/iio/iio_simple_dummy.c +++ b/drivers/staging/iio/iio_simple_dummy.c @@ -378,7 +378,7 @@ static int iio_dummy_init_device(struct iio_dev *indio_dev) * const struct i2c_device_id *id) * SPI: iio_dummy_probe(struct spi_device *spi) */ -static int __devinit iio_dummy_probe(int index) +static int iio_dummy_probe(int index) { int ret; struct iio_dev *indio_dev; diff --git a/drivers/staging/iio/iio_simple_dummy_buffer.c b/drivers/staging/iio/iio_simple_dummy_buffer.c index 697d9700db2..dee16f0e757 100644 --- a/drivers/staging/iio/iio_simple_dummy_buffer.c +++ b/drivers/staging/iio/iio_simple_dummy_buffer.c @@ -46,7 +46,6 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; - struct iio_buffer *buffer = indio_dev->buffer; int len = 0; u16 *data; @@ -76,7 +75,7 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p) i < bitmap_weight(indio_dev->active_scan_mask, indio_dev->masklength); i++, j++) { - j = find_next_bit(buffer->scan_mask, + j = find_next_bit(indio_dev->active_scan_mask, indio_dev->masklength, j); /* random access read from the 'device' */ data[i] = fakedata[j]; @@ -87,7 +86,7 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p) if (indio_dev->scan_timestamp) *(s64 *)((u8 *)data + ALIGN(len, sizeof(s64))) = iio_get_time_ns(); - iio_push_to_buffer(buffer, (u8 *)data); + iio_push_to_buffers(indio_dev, (u8 *)data); kfree(data); diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index de21d47f33e..779243d24de 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -647,7 +647,6 @@ static void ad5933_work(struct work_struct *work) struct ad5933_state *st = container_of(work, struct ad5933_state, work.work); struct iio_dev *indio_dev = i2c_get_clientdata(st->client); - struct iio_buffer *ring = indio_dev->buffer; signed short buf[2]; unsigned char status; @@ -677,8 +676,7 @@ static void ad5933_work(struct work_struct *work) } else { buf[0] = be16_to_cpu(buf[0]); } - /* save datum to the ring */ - iio_push_to_buffer(ring, (u8 *)buf); + iio_push_to_buffers(indio_dev, (u8 *)buf); } else { /* no data available - try again later */ schedule_delayed_work(&st->work, st->poll_time_jiffies); @@ -699,7 +697,7 @@ static void ad5933_work(struct work_struct *work) mutex_unlock(&indio_dev->mlock); } -static int __devinit ad5933_probe(struct i2c_client *client, +static int ad5933_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret, voltage_uv = 0; @@ -789,7 +787,7 @@ error_put_reg: return ret; } -static __devexit int ad5933_remove(struct i2c_client *client) +static int ad5933_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); struct ad5933_state *st = iio_priv(indio_dev); @@ -819,7 +817,7 @@ static struct i2c_driver ad5933_driver = { .name = "ad5933", }, .probe = ad5933_probe, - .remove = __devexit_p(ad5933_remove), + .remove = ad5933_remove, .id_table = ad5933_id, }; module_i2c_driver(ad5933_driver); diff --git a/drivers/staging/iio/imu/adis16400.h b/drivers/staging/iio/imu/adis16400.h index 77c601da184..7a105e96646 100644 --- a/drivers/staging/iio/imu/adis16400.h +++ b/drivers/staging/iio/imu/adis16400.h @@ -123,6 +123,9 @@ /* SLP_CNT */ #define ADIS16400_SLP_CNT_POWER_OFF (1<<8) +#define ADIS16334_RATE_DIV_SHIFT 8 +#define ADIS16334_RATE_INT_CLK BIT(0) + #define ADIS16400_MAX_TX 24 #define ADIS16400_MAX_RX 24 @@ -130,18 +133,21 @@ #define ADIS16400_SPI_BURST (u32)(1000 * 1000) #define ADIS16400_SPI_FAST (u32)(2000 * 1000) -#define ADIS16400_HAS_PROD_ID 1 -#define ADIS16400_NO_BURST 2 +#define ADIS16400_HAS_PROD_ID BIT(0) +#define ADIS16400_NO_BURST BIT(1) +#define ADIS16400_HAS_SLOW_MODE BIT(2) + struct adis16400_chip_info { const struct iio_chan_spec *channels; const int num_channels; - const int product_id; const long flags; unsigned int gyro_scale_micro; unsigned int accel_scale_micro; int temp_scale_nano; int temp_offset; unsigned long default_scan_mask; + int (*set_freq)(struct iio_dev *indio_dev, unsigned int freq); + int (*get_freq)(struct iio_dev *indio_dev); }; /** diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c index 3144a7b1e1c..9c8f5ab7e13 100644 --- a/drivers/staging/iio/imu/adis16400_core.c +++ b/drivers/staging/iio/imu/adis16400_core.c @@ -38,7 +38,6 @@ enum adis16400_chip_variant { ADIS16360, ADIS16362, ADIS16364, - ADIS16365, ADIS16400, }; @@ -161,10 +160,39 @@ error_ret: return ret; } -static int adis16400_get_freq(struct iio_dev *indio_dev) +static int adis16334_get_freq(struct iio_dev *indio_dev) { + int ret; u16 t; + + ret = adis16400_spi_read_reg_16(indio_dev, ADIS16400_SMPL_PRD, &t); + if (ret < 0) + return ret; + + t >>= ADIS16334_RATE_DIV_SHIFT; + + return (8192 >> t) / 10; +} + +static int adis16334_set_freq(struct iio_dev *indio_dev, unsigned int freq) +{ + unsigned int t; + + t = ilog2(8192 / (freq * 10)); + + if (t > 0x31) + t = 0x31; + + t <<= ADIS16334_RATE_DIV_SHIFT; + t |= ADIS16334_RATE_INT_CLK; + + return adis16400_spi_write_reg_16(indio_dev, ADIS16400_SMPL_PRD, t); +} + +static int adis16400_get_freq(struct iio_dev *indio_dev) +{ int sps, ret; + u16 t; ret = adis16400_spi_read_reg_16(indio_dev, ADIS16400_SMPL_PRD, &t); if (ret < 0) @@ -175,13 +203,33 @@ static int adis16400_get_freq(struct iio_dev *indio_dev) return sps; } +static int adis16400_set_freq(struct iio_dev *indio_dev, unsigned int freq) +{ + struct adis16400_state *st = iio_priv(indio_dev); + unsigned int t; + + t = 1638 / freq; + if (t > 0) + t--; + t &= ADIS16400_SMPL_PRD_DIV_MASK; + if ((t & ADIS16400_SMPL_PRD_DIV_MASK) >= 0x0A) + st->us->max_speed_hz = ADIS16400_SPI_SLOW; + else + st->us->max_speed_hz = ADIS16400_SPI_FAST; + + return adis16400_spi_write_reg_8(indio_dev, + ADIS16400_SMPL_PRD, t); +} + static ssize_t adis16400_read_frequency(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adis16400_state *st = iio_priv(indio_dev); int ret, len = 0; - ret = adis16400_get_freq(indio_dev); + + ret = st->variant->get_freq(indio_dev); if (ret < 0) return ret; len = sprintf(buf, "%d SPS\n", ret); @@ -229,7 +277,6 @@ static ssize_t adis16400_write_frequency(struct device *dev, struct adis16400_state *st = iio_priv(indio_dev); long val; int ret; - u8 t; ret = strict_strtol(buf, 10, &val); if (ret) @@ -239,18 +286,7 @@ static ssize_t adis16400_write_frequency(struct device *dev, mutex_lock(&indio_dev->mlock); - t = (1638 / val); - if (t > 0) - t--; - t &= ADIS16400_SMPL_PRD_DIV_MASK; - if ((t & ADIS16400_SMPL_PRD_DIV_MASK) >= 0x0A) - st->us->max_speed_hz = ADIS16400_SPI_SLOW; - else - st->us->max_speed_hz = ADIS16400_SPI_FAST; - - ret = adis16400_spi_write_reg_8(indio_dev, - ADIS16400_SMPL_PRD, - t); + st->variant->set_freq(indio_dev, val); /* Also update the filter */ mutex_unlock(&indio_dev->mlock); @@ -378,10 +414,14 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev) { int ret; u16 prod_id, smp_prd; + unsigned int device_id; struct adis16400_state *st = iio_priv(indio_dev); - /* use low spi speed for init */ - st->us->max_speed_hz = ADIS16400_SPI_SLOW; + /* use low spi speed for init if the device has a slow mode */ + if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) + st->us->max_speed_hz = ADIS16400_SPI_SLOW; + else + st->us->max_speed_hz = ADIS16400_SPI_FAST; st->us->mode = SPI_MODE_3; spi_setup(st->us); @@ -414,19 +454,27 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev) if (ret) goto err_ret; - if ((prod_id & 0xF000) != st->variant->product_id) - dev_warn(&indio_dev->dev, "incorrect id"); + sscanf(indio_dev->name, "adis%u\n", &device_id); + + if (prod_id != device_id) + dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.", + device_id, prod_id); dev_info(&indio_dev->dev, "%s: prod_id 0x%04x at CS%d (irq %d)\n", indio_dev->name, prod_id, st->us->chip_select, st->us->irq); } /* use high spi speed if possible */ - ret = adis16400_spi_read_reg_16(indio_dev, - ADIS16400_SMPL_PRD, &smp_prd); - if (!ret && (smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) { - st->us->max_speed_hz = ADIS16400_SPI_SLOW; - spi_setup(st->us); + if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) { + ret = adis16400_spi_read_reg_16(indio_dev, + ADIS16400_SMPL_PRD, &smp_prd); + if (ret) + goto err_ret; + + if ((smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) { + st->us->max_speed_hz = ADIS16400_SPI_FAST; + spi_setup(st->us); + } } err_ret: @@ -503,7 +551,7 @@ static int adis16400_write_raw(struct iio_dev *indio_dev, mutex_lock(&indio_dev->mlock); st->filt_int = val; /* Work out update to current value */ - sps = adis16400_get_freq(indio_dev); + sps = st->variant->get_freq(indio_dev); if (sps < 0) { mutex_unlock(&indio_dev->mlock); return sps; @@ -601,7 +649,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, mutex_unlock(&indio_dev->mlock); return ret; } - ret = adis16400_get_freq(indio_dev); + val16 = st->variant->get_freq(indio_dev); if (ret > 0) *val = ret/adis16400_3db_divisors[val16 & 0x03]; *val2 = 0; @@ -624,7 +672,7 @@ static const struct iio_chan_spec adis16400_channels[] = { IIO_CHAN_INFO_SCALE_SEPARATE_BIT, .address = in_supply, .scan_index = ADIS16400_SCAN_SUPPLY, - .scan_type = IIO_ST('u', 14, 16, 0) + .scan_type = IIO_ST('u', 14, 16, 0), }, { .type = IIO_ANGL_VEL, .modified = 1, @@ -635,7 +683,7 @@ static const struct iio_chan_spec adis16400_channels[] = { IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, .address = gyro_x, .scan_index = ADIS16400_SCAN_GYRO_X, - .scan_type = IIO_ST('s', 14, 16, 0) + .scan_type = IIO_ST('s', 14, 16, 0), }, { .type = IIO_ANGL_VEL, .modified = 1, @@ -754,7 +802,7 @@ static const struct iio_chan_spec adis16350_channels[] = { IIO_CHAN_INFO_SCALE_SEPARATE_BIT, .address = in_supply, .scan_index = ADIS16400_SCAN_SUPPLY, - .scan_type = IIO_ST('u', 12, 16, 0) + .scan_type = IIO_ST('u', 12, 16, 0), }, { .type = IIO_ANGL_VEL, .modified = 1, @@ -765,7 +813,7 @@ static const struct iio_chan_spec adis16350_channels[] = { IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, .address = gyro_x, .scan_index = ADIS16400_SCAN_GYRO_X, - .scan_type = IIO_ST('s', 14, 16, 0) + .scan_type = IIO_ST('s', 14, 16, 0), }, { .type = IIO_ANGL_VEL, .modified = 1, @@ -879,7 +927,7 @@ static const struct iio_chan_spec adis16300_channels[] = { IIO_CHAN_INFO_SCALE_SEPARATE_BIT, .address = in_supply, .scan_index = ADIS16400_SCAN_SUPPLY, - .scan_type = IIO_ST('u', 12, 16, 0) + .scan_type = IIO_ST('u', 12, 16, 0), }, { .type = IIO_ANGL_VEL, .modified = 1, @@ -1060,6 +1108,7 @@ static struct adis16400_chip_info adis16400_chips[] = { [ADIS16300] = { .channels = adis16300_channels, .num_channels = ARRAY_SIZE(adis16300_channels), + .flags = ADIS16400_HAS_SLOW_MODE, .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ .accel_scale_micro = 5884, .temp_scale_nano = 140000000, /* 0.14 C */ @@ -1070,10 +1119,13 @@ static struct adis16400_chip_info adis16400_chips[] = { (1 << ADIS16400_SCAN_TEMP) | (1 << ADIS16400_SCAN_ADC_0) | (1 << ADIS16300_SCAN_INCLI_X) | (1 << ADIS16300_SCAN_INCLI_Y) | (1 << 14), + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, }, [ADIS16334] = { .channels = adis16334_channels, .num_channels = ARRAY_SIZE(adis16334_channels), + .flags = ADIS16400_HAS_PROD_ID, .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ .temp_scale_nano = 67850000, /* 0.06785 C */ @@ -1082,6 +1134,8 @@ static struct adis16400_chip_info adis16400_chips[] = { (1 << ADIS16400_SCAN_GYRO_Y) | (1 << ADIS16400_SCAN_GYRO_Z) | (1 << ADIS16400_SCAN_ACC_X) | (1 << ADIS16400_SCAN_ACC_Y) | (1 << ADIS16400_SCAN_ACC_Z), + .set_freq = adis16334_set_freq, + .get_freq = adis16334_get_freq, }, [ADIS16350] = { .channels = adis16350_channels, @@ -1091,62 +1145,57 @@ static struct adis16400_chip_info adis16400_chips[] = { .temp_scale_nano = 145300000, /* 0.1453 C */ .temp_offset = 25000000 / 145300, /* 25 C = 0x00 */ .default_scan_mask = 0x7FF, - .flags = ADIS16400_NO_BURST, + .flags = ADIS16400_NO_BURST | ADIS16400_HAS_SLOW_MODE, + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, }, [ADIS16360] = { .channels = adis16350_channels, .num_channels = ARRAY_SIZE(adis16350_channels), - .flags = ADIS16400_HAS_PROD_ID, - .product_id = 0x3FE8, + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ .temp_scale_nano = 136000000, /* 0.136 C */ .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ .default_scan_mask = 0x7FF, + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, }, [ADIS16362] = { .channels = adis16350_channels, .num_channels = ARRAY_SIZE(adis16350_channels), - .flags = ADIS16400_HAS_PROD_ID, - .product_id = 0x3FEA, + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */ .temp_scale_nano = 136000000, /* 0.136 C */ .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ .default_scan_mask = 0x7FF, + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, }, [ADIS16364] = { .channels = adis16350_channels, .num_channels = ARRAY_SIZE(adis16350_channels), - .flags = ADIS16400_HAS_PROD_ID, - .product_id = 0x3FEC, - .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ - .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ - .temp_scale_nano = 136000000, /* 0.136 C */ - .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ - .default_scan_mask = 0x7FF, - }, - [ADIS16365] = { - .channels = adis16350_channels, - .num_channels = ARRAY_SIZE(adis16350_channels), - .flags = ADIS16400_HAS_PROD_ID, - .product_id = 0x3FED, + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ .temp_scale_nano = 136000000, /* 0.136 C */ .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ .default_scan_mask = 0x7FF, + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, }, [ADIS16400] = { .channels = adis16400_channels, .num_channels = ARRAY_SIZE(adis16400_channels), - .flags = ADIS16400_HAS_PROD_ID, - .product_id = 0x4015, + .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ .default_scan_mask = 0xFFF, .temp_scale_nano = 140000000, /* 0.14 C */ .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ + .set_freq = adis16400_set_freq, + .get_freq = adis16400_get_freq, } }; @@ -1157,7 +1206,7 @@ static const struct iio_info adis16400_info = { .attrs = &adis16400_attribute_group, }; -static int __devinit adis16400_probe(struct spi_device *spi) +static int adis16400_probe(struct spi_device *spi) { int ret; struct adis16400_state *st; @@ -1224,7 +1273,7 @@ error_ret: } /* fixme, confirm ordering in this function */ -static int __devexit adis16400_remove(struct spi_device *spi) +static int adis16400_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); @@ -1248,7 +1297,7 @@ static const struct spi_device_id adis16400_id[] = { {"adis16360", ADIS16360}, {"adis16362", ADIS16362}, {"adis16364", ADIS16364}, - {"adis16365", ADIS16365}, + {"adis16365", ADIS16360}, {"adis16400", ADIS16400}, {"adis16405", ADIS16400}, {} @@ -1262,7 +1311,7 @@ static struct spi_driver adis16400_driver = { }, .id_table = adis16400_id, .probe = adis16400_probe, - .remove = __devexit_p(adis16400_remove), + .remove = adis16400_remove, }; module_spi_driver(adis16400_driver); diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c index 260bdd1a468..d46c1e38cf7 100644 --- a/drivers/staging/iio/imu/adis16400_ring.c +++ b/drivers/staging/iio/imu/adis16400_ring.c @@ -114,7 +114,6 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p) struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct adis16400_state *st = iio_priv(indio_dev); - struct iio_buffer *ring = indio_dev->buffer; int i = 0, j, ret = 0; s16 *data; @@ -148,9 +147,9 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p) } } /* Guaranteed to be aligned with 8 byte boundary */ - if (ring->scan_timestamp) + if (indio_dev->scan_timestamp) *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; - iio_push_to_buffer(ring, (u8 *) data); + iio_push_to_buffers(indio_dev, (u8 *) data); done: kfree(data); diff --git a/drivers/staging/iio/light/isl29018.c b/drivers/staging/iio/light/isl29018.c index 6ee5567d981..b0adac0bf5d 100644 --- a/drivers/staging/iio/light/isl29018.c +++ b/drivers/staging/iio/light/isl29018.c @@ -67,6 +67,7 @@ struct isl29018_chip { unsigned int range; unsigned int adc_bit; int prox_scheme; + bool suspended; }; static int isl29018_set_range(struct isl29018_chip *chip, unsigned long range, @@ -355,7 +356,7 @@ static int isl29018_write_raw(struct iio_dev *indio_dev, } mutex_unlock(&chip->lock); - return 0; + return ret; } static int isl29018_read_raw(struct iio_dev *indio_dev, @@ -368,6 +369,10 @@ static int isl29018_read_raw(struct iio_dev *indio_dev, struct isl29018_chip *chip = iio_priv(indio_dev); mutex_lock(&chip->lock); + if (chip->suspended) { + mutex_unlock(&chip->lock); + return -EBUSY; + } switch (mask) { case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_PROCESSED: @@ -538,7 +543,7 @@ static const struct regmap_config isl29018_regmap_config = { .cache_type = REGCACHE_RBTREE, }; -static int __devinit isl29018_probe(struct i2c_client *client, +static int isl29018_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct isl29018_chip *chip; @@ -561,6 +566,7 @@ static int __devinit isl29018_probe(struct i2c_client *client, chip->lux_scale = 1; chip->range = 1000; chip->adc_bit = 16; + chip->suspended = false; chip->regmap = devm_regmap_init_i2c(client, &isl29018_regmap_config); if (IS_ERR(chip->regmap)) { @@ -592,7 +598,7 @@ exit: return err; } -static int __devexit isl29018_remove(struct i2c_client *client) +static int isl29018_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); @@ -603,6 +609,44 @@ static int __devexit isl29018_remove(struct i2c_client *client) return 0; } +#ifdef CONFIG_PM_SLEEP +static int isl29018_suspend(struct device *dev) +{ + struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev)); + + mutex_lock(&chip->lock); + + /* Since this driver uses only polling commands, we are by default in + * auto shutdown (ie, power-down) mode. + * So we do not have much to do here. + */ + chip->suspended = true; + + mutex_unlock(&chip->lock); + return 0; +} + +static int isl29018_resume(struct device *dev) +{ + struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev)); + int err; + + mutex_lock(&chip->lock); + + err = isl29018_chip_init(chip); + if (!err) + chip->suspended = false; + + mutex_unlock(&chip->lock); + return err; +} + +static SIMPLE_DEV_PM_OPS(isl29018_pm_ops, isl29018_suspend, isl29018_resume); +#define ISL29018_PM_OPS (&isl29018_pm_ops) +#else +#define ISL29018_PM_OPS NULL +#endif + static const struct i2c_device_id isl29018_id[] = { {"isl29018", 0}, {} @@ -620,11 +664,12 @@ static struct i2c_driver isl29018_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = "isl29018", + .pm = ISL29018_PM_OPS, .owner = THIS_MODULE, .of_match_table = isl29018_of_match, }, .probe = isl29018_probe, - .remove = __devexit_p(isl29018_remove), + .remove = isl29018_remove, .id_table = isl29018_id, }; module_i2c_driver(isl29018_driver); diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 33a4c3f94a1..e52af77f778 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -475,7 +475,7 @@ static const struct regmap_config isl29028_regmap_config = { .cache_type = REGCACHE_RBTREE, }; -static int __devinit isl29028_probe(struct i2c_client *client, +static int isl29028_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct isl29028_chip *chip; @@ -526,7 +526,7 @@ exit_iio_free: return ret; } -static int __devexit isl29028_remove(struct i2c_client *client) +static int isl29028_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); @@ -555,7 +555,7 @@ static struct i2c_driver isl29028_driver = { .of_match_table = isl29028_of_match, }, .probe = isl29028_probe, - .remove = __devexit_p(isl29028_remove), + .remove = isl29028_remove, .id_table = isl29028_id, }; diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c index 954ca2c172c..1a9adc020f6 100644 --- a/drivers/staging/iio/light/tsl2563.c +++ b/drivers/staging/iio/light/tsl2563.c @@ -652,7 +652,7 @@ static int tsl2563_write_interrupt_config(struct iio_dev *indio_dev, } if (!state && (chip->intr & 0x30)) { - chip->intr |= ~0x30; + chip->intr &= ~0x30; ret = i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT, chip->intr); @@ -705,7 +705,7 @@ static const struct iio_info tsl2563_info = { .write_event_config = &tsl2563_write_interrupt_config, }; -static int __devinit tsl2563_probe(struct i2c_client *client, +static int tsl2563_probe(struct i2c_client *client, const struct i2c_device_id *device_id) { struct iio_dev *indio_dev; @@ -805,7 +805,7 @@ fail1: return err; } -static int __devexit tsl2563_remove(struct i2c_client *client) +static int tsl2563_remove(struct i2c_client *client) { struct tsl2563_chip *chip = i2c_get_clientdata(client); struct iio_dev *indio_dev = iio_priv_to_dev(chip); @@ -814,7 +814,7 @@ static int __devexit tsl2563_remove(struct i2c_client *client) if (!chip->int_enabled) cancel_delayed_work(&chip->poweroff_work); /* Ensure that interrupts are disabled - then flush any bottom halves */ - chip->intr |= ~0x30; + chip->intr &= ~0x30; i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT, chip->intr); flush_scheduled_work(); @@ -889,7 +889,7 @@ static struct i2c_driver tsl2563_i2c_driver = { .pm = TSL2563_PM_OPS, }, .probe = tsl2563_probe, - .remove = __devexit_p(tsl2563_remove), + .remove = tsl2563_remove, .id_table = tsl2563_id, }; module_i2c_driver(tsl2563_i2c_driver); diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c index 6d2f4c659e5..b377dd3b76a 100644 --- a/drivers/staging/iio/light/tsl2583.c +++ b/drivers/staging/iio/light/tsl2583.c @@ -799,7 +799,7 @@ static const struct iio_info tsl2583_info = { * Client probe function - When a valid device is found, the driver's device * data structure is updated, and initialization completes successfully. */ -static int __devinit taos_probe(struct i2c_client *clientp, +static int taos_probe(struct i2c_client *clientp, const struct i2c_device_id *idp) { int i, ret; @@ -923,7 +923,7 @@ static SIMPLE_DEV_PM_OPS(taos_pm_ops, taos_suspend, taos_resume); #define TAOS_PM_OPS NULL #endif -static int __devexit taos_remove(struct i2c_client *client) +static int taos_remove(struct i2c_client *client) { iio_device_unregister(i2c_get_clientdata(client)); iio_device_free(i2c_get_clientdata(client)); @@ -947,7 +947,7 @@ static struct i2c_driver taos_driver = { }, .id_table = taos_idtable, .probe = taos_probe, - .remove = __devexit_p(taos_remove), + .remove = taos_remove, }; module_i2c_driver(taos_driver); diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c index 497a977ae41..9e50fbbadf9 100644 --- a/drivers/staging/iio/light/tsl2x7x_core.c +++ b/drivers/staging/iio/light/tsl2x7x_core.c @@ -1897,7 +1897,7 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { }, }; -static int __devinit tsl2x7x_probe(struct i2c_client *clientp, +static int tsl2x7x_probe(struct i2c_client *clientp, const struct i2c_device_id *id) { int ret; @@ -2026,7 +2026,7 @@ static int tsl2x7x_resume(struct device *dev) return ret; } -static int __devexit tsl2x7x_remove(struct i2c_client *client) +static int tsl2x7x_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); @@ -2070,7 +2070,7 @@ static struct i2c_driver tsl2x7x_driver = { }, .id_table = tsl2x7x_idtable, .probe = tsl2x7x_probe, - .remove = __devexit_p(tsl2x7x_remove), + .remove = tsl2x7x_remove, }; module_i2c_driver(tsl2x7x_driver); diff --git a/drivers/staging/iio/magnetometer/ak8975.c b/drivers/staging/iio/magnetometer/ak8975.c index 01b4b07c227..28f080e9eee 100644 --- a/drivers/staging/iio/magnetometer/ak8975.c +++ b/drivers/staging/iio/magnetometer/ak8975.c @@ -409,7 +409,7 @@ static const struct iio_info ak8975_info = { .driver_module = THIS_MODULE, }; -static int __devinit ak8975_probe(struct i2c_client *client, +static int ak8975_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct ak8975_data *data; @@ -475,7 +475,7 @@ exit: return err; } -static int __devexit ak8975_remove(struct i2c_client *client) +static int ak8975_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); struct ak8975_data *data = iio_priv(indio_dev); @@ -510,7 +510,7 @@ static struct i2c_driver ak8975_driver = { .of_match_table = ak8975_of_match, }, .probe = ak8975_probe, - .remove = __devexit_p(ak8975_remove), + .remove = ak8975_remove, .id_table = ak8975_id, }; module_i2c_driver(ak8975_driver); diff --git a/drivers/staging/iio/magnetometer/hmc5843.c b/drivers/staging/iio/magnetometer/hmc5843.c index 10e095486e5..1a520ecfa3e 100644 --- a/drivers/staging/iio/magnetometer/hmc5843.c +++ b/drivers/staging/iio/magnetometer/hmc5843.c @@ -555,7 +555,7 @@ static int hmc5843_read_raw(struct iio_dev *indio_dev, *val = 0; *val2 = data->variant->regval_to_nanoscale[data->range]; return IIO_VAL_INT_PLUS_NANO; - }; + } return -EINVAL; } @@ -665,7 +665,7 @@ static const struct iio_info hmc5843_info = { .driver_module = THIS_MODULE, }; -static int __devinit hmc5843_probe(struct i2c_client *client, +static int hmc5843_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct hmc5843_data *data; @@ -704,7 +704,7 @@ exit: return err; } -static int __devexit hmc5843_remove(struct i2c_client *client) +static int hmc5843_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); @@ -755,7 +755,7 @@ static struct i2c_driver hmc5843_driver = { }, .id_table = hmc5843_id, .probe = hmc5843_probe, - .remove = __devexit_p(hmc5843_remove), + .remove = hmc5843_remove, .detect = hmc5843_detect, .address_list = normal_i2c, }; diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c index 8b9eceb66b3..51c3bdece78 100644 --- a/drivers/staging/iio/meter/ade7753.c +++ b/drivers/staging/iio/meter/ade7753.c @@ -512,7 +512,7 @@ static const struct iio_info ade7753_info = { .driver_module = THIS_MODULE, }; -static int __devinit ade7753_probe(struct spi_device *spi) +static int ade7753_probe(struct spi_device *spi) { int ret; struct ade7753_state *st; @@ -555,7 +555,7 @@ error_ret: } /* fixme, confirm ordering in this function */ -static int __devexit ade7753_remove(struct spi_device *spi) +static int ade7753_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); @@ -572,7 +572,7 @@ static struct spi_driver ade7753_driver = { .owner = THIS_MODULE, }, .probe = ade7753_probe, - .remove = __devexit_p(ade7753_remove), + .remove = ade7753_remove, }; module_spi_driver(ade7753_driver); diff --git a/drivers/staging/iio/meter/ade7753.h b/drivers/staging/iio/meter/ade7753.h index 3f059d3d939..a9d93cc1c41 100644 --- a/drivers/staging/iio/meter/ade7753.h +++ b/drivers/staging/iio/meter/ade7753.h @@ -55,8 +55,6 @@ #define ADE7753_SPI_BURST (u32)(1000 * 1000) #define ADE7753_SPI_FAST (u32)(2000 * 1000) -#define DRIVER_NAME "ade7753" - /** * struct ade7753_state - device instance specific data * @us: actual spi_device diff --git a/drivers/staging/iio/meter/ade7754.c b/drivers/staging/iio/meter/ade7754.c index 76e0adee96e..b50c89e9399 100644 --- a/drivers/staging/iio/meter/ade7754.c +++ b/drivers/staging/iio/meter/ade7754.c @@ -535,7 +535,7 @@ static const struct iio_info ade7754_info = { .driver_module = THIS_MODULE, }; -static int __devinit ade7754_probe(struct spi_device *spi) +static int ade7754_probe(struct spi_device *spi) { int ret; struct ade7754_state *st; @@ -577,7 +577,7 @@ error_ret: } /* fixme, confirm ordering in this function */ -static int __devexit ade7754_remove(struct spi_device *spi) +static int ade7754_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); @@ -594,7 +594,7 @@ static struct spi_driver ade7754_driver = { .owner = THIS_MODULE, }, .probe = ade7754_probe, - .remove = __devexit_p(ade7754_remove), + .remove = ade7754_remove, }; module_spi_driver(ade7754_driver); diff --git a/drivers/staging/iio/meter/ade7754.h b/drivers/staging/iio/meter/ade7754.h index 6121125520f..e42ffc387a1 100644 --- a/drivers/staging/iio/meter/ade7754.h +++ b/drivers/staging/iio/meter/ade7754.h @@ -73,8 +73,6 @@ #define ADE7754_SPI_BURST (u32)(1000 * 1000) #define ADE7754_SPI_FAST (u32)(2000 * 1000) -#define DRIVER_NAME "ade7754" - /** * struct ade7754_state - device instance specific data * @us: actual spi_device diff --git a/drivers/staging/iio/meter/ade7758.h b/drivers/staging/iio/meter/ade7758.h index 1e11ad5ae5a..07318203a83 100644 --- a/drivers/staging/iio/meter/ade7758.h +++ b/drivers/staging/iio/meter/ade7758.h @@ -105,9 +105,6 @@ #define AD7758_APP_PWR 4 #define AD7758_WT(p, w) (((w) << 2) | (p)) -#define DRIVER_NAME "ade7758" - - /** * struct ade7758_state - device instance specific data * @us: actual spi_device diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c index a0fef77d8e5..3454e5154ed 100644 --- a/drivers/staging/iio/meter/ade7758_core.c +++ b/drivers/staging/iio/meter/ade7758_core.c @@ -881,7 +881,7 @@ static const struct iio_info ade7758_info = { .driver_module = THIS_MODULE, }; -static int __devinit ade7758_probe(struct spi_device *spi) +static int ade7758_probe(struct spi_device *spi) { int ret; struct ade7758_state *st; @@ -962,7 +962,7 @@ error_ret: return ret; } -static int __devexit ade7758_remove(struct spi_device *spi) +static int ade7758_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); struct ade7758_state *st = iio_priv(indio_dev); @@ -992,7 +992,7 @@ static struct spi_driver ade7758_driver = { .owner = THIS_MODULE, }, .probe = ade7758_probe, - .remove = __devexit_p(ade7758_remove), + .remove = ade7758_remove, .id_table = ade7758_id, }; module_spi_driver(ade7758_driver); diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c index 9e49baccf66..4552a4c7fe3 100644 --- a/drivers/staging/iio/meter/ade7758_ring.c +++ b/drivers/staging/iio/meter/ade7758_ring.c @@ -73,7 +73,7 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p) if (indio_dev->scan_timestamp) dat64[1] = pf->timestamp; - iio_push_to_buffer(indio_dev->buffer, (u8 *)dat64); + iio_push_to_buffers(indio_dev, (u8 *)dat64); iio_trigger_notify_done(indio_dev->trig); diff --git a/drivers/staging/iio/meter/ade7759.c b/drivers/staging/iio/meter/ade7759.c index cb0707cbc34..10b911bd385 100644 --- a/drivers/staging/iio/meter/ade7759.c +++ b/drivers/staging/iio/meter/ade7759.c @@ -458,7 +458,7 @@ static const struct iio_info ade7759_info = { .driver_module = THIS_MODULE, }; -static int __devinit ade7759_probe(struct spi_device *spi) +static int ade7759_probe(struct spi_device *spi) { int ret; struct ade7759_state *st; @@ -499,7 +499,7 @@ error_ret: } /* fixme, confirm ordering in this function */ -static int __devexit ade7759_remove(struct spi_device *spi) +static int ade7759_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); @@ -516,7 +516,7 @@ static struct spi_driver ade7759_driver = { .owner = THIS_MODULE, }, .probe = ade7759_probe, - .remove = __devexit_p(ade7759_remove), + .remove = ade7759_remove, }; module_spi_driver(ade7759_driver); diff --git a/drivers/staging/iio/meter/ade7759.h b/drivers/staging/iio/meter/ade7759.h index c81d23d730d..f9ff1f8e737 100644 --- a/drivers/staging/iio/meter/ade7759.h +++ b/drivers/staging/iio/meter/ade7759.h @@ -36,8 +36,6 @@ #define ADE7759_SPI_BURST (u32)(1000 * 1000) #define ADE7759_SPI_FAST (u32)(2000 * 1000) -#define DRIVER_NAME "ade7759" - /** * struct ade7759_state - device instance specific data * @us: actual spi_device diff --git a/drivers/staging/iio/meter/ade7854-i2c.c b/drivers/staging/iio/meter/ade7854-i2c.c index 06090465fa5..db9ef6c86c1 100644 --- a/drivers/staging/iio/meter/ade7854-i2c.c +++ b/drivers/staging/iio/meter/ade7854-i2c.c @@ -201,7 +201,7 @@ out: return ret; } -static int __devinit ade7854_i2c_probe(struct i2c_client *client, +static int ade7854_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret; @@ -231,7 +231,7 @@ static int __devinit ade7854_i2c_probe(struct i2c_client *client, return ret; } -static int __devexit ade7854_i2c_remove(struct i2c_client *client) +static int ade7854_i2c_remove(struct i2c_client *client) { return ade7854_remove(i2c_get_clientdata(client)); } @@ -250,7 +250,7 @@ static struct i2c_driver ade7854_i2c_driver = { .name = "ade7854", }, .probe = ade7854_i2c_probe, - .remove = __devexit_p(ade7854_i2c_remove), + .remove = ade7854_i2c_remove, .id_table = ade7854_id, }; module_i2c_driver(ade7854_i2c_driver); diff --git a/drivers/staging/iio/meter/ade7854-spi.c b/drivers/staging/iio/meter/ade7854-spi.c index 7dae0357342..f0984fa1cbb 100644 --- a/drivers/staging/iio/meter/ade7854-spi.c +++ b/drivers/staging/iio/meter/ade7854-spi.c @@ -300,7 +300,7 @@ error_ret: return ret; } -static int __devinit ade7854_spi_probe(struct spi_device *spi) +static int ade7854_spi_probe(struct spi_device *spi) { int ret; struct ade7854_state *st; @@ -330,7 +330,7 @@ static int __devinit ade7854_spi_probe(struct spi_device *spi) return 0; } -static int __devexit ade7854_spi_remove(struct spi_device *spi) +static int ade7854_spi_remove(struct spi_device *spi) { ade7854_remove(spi_get_drvdata(spi)); @@ -351,7 +351,7 @@ static struct spi_driver ade7854_driver = { .owner = THIS_MODULE, }, .probe = ade7854_spi_probe, - .remove = __devexit_p(ade7854_spi_remove), + .remove = ade7854_spi_remove, .id_table = ade7854_id, }; module_spi_driver(ade7854_driver); diff --git a/drivers/staging/iio/meter/ade7854.h b/drivers/staging/iio/meter/ade7854.h index 2c96e8695d5..06534577f6c 100644 --- a/drivers/staging/iio/meter/ade7854.h +++ b/drivers/staging/iio/meter/ade7854.h @@ -142,8 +142,6 @@ #define ADE7854_SPI_BURST (u32)(1000 * 1000) #define ADE7854_SPI_FAST (u32)(2000 * 1000) -#define DRIVER_NAME "ade7854" - /** * struct ade7854_state - device instance specific data * @spi: actual spi_device diff --git a/drivers/staging/iio/resolver/ad2s1200.c b/drivers/staging/iio/resolver/ad2s1200.c index 8b71eb0e16f..4fe349914f9 100644 --- a/drivers/staging/iio/resolver/ad2s1200.c +++ b/drivers/staging/iio/resolver/ad2s1200.c @@ -99,7 +99,7 @@ static const struct iio_info ad2s1200_info = { .driver_module = THIS_MODULE, }; -static int __devinit ad2s1200_probe(struct spi_device *spi) +static int ad2s1200_probe(struct spi_device *spi) { struct ad2s1200_state *st; struct iio_dev *indio_dev; @@ -149,7 +149,7 @@ error_ret: return ret; } -static int __devexit ad2s1200_remove(struct spi_device *spi) +static int ad2s1200_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -170,7 +170,7 @@ static struct spi_driver ad2s1200_driver = { .owner = THIS_MODULE, }, .probe = ad2s1200_probe, - .remove = __devexit_p(ad2s1200_remove), + .remove = ad2s1200_remove, .id_table = ad2s1200_id, }; module_spi_driver(ad2s1200_driver); diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 4ba4d05ed42..ed07a348eb5 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -610,7 +610,7 @@ static const struct attribute_group ad2s1210_attribute_group = { .attrs = ad2s1210_attributes, }; -static int __devinit ad2s1210_initial(struct ad2s1210_state *st) +static int ad2s1210_initial(struct ad2s1210_state *st) { unsigned char data; int ret; @@ -681,7 +681,7 @@ static void ad2s1210_free_gpios(struct ad2s1210_state *st) gpio_free_array(ad2s1210_gpios, ARRAY_SIZE(ad2s1210_gpios)); } -static int __devinit ad2s1210_probe(struct spi_device *spi) +static int ad2s1210_probe(struct spi_device *spi) { struct iio_dev *indio_dev; struct ad2s1210_state *st; @@ -736,7 +736,7 @@ error_ret: return ret; } -static int __devexit ad2s1210_remove(struct spi_device *spi) +static int ad2s1210_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); @@ -759,7 +759,7 @@ static struct spi_driver ad2s1210_driver = { .owner = THIS_MODULE, }, .probe = ad2s1210_probe, - .remove = __devexit_p(ad2s1210_remove), + .remove = ad2s1210_remove, .id_table = ad2s1210_id, }; module_spi_driver(ad2s1210_driver); diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c index a8057228dca..0aecfbcdb99 100644 --- a/drivers/staging/iio/resolver/ad2s90.c +++ b/drivers/staging/iio/resolver/ad2s90.c @@ -58,7 +58,7 @@ static const struct iio_chan_spec ad2s90_chan = { .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, }; -static int __devinit ad2s90_probe(struct spi_device *spi) +static int ad2s90_probe(struct spi_device *spi) { struct iio_dev *indio_dev; struct ad2s90_state *st; @@ -98,7 +98,7 @@ error_ret: return ret; } -static int __devexit ad2s90_remove(struct spi_device *spi) +static int ad2s90_remove(struct spi_device *spi) { iio_device_unregister(spi_get_drvdata(spi)); iio_device_free(spi_get_drvdata(spi)); @@ -118,7 +118,7 @@ static struct spi_driver ad2s90_driver = { .owner = THIS_MODULE, }, .probe = ad2s90_probe, - .remove = __devexit_p(ad2s90_remove), + .remove = ad2s90_remove, .id_table = ad2s90_id, }; module_spi_driver(ad2s90_driver); diff --git a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c index 52062d786f8..42798da575c 100644 --- a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c +++ b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c @@ -180,7 +180,7 @@ static const struct iio_trigger_ops iio_bfin_tmr_trigger_ops = { .set_trigger_state = iio_bfin_tmr_set_state, }; -static int __devinit iio_bfin_tmr_trigger_probe(struct platform_device *pdev) +static int iio_bfin_tmr_trigger_probe(struct platform_device *pdev) { struct iio_bfin_timer_trigger_pdata *pdata = pdev->dev.platform_data; struct bfin_tmr_state *st; @@ -275,7 +275,7 @@ out: return ret; } -static int __devexit iio_bfin_tmr_trigger_remove(struct platform_device *pdev) +static int iio_bfin_tmr_trigger_remove(struct platform_device *pdev) { struct bfin_tmr_state *st = platform_get_drvdata(pdev); @@ -296,7 +296,7 @@ static struct platform_driver iio_bfin_tmr_trigger_driver = { .owner = THIS_MODULE, }, .probe = iio_bfin_tmr_trigger_probe, - .remove = __devexit_p(iio_bfin_tmr_trigger_remove), + .remove = iio_bfin_tmr_trigger_remove, }; module_platform_driver(iio_bfin_tmr_trigger_driver); diff --git a/drivers/staging/iio/trigger/iio-trig-gpio.c b/drivers/staging/iio/trigger/iio-trig-gpio.c index 5ff4d7fa20f..fcc4cb048c9 100644 --- a/drivers/staging/iio/trigger/iio-trig-gpio.c +++ b/drivers/staging/iio/trigger/iio-trig-gpio.c @@ -51,7 +51,7 @@ static const struct iio_trigger_ops iio_gpio_trigger_ops = { .owner = THIS_MODULE, }; -static int __devinit iio_gpio_trigger_probe(struct platform_device *pdev) +static int iio_gpio_trigger_probe(struct platform_device *pdev) { struct iio_gpio_trigger_info *trig_info; struct iio_trigger *trig, *trig2; @@ -130,7 +130,7 @@ error_free_completed_registrations: return ret; } -static int __devexit iio_gpio_trigger_remove(struct platform_device *pdev) +static int iio_gpio_trigger_remove(struct platform_device *pdev) { struct iio_trigger *trig, *trig2; struct iio_gpio_trigger_info *trig_info; @@ -153,7 +153,7 @@ static int __devexit iio_gpio_trigger_remove(struct platform_device *pdev) static struct platform_driver iio_gpio_trigger_driver = { .probe = iio_gpio_trigger_probe, - .remove = __devexit_p(iio_gpio_trigger_remove), + .remove = iio_gpio_trigger_remove, .driver = { .name = "iio_gpio_trigger", .owner = THIS_MODULE, diff --git a/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c b/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c index a3de76d70cd..9102b1ba253 100644 --- a/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c +++ b/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c @@ -101,7 +101,7 @@ static const struct iio_trigger_ops iio_prtc_trigger_ops = { .set_trigger_state = &iio_trig_periodic_rtc_set_state, }; -static int __devinit iio_trig_periodic_rtc_probe(struct platform_device *dev) +static int iio_trig_periodic_rtc_probe(struct platform_device *dev) { char **pdata = dev->dev.platform_data; struct iio_prtc_trigger_info *trig_info; @@ -167,7 +167,7 @@ error_free_completed_registrations: return ret; } -static int __devexit iio_trig_periodic_rtc_remove(struct platform_device *dev) +static int iio_trig_periodic_rtc_remove(struct platform_device *dev) { struct iio_trigger *trig, *trig2; struct iio_prtc_trigger_info *trig_info; @@ -188,7 +188,7 @@ static int __devexit iio_trig_periodic_rtc_remove(struct platform_device *dev) static struct platform_driver iio_trig_periodic_rtc_driver = { .probe = iio_trig_periodic_rtc_probe, - .remove = __devexit_p(iio_trig_periodic_rtc_remove), + .remove = iio_trig_periodic_rtc_remove, .driver = { .name = "iio_prtc_trigger", .owner = THIS_MODULE, |