diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-04-04 15:31:05 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-04-04 15:31:05 -0400 |
commit | eb7bfed901b9fea6e48bec10009dc8c8641e36e7 (patch) | |
tree | e03df0b64ecdfc3c51bf0bbdd2f96cd2a6348a7a /drivers/iio/adc | |
parent | 56d118c243fbc62d95a79183bb6bcfc38a398da5 (diff) | |
parent | 486294f184c05cff116160bb731cbb679f047621 (diff) |
Merge tag 'iio-for-4.7a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes:
First round of IIO new device support, features and cleanups for the 4.7 cycle.
New core support
* UV light modifier (for intensity)
* UV light index channel type.
New device support
* hp206c barometer and altimeter
- new driver.
* mcp4131 potentiometer
- new driver supporting lots of parts from Microchip.
* mma8452
- FXLS8471Q support
- NXP LPC18XX SOC ADC
- new driver.
- NXP LPC18XX SOC DAC
- new driver.
- rockchip_saradc
- support rk3399
* st accel
- h3lis331dl support
Staging driver removals
* adis16204
- obsolete part making it hard to get parts to test the driver in order
to clean it up.
* adis16220
- obsolete part making it hard to get the parts test the driver in order
to clean it up.
Features
* core
- convenience functions to claim / release direct access to the device.
Makes more consistent handling of this corner easier. Used in ad7192 driver.
* ak8975
- power regulator support.
* at91-sama5d2
- differential channel support.
* mma8452
- runtime pm support
- drop device specific autosleep and use the runtime pm one instead.
* ms5611
- DT bindings
- oversampling ratio support
Cleanups and minor fixes
* MAINTAINERS
- Peter got married - hence name change!
* Documentation
- Fix a typo in in_proximity_raw description.
- Add some missing docs for iio_buffer_access_funcs.
* Tools
- update iio_event_monitor names to match new stuff.
- make generic_buffer look for triggers ending in -trigger as we let these in
for a number of drivers a long time back and now it is a fairly common
option.
Drivers
* staging wide
- convert bare unsigned usage to unsigned int to comply with coding style.
* non staging wide:
- since boiler plate gpio handling of interrupts has been moved into the
ACPI core we don't need to include gpio/consumer.h in a load of drivers so
drop it.
* ad7606
- fix an endian casting sparse warning.
* ak8975
- fix a possible unitialized warning from gcc.
- drop and unused field left over from earlier cleanups
- fix a missing regulator_disable on exit.
* at91-sama5d2
- typo and indentation
- missing IOMEM dependency.
- cleanup mode register usage by avoidling erasing whole thing when changing
the sampling frequency.
* bmc150
- use the core demux and available_scan_masks to simplify buffer handling
- optimize the transfers in the trigger handler now we have a magic function
to emulate bulk reads (under circumstances met here). This matters with some
rather dumb i2c adapters in particular.
- use a single regmap_conf for all bus types as they were all the same.
* bmg160
- use the core demux and available_scan_masks to simplify the buffer handling
- optimize the transfers in the trigger handler now we have a magic funciton
to emulate bulk rads (under circumstances met here).
- drop gpio interrupt probing from the driver (ACPI) as now handled by the
ACPI core.
* ina2xx-adc
- update the CALIB register when RShunt changes.
- fix scale for VShunt - in reality this error canceled out when used.
* isl29028
- use regmap to retrieve the struct device instead of carrying a second
copy of it around.
* kxcjk-1013
- use core demux
- optimize i2c transfers in the trigger handler.
* mcp4531
- refactor to use a pointer to access model parameters instead of indexing
into the array each time.
* mma8452
- style fixes
- avoid swtiching to active whenever the config changes
- add missin i2c_device_id for mma8451
* mpu6050
- fix possible NULL dereference.
- fix the name / chip_id used when ACPI used (otherwise reports as NULL).
* ms5611
- fix a missing regulator_disable that left the regulator on during removal.
* mxc4005
- drop gpio interrupt handling for ACPI case from driver as the core now
handles this case.
* st-sensors
- note that there are only ever a maximum of 3 axis on current st-sensors
so just allocate a fixed sized buffer big enough for that.
* tpl0102
- change the i2c_check_functionality condition to bring it inline with other
IIO users as EOPNOTSUPP.
* tsl2563
- replace deprecated flush_scheduled_work
Diffstat (limited to 'drivers/iio/adc')
-rw-r--r-- | drivers/iio/adc/Kconfig | 11 | ||||
-rw-r--r-- | drivers/iio/adc/Makefile | 1 | ||||
-rw-r--r-- | drivers/iio/adc/at91-sama5d2_adc.c | 102 | ||||
-rw-r--r-- | drivers/iio/adc/ina2xx-adc.c | 43 | ||||
-rw-r--r-- | drivers/iio/adc/lpc18xx_adc.c | 231 | ||||
-rw-r--r-- | drivers/iio/adc/rockchip_saradc.c | 19 |
6 files changed, 362 insertions, 45 deletions
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index af4aea7b20f9..5937030f0444 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig | |||
@@ -134,6 +134,7 @@ config AT91_ADC | |||
134 | config AT91_SAMA5D2_ADC | 134 | config AT91_SAMA5D2_ADC |
135 | tristate "Atmel AT91 SAMA5D2 ADC" | 135 | tristate "Atmel AT91 SAMA5D2 ADC" |
136 | depends on ARCH_AT91 || COMPILE_TEST | 136 | depends on ARCH_AT91 || COMPILE_TEST |
137 | depends on HAS_IOMEM | ||
137 | help | 138 | help |
138 | Say yes here to build support for Atmel SAMA5D2 ADC which is | 139 | Say yes here to build support for Atmel SAMA5D2 ADC which is |
139 | available on SAMA5D2 SoC family. | 140 | available on SAMA5D2 SoC family. |
@@ -241,6 +242,16 @@ config LP8788_ADC | |||
241 | To compile this driver as a module, choose M here: the module will be | 242 | To compile this driver as a module, choose M here: the module will be |
242 | called lp8788_adc. | 243 | called lp8788_adc. |
243 | 244 | ||
245 | config LPC18XX_ADC | ||
246 | tristate "NXP LPC18xx ADC driver" | ||
247 | depends on ARCH_LPC18XX || COMPILE_TEST | ||
248 | depends on OF && HAS_IOMEM | ||
249 | help | ||
250 | Say yes here to build support for NXP LPC18XX ADC. | ||
251 | |||
252 | To compile this driver as a module, choose M here: the module will be | ||
253 | called lpc18xx_adc. | ||
254 | |||
244 | config MAX1027 | 255 | config MAX1027 |
245 | tristate "Maxim max1027 ADC driver" | 256 | tristate "Maxim max1027 ADC driver" |
246 | depends on SPI | 257 | depends on SPI |
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 0cb79210a4b0..38638d46f972 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile | |||
@@ -25,6 +25,7 @@ obj-$(CONFIG_HI8435) += hi8435.o | |||
25 | obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o | 25 | obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o |
26 | obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o | 26 | obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o |
27 | obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o | 27 | obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o |
28 | obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o | ||
28 | obj-$(CONFIG_MAX1027) += max1027.o | 29 | obj-$(CONFIG_MAX1027) += max1027.o |
29 | obj-$(CONFIG_MAX1363) += max1363.o | 30 | obj-$(CONFIG_MAX1363) += max1363.o |
30 | obj-$(CONFIG_MCP320X) += mcp320x.o | 31 | obj-$(CONFIG_MCP320X) += mcp320x.o |
diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c index dbee13ad33a3..07adb1070fc2 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c | |||
@@ -66,8 +66,10 @@ | |||
66 | #define AT91_SAMA5D2_MR_PRESCAL(v) ((v) << AT91_SAMA5D2_MR_PRESCAL_OFFSET) | 66 | #define AT91_SAMA5D2_MR_PRESCAL(v) ((v) << AT91_SAMA5D2_MR_PRESCAL_OFFSET) |
67 | #define AT91_SAMA5D2_MR_PRESCAL_OFFSET 8 | 67 | #define AT91_SAMA5D2_MR_PRESCAL_OFFSET 8 |
68 | #define AT91_SAMA5D2_MR_PRESCAL_MAX 0xff | 68 | #define AT91_SAMA5D2_MR_PRESCAL_MAX 0xff |
69 | #define AT91_SAMA5D2_MR_PRESCAL_MASK GENMASK(15, 8) | ||
69 | /* Startup Time */ | 70 | /* Startup Time */ |
70 | #define AT91_SAMA5D2_MR_STARTUP(v) ((v) << 16) | 71 | #define AT91_SAMA5D2_MR_STARTUP(v) ((v) << 16) |
72 | #define AT91_SAMA5D2_MR_STARTUP_MASK GENMASK(19, 16) | ||
71 | /* Analog Change */ | 73 | /* Analog Change */ |
72 | #define AT91_SAMA5D2_MR_ANACH BIT(23) | 74 | #define AT91_SAMA5D2_MR_ANACH BIT(23) |
73 | /* Tracking Time */ | 75 | /* Tracking Time */ |
@@ -92,13 +94,13 @@ | |||
92 | /* Last Converted Data Register */ | 94 | /* Last Converted Data Register */ |
93 | #define AT91_SAMA5D2_LCDR 0x20 | 95 | #define AT91_SAMA5D2_LCDR 0x20 |
94 | /* Interrupt Enable Register */ | 96 | /* Interrupt Enable Register */ |
95 | #define AT91_SAMA5D2_IER 0x24 | 97 | #define AT91_SAMA5D2_IER 0x24 |
96 | /* Interrupt Disable Register */ | 98 | /* Interrupt Disable Register */ |
97 | #define AT91_SAMA5D2_IDR 0x28 | 99 | #define AT91_SAMA5D2_IDR 0x28 |
98 | /* Interrupt Mask Register */ | 100 | /* Interrupt Mask Register */ |
99 | #define AT91_SAMA5D2_IMR 0x2c | 101 | #define AT91_SAMA5D2_IMR 0x2c |
100 | /* Interrupt Status Register */ | 102 | /* Interrupt Status Register */ |
101 | #define AT91_SAMA5D2_ISR 0x30 | 103 | #define AT91_SAMA5D2_ISR 0x30 |
102 | /* Last Channel Trigger Mode Register */ | 104 | /* Last Channel Trigger Mode Register */ |
103 | #define AT91_SAMA5D2_LCTMR 0x34 | 105 | #define AT91_SAMA5D2_LCTMR 0x34 |
104 | /* Last Channel Compare Window Register */ | 106 | /* Last Channel Compare Window Register */ |
@@ -106,17 +108,20 @@ | |||
106 | /* Overrun Status Register */ | 108 | /* Overrun Status Register */ |
107 | #define AT91_SAMA5D2_OVER 0x3c | 109 | #define AT91_SAMA5D2_OVER 0x3c |
108 | /* Extended Mode Register */ | 110 | /* Extended Mode Register */ |
109 | #define AT91_SAMA5D2_EMR 0x40 | 111 | #define AT91_SAMA5D2_EMR 0x40 |
110 | /* Compare Window Register */ | 112 | /* Compare Window Register */ |
111 | #define AT91_SAMA5D2_CWR 0x44 | 113 | #define AT91_SAMA5D2_CWR 0x44 |
112 | /* Channel Gain Register */ | 114 | /* Channel Gain Register */ |
113 | #define AT91_SAMA5D2_CGR 0x48 | 115 | #define AT91_SAMA5D2_CGR 0x48 |
116 | |||
114 | /* Channel Offset Register */ | 117 | /* Channel Offset Register */ |
115 | #define AT91_SAMA5D2_COR 0x4c | 118 | #define AT91_SAMA5D2_COR 0x4c |
119 | #define AT91_SAMA5D2_COR_DIFF_OFFSET 16 | ||
120 | |||
116 | /* Channel Data Register 0 */ | 121 | /* Channel Data Register 0 */ |
117 | #define AT91_SAMA5D2_CDR0 0x50 | 122 | #define AT91_SAMA5D2_CDR0 0x50 |
118 | /* Analog Control Register */ | 123 | /* Analog Control Register */ |
119 | #define AT91_SAMA5D2_ACR 0x94 | 124 | #define AT91_SAMA5D2_ACR 0x94 |
120 | /* Touchscreen Mode Register */ | 125 | /* Touchscreen Mode Register */ |
121 | #define AT91_SAMA5D2_TSMR 0xb0 | 126 | #define AT91_SAMA5D2_TSMR 0xb0 |
122 | /* Touchscreen X Position Register */ | 127 | /* Touchscreen X Position Register */ |
@@ -130,7 +135,7 @@ | |||
130 | /* Correction Select Register */ | 135 | /* Correction Select Register */ |
131 | #define AT91_SAMA5D2_COSR 0xd0 | 136 | #define AT91_SAMA5D2_COSR 0xd0 |
132 | /* Correction Value Register */ | 137 | /* Correction Value Register */ |
133 | #define AT91_SAMA5D2_CVR 0xd4 | 138 | #define AT91_SAMA5D2_CVR 0xd4 |
134 | /* Channel Error Correction Register */ | 139 | /* Channel Error Correction Register */ |
135 | #define AT91_SAMA5D2_CECR 0xd8 | 140 | #define AT91_SAMA5D2_CECR 0xd8 |
136 | /* Write Protection Mode Register */ | 141 | /* Write Protection Mode Register */ |
@@ -140,7 +145,7 @@ | |||
140 | /* Version Register */ | 145 | /* Version Register */ |
141 | #define AT91_SAMA5D2_VERSION 0xfc | 146 | #define AT91_SAMA5D2_VERSION 0xfc |
142 | 147 | ||
143 | #define AT91_AT91_SAMA5D2_CHAN(num, addr) \ | 148 | #define AT91_SAMA5D2_CHAN_SINGLE(num, addr) \ |
144 | { \ | 149 | { \ |
145 | .type = IIO_VOLTAGE, \ | 150 | .type = IIO_VOLTAGE, \ |
146 | .channel = num, \ | 151 | .channel = num, \ |
@@ -156,6 +161,24 @@ | |||
156 | .indexed = 1, \ | 161 | .indexed = 1, \ |
157 | } | 162 | } |
158 | 163 | ||
164 | #define AT91_SAMA5D2_CHAN_DIFF(num, num2, addr) \ | ||
165 | { \ | ||
166 | .type = IIO_VOLTAGE, \ | ||
167 | .differential = 1, \ | ||
168 | .channel = num, \ | ||
169 | .channel2 = num2, \ | ||
170 | .address = addr, \ | ||
171 | .scan_type = { \ | ||
172 | .sign = 's', \ | ||
173 | .realbits = 12, \ | ||
174 | }, \ | ||
175 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
176 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ | ||
177 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\ | ||
178 | .datasheet_name = "CH"#num"-CH"#num2, \ | ||
179 | .indexed = 1, \ | ||
180 | } | ||
181 | |||
159 | #define at91_adc_readl(st, reg) readl_relaxed(st->base + reg) | 182 | #define at91_adc_readl(st, reg) readl_relaxed(st->base + reg) |
160 | #define at91_adc_writel(st, reg, val) writel_relaxed(val, st->base + reg) | 183 | #define at91_adc_writel(st, reg, val) writel_relaxed(val, st->base + reg) |
161 | 184 | ||
@@ -185,18 +208,24 @@ struct at91_adc_state { | |||
185 | }; | 208 | }; |
186 | 209 | ||
187 | static const struct iio_chan_spec at91_adc_channels[] = { | 210 | static const struct iio_chan_spec at91_adc_channels[] = { |
188 | AT91_AT91_SAMA5D2_CHAN(0, 0x50), | 211 | AT91_SAMA5D2_CHAN_SINGLE(0, 0x50), |
189 | AT91_AT91_SAMA5D2_CHAN(1, 0x54), | 212 | AT91_SAMA5D2_CHAN_SINGLE(1, 0x54), |
190 | AT91_AT91_SAMA5D2_CHAN(2, 0x58), | 213 | AT91_SAMA5D2_CHAN_SINGLE(2, 0x58), |
191 | AT91_AT91_SAMA5D2_CHAN(3, 0x5c), | 214 | AT91_SAMA5D2_CHAN_SINGLE(3, 0x5c), |
192 | AT91_AT91_SAMA5D2_CHAN(4, 0x60), | 215 | AT91_SAMA5D2_CHAN_SINGLE(4, 0x60), |
193 | AT91_AT91_SAMA5D2_CHAN(5, 0x64), | 216 | AT91_SAMA5D2_CHAN_SINGLE(5, 0x64), |
194 | AT91_AT91_SAMA5D2_CHAN(6, 0x68), | 217 | AT91_SAMA5D2_CHAN_SINGLE(6, 0x68), |
195 | AT91_AT91_SAMA5D2_CHAN(7, 0x6c), | 218 | AT91_SAMA5D2_CHAN_SINGLE(7, 0x6c), |
196 | AT91_AT91_SAMA5D2_CHAN(8, 0x70), | 219 | AT91_SAMA5D2_CHAN_SINGLE(8, 0x70), |
197 | AT91_AT91_SAMA5D2_CHAN(9, 0x74), | 220 | AT91_SAMA5D2_CHAN_SINGLE(9, 0x74), |
198 | AT91_AT91_SAMA5D2_CHAN(10, 0x78), | 221 | AT91_SAMA5D2_CHAN_SINGLE(10, 0x78), |
199 | AT91_AT91_SAMA5D2_CHAN(11, 0x7c), | 222 | AT91_SAMA5D2_CHAN_SINGLE(11, 0x7c), |
223 | AT91_SAMA5D2_CHAN_DIFF(0, 1, 0x50), | ||
224 | AT91_SAMA5D2_CHAN_DIFF(2, 3, 0x58), | ||
225 | AT91_SAMA5D2_CHAN_DIFF(4, 5, 0x60), | ||
226 | AT91_SAMA5D2_CHAN_DIFF(6, 7, 0x68), | ||
227 | AT91_SAMA5D2_CHAN_DIFF(8, 9, 0x70), | ||
228 | AT91_SAMA5D2_CHAN_DIFF(10, 11, 0x78), | ||
200 | }; | 229 | }; |
201 | 230 | ||
202 | static unsigned at91_adc_startup_time(unsigned startup_time_min, | 231 | static unsigned at91_adc_startup_time(unsigned startup_time_min, |
@@ -226,7 +255,7 @@ static unsigned at91_adc_startup_time(unsigned startup_time_min, | |||
226 | static void at91_adc_setup_samp_freq(struct at91_adc_state *st, unsigned freq) | 255 | static void at91_adc_setup_samp_freq(struct at91_adc_state *st, unsigned freq) |
227 | { | 256 | { |
228 | struct iio_dev *indio_dev = iio_priv_to_dev(st); | 257 | struct iio_dev *indio_dev = iio_priv_to_dev(st); |
229 | unsigned f_per, prescal, startup; | 258 | unsigned f_per, prescal, startup, mr; |
230 | 259 | ||
231 | f_per = clk_get_rate(st->per_clk); | 260 | f_per = clk_get_rate(st->per_clk); |
232 | prescal = (f_per / (2 * freq)) - 1; | 261 | prescal = (f_per / (2 * freq)) - 1; |
@@ -234,10 +263,11 @@ static void at91_adc_setup_samp_freq(struct at91_adc_state *st, unsigned freq) | |||
234 | startup = at91_adc_startup_time(st->soc_info.startup_time, | 263 | startup = at91_adc_startup_time(st->soc_info.startup_time, |
235 | freq / 1000); | 264 | freq / 1000); |
236 | 265 | ||
237 | at91_adc_writel(st, AT91_SAMA5D2_MR, | 266 | mr = at91_adc_readl(st, AT91_SAMA5D2_MR); |
238 | AT91_SAMA5D2_MR_TRANSFER(2) | 267 | mr &= ~(AT91_SAMA5D2_MR_STARTUP_MASK | AT91_SAMA5D2_MR_PRESCAL_MASK); |
239 | | AT91_SAMA5D2_MR_STARTUP(startup) | 268 | mr |= AT91_SAMA5D2_MR_STARTUP(startup); |
240 | | AT91_SAMA5D2_MR_PRESCAL(prescal)); | 269 | mr |= AT91_SAMA5D2_MR_PRESCAL(prescal); |
270 | at91_adc_writel(st, AT91_SAMA5D2_MR, mr); | ||
241 | 271 | ||
242 | dev_dbg(&indio_dev->dev, "freq: %u, startup: %u, prescal: %u\n", | 272 | dev_dbg(&indio_dev->dev, "freq: %u, startup: %u, prescal: %u\n", |
243 | freq, startup, prescal); | 273 | freq, startup, prescal); |
@@ -278,6 +308,7 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev, | |||
278 | int *val, int *val2, long mask) | 308 | int *val, int *val2, long mask) |
279 | { | 309 | { |
280 | struct at91_adc_state *st = iio_priv(indio_dev); | 310 | struct at91_adc_state *st = iio_priv(indio_dev); |
311 | u32 cor = 0; | ||
281 | int ret; | 312 | int ret; |
282 | 313 | ||
283 | switch (mask) { | 314 | switch (mask) { |
@@ -286,6 +317,11 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev, | |||
286 | 317 | ||
287 | st->chan = chan; | 318 | st->chan = chan; |
288 | 319 | ||
320 | if (chan->differential) | ||
321 | cor = (BIT(chan->channel) | BIT(chan->channel2)) << | ||
322 | AT91_SAMA5D2_COR_DIFF_OFFSET; | ||
323 | |||
324 | at91_adc_writel(st, AT91_SAMA5D2_COR, cor); | ||
289 | at91_adc_writel(st, AT91_SAMA5D2_CHER, BIT(chan->channel)); | 325 | at91_adc_writel(st, AT91_SAMA5D2_CHER, BIT(chan->channel)); |
290 | at91_adc_writel(st, AT91_SAMA5D2_IER, BIT(chan->channel)); | 326 | at91_adc_writel(st, AT91_SAMA5D2_IER, BIT(chan->channel)); |
291 | at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_START); | 327 | at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_START); |
@@ -298,6 +334,8 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev, | |||
298 | 334 | ||
299 | if (ret > 0) { | 335 | if (ret > 0) { |
300 | *val = st->conversion_value; | 336 | *val = st->conversion_value; |
337 | if (chan->scan_type.sign == 's') | ||
338 | *val = sign_extend32(*val, 11); | ||
301 | ret = IIO_VAL_INT; | 339 | ret = IIO_VAL_INT; |
302 | st->conversion_done = false; | 340 | st->conversion_done = false; |
303 | } | 341 | } |
@@ -310,6 +348,8 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev, | |||
310 | 348 | ||
311 | case IIO_CHAN_INFO_SCALE: | 349 | case IIO_CHAN_INFO_SCALE: |
312 | *val = st->vref_uv / 1000; | 350 | *val = st->vref_uv / 1000; |
351 | if (chan->differential) | ||
352 | *val *= 2; | ||
313 | *val2 = chan->scan_type.realbits; | 353 | *val2 = chan->scan_type.realbits; |
314 | return IIO_VAL_FRACTIONAL_LOG2; | 354 | return IIO_VAL_FRACTIONAL_LOG2; |
315 | 355 | ||
@@ -444,6 +484,12 @@ static int at91_adc_probe(struct platform_device *pdev) | |||
444 | 484 | ||
445 | at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST); | 485 | at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST); |
446 | at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff); | 486 | at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff); |
487 | /* | ||
488 | * Transfer field must be set to 2 according to the datasheet and | ||
489 | * allows different analog settings for each channel. | ||
490 | */ | ||
491 | at91_adc_writel(st, AT91_SAMA5D2_MR, | ||
492 | AT91_SAMA5D2_MR_TRANSFER(2) | AT91_SAMA5D2_MR_ANACH); | ||
447 | 493 | ||
448 | at91_adc_setup_samp_freq(st, st->soc_info.min_sample_rate); | 494 | at91_adc_setup_samp_freq(st, st->soc_info.min_sample_rate); |
449 | 495 | ||
diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c index 65909d5858b1..502f2fbe8aef 100644 --- a/drivers/iio/adc/ina2xx-adc.c +++ b/drivers/iio/adc/ina2xx-adc.c | |||
@@ -185,9 +185,9 @@ static int ina2xx_read_raw(struct iio_dev *indio_dev, | |||
185 | case IIO_CHAN_INFO_SCALE: | 185 | case IIO_CHAN_INFO_SCALE: |
186 | switch (chan->address) { | 186 | switch (chan->address) { |
187 | case INA2XX_SHUNT_VOLTAGE: | 187 | case INA2XX_SHUNT_VOLTAGE: |
188 | /* processed (mV) = raw*1000/shunt_div */ | 188 | /* processed (mV) = raw/shunt_div */ |
189 | *val2 = chip->config->shunt_div; | 189 | *val2 = chip->config->shunt_div; |
190 | *val = 1000; | 190 | *val = 1; |
191 | return IIO_VAL_FRACTIONAL; | 191 | return IIO_VAL_FRACTIONAL; |
192 | 192 | ||
193 | case INA2XX_BUS_VOLTAGE: | 193 | case INA2XX_BUS_VOLTAGE: |
@@ -350,6 +350,23 @@ static ssize_t ina2xx_allow_async_readout_store(struct device *dev, | |||
350 | return len; | 350 | return len; |
351 | } | 351 | } |
352 | 352 | ||
353 | /* | ||
354 | * Set current LSB to 1mA, shunt is in uOhms | ||
355 | * (equation 13 in datasheet). We hardcode a Current_LSB | ||
356 | * of 1.0 x10-6. The only remaining parameter is RShunt. | ||
357 | * There is no need to expose the CALIBRATION register | ||
358 | * to the user for now. But we need to reset this register | ||
359 | * if the user updates RShunt after driver init, e.g upon | ||
360 | * reading an EEPROM/Probe-type value. | ||
361 | */ | ||
362 | static int ina2xx_set_calibration(struct ina2xx_chip_info *chip) | ||
363 | { | ||
364 | u16 regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor, | ||
365 | chip->shunt_resistor); | ||
366 | |||
367 | return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval); | ||
368 | } | ||
369 | |||
353 | static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val) | 370 | static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val) |
354 | { | 371 | { |
355 | if (val <= 0 || val > chip->config->calibration_factor) | 372 | if (val <= 0 || val > chip->config->calibration_factor) |
@@ -385,6 +402,11 @@ static ssize_t ina2xx_shunt_resistor_store(struct device *dev, | |||
385 | if (ret) | 402 | if (ret) |
386 | return ret; | 403 | return ret; |
387 | 404 | ||
405 | /* Update the Calibration register */ | ||
406 | ret = ina2xx_set_calibration(chip); | ||
407 | if (ret) | ||
408 | return ret; | ||
409 | |||
388 | return len; | 410 | return len; |
389 | } | 411 | } |
390 | 412 | ||
@@ -602,24 +624,11 @@ static const struct iio_info ina2xx_info = { | |||
602 | /* Initialize the configuration and calibration registers. */ | 624 | /* Initialize the configuration and calibration registers. */ |
603 | static int ina2xx_init(struct ina2xx_chip_info *chip, unsigned int config) | 625 | static int ina2xx_init(struct ina2xx_chip_info *chip, unsigned int config) |
604 | { | 626 | { |
605 | u16 regval; | 627 | int ret = regmap_write(chip->regmap, INA2XX_CONFIG, config); |
606 | int ret; | ||
607 | |||
608 | ret = regmap_write(chip->regmap, INA2XX_CONFIG, config); | ||
609 | if (ret) | 628 | if (ret) |
610 | return ret; | 629 | return ret; |
611 | 630 | ||
612 | /* | 631 | return ina2xx_set_calibration(chip); |
613 | * Set current LSB to 1mA, shunt is in uOhms | ||
614 | * (equation 13 in datasheet). We hardcode a Current_LSB | ||
615 | * of 1.0 x10-6. The only remaining parameter is RShunt. | ||
616 | * There is no need to expose the CALIBRATION register | ||
617 | * to the user for now. | ||
618 | */ | ||
619 | regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor, | ||
620 | chip->shunt_resistor); | ||
621 | |||
622 | return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval); | ||
623 | } | 632 | } |
624 | 633 | ||
625 | static int ina2xx_probe(struct i2c_client *client, | 634 | static int ina2xx_probe(struct i2c_client *client, |
diff --git a/drivers/iio/adc/lpc18xx_adc.c b/drivers/iio/adc/lpc18xx_adc.c new file mode 100644 index 000000000000..3ef18f4b27f0 --- /dev/null +++ b/drivers/iio/adc/lpc18xx_adc.c | |||
@@ -0,0 +1,231 @@ | |||
1 | /* | ||
2 | * IIO ADC driver for NXP LPC18xx ADC | ||
3 | * | ||
4 | * Copyright (C) 2016 Joachim Eastwood <manabian@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * UNSUPPORTED hardware features: | ||
11 | * - Hardware triggers | ||
12 | * - Burst mode | ||
13 | * - Interrupts | ||
14 | * - DMA | ||
15 | */ | ||
16 | |||
17 | #include <linux/clk.h> | ||
18 | #include <linux/err.h> | ||
19 | #include <linux/iio/iio.h> | ||
20 | #include <linux/iio/driver.h> | ||
21 | #include <linux/io.h> | ||
22 | #include <linux/iopoll.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/mutex.h> | ||
25 | #include <linux/of.h> | ||
26 | #include <linux/of_device.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/regulator/consumer.h> | ||
29 | |||
30 | /* LPC18XX ADC registers and bits */ | ||
31 | #define LPC18XX_ADC_CR 0x000 | ||
32 | #define LPC18XX_ADC_CR_CLKDIV_SHIFT 8 | ||
33 | #define LPC18XX_ADC_CR_PDN BIT(21) | ||
34 | #define LPC18XX_ADC_CR_START_NOW (0x1 << 24) | ||
35 | #define LPC18XX_ADC_GDR 0x004 | ||
36 | |||
37 | /* Data register bits */ | ||
38 | #define LPC18XX_ADC_SAMPLE_SHIFT 6 | ||
39 | #define LPC18XX_ADC_SAMPLE_MASK 0x3ff | ||
40 | #define LPC18XX_ADC_CONV_DONE BIT(31) | ||
41 | |||
42 | /* Clock should be 4.5 MHz or less */ | ||
43 | #define LPC18XX_ADC_CLK_TARGET 4500000 | ||
44 | |||
45 | struct lpc18xx_adc { | ||
46 | struct regulator *vref; | ||
47 | void __iomem *base; | ||
48 | struct device *dev; | ||
49 | struct mutex lock; | ||
50 | struct clk *clk; | ||
51 | u32 cr_reg; | ||
52 | }; | ||
53 | |||
54 | #define LPC18XX_ADC_CHAN(_idx) { \ | ||
55 | .type = IIO_VOLTAGE, \ | ||
56 | .indexed = 1, \ | ||
57 | .channel = _idx, \ | ||
58 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
59 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ | ||
60 | } | ||
61 | |||
62 | static const struct iio_chan_spec lpc18xx_adc_iio_channels[] = { | ||
63 | LPC18XX_ADC_CHAN(0), | ||
64 | LPC18XX_ADC_CHAN(1), | ||
65 | LPC18XX_ADC_CHAN(2), | ||
66 | LPC18XX_ADC_CHAN(3), | ||
67 | LPC18XX_ADC_CHAN(4), | ||
68 | LPC18XX_ADC_CHAN(5), | ||
69 | LPC18XX_ADC_CHAN(6), | ||
70 | LPC18XX_ADC_CHAN(7), | ||
71 | }; | ||
72 | |||
73 | static int lpc18xx_adc_read_chan(struct lpc18xx_adc *adc, unsigned int ch) | ||
74 | { | ||
75 | int ret; | ||
76 | u32 reg; | ||
77 | |||
78 | reg = adc->cr_reg | BIT(ch) | LPC18XX_ADC_CR_START_NOW; | ||
79 | writel(reg, adc->base + LPC18XX_ADC_CR); | ||
80 | |||
81 | ret = readl_poll_timeout(adc->base + LPC18XX_ADC_GDR, reg, | ||
82 | reg & LPC18XX_ADC_CONV_DONE, 3, 9); | ||
83 | if (ret) { | ||
84 | dev_warn(adc->dev, "adc read timed out\n"); | ||
85 | return ret; | ||
86 | } | ||
87 | |||
88 | return (reg >> LPC18XX_ADC_SAMPLE_SHIFT) & LPC18XX_ADC_SAMPLE_MASK; | ||
89 | } | ||
90 | |||
91 | static int lpc18xx_adc_read_raw(struct iio_dev *indio_dev, | ||
92 | struct iio_chan_spec const *chan, | ||
93 | int *val, int *val2, long mask) | ||
94 | { | ||
95 | struct lpc18xx_adc *adc = iio_priv(indio_dev); | ||
96 | |||
97 | switch (mask) { | ||
98 | case IIO_CHAN_INFO_RAW: | ||
99 | mutex_lock(&adc->lock); | ||
100 | *val = lpc18xx_adc_read_chan(adc, chan->channel); | ||
101 | mutex_unlock(&adc->lock); | ||
102 | if (*val < 0) | ||
103 | return *val; | ||
104 | |||
105 | return IIO_VAL_INT; | ||
106 | |||
107 | case IIO_CHAN_INFO_SCALE: | ||
108 | *val = regulator_get_voltage(adc->vref) / 1000; | ||
109 | *val2 = 10; | ||
110 | |||
111 | return IIO_VAL_FRACTIONAL_LOG2; | ||
112 | } | ||
113 | |||
114 | return -EINVAL; | ||
115 | } | ||
116 | |||
117 | static const struct iio_info lpc18xx_adc_info = { | ||
118 | .read_raw = lpc18xx_adc_read_raw, | ||
119 | .driver_module = THIS_MODULE, | ||
120 | }; | ||
121 | |||
122 | static int lpc18xx_adc_probe(struct platform_device *pdev) | ||
123 | { | ||
124 | struct iio_dev *indio_dev; | ||
125 | struct lpc18xx_adc *adc; | ||
126 | struct resource *res; | ||
127 | unsigned int clkdiv; | ||
128 | unsigned long rate; | ||
129 | int ret; | ||
130 | |||
131 | indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc)); | ||
132 | if (!indio_dev) | ||
133 | return -ENOMEM; | ||
134 | |||
135 | platform_set_drvdata(pdev, indio_dev); | ||
136 | adc = iio_priv(indio_dev); | ||
137 | adc->dev = &pdev->dev; | ||
138 | mutex_init(&adc->lock); | ||
139 | |||
140 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
141 | adc->base = devm_ioremap_resource(&pdev->dev, res); | ||
142 | if (IS_ERR(adc->base)) | ||
143 | return PTR_ERR(adc->base); | ||
144 | |||
145 | adc->clk = devm_clk_get(&pdev->dev, NULL); | ||
146 | if (IS_ERR(adc->clk)) { | ||
147 | dev_err(&pdev->dev, "error getting clock\n"); | ||
148 | return PTR_ERR(adc->clk); | ||
149 | } | ||
150 | |||
151 | rate = clk_get_rate(adc->clk); | ||
152 | clkdiv = DIV_ROUND_UP(rate, LPC18XX_ADC_CLK_TARGET); | ||
153 | |||
154 | adc->vref = devm_regulator_get(&pdev->dev, "vref"); | ||
155 | if (IS_ERR(adc->vref)) { | ||
156 | dev_err(&pdev->dev, "error getting regulator\n"); | ||
157 | return PTR_ERR(adc->vref); | ||
158 | } | ||
159 | |||
160 | indio_dev->name = dev_name(&pdev->dev); | ||
161 | indio_dev->dev.parent = &pdev->dev; | ||
162 | indio_dev->info = &lpc18xx_adc_info; | ||
163 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
164 | indio_dev->channels = lpc18xx_adc_iio_channels; | ||
165 | indio_dev->num_channels = ARRAY_SIZE(lpc18xx_adc_iio_channels); | ||
166 | |||
167 | ret = regulator_enable(adc->vref); | ||
168 | if (ret) { | ||
169 | dev_err(&pdev->dev, "unable to enable regulator\n"); | ||
170 | return ret; | ||
171 | } | ||
172 | |||
173 | ret = clk_prepare_enable(adc->clk); | ||
174 | if (ret) { | ||
175 | dev_err(&pdev->dev, "unable to enable clock\n"); | ||
176 | goto dis_reg; | ||
177 | } | ||
178 | |||
179 | adc->cr_reg = (clkdiv << LPC18XX_ADC_CR_CLKDIV_SHIFT) | | ||
180 | LPC18XX_ADC_CR_PDN; | ||
181 | writel(adc->cr_reg, adc->base + LPC18XX_ADC_CR); | ||
182 | |||
183 | ret = iio_device_register(indio_dev); | ||
184 | if (ret) { | ||
185 | dev_err(&pdev->dev, "unable to register device\n"); | ||
186 | goto dis_clk; | ||
187 | } | ||
188 | |||
189 | return 0; | ||
190 | |||
191 | dis_clk: | ||
192 | writel(0, adc->base + LPC18XX_ADC_CR); | ||
193 | clk_disable_unprepare(adc->clk); | ||
194 | dis_reg: | ||
195 | regulator_disable(adc->vref); | ||
196 | return ret; | ||
197 | } | ||
198 | |||
199 | static int lpc18xx_adc_remove(struct platform_device *pdev) | ||
200 | { | ||
201 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); | ||
202 | struct lpc18xx_adc *adc = iio_priv(indio_dev); | ||
203 | |||
204 | iio_device_unregister(indio_dev); | ||
205 | |||
206 | writel(0, adc->base + LPC18XX_ADC_CR); | ||
207 | clk_disable_unprepare(adc->clk); | ||
208 | regulator_disable(adc->vref); | ||
209 | |||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | static const struct of_device_id lpc18xx_adc_match[] = { | ||
214 | { .compatible = "nxp,lpc1850-adc" }, | ||
215 | { /* sentinel */ } | ||
216 | }; | ||
217 | MODULE_DEVICE_TABLE(of, lpc18xx_adc_match); | ||
218 | |||
219 | static struct platform_driver lpc18xx_adc_driver = { | ||
220 | .probe = lpc18xx_adc_probe, | ||
221 | .remove = lpc18xx_adc_remove, | ||
222 | .driver = { | ||
223 | .name = "lpc18xx-adc", | ||
224 | .of_match_table = lpc18xx_adc_match, | ||
225 | }, | ||
226 | }; | ||
227 | module_platform_driver(lpc18xx_adc_driver); | ||
228 | |||
229 | MODULE_DESCRIPTION("LPC18xx ADC driver"); | ||
230 | MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>"); | ||
231 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/iio/adc/rockchip_saradc.c b/drivers/iio/adc/rockchip_saradc.c index 9c311c1e1ac7..f9ad6c2d6821 100644 --- a/drivers/iio/adc/rockchip_saradc.c +++ b/drivers/iio/adc/rockchip_saradc.c | |||
@@ -159,6 +159,22 @@ static const struct rockchip_saradc_data rk3066_tsadc_data = { | |||
159 | .clk_rate = 50000, | 159 | .clk_rate = 50000, |
160 | }; | 160 | }; |
161 | 161 | ||
162 | static const struct iio_chan_spec rockchip_rk3399_saradc_iio_channels[] = { | ||
163 | ADC_CHANNEL(0, "adc0"), | ||
164 | ADC_CHANNEL(1, "adc1"), | ||
165 | ADC_CHANNEL(2, "adc2"), | ||
166 | ADC_CHANNEL(3, "adc3"), | ||
167 | ADC_CHANNEL(4, "adc4"), | ||
168 | ADC_CHANNEL(5, "adc5"), | ||
169 | }; | ||
170 | |||
171 | static const struct rockchip_saradc_data rk3399_saradc_data = { | ||
172 | .num_bits = 10, | ||
173 | .channels = rockchip_rk3399_saradc_iio_channels, | ||
174 | .num_channels = ARRAY_SIZE(rockchip_rk3399_saradc_iio_channels), | ||
175 | .clk_rate = 1000000, | ||
176 | }; | ||
177 | |||
162 | static const struct of_device_id rockchip_saradc_match[] = { | 178 | static const struct of_device_id rockchip_saradc_match[] = { |
163 | { | 179 | { |
164 | .compatible = "rockchip,saradc", | 180 | .compatible = "rockchip,saradc", |
@@ -166,6 +182,9 @@ static const struct of_device_id rockchip_saradc_match[] = { | |||
166 | }, { | 182 | }, { |
167 | .compatible = "rockchip,rk3066-tsadc", | 183 | .compatible = "rockchip,rk3066-tsadc", |
168 | .data = &rk3066_tsadc_data, | 184 | .data = &rk3066_tsadc_data, |
185 | }, { | ||
186 | .compatible = "rockchip,rk3399-saradc", | ||
187 | .data = &rk3399_saradc_data, | ||
169 | }, | 188 | }, |
170 | {}, | 189 | {}, |
171 | }; | 190 | }; |