ad7879-i2c.c 2.3 KB

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