aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/adc')
-rw-r--r--drivers/iio/adc/Kconfig4
-rw-r--r--drivers/iio/adc/lp8788_adc.c18
-rw-r--r--drivers/iio/adc/max1363.c167
3 files changed, 74 insertions, 115 deletions
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index fe822a14d130..e372257a8494 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -100,10 +100,8 @@ config LP8788_ADC
100config MAX1363 100config MAX1363
101 tristate "Maxim max1363 ADC driver" 101 tristate "Maxim max1363 ADC driver"
102 depends on I2C 102 depends on I2C
103 select IIO_TRIGGER
104 select MAX1363_RING_BUFFER
105 select IIO_BUFFER 103 select IIO_BUFFER
106 select IIO_KFIFO_BUF 104 select IIO_TRIGGERED_BUFFER
107 help 105 help
108 Say yes here to build support for many Maxim i2c analog to digital 106 Say yes here to build support for many Maxim i2c analog to digital
109 converters (ADC). (max1361, max1362, max1363, max1364, max1036, 107 converters (ADC). (max1361, max1362, max1363, max1364, max1036,
diff --git a/drivers/iio/adc/lp8788_adc.c b/drivers/iio/adc/lp8788_adc.c
index 72955e45e9e0..763f57565ee4 100644
--- a/drivers/iio/adc/lp8788_adc.c
+++ b/drivers/iio/adc/lp8788_adc.c
@@ -179,7 +179,7 @@ static int lp8788_iio_map_register(struct iio_dev *indio_dev,
179 179
180 ret = iio_map_array_register(indio_dev, map); 180 ret = iio_map_array_register(indio_dev, map);
181 if (ret) { 181 if (ret) {
182 dev_err(adc->lp->dev, "iio map err: %d\n", ret); 182 dev_err(&indio_dev->dev, "iio map err: %d\n", ret);
183 return ret; 183 return ret;
184 } 184 }
185 185
@@ -187,12 +187,6 @@ static int lp8788_iio_map_register(struct iio_dev *indio_dev,
187 return 0; 187 return 0;
188} 188}
189 189
190static inline void lp8788_iio_map_unregister(struct iio_dev *indio_dev,
191 struct lp8788_adc *adc)
192{
193 iio_map_array_unregister(indio_dev, adc->map);
194}
195
196static int lp8788_adc_probe(struct platform_device *pdev) 190static int lp8788_adc_probe(struct platform_device *pdev)
197{ 191{
198 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); 192 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent);
@@ -208,13 +202,14 @@ static int lp8788_adc_probe(struct platform_device *pdev)
208 adc->lp = lp; 202 adc->lp = lp;
209 platform_set_drvdata(pdev, indio_dev); 203 platform_set_drvdata(pdev, indio_dev);
210 204
205 indio_dev->dev.of_node = pdev->dev.of_node;
211 ret = lp8788_iio_map_register(indio_dev, lp->pdata, adc); 206 ret = lp8788_iio_map_register(indio_dev, lp->pdata, adc);
212 if (ret) 207 if (ret)
213 goto err_iio_map; 208 goto err_iio_map;
214 209
215 mutex_init(&adc->lock); 210 mutex_init(&adc->lock);
216 211
217 indio_dev->dev.parent = lp->dev; 212 indio_dev->dev.parent = &pdev->dev;
218 indio_dev->name = pdev->name; 213 indio_dev->name = pdev->name;
219 indio_dev->modes = INDIO_DIRECT_MODE; 214 indio_dev->modes = INDIO_DIRECT_MODE;
220 indio_dev->info = &lp8788_adc_info; 215 indio_dev->info = &lp8788_adc_info;
@@ -223,14 +218,14 @@ static int lp8788_adc_probe(struct platform_device *pdev)
223 218
224 ret = iio_device_register(indio_dev); 219 ret = iio_device_register(indio_dev);
225 if (ret) { 220 if (ret) {
226 dev_err(lp->dev, "iio dev register err: %d\n", ret); 221 dev_err(&pdev->dev, "iio dev register err: %d\n", ret);
227 goto err_iio_device; 222 goto err_iio_device;
228 } 223 }
229 224
230 return 0; 225 return 0;
231 226
232err_iio_device: 227err_iio_device:
233 lp8788_iio_map_unregister(indio_dev, adc); 228 iio_map_array_unregister(indio_dev);
234err_iio_map: 229err_iio_map:
235 iio_device_free(indio_dev); 230 iio_device_free(indio_dev);
236 return ret; 231 return ret;
@@ -239,10 +234,9 @@ err_iio_map:
239static int lp8788_adc_remove(struct platform_device *pdev) 234static int lp8788_adc_remove(struct platform_device *pdev)
240{ 235{
241 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 236 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
242 struct lp8788_adc *adc = iio_priv(indio_dev);
243 237
244 iio_device_unregister(indio_dev); 238 iio_device_unregister(indio_dev);
245 lp8788_iio_map_unregister(indio_dev, adc); 239 iio_map_array_unregister(indio_dev);
246 iio_device_free(indio_dev); 240 iio_device_free(indio_dev);
247 241
248 return 0; 242 return 0;
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index 03b25b3dc71e..6c1cfb74bdfc 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -39,6 +39,7 @@
39#include <linux/iio/driver.h> 39#include <linux/iio/driver.h>
40#include <linux/iio/kfifo_buf.h> 40#include <linux/iio/kfifo_buf.h>
41#include <linux/iio/trigger_consumer.h> 41#include <linux/iio/trigger_consumer.h>
42#include <linux/iio/triggered_buffer.h>
42 43
43#define MAX1363_SETUP_BYTE(a) ((a) | 0x80) 44#define MAX1363_SETUP_BYTE(a) ((a) | 0x80)
44 45
@@ -55,7 +56,7 @@
55#define MAX1363_SETUP_POWER_UP_INT_REF 0x10 56#define MAX1363_SETUP_POWER_UP_INT_REF 0x10
56#define MAX1363_SETUP_POWER_DOWN_INT_REF 0x00 57#define MAX1363_SETUP_POWER_DOWN_INT_REF 0x00
57 58
58/* think about includeing max11600 etc - more settings */ 59/* think about including max11600 etc - more settings */
59#define MAX1363_SETUP_EXT_CLOCK 0x08 60#define MAX1363_SETUP_EXT_CLOCK 0x08
60#define MAX1363_SETUP_INT_CLOCK 0x00 61#define MAX1363_SETUP_INT_CLOCK 0x00
61#define MAX1363_SETUP_UNIPOLAR 0x00 62#define MAX1363_SETUP_UNIPOLAR 0x00
@@ -86,7 +87,7 @@
86/* max123{6-9} only */ 87/* max123{6-9} only */
87#define MAX1236_SCAN_MID_TO_CHANNEL 0x40 88#define MAX1236_SCAN_MID_TO_CHANNEL 0x40
88 89
89/* max1363 only - merely part of channel selects or don't care for others*/ 90/* max1363 only - merely part of channel selects or don't care for others */
90#define MAX1363_CONFIG_EN_MON_MODE_READ 0x18 91#define MAX1363_CONFIG_EN_MON_MODE_READ 0x18
91 92
92#define MAX1363_CHANNEL_SEL(a) ((a) << 1) 93#define MAX1363_CHANNEL_SEL(a) ((a) << 1)
@@ -133,7 +134,7 @@ enum max1363_modes {
133 * @mode_list: array of available scan modes 134 * @mode_list: array of available scan modes
134 * @default_mode: the scan mode in which the chip starts up 135 * @default_mode: the scan mode in which the chip starts up
135 * @int_vref_mv: the internal reference voltage 136 * @int_vref_mv: the internal reference voltage
136 * @num_channels: number of channels 137 * @num_modes: number of modes
137 * @bits: accuracy of the adc in bits 138 * @bits: accuracy of the adc in bits
138 */ 139 */
139struct max1363_chip_info { 140struct max1363_chip_info {
@@ -152,7 +153,7 @@ struct max1363_chip_info {
152 * @client: i2c_client 153 * @client: i2c_client
153 * @setupbyte: cache of current device setup byte 154 * @setupbyte: cache of current device setup byte
154 * @configbyte: cache of current device config byte 155 * @configbyte: cache of current device config byte
155 * @chip_info: chip model specific constants, available modes etc 156 * @chip_info: chip model specific constants, available modes, etc.
156 * @current_mode: the scan mode of this chip 157 * @current_mode: the scan mode of this chip
157 * @requestedmask: a valid requested set of channels 158 * @requestedmask: a valid requested set of channels
158 * @reg: supply regulator 159 * @reg: supply regulator
@@ -162,6 +163,8 @@ struct max1363_chip_info {
162 * @mask_low: bitmask for enabled low thresholds 163 * @mask_low: bitmask for enabled low thresholds
163 * @thresh_high: high threshold values 164 * @thresh_high: high threshold values
164 * @thresh_low: low threshold values 165 * @thresh_low: low threshold values
166 * @vref: Reference voltage regulator
167 * @vref_uv: Actual (external or internal) reference voltage
165 */ 168 */
166struct max1363_state { 169struct max1363_state {
167 struct i2c_client *client; 170 struct i2c_client *client;
@@ -181,6 +184,8 @@ struct max1363_state {
181 /* 4x unipolar first then the fours bipolar ones */ 184 /* 4x unipolar first then the fours bipolar ones */
182 s16 thresh_high[8]; 185 s16 thresh_high[8];
183 s16 thresh_low[8]; 186 s16 thresh_low[8];
187 struct regulator *vref;
188 u32 vref_uv;
184}; 189};
185 190
186#define MAX1363_MODE_SINGLE(_num, _mask) { \ 191#define MAX1363_MODE_SINGLE(_num, _mask) { \
@@ -293,7 +298,7 @@ static const struct max1363_mode max1363_mode_table[] = {
293 298
294static const struct max1363_mode 299static const struct max1363_mode
295*max1363_match_mode(const unsigned long *mask, 300*max1363_match_mode(const unsigned long *mask,
296const struct max1363_chip_info *ci) 301 const struct max1363_chip_info *ci)
297{ 302{
298 int i; 303 int i;
299 if (mask) 304 if (mask)
@@ -334,7 +339,7 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
334{ 339{
335 int ret = 0; 340 int ret = 0;
336 s32 data; 341 s32 data;
337 char rxbuf[2]; 342 u8 rxbuf[2];
338 struct max1363_state *st = iio_priv(indio_dev); 343 struct max1363_state *st = iio_priv(indio_dev);
339 struct i2c_client *client = st->client; 344 struct i2c_client *client = st->client;
340 345
@@ -366,7 +371,8 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
366 ret = data; 371 ret = data;
367 goto error_ret; 372 goto error_ret;
368 } 373 }
369 data = (s32)(rxbuf[1]) | ((s32)(rxbuf[0] & 0x0F)) << 8; 374 data = (rxbuf[1] | rxbuf[0] << 8) &
375 ((1 << st->chip_info->bits) - 1);
370 } else { 376 } else {
371 /* Get reading */ 377 /* Get reading */
372 data = i2c_master_recv(client, rxbuf, 1); 378 data = i2c_master_recv(client, rxbuf, 1);
@@ -391,6 +397,8 @@ static int max1363_read_raw(struct iio_dev *indio_dev,
391{ 397{
392 struct max1363_state *st = iio_priv(indio_dev); 398 struct max1363_state *st = iio_priv(indio_dev);
393 int ret; 399 int ret;
400 unsigned long scale_uv;
401
394 switch (m) { 402 switch (m) {
395 case IIO_CHAN_INFO_RAW: 403 case IIO_CHAN_INFO_RAW:
396 ret = max1363_read_single_chan(indio_dev, chan, val, m); 404 ret = max1363_read_single_chan(indio_dev, chan, val, m);
@@ -398,16 +406,10 @@ static int max1363_read_raw(struct iio_dev *indio_dev,
398 return ret; 406 return ret;
399 return IIO_VAL_INT; 407 return IIO_VAL_INT;
400 case IIO_CHAN_INFO_SCALE: 408 case IIO_CHAN_INFO_SCALE:
401 if ((1 << (st->chip_info->bits + 1)) > 409 scale_uv = st->vref_uv >> st->chip_info->bits;
402 st->chip_info->int_vref_mv) { 410 *val = scale_uv / 1000;
403 *val = 0; 411 *val2 = (scale_uv % 1000) * 1000;
404 *val2 = 500000; 412 return IIO_VAL_INT_PLUS_MICRO;
405 return IIO_VAL_INT_PLUS_MICRO;
406 } else {
407 *val = (st->chip_info->int_vref_mv)
408 >> st->chip_info->bits;
409 return IIO_VAL_INT;
410 }
411 default: 413 default:
412 return -EINVAL; 414 return -EINVAL;
413 } 415 }
@@ -1388,13 +1390,17 @@ static const struct max1363_chip_info max1363_chip_info_tbl[] = {
1388 1390
1389static int max1363_initial_setup(struct max1363_state *st) 1391static int max1363_initial_setup(struct max1363_state *st)
1390{ 1392{
1391 st->setupbyte = MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_VDD 1393 st->setupbyte = MAX1363_SETUP_INT_CLOCK
1392 | MAX1363_SETUP_POWER_UP_INT_REF
1393 | MAX1363_SETUP_INT_CLOCK
1394 | MAX1363_SETUP_UNIPOLAR 1394 | MAX1363_SETUP_UNIPOLAR
1395 | MAX1363_SETUP_NORESET; 1395 | MAX1363_SETUP_NORESET;
1396 1396
1397 /* Set scan mode writes the config anyway so wait until then*/ 1397 if (st->vref)
1398 st->setupbyte |= MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF;
1399 else
1400 st->setupbyte |= MAX1363_SETUP_POWER_UP_INT_REF
1401 | MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_INT;
1402
1403 /* Set scan mode writes the config anyway so wait until then */
1398 st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte); 1404 st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte);
1399 st->current_mode = &max1363_mode_table[st->chip_info->default_mode]; 1405 st->current_mode = &max1363_mode_table[st->chip_info->default_mode];
1400 st->configbyte = MAX1363_CONFIG_BYTE(st->configbyte); 1406 st->configbyte = MAX1363_CONFIG_BYTE(st->configbyte);
@@ -1408,8 +1414,9 @@ static int max1363_alloc_scan_masks(struct iio_dev *indio_dev)
1408 unsigned long *masks; 1414 unsigned long *masks;
1409 int i; 1415 int i;
1410 1416
1411 masks = kzalloc(BITS_TO_LONGS(MAX1363_MAX_CHANNELS)*sizeof(long)* 1417 masks = devm_kzalloc(&indio_dev->dev,
1412 (st->chip_info->num_modes + 1), GFP_KERNEL); 1418 BITS_TO_LONGS(MAX1363_MAX_CHANNELS) * sizeof(long) *
1419 (st->chip_info->num_modes + 1), GFP_KERNEL);
1413 if (!masks) 1420 if (!masks)
1414 return -ENOMEM; 1421 return -ENOMEM;
1415 1422
@@ -1423,7 +1430,6 @@ static int max1363_alloc_scan_masks(struct iio_dev *indio_dev)
1423 return 0; 1430 return 0;
1424} 1431}
1425 1432
1426
1427static irqreturn_t max1363_trigger_handler(int irq, void *p) 1433static irqreturn_t max1363_trigger_handler(int irq, void *p)
1428{ 1434{
1429 struct iio_poll_func *pf = p; 1435 struct iio_poll_func *pf = p;
@@ -1483,54 +1489,13 @@ static const struct iio_buffer_setup_ops max1363_buffered_setup_ops = {
1483 .predisable = &iio_triggered_buffer_predisable, 1489 .predisable = &iio_triggered_buffer_predisable,
1484}; 1490};
1485 1491
1486static int max1363_register_buffered_funcs_and_init(struct iio_dev *indio_dev)
1487{
1488 struct max1363_state *st = iio_priv(indio_dev);
1489 int ret = 0;
1490
1491 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
1492 if (!indio_dev->buffer) {
1493 ret = -ENOMEM;
1494 goto error_ret;
1495 }
1496 indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
1497 &max1363_trigger_handler,
1498 IRQF_ONESHOT,
1499 indio_dev,
1500 "%s_consumer%d",
1501 st->client->name,
1502 indio_dev->id);
1503 if (indio_dev->pollfunc == NULL) {
1504 ret = -ENOMEM;
1505 goto error_deallocate_sw_rb;
1506 }
1507 /* Buffer functions - here trigger setup related */
1508 indio_dev->setup_ops = &max1363_buffered_setup_ops;
1509
1510 /* Flag that polled buffering is possible */
1511 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
1512
1513 return 0;
1514
1515error_deallocate_sw_rb:
1516 iio_kfifo_free(indio_dev->buffer);
1517error_ret:
1518 return ret;
1519}
1520
1521static void max1363_buffer_cleanup(struct iio_dev *indio_dev)
1522{
1523 /* ensure that the trigger has been detached */
1524 iio_dealloc_pollfunc(indio_dev->pollfunc);
1525 iio_kfifo_free(indio_dev->buffer);
1526}
1527
1528static int max1363_probe(struct i2c_client *client, 1492static int max1363_probe(struct i2c_client *client,
1529 const struct i2c_device_id *id) 1493 const struct i2c_device_id *id)
1530{ 1494{
1531 int ret; 1495 int ret;
1532 struct max1363_state *st; 1496 struct max1363_state *st;
1533 struct iio_dev *indio_dev; 1497 struct iio_dev *indio_dev;
1498 struct regulator *vref;
1534 1499
1535 indio_dev = iio_device_alloc(sizeof(struct max1363_state)); 1500 indio_dev = iio_device_alloc(sizeof(struct max1363_state));
1536 if (indio_dev == NULL) { 1501 if (indio_dev == NULL) {
@@ -1538,13 +1503,14 @@ static int max1363_probe(struct i2c_client *client,
1538 goto error_out; 1503 goto error_out;
1539 } 1504 }
1540 1505
1506 indio_dev->dev.of_node = client->dev.of_node;
1541 ret = iio_map_array_register(indio_dev, client->dev.platform_data); 1507 ret = iio_map_array_register(indio_dev, client->dev.platform_data);
1542 if (ret < 0) 1508 if (ret < 0)
1543 goto error_free_device; 1509 goto error_free_device;
1544 1510
1545 st = iio_priv(indio_dev); 1511 st = iio_priv(indio_dev);
1546 1512
1547 st->reg = regulator_get(&client->dev, "vcc"); 1513 st->reg = devm_regulator_get(&client->dev, "vcc");
1548 if (IS_ERR(st->reg)) { 1514 if (IS_ERR(st->reg)) {
1549 ret = PTR_ERR(st->reg); 1515 ret = PTR_ERR(st->reg);
1550 goto error_unregister_map; 1516 goto error_unregister_map;
@@ -1552,7 +1518,7 @@ static int max1363_probe(struct i2c_client *client,
1552 1518
1553 ret = regulator_enable(st->reg); 1519 ret = regulator_enable(st->reg);
1554 if (ret) 1520 if (ret)
1555 goto error_put_reg; 1521 goto error_unregister_map;
1556 1522
1557 /* this is only used for device removal purposes */ 1523 /* this is only used for device removal purposes */
1558 i2c_set_clientdata(client, indio_dev); 1524 i2c_set_clientdata(client, indio_dev);
@@ -1560,35 +1526,45 @@ static int max1363_probe(struct i2c_client *client,
1560 st->chip_info = &max1363_chip_info_tbl[id->driver_data]; 1526 st->chip_info = &max1363_chip_info_tbl[id->driver_data];
1561 st->client = client; 1527 st->client = client;
1562 1528
1529 st->vref_uv = st->chip_info->int_vref_mv * 1000;
1530 vref = devm_regulator_get(&client->dev, "vref");
1531 if (!IS_ERR(vref)) {
1532 int vref_uv;
1533
1534 ret = regulator_enable(vref);
1535 if (ret)
1536 goto error_disable_reg;
1537 st->vref = vref;
1538 vref_uv = regulator_get_voltage(vref);
1539 if (vref_uv <= 0) {
1540 ret = -EINVAL;
1541 goto error_disable_reg;
1542 }
1543 st->vref_uv = vref_uv;
1544 }
1545
1563 ret = max1363_alloc_scan_masks(indio_dev); 1546 ret = max1363_alloc_scan_masks(indio_dev);
1564 if (ret) 1547 if (ret)
1565 goto error_disable_reg; 1548 goto error_disable_reg;
1566 1549
1567 /* Estabilish that the iio_dev is a child of the i2c device */ 1550 /* Establish that the iio_dev is a child of the i2c device */
1568 indio_dev->dev.parent = &client->dev; 1551 indio_dev->dev.parent = &client->dev;
1569 indio_dev->name = id->name; 1552 indio_dev->name = id->name;
1570 indio_dev->channels = st->chip_info->channels; 1553 indio_dev->channels = st->chip_info->channels;
1571 indio_dev->num_channels = st->chip_info->num_channels; 1554 indio_dev->num_channels = st->chip_info->num_channels;
1572 indio_dev->info = st->chip_info->info; 1555 indio_dev->info = st->chip_info->info;
1573 indio_dev->modes = INDIO_DIRECT_MODE; 1556 indio_dev->modes = INDIO_DIRECT_MODE;
1574 indio_dev->channels = st->chip_info->channels;
1575 indio_dev->num_channels = st->chip_info->num_channels;
1576 ret = max1363_initial_setup(st); 1557 ret = max1363_initial_setup(st);
1577 if (ret < 0) 1558 if (ret < 0)
1578 goto error_free_available_scan_masks; 1559 goto error_disable_reg;
1579
1580 ret = max1363_register_buffered_funcs_and_init(indio_dev);
1581 if (ret)
1582 goto error_free_available_scan_masks;
1583 1560
1584 ret = iio_buffer_register(indio_dev, 1561 ret = iio_triggered_buffer_setup(indio_dev, NULL,
1585 st->chip_info->channels, 1562 &max1363_trigger_handler, &max1363_buffered_setup_ops);
1586 st->chip_info->num_channels);
1587 if (ret) 1563 if (ret)
1588 goto error_cleanup_buffer; 1564 goto error_disable_reg;
1589 1565
1590 if (client->irq) { 1566 if (client->irq) {
1591 ret = request_threaded_irq(st->client->irq, 1567 ret = devm_request_threaded_irq(&client->dev, st->client->irq,
1592 NULL, 1568 NULL,
1593 &max1363_event_handler, 1569 &max1363_event_handler,
1594 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 1570 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
@@ -1601,24 +1577,18 @@ static int max1363_probe(struct i2c_client *client,
1601 1577
1602 ret = iio_device_register(indio_dev); 1578 ret = iio_device_register(indio_dev);
1603 if (ret < 0) 1579 if (ret < 0)
1604 goto error_free_irq; 1580 goto error_uninit_buffer;
1605 1581
1606 return 0; 1582 return 0;
1607error_free_irq: 1583
1608 if (client->irq)
1609 free_irq(st->client->irq, indio_dev);
1610error_uninit_buffer: 1584error_uninit_buffer:
1611 iio_buffer_unregister(indio_dev); 1585 iio_triggered_buffer_cleanup(indio_dev);
1612error_cleanup_buffer:
1613 max1363_buffer_cleanup(indio_dev);
1614error_free_available_scan_masks:
1615 kfree(indio_dev->available_scan_masks);
1616error_disable_reg: 1586error_disable_reg:
1587 if (st->vref)
1588 regulator_disable(st->vref);
1617 regulator_disable(st->reg); 1589 regulator_disable(st->reg);
1618error_put_reg:
1619 regulator_put(st->reg);
1620error_unregister_map: 1590error_unregister_map:
1621 iio_map_array_unregister(indio_dev, client->dev.platform_data); 1591 iio_map_array_unregister(indio_dev);
1622error_free_device: 1592error_free_device:
1623 iio_device_free(indio_dev); 1593 iio_device_free(indio_dev);
1624error_out: 1594error_out:
@@ -1631,14 +1601,11 @@ static int max1363_remove(struct i2c_client *client)
1631 struct max1363_state *st = iio_priv(indio_dev); 1601 struct max1363_state *st = iio_priv(indio_dev);
1632 1602
1633 iio_device_unregister(indio_dev); 1603 iio_device_unregister(indio_dev);
1634 if (client->irq) 1604 iio_triggered_buffer_cleanup(indio_dev);
1635 free_irq(st->client->irq, indio_dev); 1605 if (st->vref)
1636 iio_buffer_unregister(indio_dev); 1606 regulator_disable(st->vref);
1637 max1363_buffer_cleanup(indio_dev);
1638 kfree(indio_dev->available_scan_masks);
1639 regulator_disable(st->reg); 1607 regulator_disable(st->reg);
1640 regulator_put(st->reg); 1608 iio_map_array_unregister(indio_dev);
1641 iio_map_array_unregister(indio_dev, client->dev.platform_data);
1642 iio_device_free(indio_dev); 1609 iio_device_free(indio_dev);
1643 1610
1644 return 0; 1611 return 0;