Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'iio-for-4.6b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next

Jonathan writes:

2nd round of new IIO device support, features and cleanups for the 4.6 cycle.

New Device Support
* Apex stx104 DAC
- new driver for this PC104 board. Right now DAC support only.
* ADI ad5064
- Add support for ad5625, ad5627, ad5645, ad5665, ad5667 DACs.
- Add support for Linear Technology ltc2606, ltc2607, ltc2609, ltc2616,
ltc2617, ltc2619, ltc2626, ltc2627 and ltc2629.
* ADI ad7192
- add support for the ad7193
* Invensense mpu6050
- substantial rework of driver to use regmap allowing SPI support extending
the now split driver to cover the MPU6000.
* TI adc0832
- new driver supporting ADC0831, ADC0832, ADC0834 and ADC0838 ADCs.
* TI ads1015
- new driver, note that there is an existing hwmon driver. The long term
intention is to probably remove the hwmon driver but for now we just have
guards in place to ensure this driver is not built if that one is enabled.
* TI afe4403
- new driver for this heart rate monitor / pulse oximeter front end chip.
* TI afe4404
- new driver for this heart rate monitor / pulse oximeter front end chip.

Staging Graduations
* mxs-lradc
- A combined general purpose and touch screen (input) device driver.
Originally held in staging to allow reworking into and MFD but as
that wasn't happening and isn't an absolute requirement we are moving
it out of staging.

Driver new features
* ms5611
- triggered buffer support
- IIO_CHAN_INFO_SCALE to aid the triggered buffer support.

Driver cleanups / reworks / fixes
* ad5064
- Use an enum for the register map layout to allow support of additional
chips (precursor to the new support listed above).
- Structural driver changes to allow support of the slightly different
handling for the ltc parts above.
* ad5933
- drop an exceptional & unnecessary for a function pointer.
* ad7606
- Cleanup the repeated copies of pm ops.
- consolidate the various channels specs via a sport of rearranging so only
one version is needed.
* atlas ph sensor
- add select IRQ_WORK
* hmc8543 (soon to move out of staging)
- Comment style fixes
- functionality of suspend and resume was swapped.
* spear-adc
- use devm_clk_dev instead of managing the clk lifetime by hand.

Core
* Use new dmaengine_terminate_sync call to avoid a theoretical race.
* Fix docs for mlock in struct iio_dev as it is correctly taken in some
drivers (docs used to say for core only).
* Add a helper function for calculating the scan index storage size within
the core cutting out some cut and paste versions of the same code.

