diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-11-25 21:42:40 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-11-25 21:42:40 -0500 |
commit | 3ce5ae8d46eed6cdaf38f5c8276f8c66f403d0d6 (patch) | |
tree | 91e35051672245d46c20196e4fce7669d91e6f85 /drivers/iio | |
parent | fa590c222fbaa428edb2ce2194638906cea1400a (diff) | |
parent | 794a870e776717ccbd27676a551250613de9c40c (diff) |
Merge tag 'iio-for-3.14a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes:
First set of new features, drivers and cleanups for IIO in the 3.14 cycle.
This mostly consists of patches that didn't quite make the last cycle. Lots
of interesting things under review currently.
Core:
- Add devm_iio_device_register/unregister. I took some convincing on whether
there would be many devices that really were simple enough to need no
explicit actions on removal. Turns out there are some.
- Move some stray docs to above the relevant implemenation.
- Drop a redundant repeated check on the fact the trigger has actually changed
when there is a userspace attempt change it.
Drivers:
New drivers
- Freescale MPL3115A2 Pressure / temperature sensor
New functionality
- hid_sensors: add sensitivity support.
DT bindings
- tsl2563
- hmc5843
Cleanups
- Drop unused scan_type from viperboard adc driver.
- devm_iio_device_register used in viperboard, ad5421, ad5755, adis16130,
adxrs450, vcnl4000, adis16220, ad7816, lpc32xx, adt7316, adis16060, isl29018
and ad2s1200. Note that this was proposed in a number of other drivers
and this revealed a number of missorderings in remove functions. Also for
now I have blocked this on any device that any hardware suspend suport on
the basis that we probably want to power down devices if they have no driver
support loaded.
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/accel/hid-sensor-accel-3d.c | 12 | ||||
-rw-r--r-- | drivers/iio/adc/mcp3422.c | 9 | ||||
-rw-r--r-- | drivers/iio/adc/viperboard_adc.c | 20 | ||||
-rw-r--r-- | drivers/iio/dac/ad5421.c | 12 | ||||
-rw-r--r-- | drivers/iio/dac/ad5755.c | 12 | ||||
-rw-r--r-- | drivers/iio/gyro/adis16130.c | 9 | ||||
-rw-r--r-- | drivers/iio/gyro/adxrs450.c | 14 | ||||
-rw-r--r-- | drivers/iio/gyro/hid-sensor-gyro-3d.c | 11 | ||||
-rw-r--r-- | drivers/iio/industrialio-core.c | 101 | ||||
-rw-r--r-- | drivers/iio/industrialio-event.c | 6 | ||||
-rw-r--r-- | drivers/iio/industrialio-trigger.c | 28 | ||||
-rw-r--r-- | drivers/iio/light/hid-sensor-als.c | 11 | ||||
-rw-r--r-- | drivers/iio/light/tsl2563.c | 4 | ||||
-rw-r--r-- | drivers/iio/light/vcnl4000.c | 9 | ||||
-rw-r--r-- | drivers/iio/magnetometer/hid-sensor-magn-3d.c | 12 | ||||
-rw-r--r-- | drivers/iio/pressure/Kconfig | 12 | ||||
-rw-r--r-- | drivers/iio/pressure/Makefile | 1 | ||||
-rw-r--r-- | drivers/iio/pressure/mpl3115.c | 329 |
18 files changed, 534 insertions, 78 deletions
diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c index dcda17395c4e..6b8735ce8345 100644 --- a/drivers/iio/accel/hid-sensor-accel-3d.c +++ b/drivers/iio/accel/hid-sensor-accel-3d.c | |||
@@ -262,6 +262,18 @@ static int accel_3d_parse_report(struct platform_device *pdev, | |||
262 | st->accel[1].index, st->accel[1].report_id, | 262 | st->accel[1].index, st->accel[1].report_id, |
263 | st->accel[2].index, st->accel[2].report_id); | 263 | st->accel[2].index, st->accel[2].report_id); |
264 | 264 | ||
265 | /* Set Sensitivity field ids, when there is no individual modifier */ | ||
266 | if (st->common_attributes.sensitivity.index < 0) { | ||
267 | sensor_hub_input_get_attribute_info(hsdev, | ||
268 | HID_FEATURE_REPORT, usage_id, | ||
269 | HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | | ||
270 | HID_USAGE_SENSOR_DATA_ACCELERATION, | ||
271 | &st->common_attributes.sensitivity); | ||
272 | dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n", | ||
273 | st->common_attributes.sensitivity.index, | ||
274 | st->common_attributes.sensitivity.report_id); | ||
275 | } | ||
276 | |||
265 | return ret; | 277 | return ret; |
266 | } | 278 | } |
267 | 279 | ||
diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c index 12948325431c..dbdbd77f69ea 100644 --- a/drivers/iio/adc/mcp3422.c +++ b/drivers/iio/adc/mcp3422.c | |||
@@ -362,7 +362,7 @@ static int mcp3422_probe(struct i2c_client *client, | |||
362 | | MCP3422_SAMPLE_RATE_VALUE(MCP3422_SRATE_240)); | 362 | | MCP3422_SAMPLE_RATE_VALUE(MCP3422_SRATE_240)); |
363 | mcp3422_update_config(adc, config); | 363 | mcp3422_update_config(adc, config); |
364 | 364 | ||
365 | err = iio_device_register(indio_dev); | 365 | err = devm_iio_device_register(&client->dev, indio_dev); |
366 | if (err < 0) | 366 | if (err < 0) |
367 | return err; | 367 | return err; |
368 | 368 | ||
@@ -371,12 +371,6 @@ static int mcp3422_probe(struct i2c_client *client, | |||
371 | return 0; | 371 | return 0; |
372 | } | 372 | } |
373 | 373 | ||
374 | static int mcp3422_remove(struct i2c_client *client) | ||
375 | { | ||
376 | iio_device_unregister(i2c_get_clientdata(client)); | ||
377 | return 0; | ||
378 | } | ||
379 | |||
380 | static const struct i2c_device_id mcp3422_id[] = { | 374 | static const struct i2c_device_id mcp3422_id[] = { |
381 | { "mcp3422", 2 }, | 375 | { "mcp3422", 2 }, |
382 | { "mcp3423", 3 }, | 376 | { "mcp3423", 3 }, |
@@ -400,7 +394,6 @@ static struct i2c_driver mcp3422_driver = { | |||
400 | .of_match_table = of_match_ptr(mcp3422_of_match), | 394 | .of_match_table = of_match_ptr(mcp3422_of_match), |
401 | }, | 395 | }, |
402 | .probe = mcp3422_probe, | 396 | .probe = mcp3422_probe, |
403 | .remove = mcp3422_remove, | ||
404 | .id_table = mcp3422_id, | 397 | .id_table = mcp3422_id, |
405 | }; | 398 | }; |
406 | module_i2c_driver(mcp3422_driver); | 399 | module_i2c_driver(mcp3422_driver); |
diff --git a/drivers/iio/adc/viperboard_adc.c b/drivers/iio/adc/viperboard_adc.c index 09727a71e9fa..d0add8f9416b 100644 --- a/drivers/iio/adc/viperboard_adc.c +++ b/drivers/iio/adc/viperboard_adc.c | |||
@@ -42,12 +42,6 @@ struct vprbrd_adc { | |||
42 | .indexed = 1, \ | 42 | .indexed = 1, \ |
43 | .channel = _index, \ | 43 | .channel = _index, \ |
44 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | 44 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
45 | .scan_index = _index, \ | ||
46 | .scan_type = { \ | ||
47 | .sign = 'u', \ | ||
48 | .realbits = 8, \ | ||
49 | .storagebits = 8, \ | ||
50 | }, \ | ||
51 | } | 45 | } |
52 | 46 | ||
53 | static struct iio_chan_spec const vprbrd_adc_iio_channels[] = { | 47 | static struct iio_chan_spec const vprbrd_adc_iio_channels[] = { |
@@ -73,7 +67,7 @@ static int vprbrd_iio_read_raw(struct iio_dev *iio_dev, | |||
73 | mutex_lock(&vb->lock); | 67 | mutex_lock(&vb->lock); |
74 | 68 | ||
75 | admsg->cmd = VPRBRD_ADC_CMD_GET; | 69 | admsg->cmd = VPRBRD_ADC_CMD_GET; |
76 | admsg->chan = chan->scan_index; | 70 | admsg->chan = chan->channel; |
77 | admsg->val = 0x00; | 71 | admsg->val = 0x00; |
78 | 72 | ||
79 | ret = usb_control_msg(vb->usb_dev, | 73 | ret = usb_control_msg(vb->usb_dev, |
@@ -139,7 +133,7 @@ static int vprbrd_adc_probe(struct platform_device *pdev) | |||
139 | indio_dev->channels = vprbrd_adc_iio_channels; | 133 | indio_dev->channels = vprbrd_adc_iio_channels; |
140 | indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels); | 134 | indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels); |
141 | 135 | ||
142 | ret = iio_device_register(indio_dev); | 136 | ret = devm_iio_device_register(&pdev->dev, indio_dev); |
143 | if (ret) { | 137 | if (ret) { |
144 | dev_err(&pdev->dev, "could not register iio (adc)"); | 138 | dev_err(&pdev->dev, "could not register iio (adc)"); |
145 | return ret; | 139 | return ret; |
@@ -150,22 +144,12 @@ static int vprbrd_adc_probe(struct platform_device *pdev) | |||
150 | return 0; | 144 | return 0; |
151 | } | 145 | } |
152 | 146 | ||
153 | static int vprbrd_adc_remove(struct platform_device *pdev) | ||
154 | { | ||
155 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); | ||
156 | |||
157 | iio_device_unregister(indio_dev); | ||
158 | |||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | static struct platform_driver vprbrd_adc_driver = { | 147 | static struct platform_driver vprbrd_adc_driver = { |
163 | .driver = { | 148 | .driver = { |
164 | .name = "viperboard-adc", | 149 | .name = "viperboard-adc", |
165 | .owner = THIS_MODULE, | 150 | .owner = THIS_MODULE, |
166 | }, | 151 | }, |
167 | .probe = vprbrd_adc_probe, | 152 | .probe = vprbrd_adc_probe, |
168 | .remove = vprbrd_adc_remove, | ||
169 | }; | 153 | }; |
170 | 154 | ||
171 | module_platform_driver(vprbrd_adc_driver); | 155 | module_platform_driver(vprbrd_adc_driver); |
diff --git a/drivers/iio/dac/ad5421.c b/drivers/iio/dac/ad5421.c index 3eeaa82075f7..7d1e90811c71 100644 --- a/drivers/iio/dac/ad5421.c +++ b/drivers/iio/dac/ad5421.c | |||
@@ -514,16 +514,7 @@ static int ad5421_probe(struct spi_device *spi) | |||
514 | return ret; | 514 | return ret; |
515 | } | 515 | } |
516 | 516 | ||
517 | return iio_device_register(indio_dev); | 517 | return devm_iio_device_register(&spi->dev, indio_dev); |
518 | } | ||
519 | |||
520 | static int ad5421_remove(struct spi_device *spi) | ||
521 | { | ||
522 | struct iio_dev *indio_dev = spi_get_drvdata(spi); | ||
523 | |||
524 | iio_device_unregister(indio_dev); | ||
525 | |||
526 | return 0; | ||
527 | } | 518 | } |
528 | 519 | ||
529 | static struct spi_driver ad5421_driver = { | 520 | static struct spi_driver ad5421_driver = { |
@@ -532,7 +523,6 @@ static struct spi_driver ad5421_driver = { | |||
532 | .owner = THIS_MODULE, | 523 | .owner = THIS_MODULE, |
533 | }, | 524 | }, |
534 | .probe = ad5421_probe, | 525 | .probe = ad5421_probe, |
535 | .remove = ad5421_remove, | ||
536 | }; | 526 | }; |
537 | module_spi_driver(ad5421_driver); | 527 | module_spi_driver(ad5421_driver); |
538 | 528 | ||
diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c index 9a78d5abb2f6..ee1e95a3a0c3 100644 --- a/drivers/iio/dac/ad5755.c +++ b/drivers/iio/dac/ad5755.c | |||
@@ -589,16 +589,7 @@ static int ad5755_probe(struct spi_device *spi) | |||
589 | if (ret) | 589 | if (ret) |
590 | return ret; | 590 | return ret; |
591 | 591 | ||
592 | return iio_device_register(indio_dev); | 592 | return devm_iio_device_register(&spi->dev, indio_dev); |
593 | } | ||
594 | |||
595 | static int ad5755_remove(struct spi_device *spi) | ||
596 | { | ||
597 | struct iio_dev *indio_dev = spi_get_drvdata(spi); | ||
598 | |||
599 | iio_device_unregister(indio_dev); | ||
600 | |||
601 | return 0; | ||
602 | } | 593 | } |
603 | 594 | ||
604 | static const struct spi_device_id ad5755_id[] = { | 595 | static const struct spi_device_id ad5755_id[] = { |
@@ -617,7 +608,6 @@ static struct spi_driver ad5755_driver = { | |||
617 | .owner = THIS_MODULE, | 608 | .owner = THIS_MODULE, |
618 | }, | 609 | }, |
619 | .probe = ad5755_probe, | 610 | .probe = ad5755_probe, |
620 | .remove = ad5755_remove, | ||
621 | .id_table = ad5755_id, | 611 | .id_table = ad5755_id, |
622 | }; | 612 | }; |
623 | module_spi_driver(ad5755_driver); | 613 | module_spi_driver(ad5755_driver); |
diff --git a/drivers/iio/gyro/adis16130.c b/drivers/iio/gyro/adis16130.c index 445c2aecfadd..8d08c7ed1ea6 100644 --- a/drivers/iio/gyro/adis16130.c +++ b/drivers/iio/gyro/adis16130.c | |||
@@ -161,13 +161,7 @@ static int adis16130_probe(struct spi_device *spi) | |||
161 | indio_dev->info = &adis16130_info; | 161 | indio_dev->info = &adis16130_info; |
162 | indio_dev->modes = INDIO_DIRECT_MODE; | 162 | indio_dev->modes = INDIO_DIRECT_MODE; |
163 | 163 | ||
164 | return iio_device_register(indio_dev); | 164 | return devm_iio_device_register(&spi->dev, indio_dev); |
165 | } | ||
166 | |||
167 | static int adis16130_remove(struct spi_device *spi) | ||
168 | { | ||
169 | iio_device_unregister(spi_get_drvdata(spi)); | ||
170 | return 0; | ||
171 | } | 165 | } |
172 | 166 | ||
173 | static struct spi_driver adis16130_driver = { | 167 | static struct spi_driver adis16130_driver = { |
@@ -176,7 +170,6 @@ static struct spi_driver adis16130_driver = { | |||
176 | .owner = THIS_MODULE, | 170 | .owner = THIS_MODULE, |
177 | }, | 171 | }, |
178 | .probe = adis16130_probe, | 172 | .probe = adis16130_probe, |
179 | .remove = adis16130_remove, | ||
180 | }; | 173 | }; |
181 | module_spi_driver(adis16130_driver); | 174 | module_spi_driver(adis16130_driver); |
182 | 175 | ||
diff --git a/drivers/iio/gyro/adxrs450.c b/drivers/iio/gyro/adxrs450.c index 1e546ba7ba45..eb0e08ec9e20 100644 --- a/drivers/iio/gyro/adxrs450.c +++ b/drivers/iio/gyro/adxrs450.c | |||
@@ -434,23 +434,14 @@ static int adxrs450_probe(struct spi_device *spi) | |||
434 | indio_dev->num_channels = ARRAY_SIZE(adxrs450_channels); | 434 | indio_dev->num_channels = ARRAY_SIZE(adxrs450_channels); |
435 | indio_dev->name = spi->dev.driver->name; | 435 | indio_dev->name = spi->dev.driver->name; |
436 | 436 | ||
437 | ret = iio_device_register(indio_dev); | 437 | ret = devm_iio_device_register(&spi->dev, indio_dev); |
438 | if (ret) | 438 | if (ret) |
439 | return ret; | 439 | return ret; |
440 | 440 | ||
441 | /* Get the device into a sane initial state */ | 441 | /* Get the device into a sane initial state */ |
442 | ret = adxrs450_initial_setup(indio_dev); | 442 | ret = adxrs450_initial_setup(indio_dev); |
443 | if (ret) | 443 | if (ret) |
444 | goto error_initial; | 444 | return ret; |
445 | return 0; | ||
446 | error_initial: | ||
447 | iio_device_unregister(indio_dev); | ||
448 | return ret; | ||
449 | } | ||
450 | |||
451 | static int adxrs450_remove(struct spi_device *spi) | ||
452 | { | ||
453 | iio_device_unregister(spi_get_drvdata(spi)); | ||
454 | 445 | ||
455 | return 0; | 446 | return 0; |
456 | } | 447 | } |
@@ -468,7 +459,6 @@ static struct spi_driver adxrs450_driver = { | |||
468 | .owner = THIS_MODULE, | 459 | .owner = THIS_MODULE, |
469 | }, | 460 | }, |
470 | .probe = adxrs450_probe, | 461 | .probe = adxrs450_probe, |
471 | .remove = adxrs450_remove, | ||
472 | .id_table = adxrs450_id, | 462 | .id_table = adxrs450_id, |
473 | }; | 463 | }; |
474 | module_spi_driver(adxrs450_driver); | 464 | module_spi_driver(adxrs450_driver); |
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c index ea01c6bcfb56..97797dbaad34 100644 --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c | |||
@@ -262,6 +262,17 @@ static int gyro_3d_parse_report(struct platform_device *pdev, | |||
262 | st->gyro[1].index, st->gyro[1].report_id, | 262 | st->gyro[1].index, st->gyro[1].report_id, |
263 | st->gyro[2].index, st->gyro[2].report_id); | 263 | st->gyro[2].index, st->gyro[2].report_id); |
264 | 264 | ||
265 | /* Set Sensitivity field ids, when there is no individual modifier */ | ||
266 | if (st->common_attributes.sensitivity.index < 0) { | ||
267 | sensor_hub_input_get_attribute_info(hsdev, | ||
268 | HID_FEATURE_REPORT, usage_id, | ||
269 | HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | | ||
270 | HID_USAGE_SENSOR_DATA_ANGL_VELOCITY, | ||
271 | &st->common_attributes.sensitivity); | ||
272 | dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n", | ||
273 | st->common_attributes.sensitivity.index, | ||
274 | st->common_attributes.sensitivity.report_id); | ||
275 | } | ||
265 | return ret; | 276 | return ret; |
266 | } | 277 | } |
267 | 278 | ||
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 18f72e3d0ed6..2fe88c189f74 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c | |||
@@ -107,6 +107,11 @@ static const char * const iio_chan_info_postfix[] = { | |||
107 | [IIO_CHAN_INFO_INT_TIME] = "integration_time", | 107 | [IIO_CHAN_INFO_INT_TIME] = "integration_time", |
108 | }; | 108 | }; |
109 | 109 | ||
110 | /** | ||
111 | * iio_find_channel_from_si() - get channel from its scan index | ||
112 | * @indio_dev: device | ||
113 | * @si: scan index to match | ||
114 | */ | ||
110 | const struct iio_chan_spec | 115 | const struct iio_chan_spec |
111 | *iio_find_channel_from_si(struct iio_dev *indio_dev, int si) | 116 | *iio_find_channel_from_si(struct iio_dev *indio_dev, int si) |
112 | { | 117 | { |
@@ -922,6 +927,10 @@ struct device_type iio_device_type = { | |||
922 | .release = iio_dev_release, | 927 | .release = iio_dev_release, |
923 | }; | 928 | }; |
924 | 929 | ||
930 | /** | ||
931 | * iio_device_alloc() - allocate an iio_dev from a driver | ||
932 | * @sizeof_priv: Space to allocate for private structure. | ||
933 | **/ | ||
925 | struct iio_dev *iio_device_alloc(int sizeof_priv) | 934 | struct iio_dev *iio_device_alloc(int sizeof_priv) |
926 | { | 935 | { |
927 | struct iio_dev *dev; | 936 | struct iio_dev *dev; |
@@ -962,6 +971,10 @@ struct iio_dev *iio_device_alloc(int sizeof_priv) | |||
962 | } | 971 | } |
963 | EXPORT_SYMBOL(iio_device_alloc); | 972 | EXPORT_SYMBOL(iio_device_alloc); |
964 | 973 | ||
974 | /** | ||
975 | * iio_device_free() - free an iio_dev from a driver | ||
976 | * @dev: the iio_dev associated with the device | ||
977 | **/ | ||
965 | void iio_device_free(struct iio_dev *dev) | 978 | void iio_device_free(struct iio_dev *dev) |
966 | { | 979 | { |
967 | if (dev) | 980 | if (dev) |
@@ -984,6 +997,20 @@ static int devm_iio_device_match(struct device *dev, void *res, void *data) | |||
984 | return *r == data; | 997 | return *r == data; |
985 | } | 998 | } |
986 | 999 | ||
1000 | /** | ||
1001 | * devm_iio_device_alloc - Resource-managed iio_device_alloc() | ||
1002 | * @dev: Device to allocate iio_dev for | ||
1003 | * @sizeof_priv: Space to allocate for private structure. | ||
1004 | * | ||
1005 | * Managed iio_device_alloc. iio_dev allocated with this function is | ||
1006 | * automatically freed on driver detach. | ||
1007 | * | ||
1008 | * If an iio_dev allocated with this function needs to be freed separately, | ||
1009 | * devm_iio_device_free() must be used. | ||
1010 | * | ||
1011 | * RETURNS: | ||
1012 | * Pointer to allocated iio_dev on success, NULL on failure. | ||
1013 | */ | ||
987 | struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv) | 1014 | struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv) |
988 | { | 1015 | { |
989 | struct iio_dev **ptr, *iio_dev; | 1016 | struct iio_dev **ptr, *iio_dev; |
@@ -1006,6 +1033,13 @@ struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv) | |||
1006 | } | 1033 | } |
1007 | EXPORT_SYMBOL_GPL(devm_iio_device_alloc); | 1034 | EXPORT_SYMBOL_GPL(devm_iio_device_alloc); |
1008 | 1035 | ||
1036 | /** | ||
1037 | * devm_iio_device_free - Resource-managed iio_device_free() | ||
1038 | * @dev: Device this iio_dev belongs to | ||
1039 | * @iio_dev: the iio_dev associated with the device | ||
1040 | * | ||
1041 | * Free iio_dev allocated with devm_iio_device_alloc(). | ||
1042 | */ | ||
1009 | void devm_iio_device_free(struct device *dev, struct iio_dev *iio_dev) | 1043 | void devm_iio_device_free(struct device *dev, struct iio_dev *iio_dev) |
1010 | { | 1044 | { |
1011 | int rc; | 1045 | int rc; |
@@ -1080,6 +1114,10 @@ static const struct file_operations iio_buffer_fileops = { | |||
1080 | 1114 | ||
1081 | static const struct iio_buffer_setup_ops noop_ring_setup_ops; | 1115 | static const struct iio_buffer_setup_ops noop_ring_setup_ops; |
1082 | 1116 | ||
1117 | /** | ||
1118 | * iio_device_register() - register a device with the IIO subsystem | ||
1119 | * @indio_dev: Device structure filled by the device driver | ||
1120 | **/ | ||
1083 | int iio_device_register(struct iio_dev *indio_dev) | 1121 | int iio_device_register(struct iio_dev *indio_dev) |
1084 | { | 1122 | { |
1085 | int ret; | 1123 | int ret; |
@@ -1141,6 +1179,10 @@ error_ret: | |||
1141 | } | 1179 | } |
1142 | EXPORT_SYMBOL(iio_device_register); | 1180 | EXPORT_SYMBOL(iio_device_register); |
1143 | 1181 | ||
1182 | /** | ||
1183 | * iio_device_unregister() - unregister a device from the IIO subsystem | ||
1184 | * @indio_dev: Device structure representing the device. | ||
1185 | **/ | ||
1144 | void iio_device_unregister(struct iio_dev *indio_dev) | 1186 | void iio_device_unregister(struct iio_dev *indio_dev) |
1145 | { | 1187 | { |
1146 | mutex_lock(&indio_dev->info_exist_lock); | 1188 | mutex_lock(&indio_dev->info_exist_lock); |
@@ -1161,6 +1203,65 @@ void iio_device_unregister(struct iio_dev *indio_dev) | |||
1161 | mutex_unlock(&indio_dev->info_exist_lock); | 1203 | mutex_unlock(&indio_dev->info_exist_lock); |
1162 | } | 1204 | } |
1163 | EXPORT_SYMBOL(iio_device_unregister); | 1205 | EXPORT_SYMBOL(iio_device_unregister); |
1206 | |||
1207 | static void devm_iio_device_unreg(struct device *dev, void *res) | ||
1208 | { | ||
1209 | iio_device_unregister(*(struct iio_dev **)res); | ||
1210 | } | ||
1211 | |||
1212 | /** | ||
1213 | * devm_iio_device_register - Resource-managed iio_device_register() | ||
1214 | * @dev: Device to allocate iio_dev for | ||
1215 | * @indio_dev: Device structure filled by the device driver | ||
1216 | * | ||
1217 | * Managed iio_device_register. The IIO device registered with this | ||
1218 | * function is automatically unregistered on driver detach. This function | ||
1219 | * calls iio_device_register() internally. Refer to that function for more | ||
1220 | * information. | ||
1221 | * | ||
1222 | * If an iio_dev registered with this function needs to be unregistered | ||
1223 | * separately, devm_iio_device_unregister() must be used. | ||
1224 | * | ||
1225 | * RETURNS: | ||
1226 | * 0 on success, negative error number on failure. | ||
1227 | */ | ||
1228 | int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev) | ||
1229 | { | ||
1230 | struct iio_dev **ptr; | ||
1231 | int ret; | ||
1232 | |||
1233 | ptr = devres_alloc(devm_iio_device_unreg, sizeof(*ptr), GFP_KERNEL); | ||
1234 | if (!ptr) | ||
1235 | return -ENOMEM; | ||
1236 | |||
1237 | *ptr = indio_dev; | ||
1238 | ret = iio_device_register(indio_dev); | ||
1239 | if (!ret) | ||
1240 | devres_add(dev, ptr); | ||
1241 | else | ||
1242 | devres_free(ptr); | ||
1243 | |||
1244 | return ret; | ||
1245 | } | ||
1246 | EXPORT_SYMBOL_GPL(devm_iio_device_register); | ||
1247 | |||
1248 | /** | ||
1249 | * devm_iio_device_unregister - Resource-managed iio_device_unregister() | ||
1250 | * @dev: Device this iio_dev belongs to | ||
1251 | * @indio_dev: the iio_dev associated with the device | ||
1252 | * | ||
1253 | * Unregister iio_dev registered with devm_iio_device_register(). | ||
1254 | */ | ||
1255 | void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev) | ||
1256 | { | ||
1257 | int rc; | ||
1258 | |||
1259 | rc = devres_release(dev, devm_iio_device_unreg, | ||
1260 | devm_iio_device_match, indio_dev); | ||
1261 | WARN_ON(rc); | ||
1262 | } | ||
1263 | EXPORT_SYMBOL_GPL(devm_iio_device_unregister); | ||
1264 | |||
1164 | subsys_initcall(iio_init); | 1265 | subsys_initcall(iio_init); |
1165 | module_exit(iio_exit); | 1266 | module_exit(iio_exit); |
1166 | 1267 | ||
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c index c10eab64bc05..bc043fab4cd1 100644 --- a/drivers/iio/industrialio-event.c +++ b/drivers/iio/industrialio-event.c | |||
@@ -42,6 +42,12 @@ struct iio_event_interface { | |||
42 | struct attribute_group group; | 42 | struct attribute_group group; |
43 | }; | 43 | }; |
44 | 44 | ||
45 | /** | ||
46 | * iio_push_event() - try to add event to the list for userspace reading | ||
47 | * @indio_dev: IIO device structure | ||
48 | * @ev_code: What event | ||
49 | * @timestamp: When the event occurred | ||
50 | **/ | ||
45 | int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp) | 51 | int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp) |
46 | { | 52 | { |
47 | struct iio_event_interface *ev_int = indio_dev->event_interface; | 53 | struct iio_event_interface *ev_int = indio_dev->event_interface; |
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index bf5e70a32d3f..7ba2f002ffca 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c | |||
@@ -318,7 +318,7 @@ static ssize_t iio_trigger_read_current(struct device *dev, | |||
318 | * iio_trigger_write_current() - trigger consumer sysfs set current trigger | 318 | * iio_trigger_write_current() - trigger consumer sysfs set current trigger |
319 | * | 319 | * |
320 | * For trigger consumers the current_trigger interface allows the trigger | 320 | * For trigger consumers the current_trigger interface allows the trigger |
321 | * used for this device to be specified at run time based on the triggers | 321 | * used for this device to be specified at run time based on the trigger's |
322 | * name. | 322 | * name. |
323 | **/ | 323 | **/ |
324 | static ssize_t iio_trigger_write_current(struct device *dev, | 324 | static ssize_t iio_trigger_write_current(struct device *dev, |
@@ -356,7 +356,7 @@ static ssize_t iio_trigger_write_current(struct device *dev, | |||
356 | 356 | ||
357 | indio_dev->trig = trig; | 357 | indio_dev->trig = trig; |
358 | 358 | ||
359 | if (oldtrig && indio_dev->trig != oldtrig) | 359 | if (oldtrig) |
360 | iio_trigger_put(oldtrig); | 360 | iio_trigger_put(oldtrig); |
361 | if (indio_dev->trig) | 361 | if (indio_dev->trig) |
362 | iio_trigger_get(indio_dev->trig); | 362 | iio_trigger_get(indio_dev->trig); |
@@ -506,6 +506,23 @@ static int devm_iio_trigger_match(struct device *dev, void *res, void *data) | |||
506 | return *r == data; | 506 | return *r == data; |
507 | } | 507 | } |
508 | 508 | ||
509 | /** | ||
510 | * devm_iio_trigger_alloc - Resource-managed iio_trigger_alloc() | ||
511 | * @dev: Device to allocate iio_trigger for | ||
512 | * @fmt: trigger name format. If it includes format | ||
513 | * specifiers, the additional arguments following | ||
514 | * format are formatted and inserted in the resulting | ||
515 | * string replacing their respective specifiers. | ||
516 | * | ||
517 | * Managed iio_trigger_alloc. iio_trigger allocated with this function is | ||
518 | * automatically freed on driver detach. | ||
519 | * | ||
520 | * If an iio_trigger allocated with this function needs to be freed separately, | ||
521 | * devm_iio_trigger_free() must be used. | ||
522 | * | ||
523 | * RETURNS: | ||
524 | * Pointer to allocated iio_trigger on success, NULL on failure. | ||
525 | */ | ||
509 | struct iio_trigger *devm_iio_trigger_alloc(struct device *dev, | 526 | struct iio_trigger *devm_iio_trigger_alloc(struct device *dev, |
510 | const char *fmt, ...) | 527 | const char *fmt, ...) |
511 | { | 528 | { |
@@ -532,6 +549,13 @@ struct iio_trigger *devm_iio_trigger_alloc(struct device *dev, | |||
532 | } | 549 | } |
533 | EXPORT_SYMBOL_GPL(devm_iio_trigger_alloc); | 550 | EXPORT_SYMBOL_GPL(devm_iio_trigger_alloc); |
534 | 551 | ||
552 | /** | ||
553 | * devm_iio_trigger_free - Resource-managed iio_trigger_free() | ||
554 | * @dev: Device this iio_dev belongs to | ||
555 | * @iio_trig: the iio_trigger associated with the device | ||
556 | * | ||
557 | * Free iio_trigger allocated with devm_iio_trigger_alloc(). | ||
558 | */ | ||
535 | void devm_iio_trigger_free(struct device *dev, struct iio_trigger *iio_trig) | 559 | void devm_iio_trigger_free(struct device *dev, struct iio_trigger *iio_trig) |
536 | { | 560 | { |
537 | int rc; | 561 | int rc; |
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index fa6ae8cf89ea..0c7f115ee3b3 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c | |||
@@ -229,6 +229,17 @@ static int als_parse_report(struct platform_device *pdev, | |||
229 | dev_dbg(&pdev->dev, "als %x:%x\n", st->als_illum.index, | 229 | dev_dbg(&pdev->dev, "als %x:%x\n", st->als_illum.index, |
230 | st->als_illum.report_id); | 230 | st->als_illum.report_id); |
231 | 231 | ||
232 | /* Set Sensitivity field ids, when there is no individual modifier */ | ||
233 | if (st->common_attributes.sensitivity.index < 0) { | ||
234 | sensor_hub_input_get_attribute_info(hsdev, | ||
235 | HID_FEATURE_REPORT, usage_id, | ||
236 | HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | | ||
237 | HID_USAGE_SENSOR_DATA_LIGHT, | ||
238 | &st->common_attributes.sensitivity); | ||
239 | dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n", | ||
240 | st->common_attributes.sensitivity.index, | ||
241 | st->common_attributes.sensitivity.report_id); | ||
242 | } | ||
232 | return ret; | 243 | return ret; |
233 | } | 244 | } |
234 | 245 | ||
diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c index 5e5d9dea22c5..0c6e459c86b1 100644 --- a/drivers/iio/light/tsl2563.c +++ b/drivers/iio/light/tsl2563.c | |||
@@ -714,6 +714,7 @@ static int tsl2563_probe(struct i2c_client *client, | |||
714 | struct iio_dev *indio_dev; | 714 | struct iio_dev *indio_dev; |
715 | struct tsl2563_chip *chip; | 715 | struct tsl2563_chip *chip; |
716 | struct tsl2563_platform_data *pdata = client->dev.platform_data; | 716 | struct tsl2563_platform_data *pdata = client->dev.platform_data; |
717 | struct device_node *np = client->dev.of_node; | ||
717 | int err = 0; | 718 | int err = 0; |
718 | u8 id = 0; | 719 | u8 id = 0; |
719 | 720 | ||
@@ -750,6 +751,9 @@ static int tsl2563_probe(struct i2c_client *client, | |||
750 | 751 | ||
751 | if (pdata) | 752 | if (pdata) |
752 | chip->cover_comp_gain = pdata->cover_comp_gain; | 753 | chip->cover_comp_gain = pdata->cover_comp_gain; |
754 | else if (np) | ||
755 | of_property_read_u32(np, "amstaos,cover-comp-gain", | ||
756 | &chip->cover_comp_gain); | ||
753 | else | 757 | else |
754 | chip->cover_comp_gain = 1; | 758 | chip->cover_comp_gain = 1; |
755 | 759 | ||
diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c index ecb3341ef9c0..384ac23f576f 100644 --- a/drivers/iio/light/vcnl4000.c +++ b/drivers/iio/light/vcnl4000.c | |||
@@ -179,13 +179,7 @@ static int vcnl4000_probe(struct i2c_client *client, | |||
179 | indio_dev->name = VCNL4000_DRV_NAME; | 179 | indio_dev->name = VCNL4000_DRV_NAME; |
180 | indio_dev->modes = INDIO_DIRECT_MODE; | 180 | indio_dev->modes = INDIO_DIRECT_MODE; |
181 | 181 | ||
182 | return iio_device_register(indio_dev); | 182 | return devm_iio_device_register(&client->dev, indio_dev); |
183 | } | ||
184 | |||
185 | static int vcnl4000_remove(struct i2c_client *client) | ||
186 | { | ||
187 | iio_device_unregister(i2c_get_clientdata(client)); | ||
188 | return 0; | ||
189 | } | 183 | } |
190 | 184 | ||
191 | static struct i2c_driver vcnl4000_driver = { | 185 | static struct i2c_driver vcnl4000_driver = { |
@@ -194,7 +188,6 @@ static struct i2c_driver vcnl4000_driver = { | |||
194 | .owner = THIS_MODULE, | 188 | .owner = THIS_MODULE, |
195 | }, | 189 | }, |
196 | .probe = vcnl4000_probe, | 190 | .probe = vcnl4000_probe, |
197 | .remove = vcnl4000_remove, | ||
198 | .id_table = vcnl4000_id, | 191 | .id_table = vcnl4000_id, |
199 | }; | 192 | }; |
200 | 193 | ||
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c index 2634920562fb..67fce1916d21 100644 --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c | |||
@@ -263,6 +263,18 @@ static int magn_3d_parse_report(struct platform_device *pdev, | |||
263 | st->magn[1].index, st->magn[1].report_id, | 263 | st->magn[1].index, st->magn[1].report_id, |
264 | st->magn[2].index, st->magn[2].report_id); | 264 | st->magn[2].index, st->magn[2].report_id); |
265 | 265 | ||
266 | /* Set Sensitivity field ids, when there is no individual modifier */ | ||
267 | if (st->common_attributes.sensitivity.index < 0) { | ||
268 | sensor_hub_input_get_attribute_info(hsdev, | ||
269 | HID_FEATURE_REPORT, usage_id, | ||
270 | HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | | ||
271 | HID_USAGE_SENSOR_DATA_ORIENTATION, | ||
272 | &st->common_attributes.sensitivity); | ||
273 | dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n", | ||
274 | st->common_attributes.sensitivity.index, | ||
275 | st->common_attributes.sensitivity.report_id); | ||
276 | } | ||
277 | |||
266 | return ret; | 278 | return ret; |
267 | } | 279 | } |
268 | 280 | ||
diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig index 4f2e0f9bad8c..a8b9cae5c173 100644 --- a/drivers/iio/pressure/Kconfig +++ b/drivers/iio/pressure/Kconfig | |||
@@ -5,6 +5,18 @@ | |||
5 | 5 | ||
6 | menu "Pressure sensors" | 6 | menu "Pressure sensors" |
7 | 7 | ||
8 | config MPL3115 | ||
9 | tristate "Freescale MPL3115A2 pressure sensor driver" | ||
10 | depends on I2C | ||
11 | select IIO_BUFFER | ||
12 | select IIO_TRIGGERED_BUFFER | ||
13 | help | ||
14 | Say yes here to build support for the Freescale MPL3115A2 | ||
15 | pressure sensor / altimeter. | ||
16 | |||
17 | To compile this driver as a module, choose M here: the module | ||
18 | will be called mpl3115. | ||
19 | |||
8 | config IIO_ST_PRESS | 20 | config IIO_ST_PRESS |
9 | tristate "STMicroelectronics pressure sensor Driver" | 21 | tristate "STMicroelectronics pressure sensor Driver" |
10 | depends on (I2C || SPI_MASTER) && SYSFS | 22 | depends on (I2C || SPI_MASTER) && SYSFS |
diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile index be71464c2752..42bb9fcf5436 100644 --- a/drivers/iio/pressure/Makefile +++ b/drivers/iio/pressure/Makefile | |||
@@ -3,6 +3,7 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | # When adding new entries keep the list in alphabetical order | 5 | # When adding new entries keep the list in alphabetical order |
6 | obj-$(CONFIG_MPL3115) += mpl3115.o | ||
6 | obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o | 7 | obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o |
7 | st_pressure-y := st_pressure_core.o | 8 | st_pressure-y := st_pressure_core.o |
8 | st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o | 9 | st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o |
diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c new file mode 100644 index 000000000000..ac8c8ab723e5 --- /dev/null +++ b/drivers/iio/pressure/mpl3115.c | |||
@@ -0,0 +1,329 @@ | |||
1 | /* | ||
2 | * mpl3115.c - Support for Freescale MPL3115A2 pressure/temperature sensor | ||
3 | * | ||
4 | * Copyright (c) 2013 Peter Meerwald <pmeerw@pmeerw.net> | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of version 2 of | ||
7 | * the GNU General Public License. See the file COPYING in the main | ||
8 | * directory of this archive for more details. | ||
9 | * | ||
10 | * (7-bit I2C slave address 0x60) | ||
11 | * | ||
12 | * TODO: FIFO buffer, altimeter mode, oversampling, continuous mode, | ||
13 | * interrupts, user offset correction, raw mode | ||
14 | */ | ||
15 | |||
16 | #include <linux/module.h> | ||
17 | #include <linux/i2c.h> | ||
18 | #include <linux/iio/iio.h> | ||
19 | #include <linux/iio/sysfs.h> | ||
20 | #include <linux/iio/trigger_consumer.h> | ||
21 | #include <linux/iio/buffer.h> | ||
22 | #include <linux/iio/triggered_buffer.h> | ||
23 | #include <linux/delay.h> | ||
24 | |||
25 | #define MPL3115_STATUS 0x00 | ||
26 | #define MPL3115_OUT_PRESS 0x01 /* MSB first, 20 bit */ | ||
27 | #define MPL3115_OUT_TEMP 0x04 /* MSB first, 12 bit */ | ||
28 | #define MPL3115_WHO_AM_I 0x0c | ||
29 | #define MPL3115_CTRL_REG1 0x26 | ||
30 | |||
31 | #define MPL3115_DEVICE_ID 0xc4 | ||
32 | |||
33 | #define MPL3115_STATUS_PRESS_RDY BIT(2) | ||
34 | #define MPL3115_STATUS_TEMP_RDY BIT(1) | ||
35 | |||
36 | #define MPL3115_CTRL_RESET BIT(2) /* software reset */ | ||
37 | #define MPL3115_CTRL_OST BIT(1) /* initiate measurement */ | ||
38 | #define MPL3115_CTRL_ACTIVE BIT(0) /* continuous measurement */ | ||
39 | #define MPL3115_CTRL_OS_258MS (BIT(5) | BIT(4)) /* 64x oversampling */ | ||
40 | |||
41 | struct mpl3115_data { | ||
42 | struct i2c_client *client; | ||
43 | struct mutex lock; | ||
44 | u8 ctrl_reg1; | ||
45 | }; | ||
46 | |||
47 | static int mpl3115_request(struct mpl3115_data *data) | ||
48 | { | ||
49 | int ret, tries = 15; | ||
50 | |||
51 | /* trigger measurement */ | ||
52 | ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1, | ||
53 | data->ctrl_reg1 | MPL3115_CTRL_OST); | ||
54 | if (ret < 0) | ||
55 | return ret; | ||
56 | |||
57 | while (tries-- > 0) { | ||
58 | ret = i2c_smbus_read_byte_data(data->client, MPL3115_CTRL_REG1); | ||
59 | if (ret < 0) | ||
60 | return ret; | ||
61 | /* wait for data ready, i.e. OST cleared */ | ||
62 | if (!(ret & MPL3115_CTRL_OST)) | ||
63 | break; | ||
64 | msleep(20); | ||
65 | } | ||
66 | |||
67 | if (tries < 0) { | ||
68 | dev_err(&data->client->dev, "data not ready\n"); | ||
69 | return -EIO; | ||
70 | } | ||
71 | |||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | static int mpl3115_read_raw(struct iio_dev *indio_dev, | ||
76 | struct iio_chan_spec const *chan, | ||
77 | int *val, int *val2, long mask) | ||
78 | { | ||
79 | struct mpl3115_data *data = iio_priv(indio_dev); | ||
80 | s32 tmp = 0; | ||
81 | int ret; | ||
82 | |||
83 | switch (mask) { | ||
84 | case IIO_CHAN_INFO_RAW: | ||
85 | if (iio_buffer_enabled(indio_dev)) | ||
86 | return -EBUSY; | ||
87 | |||
88 | switch (chan->type) { | ||
89 | case IIO_PRESSURE: /* in 0.25 pascal / LSB */ | ||
90 | mutex_lock(&data->lock); | ||
91 | ret = mpl3115_request(data); | ||
92 | if (ret < 0) { | ||
93 | mutex_unlock(&data->lock); | ||
94 | return ret; | ||
95 | } | ||
96 | ret = i2c_smbus_read_i2c_block_data(data->client, | ||
97 | MPL3115_OUT_PRESS, 3, (u8 *) &tmp); | ||
98 | mutex_unlock(&data->lock); | ||
99 | if (ret < 0) | ||
100 | return ret; | ||
101 | *val = sign_extend32(be32_to_cpu(tmp) >> 12, 23); | ||
102 | return IIO_VAL_INT; | ||
103 | case IIO_TEMP: /* in 0.0625 celsius / LSB */ | ||
104 | mutex_lock(&data->lock); | ||
105 | ret = mpl3115_request(data); | ||
106 | if (ret < 0) { | ||
107 | mutex_unlock(&data->lock); | ||
108 | return ret; | ||
109 | } | ||
110 | ret = i2c_smbus_read_i2c_block_data(data->client, | ||
111 | MPL3115_OUT_TEMP, 2, (u8 *) &tmp); | ||
112 | mutex_unlock(&data->lock); | ||
113 | if (ret < 0) | ||
114 | return ret; | ||
115 | *val = sign_extend32(be32_to_cpu(tmp) >> 20, 15); | ||
116 | return IIO_VAL_INT; | ||
117 | default: | ||
118 | return -EINVAL; | ||
119 | } | ||
120 | case IIO_CHAN_INFO_SCALE: | ||
121 | switch (chan->type) { | ||
122 | case IIO_PRESSURE: | ||
123 | *val = 0; | ||
124 | *val2 = 250; /* want kilopascal */ | ||
125 | return IIO_VAL_INT_PLUS_MICRO; | ||
126 | case IIO_TEMP: | ||
127 | *val = 0; | ||
128 | *val2 = 62500; | ||
129 | return IIO_VAL_INT_PLUS_MICRO; | ||
130 | default: | ||
131 | return -EINVAL; | ||
132 | } | ||
133 | } | ||
134 | return -EINVAL; | ||
135 | } | ||
136 | |||
137 | static irqreturn_t mpl3115_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 mpl3115_data *data = iio_priv(indio_dev); | ||
142 | u8 buffer[16]; /* 32-bit channel + 16-bit channel + padding + ts */ | ||
143 | int ret, pos = 0; | ||
144 | |||
145 | mutex_lock(&data->lock); | ||
146 | ret = mpl3115_request(data); | ||
147 | if (ret < 0) { | ||
148 | mutex_unlock(&data->lock); | ||
149 | goto done; | ||
150 | } | ||
151 | |||
152 | memset(buffer, 0, sizeof(buffer)); | ||
153 | if (test_bit(0, indio_dev->active_scan_mask)) { | ||
154 | ret = i2c_smbus_read_i2c_block_data(data->client, | ||
155 | MPL3115_OUT_PRESS, 3, &buffer[pos]); | ||
156 | if (ret < 0) { | ||
157 | mutex_unlock(&data->lock); | ||
158 | goto done; | ||
159 | } | ||
160 | pos += 4; | ||
161 | } | ||
162 | |||
163 | if (test_bit(1, indio_dev->active_scan_mask)) { | ||
164 | ret = i2c_smbus_read_i2c_block_data(data->client, | ||
165 | MPL3115_OUT_TEMP, 2, &buffer[pos]); | ||
166 | if (ret < 0) { | ||
167 | mutex_unlock(&data->lock); | ||
168 | goto done; | ||
169 | } | ||
170 | } | ||
171 | mutex_unlock(&data->lock); | ||
172 | |||
173 | iio_push_to_buffers_with_timestamp(indio_dev, buffer, | ||
174 | iio_get_time_ns()); | ||
175 | |||
176 | done: | ||
177 | iio_trigger_notify_done(indio_dev->trig); | ||
178 | return IRQ_HANDLED; | ||
179 | } | ||
180 | |||
181 | static const struct iio_chan_spec mpl3115_channels[] = { | ||
182 | { | ||
183 | .type = IIO_PRESSURE, | ||
184 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | ||
185 | BIT(IIO_CHAN_INFO_SCALE), | ||
186 | .scan_index = 0, | ||
187 | .scan_type = { | ||
188 | .sign = 's', | ||
189 | .realbits = 20, | ||
190 | .storagebits = 32, | ||
191 | .shift = 12, | ||
192 | .endianness = IIO_BE, | ||
193 | } | ||
194 | }, | ||
195 | { | ||
196 | .type = IIO_TEMP, | ||
197 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | ||
198 | BIT(IIO_CHAN_INFO_SCALE), | ||
199 | .scan_index = 1, | ||
200 | .scan_type = { | ||
201 | .sign = 's', | ||
202 | .realbits = 12, | ||
203 | .storagebits = 16, | ||
204 | .shift = 4, | ||
205 | .endianness = IIO_BE, | ||
206 | } | ||
207 | }, | ||
208 | IIO_CHAN_SOFT_TIMESTAMP(2), | ||
209 | }; | ||
210 | |||
211 | static const struct iio_info mpl3115_info = { | ||
212 | .read_raw = &mpl3115_read_raw, | ||
213 | .driver_module = THIS_MODULE, | ||
214 | }; | ||
215 | |||
216 | static int mpl3115_probe(struct i2c_client *client, | ||
217 | const struct i2c_device_id *id) | ||
218 | { | ||
219 | struct mpl3115_data *data; | ||
220 | struct iio_dev *indio_dev; | ||
221 | int ret; | ||
222 | |||
223 | ret = i2c_smbus_read_byte_data(client, MPL3115_WHO_AM_I); | ||
224 | if (ret < 0) | ||
225 | return ret; | ||
226 | if (ret != MPL3115_DEVICE_ID) | ||
227 | return -ENODEV; | ||
228 | |||
229 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); | ||
230 | if (!indio_dev) | ||
231 | return -ENOMEM; | ||
232 | |||
233 | data = iio_priv(indio_dev); | ||
234 | data->client = client; | ||
235 | mutex_init(&data->lock); | ||
236 | |||
237 | i2c_set_clientdata(client, indio_dev); | ||
238 | indio_dev->info = &mpl3115_info; | ||
239 | indio_dev->name = id->name; | ||
240 | indio_dev->dev.parent = &client->dev; | ||
241 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
242 | indio_dev->channels = mpl3115_channels; | ||
243 | indio_dev->num_channels = ARRAY_SIZE(mpl3115_channels); | ||
244 | |||
245 | /* software reset, I2C transfer is aborted (fails) */ | ||
246 | i2c_smbus_write_byte_data(client, MPL3115_CTRL_REG1, | ||
247 | MPL3115_CTRL_RESET); | ||
248 | msleep(50); | ||
249 | |||
250 | data->ctrl_reg1 = MPL3115_CTRL_OS_258MS; | ||
251 | ret = i2c_smbus_write_byte_data(client, MPL3115_CTRL_REG1, | ||
252 | data->ctrl_reg1); | ||
253 | if (ret < 0) | ||
254 | return ret; | ||
255 | |||
256 | ret = iio_triggered_buffer_setup(indio_dev, NULL, | ||
257 | mpl3115_trigger_handler, NULL); | ||
258 | if (ret < 0) | ||
259 | return ret; | ||
260 | |||
261 | ret = iio_device_register(indio_dev); | ||
262 | if (ret < 0) | ||
263 | goto buffer_cleanup; | ||
264 | return 0; | ||
265 | |||
266 | buffer_cleanup: | ||
267 | iio_triggered_buffer_cleanup(indio_dev); | ||
268 | return ret; | ||
269 | } | ||
270 | |||
271 | static int mpl3115_standby(struct mpl3115_data *data) | ||
272 | { | ||
273 | return i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1, | ||
274 | data->ctrl_reg1 & ~MPL3115_CTRL_ACTIVE); | ||
275 | } | ||
276 | |||
277 | static int mpl3115_remove(struct i2c_client *client) | ||
278 | { | ||
279 | struct iio_dev *indio_dev = i2c_get_clientdata(client); | ||
280 | |||
281 | iio_device_unregister(indio_dev); | ||
282 | iio_triggered_buffer_cleanup(indio_dev); | ||
283 | mpl3115_standby(iio_priv(indio_dev)); | ||
284 | |||
285 | return 0; | ||
286 | } | ||
287 | |||
288 | #ifdef CONFIG_PM_SLEEP | ||
289 | static int mpl3115_suspend(struct device *dev) | ||
290 | { | ||
291 | return mpl3115_standby(iio_priv(i2c_get_clientdata( | ||
292 | to_i2c_client(dev)))); | ||
293 | } | ||
294 | |||
295 | static int mpl3115_resume(struct device *dev) | ||
296 | { | ||
297 | struct mpl3115_data *data = iio_priv(i2c_get_clientdata( | ||
298 | to_i2c_client(dev))); | ||
299 | |||
300 | return i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1, | ||
301 | data->ctrl_reg1); | ||
302 | } | ||
303 | |||
304 | static SIMPLE_DEV_PM_OPS(mpl3115_pm_ops, mpl3115_suspend, mpl3115_resume); | ||
305 | #define MPL3115_PM_OPS (&mpl3115_pm_ops) | ||
306 | #else | ||
307 | #define MPL3115_PM_OPS NULL | ||
308 | #endif | ||
309 | |||
310 | static const struct i2c_device_id mpl3115_id[] = { | ||
311 | { "mpl3115", 0 }, | ||
312 | { } | ||
313 | }; | ||
314 | MODULE_DEVICE_TABLE(i2c, mpl3115_id); | ||
315 | |||
316 | static struct i2c_driver mpl3115_driver = { | ||
317 | .driver = { | ||
318 | .name = "mpl3115", | ||
319 | .pm = MPL3115_PM_OPS, | ||
320 | }, | ||
321 | .probe = mpl3115_probe, | ||
322 | .remove = mpl3115_remove, | ||
323 | .id_table = mpl3115_id, | ||
324 | }; | ||
325 | module_i2c_driver(mpl3115_driver); | ||
326 | |||
327 | MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); | ||
328 | MODULE_DESCRIPTION("Freescale MPL3115 pressure/temperature driver"); | ||
329 | MODULE_LICENSE("GPL"); | ||