diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-08-29 17:33:17 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-08-29 17:33:17 -0400 |
commit | f5adda3283fb4a2304a53e56699a9a0aadc3ab69 (patch) | |
tree | 1a407c53684879540fa2ffe089a0c4a8981bd09a | |
parent | 115cac2e7a8d06aa347bf233b4cb94828eb0509a (diff) | |
parent | 9120c0bea999cc26c3493486828d34138a7ac901 (diff) |
Merge tag 'iio-for-3.12c' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes:
Third set of new drivers, cleanups and features for IIO in the 3.12 cycle.
New drivers
1) Bosh BMA180 accelerometer + a new sysfs abi element, power_mode to
allow for device that trade off accuracy and power usage.
Cleanups
1) Another lot of devm_iio_device_alloc patches
2) An code ordering bug in the twl6030 driver introduced earlier in this
cycle.
New features
1) at91 adc driver rework to support a wider range of parts and drop
the necessity for some of the current device tree elements. This is
a precursor to introducing input support which is still under review.
21 files changed, 849 insertions, 188 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio index 45ae709db4ff..39c8de0e53d0 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio +++ b/Documentation/ABI/testing/sysfs-bus-iio | |||
@@ -794,6 +794,16 @@ Description: | |||
794 | This attribute is used to read the amount of quadrature error | 794 | This attribute is used to read the amount of quadrature error |
795 | present in the device at a given time. | 795 | present in the device at a given time. |
796 | 796 | ||
797 | What: /sys/.../iio:deviceX/in_accelX_power_mode | ||
798 | KernelVersion: 3.11 | ||
799 | Contact: linux-iio@vger.kernel.org | ||
800 | Description: | ||
801 | Specifies the chip power mode. | ||
802 | low_noise: reduce noise level from ADC, | ||
803 | low_power: enable low current consumption. | ||
804 | For a list of available output power modes read | ||
805 | in_accel_power_mode_available. | ||
806 | |||
797 | What: /sys/bus/iio/devices/iio:deviceX/store_eeprom | 807 | What: /sys/bus/iio/devices/iio:deviceX/store_eeprom |
798 | KernelVersion: 3.4.0 | 808 | KernelVersion: 3.4.0 |
799 | Contact: linux-iio@vger.kernel.org | 809 | Contact: linux-iio@vger.kernel.org |
diff --git a/Documentation/devicetree/bindings/arm/atmel-adc.txt b/Documentation/devicetree/bindings/arm/atmel-adc.txt index 16769d9cedd6..723c205cb10d 100644 --- a/Documentation/devicetree/bindings/arm/atmel-adc.txt +++ b/Documentation/devicetree/bindings/arm/atmel-adc.txt | |||
@@ -1,18 +1,15 @@ | |||
1 | * AT91's Analog to Digital Converter (ADC) | 1 | * AT91's Analog to Digital Converter (ADC) |
2 | 2 | ||
3 | Required properties: | 3 | Required properties: |
4 | - compatible: Should be "atmel,at91sam9260-adc" | 4 | - compatible: Should be "atmel,<chip>-adc" |
5 | <chip> can be "at91sam9260", "at91sam9g45" or "at91sam9x5" | ||
5 | - reg: Should contain ADC registers location and length | 6 | - reg: Should contain ADC registers location and length |
6 | - interrupts: Should contain the IRQ line for the ADC | 7 | - interrupts: Should contain the IRQ line for the ADC |
7 | - atmel,adc-channel-base: Offset of the first channel data register | ||
8 | - atmel,adc-channels-used: Bitmask of the channels muxed and enable for this | 8 | - atmel,adc-channels-used: Bitmask of the channels muxed and enable for this |
9 | device | 9 | device |
10 | - atmel,adc-drdy-mask: Mask of the DRDY interruption in the ADC | ||
11 | - atmel,adc-num-channels: Number of channels available in the ADC | 10 | - atmel,adc-num-channels: Number of channels available in the ADC |
12 | - atmel,adc-startup-time: Startup Time of the ADC in microseconds as | 11 | - atmel,adc-startup-time: Startup Time of the ADC in microseconds as |
13 | defined in the datasheet | 12 | defined in the datasheet |
14 | - atmel,adc-status-register: Offset of the Interrupt Status Register | ||
15 | - atmel,adc-trigger-register: Offset of the Trigger Register | ||
16 | - atmel,adc-vref: Reference voltage in millivolts for the conversions | 13 | - atmel,adc-vref: Reference voltage in millivolts for the conversions |
17 | - atmel,adc-res: List of resolution in bits supported by the ADC. List size | 14 | - atmel,adc-res: List of resolution in bits supported by the ADC. List size |
18 | must be two at least. | 15 | must be two at least. |
diff --git a/Documentation/devicetree/bindings/iio/accel/bma180.txt b/Documentation/devicetree/bindings/iio/accel/bma180.txt new file mode 100644 index 000000000000..c5933573e0f6 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/accel/bma180.txt | |||
@@ -0,0 +1,24 @@ | |||
1 | * Bosch BMA180 triaxial acceleration sensor | ||
2 | |||
3 | http://omapworld.com/BMA180_111_1002839.pdf | ||
4 | |||
5 | Required properties: | ||
6 | |||
7 | - compatible : should be "bosch,bma180" | ||
8 | - reg : the I2C address of the sensor | ||
9 | |||
10 | Optional properties: | ||
11 | |||
12 | - interrupt-parent : should be the phandle for the interrupt controller | ||
13 | |||
14 | - interrupts : interrupt mapping for GPIO IRQ, it should by configured with | ||
15 | flags IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_EDGE_RISING | ||
16 | |||
17 | Example: | ||
18 | |||
19 | bma180@40 { | ||
20 | compatible = "bosch,bma180"; | ||
21 | reg = <0x40>; | ||
22 | interrupt-parent = <&gpio6>; | ||
23 | interrupts = <18 (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_EDGE_RISING)>; | ||
24 | }; | ||
diff --git a/arch/arm/mach-at91/include/mach/at91_adc.h b/arch/arm/mach-at91/include/mach/at91_adc.h index 8e7ed5c90817..048a57f76bd3 100644 --- a/arch/arm/mach-at91/include/mach/at91_adc.h +++ b/arch/arm/mach-at91/include/mach/at91_adc.h | |||
@@ -28,9 +28,12 @@ | |||
28 | #define AT91_ADC_TRGSEL_EXTERNAL (6 << 1) | 28 | #define AT91_ADC_TRGSEL_EXTERNAL (6 << 1) |
29 | #define AT91_ADC_LOWRES (1 << 4) /* Low Resolution */ | 29 | #define AT91_ADC_LOWRES (1 << 4) /* Low Resolution */ |
30 | #define AT91_ADC_SLEEP (1 << 5) /* Sleep Mode */ | 30 | #define AT91_ADC_SLEEP (1 << 5) /* Sleep Mode */ |
31 | #define AT91_ADC_PRESCAL (0x3f << 8) /* Prescalar Rate Selection */ | 31 | #define AT91_ADC_PRESCAL_9260 (0x3f << 8) /* Prescalar Rate Selection */ |
32 | #define AT91_ADC_PRESCAL_9G45 (0xff << 8) | ||
32 | #define AT91_ADC_PRESCAL_(x) ((x) << 8) | 33 | #define AT91_ADC_PRESCAL_(x) ((x) << 8) |
33 | #define AT91_ADC_STARTUP (0x1f << 16) /* Startup Up Time */ | 34 | #define AT91_ADC_STARTUP_9260 (0x1f << 16) /* Startup Up Time */ |
35 | #define AT91_ADC_STARTUP_9G45 (0x7f << 16) | ||
36 | #define AT91_ADC_STARTUP_9X5 (0xf << 16) | ||
34 | #define AT91_ADC_STARTUP_(x) ((x) << 16) | 37 | #define AT91_ADC_STARTUP_(x) ((x) << 16) |
35 | #define AT91_ADC_SHTIM (0xf << 24) /* Sample & Hold Time */ | 38 | #define AT91_ADC_SHTIM (0xf << 24) /* Sample & Hold Time */ |
36 | #define AT91_ADC_SHTIM_(x) ((x) << 24) | 39 | #define AT91_ADC_SHTIM_(x) ((x) << 24) |
@@ -48,6 +51,9 @@ | |||
48 | #define AT91_ADC_ENDRX (1 << 18) /* End of RX Buffer */ | 51 | #define AT91_ADC_ENDRX (1 << 18) /* End of RX Buffer */ |
49 | #define AT91_ADC_RXFUFF (1 << 19) /* RX Buffer Full */ | 52 | #define AT91_ADC_RXFUFF (1 << 19) /* RX Buffer Full */ |
50 | 53 | ||
54 | #define AT91_ADC_SR_9X5 0x30 /* Status Register for 9x5 */ | ||
55 | #define AT91_ADC_SR_DRDY_9X5 (1 << 24) /* Data Ready */ | ||
56 | |||
51 | #define AT91_ADC_LCDR 0x20 /* Last Converted Data Register */ | 57 | #define AT91_ADC_LCDR 0x20 /* Last Converted Data Register */ |
52 | #define AT91_ADC_LDATA (0x3ff) | 58 | #define AT91_ADC_LDATA (0x3ff) |
53 | 59 | ||
@@ -58,4 +64,10 @@ | |||
58 | #define AT91_ADC_CHR(n) (0x30 + ((n) * 4)) /* Channel Data Register N */ | 64 | #define AT91_ADC_CHR(n) (0x30 + ((n) * 4)) /* Channel Data Register N */ |
59 | #define AT91_ADC_DATA (0x3ff) | 65 | #define AT91_ADC_DATA (0x3ff) |
60 | 66 | ||
67 | #define AT91_ADC_CDR0_9X5 (0x50) /* Channel Data Register 0 for 9X5 */ | ||
68 | |||
69 | #define AT91_ADC_TRGR_9260 AT91_ADC_MR | ||
70 | #define AT91_ADC_TRGR_9G45 0x08 | ||
71 | #define AT91_ADC_TRGR_9X5 0xC0 | ||
72 | |||
61 | #endif | 73 | #endif |
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index 61ca7ec0f3e7..e23e50850655 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig | |||
@@ -5,6 +5,18 @@ | |||
5 | 5 | ||
6 | menu "Accelerometers" | 6 | menu "Accelerometers" |
7 | 7 | ||
8 | config BMA180 | ||
9 | tristate "Bosch BMA180 3-Axis Accelerometer Driver" | ||
10 | depends on I2C | ||
11 | select IIO_BUFFER | ||
12 | select IIO_TRIGGERED_BUFFER | ||
13 | help | ||
14 | Say Y here if you want to build a driver for the Bosch BMA180 | ||
15 | triaxial acceleration sensor. | ||
16 | |||
17 | To compile this driver as a module, choose M here: the | ||
18 | module will be called bma180. | ||
19 | |||
8 | config HID_SENSOR_ACCEL_3D | 20 | config HID_SENSOR_ACCEL_3D |
9 | depends on HID_SENSOR_HUB | 21 | depends on HID_SENSOR_HUB |
10 | select IIO_BUFFER | 22 | select IIO_BUFFER |
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index 2f95a3dffa47..c48d15f25616 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile | |||
@@ -3,6 +3,7 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | # When adding new entries keep the list in alphabetical order | 5 | # When adding new entries keep the list in alphabetical order |
6 | obj-$(CONFIG_BMA180) += bma180.o | ||
6 | obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o | 7 | obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o |
7 | obj-$(CONFIG_KXSD9) += kxsd9.o | 8 | obj-$(CONFIG_KXSD9) += kxsd9.o |
8 | 9 | ||
diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c new file mode 100644 index 000000000000..12e32e6b4103 --- /dev/null +++ b/drivers/iio/accel/bma180.c | |||
@@ -0,0 +1,676 @@ | |||
1 | /* | ||
2 | * bma180.c - IIO driver for Bosch BMA180 triaxial acceleration sensor | ||
3 | * | ||
4 | * Copyright 2013 Oleksandr Kravchenko <x0199363@ti.com> | ||
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 | |||
11 | #include <linux/module.h> | ||
12 | #include <linux/i2c.h> | ||
13 | #include <linux/interrupt.h> | ||
14 | #include <linux/delay.h> | ||
15 | #include <linux/of.h> | ||
16 | #include <linux/bitops.h> | ||
17 | #include <linux/slab.h> | ||
18 | #include <linux/string.h> | ||
19 | #include <linux/iio/iio.h> | ||
20 | #include <linux/iio/sysfs.h> | ||
21 | #include <linux/iio/buffer.h> | ||
22 | #include <linux/iio/trigger.h> | ||
23 | #include <linux/iio/trigger_consumer.h> | ||
24 | #include <linux/iio/triggered_buffer.h> | ||
25 | |||
26 | #define BMA180_DRV_NAME "bma180" | ||
27 | #define BMA180_IRQ_NAME "bma180_event" | ||
28 | |||
29 | /* Register set */ | ||
30 | #define BMA180_CHIP_ID 0x00 /* Need to distinguish BMA180 from other */ | ||
31 | #define BMA180_ACC_X_LSB 0x02 /* First of 6 registers of accel data */ | ||
32 | #define BMA180_CTRL_REG0 0x0d | ||
33 | #define BMA180_RESET 0x10 | ||
34 | #define BMA180_BW_TCS 0x20 | ||
35 | #define BMA180_CTRL_REG3 0x21 | ||
36 | #define BMA180_TCO_Z 0x30 | ||
37 | #define BMA180_OFFSET_LSB1 0x35 | ||
38 | |||
39 | /* BMA180_CTRL_REG0 bits */ | ||
40 | #define BMA180_DIS_WAKE_UP BIT(0) /* Disable wake up mode */ | ||
41 | #define BMA180_SLEEP BIT(1) /* 1 - chip will sleep */ | ||
42 | #define BMA180_EE_W BIT(4) /* Unlock writing to addr from 0x20 */ | ||
43 | #define BMA180_RESET_INT BIT(6) /* Reset pending interrupts */ | ||
44 | |||
45 | /* BMA180_CTRL_REG3 bits */ | ||
46 | #define BMA180_NEW_DATA_INT BIT(1) /* Intr every new accel data is ready */ | ||
47 | |||
48 | /* BMA180_OFFSET_LSB1 skipping mode bit */ | ||
49 | #define BMA180_SMP_SKIP BIT(0) | ||
50 | |||
51 | /* Bit masks for registers bit fields */ | ||
52 | #define BMA180_RANGE 0x0e /* Range of measured accel values*/ | ||
53 | #define BMA180_BW 0xf0 /* Accel bandwidth */ | ||
54 | #define BMA180_MODE_CONFIG 0x03 /* Config operation modes */ | ||
55 | |||
56 | /* We have to write this value in reset register to do soft reset */ | ||
57 | #define BMA180_RESET_VAL 0xb6 | ||
58 | |||
59 | #define BMA_180_ID_REG_VAL 0x03 | ||
60 | |||
61 | /* Chip power modes */ | ||
62 | #define BMA180_LOW_NOISE 0x00 | ||
63 | #define BMA180_LOW_POWER 0x03 | ||
64 | |||
65 | #define BMA180_LOW_NOISE_STR "low_noise" | ||
66 | #define BMA180_LOW_POWER_STR "low_power" | ||
67 | |||
68 | /* Defaults values */ | ||
69 | #define BMA180_DEF_PMODE 0 | ||
70 | #define BMA180_DEF_BW 20 | ||
71 | #define BMA180_DEF_SCALE 250 | ||
72 | |||
73 | /* Available values for sysfs */ | ||
74 | #define BMA180_FLP_FREQ_AVAILABLE \ | ||
75 | "10 20 40 75 150 300" | ||
76 | #define BMA180_SCALE_AVAILABLE \ | ||
77 | "0.000130 0.000190 0.000250 0.000380 0.000500 0.000990 0.001980" | ||
78 | |||
79 | struct bma180_data { | ||
80 | struct i2c_client *client; | ||
81 | struct iio_trigger *trig; | ||
82 | struct mutex mutex; | ||
83 | int sleep_state; | ||
84 | int scale; | ||
85 | int bw; | ||
86 | int pmode; | ||
87 | char *buff; | ||
88 | }; | ||
89 | |||
90 | enum bma180_axis { | ||
91 | AXIS_X, | ||
92 | AXIS_Y, | ||
93 | AXIS_Z, | ||
94 | }; | ||
95 | |||
96 | static int bw_table[] = { 10, 20, 40, 75, 150, 300 }; /* Hz */ | ||
97 | static int scale_table[] = { 130, 190, 250, 380, 500, 990, 1980 }; | ||
98 | |||
99 | static int bma180_get_acc_reg(struct bma180_data *data, enum bma180_axis axis) | ||
100 | { | ||
101 | u8 reg = BMA180_ACC_X_LSB + axis * 2; | ||
102 | int ret; | ||
103 | |||
104 | if (data->sleep_state) | ||
105 | return -EBUSY; | ||
106 | |||
107 | ret = i2c_smbus_read_word_data(data->client, reg); | ||
108 | if (ret < 0) | ||
109 | dev_err(&data->client->dev, | ||
110 | "failed to read accel_%c registers\n", 'x' + axis); | ||
111 | |||
112 | return ret; | ||
113 | } | ||
114 | |||
115 | static int bma180_set_bits(struct bma180_data *data, u8 reg, u8 mask, u8 val) | ||
116 | { | ||
117 | int ret = i2c_smbus_read_byte_data(data->client, reg); | ||
118 | u8 reg_val = (ret & ~mask) | (val << (ffs(mask) - 1)); | ||
119 | |||
120 | if (ret < 0) | ||
121 | return ret; | ||
122 | |||
123 | return i2c_smbus_write_byte_data(data->client, reg, reg_val); | ||
124 | } | ||
125 | |||
126 | static int bma180_reset_intr(struct bma180_data *data) | ||
127 | { | ||
128 | int ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_RESET_INT, 1); | ||
129 | |||
130 | if (ret) | ||
131 | dev_err(&data->client->dev, "failed to reset interrupt\n"); | ||
132 | |||
133 | return ret; | ||
134 | } | ||
135 | |||
136 | static int bma180_set_new_data_intr_state(struct bma180_data *data, int state) | ||
137 | { | ||
138 | u8 reg_val = state ? BMA180_NEW_DATA_INT : 0x00; | ||
139 | int ret = i2c_smbus_write_byte_data(data->client, BMA180_CTRL_REG3, | ||
140 | reg_val); | ||
141 | |||
142 | if (ret) | ||
143 | goto err; | ||
144 | ret = bma180_reset_intr(data); | ||
145 | if (ret) | ||
146 | goto err; | ||
147 | |||
148 | return 0; | ||
149 | |||
150 | err: | ||
151 | dev_err(&data->client->dev, | ||
152 | "failed to set new data interrupt state %d\n", state); | ||
153 | return ret; | ||
154 | } | ||
155 | |||
156 | static int bma180_set_sleep_state(struct bma180_data *data, int state) | ||
157 | { | ||
158 | int ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_SLEEP, state); | ||
159 | |||
160 | if (ret) { | ||
161 | dev_err(&data->client->dev, | ||
162 | "failed to set sleep state %d\n", state); | ||
163 | return ret; | ||
164 | } | ||
165 | data->sleep_state = state; | ||
166 | |||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | static int bma180_set_ee_writing_state(struct bma180_data *data, int state) | ||
171 | { | ||
172 | int ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_EE_W, state); | ||
173 | |||
174 | if (ret) | ||
175 | dev_err(&data->client->dev, | ||
176 | "failed to set ee writing state %d\n", state); | ||
177 | |||
178 | return ret; | ||
179 | } | ||
180 | |||
181 | static int bma180_set_bw(struct bma180_data *data, int val) | ||
182 | { | ||
183 | int ret, i; | ||
184 | |||
185 | if (data->sleep_state) | ||
186 | return -EBUSY; | ||
187 | |||
188 | for (i = 0; i < ARRAY_SIZE(bw_table); ++i) { | ||
189 | if (bw_table[i] == val) { | ||
190 | ret = bma180_set_bits(data, | ||
191 | BMA180_BW_TCS, BMA180_BW, i); | ||
192 | if (ret) { | ||
193 | dev_err(&data->client->dev, | ||
194 | "failed to set bandwidth\n"); | ||
195 | return ret; | ||
196 | } | ||
197 | data->bw = val; | ||
198 | return 0; | ||
199 | } | ||
200 | } | ||
201 | |||
202 | return -EINVAL; | ||
203 | } | ||
204 | |||
205 | static int bma180_set_scale(struct bma180_data *data, int val) | ||
206 | { | ||
207 | int ret, i; | ||
208 | |||
209 | if (data->sleep_state) | ||
210 | return -EBUSY; | ||
211 | |||
212 | for (i = 0; i < ARRAY_SIZE(scale_table); ++i) | ||
213 | if (scale_table[i] == val) { | ||
214 | ret = bma180_set_bits(data, | ||
215 | BMA180_OFFSET_LSB1, BMA180_RANGE, i); | ||
216 | if (ret) { | ||
217 | dev_err(&data->client->dev, | ||
218 | "failed to set scale\n"); | ||
219 | return ret; | ||
220 | } | ||
221 | data->scale = val; | ||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | return -EINVAL; | ||
226 | } | ||
227 | |||
228 | static int bma180_set_pmode(struct bma180_data *data, int mode) | ||
229 | { | ||
230 | u8 reg_val = mode ? BMA180_LOW_POWER : BMA180_LOW_NOISE; | ||
231 | int ret = bma180_set_bits(data, BMA180_TCO_Z, BMA180_MODE_CONFIG, | ||
232 | reg_val); | ||
233 | |||
234 | if (ret) { | ||
235 | dev_err(&data->client->dev, "failed to set power mode\n"); | ||
236 | return ret; | ||
237 | } | ||
238 | data->pmode = mode; | ||
239 | |||
240 | return 0; | ||
241 | } | ||
242 | |||
243 | static int bma180_soft_reset(struct bma180_data *data) | ||
244 | { | ||
245 | int ret = i2c_smbus_write_byte_data(data->client, | ||
246 | BMA180_RESET, BMA180_RESET_VAL); | ||
247 | |||
248 | if (ret) | ||
249 | dev_err(&data->client->dev, "failed to reset the chip\n"); | ||
250 | |||
251 | return ret; | ||
252 | } | ||
253 | |||
254 | static int bma180_chip_init(struct bma180_data *data) | ||
255 | { | ||
256 | /* Try to read chip_id register. It must return 0x03. */ | ||
257 | int ret = i2c_smbus_read_byte_data(data->client, BMA180_CHIP_ID); | ||
258 | |||
259 | if (ret < 0) | ||
260 | goto err; | ||
261 | if (ret != BMA_180_ID_REG_VAL) { | ||
262 | ret = -ENODEV; | ||
263 | goto err; | ||
264 | } | ||
265 | |||
266 | ret = bma180_soft_reset(data); | ||
267 | if (ret) | ||
268 | goto err; | ||
269 | /* | ||
270 | * No serial transaction should occur within minimum 10 us | ||
271 | * after soft_reset command | ||
272 | */ | ||
273 | msleep(20); | ||
274 | |||
275 | ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_DIS_WAKE_UP, 1); | ||
276 | if (ret) | ||
277 | goto err; | ||
278 | ret = bma180_set_ee_writing_state(data, 1); | ||
279 | if (ret) | ||
280 | goto err; | ||
281 | ret = bma180_set_new_data_intr_state(data, 0); | ||
282 | if (ret) | ||
283 | goto err; | ||
284 | ret = bma180_set_bits(data, BMA180_OFFSET_LSB1, BMA180_SMP_SKIP, 1); | ||
285 | if (ret) | ||
286 | goto err; | ||
287 | ret = bma180_set_pmode(data, BMA180_DEF_PMODE); | ||
288 | if (ret) | ||
289 | goto err; | ||
290 | ret = bma180_set_bw(data, BMA180_DEF_BW); | ||
291 | if (ret) | ||
292 | goto err; | ||
293 | ret = bma180_set_scale(data, BMA180_DEF_SCALE); | ||
294 | if (ret) | ||
295 | goto err; | ||
296 | |||
297 | return 0; | ||
298 | |||
299 | err: | ||
300 | dev_err(&data->client->dev, "failed to init the chip\n"); | ||
301 | return ret; | ||
302 | } | ||
303 | |||
304 | static void bma180_chip_disable(struct bma180_data *data) | ||
305 | { | ||
306 | if (bma180_set_new_data_intr_state(data, 0)) | ||
307 | goto err; | ||
308 | if (bma180_set_ee_writing_state(data, 0)) | ||
309 | goto err; | ||
310 | if (bma180_set_sleep_state(data, 1)) | ||
311 | goto err; | ||
312 | |||
313 | return; | ||
314 | |||
315 | err: | ||
316 | dev_err(&data->client->dev, "failed to disable the chip\n"); | ||
317 | } | ||
318 | |||
319 | static IIO_CONST_ATTR(in_accel_filter_low_pass_3db_frequency_available, | ||
320 | BMA180_FLP_FREQ_AVAILABLE); | ||
321 | static IIO_CONST_ATTR(in_accel_scale_available, BMA180_SCALE_AVAILABLE); | ||
322 | |||
323 | static struct attribute *bma180_attributes[] = { | ||
324 | &iio_const_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr, | ||
325 | &iio_const_attr_in_accel_scale_available.dev_attr.attr, | ||
326 | NULL, | ||
327 | }; | ||
328 | |||
329 | static const struct attribute_group bma180_attrs_group = { | ||
330 | .attrs = bma180_attributes, | ||
331 | }; | ||
332 | |||
333 | static int bma180_read_raw(struct iio_dev *indio_dev, | ||
334 | struct iio_chan_spec const *chan, int *val, int *val2, | ||
335 | long mask) | ||
336 | { | ||
337 | struct bma180_data *data = iio_priv(indio_dev); | ||
338 | int ret; | ||
339 | |||
340 | switch (mask) { | ||
341 | case IIO_CHAN_INFO_RAW: | ||
342 | mutex_lock(&data->mutex); | ||
343 | if (iio_buffer_enabled(indio_dev)) | ||
344 | ret = -EBUSY; | ||
345 | else | ||
346 | ret = bma180_get_acc_reg(data, chan->scan_index); | ||
347 | mutex_unlock(&data->mutex); | ||
348 | if (ret < 0) | ||
349 | return ret; | ||
350 | *val = (s16)ret >> chan->scan_type.shift; | ||
351 | return IIO_VAL_INT; | ||
352 | case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: | ||
353 | *val = data->bw; | ||
354 | return IIO_VAL_INT; | ||
355 | case IIO_CHAN_INFO_SCALE: | ||
356 | *val = 0; | ||
357 | *val2 = data->scale; | ||
358 | return IIO_VAL_INT_PLUS_MICRO; | ||
359 | default: | ||
360 | return -EINVAL; | ||
361 | } | ||
362 | } | ||
363 | |||
364 | static int bma180_write_raw(struct iio_dev *indio_dev, | ||
365 | struct iio_chan_spec const *chan, int val, int val2, long mask) | ||
366 | { | ||
367 | struct bma180_data *data = iio_priv(indio_dev); | ||
368 | int ret; | ||
369 | |||
370 | switch (mask) { | ||
371 | case IIO_CHAN_INFO_SCALE: | ||
372 | if (val) | ||
373 | return -EINVAL; | ||
374 | mutex_lock(&data->mutex); | ||
375 | ret = bma180_set_scale(data, val2); | ||
376 | mutex_unlock(&data->mutex); | ||
377 | return ret; | ||
378 | case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: | ||
379 | mutex_lock(&data->mutex); | ||
380 | ret = bma180_set_bw(data, val); | ||
381 | mutex_unlock(&data->mutex); | ||
382 | return ret; | ||
383 | default: | ||
384 | return -EINVAL; | ||
385 | } | ||
386 | } | ||
387 | |||
388 | static int bma180_update_scan_mode(struct iio_dev *indio_dev, | ||
389 | const unsigned long *scan_mask) | ||
390 | { | ||
391 | struct bma180_data *data = iio_priv(indio_dev); | ||
392 | |||
393 | if (data->buff) | ||
394 | devm_kfree(&indio_dev->dev, data->buff); | ||
395 | data->buff = devm_kzalloc(&indio_dev->dev, | ||
396 | indio_dev->scan_bytes, GFP_KERNEL); | ||
397 | if (!data->buff) | ||
398 | return -ENOMEM; | ||
399 | |||
400 | return 0; | ||
401 | } | ||
402 | |||
403 | static const struct iio_info bma180_info = { | ||
404 | .attrs = &bma180_attrs_group, | ||
405 | .read_raw = bma180_read_raw, | ||
406 | .write_raw = bma180_write_raw, | ||
407 | .update_scan_mode = bma180_update_scan_mode, | ||
408 | .driver_module = THIS_MODULE, | ||
409 | }; | ||
410 | |||
411 | static const char * const bma180_power_modes[] = { | ||
412 | BMA180_LOW_NOISE_STR, | ||
413 | BMA180_LOW_POWER_STR, | ||
414 | }; | ||
415 | |||
416 | static int bma180_get_power_mode(struct iio_dev *indio_dev, | ||
417 | const struct iio_chan_spec *chan) | ||
418 | { | ||
419 | struct bma180_data *data = iio_priv(indio_dev); | ||
420 | |||
421 | return data->pmode; | ||
422 | } | ||
423 | |||
424 | static int bma180_set_power_mode(struct iio_dev *indio_dev, | ||
425 | const struct iio_chan_spec *chan, unsigned int mode) | ||
426 | { | ||
427 | struct bma180_data *data = iio_priv(indio_dev); | ||
428 | int ret; | ||
429 | |||
430 | mutex_lock(&data->mutex); | ||
431 | ret = bma180_set_pmode(data, mode); | ||
432 | mutex_unlock(&data->mutex); | ||
433 | |||
434 | return ret; | ||
435 | } | ||
436 | |||
437 | static const struct iio_enum bma180_power_mode_enum = { | ||
438 | .items = bma180_power_modes, | ||
439 | .num_items = ARRAY_SIZE(bma180_power_modes), | ||
440 | .get = bma180_get_power_mode, | ||
441 | .set = bma180_set_power_mode, | ||
442 | }; | ||
443 | |||
444 | static const struct iio_chan_spec_ext_info bma180_ext_info[] = { | ||
445 | IIO_ENUM("power_mode", true, &bma180_power_mode_enum), | ||
446 | IIO_ENUM_AVAILABLE("power_mode", &bma180_power_mode_enum), | ||
447 | { }, | ||
448 | }; | ||
449 | |||
450 | #define BMA180_CHANNEL(_index) { \ | ||
451 | .type = IIO_ACCEL, \ | ||
452 | .indexed = 1, \ | ||
453 | .channel = (_index), \ | ||
454 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ | ||
455 | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ | ||
456 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ | ||
457 | .scan_index = (_index), \ | ||
458 | .scan_type = IIO_ST('s', 14, 16, 2), \ | ||
459 | .ext_info = bma180_ext_info, \ | ||
460 | } | ||
461 | |||
462 | static const struct iio_chan_spec bma180_channels[] = { | ||
463 | BMA180_CHANNEL(AXIS_X), | ||
464 | BMA180_CHANNEL(AXIS_Y), | ||
465 | BMA180_CHANNEL(AXIS_Z), | ||
466 | IIO_CHAN_SOFT_TIMESTAMP(4), | ||
467 | }; | ||
468 | |||
469 | static irqreturn_t bma180_trigger_handler(int irq, void *p) | ||
470 | { | ||
471 | struct iio_poll_func *pf = p; | ||
472 | struct iio_dev *indio_dev = pf->indio_dev; | ||
473 | struct bma180_data *data = iio_priv(indio_dev); | ||
474 | int bit, ret, i = 0; | ||
475 | |||
476 | mutex_lock(&data->mutex); | ||
477 | if (indio_dev->scan_timestamp) { | ||
478 | ret = indio_dev->scan_bytes / sizeof(s64) - 1; | ||
479 | ((s64 *)data->buff)[ret] = iio_get_time_ns(); | ||
480 | } | ||
481 | |||
482 | for_each_set_bit(bit, indio_dev->buffer->scan_mask, | ||
483 | indio_dev->masklength) { | ||
484 | ret = bma180_get_acc_reg(data, bit); | ||
485 | if (ret < 0) { | ||
486 | mutex_unlock(&data->mutex); | ||
487 | goto err; | ||
488 | } | ||
489 | ((s16 *)data->buff)[i++] = ret; | ||
490 | } | ||
491 | mutex_unlock(&data->mutex); | ||
492 | |||
493 | iio_push_to_buffers(indio_dev, (u8 *)data->buff); | ||
494 | err: | ||
495 | iio_trigger_notify_done(indio_dev->trig); | ||
496 | |||
497 | return IRQ_HANDLED; | ||
498 | } | ||
499 | |||
500 | static int bma180_data_rdy_trigger_set_state(struct iio_trigger *trig, | ||
501 | bool state) | ||
502 | { | ||
503 | struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); | ||
504 | struct bma180_data *data = iio_priv(indio_dev); | ||
505 | |||
506 | return bma180_set_new_data_intr_state(data, state); | ||
507 | } | ||
508 | |||
509 | static int bma180_trig_try_reen(struct iio_trigger *trig) | ||
510 | { | ||
511 | struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); | ||
512 | struct bma180_data *data = iio_priv(indio_dev); | ||
513 | |||
514 | return bma180_reset_intr(data); | ||
515 | } | ||
516 | |||
517 | static const struct iio_trigger_ops bma180_trigger_ops = { | ||
518 | .set_trigger_state = bma180_data_rdy_trigger_set_state, | ||
519 | .try_reenable = bma180_trig_try_reen, | ||
520 | .owner = THIS_MODULE, | ||
521 | }; | ||
522 | |||
523 | static int bma180_probe(struct i2c_client *client, | ||
524 | const struct i2c_device_id *id) | ||
525 | { | ||
526 | struct bma180_data *data; | ||
527 | struct iio_dev *indio_dev; | ||
528 | struct iio_trigger *trig; | ||
529 | int ret; | ||
530 | |||
531 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); | ||
532 | if (!indio_dev) | ||
533 | return -ENOMEM; | ||
534 | |||
535 | data = iio_priv(indio_dev); | ||
536 | i2c_set_clientdata(client, indio_dev); | ||
537 | data->client = client; | ||
538 | |||
539 | ret = bma180_chip_init(data); | ||
540 | if (ret < 0) | ||
541 | goto err_chip_disable; | ||
542 | |||
543 | mutex_init(&data->mutex); | ||
544 | |||
545 | indio_dev->dev.parent = &client->dev; | ||
546 | indio_dev->channels = bma180_channels; | ||
547 | indio_dev->num_channels = ARRAY_SIZE(bma180_channels); | ||
548 | indio_dev->name = BMA180_DRV_NAME; | ||
549 | indio_dev->modes = INDIO_DIRECT_MODE; | ||
550 | indio_dev->info = &bma180_info; | ||
551 | |||
552 | trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, indio_dev->id); | ||
553 | if (!trig) { | ||
554 | ret = -ENOMEM; | ||
555 | goto err_chip_disable; | ||
556 | } | ||
557 | |||
558 | ret = devm_request_irq(&client->dev, client->irq, | ||
559 | iio_trigger_generic_data_rdy_poll, | ||
560 | IRQF_TRIGGER_RISING, BMA180_IRQ_NAME, trig); | ||
561 | if (ret) { | ||
562 | dev_err(&client->dev, "unable to request IRQ\n"); | ||
563 | goto err_trigger_free; | ||
564 | } | ||
565 | |||
566 | trig->dev.parent = &client->dev; | ||
567 | trig->ops = &bma180_trigger_ops; | ||
568 | iio_trigger_set_drvdata(trig, indio_dev); | ||
569 | data->trig = trig; | ||
570 | indio_dev->trig = trig; | ||
571 | |||
572 | ret = iio_trigger_register(trig); | ||
573 | if (ret) | ||
574 | goto err_trigger_free; | ||
575 | |||
576 | ret = iio_triggered_buffer_setup(indio_dev, NULL, | ||
577 | bma180_trigger_handler, NULL); | ||
578 | if (ret < 0) { | ||
579 | dev_err(&client->dev, "unable to setup iio triggered buffer\n"); | ||
580 | goto err_trigger_unregister; | ||
581 | } | ||
582 | |||
583 | ret = iio_device_register(indio_dev); | ||
584 | if (ret < 0) { | ||
585 | dev_err(&client->dev, "unable to register iio device\n"); | ||
586 | goto err_buffer_cleanup; | ||
587 | } | ||
588 | |||
589 | return 0; | ||
590 | |||
591 | err_buffer_cleanup: | ||
592 | iio_triggered_buffer_cleanup(indio_dev); | ||
593 | err_trigger_unregister: | ||
594 | iio_trigger_unregister(trig); | ||
595 | err_trigger_free: | ||
596 | iio_trigger_free(trig); | ||
597 | err_chip_disable: | ||
598 | bma180_chip_disable(data); | ||
599 | |||
600 | return ret; | ||
601 | } | ||
602 | |||
603 | static int bma180_remove(struct i2c_client *client) | ||
604 | { | ||
605 | struct iio_dev *indio_dev = i2c_get_clientdata(client); | ||
606 | struct bma180_data *data = iio_priv(indio_dev); | ||
607 | |||
608 | iio_device_unregister(indio_dev); | ||
609 | iio_triggered_buffer_cleanup(indio_dev); | ||
610 | iio_trigger_unregister(data->trig); | ||
611 | iio_trigger_free(data->trig); | ||
612 | |||
613 | mutex_lock(&data->mutex); | ||
614 | bma180_chip_disable(data); | ||
615 | mutex_unlock(&data->mutex); | ||
616 | |||
617 | return 0; | ||
618 | } | ||
619 | |||
620 | #ifdef CONFIG_PM_SLEEP | ||
621 | static int bma180_suspend(struct device *dev) | ||
622 | { | ||
623 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); | ||
624 | struct bma180_data *data = iio_priv(indio_dev); | ||
625 | int ret; | ||
626 | |||
627 | mutex_lock(&data->mutex); | ||
628 | ret = bma180_set_sleep_state(data, 1); | ||
629 | mutex_unlock(&data->mutex); | ||
630 | |||
631 | return ret; | ||
632 | } | ||
633 | |||
634 | static int bma180_resume(struct device *dev) | ||
635 | { | ||
636 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); | ||
637 | struct bma180_data *data = iio_priv(indio_dev); | ||
638 | int ret; | ||
639 | |||
640 | mutex_lock(&data->mutex); | ||
641 | ret = bma180_set_sleep_state(data, 0); | ||
642 | mutex_unlock(&data->mutex); | ||
643 | |||
644 | return ret; | ||
645 | } | ||
646 | |||
647 | static SIMPLE_DEV_PM_OPS(bma180_pm_ops, bma180_suspend, bma180_resume); | ||
648 | #define BMA180_PM_OPS (&bma180_pm_ops) | ||
649 | #else | ||
650 | #define BMA180_PM_OPS NULL | ||
651 | #endif | ||
652 | |||
653 | static struct i2c_device_id bma180_id[] = { | ||
654 | { BMA180_DRV_NAME, 0 }, | ||
655 | { } | ||
656 | }; | ||
657 | |||
658 | MODULE_DEVICE_TABLE(i2c, bma180_id); | ||
659 | |||
660 | static struct i2c_driver bma180_driver = { | ||
661 | .driver = { | ||
662 | .name = BMA180_DRV_NAME, | ||
663 | .owner = THIS_MODULE, | ||
664 | .pm = BMA180_PM_OPS, | ||
665 | }, | ||
666 | .probe = bma180_probe, | ||
667 | .remove = bma180_remove, | ||
668 | .id_table = bma180_id, | ||
669 | }; | ||
670 | |||
671 | module_i2c_driver(bma180_driver); | ||
672 | |||
673 | MODULE_AUTHOR("Kravchenko Oleksandr <x0199363@ti.com>"); | ||
674 | MODULE_AUTHOR("Texas Instruments, Inc."); | ||
675 | MODULE_DESCRIPTION("Bosch BMA180 triaxial acceleration sensor"); | ||
676 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c index 423e079460d3..84be63bdf038 100644 --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c | |||
@@ -39,6 +39,10 @@ | |||
39 | #define at91_adc_writel(st, reg, val) \ | 39 | #define at91_adc_writel(st, reg, val) \ |
40 | (writel_relaxed(val, st->reg_base + reg)) | 40 | (writel_relaxed(val, st->reg_base + reg)) |
41 | 41 | ||
42 | struct at91_adc_caps { | ||
43 | struct at91_adc_reg_desc registers; | ||
44 | }; | ||
45 | |||
42 | struct at91_adc_state { | 46 | struct at91_adc_state { |
43 | struct clk *adc_clk; | 47 | struct clk *adc_clk; |
44 | u16 *buffer; | 48 | u16 *buffer; |
@@ -62,6 +66,7 @@ struct at91_adc_state { | |||
62 | u32 res; /* resolution used for convertions */ | 66 | u32 res; /* resolution used for convertions */ |
63 | bool low_res; /* the resolution corresponds to the lowest one */ | 67 | bool low_res; /* the resolution corresponds to the lowest one */ |
64 | wait_queue_head_t wq_data_avail; | 68 | wait_queue_head_t wq_data_avail; |
69 | struct at91_adc_caps *caps; | ||
65 | }; | 70 | }; |
66 | 71 | ||
67 | static irqreturn_t at91_adc_trigger_handler(int irq, void *p) | 72 | static irqreturn_t at91_adc_trigger_handler(int irq, void *p) |
@@ -429,6 +434,8 @@ ret: | |||
429 | return ret; | 434 | return ret; |
430 | } | 435 | } |
431 | 436 | ||
437 | static const struct of_device_id at91_adc_dt_ids[]; | ||
438 | |||
432 | static int at91_adc_probe_dt(struct at91_adc_state *st, | 439 | static int at91_adc_probe_dt(struct at91_adc_state *st, |
433 | struct platform_device *pdev) | 440 | struct platform_device *pdev) |
434 | { | 441 | { |
@@ -441,6 +448,9 @@ static int at91_adc_probe_dt(struct at91_adc_state *st, | |||
441 | if (!node) | 448 | if (!node) |
442 | return -EINVAL; | 449 | return -EINVAL; |
443 | 450 | ||
451 | st->caps = (struct at91_adc_caps *) | ||
452 | of_match_device(at91_adc_dt_ids, &pdev->dev)->data; | ||
453 | |||
444 | st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers"); | 454 | st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers"); |
445 | 455 | ||
446 | if (of_property_read_u32(node, "atmel,adc-channels-used", &prop)) { | 456 | if (of_property_read_u32(node, "atmel,adc-channels-used", &prop)) { |
@@ -481,43 +491,7 @@ static int at91_adc_probe_dt(struct at91_adc_state *st, | |||
481 | if (ret) | 491 | if (ret) |
482 | goto error_ret; | 492 | goto error_ret; |
483 | 493 | ||
484 | st->registers = devm_kzalloc(&idev->dev, | 494 | st->registers = &st->caps->registers; |
485 | sizeof(struct at91_adc_reg_desc), | ||
486 | GFP_KERNEL); | ||
487 | if (!st->registers) { | ||
488 | dev_err(&idev->dev, "Could not allocate register memory.\n"); | ||
489 | ret = -ENOMEM; | ||
490 | goto error_ret; | ||
491 | } | ||
492 | |||
493 | if (of_property_read_u32(node, "atmel,adc-channel-base", &prop)) { | ||
494 | dev_err(&idev->dev, "Missing adc-channel-base property in the DT.\n"); | ||
495 | ret = -EINVAL; | ||
496 | goto error_ret; | ||
497 | } | ||
498 | st->registers->channel_base = prop; | ||
499 | |||
500 | if (of_property_read_u32(node, "atmel,adc-drdy-mask", &prop)) { | ||
501 | dev_err(&idev->dev, "Missing adc-drdy-mask property in the DT.\n"); | ||
502 | ret = -EINVAL; | ||
503 | goto error_ret; | ||
504 | } | ||
505 | st->registers->drdy_mask = prop; | ||
506 | |||
507 | if (of_property_read_u32(node, "atmel,adc-status-register", &prop)) { | ||
508 | dev_err(&idev->dev, "Missing adc-status-register property in the DT.\n"); | ||
509 | ret = -EINVAL; | ||
510 | goto error_ret; | ||
511 | } | ||
512 | st->registers->status_register = prop; | ||
513 | |||
514 | if (of_property_read_u32(node, "atmel,adc-trigger-register", &prop)) { | ||
515 | dev_err(&idev->dev, "Missing adc-trigger-register property in the DT.\n"); | ||
516 | ret = -EINVAL; | ||
517 | goto error_ret; | ||
518 | } | ||
519 | st->registers->trigger_register = prop; | ||
520 | |||
521 | st->trigger_number = of_get_child_count(node); | 495 | st->trigger_number = of_get_child_count(node); |
522 | st->trigger_list = devm_kzalloc(&idev->dev, st->trigger_number * | 496 | st->trigger_list = devm_kzalloc(&idev->dev, st->trigger_number * |
523 | sizeof(struct at91_adc_trigger), | 497 | sizeof(struct at91_adc_trigger), |
@@ -698,8 +672,8 @@ static int at91_adc_probe(struct platform_device *pdev) | |||
698 | shtim = round_up((st->sample_hold_time * adc_clk / | 672 | shtim = round_up((st->sample_hold_time * adc_clk / |
699 | 1000000) - 1, 1); | 673 | 1000000) - 1, 1); |
700 | 674 | ||
701 | reg = AT91_ADC_PRESCAL_(prsc) & AT91_ADC_PRESCAL; | 675 | reg = AT91_ADC_PRESCAL_(prsc) & st->registers->mr_prescal_mask; |
702 | reg |= AT91_ADC_STARTUP_(ticks) & AT91_ADC_STARTUP; | 676 | reg |= AT91_ADC_STARTUP_(ticks) & st->registers->mr_startup_mask; |
703 | if (st->low_res) | 677 | if (st->low_res) |
704 | reg |= AT91_ADC_LOWRES; | 678 | reg |= AT91_ADC_LOWRES; |
705 | if (st->sleep_mode) | 679 | if (st->sleep_mode) |
@@ -766,8 +740,44 @@ static int at91_adc_remove(struct platform_device *pdev) | |||
766 | } | 740 | } |
767 | 741 | ||
768 | #ifdef CONFIG_OF | 742 | #ifdef CONFIG_OF |
743 | static struct at91_adc_caps at91sam9260_caps = { | ||
744 | .registers = { | ||
745 | .channel_base = AT91_ADC_CHR(0), | ||
746 | .drdy_mask = AT91_ADC_DRDY, | ||
747 | .status_register = AT91_ADC_SR, | ||
748 | .trigger_register = AT91_ADC_TRGR_9260, | ||
749 | .mr_prescal_mask = AT91_ADC_PRESCAL_9260, | ||
750 | .mr_startup_mask = AT91_ADC_STARTUP_9260, | ||
751 | }, | ||
752 | }; | ||
753 | |||
754 | static struct at91_adc_caps at91sam9g45_caps = { | ||
755 | .registers = { | ||
756 | .channel_base = AT91_ADC_CHR(0), | ||
757 | .drdy_mask = AT91_ADC_DRDY, | ||
758 | .status_register = AT91_ADC_SR, | ||
759 | .trigger_register = AT91_ADC_TRGR_9G45, | ||
760 | .mr_prescal_mask = AT91_ADC_PRESCAL_9G45, | ||
761 | .mr_startup_mask = AT91_ADC_STARTUP_9G45, | ||
762 | }, | ||
763 | }; | ||
764 | |||
765 | static struct at91_adc_caps at91sam9x5_caps = { | ||
766 | .registers = { | ||
767 | .channel_base = AT91_ADC_CDR0_9X5, | ||
768 | .drdy_mask = AT91_ADC_SR_DRDY_9X5, | ||
769 | .status_register = AT91_ADC_SR_9X5, | ||
770 | .trigger_register = AT91_ADC_TRGR_9X5, | ||
771 | /* prescal mask is same as 9G45 */ | ||
772 | .mr_prescal_mask = AT91_ADC_PRESCAL_9G45, | ||
773 | .mr_startup_mask = AT91_ADC_STARTUP_9X5, | ||
774 | }, | ||
775 | }; | ||
776 | |||
769 | static const struct of_device_id at91_adc_dt_ids[] = { | 777 | static const struct of_device_id at91_adc_dt_ids[] = { |
770 | { .compatible = "atmel,at91sam9260-adc" }, | 778 | { .compatible = "atmel,at91sam9260-adc", .data = &at91sam9260_caps }, |
779 | { .compatible = "atmel,at91sam9g45-adc", .data = &at91sam9g45_caps }, | ||
780 | { .compatible = "atmel,at91sam9x5-adc", .data = &at91sam9x5_caps }, | ||
771 | {}, | 781 | {}, |
772 | }; | 782 | }; |
773 | MODULE_DEVICE_TABLE(of, at91_adc_dt_ids); | 783 | MODULE_DEVICE_TABLE(of, at91_adc_dt_ids); |
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c index a558516d140d..0ea96c058c08 100644 --- a/drivers/iio/adc/twl6030-gpadc.c +++ b/drivers/iio/adc/twl6030-gpadc.c | |||
@@ -537,8 +537,8 @@ static int twl6030_gpadc_read_raw(struct iio_dev *indio_dev, | |||
537 | ret = -ETIMEDOUT; | 537 | ret = -ETIMEDOUT; |
538 | goto err; | 538 | goto err; |
539 | } else if (timeout < 0) { | 539 | } else if (timeout < 0) { |
540 | goto err; | ||
541 | ret = -EINTR; | 540 | ret = -EINTR; |
541 | goto err; | ||
542 | } | 542 | } |
543 | 543 | ||
544 | switch (mask) { | 544 | switch (mask) { |
diff --git a/drivers/staging/iio/accel/adis16201_core.c b/drivers/staging/iio/accel/adis16201_core.c index ab8ec7af88b4..2105576fa77c 100644 --- a/drivers/staging/iio/accel/adis16201_core.c +++ b/drivers/staging/iio/accel/adis16201_core.c | |||
@@ -182,11 +182,10 @@ static int adis16201_probe(struct spi_device *spi) | |||
182 | struct iio_dev *indio_dev; | 182 | struct iio_dev *indio_dev; |
183 | 183 | ||
184 | /* setup the industrialio driver allocated elements */ | 184 | /* setup the industrialio driver allocated elements */ |
185 | indio_dev = iio_device_alloc(sizeof(*st)); | 185 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
186 | if (indio_dev == NULL) { | 186 | if (!indio_dev) |
187 | ret = -ENOMEM; | 187 | return -ENOMEM; |
188 | goto error_ret; | 188 | |
189 | } | ||
190 | st = iio_priv(indio_dev); | 189 | st = iio_priv(indio_dev); |
191 | /* this is only used for removal purposes */ | 190 | /* this is only used for removal purposes */ |
192 | spi_set_drvdata(spi, indio_dev); | 191 | spi_set_drvdata(spi, indio_dev); |
@@ -201,10 +200,10 @@ static int adis16201_probe(struct spi_device *spi) | |||
201 | 200 | ||
202 | ret = adis_init(st, indio_dev, spi, &adis16201_data); | 201 | ret = adis_init(st, indio_dev, spi, &adis16201_data); |
203 | if (ret) | 202 | if (ret) |
204 | goto error_free_dev; | 203 | return ret; |
205 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); | 204 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); |
206 | if (ret) | 205 | if (ret) |
207 | goto error_free_dev; | 206 | return ret; |
208 | 207 | ||
209 | /* Get the device into a sane initial state */ | 208 | /* Get the device into a sane initial state */ |
210 | ret = adis_initial_startup(st); | 209 | ret = adis_initial_startup(st); |
@@ -218,9 +217,6 @@ static int adis16201_probe(struct spi_device *spi) | |||
218 | 217 | ||
219 | error_cleanup_buffer_trigger: | 218 | error_cleanup_buffer_trigger: |
220 | adis_cleanup_buffer_and_trigger(st, indio_dev); | 219 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
221 | error_free_dev: | ||
222 | iio_device_free(indio_dev); | ||
223 | error_ret: | ||
224 | return ret; | 220 | return ret; |
225 | } | 221 | } |
226 | 222 | ||
@@ -231,7 +227,6 @@ static int adis16201_remove(struct spi_device *spi) | |||
231 | 227 | ||
232 | iio_device_unregister(indio_dev); | 228 | iio_device_unregister(indio_dev); |
233 | adis_cleanup_buffer_and_trigger(st, indio_dev); | 229 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
234 | iio_device_free(indio_dev); | ||
235 | 230 | ||
236 | return 0; | 231 | return 0; |
237 | } | 232 | } |
diff --git a/drivers/staging/iio/accel/adis16203_core.c b/drivers/staging/iio/accel/adis16203_core.c index b08ac8fdeee2..409a28ed9043 100644 --- a/drivers/staging/iio/accel/adis16203_core.c +++ b/drivers/staging/iio/accel/adis16203_core.c | |||
@@ -148,11 +148,9 @@ static int adis16203_probe(struct spi_device *spi) | |||
148 | struct adis *st; | 148 | struct adis *st; |
149 | 149 | ||
150 | /* setup the industrialio driver allocated elements */ | 150 | /* setup the industrialio driver allocated elements */ |
151 | indio_dev = iio_device_alloc(sizeof(*st)); | 151 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
152 | if (indio_dev == NULL) { | 152 | if (!indio_dev) |
153 | ret = -ENOMEM; | 153 | return -ENOMEM; |
154 | goto error_ret; | ||
155 | } | ||
156 | st = iio_priv(indio_dev); | 154 | st = iio_priv(indio_dev); |
157 | /* this is only used for removal purposes */ | 155 | /* this is only used for removal purposes */ |
158 | spi_set_drvdata(spi, indio_dev); | 156 | spi_set_drvdata(spi, indio_dev); |
@@ -166,11 +164,11 @@ static int adis16203_probe(struct spi_device *spi) | |||
166 | 164 | ||
167 | ret = adis_init(st, indio_dev, spi, &adis16203_data); | 165 | ret = adis_init(st, indio_dev, spi, &adis16203_data); |
168 | if (ret) | 166 | if (ret) |
169 | goto error_free_dev; | 167 | return ret; |
170 | 168 | ||
171 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); | 169 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); |
172 | if (ret) | 170 | if (ret) |
173 | goto error_free_dev; | 171 | return ret; |
174 | 172 | ||
175 | /* Get the device into a sane initial state */ | 173 | /* Get the device into a sane initial state */ |
176 | ret = adis_initial_startup(st); | 174 | ret = adis_initial_startup(st); |
@@ -185,9 +183,6 @@ static int adis16203_probe(struct spi_device *spi) | |||
185 | 183 | ||
186 | error_cleanup_buffer_trigger: | 184 | error_cleanup_buffer_trigger: |
187 | adis_cleanup_buffer_and_trigger(st, indio_dev); | 185 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
188 | error_free_dev: | ||
189 | iio_device_free(indio_dev); | ||
190 | error_ret: | ||
191 | return ret; | 186 | return ret; |
192 | } | 187 | } |
193 | 188 | ||
@@ -198,7 +193,6 @@ static int adis16203_remove(struct spi_device *spi) | |||
198 | 193 | ||
199 | iio_device_unregister(indio_dev); | 194 | iio_device_unregister(indio_dev); |
200 | adis_cleanup_buffer_and_trigger(st, indio_dev); | 195 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
201 | iio_device_free(indio_dev); | ||
202 | 196 | ||
203 | return 0; | 197 | return 0; |
204 | } | 198 | } |
diff --git a/drivers/staging/iio/accel/adis16204_core.c b/drivers/staging/iio/accel/adis16204_core.c index 792ec25a50dc..b8ea76857cd6 100644 --- a/drivers/staging/iio/accel/adis16204_core.c +++ b/drivers/staging/iio/accel/adis16204_core.c | |||
@@ -187,11 +187,9 @@ static int adis16204_probe(struct spi_device *spi) | |||
187 | struct iio_dev *indio_dev; | 187 | struct iio_dev *indio_dev; |
188 | 188 | ||
189 | /* setup the industrialio driver allocated elements */ | 189 | /* setup the industrialio driver allocated elements */ |
190 | indio_dev = iio_device_alloc(sizeof(*st)); | 190 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
191 | if (indio_dev == NULL) { | 191 | if (!indio_dev) |
192 | ret = -ENOMEM; | 192 | return -ENOMEM; |
193 | goto error_ret; | ||
194 | } | ||
195 | st = iio_priv(indio_dev); | 193 | st = iio_priv(indio_dev); |
196 | /* this is only used for removal purposes */ | 194 | /* this is only used for removal purposes */ |
197 | spi_set_drvdata(spi, indio_dev); | 195 | spi_set_drvdata(spi, indio_dev); |
@@ -205,11 +203,11 @@ static int adis16204_probe(struct spi_device *spi) | |||
205 | 203 | ||
206 | ret = adis_init(st, indio_dev, spi, &adis16204_data); | 204 | ret = adis_init(st, indio_dev, spi, &adis16204_data); |
207 | if (ret) | 205 | if (ret) |
208 | goto error_free_dev; | 206 | return ret; |
209 | 207 | ||
210 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); | 208 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); |
211 | if (ret) | 209 | if (ret) |
212 | goto error_free_dev; | 210 | return ret; |
213 | 211 | ||
214 | /* Get the device into a sane initial state */ | 212 | /* Get the device into a sane initial state */ |
215 | ret = adis_initial_startup(st); | 213 | ret = adis_initial_startup(st); |
@@ -223,9 +221,6 @@ static int adis16204_probe(struct spi_device *spi) | |||
223 | 221 | ||
224 | error_cleanup_buffer_trigger: | 222 | error_cleanup_buffer_trigger: |
225 | adis_cleanup_buffer_and_trigger(st, indio_dev); | 223 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
226 | error_free_dev: | ||
227 | iio_device_free(indio_dev); | ||
228 | error_ret: | ||
229 | return ret; | 224 | return ret; |
230 | } | 225 | } |
231 | 226 | ||
@@ -236,7 +231,6 @@ static int adis16204_remove(struct spi_device *spi) | |||
236 | 231 | ||
237 | iio_device_unregister(indio_dev); | 232 | iio_device_unregister(indio_dev); |
238 | adis_cleanup_buffer_and_trigger(st, indio_dev); | 233 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
239 | iio_device_free(indio_dev); | ||
240 | 234 | ||
241 | return 0; | 235 | return 0; |
242 | } | 236 | } |
diff --git a/drivers/staging/iio/accel/adis16209_core.c b/drivers/staging/iio/accel/adis16209_core.c index 323c169d699c..4492e51d8886 100644 --- a/drivers/staging/iio/accel/adis16209_core.c +++ b/drivers/staging/iio/accel/adis16209_core.c | |||
@@ -183,11 +183,9 @@ static int adis16209_probe(struct spi_device *spi) | |||
183 | struct iio_dev *indio_dev; | 183 | struct iio_dev *indio_dev; |
184 | 184 | ||
185 | /* setup the industrialio driver allocated elements */ | 185 | /* setup the industrialio driver allocated elements */ |
186 | indio_dev = iio_device_alloc(sizeof(*st)); | 186 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
187 | if (indio_dev == NULL) { | 187 | if (!indio_dev) |
188 | ret = -ENOMEM; | 188 | return -ENOMEM; |
189 | goto error_ret; | ||
190 | } | ||
191 | st = iio_priv(indio_dev); | 189 | st = iio_priv(indio_dev); |
192 | /* this is only used for removal purposes */ | 190 | /* this is only used for removal purposes */ |
193 | spi_set_drvdata(spi, indio_dev); | 191 | spi_set_drvdata(spi, indio_dev); |
@@ -201,10 +199,10 @@ static int adis16209_probe(struct spi_device *spi) | |||
201 | 199 | ||
202 | ret = adis_init(st, indio_dev, spi, &adis16209_data); | 200 | ret = adis_init(st, indio_dev, spi, &adis16209_data); |
203 | if (ret) | 201 | if (ret) |
204 | goto error_free_dev; | 202 | return ret; |
205 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); | 203 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); |
206 | if (ret) | 204 | if (ret) |
207 | goto error_free_dev; | 205 | return ret; |
208 | 206 | ||
209 | /* Get the device into a sane initial state */ | 207 | /* Get the device into a sane initial state */ |
210 | ret = adis_initial_startup(st); | 208 | ret = adis_initial_startup(st); |
@@ -218,9 +216,6 @@ static int adis16209_probe(struct spi_device *spi) | |||
218 | 216 | ||
219 | error_cleanup_buffer_trigger: | 217 | error_cleanup_buffer_trigger: |
220 | adis_cleanup_buffer_and_trigger(st, indio_dev); | 218 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
221 | error_free_dev: | ||
222 | iio_device_free(indio_dev); | ||
223 | error_ret: | ||
224 | return ret; | 219 | return ret; |
225 | } | 220 | } |
226 | 221 | ||
@@ -231,7 +226,6 @@ static int adis16209_remove(struct spi_device *spi) | |||
231 | 226 | ||
232 | iio_device_unregister(indio_dev); | 227 | iio_device_unregister(indio_dev); |
233 | adis_cleanup_buffer_and_trigger(st, indio_dev); | 228 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
234 | iio_device_free(indio_dev); | ||
235 | 229 | ||
236 | return 0; | 230 | return 0; |
237 | } | 231 | } |
diff --git a/drivers/staging/iio/accel/adis16220_core.c b/drivers/staging/iio/accel/adis16220_core.c index 0e72f795ed09..5c289614357c 100644 --- a/drivers/staging/iio/accel/adis16220_core.c +++ b/drivers/staging/iio/accel/adis16220_core.c | |||
@@ -428,11 +428,9 @@ static int adis16220_probe(struct spi_device *spi) | |||
428 | struct iio_dev *indio_dev; | 428 | struct iio_dev *indio_dev; |
429 | 429 | ||
430 | /* setup the industrialio driver allocated elements */ | 430 | /* setup the industrialio driver allocated elements */ |
431 | indio_dev = iio_device_alloc(sizeof(*st)); | 431 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
432 | if (indio_dev == NULL) { | 432 | if (!indio_dev) |
433 | ret = -ENOMEM; | 433 | return -ENOMEM; |
434 | goto error_ret; | ||
435 | } | ||
436 | 434 | ||
437 | st = iio_priv(indio_dev); | 435 | st = iio_priv(indio_dev); |
438 | /* this is only used for removal purposes */ | 436 | /* this is only used for removal purposes */ |
@@ -447,7 +445,7 @@ static int adis16220_probe(struct spi_device *spi) | |||
447 | 445 | ||
448 | ret = iio_device_register(indio_dev); | 446 | ret = iio_device_register(indio_dev); |
449 | if (ret) | 447 | if (ret) |
450 | goto error_free_dev; | 448 | return ret; |
451 | 449 | ||
452 | ret = sysfs_create_bin_file(&indio_dev->dev.kobj, &accel_bin); | 450 | ret = sysfs_create_bin_file(&indio_dev->dev.kobj, &accel_bin); |
453 | if (ret) | 451 | if (ret) |
@@ -478,9 +476,6 @@ error_rm_accel_bin: | |||
478 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &accel_bin); | 476 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &accel_bin); |
479 | error_unregister_dev: | 477 | error_unregister_dev: |
480 | iio_device_unregister(indio_dev); | 478 | iio_device_unregister(indio_dev); |
481 | error_free_dev: | ||
482 | iio_device_free(indio_dev); | ||
483 | error_ret: | ||
484 | return ret; | 479 | return ret; |
485 | } | 480 | } |
486 | 481 | ||
@@ -492,7 +487,6 @@ static int adis16220_remove(struct spi_device *spi) | |||
492 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &adc1_bin); | 487 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &adc1_bin); |
493 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &accel_bin); | 488 | sysfs_remove_bin_file(&indio_dev->dev.kobj, &accel_bin); |
494 | iio_device_unregister(indio_dev); | 489 | iio_device_unregister(indio_dev); |
495 | iio_device_free(indio_dev); | ||
496 | 490 | ||
497 | return 0; | 491 | return 0; |
498 | } | 492 | } |
diff --git a/drivers/staging/iio/accel/adis16240_core.c b/drivers/staging/iio/accel/adis16240_core.c index fd1f0fd0fba8..3a303a03d028 100644 --- a/drivers/staging/iio/accel/adis16240_core.c +++ b/drivers/staging/iio/accel/adis16240_core.c | |||
@@ -236,11 +236,9 @@ static int adis16240_probe(struct spi_device *spi) | |||
236 | struct iio_dev *indio_dev; | 236 | struct iio_dev *indio_dev; |
237 | 237 | ||
238 | /* setup the industrialio driver allocated elements */ | 238 | /* setup the industrialio driver allocated elements */ |
239 | indio_dev = iio_device_alloc(sizeof(*st)); | 239 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
240 | if (indio_dev == NULL) { | 240 | if (!indio_dev) |
241 | ret = -ENOMEM; | 241 | return -ENOMEM; |
242 | goto error_ret; | ||
243 | } | ||
244 | st = iio_priv(indio_dev); | 242 | st = iio_priv(indio_dev); |
245 | /* this is only used for removal purposes */ | 243 | /* this is only used for removal purposes */ |
246 | spi_set_drvdata(spi, indio_dev); | 244 | spi_set_drvdata(spi, indio_dev); |
@@ -254,10 +252,10 @@ static int adis16240_probe(struct spi_device *spi) | |||
254 | 252 | ||
255 | ret = adis_init(st, indio_dev, spi, &adis16240_data); | 253 | ret = adis_init(st, indio_dev, spi, &adis16240_data); |
256 | if (ret) | 254 | if (ret) |
257 | goto error_free_dev; | 255 | return ret; |
258 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); | 256 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); |
259 | if (ret) | 257 | if (ret) |
260 | goto error_free_dev; | 258 | return ret; |
261 | 259 | ||
262 | /* Get the device into a sane initial state */ | 260 | /* Get the device into a sane initial state */ |
263 | ret = adis_initial_startup(st); | 261 | ret = adis_initial_startup(st); |
@@ -270,9 +268,6 @@ static int adis16240_probe(struct spi_device *spi) | |||
270 | 268 | ||
271 | error_cleanup_buffer_trigger: | 269 | error_cleanup_buffer_trigger: |
272 | adis_cleanup_buffer_and_trigger(st, indio_dev); | 270 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
273 | error_free_dev: | ||
274 | iio_device_free(indio_dev); | ||
275 | error_ret: | ||
276 | return ret; | 271 | return ret; |
277 | } | 272 | } |
278 | 273 | ||
@@ -283,7 +278,6 @@ static int adis16240_remove(struct spi_device *spi) | |||
283 | 278 | ||
284 | iio_device_unregister(indio_dev); | 279 | iio_device_unregister(indio_dev); |
285 | adis_cleanup_buffer_and_trigger(st, indio_dev); | 280 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
286 | iio_device_free(indio_dev); | ||
287 | 281 | ||
288 | return 0; | 282 | return 0; |
289 | } | 283 | } |
diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c index 8ed75a94f465..bb852dc9c987 100644 --- a/drivers/staging/iio/accel/lis3l02dq_core.c +++ b/drivers/staging/iio/accel/lis3l02dq_core.c | |||
@@ -668,11 +668,9 @@ static int lis3l02dq_probe(struct spi_device *spi) | |||
668 | struct lis3l02dq_state *st; | 668 | struct lis3l02dq_state *st; |
669 | struct iio_dev *indio_dev; | 669 | struct iio_dev *indio_dev; |
670 | 670 | ||
671 | indio_dev = iio_device_alloc(sizeof *st); | 671 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
672 | if (indio_dev == NULL) { | 672 | if (!indio_dev) |
673 | ret = -ENOMEM; | 673 | return -ENOMEM; |
674 | goto error_ret; | ||
675 | } | ||
676 | st = iio_priv(indio_dev); | 674 | st = iio_priv(indio_dev); |
677 | /* this is only used for removal purposes */ | 675 | /* this is only used for removal purposes */ |
678 | spi_set_drvdata(spi, indio_dev); | 676 | spi_set_drvdata(spi, indio_dev); |
@@ -690,7 +688,7 @@ static int lis3l02dq_probe(struct spi_device *spi) | |||
690 | 688 | ||
691 | ret = lis3l02dq_configure_buffer(indio_dev); | 689 | ret = lis3l02dq_configure_buffer(indio_dev); |
692 | if (ret) | 690 | if (ret) |
693 | goto error_free_dev; | 691 | return ret; |
694 | 692 | ||
695 | ret = iio_buffer_register(indio_dev, | 693 | ret = iio_buffer_register(indio_dev, |
696 | lis3l02dq_channels, | 694 | lis3l02dq_channels, |
@@ -736,9 +734,6 @@ error_uninitialize_buffer: | |||
736 | iio_buffer_unregister(indio_dev); | 734 | iio_buffer_unregister(indio_dev); |
737 | error_unreg_buffer_funcs: | 735 | error_unreg_buffer_funcs: |
738 | lis3l02dq_unconfigure_buffer(indio_dev); | 736 | lis3l02dq_unconfigure_buffer(indio_dev); |
739 | error_free_dev: | ||
740 | iio_device_free(indio_dev); | ||
741 | error_ret: | ||
742 | return ret; | 737 | return ret; |
743 | } | 738 | } |
744 | 739 | ||
@@ -786,8 +781,6 @@ static int lis3l02dq_remove(struct spi_device *spi) | |||
786 | iio_buffer_unregister(indio_dev); | 781 | iio_buffer_unregister(indio_dev); |
787 | lis3l02dq_unconfigure_buffer(indio_dev); | 782 | lis3l02dq_unconfigure_buffer(indio_dev); |
788 | 783 | ||
789 | iio_device_free(indio_dev); | ||
790 | |||
791 | return 0; | 784 | return 0; |
792 | } | 785 | } |
793 | 786 | ||
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c index 32950ad94857..48a25ba290f5 100644 --- a/drivers/staging/iio/accel/sca3000_core.c +++ b/drivers/staging/iio/accel/sca3000_core.c | |||
@@ -1135,11 +1135,9 @@ static int sca3000_probe(struct spi_device *spi) | |||
1135 | struct sca3000_state *st; | 1135 | struct sca3000_state *st; |
1136 | struct iio_dev *indio_dev; | 1136 | struct iio_dev *indio_dev; |
1137 | 1137 | ||
1138 | indio_dev = iio_device_alloc(sizeof(*st)); | 1138 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
1139 | if (indio_dev == NULL) { | 1139 | if (!indio_dev) |
1140 | ret = -ENOMEM; | 1140 | return -ENOMEM; |
1141 | goto error_ret; | ||
1142 | } | ||
1143 | 1141 | ||
1144 | st = iio_priv(indio_dev); | 1142 | st = iio_priv(indio_dev); |
1145 | spi_set_drvdata(spi, indio_dev); | 1143 | spi_set_drvdata(spi, indio_dev); |
@@ -1162,7 +1160,7 @@ static int sca3000_probe(struct spi_device *spi) | |||
1162 | sca3000_configure_ring(indio_dev); | 1160 | sca3000_configure_ring(indio_dev); |
1163 | ret = iio_device_register(indio_dev); | 1161 | ret = iio_device_register(indio_dev); |
1164 | if (ret < 0) | 1162 | if (ret < 0) |
1165 | goto error_free_dev; | 1163 | return ret; |
1166 | 1164 | ||
1167 | ret = iio_buffer_register(indio_dev, | 1165 | ret = iio_buffer_register(indio_dev, |
1168 | sca3000_channels, | 1166 | sca3000_channels, |
@@ -1198,10 +1196,6 @@ error_unregister_ring: | |||
1198 | iio_buffer_unregister(indio_dev); | 1196 | iio_buffer_unregister(indio_dev); |
1199 | error_unregister_dev: | 1197 | error_unregister_dev: |
1200 | iio_device_unregister(indio_dev); | 1198 | iio_device_unregister(indio_dev); |
1201 | error_free_dev: | ||
1202 | iio_device_free(indio_dev); | ||
1203 | |||
1204 | error_ret: | ||
1205 | return ret; | 1199 | return ret; |
1206 | } | 1200 | } |
1207 | 1201 | ||
@@ -1235,7 +1229,6 @@ static int sca3000_remove(struct spi_device *spi) | |||
1235 | iio_device_unregister(indio_dev); | 1229 | iio_device_unregister(indio_dev); |
1236 | iio_buffer_unregister(indio_dev); | 1230 | iio_buffer_unregister(indio_dev); |
1237 | sca3000_unconfigure_ring(indio_dev); | 1231 | sca3000_unconfigure_ring(indio_dev); |
1238 | iio_device_free(indio_dev); | ||
1239 | 1232 | ||
1240 | return 0; | 1233 | return 0; |
1241 | } | 1234 | } |
diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 687dd2c91437..f4a0341cc70c 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c | |||
@@ -558,11 +558,9 @@ static int ad7150_probe(struct i2c_client *client, | |||
558 | struct ad7150_chip_info *chip; | 558 | struct ad7150_chip_info *chip; |
559 | struct iio_dev *indio_dev; | 559 | struct iio_dev *indio_dev; |
560 | 560 | ||
561 | indio_dev = iio_device_alloc(sizeof(*chip)); | 561 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); |
562 | if (indio_dev == NULL) { | 562 | if (!indio_dev) |
563 | ret = -ENOMEM; | 563 | return -ENOMEM; |
564 | goto error_ret; | ||
565 | } | ||
566 | chip = iio_priv(indio_dev); | 564 | chip = iio_priv(indio_dev); |
567 | mutex_init(&chip->state_lock); | 565 | mutex_init(&chip->state_lock); |
568 | /* this is only used for device removal purposes */ | 566 | /* this is only used for device removal purposes */ |
@@ -581,7 +579,7 @@ static int ad7150_probe(struct i2c_client *client, | |||
581 | indio_dev->modes = INDIO_DIRECT_MODE; | 579 | indio_dev->modes = INDIO_DIRECT_MODE; |
582 | 580 | ||
583 | if (client->irq) { | 581 | if (client->irq) { |
584 | ret = request_threaded_irq(client->irq, | 582 | ret = devm_request_threaded_irq(&client->dev, client->irq, |
585 | NULL, | 583 | NULL, |
586 | &ad7150_event_handler, | 584 | &ad7150_event_handler, |
587 | IRQF_TRIGGER_RISING | | 585 | IRQF_TRIGGER_RISING | |
@@ -590,11 +588,11 @@ static int ad7150_probe(struct i2c_client *client, | |||
590 | "ad7150_irq1", | 588 | "ad7150_irq1", |
591 | indio_dev); | 589 | indio_dev); |
592 | if (ret) | 590 | if (ret) |
593 | goto error_free_dev; | 591 | return ret; |
594 | } | 592 | } |
595 | 593 | ||
596 | if (client->dev.platform_data) { | 594 | if (client->dev.platform_data) { |
597 | ret = request_threaded_irq(*(unsigned int *) | 595 | ret = devm_request_threaded_irq(&client->dev, *(unsigned int *) |
598 | client->dev.platform_data, | 596 | client->dev.platform_data, |
599 | NULL, | 597 | NULL, |
600 | &ad7150_event_handler, | 598 | &ad7150_event_handler, |
@@ -604,28 +602,17 @@ static int ad7150_probe(struct i2c_client *client, | |||
604 | "ad7150_irq2", | 602 | "ad7150_irq2", |
605 | indio_dev); | 603 | indio_dev); |
606 | if (ret) | 604 | if (ret) |
607 | goto error_free_irq; | 605 | return ret; |
608 | } | 606 | } |
609 | 607 | ||
610 | ret = iio_device_register(indio_dev); | 608 | ret = iio_device_register(indio_dev); |
611 | if (ret) | 609 | if (ret) |
612 | goto error_free_irq2; | 610 | return ret; |
613 | 611 | ||
614 | dev_info(&client->dev, "%s capacitive sensor registered,irq: %d\n", | 612 | dev_info(&client->dev, "%s capacitive sensor registered,irq: %d\n", |
615 | id->name, client->irq); | 613 | id->name, client->irq); |
616 | 614 | ||
617 | return 0; | 615 | return 0; |
618 | error_free_irq2: | ||
619 | if (client->dev.platform_data) | ||
620 | free_irq(*(unsigned int *)client->dev.platform_data, | ||
621 | indio_dev); | ||
622 | error_free_irq: | ||
623 | if (client->irq) | ||
624 | free_irq(client->irq, indio_dev); | ||
625 | error_free_dev: | ||
626 | iio_device_free(indio_dev); | ||
627 | error_ret: | ||
628 | return ret; | ||
629 | } | 616 | } |
630 | 617 | ||
631 | static int ad7150_remove(struct i2c_client *client) | 618 | static int ad7150_remove(struct i2c_client *client) |
@@ -633,13 +620,6 @@ static int ad7150_remove(struct i2c_client *client) | |||
633 | struct iio_dev *indio_dev = i2c_get_clientdata(client); | 620 | struct iio_dev *indio_dev = i2c_get_clientdata(client); |
634 | 621 | ||
635 | iio_device_unregister(indio_dev); | 622 | iio_device_unregister(indio_dev); |
636 | if (client->irq) | ||
637 | free_irq(client->irq, indio_dev); | ||
638 | |||
639 | if (client->dev.platform_data) | ||
640 | free_irq(*(unsigned int *)client->dev.platform_data, indio_dev); | ||
641 | |||
642 | iio_device_free(indio_dev); | ||
643 | 623 | ||
644 | return 0; | 624 | return 0; |
645 | } | 625 | } |
diff --git a/drivers/staging/iio/cdc/ad7152.c b/drivers/staging/iio/cdc/ad7152.c index 1d7c5283a85c..f2c309d1eb59 100644 --- a/drivers/staging/iio/cdc/ad7152.c +++ b/drivers/staging/iio/cdc/ad7152.c | |||
@@ -481,11 +481,9 @@ static int ad7152_probe(struct i2c_client *client, | |||
481 | struct ad7152_chip_info *chip; | 481 | struct ad7152_chip_info *chip; |
482 | struct iio_dev *indio_dev; | 482 | struct iio_dev *indio_dev; |
483 | 483 | ||
484 | indio_dev = iio_device_alloc(sizeof(*chip)); | 484 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); |
485 | if (indio_dev == NULL) { | 485 | if (!indio_dev) |
486 | ret = -ENOMEM; | 486 | return -ENOMEM; |
487 | goto error_ret; | ||
488 | } | ||
489 | chip = iio_priv(indio_dev); | 487 | chip = iio_priv(indio_dev); |
490 | /* this is only used for device removal purposes */ | 488 | /* this is only used for device removal purposes */ |
491 | i2c_set_clientdata(client, indio_dev); | 489 | i2c_set_clientdata(client, indio_dev); |
@@ -506,16 +504,11 @@ static int ad7152_probe(struct i2c_client *client, | |||
506 | 504 | ||
507 | ret = iio_device_register(indio_dev); | 505 | ret = iio_device_register(indio_dev); |
508 | if (ret) | 506 | if (ret) |
509 | goto error_free_dev; | 507 | return ret; |
510 | 508 | ||
511 | dev_err(&client->dev, "%s capacitive sensor registered\n", id->name); | 509 | dev_err(&client->dev, "%s capacitive sensor registered\n", id->name); |
512 | 510 | ||
513 | return 0; | 511 | return 0; |
514 | |||
515 | error_free_dev: | ||
516 | iio_device_free(indio_dev); | ||
517 | error_ret: | ||
518 | return ret; | ||
519 | } | 512 | } |
520 | 513 | ||
521 | static int ad7152_remove(struct i2c_client *client) | 514 | static int ad7152_remove(struct i2c_client *client) |
@@ -523,7 +516,6 @@ static int ad7152_remove(struct i2c_client *client) | |||
523 | struct iio_dev *indio_dev = i2c_get_clientdata(client); | 516 | struct iio_dev *indio_dev = i2c_get_clientdata(client); |
524 | 517 | ||
525 | iio_device_unregister(indio_dev); | 518 | iio_device_unregister(indio_dev); |
526 | iio_device_free(indio_dev); | ||
527 | 519 | ||
528 | return 0; | 520 | return 0; |
529 | } | 521 | } |
diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c index 94f9ca726d1c..75a533bce021 100644 --- a/drivers/staging/iio/cdc/ad7746.c +++ b/drivers/staging/iio/cdc/ad7746.c | |||
@@ -699,11 +699,9 @@ static int ad7746_probe(struct i2c_client *client, | |||
699 | int ret = 0; | 699 | int ret = 0; |
700 | unsigned char regval = 0; | 700 | unsigned char regval = 0; |
701 | 701 | ||
702 | indio_dev = iio_device_alloc(sizeof(*chip)); | 702 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); |
703 | if (indio_dev == NULL) { | 703 | if (!indio_dev) |
704 | ret = -ENOMEM; | 704 | return -ENOMEM; |
705 | goto error_ret; | ||
706 | } | ||
707 | chip = iio_priv(indio_dev); | 705 | chip = iio_priv(indio_dev); |
708 | /* this is only used for device removal purposes */ | 706 | /* this is only used for device removal purposes */ |
709 | i2c_set_clientdata(client, indio_dev); | 707 | i2c_set_clientdata(client, indio_dev); |
@@ -748,20 +746,15 @@ static int ad7746_probe(struct i2c_client *client, | |||
748 | ret = i2c_smbus_write_byte_data(chip->client, | 746 | ret = i2c_smbus_write_byte_data(chip->client, |
749 | AD7746_REG_EXC_SETUP, regval); | 747 | AD7746_REG_EXC_SETUP, regval); |
750 | if (ret < 0) | 748 | if (ret < 0) |
751 | goto error_free_dev; | 749 | return ret; |
752 | 750 | ||
753 | ret = iio_device_register(indio_dev); | 751 | ret = iio_device_register(indio_dev); |
754 | if (ret) | 752 | if (ret) |
755 | goto error_free_dev; | 753 | return ret; |
756 | 754 | ||
757 | dev_info(&client->dev, "%s capacitive sensor registered\n", id->name); | 755 | dev_info(&client->dev, "%s capacitive sensor registered\n", id->name); |
758 | 756 | ||
759 | return 0; | 757 | return 0; |
760 | |||
761 | error_free_dev: | ||
762 | iio_device_free(indio_dev); | ||
763 | error_ret: | ||
764 | return ret; | ||
765 | } | 758 | } |
766 | 759 | ||
767 | static int ad7746_remove(struct i2c_client *client) | 760 | static int ad7746_remove(struct i2c_client *client) |
@@ -769,7 +762,6 @@ static int ad7746_remove(struct i2c_client *client) | |||
769 | struct iio_dev *indio_dev = i2c_get_clientdata(client); | 762 | struct iio_dev *indio_dev = i2c_get_clientdata(client); |
770 | 763 | ||
771 | iio_device_unregister(indio_dev); | 764 | iio_device_unregister(indio_dev); |
772 | iio_device_free(indio_dev); | ||
773 | 765 | ||
774 | return 0; | 766 | return 0; |
775 | } | 767 | } |
diff --git a/include/linux/platform_data/at91_adc.h b/include/linux/platform_data/at91_adc.h index e15745b4f3a5..b3ca1e94e0c8 100644 --- a/include/linux/platform_data/at91_adc.h +++ b/include/linux/platform_data/at91_adc.h | |||
@@ -14,12 +14,16 @@ | |||
14 | (Interruptions registers mostly) | 14 | (Interruptions registers mostly) |
15 | * @status_register: Offset of the Interrupt Status Register | 15 | * @status_register: Offset of the Interrupt Status Register |
16 | * @trigger_register: Offset of the Trigger setup register | 16 | * @trigger_register: Offset of the Trigger setup register |
17 | * @mr_prescal_mask: Mask of the PRESCAL field in the adc MR register | ||
18 | * @mr_startup_mask: Mask of the STARTUP field in the adc MR register | ||
17 | */ | 19 | */ |
18 | struct at91_adc_reg_desc { | 20 | struct at91_adc_reg_desc { |
19 | u8 channel_base; | 21 | u8 channel_base; |
20 | u32 drdy_mask; | 22 | u32 drdy_mask; |
21 | u8 status_register; | 23 | u8 status_register; |
22 | u8 trigger_register; | 24 | u8 trigger_register; |
25 | u32 mr_prescal_mask; | ||
26 | u32 mr_startup_mask; | ||
23 | }; | 27 | }; |
24 | 28 | ||
25 | /** | 29 | /** |