ad7879-i2c.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * AD7879-1/AD7889-1 touchscreen (I2C bus)
  3. *
  4. * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <linux/input.h> /* BUS_I2C */
  9. #include <linux/i2c.h>
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/of.h>
  13. #include <linux/pm.h>
  14. #include <linux/regmap.h>
  15. #include "ad7879.h"
  16. #define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
  17. static const struct regmap_config ad7879_i2c_regmap_config = {
  18. .reg_bits = 8,
  19. .val_bits = 16,
  20. .max_register = 15,
  21. };
  22. static int ad7879_i2c_probe(struct i2c_client *client,
  23. const struct i2c_device_id *id)
  24. {
  25. struct regmap *regmap;
  26. if (!i2c_check_functionality(client->adapter,
  27. I2C_FUNC_SMBUS_WORD_DATA)) {
  28. dev_err(&client->dev, "SMBUS Word Data not Supported\n");
  29. return -EIO;
  30. }
  31. regmap = devm_regmap_init_i2c(client, &ad7879_i2c_regmap_config);
  32. if (IS_ERR(regmap))
  33. return PTR_ERR(regmap);
  34. return ad7879_probe(&client->dev, regmap, client->irq,
  35. BUS_I2C, AD7879_DEVID);
  36. }
  37. static const struct i2c_device_id ad7879_id[] = {
  38. { "ad7879", 0 },
  39. { "ad7889", 0 },
  40. { }
  41. };
  42. MODULE_DEVICE_TABLE(i2c, ad7879_id);
  43. #ifdef CONFIG_OF
  44. static const struct of_device_id ad7879_i2c_dt_ids[] = {
  45. { .compatible = "adi,ad7879-1", },
  46. { }
  47. };
  48. MODULE_DEVICE_TABLE(of, ad7879_i2c_dt_ids);
  49. #endif
  50. static struct i2c_driver ad7879_i2c_driver = {
  51. .driver = {
  52. .name = "ad7879",
  53. .pm = &ad7879_pm_ops,
  54. .of_match_table = of_match_ptr(ad7879_i2c_dt_ids),
  55. },
  56. .probe = ad7879_i2c_probe,
  57. .id_table = ad7879_id,
  58. };
  59. module_i2c_driver(ad7879_i2c_driver);
  60. MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
  61. MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
  62. MODULE_LICENSE("GPL");