diff options
author | Peter Meerwald <pmeerw@pmeerw.net> | 2012-12-30 18:26:00 -0500 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2013-01-01 12:38:30 -0500 |
commit | 4389fbec5b8fd0577c1e854ff5d7139329558c20 (patch) | |
tree | 49e1d7cd29c43a6ec3e23bc0f150be36ff3a2fb6 /drivers/iio | |
parent | 99e02018df52e9bf723ea3f0c18cf412c7e75108 (diff) |
iio: cleanup buffer setup code in max1363 driver
use iio_triggered_buffer_setup(), iio_triggered_buffer_cleanup()
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/adc/max1363.c | 59 |
1 files changed, 5 insertions, 54 deletions
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 1e84b5b55093..46d8365dd348 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 | ||
@@ -1483,48 +1484,6 @@ static const struct iio_buffer_setup_ops max1363_buffered_setup_ops = { | |||
1483 | .predisable = &iio_triggered_buffer_predisable, | 1484 | .predisable = &iio_triggered_buffer_predisable, |
1484 | }; | 1485 | }; |
1485 | 1486 | ||
1486 | static 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 | |||
1515 | error_deallocate_sw_rb: | ||
1516 | iio_kfifo_free(indio_dev->buffer); | ||
1517 | error_ret: | ||
1518 | return ret; | ||
1519 | } | ||
1520 | |||
1521 | static 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 | |||
1528 | static int __devinit max1363_probe(struct i2c_client *client, | 1487 | static int __devinit max1363_probe(struct i2c_client *client, |
1529 | const struct i2c_device_id *id) | 1488 | const struct i2c_device_id *id) |
1530 | { | 1489 | { |
@@ -1577,16 +1536,11 @@ static int __devinit max1363_probe(struct i2c_client *client, | |||
1577 | if (ret < 0) | 1536 | if (ret < 0) |
1578 | goto error_free_available_scan_masks; | 1537 | goto error_free_available_scan_masks; |
1579 | 1538 | ||
1580 | ret = max1363_register_buffered_funcs_and_init(indio_dev); | 1539 | ret = iio_triggered_buffer_setup(indio_dev, NULL, |
1540 | &max1363_trigger_handler, &max1363_buffered_setup_ops); | ||
1581 | if (ret) | 1541 | if (ret) |
1582 | goto error_free_available_scan_masks; | 1542 | goto error_free_available_scan_masks; |
1583 | 1543 | ||
1584 | ret = iio_buffer_register(indio_dev, | ||
1585 | st->chip_info->channels, | ||
1586 | st->chip_info->num_channels); | ||
1587 | if (ret) | ||
1588 | goto error_cleanup_buffer; | ||
1589 | |||
1590 | if (client->irq) { | 1544 | if (client->irq) { |
1591 | ret = request_threaded_irq(st->client->irq, | 1545 | ret = request_threaded_irq(st->client->irq, |
1592 | NULL, | 1546 | NULL, |
@@ -1607,9 +1561,7 @@ static int __devinit max1363_probe(struct i2c_client *client, | |||
1607 | error_free_irq: | 1561 | error_free_irq: |
1608 | free_irq(st->client->irq, indio_dev); | 1562 | free_irq(st->client->irq, indio_dev); |
1609 | error_uninit_buffer: | 1563 | error_uninit_buffer: |
1610 | iio_buffer_unregister(indio_dev); | 1564 | iio_triggered_buffer_cleanup(indio_dev); |
1611 | error_cleanup_buffer: | ||
1612 | max1363_buffer_cleanup(indio_dev); | ||
1613 | error_free_available_scan_masks: | 1565 | error_free_available_scan_masks: |
1614 | kfree(indio_dev->available_scan_masks); | 1566 | kfree(indio_dev->available_scan_masks); |
1615 | error_unregister_map: | 1567 | error_unregister_map: |
@@ -1632,8 +1584,7 @@ static int __devexit max1363_remove(struct i2c_client *client) | |||
1632 | iio_device_unregister(indio_dev); | 1584 | iio_device_unregister(indio_dev); |
1633 | if (client->irq) | 1585 | if (client->irq) |
1634 | free_irq(st->client->irq, indio_dev); | 1586 | free_irq(st->client->irq, indio_dev); |
1635 | iio_buffer_unregister(indio_dev); | 1587 | iio_triggered_buffer_cleanup(indio_dev); |
1636 | max1363_buffer_cleanup(indio_dev); | ||
1637 | kfree(indio_dev->available_scan_masks); | 1588 | kfree(indio_dev->available_scan_masks); |
1638 | if (!IS_ERR(st->reg)) { | 1589 | if (!IS_ERR(st->reg)) { |
1639 | regulator_disable(st->reg); | 1590 | regulator_disable(st->reg); |