cyttsp_i2c.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Source for:
  3. * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver.
  4. * For use with Cypress Txx3xx parts.
  5. * Supported parts include:
  6. * CY8CTST341
  7. * CY8CTMA340
  8. *
  9. * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc.
  10. * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org>
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * version 2, and only version 2, as published by the
  15. * Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  25. *
  26. * Contact Cypress Semiconductor at www.cypress.com <kev@cypress.com>
  27. *
  28. */
  29. #include "cyttsp_core.h"
  30. #include <linux/i2c.h>
  31. #include <linux/input.h>
  32. #define CY_I2C_DATA_SIZE 128
  33. static int cyttsp_i2c_read_block_data(struct cyttsp *ts,
  34. u8 addr, u8 length, void *values)
  35. {
  36. struct i2c_client *client = to_i2c_client(ts->dev);
  37. struct i2c_msg msgs[] = {
  38. {
  39. .addr = client->addr,
  40. .flags = 0,
  41. .len = 1,
  42. .buf = &addr,
  43. },
  44. {
  45. .addr = client->addr,
  46. .flags = I2C_M_RD,
  47. .len = length,
  48. .buf = values,
  49. },
  50. };
  51. int retval;
  52. retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  53. if (retval < 0)
  54. return retval;
  55. return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
  56. }
  57. static int cyttsp_i2c_write_block_data(struct cyttsp *ts,
  58. u8 addr, u8 length, const void *values)
  59. {
  60. struct i2c_client *client = to_i2c_client(ts->dev);
  61. int retval;
  62. ts->xfer_buf[0] = addr;
  63. memcpy(&ts->xfer_buf[1], values, length);
  64. retval = i2c_master_send(client, ts->xfer_buf, length + 1);
  65. return retval < 0 ? retval : 0;
  66. }
  67. static const struct cyttsp_bus_ops cyttsp_i2c_bus_ops = {
  68. .bustype = BUS_I2C,
  69. .write = cyttsp_i2c_write_block_data,
  70. .read = cyttsp_i2c_read_block_data,
  71. };
  72. static int __devinit cyttsp_i2c_probe(struct i2c_client *client,
  73. const struct i2c_device_id *id)
  74. {
  75. struct cyttsp *ts;
  76. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  77. dev_err(&client->dev, "I2C functionality not Supported\n");
  78. return -EIO;
  79. }
  80. ts = cyttsp_probe(&cyttsp_i2c_bus_ops, &client->dev, client->irq,
  81. CY_I2C_DATA_SIZE);
  82. if (IS_ERR(ts))
  83. return PTR_ERR(ts);
  84. i2c_set_clientdata(client, ts);
  85. return 0;
  86. }
  87. static int __devexit cyttsp_i2c_remove(struct i2c_client *client)
  88. {
  89. struct cyttsp *ts = i2c_get_clientdata(client);
  90. cyttsp_remove(ts);
  91. return 0;
  92. }
  93. static const struct i2c_device_id cyttsp_i2c_id[] = {
  94. { CY_I2C_NAME, 0 },
  95. { }
  96. };
  97. MODULE_DEVICE_TABLE(i2c, cyttsp_i2c_id);
  98. static struct i2c_driver cyttsp_i2c_driver = {
  99. .driver = {
  100. .name = CY_I2C_NAME,
  101. .owner = THIS_MODULE,
  102. .pm = &cyttsp_pm_ops,
  103. },
  104. .probe = cyttsp_i2c_probe,
  105. .remove = __devexit_p(cyttsp_i2c_remove),
  106. .id_table = cyttsp_i2c_id,
  107. };
  108. module_i2c_driver(cyttsp_i2c_driver);
  109. MODULE_LICENSE("GPL");
  110. MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard Product (TTSP) I2C driver");
  111. MODULE_AUTHOR("Cypress");
  112. MODULE_ALIAS("i2c:cyttsp");