+3904 -480
+1
Documentation/ABI/testing/sysfs-bus-iio
··· 496 496 1kohm_to_gnd: connected to ground via an 1kOhm resistor, 497 497 6kohm_to_gnd: connected to ground via a 6kOhm resistor, 498 498 20kohm_to_gnd: connected to ground via a 20kOhm resistor, 499 + 90kohm_to_gnd: connected to ground via a 90kOhm resistor, 499 500 100kohm_to_gnd: connected to ground via an 100kOhm resistor, 500 501 125kohm_to_gnd: connected to ground via an 125kOhm resistor, 501 502 500kohm_to_gnd: connected to ground via a 500kOhm resistor,
+54
Documentation/ABI/testing/sysfs-bus-iio-health-afe440x
··· 1 + What: /sys/bus/iio/devices/iio:deviceX/tia_resistanceY 2 + /sys/bus/iio/devices/iio:deviceX/tia_capacitanceY 3 + Date: December 2015 4 + KernelVersion: 5 + Contact: Andrew F. Davis <afd@ti.com> 6 + Description: 7 + Get and set the resistance and the capacitance settings for the 8 + Transimpedance Amplifier. Y is 1 for Rf1 and Cf1, Y is 2 for 9 + Rf2 and Cf2 values. 10 + 11 + What: /sys/bus/iio/devices/iio:deviceX/tia_separate_en 12 + Date: December 2015 13 + KernelVersion: 14 + Contact: Andrew F. Davis <afd@ti.com> 15 + Description: 16 + Enable or disable separate settings for the TransImpedance 17 + Amplifier above, when disabled both values are set by the 18 + first channel. 19 + 20 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_ledY_raw 21 + /sys/bus/iio/devices/iio:deviceX/in_intensity_ledY_ambient_raw 22 + Date: December 2015 23 + KernelVersion: 24 + Contact: Andrew F. Davis <afd@ti.com> 25 + Description: 26 + Get measured values from the ADC for these stages. Y is the 27 + specific LED number. The values are expressed in 24-bit twos 28 + complement. 29 + 30 + What: /sys/bus/iio/devices/iio:deviceX/in_intensity_ledY-ledY_ambient_raw 31 + Date: December 2015 32 + KernelVersion: 33 + Contact: Andrew F. Davis <afd@ti.com> 34 + Description: 35 + Get differential values from the ADC for these stages. Y is the 36 + specific LED number. The values are expressed in 24-bit twos 37 + complement for the specified LEDs. 38 + 39 + What: /sys/bus/iio/devices/iio:deviceX/out_current_ledY_offset 40 + /sys/bus/iio/devices/iio:deviceX/out_current_ledY_ambient_offset 41 + Date: December 2015 42 + KernelVersion: 43 + Contact: Andrew F. Davis <afd@ti.com> 44 + Description: 45 + Get and set the offset cancellation DAC setting for these 46 + stages. The values are expressed in 5-bit sign-magnitude. 47 + 48 + What: /sys/bus/iio/devices/iio:deviceX/out_current_ledY_raw 49 + Date: December 2015 50 + KernelVersion: 51 + Contact: Andrew F. Davis <afd@ti.com> 52 + Description: 53 + Get and set the LED current for the specified LED. Y is the 54 + specific LED number.
+19
Documentation/devicetree/bindings/iio/adc/ti-adc0832.txt
··· 1 + * Texas Instruments' ADC0831/ADC0832/ADC0832/ADC0838 2 + 3 + Required properties: 4 + - compatible: Should be one of 5 + * "ti,adc0831" 6 + * "ti,adc0832" 7 + * "ti,adc0834" 8 + * "ti,adc0838" 9 + - reg: spi chip select number for the device 10 + - vref-supply: The regulator supply for ADC reference voltage 11 + - spi-max-frequency: Max SPI frequency to use (< 400000) 12 + 13 + Example: 14 + adc@0 { 15 + compatible = "ti,adc0832"; 16 + reg = <0>; 17 + vref-supply = <&vdd_supply>; 18 + spi-max-frequency = <200000>; 19 + };
+34
Documentation/devicetree/bindings/iio/health/afe4403.txt
··· 1 + Texas Instruments AFE4403 Heart rate and Pulse Oximeter 2 + 3 + Required properties: 4 + - compatible : Should be "ti,afe4403". 5 + - reg : SPI chip select address of device. 6 + - tx-supply : Regulator supply to transmitting LEDs. 7 + - interrupt-parent : Phandle to he parent interrupt controller. 8 + - interrupts : The interrupt line the device ADC_RDY pin is 9 + connected to. For details refer to, 10 + ../../interrupt-controller/interrupts.txt. 11 + 12 + Optional properties: 13 + - reset-gpios : GPIO used to reset the device. 14 + For details refer to, ../../gpio/gpio.txt. 15 + 16 + For other required and optional properties of SPI slave nodes 17 + please refer to ../../spi/spi-bus.txt. 18 + 19 + Example: 20 + 21 + &spi0 { 22 + heart_mon@0 { 23 + compatible = "ti,afe4403"; 24 + reg = <0>; 25 + spi-max-frequency = <10000000>; 26 + 27 + tx-supply = <&vbat>; 28 + 29 + interrupt-parent = <&gpio1>; 30 + interrupts = <28 IRQ_TYPE_EDGE_RISING>; 31 + 32 + reset-gpios = <&gpio1 16 GPIO_ACTIVE_LOW>; 33 + }; 34 + };
+30
Documentation/devicetree/bindings/iio/health/afe4404.txt
··· 1 + Texas Instruments AFE4404 Heart rate and Pulse Oximeter 2 + 3 + Required properties: 4 + - compatible : Should be "ti,afe4404". 5 + - reg : I2C address of the device. 6 + - tx-supply : Regulator supply to transmitting LEDs. 7 + - interrupt-parent : Phandle to he parent interrupt controller. 8 + - interrupts : The interrupt line the device ADC_RDY pin is 9 + connected to. For details refer to, 10 + ../interrupt-controller/interrupts.txt. 11 + 12 + Optional properties: 13 + - reset-gpios : GPIO used to reset the device. 14 + For details refer to, ../gpio/gpio.txt. 15 + 16 + Example: 17 + 18 + &i2c2 { 19 + heart_mon@58 { 20 + compatible = "ti,afe4404"; 21 + reg = <0x58>; 22 + 23 + tx-supply = <&vbat>; 24 + 25 + interrupt-parent = <&gpio1>; 26 + interrupts = <28 IRQ_TYPE_EDGE_RISING>; 27 + 28 + reset-gpios = <&gpio1 16 GPIO_ACTIVE_LOW>; 29 + }; 30 + };
+6
MAINTAINERS
··· 769 769 S: Maintained 770 770 F: sound/aoa/ 771 771 772 + APEX EMBEDDED SYSTEMS STX104 DAC DRIVER 773 + M: William Breathitt Gray <vilhelm.gray@gmail.com> 774 + L: linux-iio@vger.kernel.org 775 + S: Maintained 776 + F: drivers/iio/dac/stx104.c 777 + 772 778 APM DRIVER 773 779 M: Jiri Kosina <jikos@kernel.org> 774 780 S: Odd fixes
+37
drivers/iio/adc/Kconfig
··· 297 297 This driver can also be built as a module. If so, the module will be 298 298 called men_z188_adc. 299 299 300 + config MXS_LRADC 301 + tristate "Freescale i.MX23/i.MX28 LRADC" 302 + depends on (ARCH_MXS || COMPILE_TEST) && HAS_IOMEM 303 + depends on INPUT 304 + select STMP_DEVICE 305 + select IIO_BUFFER 306 + select IIO_TRIGGERED_BUFFER 307 + help 308 + Say yes here to build support for i.MX23/i.MX28 LRADC convertor 309 + built into these chips. 310 + 311 + To compile this driver as a module, choose M here: the 312 + module will be called mxs-lradc. 313 + 300 314 config NAU7802 301 315 tristate "Nuvoton NAU7802 ADC driver" 302 316 depends on I2C ··· 376 362 This driver can also be built as a module. If so, the module will be 377 363 called ti-adc081c. 378 364 365 + config TI_ADC0832 366 + tristate "Texas Instruments ADC0831/ADC0832/ADC0834/ADC0838" 367 + depends on SPI 368 + help 369 + If you say yes here you get support for Texas Instruments ADC0831, 370 + ADC0832, ADC0834, ADC0838 ADC chips. 371 + 372 + This driver can also be built as a module. If so, the module will be 373 + called ti-adc0832. 374 + 379 375 config TI_ADC128S052 380 376 tristate "Texas Instruments ADC128S052/ADC122S021/ADC124S021" 381 377 depends on SPI ··· 395 371 396 372 This driver can also be built as a module. If so, the module will be 397 373 called ti-adc128s052. 374 + 375 + config TI_ADS1015 376 + tristate "Texas Instruments ADS1015 ADC" 377 + depends on I2C && !SENSORS_ADS1015 378 + select REGMAP_I2C 379 + select IIO_BUFFER 380 + select IIO_TRIGGERED_BUFFER 381 + help 382 + If you say yes here you get support for Texas Instruments ADS1015 383 + ADC chip. 384 + 385 + This driver can also be built as a module. If so, the module will be 386 + called ti-ads1015. 398 387 399 388 config TI_ADS8688 400 389 tristate "Texas Instruments ADS8688"
+3
drivers/iio/adc/Makefile
··· 29 29 obj-$(CONFIG_MCP320X) += mcp320x.o 30 30 obj-$(CONFIG_MCP3422) += mcp3422.o 31 31 obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o 32 + obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o 32 33 obj-$(CONFIG_NAU7802) += nau7802.o 33 34 obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o 34 35 obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o 35 36 obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o 36 37 obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o 37 38 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o 39 + obj-$(CONFIG_TI_ADC0832) += ti-adc0832.o 38 40 obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o 41 + obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o 39 42 obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o 40 43 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o 41 44 obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o
+288
drivers/iio/adc/ti-adc0832.c
··· 1 + /* 2 + * ADC0831/ADC0832/ADC0834/ADC0838 8-bit ADC driver 3 + * 4 + * Copyright (c) 2016 Akinobu Mita <akinobu.mita@gmail.com> 5 + * 6 + * This file is subject to the terms and conditions of version 2 of 7 + * the GNU General Public License. See the file COPYING in the main 8 + * directory of this archive for more details. 9 + * 10 + * Datasheet: http://www.ti.com/lit/ds/symlink/adc0832-n.pdf 11 + */ 12 + 13 + #include <linux/module.h> 14 + #include <linux/spi/spi.h> 15 + #include <linux/iio/iio.h> 16 + #include <linux/regulator/consumer.h> 17 + 18 + enum { 19 + adc0831, 20 + adc0832, 21 + adc0834, 22 + adc0838, 23 + }; 24 + 25 + struct adc0832 { 26 + struct spi_device *spi; 27 + struct regulator *reg; 28 + struct mutex lock; 29 + u8 mux_bits; 30 + 31 + u8 tx_buf[2] ____cacheline_aligned; 32 + u8 rx_buf[2]; 33 + }; 34 + 35 + #define ADC0832_VOLTAGE_CHANNEL(chan) \ 36 + { \ 37 + .type = IIO_VOLTAGE, \ 38 + .indexed = 1, \ 39 + .channel = chan, \ 40 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 41 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \ 42 + } 43 + 44 + #define ADC0832_VOLTAGE_CHANNEL_DIFF(chan1, chan2) \ 45 + { \ 46 + .type = IIO_VOLTAGE, \ 47 + .indexed = 1, \ 48 + .channel = (chan1), \ 49 + .channel2 = (chan2), \ 50 + .differential = 1, \ 51 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 52 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \ 53 + } 54 + 55 + static const struct iio_chan_spec adc0831_channels[] = { 56 + ADC0832_VOLTAGE_CHANNEL_DIFF(0, 1), 57 + }; 58 + 59 + static const struct iio_chan_spec adc0832_channels[] = { 60 + ADC0832_VOLTAGE_CHANNEL(0), 61 + ADC0832_VOLTAGE_CHANNEL(1), 62 + ADC0832_VOLTAGE_CHANNEL_DIFF(0, 1), 63 + ADC0832_VOLTAGE_CHANNEL_DIFF(1, 0), 64 + }; 65 + 66 + static const struct iio_chan_spec adc0834_channels[] = { 67 + ADC0832_VOLTAGE_CHANNEL(0), 68 + ADC0832_VOLTAGE_CHANNEL(1), 69 + ADC0832_VOLTAGE_CHANNEL(2), 70 + ADC0832_VOLTAGE_CHANNEL(3), 71 + ADC0832_VOLTAGE_CHANNEL_DIFF(0, 1), 72 + ADC0832_VOLTAGE_CHANNEL_DIFF(1, 0), 73 + ADC0832_VOLTAGE_CHANNEL_DIFF(2, 3), 74 + ADC0832_VOLTAGE_CHANNEL_DIFF(3, 2), 75 + }; 76 + 77 + static const struct iio_chan_spec adc0838_channels[] = { 78 + ADC0832_VOLTAGE_CHANNEL(0), 79 + ADC0832_VOLTAGE_CHANNEL(1), 80 + ADC0832_VOLTAGE_CHANNEL(2), 81 + ADC0832_VOLTAGE_CHANNEL(3), 82 + ADC0832_VOLTAGE_CHANNEL(4), 83 + ADC0832_VOLTAGE_CHANNEL(5), 84 + ADC0832_VOLTAGE_CHANNEL(6), 85 + ADC0832_VOLTAGE_CHANNEL(7), 86 + ADC0832_VOLTAGE_CHANNEL_DIFF(0, 1), 87 + ADC0832_VOLTAGE_CHANNEL_DIFF(1, 0), 88 + ADC0832_VOLTAGE_CHANNEL_DIFF(2, 3), 89 + ADC0832_VOLTAGE_CHANNEL_DIFF(3, 2), 90 + ADC0832_VOLTAGE_CHANNEL_DIFF(4, 5), 91 + ADC0832_VOLTAGE_CHANNEL_DIFF(5, 4), 92 + ADC0832_VOLTAGE_CHANNEL_DIFF(6, 7), 93 + ADC0832_VOLTAGE_CHANNEL_DIFF(7, 6), 94 + }; 95 + 96 + static int adc0831_adc_conversion(struct adc0832 *adc) 97 + { 98 + struct spi_device *spi = adc->spi; 99 + int ret; 100 + 101 + ret = spi_read(spi, &adc->rx_buf, 2); 102 + if (ret) 103 + return ret; 104 + 105 + /* 106 + * Skip TRI-STATE and a leading zero 107 + */ 108 + return (adc->rx_buf[0] << 2 & 0xff) | (adc->rx_buf[1] >> 6); 109 + } 110 + 111 + static int adc0832_adc_conversion(struct adc0832 *adc, int channel, 112 + bool differential) 113 + { 114 + struct spi_device *spi = adc->spi; 115 + struct spi_transfer xfer = { 116 + .tx_buf = adc->tx_buf, 117 + .rx_buf = adc->rx_buf, 118 + .len = 2, 119 + }; 120 + int ret; 121 + 122 + if (!adc->mux_bits) 123 + return adc0831_adc_conversion(adc); 124 + 125 + /* start bit */ 126 + adc->tx_buf[0] = 1 << (adc->mux_bits + 1); 127 + /* single-ended or differential */ 128 + adc->tx_buf[0] |= differential ? 0 : (1 << adc->mux_bits); 129 + /* odd / sign */ 130 + adc->tx_buf[0] |= (channel % 2) << (adc->mux_bits - 1); 131 + /* select */ 132 + if (adc->mux_bits > 1) 133 + adc->tx_buf[0] |= channel / 2; 134 + 135 + /* align Data output BIT7 (MSB) to 8-bit boundary */ 136 + adc->tx_buf[0] <<= 1; 137 + 138 + ret = spi_sync_transfer(spi, &xfer, 1); 139 + if (ret) 140 + return ret; 141 + 142 + return adc->rx_buf[1]; 143 + } 144 + 145 + static int adc0832_read_raw(struct iio_dev *iio, 146 + struct iio_chan_spec const *channel, int *value, 147 + int *shift, long mask) 148 + { 149 + struct adc0832 *adc = iio_priv(iio); 150 + 151 + switch (mask) { 152 + case IIO_CHAN_INFO_RAW: 153 + mutex_lock(&adc->lock); 154 + *value = adc0832_adc_conversion(adc, channel->channel, 155 + channel->differential); 156 + mutex_unlock(&adc->lock); 157 + if (*value < 0) 158 + return *value; 159 + 160 + return IIO_VAL_INT; 161 + case IIO_CHAN_INFO_SCALE: 162 + *value = regulator_get_voltage(adc->reg); 163 + if (*value < 0) 164 + return *value; 165 + 166 + /* convert regulator output voltage to mV */ 167 + *value /= 1000; 168 + *shift = 8; 169 + 170 + return IIO_VAL_FRACTIONAL_LOG2; 171 + } 172 + 173 + return -EINVAL; 174 + } 175 + 176 + static const struct iio_info adc0832_info = { 177 + .read_raw = adc0832_read_raw, 178 + .driver_module = THIS_MODULE, 179 + }; 180 + 181 + static int adc0832_probe(struct spi_device *spi) 182 + { 183 + struct iio_dev *indio_dev; 184 + struct adc0832 *adc; 185 + int ret; 186 + 187 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); 188 + if (!indio_dev) 189 + return -ENOMEM; 190 + 191 + adc = iio_priv(indio_dev); 192 + adc->spi = spi; 193 + mutex_init(&adc->lock); 194 + 195 + indio_dev->name = spi_get_device_id(spi)->name; 196 + indio_dev->dev.parent = &spi->dev; 197 + indio_dev->info = &adc0832_info; 198 + indio_dev->modes = INDIO_DIRECT_MODE; 199 + 200 + switch (spi_get_device_id(spi)->driver_data) { 201 + case adc0831: 202 + adc->mux_bits = 0; 203 + indio_dev->channels = adc0831_channels; 204 + indio_dev->num_channels = ARRAY_SIZE(adc0831_channels); 205 + break; 206 + case adc0832: 207 + adc->mux_bits = 1; 208 + indio_dev->channels = adc0832_channels; 209 + indio_dev->num_channels = ARRAY_SIZE(adc0832_channels); 210 + break; 211 + case adc0834: 212 + adc->mux_bits = 2; 213 + indio_dev->channels = adc0834_channels; 214 + indio_dev->num_channels = ARRAY_SIZE(adc0834_channels); 215 + break; 216 + case adc0838: 217 + adc->mux_bits = 3; 218 + indio_dev->channels = adc0838_channels; 219 + indio_dev->num_channels = ARRAY_SIZE(adc0838_channels); 220 + break; 221 + default: 222 + return -EINVAL; 223 + } 224 + 225 + adc->reg = devm_regulator_get(&spi->dev, "vref"); 226 + if (IS_ERR(adc->reg)) 227 + return PTR_ERR(adc->reg); 228 + 229 + ret = regulator_enable(adc->reg); 230 + if (ret) 231 + return ret; 232 + 233 + spi_set_drvdata(spi, indio_dev); 234 + 235 + ret = iio_device_register(indio_dev); 236 + if (ret) 237 + regulator_disable(adc->reg); 238 + 239 + return ret; 240 + } 241 + 242 + static int adc0832_remove(struct spi_device *spi) 243 + { 244 + struct iio_dev *indio_dev = spi_get_drvdata(spi); 245 + struct adc0832 *adc = iio_priv(indio_dev); 246 + 247 + iio_device_unregister(indio_dev); 248 + regulator_disable(adc->reg); 249 + 250 + return 0; 251 + } 252 + 253 + #ifdef CONFIG_OF 254 + 255 + static const struct of_device_id adc0832_dt_ids[] = { 256 + { .compatible = "ti,adc0831", }, 257 + { .compatible = "ti,adc0832", }, 258 + { .compatible = "ti,adc0834", }, 259 + { .compatible = "ti,adc0838", }, 260 + {} 261 + }; 262 + MODULE_DEVICE_TABLE(of, adc0832_dt_ids); 263 + 264 + #endif 265 + 266 + static const struct spi_device_id adc0832_id[] = { 267 + { "adc0831", adc0831 }, 268 + { "adc0832", adc0832 }, 269 + { "adc0834", adc0834 }, 270 + { "adc0838", adc0838 }, 271 + {} 272 + }; 273 + MODULE_DEVICE_TABLE(spi, adc0832_id); 274 + 275 + static struct spi_driver adc0832_driver = { 276 + .driver = { 277 + .name = "adc0832", 278 + .of_match_table = of_match_ptr(adc0832_dt_ids), 279 + }, 280 + .probe = adc0832_probe, 281 + .remove = adc0832_remove, 282 + .id_table = adc0832_id, 283 + }; 284 + module_spi_driver(adc0832_driver); 285 + 286 + MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>"); 287 + MODULE_DESCRIPTION("ADC0831/ADC0832/ADC0834/ADC0838 driver"); 288 + MODULE_LICENSE("GPL v2");
+612
drivers/iio/adc/ti-ads1015.c
··· 1 + /* 2 + * ADS1015 - Texas Instruments Analog-to-Digital Converter 3 + * 4 + * Copyright (c) 2016, Intel Corporation. 5 + * 6 + * This file is subject to the terms and conditions of version 2 of 7 + * the GNU General Public License. See the file COPYING in the main 8 + * directory of this archive for more details. 9 + * 10 + * IIO driver for ADS1015 ADC 7-bit I2C slave address: 11 + * * 0x48 - ADDR connected to Ground 12 + * * 0x49 - ADDR connected to Vdd 13 + * * 0x4A - ADDR connected to SDA 14 + * * 0x4B - ADDR connected to SCL 15 + */ 16 + 17 + #include <linux/module.h> 18 + #include <linux/init.h> 19 + #include <linux/i2c.h> 20 + #include <linux/regmap.h> 21 + #include <linux/pm_runtime.h> 22 + #include <linux/mutex.h> 23 + #include <linux/delay.h> 24 + 25 + #include <linux/i2c/ads1015.h> 26 + 27 + #include <linux/iio/iio.h> 28 + #include <linux/iio/types.h> 29 + #include <linux/iio/sysfs.h> 30 + #include <linux/iio/buffer.h> 31 + #include <linux/iio/triggered_buffer.h> 32 + #include <linux/iio/trigger_consumer.h> 33 + 34 + #define ADS1015_DRV_NAME "ads1015" 35 + 36 + #define ADS1015_CONV_REG 0x00 37 + #define ADS1015_CFG_REG 0x01 38 + 39 + #define ADS1015_CFG_DR_SHIFT 5 40 + #define ADS1015_CFG_MOD_SHIFT 8 41 + #define ADS1015_CFG_PGA_SHIFT 9 42 + #define ADS1015_CFG_MUX_SHIFT 12 43 + 44 + #define ADS1015_CFG_DR_MASK GENMASK(7, 5) 45 + #define ADS1015_CFG_MOD_MASK BIT(8) 46 + #define ADS1015_CFG_PGA_MASK GENMASK(11, 9) 47 + #define ADS1015_CFG_MUX_MASK GENMASK(14, 12) 48 + 49 + /* device operating modes */ 50 + #define ADS1015_CONTINUOUS 0 51 + #define ADS1015_SINGLESHOT 1 52 + 53 + #define ADS1015_SLEEP_DELAY_MS 2000 54 + #define ADS1015_DEFAULT_PGA 2 55 + #define ADS1015_DEFAULT_DATA_RATE 4 56 + #define ADS1015_DEFAULT_CHAN 0 57 + 58 + enum ads1015_channels { 59 + ADS1015_AIN0_AIN1 = 0, 60 + ADS1015_AIN0_AIN3, 61 + ADS1015_AIN1_AIN3, 62 + ADS1015_AIN2_AIN3, 63 + ADS1015_AIN0, 64 + ADS1015_AIN1, 65 + ADS1015_AIN2, 66 + ADS1015_AIN3, 67 + ADS1015_TIMESTAMP, 68 + }; 69 + 70 + static const unsigned int ads1015_data_rate[] = { 71 + 128, 250, 490, 920, 1600, 2400, 3300, 3300 72 + }; 73 + 74 + static const struct { 75 + int scale; 76 + int uscale; 77 + } ads1015_scale[] = { 78 + {3, 0}, 79 + {2, 0}, 80 + {1, 0}, 81 + {0, 500000}, 82 + {0, 250000}, 83 + {0, 125000}, 84 + {0, 125000}, 85 + {0, 125000}, 86 + }; 87 + 88 + #define ADS1015_V_CHAN(_chan, _addr) { \ 89 + .type = IIO_VOLTAGE, \ 90 + .indexed = 1, \ 91 + .address = _addr, \ 92 + .channel = _chan, \ 93 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 94 + BIT(IIO_CHAN_INFO_SCALE) | \ 95 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 96 + .scan_index = _addr, \ 97 + .scan_type = { \ 98 + .sign = 's', \ 99 + .realbits = 12, \ 100 + .storagebits = 16, \ 101 + .shift = 4, \ 102 + .endianness = IIO_CPU, \ 103 + }, \ 104 + } 105 + 106 + #define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr) { \ 107 + .type = IIO_VOLTAGE, \ 108 + .differential = 1, \ 109 + .indexed = 1, \ 110 + .address = _addr, \ 111 + .channel = _chan, \ 112 + .channel2 = _chan2, \ 113 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 114 + BIT(IIO_CHAN_INFO_SCALE) | \ 115 + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 116 + .scan_index = _addr, \ 117 + .scan_type = { \ 118 + .sign = 's', \ 119 + .realbits = 12, \ 120 + .storagebits = 16, \ 121 + .shift = 4, \ 122 + .endianness = IIO_CPU, \ 123 + }, \ 124 + } 125 + 126 + struct ads1015_data { 127 + struct regmap *regmap; 128 + /* 129 + * Protects ADC ops, e.g: concurrent sysfs/buffered 130 + * data reads, configuration updates 131 + */ 132 + struct mutex lock; 133 + struct ads1015_channel_data channel_data[ADS1015_CHANNELS]; 134 + }; 135 + 136 + static bool ads1015_is_writeable_reg(struct device *dev, unsigned int reg) 137 + { 138 + return (reg == ADS1015_CFG_REG); 139 + } 140 + 141 + static const struct regmap_config ads1015_regmap_config = { 142 + .reg_bits = 8, 143 + .val_bits = 16, 144 + .max_register = ADS1015_CFG_REG, 145 + .writeable_reg = ads1015_is_writeable_reg, 146 + }; 147 + 148 + static const struct iio_chan_spec ads1015_channels[] = { 149 + ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1), 150 + ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3), 151 + ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3), 152 + ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3), 153 + ADS1015_V_CHAN(0, ADS1015_AIN0), 154 + ADS1015_V_CHAN(1, ADS1015_AIN1), 155 + ADS1015_V_CHAN(2, ADS1015_AIN2), 156 + ADS1015_V_CHAN(3, ADS1015_AIN3), 157 + IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), 158 + }; 159 + 160 + static int ads1015_set_power_state(struct ads1015_data *data, bool on) 161 + { 162 + int ret; 163 + struct device *dev = regmap_get_device(data->regmap); 164 + 165 + if (on) { 166 + ret = pm_runtime_get_sync(dev); 167 + if (ret < 0) 168 + pm_runtime_put_noidle(dev); 169 + } else { 170 + pm_runtime_mark_last_busy(dev); 171 + ret = pm_runtime_put_autosuspend(dev); 172 + } 173 + 174 + return ret; 175 + } 176 + 177 + static 178 + int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val) 179 + { 180 + int ret, pga, dr, conv_time; 181 + bool change; 182 + 183 + if (chan < 0 || chan >= ADS1015_CHANNELS) 184 + return -EINVAL; 185 + 186 + pga = data->channel_data[chan].pga; 187 + dr = data->channel_data[chan].data_rate; 188 + 189 + ret = regmap_update_bits_check(data->regmap, ADS1015_CFG_REG, 190 + ADS1015_CFG_MUX_MASK | 191 + ADS1015_CFG_PGA_MASK, 192 + chan << ADS1015_CFG_MUX_SHIFT | 193 + pga << ADS1015_CFG_PGA_SHIFT, 194 + &change); 195 + if (ret < 0) 196 + return ret; 197 + 198 + if (change) { 199 + conv_time = DIV_ROUND_UP(USEC_PER_SEC, ads1015_data_rate[dr]); 200 + usleep_range(conv_time, conv_time + 1); 201 + } 202 + 203 + return regmap_read(data->regmap, ADS1015_CONV_REG, val); 204 + } 205 + 206 + static irqreturn_t ads1015_trigger_handler(int irq, void *p) 207 + { 208 + struct iio_poll_func *pf = p; 209 + struct iio_dev *indio_dev = pf->indio_dev; 210 + struct ads1015_data *data = iio_priv(indio_dev); 211 + s16 buf[8]; /* 1x s16 ADC val + 3x s16 padding + 4x s16 timestamp */ 212 + int chan, ret, res; 213 + 214 + memset(buf, 0, sizeof(buf)); 215 + 216 + mutex_lock(&data->lock); 217 + chan = find_first_bit(indio_dev->active_scan_mask, 218 + indio_dev->masklength); 219 + ret = ads1015_get_adc_result(data, chan, &res); 220 + if (ret < 0) { 221 + mutex_unlock(&data->lock); 222 + goto err; 223 + } 224 + 225 + buf[0] = res; 226 + mutex_unlock(&data->lock); 227 + 228 + iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); 229 + 230 + err: 231 + iio_trigger_notify_done(indio_dev->trig); 232 + 233 + return IRQ_HANDLED; 234 + } 235 + 236 + static int ads1015_set_scale(struct ads1015_data *data, int chan, 237 + int scale, int uscale) 238 + { 239 + int i, ret, rindex = -1; 240 + 241 + for (i = 0; i < ARRAY_SIZE(ads1015_scale); i++) 242 + if (ads1015_scale[i].scale == scale && 243 + ads1015_scale[i].uscale == uscale) { 244 + rindex = i; 245 + break; 246 + } 247 + if (rindex < 0) 248 + return -EINVAL; 249 + 250 + ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG, 251 + ADS1015_CFG_PGA_MASK, 252 + rindex << ADS1015_CFG_PGA_SHIFT); 253 + if (ret < 0) 254 + return ret; 255 + 256 + data->channel_data[chan].pga = rindex; 257 + 258 + return 0; 259 + } 260 + 261 + static int ads1015_set_data_rate(struct ads1015_data *data, int chan, int rate) 262 + { 263 + int i, ret, rindex = -1; 264 + 265 + for (i = 0; i < ARRAY_SIZE(ads1015_data_rate); i++) 266 + if (ads1015_data_rate[i] == rate) { 267 + rindex = i; 268 + break; 269 + } 270 + if (rindex < 0) 271 + return -EINVAL; 272 + 273 + ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG, 274 + ADS1015_CFG_DR_MASK, 275 + rindex << ADS1015_CFG_DR_SHIFT); 276 + if (ret < 0) 277 + return ret; 278 + 279 + data->channel_data[chan].data_rate = rindex; 280 + 281 + return 0; 282 + } 283 + 284 + static int ads1015_read_raw(struct iio_dev *indio_dev, 285 + struct iio_chan_spec const *chan, int *val, 286 + int *val2, long mask) 287 + { 288 + int ret, idx; 289 + struct ads1015_data *data = iio_priv(indio_dev); 290 + 291 + mutex_lock(&indio_dev->mlock); 292 + mutex_lock(&data->lock); 293 + switch (mask) { 294 + case IIO_CHAN_INFO_RAW: 295 + if (iio_buffer_enabled(indio_dev)) { 296 + ret = -EBUSY; 297 + break; 298 + } 299 + 300 + ret = ads1015_set_power_state(data, true); 301 + if (ret < 0) 302 + break; 303 + 304 + ret = ads1015_get_adc_result(data, chan->address, val); 305 + if (ret < 0) { 306 + ads1015_set_power_state(data, false); 307 + break; 308 + } 309 + 310 + /* 12 bit res, D0 is bit 4 in conversion register */ 311 + *val = sign_extend32(*val >> 4, 11); 312 + 313 + ret = ads1015_set_power_state(data, false); 314 + if (ret < 0) 315 + break; 316 + 317 + ret = IIO_VAL_INT; 318 + break; 319 + case IIO_CHAN_INFO_SCALE: 320 + idx = data->channel_data[chan->address].pga; 321 + *val = ads1015_scale[idx].scale; 322 + *val2 = ads1015_scale[idx].uscale; 323 + ret = IIO_VAL_INT_PLUS_MICRO; 324 + break; 325 + case IIO_CHAN_INFO_SAMP_FREQ: 326 + idx = data->channel_data[chan->address].data_rate; 327 + *val = ads1015_data_rate[idx]; 328 + ret = IIO_VAL_INT; 329 + break; 330 + default: 331 + ret = -EINVAL; 332 + break; 333 + } 334 + mutex_unlock(&data->lock); 335 + mutex_unlock(&indio_dev->mlock); 336 + 337 + return ret; 338 + } 339 + 340 + static int ads1015_write_raw(struct iio_dev *indio_dev, 341 + struct iio_chan_spec const *chan, int val, 342 + int val2, long mask) 343 + { 344 + struct ads1015_data *data = iio_priv(indio_dev); 345 + int ret; 346 + 347 + mutex_lock(&data->lock); 348 + switch (mask) { 349 + case IIO_CHAN_INFO_SCALE: 350 + ret = ads1015_set_scale(data, chan->address, val, val2); 351 + break; 352 + case IIO_CHAN_INFO_SAMP_FREQ: 353 + ret = ads1015_set_data_rate(data, chan->address, val); 354 + break; 355 + default: 356 + ret = -EINVAL; 357 + break; 358 + } 359 + mutex_unlock(&data->lock); 360 + 361 + return ret; 362 + } 363 + 364 + static int ads1015_buffer_preenable(struct iio_dev *indio_dev) 365 + { 366 + return ads1015_set_power_state(iio_priv(indio_dev), true); 367 + } 368 + 369 + static int ads1015_buffer_postdisable(struct iio_dev *indio_dev) 370 + { 371 + return ads1015_set_power_state(iio_priv(indio_dev), false); 372 + } 373 + 374 + static const struct iio_buffer_setup_ops ads1015_buffer_setup_ops = { 375 + .preenable = ads1015_buffer_preenable, 376 + .postenable = iio_triggered_buffer_postenable, 377 + .predisable = iio_triggered_buffer_predisable, 378 + .postdisable = ads1015_buffer_postdisable, 379 + .validate_scan_mask = &iio_validate_scan_mask_onehot, 380 + }; 381 + 382 + static IIO_CONST_ATTR(scale_available, "3 2 1 0.5 0.25 0.125"); 383 + static IIO_CONST_ATTR(sampling_frequency_available, 384 + "128 250 490 920 1600 2400 3300"); 385 + 386 + static struct attribute *ads1015_attributes[] = { 387 + &iio_const_attr_scale_available.dev_attr.attr, 388 + &iio_const_attr_sampling_frequency_available.dev_attr.attr, 389 + NULL, 390 + }; 391 + 392 + static const struct attribute_group ads1015_attribute_group = { 393 + .attrs = ads1015_attributes, 394 + }; 395 + 396 + static const struct iio_info ads1015_info = { 397 + .driver_module = THIS_MODULE, 398 + .read_raw = ads1015_read_raw, 399 + .write_raw = ads1015_write_raw, 400 + .attrs = &ads1015_attribute_group, 401 + }; 402 + 403 + #ifdef CONFIG_OF 404 + static int ads1015_get_channels_config_of(struct i2c_client *client) 405 + { 406 + struct ads1015_data *data = i2c_get_clientdata(client); 407 + struct device_node *node; 408 + 409 + if (!client->dev.of_node || 410 + !of_get_next_child(client->dev.of_node, NULL)) 411 + return -EINVAL; 412 + 413 + for_each_child_of_node(client->dev.of_node, node) { 414 + u32 pval; 415 + unsigned int channel; 416 + unsigned int pga = ADS1015_DEFAULT_PGA; 417 + unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE; 418 + 419 + if (of_property_read_u32(node, "reg", &pval)) { 420 + dev_err(&client->dev, "invalid reg on %s\n", 421 + node->full_name); 422 + continue; 423 + } 424 + 425 + channel = pval; 426 + if (channel >= ADS1015_CHANNELS) { 427 + dev_err(&client->dev, 428 + "invalid channel index %d on %s\n", 429 + channel, node->full_name); 430 + continue; 431 + } 432 + 433 + if (!of_property_read_u32(node, "ti,gain", &pval)) { 434 + pga = pval; 435 + if (pga > 6) { 436 + dev_err(&client->dev, "invalid gain on %s\n", 437 + node->full_name); 438 + return -EINVAL; 439 + } 440 + } 441 + 442 + if (!of_property_read_u32(node, "ti,datarate", &pval)) { 443 + data_rate = pval; 444 + if (data_rate > 7) { 445 + dev_err(&client->dev, 446 + "invalid data_rate on %s\n", 447 + node->full_name); 448 + return -EINVAL; 449 + } 450 + } 451 + 452 + data->channel_data[channel].pga = pga; 453 + data->channel_data[channel].data_rate = data_rate; 454 + } 455 + 456 + return 0; 457 + } 458 + #endif 459 + 460 + static void ads1015_get_channels_config(struct i2c_client *client) 461 + { 462 + unsigned int k; 463 + 464 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 465 + struct ads1015_data *data = iio_priv(indio_dev); 466 + struct ads1015_platform_data *pdata = dev_get_platdata(&client->dev); 467 + 468 + /* prefer platform data */ 469 + if (pdata) { 470 + memcpy(data->channel_data, pdata->channel_data, 471 + sizeof(data->channel_data)); 472 + return; 473 + } 474 + 475 + #ifdef CONFIG_OF 476 + if (!ads1015_get_channels_config_of(client)) 477 + return; 478 + #endif 479 + /* fallback on default configuration */ 480 + for (k = 0; k < ADS1015_CHANNELS; ++k) { 481 + data->channel_data[k].pga = ADS1015_DEFAULT_PGA; 482 + data->channel_data[k].data_rate = ADS1015_DEFAULT_DATA_RATE; 483 + } 484 + } 485 + 486 + static int ads1015_probe(struct i2c_client *client, 487 + const struct i2c_device_id *id) 488 + { 489 + struct iio_dev *indio_dev; 490 + struct ads1015_data *data; 491 + int ret; 492 + 493 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 494 + if (!indio_dev) 495 + return -ENOMEM; 496 + 497 + data = iio_priv(indio_dev); 498 + i2c_set_clientdata(client, indio_dev); 499 + 500 + mutex_init(&data->lock); 501 + 502 + indio_dev->dev.parent = &client->dev; 503 + indio_dev->info = &ads1015_info; 504 + indio_dev->name = ADS1015_DRV_NAME; 505 + indio_dev->channels = ads1015_channels; 506 + indio_dev->num_channels = ARRAY_SIZE(ads1015_channels); 507 + indio_dev->modes = INDIO_DIRECT_MODE; 508 + 509 + /* we need to keep this ABI the same as used by hwmon ADS1015 driver */ 510 + ads1015_get_channels_config(client); 511 + 512 + data->regmap = devm_regmap_init_i2c(client, &ads1015_regmap_config); 513 + if (IS_ERR(data->regmap)) { 514 + dev_err(&client->dev, "Failed to allocate register map\n"); 515 + return PTR_ERR(data->regmap); 516 + } 517 + 518 + ret = iio_triggered_buffer_setup(indio_dev, NULL, 519 + ads1015_trigger_handler, 520 + &ads1015_buffer_setup_ops); 521 + if (ret < 0) { 522 + dev_err(&client->dev, "iio triggered buffer setup failed\n"); 523 + return ret; 524 + } 525 + ret = pm_runtime_set_active(&client->dev); 526 + if (ret) 527 + goto err_buffer_cleanup; 528 + pm_runtime_set_autosuspend_delay(&client->dev, ADS1015_SLEEP_DELAY_MS); 529 + pm_runtime_use_autosuspend(&client->dev); 530 + pm_runtime_enable(&client->dev); 531 + 532 + ret = iio_device_register(indio_dev); 533 + if (ret < 0) { 534 + dev_err(&client->dev, "Failed to register IIO device\n"); 535 + goto err_buffer_cleanup; 536 + } 537 + 538 + return 0; 539 + 540 + err_buffer_cleanup: 541 + iio_triggered_buffer_cleanup(indio_dev); 542 + 543 + return ret; 544 + } 545 + 546 + static int ads1015_remove(struct i2c_client *client) 547 + { 548 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 549 + struct ads1015_data *data = iio_priv(indio_dev); 550 + 551 + iio_device_unregister(indio_dev); 552 + 553 + pm_runtime_disable(&client->dev); 554 + pm_runtime_set_suspended(&client->dev); 555 + pm_runtime_put_noidle(&client->dev); 556 + 557 + iio_triggered_buffer_cleanup(indio_dev); 558 + 559 + /* power down single shot mode */ 560 + return regmap_update_bits(data->regmap, ADS1015_CFG_REG, 561 + ADS1015_CFG_MOD_MASK, 562 + ADS1015_SINGLESHOT << ADS1015_CFG_MOD_SHIFT); 563 + } 564 + 565 + #ifdef CONFIG_PM 566 + static int ads1015_runtime_suspend(struct device *dev) 567 + { 568 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 569 + struct ads1015_data *data = iio_priv(indio_dev); 570 + 571 + return regmap_update_bits(data->regmap, ADS1015_CFG_REG, 572 + ADS1015_CFG_MOD_MASK, 573 + ADS1015_SINGLESHOT << ADS1015_CFG_MOD_SHIFT); 574 + } 575 + 576 + static int ads1015_runtime_resume(struct device *dev) 577 + { 578 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 579 + struct ads1015_data *data = iio_priv(indio_dev); 580 + 581 + return regmap_update_bits(data->regmap, ADS1015_CFG_REG, 582 + ADS1015_CFG_MOD_MASK, 583 + ADS1015_CONTINUOUS << ADS1015_CFG_MOD_SHIFT); 584 + } 585 + #endif 586 + 587 + static const struct dev_pm_ops ads1015_pm_ops = { 588 + SET_RUNTIME_PM_OPS(ads1015_runtime_suspend, 589 + ads1015_runtime_resume, NULL) 590 + }; 591 + 592 + static const struct i2c_device_id ads1015_id[] = { 593 + {"ads1015", 0}, 594 + {} 595 + }; 596 + MODULE_DEVICE_TABLE(i2c, ads1015_id); 597 + 598 + static struct i2c_driver ads1015_driver = { 599 + .driver = { 600 + .name = ADS1015_DRV_NAME, 601 + .pm = &ads1015_pm_ops, 602 + }, 603 + .probe = ads1015_probe, 604 + .remove = ads1015_remove, 605 + .id_table = ads1015_id, 606 + }; 607 + 608 + module_i2c_driver(ads1015_driver); 609 + 610 + MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>"); 611 + MODULE_DESCRIPTION("Texas Instruments ADS1015 ADC driver"); 612 + MODULE_LICENSE("GPL v2");
+1 -6
drivers/iio/buffer/industrialio-buffer-dmaengine.c
··· 93 93 struct dmaengine_buffer *dmaengine_buffer = 94 94 iio_buffer_to_dmaengine_buffer(&queue->buffer); 95 95 96 - dmaengine_terminate_all(dmaengine_buffer->chan); 97 - /* FIXME: There is a slight chance of a race condition here. 98 - * dmaengine_terminate_all() does not guarantee that all transfer 99 - * callbacks have finished running. Need to introduce a 100 - * dmaengine_terminate_all_sync(). 101 - */ 96 + dmaengine_terminate_sync(dmaengine_buffer->chan); 102 97 iio_dma_buffer_block_list_abort(queue, &dmaengine_buffer->active); 103 98 } 104 99
+1
drivers/iio/chemical/Kconfig
··· 10 10 select REGMAP_I2C 11 11 select IIO_BUFFER 12 12 select IIO_TRIGGERED_BUFFER 13 + select IRQ_WORK 13 14 help 14 15 Say Y here to build I2C interface support for the Atlas 15 16 Scientific OEM pH-SM sensor.
+13 -2
drivers/iio/dac/Kconfig
··· 10 10 depends on (SPI_MASTER && I2C!=m) || I2C 11 11 help 12 12 Say yes here to build support for Analog Devices AD5024, AD5025, AD5044, 13 - AD5045, AD5064, AD5064-1, AD5065, AD5628, AD5629R, AD5648, AD5666, AD5668, 14 - AD5669R Digital to Analog Converter. 13 + AD5045, AD5064, AD5064-1, AD5065, AD5625, AD5625R, AD5627, AD5627R, 14 + AD5628, AD5629R, AD5645R, AD5647R, AD5648, AD5665, AD5665R, AD5666, 15 + AD5667, AD5667R, AD5668, AD5669R, LTC2606, LTC2607, LTC2609, LTC2616, 16 + LTC2617, LTC2619, LTC2626, LTC2627, LTC2629 Digital to Analog Converter. 15 17 16 18 To compile this driver as a module, choose M here: the 17 19 module will be called ad5064. ··· 207 205 208 206 To compile this driver as a module, choose M here: the module 209 207 will be called mcp4922. 208 + 209 + config STX104 210 + tristate "Apex Embedded Systems STX104 DAC driver" 211 + depends on ISA 212 + help 213 + Say yes here to build support for the 2-channel DAC on the Apex 214 + Embedded Systems STX104 integrated analog PC/104 card. The base port 215 + addresses for the devices may be configured via the "base" module 216 + parameter array. 210 217 211 218 endmenu
+1
drivers/iio/dac/Makefile
··· 22 22 obj-$(CONFIG_MAX5821) += max5821.o 23 23 obj-$(CONFIG_MCP4725) += mcp4725.o 24 24 obj-$(CONFIG_MCP4922) += mcp4922.o 25 + obj-$(CONFIG_STX104) += stx104.o
+357 -34
drivers/iio/dac/ad5064.c
··· 1 1 /* 2 - * AD5024, AD5025, AD5044, AD5045, AD5064, AD5064-1, AD5065, AD5628, AD5629R, 3 - * AD5648, AD5666, AD5668, AD5669R Digital to analog converters driver 2 + * AD5024, AD5025, AD5044, AD5045, AD5064, AD5064-1, AD5065, AD5625, AD5625R, 3 + * AD5627, AD5627R, AD5628, AD5629R, AD5645R, AD5647R, AD5648, AD5665, AD5665R, 4 + * AD5666, AD5667, AD5667R, AD5668, AD5669R, LTC2606, LTC2607, LTC2609, LTC2616, 5 + * LTC2617, LTC2619, LTC2626, LTC2627, LTC2629 Digital to analog converters 6 + * driver 4 7 * 5 8 * Copyright 2011 Analog Devices Inc. 6 9 * ··· 42 39 #define AD5064_CMD_RESET 0x7 43 40 #define AD5064_CMD_CONFIG 0x8 44 41 42 + #define AD5064_CMD_RESET_V2 0x5 43 + #define AD5064_CMD_CONFIG_V2 0x7 44 + 45 45 #define AD5064_CONFIG_DAISY_CHAIN_ENABLE BIT(1) 46 46 #define AD5064_CONFIG_INT_VREF_ENABLE BIT(0) 47 47 ··· 54 48 #define AD5064_LDAC_PWRDN_3STATE 0x3 55 49 56 50 /** 51 + * enum ad5064_regmap_type - Register layout variant 52 + * @AD5064_REGMAP_ADI: Old Analog Devices register map layout 53 + * @AD5064_REGMAP_ADI2: New Analog Devices register map layout 54 + * @AD5064_REGMAP_LTC: LTC register map layout 55 + */ 56 + enum ad5064_regmap_type { 57 + AD5064_REGMAP_ADI, 58 + AD5064_REGMAP_ADI2, 59 + AD5064_REGMAP_LTC, 60 + }; 61 + 62 + /** 57 63 * struct ad5064_chip_info - chip specific information 58 64 * @shared_vref: whether the vref supply is shared between channels 59 - * @internal_vref: internal reference voltage. 0 if the chip has no internal 60 - * vref. 65 + * @internal_vref: internal reference voltage. 0 if the chip has no 66 + internal vref. 61 67 * @channel: channel specification 62 68 * @num_channels: number of channels 69 + * @regmap_type: register map layout variant 63 70 */ 64 71 65 72 struct ad5064_chip_info { ··· 80 61 unsigned long internal_vref; 81 62 const struct iio_chan_spec *channels; 82 63 unsigned int num_channels; 64 + enum ad5064_regmap_type regmap_type; 83 65 }; 84 66 85 67 struct ad5064_state; ··· 131 111 ID_AD5064, 132 112 ID_AD5064_1, 133 113 ID_AD5065, 114 + ID_AD5625, 115 + ID_AD5625R_1V25, 116 + ID_AD5625R_2V5, 117 + ID_AD5627, 118 + ID_AD5627R_1V25, 119 + ID_AD5627R_2V5, 134 120 ID_AD5628_1, 135 121 ID_AD5628_2, 136 122 ID_AD5629_1, 137 123 ID_AD5629_2, 124 + ID_AD5645R_1V25, 125 + ID_AD5645R_2V5, 126 + ID_AD5647R_1V25, 127 + ID_AD5647R_2V5, 138 128 ID_AD5648_1, 139 129 ID_AD5648_2, 130 + ID_AD5665, 131 + ID_AD5665R_1V25, 132 + ID_AD5665R_2V5, 140 133 ID_AD5666_1, 141 134 ID_AD5666_2, 135 + ID_AD5667, 136 + ID_AD5667R_1V25, 137 + ID_AD5667R_2V5, 142 138 ID_AD5668_1, 143 139 ID_AD5668_2, 144 140 ID_AD5669_1, 145 141 ID_AD5669_2, 142 + ID_LTC2606, 143 + ID_LTC2607, 144 + ID_LTC2609, 145 + ID_LTC2616, 146 + ID_LTC2617, 147 + ID_LTC2619, 148 + ID_LTC2626, 149 + ID_LTC2627, 150 + ID_LTC2629, 146 151 }; 147 152 148 153 static int ad5064_write(struct ad5064_state *st, unsigned int cmd, ··· 181 136 static int ad5064_sync_powerdown_mode(struct ad5064_state *st, 182 137 const struct iio_chan_spec *chan) 183 138 { 184 - unsigned int val; 139 + unsigned int val, address; 140 + unsigned int shift; 185 141 int ret; 186 142 187 - val = (0x1 << chan->address); 143 + if (st->chip_info->regmap_type == AD5064_REGMAP_LTC) { 144 + val = 0; 145 + address = chan->address; 146 + } else { 147 + if (st->chip_info->regmap_type == AD5064_REGMAP_ADI2) 148 + shift = 4; 149 + else 150 + shift = 8; 188 151 189 - if (st->pwr_down[chan->channel]) 190 - val |= st->pwr_down_mode[chan->channel] << 8; 152 + val = (0x1 << chan->address); 153 + address = 0; 191 154 192 - ret = ad5064_write(st, AD5064_CMD_POWERDOWN_DAC, 0, val, 0); 155 + if (st->pwr_down[chan->channel]) 156 + val |= st->pwr_down_mode[chan->channel] << shift; 157 + } 158 + 159 + ret = ad5064_write(st, AD5064_CMD_POWERDOWN_DAC, address, val, 0); 193 160 194 161 return ret; 195 162 } ··· 210 153 "1kohm_to_gnd", 211 154 "100kohm_to_gnd", 212 155 "three_state", 156 + }; 157 + 158 + static const char * const ltc2617_powerdown_modes[] = { 159 + "90kohm_to_gnd", 213 160 }; 214 161 215 162 static int ad5064_get_powerdown_mode(struct iio_dev *indio_dev, ··· 242 181 static const struct iio_enum ad5064_powerdown_mode_enum = { 243 182 .items = ad5064_powerdown_modes, 244 183 .num_items = ARRAY_SIZE(ad5064_powerdown_modes), 184 + .get = ad5064_get_powerdown_mode, 185 + .set = ad5064_set_powerdown_mode, 186 + }; 187 + 188 + static const struct iio_enum ltc2617_powerdown_mode_enum = { 189 + .items = ltc2617_powerdown_modes, 190 + .num_items = ARRAY_SIZE(ltc2617_powerdown_modes), 245 191 .get = ad5064_get_powerdown_mode, 246 192 .set = ad5064_set_powerdown_mode, 247 193 }; ··· 363 295 { }, 364 296 }; 365 297 366 - #define AD5064_CHANNEL(chan, addr, bits, _shift) { \ 298 + static const struct iio_chan_spec_ext_info ltc2617_ext_info[] = { 299 + { 300 + .name = "powerdown", 301 + .read = ad5064_read_dac_powerdown, 302 + .write = ad5064_write_dac_powerdown, 303 + .shared = IIO_SEPARATE, 304 + }, 305 + IIO_ENUM("powerdown_mode", IIO_SEPARATE, &ltc2617_powerdown_mode_enum), 306 + IIO_ENUM_AVAILABLE("powerdown_mode", &ltc2617_powerdown_mode_enum), 307 + { }, 308 + }; 309 + 310 + #define AD5064_CHANNEL(chan, addr, bits, _shift, _ext_info) { \ 367 311 .type = IIO_VOLTAGE, \ 368 312 .indexed = 1, \ 369 313 .output = 1, \ ··· 389 309 .storagebits = 16, \ 390 310 .shift = (_shift), \ 391 311 }, \ 392 - .ext_info = ad5064_ext_info, \ 312 + .ext_info = (_ext_info), \ 393 313 } 394 314 395 - #define DECLARE_AD5064_CHANNELS(name, bits, shift) \ 315 + #define DECLARE_AD5064_CHANNELS(name, bits, shift, ext_info) \ 396 316 const struct iio_chan_spec name[] = { \ 397 - AD5064_CHANNEL(0, 0, bits, shift), \ 398 - AD5064_CHANNEL(1, 1, bits, shift), \ 399 - AD5064_CHANNEL(2, 2, bits, shift), \ 400 - AD5064_CHANNEL(3, 3, bits, shift), \ 401 - AD5064_CHANNEL(4, 4, bits, shift), \ 402 - AD5064_CHANNEL(5, 5, bits, shift), \ 403 - AD5064_CHANNEL(6, 6, bits, shift), \ 404 - AD5064_CHANNEL(7, 7, bits, shift), \ 317 + AD5064_CHANNEL(0, 0, bits, shift, ext_info), \ 318 + AD5064_CHANNEL(1, 1, bits, shift, ext_info), \ 319 + AD5064_CHANNEL(2, 2, bits, shift, ext_info), \ 320 + AD5064_CHANNEL(3, 3, bits, shift, ext_info), \ 321 + AD5064_CHANNEL(4, 4, bits, shift, ext_info), \ 322 + AD5064_CHANNEL(5, 5, bits, shift, ext_info), \ 323 + AD5064_CHANNEL(6, 6, bits, shift, ext_info), \ 324 + AD5064_CHANNEL(7, 7, bits, shift, ext_info), \ 405 325 } 406 326 407 - #define DECLARE_AD5065_CHANNELS(name, bits, shift) \ 327 + #define DECLARE_AD5065_CHANNELS(name, bits, shift, ext_info) \ 408 328 const struct iio_chan_spec name[] = { \ 409 - AD5064_CHANNEL(0, 0, bits, shift), \ 410 - AD5064_CHANNEL(1, 3, bits, shift), \ 329 + AD5064_CHANNEL(0, 0, bits, shift, ext_info), \ 330 + AD5064_CHANNEL(1, 3, bits, shift, ext_info), \ 411 331 } 412 332 413 - static DECLARE_AD5064_CHANNELS(ad5024_channels, 12, 8); 414 - static DECLARE_AD5064_CHANNELS(ad5044_channels, 14, 6); 415 - static DECLARE_AD5064_CHANNELS(ad5064_channels, 16, 4); 333 + static DECLARE_AD5064_CHANNELS(ad5024_channels, 12, 8, ad5064_ext_info); 334 + static DECLARE_AD5064_CHANNELS(ad5044_channels, 14, 6, ad5064_ext_info); 335 + static DECLARE_AD5064_CHANNELS(ad5064_channels, 16, 4, ad5064_ext_info); 416 336 417 - static DECLARE_AD5065_CHANNELS(ad5025_channels, 12, 8); 418 - static DECLARE_AD5065_CHANNELS(ad5045_channels, 14, 6); 419 - static DECLARE_AD5065_CHANNELS(ad5065_channels, 16, 4); 337 + static DECLARE_AD5065_CHANNELS(ad5025_channels, 12, 8, ad5064_ext_info); 338 + static DECLARE_AD5065_CHANNELS(ad5045_channels, 14, 6, ad5064_ext_info); 339 + static DECLARE_AD5065_CHANNELS(ad5065_channels, 16, 4, ad5064_ext_info); 420 340 421 - static DECLARE_AD5064_CHANNELS(ad5629_channels, 12, 4); 422 - static DECLARE_AD5064_CHANNELS(ad5669_channels, 16, 0); 341 + static DECLARE_AD5064_CHANNELS(ad5629_channels, 12, 4, ad5064_ext_info); 342 + static DECLARE_AD5064_CHANNELS(ad5645_channels, 14, 2, ad5064_ext_info); 343 + static DECLARE_AD5064_CHANNELS(ad5669_channels, 16, 0, ad5064_ext_info); 344 + 345 + static DECLARE_AD5064_CHANNELS(ltc2607_channels, 16, 0, ltc2617_ext_info); 346 + static DECLARE_AD5064_CHANNELS(ltc2617_channels, 14, 2, ltc2617_ext_info); 347 + static DECLARE_AD5064_CHANNELS(ltc2627_channels, 12, 4, ltc2617_ext_info); 423 348 424 349 static const struct ad5064_chip_info ad5064_chip_info_tbl[] = { 425 350 [ID_AD5024] = { 426 351 .shared_vref = false, 427 352 .channels = ad5024_channels, 428 353 .num_channels = 4, 354 + .regmap_type = AD5064_REGMAP_ADI, 429 355 }, 430 356 [ID_AD5025] = { 431 357 .shared_vref = false, 432 358 .channels = ad5025_channels, 433 359 .num_channels = 2, 360 + .regmap_type = AD5064_REGMAP_ADI, 434 361 }, 435 362 [ID_AD5044] = { 436 363 .shared_vref = false, 437 364 .channels = ad5044_channels, 438 365 .num_channels = 4, 366 + .regmap_type = AD5064_REGMAP_ADI, 439 367 }, 440 368 [ID_AD5045] = { 441 369 .shared_vref = false, 442 370 .channels = ad5045_channels, 443 371 .num_channels = 2, 372 + .regmap_type = AD5064_REGMAP_ADI, 444 373 }, 445 374 [ID_AD5064] = { 446 375 .shared_vref = false, 447 376 .channels = ad5064_channels, 448 377 .num_channels = 4, 378 + .regmap_type = AD5064_REGMAP_ADI, 449 379 }, 450 380 [ID_AD5064_1] = { 451 381 .shared_vref = true, 452 382 .channels = ad5064_channels, 453 383 .num_channels = 4, 384 + .regmap_type = AD5064_REGMAP_ADI, 454 385 }, 455 386 [ID_AD5065] = { 456 387 .shared_vref = false, 457 388 .channels = ad5065_channels, 458 389 .num_channels = 2, 390 + .regmap_type = AD5064_REGMAP_ADI, 391 + }, 392 + [ID_AD5625] = { 393 + .shared_vref = true, 394 + .channels = ad5629_channels, 395 + .num_channels = 4, 396 + .regmap_type = AD5064_REGMAP_ADI2 397 + }, 398 + [ID_AD5625R_1V25] = { 399 + .shared_vref = true, 400 + .internal_vref = 1250000, 401 + .channels = ad5629_channels, 402 + .num_channels = 4, 403 + .regmap_type = AD5064_REGMAP_ADI2 404 + }, 405 + [ID_AD5625R_2V5] = { 406 + .shared_vref = true, 407 + .internal_vref = 2500000, 408 + .channels = ad5629_channels, 409 + .num_channels = 4, 410 + .regmap_type = AD5064_REGMAP_ADI2 411 + }, 412 + [ID_AD5627] = { 413 + .shared_vref = true, 414 + .channels = ad5629_channels, 415 + .num_channels = 2, 416 + .regmap_type = AD5064_REGMAP_ADI2 417 + }, 418 + [ID_AD5627R_1V25] = { 419 + .shared_vref = true, 420 + .internal_vref = 1250000, 421 + .channels = ad5629_channels, 422 + .num_channels = 2, 423 + .regmap_type = AD5064_REGMAP_ADI2 424 + }, 425 + [ID_AD5627R_2V5] = { 426 + .shared_vref = true, 427 + .internal_vref = 2500000, 428 + .channels = ad5629_channels, 429 + .num_channels = 2, 430 + .regmap_type = AD5064_REGMAP_ADI2 459 431 }, 460 432 [ID_AD5628_1] = { 461 433 .shared_vref = true, 462 434 .internal_vref = 2500000, 463 435 .channels = ad5024_channels, 464 436 .num_channels = 8, 437 + .regmap_type = AD5064_REGMAP_ADI, 465 438 }, 466 439 [ID_AD5628_2] = { 467 440 .shared_vref = true, 468 441 .internal_vref = 5000000, 469 442 .channels = ad5024_channels, 470 443 .num_channels = 8, 444 + .regmap_type = AD5064_REGMAP_ADI, 471 445 }, 472 446 [ID_AD5629_1] = { 473 447 .shared_vref = true, 474 448 .internal_vref = 2500000, 475 449 .channels = ad5629_channels, 476 450 .num_channels = 8, 451 + .regmap_type = AD5064_REGMAP_ADI, 477 452 }, 478 453 [ID_AD5629_2] = { 479 454 .shared_vref = true, 480 455 .internal_vref = 5000000, 481 456 .channels = ad5629_channels, 482 457 .num_channels = 8, 458 + .regmap_type = AD5064_REGMAP_ADI, 459 + }, 460 + [ID_AD5645R_1V25] = { 461 + .shared_vref = true, 462 + .internal_vref = 1250000, 463 + .channels = ad5645_channels, 464 + .num_channels = 4, 465 + .regmap_type = AD5064_REGMAP_ADI2 466 + }, 467 + [ID_AD5645R_2V5] = { 468 + .shared_vref = true, 469 + .internal_vref = 2500000, 470 + .channels = ad5645_channels, 471 + .num_channels = 4, 472 + .regmap_type = AD5064_REGMAP_ADI2 473 + }, 474 + [ID_AD5647R_1V25] = { 475 + .shared_vref = true, 476 + .internal_vref = 1250000, 477 + .channels = ad5645_channels, 478 + .num_channels = 2, 479 + .regmap_type = AD5064_REGMAP_ADI2 480 + }, 481 + [ID_AD5647R_2V5] = { 482 + .shared_vref = true, 483 + .internal_vref = 2500000, 484 + .channels = ad5645_channels, 485 + .num_channels = 2, 486 + .regmap_type = AD5064_REGMAP_ADI2 483 487 }, 484 488 [ID_AD5648_1] = { 485 489 .shared_vref = true, 486 490 .internal_vref = 2500000, 487 491 .channels = ad5044_channels, 488 492 .num_channels = 8, 493 + .regmap_type = AD5064_REGMAP_ADI, 489 494 }, 490 495 [ID_AD5648_2] = { 491 496 .shared_vref = true, 492 497 .internal_vref = 5000000, 493 498 .channels = ad5044_channels, 494 499 .num_channels = 8, 500 + .regmap_type = AD5064_REGMAP_ADI, 501 + }, 502 + [ID_AD5665] = { 503 + .shared_vref = true, 504 + .channels = ad5669_channels, 505 + .num_channels = 4, 506 + .regmap_type = AD5064_REGMAP_ADI2 507 + }, 508 + [ID_AD5665R_1V25] = { 509 + .shared_vref = true, 510 + .internal_vref = 1250000, 511 + .channels = ad5669_channels, 512 + .num_channels = 4, 513 + .regmap_type = AD5064_REGMAP_ADI2 514 + }, 515 + [ID_AD5665R_2V5] = { 516 + .shared_vref = true, 517 + .internal_vref = 2500000, 518 + .channels = ad5669_channels, 519 + .num_channels = 4, 520 + .regmap_type = AD5064_REGMAP_ADI2 495 521 }, 496 522 [ID_AD5666_1] = { 497 523 .shared_vref = true, 498 524 .internal_vref = 2500000, 499 525 .channels = ad5064_channels, 500 526 .num_channels = 4, 527 + .regmap_type = AD5064_REGMAP_ADI, 501 528 }, 502 529 [ID_AD5666_2] = { 503 530 .shared_vref = true, 504 531 .internal_vref = 5000000, 505 532 .channels = ad5064_channels, 506 533 .num_channels = 4, 534 + .regmap_type = AD5064_REGMAP_ADI, 535 + }, 536 + [ID_AD5667] = { 537 + .shared_vref = true, 538 + .channels = ad5669_channels, 539 + .num_channels = 2, 540 + .regmap_type = AD5064_REGMAP_ADI2 541 + }, 542 + [ID_AD5667R_1V25] = { 543 + .shared_vref = true, 544 + .internal_vref = 1250000, 545 + .channels = ad5669_channels, 546 + .num_channels = 2, 547 + .regmap_type = AD5064_REGMAP_ADI2 548 + }, 549 + [ID_AD5667R_2V5] = { 550 + .shared_vref = true, 551 + .internal_vref = 2500000, 552 + .channels = ad5669_channels, 553 + .num_channels = 2, 554 + .regmap_type = AD5064_REGMAP_ADI2 507 555 }, 508 556 [ID_AD5668_1] = { 509 557 .shared_vref = true, 510 558 .internal_vref = 2500000, 511 559 .channels = ad5064_channels, 512 560 .num_channels = 8, 561 + .regmap_type = AD5064_REGMAP_ADI, 513 562 }, 514 563 [ID_AD5668_2] = { 515 564 .shared_vref = true, 516 565 .internal_vref = 5000000, 517 566 .channels = ad5064_channels, 518 567 .num_channels = 8, 568 + .regmap_type = AD5064_REGMAP_ADI, 519 569 }, 520 570 [ID_AD5669_1] = { 521 571 .shared_vref = true, 522 572 .internal_vref = 2500000, 523 573 .channels = ad5669_channels, 524 574 .num_channels = 8, 575 + .regmap_type = AD5064_REGMAP_ADI, 525 576 }, 526 577 [ID_AD5669_2] = { 527 578 .shared_vref = true, 528 579 .internal_vref = 5000000, 529 580 .channels = ad5669_channels, 530 581 .num_channels = 8, 582 + .regmap_type = AD5064_REGMAP_ADI, 583 + }, 584 + [ID_LTC2606] = { 585 + .shared_vref = true, 586 + .internal_vref = 0, 587 + .channels = ltc2607_channels, 588 + .num_channels = 1, 589 + .regmap_type = AD5064_REGMAP_LTC, 590 + }, 591 + [ID_LTC2607] = { 592 + .shared_vref = true, 593 + .internal_vref = 0, 594 + .channels = ltc2607_channels, 595 + .num_channels = 2, 596 + .regmap_type = AD5064_REGMAP_LTC, 597 + }, 598 + [ID_LTC2609] = { 599 + .shared_vref = false, 600 + .internal_vref = 0, 601 + .channels = ltc2607_channels, 602 + .num_channels = 4, 603 + .regmap_type = AD5064_REGMAP_LTC, 604 + }, 605 + [ID_LTC2616] = { 606 + .shared_vref = true, 607 + .internal_vref = 0, 608 + .channels = ltc2617_channels, 609 + .num_channels = 1, 610 + .regmap_type = AD5064_REGMAP_LTC, 611 + }, 612 + [ID_LTC2617] = { 613 + .shared_vref = true, 614 + .internal_vref = 0, 615 + .channels = ltc2617_channels, 616 + .num_channels = 2, 617 + .regmap_type = AD5064_REGMAP_LTC, 618 + }, 619 + [ID_LTC2619] = { 620 + .shared_vref = false, 621 + .internal_vref = 0, 622 + .channels = ltc2617_channels, 623 + .num_channels = 4, 624 + .regmap_type = AD5064_REGMAP_LTC, 625 + }, 626 + [ID_LTC2626] = { 627 + .shared_vref = true, 628 + .internal_vref = 0, 629 + .channels = ltc2627_channels, 630 + .num_channels = 1, 631 + .regmap_type = AD5064_REGMAP_LTC, 632 + }, 633 + [ID_LTC2627] = { 634 + .shared_vref = true, 635 + .internal_vref = 0, 636 + .channels = ltc2627_channels, 637 + .num_channels = 2, 638 + .regmap_type = AD5064_REGMAP_LTC, 639 + }, 640 + [ID_LTC2629] = { 641 + .shared_vref = false, 642 + .internal_vref = 0, 643 + .channels = ltc2627_channels, 644 + .num_channels = 4, 645 + .regmap_type = AD5064_REGMAP_LTC, 531 646 }, 532 647 }; 533 648 ··· 742 467 unsigned int vref) 743 468 { 744 469 return st->chip_info->shared_vref ? "vref" : ad5064_vref_names[vref]; 470 + } 471 + 472 + static int ad5064_set_config(struct ad5064_state *st, unsigned int val) 473 + { 474 + unsigned int cmd; 475 + 476 + switch (st->chip_info->regmap_type) { 477 + case AD5064_REGMAP_ADI2: 478 + cmd = AD5064_CMD_CONFIG_V2; 479 + break; 480 + default: 481 + cmd = AD5064_CMD_CONFIG; 482 + break; 483 + } 484 + 485 + return ad5064_write(st, cmd, 0, val, 0); 745 486 } 746 487 747 488 static int ad5064_probe(struct device *dev, enum ad5064_type type, ··· 789 498 if (!st->chip_info->internal_vref) 790 499 return ret; 791 500 st->use_internal_vref = true; 792 - ret = ad5064_write(st, AD5064_CMD_CONFIG, 0, 793 - AD5064_CONFIG_INT_VREF_ENABLE, 0); 501 + ret = ad5064_set_config(st, AD5064_CONFIG_INT_VREF_ENABLE); 794 502 if (ret) { 795 503 dev_err(dev, "Failed to enable internal vref: %d\n", 796 504 ret); ··· 918 628 unsigned int addr, unsigned int val) 919 629 { 920 630 struct i2c_client *i2c = to_i2c_client(st->dev); 631 + unsigned int cmd_shift; 921 632 int ret; 922 633 923 - st->data.i2c[0] = (cmd << 4) | addr; 634 + switch (st->chip_info->regmap_type) { 635 + case AD5064_REGMAP_ADI2: 636 + cmd_shift = 3; 637 + break; 638 + default: 639 + cmd_shift = 4; 640 + break; 641 + } 642 + 643 + st->data.i2c[0] = (cmd << cmd_shift) | addr; 924 644 put_unaligned_be16(val, &st->data.i2c[1]); 925 645 926 646 ret = i2c_master_send(i2c, st->data.i2c, 3); ··· 953 653 } 954 654 955 655 static const struct i2c_device_id ad5064_i2c_ids[] = { 656 + {"ad5625", ID_AD5625 }, 657 + {"ad5625r-1v25", ID_AD5625R_1V25 }, 658 + {"ad5625r-2v5", ID_AD5625R_2V5 }, 659 + {"ad5627", ID_AD5627 }, 660 + {"ad5627r-1v25", ID_AD5627R_1V25 }, 661 + {"ad5627r-2v5", ID_AD5627R_2V5 }, 956 662 {"ad5629-1", ID_AD5629_1}, 957 663 {"ad5629-2", ID_AD5629_2}, 958 664 {"ad5629-3", ID_AD5629_2}, /* similar enough to ad5629-2 */ 665 + {"ad5645r-1v25", ID_AD5645R_1V25 }, 666 + {"ad5645r-2v5", ID_AD5645R_2V5 }, 667 + {"ad5665", ID_AD5665 }, 668 + {"ad5665r-1v25", ID_AD5665R_1V25 }, 669 + {"ad5665r-2v5", ID_AD5665R_2V5 }, 670 + {"ad5667", ID_AD5667 }, 671 + {"ad5667r-1v25", ID_AD5667R_1V25 }, 672 + {"ad5667r-2v5", ID_AD5667R_2V5 }, 959 673 {"ad5669-1", ID_AD5669_1}, 960 674 {"ad5669-2", ID_AD5669_2}, 961 675 {"ad5669-3", ID_AD5669_2}, /* similar enough to ad5669-2 */ 676 + {"ltc2606", ID_LTC2606}, 677 + {"ltc2607", ID_LTC2607}, 678 + {"ltc2609", ID_LTC2609}, 679 + {"ltc2616", ID_LTC2616}, 680 + {"ltc2617", ID_LTC2617}, 681 + {"ltc2619", ID_LTC2619}, 682 + {"ltc2626", ID_LTC2626}, 683 + {"ltc2627", ID_LTC2627}, 684 + {"ltc2629", ID_LTC2629}, 962 685 {} 963 686 }; 964 687 MODULE_DEVICE_TABLE(i2c, ad5064_i2c_ids);
+152
drivers/iio/dac/stx104.c
··· 1 + /* 2 + * DAC driver for the Apex Embedded Systems STX104 3 + * Copyright (C) 2016 William Breathitt Gray 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License, version 2, as 7 + * published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, but 10 + * WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 + * General Public License for more details. 13 + */ 14 + #include <linux/bitops.h> 15 + #include <linux/device.h> 16 + #include <linux/errno.h> 17 + #include <linux/iio/iio.h> 18 + #include <linux/iio/types.h> 19 + #include <linux/io.h> 20 + #include <linux/ioport.h> 21 + #include <linux/isa.h> 22 + #include <linux/module.h> 23 + #include <linux/moduleparam.h> 24 + 25 + #define STX104_NUM_CHAN 2 26 + 27 + #define STX104_CHAN(chan) { \ 28 + .type = IIO_VOLTAGE, \ 29 + .channel = chan, \ 30 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 31 + .indexed = 1, \ 32 + .output = 1 \ 33 + } 34 + 35 + #define STX104_EXTENT 16 36 + /** 37 + * The highest base address possible for an ISA device is 0x3FF; this results in 38 + * 1024 possible base addresses. Dividing the number of possible base addresses 39 + * by the address extent taken by each device results in the maximum number of 40 + * devices on a system. 41 + */ 42 + #define MAX_NUM_STX104 (1024 / STX104_EXTENT) 43 + 44 + static unsigned base[MAX_NUM_STX104]; 45 + static unsigned num_stx104; 46 + module_param_array(base, uint, &num_stx104, 0); 47 + MODULE_PARM_DESC(base, "Apex Embedded Systems STX104 base addresses"); 48 + 49 + /** 50 + * struct stx104_iio - IIO device private data structure 51 + * @chan_out_states: channels' output states 52 + * @base: base port address of the IIO device 53 + */ 54 + struct stx104_iio { 55 + unsigned chan_out_states[STX104_NUM_CHAN]; 56 + unsigned base; 57 + }; 58 + 59 + static int stx104_read_raw(struct iio_dev *indio_dev, 60 + struct iio_chan_spec const *chan, int *val, int *val2, long mask) 61 + { 62 + struct stx104_iio *const priv = iio_priv(indio_dev); 63 + 64 + if (mask != IIO_CHAN_INFO_RAW) 65 + return -EINVAL; 66 + 67 + *val = priv->chan_out_states[chan->channel]; 68 + 69 + return IIO_VAL_INT; 70 + } 71 + 72 + static int stx104_write_raw(struct iio_dev *indio_dev, 73 + struct iio_chan_spec const *chan, int val, int val2, long mask) 74 + { 75 + struct stx104_iio *const priv = iio_priv(indio_dev); 76 + const unsigned chan_addr_offset = 2 * chan->channel; 77 + 78 + if (mask != IIO_CHAN_INFO_RAW) 79 + return -EINVAL; 80 + 81 + priv->chan_out_states[chan->channel] = val; 82 + outw(val, priv->base + 4 + chan_addr_offset); 83 + 84 + return 0; 85 + } 86 + 87 + static const struct iio_info stx104_info = { 88 + .driver_module = THIS_MODULE, 89 + .read_raw = stx104_read_raw, 90 + .write_raw = stx104_write_raw 91 + }; 92 + 93 + static const struct iio_chan_spec stx104_channels[STX104_NUM_CHAN] = { 94 + STX104_CHAN(0), 95 + STX104_CHAN(1) 96 + }; 97 + 98 + static int stx104_probe(struct device *dev, unsigned int id) 99 + { 100 + struct iio_dev *indio_dev; 101 + struct stx104_iio *priv; 102 + 103 + indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); 104 + if (!indio_dev) 105 + return -ENOMEM; 106 + 107 + if (!devm_request_region(dev, base[id], STX104_EXTENT, 108 + dev_name(dev))) { 109 + dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", 110 + base[id], base[id] + STX104_EXTENT); 111 + return -EBUSY; 112 + } 113 + 114 + indio_dev->info = &stx104_info; 115 + indio_dev->modes = INDIO_DIRECT_MODE; 116 + indio_dev->channels = stx104_channels; 117 + indio_dev->num_channels = STX104_NUM_CHAN; 118 + indio_dev->name = dev_name(dev); 119 + 120 + priv = iio_priv(indio_dev); 121 + priv->base = base[id]; 122 + 123 + /* initialize DAC output to 0V */ 124 + outw(0, base[id] + 4); 125 + outw(0, base[id] + 6); 126 + 127 + return devm_iio_device_register(dev, indio_dev); 128 + } 129 + 130 + static struct isa_driver stx104_driver = { 131 + .probe = stx104_probe, 132 + .driver = { 133 + .name = "stx104" 134 + } 135 + }; 136 + 137 + static void __exit stx104_exit(void) 138 + { 139 + isa_unregister_driver(&stx104_driver); 140 + } 141 + 142 + static int __init stx104_init(void) 143 + { 144 + return isa_register_driver(&stx104_driver, num_stx104); 145 + } 146 + 147 + module_init(stx104_init); 148 + module_exit(stx104_exit); 149 + 150 + MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); 151 + MODULE_DESCRIPTION("Apex Embedded Systems STX104 DAC driver"); 152 + MODULE_LICENSE("GPL v2");
+30 -1
drivers/iio/health/Kconfig
··· 3 3 # 4 4 # When adding new entries keep the list in alphabetical order 5 5 6 - menu "Health sensors" 6 + menu "Health Sensors" 7 + 8 + menu "Heart Rate Monitors" 9 + 10 + config AFE4403 11 + tristate "TI AFE4403 Heart Rate Monitor" 12 + depends on SPI_MASTER 13 + select IIO_BUFFER 14 + select IIO_TRIGGERED_BUFFER 15 + help 16 + Say yes to choose the Texas Instruments AFE4403 17 + heart rate monitor and low-cost pulse oximeter. 18 + 19 + To compile this driver as a module, choose M here: the 20 + module will be called afe4403. 21 + 22 + config AFE4404 23 + tristate "TI AFE4404 heart rate and pulse oximeter sensor" 24 + depends on I2C 25 + select REGMAP_I2C 26 + select IIO_BUFFER 27 + select IIO_TRIGGERED_BUFFER 28 + help 29 + Say yes to choose the Texas Instruments AFE4404 30 + heart rate monitor and low-cost pulse oximeter. 31 + 32 + To compile this driver as a module, choose M here: the 33 + module will be called afe4404. 7 34 8 35 config MAX30100 9 36 tristate "MAX30100 heart rate and pulse oximeter sensor" ··· 44 17 45 18 To compile this driver as a module, choose M here: the 46 19 module will be called max30100. 20 + 21 + endmenu 47 22 48 23 endmenu
+2
drivers/iio/health/Makefile
··· 4 4 5 5 # When adding new entries keep the list in alphabetical order 6 6 7 + obj-$(CONFIG_AFE4403) += afe4403.o 8 + obj-$(CONFIG_AFE4404) += afe4404.o 7 9 obj-$(CONFIG_MAX30100) += max30100.o
+708
drivers/iio/health/afe4403.c
··· 1 + /* 2 + * AFE4403 Heart Rate Monitors and Low-Cost Pulse Oximeters 3 + * 4 + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ 5 + * Andrew F. Davis <afd@ti.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, but 12 + * WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 + * General Public License for more details. 15 + */ 16 + 17 + #include <linux/device.h> 18 + #include <linux/err.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/kernel.h> 21 + #include <linux/module.h> 22 + #include <linux/regmap.h> 23 + #include <linux/spi/spi.h> 24 + #include <linux/sysfs.h> 25 + #include <linux/regulator/consumer.h> 26 + 27 + #include <linux/iio/iio.h> 28 + #include <linux/iio/sysfs.h> 29 + #include <linux/iio/buffer.h> 30 + #include <linux/iio/trigger.h> 31 + #include <linux/iio/triggered_buffer.h> 32 + #include <linux/iio/trigger_consumer.h> 33 + 34 + #include "afe440x.h" 35 + 36 + #define AFE4403_DRIVER_NAME "afe4403" 37 + 38 + /* AFE4403 Registers */ 39 + #define AFE4403_TIAGAIN 0x20 40 + #define AFE4403_TIA_AMB_GAIN 0x21 41 + 42 + /* AFE4403 GAIN register fields */ 43 + #define AFE4403_TIAGAIN_RES_MASK GENMASK(2, 0) 44 + #define AFE4403_TIAGAIN_RES_SHIFT 0 45 + #define AFE4403_TIAGAIN_CAP_MASK GENMASK(7, 3) 46 + #define AFE4403_TIAGAIN_CAP_SHIFT 3 47 + 48 + /* AFE4403 LEDCNTRL register fields */ 49 + #define AFE440X_LEDCNTRL_LED1_MASK GENMASK(15, 8) 50 + #define AFE440X_LEDCNTRL_LED1_SHIFT 8 51 + #define AFE440X_LEDCNTRL_LED2_MASK GENMASK(7, 0) 52 + #define AFE440X_LEDCNTRL_LED2_SHIFT 0 53 + #define AFE440X_LEDCNTRL_LED_RANGE_MASK GENMASK(17, 16) 54 + #define AFE440X_LEDCNTRL_LED_RANGE_SHIFT 16 55 + 56 + /* AFE4403 CONTROL2 register fields */ 57 + #define AFE440X_CONTROL2_PWR_DWN_TX BIT(2) 58 + #define AFE440X_CONTROL2_EN_SLOW_DIAG BIT(8) 59 + #define AFE440X_CONTROL2_DIAG_OUT_TRI BIT(10) 60 + #define AFE440X_CONTROL2_TX_BRDG_MOD BIT(11) 61 + #define AFE440X_CONTROL2_TX_REF_MASK GENMASK(18, 17) 62 + #define AFE440X_CONTROL2_TX_REF_SHIFT 17 63 + 64 + /* AFE4404 NULL fields */ 65 + #define NULL_MASK 0 66 + #define NULL_SHIFT 0 67 + 68 + /* AFE4403 LEDCNTRL values */ 69 + #define AFE440X_LEDCNTRL_RANGE_TX_HALF 0x1 70 + #define AFE440X_LEDCNTRL_RANGE_TX_FULL 0x2 71 + #define AFE440X_LEDCNTRL_RANGE_TX_OFF 0x3 72 + 73 + /* AFE4403 CONTROL2 values */ 74 + #define AFE440X_CONTROL2_TX_REF_025 0x0 75 + #define AFE440X_CONTROL2_TX_REF_050 0x1 76 + #define AFE440X_CONTROL2_TX_REF_100 0x2 77 + #define AFE440X_CONTROL2_TX_REF_075 0x3 78 + 79 + /* AFE4403 CONTROL3 values */ 80 + #define AFE440X_CONTROL3_CLK_DIV_2 0x0 81 + #define AFE440X_CONTROL3_CLK_DIV_4 0x2 82 + #define AFE440X_CONTROL3_CLK_DIV_6 0x3 83 + #define AFE440X_CONTROL3_CLK_DIV_8 0x4 84 + #define AFE440X_CONTROL3_CLK_DIV_12 0x5 85 + #define AFE440X_CONTROL3_CLK_DIV_1 0x7 86 + 87 + /* AFE4403 TIAGAIN_CAP values */ 88 + #define AFE4403_TIAGAIN_CAP_5_P 0x0 89 + #define AFE4403_TIAGAIN_CAP_10_P 0x1 90 + #define AFE4403_TIAGAIN_CAP_20_P 0x2 91 + #define AFE4403_TIAGAIN_CAP_30_P 0x3 92 + #define AFE4403_TIAGAIN_CAP_55_P 0x8 93 + #define AFE4403_TIAGAIN_CAP_155_P 0x10 94 + 95 + /* AFE4403 TIAGAIN_RES values */ 96 + #define AFE4403_TIAGAIN_RES_500_K 0x0 97 + #define AFE4403_TIAGAIN_RES_250_K 0x1 98 + #define AFE4403_TIAGAIN_RES_100_K 0x2 99 + #define AFE4403_TIAGAIN_RES_50_K 0x3 100 + #define AFE4403_TIAGAIN_RES_25_K 0x4 101 + #define AFE4403_TIAGAIN_RES_10_K 0x5 102 + #define AFE4403_TIAGAIN_RES_1_M 0x6 103 + #define AFE4403_TIAGAIN_RES_NONE 0x7 104 + 105 + /** 106 + * struct afe4403_data 107 + * @dev - Device structure 108 + * @spi - SPI device handle 109 + * @regmap - Register map of the device 110 + * @regulator - Pointer to the regulator for the IC 111 + * @trig - IIO trigger for this device 112 + * @irq - ADC_RDY line interrupt number 113 + */ 114 + struct afe4403_data { 115 + struct device *dev; 116 + struct spi_device *spi; 117 + struct regmap *regmap; 118 + struct regulator *regulator; 119 + struct iio_trigger *trig; 120 + int irq; 121 + }; 122 + 123 + enum afe4403_chan_id { 124 + LED1, 125 + ALED1, 126 + LED2, 127 + ALED2, 128 + LED1_ALED1, 129 + LED2_ALED2, 130 + ILED1, 131 + ILED2, 132 + }; 133 + 134 + static const struct afe440x_reg_info afe4403_reg_info[] = { 135 + [LED1] = AFE440X_REG_INFO(AFE440X_LED1VAL, 0, NULL), 136 + [ALED1] = AFE440X_REG_INFO(AFE440X_ALED1VAL, 0, NULL), 137 + [LED2] = AFE440X_REG_INFO(AFE440X_LED2VAL, 0, NULL), 138 + [ALED2] = AFE440X_REG_INFO(AFE440X_ALED2VAL, 0, NULL), 139 + [LED1_ALED1] = AFE440X_REG_INFO(AFE440X_LED1_ALED1VAL, 0, NULL), 140 + [LED2_ALED2] = AFE440X_REG_INFO(AFE440X_LED2_ALED2VAL, 0, NULL), 141 + [ILED1] = AFE440X_REG_INFO(AFE440X_LEDCNTRL, 0, AFE440X_LEDCNTRL_LED1), 142 + [ILED2] = AFE440X_REG_INFO(AFE440X_LEDCNTRL, 0, AFE440X_LEDCNTRL_LED2), 143 + }; 144 + 145 + static const struct iio_chan_spec afe4403_channels[] = { 146 + /* ADC values */ 147 + AFE440X_INTENSITY_CHAN(LED1, "led1", 0), 148 + AFE440X_INTENSITY_CHAN(ALED1, "led1_ambient", 0), 149 + AFE440X_INTENSITY_CHAN(LED2, "led2", 0), 150 + AFE440X_INTENSITY_CHAN(ALED2, "led2_ambient", 0), 151 + AFE440X_INTENSITY_CHAN(LED1_ALED1, "led1-led1_ambient", 0), 152 + AFE440X_INTENSITY_CHAN(LED2_ALED2, "led2-led2_ambient", 0), 153 + /* LED current */ 154 + AFE440X_CURRENT_CHAN(ILED1, "led1"), 155 + AFE440X_CURRENT_CHAN(ILED2, "led2"), 156 + }; 157 + 158 + static const struct afe440x_val_table afe4403_res_table[] = { 159 + { 500000 }, { 250000 }, { 100000 }, { 50000 }, 160 + { 25000 }, { 10000 }, { 1000000 }, { 0 }, 161 + }; 162 + AFE440X_TABLE_ATTR(tia_resistance_available, afe4403_res_table); 163 + 164 + static const struct afe440x_val_table afe4403_cap_table[] = { 165 + { 0, 5000 }, { 0, 10000 }, { 0, 20000 }, { 0, 25000 }, 166 + { 0, 30000 }, { 0, 35000 }, { 0, 45000 }, { 0, 50000 }, 167 + { 0, 55000 }, { 0, 60000 }, { 0, 70000 }, { 0, 75000 }, 168 + { 0, 80000 }, { 0, 85000 }, { 0, 95000 }, { 0, 100000 }, 169 + { 0, 155000 }, { 0, 160000 }, { 0, 170000 }, { 0, 175000 }, 170 + { 0, 180000 }, { 0, 185000 }, { 0, 195000 }, { 0, 200000 }, 171 + { 0, 205000 }, { 0, 210000 }, { 0, 220000 }, { 0, 225000 }, 172 + { 0, 230000 }, { 0, 235000 }, { 0, 245000 }, { 0, 250000 }, 173 + }; 174 + AFE440X_TABLE_ATTR(tia_capacitance_available, afe4403_cap_table); 175 + 176 + static ssize_t afe440x_show_register(struct device *dev, 177 + struct device_attribute *attr, 178 + char *buf) 179 + { 180 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 181 + struct afe4403_data *afe = iio_priv(indio_dev); 182 + struct afe440x_attr *afe440x_attr = to_afe440x_attr(attr); 183 + unsigned int reg_val, type; 184 + int vals[2]; 185 + int ret, val_len; 186 + 187 + ret = regmap_read(afe->regmap, afe440x_attr->reg, &reg_val); 188 + if (ret) 189 + return ret; 190 + 191 + reg_val &= afe440x_attr->mask; 192 + reg_val >>= afe440x_attr->shift; 193 + 194 + switch (afe440x_attr->type) { 195 + case SIMPLE: 196 + type = IIO_VAL_INT; 197 + val_len = 1; 198 + vals[0] = reg_val; 199 + break; 200 + case RESISTANCE: 201 + case CAPACITANCE: 202 + type = IIO_VAL_INT_PLUS_MICRO; 203 + val_len = 2; 204 + if (reg_val < afe440x_attr->table_size) { 205 + vals[0] = afe440x_attr->val_table[reg_val].integer; 206 + vals[1] = afe440x_attr->val_table[reg_val].fract; 207 + break; 208 + } 209 + return -EINVAL; 210 + default: 211 + return -EINVAL; 212 + } 213 + 214 + return iio_format_value(buf, type, val_len, vals); 215 + } 216 + 217 + static ssize_t afe440x_store_register(struct device *dev, 218 + struct device_attribute *attr, 219 + const char *buf, size_t count) 220 + { 221 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 222 + struct afe4403_data *afe = iio_priv(indio_dev); 223 + struct afe440x_attr *afe440x_attr = to_afe440x_attr(attr); 224 + int val, integer, fract, ret; 225 + 226 + ret = iio_str_to_fixpoint(buf, 100000, &integer, &fract); 227 + if (ret) 228 + return ret; 229 + 230 + switch (afe440x_attr->type) { 231 + case SIMPLE: 232 + val = integer; 233 + break; 234 + case RESISTANCE: 235 + case CAPACITANCE: 236 + for (val = 0; val < afe440x_attr->table_size; val++) 237 + if (afe440x_attr->val_table[val].integer == integer && 238 + afe440x_attr->val_table[val].fract == fract) 239 + break; 240 + if (val == afe440x_attr->table_size) 241 + return -EINVAL; 242 + break; 243 + default: 244 + return -EINVAL; 245 + } 246 + 247 + ret = regmap_update_bits(afe->regmap, afe440x_attr->reg, 248 + afe440x_attr->mask, 249 + (val << afe440x_attr->shift)); 250 + if (ret) 251 + return ret; 252 + 253 + return count; 254 + } 255 + 256 + static AFE440X_ATTR(tia_separate_en, AFE4403_TIAGAIN, AFE440X_TIAGAIN_ENSEPGAIN, SIMPLE, NULL, 0); 257 + 258 + static AFE440X_ATTR(tia_resistance1, AFE4403_TIAGAIN, AFE4403_TIAGAIN_RES, RESISTANCE, afe4403_res_table, ARRAY_SIZE(afe4403_res_table)); 259 + static AFE440X_ATTR(tia_capacitance1, AFE4403_TIAGAIN, AFE4403_TIAGAIN_CAP, CAPACITANCE, afe4403_cap_table, ARRAY_SIZE(afe4403_cap_table)); 260 + 261 + static AFE440X_ATTR(tia_resistance2, AFE4403_TIA_AMB_GAIN, AFE4403_TIAGAIN_RES, RESISTANCE, afe4403_res_table, ARRAY_SIZE(afe4403_res_table)); 262 + static AFE440X_ATTR(tia_capacitance2, AFE4403_TIA_AMB_GAIN, AFE4403_TIAGAIN_RES, CAPACITANCE, afe4403_cap_table, ARRAY_SIZE(afe4403_cap_table)); 263 + 264 + static struct attribute *afe440x_attributes[] = { 265 + &afe440x_attr_tia_separate_en.dev_attr.attr, 266 + &afe440x_attr_tia_resistance1.dev_attr.attr, 267 + &afe440x_attr_tia_capacitance1.dev_attr.attr, 268 + &afe440x_attr_tia_resistance2.dev_attr.attr, 269 + &afe440x_attr_tia_capacitance2.dev_attr.attr, 270 + &dev_attr_tia_resistance_available.attr, 271 + &dev_attr_tia_capacitance_available.attr, 272 + NULL 273 + }; 274 + 275 + static const struct attribute_group afe440x_attribute_group = { 276 + .attrs = afe440x_attributes 277 + }; 278 + 279 + static int afe4403_read(struct afe4403_data *afe, unsigned int reg, u32 *val) 280 + { 281 + u8 tx[4] = {AFE440X_CONTROL0, 0x0, 0x0, AFE440X_CONTROL0_READ}; 282 + u8 rx[3]; 283 + int ret; 284 + 285 + /* Enable reading from the device */ 286 + ret = spi_write_then_read(afe->spi, tx, 4, NULL, 0); 287 + if (ret) 288 + return ret; 289 + 290 + ret = spi_write_then_read(afe->spi, &reg, 1, rx, 3); 291 + if (ret) 292 + return ret; 293 + 294 + *val = (rx[0] << 16) | 295 + (rx[1] << 8) | 296 + (rx[2]); 297 + 298 + /* Disable reading from the device */ 299 + tx[3] = AFE440X_CONTROL0_WRITE; 300 + ret = spi_write_then_read(afe->spi, tx, 4, NULL, 0); 301 + if (ret) 302 + return ret; 303 + 304 + return 0; 305 + } 306 + 307 + static int afe4403_read_raw(struct iio_dev *indio_dev, 308 + struct iio_chan_spec const *chan, 309 + int *val, int *val2, long mask) 310 + { 311 + struct afe4403_data *afe = iio_priv(indio_dev); 312 + const struct afe440x_reg_info reg_info = afe4403_reg_info[chan->address]; 313 + int ret; 314 + 315 + switch (chan->type) { 316 + case IIO_INTENSITY: 317 + switch (mask) { 318 + case IIO_CHAN_INFO_RAW: 319 + ret = afe4403_read(afe, reg_info.reg, val); 320 + if (ret) 321 + return ret; 322 + return IIO_VAL_INT; 323 + case IIO_CHAN_INFO_OFFSET: 324 + ret = regmap_read(afe->regmap, reg_info.offreg, 325 + val); 326 + if (ret) 327 + return ret; 328 + *val &= reg_info.mask; 329 + *val >>= reg_info.shift; 330 + return IIO_VAL_INT; 331 + } 332 + break; 333 + case IIO_CURRENT: 334 + switch (mask) { 335 + case IIO_CHAN_INFO_RAW: 336 + ret = regmap_read(afe->regmap, reg_info.reg, val); 337 + if (ret) 338 + return ret; 339 + *val &= reg_info.mask; 340 + *val >>= reg_info.shift; 341 + return IIO_VAL_INT; 342 + case IIO_CHAN_INFO_SCALE: 343 + *val = 0; 344 + *val2 = 800000; 345 + return IIO_VAL_INT_PLUS_MICRO; 346 + } 347 + break; 348 + default: 349 + break; 350 + } 351 + 352 + return -EINVAL; 353 + } 354 + 355 + static int afe4403_write_raw(struct iio_dev *indio_dev, 356 + struct iio_chan_spec const *chan, 357 + int val, int val2, long mask) 358 + { 359 + struct afe4403_data *afe = iio_priv(indio_dev); 360 + const struct afe440x_reg_info reg_info = afe4403_reg_info[chan->address]; 361 + 362 + switch (chan->type) { 363 + case IIO_INTENSITY: 364 + switch (mask) { 365 + case IIO_CHAN_INFO_OFFSET: 366 + return regmap_update_bits(afe->regmap, 367 + reg_info.offreg, 368 + reg_info.mask, 369 + (val << reg_info.shift)); 370 + } 371 + break; 372 + case IIO_CURRENT: 373 + switch (mask) { 374 + case IIO_CHAN_INFO_RAW: 375 + return regmap_update_bits(afe->regmap, 376 + reg_info.reg, 377 + reg_info.mask, 378 + (val << reg_info.shift)); 379 + } 380 + break; 381 + default: 382 + break; 383 + } 384 + 385 + return -EINVAL; 386 + } 387 + 388 + static const struct iio_info afe4403_iio_info = { 389 + .attrs = &afe440x_attribute_group, 390 + .read_raw = afe4403_read_raw, 391 + .write_raw = afe4403_write_raw, 392 + .driver_module = THIS_MODULE, 393 + }; 394 + 395 + static irqreturn_t afe4403_trigger_handler(int irq, void *private) 396 + { 397 + struct iio_poll_func *pf = private; 398 + struct iio_dev *indio_dev = pf->indio_dev; 399 + struct afe4403_data *afe = iio_priv(indio_dev); 400 + int ret, bit, i = 0; 401 + s32 buffer[8]; 402 + u8 tx[4] = {AFE440X_CONTROL0, 0x0, 0x0, AFE440X_CONTROL0_READ}; 403 + u8 rx[3]; 404 + 405 + /* Enable reading from the device */ 406 + ret = spi_write_then_read(afe->spi, tx, 4, NULL, 0); 407 + if (ret) 408 + goto err; 409 + 410 + for_each_set_bit(bit, indio_dev->active_scan_mask, 411 + indio_dev->masklength) { 412 + ret = spi_write_then_read(afe->spi, 413 + &afe4403_reg_info[bit].reg, 1, 414 + rx, 3); 415 + if (ret) 416 + goto err; 417 + 418 + buffer[i++] = (rx[0] << 16) | 419 + (rx[1] << 8) | 420 + (rx[2]); 421 + } 422 + 423 + /* Disable reading from the device */ 424 + tx[3] = AFE440X_CONTROL0_WRITE; 425 + ret = spi_write_then_read(afe->spi, tx, 4, NULL, 0); 426 + if (ret) 427 + goto err; 428 + 429 + iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp); 430 + err: 431 + iio_trigger_notify_done(indio_dev->trig); 432 + 433 + return IRQ_HANDLED; 434 + } 435 + 436 + static const struct iio_trigger_ops afe4403_trigger_ops = { 437 + .owner = THIS_MODULE, 438 + }; 439 + 440 + #define AFE4403_TIMING_PAIRS \ 441 + { AFE440X_LED2STC, 0x000050 }, \ 442 + { AFE440X_LED2ENDC, 0x0003e7 }, \ 443 + { AFE440X_LED1LEDSTC, 0x0007d0 }, \ 444 + { AFE440X_LED1LEDENDC, 0x000bb7 }, \ 445 + { AFE440X_ALED2STC, 0x000438 }, \ 446 + { AFE440X_ALED2ENDC, 0x0007cf }, \ 447 + { AFE440X_LED1STC, 0x000820 }, \ 448 + { AFE440X_LED1ENDC, 0x000bb7 }, \ 449 + { AFE440X_LED2LEDSTC, 0x000000 }, \ 450 + { AFE440X_LED2LEDENDC, 0x0003e7 }, \ 451 + { AFE440X_ALED1STC, 0x000c08 }, \ 452 + { AFE440X_ALED1ENDC, 0x000f9f }, \ 453 + { AFE440X_LED2CONVST, 0x0003ef }, \ 454 + { AFE440X_LED2CONVEND, 0x0007cf }, \ 455 + { AFE440X_ALED2CONVST, 0x0007d7 }, \ 456 + { AFE440X_ALED2CONVEND, 0x000bb7 }, \ 457 + { AFE440X_LED1CONVST, 0x000bbf }, \ 458 + { AFE440X_LED1CONVEND, 0x009c3f }, \ 459 + { AFE440X_ALED1CONVST, 0x000fa7 }, \ 460 + { AFE440X_ALED1CONVEND, 0x001387 }, \ 461 + { AFE440X_ADCRSTSTCT0, 0x0003e8 }, \ 462 + { AFE440X_ADCRSTENDCT0, 0x0003eb }, \ 463 + { AFE440X_ADCRSTSTCT1, 0x0007d0 }, \ 464 + { AFE440X_ADCRSTENDCT1, 0x0007d3 }, \ 465 + { AFE440X_ADCRSTSTCT2, 0x000bb8 }, \ 466 + { AFE440X_ADCRSTENDCT2, 0x000bbb }, \ 467 + { AFE440X_ADCRSTSTCT3, 0x000fa0 }, \ 468 + { AFE440X_ADCRSTENDCT3, 0x000fa3 }, \ 469 + { AFE440X_PRPCOUNT, 0x009c3f }, \ 470 + { AFE440X_PDNCYCLESTC, 0x001518 }, \ 471 + { AFE440X_PDNCYCLEENDC, 0x00991f } 472 + 473 + static const struct reg_sequence afe4403_reg_sequences[] = { 474 + AFE4403_TIMING_PAIRS, 475 + { AFE440X_CONTROL1, AFE440X_CONTROL1_TIMEREN | 0x000007}, 476 + { AFE4403_TIA_AMB_GAIN, AFE4403_TIAGAIN_RES_1_M }, 477 + { AFE440X_LEDCNTRL, (0x14 << AFE440X_LEDCNTRL_LED1_SHIFT) | 478 + (0x14 << AFE440X_LEDCNTRL_LED2_SHIFT) }, 479 + { AFE440X_CONTROL2, AFE440X_CONTROL2_TX_REF_050 << 480 + AFE440X_CONTROL2_TX_REF_SHIFT }, 481 + }; 482 + 483 + static const struct regmap_range afe4403_yes_ranges[] = { 484 + regmap_reg_range(AFE440X_LED2VAL, AFE440X_LED1_ALED1VAL), 485 + }; 486 + 487 + static const struct regmap_access_table afe4403_volatile_table = { 488 + .yes_ranges = afe4403_yes_ranges, 489 + .n_yes_ranges = ARRAY_SIZE(afe4403_yes_ranges), 490 + }; 491 + 492 + static const struct regmap_config afe4403_regmap_config = { 493 + .reg_bits = 8, 494 + .val_bits = 24, 495 + 496 + .max_register = AFE440X_PDNCYCLEENDC, 497 + .cache_type = REGCACHE_RBTREE, 498 + .volatile_table = &afe4403_volatile_table, 499 + }; 500 + 501 + #ifdef CONFIG_OF 502 + static const struct of_device_id afe4403_of_match[] = { 503 + { .compatible = "ti,afe4403", }, 504 + { /* sentinel */ } 505 + }; 506 + MODULE_DEVICE_TABLE(of, afe4403_of_match); 507 + #endif 508 + 509 + static int afe4403_suspend(struct device *dev) 510 + { 511 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 512 + struct afe4403_data *afe = iio_priv(indio_dev); 513 + int ret; 514 + 515 + ret = regmap_update_bits(afe->regmap, AFE440X_CONTROL2, 516 + AFE440X_CONTROL2_PDN_AFE, 517 + AFE440X_CONTROL2_PDN_AFE); 518 + if (ret) 519 + return ret; 520 + 521 + ret = regulator_disable(afe->regulator); 522 + if (ret) { 523 + dev_err(dev, "Unable to disable regulator\n"); 524 + return ret; 525 + } 526 + 527 + return 0; 528 + } 529 + 530 + static int afe4403_resume(struct device *dev) 531 + { 532 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 533 + struct afe4403_data *afe = iio_priv(indio_dev); 534 + int ret; 535 + 536 + ret = regulator_enable(afe->regulator); 537 + if (ret) { 538 + dev_err(dev, "Unable to enable regulator\n"); 539 + return ret; 540 + } 541 + 542 + ret = regmap_update_bits(afe->regmap, AFE440X_CONTROL2, 543 + AFE440X_CONTROL2_PDN_AFE, 0); 544 + if (ret) 545 + return ret; 546 + 547 + return 0; 548 + } 549 + 550 + static SIMPLE_DEV_PM_OPS(afe4403_pm_ops, afe4403_suspend, afe4403_resume); 551 + 552 + static int afe4403_probe(struct spi_device *spi) 553 + { 554 + struct iio_dev *indio_dev; 555 + struct afe4403_data *afe; 556 + int ret; 557 + 558 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*afe)); 559 + if (!indio_dev) 560 + return -ENOMEM; 561 + 562 + afe = iio_priv(indio_dev); 563 + spi_set_drvdata(spi, indio_dev); 564 + 565 + afe->dev = &spi->dev; 566 + afe->spi = spi; 567 + afe->irq = spi->irq; 568 + 569 + afe->regmap = devm_regmap_init_spi(spi, &afe4403_regmap_config); 570 + if (IS_ERR(afe->regmap)) { 571 + dev_err(afe->dev, "Unable to allocate register map\n"); 572 + return PTR_ERR(afe->regmap); 573 + } 574 + 575 + afe->regulator = devm_regulator_get(afe->dev, "tx_sup"); 576 + if (IS_ERR(afe->regulator)) { 577 + dev_err(afe->dev, "Unable to get regulator\n"); 578 + return PTR_ERR(afe->regulator); 579 + } 580 + ret = regulator_enable(afe->regulator); 581 + if (ret) { 582 + dev_err(afe->dev, "Unable to enable regulator\n"); 583 + return ret; 584 + } 585 + 586 + ret = regmap_write(afe->regmap, AFE440X_CONTROL0, 587 + AFE440X_CONTROL0_SW_RESET); 588 + if (ret) { 589 + dev_err(afe->dev, "Unable to reset device\n"); 590 + goto err_disable_reg; 591 + } 592 + 593 + ret = regmap_multi_reg_write(afe->regmap, afe4403_reg_sequences, 594 + ARRAY_SIZE(afe4403_reg_sequences)); 595 + if (ret) { 596 + dev_err(afe->dev, "Unable to set register defaults\n"); 597 + goto err_disable_reg; 598 + } 599 + 600 + indio_dev->modes = INDIO_DIRECT_MODE; 601 + indio_dev->dev.parent = afe->dev; 602 + indio_dev->channels = afe4403_channels; 603 + indio_dev->num_channels = ARRAY_SIZE(afe4403_channels); 604 + indio_dev->name = AFE4403_DRIVER_NAME; 605 + indio_dev->info = &afe4403_iio_info; 606 + 607 + if (afe->irq > 0) { 608 + afe->trig = devm_iio_trigger_alloc(afe->dev, 609 + "%s-dev%d", 610 + indio_dev->name, 611 + indio_dev->id); 612 + if (!afe->trig) { 613 + dev_err(afe->dev, "Unable to allocate IIO trigger\n"); 614 + ret = -ENOMEM; 615 + goto err_disable_reg; 616 + } 617 + 618 + iio_trigger_set_drvdata(afe->trig, indio_dev); 619 + 620 + afe->trig->ops = &afe4403_trigger_ops; 621 + afe->trig->dev.parent = afe->dev; 622 + 623 + ret = iio_trigger_register(afe->trig); 624 + if (ret) { 625 + dev_err(afe->dev, "Unable to register IIO trigger\n"); 626 + goto err_disable_reg; 627 + } 628 + 629 + ret = devm_request_threaded_irq(afe->dev, afe->irq, 630 + iio_trigger_generic_data_rdy_poll, 631 + NULL, IRQF_ONESHOT, 632 + AFE4403_DRIVER_NAME, 633 + afe->trig); 634 + if (ret) { 635 + dev_err(afe->dev, "Unable to request IRQ\n"); 636 + goto err_trig; 637 + } 638 + } 639 + 640 + ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, 641 + afe4403_trigger_handler, NULL); 642 + if (ret) { 643 + dev_err(afe->dev, "Unable to setup buffer\n"); 644 + goto err_trig; 645 + } 646 + 647 + ret = iio_device_register(indio_dev); 648 + if (ret) { 649 + dev_err(afe->dev, "Unable to register IIO device\n"); 650 + goto err_buff; 651 + } 652 + 653 + return 0; 654 + 655 + err_buff: 656 + iio_triggered_buffer_cleanup(indio_dev); 657 + err_trig: 658 + if (afe->irq > 0) 659 + iio_trigger_unregister(afe->trig); 660 + err_disable_reg: 661 + regulator_disable(afe->regulator); 662 + 663 + return ret; 664 + } 665 + 666 + static int afe4403_remove(struct spi_device *spi) 667 + { 668 + struct iio_dev *indio_dev = spi_get_drvdata(spi); 669 + struct afe4403_data *afe = iio_priv(indio_dev); 670 + int ret; 671 + 672 + iio_device_unregister(indio_dev); 673 + 674 + iio_triggered_buffer_cleanup(indio_dev); 675 + 676 + if (afe->irq > 0) 677 + iio_trigger_unregister(afe->trig); 678 + 679 + ret = regulator_disable(afe->regulator); 680 + if (ret) { 681 + dev_err(afe->dev, "Unable to disable regulator\n"); 682 + return ret; 683 + } 684 + 685 + return 0; 686 + } 687 + 688 + static const struct spi_device_id afe4403_ids[] = { 689 + { "afe4403", 0 }, 690 + { /* sentinel */ } 691 + }; 692 + MODULE_DEVICE_TABLE(spi, afe4403_ids); 693 + 694 + static struct spi_driver afe4403_spi_driver = { 695 + .driver = { 696 + .name = AFE4403_DRIVER_NAME, 697 + .of_match_table = of_match_ptr(afe4403_of_match), 698 + .pm = &afe4403_pm_ops, 699 + }, 700 + .probe = afe4403_probe, 701 + .remove = afe4403_remove, 702 + .id_table = afe4403_ids, 703 + }; 704 + module_spi_driver(afe4403_spi_driver); 705 + 706 + MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>"); 707 + MODULE_DESCRIPTION("TI AFE4403 Heart Rate and Pulse Oximeter"); 708 + MODULE_LICENSE("GPL v2");
+679
drivers/iio/health/afe4404.c
··· 1 + /* 2 + * AFE4404 Heart Rate Monitors and Low-Cost Pulse Oximeters 3 + * 4 + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ 5 + * Andrew F. Davis <afd@ti.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, but 12 + * WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 + * General Public License for more details. 15 + */ 16 + 17 + #include <linux/device.h> 18 + #include <linux/err.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/i2c.h> 21 + #include <linux/kernel.h> 22 + #include <linux/module.h> 23 + #include <linux/regmap.h> 24 + #include <linux/sysfs.h> 25 + #include <linux/regulator/consumer.h> 26 + 27 + #include <linux/iio/iio.h> 28 + #include <linux/iio/sysfs.h> 29 + #include <linux/iio/buffer.h> 30 + #include <linux/iio/trigger.h> 31 + #include <linux/iio/triggered_buffer.h> 32 + #include <linux/iio/trigger_consumer.h> 33 + 34 + #include "afe440x.h" 35 + 36 + #define AFE4404_DRIVER_NAME "afe4404" 37 + 38 + /* AFE4404 registers */ 39 + #define AFE4404_TIA_GAIN_SEP 0x20 40 + #define AFE4404_TIA_GAIN 0x21 41 + #define AFE4404_PROG_TG_STC 0x34 42 + #define AFE4404_PROG_TG_ENDC 0x35 43 + #define AFE4404_LED3LEDSTC 0x36 44 + #define AFE4404_LED3LEDENDC 0x37 45 + #define AFE4404_CLKDIV_PRF 0x39 46 + #define AFE4404_OFFDAC 0x3a 47 + #define AFE4404_DEC 0x3d 48 + #define AFE4404_AVG_LED2_ALED2VAL 0x3f 49 + #define AFE4404_AVG_LED1_ALED1VAL 0x40 50 + 51 + /* AFE4404 GAIN register fields */ 52 + #define AFE4404_TIA_GAIN_RES_MASK GENMASK(2, 0) 53 + #define AFE4404_TIA_GAIN_RES_SHIFT 0 54 + #define AFE4404_TIA_GAIN_CAP_MASK GENMASK(5, 3) 55 + #define AFE4404_TIA_GAIN_CAP_SHIFT 3 56 + 57 + /* AFE4404 LEDCNTRL register fields */ 58 + #define AFE4404_LEDCNTRL_ILED1_MASK GENMASK(5, 0) 59 + #define AFE4404_LEDCNTRL_ILED1_SHIFT 0 60 + #define AFE4404_LEDCNTRL_ILED2_MASK GENMASK(11, 6) 61 + #define AFE4404_LEDCNTRL_ILED2_SHIFT 6 62 + #define AFE4404_LEDCNTRL_ILED3_MASK GENMASK(17, 12) 63 + #define AFE4404_LEDCNTRL_ILED3_SHIFT 12 64 + 65 + /* AFE4404 CONTROL2 register fields */ 66 + #define AFE440X_CONTROL2_ILED_2X_MASK BIT(17) 67 + #define AFE440X_CONTROL2_ILED_2X_SHIFT 17 68 + 69 + /* AFE4404 CONTROL3 register fields */ 70 + #define AFE440X_CONTROL3_OSC_ENABLE BIT(9) 71 + 72 + /* AFE4404 OFFDAC register current fields */ 73 + #define AFE4404_OFFDAC_CURR_LED1_MASK GENMASK(9, 5) 74 + #define AFE4404_OFFDAC_CURR_LED1_SHIFT 5 75 + #define AFE4404_OFFDAC_CURR_LED2_MASK GENMASK(19, 15) 76 + #define AFE4404_OFFDAC_CURR_LED2_SHIFT 15 77 + #define AFE4404_OFFDAC_CURR_LED3_MASK GENMASK(4, 0) 78 + #define AFE4404_OFFDAC_CURR_LED3_SHIFT 0 79 + #define AFE4404_OFFDAC_CURR_ALED1_MASK GENMASK(14, 10) 80 + #define AFE4404_OFFDAC_CURR_ALED1_SHIFT 10 81 + #define AFE4404_OFFDAC_CURR_ALED2_MASK GENMASK(4, 0) 82 + #define AFE4404_OFFDAC_CURR_ALED2_SHIFT 0 83 + 84 + /* AFE4404 NULL fields */ 85 + #define NULL_MASK 0 86 + #define NULL_SHIFT 0 87 + 88 + /* AFE4404 TIA_GAIN_CAP values */ 89 + #define AFE4404_TIA_GAIN_CAP_5_P 0x0 90 + #define AFE4404_TIA_GAIN_CAP_2_5_P 0x1 91 + #define AFE4404_TIA_GAIN_CAP_10_P 0x2 92 + #define AFE4404_TIA_GAIN_CAP_7_5_P 0x3 93 + #define AFE4404_TIA_GAIN_CAP_20_P 0x4 94 + #define AFE4404_TIA_GAIN_CAP_17_5_P 0x5 95 + #define AFE4404_TIA_GAIN_CAP_25_P 0x6 96 + #define AFE4404_TIA_GAIN_CAP_22_5_P 0x7 97 + 98 + /* AFE4404 TIA_GAIN_RES values */ 99 + #define AFE4404_TIA_GAIN_RES_500_K 0x0 100 + #define AFE4404_TIA_GAIN_RES_250_K 0x1 101 + #define AFE4404_TIA_GAIN_RES_100_K 0x2 102 + #define AFE4404_TIA_GAIN_RES_50_K 0x3 103 + #define AFE4404_TIA_GAIN_RES_25_K 0x4 104 + #define AFE4404_TIA_GAIN_RES_10_K 0x5 105 + #define AFE4404_TIA_GAIN_RES_1_M 0x6 106 + #define AFE4404_TIA_GAIN_RES_2_M 0x7 107 + 108 + /** 109 + * struct afe4404_data 110 + * @dev - Device structure 111 + * @regmap - Register map of the device 112 + * @regulator - Pointer to the regulator for the IC 113 + * @trig - IIO trigger for this device 114 + * @irq - ADC_RDY line interrupt number 115 + */ 116 + struct afe4404_data { 117 + struct device *dev; 118 + struct regmap *regmap; 119 + struct regulator *regulator; 120 + struct iio_trigger *trig; 121 + int irq; 122 + }; 123 + 124 + enum afe4404_chan_id { 125 + LED1, 126 + ALED1, 127 + LED2, 128 + ALED2, 129 + LED3, 130 + LED1_ALED1, 131 + LED2_ALED2, 132 + ILED1, 133 + ILED2, 134 + ILED3, 135 + }; 136 + 137 + static const struct afe440x_reg_info afe4404_reg_info[] = { 138 + [LED1] = AFE440X_REG_INFO(AFE440X_LED1VAL, AFE4404_OFFDAC, AFE4404_OFFDAC_CURR_LED1), 139 + [ALED1] = AFE440X_REG_INFO(AFE440X_ALED1VAL, AFE4404_OFFDAC, AFE4404_OFFDAC_CURR_ALED1), 140 + [LED2] = AFE440X_REG_INFO(AFE440X_LED2VAL, AFE4404_OFFDAC, AFE4404_OFFDAC_CURR_LED2), 141 + [ALED2] = AFE440X_REG_INFO(AFE440X_ALED2VAL, AFE4404_OFFDAC, AFE4404_OFFDAC_CURR_ALED2), 142 + [LED3] = AFE440X_REG_INFO(AFE440X_ALED2VAL, 0, NULL), 143 + [LED1_ALED1] = AFE440X_REG_INFO(AFE440X_LED1_ALED1VAL, 0, NULL), 144 + [LED2_ALED2] = AFE440X_REG_INFO(AFE440X_LED2_ALED2VAL, 0, NULL), 145 + [ILED1] = AFE440X_REG_INFO(AFE440X_LEDCNTRL, 0, AFE4404_LEDCNTRL_ILED1), 146 + [ILED2] = AFE440X_REG_INFO(AFE440X_LEDCNTRL, 0, AFE4404_LEDCNTRL_ILED2), 147 + [ILED3] = AFE440X_REG_INFO(AFE440X_LEDCNTRL, 0, AFE4404_LEDCNTRL_ILED3), 148 + }; 149 + 150 + static const struct iio_chan_spec afe4404_channels[] = { 151 + /* ADC values */ 152 + AFE440X_INTENSITY_CHAN(LED1, "led1", BIT(IIO_CHAN_INFO_OFFSET)), 153 + AFE440X_INTENSITY_CHAN(ALED1, "led1_ambient", BIT(IIO_CHAN_INFO_OFFSET)), 154 + AFE440X_INTENSITY_CHAN(LED2, "led2", BIT(IIO_CHAN_INFO_OFFSET)), 155 + AFE440X_INTENSITY_CHAN(ALED2, "led2_ambient", BIT(IIO_CHAN_INFO_OFFSET)), 156 + AFE440X_INTENSITY_CHAN(LED3, "led3", BIT(IIO_CHAN_INFO_OFFSET)), 157 + AFE440X_INTENSITY_CHAN(LED1_ALED1, "led1-led1_ambient", 0), 158 + AFE440X_INTENSITY_CHAN(LED2_ALED2, "led2-led2_ambient", 0), 159 + /* LED current */ 160 + AFE440X_CURRENT_CHAN(ILED1, "led1"), 161 + AFE440X_CURRENT_CHAN(ILED2, "led2"), 162 + AFE440X_CURRENT_CHAN(ILED3, "led3"), 163 + }; 164 + 165 + static const struct afe440x_val_table afe4404_res_table[] = { 166 + { .integer = 500000, .fract = 0 }, 167 + { .integer = 250000, .fract = 0 }, 168 + { .integer = 100000, .fract = 0 }, 169 + { .integer = 50000, .fract = 0 }, 170 + { .integer = 25000, .fract = 0 }, 171 + { .integer = 10000, .fract = 0 }, 172 + { .integer = 1000000, .fract = 0 }, 173 + { .integer = 2000000, .fract = 0 }, 174 + }; 175 + AFE440X_TABLE_ATTR(tia_resistance_available, afe4404_res_table); 176 + 177 + static const struct afe440x_val_table afe4404_cap_table[] = { 178 + { .integer = 0, .fract = 5000 }, 179 + { .integer = 0, .fract = 2500 }, 180 + { .integer = 0, .fract = 10000 }, 181 + { .integer = 0, .fract = 7500 }, 182 + { .integer = 0, .fract = 20000 }, 183 + { .integer = 0, .fract = 17500 }, 184 + { .integer = 0, .fract = 25000 }, 185 + { .integer = 0, .fract = 22500 }, 186 + }; 187 + AFE440X_TABLE_ATTR(tia_capacitance_available, afe4404_cap_table); 188 + 189 + static ssize_t afe440x_show_register(struct device *dev, 190 + struct device_attribute *attr, 191 + char *buf) 192 + { 193 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 194 + struct afe4404_data *afe = iio_priv(indio_dev); 195 + struct afe440x_attr *afe440x_attr = to_afe440x_attr(attr); 196 + unsigned int reg_val, type; 197 + int vals[2]; 198 + int ret, val_len; 199 + 200 + ret = regmap_read(afe->regmap, afe440x_attr->reg, &reg_val); 201 + if (ret) 202 + return ret; 203 + 204 + reg_val &= afe440x_attr->mask; 205 + reg_val >>= afe440x_attr->shift; 206 + 207 + switch (afe440x_attr->type) { 208 + case SIMPLE: 209 + type = IIO_VAL_INT; 210 + val_len = 1; 211 + vals[0] = reg_val; 212 + break; 213 + case RESISTANCE: 214 + case CAPACITANCE: 215 + type = IIO_VAL_INT_PLUS_MICRO; 216 + val_len = 2; 217 + if (reg_val < afe440x_attr->table_size) { 218 + vals[0] = afe440x_attr->val_table[reg_val].integer; 219 + vals[1] = afe440x_attr->val_table[reg_val].fract; 220 + break; 221 + } 222 + return -EINVAL; 223 + default: 224 + return -EINVAL; 225 + } 226 + 227 + return iio_format_value(buf, type, val_len, vals); 228 + } 229 + 230 + static ssize_t afe440x_store_register(struct device *dev, 231 + struct device_attribute *attr, 232 + const char *buf, size_t count) 233 + { 234 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 235 + struct afe4404_data *afe = iio_priv(indio_dev); 236 + struct afe440x_attr *afe440x_attr = to_afe440x_attr(attr); 237 + int val, integer, fract, ret; 238 + 239 + ret = iio_str_to_fixpoint(buf, 100000, &integer, &fract); 240 + if (ret) 241 + return ret; 242 + 243 + switch (afe440x_attr->type) { 244 + case SIMPLE: 245 + val = integer; 246 + break; 247 + case RESISTANCE: 248 + case CAPACITANCE: 249 + for (val = 0; val < afe440x_attr->table_size; val++) 250 + if (afe440x_attr->val_table[val].integer == integer && 251 + afe440x_attr->val_table[val].fract == fract) 252 + break; 253 + if (val == afe440x_attr->table_size) 254 + return -EINVAL; 255 + break; 256 + default: 257 + return -EINVAL; 258 + } 259 + 260 + ret = regmap_update_bits(afe->regmap, afe440x_attr->reg, 261 + afe440x_attr->mask, 262 + (val << afe440x_attr->shift)); 263 + if (ret) 264 + return ret; 265 + 266 + return count; 267 + } 268 + 269 + static AFE440X_ATTR(tia_separate_en, AFE4404_TIA_GAIN_SEP, AFE440X_TIAGAIN_ENSEPGAIN, SIMPLE, NULL, 0); 270 + 271 + static AFE440X_ATTR(tia_resistance1, AFE4404_TIA_GAIN, AFE4404_TIA_GAIN_RES, RESISTANCE, afe4404_res_table, ARRAY_SIZE(afe4404_res_table)); 272 + static AFE440X_ATTR(tia_capacitance1, AFE4404_TIA_GAIN, AFE4404_TIA_GAIN_CAP, CAPACITANCE, afe4404_cap_table, ARRAY_SIZE(afe4404_cap_table)); 273 + 274 + static AFE440X_ATTR(tia_resistance2, AFE4404_TIA_GAIN_SEP, AFE4404_TIA_GAIN_RES, RESISTANCE, afe4404_res_table, ARRAY_SIZE(afe4404_res_table)); 275 + static AFE440X_ATTR(tia_capacitance2, AFE4404_TIA_GAIN_SEP, AFE4404_TIA_GAIN_CAP, CAPACITANCE, afe4404_cap_table, ARRAY_SIZE(afe4404_cap_table)); 276 + 277 + static struct attribute *afe440x_attributes[] = { 278 + &afe440x_attr_tia_separate_en.dev_attr.attr, 279 + &afe440x_attr_tia_resistance1.dev_attr.attr, 280 + &afe440x_attr_tia_capacitance1.dev_attr.attr, 281 + &afe440x_attr_tia_resistance2.dev_attr.attr, 282 + &afe440x_attr_tia_capacitance2.dev_attr.attr, 283 + &dev_attr_tia_resistance_available.attr, 284 + &dev_attr_tia_capacitance_available.attr, 285 + NULL 286 + }; 287 + 288 + static const struct attribute_group afe440x_attribute_group = { 289 + .attrs = afe440x_attributes 290 + }; 291 + 292 + static int afe4404_read_raw(struct iio_dev *indio_dev, 293 + struct iio_chan_spec const *chan, 294 + int *val, int *val2, long mask) 295 + { 296 + struct afe4404_data *afe = iio_priv(indio_dev); 297 + const struct afe440x_reg_info reg_info = afe4404_reg_info[chan->address]; 298 + int ret; 299 + 300 + switch (chan->type) { 301 + case IIO_INTENSITY: 302 + switch (mask) { 303 + case IIO_CHAN_INFO_RAW: 304 + ret = regmap_read(afe->regmap, reg_info.reg, val); 305 + if (ret) 306 + return ret; 307 + return IIO_VAL_INT; 308 + case IIO_CHAN_INFO_OFFSET: 309 + ret = regmap_read(afe->regmap, reg_info.offreg, 310 + val); 311 + if (ret) 312 + return ret; 313 + *val &= reg_info.mask; 314 + *val >>= reg_info.shift; 315 + return IIO_VAL_INT; 316 + } 317 + break; 318 + case IIO_CURRENT: 319 + switch (mask) { 320 + case IIO_CHAN_INFO_RAW: 321 + ret = regmap_read(afe->regmap, reg_info.reg, val); 322 + if (ret) 323 + return ret; 324 + *val &= reg_info.mask; 325 + *val >>= reg_info.shift; 326 + return IIO_VAL_INT; 327 + case IIO_CHAN_INFO_SCALE: 328 + *val = 0; 329 + *val2 = 800000; 330 + return IIO_VAL_INT_PLUS_MICRO; 331 + } 332 + break; 333 + default: 334 + break; 335 + } 336 + 337 + return -EINVAL; 338 + } 339 + 340 + static int afe4404_write_raw(struct iio_dev *indio_dev, 341 + struct iio_chan_spec const *chan, 342 + int val, int val2, long mask) 343 + { 344 + struct afe4404_data *afe = iio_priv(indio_dev); 345 + const struct afe440x_reg_info reg_info = afe4404_reg_info[chan->address]; 346 + 347 + switch (chan->type) { 348 + case IIO_INTENSITY: 349 + switch (mask) { 350 + case IIO_CHAN_INFO_OFFSET: 351 + return regmap_update_bits(afe->regmap, 352 + reg_info.offreg, 353 + reg_info.mask, 354 + (val << reg_info.shift)); 355 + } 356 + break; 357 + case IIO_CURRENT: 358 + switch (mask) { 359 + case IIO_CHAN_INFO_RAW: 360 + return regmap_update_bits(afe->regmap, 361 + reg_info.reg, 362 + reg_info.mask, 363 + (val << reg_info.shift)); 364 + } 365 + break; 366 + default: 367 + break; 368 + } 369 + 370 + return -EINVAL; 371 + } 372 + 373 + static const struct iio_info afe4404_iio_info = { 374 + .attrs = &afe440x_attribute_group, 375 + .read_raw = afe4404_read_raw, 376 + .write_raw = afe4404_write_raw, 377 + .driver_module = THIS_MODULE, 378 + }; 379 + 380 + static irqreturn_t afe4404_trigger_handler(int irq, void *private) 381 + { 382 + struct iio_poll_func *pf = private; 383 + struct iio_dev *indio_dev = pf->indio_dev; 384 + struct afe4404_data *afe = iio_priv(indio_dev); 385 + int ret, bit, i = 0; 386 + s32 buffer[10]; 387 + 388 + for_each_set_bit(bit, indio_dev->active_scan_mask, 389 + indio_dev->masklength) { 390 + ret = regmap_read(afe->regmap, afe4404_reg_info[bit].reg, 391 + &buffer[i++]); 392 + if (ret) 393 + goto err; 394 + } 395 + 396 + iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp); 397 + err: 398 + iio_trigger_notify_done(indio_dev->trig); 399 + 400 + return IRQ_HANDLED; 401 + } 402 + 403 + static const struct iio_trigger_ops afe4404_trigger_ops = { 404 + .owner = THIS_MODULE, 405 + }; 406 + 407 + /* Default timings from data-sheet */ 408 + #define AFE4404_TIMING_PAIRS \ 409 + { AFE440X_PRPCOUNT, 39999 }, \ 410 + { AFE440X_LED2LEDSTC, 0 }, \ 411 + { AFE440X_LED2LEDENDC, 398 }, \ 412 + { AFE440X_LED2STC, 80 }, \ 413 + { AFE440X_LED2ENDC, 398 }, \ 414 + { AFE440X_ADCRSTSTCT0, 5600 }, \ 415 + { AFE440X_ADCRSTENDCT0, 5606 }, \ 416 + { AFE440X_LED2CONVST, 5607 }, \ 417 + { AFE440X_LED2CONVEND, 6066 }, \ 418 + { AFE4404_LED3LEDSTC, 400 }, \ 419 + { AFE4404_LED3LEDENDC, 798 }, \ 420 + { AFE440X_ALED2STC, 480 }, \ 421 + { AFE440X_ALED2ENDC, 798 }, \ 422 + { AFE440X_ADCRSTSTCT1, 6068 }, \ 423 + { AFE440X_ADCRSTENDCT1, 6074 }, \ 424 + { AFE440X_ALED2CONVST, 6075 }, \ 425 + { AFE440X_ALED2CONVEND, 6534 }, \ 426 + { AFE440X_LED1LEDSTC, 800 }, \ 427 + { AFE440X_LED1LEDENDC, 1198 }, \ 428 + { AFE440X_LED1STC, 880 }, \ 429 + { AFE440X_LED1ENDC, 1198 }, \ 430 + { AFE440X_ADCRSTSTCT2, 6536 }, \ 431 + { AFE440X_ADCRSTENDCT2, 6542 }, \ 432 + { AFE440X_LED1CONVST, 6543 }, \ 433 + { AFE440X_LED1CONVEND, 7003 }, \ 434 + { AFE440X_ALED1STC, 1280 }, \ 435 + { AFE440X_ALED1ENDC, 1598 }, \ 436 + { AFE440X_ADCRSTSTCT3, 7005 }, \ 437 + { AFE440X_ADCRSTENDCT3, 7011 }, \ 438 + { AFE440X_ALED1CONVST, 7012 }, \ 439 + { AFE440X_ALED1CONVEND, 7471 }, \ 440 + { AFE440X_PDNCYCLESTC, 7671 }, \ 441 + { AFE440X_PDNCYCLEENDC, 39199 } 442 + 443 + static const struct reg_sequence afe4404_reg_sequences[] = { 444 + AFE4404_TIMING_PAIRS, 445 + { AFE440X_CONTROL1, AFE440X_CONTROL1_TIMEREN }, 446 + { AFE4404_TIA_GAIN, AFE4404_TIA_GAIN_RES_50_K }, 447 + { AFE440X_LEDCNTRL, (0xf << AFE4404_LEDCNTRL_ILED1_SHIFT) | 448 + (0x3 << AFE4404_LEDCNTRL_ILED2_SHIFT) | 449 + (0x3 << AFE4404_LEDCNTRL_ILED3_SHIFT) }, 450 + { AFE440X_CONTROL2, AFE440X_CONTROL3_OSC_ENABLE }, 451 + }; 452 + 453 + static const struct regmap_range afe4404_yes_ranges[] = { 454 + regmap_reg_range(AFE440X_LED2VAL, AFE440X_LED1_ALED1VAL), 455 + regmap_reg_range(AFE4404_AVG_LED2_ALED2VAL, AFE4404_AVG_LED1_ALED1VAL), 456 + }; 457 + 458 + static const struct regmap_access_table afe4404_volatile_table = { 459 + .yes_ranges = afe4404_yes_ranges, 460 + .n_yes_ranges = ARRAY_SIZE(afe4404_yes_ranges), 461 + }; 462 + 463 + static const struct regmap_config afe4404_regmap_config = { 464 + .reg_bits = 8, 465 + .val_bits = 24, 466 + 467 + .max_register = AFE4404_AVG_LED1_ALED1VAL, 468 + .cache_type = REGCACHE_RBTREE, 469 + .volatile_table = &afe4404_volatile_table, 470 + }; 471 + 472 + #ifdef CONFIG_OF 473 + static const struct of_device_id afe4404_of_match[] = { 474 + { .compatible = "ti,afe4404", }, 475 + { /* sentinel */ } 476 + }; 477 + MODULE_DEVICE_TABLE(of, afe4404_of_match); 478 + #endif 479 + 480 + static int afe4404_suspend(struct device *dev) 481 + { 482 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 483 + struct afe4404_data *afe = iio_priv(indio_dev); 484 + int ret; 485 + 486 + ret = regmap_update_bits(afe->regmap, AFE440X_CONTROL2, 487 + AFE440X_CONTROL2_PDN_AFE, 488 + AFE440X_CONTROL2_PDN_AFE); 489 + if (ret) 490 + return ret; 491 + 492 + ret = regulator_disable(afe->regulator); 493 + if (ret) { 494 + dev_err(dev, "Unable to disable regulator\n"); 495 + return ret; 496 + } 497 + 498 + return 0; 499 + } 500 + 501 + static int afe4404_resume(struct device *dev) 502 + { 503 + struct iio_dev *indio_dev = dev_to_iio_dev(dev); 504 + struct afe4404_data *afe = iio_priv(indio_dev); 505 + int ret; 506 + 507 + ret = regulator_enable(afe->regulator); 508 + if (ret) { 509 + dev_err(dev, "Unable to enable regulator\n"); 510 + return ret; 511 + } 512 + 513 + ret = regmap_update_bits(afe->regmap, AFE440X_CONTROL2, 514 + AFE440X_CONTROL2_PDN_AFE, 0); 515 + if (ret) 516 + return ret; 517 + 518 + return 0; 519 + } 520 + 521 + static SIMPLE_DEV_PM_OPS(afe4404_pm_ops, afe4404_suspend, afe4404_resume); 522 + 523 + static int afe4404_probe(struct i2c_client *client, 524 + const struct i2c_device_id *id) 525 + { 526 + struct iio_dev *indio_dev; 527 + struct afe4404_data *afe; 528 + int ret; 529 + 530 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*afe)); 531 + if (!indio_dev) 532 + return -ENOMEM; 533 + 534 + afe = iio_priv(indio_dev); 535 + i2c_set_clientdata(client, indio_dev); 536 + 537 + afe->dev = &client->dev; 538 + afe->irq = client->irq; 539 + 540 + afe->regmap = devm_regmap_init_i2c(client, &afe4404_regmap_config); 541 + if (IS_ERR(afe->regmap)) { 542 + dev_err(afe->dev, "Unable to allocate register map\n"); 543 + return PTR_ERR(afe->regmap); 544 + } 545 + 546 + afe->regulator = devm_regulator_get(afe->dev, "tx_sup"); 547 + if (IS_ERR(afe->regulator)) { 548 + dev_err(afe->dev, "Unable to get regulator\n"); 549 + return PTR_ERR(afe->regulator); 550 + } 551 + ret = regulator_enable(afe->regulator); 552 + if (ret) { 553 + dev_err(afe->dev, "Unable to enable regulator\n"); 554 + return ret; 555 + } 556 + 557 + ret = regmap_write(afe->regmap, AFE440X_CONTROL0, 558 + AFE440X_CONTROL0_SW_RESET); 559 + if (ret) { 560 + dev_err(afe->dev, "Unable to reset device\n"); 561 + goto disable_reg; 562 + } 563 + 564 + ret = regmap_multi_reg_write(afe->regmap, afe4404_reg_sequences, 565 + ARRAY_SIZE(afe4404_reg_sequences)); 566 + if (ret) { 567 + dev_err(afe->dev, "Unable to set register defaults\n"); 568 + goto disable_reg; 569 + } 570 + 571 + indio_dev->modes = INDIO_DIRECT_MODE; 572 + indio_dev->dev.parent = afe->dev; 573 + indio_dev->channels = afe4404_channels; 574 + indio_dev->num_channels = ARRAY_SIZE(afe4404_channels); 575 + indio_dev->name = AFE4404_DRIVER_NAME; 576 + indio_dev->info = &afe4404_iio_info; 577 + 578 + if (afe->irq > 0) { 579 + afe->trig = devm_iio_trigger_alloc(afe->dev, 580 + "%s-dev%d", 581 + indio_dev->name, 582 + indio_dev->id); 583 + if (!afe->trig) { 584 + dev_err(afe->dev, "Unable to allocate IIO trigger\n"); 585 + ret = -ENOMEM; 586 + goto disable_reg; 587 + } 588 + 589 + iio_trigger_set_drvdata(afe->trig, indio_dev); 590 + 591 + afe->trig->ops = &afe4404_trigger_ops; 592 + afe->trig->dev.parent = afe->dev; 593 + 594 + ret = iio_trigger_register(afe->trig); 595 + if (ret) { 596 + dev_err(afe->dev, "Unable to register IIO trigger\n"); 597 + goto disable_reg; 598 + } 599 + 600 + ret = devm_request_threaded_irq(afe->dev, afe->irq, 601 + iio_trigger_generic_data_rdy_poll, 602 + NULL, IRQF_ONESHOT, 603 + AFE4404_DRIVER_NAME, 604 + afe->trig); 605 + if (ret) { 606 + dev_err(afe->dev, "Unable to request IRQ\n"); 607 + goto disable_reg; 608 + } 609 + } 610 + 611 + ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, 612 + afe4404_trigger_handler, NULL); 613 + if (ret) { 614 + dev_err(afe->dev, "Unable to setup buffer\n"); 615 + goto unregister_trigger; 616 + } 617 + 618 + ret = iio_device_register(indio_dev); 619 + if (ret) { 620 + dev_err(afe->dev, "Unable to register IIO device\n"); 621 + goto unregister_triggered_buffer; 622 + } 623 + 624 + return 0; 625 + 626 + unregister_triggered_buffer: 627 + iio_triggered_buffer_cleanup(indio_dev); 628 + unregister_trigger: 629 + if (afe->irq > 0) 630 + iio_trigger_unregister(afe->trig); 631 + disable_reg: 632 + regulator_disable(afe->regulator); 633 + 634 + return ret; 635 + } 636 + 637 + static int afe4404_remove(struct i2c_client *client) 638 + { 639 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 640 + struct afe4404_data *afe = iio_priv(indio_dev); 641 + int ret; 642 + 643 + iio_device_unregister(indio_dev); 644 + 645 + iio_triggered_buffer_cleanup(indio_dev); 646 + 647 + if (afe->irq > 0) 648 + iio_trigger_unregister(afe->trig); 649 + 650 + ret = regulator_disable(afe->regulator); 651 + if (ret) { 652 + dev_err(afe->dev, "Unable to disable regulator\n"); 653 + return ret; 654 + } 655 + 656 + return 0; 657 + } 658 + 659 + static const struct i2c_device_id afe4404_ids[] = { 660 + { "afe4404", 0 }, 661 + { /* sentinel */ } 662 + }; 663 + MODULE_DEVICE_TABLE(i2c, afe4404_ids); 664 + 665 + static struct i2c_driver afe4404_i2c_driver = { 666 + .driver = { 667 + .name = AFE4404_DRIVER_NAME, 668 + .of_match_table = of_match_ptr(afe4404_of_match), 669 + .pm = &afe4404_pm_ops, 670 + }, 671 + .probe = afe4404_probe, 672 + .remove = afe4404_remove, 673 + .id_table = afe4404_ids, 674 + }; 675 + module_i2c_driver(afe4404_i2c_driver); 676 + 677 + MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>"); 678 + MODULE_DESCRIPTION("TI AFE4404 Heart Rate and Pulse Oximeter"); 679 + MODULE_LICENSE("GPL v2");
+191
drivers/iio/health/afe440x.h
··· 1 + /* 2 + * AFE440X Heart Rate Monitors and Low-Cost Pulse Oximeters 3 + * 4 + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ 5 + * Andrew F. Davis <afd@ti.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, but 12 + * WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 + * General Public License for more details. 15 + */ 16 + 17 + #ifndef _AFE440X_H 18 + #define _AFE440X_H 19 + 20 + /* AFE440X registers */ 21 + #define AFE440X_CONTROL0 0x00 22 + #define AFE440X_LED2STC 0x01 23 + #define AFE440X_LED2ENDC 0x02 24 + #define AFE440X_LED1LEDSTC 0x03 25 + #define AFE440X_LED1LEDENDC 0x04 26 + #define AFE440X_ALED2STC 0x05 27 + #define AFE440X_ALED2ENDC 0x06 28 + #define AFE440X_LED1STC 0x07 29 + #define AFE440X_LED1ENDC 0x08 30 + #define AFE440X_LED2LEDSTC 0x09 31 + #define AFE440X_LED2LEDENDC 0x0a 32 + #define AFE440X_ALED1STC 0x0b 33 + #define AFE440X_ALED1ENDC 0x0c 34 + #define AFE440X_LED2CONVST 0x0d 35 + #define AFE440X_LED2CONVEND 0x0e 36 + #define AFE440X_ALED2CONVST 0x0f 37 + #define AFE440X_ALED2CONVEND 0x10 38 + #define AFE440X_LED1CONVST 0x11 39 + #define AFE440X_LED1CONVEND 0x12 40 + #define AFE440X_ALED1CONVST 0x13 41 + #define AFE440X_ALED1CONVEND 0x14 42 + #define AFE440X_ADCRSTSTCT0 0x15 43 + #define AFE440X_ADCRSTENDCT0 0x16 44 + #define AFE440X_ADCRSTSTCT1 0x17 45 + #define AFE440X_ADCRSTENDCT1 0x18 46 + #define AFE440X_ADCRSTSTCT2 0x19 47 + #define AFE440X_ADCRSTENDCT2 0x1a 48 + #define AFE440X_ADCRSTSTCT3 0x1b 49 + #define AFE440X_ADCRSTENDCT3 0x1c 50 + #define AFE440X_PRPCOUNT 0x1d 51 + #define AFE440X_CONTROL1 0x1e 52 + #define AFE440X_LEDCNTRL 0x22 53 + #define AFE440X_CONTROL2 0x23 54 + #define AFE440X_ALARM 0x29 55 + #define AFE440X_LED2VAL 0x2a 56 + #define AFE440X_ALED2VAL 0x2b 57 + #define AFE440X_LED1VAL 0x2c 58 + #define AFE440X_ALED1VAL 0x2d 59 + #define AFE440X_LED2_ALED2VAL 0x2e 60 + #define AFE440X_LED1_ALED1VAL 0x2f 61 + #define AFE440X_CONTROL3 0x31 62 + #define AFE440X_PDNCYCLESTC 0x32 63 + #define AFE440X_PDNCYCLEENDC 0x33 64 + 65 + /* CONTROL0 register fields */ 66 + #define AFE440X_CONTROL0_REG_READ BIT(0) 67 + #define AFE440X_CONTROL0_TM_COUNT_RST BIT(1) 68 + #define AFE440X_CONTROL0_SW_RESET BIT(3) 69 + 70 + /* CONTROL1 register fields */ 71 + #define AFE440X_CONTROL1_TIMEREN BIT(8) 72 + 73 + /* TIAGAIN register fields */ 74 + #define AFE440X_TIAGAIN_ENSEPGAIN_MASK BIT(15) 75 + #define AFE440X_TIAGAIN_ENSEPGAIN_SHIFT 15 76 + 77 + /* CONTROL2 register fields */ 78 + #define AFE440X_CONTROL2_PDN_AFE BIT(0) 79 + #define AFE440X_CONTROL2_PDN_RX BIT(1) 80 + #define AFE440X_CONTROL2_DYNAMIC4 BIT(3) 81 + #define AFE440X_CONTROL2_DYNAMIC3 BIT(4) 82 + #define AFE440X_CONTROL2_DYNAMIC2 BIT(14) 83 + #define AFE440X_CONTROL2_DYNAMIC1 BIT(20) 84 + 85 + /* CONTROL3 register fields */ 86 + #define AFE440X_CONTROL3_CLKDIV GENMASK(2, 0) 87 + 88 + /* CONTROL0 values */ 89 + #define AFE440X_CONTROL0_WRITE 0x0 90 + #define AFE440X_CONTROL0_READ 0x1 91 + 92 + struct afe440x_reg_info { 93 + unsigned int reg; 94 + unsigned int offreg; 95 + unsigned int shift; 96 + unsigned int mask; 97 + }; 98 + 99 + #define AFE440X_REG_INFO(_reg, _offreg, _sm) \ 100 + { \ 101 + .reg = _reg, \ 102 + .offreg = _offreg, \ 103 + .shift = _sm ## _SHIFT, \ 104 + .mask = _sm ## _MASK, \ 105 + } 106 + 107 + #define AFE440X_INTENSITY_CHAN(_index, _name, _mask) \ 108 + { \ 109 + .type = IIO_INTENSITY, \ 110 + .channel = _index, \ 111 + .address = _index, \ 112 + .scan_index = _index, \ 113 + .scan_type = { \ 114 + .sign = 's', \ 115 + .realbits = 24, \ 116 + .storagebits = 32, \ 117 + .endianness = IIO_CPU, \ 118 + }, \ 119 + .extend_name = _name, \ 120 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 121 + _mask, \ 122 + } 123 + 124 + #define AFE440X_CURRENT_CHAN(_index, _name) \ 125 + { \ 126 + .type = IIO_CURRENT, \ 127 + .channel = _index, \ 128 + .address = _index, \ 129 + .scan_index = _index, \ 130 + .extend_name = _name, \ 131 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 132 + BIT(IIO_CHAN_INFO_SCALE), \ 133 + .output = true, \ 134 + } 135 + 136 + enum afe440x_reg_type { 137 + SIMPLE, 138 + RESISTANCE, 139 + CAPACITANCE, 140 + }; 141 + 142 + struct afe440x_val_table { 143 + int integer; 144 + int fract; 145 + }; 146 + 147 + #define AFE440X_TABLE_ATTR(_name, _table) \ 148 + static ssize_t _name ## _show(struct device *dev, \ 149 + struct device_attribute *attr, char *buf) \ 150 + { \ 151 + ssize_t len = 0; \ 152 + int i; \ 153 + \ 154 + for (i = 0; i < ARRAY_SIZE(_table); i++) \ 155 + len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06u ", \ 156 + _table[i].integer, \ 157 + _table[i].fract); \ 158 + \ 159 + buf[len - 1] = '\n'; \ 160 + \ 161 + return len; \ 162 + } \ 163 + static DEVICE_ATTR_RO(_name) 164 + 165 + struct afe440x_attr { 166 + struct device_attribute dev_attr; 167 + unsigned int reg; 168 + unsigned int shift; 169 + unsigned int mask; 170 + enum afe440x_reg_type type; 171 + const struct afe440x_val_table *val_table; 172 + unsigned int table_size; 173 + }; 174 + 175 + #define to_afe440x_attr(_dev_attr) \ 176 + container_of(_dev_attr, struct afe440x_attr, dev_attr) 177 + 178 + #define AFE440X_ATTR(_name, _reg, _field, _type, _table, _size) \ 179 + struct afe440x_attr afe440x_attr_##_name = { \ 180 + .dev_attr = __ATTR(_name, (S_IRUGO | S_IWUSR), \ 181 + afe440x_show_register, \ 182 + afe440x_store_register), \ 183 + .reg = _reg, \ 184 + .shift = _field ## _SHIFT, \ 185 + .mask = _field ## _MASK, \ 186 + .type = _type, \ 187 + .val_table = _table, \ 188 + .table_size = _size, \ 189 + } 190 + 191 + #endif /* _AFE440X_H */
+20 -4
drivers/iio/imu/inv_mpu6050/Kconfig
··· 3 3 # 4 4 5 5 config INV_MPU6050_IIO 6 - tristate "Invensense MPU6050 devices" 7 - depends on I2C && SYSFS 8 - depends on I2C_MUX 6 + tristate 9 7 select IIO_BUFFER 10 8 select IIO_TRIGGERED_BUFFER 9 + 10 + config INV_MPU6050_I2C 11 + tristate "Invensense MPU6050 devices (I2C)" 12 + depends on I2C 13 + select INV_MPU6050_IIO 14 + select I2C_MUX 15 + select REGMAP_I2C 11 16 help 12 17 This driver supports the Invensense MPU6050 devices. 13 18 This driver can also support MPU6500 in MPU6050 compatibility mode 14 19 and also in MPU6500 mode with some limitations. 15 20 It is a gyroscope/accelerometer combo device. 16 21 This driver can be built as a module. The module will be called 17 - inv-mpu6050. 22 + inv-mpu6050-i2c. 23 + 24 + config INV_MPU6050_SPI 25 + tristate "Invensense MPU6050 devices (SPI)" 26 + depends on SPI_MASTER 27 + select INV_MPU6050_IIO 28 + select REGMAP_SPI 29 + help 30 + This driver supports the Invensense MPU6050 devices. 31 + It is a gyroscope/accelerometer combo device. 32 + This driver can be built as a module. The module will be called 33 + inv-mpu6050-spi.
+7 -1
drivers/iio/imu/inv_mpu6050/Makefile
··· 3 3 # 4 4 5 5 obj-$(CONFIG_INV_MPU6050_IIO) += inv-mpu6050.o 6 - inv-mpu6050-objs := inv_mpu_core.o inv_mpu_ring.o inv_mpu_trigger.o inv_mpu_acpi.o 6 + inv-mpu6050-objs := inv_mpu_core.o inv_mpu_ring.o inv_mpu_trigger.o 7 + 8 + obj-$(CONFIG_INV_MPU6050_I2C) += inv-mpu6050-i2c.o 9 + inv-mpu6050-i2c-objs := inv_mpu_i2c.o inv_mpu_acpi.o 10 + 11 + obj-$(CONFIG_INV_MPU6050_SPI) += inv-mpu6050-spi.o 12 + inv-mpu6050-spi-objs := inv_mpu_spi.o
+10 -8
drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
··· 139 139 return 0; 140 140 } 141 141 142 - int inv_mpu_acpi_create_mux_client(struct inv_mpu6050_state *st) 142 + int inv_mpu_acpi_create_mux_client(struct i2c_client *client) 143 143 { 144 + struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(&client->dev)); 144 145 145 146 st->mux_client = NULL; 146 - if (ACPI_HANDLE(&st->client->dev)) { 147 + if (ACPI_HANDLE(&client->dev)) { 147 148 struct i2c_board_info info; 148 149 struct acpi_device *adev; 149 150 int ret = -1; 150 151 151 - adev = ACPI_COMPANION(&st->client->dev); 152 + adev = ACPI_COMPANION(&client->dev); 152 153 memset(&info, 0, sizeof(info)); 153 154 154 155 dmi_check_system(inv_mpu_dev_list); 155 156 switch (matched_product_name) { 156 157 case INV_MPU_ASUS_T100TA: 157 - ret = asus_acpi_get_sensor_info(adev, st->client, 158 + ret = asus_acpi_get_sensor_info(adev, client, 158 159 &info); 159 160 break; 160 161 /* Add more matched product processing here */ ··· 167 166 /* No matching DMI, so create device on INV6XX type */ 168 167 unsigned short primary, secondary; 169 168 170 - ret = inv_mpu_process_acpi_config(st->client, &primary, 169 + ret = inv_mpu_process_acpi_config(client, &primary, 171 170 &secondary); 172 171 if (!ret && secondary) { 173 172 char *name; ··· 192 191 return 0; 193 192 } 194 193 195 - void inv_mpu_acpi_delete_mux_client(struct inv_mpu6050_state *st) 194 + void inv_mpu_acpi_delete_mux_client(struct i2c_client *client) 196 195 { 196 + struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(&client->dev)); 197 197 if (st->mux_client) 198 198 i2c_unregister_device(st->mux_client); 199 199 } ··· 202 200 203 201 #include "inv_mpu_iio.h" 204 202 205 - int inv_mpu_acpi_create_mux_client(struct inv_mpu6050_state *st) 203 + int inv_mpu_acpi_create_mux_client(struct i2c_client *client) 206 204 { 207 205 return 0; 208 206 } 209 207 210 - void inv_mpu_acpi_delete_mux_client(struct inv_mpu6050_state *st) 208 + void inv_mpu_acpi_delete_mux_client(struct i2c_client *client) 211 209 { 212 210 } 213 211 #endif
+54 -204
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 75 75 }, 76 76 }; 77 77 78 - int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 d) 79 - { 80 - return i2c_smbus_write_i2c_block_data(st->client, reg, 1, &d); 81 - } 82 - 83 - /* 84 - * The i2c read/write needs to happen in unlocked mode. As the parent 85 - * adapter is common. If we use locked versions, it will fail as 86 - * the mux adapter will lock the parent i2c adapter, while calling 87 - * select/deselect functions. 88 - */ 89 - static int inv_mpu6050_write_reg_unlocked(struct inv_mpu6050_state *st, 90 - u8 reg, u8 d) 91 - { 92 - int ret; 93 - u8 buf[2]; 94 - struct i2c_msg msg[1] = { 95 - { 96 - .addr = st->client->addr, 97 - .flags = 0, 98 - .len = sizeof(buf), 99 - .buf = buf, 100 - } 101 - }; 102 - 103 - buf[0] = reg; 104 - buf[1] = d; 105 - ret = __i2c_transfer(st->client->adapter, msg, 1); 106 - if (ret != 1) 107 - return ret; 108 - 109 - return 0; 110 - } 111 - 112 - static int inv_mpu6050_select_bypass(struct i2c_adapter *adap, void *mux_priv, 113 - u32 chan_id) 114 - { 115 - struct iio_dev *indio_dev = mux_priv; 116 - struct inv_mpu6050_state *st = iio_priv(indio_dev); 117 - int ret = 0; 118 - 119 - /* Use the same mutex which was used everywhere to protect power-op */ 120 - mutex_lock(&indio_dev->mlock); 121 - if (!st->powerup_count) { 122 - ret = inv_mpu6050_write_reg_unlocked(st, st->reg->pwr_mgmt_1, 123 - 0); 124 - if (ret) 125 - goto write_error; 126 - 127 - msleep(INV_MPU6050_REG_UP_TIME); 128 - } 129 - if (!ret) { 130 - st->powerup_count++; 131 - ret = inv_mpu6050_write_reg_unlocked(st, st->reg->int_pin_cfg, 132 - st->client->irq | 133 - INV_MPU6050_BIT_BYPASS_EN); 134 - } 135 - write_error: 136 - mutex_unlock(&indio_dev->mlock); 137 - 138 - return ret; 139 - } 140 - 141 - static int inv_mpu6050_deselect_bypass(struct i2c_adapter *adap, 142 - void *mux_priv, u32 chan_id) 143 - { 144 - struct iio_dev *indio_dev = mux_priv; 145 - struct inv_mpu6050_state *st = iio_priv(indio_dev); 146 - 147 - mutex_lock(&indio_dev->mlock); 148 - /* It doesn't really mattter, if any of the calls fails */ 149 - inv_mpu6050_write_reg_unlocked(st, st->reg->int_pin_cfg, 150 - st->client->irq); 151 - st->powerup_count--; 152 - if (!st->powerup_count) 153 - inv_mpu6050_write_reg_unlocked(st, st->reg->pwr_mgmt_1, 154 - INV_MPU6050_BIT_SLEEP); 155 - mutex_unlock(&indio_dev->mlock); 156 - 157 - return 0; 158 - } 159 - 160 78 int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask) 161 79 { 162 - u8 d, mgmt_1; 80 + unsigned int d, mgmt_1; 163 81 int result; 164 82 165 83 /* switch clock needs to be careful. Only when gyro is on, can 166 84 clock source be switched to gyro. Otherwise, it must be set to 167 85 internal clock */ 168 86 if (INV_MPU6050_BIT_PWR_GYRO_STBY == mask) { 169 - result = i2c_smbus_read_i2c_block_data(st->client, 170 - st->reg->pwr_mgmt_1, 1, &mgmt_1); 171 - if (result != 1) 87 + result = regmap_read(st->map, st->reg->pwr_mgmt_1, &mgmt_1); 88 + if (result) 172 89 return result; 173 90 174 91 mgmt_1 &= ~INV_MPU6050_BIT_CLK_MASK; ··· 95 178 /* turning off gyro requires switch to internal clock first. 96 179 Then turn off gyro engine */ 97 180 mgmt_1 |= INV_CLK_INTERNAL; 98 - result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1, mgmt_1); 181 + result = regmap_write(st->map, st->reg->pwr_mgmt_1, mgmt_1); 99 182 if (result) 100 183 return result; 101 184 } 102 185 103 - result = i2c_smbus_read_i2c_block_data(st->client, 104 - st->reg->pwr_mgmt_2, 1, &d); 105 - if (result != 1) 186 + result = regmap_read(st->map, st->reg->pwr_mgmt_2, &d); 187 + if (result) 106 188 return result; 107 189 if (en) 108 190 d &= ~mask; 109 191 else 110 192 d |= mask; 111 - result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_2, d); 193 + result = regmap_write(st->map, st->reg->pwr_mgmt_2, d); 112 194 if (result) 113 195 return result; 114 196 ··· 117 201 if (INV_MPU6050_BIT_PWR_GYRO_STBY == mask) { 118 202 /* switch internal clock to PLL */ 119 203 mgmt_1 |= INV_CLK_PLL; 120 - result = inv_mpu6050_write_reg(st, 204 + result = regmap_write(st->map, 121 205 st->reg->pwr_mgmt_1, mgmt_1); 122 206 if (result) 123 207 return result; ··· 134 218 if (power_on) { 135 219 /* Already under indio-dev->mlock mutex */ 136 220 if (!st->powerup_count) 137 - result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1, 138 - 0); 221 + result = regmap_write(st->map, st->reg->pwr_mgmt_1, 0); 139 222 if (!result) 140 223 st->powerup_count++; 141 224 } else { 142 225 st->powerup_count--; 143 226 if (!st->powerup_count) 144 - result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1, 145 - INV_MPU6050_BIT_SLEEP); 227 + result = regmap_write(st->map, st->reg->pwr_mgmt_1, 228 + INV_MPU6050_BIT_SLEEP); 146 229 } 147 230 148 231 if (result) ··· 152 237 153 238 return 0; 154 239 } 240 + EXPORT_SYMBOL_GPL(inv_mpu6050_set_power_itg); 155 241 156 242 /** 157 243 * inv_mpu6050_init_config() - Initialize hardware, disable FIFO. ··· 173 257 if (result) 174 258 return result; 175 259 d = (INV_MPU6050_FSR_2000DPS << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT); 176 - result = inv_mpu6050_write_reg(st, st->reg->gyro_config, d); 260 + result = regmap_write(st->map, st->reg->gyro_config, d); 177 261 if (result) 178 262 return result; 179 263 180 264 d = INV_MPU6050_FILTER_20HZ; 181 - result = inv_mpu6050_write_reg(st, st->reg->lpf, d); 265 + result = regmap_write(st->map, st->reg->lpf, d); 182 266 if (result) 183 267 return result; 184 268 185 269 d = INV_MPU6050_ONE_K_HZ / INV_MPU6050_INIT_FIFO_RATE - 1; 186 - result = inv_mpu6050_write_reg(st, st->reg->sample_rate_div, d); 270 + result = regmap_write(st->map, st->reg->sample_rate_div, d); 187 271 if (result) 188 272 return result; 189 273 190 274 d = (INV_MPU6050_FS_02G << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT); 191 - result = inv_mpu6050_write_reg(st, st->reg->accl_config, d); 275 + result = regmap_write(st->map, st->reg->accl_config, d); 192 276 if (result) 193 277 return result; 194 278 ··· 206 290 __be16 d; 207 291 208 292 ind = (axis - IIO_MOD_X) * 2; 209 - result = i2c_smbus_read_i2c_block_data(st->client, reg + ind, 2, 210 - (u8 *)&d); 211 - if (result != 2) 293 + result = regmap_bulk_read(st->map, reg + ind, (u8 *)&d, 2); 294 + if (result) 212 295 return -EINVAL; 213 296 *val = (short)be16_to_cpup(&d); 214 297 ··· 333 418 for (i = 0; i < ARRAY_SIZE(gyro_scale_6050); ++i) { 334 419 if (gyro_scale_6050[i] == val) { 335 420 d = (i << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT); 336 - result = inv_mpu6050_write_reg(st, 337 - st->reg->gyro_config, d); 421 + result = regmap_write(st->map, st->reg->gyro_config, d); 338 422 if (result) 339 423 return result; 340 424 ··· 370 456 for (i = 0; i < ARRAY_SIZE(accel_scale); ++i) { 371 457 if (accel_scale[i] == val) { 372 458 d = (i << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT); 373 - result = inv_mpu6050_write_reg(st, 374 - st->reg->accl_config, d); 459 + result = regmap_write(st->map, st->reg->accl_config, d); 375 460 if (result) 376 461 return result; 377 462 ··· 450 537 while ((h < hz[i]) && (i < ARRAY_SIZE(d) - 1)) 451 538 i++; 452 539 data = d[i]; 453 - result = inv_mpu6050_write_reg(st, st->reg->lpf, data); 540 + result = regmap_write(st->map, st->reg->lpf, data); 454 541 if (result) 455 542 return result; 456 543 st->chip_config.lpf = data; ··· 488 575 goto fifo_rate_fail; 489 576 490 577 d = INV_MPU6050_ONE_K_HZ / fifo_rate - 1; 491 - result = inv_mpu6050_write_reg(st, st->reg->sample_rate_div, d); 578 + result = regmap_write(st->map, st->reg->sample_rate_div, d); 492 579 if (result) 493 580 goto fifo_rate_fail; 494 581 st->chip_config.fifo_rate = fifo_rate; ··· 649 736 st->reg = hw_info[st->chip_type].reg; 650 737 651 738 /* reset to make sure previous state are not there */ 652 - result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1, 653 - INV_MPU6050_BIT_H_RESET); 739 + result = regmap_write(st->map, st->reg->pwr_mgmt_1, 740 + INV_MPU6050_BIT_H_RESET); 654 741 if (result) 655 742 return result; 656 743 msleep(INV_MPU6050_POWER_UP_TIME); ··· 677 764 return 0; 678 765 } 679 766 680 - /** 681 - * inv_mpu_probe() - probe function. 682 - * @client: i2c client. 683 - * @id: i2c device id. 684 - * 685 - * Returns 0 on success, a negative error code otherwise. 686 - */ 687 - static int inv_mpu_probe(struct i2c_client *client, 688 - const struct i2c_device_id *id) 767 + int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, 768 + int (*inv_mpu_bus_setup)(struct iio_dev *)) 689 769 { 690 770 struct inv_mpu6050_state *st; 691 771 struct iio_dev *indio_dev; 692 772 struct inv_mpu6050_platform_data *pdata; 773 + struct device *dev = regmap_get_device(regmap); 693 774 int result; 694 775 695 - if (!i2c_check_functionality(client->adapter, 696 - I2C_FUNC_SMBUS_I2C_BLOCK)) 697 - return -ENOSYS; 698 - 699 - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); 776 + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 700 777 if (!indio_dev) 701 778 return -ENOMEM; 702 779 703 780 st = iio_priv(indio_dev); 704 - st->client = client; 705 781 st->powerup_count = 0; 706 - pdata = dev_get_platdata(&client->dev); 782 + st->irq = irq; 783 + st->map = regmap; 784 + pdata = dev_get_platdata(dev); 707 785 if (pdata) 708 786 st->plat_data = *pdata; 709 787 /* power is turned on inside check chip type*/ ··· 702 798 if (result) 703 799 return result; 704 800 801 + if (inv_mpu_bus_setup) 802 + inv_mpu_bus_setup(indio_dev); 803 + 705 804 result = inv_mpu6050_init_config(indio_dev); 706 805 if (result) { 707 - dev_err(&client->dev, 708 - "Could not initialize device.\n"); 806 + dev_err(dev, "Could not initialize device.\n"); 709 807 return result; 710 808 } 711 809 712 - i2c_set_clientdata(client, indio_dev); 713 - indio_dev->dev.parent = &client->dev; 714 - /* id will be NULL when enumerated via ACPI */ 715 - if (id) 716 - indio_dev->name = (char *)id->name; 810 + dev_set_drvdata(dev, indio_dev); 811 + indio_dev->dev.parent = dev; 812 + /* name will be NULL when enumerated via ACPI */ 813 + if (name) 814 + indio_dev->name = name; 717 815 else 718 - indio_dev->name = (char *)dev_name(&client->dev); 816 + indio_dev->name = dev_name(dev); 719 817 indio_dev->channels = inv_mpu_channels; 720 818 indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels); 721 819 ··· 729 823 inv_mpu6050_read_fifo, 730 824 NULL); 731 825 if (result) { 732 - dev_err(&st->client->dev, "configure buffer fail %d\n", 733 - result); 826 + dev_err(dev, "configure buffer fail %d\n", result); 734 827 return result; 735 828 } 736 829 result = inv_mpu6050_probe_trigger(indio_dev); 737 830 if (result) { 738 - dev_err(&st->client->dev, "trigger probe fail %d\n", result); 831 + dev_err(dev, "trigger probe fail %d\n", result); 739 832 goto out_unreg_ring; 740 833 } 741 834 ··· 742 837 spin_lock_init(&st->time_stamp_lock); 743 838 result = iio_device_register(indio_dev); 744 839 if (result) { 745 - dev_err(&st->client->dev, "IIO register fail %d\n", result); 840 + dev_err(dev, "IIO register fail %d\n", result); 746 841 goto out_remove_trigger; 747 842 } 748 843 749 - st->mux_adapter = i2c_add_mux_adapter(client->adapter, 750 - &client->dev, 751 - indio_dev, 752 - 0, 0, 0, 753 - inv_mpu6050_select_bypass, 754 - inv_mpu6050_deselect_bypass); 755 - if (!st->mux_adapter) { 756 - result = -ENODEV; 757 - goto out_unreg_device; 758 - } 759 - 760 - result = inv_mpu_acpi_create_mux_client(st); 761 - if (result) 762 - goto out_del_mux; 763 - 764 844 return 0; 765 845 766 - out_del_mux: 767 - i2c_del_mux_adapter(st->mux_adapter); 768 - out_unreg_device: 769 - iio_device_unregister(indio_dev); 770 846 out_remove_trigger: 771 847 inv_mpu6050_remove_trigger(st); 772 848 out_unreg_ring: 773 849 iio_triggered_buffer_cleanup(indio_dev); 774 850 return result; 775 851 } 852 + EXPORT_SYMBOL_GPL(inv_mpu_core_probe); 776 853 777 - static int inv_mpu_remove(struct i2c_client *client) 854 + int inv_mpu_core_remove(struct device *dev) 778 855 { 779 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 780 - struct inv_mpu6050_state *st = iio_priv(indio_dev); 856 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 781 857 782 - inv_mpu_acpi_delete_mux_client(st); 783 - i2c_del_mux_adapter(st->mux_adapter); 784 858 iio_device_unregister(indio_dev); 785 - inv_mpu6050_remove_trigger(st); 859 + inv_mpu6050_remove_trigger(iio_priv(indio_dev)); 786 860 iio_triggered_buffer_cleanup(indio_dev); 787 861 788 862 return 0; 789 863 } 864 + EXPORT_SYMBOL_GPL(inv_mpu_core_remove); 865 + 790 866 #ifdef CONFIG_PM_SLEEP 791 867 792 868 static int inv_mpu_resume(struct device *dev) 793 869 { 794 - return inv_mpu6050_set_power_itg( 795 - iio_priv(i2c_get_clientdata(to_i2c_client(dev))), true); 870 + return inv_mpu6050_set_power_itg(iio_priv(dev_get_drvdata(dev)), true); 796 871 } 797 872 798 873 static int inv_mpu_suspend(struct device *dev) 799 874 { 800 - return inv_mpu6050_set_power_itg( 801 - iio_priv(i2c_get_clientdata(to_i2c_client(dev))), false); 875 + return inv_mpu6050_set_power_itg(iio_priv(dev_get_drvdata(dev)), false); 802 876 } 803 - static SIMPLE_DEV_PM_OPS(inv_mpu_pmops, inv_mpu_suspend, inv_mpu_resume); 804 - 805 - #define INV_MPU6050_PMOPS (&inv_mpu_pmops) 806 - #else 807 - #define INV_MPU6050_PMOPS NULL 808 877 #endif /* CONFIG_PM_SLEEP */ 809 878 810 - /* 811 - * device id table is used to identify what device can be 812 - * supported by this driver 813 - */ 814 - static const struct i2c_device_id inv_mpu_id[] = { 815 - {"mpu6050", INV_MPU6050}, 816 - {"mpu6500", INV_MPU6500}, 817 - {} 818 - }; 819 - 820 - MODULE_DEVICE_TABLE(i2c, inv_mpu_id); 821 - 822 - static const struct acpi_device_id inv_acpi_match[] = { 823 - {"INVN6500", 0}, 824 - { }, 825 - }; 826 - 827 - MODULE_DEVICE_TABLE(acpi, inv_acpi_match); 828 - 829 - static struct i2c_driver inv_mpu_driver = { 830 - .probe = inv_mpu_probe, 831 - .remove = inv_mpu_remove, 832 - .id_table = inv_mpu_id, 833 - .driver = { 834 - .name = "inv-mpu6050", 835 - .pm = INV_MPU6050_PMOPS, 836 - .acpi_match_table = ACPI_PTR(inv_acpi_match), 837 - }, 838 - }; 839 - 840 - module_i2c_driver(inv_mpu_driver); 879 + SIMPLE_DEV_PM_OPS(inv_mpu_pmops, inv_mpu_suspend, inv_mpu_resume); 880 + EXPORT_SYMBOL_GPL(inv_mpu_pmops); 841 881 842 882 MODULE_AUTHOR("Invensense Corporation"); 843 883 MODULE_DESCRIPTION("Invensense device MPU6050 driver");
+206
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
··· 1 + /* 2 + * Copyright (C) 2012 Invensense, Inc. 3 + * 4 + * This software is licensed under the terms of the GNU General Public 5 + * License version 2, as published by the Free Software Foundation, and 6 + * may be copied, distributed, and modified under those terms. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #include <linux/acpi.h> 15 + #include <linux/delay.h> 16 + #include <linux/err.h> 17 + #include <linux/i2c.h> 18 + #include <linux/i2c-mux.h> 19 + #include <linux/iio/iio.h> 20 + #include <linux/module.h> 21 + #include "inv_mpu_iio.h" 22 + 23 + static const struct regmap_config inv_mpu_regmap_config = { 24 + .reg_bits = 8, 25 + .val_bits = 8, 26 + }; 27 + 28 + /* 29 + * The i2c read/write needs to happen in unlocked mode. As the parent 30 + * adapter is common. If we use locked versions, it will fail as 31 + * the mux adapter will lock the parent i2c adapter, while calling 32 + * select/deselect functions. 33 + */ 34 + static int inv_mpu6050_write_reg_unlocked(struct i2c_client *client, 35 + u8 reg, u8 d) 36 + { 37 + int ret; 38 + u8 buf[2] = {reg, d}; 39 + struct i2c_msg msg[1] = { 40 + { 41 + .addr = client->addr, 42 + .flags = 0, 43 + .len = sizeof(buf), 44 + .buf = buf, 45 + } 46 + }; 47 + 48 + ret = __i2c_transfer(client->adapter, msg, 1); 49 + if (ret != 1) 50 + return ret; 51 + 52 + return 0; 53 + } 54 + 55 + static int inv_mpu6050_select_bypass(struct i2c_adapter *adap, void *mux_priv, 56 + u32 chan_id) 57 + { 58 + struct i2c_client *client = mux_priv; 59 + struct iio_dev *indio_dev = dev_get_drvdata(&client->dev); 60 + struct inv_mpu6050_state *st = iio_priv(indio_dev); 61 + int ret = 0; 62 + 63 + /* Use the same mutex which was used everywhere to protect power-op */ 64 + mutex_lock(&indio_dev->mlock); 65 + if (!st->powerup_count) { 66 + ret = inv_mpu6050_write_reg_unlocked(client, 67 + st->reg->pwr_mgmt_1, 0); 68 + if (ret) 69 + goto write_error; 70 + 71 + msleep(INV_MPU6050_REG_UP_TIME); 72 + } 73 + if (!ret) { 74 + st->powerup_count++; 75 + ret = inv_mpu6050_write_reg_unlocked(client, 76 + st->reg->int_pin_cfg, 77 + INV_MPU6050_INT_PIN_CFG | 78 + INV_MPU6050_BIT_BYPASS_EN); 79 + } 80 + write_error: 81 + mutex_unlock(&indio_dev->mlock); 82 + 83 + return ret; 84 + } 85 + 86 + static int inv_mpu6050_deselect_bypass(struct i2c_adapter *adap, 87 + void *mux_priv, u32 chan_id) 88 + { 89 + struct i2c_client *client = mux_priv; 90 + struct iio_dev *indio_dev = dev_get_drvdata(&client->dev); 91 + struct inv_mpu6050_state *st = iio_priv(indio_dev); 92 + 93 + mutex_lock(&indio_dev->mlock); 94 + /* It doesn't really mattter, if any of the calls fails */ 95 + inv_mpu6050_write_reg_unlocked(client, st->reg->int_pin_cfg, 96 + INV_MPU6050_INT_PIN_CFG); 97 + st->powerup_count--; 98 + if (!st->powerup_count) 99 + inv_mpu6050_write_reg_unlocked(client, st->reg->pwr_mgmt_1, 100 + INV_MPU6050_BIT_SLEEP); 101 + mutex_unlock(&indio_dev->mlock); 102 + 103 + return 0; 104 + } 105 + 106 + /** 107 + * inv_mpu_probe() - probe function. 108 + * @client: i2c client. 109 + * @id: i2c device id. 110 + * 111 + * Returns 0 on success, a negative error code otherwise. 112 + */ 113 + static int inv_mpu_probe(struct i2c_client *client, 114 + const struct i2c_device_id *id) 115 + { 116 + struct inv_mpu6050_state *st; 117 + int result; 118 + const char *name = id ? id->name : NULL; 119 + struct regmap *regmap; 120 + 121 + if (!i2c_check_functionality(client->adapter, 122 + I2C_FUNC_SMBUS_I2C_BLOCK)) 123 + return -ENOSYS; 124 + 125 + regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config); 126 + if (IS_ERR(regmap)) { 127 + dev_err(&client->dev, "Failed to register i2c regmap %d\n", 128 + (int)PTR_ERR(regmap)); 129 + return PTR_ERR(regmap); 130 + } 131 + 132 + result = inv_mpu_core_probe(regmap, client->irq, name, NULL); 133 + if (result < 0) 134 + return result; 135 + 136 + st = iio_priv(dev_get_drvdata(&client->dev)); 137 + st->mux_adapter = i2c_add_mux_adapter(client->adapter, 138 + &client->dev, 139 + client, 140 + 0, 0, 0, 141 + inv_mpu6050_select_bypass, 142 + inv_mpu6050_deselect_bypass); 143 + if (!st->mux_adapter) { 144 + result = -ENODEV; 145 + goto out_unreg_device; 146 + } 147 + 148 + result = inv_mpu_acpi_create_mux_client(client); 149 + if (result) 150 + goto out_del_mux; 151 + 152 + return 0; 153 + 154 + out_del_mux: 155 + i2c_del_mux_adapter(st->mux_adapter); 156 + out_unreg_device: 157 + inv_mpu_core_remove(&client->dev); 158 + return result; 159 + } 160 + 161 + static int inv_mpu_remove(struct i2c_client *client) 162 + { 163 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 164 + struct inv_mpu6050_state *st = iio_priv(indio_dev); 165 + 166 + inv_mpu_acpi_delete_mux_client(client); 167 + i2c_del_mux_adapter(st->mux_adapter); 168 + 169 + return inv_mpu_core_remove(&client->dev); 170 + } 171 + 172 + /* 173 + * device id table is used to identify what device can be 174 + * supported by this driver 175 + */ 176 + static const struct i2c_device_id inv_mpu_id[] = { 177 + {"mpu6050", INV_MPU6050}, 178 + {"mpu6500", INV_MPU6500}, 179 + {} 180 + }; 181 + 182 + MODULE_DEVICE_TABLE(i2c, inv_mpu_id); 183 + 184 + static const struct acpi_device_id inv_acpi_match[] = { 185 + {"INVN6500", 0}, 186 + { }, 187 + }; 188 + 189 + MODULE_DEVICE_TABLE(acpi, inv_acpi_match); 190 + 191 + static struct i2c_driver inv_mpu_driver = { 192 + .probe = inv_mpu_probe, 193 + .remove = inv_mpu_remove, 194 + .id_table = inv_mpu_id, 195 + .driver = { 196 + .acpi_match_table = ACPI_PTR(inv_acpi_match), 197 + .name = "inv-mpu6050-i2c", 198 + .pm = &inv_mpu_pmops, 199 + }, 200 + }; 201 + 202 + module_i2c_driver(inv_mpu_driver); 203 + 204 + MODULE_AUTHOR("Invensense Corporation"); 205 + MODULE_DESCRIPTION("Invensense device MPU6050 driver"); 206 + MODULE_LICENSE("GPL");
+15 -4
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
··· 15 15 #include <linux/spinlock.h> 16 16 #include <linux/iio/iio.h> 17 17 #include <linux/iio/buffer.h> 18 + #include <linux/regmap.h> 18 19 #include <linux/iio/sysfs.h> 19 20 #include <linux/iio/kfifo_buf.h> 20 21 #include <linux/iio/trigger.h> ··· 62 61 enum inv_devices { 63 62 INV_MPU6050, 64 63 INV_MPU6500, 64 + INV_MPU6000, 65 65 INV_NUM_PARTS 66 66 }; 67 67 ··· 109 107 * @hw: Other hardware-specific information. 110 108 * @chip_type: chip type. 111 109 * @time_stamp_lock: spin lock to time stamp. 112 - * @client: i2c client handle. 113 110 * @plat_data: platform data. 114 111 * @timestamps: kfifo queue to store time stamp. 112 + * @map regmap pointer. 113 + * @irq interrupt number. 115 114 */ 116 115 struct inv_mpu6050_state { 117 116 #define TIMESTAMP_FIFO_SIZE 16 ··· 122 119 const struct inv_mpu6050_hw *hw; 123 120 enum inv_devices chip_type; 124 121 spinlock_t time_stamp_lock; 125 - struct i2c_client *client; 126 122 struct i2c_adapter *mux_adapter; 127 123 struct i2c_client *mux_client; 128 124 unsigned int powerup_count; 129 125 struct inv_mpu6050_platform_data plat_data; 130 126 DECLARE_KFIFO(timestamps, long long, TIMESTAMP_FIFO_SIZE); 127 + struct regmap *map; 128 + int irq; 131 129 }; 132 130 133 131 /*register and associated bit definition*/ ··· 155 151 #define INV_MPU6050_BIT_I2C_MST_EN 0x20 156 152 #define INV_MPU6050_BIT_FIFO_EN 0x40 157 153 #define INV_MPU6050_BIT_DMP_EN 0x80 154 + #define INV_MPU6050_BIT_I2C_IF_DIS 0x10 158 155 159 156 #define INV_MPU6050_REG_PWR_MGMT_1 0x6B 160 157 #define INV_MPU6050_BIT_H_RESET 0x80 ··· 190 185 191 186 #define INV_MPU6050_REG_INT_PIN_CFG 0x37 192 187 #define INV_MPU6050_BIT_BYPASS_EN 0x2 188 + #define INV_MPU6050_INT_PIN_CFG 0 193 189 194 190 /* init parameters */ 195 191 #define INV_MPU6050_INIT_FIFO_RATE 50 ··· 258 252 int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask); 259 253 int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 val); 260 254 int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on); 261 - int inv_mpu_acpi_create_mux_client(struct inv_mpu6050_state *st); 262 - void inv_mpu_acpi_delete_mux_client(struct inv_mpu6050_state *st); 255 + int inv_mpu_acpi_create_mux_client(struct i2c_client *client); 256 + void inv_mpu_acpi_delete_mux_client(struct i2c_client *client); 257 + int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, 258 + int (*inv_mpu_bus_setup)(struct iio_dev *)); 259 + int inv_mpu_core_remove(struct device *dev); 260 + int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on); 261 + extern const struct dev_pm_ops inv_mpu_pmops;
+17 -18
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
··· 13 13 14 14 #include <linux/module.h> 15 15 #include <linux/slab.h> 16 - #include <linux/i2c.h> 17 16 #include <linux/err.h> 18 17 #include <linux/delay.h> 19 18 #include <linux/sysfs.h> ··· 40 41 struct inv_mpu6050_state *st = iio_priv(indio_dev); 41 42 42 43 /* disable interrupt */ 43 - result = inv_mpu6050_write_reg(st, st->reg->int_enable, 0); 44 + result = regmap_write(st->map, st->reg->int_enable, 0); 44 45 if (result) { 45 - dev_err(&st->client->dev, "int_enable failed %d\n", result); 46 + dev_err(regmap_get_device(st->map), "int_enable failed %d\n", 47 + result); 46 48 return result; 47 49 } 48 50 /* disable the sensor output to FIFO */ 49 - result = inv_mpu6050_write_reg(st, st->reg->fifo_en, 0); 51 + result = regmap_write(st->map, st->reg->fifo_en, 0); 50 52 if (result) 51 53 goto reset_fifo_fail; 52 54 /* disable fifo reading */ 53 - result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 0); 55 + result = regmap_write(st->map, st->reg->user_ctrl, 0); 54 56 if (result) 55 57 goto reset_fifo_fail; 56 58 57 59 /* reset FIFO*/ 58 - result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 60 + result = regmap_write(st->map, st->reg->user_ctrl, 59 61 INV_MPU6050_BIT_FIFO_RST); 60 62 if (result) 61 63 goto reset_fifo_fail; ··· 67 67 /* enable interrupt */ 68 68 if (st->chip_config.accl_fifo_enable || 69 69 st->chip_config.gyro_fifo_enable) { 70 - result = inv_mpu6050_write_reg(st, st->reg->int_enable, 70 + result = regmap_write(st->map, st->reg->int_enable, 71 71 INV_MPU6050_BIT_DATA_RDY_EN); 72 72 if (result) 73 73 return result; 74 74 } 75 75 /* enable FIFO reading and I2C master interface*/ 76 - result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 76 + result = regmap_write(st->map, st->reg->user_ctrl, 77 77 INV_MPU6050_BIT_FIFO_EN); 78 78 if (result) 79 79 goto reset_fifo_fail; ··· 83 83 d |= INV_MPU6050_BITS_GYRO_OUT; 84 84 if (st->chip_config.accl_fifo_enable) 85 85 d |= INV_MPU6050_BIT_ACCEL_OUT; 86 - result = inv_mpu6050_write_reg(st, st->reg->fifo_en, d); 86 + result = regmap_write(st->map, st->reg->fifo_en, d); 87 87 if (result) 88 88 goto reset_fifo_fail; 89 89 90 90 return 0; 91 91 92 92 reset_fifo_fail: 93 - dev_err(&st->client->dev, "reset fifo failed %d\n", result); 94 - result = inv_mpu6050_write_reg(st, st->reg->int_enable, 93 + dev_err(regmap_get_device(st->map), "reset fifo failed %d\n", result); 94 + result = regmap_write(st->map, st->reg->int_enable, 95 95 INV_MPU6050_BIT_DATA_RDY_EN); 96 96 97 97 return result; ··· 143 143 * read fifo_count register to know how many bytes inside FIFO 144 144 * right now 145 145 */ 146 - result = i2c_smbus_read_i2c_block_data(st->client, 146 + result = regmap_bulk_read(st->map, 147 147 st->reg->fifo_count_h, 148 - INV_MPU6050_FIFO_COUNT_BYTE, data); 149 - if (result != INV_MPU6050_FIFO_COUNT_BYTE) 148 + data, INV_MPU6050_FIFO_COUNT_BYTE); 149 + if (result) 150 150 goto end_session; 151 151 fifo_count = be16_to_cpup((__be16 *)(&data[0])); 152 152 if (fifo_count < bytes_per_datum) ··· 161 161 fifo_count / bytes_per_datum + INV_MPU6050_TIME_STAMP_TOR) 162 162 goto flush_fifo; 163 163 while (fifo_count >= bytes_per_datum) { 164 - result = i2c_smbus_read_i2c_block_data(st->client, 165 - st->reg->fifo_r_w, 166 - bytes_per_datum, data); 167 - if (result != bytes_per_datum) 164 + result = regmap_bulk_read(st->map, st->reg->fifo_r_w, 165 + data, bytes_per_datum); 166 + if (result) 168 167 goto flush_fifo; 169 168 170 169 result = kfifo_out(&st->timestamps, &timestamp, 1);
+97
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
··· 1 + /* 2 + * Copyright (C) 2015 Intel Corporation Inc. 3 + * 4 + * This software is licensed under the terms of the GNU General Public 5 + * License version 2, as published by the Free Software Foundation, and 6 + * may be copied, distributed, and modified under those terms. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + #include <linux/module.h> 14 + #include <linux/acpi.h> 15 + #include <linux/spi/spi.h> 16 + #include <linux/regmap.h> 17 + #include <linux/iio/iio.h> 18 + #include "inv_mpu_iio.h" 19 + 20 + static const struct regmap_config inv_mpu_regmap_config = { 21 + .reg_bits = 8, 22 + .val_bits = 8, 23 + }; 24 + 25 + static int inv_mpu_i2c_disable(struct iio_dev *indio_dev) 26 + { 27 + struct inv_mpu6050_state *st = iio_priv(indio_dev); 28 + int ret = 0; 29 + 30 + ret = inv_mpu6050_set_power_itg(st, true); 31 + if (ret) 32 + return ret; 33 + 34 + ret = regmap_write(st->map, INV_MPU6050_REG_USER_CTRL, 35 + INV_MPU6050_BIT_I2C_IF_DIS); 36 + if (ret) { 37 + inv_mpu6050_set_power_itg(st, false); 38 + return ret; 39 + } 40 + 41 + return inv_mpu6050_set_power_itg(st, false); 42 + } 43 + 44 + static int inv_mpu_probe(struct spi_device *spi) 45 + { 46 + struct regmap *regmap; 47 + const struct spi_device_id *id = spi_get_device_id(spi); 48 + const char *name = id ? id->name : NULL; 49 + 50 + regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config); 51 + if (IS_ERR(regmap)) { 52 + dev_err(&spi->dev, "Failed to register spi regmap %d\n", 53 + (int)PTR_ERR(regmap)); 54 + return PTR_ERR(regmap); 55 + } 56 + 57 + return inv_mpu_core_probe(regmap, spi->irq, name, inv_mpu_i2c_disable); 58 + } 59 + 60 + static int inv_mpu_remove(struct spi_device *spi) 61 + { 62 + return inv_mpu_core_remove(&spi->dev); 63 + } 64 + 65 + /* 66 + * device id table is used to identify what device can be 67 + * supported by this driver 68 + */ 69 + static const struct spi_device_id inv_mpu_id[] = { 70 + {"mpu6000", INV_MPU6000}, 71 + {} 72 + }; 73 + 74 + MODULE_DEVICE_TABLE(spi, inv_mpu_id); 75 + 76 + static const struct acpi_device_id inv_acpi_match[] = { 77 + {"INVN6000", 0}, 78 + { }, 79 + }; 80 + MODULE_DEVICE_TABLE(acpi, inv_acpi_match); 81 + 82 + static struct spi_driver inv_mpu_driver = { 83 + .probe = inv_mpu_probe, 84 + .remove = inv_mpu_remove, 85 + .id_table = inv_mpu_id, 86 + .driver = { 87 + .acpi_match_table = ACPI_PTR(inv_acpi_match), 88 + .name = "inv-mpu6000-spi", 89 + .pm = &inv_mpu_pmops, 90 + }, 91 + }; 92 + 93 + module_spi_driver(inv_mpu_driver); 94 + 95 + MODULE_AUTHOR("Adriana Reus <adriana.reus@intel.com>"); 96 + MODULE_DESCRIPTION("Invensense device MPU6000 driver"); 97 + MODULE_LICENSE("GPL");
+5 -5
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
··· 65 65 if (result) 66 66 return result; 67 67 } else { 68 - result = inv_mpu6050_write_reg(st, st->reg->fifo_en, 0); 68 + result = regmap_write(st->map, st->reg->fifo_en, 0); 69 69 if (result) 70 70 return result; 71 71 72 - result = inv_mpu6050_write_reg(st, st->reg->int_enable, 0); 72 + result = regmap_write(st->map, st->reg->int_enable, 0); 73 73 if (result) 74 74 return result; 75 75 76 - result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 0); 76 + result = regmap_write(st->map, st->reg->user_ctrl, 0); 77 77 if (result) 78 78 return result; 79 79 ··· 123 123 if (!st->trig) 124 124 return -ENOMEM; 125 125 126 - ret = devm_request_irq(&indio_dev->dev, st->client->irq, 126 + ret = devm_request_irq(&indio_dev->dev, st->irq, 127 127 &iio_trigger_generic_data_rdy_poll, 128 128 IRQF_TRIGGER_RISING, 129 129 "inv_mpu", ··· 131 131 if (ret) 132 132 return ret; 133 133 134 - st->trig->dev.parent = &st->client->dev; 134 + st->trig->dev.parent = regmap_get_device(st->map); 135 135 st->trig->ops = &inv_mpu_trigger_ops; 136 136 iio_trigger_set_drvdata(st->trig, indio_dev); 137 137
+25 -34
drivers/iio/industrialio-buffer.c
··· 512 512 return sprintf(buf, "%d\n", iio_buffer_is_active(indio_dev->buffer)); 513 513 } 514 514 515 + static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev, 516 + unsigned int scan_index) 517 + { 518 + const struct iio_chan_spec *ch; 519 + unsigned int bytes; 520 + 521 + ch = iio_find_channel_from_si(indio_dev, scan_index); 522 + bytes = ch->scan_type.storagebits / 8; 523 + if (ch->scan_type.repeat > 1) 524 + bytes *= ch->scan_type.repeat; 525 + return bytes; 526 + } 527 + 528 + static unsigned int iio_storage_bytes_for_timestamp(struct iio_dev *indio_dev) 529 + { 530 + return iio_storage_bytes_for_si(indio_dev, 531 + indio_dev->scan_index_timestamp); 532 + } 533 + 515 534 static int iio_compute_scan_bytes(struct iio_dev *indio_dev, 516 535 const unsigned long *mask, bool timestamp) 517 536 { 518 - const struct iio_chan_spec *ch; 519 537 unsigned bytes = 0; 520 538 int length, i; 521 539 522 540 /* How much space will the demuxed element take? */ 523 541 for_each_set_bit(i, mask, 524 542 indio_dev->masklength) { 525 - ch = iio_find_channel_from_si(indio_dev, i); 526 - if (ch->scan_type.repeat > 1) 527 - length = ch->scan_type.storagebits / 8 * 528 - ch->scan_type.repeat; 529 - else 530 - length = ch->scan_type.storagebits / 8; 543 + length = iio_storage_bytes_for_si(indio_dev, i); 531 544 bytes = ALIGN(bytes, length); 532 545 bytes += length; 533 546 } 547 + 534 548 if (timestamp) { 535 - ch = iio_find_channel_from_si(indio_dev, 536 - indio_dev->scan_index_timestamp); 537 - if (ch->scan_type.repeat > 1) 538 - length = ch->scan_type.storagebits / 8 * 539 - ch->scan_type.repeat; 540 - else 541 - length = ch->scan_type.storagebits / 8; 549 + length = iio_storage_bytes_for_timestamp(indio_dev); 542 550 bytes = ALIGN(bytes, length); 543 551 bytes += length; 544 552 } ··· 1296 1288 static int iio_buffer_update_demux(struct iio_dev *indio_dev, 1297 1289 struct iio_buffer *buffer) 1298 1290 { 1299 - const struct iio_chan_spec *ch; 1300 1291 int ret, in_ind = -1, out_ind, length; 1301 1292 unsigned in_loc = 0, out_loc = 0; 1302 1293 struct iio_demux_table *p = NULL; ··· 1322 1315 in_ind = find_next_bit(indio_dev->active_scan_mask, 1323 1316 indio_dev->masklength, 1324 1317 in_ind + 1); 1325 - ch = iio_find_channel_from_si(indio_dev, in_ind); 1326 - if (ch->scan_type.repeat > 1) 1327 - length = ch->scan_type.storagebits / 8 * 1328 - ch->scan_type.repeat; 1329 - else 1330 - length = ch->scan_type.storagebits / 8; 1318 + length = iio_storage_bytes_for_si(indio_dev, in_ind); 1331 1319 /* Make sure we are aligned */ 1332 1320 in_loc = roundup(in_loc, length) + length; 1333 1321 } 1334 - ch = iio_find_channel_from_si(indio_dev, in_ind); 1335 - if (ch->scan_type.repeat > 1) 1336 - length = ch->scan_type.storagebits / 8 * 1337 - ch->scan_type.repeat; 1338 - else 1339 - length = ch->scan_type.storagebits / 8; 1322 + length = iio_storage_bytes_for_si(indio_dev, in_ind); 1340 1323 out_loc = roundup(out_loc, length); 1341 1324 in_loc = roundup(in_loc, length); 1342 1325 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length); ··· 1337 1340 } 1338 1341 /* Relies on scan_timestamp being last */ 1339 1342 if (buffer->scan_timestamp) { 1340 - ch = iio_find_channel_from_si(indio_dev, 1341 - indio_dev->scan_index_timestamp); 1342 - if (ch->scan_type.repeat > 1) 1343 - length = ch->scan_type.storagebits / 8 * 1344 - ch->scan_type.repeat; 1345 - else 1346 - length = ch->scan_type.storagebits / 8; 1343 + length = iio_storage_bytes_for_timestamp(indio_dev); 1347 1344 out_loc = roundup(out_loc, length); 1348 1345 in_loc = roundup(in_loc, length); 1349 1346 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length);
+1
drivers/iio/pressure/Kconfig
··· 69 69 70 70 config MS5611 71 71 tristate "Measurement Specialties MS5611 pressure sensor driver" 72 + select IIO_TRIGGERED_BUFFER 72 73 help 73 74 Say Y here to build support for the Measurement Specialties 74 75 MS5611, MS5607 pressure and temperature sensors.
+1
drivers/iio/pressure/ms5611.h
··· 52 52 }; 53 53 54 54 int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, int type); 55 + int ms5611_remove(struct iio_dev *indio_dev); 55 56 56 57 #endif /* _MS5611_H */
+88 -4
drivers/iio/pressure/ms5611_core.c
··· 17 17 #include <linux/iio/iio.h> 18 18 #include <linux/delay.h> 19 19 20 + #include <linux/iio/buffer.h> 21 + #include <linux/iio/triggered_buffer.h> 22 + #include <linux/iio/trigger_consumer.h> 20 23 #include "ms5611.h" 21 24 22 25 static bool ms5611_prom_is_valid(u16 *prom, size_t len) ··· 176 173 return 0; 177 174 } 178 175 176 + static irqreturn_t ms5611_trigger_handler(int irq, void *p) 177 + { 178 + struct iio_poll_func *pf = p; 179 + struct iio_dev *indio_dev = pf->indio_dev; 180 + struct ms5611_state *st = iio_priv(indio_dev); 181 + s32 buf[4]; /* s32 (pressure) + s32 (temp) + 2 * s32 (timestamp) */ 182 + int ret; 183 + 184 + mutex_lock(&st->lock); 185 + ret = ms5611_read_temp_and_pressure(indio_dev, &buf[1], &buf[0]); 186 + mutex_unlock(&st->lock); 187 + if (ret < 0) 188 + goto err; 189 + 190 + iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); 191 + 192 + err: 193 + iio_trigger_notify_done(indio_dev->trig); 194 + 195 + return IRQ_HANDLED; 196 + } 197 + 179 198 static int ms5611_read_raw(struct iio_dev *indio_dev, 180 199 struct iio_chan_spec const *chan, 181 200 int *val, int *val2, long mask) ··· 226 201 default: 227 202 return -EINVAL; 228 203 } 204 + case IIO_CHAN_INFO_SCALE: 205 + switch (chan->type) { 206 + case IIO_TEMP: 207 + *val = 10; 208 + return IIO_VAL_INT; 209 + case IIO_PRESSURE: 210 + *val = 0; 211 + *val2 = 1000; 212 + return IIO_VAL_INT_PLUS_MICRO; 213 + default: 214 + return -EINVAL; 215 + } 229 216 } 230 217 231 218 return -EINVAL; 232 219 } 220 + 221 + static const unsigned long ms5611_scan_masks[] = {0x3, 0}; 233 222 234 223 static struct ms5611_chip_info chip_info_tbl[] = { 235 224 [MS5611] = { ··· 257 218 static const struct iio_chan_spec ms5611_channels[] = { 258 219 { 259 220 .type = IIO_PRESSURE, 260 - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 221 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 222 + BIT(IIO_CHAN_INFO_SCALE), 223 + .scan_index = 0, 224 + .scan_type = { 225 + .sign = 's', 226 + .realbits = 32, 227 + .storagebits = 32, 228 + .endianness = IIO_CPU, 229 + }, 261 230 }, 262 231 { 263 232 .type = IIO_TEMP, 264 - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 265 - } 233 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 234 + BIT(IIO_CHAN_INFO_SCALE), 235 + .scan_index = 1, 236 + .scan_type = { 237 + .sign = 's', 238 + .realbits = 32, 239 + .storagebits = 32, 240 + .endianness = IIO_CPU, 241 + }, 242 + }, 243 + IIO_CHAN_SOFT_TIMESTAMP(2), 266 244 }; 267 245 268 246 static const struct iio_info ms5611_info = { ··· 311 255 indio_dev->channels = ms5611_channels; 312 256 indio_dev->num_channels = ARRAY_SIZE(ms5611_channels); 313 257 indio_dev->modes = INDIO_DIRECT_MODE; 258 + indio_dev->available_scan_masks = ms5611_scan_masks; 314 259 315 260 ret = ms5611_init(indio_dev); 316 261 if (ret < 0) 317 262 return ret; 318 263 319 - return devm_iio_device_register(dev, indio_dev); 264 + ret = iio_triggered_buffer_setup(indio_dev, NULL, 265 + ms5611_trigger_handler, NULL); 266 + if (ret < 0) { 267 + dev_err(dev, "iio triggered buffer setup failed\n"); 268 + return ret; 269 + } 270 + 271 + ret = iio_device_register(indio_dev); 272 + if (ret < 0) { 273 + dev_err(dev, "unable to register iio device\n"); 274 + goto err_buffer_cleanup; 275 + } 276 + 277 + return 0; 278 + 279 + err_buffer_cleanup: 280 + iio_triggered_buffer_cleanup(indio_dev); 281 + 282 + return ret; 320 283 } 321 284 EXPORT_SYMBOL(ms5611_probe); 285 + 286 + int ms5611_remove(struct iio_dev *indio_dev) 287 + { 288 + iio_device_unregister(indio_dev); 289 + iio_triggered_buffer_cleanup(indio_dev); 290 + 291 + return 0; 292 + } 293 + EXPORT_SYMBOL(ms5611_remove); 322 294 323 295 MODULE_AUTHOR("Tomasz Duszynski <tduszyns@gmail.com>"); 324 296 MODULE_DESCRIPTION("MS5611 core driver");
+7
drivers/iio/pressure/ms5611_i2c.c
··· 99 99 return -ENOMEM; 100 100 101 101 st = iio_priv(indio_dev); 102 + i2c_set_clientdata(client, indio_dev); 102 103 st->reset = ms5611_i2c_reset; 103 104 st->read_prom_word = ms5611_i2c_read_prom_word; 104 105 st->read_adc_temp_and_pressure = ms5611_i2c_read_adc_temp_and_pressure; 105 106 st->client = client; 106 107 107 108 return ms5611_probe(indio_dev, &client->dev, id->driver_data); 109 + } 110 + 111 + static int ms5611_i2c_remove(struct i2c_client *client) 112 + { 113 + return ms5611_remove(i2c_get_clientdata(client)); 108 114 } 109 115 110 116 static const struct i2c_device_id ms5611_id[] = { ··· 126 120 }, 127 121 .id_table = ms5611_id, 128 122 .probe = ms5611_i2c_probe, 123 + .remove = ms5611_i2c_remove, 129 124 }; 130 125 module_i2c_driver(ms5611_driver); 131 126
+8
drivers/iio/pressure/ms5611_spi.c
··· 90 90 if (!indio_dev) 91 91 return -ENOMEM; 92 92 93 + spi_set_drvdata(spi, indio_dev); 94 + 93 95 spi->mode = SPI_MODE_0; 94 96 spi->max_speed_hz = 20000000; 95 97 spi->bits_per_word = 8; ··· 109 107 spi_get_device_id(spi)->driver_data); 110 108 } 111 109 110 + static int ms5611_spi_remove(struct spi_device *spi) 111 + { 112 + return ms5611_remove(spi_get_drvdata(spi)); 113 + } 114 + 112 115 static const struct spi_device_id ms5611_id[] = { 113 116 { "ms5611", MS5611 }, 114 117 { "ms5607", MS5607 }, ··· 127 120 }, 128 121 .id_table = ms5611_id, 129 122 .probe = ms5611_spi_probe, 123 + .remove = ms5611_spi_remove, 130 124 }; 131 125 module_spi_driver(ms5611_driver); 132 126
+2 -16
drivers/staging/iio/adc/Kconfig
··· 59 59 temperature sensors and ADC. 60 60 61 61 config AD7192 62 - tristate "Analog Devices AD7190 AD7192 AD7195 ADC driver" 62 + tristate "Analog Devices AD7190 AD7192 AD7193 AD7195 ADC driver" 63 63 depends on SPI 64 64 select AD_SIGMA_DELTA 65 65 help 66 66 Say yes here to build support for Analog Devices AD7190, 67 - AD7192 or AD7195 SPI analog to digital converters (ADC). 67 + AD7192, AD7193 or AD7195 SPI analog to digital converters (ADC). 68 68 If unsure, say N (but it's safe to say "Y"). 69 69 70 70 To compile this driver as a module, choose M here: the ··· 91 91 drivers (lpc32xx_adc or lpc32xx_ts) or, in the OpenFirmware case, 92 92 activate only one via device tree selection. Provides direct access 93 93 via sysfs. 94 - 95 - config MXS_LRADC 96 - tristate "Freescale i.MX23/i.MX28 LRADC" 97 - depends on (ARCH_MXS || COMPILE_TEST) && HAS_IOMEM 98 - depends on INPUT 99 - select STMP_DEVICE 100 - select IIO_BUFFER 101 - select IIO_TRIGGERED_BUFFER 102 - help 103 - Say yes here to build support for i.MX23/i.MX28 LRADC convertor 104 - built into these chips. 105 - 106 - To compile this driver as a module, choose M here: the 107 - module will be called mxs-lradc. 108 94 109 95 config SPEAR_ADC 110 96 tristate "ST SPEAr ADC"
-1
drivers/staging/iio/adc/Makefile
··· 12 12 obj-$(CONFIG_AD7192) += ad7192.o 13 13 obj-$(CONFIG_AD7280) += ad7280a.o 14 14 obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o 15 - obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o 16 15 obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
+61 -15
drivers/staging/iio/adc/ad7192.c
··· 1 1 /* 2 - * AD7190 AD7192 AD7195 SPI ADC driver 2 + * AD7190 AD7192 AD7193 AD7195 SPI ADC driver 3 3 * 4 - * Copyright 2011-2012 Analog Devices Inc. 4 + * Copyright 2011-2015 Analog Devices Inc. 5 5 * 6 6 * Licensed under the GPL-2. 7 7 */ ··· 92 92 93 93 #define AD7192_CONF_CHOP BIT(23) /* CHOP enable */ 94 94 #define AD7192_CONF_REFSEL BIT(20) /* REFIN1/REFIN2 Reference Select */ 95 - #define AD7192_CONF_CHAN(x) (((1 << (x)) & 0xFF) << 8) /* Channel select */ 96 - #define AD7192_CONF_CHAN_MASK (0xFF << 8) /* Channel select mask */ 95 + #define AD7192_CONF_CHAN(x) ((x) << 8) /* Channel select */ 96 + #define AD7192_CONF_CHAN_MASK (0x7FF << 8) /* Channel select mask */ 97 97 #define AD7192_CONF_BURN BIT(7) /* Burnout current enable */ 98 98 #define AD7192_CONF_REFDET BIT(6) /* Reference detect enable */ 99 99 #define AD7192_CONF_BUF BIT(4) /* Buffered Mode Enable */ 100 100 #define AD7192_CONF_UNIPOLAR BIT(3) /* Unipolar/Bipolar Enable */ 101 101 #define AD7192_CONF_GAIN(x) ((x) & 0x7) /* Gain Select */ 102 102 103 - #define AD7192_CH_AIN1P_AIN2M 0 /* AIN1(+) - AIN2(-) */ 104 - #define AD7192_CH_AIN3P_AIN4M 1 /* AIN3(+) - AIN4(-) */ 105 - #define AD7192_CH_TEMP 2 /* Temp Sensor */ 106 - #define AD7192_CH_AIN2P_AIN2M 3 /* AIN2(+) - AIN2(-) */ 107 - #define AD7192_CH_AIN1 4 /* AIN1 - AINCOM */ 108 - #define AD7192_CH_AIN2 5 /* AIN2 - AINCOM */ 109 - #define AD7192_CH_AIN3 6 /* AIN3 - AINCOM */ 110 - #define AD7192_CH_AIN4 7 /* AIN4 - AINCOM */ 103 + #define AD7192_CH_AIN1P_AIN2M BIT(0) /* AIN1(+) - AIN2(-) */ 104 + #define AD7192_CH_AIN3P_AIN4M BIT(1) /* AIN3(+) - AIN4(-) */ 105 + #define AD7192_CH_TEMP BIT(2) /* Temp Sensor */ 106 + #define AD7192_CH_AIN2P_AIN2M BIT(3) /* AIN2(+) - AIN2(-) */ 107 + #define AD7192_CH_AIN1 BIT(4) /* AIN1 - AINCOM */ 108 + #define AD7192_CH_AIN2 BIT(5) /* AIN2 - AINCOM */ 109 + #define AD7192_CH_AIN3 BIT(6) /* AIN3 - AINCOM */ 110 + #define AD7192_CH_AIN4 BIT(7) /* AIN4 - AINCOM */ 111 + 112 + #define AD7193_CH_AIN1P_AIN2M 0x000 /* AIN1(+) - AIN2(-) */ 113 + #define AD7193_CH_AIN3P_AIN4M 0x001 /* AIN3(+) - AIN4(-) */ 114 + #define AD7193_CH_AIN5P_AIN6M 0x002 /* AIN5(+) - AIN6(-) */ 115 + #define AD7193_CH_AIN7P_AIN8M 0x004 /* AIN7(+) - AIN8(-) */ 116 + #define AD7193_CH_TEMP 0x100 /* Temp senseor */ 117 + #define AD7193_CH_AIN2P_AIN2M 0x200 /* AIN2(+) - AIN2(-) */ 118 + #define AD7193_CH_AIN1 0x401 /* AIN1 - AINCOM */ 119 + #define AD7193_CH_AIN2 0x402 /* AIN2 - AINCOM */ 120 + #define AD7193_CH_AIN3 0x404 /* AIN3 - AINCOM */ 121 + #define AD7193_CH_AIN4 0x408 /* AIN4 - AINCOM */ 122 + #define AD7193_CH_AIN5 0x410 /* AIN5 - AINCOM */ 123 + #define AD7193_CH_AIN6 0x420 /* AIN6 - AINCOM */ 124 + #define AD7193_CH_AIN7 0x440 /* AIN7 - AINCOM */ 125 + #define AD7193_CH_AIN8 0x480 /* AIN7 - AINCOM */ 126 + #define AD7193_CH_AINCOM 0x600 /* AINCOM - AINCOM */ 111 127 112 128 /* ID Register Bit Designations (AD7192_REG_ID) */ 113 129 #define ID_AD7190 0x4 114 130 #define ID_AD7192 0x0 131 + #define ID_AD7193 0x2 115 132 #define ID_AD7195 0x6 116 133 #define AD7192_ID_MASK 0x0F 117 134 ··· 624 607 IIO_CHAN_SOFT_TIMESTAMP(8), 625 608 }; 626 609 610 + static const struct iio_chan_spec ad7193_channels[] = { 611 + AD_SD_DIFF_CHANNEL(0, 1, 2, AD7193_CH_AIN1P_AIN2M, 24, 32, 0), 612 + AD_SD_DIFF_CHANNEL(1, 3, 4, AD7193_CH_AIN3P_AIN4M, 24, 32, 0), 613 + AD_SD_DIFF_CHANNEL(2, 5, 6, AD7193_CH_AIN5P_AIN6M, 24, 32, 0), 614 + AD_SD_DIFF_CHANNEL(3, 7, 8, AD7193_CH_AIN7P_AIN8M, 24, 32, 0), 615 + AD_SD_TEMP_CHANNEL(4, AD7193_CH_TEMP, 24, 32, 0), 616 + AD_SD_SHORTED_CHANNEL(5, 2, AD7193_CH_AIN2P_AIN2M, 24, 32, 0), 617 + AD_SD_CHANNEL(6, 1, AD7193_CH_AIN1, 24, 32, 0), 618 + AD_SD_CHANNEL(7, 2, AD7193_CH_AIN2, 24, 32, 0), 619 + AD_SD_CHANNEL(8, 3, AD7193_CH_AIN3, 24, 32, 0), 620 + AD_SD_CHANNEL(9, 4, AD7193_CH_AIN4, 24, 32, 0), 621 + AD_SD_CHANNEL(10, 5, AD7193_CH_AIN5, 24, 32, 0), 622 + AD_SD_CHANNEL(11, 6, AD7193_CH_AIN6, 24, 32, 0), 623 + AD_SD_CHANNEL(12, 7, AD7193_CH_AIN7, 24, 32, 0), 624 + AD_SD_CHANNEL(13, 8, AD7193_CH_AIN8, 24, 32, 0), 625 + IIO_CHAN_SOFT_TIMESTAMP(14), 626 + }; 627 + 627 628 static int ad7192_probe(struct spi_device *spi) 628 629 { 629 630 const struct ad7192_platform_data *pdata = dev_get_platdata(&spi->dev); ··· 686 651 indio_dev->dev.parent = &spi->dev; 687 652 indio_dev->name = spi_get_device_id(spi)->name; 688 653 indio_dev->modes = INDIO_DIRECT_MODE; 689 - indio_dev->channels = ad7192_channels; 690 - indio_dev->num_channels = ARRAY_SIZE(ad7192_channels); 654 + 655 + switch (st->devid) { 656 + case ID_AD7193: 657 + indio_dev->channels = ad7193_channels; 658 + indio_dev->num_channels = ARRAY_SIZE(ad7193_channels); 659 + break; 660 + default: 661 + indio_dev->channels = ad7192_channels; 662 + indio_dev->num_channels = ARRAY_SIZE(ad7192_channels); 663 + break; 664 + } 665 + 691 666 if (st->devid == ID_AD7195) 692 667 indio_dev->info = &ad7195_info; 693 668 else ··· 744 699 static const struct spi_device_id ad7192_id[] = { 745 700 {"ad7190", ID_AD7190}, 746 701 {"ad7192", ID_AD7192}, 702 + {"ad7193", ID_AD7193}, 747 703 {"ad7195", ID_AD7195}, 748 704 {} 749 705 }; ··· 761 715 module_spi_driver(ad7192_driver); 762 716 763 717 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 764 - MODULE_DESCRIPTION("Analog Devices AD7190, AD7192, AD7195 ADC"); 718 + MODULE_DESCRIPTION("Analog Devices AD7190, AD7192, AD7193, AD7195 ADC"); 765 719 MODULE_LICENSE("GPL v2");
+8 -2
drivers/staging/iio/adc/ad7606.h
··· 85 85 int (*read_block)(struct device *, int, void *); 86 86 }; 87 87 88 - void ad7606_suspend(struct iio_dev *indio_dev); 89 - void ad7606_resume(struct iio_dev *indio_dev); 90 88 struct iio_dev *ad7606_probe(struct device *dev, int irq, 91 89 void __iomem *base_address, unsigned id, 92 90 const struct ad7606_bus_ops *bops); ··· 99 101 100 102 int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev); 101 103 void ad7606_ring_cleanup(struct iio_dev *indio_dev); 104 + 105 + #ifdef CONFIG_PM_SLEEP 106 + extern const struct dev_pm_ops ad7606_pm_ops; 107 + #define AD7606_PM_OPS (&ad7606_pm_ops) 108 + #else 109 + #define AD7606_PM_OPS NULL 110 + #endif 111 + 102 112 #endif /* IIO_ADC_AD7606_H_ */
+24 -31
drivers/staging/iio/adc/ad7606_core.c
··· 250 250 }, \ 251 251 } 252 252 253 - static const struct iio_chan_spec ad7606_8_channels[] = { 253 + static const struct iio_chan_spec ad7606_channels[] = { 254 + IIO_CHAN_SOFT_TIMESTAMP(8), 254 255 AD7606_CHANNEL(0), 255 256 AD7606_CHANNEL(1), 256 257 AD7606_CHANNEL(2), ··· 260 259 AD7606_CHANNEL(5), 261 260 AD7606_CHANNEL(6), 262 261 AD7606_CHANNEL(7), 263 - IIO_CHAN_SOFT_TIMESTAMP(8), 264 - }; 265 - 266 - static const struct iio_chan_spec ad7606_6_channels[] = { 267 - AD7606_CHANNEL(0), 268 - AD7606_CHANNEL(1), 269 - AD7606_CHANNEL(2), 270 - AD7606_CHANNEL(3), 271 - AD7606_CHANNEL(4), 272 - AD7606_CHANNEL(5), 273 - IIO_CHAN_SOFT_TIMESTAMP(6), 274 - }; 275 - 276 - static const struct iio_chan_spec ad7606_4_channels[] = { 277 - AD7606_CHANNEL(0), 278 - AD7606_CHANNEL(1), 279 - AD7606_CHANNEL(2), 280 - AD7606_CHANNEL(3), 281 - IIO_CHAN_SOFT_TIMESTAMP(4), 282 262 }; 283 263 284 264 static const struct ad7606_chip_info ad7606_chip_info_tbl[] = { ··· 269 287 [ID_AD7606_8] = { 270 288 .name = "ad7606", 271 289 .int_vref_mv = 2500, 272 - .channels = ad7606_8_channels, 273 - .num_channels = 8, 290 + .channels = ad7606_channels, 291 + .num_channels = 9, 274 292 }, 275 293 [ID_AD7606_6] = { 276 294 .name = "ad7606-6", 277 295 .int_vref_mv = 2500, 278 - .channels = ad7606_6_channels, 279 - .num_channels = 6, 296 + .channels = ad7606_channels, 297 + .num_channels = 7, 280 298 }, 281 299 [ID_AD7606_4] = { 282 300 .name = "ad7606-4", 283 301 .int_vref_mv = 2500, 284 - .channels = ad7606_4_channels, 285 - .num_channels = 4, 302 + .channels = ad7606_channels, 303 + .num_channels = 5, 286 304 }, 287 305 }; 288 306 ··· 560 578 } 561 579 EXPORT_SYMBOL_GPL(ad7606_remove); 562 580 563 - void ad7606_suspend(struct iio_dev *indio_dev) 581 + #ifdef CONFIG_PM_SLEEP 582 + 583 + static int ad7606_suspend(struct device *dev) 564 584 { 585 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 565 586 struct ad7606_state *st = iio_priv(indio_dev); 566 587 567 588 if (gpio_is_valid(st->pdata->gpio_stby)) { ··· 572 587 gpio_set_value(st->pdata->gpio_range, 1); 573 588 gpio_set_value(st->pdata->gpio_stby, 0); 574 589 } 575 - } 576 - EXPORT_SYMBOL_GPL(ad7606_suspend); 577 590 578 - void ad7606_resume(struct iio_dev *indio_dev) 591 + return 0; 592 + } 593 + 594 + static int ad7606_resume(struct device *dev) 579 595 { 596 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 580 597 struct ad7606_state *st = iio_priv(indio_dev); 581 598 582 599 if (gpio_is_valid(st->pdata->gpio_stby)) { ··· 589 602 gpio_set_value(st->pdata->gpio_stby, 1); 590 603 ad7606_reset(st); 591 604 } 605 + 606 + return 0; 592 607 } 593 - EXPORT_SYMBOL_GPL(ad7606_resume); 608 + 609 + SIMPLE_DEV_PM_OPS(ad7606_pm_ops, ad7606_suspend, ad7606_resume); 610 + EXPORT_SYMBOL_GPL(ad7606_pm_ops); 611 + 612 + #endif 594 613 595 614 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 596 615 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
+1 -31
drivers/staging/iio/adc/ad7606_par.c
··· 90 90 return 0; 91 91 } 92 92 93 - #ifdef CONFIG_PM 94 - static int ad7606_par_suspend(struct device *dev) 95 - { 96 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 97 - 98 - ad7606_suspend(indio_dev); 99 - 100 - return 0; 101 - } 102 - 103 - static int ad7606_par_resume(struct device *dev) 104 - { 105 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 106 - 107 - ad7606_resume(indio_dev); 108 - 109 - return 0; 110 - } 111 - 112 - static const struct dev_pm_ops ad7606_pm_ops = { 113 - .suspend = ad7606_par_suspend, 114 - .resume = ad7606_par_resume, 115 - }; 116 - 117 - #define AD7606_PAR_PM_OPS (&ad7606_pm_ops) 118 - 119 - #else 120 - #define AD7606_PAR_PM_OPS NULL 121 - #endif /* CONFIG_PM */ 122 - 123 93 static const struct platform_device_id ad7606_driver_ids[] = { 124 94 { 125 95 .name = "ad7606-8", ··· 112 142 .id_table = ad7606_driver_ids, 113 143 .driver = { 114 144 .name = "ad7606", 115 - .pm = AD7606_PAR_PM_OPS, 145 + .pm = AD7606_PM_OPS, 116 146 }, 117 147 }; 118 148
+1 -31
drivers/staging/iio/adc/ad7606_spi.c
··· 62 62 return ad7606_remove(indio_dev, spi->irq); 63 63 } 64 64 65 - #ifdef CONFIG_PM 66 - static int ad7606_spi_suspend(struct device *dev) 67 - { 68 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 69 - 70 - ad7606_suspend(indio_dev); 71 - 72 - return 0; 73 - } 74 - 75 - static int ad7606_spi_resume(struct device *dev) 76 - { 77 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 78 - 79 - ad7606_resume(indio_dev); 80 - 81 - return 0; 82 - } 83 - 84 - static const struct dev_pm_ops ad7606_pm_ops = { 85 - .suspend = ad7606_spi_suspend, 86 - .resume = ad7606_spi_resume, 87 - }; 88 - 89 - #define AD7606_SPI_PM_OPS (&ad7606_pm_ops) 90 - 91 - #else 92 - #define AD7606_SPI_PM_OPS NULL 93 - #endif 94 - 95 65 static const struct spi_device_id ad7606_id[] = { 96 66 {"ad7606-8", ID_AD7606_8}, 97 67 {"ad7606-6", ID_AD7606_6}, ··· 73 103 static struct spi_driver ad7606_driver = { 74 104 .driver = { 75 105 .name = "ad7606", 76 - .pm = AD7606_SPI_PM_OPS, 106 + .pm = AD7606_PM_OPS, 77 107 }, 78 108 .probe = ad7606_spi_probe, 79 109 .remove = ad7606_spi_remove,
+9 -4
drivers/staging/iio/adc/mxs-lradc.c drivers/iio/adc/mxs-lradc.c
··· 443 443 LRADC_CH_NUM_SAMPLES(lradc->over_sample_cnt - 1), 444 444 LRADC_CH(ch)); 445 445 446 - /* from the datasheet: 446 + /* 447 + * from the datasheet: 447 448 * "Software must clear this register in preparation for a 448 449 * multi-cycle accumulation. 449 450 */ ··· 505 504 mxs_lradc_reg_wrt(lradc, reg, LRADC_CH(ch1)); 506 505 mxs_lradc_reg_wrt(lradc, reg, LRADC_CH(ch2)); 507 506 508 - /* from the datasheet: 507 + /* 508 + * from the datasheet: 509 509 * "Software must clear this register in preparation for a 510 510 * multi-cycle accumulation. 511 511 */ ··· 916 914 917 915 case IIO_CHAN_INFO_SCALE: 918 916 if (chan->type == IIO_TEMP) { 919 - /* From the datasheet, we have to multiply by 1.012 and 917 + /* 918 + * From the datasheet, we have to multiply by 1.012 and 920 919 * divide by 4 921 920 */ 922 921 *val = 0; ··· 932 929 933 930 case IIO_CHAN_INFO_OFFSET: 934 931 if (chan->type == IIO_TEMP) { 935 - /* The calculated value from the ADC is in Kelvin, we 932 + /* 933 + * The calculated value from the ADC is in Kelvin, we 936 934 * want Celsius for hwmon so the offset is -273.15 937 935 * The offset is applied before scaling so it is 938 936 * actually -213.15 * 4 / 1.012 = -1079.644268 ··· 1754 1750 iio_triggered_buffer_cleanup(iio); 1755 1751 1756 1752 clk_disable_unprepare(lradc->clk); 1753 + 1757 1754 return 0; 1758 1755 } 1759 1756
+7 -10
drivers/staging/iio/adc/spear_adc.c
··· 288 288 st->adc_base_spear3xx = 289 289 (struct adc_regs_spear3xx __iomem *)st->adc_base_spear6xx; 290 290 291 - st->clk = clk_get(dev, NULL); 291 + st->clk = devm_clk_get(dev, NULL); 292 292 if (IS_ERR(st->clk)) { 293 293 dev_err(dev, "failed getting clock\n"); 294 294 goto errout1; ··· 297 297 ret = clk_prepare_enable(st->clk); 298 298 if (ret) { 299 299 dev_err(dev, "failed enabling clock\n"); 300 - goto errout2; 300 + goto errout1; 301 301 } 302 302 303 303 irq = platform_get_irq(pdev, 0); 304 304 if (irq <= 0) { 305 305 dev_err(dev, "failed getting interrupt resource\n"); 306 306 ret = -EINVAL; 307 - goto errout3; 307 + goto errout2; 308 308 } 309 309 310 310 ret = devm_request_irq(dev, irq, spear_adc_isr, 0, SPEAR_ADC_MOD_NAME, 311 311 st); 312 312 if (ret < 0) { 313 313 dev_err(dev, "failed requesting interrupt\n"); 314 - goto errout3; 314 + goto errout2; 315 315 } 316 316 317 317 if (of_property_read_u32(np, "sampling-frequency", 318 318 &st->sampling_freq)) { 319 319 dev_err(dev, "sampling-frequency missing in DT\n"); 320 320 ret = -EINVAL; 321 - goto errout3; 321 + goto errout2; 322 322 } 323 323 324 324 /* ··· 348 348 349 349 ret = iio_device_register(indio_dev); 350 350 if (ret) 351 - goto errout3; 351 + goto errout2; 352 352 353 353 dev_info(dev, "SPEAR ADC driver loaded, IRQ %d\n", irq); 354 354 355 355 return 0; 356 356 357 - errout3: 358 - clk_disable_unprepare(st->clk); 359 357 errout2: 360 - clk_put(st->clk); 358 + clk_disable_unprepare(st->clk); 361 359 errout1: 362 360 iounmap(st->adc_base_spear6xx); 363 361 return ret; ··· 368 370 369 371 iio_device_unregister(indio_dev); 370 372 clk_disable_unprepare(st->clk); 371 - clk_put(st->clk); 372 373 iounmap(st->adc_base_spear6xx); 373 374 374 375 return 0;
+4 -4
drivers/staging/iio/impedance-analyzer/ad5933.c
··· 558 558 } 559 559 560 560 static const struct iio_info ad5933_info = { 561 - .read_raw = &ad5933_read_raw, 561 + .read_raw = ad5933_read_raw, 562 562 .attrs = &ad5933_attribute_group, 563 563 .driver_module = THIS_MODULE, 564 564 }; ··· 616 616 } 617 617 618 618 static const struct iio_buffer_setup_ops ad5933_ring_setup_ops = { 619 - .preenable = &ad5933_ring_preenable, 620 - .postenable = &ad5933_ring_postenable, 621 - .postdisable = &ad5933_ring_postdisable, 619 + .preenable = ad5933_ring_preenable, 620 + .postenable = ad5933_ring_postenable, 621 + .postdisable = ad5933_ring_postdisable, 622 622 }; 623 623 624 624 static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev)
+2 -3
drivers/staging/iio/magnetometer/hmc5843.h
··· 7 7 * This program is free software; you can redistribute it and/or modify 8 8 * it under the terms of the GNU General Public License version 2 as 9 9 * published by the Free Software Foundation. 10 - * 11 - * */ 10 + */ 12 11 13 12 #ifndef HMC5843_CORE_H 14 13 #define HMC5843_CORE_H ··· 37 38 * @regmap: hardware access register maps 38 39 * @variant: describe chip variants 39 40 * @buffer: 3x 16-bit channels + padding + 64-bit timestamp 40 - **/ 41 + */ 41 42 struct hmc5843_data { 42 43 struct device *dev; 43 44 struct mutex lock;
+2 -2
drivers/staging/iio/magnetometer/hmc5843_core.c
··· 565 565 int hmc5843_common_suspend(struct device *dev) 566 566 { 567 567 return hmc5843_set_mode(iio_priv(dev_get_drvdata(dev)), 568 - HMC5843_MODE_CONVERSION_CONTINUOUS); 568 + HMC5843_MODE_SLEEP); 569 569 } 570 570 EXPORT_SYMBOL(hmc5843_common_suspend); 571 571 572 572 int hmc5843_common_resume(struct device *dev) 573 573 { 574 574 return hmc5843_set_mode(iio_priv(dev_get_drvdata(dev)), 575 - HMC5843_MODE_SLEEP); 575 + HMC5843_MODE_CONVERSION_CONTINUOUS); 576 576 } 577 577 EXPORT_SYMBOL(hmc5843_common_resume); 578 578
+1 -2
drivers/staging/iio/magnetometer/hmc5843_i2c.c
··· 7 7 * This program is free software; you can redistribute it and/or modify 8 8 * it under the terms of the GNU General Public License version 2 as 9 9 * published by the Free Software Foundation. 10 - * 11 - * */ 10 + */ 12 11 13 12 #include <linux/module.h> 14 13 #include <linux/i2c.h>
+1 -2
drivers/staging/iio/magnetometer/hmc5843_spi.c
··· 6 6 * This program is free software; you can redistribute it and/or modify 7 7 * it under the terms of the GNU General Public License version 2 as 8 8 * published by the Free Software Foundation. 9 - * 10 - * */ 9 + */ 11 10 12 11 #include <linux/module.h> 13 12 #include <linux/spi/spi.h>
+1 -1
include/linux/iio/iio.h
··· 448 448 * @buffer: [DRIVER] any buffer present 449 449 * @buffer_list: [INTERN] list of all buffers currently attached 450 450 * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux 451 - * @mlock: [INTERN] lock used to prevent simultaneous device state 451 + * @mlock: [DRIVER] lock used to prevent simultaneous device state 452 452 * changes 453 453 * @available_scan_masks: [DRIVER] optional array of allowed bitmasks 454 454 * @masklength: [INTERN] the length of the mask established from