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

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

Jonathan writes:

First round of IIO new driver, functionality and cleanups for the 3.16 cycle.

New device support
* AS3935 Lightning Sensor
* MCP3426/7/8 support added to the existing MCP3422 ADC driver
* AK8963 support in the AK8975 driver
* MPU6500 support in the MPU6050 driver (the functionality that is different
is mostly not supported yet in either part).

Staging Graduations
* AD799x ADC

New functionality
* ACPI enumeration for the ak8975 driver

Cleanup / tweaks
* Use snprintf as a matter of good practice in a few additional places.
* Document *_mean_raw attributes. These have been there a while, but were
undocumented.
* Add an in kernel interface to get the mean values.
* Bug in the length of the event info mask that by coincidence wasn't yet
actually causing any problems.
* itg3000 drop an unreachable return statement.
* spear_adc cleanups (heading for a staging graduation but a few more
issues showed up in the review of these patches).
* Exynos ADC dependencies changed so it is only built when Exynos is present
or COMPILE_TEST and OF are set.
* tsl2583 cleanups.
* Some cut and paste typos in the comments of various drivers still in staging.
* Couple of minor improvements to the ST sensor drivers.

+1046 -471
+8
Documentation/ABI/testing/sysfs-bus-iio
··· 210 210 Description: 211 211 Scaled humidity measurement in milli percent. 212 212 213 + What: /sys/bus/iio/devices/iio:deviceX/in_X_mean_raw 214 + KernelVersion: 3.5 215 + Contact: linux-iio@vger.kernel.org 216 + Description: 217 + Averaged raw measurement from channel X. The number of values 218 + used for averaging is device specific. The converting rules for 219 + normal raw values also applies to the averaged raw values. 220 + 213 221 What: /sys/bus/iio/devices/iio:deviceX/in_accel_offset 214 222 What: /sys/bus/iio/devices/iio:deviceX/in_accel_x_offset 215 223 What: /sys/bus/iio/devices/iio:deviceX/in_accel_y_offset
+16
Documentation/ABI/testing/sysfs-bus-iio-proximity-as3935
··· 1 + What /sys/bus/iio/devices/iio:deviceX/in_proximity_raw 2 + Date: March 2014 3 + KernelVersion: 3.15 4 + Contact: Matt Ranostay <mranostay@gmail.com> 5 + Description: 6 + Get the current distance in meters of storm (1km steps) 7 + 1000-40000 = distance in meters 8 + 9 + What /sys/bus/iio/devices/iio:deviceX/sensor_sensitivity 10 + Date: March 2014 11 + KernelVersion: 3.15 12 + Contact: Matt Ranostay <mranostay@gmail.com> 13 + Description: 14 + Show or set the gain boost of the amp, from 0-31 range. 15 + 18 = indoors (default) 16 + 14 = outdoors
+28
Documentation/devicetree/bindings/iio/proximity/as3935.txt
··· 1 + Austrian Microsystems AS3935 Franklin lightning sensor device driver 2 + 3 + Required properties: 4 + - compatible: must be "ams,as3935" 5 + - reg: SPI chip select number for the device 6 + - spi-cpha: SPI Mode 1. Refer to spi/spi-bus.txt for generic SPI 7 + slave node bindings. 8 + - interrupt-parent : should be the phandle for the interrupt controller 9 + - interrupts : the sole interrupt generated by the device 10 + 11 + Refer to interrupt-controller/interrupts.txt for generic 12 + interrupt client node bindings. 13 + 14 + Optional properties: 15 + - ams,tuning-capacitor-pf: Calibration tuning capacitor stepping 16 + value 0 - 120pF. This will require using the calibration data from 17 + the manufacturer. 18 + 19 + Example: 20 + 21 + as3935@0 { 22 + compatible = "ams,as3935"; 23 + reg = <0>; 24 + spi-cpha; 25 + interrupt-parent = <&gpio1>; 26 + interrupts = <16 1>; 27 + ams,tuning-capacitor-pf = <80>; 28 + };
+1
Documentation/devicetree/bindings/vendor-prefixes.txt
··· 13 13 altr Altera Corp. 14 14 amcc Applied Micro Circuits Corporation (APM, formally AMCC) 15 15 amd Advanced Micro Devices (AMD), Inc. 16 + ams AMS AG 16 17 amstaos AMS-Taos Inc. 17 18 apm Applied Micro Circuits Corporation (APM) 18 19 arm ARM Ltd.
+1
drivers/iio/Kconfig
··· 74 74 source "drivers/iio/trigger/Kconfig" 75 75 endif #IIO_TRIGGER 76 76 source "drivers/iio/pressure/Kconfig" 77 + source "drivers/iio/proximity/Kconfig" 77 78 source "drivers/iio/temperature/Kconfig" 78 79 79 80 endif # IIO
+1
drivers/iio/Makefile
··· 24 24 obj-y += magnetometer/ 25 25 obj-y += orientation/ 26 26 obj-y += pressure/ 27 + obj-y += proximity/ 27 28 obj-y += temperature/ 28 29 obj-y += trigger/
+7
drivers/iio/accel/st_accel_core.c
··· 459 459 indio_dev->modes = INDIO_DIRECT_MODE; 460 460 indio_dev->info = &accel_info; 461 461 462 + st_sensors_power_enable(indio_dev); 463 + 462 464 err = st_sensors_check_device_support(indio_dev, 463 465 ARRAY_SIZE(st_accel_sensors), st_accel_sensors); 464 466 if (err < 0) ··· 498 496 if (err) 499 497 goto st_accel_device_register_error; 500 498 499 + dev_info(&indio_dev->dev, "registered accelerometer %s\n", 500 + indio_dev->name); 501 + 501 502 return 0; 502 503 503 504 st_accel_device_register_error: ··· 516 511 void st_accel_common_remove(struct iio_dev *indio_dev) 517 512 { 518 513 struct st_sensor_data *adata = iio_priv(indio_dev); 514 + 515 + st_sensors_power_disable(indio_dev); 519 516 520 517 iio_device_unregister(indio_dev); 521 518 if (adata->get_irq_data_ready(indio_dev) > 0)
+16 -4
drivers/iio/adc/Kconfig
··· 96 96 To compile this driver as a module, choose M here: the 97 97 module will be called ad7923. 98 98 99 + config AD799X 100 + tristate "Analog Devices AD799x ADC driver" 101 + depends on I2C 102 + select IIO_BUFFER 103 + select IIO_TRIGGERED_BUFFER 104 + help 105 + Say yes here to build support for Analog Devices: 106 + ad7991, ad7995, ad7999, ad7992, ad7993, ad7994, ad7997, ad7998 107 + i2c analog to digital converters (ADC). Provides direct access 108 + via sysfs. 109 + 99 110 config AT91_ADC 100 111 tristate "Atmel AT91 ADC" 101 112 depends on ARCH_AT91 ··· 118 107 119 108 config EXYNOS_ADC 120 109 bool "Exynos ADC driver support" 121 - depends on OF 110 + depends on ARCH_EXYNOS || (OF && COMPILE_TEST) 122 111 help 123 112 Core support for the ADC block found in the Samsung EXYNOS series 124 113 of SoCs for drivers such as the touchscreen and hwmon to use to share ··· 157 146 called mcp320x. 158 147 159 148 config MCP3422 160 - tristate "Microchip Technology MCP3422/3/4 driver" 149 + tristate "Microchip Technology MCP3422/3/4/6/7/8 driver" 161 150 depends on I2C 162 151 help 163 - Say yes here to build support for Microchip Technology's MCP3422, 164 - MCP3423 or MCP3424 analog to digital converters. 152 + Say yes here to build support for Microchip Technology's 153 + MCP3422, MCP3423, MCP3424, MCP3426, MCP3427 or MCP3428 154 + analog to digital converters. 165 155 166 156 This driver can also be built as a module. If so, the module will be 167 157 called mcp3422.
+1
drivers/iio/adc/Makefile
··· 11 11 obj-$(CONFIG_AD7791) += ad7791.o 12 12 obj-$(CONFIG_AD7793) += ad7793.o 13 13 obj-$(CONFIG_AD7887) += ad7887.o 14 + obj-$(CONFIG_AD799X) += ad799x.o 14 15 obj-$(CONFIG_AT91_ADC) += at91_adc.o 15 16 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o 16 17 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
+28 -5
drivers/iio/adc/mcp3422.c
··· 1 1 /* 2 - * mcp3422.c - driver for the Microchip mcp3422/3/4 chip family 2 + * mcp3422.c - driver for the Microchip mcp3422/3/4/6/7/8 chip family 3 3 * 4 4 * Copyright (C) 2013, Angelo Compagnucci 5 5 * Author: Angelo Compagnucci <angelo.compagnucci@gmail.com> 6 6 * 7 7 * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/22088b.pdf 8 + * http://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdf 8 9 * 9 10 * This driver exports the value of analog input voltage to sysfs, the 10 11 * voltage unit is nV. ··· 97 96 /* Client data (each client gets its own) */ 98 97 struct mcp3422 { 99 98 struct i2c_client *i2c; 99 + u8 id; 100 100 u8 config; 101 101 u8 pga[4]; 102 102 struct mutex lock; ··· 240 238 temp = MCP3422_SRATE_15; 241 239 break; 242 240 case 3: 241 + if (adc->id > 4) 242 + return -EINVAL; 243 243 temp = MCP3422_SRATE_3; 244 244 break; 245 245 default: ··· 275 271 } 276 272 } 277 273 274 + static ssize_t mcp3422_show_samp_freqs(struct device *dev, 275 + struct device_attribute *attr, char *buf) 276 + { 277 + struct mcp3422 *adc = iio_priv(dev_to_iio_dev(dev)); 278 + 279 + if (adc->id > 4) 280 + return sprintf(buf, "240 60 15\n"); 281 + 282 + return sprintf(buf, "240 60 15 3\n"); 283 + } 284 + 278 285 static ssize_t mcp3422_show_scales(struct device *dev, 279 286 struct device_attribute *attr, char *buf) 280 287 { ··· 299 284 mcp3422_scales[sample_rate][3]); 300 285 } 301 286 302 - static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("240 60 15 3"); 287 + static IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, 288 + mcp3422_show_samp_freqs, NULL, 0); 303 289 static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO, 304 290 mcp3422_show_scales, NULL, 0); 305 291 306 292 static struct attribute *mcp3422_attributes[] = { 307 - &iio_const_attr_sampling_frequency_available.dev_attr.attr, 293 + &iio_dev_attr_sampling_frequency_available.dev_attr.attr, 308 294 &iio_dev_attr_in_voltage_scale_available.dev_attr.attr, 309 295 NULL, 310 296 }; ··· 351 335 352 336 adc = iio_priv(indio_dev); 353 337 adc->i2c = client; 338 + adc->id = (u8)(id->driver_data); 354 339 355 340 mutex_init(&adc->lock); 356 341 ··· 360 343 indio_dev->modes = INDIO_DIRECT_MODE; 361 344 indio_dev->info = &mcp3422_info; 362 345 363 - switch ((unsigned int)(id->driver_data)) { 346 + switch (adc->id) { 364 347 case 2: 365 348 case 3: 349 + case 6: 350 + case 7: 366 351 indio_dev->channels = mcp3422_channels; 367 352 indio_dev->num_channels = ARRAY_SIZE(mcp3422_channels); 368 353 break; 369 354 case 4: 355 + case 8: 370 356 indio_dev->channels = mcp3424_channels; 371 357 indio_dev->num_channels = ARRAY_SIZE(mcp3424_channels); 372 358 break; ··· 395 375 { "mcp3422", 2 }, 396 376 { "mcp3423", 3 }, 397 377 { "mcp3424", 4 }, 378 + { "mcp3426", 6 }, 379 + { "mcp3427", 7 }, 380 + { "mcp3428", 8 }, 398 381 { } 399 382 }; 400 383 MODULE_DEVICE_TABLE(i2c, mcp3422_id); ··· 422 399 module_i2c_driver(mcp3422_driver); 423 400 424 401 MODULE_AUTHOR("Angelo Compagnucci <angelo.compagnucci@gmail.com>"); 425 - MODULE_DESCRIPTION("Microchip mcp3422/3/4 driver"); 402 + MODULE_DESCRIPTION("Microchip mcp3422/3/4/6/7/8 driver"); 426 403 MODULE_LICENSE("GPL v2");
+37
drivers/iio/common/st_sensors/st_sensors_core.c
··· 13 13 #include <linux/slab.h> 14 14 #include <linux/delay.h> 15 15 #include <linux/iio/iio.h> 16 + #include <linux/regulator/consumer.h> 16 17 #include <asm/unaligned.h> 17 18 18 19 #include <linux/iio/common/st_sensors.h> ··· 198 197 sdata->sensor->enable_axis.mask, axis_enable); 199 198 } 200 199 EXPORT_SYMBOL(st_sensors_set_axis_enable); 200 + 201 + void st_sensors_power_enable(struct iio_dev *indio_dev) 202 + { 203 + struct st_sensor_data *pdata = iio_priv(indio_dev); 204 + int err; 205 + 206 + /* Regulators not mandatory, but if requested we should enable them. */ 207 + pdata->vdd = devm_regulator_get_optional(indio_dev->dev.parent, "vdd"); 208 + if (!IS_ERR(pdata->vdd)) { 209 + err = regulator_enable(pdata->vdd); 210 + if (err != 0) 211 + dev_warn(&indio_dev->dev, 212 + "Failed to enable specified Vdd supply\n"); 213 + } 214 + 215 + pdata->vdd_io = devm_regulator_get_optional(indio_dev->dev.parent, "vddio"); 216 + if (!IS_ERR(pdata->vdd_io)) { 217 + err = regulator_enable(pdata->vdd_io); 218 + if (err != 0) 219 + dev_warn(&indio_dev->dev, 220 + "Failed to enable specified Vdd_IO supply\n"); 221 + } 222 + } 223 + EXPORT_SYMBOL(st_sensors_power_enable); 224 + 225 + void st_sensors_power_disable(struct iio_dev *indio_dev) 226 + { 227 + struct st_sensor_data *pdata = iio_priv(indio_dev); 228 + 229 + if (!IS_ERR(pdata->vdd)) 230 + regulator_disable(pdata->vdd); 231 + 232 + if (!IS_ERR(pdata->vdd_io)) 233 + regulator_disable(pdata->vdd_io); 234 + } 235 + EXPORT_SYMBOL(st_sensors_power_disable); 201 236 202 237 static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev, 203 238 struct st_sensors_platform_data *pdata)
-2
drivers/iio/gyro/itg3200_core.c
··· 110 110 default: 111 111 return -EINVAL; 112 112 } 113 - 114 - return ret; 115 113 } 116 114 117 115 static ssize_t itg3200_read_frequency(struct device *dev,
+7
drivers/iio/gyro/st_gyro_core.c
··· 311 311 indio_dev->modes = INDIO_DIRECT_MODE; 312 312 indio_dev->info = &gyro_info; 313 313 314 + st_sensors_power_enable(indio_dev); 315 + 314 316 err = st_sensors_check_device_support(indio_dev, 315 317 ARRAY_SIZE(st_gyro_sensors), st_gyro_sensors); 316 318 if (err < 0) ··· 346 344 if (err) 347 345 goto st_gyro_device_register_error; 348 346 347 + dev_info(&indio_dev->dev, "registered gyroscope %s\n", 348 + indio_dev->name); 349 + 349 350 return 0; 350 351 351 352 st_gyro_device_register_error: ··· 364 359 void st_gyro_common_remove(struct iio_dev *indio_dev) 365 360 { 366 361 struct st_sensor_data *gdata = iio_priv(indio_dev); 362 + 363 + st_sensors_power_disable(indio_dev); 367 364 368 365 iio_device_unregister(indio_dev); 369 366 if (gdata->get_irq_data_ready(indio_dev) > 0)
+2
drivers/iio/imu/inv_mpu6050/Kconfig
··· 9 9 select IIO_TRIGGERED_BUFFER 10 10 help 11 11 This driver supports the Invensense MPU6050 devices. 12 + This driver can also support MPU6500 in MPU6050 compatibility mode 13 + and also in MPU6500 mode with some limitations. 12 14 It is a gyroscope/accelerometer combo device. 13 15 This driver can be built as a module. The module will be called 14 16 inv-mpu6050.
+1
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 764 764 */ 765 765 static const struct i2c_device_id inv_mpu_id[] = { 766 766 {"mpu6050", INV_MPU6050}, 767 + {"mpu6500", INV_MPU6500}, 767 768 {} 768 769 }; 769 770
+1
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
··· 59 59 /*device enum */ 60 60 enum inv_devices { 61 61 INV_MPU6050, 62 + INV_MPU6500, 62 63 INV_NUM_PARTS 63 64 }; 64 65
+4 -2
drivers/iio/industrialio-core.c
··· 340 340 else if (i >= e->num_items) 341 341 return -EINVAL; 342 342 343 - return sprintf(buf, "%s\n", e->items[i]); 343 + return snprintf(buf, PAGE_SIZE, "%s\n", e->items[i]); 344 344 } 345 345 EXPORT_SYMBOL_GPL(iio_enum_read); 346 346 ··· 716 716 int i, ret, attrcount = 0; 717 717 718 718 for_each_set_bit(i, infomask, sizeof(infomask)*8) { 719 + if (i >= ARRAY_SIZE(iio_chan_info_postfix)) 720 + return -EINVAL; 719 721 ret = __iio_add_chan_devattr(iio_chan_info_postfix[i], 720 722 chan, 721 723 &iio_read_channel_info, ··· 822 820 char *buf) 823 821 { 824 822 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 825 - return sprintf(buf, "%s\n", indio_dev->name); 823 + return snprintf(buf, PAGE_SIZE, "%s\n", indio_dev->name); 826 824 } 827 825 828 826 static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL);
+3 -1
drivers/iio/industrialio-event.c
··· 321 321 char *postfix; 322 322 int ret; 323 323 324 - for_each_set_bit(i, mask, sizeof(*mask)) { 324 + for_each_set_bit(i, mask, sizeof(*mask)*8) { 325 + if (i >= ARRAY_SIZE(iio_ev_info_text)) 326 + return -EINVAL; 325 327 postfix = kasprintf(GFP_KERNEL, "%s_%s_%s", 326 328 iio_ev_type_text[type], iio_ev_dir_text[dir], 327 329 iio_ev_info_text[i]);
+18
drivers/iio/inkern.c
··· 443 443 } 444 444 EXPORT_SYMBOL_GPL(iio_read_channel_raw); 445 445 446 + int iio_read_channel_average_raw(struct iio_channel *chan, int *val) 447 + { 448 + int ret; 449 + 450 + mutex_lock(&chan->indio_dev->info_exist_lock); 451 + if (chan->indio_dev->info == NULL) { 452 + ret = -ENODEV; 453 + goto err_unlock; 454 + } 455 + 456 + ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_AVERAGE_RAW); 457 + err_unlock: 458 + mutex_unlock(&chan->indio_dev->info_exist_lock); 459 + 460 + return ret; 461 + } 462 + EXPORT_SYMBOL_GPL(iio_read_channel_average_raw); 463 + 446 464 static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, 447 465 int raw, int *processed, unsigned int scale) 448 466 {
+2 -1
drivers/iio/magnetometer/Kconfig
··· 11 11 depends on GPIOLIB 12 12 help 13 13 Say yes here to build support for Asahi Kasei AK8975 3-Axis 14 - Magnetometer. 14 + Magnetometer. This driver can also support AK8963, if i2c 15 + device name is identified as ak8963. 15 16 16 17 To compile this driver as a module, choose M here: the module 17 18 will be called ak8975.
+64 -6
drivers/iio/magnetometer/ak8975.c
··· 31 31 #include <linux/bitops.h> 32 32 #include <linux/gpio.h> 33 33 #include <linux/of_gpio.h> 34 + #include <linux/acpi.h> 34 35 35 36 #include <linux/iio/iio.h> 36 37 #include <linux/iio/sysfs.h> ··· 86 85 #define AK8975_MAX_CONVERSION_TIMEOUT 500 87 86 #define AK8975_CONVERSION_DONE_POLL_TIME 10 88 87 #define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000) 89 - #define RAW_TO_GAUSS(asa) ((((asa) + 128) * 3000) / 256) 88 + #define RAW_TO_GAUSS_8975(asa) ((((asa) + 128) * 3000) / 256) 89 + #define RAW_TO_GAUSS_8963(asa) ((((asa) + 128) * 6000) / 256) 90 + 91 + /* Compatible Asahi Kasei Compass parts */ 92 + enum asahi_compass_chipset { 93 + AK8975, 94 + AK8963, 95 + }; 90 96 91 97 /* 92 98 * Per-instance context data for the device. ··· 109 101 int eoc_irq; 110 102 wait_queue_head_t data_ready_queue; 111 103 unsigned long flags; 104 + enum asahi_compass_chipset chipset; 112 105 }; 113 106 114 107 static const int ak8975_index_to_reg[] = { ··· 281 272 * Since ASA doesn't change, we cache the resultant scale factor into the 282 273 * device context in ak8975_setup(). 283 274 */ 284 - data->raw_to_gauss[0] = RAW_TO_GAUSS(data->asa[0]); 285 - data->raw_to_gauss[1] = RAW_TO_GAUSS(data->asa[1]); 286 - data->raw_to_gauss[2] = RAW_TO_GAUSS(data->asa[2]); 275 + if (data->chipset == AK8963) { 276 + /* 277 + * H range is +-8190 and magnetometer range is +-4912. 278 + * So HuT using the above explanation for 8975, 279 + * 4912/8190 = ~ 6/10. 280 + * So the Hadj should use 6/10 instead of 3/10. 281 + */ 282 + data->raw_to_gauss[0] = RAW_TO_GAUSS_8963(data->asa[0]); 283 + data->raw_to_gauss[1] = RAW_TO_GAUSS_8963(data->asa[1]); 284 + data->raw_to_gauss[2] = RAW_TO_GAUSS_8963(data->asa[2]); 285 + } else { 286 + data->raw_to_gauss[0] = RAW_TO_GAUSS_8975(data->asa[0]); 287 + data->raw_to_gauss[1] = RAW_TO_GAUSS_8975(data->asa[1]); 288 + data->raw_to_gauss[2] = RAW_TO_GAUSS_8975(data->asa[2]); 289 + } 287 290 288 291 return 0; 289 292 } ··· 476 455 .driver_module = THIS_MODULE, 477 456 }; 478 457 458 + static const struct acpi_device_id ak_acpi_match[] = { 459 + {"AK8975", AK8975}, 460 + {"AK8963", AK8963}, 461 + {"INVN6500", AK8963}, 462 + { }, 463 + }; 464 + MODULE_DEVICE_TABLE(acpi, ak_acpi_match); 465 + 466 + static char *ak8975_match_acpi_device(struct device *dev, 467 + enum asahi_compass_chipset *chipset) 468 + { 469 + const struct acpi_device_id *id; 470 + 471 + id = acpi_match_device(dev->driver->acpi_match_table, dev); 472 + if (!id) 473 + return NULL; 474 + *chipset = (int)id->driver_data; 475 + 476 + return (char *)dev_name(dev); 477 + } 478 + 479 479 static int ak8975_probe(struct i2c_client *client, 480 480 const struct i2c_device_id *id) 481 481 { ··· 504 462 struct iio_dev *indio_dev; 505 463 int eoc_gpio; 506 464 int err; 465 + char *name = NULL; 507 466 508 467 /* Grab and set up the supplied GPIO. */ 509 468 if (client->dev.platform_data) ··· 542 499 data->eoc_gpio = eoc_gpio; 543 500 data->eoc_irq = 0; 544 501 502 + /* id will be NULL when enumerated via ACPI */ 503 + if (id) { 504 + data->chipset = 505 + (enum asahi_compass_chipset)(id->driver_data); 506 + name = (char *) id->name; 507 + } else if (ACPI_HANDLE(&client->dev)) 508 + name = ak8975_match_acpi_device(&client->dev, &data->chipset); 509 + else { 510 + err = -ENOSYS; 511 + goto exit_free_iio; 512 + } 513 + dev_dbg(&client->dev, "Asahi compass chip %s\n", name); 514 + 545 515 /* Perform some basic start-of-day setup of the device. */ 546 516 err = ak8975_setup(client); 547 517 if (err < 0) { ··· 571 515 indio_dev->info = &ak8975_info; 572 516 indio_dev->name = id->name; 573 517 indio_dev->modes = INDIO_DIRECT_MODE; 574 - 518 + indio_dev->name = name; 575 519 err = iio_device_register(indio_dev); 576 520 if (err < 0) 577 521 goto exit_free_iio; ··· 608 552 } 609 553 610 554 static const struct i2c_device_id ak8975_id[] = { 611 - {"ak8975", 0}, 555 + {"ak8975", AK8975}, 556 + {"ak8963", AK8963}, 612 557 {} 613 558 }; 614 559 ··· 626 569 .driver = { 627 570 .name = "ak8975", 628 571 .of_match_table = ak8975_of_match, 572 + .acpi_match_table = ACPI_PTR(ak_acpi_match), 629 573 }, 630 574 .probe = ak8975_probe, 631 575 .remove = ak8975_remove,
+7
drivers/iio/magnetometer/st_magn_core.c
··· 355 355 indio_dev->modes = INDIO_DIRECT_MODE; 356 356 indio_dev->info = &magn_info; 357 357 358 + st_sensors_power_enable(indio_dev); 359 + 358 360 err = st_sensors_check_device_support(indio_dev, 359 361 ARRAY_SIZE(st_magn_sensors), st_magn_sensors); 360 362 if (err < 0) ··· 389 387 if (err) 390 388 goto st_magn_device_register_error; 391 389 390 + dev_info(&indio_dev->dev, "registered magnetometer %s\n", 391 + indio_dev->name); 392 + 392 393 return 0; 393 394 394 395 st_magn_device_register_error: ··· 407 402 void st_magn_common_remove(struct iio_dev *indio_dev) 408 403 { 409 404 struct st_sensor_data *mdata = iio_priv(indio_dev); 405 + 406 + st_sensors_power_disable(indio_dev); 410 407 411 408 iio_device_unregister(indio_dev); 412 409 if (mdata->get_irq_data_ready(indio_dev) > 0)
+5 -37
drivers/iio/pressure/st_pressure_core.c
··· 23 23 #include <linux/iio/sysfs.h> 24 24 #include <linux/iio/trigger.h> 25 25 #include <linux/iio/buffer.h> 26 - #include <linux/regulator/consumer.h> 27 26 #include <asm/unaligned.h> 28 27 29 28 #include <linux/iio/common/st_sensors.h> ··· 386 387 #define ST_PRESS_TRIGGER_OPS NULL 387 388 #endif 388 389 389 - static void st_press_power_enable(struct iio_dev *indio_dev) 390 - { 391 - struct st_sensor_data *pdata = iio_priv(indio_dev); 392 - int err; 393 - 394 - /* Regulators not mandatory, but if requested we should enable them. */ 395 - pdata->vdd = devm_regulator_get_optional(&indio_dev->dev, "vdd"); 396 - if (!IS_ERR(pdata->vdd)) { 397 - err = regulator_enable(pdata->vdd); 398 - if (err != 0) 399 - dev_warn(&indio_dev->dev, 400 - "Failed to enable specified Vdd supply\n"); 401 - } 402 - 403 - pdata->vdd_io = devm_regulator_get_optional(&indio_dev->dev, "vddio"); 404 - if (!IS_ERR(pdata->vdd_io)) { 405 - err = regulator_enable(pdata->vdd_io); 406 - if (err != 0) 407 - dev_warn(&indio_dev->dev, 408 - "Failed to enable specified Vdd_IO supply\n"); 409 - } 410 - } 411 - 412 - static void st_press_power_disable(struct iio_dev *indio_dev) 413 - { 414 - struct st_sensor_data *pdata = iio_priv(indio_dev); 415 - 416 - if (!IS_ERR(pdata->vdd)) 417 - regulator_disable(pdata->vdd); 418 - 419 - if (!IS_ERR(pdata->vdd_io)) 420 - regulator_disable(pdata->vdd_io); 421 - } 422 - 423 390 int st_press_common_probe(struct iio_dev *indio_dev, 424 391 struct st_sensors_platform_data *plat_data) 425 392 { ··· 396 431 indio_dev->modes = INDIO_DIRECT_MODE; 397 432 indio_dev->info = &press_info; 398 433 399 - st_press_power_enable(indio_dev); 434 + st_sensors_power_enable(indio_dev); 400 435 401 436 err = st_sensors_check_device_support(indio_dev, 402 437 ARRAY_SIZE(st_press_sensors), ··· 439 474 if (err) 440 475 goto st_press_device_register_error; 441 476 477 + dev_info(&indio_dev->dev, "registered pressure sensor %s\n", 478 + indio_dev->name); 479 + 442 480 return err; 443 481 444 482 st_press_device_register_error: ··· 458 490 { 459 491 struct st_sensor_data *pdata = iio_priv(indio_dev); 460 492 461 - st_press_power_disable(indio_dev); 493 + st_sensors_power_disable(indio_dev); 462 494 463 495 iio_device_unregister(indio_dev); 464 496 if (pdata->get_irq_data_ready(indio_dev) > 0)
+19
drivers/iio/proximity/Kconfig
··· 1 + # 2 + # Proximity sensors 3 + # 4 + 5 + menu "Lightning sensors" 6 + 7 + config AS3935 8 + tristate "AS3935 Franklin lightning sensor" 9 + select IIO_BUFFER 10 + select IIO_TRIGGERED_BUFFER 11 + depends on SPI 12 + help 13 + Say Y here to build SPI interface support for the Austrian 14 + Microsystems AS3935 lightning detection sensor. 15 + 16 + To compile this driver as a module, choose M here: the 17 + module will be called as3935 18 + 19 + endmenu
+6
drivers/iio/proximity/Makefile
··· 1 + # 2 + # Makefile for IIO proximity sensors 3 + # 4 + 5 + # When adding new entries keep the list in alphabetical order 6 + obj-$(CONFIG_AS3935) += as3935.o
+456
drivers/iio/proximity/as3935.c
··· 1 + /* 2 + * as3935.c - Support for AS3935 Franklin lightning sensor 3 + * 4 + * Copyright (C) 2014 Matt Ranostay <mranostay@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 as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + */ 17 + 18 + #include <linux/module.h> 19 + #include <linux/init.h> 20 + #include <linux/interrupt.h> 21 + #include <linux/delay.h> 22 + #include <linux/workqueue.h> 23 + #include <linux/mutex.h> 24 + #include <linux/err.h> 25 + #include <linux/irq.h> 26 + #include <linux/gpio.h> 27 + #include <linux/spi/spi.h> 28 + #include <linux/iio/iio.h> 29 + #include <linux/iio/sysfs.h> 30 + #include <linux/iio/trigger.h> 31 + #include <linux/iio/trigger_consumer.h> 32 + #include <linux/iio/buffer.h> 33 + #include <linux/iio/triggered_buffer.h> 34 + #include <linux/of_gpio.h> 35 + 36 + 37 + #define AS3935_AFE_GAIN 0x00 38 + #define AS3935_AFE_MASK 0x3F 39 + #define AS3935_AFE_GAIN_MAX 0x1F 40 + #define AS3935_AFE_PWR_BIT BIT(0) 41 + 42 + #define AS3935_INT 0x03 43 + #define AS3935_INT_MASK 0x07 44 + #define AS3935_EVENT_INT BIT(3) 45 + #define AS3935_NOISE_INT BIT(1) 46 + 47 + #define AS3935_DATA 0x07 48 + #define AS3935_DATA_MASK 0x3F 49 + 50 + #define AS3935_TUNE_CAP 0x08 51 + #define AS3935_CALIBRATE 0x3D 52 + 53 + #define AS3935_WRITE_DATA BIT(15) 54 + #define AS3935_READ_DATA BIT(14) 55 + #define AS3935_ADDRESS(x) ((x) << 8) 56 + 57 + #define MAX_PF_CAP 120 58 + #define TUNE_CAP_DIV 8 59 + 60 + struct as3935_state { 61 + struct spi_device *spi; 62 + struct iio_trigger *trig; 63 + struct mutex lock; 64 + struct delayed_work work; 65 + 66 + u32 tune_cap; 67 + u8 buf[2] ____cacheline_aligned; 68 + }; 69 + 70 + static const struct iio_chan_spec as3935_channels[] = { 71 + { 72 + .type = IIO_PROXIMITY, 73 + .info_mask_separate = 74 + BIT(IIO_CHAN_INFO_RAW) | 75 + BIT(IIO_CHAN_INFO_PROCESSED), 76 + .scan_index = 0, 77 + .scan_type = { 78 + .sign = 'u', 79 + .realbits = 6, 80 + .storagebits = 8, 81 + }, 82 + }, 83 + IIO_CHAN_SOFT_TIMESTAMP(1), 84 + }; 85 + 86 + static int as3935_read(struct as3935_state *st, unsigned int reg, int *val) 87 + { 88 + u8 cmd; 89 + int ret; 90 + 91 + cmd = (AS3935_READ_DATA | AS3935_ADDRESS(reg)) >> 8; 92 + ret = spi_w8r8(st->spi, cmd); 93 + if (ret < 0) 94 + return ret; 95 + *val = ret; 96 + 97 + return 0; 98 + }; 99 + 100 + static int as3935_write(struct as3935_state *st, 101 + unsigned int reg, 102 + unsigned int val) 103 + { 104 + u8 *buf = st->buf; 105 + 106 + buf[0] = (AS3935_WRITE_DATA | AS3935_ADDRESS(reg)) >> 8; 107 + buf[1] = val; 108 + 109 + return spi_write(st->spi, buf, 2); 110 + }; 111 + 112 + static ssize_t as3935_sensor_sensitivity_show(struct device *dev, 113 + struct device_attribute *attr, 114 + char *buf) 115 + { 116 + struct as3935_state *st = iio_priv(dev_to_iio_dev(dev)); 117 + int val, ret; 118 + 119 + ret = as3935_read(st, AS3935_AFE_GAIN, &val); 120 + if (ret) 121 + return ret; 122 + val = (val & AS3935_AFE_MASK) >> 1; 123 + 124 + return sprintf(buf, "%d\n", val); 125 + }; 126 + 127 + static ssize_t as3935_sensor_sensitivity_store(struct device *dev, 128 + struct device_attribute *attr, 129 + const char *buf, size_t len) 130 + { 131 + struct as3935_state *st = iio_priv(dev_to_iio_dev(dev)); 132 + unsigned long val; 133 + int ret; 134 + 135 + ret = kstrtoul((const char *) buf, 10, &val); 136 + if (ret) 137 + return -EINVAL; 138 + 139 + if (val > AS3935_AFE_GAIN_MAX) 140 + return -EINVAL; 141 + 142 + as3935_write(st, AS3935_AFE_GAIN, val << 1); 143 + 144 + return len; 145 + }; 146 + 147 + static IIO_DEVICE_ATTR(sensor_sensitivity, S_IRUGO | S_IWUSR, 148 + as3935_sensor_sensitivity_show, as3935_sensor_sensitivity_store, 0); 149 + 150 + 151 + static struct attribute *as3935_attributes[] = { 152 + &iio_dev_attr_sensor_sensitivity.dev_attr.attr, 153 + NULL, 154 + }; 155 + 156 + static struct attribute_group as3935_attribute_group = { 157 + .attrs = as3935_attributes, 158 + }; 159 + 160 + static int as3935_read_raw(struct iio_dev *indio_dev, 161 + struct iio_chan_spec const *chan, 162 + int *val, 163 + int *val2, 164 + long m) 165 + { 166 + struct as3935_state *st = iio_priv(indio_dev); 167 + int ret; 168 + 169 + 170 + switch (m) { 171 + case IIO_CHAN_INFO_PROCESSED: 172 + case IIO_CHAN_INFO_RAW: 173 + *val2 = 0; 174 + ret = as3935_read(st, AS3935_DATA, val); 175 + if (ret) 176 + return ret; 177 + 178 + if (m == IIO_CHAN_INFO_RAW) 179 + return IIO_VAL_INT; 180 + 181 + /* storm out of range */ 182 + if (*val == AS3935_DATA_MASK) 183 + return -EINVAL; 184 + *val *= 1000; 185 + break; 186 + default: 187 + return -EINVAL; 188 + } 189 + 190 + return IIO_VAL_INT; 191 + } 192 + 193 + static const struct iio_info as3935_info = { 194 + .driver_module = THIS_MODULE, 195 + .attrs = &as3935_attribute_group, 196 + .read_raw = &as3935_read_raw, 197 + }; 198 + 199 + static irqreturn_t as3935_trigger_handler(int irq, void *private) 200 + { 201 + struct iio_poll_func *pf = private; 202 + struct iio_dev *indio_dev = pf->indio_dev; 203 + struct as3935_state *st = iio_priv(indio_dev); 204 + int val, ret; 205 + 206 + ret = as3935_read(st, AS3935_DATA, &val); 207 + if (ret) 208 + goto err_read; 209 + val &= AS3935_DATA_MASK; 210 + val *= 1000; 211 + 212 + iio_push_to_buffers_with_timestamp(indio_dev, &val, pf->timestamp); 213 + err_read: 214 + iio_trigger_notify_done(indio_dev->trig); 215 + 216 + return IRQ_HANDLED; 217 + }; 218 + 219 + static const struct iio_trigger_ops iio_interrupt_trigger_ops = { 220 + .owner = THIS_MODULE, 221 + }; 222 + 223 + static void as3935_event_work(struct work_struct *work) 224 + { 225 + struct as3935_state *st; 226 + int val; 227 + 228 + st = container_of(work, struct as3935_state, work.work); 229 + 230 + as3935_read(st, AS3935_INT, &val); 231 + val &= AS3935_INT_MASK; 232 + 233 + switch (val) { 234 + case AS3935_EVENT_INT: 235 + iio_trigger_poll(st->trig, iio_get_time_ns()); 236 + break; 237 + case AS3935_NOISE_INT: 238 + dev_warn(&st->spi->dev, "noise level is too high"); 239 + break; 240 + } 241 + }; 242 + 243 + static irqreturn_t as3935_interrupt_handler(int irq, void *private) 244 + { 245 + struct iio_dev *indio_dev = private; 246 + struct as3935_state *st = iio_priv(indio_dev); 247 + 248 + /* 249 + * Delay work for >2 milliseconds after an interrupt to allow 250 + * estimated distance to recalculated. 251 + */ 252 + 253 + schedule_delayed_work(&st->work, msecs_to_jiffies(3)); 254 + 255 + return IRQ_HANDLED; 256 + } 257 + 258 + static void calibrate_as3935(struct as3935_state *st) 259 + { 260 + mutex_lock(&st->lock); 261 + 262 + /* mask disturber interrupt bit */ 263 + as3935_write(st, AS3935_INT, BIT(5)); 264 + 265 + as3935_write(st, AS3935_CALIBRATE, 0x96); 266 + as3935_write(st, AS3935_TUNE_CAP, 267 + BIT(5) | (st->tune_cap / TUNE_CAP_DIV)); 268 + 269 + mdelay(2); 270 + as3935_write(st, AS3935_TUNE_CAP, (st->tune_cap / TUNE_CAP_DIV)); 271 + 272 + mutex_unlock(&st->lock); 273 + } 274 + 275 + #ifdef CONFIG_PM_SLEEP 276 + static int as3935_suspend(struct spi_device *spi, pm_message_t msg) 277 + { 278 + struct iio_dev *indio_dev = spi_get_drvdata(spi); 279 + struct as3935_state *st = iio_priv(indio_dev); 280 + int val, ret; 281 + 282 + mutex_lock(&st->lock); 283 + ret = as3935_read(st, AS3935_AFE_GAIN, &val); 284 + if (ret) 285 + goto err_suspend; 286 + val |= AS3935_AFE_PWR_BIT; 287 + 288 + ret = as3935_write(st, AS3935_AFE_GAIN, val); 289 + 290 + err_suspend: 291 + mutex_unlock(&st->lock); 292 + 293 + return ret; 294 + } 295 + 296 + static int as3935_resume(struct spi_device *spi) 297 + { 298 + struct iio_dev *indio_dev = spi_get_drvdata(spi); 299 + struct as3935_state *st = iio_priv(indio_dev); 300 + int val, ret; 301 + 302 + mutex_lock(&st->lock); 303 + ret = as3935_read(st, AS3935_AFE_GAIN, &val); 304 + if (ret) 305 + goto err_resume; 306 + val &= ~AS3935_AFE_PWR_BIT; 307 + ret = as3935_write(st, AS3935_AFE_GAIN, val); 308 + 309 + err_resume: 310 + mutex_unlock(&st->lock); 311 + 312 + return ret; 313 + } 314 + #else 315 + #define as3935_suspend NULL 316 + #define as3935_resume NULL 317 + #endif 318 + 319 + static int as3935_probe(struct spi_device *spi) 320 + { 321 + struct iio_dev *indio_dev; 322 + struct iio_trigger *trig; 323 + struct as3935_state *st; 324 + struct device_node *np = spi->dev.of_node; 325 + int ret; 326 + 327 + /* Be sure lightning event interrupt is specified */ 328 + if (!spi->irq) { 329 + dev_err(&spi->dev, "unable to get event interrupt\n"); 330 + return -EINVAL; 331 + } 332 + 333 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(st)); 334 + if (!indio_dev) 335 + return -ENOMEM; 336 + 337 + st = iio_priv(indio_dev); 338 + st->spi = spi; 339 + st->tune_cap = 0; 340 + 341 + spi_set_drvdata(spi, indio_dev); 342 + mutex_init(&st->lock); 343 + INIT_DELAYED_WORK(&st->work, as3935_event_work); 344 + 345 + ret = of_property_read_u32(np, 346 + "ams,tuning-capacitor-pf", &st->tune_cap); 347 + if (ret) { 348 + st->tune_cap = 0; 349 + dev_warn(&spi->dev, 350 + "no tuning-capacitor-pf set, defaulting to %d", 351 + st->tune_cap); 352 + } 353 + 354 + if (st->tune_cap > MAX_PF_CAP) { 355 + dev_err(&spi->dev, 356 + "wrong tuning-capacitor-pf setting of %d\n", 357 + st->tune_cap); 358 + return -EINVAL; 359 + } 360 + 361 + indio_dev->dev.parent = &spi->dev; 362 + indio_dev->name = spi_get_device_id(spi)->name; 363 + indio_dev->channels = as3935_channels; 364 + indio_dev->num_channels = ARRAY_SIZE(as3935_channels); 365 + indio_dev->modes = INDIO_DIRECT_MODE; 366 + indio_dev->info = &as3935_info; 367 + 368 + trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d", 369 + indio_dev->name, indio_dev->id); 370 + 371 + if (!trig) 372 + return -ENOMEM; 373 + 374 + st->trig = trig; 375 + trig->dev.parent = indio_dev->dev.parent; 376 + iio_trigger_set_drvdata(trig, indio_dev); 377 + trig->ops = &iio_interrupt_trigger_ops; 378 + 379 + ret = iio_trigger_register(trig); 380 + if (ret) { 381 + dev_err(&spi->dev, "failed to register trigger\n"); 382 + return ret; 383 + } 384 + 385 + ret = iio_triggered_buffer_setup(indio_dev, NULL, 386 + &as3935_trigger_handler, NULL); 387 + 388 + if (ret) { 389 + dev_err(&spi->dev, "cannot setup iio trigger\n"); 390 + goto unregister_trigger; 391 + } 392 + 393 + calibrate_as3935(st); 394 + 395 + ret = devm_request_irq(&spi->dev, spi->irq, 396 + &as3935_interrupt_handler, 397 + IRQF_TRIGGER_RISING, 398 + dev_name(&spi->dev), 399 + indio_dev); 400 + 401 + if (ret) { 402 + dev_err(&spi->dev, "unable to request irq\n"); 403 + goto unregister_buffer; 404 + } 405 + 406 + ret = iio_device_register(indio_dev); 407 + if (ret < 0) { 408 + dev_err(&spi->dev, "unable to register device\n"); 409 + goto unregister_buffer; 410 + } 411 + return 0; 412 + 413 + unregister_buffer: 414 + iio_triggered_buffer_cleanup(indio_dev); 415 + 416 + unregister_trigger: 417 + iio_trigger_unregister(st->trig); 418 + 419 + return ret; 420 + }; 421 + 422 + static int as3935_remove(struct spi_device *spi) 423 + { 424 + struct iio_dev *indio_dev = spi_get_drvdata(spi); 425 + struct as3935_state *st = iio_priv(indio_dev); 426 + 427 + iio_device_unregister(indio_dev); 428 + iio_triggered_buffer_cleanup(indio_dev); 429 + iio_trigger_unregister(st->trig); 430 + 431 + return 0; 432 + }; 433 + 434 + static const struct spi_device_id as3935_id[] = { 435 + {"as3935", 0}, 436 + {}, 437 + }; 438 + MODULE_DEVICE_TABLE(spi, as3935_id); 439 + 440 + static struct spi_driver as3935_driver = { 441 + .driver = { 442 + .name = "as3935", 443 + .owner = THIS_MODULE, 444 + }, 445 + .probe = as3935_probe, 446 + .remove = as3935_remove, 447 + .id_table = as3935_id, 448 + .suspend = as3935_suspend, 449 + .resume = as3935_resume, 450 + }; 451 + module_spi_driver(as3935_driver); 452 + 453 + MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>"); 454 + MODULE_DESCRIPTION("AS3935 lightning sensor"); 455 + MODULE_LICENSE("GPL"); 456 + MODULE_ALIAS("spi:as3935");
-20
drivers/staging/iio/adc/Kconfig
··· 37 37 Say yes here to include parallel interface support on the AD7606 38 38 ADC driver. 39 39 40 - config AD799X 41 - tristate "Analog Devices AD799x ADC driver" 42 - depends on I2C 43 - select IIO_TRIGGER if IIO_BUFFER 44 - select AD799X_RING_BUFFER 45 - help 46 - Say yes here to build support for Analog Devices: 47 - ad7991, ad7995, ad7999, ad7992, ad7993, ad7994, ad7997, ad7998 48 - i2c analog to digital converters (ADC). Provides direct access 49 - via sysfs. 50 - 51 - config AD799X_RING_BUFFER 52 - bool "Analog Devices AD799x: use ring buffer" 53 - depends on AD799X 54 - select IIO_BUFFER 55 - select IIO_TRIGGERED_BUFFER 56 - help 57 - Say yes here to include ring buffer support in the AD799X 58 - ADC driver. 59 - 60 40 config AD7780 61 41 tristate "Analog Devices AD7780 and similar ADCs driver" 62 42 depends on SPI
-4
drivers/staging/iio/adc/Makefile
··· 8 8 ad7606-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o 9 9 obj-$(CONFIG_AD7606) += ad7606.o 10 10 11 - ad799x-y := ad799x_core.o 12 - ad799x-$(CONFIG_AD799X_RING_BUFFER) += ad799x_ring.o 13 - obj-$(CONFIG_AD799X) += ad799x.o 14 - 15 11 obj-$(CONFIG_AD7291) += ad7291.o 16 12 obj-$(CONFIG_AD7780) += ad7780.o 17 13 obj-$(CONFIG_AD7816) += ad7816.o
+2 -2
drivers/staging/iio/adc/ad7606.h
··· 14 14 */ 15 15 16 16 /** 17 - * struct ad7606_platform_data - platform/board specifc information 17 + * struct ad7606_platform_data - platform/board specific information 18 18 * @default_os: default oversampling value {0, 2, 4, 8, 16, 32, 64} 19 19 * @default_range: default range +/-{5000, 10000} mVolt 20 20 * @gpio_convst: number of gpio connected to the CONVST pin ··· 41 41 }; 42 42 43 43 /** 44 - * struct ad7606_chip_info - chip specifc information 44 + * struct ad7606_chip_info - chip specific information 45 45 * @name: identification string for chip 46 46 * @int_vref_mv: the internal reference voltage 47 47 * @channels: channel specification
+1 -1
drivers/staging/iio/adc/ad7816.c
··· 40 40 41 41 42 42 /* 43 - * struct ad7816_chip_info - chip specifc information 43 + * struct ad7816_chip_info - chip specific information 44 44 */ 45 45 46 46 struct ad7816_chip_info {
-121
drivers/staging/iio/adc/ad799x.h
··· 1 - /* 2 - * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc. 3 - * Copyright (C) 2008-2010 Jonathan Cameron 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 - * ad799x.h 10 - */ 11 - 12 - #ifndef _AD799X_H_ 13 - #define _AD799X_H_ 14 - 15 - #define AD799X_CHANNEL_SHIFT 4 16 - #define AD799X_STORAGEBITS 16 17 - /* 18 - * AD7991, AD7995 and AD7999 defines 19 - */ 20 - 21 - #define AD7991_REF_SEL 0x08 22 - #define AD7991_FLTR 0x04 23 - #define AD7991_BIT_TRIAL_DELAY 0x02 24 - #define AD7991_SAMPLE_DELAY 0x01 25 - 26 - /* 27 - * AD7992, AD7993, AD7994, AD7997 and AD7998 defines 28 - */ 29 - 30 - #define AD7998_FLTR 0x08 31 - #define AD7998_ALERT_EN 0x04 32 - #define AD7998_BUSY_ALERT 0x02 33 - #define AD7998_BUSY_ALERT_POL 0x01 34 - 35 - #define AD7998_CONV_RES_REG 0x0 36 - #define AD7998_ALERT_STAT_REG 0x1 37 - #define AD7998_CONF_REG 0x2 38 - #define AD7998_CYCLE_TMR_REG 0x3 39 - 40 - #define AD7998_DATALOW_REG(x) ((x) * 3 + 0x4) 41 - #define AD7998_DATAHIGH_REG(x) ((x) * 3 + 0x5) 42 - #define AD7998_HYST_REG(x) ((x) * 3 + 0x6) 43 - 44 - #define AD7998_CYC_MASK 0x7 45 - #define AD7998_CYC_DIS 0x0 46 - #define AD7998_CYC_TCONF_32 0x1 47 - #define AD7998_CYC_TCONF_64 0x2 48 - #define AD7998_CYC_TCONF_128 0x3 49 - #define AD7998_CYC_TCONF_256 0x4 50 - #define AD7998_CYC_TCONF_512 0x5 51 - #define AD7998_CYC_TCONF_1024 0x6 52 - #define AD7998_CYC_TCONF_2048 0x7 53 - 54 - #define AD7998_ALERT_STAT_CLEAR 0xFF 55 - 56 - /* 57 - * AD7997 and AD7997 defines 58 - */ 59 - 60 - #define AD7997_8_READ_SINGLE 0x80 61 - #define AD7997_8_READ_SEQUENCE 0x70 62 - /* TODO: move this into a common header */ 63 - #define RES_MASK(bits) ((1 << (bits)) - 1) 64 - 65 - enum { 66 - ad7991, 67 - ad7995, 68 - ad7999, 69 - ad7992, 70 - ad7993, 71 - ad7994, 72 - ad7997, 73 - ad7998 74 - }; 75 - 76 - struct ad799x_state; 77 - 78 - /** 79 - * struct ad799x_chip_info - chip specifc information 80 - * @channel: channel specification 81 - * @num_channels: number of channels 82 - * @monitor_mode: whether the chip supports monitor interrupts 83 - * @default_config: device default configuration 84 - * @event_attrs: pointer to the monitor event attribute group 85 - */ 86 - 87 - struct ad799x_chip_info { 88 - struct iio_chan_spec channel[9]; 89 - int num_channels; 90 - u16 default_config; 91 - const struct iio_info *info; 92 - }; 93 - 94 - struct ad799x_state { 95 - struct i2c_client *client; 96 - const struct ad799x_chip_info *chip_info; 97 - struct regulator *reg; 98 - struct regulator *vref; 99 - unsigned id; 100 - u16 config; 101 - 102 - u8 *rx_buf; 103 - unsigned int transfer_size; 104 - }; 105 - 106 - #ifdef CONFIG_AD799X_RING_BUFFER 107 - int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev); 108 - void ad799x_ring_cleanup(struct iio_dev *indio_dev); 109 - #else /* CONFIG_AD799X_RING_BUFFER */ 110 - 111 - static inline int 112 - ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev) 113 - { 114 - return 0; 115 - } 116 - 117 - static inline void ad799x_ring_cleanup(struct iio_dev *indio_dev) 118 - { 119 - } 120 - #endif /* CONFIG_AD799X_RING_BUFFER */ 121 - #endif /* _AD799X_H_ */
+141 -4
drivers/staging/iio/adc/ad799x_core.c drivers/iio/adc/ad799x.c
··· 37 37 #include <linux/iio/sysfs.h> 38 38 #include <linux/iio/events.h> 39 39 #include <linux/iio/buffer.h> 40 + #include <linux/iio/trigger_consumer.h> 41 + #include <linux/iio/triggered_buffer.h> 40 42 41 - #include "ad799x.h" 43 + #define AD799X_CHANNEL_SHIFT 4 44 + #define AD799X_STORAGEBITS 16 45 + /* 46 + * AD7991, AD7995 and AD7999 defines 47 + */ 48 + 49 + #define AD7991_REF_SEL 0x08 50 + #define AD7991_FLTR 0x04 51 + #define AD7991_BIT_TRIAL_DELAY 0x02 52 + #define AD7991_SAMPLE_DELAY 0x01 53 + 54 + /* 55 + * AD7992, AD7993, AD7994, AD7997 and AD7998 defines 56 + */ 57 + 58 + #define AD7998_FLTR 0x08 59 + #define AD7998_ALERT_EN 0x04 60 + #define AD7998_BUSY_ALERT 0x02 61 + #define AD7998_BUSY_ALERT_POL 0x01 62 + 63 + #define AD7998_CONV_RES_REG 0x0 64 + #define AD7998_ALERT_STAT_REG 0x1 65 + #define AD7998_CONF_REG 0x2 66 + #define AD7998_CYCLE_TMR_REG 0x3 67 + 68 + #define AD7998_DATALOW_REG(x) ((x) * 3 + 0x4) 69 + #define AD7998_DATAHIGH_REG(x) ((x) * 3 + 0x5) 70 + #define AD7998_HYST_REG(x) ((x) * 3 + 0x6) 71 + 72 + #define AD7998_CYC_MASK 0x7 73 + #define AD7998_CYC_DIS 0x0 74 + #define AD7998_CYC_TCONF_32 0x1 75 + #define AD7998_CYC_TCONF_64 0x2 76 + #define AD7998_CYC_TCONF_128 0x3 77 + #define AD7998_CYC_TCONF_256 0x4 78 + #define AD7998_CYC_TCONF_512 0x5 79 + #define AD7998_CYC_TCONF_1024 0x6 80 + #define AD7998_CYC_TCONF_2048 0x7 81 + 82 + #define AD7998_ALERT_STAT_CLEAR 0xFF 83 + 84 + /* 85 + * AD7997 and AD7997 defines 86 + */ 87 + 88 + #define AD7997_8_READ_SINGLE 0x80 89 + #define AD7997_8_READ_SEQUENCE 0x70 90 + /* TODO: move this into a common header */ 91 + #define RES_MASK(bits) ((1 << (bits)) - 1) 92 + 93 + enum { 94 + ad7991, 95 + ad7995, 96 + ad7999, 97 + ad7992, 98 + ad7993, 99 + ad7994, 100 + ad7997, 101 + ad7998 102 + }; 103 + 104 + /** 105 + * struct ad799x_chip_info - chip specific information 106 + * @channel: channel specification 107 + * @num_channels: number of channels 108 + * @monitor_mode: whether the chip supports monitor interrupts 109 + * @default_config: device default configuration 110 + * @event_attrs: pointer to the monitor event attribute group 111 + */ 112 + struct ad799x_chip_info { 113 + struct iio_chan_spec channel[9]; 114 + int num_channels; 115 + u16 default_config; 116 + const struct iio_info *info; 117 + }; 118 + 119 + struct ad799x_state { 120 + struct i2c_client *client; 121 + const struct ad799x_chip_info *chip_info; 122 + struct regulator *reg; 123 + struct regulator *vref; 124 + unsigned id; 125 + u16 config; 126 + 127 + u8 *rx_buf; 128 + unsigned int transfer_size; 129 + }; 130 + 131 + /** 132 + * ad799x_trigger_handler() bh of trigger launched polling to ring buffer 133 + * 134 + * Currently there is no option in this driver to disable the saving of 135 + * timestamps within the ring. 136 + **/ 137 + static irqreturn_t ad799x_trigger_handler(int irq, void *p) 138 + { 139 + struct iio_poll_func *pf = p; 140 + struct iio_dev *indio_dev = pf->indio_dev; 141 + struct ad799x_state *st = iio_priv(indio_dev); 142 + int b_sent; 143 + u8 cmd; 144 + 145 + switch (st->id) { 146 + case ad7991: 147 + case ad7995: 148 + case ad7999: 149 + cmd = st->config | 150 + (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT); 151 + break; 152 + case ad7992: 153 + case ad7993: 154 + case ad7994: 155 + cmd = (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT) | 156 + AD7998_CONV_RES_REG; 157 + break; 158 + case ad7997: 159 + case ad7998: 160 + cmd = AD7997_8_READ_SEQUENCE | AD7998_CONV_RES_REG; 161 + break; 162 + default: 163 + cmd = 0; 164 + } 165 + 166 + b_sent = i2c_smbus_read_i2c_block_data(st->client, 167 + cmd, st->transfer_size, st->rx_buf); 168 + if (b_sent < 0) 169 + goto out; 170 + 171 + iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, 172 + iio_get_time_ns()); 173 + out: 174 + iio_trigger_notify_done(indio_dev->trig); 175 + 176 + return IRQ_HANDLED; 177 + } 42 178 43 179 /* 44 180 * ad799x register access by I2C ··· 714 578 indio_dev->channels = st->chip_info->channel; 715 579 indio_dev->num_channels = st->chip_info->num_channels; 716 580 717 - ret = ad799x_register_ring_funcs_and_init(indio_dev); 581 + ret = iio_triggered_buffer_setup(indio_dev, NULL, 582 + &ad799x_trigger_handler, NULL); 718 583 if (ret) 719 584 goto error_disable_reg; 720 585 ··· 738 601 return 0; 739 602 740 603 error_cleanup_ring: 741 - ad799x_ring_cleanup(indio_dev); 604 + iio_triggered_buffer_cleanup(indio_dev); 742 605 error_disable_reg: 743 606 if (!IS_ERR(st->vref)) 744 607 regulator_disable(st->vref); ··· 755 618 756 619 iio_device_unregister(indio_dev); 757 620 758 - ad799x_ring_cleanup(indio_dev); 621 + iio_triggered_buffer_cleanup(indio_dev); 759 622 if (!IS_ERR(st->vref)) 760 623 regulator_disable(st->vref); 761 624 if (!IS_ERR(st->reg))
-84
drivers/staging/iio/adc/ad799x_ring.c
··· 1 - /* 2 - * Copyright (C) 2010-2012 Michael Hennerich, Analog Devices Inc. 3 - * Copyright (C) 2008-2010 Jonathan Cameron 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 - * ad799x_ring.c 10 - */ 11 - 12 - #include <linux/interrupt.h> 13 - #include <linux/slab.h> 14 - #include <linux/kernel.h> 15 - #include <linux/list.h> 16 - #include <linux/i2c.h> 17 - #include <linux/bitops.h> 18 - 19 - #include <linux/iio/iio.h> 20 - #include <linux/iio/buffer.h> 21 - #include <linux/iio/trigger_consumer.h> 22 - #include <linux/iio/triggered_buffer.h> 23 - 24 - #include "ad799x.h" 25 - 26 - /** 27 - * ad799x_trigger_handler() bh of trigger launched polling to ring buffer 28 - * 29 - * Currently there is no option in this driver to disable the saving of 30 - * timestamps within the ring. 31 - **/ 32 - 33 - static irqreturn_t ad799x_trigger_handler(int irq, void *p) 34 - { 35 - struct iio_poll_func *pf = p; 36 - struct iio_dev *indio_dev = pf->indio_dev; 37 - struct ad799x_state *st = iio_priv(indio_dev); 38 - int b_sent; 39 - u8 cmd; 40 - 41 - switch (st->id) { 42 - case ad7991: 43 - case ad7995: 44 - case ad7999: 45 - cmd = st->config | 46 - (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT); 47 - break; 48 - case ad7992: 49 - case ad7993: 50 - case ad7994: 51 - cmd = (*indio_dev->active_scan_mask << AD799X_CHANNEL_SHIFT) | 52 - AD7998_CONV_RES_REG; 53 - break; 54 - case ad7997: 55 - case ad7998: 56 - cmd = AD7997_8_READ_SEQUENCE | AD7998_CONV_RES_REG; 57 - break; 58 - default: 59 - cmd = 0; 60 - } 61 - 62 - b_sent = i2c_smbus_read_i2c_block_data(st->client, 63 - cmd, st->transfer_size, st->rx_buf); 64 - if (b_sent < 0) 65 - goto out; 66 - 67 - iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, 68 - iio_get_time_ns()); 69 - out: 70 - iio_trigger_notify_done(indio_dev->trig); 71 - 72 - return IRQ_HANDLED; 73 - } 74 - 75 - int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev) 76 - { 77 - return iio_triggered_buffer_setup(indio_dev, NULL, 78 - &ad799x_trigger_handler, NULL); 79 - } 80 - 81 - void ad799x_ring_cleanup(struct iio_dev *indio_dev) 82 - { 83 - iio_triggered_buffer_cleanup(indio_dev); 84 - }
+142 -173
drivers/staging/iio/adc/spear_adc.c
··· 22 22 #include <linux/iio/iio.h> 23 23 #include <linux/iio/sysfs.h> 24 24 25 - /* 26 - * SPEAR registers definitions 27 - */ 28 - 29 - #define SCAN_RATE_LO(x) ((x) & 0xFFFF) 30 - #define SCAN_RATE_HI(x) (((x) >> 0x10) & 0xFFFF) 31 - #define CLK_LOW(x) (((x) & 0xf) << 0) 32 - #define CLK_HIGH(x) (((x) & 0xf) << 4) 25 + /* SPEAR registers definitions */ 26 + #define SPEAR600_ADC_SCAN_RATE_LO(x) ((x) & 0xFFFF) 27 + #define SPEAR600_ADC_SCAN_RATE_HI(x) (((x) >> 0x10) & 0xFFFF) 28 + #define SPEAR_ADC_CLK_LOW(x) (((x) & 0xf) << 0) 29 + #define SPEAR_ADC_CLK_HIGH(x) (((x) & 0xf) << 4) 33 30 34 31 /* Bit definitions for SPEAR_ADC_STATUS */ 35 - #define START_CONVERSION (1 << 0) 36 - #define CHANNEL_NUM(x) ((x) << 1) 37 - #define ADC_ENABLE (1 << 4) 38 - #define AVG_SAMPLE(x) ((x) << 5) 39 - #define VREF_INTERNAL (1 << 9) 32 + #define SPEAR_ADC_STATUS_START_CONVERSION (1 << 0) 33 + #define SPEAR_ADC_STATUS_CHANNEL_NUM(x) ((x) << 1) 34 + #define SPEAR_ADC_STATUS_ADC_ENABLE (1 << 4) 35 + #define SPEAR_ADC_STATUS_AVG_SAMPLE(x) ((x) << 5) 36 + #define SPEAR_ADC_STATUS_VREF_INTERNAL (1 << 9) 40 37 41 - #define DATA_MASK 0x03ff 42 - #define DATA_BITS 10 38 + #define SPEAR_ADC_DATA_MASK 0x03ff 39 + #define SPEAR_ADC_DATA_BITS 10 43 40 44 - #define MOD_NAME "spear-adc" 41 + #define SPEAR_ADC_MOD_NAME "spear-adc" 45 42 46 - #define ADC_CHANNEL_NUM 8 43 + #define SPEAR_ADC_CHANNEL_NUM 8 47 44 48 - #define CLK_MIN 2500000 49 - #define CLK_MAX 20000000 45 + #define SPEAR_ADC_CLK_MIN 2500000 46 + #define SPEAR_ADC_CLK_MAX 20000000 50 47 51 48 struct adc_regs_spear3xx { 52 49 u32 status; 53 50 u32 average; 54 51 u32 scan_rate; 55 52 u32 clk; /* Not avail for 1340 & 1310 */ 56 - u32 ch_ctrl[ADC_CHANNEL_NUM]; 57 - u32 ch_data[ADC_CHANNEL_NUM]; 53 + u32 ch_ctrl[SPEAR_ADC_CHANNEL_NUM]; 54 + u32 ch_data[SPEAR_ADC_CHANNEL_NUM]; 58 55 }; 59 56 60 57 struct chan_data { ··· 63 66 u32 status; 64 67 u32 pad[2]; 65 68 u32 clk; 66 - u32 ch_ctrl[ADC_CHANNEL_NUM]; 67 - struct chan_data ch_data[ADC_CHANNEL_NUM]; 69 + u32 ch_ctrl[SPEAR_ADC_CHANNEL_NUM]; 70 + struct chan_data ch_data[SPEAR_ADC_CHANNEL_NUM]; 68 71 u32 scan_rate_lo; 69 72 u32 scan_rate_hi; 70 73 struct chan_data average; 71 74 }; 72 75 73 - struct spear_adc_info { 76 + struct spear_adc_state { 74 77 struct device_node *np; 75 78 struct adc_regs_spear3xx __iomem *adc_base_spear3xx; 76 79 struct adc_regs_spear6xx __iomem *adc_base_spear6xx; ··· 88 91 * static inline functions, because of different register offsets 89 92 * on different SoC variants (SPEAr300 vs SPEAr600 etc). 90 93 */ 91 - static void spear_adc_set_status(struct spear_adc_info *info, u32 val) 94 + static void spear_adc_set_status(struct spear_adc_state *st, u32 val) 92 95 { 93 - __raw_writel(val, &info->adc_base_spear6xx->status); 96 + __raw_writel(val, &st->adc_base_spear6xx->status); 94 97 } 95 98 96 - static void spear_adc_set_clk(struct spear_adc_info *info, u32 val) 99 + static void spear_adc_set_clk(struct spear_adc_state *st, u32 val) 97 100 { 98 101 u32 clk_high, clk_low, count; 99 - u32 apb_clk = clk_get_rate(info->clk); 102 + u32 apb_clk = clk_get_rate(st->clk); 100 103 101 104 count = (apb_clk + val - 1) / val; 102 105 clk_low = count / 2; 103 106 clk_high = count - clk_low; 104 - info->current_clk = apb_clk / count; 107 + st->current_clk = apb_clk / count; 105 108 106 - __raw_writel(CLK_LOW(clk_low) | CLK_HIGH(clk_high), 107 - &info->adc_base_spear6xx->clk); 109 + __raw_writel(SPEAR_ADC_CLK_LOW(clk_low) | SPEAR_ADC_CLK_HIGH(clk_high), 110 + &st->adc_base_spear6xx->clk); 108 111 } 109 112 110 - static void spear_adc_set_ctrl(struct spear_adc_info *info, int n, 113 + static void spear_adc_set_ctrl(struct spear_adc_state *st, int n, 111 114 u32 val) 112 115 { 113 - __raw_writel(val, &info->adc_base_spear6xx->ch_ctrl[n]); 116 + __raw_writel(val, &st->adc_base_spear6xx->ch_ctrl[n]); 114 117 } 115 118 116 - static u32 spear_adc_get_average(struct spear_adc_info *info) 119 + static u32 spear_adc_get_average(struct spear_adc_state *st) 117 120 { 118 - if (of_device_is_compatible(info->np, "st,spear600-adc")) { 119 - return __raw_readl(&info->adc_base_spear6xx->average.msb) & 120 - DATA_MASK; 121 + if (of_device_is_compatible(st->np, "st,spear600-adc")) { 122 + return __raw_readl(&st->adc_base_spear6xx->average.msb) & 123 + SPEAR_ADC_DATA_MASK; 121 124 } else { 122 - return __raw_readl(&info->adc_base_spear3xx->average) & 123 - DATA_MASK; 125 + return __raw_readl(&st->adc_base_spear3xx->average) & 126 + SPEAR_ADC_DATA_MASK; 124 127 } 125 128 } 126 129 127 - static void spear_adc_set_scanrate(struct spear_adc_info *info, u32 rate) 130 + static void spear_adc_set_scanrate(struct spear_adc_state *st, u32 rate) 128 131 { 129 - if (of_device_is_compatible(info->np, "st,spear600-adc")) { 130 - __raw_writel(SCAN_RATE_LO(rate), 131 - &info->adc_base_spear6xx->scan_rate_lo); 132 - __raw_writel(SCAN_RATE_HI(rate), 133 - &info->adc_base_spear6xx->scan_rate_hi); 132 + if (of_device_is_compatible(st->np, "st,spear600-adc")) { 133 + __raw_writel(SPEAR600_ADC_SCAN_RATE_LO(rate), 134 + &st->adc_base_spear6xx->scan_rate_lo); 135 + __raw_writel(SPEAR600_ADC_SCAN_RATE_HI(rate), 136 + &st->adc_base_spear6xx->scan_rate_hi); 134 137 } else { 135 - __raw_writel(rate, &info->adc_base_spear3xx->scan_rate); 138 + __raw_writel(rate, &st->adc_base_spear3xx->scan_rate); 136 139 } 137 140 } 138 141 139 - static int spear_read_raw(struct iio_dev *indio_dev, 140 - struct iio_chan_spec const *chan, 141 - int *val, 142 - int *val2, 143 - long mask) 142 + static int spear_adc_read_raw(struct iio_dev *indio_dev, 143 + struct iio_chan_spec const *chan, 144 + int *val, 145 + int *val2, 146 + long mask) 144 147 { 145 - struct spear_adc_info *info = iio_priv(indio_dev); 148 + struct spear_adc_state *st = iio_priv(indio_dev); 146 149 u32 status; 147 150 148 151 switch (mask) { 149 152 case IIO_CHAN_INFO_RAW: 150 153 mutex_lock(&indio_dev->mlock); 151 154 152 - status = CHANNEL_NUM(chan->channel) | 153 - AVG_SAMPLE(info->avg_samples) | 154 - START_CONVERSION | ADC_ENABLE; 155 - if (info->vref_external == 0) 156 - status |= VREF_INTERNAL; 155 + status = SPEAR_ADC_STATUS_CHANNEL_NUM(chan->channel) | 156 + SPEAR_ADC_STATUS_AVG_SAMPLE(st->avg_samples) | 157 + SPEAR_ADC_STATUS_START_CONVERSION | 158 + SPEAR_ADC_STATUS_ADC_ENABLE; 159 + if (st->vref_external == 0) 160 + status |= SPEAR_ADC_STATUS_VREF_INTERNAL; 157 161 158 - spear_adc_set_status(info, status); 159 - wait_for_completion(&info->completion); /* set by ISR */ 160 - *val = info->value; 162 + spear_adc_set_status(st, status); 163 + wait_for_completion(&st->completion); /* set by ISR */ 164 + *val = st->value; 161 165 162 166 mutex_unlock(&indio_dev->mlock); 163 167 164 168 return IIO_VAL_INT; 165 169 166 170 case IIO_CHAN_INFO_SCALE: 167 - *val = info->vref_external; 168 - *val2 = DATA_BITS; 171 + *val = st->vref_external; 172 + *val2 = SPEAR_ADC_DATA_BITS; 169 173 return IIO_VAL_FRACTIONAL_LOG2; 174 + case IIO_CHAN_INFO_SAMP_FREQ: 175 + *val = st->current_clk; 176 + return IIO_VAL_INT; 170 177 } 171 178 172 179 return -EINVAL; 180 + } 181 + 182 + static int spear_adc_write_raw(struct iio_dev *indio_dev, 183 + struct iio_chan_spec const *chan, 184 + int val, 185 + int val2, 186 + long mask) 187 + { 188 + struct spear_adc_state *st = iio_priv(indio_dev); 189 + int ret = 0; 190 + 191 + if (mask != IIO_CHAN_INFO_SAMP_FREQ) 192 + return -EINVAL; 193 + 194 + mutex_lock(&indio_dev->mlock); 195 + 196 + if ((val < SPEAR_ADC_CLK_MIN) || 197 + (val > SPEAR_ADC_CLK_MAX) || 198 + (val2 != 0)) { 199 + ret = -EINVAL; 200 + goto out; 201 + } 202 + 203 + spear_adc_set_clk(st, val); 204 + 205 + out: 206 + mutex_unlock(&indio_dev->mlock); 207 + return ret; 173 208 } 174 209 175 210 #define SPEAR_ADC_CHAN(idx) { \ ··· 209 180 .indexed = 1, \ 210 181 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 211 182 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 183 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\ 212 184 .channel = idx, \ 213 - .scan_type = { \ 214 - .sign = 'u', \ 215 - .storagebits = 16, \ 216 - }, \ 217 185 } 218 186 219 187 static const struct iio_chan_spec spear_adc_iio_channels[] = { ··· 226 200 227 201 static irqreturn_t spear_adc_isr(int irq, void *dev_id) 228 202 { 229 - struct spear_adc_info *info = (struct spear_adc_info *)dev_id; 203 + struct spear_adc_state *st = (struct spear_adc_state *)dev_id; 230 204 231 205 /* Read value to clear IRQ */ 232 - info->value = spear_adc_get_average(info); 233 - complete(&info->completion); 206 + st->value = spear_adc_get_average(st); 207 + complete(&st->completion); 234 208 235 209 return IRQ_HANDLED; 236 210 } 237 211 238 - static int spear_adc_configure(struct spear_adc_info *info) 212 + static int spear_adc_configure(struct spear_adc_state *st) 239 213 { 240 214 int i; 241 215 242 216 /* Reset ADC core */ 243 - spear_adc_set_status(info, 0); 244 - __raw_writel(0, &info->adc_base_spear6xx->clk); 217 + spear_adc_set_status(st, 0); 218 + __raw_writel(0, &st->adc_base_spear6xx->clk); 245 219 for (i = 0; i < 8; i++) 246 - spear_adc_set_ctrl(info, i, 0); 247 - spear_adc_set_scanrate(info, 0); 220 + spear_adc_set_ctrl(st, i, 0); 221 + spear_adc_set_scanrate(st, 0); 248 222 249 - spear_adc_set_clk(info, info->sampling_freq); 223 + spear_adc_set_clk(st, st->sampling_freq); 250 224 251 225 return 0; 252 226 } 253 227 254 - static ssize_t spear_adc_read_frequency(struct device *dev, 255 - struct device_attribute *attr, 256 - char *buf) 257 - { 258 - struct iio_dev *indio_dev = dev_to_iio_dev(dev); 259 - struct spear_adc_info *info = iio_priv(indio_dev); 260 - 261 - return sprintf(buf, "%d\n", info->current_clk); 262 - } 263 - 264 - static ssize_t spear_adc_write_frequency(struct device *dev, 265 - struct device_attribute *attr, 266 - const char *buf, 267 - size_t len) 268 - { 269 - struct iio_dev *indio_dev = dev_to_iio_dev(dev); 270 - struct spear_adc_info *info = iio_priv(indio_dev); 271 - u32 clk_high, clk_low, count; 272 - u32 apb_clk = clk_get_rate(info->clk); 273 - unsigned long lval; 274 - int ret; 275 - 276 - ret = kstrtoul(buf, 10, &lval); 277 - if (ret) 278 - return ret; 279 - 280 - mutex_lock(&indio_dev->mlock); 281 - 282 - if ((lval < CLK_MIN) || (lval > CLK_MAX)) { 283 - ret = -EINVAL; 284 - goto out; 285 - } 286 - 287 - count = (apb_clk + lval - 1) / lval; 288 - clk_low = count / 2; 289 - clk_high = count - clk_low; 290 - info->current_clk = apb_clk / count; 291 - spear_adc_set_clk(info, lval); 292 - 293 - out: 294 - mutex_unlock(&indio_dev->mlock); 295 - 296 - return ret ? ret : len; 297 - } 298 - 299 - static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, 300 - spear_adc_read_frequency, 301 - spear_adc_write_frequency); 302 - 303 - static struct attribute *spear_attributes[] = { 304 - &iio_dev_attr_sampling_frequency.dev_attr.attr, 305 - NULL 306 - }; 307 - 308 - static const struct attribute_group spear_attribute_group = { 309 - .attrs = spear_attributes, 310 - }; 311 - 312 - static const struct iio_info spear_adc_iio_info = { 313 - .read_raw = &spear_read_raw, 314 - .attrs = &spear_attribute_group, 228 + static const struct iio_info spear_adc_info = { 229 + .read_raw = &spear_adc_read_raw, 230 + .write_raw = &spear_adc_write_raw, 315 231 .driver_module = THIS_MODULE, 316 232 }; 317 233 ··· 261 293 { 262 294 struct device_node *np = pdev->dev.of_node; 263 295 struct device *dev = &pdev->dev; 264 - struct spear_adc_info *info; 265 - struct iio_dev *iodev = NULL; 296 + struct spear_adc_state *st; 297 + struct iio_dev *indio_dev = NULL; 266 298 int ret = -ENODEV; 267 299 int irq; 268 300 269 - iodev = devm_iio_device_alloc(dev, sizeof(struct spear_adc_info)); 270 - if (!iodev) { 301 + indio_dev = devm_iio_device_alloc(dev, sizeof(struct spear_adc_state)); 302 + if (!indio_dev) { 271 303 dev_err(dev, "failed allocating iio device\n"); 272 304 return -ENOMEM; 273 305 } 274 306 275 - info = iio_priv(iodev); 276 - info->np = np; 307 + st = iio_priv(indio_dev); 308 + st->np = np; 277 309 278 310 /* 279 311 * SPEAr600 has a different register layout than other SPEAr SoC's 280 312 * (e.g. SPEAr3xx). Let's provide two register base addresses 281 313 * to support multi-arch kernels. 282 314 */ 283 - info->adc_base_spear6xx = of_iomap(np, 0); 284 - if (!info->adc_base_spear6xx) { 315 + st->adc_base_spear6xx = of_iomap(np, 0); 316 + if (!st->adc_base_spear6xx) { 285 317 dev_err(dev, "failed mapping memory\n"); 286 318 return -ENOMEM; 287 319 } 288 - info->adc_base_spear3xx = 289 - (struct adc_regs_spear3xx __iomem *)info->adc_base_spear6xx; 320 + st->adc_base_spear3xx = 321 + (struct adc_regs_spear3xx __iomem *)st->adc_base_spear6xx; 290 322 291 - info->clk = clk_get(dev, NULL); 292 - if (IS_ERR(info->clk)) { 323 + st->clk = clk_get(dev, NULL); 324 + if (IS_ERR(st->clk)) { 293 325 dev_err(dev, "failed getting clock\n"); 294 326 goto errout1; 295 327 } 296 328 297 - ret = clk_prepare_enable(info->clk); 329 + ret = clk_prepare_enable(st->clk); 298 330 if (ret) { 299 331 dev_err(dev, "failed enabling clock\n"); 300 332 goto errout2; ··· 307 339 goto errout3; 308 340 } 309 341 310 - ret = devm_request_irq(dev, irq, spear_adc_isr, 0, MOD_NAME, info); 342 + ret = devm_request_irq(dev, irq, spear_adc_isr, 0, SPEAR_ADC_MOD_NAME, 343 + st); 311 344 if (ret < 0) { 312 345 dev_err(dev, "failed requesting interrupt\n"); 313 346 goto errout3; 314 347 } 315 348 316 349 if (of_property_read_u32(np, "sampling-frequency", 317 - &info->sampling_freq)) { 350 + &st->sampling_freq)) { 318 351 dev_err(dev, "sampling-frequency missing in DT\n"); 319 352 ret = -EINVAL; 320 353 goto errout3; ··· 325 356 * Optional avg_samples defaults to 0, resulting in single data 326 357 * conversion 327 358 */ 328 - of_property_read_u32(np, "average-samples", &info->avg_samples); 359 + of_property_read_u32(np, "average-samples", &st->avg_samples); 329 360 330 361 /* 331 362 * Optional vref_external defaults to 0, resulting in internal vref 332 363 * selection 333 364 */ 334 - of_property_read_u32(np, "vref-external", &info->vref_external); 365 + of_property_read_u32(np, "vref-external", &st->vref_external); 335 366 336 - spear_adc_configure(info); 367 + spear_adc_configure(st); 337 368 338 - platform_set_drvdata(pdev, iodev); 369 + platform_set_drvdata(pdev, indio_dev); 339 370 340 - init_completion(&info->completion); 371 + init_completion(&st->completion); 341 372 342 - iodev->name = MOD_NAME; 343 - iodev->dev.parent = dev; 344 - iodev->info = &spear_adc_iio_info; 345 - iodev->modes = INDIO_DIRECT_MODE; 346 - iodev->channels = spear_adc_iio_channels; 347 - iodev->num_channels = ARRAY_SIZE(spear_adc_iio_channels); 373 + indio_dev->name = SPEAR_ADC_MOD_NAME; 374 + indio_dev->dev.parent = dev; 375 + indio_dev->info = &spear_adc_info; 376 + indio_dev->modes = INDIO_DIRECT_MODE; 377 + indio_dev->channels = spear_adc_iio_channels; 378 + indio_dev->num_channels = ARRAY_SIZE(spear_adc_iio_channels); 348 379 349 - ret = iio_device_register(iodev); 380 + ret = iio_device_register(indio_dev); 350 381 if (ret) 351 382 goto errout3; 352 383 ··· 355 386 return 0; 356 387 357 388 errout3: 358 - clk_disable_unprepare(info->clk); 389 + clk_disable_unprepare(st->clk); 359 390 errout2: 360 - clk_put(info->clk); 391 + clk_put(st->clk); 361 392 errout1: 362 - iounmap(info->adc_base_spear6xx); 393 + iounmap(st->adc_base_spear6xx); 363 394 return ret; 364 395 } 365 396 366 397 static int spear_adc_remove(struct platform_device *pdev) 367 398 { 368 - struct iio_dev *iodev = platform_get_drvdata(pdev); 369 - struct spear_adc_info *info = iio_priv(iodev); 399 + struct iio_dev *indio_dev = platform_get_drvdata(pdev); 400 + struct spear_adc_state *st = iio_priv(indio_dev); 370 401 371 - iio_device_unregister(iodev); 372 - clk_disable_unprepare(info->clk); 373 - clk_put(info->clk); 374 - iounmap(info->adc_base_spear6xx); 402 + iio_device_unregister(indio_dev); 403 + clk_disable_unprepare(st->clk); 404 + clk_put(st->clk); 405 + iounmap(st->adc_base_spear6xx); 375 406 376 407 return 0; 377 408 } ··· 388 419 .probe = spear_adc_probe, 389 420 .remove = spear_adc_remove, 390 421 .driver = { 391 - .name = MOD_NAME, 422 + .name = SPEAR_ADC_MOD_NAME, 392 423 .owner = THIS_MODULE, 393 424 .of_match_table = of_match_ptr(spear_adc_dt_ids), 394 425 },
+2 -2
drivers/staging/iio/addac/adt7316.c
··· 172 172 #define ID_ADT75XX 0x10 173 173 174 174 /* 175 - * struct adt7316_chip_info - chip specifc information 175 + * struct adt7316_chip_info - chip specific information 176 176 */ 177 177 178 178 struct adt7316_chip_info { ··· 208 208 (ADT7316_TEMP_INT_MASK) 209 209 210 210 /* 211 - * struct adt7316_chip_info - chip specifc information 211 + * struct adt7316_chip_info - chip specific information 212 212 */ 213 213 214 214 struct adt7316_limit_regs {
+1 -1
drivers/staging/iio/cdc/ad7152.c
··· 78 78 }; 79 79 80 80 /* 81 - * struct ad7152_chip_info - chip specifc information 81 + * struct ad7152_chip_info - chip specific information 82 82 */ 83 83 84 84 struct ad7152_chip_info {
+1 -1
drivers/staging/iio/cdc/ad7746.c
··· 91 91 #define AD7746_CAPDAC_DACP(x) ((x) & 0x7F) 92 92 93 93 /* 94 - * struct ad7746_chip_info - chip specifc information 94 + * struct ad7746_chip_info - chip specific information 95 95 */ 96 96 97 97 struct ad7746_chip_info {
+4
include/linux/iio/common/st_sensors.h
··· 269 269 270 270 int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable); 271 271 272 + void st_sensors_power_enable(struct iio_dev *indio_dev); 273 + 274 + void st_sensors_power_disable(struct iio_dev *indio_dev); 275 + 272 276 int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr); 273 277 274 278 int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable);
+13
include/linux/iio/consumer.h
··· 123 123 int *val); 124 124 125 125 /** 126 + * iio_read_channel_average_raw() - read from a given channel 127 + * @chan: The channel being queried. 128 + * @val: Value read back. 129 + * 130 + * Note raw reads from iio channels are in adc counts and hence 131 + * scale will need to be applied if standard units required. 132 + * 133 + * In opposit to the normal iio_read_channel_raw this function 134 + * returns the average of multiple reads. 135 + */ 136 + int iio_read_channel_average_raw(struct iio_channel *chan, int *val); 137 + 138 + /** 126 139 * iio_read_channel_processed() - read processed value from a given channel 127 140 * @chan: The channel being queried. 128 141 * @val: Value read back.