ad7879-i2c.c 1.7 KB

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