cyttsp_i2c_common.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * cyttsp_i2c_common.c
  3. * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver.
  4. * For use with Cypress Txx3xx and Txx4xx parts.
  5. * Supported parts include:
  6. * CY8CTST341
  7. * CY8CTMA340
  8. * TMA4XX
  9. * TMA1036
  10. *
  11. * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc.
  12. * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org>
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * version 2, and only version 2, as published by the
  17. * Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
  25. *
  26. */
  27. #include <linux/device.h>
  28. #include <linux/export.h>
  29. #include <linux/i2c.h>
  30. #include <linux/module.h>
  31. #include <linux/types.h>
  32. int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf,
  33. u16 addr, u8 length, void *values)
  34. {
  35. struct i2c_client *client = to_i2c_client(dev);
  36. u8 client_addr = client->addr | ((addr >> 8) & 0x1);
  37. u8 addr_lo = addr & 0xFF;
  38. struct i2c_msg msgs[] = {
  39. {
  40. .addr = client_addr,
  41. .flags = 0,
  42. .len = 1,
  43. .buf = &addr_lo,
  44. },
  45. {
  46. .addr = client_addr,
  47. .flags = I2C_M_RD,
  48. .len = length,
  49. .buf = values,
  50. },
  51. };
  52. int retval;
  53. retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  54. if (retval < 0)
  55. return retval;
  56. return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
  57. }
  58. EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data);
  59. int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf,
  60. u16 addr, u8 length, const void *values)
  61. {
  62. struct i2c_client *client = to_i2c_client(dev);
  63. u8 client_addr = client->addr | ((addr >> 8) & 0x1);
  64. u8 addr_lo = addr & 0xFF;
  65. struct i2c_msg msgs[] = {
  66. {
  67. .addr = client_addr,
  68. .flags = 0,
  69. .len = length + 1,
  70. .buf = xfer_buf,
  71. },
  72. };
  73. int retval;
  74. xfer_buf[0] = addr_lo;
  75. memcpy(&xfer_buf[1], values, length);
  76. retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  77. if (retval < 0)
  78. return retval;
  79. return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
  80. }
  81. EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data);
  82. MODULE_LICENSE("GPL");
  83. MODULE_AUTHOR("Cypress");