1/* 2 * AD7150 capacitive sensor driver supporting AD7150/1/6 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/i2c.h> 14#include <linux/module.h> 15 16#include <linux/iio/iio.h> 17#include <linux/iio/sysfs.h> 18#include <linux/iio/events.h> 19/* 20 * AD7150 registers definition 21 */ 22 23#define AD7150_STATUS 0 24#define AD7150_STATUS_OUT1 (1 << 3) 25#define AD7150_STATUS_OUT2 (1 << 5) 26#define AD7150_CH1_DATA_HIGH 1 27#define AD7150_CH2_DATA_HIGH 3 28#define AD7150_CH1_AVG_HIGH 5 29#define AD7150_CH2_AVG_HIGH 7 30#define AD7150_CH1_SENSITIVITY 9 31#define AD7150_CH1_THR_HOLD_H 9 32#define AD7150_CH1_TIMEOUT 10 33#define AD7150_CH1_SETUP 11 34#define AD7150_CH2_SENSITIVITY 12 35#define AD7150_CH2_THR_HOLD_H 12 36#define AD7150_CH2_TIMEOUT 13 37#define AD7150_CH2_SETUP 14 38#define AD7150_CFG 15 39#define AD7150_CFG_FIX (1 << 7) 40#define AD7150_PD_TIMER 16 41#define AD7150_CH1_CAPDAC 17 42#define AD7150_CH2_CAPDAC 18 43#define AD7150_SN3 19 44#define AD7150_SN2 20 45#define AD7150_SN1 21 46#define AD7150_SN0 22 47#define AD7150_ID 23 48 49/** 50 * struct ad7150_chip_info - instance specific chip data 51 * @client: i2c client for this device 52 * @current_event: device always has one type of event enabled. 53 * This element stores the event code of the current one. 54 * @threshold: thresholds for simple capacitance value events 55 * @thresh_sensitivity: threshold for simple capacitance offset 56 * from 'average' value. 57 * @mag_sensitity: threshold for magnitude of capacitance offset from 58 * from 'average' value. 59 * @thresh_timeout: a timeout, in samples from the moment an 60 * adaptive threshold event occurs to when the average 61 * value jumps to current value. 62 * @mag_timeout: a timeout, in sample from the moment an 63 * adaptive magnitude event occurs to when the average 64 * value jumps to the current value. 65 * @old_state: store state from previous event, allowing confirmation 66 * of new condition. 67 * @conversion_mode: the current conversion mode. 68 * @state_lock: ensure consistent state of this structure wrt the 69 * hardware. 70 */ 71struct ad7150_chip_info { 72 struct i2c_client *client; 73 u64 current_event; 74 u16 threshold[2][2]; 75 u8 thresh_sensitivity[2][2]; 76 u8 mag_sensitivity[2][2]; 77 u8 thresh_timeout[2][2]; 78 u8 mag_timeout[2][2]; 79 int old_state; 80 char *conversion_mode; 81 struct mutex state_lock; 82}; 83 84/* 85 * sysfs nodes 86 */ 87 88static const u8 ad7150_addresses[][6] = { 89 { AD7150_CH1_DATA_HIGH, AD7150_CH1_AVG_HIGH, 90 AD7150_CH1_SETUP, AD7150_CH1_THR_HOLD_H, 91 AD7150_CH1_SENSITIVITY, AD7150_CH1_TIMEOUT }, 92 { AD7150_CH2_DATA_HIGH, AD7150_CH2_AVG_HIGH, 93 AD7150_CH2_SETUP, AD7150_CH2_THR_HOLD_H, 94 AD7150_CH2_SENSITIVITY, AD7150_CH2_TIMEOUT }, 95}; 96 97static int ad7150_read_raw(struct iio_dev *indio_dev, 98 struct iio_chan_spec const *chan, 99 int *val, 100 int *val2, 101 long mask) 102{ 103 int ret; 104 struct ad7150_chip_info *chip = iio_priv(indio_dev); 105 106 switch (mask) { 107 case IIO_CHAN_INFO_RAW: 108 ret = i2c_smbus_read_word_data(chip->client, 109 ad7150_addresses[chan->channel][0]); 110 if (ret < 0) 111 return ret; 112 *val = swab16(ret); 113 return IIO_VAL_INT; 114 case IIO_CHAN_INFO_AVERAGE_RAW: 115 ret = i2c_smbus_read_word_data(chip->client, 116 ad7150_addresses[chan->channel][1]); 117 if (ret < 0) 118 return ret; 119 *val = swab16(ret); 120 return IIO_VAL_INT; 121 default: 122 return -EINVAL; 123 } 124} 125 126static int ad7150_read_event_config(struct iio_dev *indio_dev, 127 const struct iio_chan_spec *chan, enum iio_event_type type, 128 enum iio_event_direction dir) 129{ 130 int ret; 131 u8 threshtype; 132 bool adaptive; 133 struct ad7150_chip_info *chip = iio_priv(indio_dev); 134 135 ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG); 136 if (ret < 0) 137 return ret; 138 139 threshtype = (ret >> 5) & 0x03; 140 adaptive = !!(ret & 0x80); 141 142 switch (type) { 143 case IIO_EV_TYPE_MAG_ADAPTIVE: 144 if (dir == IIO_EV_DIR_RISING) 145 return adaptive && (threshtype == 0x1); 146 return adaptive && (threshtype == 0x0); 147 case IIO_EV_TYPE_THRESH_ADAPTIVE: 148 if (dir == IIO_EV_DIR_RISING) 149 return adaptive && (threshtype == 0x3); 150 return adaptive && (threshtype == 0x2); 151 case IIO_EV_TYPE_THRESH: 152 if (dir == IIO_EV_DIR_RISING) 153 return !adaptive && (threshtype == 0x1); 154 return !adaptive && (threshtype == 0x0); 155 default: 156 break; 157 } 158 return -EINVAL; 159} 160 161/* lock should be held */ 162static int ad7150_write_event_params(struct iio_dev *indio_dev, 163 unsigned int chan, enum iio_event_type type, 164 enum iio_event_direction dir) 165{ 166 int ret; 167 u16 value; 168 u8 sens, timeout; 169 struct ad7150_chip_info *chip = iio_priv(indio_dev); 170 int rising = (dir == IIO_EV_DIR_RISING); 171 u64 event_code; 172 173 event_code = IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, chan, type, dir); 174 175 if (event_code != chip->current_event) 176 return 0; 177 178 switch (type) { 179 /* Note completely different from the adaptive versions */ 180 case IIO_EV_TYPE_THRESH: 181 value = chip->threshold[rising][chan]; 182 ret = i2c_smbus_write_word_data(chip->client, 183 ad7150_addresses[chan][3], 184 swab16(value)); 185 if (ret < 0) 186 return ret; 187 return 0; 188 case IIO_EV_TYPE_MAG_ADAPTIVE: 189 sens = chip->mag_sensitivity[rising][chan]; 190 timeout = chip->mag_timeout[rising][chan]; 191 break; 192 case IIO_EV_TYPE_THRESH_ADAPTIVE: 193 sens = chip->thresh_sensitivity[rising][chan]; 194 timeout = chip->thresh_timeout[rising][chan]; 195 break; 196 default: 197 return -EINVAL; 198 } 199 ret = i2c_smbus_write_byte_data(chip->client, 200 ad7150_addresses[chan][4], 201 sens); 202 if (ret < 0) 203 return ret; 204 205 ret = i2c_smbus_write_byte_data(chip->client, 206 ad7150_addresses[chan][5], 207 timeout); 208 if (ret < 0) 209 return ret; 210 211 return 0; 212} 213 214static int ad7150_write_event_config(struct iio_dev *indio_dev, 215 const struct iio_chan_spec *chan, enum iio_event_type type, 216 enum iio_event_direction dir, int state) 217{ 218 u8 thresh_type, cfg, adaptive; 219 int ret; 220 struct ad7150_chip_info *chip = iio_priv(indio_dev); 221 int rising = (dir == IIO_EV_DIR_RISING); 222 u64 event_code; 223 224 /* Something must always be turned on */ 225 if (state == 0) 226 return -EINVAL; 227 228 event_code = IIO_UNMOD_EVENT_CODE(chan->type, chan->channel, type, dir); 229 if (event_code == chip->current_event) 230 return 0; 231 mutex_lock(&chip->state_lock); 232 ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG); 233 if (ret < 0) 234 goto error_ret; 235 236 cfg = ret & ~((0x03 << 5) | (0x1 << 7)); 237 238 switch (type) { 239 case IIO_EV_TYPE_MAG_ADAPTIVE: 240 adaptive = 1; 241 if (rising) 242 thresh_type = 0x1; 243 else 244 thresh_type = 0x0; 245 break; 246 case IIO_EV_TYPE_THRESH_ADAPTIVE: 247 adaptive = 1; 248 if (rising) 249 thresh_type = 0x3; 250 else 251 thresh_type = 0x2; 252 break; 253 case IIO_EV_TYPE_THRESH: 254 adaptive = 0; 255 if (rising) 256 thresh_type = 0x1; 257 else 258 thresh_type = 0x0; 259 break; 260 default: 261 ret = -EINVAL; 262 goto error_ret; 263 } 264 265 cfg |= (!adaptive << 7) | (thresh_type << 5); 266 267 ret = i2c_smbus_write_byte_data(chip->client, AD7150_CFG, cfg); 268 if (ret < 0) 269 goto error_ret; 270 271 chip->current_event = event_code; 272 273 /* update control attributes */ 274 ret = ad7150_write_event_params(indio_dev, chan->channel, type, dir); 275error_ret: 276 mutex_unlock(&chip->state_lock); 277 278 return 0; 279} 280 281static int ad7150_read_event_value(struct iio_dev *indio_dev, 282 const struct iio_chan_spec *chan, 283 enum iio_event_type type, 284 enum iio_event_direction dir, 285 enum iio_event_info info, 286 int *val, int *val2) 287{ 288 struct ad7150_chip_info *chip = iio_priv(indio_dev); 289 int rising = (dir == IIO_EV_DIR_RISING); 290 291 /* Complex register sharing going on here */ 292 switch (type) { 293 case IIO_EV_TYPE_MAG_ADAPTIVE: 294 *val = chip->mag_sensitivity[rising][chan->channel]; 295 return IIO_VAL_INT; 296 case IIO_EV_TYPE_THRESH_ADAPTIVE: 297 *val = chip->thresh_sensitivity[rising][chan->channel]; 298 return IIO_VAL_INT; 299 case IIO_EV_TYPE_THRESH: 300 *val = chip->threshold[rising][chan->channel]; 301 return IIO_VAL_INT; 302 default: 303 return -EINVAL; 304 } 305} 306 307static int ad7150_write_event_value(struct iio_dev *indio_dev, 308 const struct iio_chan_spec *chan, 309 enum iio_event_type type, 310 enum iio_event_direction dir, 311 enum iio_event_info info, 312 int val, int val2) 313{ 314 int ret; 315 struct ad7150_chip_info *chip = iio_priv(indio_dev); 316 int rising = (dir == IIO_EV_DIR_RISING); 317 318 mutex_lock(&chip->state_lock); 319 switch (type) { 320 case IIO_EV_TYPE_MAG_ADAPTIVE: 321 chip->mag_sensitivity[rising][chan->channel] = val; 322 break; 323 case IIO_EV_TYPE_THRESH_ADAPTIVE: 324 chip->thresh_sensitivity[rising][chan->channel] = val; 325 break; 326 case IIO_EV_TYPE_THRESH: 327 chip->threshold[rising][chan->channel] = val; 328 break; 329 default: 330 ret = -EINVAL; 331 goto error_ret; 332 } 333 334 /* write back if active */ 335 ret = ad7150_write_event_params(indio_dev, chan->channel, type, dir); 336 337error_ret: 338 mutex_unlock(&chip->state_lock); 339 return ret; 340} 341 342static ssize_t ad7150_show_timeout(struct device *dev, 343 struct device_attribute *attr, 344 char *buf) 345{ 346 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 347 struct ad7150_chip_info *chip = iio_priv(indio_dev); 348 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 349 u8 value; 350 351 /* use the event code for consistency reasons */ 352 int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address); 353 int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address) 354 == IIO_EV_DIR_RISING); 355 356 switch (IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address)) { 357 case IIO_EV_TYPE_MAG_ADAPTIVE: 358 value = chip->mag_timeout[rising][chan]; 359 break; 360 case IIO_EV_TYPE_THRESH_ADAPTIVE: 361 value = chip->thresh_timeout[rising][chan]; 362 break; 363 default: 364 return -EINVAL; 365 } 366 367 return sprintf(buf, "%d\n", value); 368} 369 370static ssize_t ad7150_store_timeout(struct device *dev, 371 struct device_attribute *attr, 372 const char *buf, 373 size_t len) 374{ 375 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 376 struct ad7150_chip_info *chip = iio_priv(indio_dev); 377 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 378 int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address); 379 enum iio_event_direction dir; 380 enum iio_event_type type; 381 int rising; 382 u8 data; 383 int ret; 384 385 type = IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address); 386 dir = IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address); 387 rising = (dir == IIO_EV_DIR_RISING); 388 389 ret = kstrtou8(buf, 10, &data); 390 if (ret < 0) 391 return ret; 392 393 mutex_lock(&chip->state_lock); 394 switch (type) { 395 case IIO_EV_TYPE_MAG_ADAPTIVE: 396 chip->mag_timeout[rising][chan] = data; 397 break; 398 case IIO_EV_TYPE_THRESH_ADAPTIVE: 399 chip->thresh_timeout[rising][chan] = data; 400 break; 401 default: 402 ret = -EINVAL; 403 goto error_ret; 404 } 405 406 ret = ad7150_write_event_params(indio_dev, chan, type, dir); 407error_ret: 408 mutex_unlock(&chip->state_lock); 409 410 if (ret < 0) 411 return ret; 412 413 return len; 414} 415 416#define AD7150_TIMEOUT(chan, type, dir, ev_type, ev_dir) \ 417 IIO_DEVICE_ATTR(in_capacitance##chan##_##type##_##dir##_timeout, \ 418 S_IRUGO | S_IWUSR, \ 419 &ad7150_show_timeout, \ 420 &ad7150_store_timeout, \ 421 IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, \ 422 chan, \ 423 IIO_EV_TYPE_##ev_type, \ 424 IIO_EV_DIR_##ev_dir)) 425static AD7150_TIMEOUT(0, mag_adaptive, rising, MAG_ADAPTIVE, RISING); 426static AD7150_TIMEOUT(0, mag_adaptive, falling, MAG_ADAPTIVE, FALLING); 427static AD7150_TIMEOUT(1, mag_adaptive, rising, MAG_ADAPTIVE, RISING); 428static AD7150_TIMEOUT(1, mag_adaptive, falling, MAG_ADAPTIVE, FALLING); 429static AD7150_TIMEOUT(0, thresh_adaptive, rising, THRESH_ADAPTIVE, RISING); 430static AD7150_TIMEOUT(0, thresh_adaptive, falling, THRESH_ADAPTIVE, FALLING); 431static AD7150_TIMEOUT(1, thresh_adaptive, rising, THRESH_ADAPTIVE, RISING); 432static AD7150_TIMEOUT(1, thresh_adaptive, falling, THRESH_ADAPTIVE, FALLING); 433 434static const struct iio_event_spec ad7150_events[] = { 435 { 436 .type = IIO_EV_TYPE_THRESH, 437 .dir = IIO_EV_DIR_RISING, 438 .mask_separate = BIT(IIO_EV_INFO_VALUE) | 439 BIT(IIO_EV_INFO_ENABLE), 440 }, { 441 .type = IIO_EV_TYPE_THRESH, 442 .dir = IIO_EV_DIR_FALLING, 443 .mask_separate = BIT(IIO_EV_INFO_VALUE) | 444 BIT(IIO_EV_INFO_ENABLE), 445 }, { 446 .type = IIO_EV_TYPE_THRESH_ADAPTIVE, 447 .dir = IIO_EV_DIR_RISING, 448 .mask_separate = BIT(IIO_EV_INFO_VALUE) | 449 BIT(IIO_EV_INFO_ENABLE), 450 }, { 451 .type = IIO_EV_TYPE_THRESH_ADAPTIVE, 452 .dir = IIO_EV_DIR_FALLING, 453 .mask_separate = BIT(IIO_EV_INFO_VALUE) | 454 BIT(IIO_EV_INFO_ENABLE), 455 }, { 456 .type = IIO_EV_TYPE_MAG_ADAPTIVE, 457 .dir = IIO_EV_DIR_RISING, 458 .mask_separate = BIT(IIO_EV_INFO_VALUE) | 459 BIT(IIO_EV_INFO_ENABLE), 460 }, { 461 .type = IIO_EV_TYPE_MAG_ADAPTIVE, 462 .dir = IIO_EV_DIR_FALLING, 463 .mask_separate = BIT(IIO_EV_INFO_VALUE) | 464 BIT(IIO_EV_INFO_ENABLE), 465 }, 466}; 467 468static const struct iio_chan_spec ad7150_channels[] = { 469 { 470 .type = IIO_CAPACITANCE, 471 .indexed = 1, 472 .channel = 0, 473 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 474 BIT(IIO_CHAN_INFO_AVERAGE_RAW), 475 .event_spec = ad7150_events, 476 .num_event_specs = ARRAY_SIZE(ad7150_events), 477 }, { 478 .type = IIO_CAPACITANCE, 479 .indexed = 1, 480 .channel = 1, 481 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 482 BIT(IIO_CHAN_INFO_AVERAGE_RAW), 483 .event_spec = ad7150_events, 484 .num_event_specs = ARRAY_SIZE(ad7150_events), 485 }, 486}; 487 488/* 489 * threshold events 490 */ 491 492static irqreturn_t ad7150_event_handler(int irq, void *private) 493{ 494 struct iio_dev *indio_dev = private; 495 struct ad7150_chip_info *chip = iio_priv(indio_dev); 496 u8 int_status; 497 s64 timestamp = iio_get_time_ns(); 498 int ret; 499 500 ret = i2c_smbus_read_byte_data(chip->client, AD7150_STATUS); 501 if (ret < 0) 502 return IRQ_HANDLED; 503 504 int_status = ret; 505 506 if ((int_status & AD7150_STATUS_OUT1) && 507 !(chip->old_state & AD7150_STATUS_OUT1)) 508 iio_push_event(indio_dev, 509 IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, 510 0, 511 IIO_EV_TYPE_THRESH, 512 IIO_EV_DIR_RISING), 513 timestamp); 514 else if ((!(int_status & AD7150_STATUS_OUT1)) && 515 (chip->old_state & AD7150_STATUS_OUT1)) 516 iio_push_event(indio_dev, 517 IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, 518 0, 519 IIO_EV_TYPE_THRESH, 520 IIO_EV_DIR_FALLING), 521 timestamp); 522 523 if ((int_status & AD7150_STATUS_OUT2) && 524 !(chip->old_state & AD7150_STATUS_OUT2)) 525 iio_push_event(indio_dev, 526 IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, 527 1, 528 IIO_EV_TYPE_THRESH, 529 IIO_EV_DIR_RISING), 530 timestamp); 531 else if ((!(int_status & AD7150_STATUS_OUT2)) && 532 (chip->old_state & AD7150_STATUS_OUT2)) 533 iio_push_event(indio_dev, 534 IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, 535 1, 536 IIO_EV_TYPE_THRESH, 537 IIO_EV_DIR_FALLING), 538 timestamp); 539 /* store the status to avoid repushing same events */ 540 chip->old_state = int_status; 541 542 return IRQ_HANDLED; 543} 544 545/* Timeouts not currently handled by core */ 546static struct attribute *ad7150_event_attributes[] = { 547 &iio_dev_attr_in_capacitance0_mag_adaptive_rising_timeout 548 .dev_attr.attr, 549 &iio_dev_attr_in_capacitance0_mag_adaptive_falling_timeout 550 .dev_attr.attr, 551 &iio_dev_attr_in_capacitance1_mag_adaptive_rising_timeout 552 .dev_attr.attr, 553 &iio_dev_attr_in_capacitance1_mag_adaptive_falling_timeout 554 .dev_attr.attr, 555 &iio_dev_attr_in_capacitance0_thresh_adaptive_rising_timeout 556 .dev_attr.attr, 557 &iio_dev_attr_in_capacitance0_thresh_adaptive_falling_timeout 558 .dev_attr.attr, 559 &iio_dev_attr_in_capacitance1_thresh_adaptive_rising_timeout 560 .dev_attr.attr, 561 &iio_dev_attr_in_capacitance1_thresh_adaptive_falling_timeout 562 .dev_attr.attr, 563 NULL, 564}; 565 566static struct attribute_group ad7150_event_attribute_group = { 567 .attrs = ad7150_event_attributes, 568 .name = "events", 569}; 570 571static const struct iio_info ad7150_info = { 572 .event_attrs = &ad7150_event_attribute_group, 573 .driver_module = THIS_MODULE, 574 .read_raw = &ad7150_read_raw, 575 .read_event_config = &ad7150_read_event_config, 576 .write_event_config = &ad7150_write_event_config, 577 .read_event_value = &ad7150_read_event_value, 578 .write_event_value = &ad7150_write_event_value, 579}; 580 581/* 582 * device probe and remove 583 */ 584 585static int ad7150_probe(struct i2c_client *client, 586 const struct i2c_device_id *id) 587{ 588 int ret; 589 struct ad7150_chip_info *chip; 590 struct iio_dev *indio_dev; 591 592 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); 593 if (!indio_dev) 594 return -ENOMEM; 595 chip = iio_priv(indio_dev); 596 mutex_init(&chip->state_lock); 597 /* this is only used for device removal purposes */ 598 i2c_set_clientdata(client, indio_dev); 599 600 chip->client = client; 601 602 indio_dev->name = id->name; 603 indio_dev->channels = ad7150_channels; 604 indio_dev->num_channels = ARRAY_SIZE(ad7150_channels); 605 /* Establish that the iio_dev is a child of the i2c device */ 606 indio_dev->dev.parent = &client->dev; 607 608 indio_dev->info = &ad7150_info; 609 610 indio_dev->modes = INDIO_DIRECT_MODE; 611 612 if (client->irq) { 613 ret = devm_request_threaded_irq(&client->dev, client->irq, 614 NULL, 615 &ad7150_event_handler, 616 IRQF_TRIGGER_RISING | 617 IRQF_TRIGGER_FALLING | 618 IRQF_ONESHOT, 619 "ad7150_irq1", 620 indio_dev); 621 if (ret) 622 return ret; 623 } 624 625 if (client->dev.platform_data) { 626 ret = devm_request_threaded_irq(&client->dev, *(unsigned int *) 627 client->dev.platform_data, 628 NULL, 629 &ad7150_event_handler, 630 IRQF_TRIGGER_RISING | 631 IRQF_TRIGGER_FALLING | 632 IRQF_ONESHOT, 633 "ad7150_irq2", 634 indio_dev); 635 if (ret) 636 return ret; 637 } 638 639 ret = iio_device_register(indio_dev); 640 if (ret) 641 return ret; 642 643 dev_info(&client->dev, "%s capacitive sensor registered,irq: %d\n", 644 id->name, client->irq); 645 646 return 0; 647} 648 649static int ad7150_remove(struct i2c_client *client) 650{ 651 struct iio_dev *indio_dev = i2c_get_clientdata(client); 652 653 iio_device_unregister(indio_dev); 654 655 return 0; 656} 657 658static const struct i2c_device_id ad7150_id[] = { 659 { "ad7150", 0 }, 660 { "ad7151", 0 }, 661 { "ad7156", 0 }, 662 {} 663}; 664 665MODULE_DEVICE_TABLE(i2c, ad7150_id); 666 667static struct i2c_driver ad7150_driver = { 668 .driver = { 669 .name = "ad7150", 670 }, 671 .probe = ad7150_probe, 672 .remove = ad7150_remove, 673 .id_table = ad7150_id, 674}; 675module_i2c_driver(ad7150_driver); 676 677MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); 678MODULE_DESCRIPTION("Analog Devices AD7150/1/6 capacitive sensor driver"); 679MODULE_LICENSE("GPL v2"); 680