diff options
26 files changed, 781 insertions, 158 deletions
diff --git a/Documentation/devicetree/bindings/arm/atmel-adc.txt b/Documentation/devicetree/bindings/arm/atmel-adc.txt index d1061469f63d..9a1175b46f49 100644 --- a/Documentation/devicetree/bindings/arm/atmel-adc.txt +++ b/Documentation/devicetree/bindings/arm/atmel-adc.txt | |||
@@ -5,6 +5,9 @@ Required properties: | |||
5 | <chip> can be "at91sam9260", "at91sam9g45" or "at91sam9x5" | 5 | <chip> can be "at91sam9260", "at91sam9g45" or "at91sam9x5" |
6 | - reg: Should contain ADC registers location and length | 6 | - reg: Should contain ADC registers location and length |
7 | - interrupts: Should contain the IRQ line for the ADC | 7 | - interrupts: Should contain the IRQ line for the ADC |
8 | - clock-names: tuple listing input clock names. | ||
9 | Required elements: "adc_clk", "adc_op_clk". | ||
10 | - clocks: phandles to input clocks. | ||
8 | - atmel,adc-channels-used: Bitmask of the channels muxed and enable for this | 11 | - atmel,adc-channels-used: Bitmask of the channels muxed and enable for this |
9 | device | 12 | device |
10 | - atmel,adc-startup-time: Startup Time of the ADC in microseconds as | 13 | - atmel,adc-startup-time: Startup Time of the ADC in microseconds as |
@@ -44,6 +47,8 @@ adc0: adc@fffb0000 { | |||
44 | compatible = "atmel,at91sam9260-adc"; | 47 | compatible = "atmel,at91sam9260-adc"; |
45 | reg = <0xfffb0000 0x100>; | 48 | reg = <0xfffb0000 0x100>; |
46 | interrupts = <20 4>; | 49 | interrupts = <20 4>; |
50 | clocks = <&adc_clk>, <&adc_op_clk>; | ||
51 | clock-names = "adc_clk", "adc_op_clk"; | ||
47 | atmel,adc-channel-base = <0x30>; | 52 | atmel,adc-channel-base = <0x30>; |
48 | atmel,adc-channels-used = <0xff>; | 53 | atmel,adc-channels-used = <0xff>; |
49 | atmel,adc-drdy-mask = <0x10000>; | 54 | atmel,adc-drdy-mask = <0x10000>; |
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 360259266d4f..ce84b012f7df 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c | |||
@@ -8,17 +8,11 @@ | |||
8 | * based on linux/drivers/acron/char/pcf8583.c | 8 | * based on linux/drivers/acron/char/pcf8583.c |
9 | * Copyright (C) 2000 Russell King | 9 | * Copyright (C) 2000 Russell King |
10 | * | 10 | * |
11 | * Driver for max1363 and similar chips. | ||
12 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | 13 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License version 2 as | 14 | * it under the terms of the GNU General Public License version 2 as |
13 | * published by the Free Software Foundation. | 15 | * published by the Free Software Foundation. |
14 | * | ||
15 | * max1363.c | ||
16 | * | ||
17 | * Partial support for max1363 and similar chips. | ||
18 | * | ||
19 | * Not currently implemented. | ||
20 | * | ||
21 | * - Control of internal reference. | ||
22 | */ | 16 | */ |
23 | 17 | ||
24 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c index 31e786e3999b..a4db3026bec6 100644 --- a/drivers/iio/adc/ti_am335x_adc.c +++ b/drivers/iio/adc/ti_am335x_adc.c | |||
@@ -13,7 +13,6 @@ | |||
13 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
18 | #include <linux/err.h> | 17 | #include <linux/err.h> |
19 | #include <linux/module.h> | 18 | #include <linux/module.h> |
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c index 53a24ebb92c3..15282f148b3b 100644 --- a/drivers/iio/adc/twl6030-gpadc.c +++ b/drivers/iio/adc/twl6030-gpadc.c | |||
@@ -28,7 +28,6 @@ | |||
28 | * 02110-1301 USA | 28 | * 02110-1301 USA |
29 | * | 29 | * |
30 | */ | 30 | */ |
31 | #include <linux/init.h> | ||
32 | #include <linux/interrupt.h> | 31 | #include <linux/interrupt.h> |
33 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
34 | #include <linux/module.h> | 33 | #include <linux/module.h> |
diff --git a/drivers/iio/adc/viperboard_adc.c b/drivers/iio/adc/viperboard_adc.c index d0add8f9416b..9acf6b6d705b 100644 --- a/drivers/iio/adc/viperboard_adc.c +++ b/drivers/iio/adc/viperboard_adc.c | |||
@@ -139,8 +139,6 @@ static int vprbrd_adc_probe(struct platform_device *pdev) | |||
139 | return ret; | 139 | return ret; |
140 | } | 140 | } |
141 | 141 | ||
142 | platform_set_drvdata(pdev, indio_dev); | ||
143 | |||
144 | return 0; | 142 | return 0; |
145 | } | 143 | } |
146 | 144 | ||
diff --git a/drivers/iio/dac/ad7303.c b/drivers/iio/dac/ad7303.c index d0505fd22ef4..fa2810032968 100644 --- a/drivers/iio/dac/ad7303.c +++ b/drivers/iio/dac/ad7303.c | |||
@@ -92,7 +92,7 @@ static ssize_t ad7303_write_dac_powerdown(struct iio_dev *indio_dev, | |||
92 | ad7303_write(st, chan->channel, st->dac_cache[chan->channel]); | 92 | ad7303_write(st, chan->channel, st->dac_cache[chan->channel]); |
93 | 93 | ||
94 | mutex_unlock(&indio_dev->mlock); | 94 | mutex_unlock(&indio_dev->mlock); |
95 | return ret ? ret : len; | 95 | return len; |
96 | } | 96 | } |
97 | 97 | ||
98 | static int ad7303_get_vref(struct ad7303_state *st, | 98 | static int ad7303_get_vref(struct ad7303_state *st, |
diff --git a/drivers/iio/dac/max517.c b/drivers/iio/dac/max517.c index de76e6a34c1e..9a82a7255ebb 100644 --- a/drivers/iio/dac/max517.c +++ b/drivers/iio/dac/max517.c | |||
@@ -19,7 +19,6 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/init.h> | ||
23 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
24 | #include <linux/jiffies.h> | 23 | #include <linux/jiffies.h> |
25 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c index 7d9f5c31d2fc..43d14588448d 100644 --- a/drivers/iio/dac/mcp4725.c +++ b/drivers/iio/dac/mcp4725.c | |||
@@ -15,7 +15,6 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/init.h> | ||
19 | #include <linux/i2c.h> | 18 | #include <linux/i2c.h> |
20 | #include <linux/err.h> | 19 | #include <linux/err.h> |
21 | #include <linux/delay.h> | 20 | #include <linux/delay.h> |
diff --git a/drivers/iio/humidity/Kconfig b/drivers/iio/humidity/Kconfig index 463c4d9da79e..e116bd8dd0e4 100644 --- a/drivers/iio/humidity/Kconfig +++ b/drivers/iio/humidity/Kconfig | |||
@@ -12,4 +12,14 @@ config DHT11 | |||
12 | Other sensors should work as well as long as they speak the | 12 | Other sensors should work as well as long as they speak the |
13 | same protocol. | 13 | same protocol. |
14 | 14 | ||
15 | config SI7005 | ||
16 | tristate "SI7005 relative humidity and temperature sensor" | ||
17 | depends on I2C | ||
18 | help | ||
19 | Say yes here to build support for the Silabs Si7005 relative | ||
20 | humidity and temperature sensor. | ||
21 | |||
22 | To compile this driver as a module, choose M here: the module | ||
23 | will be called si7005. | ||
24 | |||
15 | endmenu | 25 | endmenu |
diff --git a/drivers/iio/humidity/Makefile b/drivers/iio/humidity/Makefile index d5d36c0c95f9..e3f3d942e646 100644 --- a/drivers/iio/humidity/Makefile +++ b/drivers/iio/humidity/Makefile | |||
@@ -3,3 +3,4 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | obj-$(CONFIG_DHT11) += dht11.o | 5 | obj-$(CONFIG_DHT11) += dht11.o |
6 | obj-$(CONFIG_SI7005) += si7005.o | ||
diff --git a/drivers/iio/humidity/si7005.c b/drivers/iio/humidity/si7005.c new file mode 100644 index 000000000000..bdd586e6d955 --- /dev/null +++ b/drivers/iio/humidity/si7005.c | |||
@@ -0,0 +1,189 @@ | |||
1 | /* | ||
2 | * si7005.c - Support for Silabs Si7005 humidity and temperature sensor | ||
3 | * | ||
4 | * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net> | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of version 2 of | ||
7 | * the GNU General Public License. See the file COPYING in the main | ||
8 | * directory of this archive for more details. | ||
9 | * | ||
10 | * (7-bit I2C slave address 0x40) | ||
11 | * | ||
12 | * TODO: heater, fast mode, processed mode (temp. / linearity compensation) | ||
13 | */ | ||
14 | |||
15 | #include <linux/err.h> | ||
16 | #include <linux/i2c.h> | ||
17 | #include <linux/delay.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/pm.h> | ||
20 | |||
21 | #include <linux/iio/iio.h> | ||
22 | #include <linux/iio/sysfs.h> | ||
23 | |||
24 | #define SI7005_STATUS 0x00 | ||
25 | #define SI7005_DATA 0x01 /* 16-bit, MSB */ | ||
26 | #define SI7005_CONFIG 0x03 | ||
27 | #define SI7005_ID 0x11 | ||
28 | |||
29 | #define SI7005_STATUS_NRDY BIT(0) | ||
30 | #define SI7005_CONFIG_TEMP BIT(4) | ||
31 | #define SI7005_CONFIG_START BIT(0) | ||
32 | |||
33 | #define SI7005_ID_7005 0x50 | ||
34 | #define SI7005_ID_7015 0xf0 | ||
35 | |||
36 | struct si7005_data { | ||
37 | struct i2c_client *client; | ||
38 | struct mutex lock; | ||
39 | u8 config; | ||
40 | }; | ||
41 | |||
42 | static int si7005_read_measurement(struct si7005_data *data, bool temp) | ||
43 | { | ||
44 | int tries = 50; | ||
45 | int ret; | ||
46 | |||
47 | mutex_lock(&data->lock); | ||
48 | |||
49 | ret = i2c_smbus_write_byte_data(data->client, SI7005_CONFIG, | ||
50 | data->config | SI7005_CONFIG_START | | ||
51 | (temp ? SI7005_CONFIG_TEMP : 0)); | ||
52 | if (ret < 0) | ||
53 | goto done; | ||
54 | |||
55 | while (tries-- > 0) { | ||
56 | msleep(20); | ||
57 | ret = i2c_smbus_read_byte_data(data->client, SI7005_STATUS); | ||
58 | if (ret < 0) | ||
59 | goto done; | ||
60 | if (!(ret & SI7005_STATUS_NRDY)) | ||
61 | break; | ||
62 | } | ||
63 | if (tries < 0) { | ||
64 | ret = -EIO; | ||
65 | goto done; | ||
66 | } | ||
67 | |||
68 | ret = i2c_smbus_read_word_swapped(data->client, SI7005_DATA); | ||
69 | |||
70 | done: | ||
71 | mutex_unlock(&data->lock); | ||
72 | |||
73 | return ret; | ||
74 | } | ||
75 | |||
76 | static int si7005_read_raw(struct iio_dev *indio_dev, | ||
77 | struct iio_chan_spec const *chan, int *val, | ||
78 | int *val2, long mask) | ||
79 | { | ||
80 | struct si7005_data *data = iio_priv(indio_dev); | ||
81 | int ret; | ||
82 | |||
83 | switch (mask) { | ||
84 | case IIO_CHAN_INFO_RAW: | ||
85 | ret = si7005_read_measurement(data, chan->type == IIO_TEMP); | ||
86 | if (ret < 0) | ||
87 | return ret; | ||
88 | *val = ret; | ||
89 | return IIO_VAL_INT; | ||
90 | case IIO_CHAN_INFO_SCALE: | ||
91 | if (chan->type == IIO_TEMP) { | ||
92 | *val = 7; | ||
93 | *val2 = 812500; | ||
94 | } else { | ||
95 | *val = 3; | ||
96 | *val2 = 906250; | ||
97 | } | ||
98 | return IIO_VAL_INT_PLUS_MICRO; | ||
99 | case IIO_CHAN_INFO_OFFSET: | ||
100 | if (chan->type == IIO_TEMP) | ||
101 | *val = -50 * 32 * 4; | ||
102 | else | ||
103 | *val = -24 * 16 * 16; | ||
104 | return IIO_VAL_INT; | ||
105 | default: | ||
106 | break; | ||
107 | } | ||
108 | |||
109 | return -EINVAL; | ||
110 | } | ||
111 | |||
112 | static const struct iio_chan_spec si7005_channels[] = { | ||
113 | { | ||
114 | .type = IIO_HUMIDITYRELATIVE, | ||
115 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | ||
116 | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET), | ||
117 | }, | ||
118 | { | ||
119 | .type = IIO_TEMP, | ||
120 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | ||
121 | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET), | ||
122 | } | ||
123 | }; | ||
124 | |||
125 | static const struct iio_info si7005_info = { | ||
126 | .read_raw = si7005_read_raw, | ||
127 | .driver_module = THIS_MODULE, | ||
128 | }; | ||
129 | |||
130 | static int si7005_probe(struct i2c_client *client, | ||
131 | const struct i2c_device_id *id) | ||
132 | { | ||
133 | struct iio_dev *indio_dev; | ||
134 | struct si7005_data *data; | ||
135 | int ret; | ||
136 | |||
137 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) | ||
138 | return -ENODEV; | ||
139 | |||
140 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); | ||
141 | if (!indio_dev) | ||
142 | return -ENOMEM; | ||
143 | |||
144 | data = iio_priv(indio_dev); | ||
145 | i2c_set_clientdata(client, indio_dev); | ||
146 | data->client = client; | ||
147 | mutex_init(&data->lock); | ||
148 | |||
149 | indio_dev->dev.parent = &client->dev; | ||
150 | indio_dev->name = dev_name(&client->dev); | ||
151 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
152 | indio_dev->info = &si7005_info; | ||
153 | |||
154 | indio_dev->channels = si7005_channels; | ||
155 | indio_dev->num_channels = ARRAY_SIZE(si7005_channels); | ||
156 | |||
157 | ret = i2c_smbus_read_byte_data(client, SI7005_ID); | ||
158 | if (ret < 0) | ||
159 | return ret; | ||
160 | if (ret != SI7005_ID_7005 && ret != SI7005_ID_7015) | ||
161 | return -ENODEV; | ||
162 | |||
163 | ret = i2c_smbus_read_byte_data(client, SI7005_CONFIG); | ||
164 | if (ret < 0) | ||
165 | return ret; | ||
166 | data->config = ret; | ||
167 | |||
168 | return devm_iio_device_register(&client->dev, indio_dev); | ||
169 | } | ||
170 | |||
171 | static const struct i2c_device_id si7005_id[] = { | ||
172 | { "si7005", 0 }, | ||
173 | { } | ||
174 | }; | ||
175 | MODULE_DEVICE_TABLE(i2c, si7005_id); | ||
176 | |||
177 | static struct i2c_driver si7005_driver = { | ||
178 | .driver = { | ||
179 | .name = "si7005", | ||
180 | .owner = THIS_MODULE, | ||
181 | }, | ||
182 | .probe = si7005_probe, | ||
183 | .id_table = si7005_id, | ||
184 | }; | ||
185 | module_i2c_driver(si7005_driver); | ||
186 | |||
187 | MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); | ||
188 | MODULE_DESCRIPTION("Silabs Si7005 humidity and temperature sensor driver"); | ||
189 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig index 663e88a1a3c1..2b0e45133e9d 100644 --- a/drivers/iio/imu/Kconfig +++ b/drivers/iio/imu/Kconfig | |||
@@ -25,6 +25,8 @@ config ADIS16480 | |||
25 | Say yes here to build support for Analog Devices ADIS16375, ADIS16480, | 25 | Say yes here to build support for Analog Devices ADIS16375, ADIS16480, |
26 | ADIS16485, ADIS16488 inertial sensors. | 26 | ADIS16485, ADIS16488 inertial sensors. |
27 | 27 | ||
28 | source "drivers/iio/imu/inv_mpu6050/Kconfig" | ||
29 | |||
28 | endmenu | 30 | endmenu |
29 | 31 | ||
30 | config IIO_ADIS_LIB | 32 | config IIO_ADIS_LIB |
@@ -38,5 +40,3 @@ config IIO_ADIS_LIB_BUFFER | |||
38 | help | 40 | help |
39 | A set of buffer helper functions for the Analog Devices ADIS* device | 41 | A set of buffer helper functions for the Analog Devices ADIS* device |
40 | family. | 42 | family. |
41 | |||
42 | source "drivers/iio/imu/inv_mpu6050/Kconfig" | ||
diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c index 7c582f7ae34e..433583b6f800 100644 --- a/drivers/iio/imu/adis16400_core.c +++ b/drivers/iio/imu/adis16400_core.c | |||
@@ -281,7 +281,7 @@ static ssize_t adis16400_write_frequency(struct device *dev, | |||
281 | st->variant->set_freq(st, val); | 281 | st->variant->set_freq(st, val); |
282 | mutex_unlock(&indio_dev->mlock); | 282 | mutex_unlock(&indio_dev->mlock); |
283 | 283 | ||
284 | return ret ? ret : len; | 284 | return len; |
285 | } | 285 | } |
286 | 286 | ||
287 | /* Power down the device */ | 287 | /* Power down the device */ |
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index df7f1e1157ae..cb9f96b446a5 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | |||
@@ -12,7 +12,6 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/init.h> | ||
16 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
17 | #include <linux/i2c.h> | 16 | #include <linux/i2c.h> |
18 | #include <linux/err.h> | 17 | #include <linux/err.h> |
@@ -117,7 +116,7 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask) | |||
117 | return result; | 116 | return result; |
118 | 117 | ||
119 | if (en) { | 118 | if (en) { |
120 | /* Wait for output stablize */ | 119 | /* Wait for output stabilize */ |
121 | msleep(INV_MPU6050_TEMP_UP_TIME); | 120 | msleep(INV_MPU6050_TEMP_UP_TIME); |
122 | if (INV_MPU6050_BIT_PWR_GYRO_STBY == mask) { | 121 | if (INV_MPU6050_BIT_PWR_GYRO_STBY == mask) { |
123 | /* switch internal clock to PLL */ | 122 | /* switch internal clock to PLL */ |
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index f38395529a44..0ab382be1e64 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | |||
@@ -126,35 +126,35 @@ struct inv_mpu6050_state { | |||
126 | #define INV_MPU6050_REG_SAMPLE_RATE_DIV 0x19 | 126 | #define INV_MPU6050_REG_SAMPLE_RATE_DIV 0x19 |
127 | #define INV_MPU6050_REG_CONFIG 0x1A | 127 | #define INV_MPU6050_REG_CONFIG 0x1A |
128 | #define INV_MPU6050_REG_GYRO_CONFIG 0x1B | 128 | #define INV_MPU6050_REG_GYRO_CONFIG 0x1B |
129 | #define INV_MPU6050_REG_ACCEL_CONFIG 0x1C | 129 | #define INV_MPU6050_REG_ACCEL_CONFIG 0x1C |
130 | 130 | ||
131 | #define INV_MPU6050_REG_FIFO_EN 0x23 | 131 | #define INV_MPU6050_REG_FIFO_EN 0x23 |
132 | #define INV_MPU6050_BIT_ACCEL_OUT 0x08 | 132 | #define INV_MPU6050_BIT_ACCEL_OUT 0x08 |
133 | #define INV_MPU6050_BITS_GYRO_OUT 0x70 | 133 | #define INV_MPU6050_BITS_GYRO_OUT 0x70 |
134 | 134 | ||
135 | #define INV_MPU6050_REG_INT_ENABLE 0x38 | 135 | #define INV_MPU6050_REG_INT_ENABLE 0x38 |
136 | #define INV_MPU6050_BIT_DATA_RDY_EN 0x01 | 136 | #define INV_MPU6050_BIT_DATA_RDY_EN 0x01 |
137 | #define INV_MPU6050_BIT_DMP_INT_EN 0x02 | 137 | #define INV_MPU6050_BIT_DMP_INT_EN 0x02 |
138 | 138 | ||
139 | #define INV_MPU6050_REG_RAW_ACCEL 0x3B | 139 | #define INV_MPU6050_REG_RAW_ACCEL 0x3B |
140 | #define INV_MPU6050_REG_TEMPERATURE 0x41 | 140 | #define INV_MPU6050_REG_TEMPERATURE 0x41 |
141 | #define INV_MPU6050_REG_RAW_GYRO 0x43 | 141 | #define INV_MPU6050_REG_RAW_GYRO 0x43 |
142 | 142 | ||
143 | #define INV_MPU6050_REG_USER_CTRL 0x6A | 143 | #define INV_MPU6050_REG_USER_CTRL 0x6A |
144 | #define INV_MPU6050_BIT_FIFO_RST 0x04 | 144 | #define INV_MPU6050_BIT_FIFO_RST 0x04 |
145 | #define INV_MPU6050_BIT_DMP_RST 0x08 | 145 | #define INV_MPU6050_BIT_DMP_RST 0x08 |
146 | #define INV_MPU6050_BIT_I2C_MST_EN 0x20 | 146 | #define INV_MPU6050_BIT_I2C_MST_EN 0x20 |
147 | #define INV_MPU6050_BIT_FIFO_EN 0x40 | 147 | #define INV_MPU6050_BIT_FIFO_EN 0x40 |
148 | #define INV_MPU6050_BIT_DMP_EN 0x80 | 148 | #define INV_MPU6050_BIT_DMP_EN 0x80 |
149 | 149 | ||
150 | #define INV_MPU6050_REG_PWR_MGMT_1 0x6B | 150 | #define INV_MPU6050_REG_PWR_MGMT_1 0x6B |
151 | #define INV_MPU6050_BIT_H_RESET 0x80 | 151 | #define INV_MPU6050_BIT_H_RESET 0x80 |
152 | #define INV_MPU6050_BIT_SLEEP 0x40 | 152 | #define INV_MPU6050_BIT_SLEEP 0x40 |
153 | #define INV_MPU6050_BIT_CLK_MASK 0x7 | 153 | #define INV_MPU6050_BIT_CLK_MASK 0x7 |
154 | 154 | ||
155 | #define INV_MPU6050_REG_PWR_MGMT_2 0x6C | 155 | #define INV_MPU6050_REG_PWR_MGMT_2 0x6C |
156 | #define INV_MPU6050_BIT_PWR_ACCL_STBY 0x38 | 156 | #define INV_MPU6050_BIT_PWR_ACCL_STBY 0x38 |
157 | #define INV_MPU6050_BIT_PWR_GYRO_STBY 0x07 | 157 | #define INV_MPU6050_BIT_PWR_GYRO_STBY 0x07 |
158 | 158 | ||
159 | #define INV_MPU6050_REG_FIFO_COUNT_H 0x72 | 159 | #define INV_MPU6050_REG_FIFO_COUNT_H 0x72 |
160 | #define INV_MPU6050_REG_FIFO_R_W 0x74 | 160 | #define INV_MPU6050_REG_FIFO_R_W 0x74 |
@@ -180,10 +180,10 @@ struct inv_mpu6050_state { | |||
180 | 180 | ||
181 | /* init parameters */ | 181 | /* init parameters */ |
182 | #define INV_MPU6050_INIT_FIFO_RATE 50 | 182 | #define INV_MPU6050_INIT_FIFO_RATE 50 |
183 | #define INV_MPU6050_TIME_STAMP_TOR 5 | 183 | #define INV_MPU6050_TIME_STAMP_TOR 5 |
184 | #define INV_MPU6050_MAX_FIFO_RATE 1000 | 184 | #define INV_MPU6050_MAX_FIFO_RATE 1000 |
185 | #define INV_MPU6050_MIN_FIFO_RATE 4 | 185 | #define INV_MPU6050_MIN_FIFO_RATE 4 |
186 | #define INV_MPU6050_ONE_K_HZ 1000 | 186 | #define INV_MPU6050_ONE_K_HZ 1000 |
187 | 187 | ||
188 | /* scan element definition */ | 188 | /* scan element definition */ |
189 | enum inv_mpu6050_scan { | 189 | enum inv_mpu6050_scan { |
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index 429517117eff..0cd306a72a6e 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | |||
@@ -12,7 +12,6 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/init.h> | ||
16 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
17 | #include <linux/i2c.h> | 16 | #include <linux/i2c.h> |
18 | #include <linux/err.h> | 17 | #include <linux/err.h> |
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index d12b2a0dbfbc..3a7a5d9f03a3 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig | |||
@@ -90,6 +90,18 @@ config SENSORS_LM3533 | |||
90 | changes. The ALS-control output values can be set per zone for the | 90 | changes. The ALS-control output values can be set per zone for the |
91 | three current output channels. | 91 | three current output channels. |
92 | 92 | ||
93 | config LTR501 | ||
94 | tristate "LTR-501ALS-01 light sensor" | ||
95 | depends on I2C | ||
96 | select IIO_BUFFER | ||
97 | select IIO_TRIGGERED_BUFFER | ||
98 | help | ||
99 | If you say yes here you get support for the Lite-On LTR-501ALS-01 | ||
100 | ambient light and proximity sensor. | ||
101 | |||
102 | This driver can also be built as a module. If so, the module | ||
103 | will be called ltr501. | ||
104 | |||
93 | config TCS3472 | 105 | config TCS3472 |
94 | tristate "TAOS TCS3472 color light-to-digital converter" | 106 | tristate "TAOS TCS3472 color light-to-digital converter" |
95 | depends on I2C | 107 | depends on I2C |
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 60e35ac07ff0..924530597f83 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile | |||
@@ -10,6 +10,7 @@ obj-$(CONFIG_CM36651) += cm36651.o | |||
10 | obj-$(CONFIG_GP2AP020A00F) += gp2ap020a00f.o | 10 | obj-$(CONFIG_GP2AP020A00F) += gp2ap020a00f.o |
11 | obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o | 11 | obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o |
12 | obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o | 12 | obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o |
13 | obj-$(CONFIG_LTR501) += ltr501.o | ||
13 | obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o | 14 | obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o |
14 | obj-$(CONFIG_TCS3472) += tcs3472.o | 15 | obj-$(CONFIG_TCS3472) += tcs3472.o |
15 | obj-$(CONFIG_TSL4531) += tsl4531.o | 16 | obj-$(CONFIG_TSL4531) += tsl4531.o |
diff --git a/drivers/iio/light/adjd_s311.c b/drivers/iio/light/adjd_s311.c index f3068477b466..09ad5f1ce539 100644 --- a/drivers/iio/light/adjd_s311.c +++ b/drivers/iio/light/adjd_s311.c | |||
@@ -14,7 +14,6 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/init.h> | ||
18 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
19 | #include <linux/i2c.h> | 18 | #include <linux/i2c.h> |
20 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
@@ -120,7 +119,6 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p) | |||
120 | struct iio_dev *indio_dev = pf->indio_dev; | 119 | struct iio_dev *indio_dev = pf->indio_dev; |
121 | struct adjd_s311_data *data = iio_priv(indio_dev); | 120 | struct adjd_s311_data *data = iio_priv(indio_dev); |
122 | s64 time_ns = iio_get_time_ns(); | 121 | s64 time_ns = iio_get_time_ns(); |
123 | int len = 0; | ||
124 | int i, j = 0; | 122 | int i, j = 0; |
125 | 123 | ||
126 | int ret = adjd_s311_req_data(indio_dev); | 124 | int ret = adjd_s311_req_data(indio_dev); |
@@ -135,7 +133,6 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p) | |||
135 | goto done; | 133 | goto done; |
136 | 134 | ||
137 | data->buffer[j++] = ret & ADJD_S311_DATA_MASK; | 135 | data->buffer[j++] = ret & ADJD_S311_DATA_MASK; |
138 | len += 2; | ||
139 | } | 136 | } |
140 | 137 | ||
141 | iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, time_ns); | 138 | iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, time_ns); |
diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c new file mode 100644 index 000000000000..62b7072af4de --- /dev/null +++ b/drivers/iio/light/ltr501.c | |||
@@ -0,0 +1,445 @@ | |||
1 | /* | ||
2 | * ltr501.c - Support for Lite-On LTR501 ambient light and proximity sensor | ||
3 | * | ||
4 | * Copyright 2014 Peter Meerwald <pmeerw@pmeerw.net> | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of version 2 of | ||
7 | * the GNU General Public License. See the file COPYING in the main | ||
8 | * directory of this archive for more details. | ||
9 | * | ||
10 | * 7-bit I2C slave address 0x23 | ||
11 | * | ||
12 | * TODO: interrupt, threshold, measurement rate, IR LED characteristics | ||
13 | */ | ||
14 | |||
15 | #include <linux/module.h> | ||
16 | #include <linux/i2c.h> | ||
17 | #include <linux/err.h> | ||
18 | #include <linux/delay.h> | ||
19 | |||
20 | #include <linux/iio/iio.h> | ||
21 | #include <linux/iio/sysfs.h> | ||
22 | #include <linux/iio/trigger_consumer.h> | ||
23 | #include <linux/iio/buffer.h> | ||
24 | #include <linux/iio/triggered_buffer.h> | ||
25 | |||
26 | #define LTR501_DRV_NAME "ltr501" | ||
27 | |||
28 | #define LTR501_ALS_CONTR 0x80 /* ALS operation mode, SW reset */ | ||
29 | #define LTR501_PS_CONTR 0x81 /* PS operation mode */ | ||
30 | #define LTR501_PART_ID 0x86 | ||
31 | #define LTR501_MANUFAC_ID 0x87 | ||
32 | #define LTR501_ALS_DATA1 0x88 /* 16-bit, little endian */ | ||
33 | #define LTR501_ALS_DATA0 0x8a /* 16-bit, little endian */ | ||
34 | #define LTR501_ALS_PS_STATUS 0x8c | ||
35 | #define LTR501_PS_DATA 0x8d /* 16-bit, little endian */ | ||
36 | |||
37 | #define LTR501_ALS_CONTR_SW_RESET BIT(2) | ||
38 | #define LTR501_CONTR_PS_GAIN_MASK (BIT(3) | BIT(2)) | ||
39 | #define LTR501_CONTR_PS_GAIN_SHIFT 2 | ||
40 | #define LTR501_CONTR_ALS_GAIN_MASK BIT(3) | ||
41 | #define LTR501_CONTR_ACTIVE BIT(1) | ||
42 | |||
43 | #define LTR501_STATUS_ALS_RDY BIT(2) | ||
44 | #define LTR501_STATUS_PS_RDY BIT(0) | ||
45 | |||
46 | #define LTR501_PS_DATA_MASK 0x7ff | ||
47 | |||
48 | struct ltr501_data { | ||
49 | struct i2c_client *client; | ||
50 | struct mutex lock_als, lock_ps; | ||
51 | u8 als_contr, ps_contr; | ||
52 | }; | ||
53 | |||
54 | static int ltr501_drdy(struct ltr501_data *data, u8 drdy_mask) | ||
55 | { | ||
56 | int tries = 100; | ||
57 | int ret; | ||
58 | |||
59 | while (tries--) { | ||
60 | ret = i2c_smbus_read_byte_data(data->client, | ||
61 | LTR501_ALS_PS_STATUS); | ||
62 | if (ret < 0) | ||
63 | return ret; | ||
64 | if ((ret & drdy_mask) == drdy_mask) | ||
65 | return 0; | ||
66 | msleep(25); | ||
67 | } | ||
68 | |||
69 | dev_err(&data->client->dev, "ltr501_drdy() failed, data not ready\n"); | ||
70 | return -EIO; | ||
71 | } | ||
72 | |||
73 | static int ltr501_read_als(struct ltr501_data *data, __le16 buf[2]) | ||
74 | { | ||
75 | int ret = ltr501_drdy(data, LTR501_STATUS_ALS_RDY); | ||
76 | if (ret < 0) | ||
77 | return ret; | ||
78 | /* always read both ALS channels in given order */ | ||
79 | return i2c_smbus_read_i2c_block_data(data->client, | ||
80 | LTR501_ALS_DATA1, 2 * sizeof(__le16), (u8 *) buf); | ||
81 | } | ||
82 | |||
83 | static int ltr501_read_ps(struct ltr501_data *data) | ||
84 | { | ||
85 | int ret = ltr501_drdy(data, LTR501_STATUS_PS_RDY); | ||
86 | if (ret < 0) | ||
87 | return ret; | ||
88 | return i2c_smbus_read_word_data(data->client, LTR501_PS_DATA); | ||
89 | } | ||
90 | |||
91 | #define LTR501_INTENSITY_CHANNEL(_idx, _addr, _mod, _shared) { \ | ||
92 | .type = IIO_INTENSITY, \ | ||
93 | .modified = 1, \ | ||
94 | .address = (_addr), \ | ||
95 | .channel2 = (_mod), \ | ||
96 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ | ||
97 | .info_mask_shared_by_type = (_shared), \ | ||
98 | .scan_index = (_idx), \ | ||
99 | .scan_type = { \ | ||
100 | .sign = 'u', \ | ||
101 | .realbits = 16, \ | ||
102 | .storagebits = 16, \ | ||
103 | .endianness = IIO_CPU, \ | ||
104 | } \ | ||
105 | } | ||
106 | |||
107 | static const struct iio_chan_spec ltr501_channels[] = { | ||
108 | LTR501_INTENSITY_CHANNEL(0, LTR501_ALS_DATA0, IIO_MOD_LIGHT_BOTH, 0), | ||
109 | LTR501_INTENSITY_CHANNEL(1, LTR501_ALS_DATA1, IIO_MOD_LIGHT_IR, | ||
110 | BIT(IIO_CHAN_INFO_SCALE)), | ||
111 | { | ||
112 | .type = IIO_PROXIMITY, | ||
113 | .address = LTR501_PS_DATA, | ||
114 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | | ||
115 | BIT(IIO_CHAN_INFO_SCALE), | ||
116 | .scan_index = 2, | ||
117 | .scan_type = { | ||
118 | .sign = 'u', | ||
119 | .realbits = 11, | ||
120 | .storagebits = 16, | ||
121 | .endianness = IIO_CPU, | ||
122 | }, | ||
123 | }, | ||
124 | IIO_CHAN_SOFT_TIMESTAMP(3), | ||
125 | }; | ||
126 | |||
127 | static const int ltr501_ps_gain[4][2] = { | ||
128 | {1, 0}, {0, 250000}, {0, 125000}, {0, 62500} | ||
129 | }; | ||
130 | |||
131 | static int ltr501_read_raw(struct iio_dev *indio_dev, | ||
132 | struct iio_chan_spec const *chan, | ||
133 | int *val, int *val2, long mask) | ||
134 | { | ||
135 | struct ltr501_data *data = iio_priv(indio_dev); | ||
136 | __le16 buf[2]; | ||
137 | int ret, i; | ||
138 | |||
139 | switch (mask) { | ||
140 | case IIO_CHAN_INFO_RAW: | ||
141 | if (iio_buffer_enabled(indio_dev)) | ||
142 | return -EBUSY; | ||
143 | |||
144 | switch (chan->type) { | ||
145 | case IIO_INTENSITY: | ||
146 | mutex_lock(&data->lock_als); | ||
147 | ret = ltr501_read_als(data, buf); | ||
148 | mutex_unlock(&data->lock_als); | ||
149 | if (ret < 0) | ||
150 | return ret; | ||
151 | *val = le16_to_cpu(chan->address == LTR501_ALS_DATA1 ? | ||
152 | buf[0] : buf[1]); | ||
153 | return IIO_VAL_INT; | ||
154 | case IIO_PROXIMITY: | ||
155 | mutex_lock(&data->lock_ps); | ||
156 | ret = ltr501_read_ps(data); | ||
157 | mutex_unlock(&data->lock_ps); | ||
158 | if (ret < 0) | ||
159 | return ret; | ||
160 | *val = ret & LTR501_PS_DATA_MASK; | ||
161 | return IIO_VAL_INT; | ||
162 | default: | ||
163 | return -EINVAL; | ||
164 | } | ||
165 | case IIO_CHAN_INFO_SCALE: | ||
166 | switch (chan->type) { | ||
167 | case IIO_INTENSITY: | ||
168 | if (data->als_contr & LTR501_CONTR_ALS_GAIN_MASK) { | ||
169 | *val = 0; | ||
170 | *val2 = 5000; | ||
171 | return IIO_VAL_INT_PLUS_MICRO; | ||
172 | } else { | ||
173 | *val = 1; | ||
174 | *val2 = 0; | ||
175 | return IIO_VAL_INT; | ||
176 | } | ||
177 | case IIO_PROXIMITY: | ||
178 | i = (data->ps_contr & LTR501_CONTR_PS_GAIN_MASK) >> | ||
179 | LTR501_CONTR_PS_GAIN_SHIFT; | ||
180 | *val = ltr501_ps_gain[i][0]; | ||
181 | *val2 = ltr501_ps_gain[i][1]; | ||
182 | return IIO_VAL_INT_PLUS_MICRO; | ||
183 | default: | ||
184 | return -EINVAL; | ||
185 | } | ||
186 | } | ||
187 | return -EINVAL; | ||
188 | } | ||
189 | |||
190 | static int ltr501_get_ps_gain_index(int val, int val2) | ||
191 | { | ||
192 | int i; | ||
193 | |||
194 | for (i = 0; i < ARRAY_SIZE(ltr501_ps_gain); i++) | ||
195 | if (val == ltr501_ps_gain[i][0] && val2 == ltr501_ps_gain[i][1]) | ||
196 | return i; | ||
197 | |||
198 | return -1; | ||
199 | } | ||
200 | |||
201 | static int ltr501_write_raw(struct iio_dev *indio_dev, | ||
202 | struct iio_chan_spec const *chan, | ||
203 | int val, int val2, long mask) | ||
204 | { | ||
205 | struct ltr501_data *data = iio_priv(indio_dev); | ||
206 | int i; | ||
207 | |||
208 | if (iio_buffer_enabled(indio_dev)) | ||
209 | return -EBUSY; | ||
210 | |||
211 | switch (mask) { | ||
212 | case IIO_CHAN_INFO_SCALE: | ||
213 | switch (chan->type) { | ||
214 | case IIO_INTENSITY: | ||
215 | if (val == 0 && val2 == 5000) | ||
216 | data->als_contr |= LTR501_CONTR_ALS_GAIN_MASK; | ||
217 | else if (val == 1 && val2 == 0) | ||
218 | data->als_contr &= ~LTR501_CONTR_ALS_GAIN_MASK; | ||
219 | else | ||
220 | return -EINVAL; | ||
221 | return i2c_smbus_write_byte_data(data->client, | ||
222 | LTR501_ALS_CONTR, data->als_contr); | ||
223 | case IIO_PROXIMITY: | ||
224 | i = ltr501_get_ps_gain_index(val, val2); | ||
225 | if (i < 0) | ||
226 | return -EINVAL; | ||
227 | data->ps_contr &= ~LTR501_CONTR_PS_GAIN_MASK; | ||
228 | data->ps_contr |= i << LTR501_CONTR_PS_GAIN_SHIFT; | ||
229 | return i2c_smbus_write_byte_data(data->client, | ||
230 | LTR501_PS_CONTR, data->ps_contr); | ||
231 | default: | ||
232 | return -EINVAL; | ||
233 | } | ||
234 | } | ||
235 | return -EINVAL; | ||
236 | } | ||
237 | |||
238 | static IIO_CONST_ATTR(in_proximity_scale_available, "1 0.25 0.125 0.0625"); | ||
239 | static IIO_CONST_ATTR(in_intensity_scale_available, "1 0.005"); | ||
240 | |||
241 | static struct attribute *ltr501_attributes[] = { | ||
242 | &iio_const_attr_in_proximity_scale_available.dev_attr.attr, | ||
243 | &iio_const_attr_in_intensity_scale_available.dev_attr.attr, | ||
244 | NULL | ||
245 | }; | ||
246 | |||
247 | static const struct attribute_group ltr501_attribute_group = { | ||
248 | .attrs = ltr501_attributes, | ||
249 | }; | ||
250 | |||
251 | static const struct iio_info ltr501_info = { | ||
252 | .read_raw = ltr501_read_raw, | ||
253 | .write_raw = ltr501_write_raw, | ||
254 | .attrs = <r501_attribute_group, | ||
255 | .driver_module = THIS_MODULE, | ||
256 | }; | ||
257 | |||
258 | static int ltr501_write_contr(struct i2c_client *client, u8 als_val, u8 ps_val) | ||
259 | { | ||
260 | int ret = i2c_smbus_write_byte_data(client, LTR501_ALS_CONTR, als_val); | ||
261 | if (ret < 0) | ||
262 | return ret; | ||
263 | |||
264 | return i2c_smbus_write_byte_data(client, LTR501_PS_CONTR, ps_val); | ||
265 | } | ||
266 | |||
267 | static irqreturn_t ltr501_trigger_handler(int irq, void *p) | ||
268 | { | ||
269 | struct iio_poll_func *pf = p; | ||
270 | struct iio_dev *indio_dev = pf->indio_dev; | ||
271 | struct ltr501_data *data = iio_priv(indio_dev); | ||
272 | u16 buf[8]; | ||
273 | __le16 als_buf[2]; | ||
274 | u8 mask = 0; | ||
275 | int j = 0; | ||
276 | int ret; | ||
277 | |||
278 | memset(buf, 0, sizeof(buf)); | ||
279 | |||
280 | /* figure out which data needs to be ready */ | ||
281 | if (test_bit(0, indio_dev->active_scan_mask) || | ||
282 | test_bit(1, indio_dev->active_scan_mask)) | ||
283 | mask |= LTR501_STATUS_ALS_RDY; | ||
284 | if (test_bit(2, indio_dev->active_scan_mask)) | ||
285 | mask |= LTR501_STATUS_PS_RDY; | ||
286 | |||
287 | ret = ltr501_drdy(data, mask); | ||
288 | if (ret < 0) | ||
289 | goto done; | ||
290 | |||
291 | if (mask & LTR501_STATUS_ALS_RDY) { | ||
292 | ret = i2c_smbus_read_i2c_block_data(data->client, | ||
293 | LTR501_ALS_DATA1, sizeof(als_buf), (u8 *) als_buf); | ||
294 | if (ret < 0) | ||
295 | return ret; | ||
296 | if (test_bit(0, indio_dev->active_scan_mask)) | ||
297 | buf[j++] = le16_to_cpu(als_buf[1]); | ||
298 | if (test_bit(1, indio_dev->active_scan_mask)) | ||
299 | buf[j++] = le16_to_cpu(als_buf[0]); | ||
300 | } | ||
301 | |||
302 | if (mask & LTR501_STATUS_PS_RDY) { | ||
303 | ret = i2c_smbus_read_word_data(data->client, LTR501_PS_DATA); | ||
304 | if (ret < 0) | ||
305 | goto done; | ||
306 | buf[j++] = ret & LTR501_PS_DATA_MASK; | ||
307 | } | ||
308 | |||
309 | iio_push_to_buffers_with_timestamp(indio_dev, buf, | ||
310 | iio_get_time_ns()); | ||
311 | |||
312 | done: | ||
313 | iio_trigger_notify_done(indio_dev->trig); | ||
314 | |||
315 | return IRQ_HANDLED; | ||
316 | } | ||
317 | |||
318 | static int ltr501_init(struct ltr501_data *data) | ||
319 | { | ||
320 | int ret; | ||
321 | |||
322 | ret = i2c_smbus_read_byte_data(data->client, LTR501_ALS_CONTR); | ||
323 | if (ret < 0) | ||
324 | return ret; | ||
325 | data->als_contr = ret | LTR501_CONTR_ACTIVE; | ||
326 | |||
327 | ret = i2c_smbus_read_byte_data(data->client, LTR501_PS_CONTR); | ||
328 | if (ret < 0) | ||
329 | return ret; | ||
330 | data->ps_contr = ret | LTR501_CONTR_ACTIVE; | ||
331 | |||
332 | return ltr501_write_contr(data->client, data->als_contr, | ||
333 | data->ps_contr); | ||
334 | } | ||
335 | |||
336 | static int ltr501_probe(struct i2c_client *client, | ||
337 | const struct i2c_device_id *id) | ||
338 | { | ||
339 | struct ltr501_data *data; | ||
340 | struct iio_dev *indio_dev; | ||
341 | int ret; | ||
342 | |||
343 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); | ||
344 | if (!indio_dev) | ||
345 | return -ENOMEM; | ||
346 | |||
347 | data = iio_priv(indio_dev); | ||
348 | i2c_set_clientdata(client, indio_dev); | ||
349 | data->client = client; | ||
350 | mutex_init(&data->lock_als); | ||
351 | mutex_init(&data->lock_ps); | ||
352 | |||
353 | ret = i2c_smbus_read_byte_data(data->client, LTR501_PART_ID); | ||
354 | if (ret < 0) | ||
355 | return ret; | ||
356 | if ((ret >> 4) != 0x8) | ||
357 | return -ENODEV; | ||
358 | |||
359 | indio_dev->dev.parent = &client->dev; | ||
360 | indio_dev->info = <r501_info; | ||
361 | indio_dev->channels = ltr501_channels; | ||
362 | indio_dev->num_channels = ARRAY_SIZE(ltr501_channels); | ||
363 | indio_dev->name = LTR501_DRV_NAME; | ||
364 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
365 | |||
366 | ret = ltr501_init(data); | ||
367 | if (ret < 0) | ||
368 | return ret; | ||
369 | |||
370 | ret = iio_triggered_buffer_setup(indio_dev, NULL, | ||
371 | ltr501_trigger_handler, NULL); | ||
372 | if (ret) | ||
373 | return ret; | ||
374 | |||
375 | ret = iio_device_register(indio_dev); | ||
376 | if (ret) | ||
377 | goto error_unreg_buffer; | ||
378 | |||
379 | return 0; | ||
380 | |||
381 | error_unreg_buffer: | ||
382 | iio_triggered_buffer_cleanup(indio_dev); | ||
383 | return ret; | ||
384 | } | ||
385 | |||
386 | static int ltr501_powerdown(struct ltr501_data *data) | ||
387 | { | ||
388 | return ltr501_write_contr(data->client, | ||
389 | data->als_contr & ~LTR501_CONTR_ACTIVE, | ||
390 | data->ps_contr & ~LTR501_CONTR_ACTIVE); | ||
391 | } | ||
392 | |||
393 | static int ltr501_remove(struct i2c_client *client) | ||
394 | { | ||
395 | struct iio_dev *indio_dev = i2c_get_clientdata(client); | ||
396 | |||
397 | iio_device_unregister(indio_dev); | ||
398 | iio_triggered_buffer_cleanup(indio_dev); | ||
399 | ltr501_powerdown(iio_priv(indio_dev)); | ||
400 | |||
401 | return 0; | ||
402 | } | ||
403 | |||
404 | #ifdef CONFIG_PM_SLEEP | ||
405 | static int ltr501_suspend(struct device *dev) | ||
406 | { | ||
407 | struct ltr501_data *data = iio_priv(i2c_get_clientdata( | ||
408 | to_i2c_client(dev))); | ||
409 | return ltr501_powerdown(data); | ||
410 | } | ||
411 | |||
412 | static int ltr501_resume(struct device *dev) | ||
413 | { | ||
414 | struct ltr501_data *data = iio_priv(i2c_get_clientdata( | ||
415 | to_i2c_client(dev))); | ||
416 | |||
417 | return ltr501_write_contr(data->client, data->als_contr, | ||
418 | data->ps_contr); | ||
419 | } | ||
420 | #endif | ||
421 | |||
422 | static SIMPLE_DEV_PM_OPS(ltr501_pm_ops, ltr501_suspend, ltr501_resume); | ||
423 | |||
424 | static const struct i2c_device_id ltr501_id[] = { | ||
425 | { "ltr501", 0 }, | ||
426 | { } | ||
427 | }; | ||
428 | MODULE_DEVICE_TABLE(i2c, ltr501_id); | ||
429 | |||
430 | static struct i2c_driver ltr501_driver = { | ||
431 | .driver = { | ||
432 | .name = LTR501_DRV_NAME, | ||
433 | .pm = <r501_pm_ops, | ||
434 | .owner = THIS_MODULE, | ||
435 | }, | ||
436 | .probe = ltr501_probe, | ||
437 | .remove = ltr501_remove, | ||
438 | .id_table = ltr501_id, | ||
439 | }; | ||
440 | |||
441 | module_i2c_driver(ltr501_driver); | ||
442 | |||
443 | MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); | ||
444 | MODULE_DESCRIPTION("Lite-On LTR501 ambient light and proximity sensor driver"); | ||
445 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/iio/light/tcs3472.c b/drivers/iio/light/tcs3472.c index 887fecf1f9bb..fe063a0a21cd 100644 --- a/drivers/iio/light/tcs3472.c +++ b/drivers/iio/light/tcs3472.c | |||
@@ -179,7 +179,6 @@ static irqreturn_t tcs3472_trigger_handler(int irq, void *p) | |||
179 | struct iio_poll_func *pf = p; | 179 | struct iio_poll_func *pf = p; |
180 | struct iio_dev *indio_dev = pf->indio_dev; | 180 | struct iio_dev *indio_dev = pf->indio_dev; |
181 | struct tcs3472_data *data = iio_priv(indio_dev); | 181 | struct tcs3472_data *data = iio_priv(indio_dev); |
182 | int len = 0; | ||
183 | int i, j = 0; | 182 | int i, j = 0; |
184 | 183 | ||
185 | int ret = tcs3472_req_data(data); | 184 | int ret = tcs3472_req_data(data); |
@@ -194,7 +193,6 @@ static irqreturn_t tcs3472_trigger_handler(int irq, void *p) | |||
194 | goto done; | 193 | goto done; |
195 | 194 | ||
196 | data->buffer[j++] = ret; | 195 | data->buffer[j++] = ret; |
197 | len += 2; | ||
198 | } | 196 | } |
199 | 197 | ||
200 | iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, | 198 | iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, |
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index 05423543f89d..74866d1efd1b 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c | |||
@@ -513,6 +513,7 @@ static int ak8975_probe(struct i2c_client *client, | |||
513 | indio_dev->channels = ak8975_channels; | 513 | indio_dev->channels = ak8975_channels; |
514 | indio_dev->num_channels = ARRAY_SIZE(ak8975_channels); | 514 | indio_dev->num_channels = ARRAY_SIZE(ak8975_channels); |
515 | indio_dev->info = &ak8975_info; | 515 | indio_dev->info = &ak8975_info; |
516 | indio_dev->name = id->name; | ||
516 | indio_dev->modes = INDIO_DIRECT_MODE; | 517 | indio_dev->modes = INDIO_DIRECT_MODE; |
517 | 518 | ||
518 | err = iio_device_register(indio_dev); | 519 | err = iio_device_register(indio_dev); |
diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c index ac8c8ab723e5..ba6d0c520e63 100644 --- a/drivers/iio/pressure/mpl3115.c +++ b/drivers/iio/pressure/mpl3115.c | |||
@@ -77,7 +77,7 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev, | |||
77 | int *val, int *val2, long mask) | 77 | int *val, int *val2, long mask) |
78 | { | 78 | { |
79 | struct mpl3115_data *data = iio_priv(indio_dev); | 79 | struct mpl3115_data *data = iio_priv(indio_dev); |
80 | s32 tmp = 0; | 80 | __be32 tmp = 0; |
81 | int ret; | 81 | int ret; |
82 | 82 | ||
83 | switch (mask) { | 83 | switch (mask) { |
diff --git a/drivers/staging/iio/accel/sca3000.h b/drivers/staging/iio/accel/sca3000.h index c1016c510dae..b284e5a6cac1 100644 --- a/drivers/staging/iio/accel/sca3000.h +++ b/drivers/staging/iio/accel/sca3000.h | |||
@@ -65,7 +65,8 @@ | |||
65 | 65 | ||
66 | #define SCA3000_RING_BUF_ENABLE 0x80 | 66 | #define SCA3000_RING_BUF_ENABLE 0x80 |
67 | #define SCA3000_RING_BUF_8BIT 0x40 | 67 | #define SCA3000_RING_BUF_8BIT 0x40 |
68 | /* Free fall detection triggers an interrupt if the acceleration | 68 | /* |
69 | * Free fall detection triggers an interrupt if the acceleration | ||
69 | * is below a threshold for equivalent of 25cm drop | 70 | * is below a threshold for equivalent of 25cm drop |
70 | */ | 71 | */ |
71 | #define SCA3000_FREE_FALL_DETECT 0x10 | 72 | #define SCA3000_FREE_FALL_DETECT 0x10 |
@@ -73,8 +74,9 @@ | |||
73 | #define SCA3000_MEAS_MODE_OP_1 0x01 | 74 | #define SCA3000_MEAS_MODE_OP_1 0x01 |
74 | #define SCA3000_MEAS_MODE_OP_2 0x02 | 75 | #define SCA3000_MEAS_MODE_OP_2 0x02 |
75 | 76 | ||
76 | /* In motion detection mode the accelerations are band pass filtered | 77 | /* |
77 | * (aprox 1 - 25Hz) and then a programmable threshold used to trigger | 78 | * In motion detection mode the accelerations are band pass filtered |
79 | * (approx 1 - 25Hz) and then a programmable threshold used to trigger | ||
78 | * and interrupt. | 80 | * and interrupt. |
79 | */ | 81 | */ |
80 | #define SCA3000_MEAS_MODE_MOT_DET 0x03 | 82 | #define SCA3000_MEAS_MODE_MOT_DET 0x03 |
@@ -99,8 +101,10 @@ | |||
99 | #define SCA3000_REG_CTRL_SEL_MD_Y_TH 0x03 | 101 | #define SCA3000_REG_CTRL_SEL_MD_Y_TH 0x03 |
100 | #define SCA3000_REG_CTRL_SEL_MD_X_TH 0x04 | 102 | #define SCA3000_REG_CTRL_SEL_MD_X_TH 0x04 |
101 | #define SCA3000_REG_CTRL_SEL_MD_Z_TH 0x05 | 103 | #define SCA3000_REG_CTRL_SEL_MD_Z_TH 0x05 |
102 | /* BE VERY CAREFUL WITH THIS, IF 3 BITS ARE NOT SET the device | 104 | /* |
103 | will not function */ | 105 | * BE VERY CAREFUL WITH THIS, IF 3 BITS ARE NOT SET the device |
106 | * will not function | ||
107 | */ | ||
104 | #define SCA3000_REG_CTRL_SEL_OUT_CTRL 0x0B | 108 | #define SCA3000_REG_CTRL_SEL_OUT_CTRL 0x0B |
105 | #define SCA3000_OUT_CTRL_PROT_MASK 0xE0 | 109 | #define SCA3000_OUT_CTRL_PROT_MASK 0xE0 |
106 | #define SCA3000_OUT_CTRL_BUF_X_EN 0x10 | 110 | #define SCA3000_OUT_CTRL_BUF_X_EN 0x10 |
@@ -109,8 +113,9 @@ | |||
109 | #define SCA3000_OUT_CTRL_BUF_DIV_4 0x02 | 113 | #define SCA3000_OUT_CTRL_BUF_DIV_4 0x02 |
110 | #define SCA3000_OUT_CTRL_BUF_DIV_2 0x01 | 114 | #define SCA3000_OUT_CTRL_BUF_DIV_2 0x01 |
111 | 115 | ||
112 | /* Control which motion detector interrupts are on. | 116 | /* |
113 | * For now only OR combinations are supported.x | 117 | * Control which motion detector interrupts are on. |
118 | * For now only OR combinations are supported. | ||
114 | */ | 119 | */ |
115 | #define SCA3000_MD_CTRL_PROT_MASK 0xC0 | 120 | #define SCA3000_MD_CTRL_PROT_MASK 0xC0 |
116 | #define SCA3000_MD_CTRL_OR_Y 0x01 | 121 | #define SCA3000_MD_CTRL_OR_Y 0x01 |
@@ -121,7 +126,8 @@ | |||
121 | #define SCA3000_MD_CTRL_AND_X 0x10 | 126 | #define SCA3000_MD_CTRL_AND_X 0x10 |
122 | #define SAC3000_MD_CTRL_AND_Z 0x20 | 127 | #define SAC3000_MD_CTRL_AND_Z 0x20 |
123 | 128 | ||
124 | /* Some control registers of complex access methods requiring this register to | 129 | /* |
130 | * Some control registers of complex access methods requiring this register to | ||
125 | * be used to remove a lock. | 131 | * be used to remove a lock. |
126 | */ | 132 | */ |
127 | #define SCA3000_REG_ADDR_UNLOCK 0x1e | 133 | #define SCA3000_REG_ADDR_UNLOCK 0x1e |
@@ -139,7 +145,8 @@ | |||
139 | /* Values of multiplexed registers (write to ctrl_data after select) */ | 145 | /* Values of multiplexed registers (write to ctrl_data after select) */ |
140 | #define SCA3000_REG_ADDR_CTRL_DATA 0x22 | 146 | #define SCA3000_REG_ADDR_CTRL_DATA 0x22 |
141 | 147 | ||
142 | /* Measurement modes available on some sca3000 series chips. Code assumes others | 148 | /* |
149 | * Measurement modes available on some sca3000 series chips. Code assumes others | ||
143 | * may become available in the future. | 150 | * may become available in the future. |
144 | * | 151 | * |
145 | * Bypass - Bypass the low-pass filter in the signal channel so as to increase | 152 | * Bypass - Bypass the low-pass filter in the signal channel so as to increase |
@@ -160,7 +167,6 @@ | |||
160 | * struct sca3000_state - device instance state information | 167 | * struct sca3000_state - device instance state information |
161 | * @us: the associated spi device | 168 | * @us: the associated spi device |
162 | * @info: chip variant information | 169 | * @info: chip variant information |
163 | * @indio_dev: device information used by the IIO core | ||
164 | * @interrupt_handler_ws: event interrupt handler for all events | 170 | * @interrupt_handler_ws: event interrupt handler for all events |
165 | * @last_timestamp: the timestamp of the last event | 171 | * @last_timestamp: the timestamp of the last event |
166 | * @mo_det_use_count: reference counter for the motion detection unit | 172 | * @mo_det_use_count: reference counter for the motion detection unit |
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c index 7f6ccdfaf168..ed30e32e60de 100644 --- a/drivers/staging/iio/accel/sca3000_core.c +++ b/drivers/staging/iio/accel/sca3000_core.c | |||
@@ -32,7 +32,8 @@ enum sca3000_variant { | |||
32 | e05, | 32 | e05, |
33 | }; | 33 | }; |
34 | 34 | ||
35 | /* Note where option modes are not defined, the chip simply does not | 35 | /* |
36 | * Note where option modes are not defined, the chip simply does not | ||
36 | * support any. | 37 | * support any. |
37 | * Other chips in the sca3000 series use i2c and are not included here. | 38 | * Other chips in the sca3000 series use i2c and are not included here. |
38 | * | 39 | * |
@@ -191,7 +192,6 @@ error_ret: | |||
191 | return ret; | 192 | return ret; |
192 | } | 193 | } |
193 | 194 | ||
194 | /* Crucial that lock is called before calling this */ | ||
195 | /** | 195 | /** |
196 | * sca3000_read_ctrl_reg() read from lock protected control register. | 196 | * sca3000_read_ctrl_reg() read from lock protected control register. |
197 | * | 197 | * |
@@ -250,9 +250,8 @@ error_ret: | |||
250 | } | 250 | } |
251 | #endif /* SCA3000_DEBUG */ | 251 | #endif /* SCA3000_DEBUG */ |
252 | 252 | ||
253 | |||
254 | /** | 253 | /** |
255 | * sca3000_show_reg() - sysfs interface to read the chip revision number | 254 | * sca3000_show_rev() - sysfs interface to read the chip revision number |
256 | **/ | 255 | **/ |
257 | static ssize_t sca3000_show_rev(struct device *dev, | 256 | static ssize_t sca3000_show_rev(struct device *dev, |
258 | struct device_attribute *attr, | 257 | struct device_attribute *attr, |
@@ -312,7 +311,7 @@ sca3000_show_available_measurement_modes(struct device *dev, | |||
312 | } | 311 | } |
313 | 312 | ||
314 | /** | 313 | /** |
315 | * sca3000_show_measurmenet_mode() sysfs read of current mode | 314 | * sca3000_show_measurement_mode() sysfs read of current mode |
316 | **/ | 315 | **/ |
317 | static ssize_t | 316 | static ssize_t |
318 | sca3000_show_measurement_mode(struct device *dev, | 317 | sca3000_show_measurement_mode(struct device *dev, |
@@ -403,7 +402,8 @@ error_ret: | |||
403 | } | 402 | } |
404 | 403 | ||
405 | 404 | ||
406 | /* Not even vaguely standard attributes so defined here rather than | 405 | /* |
406 | * Not even vaguely standard attributes so defined here rather than | ||
407 | * in the relevant IIO core headers | 407 | * in the relevant IIO core headers |
408 | */ | 408 | */ |
409 | static IIO_DEVICE_ATTR(measurement_mode_available, S_IRUGO, | 409 | static IIO_DEVICE_ATTR(measurement_mode_available, S_IRUGO, |
@@ -450,6 +450,18 @@ static const struct iio_chan_spec sca3000_channels[] = { | |||
450 | SCA3000_CHAN(2, IIO_MOD_Z), | 450 | SCA3000_CHAN(2, IIO_MOD_Z), |
451 | }; | 451 | }; |
452 | 452 | ||
453 | static const struct iio_chan_spec sca3000_channels_with_temp[] = { | ||
454 | SCA3000_CHAN(0, IIO_MOD_X), | ||
455 | SCA3000_CHAN(1, IIO_MOD_Y), | ||
456 | SCA3000_CHAN(2, IIO_MOD_Z), | ||
457 | { | ||
458 | .type = IIO_TEMP, | ||
459 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | ||
460 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | | ||
461 | BIT(IIO_CHAN_INFO_OFFSET), | ||
462 | }, | ||
463 | }; | ||
464 | |||
453 | static u8 sca3000_addresses[3][3] = { | 465 | static u8 sca3000_addresses[3][3] = { |
454 | [0] = {SCA3000_REG_ADDR_X_MSB, SCA3000_REG_CTRL_SEL_MD_X_TH, | 466 | [0] = {SCA3000_REG_ADDR_X_MSB, SCA3000_REG_CTRL_SEL_MD_X_TH, |
455 | SCA3000_MD_CTRL_OR_X}, | 467 | SCA3000_MD_CTRL_OR_X}, |
@@ -472,19 +484,30 @@ static int sca3000_read_raw(struct iio_dev *indio_dev, | |||
472 | switch (mask) { | 484 | switch (mask) { |
473 | case IIO_CHAN_INFO_RAW: | 485 | case IIO_CHAN_INFO_RAW: |
474 | mutex_lock(&st->lock); | 486 | mutex_lock(&st->lock); |
475 | if (st->mo_det_use_count) { | 487 | if (chan->type == IIO_ACCEL) { |
476 | mutex_unlock(&st->lock); | 488 | if (st->mo_det_use_count) { |
477 | return -EBUSY; | 489 | mutex_unlock(&st->lock); |
478 | } | 490 | return -EBUSY; |
479 | address = sca3000_addresses[chan->address][0]; | 491 | } |
480 | ret = sca3000_read_data_short(st, address, 2); | 492 | address = sca3000_addresses[chan->address][0]; |
481 | if (ret < 0) { | 493 | ret = sca3000_read_data_short(st, address, 2); |
482 | mutex_unlock(&st->lock); | 494 | if (ret < 0) { |
483 | return ret; | 495 | mutex_unlock(&st->lock); |
496 | return ret; | ||
497 | } | ||
498 | *val = (be16_to_cpup((__be16 *)st->rx) >> 3) & 0x1FFF; | ||
499 | *val = ((*val) << (sizeof(*val)*8 - 13)) >> | ||
500 | (sizeof(*val)*8 - 13); | ||
501 | } else { | ||
502 | /* get the temperature when available */ | ||
503 | ret = sca3000_read_data_short(st, | ||
504 | SCA3000_REG_ADDR_TEMP_MSB, 2); | ||
505 | if (ret < 0) { | ||
506 | mutex_unlock(&st->lock); | ||
507 | return ret; | ||
508 | } | ||
509 | *val = ((st->rx[0] & 0x3F) << 3) | ((st->rx[1] & 0xE0) >> 5); | ||
484 | } | 510 | } |
485 | *val = (be16_to_cpup((__be16 *)st->rx) >> 3) & 0x1FFF; | ||
486 | *val = ((*val) << (sizeof(*val)*8 - 13)) >> | ||
487 | (sizeof(*val)*8 - 13); | ||
488 | mutex_unlock(&st->lock); | 511 | mutex_unlock(&st->lock); |
489 | return IIO_VAL_INT; | 512 | return IIO_VAL_INT; |
490 | case IIO_CHAN_INFO_SCALE: | 513 | case IIO_CHAN_INFO_SCALE: |
@@ -494,6 +517,10 @@ static int sca3000_read_raw(struct iio_dev *indio_dev, | |||
494 | else /* temperature */ | 517 | else /* temperature */ |
495 | *val2 = 555556; | 518 | *val2 = 555556; |
496 | return IIO_VAL_INT_PLUS_MICRO; | 519 | return IIO_VAL_INT_PLUS_MICRO; |
520 | case IIO_CHAN_INFO_OFFSET: | ||
521 | *val = -214; | ||
522 | *val2 = 600000; | ||
523 | return IIO_VAL_INT_PLUS_MICRO; | ||
497 | default: | 524 | default: |
498 | return -EINVAL; | 525 | return -EINVAL; |
499 | } | 526 | } |
@@ -547,7 +574,7 @@ error_ret: | |||
547 | return ret; | 574 | return ret; |
548 | } | 575 | } |
549 | /** | 576 | /** |
550 | * __sca3000_get_base_frequency() obtain mode specific base frequency | 577 | * __sca3000_get_base_freq() obtain mode specific base frequency |
551 | * | 578 | * |
552 | * lock must be held | 579 | * lock must be held |
553 | **/ | 580 | **/ |
@@ -663,7 +690,8 @@ error_free_lock: | |||
663 | return ret ? ret : len; | 690 | return ret ? ret : len; |
664 | } | 691 | } |
665 | 692 | ||
666 | /* Should only really be registered if ring buffer support is compiled in. | 693 | /* |
694 | * Should only really be registered if ring buffer support is compiled in. | ||
667 | * Does no harm however and doing it right would add a fair bit of complexity | 695 | * Does no harm however and doing it right would add a fair bit of complexity |
668 | */ | 696 | */ |
669 | static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(sca3000_read_av_freq); | 697 | static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(sca3000_read_av_freq); |
@@ -672,37 +700,6 @@ static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, | |||
672 | sca3000_read_frequency, | 700 | sca3000_read_frequency, |
673 | sca3000_set_frequency); | 701 | sca3000_set_frequency); |
674 | 702 | ||
675 | |||
676 | /** | ||
677 | * sca3000_read_temp() sysfs interface to get the temperature when available | ||
678 | * | ||
679 | * The alignment of data in here is downright odd. See data sheet. | ||
680 | * Converting this into a meaningful value is left to inline functions in | ||
681 | * userspace part of header. | ||
682 | **/ | ||
683 | static ssize_t sca3000_read_temp(struct device *dev, | ||
684 | struct device_attribute *attr, | ||
685 | char *buf) | ||
686 | { | ||
687 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); | ||
688 | struct sca3000_state *st = iio_priv(indio_dev); | ||
689 | int ret; | ||
690 | int val; | ||
691 | ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_TEMP_MSB, 2); | ||
692 | if (ret < 0) | ||
693 | goto error_ret; | ||
694 | val = ((st->rx[0] & 0x3F) << 3) | ((st->rx[1] & 0xE0) >> 5); | ||
695 | |||
696 | return sprintf(buf, "%d\n", val); | ||
697 | |||
698 | error_ret: | ||
699 | return ret; | ||
700 | } | ||
701 | static IIO_DEV_ATTR_TEMP_RAW(sca3000_read_temp); | ||
702 | |||
703 | static IIO_CONST_ATTR_TEMP_SCALE("0.555556"); | ||
704 | static IIO_CONST_ATTR_TEMP_OFFSET("-214.6"); | ||
705 | |||
706 | /** | 703 | /** |
707 | * sca3000_read_thresh() - query of a threshold | 704 | * sca3000_read_thresh() - query of a threshold |
708 | **/ | 705 | **/ |
@@ -782,33 +779,16 @@ static struct attribute *sca3000_attributes[] = { | |||
782 | NULL, | 779 | NULL, |
783 | }; | 780 | }; |
784 | 781 | ||
785 | static struct attribute *sca3000_attributes_with_temp[] = { | ||
786 | &iio_dev_attr_revision.dev_attr.attr, | ||
787 | &iio_dev_attr_measurement_mode_available.dev_attr.attr, | ||
788 | &iio_dev_attr_measurement_mode.dev_attr.attr, | ||
789 | &iio_dev_attr_sampling_frequency_available.dev_attr.attr, | ||
790 | &iio_dev_attr_sampling_frequency.dev_attr.attr, | ||
791 | /* Only present if temp sensor is */ | ||
792 | &iio_dev_attr_in_temp_raw.dev_attr.attr, | ||
793 | &iio_const_attr_in_temp_offset.dev_attr.attr, | ||
794 | &iio_const_attr_in_temp_scale.dev_attr.attr, | ||
795 | NULL, | ||
796 | }; | ||
797 | |||
798 | static const struct attribute_group sca3000_attribute_group = { | 782 | static const struct attribute_group sca3000_attribute_group = { |
799 | .attrs = sca3000_attributes, | 783 | .attrs = sca3000_attributes, |
800 | }; | 784 | }; |
801 | 785 | ||
802 | static const struct attribute_group sca3000_attribute_group_with_temp = { | ||
803 | .attrs = sca3000_attributes_with_temp, | ||
804 | }; | ||
805 | |||
806 | /* RING RELATED interrupt handler */ | ||
807 | /* depending on event, push to the ring buffer event chrdev or the event one */ | ||
808 | |||
809 | /** | 786 | /** |
810 | * sca3000_event_handler() - handling ring and non ring events | 787 | * sca3000_event_handler() - handling ring and non ring events |
811 | * | 788 | * |
789 | * Ring related interrupt handler. Depending on event, push to | ||
790 | * the ring buffer event chrdev or the event one. | ||
791 | * | ||
812 | * This function is complicated by the fact that the devices can signify ring | 792 | * This function is complicated by the fact that the devices can signify ring |
813 | * and non ring events via the same interrupt line and they can only | 793 | * and non ring events via the same interrupt line and they can only |
814 | * be distinguished via a read of the relevant status register. | 794 | * be distinguished via a read of the relevant status register. |
@@ -820,7 +800,8 @@ static irqreturn_t sca3000_event_handler(int irq, void *private) | |||
820 | int ret, val; | 800 | int ret, val; |
821 | s64 last_timestamp = iio_get_time_ns(); | 801 | s64 last_timestamp = iio_get_time_ns(); |
822 | 802 | ||
823 | /* Could lead if badly timed to an extra read of status reg, | 803 | /* |
804 | * Could lead if badly timed to an extra read of status reg, | ||
824 | * but ensures no interrupt is missed. | 805 | * but ensures no interrupt is missed. |
825 | */ | 806 | */ |
826 | mutex_lock(&st->lock); | 807 | mutex_lock(&st->lock); |
@@ -935,7 +916,6 @@ static ssize_t sca3000_query_free_fall_mode(struct device *dev, | |||
935 | * the device falls more than 25cm. This has not been tested due | 916 | * the device falls more than 25cm. This has not been tested due |
936 | * to fragile wiring. | 917 | * to fragile wiring. |
937 | **/ | 918 | **/ |
938 | |||
939 | static ssize_t sca3000_set_free_fall_mode(struct device *dev, | 919 | static ssize_t sca3000_set_free_fall_mode(struct device *dev, |
940 | struct device_attribute *attr, | 920 | struct device_attribute *attr, |
941 | const char *buf, | 921 | const char *buf, |
@@ -957,7 +937,7 @@ static ssize_t sca3000_set_free_fall_mode(struct device *dev, | |||
957 | if (ret) | 937 | if (ret) |
958 | goto error_ret; | 938 | goto error_ret; |
959 | 939 | ||
960 | /*if off and should be on*/ | 940 | /* if off and should be on */ |
961 | if (val && !(st->rx[0] & protect_mask)) | 941 | if (val && !(st->rx[0] & protect_mask)) |
962 | ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE, | 942 | ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE, |
963 | (st->rx[0] | SCA3000_FREE_FALL_DETECT)); | 943 | (st->rx[0] | SCA3000_FREE_FALL_DETECT)); |
@@ -972,7 +952,7 @@ error_ret: | |||
972 | } | 952 | } |
973 | 953 | ||
974 | /** | 954 | /** |
975 | * sca3000_set_mo_det() simple on off control for motion detector | 955 | * sca3000_write_event_config() simple on off control for motion detector |
976 | * | 956 | * |
977 | * This is a per axis control, but enabling any will result in the | 957 | * This is a per axis control, but enabling any will result in the |
978 | * motion detector unit being enabled. | 958 | * motion detector unit being enabled. |
@@ -992,13 +972,15 @@ static int sca3000_write_event_config(struct iio_dev *indio_dev, | |||
992 | int num = chan->channel2; | 972 | int num = chan->channel2; |
993 | 973 | ||
994 | mutex_lock(&st->lock); | 974 | mutex_lock(&st->lock); |
995 | /* First read the motion detector config to find out if | 975 | /* |
996 | * this axis is on*/ | 976 | * First read the motion detector config to find out if |
977 | * this axis is on | ||
978 | */ | ||
997 | ret = sca3000_read_ctrl_reg(st, SCA3000_REG_CTRL_SEL_MD_CTRL); | 979 | ret = sca3000_read_ctrl_reg(st, SCA3000_REG_CTRL_SEL_MD_CTRL); |
998 | if (ret < 0) | 980 | if (ret < 0) |
999 | goto exit_point; | 981 | goto exit_point; |
1000 | ctrlval = ret; | 982 | ctrlval = ret; |
1001 | /* Off and should be on */ | 983 | /* if off and should be on */ |
1002 | if (state && !(ctrlval & sca3000_addresses[num][2])) { | 984 | if (state && !(ctrlval & sca3000_addresses[num][2])) { |
1003 | ret = sca3000_write_ctrl_reg(st, | 985 | ret = sca3000_write_ctrl_reg(st, |
1004 | SCA3000_REG_CTRL_SEL_MD_CTRL, | 986 | SCA3000_REG_CTRL_SEL_MD_CTRL, |
@@ -1021,7 +1003,7 @@ static int sca3000_write_event_config(struct iio_dev *indio_dev, | |||
1021 | ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1); | 1003 | ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1); |
1022 | if (ret) | 1004 | if (ret) |
1023 | goto exit_point; | 1005 | goto exit_point; |
1024 | /*if off and should be on*/ | 1006 | /* if off and should be on */ |
1025 | if ((st->mo_det_use_count) | 1007 | if ((st->mo_det_use_count) |
1026 | && ((st->rx[0] & protect_mask) != SCA3000_MEAS_MODE_MOT_DET)) | 1008 | && ((st->rx[0] & protect_mask) != SCA3000_MEAS_MODE_MOT_DET)) |
1027 | ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE, | 1009 | ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE, |
@@ -1067,7 +1049,7 @@ static struct attribute_group sca3000_event_attribute_group = { | |||
1067 | * Devices use flash memory to store many of the register values | 1049 | * Devices use flash memory to store many of the register values |
1068 | * and hence can come up in somewhat unpredictable states. | 1050 | * and hence can come up in somewhat unpredictable states. |
1069 | * Hence reset everything on driver load. | 1051 | * Hence reset everything on driver load. |
1070 | **/ | 1052 | **/ |
1071 | static int sca3000_clean_setup(struct sca3000_state *st) | 1053 | static int sca3000_clean_setup(struct sca3000_state *st) |
1072 | { | 1054 | { |
1073 | int ret; | 1055 | int ret; |
@@ -1107,9 +1089,11 @@ static int sca3000_clean_setup(struct sca3000_state *st) | |||
1107 | | SCA3000_INT_MASK_ACTIVE_LOW); | 1089 | | SCA3000_INT_MASK_ACTIVE_LOW); |
1108 | if (ret) | 1090 | if (ret) |
1109 | goto error_ret; | 1091 | goto error_ret; |
1110 | /* Select normal measurement mode, free fall off, ring off */ | 1092 | /* |
1111 | /* Ring in 12 bit mode - it is fine to overwrite reserved bits 3,5 | 1093 | * Select normal measurement mode, free fall off, ring off |
1112 | * as that occurs in one of the example on the datasheet */ | 1094 | * Ring in 12 bit mode - it is fine to overwrite reserved bits 3,5 |
1095 | * as that occurs in one of the example on the datasheet | ||
1096 | */ | ||
1113 | ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1); | 1097 | ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1); |
1114 | if (ret) | 1098 | if (ret) |
1115 | goto error_ret; | 1099 | goto error_ret; |
@@ -1133,16 +1117,6 @@ static const struct iio_info sca3000_info = { | |||
1133 | .driver_module = THIS_MODULE, | 1117 | .driver_module = THIS_MODULE, |
1134 | }; | 1118 | }; |
1135 | 1119 | ||
1136 | static const struct iio_info sca3000_info_with_temp = { | ||
1137 | .attrs = &sca3000_attribute_group_with_temp, | ||
1138 | .read_raw = &sca3000_read_raw, | ||
1139 | .read_event_value = &sca3000_read_thresh, | ||
1140 | .write_event_value = &sca3000_write_thresh, | ||
1141 | .read_event_config = &sca3000_read_event_config, | ||
1142 | .write_event_config = &sca3000_write_event_config, | ||
1143 | .driver_module = THIS_MODULE, | ||
1144 | }; | ||
1145 | |||
1146 | static int sca3000_probe(struct spi_device *spi) | 1120 | static int sca3000_probe(struct spi_device *spi) |
1147 | { | 1121 | { |
1148 | int ret; | 1122 | int ret; |
@@ -1162,10 +1136,12 @@ static int sca3000_probe(struct spi_device *spi) | |||
1162 | 1136 | ||
1163 | indio_dev->dev.parent = &spi->dev; | 1137 | indio_dev->dev.parent = &spi->dev; |
1164 | indio_dev->name = spi_get_device_id(spi)->name; | 1138 | indio_dev->name = spi_get_device_id(spi)->name; |
1165 | if (st->info->temp_output) | 1139 | indio_dev->info = &sca3000_info; |
1166 | indio_dev->info = &sca3000_info_with_temp; | 1140 | if (st->info->temp_output) { |
1167 | else { | 1141 | indio_dev->channels = sca3000_channels_with_temp; |
1168 | indio_dev->info = &sca3000_info; | 1142 | indio_dev->num_channels = |
1143 | ARRAY_SIZE(sca3000_channels_with_temp); | ||
1144 | } else { | ||
1169 | indio_dev->channels = sca3000_channels; | 1145 | indio_dev->channels = sca3000_channels; |
1170 | indio_dev->num_channels = ARRAY_SIZE(sca3000_channels); | 1146 | indio_dev->num_channels = ARRAY_SIZE(sca3000_channels); |
1171 | } | 1147 | } |
@@ -1236,7 +1212,7 @@ static int sca3000_remove(struct spi_device *spi) | |||
1236 | struct iio_dev *indio_dev = spi_get_drvdata(spi); | 1212 | struct iio_dev *indio_dev = spi_get_drvdata(spi); |
1237 | struct sca3000_state *st = iio_priv(indio_dev); | 1213 | struct sca3000_state *st = iio_priv(indio_dev); |
1238 | 1214 | ||
1239 | /* Must ensure no interrupts can be generated after this!*/ | 1215 | /* Must ensure no interrupts can be generated after this! */ |
1240 | sca3000_stop_all_interrupts(st); | 1216 | sca3000_stop_all_interrupts(st); |
1241 | if (spi->irq) | 1217 | if (spi->irq) |
1242 | free_irq(spi->irq, indio_dev); | 1218 | free_irq(spi->irq, indio_dev); |
diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c index 7fc66a6a6e36..d304156ca2f7 100644 --- a/drivers/staging/iio/adc/mxs-lradc.c +++ b/drivers/staging/iio/adc/mxs-lradc.c | |||
@@ -897,10 +897,6 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev, | |||
897 | { | 897 | { |
898 | struct mxs_lradc *lradc = iio_priv(iio_dev); | 898 | struct mxs_lradc *lradc = iio_priv(iio_dev); |
899 | 899 | ||
900 | /* Check for invalid channel */ | ||
901 | if (chan->channel > LRADC_MAX_TOTAL_CHANS) | ||
902 | return -EINVAL; | ||
903 | |||
904 | switch (m) { | 900 | switch (m) { |
905 | case IIO_CHAN_INFO_RAW: | 901 | case IIO_CHAN_INFO_RAW: |
906 | if (chan->type == IIO_TEMP) | 902 | if (chan->type == IIO_TEMP) |