]>
Commit | Line | Data |
---|---|---|
b5a49481 MH |
1 | /* |
2 | * AD5446 SPI DAC driver | |
3 | * | |
4 | * Copyright 2010 Analog Devices Inc. | |
5 | * | |
6 | * Licensed under the GPL-2 or later. | |
7 | */ | |
8 | ||
9 | #include <linux/interrupt.h> | |
10 | #include <linux/workqueue.h> | |
11 | #include <linux/device.h> | |
12 | #include <linux/kernel.h> | |
13 | #include <linux/slab.h> | |
14 | #include <linux/sysfs.h> | |
15 | #include <linux/list.h> | |
16 | #include <linux/spi/spi.h> | |
3ec36a2c | 17 | #include <linux/i2c.h> |
b5a49481 MH |
18 | #include <linux/regulator/consumer.h> |
19 | #include <linux/err.h> | |
99c97852 | 20 | #include <linux/module.h> |
b5a49481 | 21 | |
06458e27 JC |
22 | #include <linux/iio/iio.h> |
23 | #include <linux/iio/sysfs.h> | |
b5a49481 | 24 | |
2e15c903 JFD |
25 | #define MODE_PWRDWN_1k 0x1 |
26 | #define MODE_PWRDWN_100k 0x2 | |
27 | #define MODE_PWRDWN_TRISTATE 0x3 | |
28 | ||
29 | /** | |
30 | * struct ad5446_state - driver instance specific data | |
31 | * @spi: spi_device | |
32 | * @chip_info: chip model specific constants, available modes etc | |
33 | * @reg: supply regulator | |
34 | * @vref_mv: actual reference voltage used | |
35 | */ | |
36 | ||
37 | struct ad5446_state { | |
38 | struct device *dev; | |
39 | const struct ad5446_chip_info *chip_info; | |
40 | struct regulator *reg; | |
41 | unsigned short vref_mv; | |
42 | unsigned cached_val; | |
43 | unsigned pwr_down_mode; | |
44 | unsigned pwr_down; | |
45 | }; | |
46 | ||
47 | /** | |
48 | * struct ad5446_chip_info - chip specific information | |
49 | * @channel: channel spec for the DAC | |
50 | * @int_vref_mv: AD5620/40/60: the internal reference voltage | |
51 | * @write: chip specific helper function to write to the register | |
52 | */ | |
53 | ||
54 | struct ad5446_chip_info { | |
55 | struct iio_chan_spec channel; | |
56 | u16 int_vref_mv; | |
57 | int (*write)(struct ad5446_state *st, unsigned val); | |
58 | }; | |
b5a49481 | 59 | |
83f0f572 | 60 | static const char * const ad5446_powerdown_modes[] = { |
09d48aa9 | 61 | "1kohm_to_gnd", "100kohm_to_gnd", "three_state" |
83f0f572 LPC |
62 | }; |
63 | ||
09d48aa9 LPC |
64 | static int ad5446_set_powerdown_mode(struct iio_dev *indio_dev, |
65 | const struct iio_chan_spec *chan, unsigned int mode) | |
bbed4dc7 | 66 | { |
638e59fc | 67 | struct ad5446_state *st = iio_priv(indio_dev); |
83f0f572 | 68 | |
09d48aa9 | 69 | st->pwr_down_mode = mode + 1; |
bbed4dc7 | 70 | |
09d48aa9 | 71 | return 0; |
bbed4dc7 MH |
72 | } |
73 | ||
09d48aa9 LPC |
74 | static int ad5446_get_powerdown_mode(struct iio_dev *indio_dev, |
75 | const struct iio_chan_spec *chan) | |
bbed4dc7 | 76 | { |
638e59fc | 77 | struct ad5446_state *st = iio_priv(indio_dev); |
bbed4dc7 | 78 | |
09d48aa9 | 79 | return st->pwr_down_mode - 1; |
bbed4dc7 MH |
80 | } |
81 | ||
09d48aa9 LPC |
82 | static const struct iio_enum ad5446_powerdown_mode_enum = { |
83 | .items = ad5446_powerdown_modes, | |
84 | .num_items = ARRAY_SIZE(ad5446_powerdown_modes), | |
85 | .get = ad5446_get_powerdown_mode, | |
86 | .set = ad5446_set_powerdown_mode, | |
87 | }; | |
88 | ||
83f0f572 | 89 | static ssize_t ad5446_read_dac_powerdown(struct iio_dev *indio_dev, |
fc6d1139 | 90 | uintptr_t private, |
83f0f572 | 91 | const struct iio_chan_spec *chan, |
bbed4dc7 MH |
92 | char *buf) |
93 | { | |
638e59fc | 94 | struct ad5446_state *st = iio_priv(indio_dev); |
bbed4dc7 MH |
95 | |
96 | return sprintf(buf, "%d\n", st->pwr_down); | |
97 | } | |
98 | ||
83f0f572 | 99 | static ssize_t ad5446_write_dac_powerdown(struct iio_dev *indio_dev, |
fc6d1139 | 100 | uintptr_t private, |
83f0f572 | 101 | const struct iio_chan_spec *chan, |
bbed4dc7 MH |
102 | const char *buf, size_t len) |
103 | { | |
638e59fc | 104 | struct ad5446_state *st = iio_priv(indio_dev); |
cae329e0 LPC |
105 | unsigned int shift; |
106 | unsigned int val; | |
83f0f572 | 107 | bool powerdown; |
bbed4dc7 MH |
108 | int ret; |
109 | ||
83f0f572 | 110 | ret = strtobool(buf, &powerdown); |
bbed4dc7 MH |
111 | if (ret) |
112 | return ret; | |
113 | ||
638e59fc | 114 | mutex_lock(&indio_dev->mlock); |
83f0f572 | 115 | st->pwr_down = powerdown; |
bbed4dc7 | 116 | |
cae329e0 LPC |
117 | if (st->pwr_down) { |
118 | shift = chan->scan_type.realbits + chan->scan_type.shift; | |
119 | val = st->pwr_down_mode << shift; | |
120 | } else { | |
121 | val = st->cached_val; | |
122 | } | |
bbed4dc7 | 123 | |
cae329e0 | 124 | ret = st->chip_info->write(st, val); |
638e59fc | 125 | mutex_unlock(&indio_dev->mlock); |
bbed4dc7 MH |
126 | |
127 | return ret ? ret : len; | |
128 | } | |
129 | ||
3ec36a2c | 130 | static const struct iio_chan_spec_ext_info ad5446_ext_info_powerdown[] = { |
83f0f572 LPC |
131 | { |
132 | .name = "powerdown", | |
133 | .read = ad5446_read_dac_powerdown, | |
134 | .write = ad5446_write_dac_powerdown, | |
83f0f572 | 135 | }, |
09d48aa9 LPC |
136 | IIO_ENUM("powerdown_mode", false, &ad5446_powerdown_mode_enum), |
137 | IIO_ENUM_AVAILABLE("powerdown_mode", &ad5446_powerdown_mode_enum), | |
83f0f572 | 138 | { }, |
b5a49481 MH |
139 | }; |
140 | ||
83f0f572 | 141 | #define _AD5446_CHANNEL(bits, storage, shift, ext) { \ |
33ad6b21 LPC |
142 | .type = IIO_VOLTAGE, \ |
143 | .indexed = 1, \ | |
144 | .output = 1, \ | |
145 | .channel = 0, \ | |
2f6a4a44 JC |
146 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
147 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ | |
83f0f572 LPC |
148 | .scan_type = IIO_ST('u', (bits), (storage), (shift)), \ |
149 | .ext_info = (ext), \ | |
33ad6b21 LPC |
150 | } |
151 | ||
83f0f572 LPC |
152 | #define AD5446_CHANNEL(bits, storage, shift) \ |
153 | _AD5446_CHANNEL(bits, storage, shift, NULL) | |
154 | ||
155 | #define AD5446_CHANNEL_POWERDOWN(bits, storage, shift) \ | |
3ec36a2c | 156 | _AD5446_CHANNEL(bits, storage, shift, ad5446_ext_info_powerdown) |
b5a49481 | 157 | |
33ad6b21 LPC |
158 | static int ad5446_read_raw(struct iio_dev *indio_dev, |
159 | struct iio_chan_spec const *chan, | |
160 | int *val, | |
161 | int *val2, | |
162 | long m) | |
163 | { | |
164 | struct ad5446_state *st = iio_priv(indio_dev); | |
165 | unsigned long scale_uv; | |
166 | ||
167 | switch (m) { | |
5e06bdfb LPC |
168 | case IIO_CHAN_INFO_RAW: |
169 | *val = st->cached_val; | |
170 | return IIO_VAL_INT; | |
33ad6b21 LPC |
171 | case IIO_CHAN_INFO_SCALE: |
172 | scale_uv = (st->vref_mv * 1000) >> chan->scan_type.realbits; | |
173 | *val = scale_uv / 1000; | |
174 | *val2 = (scale_uv % 1000) * 1000; | |
175 | return IIO_VAL_INT_PLUS_MICRO; | |
176 | ||
177 | } | |
178 | return -EINVAL; | |
179 | } | |
180 | ||
181 | static int ad5446_write_raw(struct iio_dev *indio_dev, | |
182 | struct iio_chan_spec const *chan, | |
183 | int val, | |
184 | int val2, | |
185 | long mask) | |
186 | { | |
187 | struct ad5446_state *st = iio_priv(indio_dev); | |
07ffd0d0 | 188 | int ret = 0; |
33ad6b21 LPC |
189 | |
190 | switch (mask) { | |
09f4eb40 | 191 | case IIO_CHAN_INFO_RAW: |
33ad6b21 LPC |
192 | if (val >= (1 << chan->scan_type.realbits) || val < 0) |
193 | return -EINVAL; | |
194 | ||
195 | val <<= chan->scan_type.shift; | |
196 | mutex_lock(&indio_dev->mlock); | |
197 | st->cached_val = val; | |
af836d9a | 198 | if (!st->pwr_down) |
cae329e0 | 199 | ret = st->chip_info->write(st, val); |
33ad6b21 LPC |
200 | mutex_unlock(&indio_dev->mlock); |
201 | break; | |
202 | default: | |
203 | ret = -EINVAL; | |
204 | } | |
205 | ||
206 | return ret; | |
207 | } | |
208 | ||
6fe8135f | 209 | static const struct iio_info ad5446_info = { |
7389266c JC |
210 | .read_raw = ad5446_read_raw, |
211 | .write_raw = ad5446_write_raw, | |
212 | .driver_module = THIS_MODULE, | |
213 | }; | |
214 | ||
fc52692c GKH |
215 | static int ad5446_probe(struct device *dev, const char *name, |
216 | const struct ad5446_chip_info *chip_info) | |
b5a49481 MH |
217 | { |
218 | struct ad5446_state *st; | |
86729fc4 JC |
219 | struct iio_dev *indio_dev; |
220 | struct regulator *reg; | |
b5a49481 MH |
221 | int ret, voltage_uv = 0; |
222 | ||
ba727295 | 223 | reg = devm_regulator_get(dev, "vcc"); |
86729fc4 JC |
224 | if (!IS_ERR(reg)) { |
225 | ret = regulator_enable(reg); | |
b5a49481 | 226 | if (ret) |
ba727295 | 227 | return ret; |
b5a49481 | 228 | |
13e57ee2 AL |
229 | ret = regulator_get_voltage(reg); |
230 | if (ret < 0) | |
231 | goto error_disable_reg; | |
232 | ||
233 | voltage_uv = ret; | |
b5a49481 MH |
234 | } |
235 | ||
ba727295 | 236 | indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); |
86729fc4 JC |
237 | if (indio_dev == NULL) { |
238 | ret = -ENOMEM; | |
239 | goto error_disable_reg; | |
240 | } | |
241 | st = iio_priv(indio_dev); | |
3ec36a2c | 242 | st->chip_info = chip_info; |
b5a49481 | 243 | |
3ec36a2c | 244 | dev_set_drvdata(dev, indio_dev); |
86729fc4 | 245 | st->reg = reg; |
3ec36a2c | 246 | st->dev = dev; |
b5a49481 | 247 | |
3ec36a2c JFD |
248 | /* Establish that the iio_dev is a child of the device */ |
249 | indio_dev->dev.parent = dev; | |
250 | indio_dev->name = name; | |
83f0f572 | 251 | indio_dev->info = &ad5446_info; |
86729fc4 | 252 | indio_dev->modes = INDIO_DIRECT_MODE; |
33ad6b21 LPC |
253 | indio_dev->channels = &st->chip_info->channel; |
254 | indio_dev->num_channels = 1; | |
b5a49481 | 255 | |
09d48aa9 LPC |
256 | st->pwr_down_mode = MODE_PWRDWN_1k; |
257 | ||
4e5d3f92 | 258 | if (st->chip_info->int_vref_mv) |
bbed4dc7 | 259 | st->vref_mv = st->chip_info->int_vref_mv; |
4e5d3f92 LPC |
260 | else if (voltage_uv) |
261 | st->vref_mv = voltage_uv / 1000; | |
262 | else | |
3ec36a2c | 263 | dev_warn(dev, "reference voltage unspecified\n"); |
b5a49481 | 264 | |
86729fc4 | 265 | ret = iio_device_register(indio_dev); |
b5a49481 | 266 | if (ret) |
ba727295 | 267 | goto error_disable_reg; |
b5a49481 MH |
268 | |
269 | return 0; | |
270 | ||
b5a49481 | 271 | error_disable_reg: |
86729fc4 JC |
272 | if (!IS_ERR(reg)) |
273 | regulator_disable(reg); | |
b5a49481 MH |
274 | return ret; |
275 | } | |
276 | ||
3ec36a2c | 277 | static int ad5446_remove(struct device *dev) |
b5a49481 | 278 | { |
3ec36a2c | 279 | struct iio_dev *indio_dev = dev_get_drvdata(dev); |
86729fc4 | 280 | struct ad5446_state *st = iio_priv(indio_dev); |
b5a49481 MH |
281 | |
282 | iio_device_unregister(indio_dev); | |
ba727295 | 283 | if (!IS_ERR(st->reg)) |
d2fffd6c | 284 | regulator_disable(st->reg); |
d2fffd6c | 285 | |
b5a49481 MH |
286 | return 0; |
287 | } | |
288 | ||
3ec36a2c JFD |
289 | #if IS_ENABLED(CONFIG_SPI_MASTER) |
290 | ||
291 | static int ad5446_write(struct ad5446_state *st, unsigned val) | |
292 | { | |
293 | struct spi_device *spi = to_spi_device(st->dev); | |
294 | __be16 data = cpu_to_be16(val); | |
295 | ||
296 | return spi_write(spi, &data, sizeof(data)); | |
297 | } | |
298 | ||
299 | static int ad5660_write(struct ad5446_state *st, unsigned val) | |
300 | { | |
301 | struct spi_device *spi = to_spi_device(st->dev); | |
302 | uint8_t data[3]; | |
303 | ||
304 | data[0] = (val >> 16) & 0xFF; | |
305 | data[1] = (val >> 8) & 0xFF; | |
306 | data[2] = val & 0xFF; | |
307 | ||
308 | return spi_write(spi, data, sizeof(data)); | |
309 | } | |
310 | ||
311 | /** | |
312 | * ad5446_supported_spi_device_ids: | |
313 | * The AD5620/40/60 parts are available in different fixed internal reference | |
314 | * voltage options. The actual part numbers may look differently | |
315 | * (and a bit cryptic), however this style is used to make clear which | |
316 | * parts are supported here. | |
317 | */ | |
318 | enum ad5446_supported_spi_device_ids { | |
2fafbce2 LPC |
319 | ID_AD5300, |
320 | ID_AD5310, | |
321 | ID_AD5320, | |
3ec36a2c JFD |
322 | ID_AD5444, |
323 | ID_AD5446, | |
324 | ID_AD5450, | |
325 | ID_AD5451, | |
326 | ID_AD5541A, | |
327 | ID_AD5512A, | |
328 | ID_AD5553, | |
329 | ID_AD5601, | |
330 | ID_AD5611, | |
331 | ID_AD5621, | |
332 | ID_AD5620_2500, | |
333 | ID_AD5620_1250, | |
334 | ID_AD5640_2500, | |
335 | ID_AD5640_1250, | |
336 | ID_AD5660_2500, | |
337 | ID_AD5660_1250, | |
338 | ID_AD5662, | |
339 | }; | |
340 | ||
341 | static const struct ad5446_chip_info ad5446_spi_chip_info[] = { | |
2fafbce2 LPC |
342 | [ID_AD5300] = { |
343 | .channel = AD5446_CHANNEL_POWERDOWN(8, 16, 4), | |
344 | .write = ad5446_write, | |
345 | }, | |
346 | [ID_AD5310] = { | |
347 | .channel = AD5446_CHANNEL_POWERDOWN(10, 16, 2), | |
348 | .write = ad5446_write, | |
349 | }, | |
350 | [ID_AD5320] = { | |
351 | .channel = AD5446_CHANNEL_POWERDOWN(12, 16, 0), | |
352 | .write = ad5446_write, | |
353 | }, | |
3ec36a2c JFD |
354 | [ID_AD5444] = { |
355 | .channel = AD5446_CHANNEL(12, 16, 2), | |
356 | .write = ad5446_write, | |
357 | }, | |
358 | [ID_AD5446] = { | |
359 | .channel = AD5446_CHANNEL(14, 16, 0), | |
360 | .write = ad5446_write, | |
361 | }, | |
362 | [ID_AD5450] = { | |
363 | .channel = AD5446_CHANNEL(8, 16, 6), | |
364 | .write = ad5446_write, | |
365 | }, | |
366 | [ID_AD5451] = { | |
367 | .channel = AD5446_CHANNEL(10, 16, 4), | |
368 | .write = ad5446_write, | |
369 | }, | |
370 | [ID_AD5541A] = { | |
371 | .channel = AD5446_CHANNEL(16, 16, 0), | |
372 | .write = ad5446_write, | |
373 | }, | |
374 | [ID_AD5512A] = { | |
375 | .channel = AD5446_CHANNEL(12, 16, 4), | |
376 | .write = ad5446_write, | |
377 | }, | |
378 | [ID_AD5553] = { | |
379 | .channel = AD5446_CHANNEL(14, 16, 0), | |
380 | .write = ad5446_write, | |
381 | }, | |
382 | [ID_AD5601] = { | |
383 | .channel = AD5446_CHANNEL_POWERDOWN(8, 16, 6), | |
384 | .write = ad5446_write, | |
385 | }, | |
386 | [ID_AD5611] = { | |
387 | .channel = AD5446_CHANNEL_POWERDOWN(10, 16, 4), | |
388 | .write = ad5446_write, | |
389 | }, | |
390 | [ID_AD5621] = { | |
391 | .channel = AD5446_CHANNEL_POWERDOWN(12, 16, 2), | |
392 | .write = ad5446_write, | |
393 | }, | |
394 | [ID_AD5620_2500] = { | |
395 | .channel = AD5446_CHANNEL_POWERDOWN(12, 16, 2), | |
396 | .int_vref_mv = 2500, | |
397 | .write = ad5446_write, | |
398 | }, | |
399 | [ID_AD5620_1250] = { | |
400 | .channel = AD5446_CHANNEL_POWERDOWN(12, 16, 2), | |
401 | .int_vref_mv = 1250, | |
402 | .write = ad5446_write, | |
403 | }, | |
404 | [ID_AD5640_2500] = { | |
405 | .channel = AD5446_CHANNEL_POWERDOWN(14, 16, 0), | |
406 | .int_vref_mv = 2500, | |
407 | .write = ad5446_write, | |
408 | }, | |
409 | [ID_AD5640_1250] = { | |
410 | .channel = AD5446_CHANNEL_POWERDOWN(14, 16, 0), | |
411 | .int_vref_mv = 1250, | |
412 | .write = ad5446_write, | |
413 | }, | |
414 | [ID_AD5660_2500] = { | |
415 | .channel = AD5446_CHANNEL_POWERDOWN(16, 16, 0), | |
416 | .int_vref_mv = 2500, | |
417 | .write = ad5660_write, | |
418 | }, | |
419 | [ID_AD5660_1250] = { | |
420 | .channel = AD5446_CHANNEL_POWERDOWN(16, 16, 0), | |
421 | .int_vref_mv = 1250, | |
422 | .write = ad5660_write, | |
423 | }, | |
424 | [ID_AD5662] = { | |
425 | .channel = AD5446_CHANNEL_POWERDOWN(16, 16, 0), | |
426 | .write = ad5660_write, | |
427 | }, | |
428 | }; | |
429 | ||
430 | static const struct spi_device_id ad5446_spi_ids[] = { | |
2fafbce2 LPC |
431 | {"ad5300", ID_AD5300}, |
432 | {"ad5310", ID_AD5310}, | |
433 | {"ad5320", ID_AD5320}, | |
b5a49481 MH |
434 | {"ad5444", ID_AD5444}, |
435 | {"ad5446", ID_AD5446}, | |
779c0c46 LPC |
436 | {"ad5450", ID_AD5450}, |
437 | {"ad5451", ID_AD5451}, | |
438 | {"ad5452", ID_AD5444}, /* ad5452 is compatible to the ad5444 */ | |
439 | {"ad5453", ID_AD5446}, /* ad5453 is compatible to the ad5446 */ | |
b5a49481 | 440 | {"ad5512a", ID_AD5512A}, |
67d1c1f4 | 441 | {"ad5541a", ID_AD5541A}, |
11a7df48 LPC |
442 | {"ad5542a", ID_AD5541A}, /* ad5541a and ad5542a are compatible */ |
443 | {"ad5543", ID_AD5541A}, /* ad5541a and ad5543 are compatible */ | |
bd51c0b0 | 444 | {"ad5553", ID_AD5553}, |
2b61535a MH |
445 | {"ad5601", ID_AD5601}, |
446 | {"ad5611", ID_AD5611}, | |
447 | {"ad5621", ID_AD5621}, | |
d846263d MH |
448 | {"ad5620-2500", ID_AD5620_2500}, /* AD5620/40/60: */ |
449 | {"ad5620-1250", ID_AD5620_1250}, /* part numbers may look differently */ | |
450 | {"ad5640-2500", ID_AD5640_2500}, | |
451 | {"ad5640-1250", ID_AD5640_1250}, | |
452 | {"ad5660-2500", ID_AD5660_2500}, | |
453 | {"ad5660-1250", ID_AD5660_1250}, | |
18e5ab31 | 454 | {"ad5662", ID_AD5662}, |
b5a49481 MH |
455 | {} |
456 | }; | |
3ec36a2c JFD |
457 | MODULE_DEVICE_TABLE(spi, ad5446_spi_ids); |
458 | ||
fc52692c | 459 | static int ad5446_spi_probe(struct spi_device *spi) |
3ec36a2c JFD |
460 | { |
461 | const struct spi_device_id *id = spi_get_device_id(spi); | |
462 | ||
463 | return ad5446_probe(&spi->dev, id->name, | |
464 | &ad5446_spi_chip_info[id->driver_data]); | |
465 | } | |
b5a49481 | 466 | |
fc52692c | 467 | static int ad5446_spi_remove(struct spi_device *spi) |
3ec36a2c JFD |
468 | { |
469 | return ad5446_remove(&spi->dev); | |
470 | } | |
471 | ||
472 | static struct spi_driver ad5446_spi_driver = { | |
b5a49481 MH |
473 | .driver = { |
474 | .name = "ad5446", | |
b5a49481 MH |
475 | .owner = THIS_MODULE, |
476 | }, | |
3ec36a2c | 477 | .probe = ad5446_spi_probe, |
fc52692c | 478 | .remove = ad5446_spi_remove, |
3ec36a2c JFD |
479 | .id_table = ad5446_spi_ids, |
480 | }; | |
481 | ||
482 | static int __init ad5446_spi_register_driver(void) | |
483 | { | |
484 | return spi_register_driver(&ad5446_spi_driver); | |
485 | } | |
486 | ||
487 | static void ad5446_spi_unregister_driver(void) | |
488 | { | |
489 | spi_unregister_driver(&ad5446_spi_driver); | |
490 | } | |
491 | ||
492 | #else | |
493 | ||
494 | static inline int ad5446_spi_register_driver(void) { return 0; } | |
495 | static inline void ad5446_spi_unregister_driver(void) { } | |
496 | ||
497 | #endif | |
498 | ||
499 | #if IS_ENABLED(CONFIG_I2C) | |
500 | ||
501 | static int ad5622_write(struct ad5446_state *st, unsigned val) | |
502 | { | |
503 | struct i2c_client *client = to_i2c_client(st->dev); | |
504 | __be16 data = cpu_to_be16(val); | |
505 | ||
506 | return i2c_master_send(client, (char *)&data, sizeof(data)); | |
507 | } | |
508 | ||
509 | /** | |
510 | * ad5446_supported_i2c_device_ids: | |
511 | * The AD5620/40/60 parts are available in different fixed internal reference | |
512 | * voltage options. The actual part numbers may look differently | |
513 | * (and a bit cryptic), however this style is used to make clear which | |
514 | * parts are supported here. | |
515 | */ | |
516 | enum ad5446_supported_i2c_device_ids { | |
517 | ID_AD5602, | |
518 | ID_AD5612, | |
519 | ID_AD5622, | |
520 | }; | |
521 | ||
522 | static const struct ad5446_chip_info ad5446_i2c_chip_info[] = { | |
523 | [ID_AD5602] = { | |
524 | .channel = AD5446_CHANNEL_POWERDOWN(8, 16, 4), | |
525 | .write = ad5622_write, | |
526 | }, | |
527 | [ID_AD5612] = { | |
528 | .channel = AD5446_CHANNEL_POWERDOWN(10, 16, 2), | |
529 | .write = ad5622_write, | |
530 | }, | |
531 | [ID_AD5622] = { | |
532 | .channel = AD5446_CHANNEL_POWERDOWN(12, 16, 0), | |
533 | .write = ad5622_write, | |
534 | }, | |
b5a49481 | 535 | }; |
3ec36a2c | 536 | |
fc52692c GKH |
537 | static int ad5446_i2c_probe(struct i2c_client *i2c, |
538 | const struct i2c_device_id *id) | |
3ec36a2c JFD |
539 | { |
540 | return ad5446_probe(&i2c->dev, id->name, | |
541 | &ad5446_i2c_chip_info[id->driver_data]); | |
542 | } | |
543 | ||
fc52692c | 544 | static int ad5446_i2c_remove(struct i2c_client *i2c) |
3ec36a2c JFD |
545 | { |
546 | return ad5446_remove(&i2c->dev); | |
547 | } | |
548 | ||
549 | static const struct i2c_device_id ad5446_i2c_ids[] = { | |
bf832380 LPC |
550 | {"ad5301", ID_AD5602}, |
551 | {"ad5311", ID_AD5612}, | |
552 | {"ad5321", ID_AD5622}, | |
3ec36a2c JFD |
553 | {"ad5602", ID_AD5602}, |
554 | {"ad5612", ID_AD5612}, | |
555 | {"ad5622", ID_AD5622}, | |
556 | {} | |
557 | }; | |
558 | MODULE_DEVICE_TABLE(i2c, ad5446_i2c_ids); | |
559 | ||
560 | static struct i2c_driver ad5446_i2c_driver = { | |
561 | .driver = { | |
562 | .name = "ad5446", | |
563 | .owner = THIS_MODULE, | |
564 | }, | |
565 | .probe = ad5446_i2c_probe, | |
fc52692c | 566 | .remove = ad5446_i2c_remove, |
3ec36a2c JFD |
567 | .id_table = ad5446_i2c_ids, |
568 | }; | |
569 | ||
570 | static int __init ad5446_i2c_register_driver(void) | |
571 | { | |
572 | return i2c_add_driver(&ad5446_i2c_driver); | |
573 | } | |
574 | ||
575 | static void __exit ad5446_i2c_unregister_driver(void) | |
576 | { | |
577 | i2c_del_driver(&ad5446_i2c_driver); | |
578 | } | |
579 | ||
580 | #else | |
581 | ||
582 | static inline int ad5446_i2c_register_driver(void) { return 0; } | |
583 | static inline void ad5446_i2c_unregister_driver(void) { } | |
584 | ||
585 | #endif | |
586 | ||
587 | static int __init ad5446_init(void) | |
588 | { | |
589 | int ret; | |
590 | ||
591 | ret = ad5446_spi_register_driver(); | |
592 | if (ret) | |
593 | return ret; | |
594 | ||
595 | ret = ad5446_i2c_register_driver(); | |
596 | if (ret) { | |
597 | ad5446_spi_unregister_driver(); | |
598 | return ret; | |
599 | } | |
600 | ||
601 | return 0; | |
602 | } | |
603 | module_init(ad5446_init); | |
604 | ||
605 | static void __exit ad5446_exit(void) | |
606 | { | |
607 | ad5446_i2c_unregister_driver(); | |
608 | ad5446_spi_unregister_driver(); | |
609 | } | |
610 | module_exit(ad5446_exit); | |
b5a49481 MH |
611 | |
612 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | |
613 | MODULE_DESCRIPTION("Analog Devices AD5444/AD5446 DAC"); | |
614 | MODULE_LICENSE("GPL v2"); |