aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMichael Hennerich <michael.hennerich@analog.com>2011-05-18 09:42:36 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-05-19 19:15:05 -0400
commita3f02370c9fa6d85fbee2c11649ebc9c84bae919 (patch)
tree137f547f29e7f5e5954e5d82174b91bcebe8dca6 /drivers
parent7df86302f4258764a3b8b1d63848dab3aa292654 (diff)
staging:iio:meter:ade7758: Use private data space from iio_allocate_device
Use private data space from iio_allocate_device. Drop dev_data in favor of iio_priv(). Fix indention issues from previous patches. Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Acked-by: Jonathan Cameron <jic23@cam.ac.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/iio/meter/ade7758.h10
-rw-r--r--drivers/staging/iio/meter/ade7758_core.c92
-rw-r--r--drivers/staging/iio/meter/ade7758_ring.c12
-rw-r--r--drivers/staging/iio/meter/ade7758_trigger.c18
4 files changed, 62 insertions, 70 deletions
diff --git a/drivers/staging/iio/meter/ade7758.h b/drivers/staging/iio/meter/ade7758.h
index 372a9f62b3b2..fd74e156abf9 100644
--- a/drivers/staging/iio/meter/ade7758.h
+++ b/drivers/staging/iio/meter/ade7758.h
@@ -111,7 +111,6 @@
111/** 111/**
112 * struct ade7758_state - device instance specific data 112 * struct ade7758_state - device instance specific data
113 * @us: actual spi_device 113 * @us: actual spi_device
114 * @indio_dev: industrial I/O device structure
115 * @trig: data ready trigger registered with iio 114 * @trig: data ready trigger registered with iio
116 * @tx: transmit buffer 115 * @tx: transmit buffer
117 * @rx: receive buffer 116 * @rx: receive buffer
@@ -119,21 +118,20 @@
119 **/ 118 **/
120struct ade7758_state { 119struct ade7758_state {
121 struct spi_device *us; 120 struct spi_device *us;
122 struct iio_dev *indio_dev;
123 struct iio_trigger *trig; 121 struct iio_trigger *trig;
124 u8 *tx; 122 u8 *tx;
125 u8 *rx; 123 u8 *rx;
126 struct mutex buf_lock; 124 struct mutex buf_lock;
127 u32 available_scan_masks[AD7758_NUM_WAVESRC]; 125 u32 available_scan_masks[AD7758_NUM_WAVESRC];
128 struct iio_chan_spec *ade7758_ring_channels; 126 struct iio_chan_spec *ade7758_ring_channels;
129 struct spi_transfer ring_xfer[4]; 127 struct spi_transfer ring_xfer[4];
130 struct spi_message ring_msg; 128 struct spi_message ring_msg;
131 /* 129 /*
132 * DMA (thus cache coherency maintenance) requires the 130 * DMA (thus cache coherency maintenance) requires the
133 * transfer buffers to live in their own cache lines. 131 * transfer buffers to live in their own cache lines.
134 */ 132 */
135 unsigned char rx_buf[8] ____cacheline_aligned; 133 unsigned char rx_buf[8] ____cacheline_aligned;
136 unsigned char tx_buf[8]; 134 unsigned char tx_buf[8];
137 135
138}; 136};
139#ifdef CONFIG_IIO_RING_BUFFER 137#ifdef CONFIG_IIO_RING_BUFFER
diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
index 42682ad0b26c..d9dfd8321222 100644
--- a/drivers/staging/iio/meter/ade7758_core.c
+++ b/drivers/staging/iio/meter/ade7758_core.c
@@ -30,7 +30,7 @@ int ade7758_spi_write_reg_8(struct device *dev,
30{ 30{
31 int ret; 31 int ret;
32 struct iio_dev *indio_dev = dev_get_drvdata(dev); 32 struct iio_dev *indio_dev = dev_get_drvdata(dev);
33 struct ade7758_state *st = iio_dev_get_devdata(indio_dev); 33 struct ade7758_state *st = iio_priv(indio_dev);
34 34
35 mutex_lock(&st->buf_lock); 35 mutex_lock(&st->buf_lock);
36 st->tx[0] = ADE7758_WRITE_REG(reg_address); 36 st->tx[0] = ADE7758_WRITE_REG(reg_address);
@@ -49,7 +49,7 @@ static int ade7758_spi_write_reg_16(struct device *dev,
49 int ret; 49 int ret;
50 struct spi_message msg; 50 struct spi_message msg;
51 struct iio_dev *indio_dev = dev_get_drvdata(dev); 51 struct iio_dev *indio_dev = dev_get_drvdata(dev);
52 struct ade7758_state *st = iio_dev_get_devdata(indio_dev); 52 struct ade7758_state *st = iio_priv(indio_dev);
53 struct spi_transfer xfers[] = { 53 struct spi_transfer xfers[] = {
54 { 54 {
55 .tx_buf = st->tx, 55 .tx_buf = st->tx,
@@ -78,7 +78,7 @@ static int ade7758_spi_write_reg_24(struct device *dev,
78 int ret; 78 int ret;
79 struct spi_message msg; 79 struct spi_message msg;
80 struct iio_dev *indio_dev = dev_get_drvdata(dev); 80 struct iio_dev *indio_dev = dev_get_drvdata(dev);
81 struct ade7758_state *st = iio_dev_get_devdata(indio_dev); 81 struct ade7758_state *st = iio_priv(indio_dev);
82 struct spi_transfer xfers[] = { 82 struct spi_transfer xfers[] = {
83 { 83 {
84 .tx_buf = st->tx, 84 .tx_buf = st->tx,
@@ -107,7 +107,7 @@ int ade7758_spi_read_reg_8(struct device *dev,
107{ 107{
108 struct spi_message msg; 108 struct spi_message msg;
109 struct iio_dev *indio_dev = dev_get_drvdata(dev); 109 struct iio_dev *indio_dev = dev_get_drvdata(dev);
110 struct ade7758_state *st = iio_dev_get_devdata(indio_dev); 110 struct ade7758_state *st = iio_priv(indio_dev);
111 int ret; 111 int ret;
112 struct spi_transfer xfers[] = { 112 struct spi_transfer xfers[] = {
113 { 113 {
@@ -150,7 +150,7 @@ static int ade7758_spi_read_reg_16(struct device *dev,
150{ 150{
151 struct spi_message msg; 151 struct spi_message msg;
152 struct iio_dev *indio_dev = dev_get_drvdata(dev); 152 struct iio_dev *indio_dev = dev_get_drvdata(dev);
153 struct ade7758_state *st = iio_dev_get_devdata(indio_dev); 153 struct ade7758_state *st = iio_priv(indio_dev);
154 int ret; 154 int ret;
155 struct spi_transfer xfers[] = { 155 struct spi_transfer xfers[] = {
156 { 156 {
@@ -196,7 +196,7 @@ static int ade7758_spi_read_reg_24(struct device *dev,
196{ 196{
197 struct spi_message msg; 197 struct spi_message msg;
198 struct iio_dev *indio_dev = dev_get_drvdata(dev); 198 struct iio_dev *indio_dev = dev_get_drvdata(dev);
199 struct ade7758_state *st = iio_dev_get_devdata(indio_dev); 199 struct ade7758_state *st = iio_priv(indio_dev);
200 int ret; 200 int ret;
201 struct spi_transfer xfers[] = { 201 struct spi_transfer xfers[] = {
202 { 202 {
@@ -485,10 +485,11 @@ static int ade7758_stop_device(struct device *dev)
485 return ret; 485 return ret;
486} 486}
487 487
488static int ade7758_initial_setup(struct ade7758_state *st) 488static int ade7758_initial_setup(struct iio_dev *indio_dev)
489{ 489{
490 struct ade7758_state *st = iio_priv(indio_dev);
491 struct device *dev = &indio_dev->dev;
490 int ret; 492 int ret;
491 struct device *dev = &st->indio_dev->dev;
492 493
493 /* use low spi speed for init */ 494 /* use low spi speed for init */
494 st->us->mode = SPI_MODE_1; 495 st->us->mode = SPI_MODE_1;
@@ -727,19 +728,23 @@ static struct iio_chan_spec ade7758_channels[] = {
727static int __devinit ade7758_probe(struct spi_device *spi) 728static int __devinit ade7758_probe(struct spi_device *spi)
728{ 729{
729 int i, ret, regdone = 0; 730 int i, ret, regdone = 0;
730 struct ade7758_state *st = kzalloc(sizeof *st, GFP_KERNEL); 731 struct ade7758_state *st;
731 if (!st) { 732 struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
732 ret = -ENOMEM; 733
734 if (indio_dev == NULL) {
735 ret = -ENOMEM;
733 goto error_ret; 736 goto error_ret;
734 } 737 }
738
739 st = iio_priv(indio_dev);
735 /* this is only used for removal purposes */ 740 /* this is only used for removal purposes */
736 spi_set_drvdata(spi, st); 741 spi_set_drvdata(spi, indio_dev);
737 742
738 /* Allocate the comms buffers */ 743 /* Allocate the comms buffers */
739 st->rx = kzalloc(sizeof(*st->rx)*ADE7758_MAX_RX, GFP_KERNEL); 744 st->rx = kzalloc(sizeof(*st->rx)*ADE7758_MAX_RX, GFP_KERNEL);
740 if (st->rx == NULL) { 745 if (st->rx == NULL) {
741 ret = -ENOMEM; 746 ret = -ENOMEM;
742 goto error_free_st; 747 goto error_free_dev;
743 } 748 }
744 st->tx = kzalloc(sizeof(*st->tx)*ADE7758_MAX_TX, GFP_KERNEL); 749 st->tx = kzalloc(sizeof(*st->tx)*ADE7758_MAX_TX, GFP_KERNEL);
745 if (st->tx == NULL) { 750 if (st->tx == NULL) {
@@ -749,35 +754,28 @@ static int __devinit ade7758_probe(struct spi_device *spi)
749 st->us = spi; 754 st->us = spi;
750 st->ade7758_ring_channels = &ade7758_channels[0]; 755 st->ade7758_ring_channels = &ade7758_channels[0];
751 mutex_init(&st->buf_lock); 756 mutex_init(&st->buf_lock);
752 /* setup the industrialio driver allocated elements */
753 st->indio_dev = iio_allocate_device(0);
754 if (st->indio_dev == NULL) {
755 ret = -ENOMEM;
756 goto error_free_tx;
757 }
758 757
759 st->indio_dev->name = spi->dev.driver->name; 758 indio_dev->name = spi->dev.driver->name;
760 st->indio_dev->dev.parent = &spi->dev; 759 indio_dev->dev.parent = &spi->dev;
761 st->indio_dev->attrs = &ade7758_attribute_group; 760 indio_dev->attrs = &ade7758_attribute_group;
762 st->indio_dev->dev_data = (void *)(st); 761 indio_dev->driver_module = THIS_MODULE;
763 st->indio_dev->driver_module = THIS_MODULE; 762 indio_dev->modes = INDIO_DIRECT_MODE;
764 st->indio_dev->modes = INDIO_DIRECT_MODE;
765 763
766 for (i = 0; i < AD7758_NUM_WAVESRC; i++) 764 for (i = 0; i < AD7758_NUM_WAVESRC; i++)
767 st->available_scan_masks[i] = 1 << i; 765 st->available_scan_masks[i] = 1 << i;
768 766
769 st->indio_dev->available_scan_masks = st->available_scan_masks; 767 indio_dev->available_scan_masks = st->available_scan_masks;
770 768
771 ret = ade7758_configure_ring(st->indio_dev); 769 ret = ade7758_configure_ring(indio_dev);
772 if (ret) 770 if (ret)
773 goto error_free_dev; 771 goto error_free_tx;
774 772
775 ret = iio_device_register(st->indio_dev); 773 ret = iio_device_register(indio_dev);
776 if (ret) 774 if (ret)
777 goto error_unreg_ring_funcs; 775 goto error_unreg_ring_funcs;
778 regdone = 1; 776 regdone = 1;
779 777
780 ret = iio_ring_buffer_register_ex(st->indio_dev->ring, 0, 778 ret = iio_ring_buffer_register_ex(indio_dev->ring, 0,
781 &ade7758_channels[0], 779 &ade7758_channels[0],
782 ARRAY_SIZE(ade7758_channels)); 780 ARRAY_SIZE(ade7758_channels));
783 if (ret) { 781 if (ret) {
@@ -786,12 +784,12 @@ static int __devinit ade7758_probe(struct spi_device *spi)
786 } 784 }
787 785
788 /* Get the device into a sane initial state */ 786 /* Get the device into a sane initial state */
789 ret = ade7758_initial_setup(st); 787 ret = ade7758_initial_setup(indio_dev);
790 if (ret) 788 if (ret)
791 goto error_uninitialize_ring; 789 goto error_uninitialize_ring;
792 790
793 if (spi->irq) { 791 if (spi->irq) {
794 ret = ade7758_probe_trigger(st->indio_dev); 792 ret = ade7758_probe_trigger(indio_dev);
795 if (ret) 793 if (ret)
796 goto error_remove_trigger; 794 goto error_remove_trigger;
797 } 795 }
@@ -799,47 +797,43 @@ static int __devinit ade7758_probe(struct spi_device *spi)
799 return 0; 797 return 0;
800 798
801error_remove_trigger: 799error_remove_trigger:
802 if (st->indio_dev->modes & INDIO_RING_TRIGGERED) 800 if (indio_dev->modes & INDIO_RING_TRIGGERED)
803 ade7758_remove_trigger(st->indio_dev); 801 ade7758_remove_trigger(indio_dev);
804error_uninitialize_ring: 802error_uninitialize_ring:
805 ade7758_uninitialize_ring(st->indio_dev->ring); 803 ade7758_uninitialize_ring(indio_dev->ring);
806error_unreg_ring_funcs: 804error_unreg_ring_funcs:
807 ade7758_unconfigure_ring(st->indio_dev); 805 ade7758_unconfigure_ring(indio_dev);
808error_free_dev:
809 if (regdone)
810 iio_device_unregister(st->indio_dev);
811 else
812 iio_free_device(st->indio_dev);
813error_free_tx: 806error_free_tx:
814 kfree(st->tx); 807 kfree(st->tx);
815error_free_rx: 808error_free_rx:
816 kfree(st->rx); 809 kfree(st->rx);
817error_free_st: 810error_free_dev:
818 kfree(st); 811 if (regdone)
812 iio_device_unregister(indio_dev);
813 else
814 iio_free_device(indio_dev);
819error_ret: 815error_ret:
820 return ret; 816 return ret;
821} 817}
822 818
823static int ade7758_remove(struct spi_device *spi) 819static int ade7758_remove(struct spi_device *spi)
824{ 820{
821 struct iio_dev *indio_dev = spi_get_drvdata(spi);
822 struct ade7758_state *st = iio_priv(indio_dev);
825 int ret; 823 int ret;
826 struct ade7758_state *st = spi_get_drvdata(spi);
827 struct iio_dev *indio_dev = st->indio_dev;
828 824
829 ret = ade7758_stop_device(&(indio_dev->dev)); 825 ret = ade7758_stop_device(&indio_dev->dev);
830 if (ret) 826 if (ret)
831 goto err_ret; 827 goto err_ret;
832 828
833 ade7758_remove_trigger(indio_dev); 829 ade7758_remove_trigger(indio_dev);
834 ade7758_uninitialize_ring(indio_dev->ring); 830 ade7758_uninitialize_ring(indio_dev->ring);
835 iio_device_unregister(indio_dev);
836 ade7758_unconfigure_ring(indio_dev); 831 ade7758_unconfigure_ring(indio_dev);
837 kfree(st->tx); 832 kfree(st->tx);
838 kfree(st->rx); 833 kfree(st->rx);
839 kfree(st); 834 iio_device_unregister(indio_dev);
840 835
841 return 0; 836 return 0;
842
843err_ret: 837err_ret:
844 return ret; 838 return ret;
845} 839}
diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
index 564555a81191..a5e48c1bd424 100644
--- a/drivers/staging/iio/meter/ade7758_ring.c
+++ b/drivers/staging/iio/meter/ade7758_ring.c
@@ -32,7 +32,7 @@
32static int ade7758_spi_read_burst(struct device *dev) 32static int ade7758_spi_read_burst(struct device *dev)
33{ 33{
34 struct iio_dev *indio_dev = dev_get_drvdata(dev); 34 struct iio_dev *indio_dev = dev_get_drvdata(dev);
35 struct ade7758_state *st = iio_dev_get_devdata(indio_dev); 35 struct ade7758_state *st = iio_priv(indio_dev);
36 int ret; 36 int ret;
37 37
38 ret = spi_sync(st->us, &st->ring_msg); 38 ret = spi_sync(st->us, &st->ring_msg);
@@ -71,12 +71,12 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)
71 struct iio_poll_func *pf = p; 71 struct iio_poll_func *pf = p;
72 struct iio_dev *indio_dev = pf->private_data; 72 struct iio_dev *indio_dev = pf->private_data;
73 struct iio_ring_buffer *ring = indio_dev->ring; 73 struct iio_ring_buffer *ring = indio_dev->ring;
74 struct ade7758_state *st = iio_dev_get_devdata(indio_dev); 74 struct ade7758_state *st = iio_priv(indio_dev);
75 s64 dat64[2]; 75 s64 dat64[2];
76 u32 *dat32 = (u32 *)dat64; 76 u32 *dat32 = (u32 *)dat64;
77 77
78 if (ring->scan_count) 78 if (ring->scan_count)
79 if (ade7758_spi_read_burst(&st->indio_dev->dev) >= 0) 79 if (ade7758_spi_read_burst(&indio_dev->dev) >= 0)
80 *dat32 = get_unaligned_be32(&st->rx_buf[5]) & 0xFFFFFF; 80 *dat32 = get_unaligned_be32(&st->rx_buf[5]) & 0xFFFFFF;
81 81
82 /* Guaranteed to be aligned with 8 byte boundary */ 82 /* Guaranteed to be aligned with 8 byte boundary */
@@ -85,7 +85,7 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)
85 85
86 ring->access->store_to(ring, (u8 *)dat64, pf->timestamp); 86 ring->access->store_to(ring, (u8 *)dat64, pf->timestamp);
87 87
88 iio_trigger_notify_done(st->indio_dev->trig); 88 iio_trigger_notify_done(indio_dev->trig);
89 89
90 return IRQ_HANDLED; 90 return IRQ_HANDLED;
91} 91}
@@ -99,7 +99,7 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)
99 **/ 99 **/
100static int ade7758_ring_preenable(struct iio_dev *indio_dev) 100static int ade7758_ring_preenable(struct iio_dev *indio_dev)
101{ 101{
102 struct ade7758_state *st = indio_dev->dev_data; 102 struct ade7758_state *st = iio_priv(indio_dev);
103 struct iio_ring_buffer *ring = indio_dev->ring; 103 struct iio_ring_buffer *ring = indio_dev->ring;
104 size_t d_size; 104 size_t d_size;
105 unsigned channel; 105 unsigned channel;
@@ -149,7 +149,7 @@ void ade7758_unconfigure_ring(struct iio_dev *indio_dev)
149 149
150int ade7758_configure_ring(struct iio_dev *indio_dev) 150int ade7758_configure_ring(struct iio_dev *indio_dev)
151{ 151{
152 struct ade7758_state *st = indio_dev->dev_data; 152 struct ade7758_state *st = iio_priv(indio_dev);
153 int ret = 0; 153 int ret = 0;
154 154
155 indio_dev->ring = iio_sw_rb_allocate(indio_dev); 155 indio_dev->ring = iio_sw_rb_allocate(indio_dev);
diff --git a/drivers/staging/iio/meter/ade7758_trigger.c b/drivers/staging/iio/meter/ade7758_trigger.c
index 5442d796357c..a5c3248151ed 100644
--- a/drivers/staging/iio/meter/ade7758_trigger.c
+++ b/drivers/staging/iio/meter/ade7758_trigger.c
@@ -37,8 +37,7 @@ static irqreturn_t ade7758_data_rdy_trig_poll(int irq, void *private)
37static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig, 37static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig,
38 bool state) 38 bool state)
39{ 39{
40 struct ade7758_state *st = trig->private_data; 40 struct iio_dev *indio_dev = trig->private_data;
41 struct iio_dev *indio_dev = st->indio_dev;
42 41
43 dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); 42 dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
44 return ade7758_set_irq(&indio_dev->dev, state); 43 return ade7758_set_irq(&indio_dev->dev, state);
@@ -50,7 +49,8 @@ static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig,
50 **/ 49 **/
51static int ade7758_trig_try_reen(struct iio_trigger *trig) 50static int ade7758_trig_try_reen(struct iio_trigger *trig)
52{ 51{
53 struct ade7758_state *st = trig->private_data; 52 struct iio_dev *indio_dev = trig->private_data;
53 struct ade7758_state *st = iio_priv(indio_dev);
54 54
55 enable_irq(st->us->irq); 55 enable_irq(st->us->irq);
56 /* irq reenabled so success! */ 56 /* irq reenabled so success! */
@@ -59,8 +59,8 @@ static int ade7758_trig_try_reen(struct iio_trigger *trig)
59 59
60int ade7758_probe_trigger(struct iio_dev *indio_dev) 60int ade7758_probe_trigger(struct iio_dev *indio_dev)
61{ 61{
62 struct ade7758_state *st = iio_priv(indio_dev);
62 int ret; 63 int ret;
63 struct ade7758_state *st = indio_dev->dev_data;
64 64
65 st->trig = iio_allocate_trigger("%s-dev%d", 65 st->trig = iio_allocate_trigger("%s-dev%d",
66 spi_get_device_id(st->us)->name, 66 spi_get_device_id(st->us)->name,
@@ -80,7 +80,7 @@ int ade7758_probe_trigger(struct iio_dev *indio_dev)
80 80
81 st->trig->dev.parent = &st->us->dev; 81 st->trig->dev.parent = &st->us->dev;
82 st->trig->owner = THIS_MODULE; 82 st->trig->owner = THIS_MODULE;
83 st->trig->private_data = st; 83 st->trig->private_data = indio_dev;
84 st->trig->set_trigger_state = &ade7758_data_rdy_trigger_set_state; 84 st->trig->set_trigger_state = &ade7758_data_rdy_trigger_set_state;
85 st->trig->try_reenable = &ade7758_trig_try_reen; 85 st->trig->try_reenable = &ade7758_trig_try_reen;
86 ret = iio_trigger_register(st->trig); 86 ret = iio_trigger_register(st->trig);
@@ -102,9 +102,9 @@ error_ret:
102 102
103void ade7758_remove_trigger(struct iio_dev *indio_dev) 103void ade7758_remove_trigger(struct iio_dev *indio_dev)
104{ 104{
105 struct ade7758_state *state = indio_dev->dev_data; 105 struct ade7758_state *st = iio_priv(indio_dev);
106 106
107 iio_trigger_unregister(state->trig); 107 iio_trigger_unregister(st->trig);
108 free_irq(state->us->irq, state->trig); 108 free_irq(st->us->irq, st->trig);
109 iio_free_trigger(state->trig); 109 iio_free_trigger(st->trig);
110} 110}