staging:iio:ad7291: Use i2c_smbus_{read,write}_word_swapped instead of open-coding it
[firefly-linux-kernel-4.4.55.git] / drivers / staging / iio / adc / ad7291.c
1 /*
2  * AD7291 8-Channel, I2C, 12-Bit SAR ADC with Temperature Sensor
3  *
4  * Copyright 2010-2011 Analog Devices Inc.
5  *
6  * Licensed under the GPL-2 or later.
7  */
8
9 #include <linux/interrupt.h>
10 #include <linux/device.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/sysfs.h>
14 #include <linux/i2c.h>
15 #include <linux/module.h>
16 #include <linux/mutex.h>
17 #include <linux/regulator/consumer.h>
18 #include <linux/err.h>
19
20 #include <linux/iio/iio.h>
21 #include <linux/iio/sysfs.h>
22 #include <linux/iio/events.h>
23
24 /*
25  * Simplified handling
26  *
27  * If no events enabled - single polled channel read
28  * If event enabled direct reads disable unless channel
29  * is in the read mask.
30  *
31  * The noise-delayed bit as per datasheet suggestion is always enabled.
32  *
33  */
34
35 /*
36  * AD7291 registers definition
37  */
38 #define AD7291_COMMAND                  0x00
39 #define AD7291_VOLTAGE                  0x01
40 #define AD7291_T_SENSE                  0x02
41 #define AD7291_T_AVERAGE                0x03
42 #define AD7291_DATA_HIGH(x)             ((x) * 3 + 0x4)
43 #define AD7291_DATA_LOW(x)              ((x) * 3 + 0x5)
44 #define AD7291_HYST(x)                  ((x) * 3 + 0x6)
45 #define AD7291_VOLTAGE_ALERT_STATUS     0x1F
46 #define AD7291_T_ALERT_STATUS           0x20
47
48 #define AD7291_VOLTAGE_LIMIT_COUNT      8
49
50
51 /*
52  * AD7291 command
53  */
54 #define AD7291_AUTOCYCLE                (1 << 0)
55 #define AD7291_RESET                    (1 << 1)
56 #define AD7291_ALERT_CLEAR              (1 << 2)
57 #define AD7291_ALERT_POLARITY           (1 << 3)
58 #define AD7291_EXT_REF                  (1 << 4)
59 #define AD7291_NOISE_DELAY              (1 << 5)
60 #define AD7291_T_SENSE_MASK             (1 << 7)
61 #define AD7291_VOLTAGE_MASK             0xFF00
62 #define AD7291_VOLTAGE_OFFSET           0x8
63
64 /*
65  * AD7291 value masks
66  */
67 #define AD7291_CHANNEL_MASK             0xF000
68 #define AD7291_BITS                     12
69 #define AD7291_VALUE_MASK               0xFFF
70 #define AD7291_T_VALUE_SIGN             0x400
71 #define AD7291_T_VALUE_FLOAT_OFFSET     2
72 #define AD7291_T_VALUE_FLOAT_MASK       0x2
73
74 #define AD7291_BITS                     12
75
76 struct ad7291_chip_info {
77         struct i2c_client       *client;
78         struct regulator        *reg;
79         u16                     int_vref_mv;
80         u16                     command;
81         u16                     c_mask; /* Active voltage channels for events */
82         struct mutex            state_lock;
83 };
84
85 static int ad7291_i2c_read(struct ad7291_chip_info *chip, u8 reg, u16 *data)
86 {
87         struct i2c_client *client = chip->client;
88         int ret = 0;
89
90         ret = i2c_smbus_read_word_swapped(client, reg);
91         if (ret < 0) {
92                 dev_err(&client->dev, "I2C read error\n");
93                 return ret;
94         }
95
96         *data = ret;
97
98         return 0;
99 }
100
101 static int ad7291_i2c_write(struct ad7291_chip_info *chip, u8 reg, u16 data)
102 {
103         return i2c_smbus_write_word_swapped(chip->client, reg, data);
104 }
105
106 static irqreturn_t ad7291_event_handler(int irq, void *private)
107 {
108         struct iio_dev *indio_dev = private;
109         struct ad7291_chip_info *chip = iio_priv(private);
110         u16 t_status, v_status;
111         u16 command;
112         int i;
113         s64 timestamp = iio_get_time_ns();
114
115         if (ad7291_i2c_read(chip, AD7291_T_ALERT_STATUS, &t_status))
116                 return IRQ_HANDLED;
117
118         if (ad7291_i2c_read(chip, AD7291_VOLTAGE_ALERT_STATUS, &v_status))
119                 return IRQ_HANDLED;
120
121         if (!(t_status || v_status))
122                 return IRQ_HANDLED;
123
124         command = chip->command | AD7291_ALERT_CLEAR;
125         ad7291_i2c_write(chip, AD7291_COMMAND, command);
126
127         command = chip->command & ~AD7291_ALERT_CLEAR;
128         ad7291_i2c_write(chip, AD7291_COMMAND, command);
129
130         /* For now treat t_sense and t_sense_average the same */
131         if ((t_status & (1 << 0)) || (t_status & (1 << 2)))
132                 iio_push_event(indio_dev,
133                                IIO_UNMOD_EVENT_CODE(IIO_TEMP,
134                                                     0,
135                                                     IIO_EV_TYPE_THRESH,
136                                                     IIO_EV_DIR_FALLING),
137                                timestamp);
138         if ((t_status & (1 << 1)) || (t_status & (1 << 3)))
139                 iio_push_event(indio_dev,
140                                IIO_UNMOD_EVENT_CODE(IIO_TEMP,
141                                                     0,
142                                                     IIO_EV_TYPE_THRESH,
143                                                     IIO_EV_DIR_RISING),
144                                timestamp);
145
146         for (i = 0; i < AD7291_VOLTAGE_LIMIT_COUNT*2; i += 2) {
147                 if (v_status & (1 << i))
148                         iio_push_event(indio_dev,
149                                        IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
150                                                             i/2,
151                                                             IIO_EV_TYPE_THRESH,
152                                                             IIO_EV_DIR_FALLING),
153                                        timestamp);
154                 if (v_status & (1 << (i + 1)))
155                         iio_push_event(indio_dev,
156                                        IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
157                                                             i/2,
158                                                             IIO_EV_TYPE_THRESH,
159                                                             IIO_EV_DIR_RISING),
160                                        timestamp);
161         }
162
163         return IRQ_HANDLED;
164 }
165
166 static inline ssize_t ad7291_show_hyst(struct device *dev,
167                 struct device_attribute *attr,
168                 char *buf)
169 {
170         struct iio_dev *indio_dev = dev_to_iio_dev(dev);
171         struct ad7291_chip_info *chip = iio_priv(indio_dev);
172         struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
173         u16 data;
174         int ret;
175
176         ret = ad7291_i2c_read(chip, this_attr->address, &data);
177         if (ret < 0)
178                 return ret;
179
180         return sprintf(buf, "%d\n", data & AD7291_VALUE_MASK);
181 }
182
183 static inline ssize_t ad7291_set_hyst(struct device *dev,
184                                       struct device_attribute *attr,
185                                       const char *buf,
186                                       size_t len)
187 {
188         struct iio_dev *indio_dev = dev_to_iio_dev(dev);
189         struct ad7291_chip_info *chip = iio_priv(indio_dev);
190         struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
191         u16 data;
192         int ret;
193
194         ret = kstrtou16(buf, 10, &data);
195
196         if (ret < 0)
197                 return ret;
198         if (data > AD7291_VALUE_MASK)
199                 return -EINVAL;
200
201         ret = ad7291_i2c_write(chip, this_attr->address, data);
202         if (ret < 0)
203                 return ret;
204
205         return len;
206 }
207
208 static IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw,
209                        S_IRUGO | S_IWUSR,
210                        ad7291_show_hyst, ad7291_set_hyst,
211                        AD7291_HYST(8));
212 static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw,
213                        S_IRUGO | S_IWUSR,
214                        ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(0));
215 static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw,
216                        S_IRUGO | S_IWUSR,
217                        ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(1));
218 static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw,
219                        S_IRUGO | S_IWUSR,
220                        ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(2));
221 static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
222                        S_IRUGO | S_IWUSR,
223                        ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(3));
224 static IIO_DEVICE_ATTR(in_voltage4_thresh_both_hyst_raw,
225                        S_IRUGO | S_IWUSR,
226                        ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(4));
227 static IIO_DEVICE_ATTR(in_voltage5_thresh_both_hyst_raw,
228                        S_IRUGO | S_IWUSR,
229                        ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(5));
230 static IIO_DEVICE_ATTR(in_voltage6_thresh_both_hyst_raw,
231                        S_IRUGO | S_IWUSR,
232                        ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(6));
233 static IIO_DEVICE_ATTR(in_voltage7_thresh_both_hyst_raw,
234                        S_IRUGO | S_IWUSR,
235                        ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(7));
236
237 static struct attribute *ad7291_event_attributes[] = {
238         &iio_dev_attr_in_temp0_thresh_both_hyst_raw.dev_attr.attr,
239         &iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
240         &iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
241         &iio_dev_attr_in_voltage2_thresh_both_hyst_raw.dev_attr.attr,
242         &iio_dev_attr_in_voltage3_thresh_both_hyst_raw.dev_attr.attr,
243         &iio_dev_attr_in_voltage4_thresh_both_hyst_raw.dev_attr.attr,
244         &iio_dev_attr_in_voltage5_thresh_both_hyst_raw.dev_attr.attr,
245         &iio_dev_attr_in_voltage6_thresh_both_hyst_raw.dev_attr.attr,
246         &iio_dev_attr_in_voltage7_thresh_both_hyst_raw.dev_attr.attr,
247         NULL,
248 };
249
250 static unsigned int ad7291_threshold_reg(u64 event_code)
251 {
252         unsigned int offset;
253
254         switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
255         case IIO_VOLTAGE:
256                 offset = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
257                 break;
258         case IIO_TEMP:
259                 offset = 8;
260                 break;
261         default:
262             return 0;
263         }
264
265         if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING)
266                 return AD7291_DATA_LOW(offset);
267         else
268                 return AD7291_DATA_HIGH(offset);
269 }
270
271 static int ad7291_read_event_value(struct iio_dev *indio_dev,
272                                    u64 event_code,
273                                    int *val)
274 {
275         struct ad7291_chip_info *chip = iio_priv(indio_dev);
276         int ret;
277         u16 uval;
278         s16 signval;
279
280         ret = ad7291_i2c_read(chip, ad7291_threshold_reg(event_code), &uval);
281         if (ret < 0)
282                 return ret;
283
284         switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
285         case IIO_VOLTAGE:
286                 *val = uval & AD7291_VALUE_MASK;
287                 return 0;
288         case IIO_TEMP:
289                 signval = (s16)((uval & AD7291_VALUE_MASK) << 4) >> 4;
290                 *val = signval;
291                 return 0;
292         default:
293                 return -EINVAL;
294         };
295 }
296
297 static int ad7291_write_event_value(struct iio_dev *indio_dev,
298                                     u64 event_code,
299                                     int val)
300 {
301         struct ad7291_chip_info *chip = iio_priv(indio_dev);
302
303         switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
304         case IIO_VOLTAGE:
305                 if (val > AD7291_VALUE_MASK || val < 0)
306                         return -EINVAL;
307                 break;
308         case IIO_TEMP:
309                 if (val > 2047 || val < -2048)
310                         return -EINVAL;
311                 break;
312         default:
313                 return -EINVAL;
314         }
315
316         return ad7291_i2c_write(chip, ad7291_threshold_reg(event_code), val);
317 }
318
319 static int ad7291_read_event_config(struct iio_dev *indio_dev,
320                                     u64 event_code)
321 {
322         struct ad7291_chip_info *chip = iio_priv(indio_dev);
323         /* To be enabled the channel must simply be on. If any are enabled
324            we are in continuous sampling mode */
325
326         switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
327         case IIO_VOLTAGE:
328                 if (chip->c_mask &
329                     (1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN(event_code))))
330                         return 1;
331                 else
332                         return 0;
333         case IIO_TEMP:
334                 /* always on */
335                 return 1;
336         default:
337                 return -EINVAL;
338         }
339
340 }
341
342 static int ad7291_write_event_config(struct iio_dev *indio_dev,
343                                      u64 event_code,
344                                      int state)
345 {
346         int ret = 0;
347         struct ad7291_chip_info *chip = iio_priv(indio_dev);
348         u16 regval;
349
350         mutex_lock(&chip->state_lock);
351         regval = chip->command;
352         /*
353          * To be enabled the channel must simply be on. If any are enabled
354          * use continuous sampling mode.
355          * Possible to disable temp as well but that makes single read tricky.
356          */
357
358         switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
359         case IIO_VOLTAGE:
360                 if ((!state) && (chip->c_mask & (1 << (15 -
361                                 IIO_EVENT_CODE_EXTRACT_CHAN(event_code)))))
362                         chip->c_mask &= ~(1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN
363                                                         (event_code)));
364                 else if (state && (!(chip->c_mask & (1 << (15 -
365                                 IIO_EVENT_CODE_EXTRACT_CHAN(event_code))))))
366                         chip->c_mask |= (1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN
367                                                         (event_code)));
368                 else
369                         break;
370
371                 regval &= ~AD7291_AUTOCYCLE;
372                 regval |= chip->c_mask;
373                 if (chip->c_mask) /* Enable autocycle? */
374                         regval |= AD7291_AUTOCYCLE;
375
376                 ret = ad7291_i2c_write(chip, AD7291_COMMAND, regval);
377                 if (ret < 0)
378                         goto error_ret;
379
380                 chip->command = regval;
381                 break;
382         default:
383                 ret = -EINVAL;
384         }
385
386 error_ret:
387         mutex_unlock(&chip->state_lock);
388         return ret;
389 }
390
391 static int ad7291_read_raw(struct iio_dev *indio_dev,
392                            struct iio_chan_spec const *chan,
393                            int *val,
394                            int *val2,
395                            long mask)
396 {
397         int ret;
398         struct ad7291_chip_info *chip = iio_priv(indio_dev);
399         u16 regval;
400         s16 signval;
401
402         switch (mask) {
403         case IIO_CHAN_INFO_RAW:
404                 switch (chan->type) {
405                 case IIO_VOLTAGE:
406                         mutex_lock(&chip->state_lock);
407                         /* If in autocycle mode drop through */
408                         if (chip->command & AD7291_AUTOCYCLE) {
409                                 mutex_unlock(&chip->state_lock);
410                                 return -EBUSY;
411                         }
412                         /* Enable this channel alone */
413                         regval = chip->command & (~AD7291_VOLTAGE_MASK);
414                         regval |= 1 << (15 - chan->channel);
415                         ret = ad7291_i2c_write(chip, AD7291_COMMAND, regval);
416                         if (ret < 0) {
417                                 mutex_unlock(&chip->state_lock);
418                                 return ret;
419                         }
420                         /* Read voltage */
421                         ret = i2c_smbus_read_word_swapped(chip->client,
422                                                        AD7291_VOLTAGE);
423                         if (ret < 0) {
424                                 mutex_unlock(&chip->state_lock);
425                                 return ret;
426                         }
427                         *val = ret & AD7291_VALUE_MASK;
428                         mutex_unlock(&chip->state_lock);
429                         return IIO_VAL_INT;
430                 case IIO_TEMP:
431                         /* Assumes tsense bit of command register always set */
432                         ret = i2c_smbus_read_word_swapped(chip->client,
433                                                        AD7291_T_SENSE);
434                         if (ret < 0)
435                                 return ret;
436                         signval = (s16)((ret & AD7291_VALUE_MASK) << 4) >> 4;
437                         *val = signval;
438                         return IIO_VAL_INT;
439                 default:
440                         return -EINVAL;
441                 }
442         case IIO_CHAN_INFO_AVERAGE_RAW:
443                 ret = i2c_smbus_read_word_swapped(chip->client,
444                                                AD7291_T_AVERAGE);
445                         if (ret < 0)
446                                 return ret;
447                         signval = (s16)((ret & AD7291_VALUE_MASK) << 4) >> 4;
448                         *val = signval;
449                         return IIO_VAL_INT;
450         case IIO_CHAN_INFO_SCALE:
451                 switch (chan->type) {
452                 case IIO_VOLTAGE:
453                         *val = chip->int_vref_mv;
454                         *val2 = AD7291_BITS;
455                         return IIO_VAL_FRACTIONAL_LOG2;
456                 case IIO_TEMP:
457                         /*
458                          * One LSB of the ADC corresponds to 0.25 deg C.
459                          * The temperature reading is in 12-bit twos
460                          * complement format
461                          */
462                         *val = 250;
463                         return IIO_VAL_INT;
464                 default:
465                         return -EINVAL;
466                 }
467         default:
468                 return -EINVAL;
469         }
470 }
471
472 #define AD7291_VOLTAGE_CHAN(_chan)                                      \
473 {                                                                       \
474         .type = IIO_VOLTAGE,                                            \
475         .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),                   \
476         .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),           \
477         .indexed = 1,                                                   \
478         .channel = _chan,                                               \
479         .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)|\
480         IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)              \
481 }
482
483 static const struct iio_chan_spec ad7291_channels[] = {
484         AD7291_VOLTAGE_CHAN(0),
485         AD7291_VOLTAGE_CHAN(1),
486         AD7291_VOLTAGE_CHAN(2),
487         AD7291_VOLTAGE_CHAN(3),
488         AD7291_VOLTAGE_CHAN(4),
489         AD7291_VOLTAGE_CHAN(5),
490         AD7291_VOLTAGE_CHAN(6),
491         AD7291_VOLTAGE_CHAN(7),
492         {
493                 .type = IIO_TEMP,
494                 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
495                                 BIT(IIO_CHAN_INFO_AVERAGE_RAW) |
496                                 BIT(IIO_CHAN_INFO_SCALE),
497                 .indexed = 1,
498                 .channel = 0,
499                 .event_mask =
500                 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)|
501                 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)
502         }
503 };
504
505 static struct attribute_group ad7291_event_attribute_group = {
506         .attrs = ad7291_event_attributes,
507 };
508
509 static const struct iio_info ad7291_info = {
510         .read_raw = &ad7291_read_raw,
511         .read_event_config = &ad7291_read_event_config,
512         .write_event_config = &ad7291_write_event_config,
513         .read_event_value = &ad7291_read_event_value,
514         .write_event_value = &ad7291_write_event_value,
515         .event_attrs = &ad7291_event_attribute_group,
516 };
517
518 static int ad7291_probe(struct i2c_client *client,
519                 const struct i2c_device_id *id)
520 {
521         struct ad7291_chip_info *chip;
522         struct iio_dev *indio_dev;
523         int ret = 0, voltage_uv = 0;
524
525         indio_dev = iio_device_alloc(sizeof(*chip));
526         if (indio_dev == NULL) {
527                 ret = -ENOMEM;
528                 goto error_ret;
529         }
530         chip = iio_priv(indio_dev);
531
532         chip->reg = regulator_get(&client->dev, "vcc");
533         if (!IS_ERR(chip->reg)) {
534                 ret = regulator_enable(chip->reg);
535                 if (ret)
536                         goto error_put_reg;
537                 voltage_uv = regulator_get_voltage(chip->reg);
538         }
539
540         mutex_init(&chip->state_lock);
541         /* this is only used for device removal purposes */
542         i2c_set_clientdata(client, indio_dev);
543
544         chip->client = client;
545
546         chip->command = AD7291_NOISE_DELAY |
547                         AD7291_T_SENSE_MASK | /* Tsense always enabled */
548                         AD7291_ALERT_POLARITY; /* set irq polarity low level */
549
550         if (voltage_uv) {
551                 chip->int_vref_mv = voltage_uv / 1000;
552                 chip->command |= AD7291_EXT_REF;
553         } else {
554                 chip->int_vref_mv = 2500; /* Build-in ref */
555         }
556
557         indio_dev->name = id->name;
558         indio_dev->channels = ad7291_channels;
559         indio_dev->num_channels = ARRAY_SIZE(ad7291_channels);
560
561         indio_dev->dev.parent = &client->dev;
562         indio_dev->info = &ad7291_info;
563         indio_dev->modes = INDIO_DIRECT_MODE;
564
565         ret = ad7291_i2c_write(chip, AD7291_COMMAND, AD7291_RESET);
566         if (ret) {
567                 ret = -EIO;
568                 goto error_disable_reg;
569         }
570
571         ret = ad7291_i2c_write(chip, AD7291_COMMAND, chip->command);
572         if (ret) {
573                 ret = -EIO;
574                 goto error_disable_reg;
575         }
576
577         if (client->irq > 0) {
578                 ret = request_threaded_irq(client->irq,
579                                            NULL,
580                                            &ad7291_event_handler,
581                                            IRQF_TRIGGER_LOW | IRQF_ONESHOT,
582                                            id->name,
583                                            indio_dev);
584                 if (ret)
585                         goto error_disable_reg;
586         }
587
588         ret = iio_device_register(indio_dev);
589         if (ret)
590                 goto error_unreg_irq;
591
592         return 0;
593
594 error_unreg_irq:
595         if (client->irq)
596                 free_irq(client->irq, indio_dev);
597 error_disable_reg:
598         if (!IS_ERR(chip->reg))
599                 regulator_disable(chip->reg);
600 error_put_reg:
601         if (!IS_ERR(chip->reg))
602                 regulator_put(chip->reg);
603
604         iio_device_free(indio_dev);
605 error_ret:
606         return ret;
607 }
608
609 static int ad7291_remove(struct i2c_client *client)
610 {
611         struct iio_dev *indio_dev = i2c_get_clientdata(client);
612         struct ad7291_chip_info *chip = iio_priv(indio_dev);
613
614         iio_device_unregister(indio_dev);
615
616         if (client->irq)
617                 free_irq(client->irq, indio_dev);
618
619         if (!IS_ERR(chip->reg)) {
620                 regulator_disable(chip->reg);
621                 regulator_put(chip->reg);
622         }
623
624         iio_device_free(indio_dev);
625
626         return 0;
627 }
628
629 static const struct i2c_device_id ad7291_id[] = {
630         { "ad7291", 0 },
631         {}
632 };
633
634 MODULE_DEVICE_TABLE(i2c, ad7291_id);
635
636 static struct i2c_driver ad7291_driver = {
637         .driver = {
638                 .name = KBUILD_MODNAME,
639         },
640         .probe = ad7291_probe,
641         .remove = ad7291_remove,
642         .id_table = ad7291_id,
643 };
644 module_i2c_driver(ad7291_driver);
645
646 MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
647 MODULE_DESCRIPTION("Analog Devices AD7291 ADC driver");
648 MODULE_LICENSE("GPL v2");