raydium.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * linux/drivers/input/touchscreen/raydium.c
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. */
  9. #include <mach/gpio.h>
  10. #include <linux/delay.h>
  11. #include <linux/i2c.h>
  12. #include <linux/capts.h>
  13. #define DRIVER_NAME "raydium"
  14. #define DRIVER_VERSION "1"
  15. #define RAYDIUM_CMD_START 0
  16. #define RAYDIUM_PACKET_SIZE 8
  17. #define raydium_debug_info// printk
  18. #define buf_to_short(buf) ((*buf << 8) | *(buf+1))
  19. int raydium_reset(struct device *dev);
  20. int raydium_calibration(struct device *dev);
  21. int raydium_get_event (struct device *dev, struct ts_event *event);
  22. struct ts_chip raydium_chip = {
  23. .name = DRIVER_NAME,
  24. .version = DRIVER_VERSION,
  25. .reset = raydium_reset,
  26. .calibration = raydium_calibration,
  27. .get_event = raydium_get_event,
  28. };
  29. static int raydium_write_block(struct i2c_client *client, u8 addr, u8 *buf, int len)
  30. {
  31. struct i2c_msg msg[2] = {
  32. [0] = {
  33. .addr = client->addr,
  34. .flags = client->flags,
  35. .len = 1,
  36. .buf = &addr
  37. },
  38. [1] = {
  39. .addr = client->addr,
  40. .flags = client->flags | I2C_M_NOSTART,
  41. .len = len,
  42. .buf = buf
  43. },
  44. };
  45. int msg_num = (buf && len) ? ARRAY_SIZE(msg) : 1;
  46. return i2c_transfer(client->adapter, msg, msg_num);
  47. }
  48. static int raydium_read_block(struct i2c_client *client, u8 addr, u8 *buf, int len)
  49. {
  50. struct i2c_msg msg[2] = {
  51. [0] = {
  52. .addr = client->addr,
  53. .flags = client->flags,
  54. .len = 1,
  55. .buf = &addr
  56. },
  57. [1] = {
  58. .addr = client->addr,
  59. .flags = client->flags | I2C_M_RD,
  60. .len = len,
  61. .buf = buf
  62. },
  63. };
  64. return i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
  65. }
  66. int raydium_reset(struct device *dev)
  67. {
  68. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  69. struct ts_platform_data *pdata = dev->platform_data;
  70. if (pdata->data) {
  71. int reset_gpio = (int)pdata->data - 1;
  72. gpio_direction_output(reset_gpio, 0);
  73. msleep(20);
  74. gpio_direction_output(reset_gpio, 1);
  75. msleep(20);
  76. }
  77. return 0;
  78. }
  79. int raydium_calibration(struct device *dev)
  80. {
  81. int ret = -1;
  82. char buf=0x03;
  83. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  84. ret = raydium_write_block(client,0x78,&buf,1);
  85. mdelay(500);
  86. return ret;
  87. }
  88. int raydium_get_event (struct device *dev, struct ts_event *event)
  89. {
  90. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  91. struct ts_platform_data *pdata = dev->platform_data;
  92. struct ts_info *info = &pdata->info;
  93. u8 buf[RAYDIUM_PACKET_SIZE];
  94. int event_num;
  95. int i, ba;
  96. memset(buf, 0, ARRAY_SIZE(buf));
  97. if (raydium_read_block(client, RAYDIUM_CMD_START,
  98. buf, RAYDIUM_PACKET_SIZE) < 0) {
  99. /* i2c read failed */
  100. raydium_debug_info("raydium read i2c failed!\n");
  101. return -1;
  102. }
  103. raydium_debug_info("org data =%d, %d, %d, %d, ", buf[0], buf[1], buf[2], buf[3]);
  104. raydium_debug_info("%d, %d, %d, %d\n", buf[4], buf[5], buf[6], buf[7]);
  105. event_num = 0;
  106. for (i=0; i<2; i++) {
  107. ba = i*4;
  108. event->x = (buf[ba+1] << 8) | buf[ba];
  109. event->y = (buf[ba+3] << 8) | buf[ba+2];
  110. if (info->swap_xy) {
  111. swap(event->x, event->y);
  112. }
  113. if (info->x_pol) {
  114. event->x = info->xmax + info->xmin - event->x;
  115. }
  116. if (info->y_pol) {
  117. event->y = info->ymax + info->ymin - event->y;
  118. }
  119. if (event->x || event->y) {
  120. event->z = 1;
  121. event->w = 1;
  122. event++;
  123. event_num++;
  124. }
  125. }
  126. return event_num;
  127. }
  128. static int raydium_probe(struct i2c_client *client, const struct i2c_device_id *id)
  129. {
  130. int ret;
  131. ret = capts_probe(&client->dev, &raydium_chip);
  132. if(ret == 0)
  133. raydium_calibration(&client->dev);
  134. return ret;
  135. }
  136. static int raydium_remove(struct i2c_client *client)
  137. {
  138. return capts_remove(&client->dev);
  139. }
  140. static int raydium_suspend(struct i2c_client *client, pm_message_t msg)
  141. {
  142. return capts_suspend(&client->dev, msg);
  143. }
  144. static int raydium_resume(struct i2c_client *client)
  145. {
  146. return capts_resume(&client->dev);
  147. }
  148. static const struct i2c_device_id raydium_ids[] = {
  149. { DRIVER_NAME, 0 },
  150. { }
  151. };
  152. MODULE_DEVICE_TABLE(i2c, raydium_ids);
  153. static struct i2c_driver raydium_driver = {
  154. .driver = {
  155. .name = DRIVER_NAME,
  156. .owner = THIS_MODULE,
  157. },
  158. .probe = raydium_probe,
  159. .remove = raydium_remove,
  160. .suspend = raydium_suspend,
  161. .resume = raydium_resume,
  162. .id_table = raydium_ids,
  163. };
  164. static int __init raydium_init(void)
  165. {
  166. return i2c_add_driver(&raydium_driver);
  167. }
  168. static void __exit raydium_exit(void)
  169. {
  170. i2c_del_driver(&raydium_driver);
  171. }
  172. module_init(raydium_init);
  173. module_exit(raydium_exit);
  174. MODULE_AUTHOR("");
  175. MODULE_DESCRIPTION("raydium capacitive touch screen driver");
  176. MODULE_LICENSE("GPL v2");
  177. MODULE_VERSION(DRIVER_VERSION);