diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-04-04 15:31:05 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-04-04 15:31:05 -0400 |
commit | eb7bfed901b9fea6e48bec10009dc8c8641e36e7 (patch) | |
tree | e03df0b64ecdfc3c51bf0bbdd2f96cd2a6348a7a /drivers | |
parent | 56d118c243fbc62d95a79183bb6bcfc38a398da5 (diff) | |
parent | 486294f184c05cff116160bb731cbb679f047621 (diff) |
Merge tag 'iio-for-4.7a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes:
First round of IIO new device support, features and cleanups for the 4.7 cycle.
New core support
* UV light modifier (for intensity)
* UV light index channel type.
New device support
* hp206c barometer and altimeter
- new driver.
* mcp4131 potentiometer
- new driver supporting lots of parts from Microchip.
* mma8452
- FXLS8471Q support
- NXP LPC18XX SOC ADC
- new driver.
- NXP LPC18XX SOC DAC
- new driver.
- rockchip_saradc
- support rk3399
* st accel
- h3lis331dl support
Staging driver removals
* adis16204
- obsolete part making it hard to get parts to test the driver in order
to clean it up.
* adis16220
- obsolete part making it hard to get the parts test the driver in order
to clean it up.
Features
* core
- convenience functions to claim / release direct access to the device.
Makes more consistent handling of this corner easier. Used in ad7192 driver.
* ak8975
- power regulator support.
* at91-sama5d2
- differential channel support.
* mma8452
- runtime pm support
- drop device specific autosleep and use the runtime pm one instead.
* ms5611
- DT bindings
- oversampling ratio support
Cleanups and minor fixes
* MAINTAINERS
- Peter got married - hence name change!
* Documentation
- Fix a typo in in_proximity_raw description.
- Add some missing docs for iio_buffer_access_funcs.
* Tools
- update iio_event_monitor names to match new stuff.
- make generic_buffer look for triggers ending in -trigger as we let these in
for a number of drivers a long time back and now it is a fairly common
option.
Drivers
* staging wide
- convert bare unsigned usage to unsigned int to comply with coding style.
* non staging wide:
- since boiler plate gpio handling of interrupts has been moved into the
ACPI core we don't need to include gpio/consumer.h in a load of drivers so
drop it.
* ad7606
- fix an endian casting sparse warning.
* ak8975
- fix a possible unitialized warning from gcc.
- drop and unused field left over from earlier cleanups
- fix a missing regulator_disable on exit.
* at91-sama5d2
- typo and indentation
- missing IOMEM dependency.
- cleanup mode register usage by avoidling erasing whole thing when changing
the sampling frequency.
* bmc150
- use the core demux and available_scan_masks to simplify buffer handling
- optimize the transfers in the trigger handler now we have a magic function
to emulate bulk reads (under circumstances met here). This matters with some
rather dumb i2c adapters in particular.
- use a single regmap_conf for all bus types as they were all the same.
* bmg160
- use the core demux and available_scan_masks to simplify the buffer handling
- optimize the transfers in the trigger handler now we have a magic funciton
to emulate bulk rads (under circumstances met here).
- drop gpio interrupt probing from the driver (ACPI) as now handled by the
ACPI core.
* ina2xx-adc
- update the CALIB register when RShunt changes.
- fix scale for VShunt - in reality this error canceled out when used.
* isl29028
- use regmap to retrieve the struct device instead of carrying a second
copy of it around.
* kxcjk-1013
- use core demux
- optimize i2c transfers in the trigger handler.
* mcp4531
- refactor to use a pointer to access model parameters instead of indexing
into the array each time.
* mma8452
- style fixes
- avoid swtiching to active whenever the config changes
- add missin i2c_device_id for mma8451
* mpu6050
- fix possible NULL dereference.
- fix the name / chip_id used when ACPI used (otherwise reports as NULL).
* ms5611
- fix a missing regulator_disable that left the regulator on during removal.
* mxc4005
- drop gpio interrupt handling for ACPI case from driver as the core now
handles this case.
* st-sensors
- note that there are only ever a maximum of 3 axis on current st-sensors
so just allocate a fixed sized buffer big enough for that.
* tpl0102
- change the i2c_check_functionality condition to bring it inline with other
IIO users as EOPNOTSUPP.
* tsl2563
- replace deprecated flush_scheduled_work
Diffstat (limited to 'drivers')
62 files changed, 2288 insertions, 1469 deletions
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index b0d3ecf3318b..e4a758cd7d35 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig | |||
@@ -64,7 +64,7 @@ config IIO_ST_ACCEL_3AXIS | |||
64 | help | 64 | help |
65 | Say yes here to build support for STMicroelectronics accelerometers: | 65 | Say yes here to build support for STMicroelectronics accelerometers: |
66 | LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC, | 66 | LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC, |
67 | LIS331DLH, LSM303DL, LSM303DLM, LSM330, LIS2DH12. | 67 | LIS331DLH, LSM303DL, LSM303DLM, LSM330, LIS2DH12, H3LIS331DL. |
68 | 68 | ||
69 | This driver can also be built as a module. If so, these modules | 69 | This driver can also be built as a module. If so, these modules |
70 | will be created: | 70 | will be created: |
@@ -143,7 +143,8 @@ config MMA8452 | |||
143 | select IIO_TRIGGERED_BUFFER | 143 | select IIO_TRIGGERED_BUFFER |
144 | help | 144 | help |
145 | Say yes here to build support for the following Freescale 3-axis | 145 | Say yes here to build support for the following Freescale 3-axis |
146 | accelerometers: MMA8451Q, MMA8452Q, MMA8453Q, MMA8652FC, MMA8653FC. | 146 | accelerometers: MMA8451Q, MMA8452Q, MMA8453Q, MMA8652FC, MMA8653FC, |
147 | FXLS8471Q. | ||
147 | 148 | ||
148 | To compile this driver as a module, choose M here: the module | 149 | To compile this driver as a module, choose M here: the module |
149 | will be called mma8452. | 150 | will be called mma8452. |
diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c index c73331f7782b..e631ee9a6a77 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c | |||
@@ -25,7 +25,6 @@ | |||
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <linux/acpi.h> | 27 | #include <linux/acpi.h> |
28 | #include <linux/gpio/consumer.h> | ||
29 | #include <linux/pm.h> | 28 | #include <linux/pm.h> |
30 | #include <linux/pm_runtime.h> | 29 | #include <linux/pm_runtime.h> |
31 | #include <linux/iio/iio.h> | 30 | #include <linux/iio/iio.h> |
@@ -138,6 +137,7 @@ enum bmc150_accel_axis { | |||
138 | AXIS_X, | 137 | AXIS_X, |
139 | AXIS_Y, | 138 | AXIS_Y, |
140 | AXIS_Z, | 139 | AXIS_Z, |
140 | AXIS_MAX, | ||
141 | }; | 141 | }; |
142 | 142 | ||
143 | enum bmc150_power_modes { | 143 | enum bmc150_power_modes { |
@@ -246,11 +246,12 @@ static const struct { | |||
246 | {500000, BMC150_ACCEL_SLEEP_500_MS}, | 246 | {500000, BMC150_ACCEL_SLEEP_500_MS}, |
247 | {1000000, BMC150_ACCEL_SLEEP_1_SEC} }; | 247 | {1000000, BMC150_ACCEL_SLEEP_1_SEC} }; |
248 | 248 | ||
249 | static const struct regmap_config bmc150_i2c_regmap_conf = { | 249 | const struct regmap_config bmc150_regmap_conf = { |
250 | .reg_bits = 8, | 250 | .reg_bits = 8, |
251 | .val_bits = 8, | 251 | .val_bits = 8, |
252 | .max_register = 0x3f, | 252 | .max_register = 0x3f, |
253 | }; | 253 | }; |
254 | EXPORT_SYMBOL_GPL(bmc150_regmap_conf); | ||
254 | 255 | ||
255 | static int bmc150_accel_set_mode(struct bmc150_accel_data *data, | 256 | static int bmc150_accel_set_mode(struct bmc150_accel_data *data, |
256 | enum bmc150_power_modes mode, | 257 | enum bmc150_power_modes mode, |
@@ -988,6 +989,7 @@ static const struct iio_event_spec bmc150_accel_event = { | |||
988 | .realbits = (bits), \ | 989 | .realbits = (bits), \ |
989 | .storagebits = 16, \ | 990 | .storagebits = 16, \ |
990 | .shift = 16 - (bits), \ | 991 | .shift = 16 - (bits), \ |
992 | .endianness = IIO_LE, \ | ||
991 | }, \ | 993 | }, \ |
992 | .event_spec = &bmc150_accel_event, \ | 994 | .event_spec = &bmc150_accel_event, \ |
993 | .num_event_specs = 1 \ | 995 | .num_event_specs = 1 \ |
@@ -1104,27 +1106,23 @@ static const struct iio_info bmc150_accel_info_fifo = { | |||
1104 | .driver_module = THIS_MODULE, | 1106 | .driver_module = THIS_MODULE, |
1105 | }; | 1107 | }; |
1106 | 1108 | ||
1109 | static const unsigned long bmc150_accel_scan_masks[] = { | ||
1110 | BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z), | ||
1111 | 0}; | ||
1112 | |||
1107 | static irqreturn_t bmc150_accel_trigger_handler(int irq, void *p) | 1113 | static irqreturn_t bmc150_accel_trigger_handler(int irq, void *p) |
1108 | { | 1114 | { |
1109 | struct iio_poll_func *pf = p; | 1115 | struct iio_poll_func *pf = p; |
1110 | struct iio_dev *indio_dev = pf->indio_dev; | 1116 | struct iio_dev *indio_dev = pf->indio_dev; |
1111 | struct bmc150_accel_data *data = iio_priv(indio_dev); | 1117 | struct bmc150_accel_data *data = iio_priv(indio_dev); |
1112 | int bit, ret, i = 0; | 1118 | int ret; |
1113 | unsigned int raw_val; | ||
1114 | 1119 | ||
1115 | mutex_lock(&data->mutex); | 1120 | mutex_lock(&data->mutex); |
1116 | for_each_set_bit(bit, indio_dev->active_scan_mask, | 1121 | ret = regmap_bulk_read(data->regmap, BMC150_ACCEL_REG_XOUT_L, |
1117 | indio_dev->masklength) { | 1122 | data->buffer, AXIS_MAX * 2); |
1118 | ret = regmap_bulk_read(data->regmap, | ||
1119 | BMC150_ACCEL_AXIS_TO_REG(bit), &raw_val, | ||
1120 | 2); | ||
1121 | if (ret < 0) { | ||
1122 | mutex_unlock(&data->mutex); | ||
1123 | goto err_read; | ||
1124 | } | ||
1125 | data->buffer[i++] = raw_val; | ||
1126 | } | ||
1127 | mutex_unlock(&data->mutex); | 1123 | mutex_unlock(&data->mutex); |
1124 | if (ret < 0) | ||
1125 | goto err_read; | ||
1128 | 1126 | ||
1129 | iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, | 1127 | iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, |
1130 | pf->timestamp); | 1128 | pf->timestamp); |
@@ -1574,6 +1572,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, | |||
1574 | indio_dev->channels = data->chip_info->channels; | 1572 | indio_dev->channels = data->chip_info->channels; |
1575 | indio_dev->num_channels = data->chip_info->num_channels; | 1573 | indio_dev->num_channels = data->chip_info->num_channels; |
1576 | indio_dev->name = name ? name : data->chip_info->name; | 1574 | indio_dev->name = name ? name : data->chip_info->name; |
1575 | indio_dev->available_scan_masks = bmc150_accel_scan_masks; | ||
1577 | indio_dev->modes = INDIO_DIRECT_MODE; | 1576 | indio_dev->modes = INDIO_DIRECT_MODE; |
1578 | indio_dev->info = &bmc150_accel_info; | 1577 | indio_dev->info = &bmc150_accel_info; |
1579 | 1578 | ||
diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c index b41404ba32fc..8ca8041267ef 100644 --- a/drivers/iio/accel/bmc150-accel-i2c.c +++ b/drivers/iio/accel/bmc150-accel-i2c.c | |||
@@ -28,11 +28,6 @@ | |||
28 | 28 | ||
29 | #include "bmc150-accel.h" | 29 | #include "bmc150-accel.h" |
30 | 30 | ||
31 | static const struct regmap_config bmc150_i2c_regmap_conf = { | ||
32 | .reg_bits = 8, | ||
33 | .val_bits = 8, | ||
34 | }; | ||
35 | |||
36 | static int bmc150_accel_probe(struct i2c_client *client, | 31 | static int bmc150_accel_probe(struct i2c_client *client, |
37 | const struct i2c_device_id *id) | 32 | const struct i2c_device_id *id) |
38 | { | 33 | { |
@@ -43,7 +38,7 @@ static int bmc150_accel_probe(struct i2c_client *client, | |||
43 | i2c_check_functionality(client->adapter, | 38 | i2c_check_functionality(client->adapter, |
44 | I2C_FUNC_SMBUS_READ_I2C_BLOCK); | 39 | I2C_FUNC_SMBUS_READ_I2C_BLOCK); |
45 | 40 | ||
46 | regmap = devm_regmap_init_i2c(client, &bmc150_i2c_regmap_conf); | 41 | regmap = devm_regmap_init_i2c(client, &bmc150_regmap_conf); |
47 | if (IS_ERR(regmap)) { | 42 | if (IS_ERR(regmap)) { |
48 | dev_err(&client->dev, "Failed to initialize i2c regmap\n"); | 43 | dev_err(&client->dev, "Failed to initialize i2c regmap\n"); |
49 | return PTR_ERR(regmap); | 44 | return PTR_ERR(regmap); |
diff --git a/drivers/iio/accel/bmc150-accel-spi.c b/drivers/iio/accel/bmc150-accel-spi.c index 16b66f2a7204..006794a70a1f 100644 --- a/drivers/iio/accel/bmc150-accel-spi.c +++ b/drivers/iio/accel/bmc150-accel-spi.c | |||
@@ -25,18 +25,12 @@ | |||
25 | 25 | ||
26 | #include "bmc150-accel.h" | 26 | #include "bmc150-accel.h" |
27 | 27 | ||
28 | static const struct regmap_config bmc150_spi_regmap_conf = { | ||
29 | .reg_bits = 8, | ||
30 | .val_bits = 8, | ||
31 | .max_register = 0x3f, | ||
32 | }; | ||
33 | |||
34 | static int bmc150_accel_probe(struct spi_device *spi) | 28 | static int bmc150_accel_probe(struct spi_device *spi) |
35 | { | 29 | { |
36 | struct regmap *regmap; | 30 | struct regmap *regmap; |
37 | const struct spi_device_id *id = spi_get_device_id(spi); | 31 | const struct spi_device_id *id = spi_get_device_id(spi); |
38 | 32 | ||
39 | regmap = devm_regmap_init_spi(spi, &bmc150_spi_regmap_conf); | 33 | regmap = devm_regmap_init_spi(spi, &bmc150_regmap_conf); |
40 | if (IS_ERR(regmap)) { | 34 | if (IS_ERR(regmap)) { |
41 | dev_err(&spi->dev, "Failed to initialize spi regmap\n"); | 35 | dev_err(&spi->dev, "Failed to initialize spi regmap\n"); |
42 | return PTR_ERR(regmap); | 36 | return PTR_ERR(regmap); |
diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h index ba0335987f94..38a8b11f8c19 100644 --- a/drivers/iio/accel/bmc150-accel.h +++ b/drivers/iio/accel/bmc150-accel.h | |||
@@ -16,5 +16,6 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, | |||
16 | const char *name, bool block_supported); | 16 | const char *name, bool block_supported); |
17 | int bmc150_accel_core_remove(struct device *dev); | 17 | int bmc150_accel_core_remove(struct device *dev); |
18 | extern const struct dev_pm_ops bmc150_accel_pm_ops; | 18 | extern const struct dev_pm_ops bmc150_accel_pm_ops; |
19 | extern const struct regmap_config bmc150_regmap_conf; | ||
19 | 20 | ||
20 | #endif /* _BMC150_ACCEL_H_ */ | 21 | #endif /* _BMC150_ACCEL_H_ */ |
diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c index edec1d099e91..bfe219a8bea2 100644 --- a/drivers/iio/accel/kxcjk-1013.c +++ b/drivers/iio/accel/kxcjk-1013.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/string.h> | 21 | #include <linux/string.h> |
22 | #include <linux/acpi.h> | 22 | #include <linux/acpi.h> |
23 | #include <linux/gpio/consumer.h> | ||
24 | #include <linux/pm.h> | 23 | #include <linux/pm.h> |
25 | #include <linux/pm_runtime.h> | 24 | #include <linux/pm_runtime.h> |
26 | #include <linux/iio/iio.h> | 25 | #include <linux/iio/iio.h> |
@@ -115,6 +114,7 @@ enum kxcjk1013_axis { | |||
115 | AXIS_X, | 114 | AXIS_X, |
116 | AXIS_Y, | 115 | AXIS_Y, |
117 | AXIS_Z, | 116 | AXIS_Z, |
117 | AXIS_MAX, | ||
118 | }; | 118 | }; |
119 | 119 | ||
120 | enum kxcjk1013_mode { | 120 | enum kxcjk1013_mode { |
@@ -922,7 +922,7 @@ static const struct iio_event_spec kxcjk1013_event = { | |||
922 | .realbits = 12, \ | 922 | .realbits = 12, \ |
923 | .storagebits = 16, \ | 923 | .storagebits = 16, \ |
924 | .shift = 4, \ | 924 | .shift = 4, \ |
925 | .endianness = IIO_CPU, \ | 925 | .endianness = IIO_LE, \ |
926 | }, \ | 926 | }, \ |
927 | .event_spec = &kxcjk1013_event, \ | 927 | .event_spec = &kxcjk1013_event, \ |
928 | .num_event_specs = 1 \ | 928 | .num_event_specs = 1 \ |
@@ -953,25 +953,23 @@ static const struct iio_info kxcjk1013_info = { | |||
953 | .driver_module = THIS_MODULE, | 953 | .driver_module = THIS_MODULE, |
954 | }; | 954 | }; |
955 | 955 | ||
956 | static const unsigned long kxcjk1013_scan_masks[] = {0x7, 0}; | ||
957 | |||
956 | static irqreturn_t kxcjk1013_trigger_handler(int irq, void *p) | 958 | static irqreturn_t kxcjk1013_trigger_handler(int irq, void *p) |
957 | { | 959 | { |
958 | struct iio_poll_func *pf = p; | 960 | struct iio_poll_func *pf = p; |
959 | struct iio_dev *indio_dev = pf->indio_dev; | 961 | struct iio_dev *indio_dev = pf->indio_dev; |
960 | struct kxcjk1013_data *data = iio_priv(indio_dev); | 962 | struct kxcjk1013_data *data = iio_priv(indio_dev); |
961 | int bit, ret, i = 0; | 963 | int ret; |
962 | 964 | ||
963 | mutex_lock(&data->mutex); | 965 | mutex_lock(&data->mutex); |
964 | 966 | ret = i2c_smbus_read_i2c_block_data_or_emulated(data->client, | |
965 | for_each_set_bit(bit, indio_dev->active_scan_mask, | 967 | KXCJK1013_REG_XOUT_L, |
966 | indio_dev->masklength) { | 968 | AXIS_MAX * 2, |
967 | ret = kxcjk1013_get_acc_reg(data, bit); | 969 | (u8 *)data->buffer); |
968 | if (ret < 0) { | ||
969 | mutex_unlock(&data->mutex); | ||
970 | goto err; | ||
971 | } | ||
972 | data->buffer[i++] = ret; | ||
973 | } | ||
974 | mutex_unlock(&data->mutex); | 970 | mutex_unlock(&data->mutex); |
971 | if (ret < 0) | ||
972 | goto err; | ||
975 | 973 | ||
976 | iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, | 974 | iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, |
977 | data->timestamp); | 975 | data->timestamp); |
@@ -1204,6 +1202,7 @@ static int kxcjk1013_probe(struct i2c_client *client, | |||
1204 | indio_dev->dev.parent = &client->dev; | 1202 | indio_dev->dev.parent = &client->dev; |
1205 | indio_dev->channels = kxcjk1013_channels; | 1203 | indio_dev->channels = kxcjk1013_channels; |
1206 | indio_dev->num_channels = ARRAY_SIZE(kxcjk1013_channels); | 1204 | indio_dev->num_channels = ARRAY_SIZE(kxcjk1013_channels); |
1205 | indio_dev->available_scan_masks = kxcjk1013_scan_masks; | ||
1207 | indio_dev->name = name; | 1206 | indio_dev->name = name; |
1208 | indio_dev->modes = INDIO_DIRECT_MODE; | 1207 | indio_dev->modes = INDIO_DIRECT_MODE; |
1209 | indio_dev->info = &kxcjk1013_info; | 1208 | indio_dev->info = &kxcjk1013_info; |
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c index 7f4994f32a90..e225d3c53bd5 100644 --- a/drivers/iio/accel/mma8452.c +++ b/drivers/iio/accel/mma8452.c | |||
@@ -6,6 +6,7 @@ | |||
6 | * MMA8453Q (10 bit) | 6 | * MMA8453Q (10 bit) |
7 | * MMA8652FC (12 bit) | 7 | * MMA8652FC (12 bit) |
8 | * MMA8653FC (10 bit) | 8 | * MMA8653FC (10 bit) |
9 | * FXLS8471Q (14 bit) | ||
9 | * | 10 | * |
10 | * Copyright 2015 Martin Kepplinger <martin.kepplinger@theobroma-systems.com> | 11 | * Copyright 2015 Martin Kepplinger <martin.kepplinger@theobroma-systems.com> |
11 | * Copyright 2014 Peter Meerwald <pmeerw@pmeerw.net> | 12 | * Copyright 2014 Peter Meerwald <pmeerw@pmeerw.net> |
@@ -16,7 +17,7 @@ | |||
16 | * | 17 | * |
17 | * 7-bit I2C slave address 0x1c/0x1d (pin selectable) | 18 | * 7-bit I2C slave address 0x1c/0x1d (pin selectable) |
18 | * | 19 | * |
19 | * TODO: orientation events, autosleep | 20 | * TODO: orientation events |
20 | */ | 21 | */ |
21 | 22 | ||
22 | #include <linux/module.h> | 23 | #include <linux/module.h> |
@@ -31,6 +32,7 @@ | |||
31 | #include <linux/delay.h> | 32 | #include <linux/delay.h> |
32 | #include <linux/of_device.h> | 33 | #include <linux/of_device.h> |
33 | #include <linux/of_irq.h> | 34 | #include <linux/of_irq.h> |
35 | #include <linux/pm_runtime.h> | ||
34 | 36 | ||
35 | #define MMA8452_STATUS 0x00 | 37 | #define MMA8452_STATUS 0x00 |
36 | #define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0)) | 38 | #define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0)) |
@@ -91,6 +93,9 @@ | |||
91 | #define MMA8453_DEVICE_ID 0x3a | 93 | #define MMA8453_DEVICE_ID 0x3a |
92 | #define MMA8652_DEVICE_ID 0x4a | 94 | #define MMA8652_DEVICE_ID 0x4a |
93 | #define MMA8653_DEVICE_ID 0x5a | 95 | #define MMA8653_DEVICE_ID 0x5a |
96 | #define FXLS8471_DEVICE_ID 0x6a | ||
97 | |||
98 | #define MMA8452_AUTO_SUSPEND_DELAY_MS 2000 | ||
94 | 99 | ||
95 | struct mma8452_data { | 100 | struct mma8452_data { |
96 | struct i2c_client *client; | 101 | struct i2c_client *client; |
@@ -172,6 +177,31 @@ static int mma8452_drdy(struct mma8452_data *data) | |||
172 | return -EIO; | 177 | return -EIO; |
173 | } | 178 | } |
174 | 179 | ||
180 | static int mma8452_set_runtime_pm_state(struct i2c_client *client, bool on) | ||
181 | { | ||
182 | #ifdef CONFIG_PM | ||
183 | int ret; | ||
184 | |||
185 | if (on) { | ||
186 | ret = pm_runtime_get_sync(&client->dev); | ||
187 | } else { | ||
188 | pm_runtime_mark_last_busy(&client->dev); | ||
189 | ret = pm_runtime_put_autosuspend(&client->dev); | ||
190 | } | ||
191 | |||
192 | if (ret < 0) { | ||
193 | dev_err(&client->dev, | ||
194 | "failed to change power state to %d\n", on); | ||
195 | if (on) | ||
196 | pm_runtime_put_noidle(&client->dev); | ||
197 | |||
198 | return ret; | ||
199 | } | ||
200 | #endif | ||
201 | |||
202 | return 0; | ||
203 | } | ||
204 | |||
175 | static int mma8452_read(struct mma8452_data *data, __be16 buf[3]) | 205 | static int mma8452_read(struct mma8452_data *data, __be16 buf[3]) |
176 | { | 206 | { |
177 | int ret = mma8452_drdy(data); | 207 | int ret = mma8452_drdy(data); |
@@ -179,8 +209,16 @@ static int mma8452_read(struct mma8452_data *data, __be16 buf[3]) | |||
179 | if (ret < 0) | 209 | if (ret < 0) |
180 | return ret; | 210 | return ret; |
181 | 211 | ||
182 | return i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X, | 212 | ret = mma8452_set_runtime_pm_state(data->client, true); |
183 | 3 * sizeof(__be16), (u8 *)buf); | 213 | if (ret) |
214 | return ret; | ||
215 | |||
216 | ret = i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X, | ||
217 | 3 * sizeof(__be16), (u8 *)buf); | ||
218 | |||
219 | ret = mma8452_set_runtime_pm_state(data->client, false); | ||
220 | |||
221 | return ret; | ||
184 | } | 222 | } |
185 | 223 | ||
186 | static ssize_t mma8452_show_int_plus_micros(char *buf, const int (*vals)[2], | 224 | static ssize_t mma8452_show_int_plus_micros(char *buf, const int (*vals)[2], |
@@ -357,7 +395,8 @@ static int mma8452_read_raw(struct iio_dev *indio_dev, | |||
357 | return IIO_VAL_INT_PLUS_MICRO; | 395 | return IIO_VAL_INT_PLUS_MICRO; |
358 | case IIO_CHAN_INFO_CALIBBIAS: | 396 | case IIO_CHAN_INFO_CALIBBIAS: |
359 | ret = i2c_smbus_read_byte_data(data->client, | 397 | ret = i2c_smbus_read_byte_data(data->client, |
360 | MMA8452_OFF_X + chan->scan_index); | 398 | MMA8452_OFF_X + |
399 | chan->scan_index); | ||
361 | if (ret < 0) | 400 | if (ret < 0) |
362 | return ret; | 401 | return ret; |
363 | 402 | ||
@@ -392,24 +431,47 @@ static int mma8452_active(struct mma8452_data *data) | |||
392 | data->ctrl_reg1); | 431 | data->ctrl_reg1); |
393 | } | 432 | } |
394 | 433 | ||
434 | /* returns >0 if active, 0 if in standby and <0 on error */ | ||
435 | static int mma8452_is_active(struct mma8452_data *data) | ||
436 | { | ||
437 | int reg; | ||
438 | |||
439 | reg = i2c_smbus_read_byte_data(data->client, MMA8452_CTRL_REG1); | ||
440 | if (reg < 0) | ||
441 | return reg; | ||
442 | |||
443 | return reg & MMA8452_CTRL_ACTIVE; | ||
444 | } | ||
445 | |||
395 | static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val) | 446 | static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val) |
396 | { | 447 | { |
397 | int ret; | 448 | int ret; |
449 | int is_active; | ||
398 | 450 | ||
399 | mutex_lock(&data->lock); | 451 | mutex_lock(&data->lock); |
400 | 452 | ||
401 | /* config can only be changed when in standby */ | 453 | is_active = mma8452_is_active(data); |
402 | ret = mma8452_standby(data); | 454 | if (is_active < 0) { |
403 | if (ret < 0) | 455 | ret = is_active; |
404 | goto fail; | 456 | goto fail; |
457 | } | ||
458 | |||
459 | /* config can only be changed when in standby */ | ||
460 | if (is_active > 0) { | ||
461 | ret = mma8452_standby(data); | ||
462 | if (ret < 0) | ||
463 | goto fail; | ||
464 | } | ||
405 | 465 | ||
406 | ret = i2c_smbus_write_byte_data(data->client, reg, val); | 466 | ret = i2c_smbus_write_byte_data(data->client, reg, val); |
407 | if (ret < 0) | 467 | if (ret < 0) |
408 | goto fail; | 468 | goto fail; |
409 | 469 | ||
410 | ret = mma8452_active(data); | 470 | if (is_active > 0) { |
411 | if (ret < 0) | 471 | ret = mma8452_active(data); |
412 | goto fail; | 472 | if (ret < 0) |
473 | goto fail; | ||
474 | } | ||
413 | 475 | ||
414 | ret = 0; | 476 | ret = 0; |
415 | fail: | 477 | fail: |
@@ -418,7 +480,7 @@ fail: | |||
418 | return ret; | 480 | return ret; |
419 | } | 481 | } |
420 | 482 | ||
421 | /* returns >0 if in freefall mode, 0 if not or <0 if an error occured */ | 483 | /* returns >0 if in freefall mode, 0 if not or <0 if an error occurred */ |
422 | static int mma8452_freefall_mode_enabled(struct mma8452_data *data) | 484 | static int mma8452_freefall_mode_enabled(struct mma8452_data *data) |
423 | { | 485 | { |
424 | int val; | 486 | int val; |
@@ -668,7 +730,8 @@ static int mma8452_read_event_config(struct iio_dev *indio_dev, | |||
668 | if (ret < 0) | 730 | if (ret < 0) |
669 | return ret; | 731 | return ret; |
670 | 732 | ||
671 | return !!(ret & BIT(chan->scan_index + chip->ev_cfg_chan_shift)); | 733 | return !!(ret & BIT(chan->scan_index + |
734 | chip->ev_cfg_chan_shift)); | ||
672 | default: | 735 | default: |
673 | return -EINVAL; | 736 | return -EINVAL; |
674 | } | 737 | } |
@@ -682,7 +745,11 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev, | |||
682 | { | 745 | { |
683 | struct mma8452_data *data = iio_priv(indio_dev); | 746 | struct mma8452_data *data = iio_priv(indio_dev); |
684 | const struct mma_chip_info *chip = data->chip_info; | 747 | const struct mma_chip_info *chip = data->chip_info; |
685 | int val; | 748 | int val, ret; |
749 | |||
750 | ret = mma8452_set_runtime_pm_state(data->client, state); | ||
751 | if (ret) | ||
752 | return ret; | ||
686 | 753 | ||
687 | switch (dir) { | 754 | switch (dir) { |
688 | case IIO_EV_DIR_FALLING: | 755 | case IIO_EV_DIR_FALLING: |
@@ -990,6 +1057,7 @@ enum { | |||
990 | mma8453, | 1057 | mma8453, |
991 | mma8652, | 1058 | mma8652, |
992 | mma8653, | 1059 | mma8653, |
1060 | fxls8471, | ||
993 | }; | 1061 | }; |
994 | 1062 | ||
995 | static const struct mma_chip_info mma_chip_info_table[] = { | 1063 | static const struct mma_chip_info mma_chip_info_table[] = { |
@@ -1003,7 +1071,7 @@ static const struct mma_chip_info mma_chip_info_table[] = { | |||
1003 | * bit. | 1071 | * bit. |
1004 | * The userspace interface uses m/s^2 and we declare micro units | 1072 | * The userspace interface uses m/s^2 and we declare micro units |
1005 | * So scale factor for 12 bit here is given by: | 1073 | * So scale factor for 12 bit here is given by: |
1006 | * g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665 | 1074 | * g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665 |
1007 | */ | 1075 | */ |
1008 | .mma_scales = { {0, 2394}, {0, 4788}, {0, 9577} }, | 1076 | .mma_scales = { {0, 2394}, {0, 4788}, {0, 9577} }, |
1009 | .ev_cfg = MMA8452_TRANSIENT_CFG, | 1077 | .ev_cfg = MMA8452_TRANSIENT_CFG, |
@@ -1081,6 +1149,22 @@ static const struct mma_chip_info mma_chip_info_table[] = { | |||
1081 | .ev_ths_mask = MMA8452_FF_MT_THS_MASK, | 1149 | .ev_ths_mask = MMA8452_FF_MT_THS_MASK, |
1082 | .ev_count = MMA8452_FF_MT_COUNT, | 1150 | .ev_count = MMA8452_FF_MT_COUNT, |
1083 | }, | 1151 | }, |
1152 | [fxls8471] = { | ||
1153 | .chip_id = FXLS8471_DEVICE_ID, | ||
1154 | .channels = mma8451_channels, | ||
1155 | .num_channels = ARRAY_SIZE(mma8451_channels), | ||
1156 | .mma_scales = { {0, 2394}, {0, 4788}, {0, 9577} }, | ||
1157 | .ev_cfg = MMA8452_TRANSIENT_CFG, | ||
1158 | .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE, | ||
1159 | .ev_cfg_chan_shift = 1, | ||
1160 | .ev_src = MMA8452_TRANSIENT_SRC, | ||
1161 | .ev_src_xe = MMA8452_TRANSIENT_SRC_XTRANSE, | ||
1162 | .ev_src_ye = MMA8452_TRANSIENT_SRC_YTRANSE, | ||
1163 | .ev_src_ze = MMA8452_TRANSIENT_SRC_ZTRANSE, | ||
1164 | .ev_ths = MMA8452_TRANSIENT_THS, | ||
1165 | .ev_ths_mask = MMA8452_TRANSIENT_THS_MASK, | ||
1166 | .ev_count = MMA8452_TRANSIENT_COUNT, | ||
1167 | }, | ||
1084 | }; | 1168 | }; |
1085 | 1169 | ||
1086 | static struct attribute *mma8452_attributes[] = { | 1170 | static struct attribute *mma8452_attributes[] = { |
@@ -1114,7 +1198,11 @@ static int mma8452_data_rdy_trigger_set_state(struct iio_trigger *trig, | |||
1114 | { | 1198 | { |
1115 | struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); | 1199 | struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); |
1116 | struct mma8452_data *data = iio_priv(indio_dev); | 1200 | struct mma8452_data *data = iio_priv(indio_dev); |
1117 | int reg; | 1201 | int reg, ret; |
1202 | |||
1203 | ret = mma8452_set_runtime_pm_state(data->client, state); | ||
1204 | if (ret) | ||
1205 | return ret; | ||
1118 | 1206 | ||
1119 | reg = i2c_smbus_read_byte_data(data->client, MMA8452_CTRL_REG4); | 1207 | reg = i2c_smbus_read_byte_data(data->client, MMA8452_CTRL_REG4); |
1120 | if (reg < 0) | 1208 | if (reg < 0) |
@@ -1206,6 +1294,7 @@ static const struct of_device_id mma8452_dt_ids[] = { | |||
1206 | { .compatible = "fsl,mma8453", .data = &mma_chip_info_table[mma8453] }, | 1294 | { .compatible = "fsl,mma8453", .data = &mma_chip_info_table[mma8453] }, |
1207 | { .compatible = "fsl,mma8652", .data = &mma_chip_info_table[mma8652] }, | 1295 | { .compatible = "fsl,mma8652", .data = &mma_chip_info_table[mma8652] }, |
1208 | { .compatible = "fsl,mma8653", .data = &mma_chip_info_table[mma8653] }, | 1296 | { .compatible = "fsl,mma8653", .data = &mma_chip_info_table[mma8653] }, |
1297 | { .compatible = "fsl,fxls8471", .data = &mma_chip_info_table[fxls8471] }, | ||
1209 | { } | 1298 | { } |
1210 | }; | 1299 | }; |
1211 | MODULE_DEVICE_TABLE(of, mma8452_dt_ids); | 1300 | MODULE_DEVICE_TABLE(of, mma8452_dt_ids); |
@@ -1243,6 +1332,7 @@ static int mma8452_probe(struct i2c_client *client, | |||
1243 | case MMA8453_DEVICE_ID: | 1332 | case MMA8453_DEVICE_ID: |
1244 | case MMA8652_DEVICE_ID: | 1333 | case MMA8652_DEVICE_ID: |
1245 | case MMA8653_DEVICE_ID: | 1334 | case MMA8653_DEVICE_ID: |
1335 | case FXLS8471_DEVICE_ID: | ||
1246 | if (ret == data->chip_info->chip_id) | 1336 | if (ret == data->chip_info->chip_id) |
1247 | break; | 1337 | break; |
1248 | default: | 1338 | default: |
@@ -1340,6 +1430,15 @@ static int mma8452_probe(struct i2c_client *client, | |||
1340 | goto buffer_cleanup; | 1430 | goto buffer_cleanup; |
1341 | } | 1431 | } |
1342 | 1432 | ||
1433 | ret = pm_runtime_set_active(&client->dev); | ||
1434 | if (ret < 0) | ||
1435 | goto buffer_cleanup; | ||
1436 | |||
1437 | pm_runtime_enable(&client->dev); | ||
1438 | pm_runtime_set_autosuspend_delay(&client->dev, | ||
1439 | MMA8452_AUTO_SUSPEND_DELAY_MS); | ||
1440 | pm_runtime_use_autosuspend(&client->dev); | ||
1441 | |||
1343 | ret = iio_device_register(indio_dev); | 1442 | ret = iio_device_register(indio_dev); |
1344 | if (ret < 0) | 1443 | if (ret < 0) |
1345 | goto buffer_cleanup; | 1444 | goto buffer_cleanup; |
@@ -1364,6 +1463,11 @@ static int mma8452_remove(struct i2c_client *client) | |||
1364 | struct iio_dev *indio_dev = i2c_get_clientdata(client); | 1463 | struct iio_dev *indio_dev = i2c_get_clientdata(client); |
1365 | 1464 | ||
1366 | iio_device_unregister(indio_dev); | 1465 | iio_device_unregister(indio_dev); |
1466 | |||
1467 | pm_runtime_disable(&client->dev); | ||
1468 | pm_runtime_set_suspended(&client->dev); | ||
1469 | pm_runtime_put_noidle(&client->dev); | ||
1470 | |||
1367 | iio_triggered_buffer_cleanup(indio_dev); | 1471 | iio_triggered_buffer_cleanup(indio_dev); |
1368 | mma8452_trigger_cleanup(indio_dev); | 1472 | mma8452_trigger_cleanup(indio_dev); |
1369 | mma8452_standby(iio_priv(indio_dev)); | 1473 | mma8452_standby(iio_priv(indio_dev)); |
@@ -1371,6 +1475,45 @@ static int mma8452_remove(struct i2c_client *client) | |||
1371 | return 0; | 1475 | return 0; |
1372 | } | 1476 | } |
1373 | 1477 | ||
1478 | #ifdef CONFIG_PM | ||
1479 | static int mma8452_runtime_suspend(struct device *dev) | ||
1480 | { | ||
1481 | struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); | ||
1482 | struct mma8452_data *data = iio_priv(indio_dev); | ||
1483 | int ret; | ||
1484 | |||
1485 | mutex_lock(&data->lock); | ||
1486 | ret = mma8452_standby(data); | ||
1487 | mutex_unlock(&data->lock); | ||
1488 | if (ret < 0) { | ||
1489 | dev_err(&data->client->dev, "powering off device failed\n"); | ||
1490 | return -EAGAIN; | ||
1491 | } | ||
1492 | |||
1493 | return 0; | ||
1494 | } | ||
1495 | |||
1496 | static int mma8452_runtime_resume(struct device *dev) | ||
1497 | { | ||
1498 | struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); | ||
1499 | struct mma8452_data *data = iio_priv(indio_dev); | ||
1500 | int ret, sleep_val; | ||
1501 | |||
1502 | ret = mma8452_active(data); | ||
1503 | if (ret < 0) | ||
1504 | return ret; | ||
1505 | |||
1506 | ret = mma8452_get_odr_index(data); | ||
1507 | sleep_val = 1000 / mma8452_samp_freq[ret][0]; | ||
1508 | if (sleep_val < 20) | ||
1509 | usleep_range(sleep_val * 1000, 20000); | ||
1510 | else | ||
1511 | msleep_interruptible(sleep_val); | ||
1512 | |||
1513 | return 0; | ||
1514 | } | ||
1515 | #endif | ||
1516 | |||
1374 | #ifdef CONFIG_PM_SLEEP | 1517 | #ifdef CONFIG_PM_SLEEP |
1375 | static int mma8452_suspend(struct device *dev) | 1518 | static int mma8452_suspend(struct device *dev) |
1376 | { | 1519 | { |
@@ -1383,18 +1526,21 @@ static int mma8452_resume(struct device *dev) | |||
1383 | return mma8452_active(iio_priv(i2c_get_clientdata( | 1526 | return mma8452_active(iio_priv(i2c_get_clientdata( |
1384 | to_i2c_client(dev)))); | 1527 | to_i2c_client(dev)))); |
1385 | } | 1528 | } |
1386 | |||
1387 | static SIMPLE_DEV_PM_OPS(mma8452_pm_ops, mma8452_suspend, mma8452_resume); | ||
1388 | #define MMA8452_PM_OPS (&mma8452_pm_ops) | ||
1389 | #else | ||
1390 | #define MMA8452_PM_OPS NULL | ||
1391 | #endif | 1529 | #endif |
1392 | 1530 | ||
1531 | static const struct dev_pm_ops mma8452_pm_ops = { | ||
1532 | SET_SYSTEM_SLEEP_PM_OPS(mma8452_suspend, mma8452_resume) | ||
1533 | SET_RUNTIME_PM_OPS(mma8452_runtime_suspend, | ||
1534 | mma8452_runtime_resume, NULL) | ||
1535 | }; | ||
1536 | |||
1393 | static const struct i2c_device_id mma8452_id[] = { | 1537 | static const struct i2c_device_id mma8452_id[] = { |
1538 | { "mma8451", mma8451 }, | ||
1394 | { "mma8452", mma8452 }, | 1539 | { "mma8452", mma8452 }, |
1395 | { "mma8453", mma8453 }, | 1540 | { "mma8453", mma8453 }, |
1396 | { "mma8652", mma8652 }, | 1541 | { "mma8652", mma8652 }, |
1397 | { "mma8653", mma8653 }, | 1542 | { "mma8653", mma8653 }, |
1543 | { "fxls8471", fxls8471 }, | ||
1398 | { } | 1544 | { } |
1399 | }; | 1545 | }; |
1400 | MODULE_DEVICE_TABLE(i2c, mma8452_id); | 1546 | MODULE_DEVICE_TABLE(i2c, mma8452_id); |
@@ -1403,7 +1549,7 @@ static struct i2c_driver mma8452_driver = { | |||
1403 | .driver = { | 1549 | .driver = { |
1404 | .name = "mma8452", | 1550 | .name = "mma8452", |
1405 | .of_match_table = of_match_ptr(mma8452_dt_ids), | 1551 | .of_match_table = of_match_ptr(mma8452_dt_ids), |
1406 | .pm = MMA8452_PM_OPS, | 1552 | .pm = &mma8452_pm_ops, |
1407 | }, | 1553 | }, |
1408 | .probe = mma8452_probe, | 1554 | .probe = mma8452_probe, |
1409 | .remove = mma8452_remove, | 1555 | .remove = mma8452_remove, |
diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c index fa7d36217c4b..bb05f3efddca 100644 --- a/drivers/iio/accel/mma9553.c +++ b/drivers/iio/accel/mma9553.c | |||
@@ -17,7 +17,6 @@ | |||
17 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/acpi.h> | 19 | #include <linux/acpi.h> |
20 | #include <linux/gpio/consumer.h> | ||
21 | #include <linux/iio/iio.h> | 20 | #include <linux/iio/iio.h> |
22 | #include <linux/iio/sysfs.h> | 21 | #include <linux/iio/sysfs.h> |
23 | #include <linux/iio/events.h> | 22 | #include <linux/iio/events.h> |
diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c index e72e218c2696..c23f47af7256 100644 --- a/drivers/iio/accel/mxc4005.c +++ b/drivers/iio/accel/mxc4005.c | |||
@@ -17,7 +17,6 @@ | |||
17 | #include <linux/i2c.h> | 17 | #include <linux/i2c.h> |
18 | #include <linux/iio/iio.h> | 18 | #include <linux/iio/iio.h> |
19 | #include <linux/acpi.h> | 19 | #include <linux/acpi.h> |
20 | #include <linux/gpio/consumer.h> | ||
21 | #include <linux/regmap.h> | 20 | #include <linux/regmap.h> |
22 | #include <linux/iio/sysfs.h> | 21 | #include <linux/iio/sysfs.h> |
23 | #include <linux/iio/trigger.h> | 22 | #include <linux/iio/trigger.h> |
@@ -380,31 +379,6 @@ static const struct iio_trigger_ops mxc4005_trigger_ops = { | |||
380 | .owner = THIS_MODULE, | 379 | .owner = THIS_MODULE, |
381 | }; | 380 | }; |
382 | 381 | ||
383 | static int mxc4005_gpio_probe(struct i2c_client *client, | ||
384 | struct mxc4005_data *data) | ||
385 | { | ||
386 | struct device *dev; | ||
387 | struct gpio_desc *gpio; | ||
388 | int ret; | ||
389 | |||
390 | if (!client) | ||
391 | return -EINVAL; | ||
392 | |||
393 | dev = &client->dev; | ||
394 | |||
395 | gpio = devm_gpiod_get_index(dev, "mxc4005_int", 0, GPIOD_IN); | ||
396 | if (IS_ERR(gpio)) { | ||
397 | dev_err(dev, "failed to get acpi gpio index\n"); | ||
398 | return PTR_ERR(gpio); | ||
399 | } | ||
400 | |||
401 | ret = gpiod_to_irq(gpio); | ||
402 | |||
403 | dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); | ||
404 | |||
405 | return ret; | ||
406 | } | ||
407 | |||
408 | static int mxc4005_chip_init(struct mxc4005_data *data) | 382 | static int mxc4005_chip_init(struct mxc4005_data *data) |
409 | { | 383 | { |
410 | int ret; | 384 | int ret; |
@@ -470,9 +444,6 @@ static int mxc4005_probe(struct i2c_client *client, | |||
470 | return ret; | 444 | return ret; |
471 | } | 445 | } |
472 | 446 | ||
473 | if (client->irq < 0) | ||
474 | client->irq = mxc4005_gpio_probe(client, data); | ||
475 | |||
476 | if (client->irq > 0) { | 447 | if (client->irq > 0) { |
477 | data->dready_trig = devm_iio_trigger_alloc(&client->dev, | 448 | data->dready_trig = devm_iio_trigger_alloc(&client->dev, |
478 | "%s-dev%d", | 449 | "%s-dev%d", |
diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h index 5d4a1897b293..57f83a67948c 100644 --- a/drivers/iio/accel/st_accel.h +++ b/drivers/iio/accel/st_accel.h | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/types.h> | 14 | #include <linux/types.h> |
15 | #include <linux/iio/common/st_sensors.h> | 15 | #include <linux/iio/common/st_sensors.h> |
16 | 16 | ||
17 | #define H3LIS331DL_DRIVER_NAME "h3lis331dl_accel" | ||
17 | #define LIS3LV02DL_ACCEL_DEV_NAME "lis3lv02dl_accel" | 18 | #define LIS3LV02DL_ACCEL_DEV_NAME "lis3lv02dl_accel" |
18 | #define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel" | 19 | #define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel" |
19 | #define LIS3DH_ACCEL_DEV_NAME "lis3dh" | 20 | #define LIS3DH_ACCEL_DEV_NAME "lis3dh" |
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c index a03a1417dd63..fee32e3d7a05 100644 --- a/drivers/iio/accel/st_accel_core.c +++ b/drivers/iio/accel/st_accel_core.c | |||
@@ -39,6 +39,9 @@ | |||
39 | #define ST_ACCEL_FS_AVL_6G 6 | 39 | #define ST_ACCEL_FS_AVL_6G 6 |
40 | #define ST_ACCEL_FS_AVL_8G 8 | 40 | #define ST_ACCEL_FS_AVL_8G 8 |
41 | #define ST_ACCEL_FS_AVL_16G 16 | 41 | #define ST_ACCEL_FS_AVL_16G 16 |
42 | #define ST_ACCEL_FS_AVL_100G 100 | ||
43 | #define ST_ACCEL_FS_AVL_200G 200 | ||
44 | #define ST_ACCEL_FS_AVL_400G 400 | ||
42 | 45 | ||
43 | /* CUSTOM VALUES FOR SENSOR 1 */ | 46 | /* CUSTOM VALUES FOR SENSOR 1 */ |
44 | #define ST_ACCEL_1_WAI_EXP 0x33 | 47 | #define ST_ACCEL_1_WAI_EXP 0x33 |
@@ -181,6 +184,33 @@ | |||
181 | #define ST_ACCEL_5_IG1_EN_MASK 0x08 | 184 | #define ST_ACCEL_5_IG1_EN_MASK 0x08 |
182 | #define ST_ACCEL_5_MULTIREAD_BIT false | 185 | #define ST_ACCEL_5_MULTIREAD_BIT false |
183 | 186 | ||
187 | /* CUSTOM VALUES FOR SENSOR 6 */ | ||
188 | #define ST_ACCEL_6_WAI_EXP 0x32 | ||
189 | #define ST_ACCEL_6_ODR_ADDR 0x20 | ||
190 | #define ST_ACCEL_6_ODR_MASK 0x18 | ||
191 | #define ST_ACCEL_6_ODR_AVL_50HZ_VAL 0x00 | ||
192 | #define ST_ACCEL_6_ODR_AVL_100HZ_VAL 0x01 | ||
193 | #define ST_ACCEL_6_ODR_AVL_400HZ_VAL 0x02 | ||
194 | #define ST_ACCEL_6_ODR_AVL_1000HZ_VAL 0x03 | ||
195 | #define ST_ACCEL_6_PW_ADDR 0x20 | ||
196 | #define ST_ACCEL_6_PW_MASK 0x20 | ||
197 | #define ST_ACCEL_6_FS_ADDR 0x23 | ||
198 | #define ST_ACCEL_6_FS_MASK 0x30 | ||
199 | #define ST_ACCEL_6_FS_AVL_100_VAL 0x00 | ||
200 | #define ST_ACCEL_6_FS_AVL_200_VAL 0x01 | ||
201 | #define ST_ACCEL_6_FS_AVL_400_VAL 0x03 | ||
202 | #define ST_ACCEL_6_FS_AVL_100_GAIN IIO_G_TO_M_S_2(49000) | ||
203 | #define ST_ACCEL_6_FS_AVL_200_GAIN IIO_G_TO_M_S_2(98000) | ||
204 | #define ST_ACCEL_6_FS_AVL_400_GAIN IIO_G_TO_M_S_2(195000) | ||
205 | #define ST_ACCEL_6_BDU_ADDR 0x23 | ||
206 | #define ST_ACCEL_6_BDU_MASK 0x80 | ||
207 | #define ST_ACCEL_6_DRDY_IRQ_ADDR 0x22 | ||
208 | #define ST_ACCEL_6_DRDY_IRQ_INT1_MASK 0x02 | ||
209 | #define ST_ACCEL_6_DRDY_IRQ_INT2_MASK 0x10 | ||
210 | #define ST_ACCEL_6_IHL_IRQ_ADDR 0x22 | ||
211 | #define ST_ACCEL_6_IHL_IRQ_MASK 0x80 | ||
212 | #define ST_ACCEL_6_MULTIREAD_BIT true | ||
213 | |||
184 | static const struct iio_chan_spec st_accel_8bit_channels[] = { | 214 | static const struct iio_chan_spec st_accel_8bit_channels[] = { |
185 | ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, | 215 | ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, |
186 | BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), | 216 | BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), |
@@ -557,6 +587,68 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { | |||
557 | .multi_read_bit = ST_ACCEL_5_MULTIREAD_BIT, | 587 | .multi_read_bit = ST_ACCEL_5_MULTIREAD_BIT, |
558 | .bootime = 2, /* guess */ | 588 | .bootime = 2, /* guess */ |
559 | }, | 589 | }, |
590 | { | ||
591 | .wai = ST_ACCEL_6_WAI_EXP, | ||
592 | .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, | ||
593 | .sensors_supported = { | ||
594 | [0] = H3LIS331DL_DRIVER_NAME, | ||
595 | }, | ||
596 | .ch = (struct iio_chan_spec *)st_accel_12bit_channels, | ||
597 | .odr = { | ||
598 | .addr = ST_ACCEL_6_ODR_ADDR, | ||
599 | .mask = ST_ACCEL_6_ODR_MASK, | ||
600 | .odr_avl = { | ||
601 | { 50, ST_ACCEL_6_ODR_AVL_50HZ_VAL }, | ||
602 | { 100, ST_ACCEL_6_ODR_AVL_100HZ_VAL, }, | ||
603 | { 400, ST_ACCEL_6_ODR_AVL_400HZ_VAL, }, | ||
604 | { 1000, ST_ACCEL_6_ODR_AVL_1000HZ_VAL, }, | ||
605 | }, | ||
606 | }, | ||
607 | .pw = { | ||
608 | .addr = ST_ACCEL_6_PW_ADDR, | ||
609 | .mask = ST_ACCEL_6_PW_MASK, | ||
610 | .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE, | ||
611 | .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, | ||
612 | }, | ||
613 | .enable_axis = { | ||
614 | .addr = ST_SENSORS_DEFAULT_AXIS_ADDR, | ||
615 | .mask = ST_SENSORS_DEFAULT_AXIS_MASK, | ||
616 | }, | ||
617 | .fs = { | ||
618 | .addr = ST_ACCEL_6_FS_ADDR, | ||
619 | .mask = ST_ACCEL_6_FS_MASK, | ||
620 | .fs_avl = { | ||
621 | [0] = { | ||
622 | .num = ST_ACCEL_FS_AVL_100G, | ||
623 | .value = ST_ACCEL_6_FS_AVL_100_VAL, | ||
624 | .gain = ST_ACCEL_6_FS_AVL_100_GAIN, | ||
625 | }, | ||
626 | [1] = { | ||
627 | .num = ST_ACCEL_FS_AVL_200G, | ||
628 | .value = ST_ACCEL_6_FS_AVL_200_VAL, | ||
629 | .gain = ST_ACCEL_6_FS_AVL_200_GAIN, | ||
630 | }, | ||
631 | [2] = { | ||
632 | .num = ST_ACCEL_FS_AVL_400G, | ||
633 | .value = ST_ACCEL_6_FS_AVL_400_VAL, | ||
634 | .gain = ST_ACCEL_6_FS_AVL_400_GAIN, | ||
635 | }, | ||
636 | }, | ||
637 | }, | ||
638 | .bdu = { | ||
639 | .addr = ST_ACCEL_6_BDU_ADDR, | ||
640 | .mask = ST_ACCEL_6_BDU_MASK, | ||
641 | }, | ||
642 | .drdy_irq = { | ||
643 | .addr = ST_ACCEL_6_DRDY_IRQ_ADDR, | ||
644 | .mask_int1 = ST_ACCEL_6_DRDY_IRQ_INT1_MASK, | ||
645 | .mask_int2 = ST_ACCEL_6_DRDY_IRQ_INT2_MASK, | ||
646 | .addr_ihl = ST_ACCEL_6_IHL_IRQ_ADDR, | ||
647 | .mask_ihl = ST_ACCEL_6_IHL_IRQ_MASK, | ||
648 | }, | ||
649 | .multi_read_bit = ST_ACCEL_6_MULTIREAD_BIT, | ||
650 | .bootime = 2, | ||
651 | }, | ||
560 | }; | 652 | }; |
561 | 653 | ||
562 | static int st_accel_read_raw(struct iio_dev *indio_dev, | 654 | static int st_accel_read_raw(struct iio_dev *indio_dev, |
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c index 294a32f89367..7333ee9fb11b 100644 --- a/drivers/iio/accel/st_accel_i2c.c +++ b/drivers/iio/accel/st_accel_i2c.c | |||
@@ -76,6 +76,10 @@ static const struct of_device_id st_accel_of_match[] = { | |||
76 | .compatible = "st,lis2dh12-accel", | 76 | .compatible = "st,lis2dh12-accel", |
77 | .data = LIS2DH12_ACCEL_DEV_NAME, | 77 | .data = LIS2DH12_ACCEL_DEV_NAME, |
78 | }, | 78 | }, |
79 | { | ||
80 | .compatible = "st,h3lis331dl-accel", | ||
81 | .data = H3LIS331DL_DRIVER_NAME, | ||
82 | }, | ||
79 | {}, | 83 | {}, |
80 | }; | 84 | }; |
81 | MODULE_DEVICE_TABLE(of, st_accel_of_match); | 85 | MODULE_DEVICE_TABLE(of, st_accel_of_match); |
diff --git a/drivers/iio/accel/stk8312.c b/drivers/iio/accel/stk8312.c index 85fe7f7247c1..e31023dc5f1b 100644 --- a/drivers/iio/accel/stk8312.c +++ b/drivers/iio/accel/stk8312.c | |||
@@ -11,7 +11,6 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/acpi.h> | 13 | #include <linux/acpi.h> |
14 | #include <linux/gpio/consumer.h> | ||
15 | #include <linux/i2c.h> | 14 | #include <linux/i2c.h> |
16 | #include <linux/interrupt.h> | 15 | #include <linux/interrupt.h> |
17 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
diff --git a/drivers/iio/accel/stk8ba50.c b/drivers/iio/accel/stk8ba50.c index 5709d9eb8f34..300d955bad00 100644 --- a/drivers/iio/accel/stk8ba50.c +++ b/drivers/iio/accel/stk8ba50.c | |||
@@ -11,7 +11,6 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/acpi.h> | 13 | #include <linux/acpi.h> |
14 | #include <linux/gpio/consumer.h> | ||
15 | #include <linux/i2c.h> | 14 | #include <linux/i2c.h> |
16 | #include <linux/interrupt.h> | 15 | #include <linux/interrupt.h> |
17 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index af4aea7b20f9..5937030f0444 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig | |||
@@ -134,6 +134,7 @@ config AT91_ADC | |||
134 | config AT91_SAMA5D2_ADC | 134 | config AT91_SAMA5D2_ADC |
135 | tristate "Atmel AT91 SAMA5D2 ADC" | 135 | tristate "Atmel AT91 SAMA5D2 ADC" |
136 | depends on ARCH_AT91 || COMPILE_TEST | 136 | depends on ARCH_AT91 || COMPILE_TEST |
137 | depends on HAS_IOMEM | ||
137 | help | 138 | help |
138 | Say yes here to build support for Atmel SAMA5D2 ADC which is | 139 | Say yes here to build support for Atmel SAMA5D2 ADC which is |
139 | available on SAMA5D2 SoC family. | 140 | available on SAMA5D2 SoC family. |
@@ -241,6 +242,16 @@ config LP8788_ADC | |||
241 | To compile this driver as a module, choose M here: the module will be | 242 | To compile this driver as a module, choose M here: the module will be |
242 | called lp8788_adc. | 243 | called lp8788_adc. |
243 | 244 | ||
245 | config LPC18XX_ADC | ||
246 | tristate "NXP LPC18xx ADC driver" | ||
247 | depends on ARCH_LPC18XX || COMPILE_TEST | ||
248 | depends on OF && HAS_IOMEM | ||
249 | help | ||
250 | Say yes here to build support for NXP LPC18XX ADC. | ||
251 | |||
252 | To compile this driver as a module, choose M here: the module will be | ||
253 | called lpc18xx_adc. | ||
254 | |||
244 | config MAX1027 | 255 | config MAX1027 |
245 | tristate "Maxim max1027 ADC driver" | 256 | tristate "Maxim max1027 ADC driver" |
246 | depends on SPI | 257 | depends on SPI |
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 0cb79210a4b0..38638d46f972 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile | |||
@@ -25,6 +25,7 @@ obj-$(CONFIG_HI8435) += hi8435.o | |||
25 | obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o | 25 | obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o |
26 | obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o | 26 | obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o |
27 | obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o | 27 | obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o |
28 | obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o | ||
28 | obj-$(CONFIG_MAX1027) += max1027.o | 29 | obj-$(CONFIG_MAX1027) += max1027.o |
29 | obj-$(CONFIG_MAX1363) += max1363.o | 30 | obj-$(CONFIG_MAX1363) += max1363.o |
30 | obj-$(CONFIG_MCP320X) += mcp320x.o | 31 | obj-$(CONFIG_MCP320X) += mcp320x.o |
diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c index dbee13ad33a3..07adb1070fc2 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c | |||
@@ -66,8 +66,10 @@ | |||
66 | #define AT91_SAMA5D2_MR_PRESCAL(v) ((v) << AT91_SAMA5D2_MR_PRESCAL_OFFSET) | 66 | #define AT91_SAMA5D2_MR_PRESCAL(v) ((v) << AT91_SAMA5D2_MR_PRESCAL_OFFSET) |
67 | #define AT91_SAMA5D2_MR_PRESCAL_OFFSET 8 | 67 | #define AT91_SAMA5D2_MR_PRESCAL_OFFSET 8 |
68 | #define AT91_SAMA5D2_MR_PRESCAL_MAX 0xff | 68 | #define AT91_SAMA5D2_MR_PRESCAL_MAX 0xff |
69 | #define AT91_SAMA5D2_MR_PRESCAL_MASK GENMASK(15, 8) | ||
69 | /* Startup Time */ | 70 | /* Startup Time */ |
70 | #define AT91_SAMA5D2_MR_STARTUP(v) ((v) << 16) | 71 | #define AT91_SAMA5D2_MR_STARTUP(v) ((v) << 16) |
72 | #define AT91_SAMA5D2_MR_STARTUP_MASK GENMASK(19, 16) | ||
71 | /* Analog Change */ | 73 | /* Analog Change */ |
72 | #define AT91_SAMA5D2_MR_ANACH BIT(23) | 74 | #define AT91_SAMA5D2_MR_ANACH BIT(23) |
73 | /* Tracking Time */ | 75 | /* Tracking Time */ |
@@ -92,13 +94,13 @@ | |||
92 | /* Last Converted Data Register */ | 94 | /* Last Converted Data Register */ |
93 | #define AT91_SAMA5D2_LCDR 0x20 | 95 | #define AT91_SAMA5D2_LCDR 0x20 |
94 | /* Interrupt Enable Register */ | 96 | /* Interrupt Enable Register */ |
95 | #define AT91_SAMA5D2_IER 0x24 | 97 | #define AT91_SAMA5D2_IER 0x24 |
96 | /* Interrupt Disable Register */ | 98 | /* Interrupt Disable Register */ |
97 | #define AT91_SAMA5D2_IDR 0x28 | 99 | #define AT91_SAMA5D2_IDR 0x28 |
98 | /* Interrupt Mask Register */ | 100 | /* Interrupt Mask Register */ |
99 | #define AT91_SAMA5D2_IMR 0x2c | 101 | #define AT91_SAMA5D2_IMR 0x2c |
100 | /* Interrupt Status Register */ | 102 | /* Interrupt Status Register */ |
101 | #define AT91_SAMA5D2_ISR 0x30 | 103 | #define AT91_SAMA5D2_ISR 0x30 |
102 | /* Last Channel Trigger Mode Register */ | 104 | /* Last Channel Trigger Mode Register */ |
103 | #define AT91_SAMA5D2_LCTMR 0x34 | 105 | #define AT91_SAMA5D2_LCTMR 0x34 |
104 | /* Last Channel Compare Window Register */ | 106 | /* Last Channel Compare Window Register */ |
@@ -106,17 +108,20 @@ | |||
106 | /* Overrun Status Register */ | 108 | /* Overrun Status Register */ |
107 | #define AT91_SAMA5D2_OVER 0x3c | 109 | #define AT91_SAMA5D2_OVER 0x3c |
108 | /* Extended Mode Register */ | 110 | /* Extended Mode Register */ |
109 | #define AT91_SAMA5D2_EMR 0x40 | 111 | #define AT91_SAMA5D2_EMR 0x40 |
110 | /* Compare Window Register */ | 112 | /* Compare Window Register */ |
111 | #define AT91_SAMA5D2_CWR 0x44 | 113 | #define AT91_SAMA5D2_CWR 0x44 |
112 | /* Channel Gain Register */ | 114 | /* Channel Gain Register */ |
113 | #define AT91_SAMA5D2_CGR 0x48 | 115 | #define AT91_SAMA5D2_CGR 0x48 |
116 | |||
114 | /* Channel Offset Register */ | 117 | /* Channel Offset Register */ |
115 | #define AT91_SAMA5D2_COR 0x4c | 118 | #define AT91_SAMA5D2_COR 0x4c |
119 | #define AT91_SAMA5D2_COR_DIFF_OFFSET 16 | ||
120 | |||
116 | /* Channel Data Register 0 */ | 121 | /* Channel Data Register 0 */ |
117 | #define AT91_SAMA5D2_CDR0 0x50 | 122 | #define AT91_SAMA5D2_CDR0 0x50 |
118 | /* Analog Control Register */ | 123 | /* Analog Control Register */ |
119 | #define AT91_SAMA5D2_ACR 0x94 | 124 | #define AT91_SAMA5D2_ACR 0x94 |
120 | /* Touchscreen Mode Register */ | 125 | /* Touchscreen Mode Register */ |
121 | #define AT91_SAMA5D2_TSMR 0xb0 | 126 | #define AT91_SAMA5D2_TSMR 0xb0 |
122 | /* Touchscreen X Position Register */ | 127 | /* Touchscreen X Position Register */ |
@@ -130,7 +135,7 @@ | |||
130 | /* Correction Select Register */ | 135 | /* Correction Select Register */ |
131 | #define AT91_SAMA5D2_COSR 0xd0 | 136 | #define AT91_SAMA5D2_COSR 0xd0 |
132 | /* Correction Value Register */ | 137 | /* Correction Value Register */ |
133 | #define AT91_SAMA5D2_CVR 0xd4 | 138 | #define AT91_SAMA5D2_CVR 0xd4 |
134 | /* Channel Error Correction Register */ | 139 | /* Channel Error Correction Register */ |
135 | #define AT91_SAMA5D2_CECR 0xd8 | 140 | #define AT91_SAMA5D2_CECR 0xd8 |
136 | /* Write Protection Mode Register */ | 141 | /* Write Protection Mode Register */ |
@@ -140,7 +145,7 @@ | |||
140 | /* Version Register */ | 145 | /* Version Register */ |
141 | #define AT91_SAMA5D2_VERSION 0xfc | 146 | #define AT91_SAMA5D2_VERSION 0xfc |
142 | 147 | ||
143 | #define AT91_AT91_SAMA5D2_CHAN(num, addr) \ | 148 | #define AT91_SAMA5D2_CHAN_SINGLE(num, addr) \ |
144 | { \ | 149 | { \ |
145 | .type = IIO_VOLTAGE, \ | 150 | .type = IIO_VOLTAGE, \ |
146 | .channel = num, \ | 151 | .channel = num, \ |
@@ -156,6 +161,24 @@ | |||
156 | .indexed = 1, \ | 161 | .indexed = 1, \ |
157 | } | 162 | } |
158 | 163 | ||
164 | #define AT91_SAMA5D2_CHAN_DIFF(num, num2, addr) \ | ||
165 | { \ | ||
166 | .type = IIO_VOLTAGE, \ | ||
167 | .differential = 1, \ | ||
168 | .channel = num, \ | ||
169 | .channel2 = num2, \ | ||
170 | .address = addr, \ | ||
171 | .scan_type = { \ | ||
172 | .sign = 's', \ | ||
173 | .realbits = 12, \ | ||
174 | }, \ | ||
175 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
176 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ | ||
177 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\ | ||
178 | .datasheet_name = "CH"#num"-CH"#num2, \ | ||
179 | .indexed = 1, \ | ||
180 | } | ||
181 | |||
159 | #define at91_adc_readl(st, reg) readl_relaxed(st->base + reg) | 182 | #define at91_adc_readl(st, reg) readl_relaxed(st->base + reg) |
160 | #define at91_adc_writel(st, reg, val) writel_relaxed(val, st->base + reg) | 183 | #define at91_adc_writel(st, reg, val) writel_relaxed(val, st->base + reg) |
161 | 184 | ||
@@ -185,18 +208,24 @@ struct at91_adc_state { | |||
185 | }; | 208 | }; |
186 | 209 | ||
187 | static const struct iio_chan_spec at91_adc_channels[] = { | 210 | static const struct iio_chan_spec at91_adc_channels[] = { |
188 | AT91_AT91_SAMA5D2_CHAN(0, 0x50), | 211 | AT91_SAMA5D2_CHAN_SINGLE(0, 0x50), |
189 | AT91_AT91_SAMA5D2_CHAN(1, 0x54), | 212 | AT91_SAMA5D2_CHAN_SINGLE(1, 0x54), |
190 | AT91_AT91_SAMA5D2_CHAN(2, 0x58), | 213 | AT91_SAMA5D2_CHAN_SINGLE(2, 0x58), |
191 | AT91_AT91_SAMA5D2_CHAN(3, 0x5c), | 214 | AT91_SAMA5D2_CHAN_SINGLE(3, 0x5c), |
192 | AT91_AT91_SAMA5D2_CHAN(4, 0x60), | 215 | AT91_SAMA5D2_CHAN_SINGLE(4, 0x60), |
193 | AT91_AT91_SAMA5D2_CHAN(5, 0x64), | 216 | AT91_SAMA5D2_CHAN_SINGLE(5, 0x64), |
194 | AT91_AT91_SAMA5D2_CHAN(6, 0x68), | 217 | AT91_SAMA5D2_CHAN_SINGLE(6, 0x68), |
195 | AT91_AT91_SAMA5D2_CHAN(7, 0x6c), | 218 | AT91_SAMA5D2_CHAN_SINGLE(7, 0x6c), |
196 | AT91_AT91_SAMA5D2_CHAN(8, 0x70), | 219 | AT91_SAMA5D2_CHAN_SINGLE(8, 0x70), |
197 | AT91_AT91_SAMA5D2_CHAN(9, 0x74), | 220 | AT91_SAMA5D2_CHAN_SINGLE(9, 0x74), |
198 | AT91_AT91_SAMA5D2_CHAN(10, 0x78), | 221 | AT91_SAMA5D2_CHAN_SINGLE(10, 0x78), |
199 | AT91_AT91_SAMA5D2_CHAN(11, 0x7c), | 222 | AT91_SAMA5D2_CHAN_SINGLE(11, 0x7c), |
223 | AT91_SAMA5D2_CHAN_DIFF(0, 1, 0x50), | ||
224 | AT91_SAMA5D2_CHAN_DIFF(2, 3, 0x58), | ||
225 | AT91_SAMA5D2_CHAN_DIFF(4, 5, 0x60), | ||
226 | AT91_SAMA5D2_CHAN_DIFF(6, 7, 0x68), | ||
227 | AT91_SAMA5D2_CHAN_DIFF(8, 9, 0x70), | ||
228 | AT91_SAMA5D2_CHAN_DIFF(10, 11, 0x78), | ||
200 | }; | 229 | }; |
201 | 230 | ||
202 | static unsigned at91_adc_startup_time(unsigned startup_time_min, | 231 | static unsigned at91_adc_startup_time(unsigned startup_time_min, |
@@ -226,7 +255,7 @@ static unsigned at91_adc_startup_time(unsigned startup_time_min, | |||
226 | static void at91_adc_setup_samp_freq(struct at91_adc_state *st, unsigned freq) | 255 | static void at91_adc_setup_samp_freq(struct at91_adc_state *st, unsigned freq) |
227 | { | 256 | { |
228 | struct iio_dev *indio_dev = iio_priv_to_dev(st); | 257 | struct iio_dev *indio_dev = iio_priv_to_dev(st); |
229 | unsigned f_per, prescal, startup; | 258 | unsigned f_per, prescal, startup, mr; |
230 | 259 | ||
231 | f_per = clk_get_rate(st->per_clk); | 260 | f_per = clk_get_rate(st->per_clk); |
232 | prescal = (f_per / (2 * freq)) - 1; | 261 | prescal = (f_per / (2 * freq)) - 1; |
@@ -234,10 +263,11 @@ static void at91_adc_setup_samp_freq(struct at91_adc_state *st, unsigned freq) | |||
234 | startup = at91_adc_startup_time(st->soc_info.startup_time, | 263 | startup = at91_adc_startup_time(st->soc_info.startup_time, |
235 | freq / 1000); | 264 | freq / 1000); |
236 | 265 | ||
237 | at91_adc_writel(st, AT91_SAMA5D2_MR, | 266 | mr = at91_adc_readl(st, AT91_SAMA5D2_MR); |
238 | AT91_SAMA5D2_MR_TRANSFER(2) | 267 | mr &= ~(AT91_SAMA5D2_MR_STARTUP_MASK | AT91_SAMA5D2_MR_PRESCAL_MASK); |
239 | | AT91_SAMA5D2_MR_STARTUP(startup) | 268 | mr |= AT91_SAMA5D2_MR_STARTUP(startup); |
240 | | AT91_SAMA5D2_MR_PRESCAL(prescal)); | 269 | mr |= AT91_SAMA5D2_MR_PRESCAL(prescal); |
270 | at91_adc_writel(st, AT91_SAMA5D2_MR, mr); | ||
241 | 271 | ||
242 | dev_dbg(&indio_dev->dev, "freq: %u, startup: %u, prescal: %u\n", | 272 | dev_dbg(&indio_dev->dev, "freq: %u, startup: %u, prescal: %u\n", |
243 | freq, startup, prescal); | 273 | freq, startup, prescal); |
@@ -278,6 +308,7 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev, | |||
278 | int *val, int *val2, long mask) | 308 | int *val, int *val2, long mask) |
279 | { | 309 | { |
280 | struct at91_adc_state *st = iio_priv(indio_dev); | 310 | struct at91_adc_state *st = iio_priv(indio_dev); |
311 | u32 cor = 0; | ||
281 | int ret; | 312 | int ret; |
282 | 313 | ||
283 | switch (mask) { | 314 | switch (mask) { |
@@ -286,6 +317,11 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev, | |||
286 | 317 | ||
287 | st->chan = chan; | 318 | st->chan = chan; |
288 | 319 | ||
320 | if (chan->differential) | ||
321 | cor = (BIT(chan->channel) | BIT(chan->channel2)) << | ||
322 | AT91_SAMA5D2_COR_DIFF_OFFSET; | ||
323 | |||
324 | at91_adc_writel(st, AT91_SAMA5D2_COR, cor); | ||
289 | at91_adc_writel(st, AT91_SAMA5D2_CHER, BIT(chan->channel)); | 325 | at91_adc_writel(st, AT91_SAMA5D2_CHER, BIT(chan->channel)); |
290 | at91_adc_writel(st, AT91_SAMA5D2_IER, BIT(chan->channel)); | 326 | at91_adc_writel(st, AT91_SAMA5D2_IER, BIT(chan->channel)); |
291 | at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_START); | 327 | at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_START); |
@@ -298,6 +334,8 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev, | |||
298 | 334 | ||
299 | if (ret > 0) { | 335 | if (ret > 0) { |
300 | *val = st->conversion_value; | 336 | *val = st->conversion_value; |
337 | if (chan->scan_type.sign == 's') | ||
338 | *val = sign_extend32(*val, 11); | ||
301 | ret = IIO_VAL_INT; | 339 | ret = IIO_VAL_INT; |
302 | st->conversion_done = false; | 340 | st->conversion_done = false; |
303 | } | 341 | } |
@@ -310,6 +348,8 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev, | |||
310 | 348 | ||
311 | case IIO_CHAN_INFO_SCALE: | 349 | case IIO_CHAN_INFO_SCALE: |
312 | *val = st->vref_uv / 1000; | 350 | *val = st->vref_uv / 1000; |
351 | if (chan->differential) | ||
352 | *val *= 2; | ||
313 | *val2 = chan->scan_type.realbits; | 353 | *val2 = chan->scan_type.realbits; |
314 | return IIO_VAL_FRACTIONAL_LOG2; | 354 | return IIO_VAL_FRACTIONAL_LOG2; |
315 | 355 | ||
@@ -444,6 +484,12 @@ static int at91_adc_probe(struct platform_device *pdev) | |||
444 | 484 | ||
445 | at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST); | 485 | at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_SWRST); |
446 | at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff); | 486 | at91_adc_writel(st, AT91_SAMA5D2_IDR, 0xffffffff); |
487 | /* | ||
488 | * Transfer field must be set to 2 according to the datasheet and | ||
489 | * allows different analog settings for each channel. | ||
490 | */ | ||
491 | at91_adc_writel(st, AT91_SAMA5D2_MR, | ||
492 | AT91_SAMA5D2_MR_TRANSFER(2) | AT91_SAMA5D2_MR_ANACH); | ||
447 | 493 | ||
448 | at91_adc_setup_samp_freq(st, st->soc_info.min_sample_rate); | 494 | at91_adc_setup_samp_freq(st, st->soc_info.min_sample_rate); |
449 | 495 | ||
diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c index 65909d5858b1..502f2fbe8aef 100644 --- a/drivers/iio/adc/ina2xx-adc.c +++ b/drivers/iio/adc/ina2xx-adc.c | |||
@@ -185,9 +185,9 @@ static int ina2xx_read_raw(struct iio_dev *indio_dev, | |||
185 | case IIO_CHAN_INFO_SCALE: | 185 | case IIO_CHAN_INFO_SCALE: |
186 | switch (chan->address) { | 186 | switch (chan->address) { |
187 | case INA2XX_SHUNT_VOLTAGE: | 187 | case INA2XX_SHUNT_VOLTAGE: |
188 | /* processed (mV) = raw*1000/shunt_div */ | 188 | /* processed (mV) = raw/shunt_div */ |
189 | *val2 = chip->config->shunt_div; | 189 | *val2 = chip->config->shunt_div; |
190 | *val = 1000; | 190 | *val = 1; |
191 | return IIO_VAL_FRACTIONAL; | 191 | return IIO_VAL_FRACTIONAL; |
192 | 192 | ||
193 | case INA2XX_BUS_VOLTAGE: | 193 | case INA2XX_BUS_VOLTAGE: |
@@ -350,6 +350,23 @@ static ssize_t ina2xx_allow_async_readout_store(struct device *dev, | |||
350 | return len; | 350 | return len; |
351 | } | 351 | } |
352 | 352 | ||
353 | /* | ||
354 | * Set current LSB to 1mA, shunt is in uOhms | ||
355 | * (equation 13 in datasheet). We hardcode a Current_LSB | ||
356 | * of 1.0 x10-6. The only remaining parameter is RShunt. | ||
357 | * There is no need to expose the CALIBRATION register | ||
358 | * to the user for now. But we need to reset this register | ||
359 | * if the user updates RShunt after driver init, e.g upon | ||
360 | * reading an EEPROM/Probe-type value. | ||
361 | */ | ||
362 | static int ina2xx_set_calibration(struct ina2xx_chip_info *chip) | ||
363 | { | ||
364 | u16 regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor, | ||
365 | chip->shunt_resistor); | ||
366 | |||
367 | return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval); | ||
368 | } | ||
369 | |||
353 | static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val) | 370 | static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val) |
354 | { | 371 | { |
355 | if (val <= 0 || val > chip->config->calibration_factor) | 372 | if (val <= 0 || val > chip->config->calibration_factor) |
@@ -385,6 +402,11 @@ static ssize_t ina2xx_shunt_resistor_store(struct device *dev, | |||
385 | if (ret) | 402 | if (ret) |
386 | return ret; | 403 | return ret; |
387 | 404 | ||
405 | /* Update the Calibration register */ | ||
406 | ret = ina2xx_set_calibration(chip); | ||
407 | if (ret) | ||
408 | return ret; | ||
409 | |||
388 | return len; | 410 | return len; |
389 | } | 411 | } |
390 | 412 | ||
@@ -602,24 +624,11 @@ static const struct iio_info ina2xx_info = { | |||
602 | /* Initialize the configuration and calibration registers. */ | 624 | /* Initialize the configuration and calibration registers. */ |
603 | static int ina2xx_init(struct ina2xx_chip_info *chip, unsigned int config) | 625 | static int ina2xx_init(struct ina2xx_chip_info *chip, unsigned int config) |
604 | { | 626 | { |
605 | u16 regval; | 627 | int ret = regmap_write(chip->regmap, INA2XX_CONFIG, config); |
606 | int ret; | ||
607 | |||
608 | ret = regmap_write(chip->regmap, INA2XX_CONFIG, config); | ||
609 | if (ret) | 628 | if (ret) |
610 | return ret; | 629 | return ret; |
611 | 630 | ||
612 | /* | 631 | return ina2xx_set_calibration(chip); |
613 | * Set current LSB to 1mA, shunt is in uOhms | ||
614 | * (equation 13 in datasheet). We hardcode a Current_LSB | ||
615 | * of 1.0 x10-6. The only remaining parameter is RShunt. | ||
616 | * There is no need to expose the CALIBRATION register | ||
617 | * to the user for now. | ||
618 | */ | ||
619 | regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor, | ||
620 | chip->shunt_resistor); | ||
621 | |||
622 | return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval); | ||
623 | } | 632 | } |
624 | 633 | ||
625 | static int ina2xx_probe(struct i2c_client *client, | 634 | static int ina2xx_probe(struct i2c_client *client, |
diff --git a/drivers/iio/adc/lpc18xx_adc.c b/drivers/iio/adc/lpc18xx_adc.c new file mode 100644 index 000000000000..3ef18f4b27f0 --- /dev/null +++ b/drivers/iio/adc/lpc18xx_adc.c | |||
@@ -0,0 +1,231 @@ | |||
1 | /* | ||
2 | * IIO ADC driver for NXP LPC18xx ADC | ||
3 | * | ||
4 | * Copyright (C) 2016 Joachim Eastwood <manabian@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * UNSUPPORTED hardware features: | ||
11 | * - Hardware triggers | ||
12 | * - Burst mode | ||
13 | * - Interrupts | ||
14 | * - DMA | ||
15 | */ | ||
16 | |||
17 | #include <linux/clk.h> | ||
18 | #include <linux/err.h> | ||
19 | #include <linux/iio/iio.h> | ||
20 | #include <linux/iio/driver.h> | ||
21 | #include <linux/io.h> | ||
22 | #include <linux/iopoll.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/mutex.h> | ||
25 | #include <linux/of.h> | ||
26 | #include <linux/of_device.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/regulator/consumer.h> | ||
29 | |||
30 | /* LPC18XX ADC registers and bits */ | ||
31 | #define LPC18XX_ADC_CR 0x000 | ||
32 | #define LPC18XX_ADC_CR_CLKDIV_SHIFT 8 | ||
33 | #define LPC18XX_ADC_CR_PDN BIT(21) | ||
34 | #define LPC18XX_ADC_CR_START_NOW (0x1 << 24) | ||
35 | #define LPC18XX_ADC_GDR 0x004 | ||
36 | |||
37 | /* Data register bits */ | ||
38 | #define LPC18XX_ADC_SAMPLE_SHIFT 6 | ||
39 | #define LPC18XX_ADC_SAMPLE_MASK 0x3ff | ||
40 | #define LPC18XX_ADC_CONV_DONE BIT(31) | ||
41 | |||
42 | /* Clock should be 4.5 MHz or less */ | ||
43 | #define LPC18XX_ADC_CLK_TARGET 4500000 | ||
44 | |||
45 | struct lpc18xx_adc { | ||
46 | struct regulator *vref; | ||
47 | void __iomem *base; | ||
48 | struct device *dev; | ||
49 | struct mutex lock; | ||
50 | struct clk *clk; | ||
51 | u32 cr_reg; | ||
52 | }; | ||
53 | |||
54 | #define LPC18XX_ADC_CHAN(_idx) { \ | ||
55 | .type = IIO_VOLTAGE, \ | ||
56 | .indexed = 1, \ | ||
57 | .channel = _idx, \ | ||
58 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
59 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ | ||
60 | } | ||
61 | |||
62 | static const struct iio_chan_spec lpc18xx_adc_iio_channels[] = { | ||
63 | LPC18XX_ADC_CHAN(0), | ||
64 | LPC18XX_ADC_CHAN(1), | ||
65 | LPC18XX_ADC_CHAN(2), | ||
66 | LPC18XX_ADC_CHAN(3), | ||
67 | LPC18XX_ADC_CHAN(4), | ||
68 | LPC18XX_ADC_CHAN(5), | ||
69 | LPC18XX_ADC_CHAN(6), | ||
70 | LPC18XX_ADC_CHAN(7), | ||
71 | }; | ||
72 | |||
73 | static int lpc18xx_adc_read_chan(struct lpc18xx_adc *adc, unsigned int ch) | ||
74 | { | ||
75 | int ret; | ||
76 | u32 reg; | ||
77 | |||
78 | reg = adc->cr_reg | BIT(ch) | LPC18XX_ADC_CR_START_NOW; | ||
79 | writel(reg, adc->base + LPC18XX_ADC_CR); | ||
80 | |||
81 | ret = readl_poll_timeout(adc->base + LPC18XX_ADC_GDR, reg, | ||
82 | reg & LPC18XX_ADC_CONV_DONE, 3, 9); | ||
83 | if (ret) { | ||
84 | dev_warn(adc->dev, "adc read timed out\n"); | ||
85 | return ret; | ||
86 | } | ||
87 | |||
88 | return (reg >> LPC18XX_ADC_SAMPLE_SHIFT) & LPC18XX_ADC_SAMPLE_MASK; | ||
89 | } | ||
90 | |||
91 | static int lpc18xx_adc_read_raw(struct iio_dev *indio_dev, | ||
92 | struct iio_chan_spec const *chan, | ||
93 | int *val, int *val2, long mask) | ||
94 | { | ||
95 | struct lpc18xx_adc *adc = iio_priv(indio_dev); | ||
96 | |||
97 | switch (mask) { | ||
98 | case IIO_CHAN_INFO_RAW: | ||
99 | mutex_lock(&adc->lock); | ||
100 | *val = lpc18xx_adc_read_chan(adc, chan->channel); | ||
101 | mutex_unlock(&adc->lock); | ||
102 | if (*val < 0) | ||
103 | return *val; | ||
104 | |||
105 | return IIO_VAL_INT; | ||
106 | |||
107 | case IIO_CHAN_INFO_SCALE: | ||
108 | *val = regulator_get_voltage(adc->vref) / 1000; | ||
109 | *val2 = 10; | ||
110 | |||
111 | return IIO_VAL_FRACTIONAL_LOG2; | ||
112 | } | ||
113 | |||
114 | return -EINVAL; | ||
115 | } | ||
116 | |||
117 | static const struct iio_info lpc18xx_adc_info = { | ||
118 | .read_raw = lpc18xx_adc_read_raw, | ||
119 | .driver_module = THIS_MODULE, | ||
120 | }; | ||
121 | |||
122 | static int lpc18xx_adc_probe(struct platform_device *pdev) | ||
123 | { | ||
124 | struct iio_dev *indio_dev; | ||
125 | struct lpc18xx_adc *adc; | ||
126 | struct resource *res; | ||
127 | unsigned int clkdiv; | ||
128 | unsigned long rate; | ||
129 | int ret; | ||
130 | |||
131 | indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc)); | ||
132 | if (!indio_dev) | ||
133 | return -ENOMEM; | ||
134 | |||
135 | platform_set_drvdata(pdev, indio_dev); | ||
136 | adc = iio_priv(indio_dev); | ||
137 | adc->dev = &pdev->dev; | ||
138 | mutex_init(&adc->lock); | ||
139 | |||
140 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
141 | adc->base = devm_ioremap_resource(&pdev->dev, res); | ||
142 | if (IS_ERR(adc->base)) | ||
143 | return PTR_ERR(adc->base); | ||
144 | |||
145 | adc->clk = devm_clk_get(&pdev->dev, NULL); | ||
146 | if (IS_ERR(adc->clk)) { | ||
147 | dev_err(&pdev->dev, "error getting clock\n"); | ||
148 | return PTR_ERR(adc->clk); | ||
149 | } | ||
150 | |||
151 | rate = clk_get_rate(adc->clk); | ||
152 | clkdiv = DIV_ROUND_UP(rate, LPC18XX_ADC_CLK_TARGET); | ||
153 | |||
154 | adc->vref = devm_regulator_get(&pdev->dev, "vref"); | ||
155 | if (IS_ERR(adc->vref)) { | ||
156 | dev_err(&pdev->dev, "error getting regulator\n"); | ||
157 | return PTR_ERR(adc->vref); | ||
158 | } | ||
159 | |||
160 | indio_dev->name = dev_name(&pdev->dev); | ||
161 | indio_dev->dev.parent = &pdev->dev; | ||
162 | indio_dev->info = &lpc18xx_adc_info; | ||
163 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
164 | indio_dev->channels = lpc18xx_adc_iio_channels; | ||
165 | indio_dev->num_channels = ARRAY_SIZE(lpc18xx_adc_iio_channels); | ||
166 | |||
167 | ret = regulator_enable(adc->vref); | ||
168 | if (ret) { | ||
169 | dev_err(&pdev->dev, "unable to enable regulator\n"); | ||
170 | return ret; | ||
171 | } | ||
172 | |||
173 | ret = clk_prepare_enable(adc->clk); | ||
174 | if (ret) { | ||
175 | dev_err(&pdev->dev, "unable to enable clock\n"); | ||
176 | goto dis_reg; | ||
177 | } | ||
178 | |||
179 | adc->cr_reg = (clkdiv << LPC18XX_ADC_CR_CLKDIV_SHIFT) | | ||
180 | LPC18XX_ADC_CR_PDN; | ||
181 | writel(adc->cr_reg, adc->base + LPC18XX_ADC_CR); | ||
182 | |||
183 | ret = iio_device_register(indio_dev); | ||
184 | if (ret) { | ||
185 | dev_err(&pdev->dev, "unable to register device\n"); | ||
186 | goto dis_clk; | ||
187 | } | ||
188 | |||
189 | return 0; | ||
190 | |||
191 | dis_clk: | ||
192 | writel(0, adc->base + LPC18XX_ADC_CR); | ||
193 | clk_disable_unprepare(adc->clk); | ||
194 | dis_reg: | ||
195 | regulator_disable(adc->vref); | ||
196 | return ret; | ||
197 | } | ||
198 | |||
199 | static int lpc18xx_adc_remove(struct platform_device *pdev) | ||
200 | { | ||
201 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); | ||
202 | struct lpc18xx_adc *adc = iio_priv(indio_dev); | ||
203 | |||
204 | iio_device_unregister(indio_dev); | ||
205 | |||
206 | writel(0, adc->base + LPC18XX_ADC_CR); | ||
207 | clk_disable_unprepare(adc->clk); | ||
208 | regulator_disable(adc->vref); | ||
209 | |||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | static const struct of_device_id lpc18xx_adc_match[] = { | ||
214 | { .compatible = "nxp,lpc1850-adc" }, | ||
215 | { /* sentinel */ } | ||
216 | }; | ||
217 | MODULE_DEVICE_TABLE(of, lpc18xx_adc_match); | ||
218 | |||
219 | static struct platform_driver lpc18xx_adc_driver = { | ||
220 | .probe = lpc18xx_adc_probe, | ||
221 | .remove = lpc18xx_adc_remove, | ||
222 | .driver = { | ||
223 | .name = "lpc18xx-adc", | ||
224 | .of_match_table = lpc18xx_adc_match, | ||
225 | }, | ||
226 | }; | ||
227 | module_platform_driver(lpc18xx_adc_driver); | ||
228 | |||
229 | MODULE_DESCRIPTION("LPC18xx ADC driver"); | ||
230 | MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>"); | ||
231 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/iio/adc/rockchip_saradc.c b/drivers/iio/adc/rockchip_saradc.c index 9c311c1e1ac7..f9ad6c2d6821 100644 --- a/drivers/iio/adc/rockchip_saradc.c +++ b/drivers/iio/adc/rockchip_saradc.c | |||
@@ -159,6 +159,22 @@ static const struct rockchip_saradc_data rk3066_tsadc_data = { | |||
159 | .clk_rate = 50000, | 159 | .clk_rate = 50000, |
160 | }; | 160 | }; |
161 | 161 | ||
162 | static const struct iio_chan_spec rockchip_rk3399_saradc_iio_channels[] = { | ||
163 | ADC_CHANNEL(0, "adc0"), | ||
164 | ADC_CHANNEL(1, "adc1"), | ||
165 | ADC_CHANNEL(2, "adc2"), | ||
166 | ADC_CHANNEL(3, "adc3"), | ||
167 | ADC_CHANNEL(4, "adc4"), | ||
168 | ADC_CHANNEL(5, "adc5"), | ||
169 | }; | ||
170 | |||
171 | static const struct rockchip_saradc_data rk3399_saradc_data = { | ||
172 | .num_bits = 10, | ||
173 | .channels = rockchip_rk3399_saradc_iio_channels, | ||
174 | .num_channels = ARRAY_SIZE(rockchip_rk3399_saradc_iio_channels), | ||
175 | .clk_rate = 1000000, | ||
176 | }; | ||
177 | |||
162 | static const struct of_device_id rockchip_saradc_match[] = { | 178 | static const struct of_device_id rockchip_saradc_match[] = { |
163 | { | 179 | { |
164 | .compatible = "rockchip,saradc", | 180 | .compatible = "rockchip,saradc", |
@@ -166,6 +182,9 @@ static const struct of_device_id rockchip_saradc_match[] = { | |||
166 | }, { | 182 | }, { |
167 | .compatible = "rockchip,rk3066-tsadc", | 183 | .compatible = "rockchip,rk3066-tsadc", |
168 | .data = &rk3066_tsadc_data, | 184 | .data = &rk3066_tsadc_data, |
185 | }, { | ||
186 | .compatible = "rockchip,rk3399-saradc", | ||
187 | .data = &rk3399_saradc_data, | ||
169 | }, | 188 | }, |
170 | {}, | 189 | {}, |
171 | }; | 190 | }; |
diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c index e18bc6782256..73764961feac 100644 --- a/drivers/iio/common/st_sensors/st_sensors_buffer.c +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c | |||
@@ -24,19 +24,13 @@ | |||
24 | 24 | ||
25 | int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) | 25 | int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) |
26 | { | 26 | { |
27 | u8 *addr; | 27 | u8 addr[3]; /* no ST sensor has more than 3 channels */ |
28 | int i, n = 0, len; | 28 | int i, n = 0, len; |
29 | struct st_sensor_data *sdata = iio_priv(indio_dev); | 29 | struct st_sensor_data *sdata = iio_priv(indio_dev); |
30 | unsigned int num_data_channels = sdata->num_data_channels; | 30 | unsigned int num_data_channels = sdata->num_data_channels; |
31 | unsigned int byte_for_channel = | 31 | unsigned int byte_for_channel = |
32 | indio_dev->channels[0].scan_type.storagebits >> 3; | 32 | indio_dev->channels[0].scan_type.storagebits >> 3; |
33 | 33 | ||
34 | addr = kmalloc(num_data_channels, GFP_KERNEL); | ||
35 | if (!addr) { | ||
36 | len = -ENOMEM; | ||
37 | goto st_sensors_get_buffer_element_error; | ||
38 | } | ||
39 | |||
40 | for (i = 0; i < num_data_channels; i++) { | 34 | for (i = 0; i < num_data_channels; i++) { |
41 | if (test_bit(i, indio_dev->active_scan_mask)) { | 35 | if (test_bit(i, indio_dev->active_scan_mask)) { |
42 | addr[n] = indio_dev->channels[i].address; | 36 | addr[n] = indio_dev->channels[i].address; |
@@ -57,10 +51,8 @@ int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) | |||
57 | u8 *rx_array; | 51 | u8 *rx_array; |
58 | rx_array = kmalloc(byte_for_channel * num_data_channels, | 52 | rx_array = kmalloc(byte_for_channel * num_data_channels, |
59 | GFP_KERNEL); | 53 | GFP_KERNEL); |
60 | if (!rx_array) { | 54 | if (!rx_array) |
61 | len = -ENOMEM; | 55 | return -ENOMEM; |
62 | goto st_sensors_free_memory; | ||
63 | } | ||
64 | 56 | ||
65 | len = sdata->tf->read_multiple_byte(&sdata->tb, | 57 | len = sdata->tf->read_multiple_byte(&sdata->tb, |
66 | sdata->dev, addr[0], | 58 | sdata->dev, addr[0], |
@@ -68,7 +60,7 @@ int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) | |||
68 | rx_array, sdata->multiread_bit); | 60 | rx_array, sdata->multiread_bit); |
69 | if (len < 0) { | 61 | if (len < 0) { |
70 | kfree(rx_array); | 62 | kfree(rx_array); |
71 | goto st_sensors_free_memory; | 63 | return len; |
72 | } | 64 | } |
73 | 65 | ||
74 | for (i = 0; i < n * byte_for_channel; i++) { | 66 | for (i = 0; i < n * byte_for_channel; i++) { |
@@ -87,17 +79,11 @@ int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) | |||
87 | buf, sdata->multiread_bit); | 79 | buf, sdata->multiread_bit); |
88 | break; | 80 | break; |
89 | default: | 81 | default: |
90 | len = -EINVAL; | 82 | return -EINVAL; |
91 | goto st_sensors_free_memory; | ||
92 | } | ||
93 | if (len != byte_for_channel * n) { | ||
94 | len = -EIO; | ||
95 | goto st_sensors_free_memory; | ||
96 | } | 83 | } |
84 | if (len != byte_for_channel * n) | ||
85 | return -EIO; | ||
97 | 86 | ||
98 | st_sensors_free_memory: | ||
99 | kfree(addr); | ||
100 | st_sensors_get_buffer_element_error: | ||
101 | return len; | 87 | return len; |
102 | } | 88 | } |
103 | EXPORT_SYMBOL(st_sensors_get_buffer_element); | 89 | EXPORT_SYMBOL(st_sensors_get_buffer_element); |
diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig index a995139f907c..210db81ca144 100644 --- a/drivers/iio/dac/Kconfig +++ b/drivers/iio/dac/Kconfig | |||
@@ -154,6 +154,16 @@ config AD7303 | |||
154 | To compile this driver as module choose M here: the module will be called | 154 | To compile this driver as module choose M here: the module will be called |
155 | ad7303. | 155 | ad7303. |
156 | 156 | ||
157 | config LPC18XX_DAC | ||
158 | tristate "NXP LPC18xx DAC driver" | ||
159 | depends on ARCH_LPC18XX || COMPILE_TEST | ||
160 | depends on OF && HAS_IOMEM | ||
161 | help | ||
162 | Say yes here to build support for NXP LPC18XX DAC. | ||
163 | |||
164 | To compile this driver as a module, choose M here: the module will be | ||
165 | called lpc18xx_dac. | ||
166 | |||
157 | config M62332 | 167 | config M62332 |
158 | tristate "Mitsubishi M62332 DAC driver" | 168 | tristate "Mitsubishi M62332 DAC driver" |
159 | depends on I2C | 169 | depends on I2C |
diff --git a/drivers/iio/dac/Makefile b/drivers/iio/dac/Makefile index 67b48429686d..420a15cdaa53 100644 --- a/drivers/iio/dac/Makefile +++ b/drivers/iio/dac/Makefile | |||
@@ -17,6 +17,7 @@ obj-$(CONFIG_AD5764) += ad5764.o | |||
17 | obj-$(CONFIG_AD5791) += ad5791.o | 17 | obj-$(CONFIG_AD5791) += ad5791.o |
18 | obj-$(CONFIG_AD5686) += ad5686.o | 18 | obj-$(CONFIG_AD5686) += ad5686.o |
19 | obj-$(CONFIG_AD7303) += ad7303.o | 19 | obj-$(CONFIG_AD7303) += ad7303.o |
20 | obj-$(CONFIG_LPC18XX_DAC) += lpc18xx_dac.o | ||
20 | obj-$(CONFIG_M62332) += m62332.o | 21 | obj-$(CONFIG_M62332) += m62332.o |
21 | obj-$(CONFIG_MAX517) += max517.o | 22 | obj-$(CONFIG_MAX517) += max517.o |
22 | obj-$(CONFIG_MAX5821) += max5821.o | 23 | obj-$(CONFIG_MAX5821) += max5821.o |
diff --git a/drivers/iio/dac/lpc18xx_dac.c b/drivers/iio/dac/lpc18xx_dac.c new file mode 100644 index 000000000000..55d1456a059d --- /dev/null +++ b/drivers/iio/dac/lpc18xx_dac.c | |||
@@ -0,0 +1,210 @@ | |||
1 | /* | ||
2 | * IIO DAC driver for NXP LPC18xx DAC | ||
3 | * | ||
4 | * Copyright (C) 2016 Joachim Eastwood <manabian@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * UNSUPPORTED hardware features: | ||
11 | * - Interrupts | ||
12 | * - DMA | ||
13 | */ | ||
14 | |||
15 | #include <linux/clk.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/iio/iio.h> | ||
18 | #include <linux/iio/driver.h> | ||
19 | #include <linux/io.h> | ||
20 | #include <linux/iopoll.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/mutex.h> | ||
23 | #include <linux/of.h> | ||
24 | #include <linux/of_device.h> | ||
25 | #include <linux/platform_device.h> | ||
26 | #include <linux/regulator/consumer.h> | ||
27 | |||
28 | /* LPC18XX DAC registers and bits */ | ||
29 | #define LPC18XX_DAC_CR 0x000 | ||
30 | #define LPC18XX_DAC_CR_VALUE_SHIFT 6 | ||
31 | #define LPC18XX_DAC_CR_VALUE_MASK 0x3ff | ||
32 | #define LPC18XX_DAC_CR_BIAS BIT(16) | ||
33 | #define LPC18XX_DAC_CTRL 0x004 | ||
34 | #define LPC18XX_DAC_CTRL_DMA_ENA BIT(3) | ||
35 | |||
36 | struct lpc18xx_dac { | ||
37 | struct regulator *vref; | ||
38 | void __iomem *base; | ||
39 | struct mutex lock; | ||
40 | struct clk *clk; | ||
41 | }; | ||
42 | |||
43 | static const struct iio_chan_spec lpc18xx_dac_iio_channels[] = { | ||
44 | { | ||
45 | .type = IIO_VOLTAGE, | ||
46 | .output = 1, | ||
47 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | ||
48 | BIT(IIO_CHAN_INFO_SCALE), | ||
49 | }, | ||
50 | }; | ||
51 | |||
52 | static int lpc18xx_dac_read_raw(struct iio_dev *indio_dev, | ||
53 | struct iio_chan_spec const *chan, | ||
54 | int *val, int *val2, long mask) | ||
55 | { | ||
56 | struct lpc18xx_dac *dac = iio_priv(indio_dev); | ||
57 | u32 reg; | ||
58 | |||
59 | switch (mask) { | ||
60 | case IIO_CHAN_INFO_RAW: | ||
61 | reg = readl(dac->base + LPC18XX_DAC_CR); | ||
62 | *val = reg >> LPC18XX_DAC_CR_VALUE_SHIFT; | ||
63 | *val &= LPC18XX_DAC_CR_VALUE_MASK; | ||
64 | |||
65 | return IIO_VAL_INT; | ||
66 | |||
67 | case IIO_CHAN_INFO_SCALE: | ||
68 | *val = regulator_get_voltage(dac->vref) / 1000; | ||
69 | *val2 = 10; | ||
70 | |||
71 | return IIO_VAL_FRACTIONAL_LOG2; | ||
72 | } | ||
73 | |||
74 | return -EINVAL; | ||
75 | } | ||
76 | |||
77 | static int lpc18xx_dac_write_raw(struct iio_dev *indio_dev, | ||
78 | struct iio_chan_spec const *chan, | ||
79 | int val, int val2, long mask) | ||
80 | { | ||
81 | struct lpc18xx_dac *dac = iio_priv(indio_dev); | ||
82 | u32 reg; | ||
83 | |||
84 | switch (mask) { | ||
85 | case IIO_CHAN_INFO_RAW: | ||
86 | if (val < 0 || val > LPC18XX_DAC_CR_VALUE_MASK) | ||
87 | return -EINVAL; | ||
88 | |||
89 | reg = LPC18XX_DAC_CR_BIAS; | ||
90 | reg |= val << LPC18XX_DAC_CR_VALUE_SHIFT; | ||
91 | |||
92 | mutex_lock(&dac->lock); | ||
93 | writel(reg, dac->base + LPC18XX_DAC_CR); | ||
94 | writel(LPC18XX_DAC_CTRL_DMA_ENA, dac->base + LPC18XX_DAC_CTRL); | ||
95 | mutex_unlock(&dac->lock); | ||
96 | |||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | return -EINVAL; | ||
101 | } | ||
102 | |||
103 | static const struct iio_info lpc18xx_dac_info = { | ||
104 | .read_raw = lpc18xx_dac_read_raw, | ||
105 | .write_raw = lpc18xx_dac_write_raw, | ||
106 | .driver_module = THIS_MODULE, | ||
107 | }; | ||
108 | |||
109 | static int lpc18xx_dac_probe(struct platform_device *pdev) | ||
110 | { | ||
111 | struct iio_dev *indio_dev; | ||
112 | struct lpc18xx_dac *dac; | ||
113 | struct resource *res; | ||
114 | int ret; | ||
115 | |||
116 | indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*dac)); | ||
117 | if (!indio_dev) | ||
118 | return -ENOMEM; | ||
119 | |||
120 | platform_set_drvdata(pdev, indio_dev); | ||
121 | dac = iio_priv(indio_dev); | ||
122 | mutex_init(&dac->lock); | ||
123 | |||
124 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
125 | dac->base = devm_ioremap_resource(&pdev->dev, res); | ||
126 | if (IS_ERR(dac->base)) | ||
127 | return PTR_ERR(dac->base); | ||
128 | |||
129 | dac->clk = devm_clk_get(&pdev->dev, NULL); | ||
130 | if (IS_ERR(dac->clk)) { | ||
131 | dev_err(&pdev->dev, "error getting clock\n"); | ||
132 | return PTR_ERR(dac->clk); | ||
133 | } | ||
134 | |||
135 | dac->vref = devm_regulator_get(&pdev->dev, "vref"); | ||
136 | if (IS_ERR(dac->vref)) { | ||
137 | dev_err(&pdev->dev, "error getting regulator\n"); | ||
138 | return PTR_ERR(dac->vref); | ||
139 | } | ||
140 | |||
141 | indio_dev->name = dev_name(&pdev->dev); | ||
142 | indio_dev->dev.parent = &pdev->dev; | ||
143 | indio_dev->info = &lpc18xx_dac_info; | ||
144 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
145 | indio_dev->channels = lpc18xx_dac_iio_channels; | ||
146 | indio_dev->num_channels = ARRAY_SIZE(lpc18xx_dac_iio_channels); | ||
147 | |||
148 | ret = regulator_enable(dac->vref); | ||
149 | if (ret) { | ||
150 | dev_err(&pdev->dev, "unable to enable regulator\n"); | ||
151 | return ret; | ||
152 | } | ||
153 | |||
154 | ret = clk_prepare_enable(dac->clk); | ||
155 | if (ret) { | ||
156 | dev_err(&pdev->dev, "unable to enable clock\n"); | ||
157 | goto dis_reg; | ||
158 | } | ||
159 | |||
160 | writel(0, dac->base + LPC18XX_DAC_CTRL); | ||
161 | writel(0, dac->base + LPC18XX_DAC_CR); | ||
162 | |||
163 | ret = iio_device_register(indio_dev); | ||
164 | if (ret) { | ||
165 | dev_err(&pdev->dev, "unable to register device\n"); | ||
166 | goto dis_clk; | ||
167 | } | ||
168 | |||
169 | return 0; | ||
170 | |||
171 | dis_clk: | ||
172 | clk_disable_unprepare(dac->clk); | ||
173 | dis_reg: | ||
174 | regulator_disable(dac->vref); | ||
175 | return ret; | ||
176 | } | ||
177 | |||
178 | static int lpc18xx_dac_remove(struct platform_device *pdev) | ||
179 | { | ||
180 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); | ||
181 | struct lpc18xx_dac *dac = iio_priv(indio_dev); | ||
182 | |||
183 | iio_device_unregister(indio_dev); | ||
184 | |||
185 | writel(0, dac->base + LPC18XX_DAC_CTRL); | ||
186 | clk_disable_unprepare(dac->clk); | ||
187 | regulator_disable(dac->vref); | ||
188 | |||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | static const struct of_device_id lpc18xx_dac_match[] = { | ||
193 | { .compatible = "nxp,lpc1850-dac" }, | ||
194 | { /* sentinel */ } | ||
195 | }; | ||
196 | MODULE_DEVICE_TABLE(of, lpc18xx_dac_match); | ||
197 | |||
198 | static struct platform_driver lpc18xx_dac_driver = { | ||
199 | .probe = lpc18xx_dac_probe, | ||
200 | .remove = lpc18xx_dac_remove, | ||
201 | .driver = { | ||
202 | .name = "lpc18xx-dac", | ||
203 | .of_match_table = lpc18xx_dac_match, | ||
204 | }, | ||
205 | }; | ||
206 | module_platform_driver(lpc18xx_dac_driver); | ||
207 | |||
208 | MODULE_DESCRIPTION("LPC18xx DAC driver"); | ||
209 | MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>"); | ||
210 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c index bbce3b09ac45..2493bb17a03d 100644 --- a/drivers/iio/gyro/bmg160_core.c +++ b/drivers/iio/gyro/bmg160_core.c | |||
@@ -17,7 +17,6 @@ | |||
17 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/acpi.h> | 19 | #include <linux/acpi.h> |
20 | #include <linux/gpio/consumer.h> | ||
21 | #include <linux/pm.h> | 20 | #include <linux/pm.h> |
22 | #include <linux/pm_runtime.h> | 21 | #include <linux/pm_runtime.h> |
23 | #include <linux/iio/iio.h> | 22 | #include <linux/iio/iio.h> |
@@ -31,7 +30,6 @@ | |||
31 | #include "bmg160.h" | 30 | #include "bmg160.h" |
32 | 31 | ||
33 | #define BMG160_IRQ_NAME "bmg160_event" | 32 | #define BMG160_IRQ_NAME "bmg160_event" |
34 | #define BMG160_GPIO_NAME "gpio_int" | ||
35 | 33 | ||
36 | #define BMG160_REG_CHIP_ID 0x00 | 34 | #define BMG160_REG_CHIP_ID 0x00 |
37 | #define BMG160_CHIP_ID_VAL 0x0F | 35 | #define BMG160_CHIP_ID_VAL 0x0F |
@@ -116,6 +114,7 @@ enum bmg160_axis { | |||
116 | AXIS_X, | 114 | AXIS_X, |
117 | AXIS_Y, | 115 | AXIS_Y, |
118 | AXIS_Z, | 116 | AXIS_Z, |
117 | AXIS_MAX, | ||
119 | }; | 118 | }; |
120 | 119 | ||
121 | static const struct { | 120 | static const struct { |
@@ -733,6 +732,7 @@ static const struct iio_event_spec bmg160_event = { | |||
733 | .sign = 's', \ | 732 | .sign = 's', \ |
734 | .realbits = 16, \ | 733 | .realbits = 16, \ |
735 | .storagebits = 16, \ | 734 | .storagebits = 16, \ |
735 | .endianness = IIO_LE, \ | ||
736 | }, \ | 736 | }, \ |
737 | .event_spec = &bmg160_event, \ | 737 | .event_spec = &bmg160_event, \ |
738 | .num_event_specs = 1 \ | 738 | .num_event_specs = 1 \ |
@@ -763,26 +763,23 @@ static const struct iio_info bmg160_info = { | |||
763 | .driver_module = THIS_MODULE, | 763 | .driver_module = THIS_MODULE, |
764 | }; | 764 | }; |
765 | 765 | ||
766 | static const unsigned long bmg160_accel_scan_masks[] = { | ||
767 | BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z), | ||
768 | 0}; | ||
769 | |||
766 | static irqreturn_t bmg160_trigger_handler(int irq, void *p) | 770 | static irqreturn_t bmg160_trigger_handler(int irq, void *p) |
767 | { | 771 | { |
768 | struct iio_poll_func *pf = p; | 772 | struct iio_poll_func *pf = p; |
769 | struct iio_dev *indio_dev = pf->indio_dev; | 773 | struct iio_dev *indio_dev = pf->indio_dev; |
770 | struct bmg160_data *data = iio_priv(indio_dev); | 774 | struct bmg160_data *data = iio_priv(indio_dev); |
771 | int bit, ret, i = 0; | 775 | int ret; |
772 | unsigned int val; | ||
773 | 776 | ||
774 | mutex_lock(&data->mutex); | 777 | mutex_lock(&data->mutex); |
775 | for_each_set_bit(bit, indio_dev->active_scan_mask, | 778 | ret = regmap_bulk_read(data->regmap, BMG160_REG_XOUT_L, |
776 | indio_dev->masklength) { | 779 | data->buffer, AXIS_MAX * 2); |
777 | ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(bit), | ||
778 | &val, 2); | ||
779 | if (ret < 0) { | ||
780 | mutex_unlock(&data->mutex); | ||
781 | goto err; | ||
782 | } | ||
783 | data->buffer[i++] = ret; | ||
784 | } | ||
785 | mutex_unlock(&data->mutex); | 780 | mutex_unlock(&data->mutex); |
781 | if (ret < 0) | ||
782 | goto err; | ||
786 | 783 | ||
787 | iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, | 784 | iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, |
788 | pf->timestamp); | 785 | pf->timestamp); |
@@ -955,29 +952,6 @@ static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = { | |||
955 | .postdisable = bmg160_buffer_postdisable, | 952 | .postdisable = bmg160_buffer_postdisable, |
956 | }; | 953 | }; |
957 | 954 | ||
958 | static int bmg160_gpio_probe(struct bmg160_data *data) | ||
959 | |||
960 | { | ||
961 | struct device *dev; | ||
962 | struct gpio_desc *gpio; | ||
963 | |||
964 | dev = data->dev; | ||
965 | |||
966 | /* data ready gpio interrupt pin */ | ||
967 | gpio = devm_gpiod_get_index(dev, BMG160_GPIO_NAME, 0, GPIOD_IN); | ||
968 | if (IS_ERR(gpio)) { | ||
969 | dev_err(dev, "acpi gpio get index failed\n"); | ||
970 | return PTR_ERR(gpio); | ||
971 | } | ||
972 | |||
973 | data->irq = gpiod_to_irq(gpio); | ||
974 | |||
975 | dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), | ||
976 | data->irq); | ||
977 | |||
978 | return 0; | ||
979 | } | ||
980 | |||
981 | static const char *bmg160_match_acpi_device(struct device *dev) | 955 | static const char *bmg160_match_acpi_device(struct device *dev) |
982 | { | 956 | { |
983 | const struct acpi_device_id *id; | 957 | const struct acpi_device_id *id; |
@@ -1019,12 +993,10 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, | |||
1019 | indio_dev->channels = bmg160_channels; | 993 | indio_dev->channels = bmg160_channels; |
1020 | indio_dev->num_channels = ARRAY_SIZE(bmg160_channels); | 994 | indio_dev->num_channels = ARRAY_SIZE(bmg160_channels); |
1021 | indio_dev->name = name; | 995 | indio_dev->name = name; |
996 | indio_dev->available_scan_masks = bmg160_accel_scan_masks; | ||
1022 | indio_dev->modes = INDIO_DIRECT_MODE; | 997 | indio_dev->modes = INDIO_DIRECT_MODE; |
1023 | indio_dev->info = &bmg160_info; | 998 | indio_dev->info = &bmg160_info; |
1024 | 999 | ||
1025 | if (data->irq <= 0) | ||
1026 | bmg160_gpio_probe(data); | ||
1027 | |||
1028 | if (data->irq > 0) { | 1000 | if (data->irq > 0) { |
1029 | ret = devm_request_threaded_irq(dev, | 1001 | ret = devm_request_threaded_irq(dev, |
1030 | data->irq, | 1002 | data->irq, |
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c index f581256d9d4c..5ee4e0dc093e 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | |||
@@ -104,6 +104,19 @@ static int inv_mpu6050_deselect_bypass(struct i2c_adapter *adap, | |||
104 | return 0; | 104 | return 0; |
105 | } | 105 | } |
106 | 106 | ||
107 | static const char *inv_mpu_match_acpi_device(struct device *dev, int *chip_id) | ||
108 | { | ||
109 | const struct acpi_device_id *id; | ||
110 | |||
111 | id = acpi_match_device(dev->driver->acpi_match_table, dev); | ||
112 | if (!id) | ||
113 | return NULL; | ||
114 | |||
115 | *chip_id = (int)id->driver_data; | ||
116 | |||
117 | return dev_name(dev); | ||
118 | } | ||
119 | |||
107 | /** | 120 | /** |
108 | * inv_mpu_probe() - probe function. | 121 | * inv_mpu_probe() - probe function. |
109 | * @client: i2c client. | 122 | * @client: i2c client. |
@@ -115,14 +128,25 @@ static int inv_mpu_probe(struct i2c_client *client, | |||
115 | const struct i2c_device_id *id) | 128 | const struct i2c_device_id *id) |
116 | { | 129 | { |
117 | struct inv_mpu6050_state *st; | 130 | struct inv_mpu6050_state *st; |
118 | int result; | 131 | int result, chip_type; |
119 | const char *name = id ? id->name : NULL; | ||
120 | struct regmap *regmap; | 132 | struct regmap *regmap; |
133 | const char *name; | ||
121 | 134 | ||
122 | if (!i2c_check_functionality(client->adapter, | 135 | if (!i2c_check_functionality(client->adapter, |
123 | I2C_FUNC_SMBUS_I2C_BLOCK)) | 136 | I2C_FUNC_SMBUS_I2C_BLOCK)) |
124 | return -EOPNOTSUPP; | 137 | return -EOPNOTSUPP; |
125 | 138 | ||
139 | if (id) { | ||
140 | chip_type = (int)id->driver_data; | ||
141 | name = id->name; | ||
142 | } else if (ACPI_HANDLE(&client->dev)) { | ||
143 | name = inv_mpu_match_acpi_device(&client->dev, &chip_type); | ||
144 | if (!name) | ||
145 | return -ENODEV; | ||
146 | } else { | ||
147 | return -ENOSYS; | ||
148 | } | ||
149 | |||
126 | regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config); | 150 | regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config); |
127 | if (IS_ERR(regmap)) { | 151 | if (IS_ERR(regmap)) { |
128 | dev_err(&client->dev, "Failed to register i2c regmap %d\n", | 152 | dev_err(&client->dev, "Failed to register i2c regmap %d\n", |
@@ -131,7 +155,7 @@ static int inv_mpu_probe(struct i2c_client *client, | |||
131 | } | 155 | } |
132 | 156 | ||
133 | result = inv_mpu_core_probe(regmap, client->irq, name, | 157 | result = inv_mpu_core_probe(regmap, client->irq, name, |
134 | NULL, id->driver_data); | 158 | NULL, chip_type); |
135 | if (result < 0) | 159 | if (result < 0) |
136 | return result; | 160 | return result; |
137 | 161 | ||
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c index dea6c4361de0..7bcb8d839f05 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | |||
@@ -46,6 +46,7 @@ static int inv_mpu_probe(struct spi_device *spi) | |||
46 | struct regmap *regmap; | 46 | struct regmap *regmap; |
47 | const struct spi_device_id *id = spi_get_device_id(spi); | 47 | const struct spi_device_id *id = spi_get_device_id(spi); |
48 | const char *name = id ? id->name : NULL; | 48 | const char *name = id ? id->name : NULL; |
49 | const int chip_type = id ? id->driver_data : 0; | ||
49 | 50 | ||
50 | regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config); | 51 | regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config); |
51 | if (IS_ERR(regmap)) { | 52 | if (IS_ERR(regmap)) { |
@@ -55,7 +56,7 @@ static int inv_mpu_probe(struct spi_device *spi) | |||
55 | } | 56 | } |
56 | 57 | ||
57 | return inv_mpu_core_probe(regmap, spi->irq, name, | 58 | return inv_mpu_core_probe(regmap, spi->irq, name, |
58 | inv_mpu_i2c_disable, id->driver_data); | 59 | inv_mpu_i2c_disable, chip_type); |
59 | } | 60 | } |
60 | 61 | ||
61 | static int inv_mpu_remove(struct spi_device *spi) | 62 | static int inv_mpu_remove(struct spi_device *spi) |
diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c index e5306b4e020e..2e7dd5754a56 100644 --- a/drivers/iio/imu/kmx61.c +++ b/drivers/iio/imu/kmx61.c | |||
@@ -14,7 +14,6 @@ | |||
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/i2c.h> | 15 | #include <linux/i2c.h> |
16 | #include <linux/acpi.h> | 16 | #include <linux/acpi.h> |
17 | #include <linux/gpio/consumer.h> | ||
18 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
19 | #include <linux/pm.h> | 18 | #include <linux/pm.h> |
20 | #include <linux/pm_runtime.h> | 19 | #include <linux/pm_runtime.h> |
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 70cb7eb0a75c..190a5939fd8c 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | #include <linux/anon_inodes.h> | 26 | #include <linux/anon_inodes.h> |
27 | #include <linux/debugfs.h> | 27 | #include <linux/debugfs.h> |
28 | #include <linux/mutex.h> | ||
28 | #include <linux/iio/iio.h> | 29 | #include <linux/iio/iio.h> |
29 | #include "iio_core.h" | 30 | #include "iio_core.h" |
30 | #include "iio_core_trigger.h" | 31 | #include "iio_core_trigger.h" |
@@ -78,6 +79,7 @@ static const char * const iio_chan_type_name_spec[] = { | |||
78 | [IIO_CONCENTRATION] = "concentration", | 79 | [IIO_CONCENTRATION] = "concentration", |
79 | [IIO_RESISTANCE] = "resistance", | 80 | [IIO_RESISTANCE] = "resistance", |
80 | [IIO_PH] = "ph", | 81 | [IIO_PH] = "ph", |
82 | [IIO_UVINDEX] = "uvindex", | ||
81 | }; | 83 | }; |
82 | 84 | ||
83 | static const char * const iio_modifier_names[] = { | 85 | static const char * const iio_modifier_names[] = { |
@@ -100,6 +102,7 @@ static const char * const iio_modifier_names[] = { | |||
100 | [IIO_MOD_LIGHT_RED] = "red", | 102 | [IIO_MOD_LIGHT_RED] = "red", |
101 | [IIO_MOD_LIGHT_GREEN] = "green", | 103 | [IIO_MOD_LIGHT_GREEN] = "green", |
102 | [IIO_MOD_LIGHT_BLUE] = "blue", | 104 | [IIO_MOD_LIGHT_BLUE] = "blue", |
105 | [IIO_MOD_LIGHT_UV] = "uv", | ||
103 | [IIO_MOD_QUATERNION] = "quaternion", | 106 | [IIO_MOD_QUATERNION] = "quaternion", |
104 | [IIO_MOD_TEMP_AMBIENT] = "ambient", | 107 | [IIO_MOD_TEMP_AMBIENT] = "ambient", |
105 | [IIO_MOD_TEMP_OBJECT] = "object", | 108 | [IIO_MOD_TEMP_OBJECT] = "object", |
@@ -1375,6 +1378,44 @@ void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev) | |||
1375 | } | 1378 | } |
1376 | EXPORT_SYMBOL_GPL(devm_iio_device_unregister); | 1379 | EXPORT_SYMBOL_GPL(devm_iio_device_unregister); |
1377 | 1380 | ||
1381 | /** | ||
1382 | * iio_device_claim_direct_mode - Keep device in direct mode | ||
1383 | * @indio_dev: the iio_dev associated with the device | ||
1384 | * | ||
1385 | * If the device is in direct mode it is guaranteed to stay | ||
1386 | * that way until iio_device_release_direct_mode() is called. | ||
1387 | * | ||
1388 | * Use with iio_device_release_direct_mode() | ||
1389 | * | ||
1390 | * Returns: 0 on success, -EBUSY on failure | ||
1391 | */ | ||
1392 | int iio_device_claim_direct_mode(struct iio_dev *indio_dev) | ||
1393 | { | ||
1394 | mutex_lock(&indio_dev->mlock); | ||
1395 | |||
1396 | if (iio_buffer_enabled(indio_dev)) { | ||
1397 | mutex_unlock(&indio_dev->mlock); | ||
1398 | return -EBUSY; | ||
1399 | } | ||
1400 | return 0; | ||
1401 | } | ||
1402 | EXPORT_SYMBOL_GPL(iio_device_claim_direct_mode); | ||
1403 | |||
1404 | /** | ||
1405 | * iio_device_release_direct_mode - releases claim on direct mode | ||
1406 | * @indio_dev: the iio_dev associated with the device | ||
1407 | * | ||
1408 | * Release the claim. Device is no longer guaranteed to stay | ||
1409 | * in direct mode. | ||
1410 | * | ||
1411 | * Use with iio_device_claim_direct_mode() | ||
1412 | */ | ||
1413 | void iio_device_release_direct_mode(struct iio_dev *indio_dev) | ||
1414 | { | ||
1415 | mutex_unlock(&indio_dev->mlock); | ||
1416 | } | ||
1417 | EXPORT_SYMBOL_GPL(iio_device_release_direct_mode); | ||
1418 | |||
1378 | subsys_initcall(iio_init); | 1419 | subsys_initcall(iio_init); |
1379 | module_exit(iio_exit); | 1420 | module_exit(iio_exit); |
1380 | 1421 | ||
diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index 42d334ba612e..9e847f8f4f0c 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c | |||
@@ -16,7 +16,6 @@ | |||
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/regmap.h> | 18 | #include <linux/regmap.h> |
19 | #include <linux/gpio/consumer.h> | ||
20 | #include <linux/iio/events.h> | 19 | #include <linux/iio/events.h> |
21 | #include <linux/iio/iio.h> | 20 | #include <linux/iio/iio.h> |
22 | #include <linux/iio/sysfs.h> | 21 | #include <linux/iio/sysfs.h> |
diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c index 12731d6b89ec..57b108c30e98 100644 --- a/drivers/iio/light/tsl2563.c +++ b/drivers/iio/light/tsl2563.c | |||
@@ -806,8 +806,7 @@ static int tsl2563_probe(struct i2c_client *client, | |||
806 | return 0; | 806 | return 0; |
807 | 807 | ||
808 | fail: | 808 | fail: |
809 | cancel_delayed_work(&chip->poweroff_work); | 809 | cancel_delayed_work_sync(&chip->poweroff_work); |
810 | flush_scheduled_work(); | ||
811 | return err; | 810 | return err; |
812 | } | 811 | } |
813 | 812 | ||
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index 9c5c9ef3f1da..48d127a45d90 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/gpio.h> | 32 | #include <linux/gpio.h> |
33 | #include <linux/of_gpio.h> | 33 | #include <linux/of_gpio.h> |
34 | #include <linux/acpi.h> | 34 | #include <linux/acpi.h> |
35 | #include <linux/regulator/consumer.h> | ||
35 | 36 | ||
36 | #include <linux/iio/iio.h> | 37 | #include <linux/iio/iio.h> |
37 | #include <linux/iio/sysfs.h> | 38 | #include <linux/iio/sysfs.h> |
@@ -361,7 +362,6 @@ static const struct ak_def ak_def_array[AK_MAX_TYPE] = { | |||
361 | struct ak8975_data { | 362 | struct ak8975_data { |
362 | struct i2c_client *client; | 363 | struct i2c_client *client; |
363 | const struct ak_def *def; | 364 | const struct ak_def *def; |
364 | struct attribute_group attrs; | ||
365 | struct mutex lock; | 365 | struct mutex lock; |
366 | u8 asa[3]; | 366 | u8 asa[3]; |
367 | long raw_to_gauss[3]; | 367 | long raw_to_gauss[3]; |
@@ -370,8 +370,40 @@ struct ak8975_data { | |||
370 | wait_queue_head_t data_ready_queue; | 370 | wait_queue_head_t data_ready_queue; |
371 | unsigned long flags; | 371 | unsigned long flags; |
372 | u8 cntl_cache; | 372 | u8 cntl_cache; |
373 | struct regulator *vdd; | ||
373 | }; | 374 | }; |
374 | 375 | ||
376 | /* Enable attached power regulator if any. */ | ||
377 | static int ak8975_power_on(struct i2c_client *client) | ||
378 | { | ||
379 | const struct iio_dev *indio_dev = i2c_get_clientdata(client); | ||
380 | struct ak8975_data *data = iio_priv(indio_dev); | ||
381 | int ret; | ||
382 | |||
383 | data->vdd = devm_regulator_get(&client->dev, "vdd"); | ||
384 | if (IS_ERR_OR_NULL(data->vdd)) { | ||
385 | ret = PTR_ERR(data->vdd); | ||
386 | if (ret == -ENODEV) | ||
387 | ret = 0; | ||
388 | } else { | ||
389 | ret = regulator_enable(data->vdd); | ||
390 | } | ||
391 | |||
392 | if (ret) | ||
393 | dev_err(&client->dev, "failed to enable Vdd supply: %d\n", ret); | ||
394 | return ret; | ||
395 | } | ||
396 | |||
397 | /* Disable attached power regulator if any. */ | ||
398 | static void ak8975_power_off(const struct i2c_client *client) | ||
399 | { | ||
400 | const struct iio_dev *indio_dev = i2c_get_clientdata(client); | ||
401 | const struct ak8975_data *data = iio_priv(indio_dev); | ||
402 | |||
403 | if (!IS_ERR_OR_NULL(data->vdd)) | ||
404 | regulator_disable(data->vdd); | ||
405 | } | ||
406 | |||
375 | /* | 407 | /* |
376 | * Return 0 if the i2c device is the one we expect. | 408 | * Return 0 if the i2c device is the one we expect. |
377 | * return a negative error number otherwise | 409 | * return a negative error number otherwise |
@@ -774,8 +806,11 @@ static int ak8975_probe(struct i2c_client *client, | |||
774 | if (id) { | 806 | if (id) { |
775 | chipset = (enum asahi_compass_chipset)(id->driver_data); | 807 | chipset = (enum asahi_compass_chipset)(id->driver_data); |
776 | name = id->name; | 808 | name = id->name; |
777 | } else if (ACPI_HANDLE(&client->dev)) | 809 | } else if (ACPI_HANDLE(&client->dev)) { |
778 | name = ak8975_match_acpi_device(&client->dev, &chipset); | 810 | name = ak8975_match_acpi_device(&client->dev, &chipset); |
811 | if (!name) | ||
812 | return -ENODEV; | ||
813 | } | ||
779 | else | 814 | else |
780 | return -ENOSYS; | 815 | return -ENOSYS; |
781 | 816 | ||
@@ -786,10 +821,15 @@ static int ak8975_probe(struct i2c_client *client, | |||
786 | } | 821 | } |
787 | 822 | ||
788 | data->def = &ak_def_array[chipset]; | 823 | data->def = &ak_def_array[chipset]; |
824 | |||
825 | err = ak8975_power_on(client); | ||
826 | if (err) | ||
827 | return err; | ||
828 | |||
789 | err = ak8975_who_i_am(client, data->def->type); | 829 | err = ak8975_who_i_am(client, data->def->type); |
790 | if (err < 0) { | 830 | if (err < 0) { |
791 | dev_err(&client->dev, "Unexpected device\n"); | 831 | dev_err(&client->dev, "Unexpected device\n"); |
792 | return err; | 832 | goto power_off; |
793 | } | 833 | } |
794 | dev_dbg(&client->dev, "Asahi compass chip %s\n", name); | 834 | dev_dbg(&client->dev, "Asahi compass chip %s\n", name); |
795 | 835 | ||
@@ -797,7 +837,7 @@ static int ak8975_probe(struct i2c_client *client, | |||
797 | err = ak8975_setup(client); | 837 | err = ak8975_setup(client); |
798 | if (err < 0) { | 838 | if (err < 0) { |
799 | dev_err(&client->dev, "%s initialization fails\n", name); | 839 | dev_err(&client->dev, "%s initialization fails\n", name); |
800 | return err; | 840 | goto power_off; |
801 | } | 841 | } |
802 | 842 | ||
803 | mutex_init(&data->lock); | 843 | mutex_init(&data->lock); |
@@ -807,7 +847,26 @@ static int ak8975_probe(struct i2c_client *client, | |||
807 | indio_dev->info = &ak8975_info; | 847 | indio_dev->info = &ak8975_info; |
808 | indio_dev->modes = INDIO_DIRECT_MODE; | 848 | indio_dev->modes = INDIO_DIRECT_MODE; |
809 | indio_dev->name = name; | 849 | indio_dev->name = name; |
810 | return devm_iio_device_register(&client->dev, indio_dev); | 850 | |
851 | err = iio_device_register(indio_dev); | ||
852 | if (err) | ||
853 | goto power_off; | ||
854 | |||
855 | return 0; | ||
856 | |||
857 | power_off: | ||
858 | ak8975_power_off(client); | ||
859 | return err; | ||
860 | } | ||
861 | |||
862 | static int ak8975_remove(struct i2c_client *client) | ||
863 | { | ||
864 | struct iio_dev *indio_dev = i2c_get_clientdata(client); | ||
865 | |||
866 | iio_device_unregister(indio_dev); | ||
867 | ak8975_power_off(client); | ||
868 | |||
869 | return 0; | ||
811 | } | 870 | } |
812 | 871 | ||
813 | static const struct i2c_device_id ak8975_id[] = { | 872 | static const struct i2c_device_id ak8975_id[] = { |
@@ -841,6 +900,7 @@ static struct i2c_driver ak8975_driver = { | |||
841 | .acpi_match_table = ACPI_PTR(ak_acpi_match), | 900 | .acpi_match_table = ACPI_PTR(ak_acpi_match), |
842 | }, | 901 | }, |
843 | .probe = ak8975_probe, | 902 | .probe = ak8975_probe, |
903 | .remove = ak8975_remove, | ||
844 | .id_table = ak8975_id, | 904 | .id_table = ak8975_id, |
845 | }; | 905 | }; |
846 | module_i2c_driver(ak8975_driver); | 906 | module_i2c_driver(ak8975_driver); |
diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c index ffcb75ea64fb..0e9da189dc4c 100644 --- a/drivers/iio/magnetometer/bmc150_magn.c +++ b/drivers/iio/magnetometer/bmc150_magn.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/acpi.h> | 25 | #include <linux/acpi.h> |
26 | #include <linux/gpio/consumer.h> | ||
27 | #include <linux/pm.h> | 26 | #include <linux/pm.h> |
28 | #include <linux/pm_runtime.h> | 27 | #include <linux/pm_runtime.h> |
29 | #include <linux/iio/iio.h> | 28 | #include <linux/iio/iio.h> |
diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig index ffc735c168fb..7ea069bbca2d 100644 --- a/drivers/iio/potentiometer/Kconfig +++ b/drivers/iio/potentiometer/Kconfig | |||
@@ -5,6 +5,24 @@ | |||
5 | 5 | ||
6 | menu "Digital potentiometers" | 6 | menu "Digital potentiometers" |
7 | 7 | ||
8 | config MCP4131 | ||
9 | tristate "Microchip MCP413X/414X/415X/416X/423X/424X/425X/426X Digital Potentiometer driver" | ||
10 | depends on SPI | ||
11 | help | ||
12 | Say yes here to build support for the Microchip | ||
13 | MCP4131, MCP4132, | ||
14 | MCP4141, MCP4142, | ||
15 | MCP4151, MCP4152, | ||
16 | MCP4161, MCP4162, | ||
17 | MCP4231, MCP4232, | ||
18 | MCP4241, MCP4242, | ||
19 | MCP4251, MCP4252, | ||
20 | MCP4261, MCP4262, | ||
21 | digital potentiomenter chips. | ||
22 | |||
23 | To compile this driver as a module, choose M here: the | ||
24 | module will be called mcp4131. | ||
25 | |||
8 | config MCP4531 | 26 | config MCP4531 |
9 | tristate "Microchip MCP45xx/MCP46xx Digital Potentiometer driver" | 27 | tristate "Microchip MCP45xx/MCP46xx Digital Potentiometer driver" |
10 | depends on I2C | 28 | depends on I2C |
diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile index b563b492b486..91a80f8db24d 100644 --- a/drivers/iio/potentiometer/Makefile +++ b/drivers/iio/potentiometer/Makefile | |||
@@ -3,5 +3,6 @@ | |||
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_MCP4131) += mcp4131.o | ||
6 | obj-$(CONFIG_MCP4531) += mcp4531.o | 7 | obj-$(CONFIG_MCP4531) += mcp4531.o |
7 | obj-$(CONFIG_TPL0102) += tpl0102.o | 8 | obj-$(CONFIG_TPL0102) += tpl0102.o |
diff --git a/drivers/iio/potentiometer/mcp4131.c b/drivers/iio/potentiometer/mcp4131.c new file mode 100644 index 000000000000..4e7e2c6c522c --- /dev/null +++ b/drivers/iio/potentiometer/mcp4131.c | |||
@@ -0,0 +1,494 @@ | |||
1 | /* | ||
2 | * Industrial I/O driver for Microchip digital potentiometers | ||
3 | * | ||
4 | * Copyright (c) 2016 Slawomir Stepien | ||
5 | * Based on: Peter Rosin's code from mcp4531.c | ||
6 | * | ||
7 | * Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf | ||
8 | * | ||
9 | * DEVID #Wipers #Positions Resistor Opts (kOhm) | ||
10 | * mcp4131 1 129 5, 10, 50, 100 | ||
11 | * mcp4132 1 129 5, 10, 50, 100 | ||
12 | * mcp4141 1 129 5, 10, 50, 100 | ||
13 | * mcp4142 1 129 5, 10, 50, 100 | ||
14 | * mcp4151 1 257 5, 10, 50, 100 | ||
15 | * mcp4152 1 257 5, 10, 50, 100 | ||
16 | * mcp4161 1 257 5, 10, 50, 100 | ||
17 | * mcp4162 1 257 5, 10, 50, 100 | ||
18 | * mcp4231 2 129 5, 10, 50, 100 | ||
19 | * mcp4232 2 129 5, 10, 50, 100 | ||
20 | * mcp4241 2 129 5, 10, 50, 100 | ||
21 | * mcp4242 2 129 5, 10, 50, 100 | ||
22 | * mcp4251 2 257 5, 10, 50, 100 | ||
23 | * mcp4252 2 257 5, 10, 50, 100 | ||
24 | * mcp4261 2 257 5, 10, 50, 100 | ||
25 | * mcp4262 2 257 5, 10, 50, 100 | ||
26 | * | ||
27 | * This program is free software; you can redistribute it and/or modify it | ||
28 | * under the terms of the GNU General Public License version 2 as published by | ||
29 | * the Free Software Foundation. | ||
30 | */ | ||
31 | |||
32 | /* | ||
33 | * TODO: | ||
34 | * 1. Write wiper setting to EEPROM for EEPROM capable models. | ||
35 | */ | ||
36 | |||
37 | #include <linux/cache.h> | ||
38 | #include <linux/err.h> | ||
39 | #include <linux/export.h> | ||
40 | #include <linux/iio/iio.h> | ||
41 | #include <linux/iio/types.h> | ||
42 | #include <linux/module.h> | ||
43 | #include <linux/mutex.h> | ||
44 | #include <linux/of.h> | ||
45 | #include <linux/spi/spi.h> | ||
46 | |||
47 | #define MCP4131_WRITE (0x00 << 2) | ||
48 | #define MCP4131_READ (0x03 << 2) | ||
49 | |||
50 | #define MCP4131_WIPER_SHIFT 4 | ||
51 | #define MCP4131_CMDERR(r) ((r[0]) & 0x02) | ||
52 | #define MCP4131_RAW(r) ((r[0]) == 0xff ? 0x100 : (r[1])) | ||
53 | |||
54 | struct mcp4131_cfg { | ||
55 | int wipers; | ||
56 | int max_pos; | ||
57 | int kohms; | ||
58 | }; | ||
59 | |||
60 | enum mcp4131_type { | ||
61 | MCP413x_502 = 0, | ||
62 | MCP413x_103, | ||
63 | MCP413x_503, | ||
64 | MCP413x_104, | ||
65 | MCP414x_502, | ||
66 | MCP414x_103, | ||
67 | MCP414x_503, | ||
68 | MCP414x_104, | ||
69 | MCP415x_502, | ||
70 | MCP415x_103, | ||
71 | MCP415x_503, | ||
72 | MCP415x_104, | ||
73 | MCP416x_502, | ||
74 | MCP416x_103, | ||
75 | MCP416x_503, | ||
76 | MCP416x_104, | ||
77 | MCP423x_502, | ||
78 | MCP423x_103, | ||
79 | MCP423x_503, | ||
80 | MCP423x_104, | ||
81 | MCP424x_502, | ||
82 | MCP424x_103, | ||
83 | MCP424x_503, | ||
84 | MCP424x_104, | ||
85 | MCP425x_502, | ||
86 | MCP425x_103, | ||
87 | MCP425x_503, | ||
88 | MCP425x_104, | ||
89 | MCP426x_502, | ||
90 | MCP426x_103, | ||
91 | MCP426x_503, | ||
92 | MCP426x_104, | ||
93 | }; | ||
94 | |||
95 | static const struct mcp4131_cfg mcp4131_cfg[] = { | ||
96 | [MCP413x_502] = { .wipers = 1, .max_pos = 128, .kohms = 5, }, | ||
97 | [MCP413x_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, }, | ||
98 | [MCP413x_503] = { .wipers = 1, .max_pos = 128, .kohms = 50, }, | ||
99 | [MCP413x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, }, | ||
100 | [MCP414x_502] = { .wipers = 1, .max_pos = 128, .kohms = 5, }, | ||
101 | [MCP414x_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, }, | ||
102 | [MCP414x_503] = { .wipers = 1, .max_pos = 128, .kohms = 50, }, | ||
103 | [MCP414x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, }, | ||
104 | [MCP415x_502] = { .wipers = 1, .max_pos = 256, .kohms = 5, }, | ||
105 | [MCP415x_103] = { .wipers = 1, .max_pos = 256, .kohms = 10, }, | ||
106 | [MCP415x_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, }, | ||
107 | [MCP415x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, }, | ||
108 | [MCP416x_502] = { .wipers = 1, .max_pos = 256, .kohms = 5, }, | ||
109 | [MCP416x_103] = { .wipers = 1, .max_pos = 256, .kohms = 10, }, | ||
110 | [MCP416x_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, }, | ||
111 | [MCP416x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, }, | ||
112 | [MCP423x_502] = { .wipers = 2, .max_pos = 128, .kohms = 5, }, | ||
113 | [MCP423x_103] = { .wipers = 2, .max_pos = 128, .kohms = 10, }, | ||
114 | [MCP423x_503] = { .wipers = 2, .max_pos = 128, .kohms = 50, }, | ||
115 | [MCP423x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, }, | ||
116 | [MCP424x_502] = { .wipers = 2, .max_pos = 128, .kohms = 5, }, | ||
117 | [MCP424x_103] = { .wipers = 2, .max_pos = 128, .kohms = 10, }, | ||
118 | [MCP424x_503] = { .wipers = 2, .max_pos = 128, .kohms = 50, }, | ||
119 | [MCP424x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, }, | ||
120 | [MCP425x_502] = { .wipers = 2, .max_pos = 256, .kohms = 5, }, | ||
121 | [MCP425x_103] = { .wipers = 2, .max_pos = 256, .kohms = 10, }, | ||
122 | [MCP425x_503] = { .wipers = 2, .max_pos = 256, .kohms = 50, }, | ||
123 | [MCP425x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, }, | ||
124 | [MCP426x_502] = { .wipers = 2, .max_pos = 256, .kohms = 5, }, | ||
125 | [MCP426x_103] = { .wipers = 2, .max_pos = 256, .kohms = 10, }, | ||
126 | [MCP426x_503] = { .wipers = 2, .max_pos = 256, .kohms = 50, }, | ||
127 | [MCP426x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, }, | ||
128 | }; | ||
129 | |||
130 | struct mcp4131_data { | ||
131 | struct spi_device *spi; | ||
132 | const struct mcp4131_cfg *cfg; | ||
133 | struct mutex lock; | ||
134 | u8 buf[2] ____cacheline_aligned; | ||
135 | }; | ||
136 | |||
137 | #define MCP4131_CHANNEL(ch) { \ | ||
138 | .type = IIO_RESISTANCE, \ | ||
139 | .indexed = 1, \ | ||
140 | .output = 1, \ | ||
141 | .channel = (ch), \ | ||
142 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
143 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ | ||
144 | } | ||
145 | |||
146 | static const struct iio_chan_spec mcp4131_channels[] = { | ||
147 | MCP4131_CHANNEL(0), | ||
148 | MCP4131_CHANNEL(1), | ||
149 | }; | ||
150 | |||
151 | static int mcp4131_read(struct spi_device *spi, void *buf, size_t len) | ||
152 | { | ||
153 | struct spi_transfer t = { | ||
154 | .tx_buf = buf, /* We need to send addr, cmd and 12 bits */ | ||
155 | .rx_buf = buf, | ||
156 | .len = len, | ||
157 | }; | ||
158 | struct spi_message m; | ||
159 | |||
160 | spi_message_init(&m); | ||
161 | spi_message_add_tail(&t, &m); | ||
162 | |||
163 | return spi_sync(spi, &m); | ||
164 | } | ||
165 | |||
166 | static int mcp4131_read_raw(struct iio_dev *indio_dev, | ||
167 | struct iio_chan_spec const *chan, | ||
168 | int *val, int *val2, long mask) | ||
169 | { | ||
170 | int err; | ||
171 | struct mcp4131_data *data = iio_priv(indio_dev); | ||
172 | int address = chan->channel; | ||
173 | |||
174 | switch (mask) { | ||
175 | case IIO_CHAN_INFO_RAW: | ||
176 | mutex_lock(&data->lock); | ||
177 | |||
178 | data->buf[0] = (address << MCP4131_WIPER_SHIFT) | MCP4131_READ; | ||
179 | data->buf[1] = 0; | ||
180 | |||
181 | err = mcp4131_read(data->spi, data->buf, 2); | ||
182 | if (err) { | ||
183 | mutex_unlock(&data->lock); | ||
184 | return err; | ||
185 | } | ||
186 | |||
187 | /* Error, bad address/command combination */ | ||
188 | if (!MCP4131_CMDERR(data->buf)) { | ||
189 | mutex_unlock(&data->lock); | ||
190 | return -EIO; | ||
191 | } | ||
192 | |||
193 | *val = MCP4131_RAW(data->buf); | ||
194 | mutex_unlock(&data->lock); | ||
195 | |||
196 | return IIO_VAL_INT; | ||
197 | |||
198 | case IIO_CHAN_INFO_SCALE: | ||
199 | *val = 1000 * data->cfg->kohms; | ||
200 | *val2 = data->cfg->max_pos; | ||
201 | return IIO_VAL_FRACTIONAL; | ||
202 | } | ||
203 | |||
204 | return -EINVAL; | ||
205 | } | ||
206 | |||
207 | static int mcp4131_write_raw(struct iio_dev *indio_dev, | ||
208 | struct iio_chan_spec const *chan, | ||
209 | int val, int val2, long mask) | ||
210 | { | ||
211 | int err; | ||
212 | struct mcp4131_data *data = iio_priv(indio_dev); | ||
213 | int address = chan->channel << MCP4131_WIPER_SHIFT; | ||
214 | |||
215 | switch (mask) { | ||
216 | case IIO_CHAN_INFO_RAW: | ||
217 | if (val > data->cfg->max_pos || val < 0) | ||
218 | return -EINVAL; | ||
219 | break; | ||
220 | |||
221 | default: | ||
222 | return -EINVAL; | ||
223 | } | ||
224 | |||
225 | mutex_lock(&data->lock); | ||
226 | |||
227 | data->buf[0] = address << MCP4131_WIPER_SHIFT; | ||
228 | data->buf[0] |= MCP4131_WRITE | (val >> 8); | ||
229 | data->buf[1] = val & 0xFF; /* 8 bits here */ | ||
230 | |||
231 | err = spi_write(data->spi, data->buf, 2); | ||
232 | mutex_unlock(&data->lock); | ||
233 | |||
234 | return err; | ||
235 | } | ||
236 | |||
237 | static const struct iio_info mcp4131_info = { | ||
238 | .read_raw = mcp4131_read_raw, | ||
239 | .write_raw = mcp4131_write_raw, | ||
240 | .driver_module = THIS_MODULE, | ||
241 | }; | ||
242 | |||
243 | static int mcp4131_probe(struct spi_device *spi) | ||
244 | { | ||
245 | int err; | ||
246 | struct device *dev = &spi->dev; | ||
247 | unsigned long devid = spi_get_device_id(spi)->driver_data; | ||
248 | struct mcp4131_data *data; | ||
249 | struct iio_dev *indio_dev; | ||
250 | |||
251 | indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); | ||
252 | if (!indio_dev) | ||
253 | return -ENOMEM; | ||
254 | |||
255 | data = iio_priv(indio_dev); | ||
256 | spi_set_drvdata(spi, indio_dev); | ||
257 | data->spi = spi; | ||
258 | data->cfg = &mcp4131_cfg[devid]; | ||
259 | |||
260 | mutex_init(&data->lock); | ||
261 | |||
262 | indio_dev->dev.parent = dev; | ||
263 | indio_dev->info = &mcp4131_info; | ||
264 | indio_dev->channels = mcp4131_channels; | ||
265 | indio_dev->num_channels = data->cfg->wipers; | ||
266 | indio_dev->name = spi_get_device_id(spi)->name; | ||
267 | |||
268 | err = devm_iio_device_register(dev, indio_dev); | ||
269 | if (err) { | ||
270 | dev_info(&spi->dev, "Unable to register %s\n", indio_dev->name); | ||
271 | return err; | ||
272 | } | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | #if defined(CONFIG_OF) | ||
278 | static const struct of_device_id mcp4131_dt_ids[] = { | ||
279 | { .compatible = "microchip,mcp4131-502", | ||
280 | .data = &mcp4131_cfg[MCP413x_502] }, | ||
281 | { .compatible = "microchip,mcp4131-103", | ||
282 | .data = &mcp4131_cfg[MCP413x_103] }, | ||
283 | { .compatible = "microchip,mcp4131-503", | ||
284 | .data = &mcp4131_cfg[MCP413x_503] }, | ||
285 | { .compatible = "microchip,mcp4131-104", | ||
286 | .data = &mcp4131_cfg[MCP413x_104] }, | ||
287 | { .compatible = "microchip,mcp4132-502", | ||
288 | .data = &mcp4131_cfg[MCP413x_502] }, | ||
289 | { .compatible = "microchip,mcp4132-103", | ||
290 | .data = &mcp4131_cfg[MCP413x_103] }, | ||
291 | { .compatible = "microchip,mcp4132-503", | ||
292 | .data = &mcp4131_cfg[MCP413x_503] }, | ||
293 | { .compatible = "microchip,mcp4132-104", | ||
294 | .data = &mcp4131_cfg[MCP413x_104] }, | ||
295 | { .compatible = "microchip,mcp4141-502", | ||
296 | .data = &mcp4131_cfg[MCP414x_502] }, | ||
297 | { .compatible = "microchip,mcp4141-103", | ||
298 | .data = &mcp4131_cfg[MCP414x_103] }, | ||
299 | { .compatible = "microchip,mcp4141-503", | ||
300 | .data = &mcp4131_cfg[MCP414x_503] }, | ||
301 | { .compatible = "microchip,mcp4141-104", | ||
302 | .data = &mcp4131_cfg[MCP414x_104] }, | ||
303 | { .compatible = "microchip,mcp4142-502", | ||
304 | .data = &mcp4131_cfg[MCP414x_502] }, | ||
305 | { .compatible = "microchip,mcp4142-103", | ||
306 | .data = &mcp4131_cfg[MCP414x_103] }, | ||
307 | { .compatible = "microchip,mcp4142-503", | ||
308 | .data = &mcp4131_cfg[MCP414x_503] }, | ||
309 | { .compatible = "microchip,mcp4142-104", | ||
310 | .data = &mcp4131_cfg[MCP414x_104] }, | ||
311 | { .compatible = "microchip,mcp4151-502", | ||
312 | .data = &mcp4131_cfg[MCP415x_502] }, | ||
313 | { .compatible = "microchip,mcp4151-103", | ||
314 | .data = &mcp4131_cfg[MCP415x_103] }, | ||
315 | { .compatible = "microchip,mcp4151-503", | ||
316 | .data = &mcp4131_cfg[MCP415x_503] }, | ||
317 | { .compatible = "microchip,mcp4151-104", | ||
318 | .data = &mcp4131_cfg[MCP415x_104] }, | ||
319 | { .compatible = "microchip,mcp4152-502", | ||
320 | .data = &mcp4131_cfg[MCP415x_502] }, | ||
321 | { .compatible = "microchip,mcp4152-103", | ||
322 | .data = &mcp4131_cfg[MCP415x_103] }, | ||
323 | { .compatible = "microchip,mcp4152-503", | ||
324 | .data = &mcp4131_cfg[MCP415x_503] }, | ||
325 | { .compatible = "microchip,mcp4152-104", | ||
326 | .data = &mcp4131_cfg[MCP415x_104] }, | ||
327 | { .compatible = "microchip,mcp4161-502", | ||
328 | .data = &mcp4131_cfg[MCP416x_502] }, | ||
329 | { .compatible = "microchip,mcp4161-103", | ||
330 | .data = &mcp4131_cfg[MCP416x_103] }, | ||
331 | { .compatible = "microchip,mcp4161-503", | ||
332 | .data = &mcp4131_cfg[MCP416x_503] }, | ||
333 | { .compatible = "microchip,mcp4161-104", | ||
334 | .data = &mcp4131_cfg[MCP416x_104] }, | ||
335 | { .compatible = "microchip,mcp4162-502", | ||
336 | .data = &mcp4131_cfg[MCP416x_502] }, | ||
337 | { .compatible = "microchip,mcp4162-103", | ||
338 | .data = &mcp4131_cfg[MCP416x_103] }, | ||
339 | { .compatible = "microchip,mcp4162-503", | ||
340 | .data = &mcp4131_cfg[MCP416x_503] }, | ||
341 | { .compatible = "microchip,mcp4162-104", | ||
342 | .data = &mcp4131_cfg[MCP416x_104] }, | ||
343 | { .compatible = "microchip,mcp4231-502", | ||
344 | .data = &mcp4131_cfg[MCP423x_502] }, | ||
345 | { .compatible = "microchip,mcp4231-103", | ||
346 | .data = &mcp4131_cfg[MCP423x_103] }, | ||
347 | { .compatible = "microchip,mcp4231-503", | ||
348 | .data = &mcp4131_cfg[MCP423x_503] }, | ||
349 | { .compatible = "microchip,mcp4231-104", | ||
350 | .data = &mcp4131_cfg[MCP423x_104] }, | ||
351 | { .compatible = "microchip,mcp4232-502", | ||
352 | .data = &mcp4131_cfg[MCP423x_502] }, | ||
353 | { .compatible = "microchip,mcp4232-103", | ||
354 | .data = &mcp4131_cfg[MCP423x_103] }, | ||
355 | { .compatible = "microchip,mcp4232-503", | ||
356 | .data = &mcp4131_cfg[MCP423x_503] }, | ||
357 | { .compatible = "microchip,mcp4232-104", | ||
358 | .data = &mcp4131_cfg[MCP423x_104] }, | ||
359 | { .compatible = "microchip,mcp4241-502", | ||
360 | .data = &mcp4131_cfg[MCP424x_502] }, | ||
361 | { .compatible = "microchip,mcp4241-103", | ||
362 | .data = &mcp4131_cfg[MCP424x_103] }, | ||
363 | { .compatible = "microchip,mcp4241-503", | ||
364 | .data = &mcp4131_cfg[MCP424x_503] }, | ||
365 | { .compatible = "microchip,mcp4241-104", | ||
366 | .data = &mcp4131_cfg[MCP424x_104] }, | ||
367 | { .compatible = "microchip,mcp4242-502", | ||
368 | .data = &mcp4131_cfg[MCP424x_502] }, | ||
369 | { .compatible = "microchip,mcp4242-103", | ||
370 | .data = &mcp4131_cfg[MCP424x_103] }, | ||
371 | { .compatible = "microchip,mcp4242-503", | ||
372 | .data = &mcp4131_cfg[MCP424x_503] }, | ||
373 | { .compatible = "microchip,mcp4242-104", | ||
374 | .data = &mcp4131_cfg[MCP424x_104] }, | ||
375 | { .compatible = "microchip,mcp4251-502", | ||
376 | .data = &mcp4131_cfg[MCP425x_502] }, | ||
377 | { .compatible = "microchip,mcp4251-103", | ||
378 | .data = &mcp4131_cfg[MCP425x_103] }, | ||
379 | { .compatible = "microchip,mcp4251-503", | ||
380 | .data = &mcp4131_cfg[MCP425x_503] }, | ||
381 | { .compatible = "microchip,mcp4251-104", | ||
382 | .data = &mcp4131_cfg[MCP425x_104] }, | ||
383 | { .compatible = "microchip,mcp4252-502", | ||
384 | .data = &mcp4131_cfg[MCP425x_502] }, | ||
385 | { .compatible = "microchip,mcp4252-103", | ||
386 | .data = &mcp4131_cfg[MCP425x_103] }, | ||
387 | { .compatible = "microchip,mcp4252-503", | ||
388 | .data = &mcp4131_cfg[MCP425x_503] }, | ||
389 | { .compatible = "microchip,mcp4252-104", | ||
390 | .data = &mcp4131_cfg[MCP425x_104] }, | ||
391 | { .compatible = "microchip,mcp4261-502", | ||
392 | .data = &mcp4131_cfg[MCP426x_502] }, | ||
393 | { .compatible = "microchip,mcp4261-103", | ||
394 | .data = &mcp4131_cfg[MCP426x_103] }, | ||
395 | { .compatible = "microchip,mcp4261-503", | ||
396 | .data = &mcp4131_cfg[MCP426x_503] }, | ||
397 | { .compatible = "microchip,mcp4261-104", | ||
398 | .data = &mcp4131_cfg[MCP426x_104] }, | ||
399 | { .compatible = "microchip,mcp4262-502", | ||
400 | .data = &mcp4131_cfg[MCP426x_502] }, | ||
401 | { .compatible = "microchip,mcp4262-103", | ||
402 | .data = &mcp4131_cfg[MCP426x_103] }, | ||
403 | { .compatible = "microchip,mcp4262-503", | ||
404 | .data = &mcp4131_cfg[MCP426x_503] }, | ||
405 | { .compatible = "microchip,mcp4262-104", | ||
406 | .data = &mcp4131_cfg[MCP426x_104] }, | ||
407 | {} | ||
408 | }; | ||
409 | MODULE_DEVICE_TABLE(of, mcp4131_dt_ids); | ||
410 | #endif /* CONFIG_OF */ | ||
411 | |||
412 | static const struct spi_device_id mcp4131_id[] = { | ||
413 | { "mcp4131-502", MCP413x_502 }, | ||
414 | { "mcp4131-103", MCP413x_103 }, | ||
415 | { "mcp4131-503", MCP413x_503 }, | ||
416 | { "mcp4131-104", MCP413x_104 }, | ||
417 | { "mcp4132-502", MCP413x_502 }, | ||
418 | { "mcp4132-103", MCP413x_103 }, | ||
419 | { "mcp4132-503", MCP413x_503 }, | ||
420 | { "mcp4132-104", MCP413x_104 }, | ||
421 | { "mcp4141-502", MCP414x_502 }, | ||
422 | { "mcp4141-103", MCP414x_103 }, | ||
423 | { "mcp4141-503", MCP414x_503 }, | ||
424 | { "mcp4141-104", MCP414x_104 }, | ||
425 | { "mcp4142-502", MCP414x_502 }, | ||
426 | { "mcp4142-103", MCP414x_103 }, | ||
427 | { "mcp4142-503", MCP414x_503 }, | ||
428 | { "mcp4142-104", MCP414x_104 }, | ||
429 | { "mcp4151-502", MCP415x_502 }, | ||
430 | { "mcp4151-103", MCP415x_103 }, | ||
431 | { "mcp4151-503", MCP415x_503 }, | ||
432 | { "mcp4151-104", MCP415x_104 }, | ||
433 | { "mcp4152-502", MCP415x_502 }, | ||
434 | { "mcp4152-103", MCP415x_103 }, | ||
435 | { "mcp4152-503", MCP415x_503 }, | ||
436 | { "mcp4152-104", MCP415x_104 }, | ||
437 | { "mcp4161-502", MCP416x_502 }, | ||
438 | { "mcp4161-103", MCP416x_103 }, | ||
439 | { "mcp4161-503", MCP416x_503 }, | ||
440 | { "mcp4161-104", MCP416x_104 }, | ||
441 | { "mcp4162-502", MCP416x_502 }, | ||
442 | { "mcp4162-103", MCP416x_103 }, | ||
443 | { "mcp4162-503", MCP416x_503 }, | ||
444 | { "mcp4162-104", MCP416x_104 }, | ||
445 | { "mcp4231-502", MCP423x_502 }, | ||
446 | { "mcp4231-103", MCP423x_103 }, | ||
447 | { "mcp4231-503", MCP423x_503 }, | ||
448 | { "mcp4231-104", MCP423x_104 }, | ||
449 | { "mcp4232-502", MCP423x_502 }, | ||
450 | { "mcp4232-103", MCP423x_103 }, | ||
451 | { "mcp4232-503", MCP423x_503 }, | ||
452 | { "mcp4232-104", MCP423x_104 }, | ||
453 | { "mcp4241-502", MCP424x_502 }, | ||
454 | { "mcp4241-103", MCP424x_103 }, | ||
455 | { "mcp4241-503", MCP424x_503 }, | ||
456 | { "mcp4241-104", MCP424x_104 }, | ||
457 | { "mcp4242-502", MCP424x_502 }, | ||
458 | { "mcp4242-103", MCP424x_103 }, | ||
459 | { "mcp4242-503", MCP424x_503 }, | ||
460 | { "mcp4242-104", MCP424x_104 }, | ||
461 | { "mcp4251-502", MCP425x_502 }, | ||
462 | { "mcp4251-103", MCP425x_103 }, | ||
463 | { "mcp4251-503", MCP425x_503 }, | ||
464 | { "mcp4251-104", MCP425x_104 }, | ||
465 | { "mcp4252-502", MCP425x_502 }, | ||
466 | { "mcp4252-103", MCP425x_103 }, | ||
467 | { "mcp4252-503", MCP425x_503 }, | ||
468 | { "mcp4252-104", MCP425x_104 }, | ||
469 | { "mcp4261-502", MCP426x_502 }, | ||
470 | { "mcp4261-103", MCP426x_103 }, | ||
471 | { "mcp4261-503", MCP426x_503 }, | ||
472 | { "mcp4261-104", MCP426x_104 }, | ||
473 | { "mcp4262-502", MCP426x_502 }, | ||
474 | { "mcp4262-103", MCP426x_103 }, | ||
475 | { "mcp4262-503", MCP426x_503 }, | ||
476 | { "mcp4262-104", MCP426x_104 }, | ||
477 | {} | ||
478 | }; | ||
479 | MODULE_DEVICE_TABLE(spi, mcp4131_id); | ||
480 | |||
481 | static struct spi_driver mcp4131_driver = { | ||
482 | .driver = { | ||
483 | .name = "mcp4131", | ||
484 | .of_match_table = of_match_ptr(mcp4131_dt_ids), | ||
485 | }, | ||
486 | .probe = mcp4131_probe, | ||
487 | .id_table = mcp4131_id, | ||
488 | }; | ||
489 | |||
490 | module_spi_driver(mcp4131_driver); | ||
491 | |||
492 | MODULE_AUTHOR("Slawomir Stepien <sst@poczta.fm>"); | ||
493 | MODULE_DESCRIPTION("MCP4131 digital potentiometer"); | ||
494 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c index 0db67fe14766..3b72e1a595db 100644 --- a/drivers/iio/potentiometer/mcp4531.c +++ b/drivers/iio/potentiometer/mcp4531.c | |||
@@ -79,7 +79,7 @@ static const struct mcp4531_cfg mcp4531_cfg[] = { | |||
79 | 79 | ||
80 | struct mcp4531_data { | 80 | struct mcp4531_data { |
81 | struct i2c_client *client; | 81 | struct i2c_client *client; |
82 | unsigned long devid; | 82 | const struct mcp4531_cfg *cfg; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | #define MCP4531_CHANNEL(ch) { \ | 85 | #define MCP4531_CHANNEL(ch) { \ |
@@ -113,8 +113,8 @@ static int mcp4531_read_raw(struct iio_dev *indio_dev, | |||
113 | *val = ret; | 113 | *val = ret; |
114 | return IIO_VAL_INT; | 114 | return IIO_VAL_INT; |
115 | case IIO_CHAN_INFO_SCALE: | 115 | case IIO_CHAN_INFO_SCALE: |
116 | *val = 1000 * mcp4531_cfg[data->devid].kohms; | 116 | *val = 1000 * data->cfg->kohms; |
117 | *val2 = mcp4531_cfg[data->devid].max_pos; | 117 | *val2 = data->cfg->max_pos; |
118 | return IIO_VAL_FRACTIONAL; | 118 | return IIO_VAL_FRACTIONAL; |
119 | } | 119 | } |
120 | 120 | ||
@@ -130,7 +130,7 @@ static int mcp4531_write_raw(struct iio_dev *indio_dev, | |||
130 | 130 | ||
131 | switch (mask) { | 131 | switch (mask) { |
132 | case IIO_CHAN_INFO_RAW: | 132 | case IIO_CHAN_INFO_RAW: |
133 | if (val > mcp4531_cfg[data->devid].max_pos || val < 0) | 133 | if (val > data->cfg->max_pos || val < 0) |
134 | return -EINVAL; | 134 | return -EINVAL; |
135 | break; | 135 | break; |
136 | default: | 136 | default: |
@@ -152,7 +152,6 @@ static int mcp4531_probe(struct i2c_client *client, | |||
152 | const struct i2c_device_id *id) | 152 | const struct i2c_device_id *id) |
153 | { | 153 | { |
154 | struct device *dev = &client->dev; | 154 | struct device *dev = &client->dev; |
155 | unsigned long devid = id->driver_data; | ||
156 | struct mcp4531_data *data; | 155 | struct mcp4531_data *data; |
157 | struct iio_dev *indio_dev; | 156 | struct iio_dev *indio_dev; |
158 | 157 | ||
@@ -168,12 +167,12 @@ static int mcp4531_probe(struct i2c_client *client, | |||
168 | data = iio_priv(indio_dev); | 167 | data = iio_priv(indio_dev); |
169 | i2c_set_clientdata(client, indio_dev); | 168 | i2c_set_clientdata(client, indio_dev); |
170 | data->client = client; | 169 | data->client = client; |
171 | data->devid = devid; | 170 | data->cfg = &mcp4531_cfg[id->driver_data]; |
172 | 171 | ||
173 | indio_dev->dev.parent = dev; | 172 | indio_dev->dev.parent = dev; |
174 | indio_dev->info = &mcp4531_info; | 173 | indio_dev->info = &mcp4531_info; |
175 | indio_dev->channels = mcp4531_channels; | 174 | indio_dev->channels = mcp4531_channels; |
176 | indio_dev->num_channels = mcp4531_cfg[devid].wipers; | 175 | indio_dev->num_channels = data->cfg->wipers; |
177 | indio_dev->name = client->name; | 176 | indio_dev->name = client->name; |
178 | 177 | ||
179 | return devm_iio_device_register(dev, indio_dev); | 178 | return devm_iio_device_register(dev, indio_dev); |
diff --git a/drivers/iio/potentiometer/tpl0102.c b/drivers/iio/potentiometer/tpl0102.c index 313124b6fd59..5c304d42d713 100644 --- a/drivers/iio/potentiometer/tpl0102.c +++ b/drivers/iio/potentiometer/tpl0102.c | |||
@@ -118,7 +118,7 @@ static int tpl0102_probe(struct i2c_client *client, | |||
118 | 118 | ||
119 | if (!i2c_check_functionality(client->adapter, | 119 | if (!i2c_check_functionality(client->adapter, |
120 | I2C_FUNC_SMBUS_WORD_DATA)) | 120 | I2C_FUNC_SMBUS_WORD_DATA)) |
121 | return -ENOTSUPP; | 121 | return -EOPNOTSUPP; |
122 | 122 | ||
123 | indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); | 123 | indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); |
124 | if (!indio_dev) | 124 | if (!indio_dev) |
diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig index 31c0e1fd2202..8de0192adea6 100644 --- a/drivers/iio/pressure/Kconfig +++ b/drivers/iio/pressure/Kconfig | |||
@@ -148,4 +148,14 @@ config T5403 | |||
148 | To compile this driver as a module, choose M here: the module | 148 | To compile this driver as a module, choose M here: the module |
149 | will be called t5403. | 149 | will be called t5403. |
150 | 150 | ||
151 | config HP206C | ||
152 | tristate "HOPERF HP206C precision barometer and altimeter sensor" | ||
153 | depends on I2C | ||
154 | help | ||
155 | Say yes here to build support for the HOPREF HP206C precision | ||
156 | barometer and altimeter sensor. | ||
157 | |||
158 | This driver can also be built as a module. If so, the module will | ||
159 | be called hp206c. | ||
160 | |||
151 | endmenu | 161 | endmenu |
diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile index d336af14f3fe..6e60863c1086 100644 --- a/drivers/iio/pressure/Makefile +++ b/drivers/iio/pressure/Makefile | |||
@@ -17,6 +17,7 @@ obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o | |||
17 | st_pressure-y := st_pressure_core.o | 17 | st_pressure-y := st_pressure_core.o |
18 | st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o | 18 | st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o |
19 | obj-$(CONFIG_T5403) += t5403.o | 19 | obj-$(CONFIG_T5403) += t5403.o |
20 | obj-$(CONFIG_HP206C) += hp206c.o | ||
20 | 21 | ||
21 | obj-$(CONFIG_IIO_ST_PRESS_I2C) += st_pressure_i2c.o | 22 | obj-$(CONFIG_IIO_ST_PRESS_I2C) += st_pressure_i2c.o |
22 | obj-$(CONFIG_IIO_ST_PRESS_SPI) += st_pressure_spi.o | 23 | obj-$(CONFIG_IIO_ST_PRESS_SPI) += st_pressure_spi.o |
diff --git a/drivers/iio/pressure/hp206c.c b/drivers/iio/pressure/hp206c.c new file mode 100644 index 000000000000..90f2b6e4a920 --- /dev/null +++ b/drivers/iio/pressure/hp206c.c | |||
@@ -0,0 +1,426 @@ | |||
1 | /* | ||
2 | * hp206c.c - HOPERF HP206C precision barometer and altimeter sensor | ||
3 | * | ||
4 | * Copyright (c) 2016, Intel Corporation. | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of version 2 of | ||
7 | * the GNU General Public License. See the file COPYING in the main | ||
8 | * directory of this archive for more details. | ||
9 | * | ||
10 | * (7-bit I2C slave address 0x76) | ||
11 | * | ||
12 | * Datasheet: | ||
13 | * http://www.hoperf.com/upload/sensor/HP206C_DataSheet_EN_V2.0.pdf | ||
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/delay.h> | ||
21 | #include <linux/util_macros.h> | ||
22 | #include <linux/acpi.h> | ||
23 | |||
24 | /* I2C commands: */ | ||
25 | #define HP206C_CMD_SOFT_RST 0x06 | ||
26 | |||
27 | #define HP206C_CMD_ADC_CVT 0x40 | ||
28 | |||
29 | #define HP206C_CMD_ADC_CVT_OSR_4096 0x00 | ||
30 | #define HP206C_CMD_ADC_CVT_OSR_2048 0x04 | ||
31 | #define HP206C_CMD_ADC_CVT_OSR_1024 0x08 | ||
32 | #define HP206C_CMD_ADC_CVT_OSR_512 0x0c | ||
33 | #define HP206C_CMD_ADC_CVT_OSR_256 0x10 | ||
34 | #define HP206C_CMD_ADC_CVT_OSR_128 0x14 | ||
35 | |||
36 | #define HP206C_CMD_ADC_CVT_CHNL_PT 0x00 | ||
37 | #define HP206C_CMD_ADC_CVT_CHNL_T 0x02 | ||
38 | |||
39 | #define HP206C_CMD_READ_P 0x30 | ||
40 | #define HP206C_CMD_READ_T 0x32 | ||
41 | |||
42 | #define HP206C_CMD_READ_REG 0x80 | ||
43 | #define HP206C_CMD_WRITE_REG 0xc0 | ||
44 | |||
45 | #define HP206C_REG_INT_EN 0x0b | ||
46 | #define HP206C_REG_INT_CFG 0x0c | ||
47 | |||
48 | #define HP206C_REG_INT_SRC 0x0d | ||
49 | #define HP206C_FLAG_DEV_RDY 0x40 | ||
50 | |||
51 | #define HP206C_REG_PARA 0x0f | ||
52 | #define HP206C_FLAG_CMPS_EN 0x80 | ||
53 | |||
54 | /* Maximum spin for DEV_RDY */ | ||
55 | #define HP206C_MAX_DEV_RDY_WAIT_COUNT 20 | ||
56 | #define HP206C_DEV_RDY_WAIT_US 20000 | ||
57 | |||
58 | struct hp206c_data { | ||
59 | struct mutex mutex; | ||
60 | struct i2c_client *client; | ||
61 | int temp_osr_index; | ||
62 | int pres_osr_index; | ||
63 | }; | ||
64 | |||
65 | struct hp206c_osr_setting { | ||
66 | u8 osr_mask; | ||
67 | unsigned int temp_conv_time_us; | ||
68 | unsigned int pres_conv_time_us; | ||
69 | }; | ||
70 | |||
71 | /* Data from Table 5 in datasheet. */ | ||
72 | static const struct hp206c_osr_setting hp206c_osr_settings[] = { | ||
73 | { HP206C_CMD_ADC_CVT_OSR_4096, 65600, 131100 }, | ||
74 | { HP206C_CMD_ADC_CVT_OSR_2048, 32800, 65600 }, | ||
75 | { HP206C_CMD_ADC_CVT_OSR_1024, 16400, 32800 }, | ||
76 | { HP206C_CMD_ADC_CVT_OSR_512, 8200, 16400 }, | ||
77 | { HP206C_CMD_ADC_CVT_OSR_256, 4100, 8200 }, | ||
78 | { HP206C_CMD_ADC_CVT_OSR_128, 2100, 4100 }, | ||
79 | }; | ||
80 | static const int hp206c_osr_rates[] = { 4096, 2048, 1024, 512, 256, 128 }; | ||
81 | static const char hp206c_osr_rates_str[] = "4096 2048 1024 512 256 128"; | ||
82 | |||
83 | static inline int hp206c_read_reg(struct i2c_client *client, u8 reg) | ||
84 | { | ||
85 | return i2c_smbus_read_byte_data(client, HP206C_CMD_READ_REG | reg); | ||
86 | } | ||
87 | |||
88 | static inline int hp206c_write_reg(struct i2c_client *client, u8 reg, u8 val) | ||
89 | { | ||
90 | return i2c_smbus_write_byte_data(client, | ||
91 | HP206C_CMD_WRITE_REG | reg, val); | ||
92 | } | ||
93 | |||
94 | static int hp206c_read_20bit(struct i2c_client *client, u8 cmd) | ||
95 | { | ||
96 | int ret; | ||
97 | u8 values[3]; | ||
98 | |||
99 | ret = i2c_smbus_read_i2c_block_data(client, cmd, 3, values); | ||
100 | if (ret < 0) | ||
101 | return ret; | ||
102 | if (ret != 3) | ||
103 | return -EIO; | ||
104 | return ((values[0] & 0xF) << 16) | (values[1] << 8) | (values[2]); | ||
105 | } | ||
106 | |||
107 | /* Spin for max 160ms until DEV_RDY is 1, or return error. */ | ||
108 | static int hp206c_wait_dev_rdy(struct iio_dev *indio_dev) | ||
109 | { | ||
110 | int ret; | ||
111 | int count = 0; | ||
112 | struct hp206c_data *data = iio_priv(indio_dev); | ||
113 | struct i2c_client *client = data->client; | ||
114 | |||
115 | while (++count <= HP206C_MAX_DEV_RDY_WAIT_COUNT) { | ||
116 | ret = hp206c_read_reg(client, HP206C_REG_INT_SRC); | ||
117 | if (ret < 0) { | ||
118 | dev_err(&indio_dev->dev, "Failed READ_REG INT_SRC: %d\n", ret); | ||
119 | return ret; | ||
120 | } | ||
121 | if (ret & HP206C_FLAG_DEV_RDY) | ||
122 | return 0; | ||
123 | usleep_range(HP206C_DEV_RDY_WAIT_US, HP206C_DEV_RDY_WAIT_US * 3 / 2); | ||
124 | } | ||
125 | return -ETIMEDOUT; | ||
126 | } | ||
127 | |||
128 | static int hp206c_set_compensation(struct i2c_client *client, bool enabled) | ||
129 | { | ||
130 | int val; | ||
131 | |||
132 | val = hp206c_read_reg(client, HP206C_REG_PARA); | ||
133 | if (val < 0) | ||
134 | return val; | ||
135 | if (enabled) | ||
136 | val |= HP206C_FLAG_CMPS_EN; | ||
137 | else | ||
138 | val &= ~HP206C_FLAG_CMPS_EN; | ||
139 | |||
140 | return hp206c_write_reg(client, HP206C_REG_PARA, val); | ||
141 | } | ||
142 | |||
143 | /* Do a soft reset */ | ||
144 | static int hp206c_soft_reset(struct iio_dev *indio_dev) | ||
145 | { | ||
146 | int ret; | ||
147 | struct hp206c_data *data = iio_priv(indio_dev); | ||
148 | struct i2c_client *client = data->client; | ||
149 | |||
150 | ret = i2c_smbus_write_byte(client, HP206C_CMD_SOFT_RST); | ||
151 | if (ret) { | ||
152 | dev_err(&client->dev, "Failed to reset device: %d\n", ret); | ||
153 | return ret; | ||
154 | } | ||
155 | |||
156 | usleep_range(400, 600); | ||
157 | |||
158 | ret = hp206c_wait_dev_rdy(indio_dev); | ||
159 | if (ret) { | ||
160 | dev_err(&client->dev, "Device not ready after soft reset: %d\n", ret); | ||
161 | return ret; | ||
162 | } | ||
163 | |||
164 | ret = hp206c_set_compensation(client, true); | ||
165 | if (ret) | ||
166 | dev_err(&client->dev, "Failed to enable compensation: %d\n", ret); | ||
167 | return ret; | ||
168 | } | ||
169 | |||
170 | static int hp206c_conv_and_read(struct iio_dev *indio_dev, | ||
171 | u8 conv_cmd, u8 read_cmd, | ||
172 | unsigned int sleep_us) | ||
173 | { | ||
174 | int ret; | ||
175 | struct hp206c_data *data = iio_priv(indio_dev); | ||
176 | struct i2c_client *client = data->client; | ||
177 | |||
178 | ret = hp206c_wait_dev_rdy(indio_dev); | ||
179 | if (ret < 0) { | ||
180 | dev_err(&indio_dev->dev, "Device not ready: %d\n", ret); | ||
181 | return ret; | ||
182 | } | ||
183 | |||
184 | ret = i2c_smbus_write_byte(client, conv_cmd); | ||
185 | if (ret < 0) { | ||
186 | dev_err(&indio_dev->dev, "Failed convert: %d\n", ret); | ||
187 | return ret; | ||
188 | } | ||
189 | |||
190 | usleep_range(sleep_us, sleep_us * 3 / 2); | ||
191 | |||
192 | ret = hp206c_wait_dev_rdy(indio_dev); | ||
193 | if (ret < 0) { | ||
194 | dev_err(&indio_dev->dev, "Device not ready: %d\n", ret); | ||
195 | return ret; | ||
196 | } | ||
197 | |||
198 | ret = hp206c_read_20bit(client, read_cmd); | ||
199 | if (ret < 0) | ||
200 | dev_err(&indio_dev->dev, "Failed read: %d\n", ret); | ||
201 | |||
202 | return ret; | ||
203 | } | ||
204 | |||
205 | static int hp206c_read_raw(struct iio_dev *indio_dev, | ||
206 | struct iio_chan_spec const *chan, int *val, | ||
207 | int *val2, long mask) | ||
208 | { | ||
209 | int ret; | ||
210 | struct hp206c_data *data = iio_priv(indio_dev); | ||
211 | const struct hp206c_osr_setting *osr_setting; | ||
212 | u8 conv_cmd; | ||
213 | |||
214 | mutex_lock(&data->mutex); | ||
215 | |||
216 | switch (mask) { | ||
217 | case IIO_CHAN_INFO_OVERSAMPLING_RATIO: | ||
218 | switch (chan->type) { | ||
219 | case IIO_TEMP: | ||
220 | *val = hp206c_osr_rates[data->temp_osr_index]; | ||
221 | ret = IIO_VAL_INT; | ||
222 | break; | ||
223 | |||
224 | case IIO_PRESSURE: | ||
225 | *val = hp206c_osr_rates[data->pres_osr_index]; | ||
226 | ret = IIO_VAL_INT; | ||
227 | break; | ||
228 | default: | ||
229 | ret = -EINVAL; | ||
230 | } | ||
231 | break; | ||
232 | |||
233 | case IIO_CHAN_INFO_RAW: | ||
234 | switch (chan->type) { | ||
235 | case IIO_TEMP: | ||
236 | osr_setting = &hp206c_osr_settings[data->temp_osr_index]; | ||
237 | conv_cmd = HP206C_CMD_ADC_CVT | | ||
238 | osr_setting->osr_mask | | ||
239 | HP206C_CMD_ADC_CVT_CHNL_T; | ||
240 | ret = hp206c_conv_and_read(indio_dev, | ||
241 | conv_cmd, | ||
242 | HP206C_CMD_READ_T, | ||
243 | osr_setting->temp_conv_time_us); | ||
244 | if (ret >= 0) { | ||
245 | /* 20 significant bits are provided. | ||
246 | * Extend sign over the rest. | ||
247 | */ | ||
248 | *val = sign_extend32(ret, 19); | ||
249 | ret = IIO_VAL_INT; | ||
250 | } | ||
251 | break; | ||
252 | |||
253 | case IIO_PRESSURE: | ||
254 | osr_setting = &hp206c_osr_settings[data->pres_osr_index]; | ||
255 | conv_cmd = HP206C_CMD_ADC_CVT | | ||
256 | osr_setting->osr_mask | | ||
257 | HP206C_CMD_ADC_CVT_CHNL_PT; | ||
258 | ret = hp206c_conv_and_read(indio_dev, | ||
259 | conv_cmd, | ||
260 | HP206C_CMD_READ_P, | ||
261 | osr_setting->pres_conv_time_us); | ||
262 | if (ret >= 0) { | ||
263 | *val = ret; | ||
264 | ret = IIO_VAL_INT; | ||
265 | } | ||
266 | break; | ||
267 | default: | ||
268 | ret = -EINVAL; | ||
269 | } | ||
270 | break; | ||
271 | |||
272 | case IIO_CHAN_INFO_SCALE: | ||
273 | switch (chan->type) { | ||
274 | case IIO_TEMP: | ||
275 | *val = 0; | ||
276 | *val2 = 10000; | ||
277 | ret = IIO_VAL_INT_PLUS_MICRO; | ||
278 | break; | ||
279 | |||
280 | case IIO_PRESSURE: | ||
281 | *val = 0; | ||
282 | *val2 = 1000; | ||
283 | ret = IIO_VAL_INT_PLUS_MICRO; | ||
284 | break; | ||
285 | default: | ||
286 | ret = -EINVAL; | ||
287 | } | ||
288 | break; | ||
289 | |||
290 | default: | ||
291 | ret = -EINVAL; | ||
292 | } | ||
293 | |||
294 | mutex_unlock(&data->mutex); | ||
295 | return ret; | ||
296 | } | ||
297 | |||
298 | static int hp206c_write_raw(struct iio_dev *indio_dev, | ||
299 | struct iio_chan_spec const *chan, | ||
300 | int val, int val2, long mask) | ||
301 | { | ||
302 | int ret = 0; | ||
303 | struct hp206c_data *data = iio_priv(indio_dev); | ||
304 | |||
305 | if (mask != IIO_CHAN_INFO_OVERSAMPLING_RATIO) | ||
306 | return -EINVAL; | ||
307 | mutex_lock(&data->mutex); | ||
308 | switch (chan->type) { | ||
309 | case IIO_TEMP: | ||
310 | data->temp_osr_index = find_closest_descending(val, | ||
311 | hp206c_osr_rates, ARRAY_SIZE(hp206c_osr_rates)); | ||
312 | break; | ||
313 | case IIO_PRESSURE: | ||
314 | data->pres_osr_index = find_closest_descending(val, | ||
315 | hp206c_osr_rates, ARRAY_SIZE(hp206c_osr_rates)); | ||
316 | break; | ||
317 | default: | ||
318 | ret = -EINVAL; | ||
319 | } | ||
320 | mutex_unlock(&data->mutex); | ||
321 | return ret; | ||
322 | } | ||
323 | |||
324 | static const struct iio_chan_spec hp206c_channels[] = { | ||
325 | { | ||
326 | .type = IIO_TEMP, | ||
327 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | ||
328 | BIT(IIO_CHAN_INFO_SCALE) | | ||
329 | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), | ||
330 | }, | ||
331 | { | ||
332 | .type = IIO_PRESSURE, | ||
333 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | ||
334 | BIT(IIO_CHAN_INFO_SCALE) | | ||
335 | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), | ||
336 | } | ||
337 | }; | ||
338 | |||
339 | static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(hp206c_osr_rates_str); | ||
340 | |||
341 | static struct attribute *hp206c_attributes[] = { | ||
342 | &iio_const_attr_sampling_frequency_available.dev_attr.attr, | ||
343 | NULL, | ||
344 | }; | ||
345 | |||
346 | static const struct attribute_group hp206c_attribute_group = { | ||
347 | .attrs = hp206c_attributes, | ||
348 | }; | ||
349 | |||
350 | static const struct iio_info hp206c_info = { | ||
351 | .attrs = &hp206c_attribute_group, | ||
352 | .read_raw = hp206c_read_raw, | ||
353 | .write_raw = hp206c_write_raw, | ||
354 | .driver_module = THIS_MODULE, | ||
355 | }; | ||
356 | |||
357 | static int hp206c_probe(struct i2c_client *client, | ||
358 | const struct i2c_device_id *id) | ||
359 | { | ||
360 | struct iio_dev *indio_dev; | ||
361 | struct hp206c_data *data; | ||
362 | int ret; | ||
363 | |||
364 | if (!i2c_check_functionality(client->adapter, | ||
365 | I2C_FUNC_SMBUS_BYTE | | ||
366 | I2C_FUNC_SMBUS_BYTE_DATA | | ||
367 | I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { | ||
368 | dev_err(&client->dev, "Adapter does not support " | ||
369 | "all required i2c functionality\n"); | ||
370 | return -ENODEV; | ||
371 | } | ||
372 | |||
373 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); | ||
374 | if (!indio_dev) | ||
375 | return -ENOMEM; | ||
376 | |||
377 | data = iio_priv(indio_dev); | ||
378 | data->client = client; | ||
379 | mutex_init(&data->mutex); | ||
380 | |||
381 | indio_dev->info = &hp206c_info; | ||
382 | indio_dev->name = id->name; | ||
383 | indio_dev->dev.parent = &client->dev; | ||
384 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
385 | indio_dev->channels = hp206c_channels; | ||
386 | indio_dev->num_channels = ARRAY_SIZE(hp206c_channels); | ||
387 | |||
388 | i2c_set_clientdata(client, indio_dev); | ||
389 | |||
390 | /* Do a soft reset on probe */ | ||
391 | ret = hp206c_soft_reset(indio_dev); | ||
392 | if (ret) { | ||
393 | dev_err(&client->dev, "Failed to reset on startup: %d\n", ret); | ||
394 | return -ENODEV; | ||
395 | } | ||
396 | |||
397 | return devm_iio_device_register(&client->dev, indio_dev); | ||
398 | } | ||
399 | |||
400 | static const struct i2c_device_id hp206c_id[] = { | ||
401 | {"hp206c"}, | ||
402 | {} | ||
403 | }; | ||
404 | |||
405 | #ifdef CONFIG_ACPI | ||
406 | static const struct acpi_device_id hp206c_acpi_match[] = { | ||
407 | {"HOP206C", 0}, | ||
408 | { }, | ||
409 | }; | ||
410 | MODULE_DEVICE_TABLE(acpi, hp206c_acpi_match); | ||
411 | #endif | ||
412 | |||
413 | static struct i2c_driver hp206c_driver = { | ||
414 | .probe = hp206c_probe, | ||
415 | .id_table = hp206c_id, | ||
416 | .driver = { | ||
417 | .name = "hp206c", | ||
418 | .acpi_match_table = ACPI_PTR(hp206c_acpi_match), | ||
419 | }, | ||
420 | }; | ||
421 | |||
422 | module_i2c_driver(hp206c_driver); | ||
423 | |||
424 | MODULE_DESCRIPTION("HOPERF HP206C precision barometer and altimeter sensor"); | ||
425 | MODULE_AUTHOR("Leonard Crestez <leonard.crestez@intel.com>"); | ||
426 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/iio/pressure/ms5611.h b/drivers/iio/pressure/ms5611.h index 8b08e4b7e3a9..ccda63c5b3c3 100644 --- a/drivers/iio/pressure/ms5611.h +++ b/drivers/iio/pressure/ms5611.h | |||
@@ -16,15 +16,11 @@ | |||
16 | #include <linux/iio/iio.h> | 16 | #include <linux/iio/iio.h> |
17 | #include <linux/mutex.h> | 17 | #include <linux/mutex.h> |
18 | 18 | ||
19 | struct regulator; | ||
20 | |||
19 | #define MS5611_RESET 0x1e | 21 | #define MS5611_RESET 0x1e |
20 | #define MS5611_READ_ADC 0x00 | 22 | #define MS5611_READ_ADC 0x00 |
21 | #define MS5611_READ_PROM_WORD 0xA0 | 23 | #define MS5611_READ_PROM_WORD 0xA0 |
22 | #define MS5611_START_TEMP_CONV 0x58 | ||
23 | #define MS5611_START_PRESSURE_CONV 0x48 | ||
24 | |||
25 | #define MS5611_CONV_TIME_MIN 9040 | ||
26 | #define MS5611_CONV_TIME_MAX 10000 | ||
27 | |||
28 | #define MS5611_PROM_WORDS_NB 8 | 24 | #define MS5611_PROM_WORDS_NB 8 |
29 | 25 | ||
30 | enum { | 26 | enum { |
@@ -39,16 +35,31 @@ struct ms5611_chip_info { | |||
39 | s32 *temp, s32 *pressure); | 35 | s32 *temp, s32 *pressure); |
40 | }; | 36 | }; |
41 | 37 | ||
38 | /* | ||
39 | * OverSampling Rate descriptor. | ||
40 | * Warning: cmd MUST be kept aligned on a word boundary (see | ||
41 | * m5611_spi_read_adc_temp_and_pressure in ms5611_spi.c). | ||
42 | */ | ||
43 | struct ms5611_osr { | ||
44 | unsigned long conv_usec; | ||
45 | u8 cmd; | ||
46 | unsigned short rate; | ||
47 | }; | ||
48 | |||
42 | struct ms5611_state { | 49 | struct ms5611_state { |
43 | void *client; | 50 | void *client; |
44 | struct mutex lock; | 51 | struct mutex lock; |
45 | 52 | ||
53 | const struct ms5611_osr *pressure_osr; | ||
54 | const struct ms5611_osr *temp_osr; | ||
55 | |||
46 | int (*reset)(struct device *dev); | 56 | int (*reset)(struct device *dev); |
47 | int (*read_prom_word)(struct device *dev, int index, u16 *word); | 57 | int (*read_prom_word)(struct device *dev, int index, u16 *word); |
48 | int (*read_adc_temp_and_pressure)(struct device *dev, | 58 | int (*read_adc_temp_and_pressure)(struct device *dev, |
49 | s32 *temp, s32 *pressure); | 59 | s32 *temp, s32 *pressure); |
50 | 60 | ||
51 | struct ms5611_chip_info *chip_info; | 61 | struct ms5611_chip_info *chip_info; |
62 | struct regulator *vdd; | ||
52 | }; | 63 | }; |
53 | 64 | ||
54 | int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, | 65 | int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, |
diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c index 992ad8d3b67a..c4e65868bc28 100644 --- a/drivers/iio/pressure/ms5611_core.c +++ b/drivers/iio/pressure/ms5611_core.c | |||
@@ -18,11 +18,44 @@ | |||
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/regulator/consumer.h> | 19 | #include <linux/regulator/consumer.h> |
20 | 20 | ||
21 | #include <linux/iio/sysfs.h> | ||
21 | #include <linux/iio/buffer.h> | 22 | #include <linux/iio/buffer.h> |
22 | #include <linux/iio/triggered_buffer.h> | 23 | #include <linux/iio/triggered_buffer.h> |
23 | #include <linux/iio/trigger_consumer.h> | 24 | #include <linux/iio/trigger_consumer.h> |
24 | #include "ms5611.h" | 25 | #include "ms5611.h" |
25 | 26 | ||
27 | #define MS5611_INIT_OSR(_cmd, _conv_usec, _rate) \ | ||
28 | { .cmd = _cmd, .conv_usec = _conv_usec, .rate = _rate } | ||
29 | |||
30 | static const struct ms5611_osr ms5611_avail_pressure_osr[] = { | ||
31 | MS5611_INIT_OSR(0x40, 600, 256), | ||
32 | MS5611_INIT_OSR(0x42, 1170, 512), | ||
33 | MS5611_INIT_OSR(0x44, 2280, 1024), | ||
34 | MS5611_INIT_OSR(0x46, 4540, 2048), | ||
35 | MS5611_INIT_OSR(0x48, 9040, 4096) | ||
36 | }; | ||
37 | |||
38 | static const struct ms5611_osr ms5611_avail_temp_osr[] = { | ||
39 | MS5611_INIT_OSR(0x50, 600, 256), | ||
40 | MS5611_INIT_OSR(0x52, 1170, 512), | ||
41 | MS5611_INIT_OSR(0x54, 2280, 1024), | ||
42 | MS5611_INIT_OSR(0x56, 4540, 2048), | ||
43 | MS5611_INIT_OSR(0x58, 9040, 4096) | ||
44 | }; | ||
45 | |||
46 | static const char ms5611_show_osr[] = "256 512 1024 2048 4096"; | ||
47 | |||
48 | static IIO_CONST_ATTR(oversampling_ratio_available, ms5611_show_osr); | ||
49 | |||
50 | static struct attribute *ms5611_attributes[] = { | ||
51 | &iio_const_attr_oversampling_ratio_available.dev_attr.attr, | ||
52 | NULL, | ||
53 | }; | ||
54 | |||
55 | static const struct attribute_group ms5611_attribute_group = { | ||
56 | .attrs = ms5611_attributes, | ||
57 | }; | ||
58 | |||
26 | static bool ms5611_prom_is_valid(u16 *prom, size_t len) | 59 | static bool ms5611_prom_is_valid(u16 *prom, size_t len) |
27 | { | 60 | { |
28 | int i, j; | 61 | int i, j; |
@@ -239,11 +272,70 @@ static int ms5611_read_raw(struct iio_dev *indio_dev, | |||
239 | default: | 272 | default: |
240 | return -EINVAL; | 273 | return -EINVAL; |
241 | } | 274 | } |
275 | case IIO_CHAN_INFO_OVERSAMPLING_RATIO: | ||
276 | if (chan->type != IIO_TEMP && chan->type != IIO_PRESSURE) | ||
277 | break; | ||
278 | mutex_lock(&st->lock); | ||
279 | if (chan->type == IIO_TEMP) | ||
280 | *val = (int)st->temp_osr->rate; | ||
281 | else | ||
282 | *val = (int)st->pressure_osr->rate; | ||
283 | mutex_unlock(&st->lock); | ||
284 | return IIO_VAL_INT; | ||
242 | } | 285 | } |
243 | 286 | ||
244 | return -EINVAL; | 287 | return -EINVAL; |
245 | } | 288 | } |
246 | 289 | ||
290 | static const struct ms5611_osr *ms5611_find_osr(int rate, | ||
291 | const struct ms5611_osr *osr, | ||
292 | size_t count) | ||
293 | { | ||
294 | unsigned int r; | ||
295 | |||
296 | for (r = 0; r < count; r++) | ||
297 | if ((unsigned short)rate == osr[r].rate) | ||
298 | break; | ||
299 | if (r >= count) | ||
300 | return NULL; | ||
301 | return &osr[r]; | ||
302 | } | ||
303 | |||
304 | static int ms5611_write_raw(struct iio_dev *indio_dev, | ||
305 | struct iio_chan_spec const *chan, | ||
306 | int val, int val2, long mask) | ||
307 | { | ||
308 | struct ms5611_state *st = iio_priv(indio_dev); | ||
309 | const struct ms5611_osr *osr = NULL; | ||
310 | |||
311 | if (mask != IIO_CHAN_INFO_OVERSAMPLING_RATIO) | ||
312 | return -EINVAL; | ||
313 | |||
314 | if (chan->type == IIO_TEMP) | ||
315 | osr = ms5611_find_osr(val, ms5611_avail_temp_osr, | ||
316 | ARRAY_SIZE(ms5611_avail_temp_osr)); | ||
317 | else if (chan->type == IIO_PRESSURE) | ||
318 | osr = ms5611_find_osr(val, ms5611_avail_pressure_osr, | ||
319 | ARRAY_SIZE(ms5611_avail_pressure_osr)); | ||
320 | if (!osr) | ||
321 | return -EINVAL; | ||
322 | |||
323 | mutex_lock(&st->lock); | ||
324 | |||
325 | if (iio_buffer_enabled(indio_dev)) { | ||
326 | mutex_unlock(&st->lock); | ||
327 | return -EBUSY; | ||
328 | } | ||
329 | |||
330 | if (chan->type == IIO_TEMP) | ||
331 | st->temp_osr = osr; | ||
332 | else | ||
333 | st->pressure_osr = osr; | ||
334 | |||
335 | mutex_unlock(&st->lock); | ||
336 | return 0; | ||
337 | } | ||
338 | |||
247 | static const unsigned long ms5611_scan_masks[] = {0x3, 0}; | 339 | static const unsigned long ms5611_scan_masks[] = {0x3, 0}; |
248 | 340 | ||
249 | static struct ms5611_chip_info chip_info_tbl[] = { | 341 | static struct ms5611_chip_info chip_info_tbl[] = { |
@@ -259,7 +351,8 @@ static const struct iio_chan_spec ms5611_channels[] = { | |||
259 | { | 351 | { |
260 | .type = IIO_PRESSURE, | 352 | .type = IIO_PRESSURE, |
261 | .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | | 353 | .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | |
262 | BIT(IIO_CHAN_INFO_SCALE), | 354 | BIT(IIO_CHAN_INFO_SCALE) | |
355 | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), | ||
263 | .scan_index = 0, | 356 | .scan_index = 0, |
264 | .scan_type = { | 357 | .scan_type = { |
265 | .sign = 's', | 358 | .sign = 's', |
@@ -271,7 +364,8 @@ static const struct iio_chan_spec ms5611_channels[] = { | |||
271 | { | 364 | { |
272 | .type = IIO_TEMP, | 365 | .type = IIO_TEMP, |
273 | .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | | 366 | .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | |
274 | BIT(IIO_CHAN_INFO_SCALE), | 367 | BIT(IIO_CHAN_INFO_SCALE) | |
368 | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), | ||
275 | .scan_index = 1, | 369 | .scan_index = 1, |
276 | .scan_type = { | 370 | .scan_type = { |
277 | .sign = 's', | 371 | .sign = 's', |
@@ -285,30 +379,53 @@ static const struct iio_chan_spec ms5611_channels[] = { | |||
285 | 379 | ||
286 | static const struct iio_info ms5611_info = { | 380 | static const struct iio_info ms5611_info = { |
287 | .read_raw = &ms5611_read_raw, | 381 | .read_raw = &ms5611_read_raw, |
382 | .write_raw = &ms5611_write_raw, | ||
383 | .attrs = &ms5611_attribute_group, | ||
288 | .driver_module = THIS_MODULE, | 384 | .driver_module = THIS_MODULE, |
289 | }; | 385 | }; |
290 | 386 | ||
291 | static int ms5611_init(struct iio_dev *indio_dev) | 387 | static int ms5611_init(struct iio_dev *indio_dev) |
292 | { | 388 | { |
293 | int ret; | 389 | int ret; |
294 | struct regulator *vdd = devm_regulator_get(indio_dev->dev.parent, | 390 | struct ms5611_state *st = iio_priv(indio_dev); |
295 | "vdd"); | ||
296 | 391 | ||
297 | /* Enable attached regulator if any. */ | 392 | /* Enable attached regulator if any. */ |
298 | if (!IS_ERR(vdd)) { | 393 | st->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd"); |
299 | ret = regulator_enable(vdd); | 394 | if (!IS_ERR(st->vdd)) { |
395 | ret = regulator_enable(st->vdd); | ||
300 | if (ret) { | 396 | if (ret) { |
301 | dev_err(indio_dev->dev.parent, | 397 | dev_err(indio_dev->dev.parent, |
302 | "failed to enable Vdd supply: %d\n", ret); | 398 | "failed to enable Vdd supply: %d\n", ret); |
303 | return ret; | 399 | return ret; |
304 | } | 400 | } |
401 | } else { | ||
402 | ret = PTR_ERR(st->vdd); | ||
403 | if (ret != -ENODEV) | ||
404 | return ret; | ||
305 | } | 405 | } |
306 | 406 | ||
307 | ret = ms5611_reset(indio_dev); | 407 | ret = ms5611_reset(indio_dev); |
308 | if (ret < 0) | 408 | if (ret < 0) |
309 | return ret; | 409 | goto err_regulator_disable; |
310 | 410 | ||
311 | return ms5611_read_prom(indio_dev); | 411 | ret = ms5611_read_prom(indio_dev); |
412 | if (ret < 0) | ||
413 | goto err_regulator_disable; | ||
414 | |||
415 | return 0; | ||
416 | |||
417 | err_regulator_disable: | ||
418 | if (!IS_ERR_OR_NULL(st->vdd)) | ||
419 | regulator_disable(st->vdd); | ||
420 | return ret; | ||
421 | } | ||
422 | |||
423 | static void ms5611_fini(const struct iio_dev *indio_dev) | ||
424 | { | ||
425 | const struct ms5611_state *st = iio_priv(indio_dev); | ||
426 | |||
427 | if (!IS_ERR_OR_NULL(st->vdd)) | ||
428 | regulator_disable(st->vdd); | ||
312 | } | 429 | } |
313 | 430 | ||
314 | int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, | 431 | int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, |
@@ -319,6 +436,11 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, | |||
319 | 436 | ||
320 | mutex_init(&st->lock); | 437 | mutex_init(&st->lock); |
321 | st->chip_info = &chip_info_tbl[type]; | 438 | st->chip_info = &chip_info_tbl[type]; |
439 | st->temp_osr = | ||
440 | &ms5611_avail_temp_osr[ARRAY_SIZE(ms5611_avail_temp_osr) - 1]; | ||
441 | st->pressure_osr = | ||
442 | &ms5611_avail_pressure_osr[ARRAY_SIZE(ms5611_avail_pressure_osr) | ||
443 | - 1]; | ||
322 | indio_dev->dev.parent = dev; | 444 | indio_dev->dev.parent = dev; |
323 | indio_dev->name = name; | 445 | indio_dev->name = name; |
324 | indio_dev->info = &ms5611_info; | 446 | indio_dev->info = &ms5611_info; |
@@ -335,7 +457,7 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, | |||
335 | ms5611_trigger_handler, NULL); | 457 | ms5611_trigger_handler, NULL); |
336 | if (ret < 0) { | 458 | if (ret < 0) { |
337 | dev_err(dev, "iio triggered buffer setup failed\n"); | 459 | dev_err(dev, "iio triggered buffer setup failed\n"); |
338 | return ret; | 460 | goto err_fini; |
339 | } | 461 | } |
340 | 462 | ||
341 | ret = iio_device_register(indio_dev); | 463 | ret = iio_device_register(indio_dev); |
@@ -348,7 +470,8 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, | |||
348 | 470 | ||
349 | err_buffer_cleanup: | 471 | err_buffer_cleanup: |
350 | iio_triggered_buffer_cleanup(indio_dev); | 472 | iio_triggered_buffer_cleanup(indio_dev); |
351 | 473 | err_fini: | |
474 | ms5611_fini(indio_dev); | ||
352 | return ret; | 475 | return ret; |
353 | } | 476 | } |
354 | EXPORT_SYMBOL(ms5611_probe); | 477 | EXPORT_SYMBOL(ms5611_probe); |
@@ -357,6 +480,7 @@ int ms5611_remove(struct iio_dev *indio_dev) | |||
357 | { | 480 | { |
358 | iio_device_unregister(indio_dev); | 481 | iio_device_unregister(indio_dev); |
359 | iio_triggered_buffer_cleanup(indio_dev); | 482 | iio_triggered_buffer_cleanup(indio_dev); |
483 | ms5611_fini(indio_dev); | ||
360 | 484 | ||
361 | return 0; | 485 | return 0; |
362 | } | 486 | } |
diff --git a/drivers/iio/pressure/ms5611_i2c.c b/drivers/iio/pressure/ms5611_i2c.c index 7f6fc8eee922..55fb5fc0b6ea 100644 --- a/drivers/iio/pressure/ms5611_i2c.c +++ b/drivers/iio/pressure/ms5611_i2c.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
18 | #include <linux/i2c.h> | 18 | #include <linux/i2c.h> |
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/of_device.h> | ||
20 | 21 | ||
21 | #include "ms5611.h" | 22 | #include "ms5611.h" |
22 | 23 | ||
@@ -62,23 +63,23 @@ static int ms5611_i2c_read_adc_temp_and_pressure(struct device *dev, | |||
62 | { | 63 | { |
63 | int ret; | 64 | int ret; |
64 | struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); | 65 | struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); |
66 | const struct ms5611_osr *osr = st->temp_osr; | ||
65 | 67 | ||
66 | ret = i2c_smbus_write_byte(st->client, MS5611_START_TEMP_CONV); | 68 | ret = i2c_smbus_write_byte(st->client, osr->cmd); |
67 | if (ret < 0) | 69 | if (ret < 0) |
68 | return ret; | 70 | return ret; |
69 | 71 | ||
70 | usleep_range(MS5611_CONV_TIME_MIN, MS5611_CONV_TIME_MAX); | 72 | usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL)); |
71 | |||
72 | ret = ms5611_i2c_read_adc(st, temp); | 73 | ret = ms5611_i2c_read_adc(st, temp); |
73 | if (ret < 0) | 74 | if (ret < 0) |
74 | return ret; | 75 | return ret; |
75 | 76 | ||
76 | ret = i2c_smbus_write_byte(st->client, MS5611_START_PRESSURE_CONV); | 77 | osr = st->pressure_osr; |
78 | ret = i2c_smbus_write_byte(st->client, osr->cmd); | ||
77 | if (ret < 0) | 79 | if (ret < 0) |
78 | return ret; | 80 | return ret; |
79 | 81 | ||
80 | usleep_range(MS5611_CONV_TIME_MIN, MS5611_CONV_TIME_MAX); | 82 | usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL)); |
81 | |||
82 | return ms5611_i2c_read_adc(st, pressure); | 83 | return ms5611_i2c_read_adc(st, pressure); |
83 | } | 84 | } |
84 | 85 | ||
@@ -113,6 +114,17 @@ static int ms5611_i2c_remove(struct i2c_client *client) | |||
113 | return ms5611_remove(i2c_get_clientdata(client)); | 114 | return ms5611_remove(i2c_get_clientdata(client)); |
114 | } | 115 | } |
115 | 116 | ||
117 | #if defined(CONFIG_OF) | ||
118 | static const struct of_device_id ms5611_i2c_matches[] = { | ||
119 | { .compatible = "meas,ms5611" }, | ||
120 | { .compatible = "ms5611" }, | ||
121 | { .compatible = "meas,ms5607" }, | ||
122 | { .compatible = "ms5607" }, | ||
123 | { } | ||
124 | }; | ||
125 | MODULE_DEVICE_TABLE(of, ms5611_i2c_matches); | ||
126 | #endif | ||
127 | |||
116 | static const struct i2c_device_id ms5611_id[] = { | 128 | static const struct i2c_device_id ms5611_id[] = { |
117 | { "ms5611", MS5611 }, | 129 | { "ms5611", MS5611 }, |
118 | { "ms5607", MS5607 }, | 130 | { "ms5607", MS5607 }, |
@@ -123,6 +135,7 @@ MODULE_DEVICE_TABLE(i2c, ms5611_id); | |||
123 | static struct i2c_driver ms5611_driver = { | 135 | static struct i2c_driver ms5611_driver = { |
124 | .driver = { | 136 | .driver = { |
125 | .name = "ms5611", | 137 | .name = "ms5611", |
138 | .of_match_table = of_match_ptr(ms5611_i2c_matches) | ||
126 | }, | 139 | }, |
127 | .id_table = ms5611_id, | 140 | .id_table = ms5611_id, |
128 | .probe = ms5611_i2c_probe, | 141 | .probe = ms5611_i2c_probe, |
diff --git a/drivers/iio/pressure/ms5611_spi.c b/drivers/iio/pressure/ms5611_spi.c index 5cc009e85f0e..7600483e8cb4 100644 --- a/drivers/iio/pressure/ms5611_spi.c +++ b/drivers/iio/pressure/ms5611_spi.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/delay.h> | 12 | #include <linux/delay.h> |
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/spi/spi.h> | 14 | #include <linux/spi/spi.h> |
15 | #include <linux/of_device.h> | ||
15 | 16 | ||
16 | #include "ms5611.h" | 17 | #include "ms5611.h" |
17 | 18 | ||
@@ -55,28 +56,29 @@ static int ms5611_spi_read_adc(struct device *dev, s32 *val) | |||
55 | static int ms5611_spi_read_adc_temp_and_pressure(struct device *dev, | 56 | static int ms5611_spi_read_adc_temp_and_pressure(struct device *dev, |
56 | s32 *temp, s32 *pressure) | 57 | s32 *temp, s32 *pressure) |
57 | { | 58 | { |
58 | u8 cmd; | ||
59 | int ret; | 59 | int ret; |
60 | struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); | 60 | struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); |
61 | const struct ms5611_osr *osr = st->temp_osr; | ||
61 | 62 | ||
62 | cmd = MS5611_START_TEMP_CONV; | 63 | /* |
63 | ret = spi_write_then_read(st->client, &cmd, 1, NULL, 0); | 64 | * Warning: &osr->cmd MUST be aligned on a word boundary since used as |
65 | * 2nd argument (void*) of spi_write_then_read. | ||
66 | */ | ||
67 | ret = spi_write_then_read(st->client, &osr->cmd, 1, NULL, 0); | ||
64 | if (ret < 0) | 68 | if (ret < 0) |
65 | return ret; | 69 | return ret; |
66 | 70 | ||
67 | usleep_range(MS5611_CONV_TIME_MIN, MS5611_CONV_TIME_MAX); | 71 | usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL)); |
68 | |||
69 | ret = ms5611_spi_read_adc(dev, temp); | 72 | ret = ms5611_spi_read_adc(dev, temp); |
70 | if (ret < 0) | 73 | if (ret < 0) |
71 | return ret; | 74 | return ret; |
72 | 75 | ||
73 | cmd = MS5611_START_PRESSURE_CONV; | 76 | osr = st->pressure_osr; |
74 | ret = spi_write_then_read(st->client, &cmd, 1, NULL, 0); | 77 | ret = spi_write_then_read(st->client, &osr->cmd, 1, NULL, 0); |
75 | if (ret < 0) | 78 | if (ret < 0) |
76 | return ret; | 79 | return ret; |
77 | 80 | ||
78 | usleep_range(MS5611_CONV_TIME_MIN, MS5611_CONV_TIME_MAX); | 81 | usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL)); |
79 | |||
80 | return ms5611_spi_read_adc(dev, pressure); | 82 | return ms5611_spi_read_adc(dev, pressure); |
81 | } | 83 | } |
82 | 84 | ||
@@ -114,6 +116,17 @@ static int ms5611_spi_remove(struct spi_device *spi) | |||
114 | return ms5611_remove(spi_get_drvdata(spi)); | 116 | return ms5611_remove(spi_get_drvdata(spi)); |
115 | } | 117 | } |
116 | 118 | ||
119 | #if defined(CONFIG_OF) | ||
120 | static const struct of_device_id ms5611_spi_matches[] = { | ||
121 | { .compatible = "meas,ms5611" }, | ||
122 | { .compatible = "ms5611" }, | ||
123 | { .compatible = "meas,ms5607" }, | ||
124 | { .compatible = "ms5607" }, | ||
125 | { } | ||
126 | }; | ||
127 | MODULE_DEVICE_TABLE(of, ms5611_spi_matches); | ||
128 | #endif | ||
129 | |||
117 | static const struct spi_device_id ms5611_id[] = { | 130 | static const struct spi_device_id ms5611_id[] = { |
118 | { "ms5611", MS5611 }, | 131 | { "ms5611", MS5611 }, |
119 | { "ms5607", MS5607 }, | 132 | { "ms5607", MS5607 }, |
@@ -124,6 +137,7 @@ MODULE_DEVICE_TABLE(spi, ms5611_id); | |||
124 | static struct spi_driver ms5611_driver = { | 137 | static struct spi_driver ms5611_driver = { |
125 | .driver = { | 138 | .driver = { |
126 | .name = "ms5611", | 139 | .name = "ms5611", |
140 | .of_match_table = of_match_ptr(ms5611_spi_matches) | ||
127 | }, | 141 | }, |
128 | .id_table = ms5611_id, | 142 | .id_table = ms5611_id, |
129 | .probe = ms5611_spi_probe, | 143 | .probe = ms5611_spi_probe, |
diff --git a/drivers/staging/iio/accel/Kconfig b/drivers/staging/iio/accel/Kconfig index fa67da9408b6..f066aa30f0ac 100644 --- a/drivers/staging/iio/accel/Kconfig +++ b/drivers/staging/iio/accel/Kconfig | |||
@@ -27,18 +27,6 @@ config ADIS16203 | |||
27 | To compile this driver as a module, say M here: the module will be | 27 | To compile this driver as a module, say M here: the module will be |
28 | called adis16203. | 28 | called adis16203. |
29 | 29 | ||
30 | config ADIS16204 | ||
31 | tristate "Analog Devices ADIS16204 Programmable High-g Digital Impact Sensor and Recorder" | ||
32 | depends on SPI | ||
33 | select IIO_ADIS_LIB | ||
34 | select IIO_ADIS_LIB_BUFFER if IIO_BUFFER | ||
35 | help | ||
36 | Say Y here to build support for Analog Devices adis16204 Programmable | ||
37 | High-g Digital Impact Sensor and Recorder. | ||
38 | |||
39 | To compile this driver as a module, say M here: the module will be | ||
40 | called adis16204. | ||
41 | |||
42 | config ADIS16209 | 30 | config ADIS16209 |
43 | tristate "Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer" | 31 | tristate "Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer" |
44 | depends on SPI | 32 | depends on SPI |
@@ -51,17 +39,6 @@ config ADIS16209 | |||
51 | To compile this driver as a module, say M here: the module will be | 39 | To compile this driver as a module, say M here: the module will be |
52 | called adis16209. | 40 | called adis16209. |
53 | 41 | ||
54 | config ADIS16220 | ||
55 | tristate "Analog Devices ADIS16220 Programmable Digital Vibration Sensor" | ||
56 | depends on SPI | ||
57 | select IIO_ADIS_LIB | ||
58 | help | ||
59 | Say Y here to build support for Analog Devices adis16220 programmable | ||
60 | digital vibration sensor. | ||
61 | |||
62 | To compile this driver as a module, say M here: the module will be | ||
63 | called adis16220. | ||
64 | |||
65 | config ADIS16240 | 42 | config ADIS16240 |
66 | tristate "Analog Devices ADIS16240 Programmable Impact Sensor and Recorder" | 43 | tristate "Analog Devices ADIS16240 Programmable Impact Sensor and Recorder" |
67 | depends on SPI | 44 | depends on SPI |
diff --git a/drivers/staging/iio/accel/Makefile b/drivers/staging/iio/accel/Makefile index 1ed137f1a506..415329c96f0c 100644 --- a/drivers/staging/iio/accel/Makefile +++ b/drivers/staging/iio/accel/Makefile | |||
@@ -8,15 +8,9 @@ obj-$(CONFIG_ADIS16201) += adis16201.o | |||
8 | adis16203-y := adis16203_core.o | 8 | adis16203-y := adis16203_core.o |
9 | obj-$(CONFIG_ADIS16203) += adis16203.o | 9 | obj-$(CONFIG_ADIS16203) += adis16203.o |
10 | 10 | ||
11 | adis16204-y := adis16204_core.o | ||
12 | obj-$(CONFIG_ADIS16204) += adis16204.o | ||
13 | |||
14 | adis16209-y := adis16209_core.o | 11 | adis16209-y := adis16209_core.o |
15 | obj-$(CONFIG_ADIS16209) += adis16209.o | 12 | obj-$(CONFIG_ADIS16209) += adis16209.o |
16 | 13 | ||
17 | adis16220-y := adis16220_core.o | ||
18 | obj-$(CONFIG_ADIS16220) += adis16220.o | ||
19 | |||
20 | adis16240-y := adis16240_core.o | 14 | adis16240-y := adis16240_core.o |
21 | obj-$(CONFIG_ADIS16240) += adis16240.o | 15 | obj-$(CONFIG_ADIS16240) += adis16240.o |
22 | 16 | ||
diff --git a/drivers/staging/iio/accel/adis16204.h b/drivers/staging/iio/accel/adis16204.h deleted file mode 100644 index cfc4038ffdfb..000000000000 --- a/drivers/staging/iio/accel/adis16204.h +++ /dev/null | |||
@@ -1,145 +0,0 @@ | |||
1 | #ifndef SPI_ADIS16204_H_ | ||
2 | #define SPI_ADIS16204_H_ | ||
3 | |||
4 | #define ADIS16204_STARTUP_DELAY 220 /* ms */ | ||
5 | |||
6 | /* Flash memory write count */ | ||
7 | #define ADIS16204_FLASH_CNT 0x00 | ||
8 | |||
9 | /* Output, power supply */ | ||
10 | #define ADIS16204_SUPPLY_OUT 0x02 | ||
11 | |||
12 | /* Output, x-axis accelerometer */ | ||
13 | #define ADIS16204_XACCL_OUT 0x04 | ||
14 | |||
15 | /* Output, y-axis accelerometer */ | ||
16 | #define ADIS16204_YACCL_OUT 0x06 | ||
17 | |||
18 | /* Output, auxiliary ADC input */ | ||
19 | #define ADIS16204_AUX_ADC 0x08 | ||
20 | |||
21 | /* Output, temperature */ | ||
22 | #define ADIS16204_TEMP_OUT 0x0A | ||
23 | |||
24 | /* Twos complement */ | ||
25 | #define ADIS16204_X_PEAK_OUT 0x0C | ||
26 | #define ADIS16204_Y_PEAK_OUT 0x0E | ||
27 | |||
28 | /* Calibration, x-axis acceleration offset null */ | ||
29 | #define ADIS16204_XACCL_NULL 0x10 | ||
30 | |||
31 | /* Calibration, y-axis acceleration offset null */ | ||
32 | #define ADIS16204_YACCL_NULL 0x12 | ||
33 | |||
34 | /* X-axis scale factor calibration register */ | ||
35 | #define ADIS16204_XACCL_SCALE 0x14 | ||
36 | |||
37 | /* Y-axis scale factor calibration register */ | ||
38 | #define ADIS16204_YACCL_SCALE 0x16 | ||
39 | |||
40 | /* XY combined acceleration (RSS) */ | ||
41 | #define ADIS16204_XY_RSS_OUT 0x18 | ||
42 | |||
43 | /* Peak, XY combined output (RSS) */ | ||
44 | #define ADIS16204_XY_PEAK_OUT 0x1A | ||
45 | |||
46 | /* Capture buffer output register 1 */ | ||
47 | #define ADIS16204_CAP_BUF_1 0x1C | ||
48 | |||
49 | /* Capture buffer output register 2 */ | ||
50 | #define ADIS16204_CAP_BUF_2 0x1E | ||
51 | |||
52 | /* Alarm 1 amplitude threshold */ | ||
53 | #define ADIS16204_ALM_MAG1 0x20 | ||
54 | |||
55 | /* Alarm 2 amplitude threshold */ | ||
56 | #define ADIS16204_ALM_MAG2 0x22 | ||
57 | |||
58 | /* Alarm control */ | ||
59 | #define ADIS16204_ALM_CTRL 0x28 | ||
60 | |||
61 | /* Capture register address pointer */ | ||
62 | #define ADIS16204_CAPT_PNTR 0x2A | ||
63 | |||
64 | /* Auxiliary DAC data */ | ||
65 | #define ADIS16204_AUX_DAC 0x30 | ||
66 | |||
67 | /* General-purpose digital input/output control */ | ||
68 | #define ADIS16204_GPIO_CTRL 0x32 | ||
69 | |||
70 | /* Miscellaneous control */ | ||
71 | #define ADIS16204_MSC_CTRL 0x34 | ||
72 | |||
73 | /* Internal sample period (rate) control */ | ||
74 | #define ADIS16204_SMPL_PRD 0x36 | ||
75 | |||
76 | /* Operation, filter configuration */ | ||
77 | #define ADIS16204_AVG_CNT 0x38 | ||
78 | |||
79 | /* Operation, sleep mode control */ | ||
80 | #define ADIS16204_SLP_CNT 0x3A | ||
81 | |||
82 | /* Diagnostics, system status register */ | ||
83 | #define ADIS16204_DIAG_STAT 0x3C | ||
84 | |||
85 | /* Operation, system command register */ | ||
86 | #define ADIS16204_GLOB_CMD 0x3E | ||
87 | |||
88 | /* MSC_CTRL */ | ||
89 | |||
90 | /* Self-test at power-on: 1 = disabled, 0 = enabled */ | ||
91 | #define ADIS16204_MSC_CTRL_PWRUP_SELF_TEST BIT(10) | ||
92 | |||
93 | /* Self-test enable */ | ||
94 | #define ADIS16204_MSC_CTRL_SELF_TEST_EN BIT(8) | ||
95 | |||
96 | /* Data-ready enable: 1 = enabled, 0 = disabled */ | ||
97 | #define ADIS16204_MSC_CTRL_DATA_RDY_EN BIT(2) | ||
98 | |||
99 | /* Data-ready polarity: 1 = active high, 0 = active low */ | ||
100 | #define ADIS16204_MSC_CTRL_ACTIVE_HIGH BIT(1) | ||
101 | |||
102 | /* Data-ready line selection: 1 = DIO2, 0 = DIO1 */ | ||
103 | #define ADIS16204_MSC_CTRL_DATA_RDY_DIO2 BIT(0) | ||
104 | |||
105 | /* DIAG_STAT */ | ||
106 | |||
107 | /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ | ||
108 | #define ADIS16204_DIAG_STAT_ALARM2 BIT(9) | ||
109 | |||
110 | /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ | ||
111 | #define ADIS16204_DIAG_STAT_ALARM1 BIT(8) | ||
112 | |||
113 | /* Self-test diagnostic error flag: 1 = error condition, 0 = normal operation */ | ||
114 | #define ADIS16204_DIAG_STAT_SELFTEST_FAIL_BIT 5 | ||
115 | |||
116 | /* SPI communications failure */ | ||
117 | #define ADIS16204_DIAG_STAT_SPI_FAIL_BIT 3 | ||
118 | |||
119 | /* Flash update failure */ | ||
120 | #define ADIS16204_DIAG_STAT_FLASH_UPT_BIT 2 | ||
121 | |||
122 | /* Power supply above 3.625 V */ | ||
123 | #define ADIS16204_DIAG_STAT_POWER_HIGH_BIT 1 | ||
124 | |||
125 | /* Power supply below 2.975 V */ | ||
126 | #define ADIS16204_DIAG_STAT_POWER_LOW_BIT 0 | ||
127 | |||
128 | /* GLOB_CMD */ | ||
129 | |||
130 | #define ADIS16204_GLOB_CMD_SW_RESET BIT(7) | ||
131 | #define ADIS16204_GLOB_CMD_CLEAR_STAT BIT(4) | ||
132 | #define ADIS16204_GLOB_CMD_FACTORY_CAL BIT(1) | ||
133 | |||
134 | #define ADIS16204_ERROR_ACTIVE BIT(14) | ||
135 | |||
136 | enum adis16204_scan { | ||
137 | ADIS16204_SCAN_ACC_X, | ||
138 | ADIS16204_SCAN_ACC_Y, | ||
139 | ADIS16204_SCAN_ACC_XY, | ||
140 | ADIS16204_SCAN_SUPPLY, | ||
141 | ADIS16204_SCAN_AUX_ADC, | ||
142 | ADIS16204_SCAN_TEMP, | ||
143 | }; | ||
144 | |||
145 | #endif /* SPI_ADIS16204_H_ */ | ||
diff --git a/drivers/staging/iio/accel/adis16204_core.c b/drivers/staging/iio/accel/adis16204_core.c deleted file mode 100644 index 20a9df64f1ed..000000000000 --- a/drivers/staging/iio/accel/adis16204_core.c +++ /dev/null | |||
@@ -1,253 +0,0 @@ | |||
1 | /* | ||
2 | * ADIS16204 Programmable High-g Digital Impact Sensor and Recorder | ||
3 | * | ||
4 | * Copyright 2010 Analog Devices Inc. | ||
5 | * | ||
6 | * Licensed under the GPL-2 or later. | ||
7 | */ | ||
8 | |||
9 | #include <linux/interrupt.h> | ||
10 | #include <linux/irq.h> | ||
11 | #include <linux/delay.h> | ||
12 | #include <linux/mutex.h> | ||
13 | #include <linux/device.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/spi/spi.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/sysfs.h> | ||
18 | #include <linux/list.h> | ||
19 | #include <linux/module.h> | ||
20 | |||
21 | #include <linux/iio/iio.h> | ||
22 | #include <linux/iio/sysfs.h> | ||
23 | #include <linux/iio/buffer.h> | ||
24 | #include <linux/iio/imu/adis.h> | ||
25 | |||
26 | #include "adis16204.h" | ||
27 | |||
28 | /* Unique to this driver currently */ | ||
29 | |||
30 | static const u8 adis16204_addresses[][2] = { | ||
31 | [ADIS16204_SCAN_ACC_X] = { ADIS16204_XACCL_NULL, ADIS16204_X_PEAK_OUT }, | ||
32 | [ADIS16204_SCAN_ACC_Y] = { ADIS16204_YACCL_NULL, ADIS16204_Y_PEAK_OUT }, | ||
33 | [ADIS16204_SCAN_ACC_XY] = { 0, ADIS16204_XY_PEAK_OUT }, | ||
34 | }; | ||
35 | |||
36 | static int adis16204_read_raw(struct iio_dev *indio_dev, | ||
37 | struct iio_chan_spec const *chan, | ||
38 | int *val, int *val2, | ||
39 | long mask) | ||
40 | { | ||
41 | struct adis *st = iio_priv(indio_dev); | ||
42 | int ret; | ||
43 | int bits; | ||
44 | u8 addr; | ||
45 | s16 val16; | ||
46 | int addrind; | ||
47 | |||
48 | switch (mask) { | ||
49 | case IIO_CHAN_INFO_RAW: | ||
50 | return adis_single_conversion(indio_dev, chan, | ||
51 | ADIS16204_ERROR_ACTIVE, val); | ||
52 | case IIO_CHAN_INFO_SCALE: | ||
53 | switch (chan->type) { | ||
54 | case IIO_VOLTAGE: | ||
55 | if (chan->channel == 0) { | ||
56 | *val = 1; | ||
57 | *val2 = 220000; /* 1.22 mV */ | ||
58 | } else { | ||
59 | *val = 0; | ||
60 | *val2 = 610000; /* 0.61 mV */ | ||
61 | } | ||
62 | return IIO_VAL_INT_PLUS_MICRO; | ||
63 | case IIO_TEMP: | ||
64 | *val = -470; /* 0.47 C */ | ||
65 | *val2 = 0; | ||
66 | return IIO_VAL_INT_PLUS_MICRO; | ||
67 | case IIO_ACCEL: | ||
68 | *val = 0; | ||
69 | switch (chan->channel2) { | ||
70 | case IIO_MOD_X: | ||
71 | case IIO_MOD_ROOT_SUM_SQUARED_X_Y: | ||
72 | *val2 = IIO_G_TO_M_S_2(17125); /* 17.125 mg */ | ||
73 | break; | ||
74 | case IIO_MOD_Y: | ||
75 | case IIO_MOD_Z: | ||
76 | *val2 = IIO_G_TO_M_S_2(8407); /* 8.407 mg */ | ||
77 | break; | ||
78 | } | ||
79 | return IIO_VAL_INT_PLUS_MICRO; | ||
80 | default: | ||
81 | return -EINVAL; | ||
82 | } | ||
83 | break; | ||
84 | case IIO_CHAN_INFO_OFFSET: | ||
85 | *val = 25000 / -470 - 1278; /* 25 C = 1278 */ | ||
86 | return IIO_VAL_INT; | ||
87 | case IIO_CHAN_INFO_CALIBBIAS: | ||
88 | case IIO_CHAN_INFO_PEAK: | ||
89 | if (mask == IIO_CHAN_INFO_CALIBBIAS) { | ||
90 | bits = 12; | ||
91 | addrind = 0; | ||
92 | } else { /* PEAK_SEPARATE */ | ||
93 | bits = 14; | ||
94 | addrind = 1; | ||
95 | } | ||
96 | mutex_lock(&indio_dev->mlock); | ||
97 | addr = adis16204_addresses[chan->scan_index][addrind]; | ||
98 | ret = adis_read_reg_16(st, addr, &val16); | ||
99 | if (ret) { | ||
100 | mutex_unlock(&indio_dev->mlock); | ||
101 | return ret; | ||
102 | } | ||
103 | val16 &= (1 << bits) - 1; | ||
104 | val16 = (s16)(val16 << (16 - bits)) >> (16 - bits); | ||
105 | *val = val16; | ||
106 | mutex_unlock(&indio_dev->mlock); | ||
107 | return IIO_VAL_INT; | ||
108 | } | ||
109 | return -EINVAL; | ||
110 | } | ||
111 | |||
112 | static int adis16204_write_raw(struct iio_dev *indio_dev, | ||
113 | struct iio_chan_spec const *chan, | ||
114 | int val, | ||
115 | int val2, | ||
116 | long mask) | ||
117 | { | ||
118 | struct adis *st = iio_priv(indio_dev); | ||
119 | int bits; | ||
120 | s16 val16; | ||
121 | u8 addr; | ||
122 | |||
123 | switch (mask) { | ||
124 | case IIO_CHAN_INFO_CALIBBIAS: | ||
125 | switch (chan->type) { | ||
126 | case IIO_ACCEL: | ||
127 | bits = 12; | ||
128 | break; | ||
129 | default: | ||
130 | return -EINVAL; | ||
131 | } | ||
132 | val16 = val & ((1 << bits) - 1); | ||
133 | addr = adis16204_addresses[chan->scan_index][1]; | ||
134 | return adis_write_reg_16(st, addr, val16); | ||
135 | } | ||
136 | return -EINVAL; | ||
137 | } | ||
138 | |||
139 | static const struct iio_chan_spec adis16204_channels[] = { | ||
140 | ADIS_SUPPLY_CHAN(ADIS16204_SUPPLY_OUT, ADIS16204_SCAN_SUPPLY, 0, 12), | ||
141 | ADIS_AUX_ADC_CHAN(ADIS16204_AUX_ADC, ADIS16204_SCAN_AUX_ADC, 0, 12), | ||
142 | ADIS_TEMP_CHAN(ADIS16204_TEMP_OUT, ADIS16204_SCAN_TEMP, 0, 12), | ||
143 | ADIS_ACCEL_CHAN(X, ADIS16204_XACCL_OUT, ADIS16204_SCAN_ACC_X, | ||
144 | BIT(IIO_CHAN_INFO_CALIBBIAS) | BIT(IIO_CHAN_INFO_PEAK), | ||
145 | 0, 14), | ||
146 | ADIS_ACCEL_CHAN(Y, ADIS16204_YACCL_OUT, ADIS16204_SCAN_ACC_Y, | ||
147 | BIT(IIO_CHAN_INFO_CALIBBIAS) | BIT(IIO_CHAN_INFO_PEAK), | ||
148 | 0, 14), | ||
149 | ADIS_ACCEL_CHAN(ROOT_SUM_SQUARED_X_Y, ADIS16204_XY_RSS_OUT, | ||
150 | ADIS16204_SCAN_ACC_XY, BIT(IIO_CHAN_INFO_PEAK), 0, 14), | ||
151 | IIO_CHAN_SOFT_TIMESTAMP(5), | ||
152 | }; | ||
153 | |||
154 | static const struct iio_info adis16204_info = { | ||
155 | .read_raw = &adis16204_read_raw, | ||
156 | .write_raw = &adis16204_write_raw, | ||
157 | .update_scan_mode = adis_update_scan_mode, | ||
158 | .driver_module = THIS_MODULE, | ||
159 | }; | ||
160 | |||
161 | static const char * const adis16204_status_error_msgs[] = { | ||
162 | [ADIS16204_DIAG_STAT_SELFTEST_FAIL_BIT] = "Self test failure", | ||
163 | [ADIS16204_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure", | ||
164 | [ADIS16204_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed", | ||
165 | [ADIS16204_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", | ||
166 | [ADIS16204_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 2.975V", | ||
167 | }; | ||
168 | |||
169 | static const struct adis_data adis16204_data = { | ||
170 | .read_delay = 20, | ||
171 | .msc_ctrl_reg = ADIS16204_MSC_CTRL, | ||
172 | .glob_cmd_reg = ADIS16204_GLOB_CMD, | ||
173 | .diag_stat_reg = ADIS16204_DIAG_STAT, | ||
174 | |||
175 | .self_test_mask = ADIS16204_MSC_CTRL_SELF_TEST_EN, | ||
176 | .startup_delay = ADIS16204_STARTUP_DELAY, | ||
177 | |||
178 | .status_error_msgs = adis16204_status_error_msgs, | ||
179 | .status_error_mask = BIT(ADIS16204_DIAG_STAT_SELFTEST_FAIL_BIT) | | ||
180 | BIT(ADIS16204_DIAG_STAT_SPI_FAIL_BIT) | | ||
181 | BIT(ADIS16204_DIAG_STAT_FLASH_UPT_BIT) | | ||
182 | BIT(ADIS16204_DIAG_STAT_POWER_HIGH_BIT) | | ||
183 | BIT(ADIS16204_DIAG_STAT_POWER_LOW_BIT), | ||
184 | }; | ||
185 | |||
186 | static int adis16204_probe(struct spi_device *spi) | ||
187 | { | ||
188 | int ret; | ||
189 | struct adis *st; | ||
190 | struct iio_dev *indio_dev; | ||
191 | |||
192 | /* setup the industrialio driver allocated elements */ | ||
193 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); | ||
194 | if (!indio_dev) | ||
195 | return -ENOMEM; | ||
196 | st = iio_priv(indio_dev); | ||
197 | /* this is only used for removal purposes */ | ||
198 | spi_set_drvdata(spi, indio_dev); | ||
199 | |||
200 | indio_dev->name = spi->dev.driver->name; | ||
201 | indio_dev->dev.parent = &spi->dev; | ||
202 | indio_dev->info = &adis16204_info; | ||
203 | indio_dev->channels = adis16204_channels; | ||
204 | indio_dev->num_channels = ARRAY_SIZE(adis16204_channels); | ||
205 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
206 | |||
207 | ret = adis_init(st, indio_dev, spi, &adis16204_data); | ||
208 | if (ret) | ||
209 | return ret; | ||
210 | |||
211 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); | ||
212 | if (ret) | ||
213 | return ret; | ||
214 | |||
215 | /* Get the device into a sane initial state */ | ||
216 | ret = adis_initial_startup(st); | ||
217 | if (ret) | ||
218 | goto error_cleanup_buffer_trigger; | ||
219 | ret = iio_device_register(indio_dev); | ||
220 | if (ret) | ||
221 | goto error_cleanup_buffer_trigger; | ||
222 | |||
223 | return 0; | ||
224 | |||
225 | error_cleanup_buffer_trigger: | ||
226 | adis_cleanup_buffer_and_trigger(st, indio_dev); | ||
227 | return ret; | ||
228 | } | ||
229 | |||
230 | static int adis16204_remove(struct spi_device *spi) | ||
231 | { | ||
232 | struct iio_dev *indio_dev = spi_get_drvdata(spi); | ||
233 | struct adis *st = iio_priv(indio_dev); | ||
234 | |||
235 | iio_device_unregister(indio_dev); | ||
236 | adis_cleanup_buffer_and_trigger(st, indio_dev); | ||
237 | |||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | static struct spi_driver adis16204_driver = { | ||
242 | .driver = { | ||
243 | .name = "adis16204", | ||
244 | }, | ||
245 | .probe = adis16204_probe, | ||
246 | .remove = adis16204_remove, | ||
247 | }; | ||
248 | module_spi_driver(adis16204_driver); | ||
249 | |||
250 | MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); | ||
251 | MODULE_DESCRIPTION("ADIS16204 High-g Digital Impact Sensor and Recorder"); | ||
252 | MODULE_LICENSE("GPL v2"); | ||
253 | MODULE_ALIAS("spi:adis16204"); | ||
diff --git a/drivers/staging/iio/accel/adis16220.h b/drivers/staging/iio/accel/adis16220.h deleted file mode 100644 index 31a1268bbfad..000000000000 --- a/drivers/staging/iio/accel/adis16220.h +++ /dev/null | |||
@@ -1,188 +0,0 @@ | |||
1 | #ifndef SPI_ADIS16220_H_ | ||
2 | #define SPI_ADIS16220_H_ | ||
3 | |||
4 | #include <linux/iio/imu/adis.h> | ||
5 | |||
6 | #define ADIS16220_STARTUP_DELAY 220 /* ms */ | ||
7 | |||
8 | /* Flash memory write count */ | ||
9 | #define ADIS16220_FLASH_CNT 0x00 | ||
10 | |||
11 | /* Control, acceleration offset adjustment control */ | ||
12 | #define ADIS16220_ACCL_NULL 0x02 | ||
13 | |||
14 | /* Control, AIN1 offset adjustment control */ | ||
15 | #define ADIS16220_AIN1_NULL 0x04 | ||
16 | |||
17 | /* Control, AIN2 offset adjustment control */ | ||
18 | #define ADIS16220_AIN2_NULL 0x06 | ||
19 | |||
20 | /* Output, power supply during capture */ | ||
21 | #define ADIS16220_CAPT_SUPPLY 0x0A | ||
22 | |||
23 | /* Output, temperature during capture */ | ||
24 | #define ADIS16220_CAPT_TEMP 0x0C | ||
25 | |||
26 | /* Output, peak acceleration during capture */ | ||
27 | #define ADIS16220_CAPT_PEAKA 0x0E | ||
28 | |||
29 | /* Output, peak AIN1 level during capture */ | ||
30 | #define ADIS16220_CAPT_PEAK1 0x10 | ||
31 | |||
32 | /* Output, peak AIN2 level during capture */ | ||
33 | #define ADIS16220_CAPT_PEAK2 0x12 | ||
34 | |||
35 | /* Output, capture buffer for acceleration */ | ||
36 | #define ADIS16220_CAPT_BUFA 0x14 | ||
37 | |||
38 | /* Output, capture buffer for AIN1 */ | ||
39 | #define ADIS16220_CAPT_BUF1 0x16 | ||
40 | |||
41 | /* Output, capture buffer for AIN2 */ | ||
42 | #define ADIS16220_CAPT_BUF2 0x18 | ||
43 | |||
44 | /* Control, capture buffer address pointer */ | ||
45 | #define ADIS16220_CAPT_PNTR 0x1A | ||
46 | |||
47 | /* Control, capture control register */ | ||
48 | #define ADIS16220_CAPT_CTRL 0x1C | ||
49 | |||
50 | /* Control, capture period (automatic mode) */ | ||
51 | #define ADIS16220_CAPT_PRD 0x1E | ||
52 | |||
53 | /* Control, Alarm A, acceleration peak threshold */ | ||
54 | #define ADIS16220_ALM_MAGA 0x20 | ||
55 | |||
56 | /* Control, Alarm 1, AIN1 peak threshold */ | ||
57 | #define ADIS16220_ALM_MAG1 0x22 | ||
58 | |||
59 | /* Control, Alarm 2, AIN2 peak threshold */ | ||
60 | #define ADIS16220_ALM_MAG2 0x24 | ||
61 | |||
62 | /* Control, Alarm S, peak threshold */ | ||
63 | #define ADIS16220_ALM_MAGS 0x26 | ||
64 | |||
65 | /* Control, alarm configuration register */ | ||
66 | #define ADIS16220_ALM_CTRL 0x28 | ||
67 | |||
68 | /* Control, general I/O configuration */ | ||
69 | #define ADIS16220_GPIO_CTRL 0x32 | ||
70 | |||
71 | /* Control, self-test control, AIN configuration */ | ||
72 | #define ADIS16220_MSC_CTRL 0x34 | ||
73 | |||
74 | /* Control, digital I/O configuration */ | ||
75 | #define ADIS16220_DIO_CTRL 0x36 | ||
76 | |||
77 | /* Control, filter configuration */ | ||
78 | #define ADIS16220_AVG_CNT 0x38 | ||
79 | |||
80 | /* Status, system status */ | ||
81 | #define ADIS16220_DIAG_STAT 0x3C | ||
82 | |||
83 | /* Control, system commands */ | ||
84 | #define ADIS16220_GLOB_CMD 0x3E | ||
85 | |||
86 | /* Status, self-test response */ | ||
87 | #define ADIS16220_ST_DELTA 0x40 | ||
88 | |||
89 | /* Lot Identification Code 1 */ | ||
90 | #define ADIS16220_LOT_ID1 0x52 | ||
91 | |||
92 | /* Lot Identification Code 2 */ | ||
93 | #define ADIS16220_LOT_ID2 0x54 | ||
94 | |||
95 | /* Product identifier; convert to decimal = 16220 */ | ||
96 | #define ADIS16220_PROD_ID 0x56 | ||
97 | |||
98 | /* Serial number */ | ||
99 | #define ADIS16220_SERIAL_NUM 0x58 | ||
100 | |||
101 | #define ADIS16220_CAPTURE_SIZE 2048 | ||
102 | |||
103 | /* MSC_CTRL */ | ||
104 | |||
105 | #define ADIS16220_MSC_CTRL_SELF_TEST_EN BIT(8) | ||
106 | #define ADIS16220_MSC_CTRL_POWER_SUP_COM_AIN1 BIT(1) | ||
107 | #define ADIS16220_MSC_CTRL_POWER_SUP_COM_AIN2 BIT(0) | ||
108 | |||
109 | /* DIO_CTRL */ | ||
110 | |||
111 | #define ADIS16220_MSC_CTRL_DIO2_BUSY_IND (BIT(5) | BIT(4)) | ||
112 | #define ADIS16220_MSC_CTRL_DIO1_BUSY_IND (BIT(3) | BIT(2)) | ||
113 | #define ADIS16220_MSC_CTRL_DIO2_ACT_HIGH BIT(1) | ||
114 | #define ADIS16220_MSC_CTRL_DIO1_ACT_HIGH BIT(0) | ||
115 | |||
116 | /* DIAG_STAT */ | ||
117 | |||
118 | /* AIN2 sample > ALM_MAG2 */ | ||
119 | #define ADIS16220_DIAG_STAT_ALM_MAG2 BIT(14) | ||
120 | |||
121 | /* AIN1 sample > ALM_MAG1 */ | ||
122 | #define ADIS16220_DIAG_STAT_ALM_MAG1 BIT(13) | ||
123 | |||
124 | /* Acceleration sample > ALM_MAGA */ | ||
125 | #define ADIS16220_DIAG_STAT_ALM_MAGA BIT(12) | ||
126 | |||
127 | /* Error condition programmed into ALM_MAGS[11:0] and ALM_CTRL[5:4] is true */ | ||
128 | #define ADIS16220_DIAG_STAT_ALM_MAGS BIT(11) | ||
129 | |||
130 | /* |Peak value in AIN2 data capture| > ALM_MAG2 */ | ||
131 | #define ADIS16220_DIAG_STAT_PEAK_AIN2 BIT(10) | ||
132 | |||
133 | /* |Peak value in AIN1 data capture| > ALM_MAG1 */ | ||
134 | #define ADIS16220_DIAG_STAT_PEAK_AIN1 BIT(9) | ||
135 | |||
136 | /* |Peak value in acceleration data capture| > ALM_MAGA */ | ||
137 | #define ADIS16220_DIAG_STAT_PEAK_ACCEL BIT(8) | ||
138 | |||
139 | /* Data ready, capture complete */ | ||
140 | #define ADIS16220_DIAG_STAT_DATA_RDY BIT(7) | ||
141 | |||
142 | #define ADIS16220_DIAG_STAT_FLASH_CHK BIT(6) | ||
143 | |||
144 | #define ADIS16220_DIAG_STAT_SELF_TEST BIT(5) | ||
145 | |||
146 | /* Capture period violation/interruption */ | ||
147 | #define ADIS16220_DIAG_STAT_VIOLATION_BIT 4 | ||
148 | |||
149 | /* SPI communications failure */ | ||
150 | #define ADIS16220_DIAG_STAT_SPI_FAIL_BIT 3 | ||
151 | |||
152 | /* Flash update failure */ | ||
153 | #define ADIS16220_DIAG_STAT_FLASH_UPT_BIT 2 | ||
154 | |||
155 | /* Power supply above 3.625 V */ | ||
156 | #define ADIS16220_DIAG_STAT_POWER_HIGH_BIT 1 | ||
157 | |||
158 | /* Power supply below 3.15 V */ | ||
159 | #define ADIS16220_DIAG_STAT_POWER_LOW_BIT 0 | ||
160 | |||
161 | /* GLOB_CMD */ | ||
162 | |||
163 | #define ADIS16220_GLOB_CMD_SW_RESET BIT(7) | ||
164 | #define ADIS16220_GLOB_CMD_SELF_TEST BIT(2) | ||
165 | #define ADIS16220_GLOB_CMD_PWR_DOWN BIT(1) | ||
166 | |||
167 | #define ADIS16220_MAX_TX 2048 | ||
168 | #define ADIS16220_MAX_RX 2048 | ||
169 | |||
170 | #define ADIS16220_SPI_BURST (u32)(1000 * 1000) | ||
171 | #define ADIS16220_SPI_FAST (u32)(2000 * 1000) | ||
172 | |||
173 | /** | ||
174 | * struct adis16220_state - device instance specific data | ||
175 | * @adis: adis device | ||
176 | * @tx: transmit buffer | ||
177 | * @rx: receive buffer | ||
178 | * @buf_lock: mutex to protect tx and rx | ||
179 | **/ | ||
180 | struct adis16220_state { | ||
181 | struct adis adis; | ||
182 | |||
183 | struct mutex buf_lock; | ||
184 | u8 tx[ADIS16220_MAX_TX] ____cacheline_aligned; | ||
185 | u8 rx[ADIS16220_MAX_RX]; | ||
186 | }; | ||
187 | |||
188 | #endif /* SPI_ADIS16220_H_ */ | ||
diff --git a/drivers/staging/iio/accel/adis16220_core.c b/drivers/staging/iio/accel/adis16220_core.c deleted file mode 100644 index d0165218b60c..000000000000 --- a/drivers/staging/iio/accel/adis16220_core.c +++ /dev/null | |||
@@ -1,494 +0,0 @@ | |||
1 | /* | ||
2 | * ADIS16220 Programmable Digital Vibration Sensor driver | ||
3 | * | ||
4 | * Copyright 2010 Analog Devices Inc. | ||
5 | * | ||
6 | * Licensed under the GPL-2 or later. | ||
7 | */ | ||
8 | |||
9 | #include <linux/delay.h> | ||
10 | #include <linux/mutex.h> | ||
11 | #include <linux/device.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/spi/spi.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/sysfs.h> | ||
16 | #include <linux/module.h> | ||
17 | |||
18 | #include <linux/iio/iio.h> | ||
19 | #include <linux/iio/sysfs.h> | ||
20 | |||
21 | #include "adis16220.h" | ||
22 | |||
23 | static ssize_t adis16220_read_16bit(struct device *dev, | ||
24 | struct device_attribute *attr, | ||
25 | char *buf) | ||
26 | { | ||
27 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); | ||
28 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); | ||
29 | struct adis16220_state *st = iio_priv(indio_dev); | ||
30 | ssize_t ret; | ||
31 | u16 val; | ||
32 | |||
33 | /* Take the iio_dev status lock */ | ||
34 | mutex_lock(&indio_dev->mlock); | ||
35 | ret = adis_read_reg_16(&st->adis, this_attr->address, &val); | ||
36 | mutex_unlock(&indio_dev->mlock); | ||
37 | if (ret) | ||
38 | return ret; | ||
39 | return sprintf(buf, "%u\n", val); | ||
40 | } | ||
41 | |||
42 | static ssize_t adis16220_write_16bit(struct device *dev, | ||
43 | struct device_attribute *attr, | ||
44 | const char *buf, | ||
45 | size_t len) | ||
46 | { | ||
47 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); | ||
48 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); | ||
49 | struct adis16220_state *st = iio_priv(indio_dev); | ||
50 | int ret; | ||
51 | u16 val; | ||
52 | |||
53 | ret = kstrtou16(buf, 10, &val); | ||
54 | if (ret) | ||
55 | goto error_ret; | ||
56 | ret = adis_write_reg_16(&st->adis, this_attr->address, val); | ||
57 | |||
58 | error_ret: | ||
59 | return ret ? ret : len; | ||
60 | } | ||
61 | |||
62 | static int adis16220_capture(struct iio_dev *indio_dev) | ||
63 | { | ||
64 | struct adis16220_state *st = iio_priv(indio_dev); | ||
65 | int ret; | ||
66 | |||
67 | /* initiates a manual data capture */ | ||
68 | ret = adis_write_reg_16(&st->adis, ADIS16220_GLOB_CMD, 0xBF08); | ||
69 | if (ret) | ||
70 | dev_err(&indio_dev->dev, "problem beginning capture"); | ||
71 | |||
72 | usleep_range(10000, 11000); /* delay for capture to finish */ | ||
73 | |||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | static ssize_t adis16220_write_capture(struct device *dev, | ||
78 | struct device_attribute *attr, | ||
79 | const char *buf, size_t len) | ||
80 | { | ||
81 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); | ||
82 | bool val; | ||
83 | int ret; | ||
84 | |||
85 | ret = strtobool(buf, &val); | ||
86 | if (ret) | ||
87 | return ret; | ||
88 | if (!val) | ||
89 | return -EINVAL; | ||
90 | ret = adis16220_capture(indio_dev); | ||
91 | if (ret) | ||
92 | return ret; | ||
93 | |||
94 | return len; | ||
95 | } | ||
96 | |||
97 | static ssize_t adis16220_capture_buffer_read(struct iio_dev *indio_dev, | ||
98 | char *buf, | ||
99 | loff_t off, | ||
100 | size_t count, | ||
101 | int addr) | ||
102 | { | ||
103 | struct adis16220_state *st = iio_priv(indio_dev); | ||
104 | struct spi_transfer xfers[] = { | ||
105 | { | ||
106 | .tx_buf = st->tx, | ||
107 | .bits_per_word = 8, | ||
108 | .len = 2, | ||
109 | .cs_change = 1, | ||
110 | .delay_usecs = 25, | ||
111 | }, { | ||
112 | .tx_buf = st->tx, | ||
113 | .rx_buf = st->rx, | ||
114 | .bits_per_word = 8, | ||
115 | .cs_change = 1, | ||
116 | .delay_usecs = 25, | ||
117 | }, | ||
118 | }; | ||
119 | int ret; | ||
120 | int i; | ||
121 | |||
122 | if (unlikely(!count)) | ||
123 | return count; | ||
124 | |||
125 | if ((off >= ADIS16220_CAPTURE_SIZE) || (count & 1) || (off & 1)) | ||
126 | return -EINVAL; | ||
127 | |||
128 | if (off + count > ADIS16220_CAPTURE_SIZE) | ||
129 | count = ADIS16220_CAPTURE_SIZE - off; | ||
130 | |||
131 | /* write the begin position of capture buffer */ | ||
132 | ret = adis_write_reg_16(&st->adis, | ||
133 | ADIS16220_CAPT_PNTR, | ||
134 | off > 1); | ||
135 | if (ret) | ||
136 | return -EIO; | ||
137 | |||
138 | /* read count/2 values from capture buffer */ | ||
139 | mutex_lock(&st->buf_lock); | ||
140 | |||
141 | for (i = 0; i < count; i += 2) { | ||
142 | st->tx[i] = ADIS_READ_REG(addr); | ||
143 | st->tx[i + 1] = 0; | ||
144 | } | ||
145 | xfers[1].len = count; | ||
146 | |||
147 | ret = spi_sync_transfer(st->adis.spi, xfers, ARRAY_SIZE(xfers)); | ||
148 | if (ret) { | ||
149 | mutex_unlock(&st->buf_lock); | ||
150 | return -EIO; | ||
151 | } | ||
152 | |||
153 | memcpy(buf, st->rx, count); | ||
154 | |||
155 | mutex_unlock(&st->buf_lock); | ||
156 | return count; | ||
157 | } | ||
158 | |||
159 | static ssize_t adis16220_accel_bin_read(struct file *filp, struct kobject *kobj, | ||
160 | struct bin_attribute *attr, | ||
161 | char *buf, | ||
162 | loff_t off, | ||
163 | size_t count) | ||
164 | { | ||
165 | struct iio_dev *indio_dev = dev_to_iio_dev(kobj_to_dev(kobj)); | ||
166 | |||
167 | return adis16220_capture_buffer_read(indio_dev, buf, | ||
168 | off, count, | ||
169 | ADIS16220_CAPT_BUFA); | ||
170 | } | ||
171 | |||
172 | static struct bin_attribute accel_bin = { | ||
173 | .attr = { | ||
174 | .name = "accel_bin", | ||
175 | .mode = S_IRUGO, | ||
176 | }, | ||
177 | .read = adis16220_accel_bin_read, | ||
178 | .size = ADIS16220_CAPTURE_SIZE, | ||
179 | }; | ||
180 | |||
181 | static ssize_t adis16220_adc1_bin_read(struct file *filp, struct kobject *kobj, | ||
182 | struct bin_attribute *attr, | ||
183 | char *buf, loff_t off, | ||
184 | size_t count) | ||
185 | { | ||
186 | struct iio_dev *indio_dev = dev_to_iio_dev(kobj_to_dev(kobj)); | ||
187 | |||
188 | return adis16220_capture_buffer_read(indio_dev, buf, | ||
189 | off, count, | ||
190 | ADIS16220_CAPT_BUF1); | ||
191 | } | ||
192 | |||
193 | static struct bin_attribute adc1_bin = { | ||
194 | .attr = { | ||
195 | .name = "in0_bin", | ||
196 | .mode = S_IRUGO, | ||
197 | }, | ||
198 | .read = adis16220_adc1_bin_read, | ||
199 | .size = ADIS16220_CAPTURE_SIZE, | ||
200 | }; | ||
201 | |||
202 | static ssize_t adis16220_adc2_bin_read(struct file *filp, struct kobject *kobj, | ||
203 | struct bin_attribute *attr, | ||
204 | char *buf, loff_t off, | ||
205 | size_t count) | ||
206 | { | ||
207 | struct iio_dev *indio_dev = dev_to_iio_dev(kobj_to_dev(kobj)); | ||
208 | |||
209 | return adis16220_capture_buffer_read(indio_dev, buf, | ||
210 | off, count, | ||
211 | ADIS16220_CAPT_BUF2); | ||
212 | } | ||
213 | |||
214 | static struct bin_attribute adc2_bin = { | ||
215 | .attr = { | ||
216 | .name = "in1_bin", | ||
217 | .mode = S_IRUGO, | ||
218 | }, | ||
219 | .read = adis16220_adc2_bin_read, | ||
220 | .size = ADIS16220_CAPTURE_SIZE, | ||
221 | }; | ||
222 | |||
223 | #define IIO_DEV_ATTR_CAPTURE(_store) \ | ||
224 | IIO_DEVICE_ATTR(capture, S_IWUSR, NULL, _store, 0) | ||
225 | |||
226 | static IIO_DEV_ATTR_CAPTURE(adis16220_write_capture); | ||
227 | |||
228 | #define IIO_DEV_ATTR_CAPTURE_COUNT(_mode, _show, _store, _addr) \ | ||
229 | IIO_DEVICE_ATTR(capture_count, _mode, _show, _store, _addr) | ||
230 | |||
231 | static IIO_DEV_ATTR_CAPTURE_COUNT(S_IWUSR | S_IRUGO, | ||
232 | adis16220_read_16bit, | ||
233 | adis16220_write_16bit, | ||
234 | ADIS16220_CAPT_PNTR); | ||
235 | |||
236 | enum adis16220_channel { | ||
237 | in_supply, in_1, in_2, accel, temp | ||
238 | }; | ||
239 | |||
240 | struct adis16220_address_spec { | ||
241 | u8 addr; | ||
242 | u8 bits; | ||
243 | bool sign; | ||
244 | }; | ||
245 | |||
246 | /* Address / bits / signed */ | ||
247 | static const struct adis16220_address_spec adis16220_addresses[][3] = { | ||
248 | [in_supply] = { { ADIS16220_CAPT_SUPPLY, 12, 0 }, }, | ||
249 | [in_1] = { { ADIS16220_CAPT_BUF1, 16, 1 }, | ||
250 | { ADIS16220_AIN1_NULL, 16, 1 }, | ||
251 | { ADIS16220_CAPT_PEAK1, 16, 1 }, }, | ||
252 | [in_2] = { { ADIS16220_CAPT_BUF2, 16, 1 }, | ||
253 | { ADIS16220_AIN2_NULL, 16, 1 }, | ||
254 | { ADIS16220_CAPT_PEAK2, 16, 1 }, }, | ||
255 | [accel] = { { ADIS16220_CAPT_BUFA, 16, 1 }, | ||
256 | { ADIS16220_ACCL_NULL, 16, 1 }, | ||
257 | { ADIS16220_CAPT_PEAKA, 16, 1 }, }, | ||
258 | [temp] = { { ADIS16220_CAPT_TEMP, 12, 0 }, } | ||
259 | }; | ||
260 | |||
261 | static int adis16220_read_raw(struct iio_dev *indio_dev, | ||
262 | struct iio_chan_spec const *chan, | ||
263 | int *val, int *val2, | ||
264 | long mask) | ||
265 | { | ||
266 | struct adis16220_state *st = iio_priv(indio_dev); | ||
267 | const struct adis16220_address_spec *addr; | ||
268 | int ret = -EINVAL; | ||
269 | int addrind = 0; | ||
270 | u16 uval; | ||
271 | s16 sval; | ||
272 | u8 bits; | ||
273 | |||
274 | switch (mask) { | ||
275 | case IIO_CHAN_INFO_RAW: | ||
276 | addrind = 0; | ||
277 | break; | ||
278 | case IIO_CHAN_INFO_OFFSET: | ||
279 | if (chan->type == IIO_TEMP) { | ||
280 | *val = 25000 / -470 - 1278; /* 25 C = 1278 */ | ||
281 | return IIO_VAL_INT; | ||
282 | } | ||
283 | addrind = 1; | ||
284 | break; | ||
285 | case IIO_CHAN_INFO_PEAK: | ||
286 | addrind = 2; | ||
287 | break; | ||
288 | case IIO_CHAN_INFO_SCALE: | ||
289 | switch (chan->type) { | ||
290 | case IIO_TEMP: | ||
291 | *val = -470; /* -0.47 C */ | ||
292 | *val2 = 0; | ||
293 | return IIO_VAL_INT_PLUS_MICRO; | ||
294 | case IIO_ACCEL: | ||
295 | *val2 = IIO_G_TO_M_S_2(19073); /* 19.073 g */ | ||
296 | return IIO_VAL_INT_PLUS_MICRO; | ||
297 | case IIO_VOLTAGE: | ||
298 | if (chan->channel == 0) { | ||
299 | *val = 1; | ||
300 | *val2 = 220700; /* 1.2207 mV */ | ||
301 | } else { | ||
302 | /* Should really be dependent on VDD */ | ||
303 | *val2 = 305180; /* 305.18 uV */ | ||
304 | } | ||
305 | return IIO_VAL_INT_PLUS_MICRO; | ||
306 | default: | ||
307 | return -EINVAL; | ||
308 | } | ||
309 | default: | ||
310 | return -EINVAL; | ||
311 | } | ||
312 | addr = &adis16220_addresses[chan->address][addrind]; | ||
313 | if (addr->sign) { | ||
314 | ret = adis_read_reg_16(&st->adis, addr->addr, &sval); | ||
315 | if (ret) | ||
316 | return ret; | ||
317 | bits = addr->bits; | ||
318 | sval &= (1 << bits) - 1; | ||
319 | sval = (s16)(sval << (16 - bits)) >> (16 - bits); | ||
320 | *val = sval; | ||
321 | return IIO_VAL_INT; | ||
322 | } | ||
323 | ret = adis_read_reg_16(&st->adis, addr->addr, &uval); | ||
324 | if (ret) | ||
325 | return ret; | ||
326 | bits = addr->bits; | ||
327 | uval &= (1 << bits) - 1; | ||
328 | *val = uval; | ||
329 | return IIO_VAL_INT; | ||
330 | } | ||
331 | |||
332 | static const struct iio_chan_spec adis16220_channels[] = { | ||
333 | { | ||
334 | .type = IIO_VOLTAGE, | ||
335 | .indexed = 1, | ||
336 | .channel = 0, | ||
337 | .extend_name = "supply", | ||
338 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | ||
339 | BIT(IIO_CHAN_INFO_SCALE), | ||
340 | .address = in_supply, | ||
341 | }, { | ||
342 | .type = IIO_ACCEL, | ||
343 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | ||
344 | BIT(IIO_CHAN_INFO_OFFSET) | | ||
345 | BIT(IIO_CHAN_INFO_SCALE) | | ||
346 | BIT(IIO_CHAN_INFO_PEAK), | ||
347 | .address = accel, | ||
348 | }, { | ||
349 | .type = IIO_TEMP, | ||
350 | .indexed = 1, | ||
351 | .channel = 0, | ||
352 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | ||
353 | BIT(IIO_CHAN_INFO_OFFSET) | | ||
354 | BIT(IIO_CHAN_INFO_SCALE), | ||
355 | .address = temp, | ||
356 | }, { | ||
357 | .type = IIO_VOLTAGE, | ||
358 | .indexed = 1, | ||
359 | .channel = 1, | ||
360 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | ||
361 | BIT(IIO_CHAN_INFO_OFFSET) | | ||
362 | BIT(IIO_CHAN_INFO_SCALE), | ||
363 | .address = in_1, | ||
364 | }, { | ||
365 | .type = IIO_VOLTAGE, | ||
366 | .indexed = 1, | ||
367 | .channel = 2, | ||
368 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | ||
369 | .address = in_2, | ||
370 | } | ||
371 | }; | ||
372 | |||
373 | static struct attribute *adis16220_attributes[] = { | ||
374 | &iio_dev_attr_capture.dev_attr.attr, | ||
375 | &iio_dev_attr_capture_count.dev_attr.attr, | ||
376 | NULL | ||
377 | }; | ||
378 | |||
379 | static const struct attribute_group adis16220_attribute_group = { | ||
380 | .attrs = adis16220_attributes, | ||
381 | }; | ||
382 | |||
383 | static const struct iio_info adis16220_info = { | ||
384 | .attrs = &adis16220_attribute_group, | ||
385 | .driver_module = THIS_MODULE, | ||
386 | .read_raw = &adis16220_read_raw, | ||
387 | }; | ||
388 | |||
389 | static const char * const adis16220_status_error_msgs[] = { | ||
390 | [ADIS16220_DIAG_STAT_VIOLATION_BIT] = "Capture period violation/interruption", | ||
391 | [ADIS16220_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure", | ||
392 | [ADIS16220_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed", | ||
393 | [ADIS16220_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", | ||
394 | [ADIS16220_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 3.15V", | ||
395 | }; | ||
396 | |||
397 | static const struct adis_data adis16220_data = { | ||
398 | .read_delay = 35, | ||
399 | .write_delay = 35, | ||
400 | .msc_ctrl_reg = ADIS16220_MSC_CTRL, | ||
401 | .glob_cmd_reg = ADIS16220_GLOB_CMD, | ||
402 | .diag_stat_reg = ADIS16220_DIAG_STAT, | ||
403 | |||
404 | .self_test_mask = ADIS16220_MSC_CTRL_SELF_TEST_EN, | ||
405 | .startup_delay = ADIS16220_STARTUP_DELAY, | ||
406 | |||
407 | .status_error_msgs = adis16220_status_error_msgs, | ||
408 | .status_error_mask = BIT(ADIS16220_DIAG_STAT_VIOLATION_BIT) | | ||
409 | BIT(ADIS16220_DIAG_STAT_SPI_FAIL_BIT) | | ||
410 | BIT(ADIS16220_DIAG_STAT_FLASH_UPT_BIT) | | ||
411 | BIT(ADIS16220_DIAG_STAT_POWER_HIGH_BIT) | | ||
412 | BIT(ADIS16220_DIAG_STAT_POWER_LOW_BIT), | ||
413 | }; | ||
414 | |||
415 | static int adis16220_probe(struct spi_device *spi) | ||
416 | { | ||
417 | int ret; | ||
418 | struct adis16220_state *st; | ||
419 | struct iio_dev *indio_dev; | ||
420 | |||
421 | /* setup the industrialio driver allocated elements */ | ||
422 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); | ||
423 | if (!indio_dev) | ||
424 | return -ENOMEM; | ||
425 | |||
426 | st = iio_priv(indio_dev); | ||
427 | /* this is only used for removal purposes */ | ||
428 | spi_set_drvdata(spi, indio_dev); | ||
429 | |||
430 | indio_dev->name = spi->dev.driver->name; | ||
431 | indio_dev->dev.parent = &spi->dev; | ||
432 | indio_dev->info = &adis16220_info; | ||
433 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
434 | indio_dev->channels = adis16220_channels; | ||
435 | indio_dev->num_channels = ARRAY_SIZE(adis16220_channels); | ||
436 | |||
437 | ret = devm_iio_device_register(&spi->dev, indio_dev); | ||
438 | if (ret) | ||
439 | return ret; | ||
440 | |||
441 | ret = sysfs_create_bin_file(&indio_dev->dev.kobj, &accel_bin); | ||
442 | if (ret) | ||
443 | return ret; | ||
444 | |||
445 | ret = sysfs_create_bin_file(&indio_dev->dev.kobj, &adc1_bin); | ||
446 | if (ret) | ||
447 | goto error_rm_accel_bin; | ||
448 | |||
449 | ret = sysfs_create_bin_file(&indio_dev->dev.kobj, &adc2_bin); | ||
450 | if (ret) | ||
451 | goto error_rm_adc1_bin; | ||
452 | |||
453 | ret = adis_init(&st->adis, indio_dev, spi, &adis16220_data); | ||
454 | if (ret) | ||
455 | goto error_rm_adc2_bin; | ||
456 | /* Get the device into a sane initial state */ | ||
457 | ret = adis_initial_startup(&st->adis); | ||
458 | if (ret) | ||
459 | goto error_rm_adc2_bin; | ||
460 | return 0; | ||
461 | |||
462 | error_rm_adc2_bin: | ||
463 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &adc2_bin); | ||
464 | error_rm_adc1_bin: | ||
465 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &adc1_bin); | ||
466 | error_rm_accel_bin: | ||
467 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &accel_bin); | ||
468 | return ret; | ||
469 | } | ||
470 | |||
471 | static int adis16220_remove(struct spi_device *spi) | ||
472 | { | ||
473 | struct iio_dev *indio_dev = spi_get_drvdata(spi); | ||
474 | |||
475 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &adc2_bin); | ||
476 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &adc1_bin); | ||
477 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &accel_bin); | ||
478 | |||
479 | return 0; | ||
480 | } | ||
481 | |||
482 | static struct spi_driver adis16220_driver = { | ||
483 | .driver = { | ||
484 | .name = "adis16220", | ||
485 | }, | ||
486 | .probe = adis16220_probe, | ||
487 | .remove = adis16220_remove, | ||
488 | }; | ||
489 | module_spi_driver(adis16220_driver); | ||
490 | |||
491 | MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); | ||
492 | MODULE_DESCRIPTION("Analog Devices ADIS16220 Digital Vibration Sensor"); | ||
493 | MODULE_LICENSE("GPL v2"); | ||
494 | MODULE_ALIAS("spi:adis16220"); | ||
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index f91468e20b84..1cf6b79801a9 100644 --- a/drivers/staging/iio/adc/ad7192.c +++ b/drivers/staging/iio/adc/ad7192.c | |||
@@ -349,11 +349,9 @@ static ssize_t ad7192_write_frequency(struct device *dev, | |||
349 | if (lval == 0) | 349 | if (lval == 0) |
350 | return -EINVAL; | 350 | return -EINVAL; |
351 | 351 | ||
352 | mutex_lock(&indio_dev->mlock); | 352 | ret = iio_device_claim_direct_mode(indio_dev); |
353 | if (iio_buffer_enabled(indio_dev)) { | 353 | if (ret) |
354 | mutex_unlock(&indio_dev->mlock); | 354 | return ret; |
355 | return -EBUSY; | ||
356 | } | ||
357 | 355 | ||
358 | div = st->mclk / (lval * st->f_order * 1024); | 356 | div = st->mclk / (lval * st->f_order * 1024); |
359 | if (div < 1 || div > 1023) { | 357 | if (div < 1 || div > 1023) { |
@@ -366,7 +364,7 @@ static ssize_t ad7192_write_frequency(struct device *dev, | |||
366 | ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode); | 364 | ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode); |
367 | 365 | ||
368 | out: | 366 | out: |
369 | mutex_unlock(&indio_dev->mlock); | 367 | iio_device_release_direct_mode(indio_dev); |
370 | 368 | ||
371 | return ret ? ret : len; | 369 | return ret ? ret : len; |
372 | } | 370 | } |
@@ -434,11 +432,9 @@ static ssize_t ad7192_set(struct device *dev, | |||
434 | if (ret < 0) | 432 | if (ret < 0) |
435 | return ret; | 433 | return ret; |
436 | 434 | ||
437 | mutex_lock(&indio_dev->mlock); | 435 | ret = iio_device_claim_direct_mode(indio_dev); |
438 | if (iio_buffer_enabled(indio_dev)) { | 436 | if (ret) |
439 | mutex_unlock(&indio_dev->mlock); | 437 | return ret; |
440 | return -EBUSY; | ||
441 | } | ||
442 | 438 | ||
443 | switch ((u32)this_attr->address) { | 439 | switch ((u32)this_attr->address) { |
444 | case AD7192_REG_GPOCON: | 440 | case AD7192_REG_GPOCON: |
@@ -461,7 +457,7 @@ static ssize_t ad7192_set(struct device *dev, | |||
461 | ret = -EINVAL; | 457 | ret = -EINVAL; |
462 | } | 458 | } |
463 | 459 | ||
464 | mutex_unlock(&indio_dev->mlock); | 460 | iio_device_release_direct_mode(indio_dev); |
465 | 461 | ||
466 | return ret ? ret : len; | 462 | return ret ? ret : len; |
467 | } | 463 | } |
@@ -555,11 +551,9 @@ static int ad7192_write_raw(struct iio_dev *indio_dev, | |||
555 | int ret, i; | 551 | int ret, i; |
556 | unsigned int tmp; | 552 | unsigned int tmp; |
557 | 553 | ||
558 | mutex_lock(&indio_dev->mlock); | 554 | ret = iio_device_claim_direct_mode(indio_dev); |
559 | if (iio_buffer_enabled(indio_dev)) { | 555 | if (ret) |
560 | mutex_unlock(&indio_dev->mlock); | 556 | return ret; |
561 | return -EBUSY; | ||
562 | } | ||
563 | 557 | ||
564 | switch (mask) { | 558 | switch (mask) { |
565 | case IIO_CHAN_INFO_SCALE: | 559 | case IIO_CHAN_INFO_SCALE: |
@@ -582,7 +576,7 @@ static int ad7192_write_raw(struct iio_dev *indio_dev, | |||
582 | ret = -EINVAL; | 576 | ret = -EINVAL; |
583 | } | 577 | } |
584 | 578 | ||
585 | mutex_unlock(&indio_dev->mlock); | 579 | iio_device_release_direct_mode(indio_dev); |
586 | 580 | ||
587 | return ret; | 581 | return ret; |
588 | } | 582 | } |
diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index 62e5ecacf634..a06b46cb81ca 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c | |||
@@ -155,7 +155,7 @@ static void ad7280_crc8_build_table(unsigned char *crc_tab) | |||
155 | } | 155 | } |
156 | } | 156 | } |
157 | 157 | ||
158 | static unsigned char ad7280_calc_crc8(unsigned char *crc_tab, unsigned val) | 158 | static unsigned char ad7280_calc_crc8(unsigned char *crc_tab, unsigned int val) |
159 | { | 159 | { |
160 | unsigned char crc; | 160 | unsigned char crc; |
161 | 161 | ||
@@ -165,7 +165,7 @@ static unsigned char ad7280_calc_crc8(unsigned char *crc_tab, unsigned val) | |||
165 | return crc ^ (val & 0xFF); | 165 | return crc ^ (val & 0xFF); |
166 | } | 166 | } |
167 | 167 | ||
168 | static int ad7280_check_crc(struct ad7280_state *st, unsigned val) | 168 | static int ad7280_check_crc(struct ad7280_state *st, unsigned int val) |
169 | { | 169 | { |
170 | unsigned char crc = ad7280_calc_crc8(st->crc_tab, val >> 10); | 170 | unsigned char crc = ad7280_calc_crc8(st->crc_tab, val >> 10); |
171 | 171 | ||
@@ -191,7 +191,7 @@ static void ad7280_delay(struct ad7280_state *st) | |||
191 | usleep_range(250, 500); | 191 | usleep_range(250, 500); |
192 | } | 192 | } |
193 | 193 | ||
194 | static int __ad7280_read32(struct ad7280_state *st, unsigned *val) | 194 | static int __ad7280_read32(struct ad7280_state *st, unsigned int *val) |
195 | { | 195 | { |
196 | int ret; | 196 | int ret; |
197 | struct spi_transfer t = { | 197 | struct spi_transfer t = { |
@@ -211,10 +211,10 @@ static int __ad7280_read32(struct ad7280_state *st, unsigned *val) | |||
211 | return 0; | 211 | return 0; |
212 | } | 212 | } |
213 | 213 | ||
214 | static int ad7280_write(struct ad7280_state *st, unsigned devaddr, | 214 | static int ad7280_write(struct ad7280_state *st, unsigned int devaddr, |
215 | unsigned addr, bool all, unsigned val) | 215 | unsigned int addr, bool all, unsigned int val) |
216 | { | 216 | { |
217 | unsigned reg = devaddr << 27 | addr << 21 | | 217 | unsigned int reg = devaddr << 27 | addr << 21 | |
218 | (val & 0xFF) << 13 | all << 12; | 218 | (val & 0xFF) << 13 | all << 12; |
219 | 219 | ||
220 | reg |= ad7280_calc_crc8(st->crc_tab, reg >> 11) << 3 | 0x2; | 220 | reg |= ad7280_calc_crc8(st->crc_tab, reg >> 11) << 3 | 0x2; |
@@ -223,11 +223,11 @@ static int ad7280_write(struct ad7280_state *st, unsigned devaddr, | |||
223 | return spi_write(st->spi, &st->buf[0], 4); | 223 | return spi_write(st->spi, &st->buf[0], 4); |
224 | } | 224 | } |
225 | 225 | ||
226 | static int ad7280_read(struct ad7280_state *st, unsigned devaddr, | 226 | static int ad7280_read(struct ad7280_state *st, unsigned int devaddr, |
227 | unsigned addr) | 227 | unsigned int addr) |
228 | { | 228 | { |
229 | int ret; | 229 | int ret; |
230 | unsigned tmp; | 230 | unsigned int tmp; |
231 | 231 | ||
232 | /* turns off the read operation on all parts */ | 232 | /* turns off the read operation on all parts */ |
233 | ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, | 233 | ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, |
@@ -261,11 +261,11 @@ static int ad7280_read(struct ad7280_state *st, unsigned devaddr, | |||
261 | return (tmp >> 13) & 0xFF; | 261 | return (tmp >> 13) & 0xFF; |
262 | } | 262 | } |
263 | 263 | ||
264 | static int ad7280_read_channel(struct ad7280_state *st, unsigned devaddr, | 264 | static int ad7280_read_channel(struct ad7280_state *st, unsigned int devaddr, |
265 | unsigned addr) | 265 | unsigned int addr) |
266 | { | 266 | { |
267 | int ret; | 267 | int ret; |
268 | unsigned tmp; | 268 | unsigned int tmp; |
269 | 269 | ||
270 | ret = ad7280_write(st, devaddr, AD7280A_READ, 0, addr << 2); | 270 | ret = ad7280_write(st, devaddr, AD7280A_READ, 0, addr << 2); |
271 | if (ret) | 271 | if (ret) |
@@ -299,11 +299,11 @@ static int ad7280_read_channel(struct ad7280_state *st, unsigned devaddr, | |||
299 | return (tmp >> 11) & 0xFFF; | 299 | return (tmp >> 11) & 0xFFF; |
300 | } | 300 | } |
301 | 301 | ||
302 | static int ad7280_read_all_channels(struct ad7280_state *st, unsigned cnt, | 302 | static int ad7280_read_all_channels(struct ad7280_state *st, unsigned int cnt, |
303 | unsigned *array) | 303 | unsigned int *array) |
304 | { | 304 | { |
305 | int i, ret; | 305 | int i, ret; |
306 | unsigned tmp, sum = 0; | 306 | unsigned int tmp, sum = 0; |
307 | 307 | ||
308 | ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_READ, 1, | 308 | ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_READ, 1, |
309 | AD7280A_CELL_VOLTAGE_1 << 2); | 309 | AD7280A_CELL_VOLTAGE_1 << 2); |
@@ -338,7 +338,7 @@ static int ad7280_read_all_channels(struct ad7280_state *st, unsigned cnt, | |||
338 | 338 | ||
339 | static int ad7280_chain_setup(struct ad7280_state *st) | 339 | static int ad7280_chain_setup(struct ad7280_state *st) |
340 | { | 340 | { |
341 | unsigned val, n; | 341 | unsigned int val, n; |
342 | int ret; | 342 | int ret; |
343 | 343 | ||
344 | ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_LB, 1, | 344 | ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_LB, 1, |
@@ -401,7 +401,7 @@ static ssize_t ad7280_store_balance_sw(struct device *dev, | |||
401 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); | 401 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
402 | bool readin; | 402 | bool readin; |
403 | int ret; | 403 | int ret; |
404 | unsigned devaddr, ch; | 404 | unsigned int devaddr, ch; |
405 | 405 | ||
406 | ret = strtobool(buf, &readin); | 406 | ret = strtobool(buf, &readin); |
407 | if (ret) | 407 | if (ret) |
@@ -431,7 +431,7 @@ static ssize_t ad7280_show_balance_timer(struct device *dev, | |||
431 | struct ad7280_state *st = iio_priv(indio_dev); | 431 | struct ad7280_state *st = iio_priv(indio_dev); |
432 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); | 432 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
433 | int ret; | 433 | int ret; |
434 | unsigned msecs; | 434 | unsigned int msecs; |
435 | 435 | ||
436 | mutex_lock(&indio_dev->mlock); | 436 | mutex_lock(&indio_dev->mlock); |
437 | ret = ad7280_read(st, this_attr->address >> 8, | 437 | ret = ad7280_read(st, this_attr->address >> 8, |
@@ -602,7 +602,7 @@ static ssize_t ad7280_read_channel_config(struct device *dev, | |||
602 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); | 602 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
603 | struct ad7280_state *st = iio_priv(indio_dev); | 603 | struct ad7280_state *st = iio_priv(indio_dev); |
604 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); | 604 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
605 | unsigned val; | 605 | unsigned int val; |
606 | 606 | ||
607 | switch ((u32)this_attr->address) { | 607 | switch ((u32)this_attr->address) { |
608 | case AD7280A_CELL_OVERVOLTAGE: | 608 | case AD7280A_CELL_OVERVOLTAGE: |
@@ -683,7 +683,7 @@ static irqreturn_t ad7280_event_handler(int irq, void *private) | |||
683 | { | 683 | { |
684 | struct iio_dev *indio_dev = private; | 684 | struct iio_dev *indio_dev = private; |
685 | struct ad7280_state *st = iio_priv(indio_dev); | 685 | struct ad7280_state *st = iio_priv(indio_dev); |
686 | unsigned *channels; | 686 | unsigned int *channels; |
687 | int i, ret; | 687 | int i, ret; |
688 | 688 | ||
689 | channels = kcalloc(st->scan_cnt, sizeof(*channels), GFP_KERNEL); | 689 | channels = kcalloc(st->scan_cnt, sizeof(*channels), GFP_KERNEL); |
diff --git a/drivers/staging/iio/adc/ad7280a.h b/drivers/staging/iio/adc/ad7280a.h index 732347a9bce4..ccfb90d20e71 100644 --- a/drivers/staging/iio/adc/ad7280a.h +++ b/drivers/staging/iio/adc/ad7280a.h | |||
@@ -29,10 +29,10 @@ | |||
29 | #define AD7280A_ALERT_REMOVE_AUX4_AUX5 BIT(1) | 29 | #define AD7280A_ALERT_REMOVE_AUX4_AUX5 BIT(1) |
30 | 30 | ||
31 | struct ad7280_platform_data { | 31 | struct ad7280_platform_data { |
32 | unsigned acquisition_time; | 32 | unsigned int acquisition_time; |
33 | unsigned conversion_averaging; | 33 | unsigned int conversion_averaging; |
34 | unsigned chain_last_alert_ignore; | 34 | unsigned int chain_last_alert_ignore; |
35 | bool thermistor_term_en; | 35 | bool thermistor_term_en; |
36 | }; | 36 | }; |
37 | 37 | ||
38 | #endif /* IIO_ADC_AD7280_H_ */ | 38 | #endif /* IIO_ADC_AD7280_H_ */ |
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h index cca946924c58..39f50440d915 100644 --- a/drivers/staging/iio/adc/ad7606.h +++ b/drivers/staging/iio/adc/ad7606.h | |||
@@ -28,16 +28,16 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | struct ad7606_platform_data { | 30 | struct ad7606_platform_data { |
31 | unsigned default_os; | 31 | unsigned int default_os; |
32 | unsigned default_range; | 32 | unsigned int default_range; |
33 | unsigned gpio_convst; | 33 | unsigned int gpio_convst; |
34 | unsigned gpio_reset; | 34 | unsigned int gpio_reset; |
35 | unsigned gpio_range; | 35 | unsigned int gpio_range; |
36 | unsigned gpio_os0; | 36 | unsigned int gpio_os0; |
37 | unsigned gpio_os1; | 37 | unsigned int gpio_os1; |
38 | unsigned gpio_os2; | 38 | unsigned int gpio_os2; |
39 | unsigned gpio_frstdata; | 39 | unsigned int gpio_frstdata; |
40 | unsigned gpio_stby; | 40 | unsigned int gpio_stby; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | /** | 43 | /** |
@@ -52,7 +52,7 @@ struct ad7606_chip_info { | |||
52 | const char *name; | 52 | const char *name; |
53 | u16 int_vref_mv; | 53 | u16 int_vref_mv; |
54 | const struct iio_chan_spec *channels; | 54 | const struct iio_chan_spec *channels; |
55 | unsigned num_channels; | 55 | unsigned int num_channels; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | /** | 58 | /** |
@@ -67,8 +67,8 @@ struct ad7606_state { | |||
67 | struct work_struct poll_work; | 67 | struct work_struct poll_work; |
68 | wait_queue_head_t wq_data_avail; | 68 | wait_queue_head_t wq_data_avail; |
69 | const struct ad7606_bus_ops *bops; | 69 | const struct ad7606_bus_ops *bops; |
70 | unsigned range; | 70 | unsigned int range; |
71 | unsigned oversampling; | 71 | unsigned int oversampling; |
72 | bool done; | 72 | bool done; |
73 | void __iomem *base_address; | 73 | void __iomem *base_address; |
74 | 74 | ||
@@ -86,7 +86,7 @@ struct ad7606_bus_ops { | |||
86 | }; | 86 | }; |
87 | 87 | ||
88 | struct iio_dev *ad7606_probe(struct device *dev, int irq, | 88 | struct iio_dev *ad7606_probe(struct device *dev, int irq, |
89 | void __iomem *base_address, unsigned id, | 89 | void __iomem *base_address, unsigned int id, |
90 | const struct ad7606_bus_ops *bops); | 90 | const struct ad7606_bus_ops *bops); |
91 | int ad7606_remove(struct iio_dev *indio_dev, int irq); | 91 | int ad7606_remove(struct iio_dev *indio_dev, int irq); |
92 | int ad7606_reset(struct ad7606_state *st); | 92 | int ad7606_reset(struct ad7606_state *st); |
diff --git a/drivers/staging/iio/adc/ad7606_core.c b/drivers/staging/iio/adc/ad7606_core.c index fe6caeee0843..6dbc811730ae 100644 --- a/drivers/staging/iio/adc/ad7606_core.c +++ b/drivers/staging/iio/adc/ad7606_core.c | |||
@@ -36,7 +36,7 @@ int ad7606_reset(struct ad7606_state *st) | |||
36 | return -ENODEV; | 36 | return -ENODEV; |
37 | } | 37 | } |
38 | 38 | ||
39 | static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned ch) | 39 | static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch) |
40 | { | 40 | { |
41 | struct ad7606_state *st = iio_priv(indio_dev); | 41 | struct ad7606_state *st = iio_priv(indio_dev); |
42 | int ret; | 42 | int ret; |
@@ -155,7 +155,7 @@ static ssize_t ad7606_show_oversampling_ratio(struct device *dev, | |||
155 | return sprintf(buf, "%u\n", st->oversampling); | 155 | return sprintf(buf, "%u\n", st->oversampling); |
156 | } | 156 | } |
157 | 157 | ||
158 | static int ad7606_oversampling_get_index(unsigned val) | 158 | static int ad7606_oversampling_get_index(unsigned int val) |
159 | { | 159 | { |
160 | unsigned char supported[] = {0, 2, 4, 8, 16, 32, 64}; | 160 | unsigned char supported[] = {0, 2, 4, 8, 16, 32, 64}; |
161 | int i; | 161 | int i; |
@@ -446,7 +446,7 @@ static const struct iio_info ad7606_info_range = { | |||
446 | 446 | ||
447 | struct iio_dev *ad7606_probe(struct device *dev, int irq, | 447 | struct iio_dev *ad7606_probe(struct device *dev, int irq, |
448 | void __iomem *base_address, | 448 | void __iomem *base_address, |
449 | unsigned id, | 449 | unsigned int id, |
450 | const struct ad7606_bus_ops *bops) | 450 | const struct ad7606_bus_ops *bops) |
451 | { | 451 | { |
452 | struct ad7606_platform_data *pdata = dev->platform_data; | 452 | struct ad7606_platform_data *pdata = dev->platform_data; |
diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index 1439cfdbb09c..c9a0c2aa602f 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c | |||
@@ -63,7 +63,7 @@ static int ad7780_set_mode(struct ad_sigma_delta *sigma_delta, | |||
63 | enum ad_sigma_delta_mode mode) | 63 | enum ad_sigma_delta_mode mode) |
64 | { | 64 | { |
65 | struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta); | 65 | struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta); |
66 | unsigned val; | 66 | unsigned int val; |
67 | 67 | ||
68 | switch (mode) { | 68 | switch (mode) { |
69 | case AD_SD_MODE_SINGLE: | 69 | case AD_SD_MODE_SINGLE: |
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index e6fdb3d54e25..9f43976f4ef2 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c | |||
@@ -101,14 +101,14 @@ struct ad5933_state { | |||
101 | unsigned long mclk_hz; | 101 | unsigned long mclk_hz; |
102 | unsigned char ctrl_hb; | 102 | unsigned char ctrl_hb; |
103 | unsigned char ctrl_lb; | 103 | unsigned char ctrl_lb; |
104 | unsigned range_avail[4]; | 104 | unsigned int range_avail[4]; |
105 | unsigned short vref_mv; | 105 | unsigned short vref_mv; |
106 | unsigned short settling_cycles; | 106 | unsigned short settling_cycles; |
107 | unsigned short freq_points; | 107 | unsigned short freq_points; |
108 | unsigned freq_start; | 108 | unsigned int freq_start; |
109 | unsigned freq_inc; | 109 | unsigned int freq_inc; |
110 | unsigned state; | 110 | unsigned int state; |
111 | unsigned poll_time_jiffies; | 111 | unsigned int poll_time_jiffies; |
112 | }; | 112 | }; |
113 | 113 | ||
114 | static struct ad5933_platform_data ad5933_default_pdata = { | 114 | static struct ad5933_platform_data ad5933_default_pdata = { |
@@ -222,7 +222,7 @@ static int ad5933_wait_busy(struct ad5933_state *st, unsigned char event) | |||
222 | } | 222 | } |
223 | 223 | ||
224 | static int ad5933_set_freq(struct ad5933_state *st, | 224 | static int ad5933_set_freq(struct ad5933_state *st, |
225 | unsigned reg, unsigned long freq) | 225 | unsigned int reg, unsigned long freq) |
226 | { | 226 | { |
227 | unsigned long long freqreg; | 227 | unsigned long long freqreg; |
228 | union { | 228 | union { |
@@ -282,7 +282,7 @@ static int ad5933_setup(struct ad5933_state *st) | |||
282 | static void ad5933_calc_out_ranges(struct ad5933_state *st) | 282 | static void ad5933_calc_out_ranges(struct ad5933_state *st) |
283 | { | 283 | { |
284 | int i; | 284 | int i; |
285 | unsigned normalized_3v3[4] = {1980, 198, 383, 970}; | 285 | unsigned int normalized_3v3[4] = {1980, 198, 383, 970}; |
286 | 286 | ||
287 | for (i = 0; i < 4; i++) | 287 | for (i = 0; i < 4; i++) |
288 | st->range_avail[i] = normalized_3v3[i] * st->vref_mv / 3300; | 288 | st->range_avail[i] = normalized_3v3[i] * st->vref_mv / 3300; |
diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 6e2ba458c24d..2e3b1d64e32a 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c | |||
@@ -69,7 +69,6 @@ enum als_ir_mode { | |||
69 | }; | 69 | }; |
70 | 70 | ||
71 | struct isl29028_chip { | 71 | struct isl29028_chip { |
72 | struct device *dev; | ||
73 | struct mutex lock; | 72 | struct mutex lock; |
74 | struct regmap *regmap; | 73 | struct regmap *regmap; |
75 | 74 | ||
@@ -166,20 +165,21 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, | |||
166 | 165 | ||
167 | static int isl29028_read_als_ir(struct isl29028_chip *chip, int *als_ir) | 166 | static int isl29028_read_als_ir(struct isl29028_chip *chip, int *als_ir) |
168 | { | 167 | { |
168 | struct device *dev = regmap_get_device(chip->regmap); | ||
169 | unsigned int lsb; | 169 | unsigned int lsb; |
170 | unsigned int msb; | 170 | unsigned int msb; |
171 | int ret; | 171 | int ret; |
172 | 172 | ||
173 | ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_L, &lsb); | 173 | ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_L, &lsb); |
174 | if (ret < 0) { | 174 | if (ret < 0) { |
175 | dev_err(chip->dev, | 175 | dev_err(dev, |
176 | "Error in reading register ALSIR_L err %d\n", ret); | 176 | "Error in reading register ALSIR_L err %d\n", ret); |
177 | return ret; | 177 | return ret; |
178 | } | 178 | } |
179 | 179 | ||
180 | ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_U, &msb); | 180 | ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_U, &msb); |
181 | if (ret < 0) { | 181 | if (ret < 0) { |
182 | dev_err(chip->dev, | 182 | dev_err(dev, |
183 | "Error in reading register ALSIR_U err %d\n", ret); | 183 | "Error in reading register ALSIR_U err %d\n", ret); |
184 | return ret; | 184 | return ret; |
185 | } | 185 | } |
@@ -190,12 +190,13 @@ static int isl29028_read_als_ir(struct isl29028_chip *chip, int *als_ir) | |||
190 | 190 | ||
191 | static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) | 191 | static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) |
192 | { | 192 | { |
193 | struct device *dev = regmap_get_device(chip->regmap); | ||
193 | unsigned int data; | 194 | unsigned int data; |
194 | int ret; | 195 | int ret; |
195 | 196 | ||
196 | ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data); | 197 | ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data); |
197 | if (ret < 0) { | 198 | if (ret < 0) { |
198 | dev_err(chip->dev, "Error in reading register %d, error %d\n", | 199 | dev_err(dev, "Error in reading register %d, error %d\n", |
199 | ISL29028_REG_PROX_DATA, ret); | 200 | ISL29028_REG_PROX_DATA, ret); |
200 | return ret; | 201 | return ret; |
201 | } | 202 | } |
@@ -218,13 +219,14 @@ static int isl29028_proxim_get(struct isl29028_chip *chip, int *prox_data) | |||
218 | 219 | ||
219 | static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) | 220 | static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) |
220 | { | 221 | { |
222 | struct device *dev = regmap_get_device(chip->regmap); | ||
221 | int ret; | 223 | int ret; |
222 | int als_ir_data; | 224 | int als_ir_data; |
223 | 225 | ||
224 | if (chip->als_ir_mode != MODE_ALS) { | 226 | if (chip->als_ir_mode != MODE_ALS) { |
225 | ret = isl29028_set_als_ir_mode(chip, MODE_ALS); | 227 | ret = isl29028_set_als_ir_mode(chip, MODE_ALS); |
226 | if (ret < 0) { | 228 | if (ret < 0) { |
227 | dev_err(chip->dev, | 229 | dev_err(dev, |
228 | "Error in enabling ALS mode err %d\n", ret); | 230 | "Error in enabling ALS mode err %d\n", ret); |
229 | return ret; | 231 | return ret; |
230 | } | 232 | } |
@@ -251,12 +253,13 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) | |||
251 | 253 | ||
252 | static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data) | 254 | static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data) |
253 | { | 255 | { |
256 | struct device *dev = regmap_get_device(chip->regmap); | ||
254 | int ret; | 257 | int ret; |
255 | 258 | ||
256 | if (chip->als_ir_mode != MODE_IR) { | 259 | if (chip->als_ir_mode != MODE_IR) { |
257 | ret = isl29028_set_als_ir_mode(chip, MODE_IR); | 260 | ret = isl29028_set_als_ir_mode(chip, MODE_IR); |
258 | if (ret < 0) { | 261 | if (ret < 0) { |
259 | dev_err(chip->dev, | 262 | dev_err(dev, |
260 | "Error in enabling IR mode err %d\n", ret); | 263 | "Error in enabling IR mode err %d\n", ret); |
261 | return ret; | 264 | return ret; |
262 | } | 265 | } |
@@ -271,25 +274,26 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, | |||
271 | int val, int val2, long mask) | 274 | int val, int val2, long mask) |
272 | { | 275 | { |
273 | struct isl29028_chip *chip = iio_priv(indio_dev); | 276 | struct isl29028_chip *chip = iio_priv(indio_dev); |
277 | struct device *dev = regmap_get_device(chip->regmap); | ||
274 | int ret = -EINVAL; | 278 | int ret = -EINVAL; |
275 | 279 | ||
276 | mutex_lock(&chip->lock); | 280 | mutex_lock(&chip->lock); |
277 | switch (chan->type) { | 281 | switch (chan->type) { |
278 | case IIO_PROXIMITY: | 282 | case IIO_PROXIMITY: |
279 | if (mask != IIO_CHAN_INFO_SAMP_FREQ) { | 283 | if (mask != IIO_CHAN_INFO_SAMP_FREQ) { |
280 | dev_err(chip->dev, | 284 | dev_err(dev, |
281 | "proximity: mask value 0x%08lx not supported\n", | 285 | "proximity: mask value 0x%08lx not supported\n", |
282 | mask); | 286 | mask); |
283 | break; | 287 | break; |
284 | } | 288 | } |
285 | if (val < 1 || val > 100) { | 289 | if (val < 1 || val > 100) { |
286 | dev_err(chip->dev, | 290 | dev_err(dev, |
287 | "Samp_freq %d is not in range[1:100]\n", val); | 291 | "Samp_freq %d is not in range[1:100]\n", val); |
288 | break; | 292 | break; |
289 | } | 293 | } |
290 | ret = isl29028_set_proxim_sampling(chip, val); | 294 | ret = isl29028_set_proxim_sampling(chip, val); |
291 | if (ret < 0) { | 295 | if (ret < 0) { |
292 | dev_err(chip->dev, | 296 | dev_err(dev, |
293 | "Setting proximity samp_freq fail, err %d\n", | 297 | "Setting proximity samp_freq fail, err %d\n", |
294 | ret); | 298 | ret); |
295 | break; | 299 | break; |
@@ -299,19 +303,19 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, | |||
299 | 303 | ||
300 | case IIO_LIGHT: | 304 | case IIO_LIGHT: |
301 | if (mask != IIO_CHAN_INFO_SCALE) { | 305 | if (mask != IIO_CHAN_INFO_SCALE) { |
302 | dev_err(chip->dev, | 306 | dev_err(dev, |
303 | "light: mask value 0x%08lx not supported\n", | 307 | "light: mask value 0x%08lx not supported\n", |
304 | mask); | 308 | mask); |
305 | break; | 309 | break; |
306 | } | 310 | } |
307 | if ((val != 125) && (val != 2000)) { | 311 | if ((val != 125) && (val != 2000)) { |
308 | dev_err(chip->dev, | 312 | dev_err(dev, |
309 | "lux scale %d is invalid [125, 2000]\n", val); | 313 | "lux scale %d is invalid [125, 2000]\n", val); |
310 | break; | 314 | break; |
311 | } | 315 | } |
312 | ret = isl29028_set_als_scale(chip, val); | 316 | ret = isl29028_set_als_scale(chip, val); |
313 | if (ret < 0) { | 317 | if (ret < 0) { |
314 | dev_err(chip->dev, | 318 | dev_err(dev, |
315 | "Setting lux scale fail with error %d\n", ret); | 319 | "Setting lux scale fail with error %d\n", ret); |
316 | break; | 320 | break; |
317 | } | 321 | } |
@@ -319,7 +323,7 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, | |||
319 | break; | 323 | break; |
320 | 324 | ||
321 | default: | 325 | default: |
322 | dev_err(chip->dev, "Unsupported channel type\n"); | 326 | dev_err(dev, "Unsupported channel type\n"); |
323 | break; | 327 | break; |
324 | } | 328 | } |
325 | mutex_unlock(&chip->lock); | 329 | mutex_unlock(&chip->lock); |
@@ -331,6 +335,7 @@ static int isl29028_read_raw(struct iio_dev *indio_dev, | |||
331 | int *val, int *val2, long mask) | 335 | int *val, int *val2, long mask) |
332 | { | 336 | { |
333 | struct isl29028_chip *chip = iio_priv(indio_dev); | 337 | struct isl29028_chip *chip = iio_priv(indio_dev); |
338 | struct device *dev = regmap_get_device(chip->regmap); | ||
334 | int ret = -EINVAL; | 339 | int ret = -EINVAL; |
335 | 340 | ||
336 | mutex_lock(&chip->lock); | 341 | mutex_lock(&chip->lock); |
@@ -370,7 +375,7 @@ static int isl29028_read_raw(struct iio_dev *indio_dev, | |||
370 | break; | 375 | break; |
371 | 376 | ||
372 | default: | 377 | default: |
373 | dev_err(chip->dev, "mask value 0x%08lx not supported\n", mask); | 378 | dev_err(dev, "mask value 0x%08lx not supported\n", mask); |
374 | break; | 379 | break; |
375 | } | 380 | } |
376 | mutex_unlock(&chip->lock); | 381 | mutex_unlock(&chip->lock); |
@@ -417,6 +422,7 @@ static const struct iio_info isl29028_info = { | |||
417 | 422 | ||
418 | static int isl29028_chip_init(struct isl29028_chip *chip) | 423 | static int isl29028_chip_init(struct isl29028_chip *chip) |
419 | { | 424 | { |
425 | struct device *dev = regmap_get_device(chip->regmap); | ||
420 | int ret; | 426 | int ret; |
421 | 427 | ||
422 | chip->enable_prox = false; | 428 | chip->enable_prox = false; |
@@ -426,35 +432,33 @@ static int isl29028_chip_init(struct isl29028_chip *chip) | |||
426 | 432 | ||
427 | ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0); | 433 | ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0); |
428 | if (ret < 0) { | 434 | if (ret < 0) { |
429 | dev_err(chip->dev, "%s(): write to reg %d failed, err = %d\n", | 435 | dev_err(dev, "%s(): write to reg %d failed, err = %d\n", |
430 | __func__, ISL29028_REG_TEST1_MODE, ret); | 436 | __func__, ISL29028_REG_TEST1_MODE, ret); |
431 | return ret; | 437 | return ret; |
432 | } | 438 | } |
433 | ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0); | 439 | ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0); |
434 | if (ret < 0) { | 440 | if (ret < 0) { |
435 | dev_err(chip->dev, "%s(): write to reg %d failed, err = %d\n", | 441 | dev_err(dev, "%s(): write to reg %d failed, err = %d\n", |
436 | __func__, ISL29028_REG_TEST2_MODE, ret); | 442 | __func__, ISL29028_REG_TEST2_MODE, ret); |
437 | return ret; | 443 | return ret; |
438 | } | 444 | } |
439 | 445 | ||
440 | ret = regmap_write(chip->regmap, ISL29028_REG_CONFIGURE, 0x0); | 446 | ret = regmap_write(chip->regmap, ISL29028_REG_CONFIGURE, 0x0); |
441 | if (ret < 0) { | 447 | if (ret < 0) { |
442 | dev_err(chip->dev, "%s(): write to reg %d failed, err = %d\n", | 448 | dev_err(dev, "%s(): write to reg %d failed, err = %d\n", |
443 | __func__, ISL29028_REG_CONFIGURE, ret); | 449 | __func__, ISL29028_REG_CONFIGURE, ret); |
444 | return ret; | 450 | return ret; |
445 | } | 451 | } |
446 | 452 | ||
447 | ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling); | 453 | ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling); |
448 | if (ret < 0) { | 454 | if (ret < 0) { |
449 | dev_err(chip->dev, "setting the proximity, err = %d\n", | 455 | dev_err(dev, "setting the proximity, err = %d\n", ret); |
450 | ret); | ||
451 | return ret; | 456 | return ret; |
452 | } | 457 | } |
453 | 458 | ||
454 | ret = isl29028_set_als_scale(chip, chip->lux_scale); | 459 | ret = isl29028_set_als_scale(chip, chip->lux_scale); |
455 | if (ret < 0) | 460 | if (ret < 0) |
456 | dev_err(chip->dev, | 461 | dev_err(dev, "setting als scale failed, err = %d\n", ret); |
457 | "setting als scale failed, err = %d\n", ret); | ||
458 | return ret; | 462 | return ret; |
459 | } | 463 | } |
460 | 464 | ||
@@ -496,19 +500,19 @@ static int isl29028_probe(struct i2c_client *client, | |||
496 | chip = iio_priv(indio_dev); | 500 | chip = iio_priv(indio_dev); |
497 | 501 | ||
498 | i2c_set_clientdata(client, indio_dev); | 502 | i2c_set_clientdata(client, indio_dev); |
499 | chip->dev = &client->dev; | ||
500 | mutex_init(&chip->lock); | 503 | mutex_init(&chip->lock); |
501 | 504 | ||
502 | chip->regmap = devm_regmap_init_i2c(client, &isl29028_regmap_config); | 505 | chip->regmap = devm_regmap_init_i2c(client, &isl29028_regmap_config); |
503 | if (IS_ERR(chip->regmap)) { | 506 | if (IS_ERR(chip->regmap)) { |
504 | ret = PTR_ERR(chip->regmap); | 507 | ret = PTR_ERR(chip->regmap); |
505 | dev_err(chip->dev, "regmap initialization failed: %d\n", ret); | 508 | dev_err(&client->dev, "regmap initialization failed: %d\n", |
509 | ret); | ||
506 | return ret; | 510 | return ret; |
507 | } | 511 | } |
508 | 512 | ||
509 | ret = isl29028_chip_init(chip); | 513 | ret = isl29028_chip_init(chip); |
510 | if (ret < 0) { | 514 | if (ret < 0) { |
511 | dev_err(chip->dev, "chip initialization failed: %d\n", ret); | 515 | dev_err(&client->dev, "chip initialization failed: %d\n", ret); |
512 | return ret; | 516 | return ret; |
513 | } | 517 | } |
514 | 518 | ||
@@ -520,7 +524,8 @@ static int isl29028_probe(struct i2c_client *client, | |||
520 | indio_dev->modes = INDIO_DIRECT_MODE; | 524 | indio_dev->modes = INDIO_DIRECT_MODE; |
521 | ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev); | 525 | ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev); |
522 | if (ret < 0) { | 526 | if (ret < 0) { |
523 | dev_err(chip->dev, "iio registration fails with error %d\n", | 527 | dev_err(&client->dev, |
528 | "iio registration fails with error %d\n", | ||
524 | ret); | 529 | ret); |
525 | return ret; | 530 | return ret; |
526 | } | 531 | } |
diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c index 9a24e0226f8b..a6b76d4b1c80 100644 --- a/drivers/staging/iio/meter/ade7758_ring.c +++ b/drivers/staging/iio/meter/ade7758_ring.c | |||
@@ -33,7 +33,7 @@ static int ade7758_spi_read_burst(struct iio_dev *indio_dev) | |||
33 | return ret; | 33 | return ret; |
34 | } | 34 | } |
35 | 35 | ||
36 | static int ade7758_write_waveform_type(struct device *dev, unsigned type) | 36 | static int ade7758_write_waveform_type(struct device *dev, unsigned int type) |
37 | { | 37 | { |
38 | int ret; | 38 | int ret; |
39 | u8 reg; | 39 | u8 reg; |
@@ -85,7 +85,7 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p) | |||
85 | **/ | 85 | **/ |
86 | static int ade7758_ring_preenable(struct iio_dev *indio_dev) | 86 | static int ade7758_ring_preenable(struct iio_dev *indio_dev) |
87 | { | 87 | { |
88 | unsigned channel; | 88 | unsigned int channel; |
89 | 89 | ||
90 | if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) | 90 | if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) |
91 | return -EINVAL; | 91 | return -EINVAL; |
diff --git a/drivers/staging/iio/resolver/ad2s1210.h b/drivers/staging/iio/resolver/ad2s1210.h index c7158f6e61c2..e9b2147701fc 100644 --- a/drivers/staging/iio/resolver/ad2s1210.h +++ b/drivers/staging/iio/resolver/ad2s1210.h | |||
@@ -12,9 +12,9 @@ | |||
12 | #define _AD2S1210_H | 12 | #define _AD2S1210_H |
13 | 13 | ||
14 | struct ad2s1210_platform_data { | 14 | struct ad2s1210_platform_data { |
15 | unsigned sample; | 15 | unsigned int sample; |
16 | unsigned a[2]; | 16 | unsigned int a[2]; |
17 | unsigned res[2]; | 17 | unsigned int res[2]; |
18 | bool gpioin; | 18 | bool gpioin; |
19 | }; | 19 | }; |
20 | #endif /* _AD2S1210_H */ | 20 | #endif /* _AD2S1210_H */ |
diff --git a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c index 8667334f3f41..38dca69a06eb 100644 --- a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c +++ b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c | |||
@@ -55,12 +55,12 @@ static struct bfin_timer iio_bfin_timer_code[MAX_BLACKFIN_GPTIMERS] = { | |||
55 | }; | 55 | }; |
56 | 56 | ||
57 | struct bfin_tmr_state { | 57 | struct bfin_tmr_state { |
58 | struct iio_trigger *trig; | 58 | struct iio_trigger *trig; |
59 | struct bfin_timer *t; | 59 | struct bfin_timer *t; |
60 | unsigned timer_num; | 60 | unsigned int timer_num; |
61 | bool output_enable; | 61 | bool output_enable; |
62 | unsigned int duty; | 62 | unsigned int duty; |
63 | int irq; | 63 | int irq; |
64 | }; | 64 | }; |
65 | 65 | ||
66 | static int iio_bfin_tmr_set_state(struct iio_trigger *trig, bool state) | 66 | static int iio_bfin_tmr_set_state(struct iio_trigger *trig, bool state) |