cyttsp_i2c_common.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "cyttsp4_core.h"
  33. int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf,
  34. u16 addr, u8 length, void *values)
  35. {
  36. struct i2c_client *client = to_i2c_client(dev);
  37. u8 client_addr = client->addr | ((addr >> 8) & 0x1);
  38. u8 addr_lo = addr & 0xFF;
  39. struct i2c_msg msgs[] = {
  40. {
  41. .addr = client_addr,
  42. .flags = 0,
  43. .len = 1,
  44. .buf = &addr_lo,
  45. },
  46. {
  47. .addr = client_addr,
  48. .flags = I2C_M_RD,
  49. .len = length,
  50. .buf = values,
  51. },
  52. };
  53. int retval;
  54. retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  55. if (retval < 0)
  56. return retval;
  57. return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
  58. }
  59. EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data);
  60. int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf,
  61. u16 addr, u8 length, const void *values)
  62. {
  63. struct i2c_client *client = to_i2c_client(dev);
  64. u8 client_addr = client->addr | ((addr >> 8) & 0x1);
  65. u8 addr_lo = addr & 0xFF;
  66. struct i2c_msg msgs[] = {
  67. {
  68. .addr = client_addr,
  69. .flags = 0,
  70. .len = length + 1,
  71. .buf = xfer_buf,
  72. },
  73. };
  74. int retval;
  75. xfer_buf[0] = addr_lo;
  76. memcpy(&xfer_buf[1], values, length);
  77. retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  78. if (retval < 0)
  79. return retval;
  80. return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
  81. }
  82. EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data);
  83. MODULE_LICENSE("GPL");
  84. MODULE_AUTHOR("Cypress");