diff options
author | Michael Hennerich <michael.hennerich@analog.com> | 2011-05-18 09:42:29 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-05-19 19:15:04 -0400 |
commit | 643ea260b4cb81dfc99b3e18e4be25ba2f1936ed (patch) | |
tree | d7a3e1c79c60bfeaf0b22c0c9ce2cda4870974e5 | |
parent | 44039a671ecceaf023209b0446ca7443ec11c57c (diff) |
staging:iio:adc:AD7780: Convert to new channel registration method
Convert to new channel registration method
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>
-rw-r--r-- | drivers/staging/iio/adc/ad7780.c | 113 |
1 files changed, 51 insertions, 62 deletions
diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index f828e832a95f..14b16b5d4b1a 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c | |||
@@ -36,9 +36,7 @@ | |||
36 | #define AD7780_PAT0 (1 << 0) | 36 | #define AD7780_PAT0 (1 << 0) |
37 | 37 | ||
38 | struct ad7780_chip_info { | 38 | struct ad7780_chip_info { |
39 | u8 bits; | 39 | struct iio_chan_spec channel; |
40 | u8 storagebits; | ||
41 | u8 res_shift; | ||
42 | }; | 40 | }; |
43 | 41 | ||
44 | struct ad7780_state { | 42 | struct ad7780_state { |
@@ -88,70 +86,59 @@ out: | |||
88 | return ret; | 86 | return ret; |
89 | } | 87 | } |
90 | 88 | ||
91 | static ssize_t ad7780_scan(struct device *dev, | 89 | static int ad7780_read_raw(struct iio_dev *indio_dev, |
92 | struct device_attribute *attr, | 90 | struct iio_chan_spec const *chan, |
93 | char *buf) | 91 | int *val, |
92 | int *val2, | ||
93 | long m) | ||
94 | { | 94 | { |
95 | struct iio_dev *dev_info = dev_get_drvdata(dev); | 95 | int ret, smpl; |
96 | struct ad7780_state *st = dev_info->dev_data; | 96 | struct ad7780_state *st = indio_dev->dev_data; |
97 | int ret, val, smpl; | 97 | unsigned int scale_uv; |
98 | 98 | ||
99 | mutex_lock(&dev_info->mlock); | 99 | switch (m) { |
100 | ret = ad7780_read(st, &smpl); | 100 | case 0: |
101 | mutex_unlock(&dev_info->mlock); | 101 | mutex_lock(&indio_dev->mlock); |
102 | 102 | ret = ad7780_read(st, &smpl); | |
103 | if (ret < 0) | 103 | mutex_unlock(&indio_dev->mlock); |
104 | return ret; | 104 | |
105 | 105 | if (ret < 0) | |
106 | if ((smpl & AD7780_ERR) || | 106 | return ret; |
107 | !((smpl & AD7780_PAT0) && !(smpl & AD7780_PAT1))) | 107 | |
108 | return -EIO; | 108 | if ((smpl & AD7780_ERR) || |
109 | 109 | !((smpl & AD7780_PAT0) && !(smpl & AD7780_PAT1))) | |
110 | val = (smpl >> st->chip_info->res_shift) & | 110 | return -EIO; |
111 | ((1 << (st->chip_info->bits)) - 1); | 111 | |
112 | val -= (1 << (st->chip_info->bits - 1)); | 112 | *val = (smpl >> st->chip_info->channel.scan_type.shift) & |
113 | 113 | ((1 << (st->chip_info->channel.scan_type.realbits)) | |
114 | if (!(smpl & AD7780_GAIN)) | 114 | - 1); |
115 | val *= 128; | 115 | *val -= (1 << (st->chip_info->channel.scan_type.realbits |
116 | 116 | - 1)); | |
117 | return sprintf(buf, "%d\n", val); | 117 | |
118 | } | 118 | if (!(smpl & AD7780_GAIN)) |
119 | static IIO_DEV_ATTR_IN_RAW(0, ad7780_scan, 0); | 119 | *val *= 128; |
120 | 120 | ||
121 | static ssize_t ad7780_show_scale(struct device *dev, | 121 | return IIO_VAL_INT; |
122 | struct device_attribute *attr, | 122 | case (1 << IIO_CHAN_INFO_SCALE_SHARED): |
123 | char *buf) | 123 | scale_uv = (st->int_vref_mv * 100000) |
124 | { | 124 | >> (st->chip_info->channel.scan_type.realbits - 1); |
125 | struct iio_dev *dev_info = dev_get_drvdata(dev); | 125 | *val = scale_uv / 100000; |
126 | struct ad7780_state *st = iio_dev_get_devdata(dev_info); | 126 | *val2 = (scale_uv % 100000) * 10; |
127 | /* Corresponds to Vref / 2^(bits-1) */ | 127 | return IIO_VAL_INT_PLUS_MICRO; |
128 | unsigned int scale = (st->int_vref_mv * 100000) >> | 128 | } |
129 | (st->chip_info->bits - 1); | 129 | return -EINVAL; |
130 | |||
131 | return sprintf(buf, "%d.%05d\n", scale / 100000, scale % 100000); | ||
132 | } | 130 | } |
133 | static IIO_DEVICE_ATTR(in_scale, S_IRUGO, ad7780_show_scale, NULL, 0); | ||
134 | |||
135 | static struct attribute *ad7780_attributes[] = { | ||
136 | &iio_dev_attr_in0_raw.dev_attr.attr, | ||
137 | &iio_dev_attr_in_scale.dev_attr.attr, | ||
138 | NULL, | ||
139 | }; | ||
140 | |||
141 | static const struct attribute_group ad7780_attribute_group = { | ||
142 | .attrs = ad7780_attributes, | ||
143 | }; | ||
144 | 131 | ||
145 | static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { | 132 | static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { |
146 | [ID_AD7780] = { | 133 | [ID_AD7780] = { |
147 | .bits = 24, | 134 | .channel = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0, |
148 | .storagebits = 32, | 135 | (1 << IIO_CHAN_INFO_SCALE_SHARED), |
149 | .res_shift = 8, | 136 | 0, 0, IIO_ST('s', 24, 32, 8), 0), |
150 | }, | 137 | }, |
151 | [ID_AD7781] = { | 138 | [ID_AD7781] = { |
152 | .bits = 20, | 139 | .channel = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0, |
153 | .storagebits = 32, | 140 | (1 << IIO_CHAN_INFO_SCALE_SHARED), |
154 | .res_shift = 12, | 141 | 0, 0, IIO_ST('s', 20, 32, 12), 0), |
155 | }, | 142 | }, |
156 | }; | 143 | }; |
157 | 144 | ||
@@ -218,17 +205,19 @@ static int __devinit ad7780_probe(struct spi_device *spi) | |||
218 | /* Establish that the iio_dev is a child of the spi device */ | 205 | /* Establish that the iio_dev is a child of the spi device */ |
219 | st->indio_dev->dev.parent = &spi->dev; | 206 | st->indio_dev->dev.parent = &spi->dev; |
220 | st->indio_dev->name = spi_get_device_id(spi)->name; | 207 | st->indio_dev->name = spi_get_device_id(spi)->name; |
221 | st->indio_dev->attrs = &ad7780_attribute_group; | ||
222 | st->indio_dev->dev_data = (void *)(st); | 208 | st->indio_dev->dev_data = (void *)(st); |
223 | st->indio_dev->driver_module = THIS_MODULE; | 209 | st->indio_dev->driver_module = THIS_MODULE; |
224 | st->indio_dev->modes = INDIO_DIRECT_MODE; | 210 | st->indio_dev->modes = INDIO_DIRECT_MODE; |
211 | st->indio_dev->channels = &st->chip_info->channel; | ||
212 | st->indio_dev->num_channels = 1; | ||
213 | st->indio_dev->read_raw = &ad7780_read_raw; | ||
225 | 214 | ||
226 | init_waitqueue_head(&st->wq_data_avail); | 215 | init_waitqueue_head(&st->wq_data_avail); |
227 | 216 | ||
228 | /* Setup default message */ | 217 | /* Setup default message */ |
229 | 218 | ||
230 | st->xfer.rx_buf = &st->data; | 219 | st->xfer.rx_buf = &st->data; |
231 | st->xfer.len = st->chip_info->storagebits / 8; | 220 | st->xfer.len = st->chip_info->channel.scan_type.storagebits / 8; |
232 | 221 | ||
233 | spi_message_init(&st->msg); | 222 | spi_message_init(&st->msg); |
234 | spi_message_add_tail(&st->xfer, &st->msg); | 223 | spi_message_add_tail(&st->xfer, &st->msg); |