ad7879-i2c.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "ad7879.h"
  15. #define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
  16. /* All registers are word-sized.
  17. * AD7879 uses a high-byte first convention.
  18. */
  19. static int ad7879_i2c_read(struct device *dev, u8 reg)
  20. {
  21. struct i2c_client *client = to_i2c_client(dev);
  22. return i2c_smbus_read_word_swapped(client, reg);
  23. }
  24. static int ad7879_i2c_multi_read(struct device *dev,
  25. u8 first_reg, u8 count, u16 *buf)
  26. {
  27. struct i2c_client *client = to_i2c_client(dev);
  28. u8 idx;
  29. i2c_smbus_read_i2c_block_data(client, first_reg, count * 2, (u8 *)buf);
  30. for (idx = 0; idx < count; ++idx)
  31. buf[idx] = swab16(buf[idx]);
  32. return 0;
  33. }
  34. static int ad7879_i2c_write(struct device *dev, u8 reg, u16 val)
  35. {
  36. struct i2c_client *client = to_i2c_client(dev);
  37. return i2c_smbus_write_word_swapped(client, reg, val);
  38. }
  39. static const struct ad7879_bus_ops ad7879_i2c_bus_ops = {
  40. .bustype = BUS_I2C,
  41. .read = ad7879_i2c_read,
  42. .multi_read = ad7879_i2c_multi_read,
  43. .write = ad7879_i2c_write,
  44. };
  45. static int ad7879_i2c_probe(struct i2c_client *client,
  46. const struct i2c_device_id *id)
  47. {
  48. struct ad7879 *ts;
  49. if (!i2c_check_functionality(client->adapter,
  50. I2C_FUNC_SMBUS_WORD_DATA)) {
  51. dev_err(&client->dev, "SMBUS Word Data not Supported\n");
  52. return -EIO;
  53. }
  54. ts = ad7879_probe(&client->dev, AD7879_DEVID, client->irq,
  55. &ad7879_i2c_bus_ops);
  56. if (IS_ERR(ts))
  57. return PTR_ERR(ts);
  58. i2c_set_clientdata(client, ts);
  59. return 0;
  60. }
  61. static int ad7879_i2c_remove(struct i2c_client *client)
  62. {
  63. struct ad7879 *ts = i2c_get_clientdata(client);
  64. ad7879_remove(ts);
  65. return 0;
  66. }
  67. static const struct i2c_device_id ad7879_id[] = {
  68. { "ad7879", 0 },
  69. { "ad7889", 0 },
  70. { }
  71. };
  72. MODULE_DEVICE_TABLE(i2c, ad7879_id);
  73. #ifdef CONFIG_OF
  74. static const struct of_device_id ad7879_i2c_dt_ids[] = {
  75. { .compatible = "adi,ad7879-1", },
  76. { }
  77. };
  78. MODULE_DEVICE_TABLE(of, ad7879_i2c_dt_ids);
  79. #endif
  80. static struct i2c_driver ad7879_i2c_driver = {
  81. .driver = {
  82. .name = "ad7879",
  83. .pm = &ad7879_pm_ops,
  84. .of_match_table = of_match_ptr(ad7879_i2c_dt_ids),
  85. },
  86. .probe = ad7879_i2c_probe,
  87. .remove = ad7879_i2c_remove,
  88. .id_table = ad7879_id,
  89. };
  90. module_i2c_driver(ad7879_i2c_driver);
  91. MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
  92. MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
  93. MODULE_LICENSE("GPL");