gt9xx_driver.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891
  1. #include "tpd.h"
  2. #define GUP_FW_INFO
  3. #include "tpd_custom_gt9xx.h"
  4. #include <mt_boot_common.h>
  5. #ifdef TPD_PROXIMITY
  6. #include <linux/hwmsensor.h>
  7. #include <linux/hwmsen_dev.h>
  8. #include <linux/sensors_io.h>
  9. #endif
  10. /* #include <linux/mmprofile.h> */
  11. #include <linux/device.h>
  12. #include <linux/proc_fs.h> /*proc */
  13. #include <linux/gpio.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/of_device.h>
  17. #include <linux/of_gpio.h>
  18. #include <linux/of_irq.h>
  19. #define USE_REGULATOR_FRAMEWORK
  20. /* extern struct tpd_device *tpd; */
  21. /* #ifdef VELOCITY_CUSTOM */
  22. /* extern int tpd_v_magnify_x; */
  23. /* extern int tpd_v_magnify_y; */
  24. /* #endif */
  25. static int tpd_flag;
  26. static int tpd_halt;
  27. static int tpd_eint_mode = 1;
  28. static int tpd_polling_time = 50;
  29. static DECLARE_WAIT_QUEUE_HEAD(waiter);
  30. static DEFINE_MUTEX(i2c_access);
  31. unsigned int tpd_rst_gpio_number = 0;
  32. unsigned int tpd_int_gpio_number = 0;
  33. #ifdef TPD_HAVE_BUTTON
  34. static int tpd_keys_local[TPD_KEY_COUNT] = TPD_KEYS;
  35. static int tpd_keys_dim_local[TPD_KEY_COUNT][4] = TPD_KEYS_DIM;
  36. #endif
  37. #if GTP_HAVE_TOUCH_KEY
  38. const u16 touch_key_array[] = TPD_KEYS;
  39. /* #define GTP_MAX_KEY_NUM ( sizeof( touch_key_array )/sizeof( touch_key_array[0] ) ) */
  40. struct touch_virtual_key_map_t {
  41. int point_x;
  42. int point_y;
  43. };
  44. static struct touch_virtual_key_map_t touch_key_point_maping_array[] = GTP_KEY_MAP_ARRAY;
  45. #endif
  46. unsigned int touch_irq = 0;
  47. #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
  48. static int tpd_wb_start_local[TPD_WARP_CNT] = TPD_WARP_START;
  49. static int tpd_wb_end_local[TPD_WARP_CNT] = TPD_WARP_END;
  50. #endif
  51. #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
  52. /* static int tpd_calmat_local[8] = TPD_CALIBRATION_MATRIX; */
  53. /* static int tpd_def_calmat_local[8] = TPD_CALIBRATION_MATRIX; */
  54. static int tpd_def_calmat_local_normal[8] = TPD_CALIBRATION_MATRIX_ROTATION_NORMAL;
  55. static int tpd_def_calmat_local_factory[8] = TPD_CALIBRATION_MATRIX_ROTATION_FACTORY;
  56. #endif
  57. /* s32 gtp_send_cfg(struct i2c_client *client); */
  58. static irqreturn_t tpd_interrupt_handler(int irq, void *dev_id);
  59. static int touch_event_handler(void *unused);
  60. static int tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id);
  61. static int tpd_i2c_detect(struct i2c_client *client, struct i2c_board_info *info);
  62. static int tpd_i2c_remove(struct i2c_client *client);
  63. static void tpd_on(void);
  64. static void tpd_off(void);
  65. #if GTP_CREATE_WR_NODE
  66. /* extern s32 init_wr_node(struct i2c_client *); */
  67. /* extern void uninit_wr_node(void); */
  68. #endif
  69. #ifdef GTP_CHARGER_DETECT
  70. /* extern bool upmu_get_pchr_chrdet(void); */
  71. #define TPD_CHARGER_CHECK_CIRCLE 50
  72. static struct delayed_work gtp_charger_check_work;
  73. static struct workqueue_struct *gtp_charger_check_workqueue;
  74. static void gtp_charger_check_func(struct work_struct *);
  75. static u8 gtp_charger_mode;
  76. #endif
  77. #if GTP_ESD_PROTECT
  78. #define TPD_ESD_CHECK_CIRCLE 2000
  79. static struct delayed_work gtp_esd_check_work;
  80. static struct workqueue_struct *gtp_esd_check_workqueue;
  81. static void gtp_esd_check_func(struct work_struct *);
  82. #endif
  83. #ifdef TPD_PROXIMITY
  84. #define TPD_PROXIMITY_VALID_REG 0x814E
  85. #define TPD_PROXIMITY_ENABLE_REG 0x8042
  86. static u8 tpd_proximity_flag;
  87. static u8 tpd_proximity_detect = 1; /* 0-->close ; 1--> far away */
  88. #endif
  89. #ifndef GTP_REG_REFRESH_RATE
  90. #define GTP_REG_REFRESH_RATE 0x8056
  91. #endif
  92. u32 gtp_eint_trigger_type = IRQF_TRIGGER_FALLING;
  93. struct i2c_client *i2c_client_point = NULL;
  94. static const struct i2c_device_id tpd_i2c_id[] = { {"gt9xx", 0}, {} };
  95. static unsigned short force[] = { 0, 0xBA, I2C_CLIENT_END, I2C_CLIENT_END };
  96. static const unsigned short *const forces[] = { force, NULL };
  97. /* static struct i2c_client_address_data addr_data = { .forces = forces,}; */
  98. static const struct of_device_id gt9xx_dt_match[] = {
  99. {.compatible = "mediatek,cap_touch"},
  100. {},
  101. };
  102. MODULE_DEVICE_TABLE(of, gt9xx_dt_match);
  103. static struct i2c_driver tpd_i2c_driver = {
  104. .driver = {
  105. .of_match_table = of_match_ptr(gt9xx_dt_match),
  106. },
  107. .probe = tpd_i2c_probe,
  108. .remove = tpd_i2c_remove,
  109. .detect = tpd_i2c_detect,
  110. .driver.name = "gt9xx",
  111. .id_table = tpd_i2c_id,
  112. .address_list = (const unsigned short *)forces,
  113. };
  114. #ifdef CONFIG_OF
  115. static int of_get_gt9xx_platform_data(struct device *dev)
  116. {
  117. /*int ret, num;*/
  118. if (dev->of_node) {
  119. const struct of_device_id *match;
  120. match = of_match_device(of_match_ptr(gt9xx_dt_match), dev);
  121. if (!match) {
  122. GTP_ERROR("Error: No device match found\n");
  123. return -ENODEV;
  124. }
  125. }
  126. tpd_rst_gpio_number = of_get_named_gpio(dev->of_node, "rst-gpio", 0);
  127. tpd_int_gpio_number = of_get_named_gpio(dev->of_node, "int-gpio", 0);
  128. /*ret = of_property_read_u32(dev->of_node, "rst-gpio", &num);
  129. if (!ret)
  130. tpd_rst_gpio_number = num;
  131. ret = of_property_read_u32(dev->of_node, "int-gpio", &num);
  132. if (!ret)
  133. tpd_int_gpio_number = num;
  134. */
  135. GTP_ERROR("g_vproc_en_gpio_number %d\n", tpd_rst_gpio_number);
  136. GTP_ERROR("g_vproc_vsel_gpio_number %d\n", tpd_int_gpio_number);
  137. return 0;
  138. }
  139. #else
  140. static int of_get_gt9xx_platform_data(struct device *dev)
  141. {
  142. return 0;
  143. }
  144. #endif
  145. static u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]
  146. = { GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff };
  147. #ifdef GTP_CHARGER_DETECT
  148. static u8 config_charger[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]
  149. = { GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff };
  150. #endif
  151. #pragma pack(1)
  152. struct st_tpd_info {
  153. u16 pid; /* product id */
  154. u16 vid; /* version id */
  155. };
  156. #pragma pack()
  157. struct st_tpd_info tpd_info;
  158. u8 int_type = 0;
  159. u32 abs_x_max = 0;
  160. u32 abs_y_max = 0;
  161. u8 gtp_rawdiff_mode = 0;
  162. u8 cfg_len = 0;
  163. /* proc file system */
  164. /* s32 i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *rxbuf, int len); */
  165. /* s32 i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *txbuf, int len); */
  166. static struct proc_dir_entry *gt91xx_config_proc;
  167. /*******************************************************
  168. Function:
  169. Write refresh rate
  170. Input:
  171. rate: refresh rate N (Duration=5+N ms, N=0~15)
  172. Output:
  173. Executive outcomes.0---succeed.
  174. *******************************************************/
  175. static u8 gtp_set_refresh_rate(u8 rate)
  176. {
  177. u8 buf[3] = { GTP_REG_REFRESH_RATE >> 8, GTP_REG_REFRESH_RATE & 0xff, rate };
  178. if (rate > 0xf) {
  179. GTP_ERROR("Refresh rate is over range (%d)", rate);
  180. return FAIL;
  181. }
  182. GTP_INFO("Refresh rate change to %d", rate);
  183. return gtp_i2c_write(i2c_client_point, buf, sizeof(buf));
  184. }
  185. /*******************************************************
  186. Function:
  187. Get refresh rate
  188. Output:
  189. Refresh rate or error code
  190. *******************************************************/
  191. static u8 gtp_get_refresh_rate(void)
  192. {
  193. int ret;
  194. u8 buf[3] = { GTP_REG_REFRESH_RATE >> 8, GTP_REG_REFRESH_RATE & 0xff };
  195. ret = gtp_i2c_read(i2c_client_point, buf, sizeof(buf));
  196. if (ret < 0)
  197. return ret;
  198. GTP_INFO("Refresh rate is %d", buf[GTP_ADDR_LENGTH]);
  199. return buf[GTP_ADDR_LENGTH];
  200. }
  201. /* ============================================================= */
  202. static ssize_t show_refresh_rate(struct device *dev, struct device_attribute *attr, char *buf)
  203. {
  204. int ret = gtp_get_refresh_rate();
  205. if (ret < 0)
  206. return 0;
  207. else
  208. return sprintf(buf, "%d\n", ret);
  209. }
  210. static ssize_t store_refresh_rate(struct device *dev, struct device_attribute *attr,
  211. const char *buf, size_t size)
  212. {
  213. unsigned long rate;
  214. gtp_set_refresh_rate(kstrtoul(buf, 16, &rate));
  215. return size;
  216. }
  217. static DEVICE_ATTR(tpd_refresh_rate, 0664, show_refresh_rate, store_refresh_rate);
  218. static struct device_attribute *gt9xx_attrs[] = {
  219. &dev_attr_tpd_refresh_rate,
  220. };
  221. /* ============================================================= */
  222. static int tpd_i2c_detect(struct i2c_client *client, struct i2c_board_info *info)
  223. {
  224. strcpy(info->type, "mtk-tpd");
  225. return 0;
  226. }
  227. #ifdef TPD_PROXIMITY
  228. static s32 tpd_get_ps_value(void)
  229. {
  230. return tpd_proximity_detect;
  231. }
  232. static s32 tpd_enable_ps(s32 enable)
  233. {
  234. u8 state;
  235. s32 ret = -1;
  236. if (enable) {
  237. state = 1;
  238. tpd_proximity_flag = 1;
  239. GTP_INFO("TPD proximity function to be on.");
  240. } else {
  241. state = 0;
  242. tpd_proximity_flag = 0;
  243. GTP_INFO("TPD proximity function to be off.");
  244. }
  245. ret = i2c_write_bytes(i2c_client_point, TPD_PROXIMITY_ENABLE_REG, &state, 1);
  246. if (ret < 0) {
  247. GTP_ERROR("TPD %s proximity cmd failed.", state ? "enable" : "disable");
  248. return ret;
  249. }
  250. GTP_INFO("TPD proximity function %s success.", state ? "enable" : "disable");
  251. return 0;
  252. }
  253. s32 tpd_ps_operate(void *self, u32 command, void *buff_in, s32 size_in,
  254. void *buff_out, s32 size_out, s32 *actualout)
  255. {
  256. s32 err = 0;
  257. s32 value;
  258. hwm_sensor_data *sensor_data;
  259. switch (command) {
  260. case SENSOR_DELAY:
  261. if ((buff_in == NULL) || (size_in < sizeof(int))) {
  262. GTP_ERROR("Set delay parameter error!");
  263. err = -EINVAL;
  264. }
  265. /* Do nothing */
  266. break;
  267. case SENSOR_ENABLE:
  268. if ((buff_in == NULL) || (size_in < sizeof(int))) {
  269. GTP_ERROR("Enable sensor parameter error!");
  270. err = -EINVAL;
  271. } else {
  272. value = *(int *)buff_in;
  273. err = tpd_enable_ps(value);
  274. }
  275. break;
  276. case SENSOR_GET_DATA:
  277. if ((buff_out == NULL) || (size_out < sizeof(hwm_sensor_data))) {
  278. GTP_ERROR("Get sensor data parameter error!");
  279. err = -EINVAL;
  280. } else {
  281. sensor_data = (hwm_sensor_data *) buff_out;
  282. sensor_data->values[0] = tpd_get_ps_value();
  283. sensor_data->value_divide = 1;
  284. sensor_data->status = SENSOR_STATUS_ACCURACY_MEDIUM;
  285. }
  286. break;
  287. default:
  288. GTP_ERROR("proxmy sensor operate function no this parameter %d!", command);
  289. err = -1;
  290. break;
  291. }
  292. return err;
  293. }
  294. #endif
  295. static ssize_t gt91xx_config_read_proc(struct file *file, char *buffer, size_t count, loff_t *ppos)
  296. {
  297. char *page = NULL;
  298. char *ptr = NULL;
  299. char temp_data[GTP_CONFIG_MAX_LENGTH + 2] = { 0 };
  300. int i, len, err = -1;
  301. page = kmalloc(PAGE_SIZE, GFP_KERNEL);
  302. if (!page) {
  303. kfree(page);
  304. return -ENOMEM;
  305. }
  306. ptr = page;
  307. ptr += sprintf(ptr, "==== GT9XX config init value====\n");
  308. for (i = 0; i < GTP_CONFIG_MAX_LENGTH; i++) {
  309. ptr += sprintf(ptr, "0x%02X ", config[i + 2]);
  310. if (i % 8 == 7)
  311. ptr += sprintf(ptr, "\n");
  312. }
  313. ptr += sprintf(ptr, "\n");
  314. ptr += sprintf(ptr, "==== GT9XX config real value====\n");
  315. i2c_read_bytes(i2c_client_point, GTP_REG_CONFIG_DATA, temp_data, GTP_CONFIG_MAX_LENGTH);
  316. for (i = 0; i < GTP_CONFIG_MAX_LENGTH; i++) {
  317. ptr += sprintf(ptr, "0x%02X ", temp_data[i]);
  318. if (i % 8 == 7)
  319. ptr += sprintf(ptr, "\n");
  320. }
  321. /* Touch PID & VID */
  322. ptr += sprintf(ptr, "\n");
  323. ptr += sprintf(ptr, "==== GT9XX Version ID ====\n");
  324. i2c_read_bytes(i2c_client_point, GTP_REG_VERSION, temp_data, 6);
  325. ptr +=
  326. sprintf(ptr, "Chip PID: %c%c%c VID: 0x%02X%02X\n", temp_data[0], temp_data[1],
  327. temp_data[2], temp_data[5], temp_data[4]);
  328. ptr += sprintf(ptr, "Driver VID: 0x%02X%02X\n", gtp_default_FW[12], gtp_default_FW[13]);
  329. i2c_read_bytes(i2c_client_point, 0x41E4, temp_data, 1);
  330. ptr += sprintf(ptr, "Boot status 0x%X\n", temp_data[0]);
  331. /* Touch Status and Clock Gate */
  332. ptr += sprintf(ptr, "\n");
  333. ptr += sprintf(ptr, "==== Touch Status and Clock Gate ====\n");
  334. ptr += sprintf(ptr, "status: 1: on, 0 :off\n");
  335. ptr += sprintf(ptr, "status:%d\n", (tpd_halt + 1) & 0x1);
  336. len = ptr - page;
  337. if (*ppos >= len) {
  338. kfree(page);
  339. return 0;
  340. }
  341. err = copy_to_user(buffer, (char *)page, len);
  342. *ppos += len;
  343. if (err) {
  344. kfree(page);
  345. return err;
  346. }
  347. kfree(page);
  348. return len;
  349. /* return (ptr - page); */
  350. }
  351. static ssize_t gt91xx_config_write_proc(struct file *file, const char *buffer, size_t count,
  352. loff_t *ppos)
  353. {
  354. s32 ret = 0;
  355. char temp[25] = { 0 }; /* for store special format cmd */
  356. char mode_str[15] = { 0 };
  357. unsigned int mode;
  358. u8 buf[1];
  359. GTP_DEBUG("write count %ld\n", (unsigned long)count);
  360. if (count > GTP_CONFIG_MAX_LENGTH) {
  361. GTP_ERROR("size not match [%d:%ld]", GTP_CONFIG_MAX_LENGTH, (unsigned long)count);
  362. return -EFAULT;
  363. }
  364. /**********************************************/
  365. /* for store special format cmd */
  366. if (copy_from_user(temp, buffer, sizeof(temp))) {
  367. GTP_ERROR("copy from user fail 2");
  368. return -EFAULT;
  369. }
  370. if (sscanf(temp, "%s %d", (char *)&mode_str, &mode) == -1)
  371. return -EINVAL;
  372. /***********POLLING/EINT MODE switch****************/
  373. if (strcmp(mode_str, "polling") == 0) {
  374. if (mode >= 10 && mode <= 200) {
  375. GTP_INFO("Switch to polling mode, polling time is %d", mode);
  376. tpd_eint_mode = 0;
  377. tpd_polling_time = mode;
  378. tpd_flag = 1;
  379. wake_up_interruptible(&waiter);
  380. } else {
  381. GTP_INFO("Wrong polling time, please set between 10~200ms");
  382. }
  383. return count;
  384. }
  385. if (strcmp(mode_str, "eint") == 0) {
  386. GTP_INFO("Switch to eint mode");
  387. tpd_eint_mode = 1;
  388. return count;
  389. }
  390. /**********************************************/
  391. if (strcmp(mode_str, "switch") == 0) {
  392. if (mode == 0) /* turn off */
  393. tpd_off();
  394. else if (mode == 1) /* turn on */
  395. tpd_on();
  396. else
  397. GTP_ERROR("error mode :%d", mode);
  398. return count;
  399. }
  400. /* force clear config */
  401. if (strcmp(mode_str, "clear_config") == 0) {
  402. GTP_INFO("Force clear config");
  403. buf[0] = 0x10;
  404. ret = i2c_write_bytes(i2c_client_point, GTP_REG_SLEEP, buf, 1);
  405. return count;
  406. }
  407. if (copy_from_user(&config[2], buffer, count)) {
  408. GTP_ERROR("copy from user fail");
  409. return -EFAULT;
  410. }
  411. /***********clk operate reseved****************/
  412. /**********************************************/
  413. ret = gtp_send_cfg(i2c_client_point);
  414. abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];
  415. abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];
  416. int_type = (config[TRIGGER_LOC]) & 0x03;
  417. if (ret < 0)
  418. GTP_ERROR("send config failed.");
  419. return count;
  420. }
  421. int i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *rxbuf, int len)
  422. {
  423. u8 buffer[GTP_ADDR_LENGTH];
  424. u16 left = len;
  425. u16 offset = 0;
  426. struct i2c_msg msg[2] = {
  427. {
  428. .addr = (client->addr),
  429. /* .addr = (client->addr &I2C_MASK_FLAG), */
  430. /* .ext_flag = I2C_ENEXT_FLAG, */
  431. /* .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), */
  432. .flags = 0,
  433. .buf = buffer,
  434. .len = GTP_ADDR_LENGTH},
  435. {
  436. .addr = (client->addr),
  437. /* .addr = (client->addr &I2C_MASK_FLAG), */
  438. /* .ext_flag = I2C_ENEXT_FLAG, */
  439. /* .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), */
  440. .flags = I2C_M_RD},
  441. };
  442. if (rxbuf == NULL)
  443. return -1;
  444. GTP_ERROR("i2c_read_bytes to device %02X address %04X len %d", client->addr, addr, len);
  445. while (left > 0) {
  446. buffer[0] = ((addr + offset) >> 8) & 0xFF;
  447. buffer[1] = (addr + offset) & 0xFF;
  448. msg[1].buf = &rxbuf[offset];
  449. if (left > MAX_TRANSACTION_LENGTH) {
  450. msg[1].len = MAX_TRANSACTION_LENGTH;
  451. left -= MAX_TRANSACTION_LENGTH;
  452. offset += MAX_TRANSACTION_LENGTH;
  453. } else {
  454. msg[1].len = left;
  455. left = 0;
  456. }
  457. if (i2c_transfer(client->adapter, &msg[0], 2) != 2) {
  458. GTP_ERROR("I2C read 0x%X length=%d failed", addr + offset, len);
  459. return -1;
  460. }
  461. }
  462. return 0;
  463. }
  464. s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len)
  465. {
  466. s32 ret = -1;
  467. u16 addr = (buf[0] << 8) + buf[1];
  468. ret = i2c_read_bytes(client, addr, &buf[2], len - 2);
  469. if (!ret)
  470. return 2;
  471. gtp_reset_guitar(client, 20);
  472. return ret;
  473. }
  474. int i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *txbuf, int len)
  475. {
  476. u8 buffer[MAX_TRANSACTION_LENGTH];
  477. u16 left = len;
  478. u16 offset = 0;
  479. struct i2c_msg msg = {
  480. .addr = (client->addr),
  481. /* .addr = (client->addr &I2C_MASK_FLAG), */
  482. /* .ext_flag = I2C_ENEXT_FLAG, */
  483. /* .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), */
  484. .flags = 0,
  485. .buf = buffer,
  486. };
  487. if (txbuf == NULL)
  488. return -1;
  489. GTP_ERROR("i2c_write_bytes to device %02X address %04X len %d", client->addr, addr, len);
  490. while (left > 0) {
  491. buffer[0] = ((addr + offset) >> 8) & 0xFF;
  492. buffer[1] = (addr + offset) & 0xFF;
  493. if (left > MAX_I2C_TRANSFER_SIZE) {
  494. memcpy(&buffer[GTP_ADDR_LENGTH], &txbuf[offset], MAX_I2C_TRANSFER_SIZE);
  495. msg.len = MAX_TRANSACTION_LENGTH;
  496. left -= MAX_I2C_TRANSFER_SIZE;
  497. offset += MAX_I2C_TRANSFER_SIZE;
  498. } else {
  499. memcpy(&buffer[GTP_ADDR_LENGTH], &txbuf[offset], left);
  500. msg.len = left + GTP_ADDR_LENGTH;
  501. left = 0;
  502. }
  503. /* GTP_DEBUG("byte left %d offset %d", left, offset); */
  504. if (i2c_transfer(client->adapter, &msg, 1) != 1) {
  505. GTP_ERROR("I2C write 0x%X%X length=%d failed", buffer[0], buffer[1], len);
  506. return -1;
  507. }
  508. }
  509. return 0;
  510. }
  511. s32 gtp_i2c_write(struct i2c_client *client, u8 *buf, s32 len)
  512. {
  513. s32 ret = -1;
  514. u16 addr = (buf[0] << 8) + buf[1];
  515. ret = i2c_write_bytes(client, addr, &buf[2], len - 2);
  516. if (!ret)
  517. return 1;
  518. gtp_reset_guitar(client, 20);
  519. return ret;
  520. }
  521. /*******************************************************
  522. Function:
  523. Send config Function.
  524. Input:
  525. client: i2c client.
  526. Output:
  527. Executive outcomes.0--success,non-0--fail.
  528. *******************************************************/
  529. s32 gtp_send_cfg(struct i2c_client *client)
  530. {
  531. s32 ret = 0;
  532. #if GTP_DRIVER_SEND_CFG
  533. s32 retry = 0;
  534. for (retry = 0; retry < 5; retry++) {
  535. #ifdef GTP_CHARGER_DETECT
  536. if (gtp_charger_mode == 1) {
  537. GTP_DEBUG("Write charger config");
  538. ret =
  539. gtp_i2c_write(client, config_charger,
  540. GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH);
  541. } else {
  542. GTP_DEBUG("Write normal config");
  543. ret =
  544. gtp_i2c_write(client, config, GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH);
  545. }
  546. #else
  547. ret = gtp_i2c_write(client, config, GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH);
  548. #endif
  549. if (ret > 0)
  550. break;
  551. }
  552. #endif
  553. return ret;
  554. }
  555. /*******************************************************
  556. Function:
  557. Read goodix touchscreen version function.
  558. Input:
  559. client: i2c client struct.
  560. version:address to store version info
  561. Output:
  562. Executive outcomes.0---succeed.
  563. *******************************************************/
  564. s32 gtp_read_version(struct i2c_client *client, u16 *version)
  565. {
  566. s32 ret = -1;
  567. s32 i;
  568. u8 buf[8] = { GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff };
  569. GTP_DEBUG_FUNC();
  570. ret = gtp_i2c_read(client, buf, sizeof(buf));
  571. if (ret < 0) {
  572. GTP_ERROR("GTP read version failed");
  573. return ret;
  574. }
  575. if (version)
  576. *version = (buf[7] << 8) | buf[6];
  577. tpd_info.vid = *version;
  578. tpd_info.pid = 0x00;
  579. /* for gt9xx series */
  580. for (i = 0; i < 3; i++) {
  581. if (buf[i + 2] < 0x30)
  582. break;
  583. tpd_info.pid |= ((buf[i + 2] - 0x30) << ((2 - i) * 4));
  584. }
  585. GTP_INFO("IC VERSION:%c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[7], buf[6]);
  586. return ret;
  587. }
  588. /*******************************************************
  589. Function:
  590. GTP initialize function.
  591. Input:
  592. client: i2c client private struct.
  593. Output:
  594. Executive outcomes.0---succeed.
  595. *******************************************************/
  596. static s32 gtp_init_panel(struct i2c_client *client)
  597. {
  598. s32 ret = -1;
  599. #if GTP_DRIVER_SEND_CFG
  600. s32 i;
  601. u8 check_sum = 0;
  602. u8 rd_cfg_buf[16];
  603. u8 cfg_info_group1[] = CTP_CFG_GROUP1;
  604. u8 cfg_info_group2[] = CTP_CFG_GROUP2;
  605. u8 cfg_info_group3[] = CTP_CFG_GROUP3;
  606. u8 *send_cfg_buf[3] = { cfg_info_group1, cfg_info_group2, cfg_info_group3 };
  607. #ifdef GTP_CHARGER_DETECT
  608. u8 cfg_info_group1_charger[] = CTP_CFG_GROUP1_CHARGER;
  609. u8 cfg_info_group2_charger[] = CTP_CFG_GROUP2_CHARGER;
  610. u8 cfg_info_group3_charger[] = CTP_CFG_GROUP3_CHARGER;
  611. u8 *send_cfg_buf_charger[3] = { cfg_info_group1_charger,
  612. cfg_info_group2_charger, cfg_info_group3_charger };
  613. #endif
  614. u8 cfg_info_len[3] = { sizeof(cfg_info_group1) / sizeof(cfg_info_group1[0]),
  615. sizeof(cfg_info_group2) / sizeof(cfg_info_group2[0]),
  616. sizeof(cfg_info_group3) / sizeof(cfg_info_group3[0])
  617. };
  618. for (i = 0; i < 3; i++) {
  619. if (cfg_info_len[i] > cfg_len)
  620. cfg_len = cfg_info_len[i];
  621. }
  622. GTP_DEBUG("len1=%d,len2=%d,len3=%d,get_len=%d", cfg_info_len[0], cfg_info_len[1],
  623. cfg_info_len[2], cfg_len);
  624. if ((!cfg_info_len[1]) && (!cfg_info_len[2])) {
  625. rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
  626. } else {
  627. rd_cfg_buf[0] = GTP_REG_SENSOR_ID >> 8;
  628. rd_cfg_buf[1] = GTP_REG_SENSOR_ID & 0xff;
  629. ret = gtp_i2c_read(client, rd_cfg_buf, 3);
  630. if (ret < 0) {
  631. GTP_ERROR("Read SENSOR ID failed,default use group1 config!");
  632. rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
  633. goto out;
  634. }
  635. rd_cfg_buf[GTP_ADDR_LENGTH] &= 0x03;
  636. }
  637. GTP_INFO("SENSOR ID:%d", rd_cfg_buf[GTP_ADDR_LENGTH]);
  638. memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
  639. memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[rd_cfg_buf[GTP_ADDR_LENGTH]], cfg_len);
  640. #ifdef GTP_CHARGER_DETECT
  641. memset(&config_charger[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
  642. memcpy(&config_charger[GTP_ADDR_LENGTH], send_cfg_buf_charger[rd_cfg_buf[GTP_ADDR_LENGTH]],
  643. cfg_len);
  644. #endif
  645. #if GTP_CUSTOM_CFG
  646. config[RESOLUTION_LOC] = (u8) GTP_MAX_WIDTH;
  647. config[RESOLUTION_LOC + 1] = (u8) (GTP_MAX_WIDTH >> 8);
  648. config[RESOLUTION_LOC + 2] = (u8) GTP_MAX_HEIGHT;
  649. config[RESOLUTION_LOC + 3] = (u8) (GTP_MAX_HEIGHT >> 8);
  650. if (GTP_INT_TRIGGER == 0) { /* RISING */
  651. config[TRIGGER_LOC] &= 0xfe;
  652. } else if (GTP_INT_TRIGGER == 1) { /* FALLING */
  653. config[TRIGGER_LOC] |= 0x01;
  654. }
  655. #endif /* endif GTP_CUSTOM_CFG */
  656. check_sum = 0;
  657. for (i = GTP_ADDR_LENGTH; i < cfg_len; i++)
  658. check_sum += config[i];
  659. config[cfg_len] = (~check_sum) + 1;
  660. #ifdef GTP_CHARGER_DETECT
  661. check_sum = 0;
  662. for (i = GTP_ADDR_LENGTH; i < cfg_len; i++)
  663. check_sum += config_charger[i];
  664. config_charger[cfg_len] = (~check_sum) + 1;
  665. #endif
  666. #else /* else DRIVER NEED NOT SEND CONFIG */
  667. if (cfg_len == 0)
  668. cfg_len = GTP_CONFIG_MAX_LENGTH;
  669. ret = gtp_i2c_read(client, config, cfg_len + GTP_ADDR_LENGTH);
  670. if (ret < 0) {
  671. GTP_ERROR("GTP read resolution & max_touch_num failed, use default value!");
  672. abs_x_max = GTP_MAX_WIDTH;
  673. abs_y_max = GTP_MAX_HEIGHT;
  674. int_type = GTP_INT_TRIGGER;
  675. goto out;
  676. }
  677. #endif /* endif GTP_DRIVER_SEND_CFG */
  678. abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];
  679. abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];
  680. int_type = (config[TRIGGER_LOC]) & 0x03;
  681. if ((!abs_x_max) || (!abs_y_max)) {
  682. GTP_ERROR("GTP resolution & max_touch_num invalid, use default value!");
  683. abs_x_max = GTP_MAX_WIDTH;
  684. abs_y_max = GTP_MAX_HEIGHT;
  685. }
  686. ret = gtp_send_cfg(client);
  687. if (ret < 0) {
  688. GTP_ERROR("Send config error.");
  689. goto out;
  690. }
  691. GTP_DEBUG("X_MAX = %d,Y_MAX = %d,TRIGGER = 0x%02x", abs_x_max, abs_y_max, int_type);
  692. msleep(20);
  693. out:
  694. return ret;
  695. }
  696. static s8 gtp_i2c_test(struct i2c_client *client)
  697. {
  698. u8 retry = 0;
  699. s8 ret = -1;
  700. u32 hw_info = 0;
  701. GTP_DEBUG_FUNC();
  702. while (retry++ < 5) {
  703. ret = i2c_read_bytes(client, GTP_REG_HW_INFO, (u8 *) &hw_info, sizeof(hw_info));
  704. if ((!ret) && (hw_info == 0x00900600)) { /* 20121212 */
  705. return ret;
  706. }
  707. GTP_ERROR("GTP_REG_HW_INFO : %08X", hw_info);
  708. GTP_ERROR("GTP i2c test failed time %d.", retry);
  709. msleep(20);
  710. }
  711. return -1;
  712. }
  713. /*******************************************************
  714. Function:
  715. Set INT pin as input for FW sync.
  716. Note:
  717. If the INT is high, It means there is pull up resistor attached on the INT pin.
  718. Pull low the INT pin manaully for FW sync.
  719. *******************************************************/
  720. void gtp_int_sync(void)
  721. {
  722. GTP_DEBUG("There is pull up resisitor attached on the INT pin~!");
  723. gpio_direction_output(tpd_int_gpio_number, 0);
  724. msleep(50);
  725. gpio_direction_input(tpd_int_gpio_number);
  726. }
  727. void gtp_reset_guitar(struct i2c_client *client, s32 ms)
  728. {
  729. GTP_INFO("GTP RESET! %d\n", client->addr);
  730. gpio_direction_output(tpd_rst_gpio_number, 0);
  731. msleep(ms);
  732. gpio_direction_output(tpd_int_gpio_number, client->addr == 0x14);
  733. msleep(20);
  734. gpio_direction_output(tpd_rst_gpio_number, 1);
  735. msleep(20);
  736. gtp_int_sync();
  737. }
  738. static int tpd_power_on(struct i2c_client *client)
  739. {
  740. int ret = 0;
  741. int reset_count = 0;
  742. /* int i=0; */
  743. reset_proc:
  744. gpio_direction_output(tpd_int_gpio_number, 0);
  745. gpio_direction_output(tpd_rst_gpio_number, 0);
  746. msleep(20);
  747. /* power on, need confirm with SA */
  748. GTP_ERROR("turn on power reg-vgp6\n");
  749. ret = regulator_enable(tpd->reg);
  750. if (ret != 0)
  751. TPD_DMESG("Failed to enable reg-vgp6: %d\n", ret);
  752. GTP_ERROR("turn on power reg-vgp4\n");
  753. ret = regulator_enable(tpd->io_reg);
  754. if (ret != 0)
  755. TPD_DMESG("Failed to enable reg-vgp4: %d\n", ret);
  756. gtp_reset_guitar(client, 20);
  757. GTP_ERROR("tpd_int_gpio_number:0x%x, tpd_rst_gpio_number:0x%x", tpd_int_gpio_number, tpd_rst_gpio_number);
  758. ret = gtp_i2c_test(client);
  759. if (ret < 0) {
  760. GTP_ERROR("I2C communication ERROR!");
  761. if (reset_count < TPD_MAX_RESET_COUNT) {
  762. reset_count++;
  763. goto reset_proc;
  764. } else {
  765. goto out;
  766. }
  767. }
  768. #if GTP_FW_DOWNLOAD
  769. ret = gup_init_fw_proc(client);
  770. if (ret < 0)
  771. GTP_ERROR("Create fw download thread error.");
  772. #endif
  773. out:
  774. return ret;
  775. }
  776. #ifdef MTK_CTP_RESET_CONFIG
  777. static int tpd_clear_config(void *unused)
  778. {
  779. int ret = 0, check_sum = 0;
  780. u8 temp_data = 0, i = 0;
  781. u8 config_1st[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]
  782. = { GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff };
  783. GTP_INFO("Clear Config Begin......");
  784. msleep(10000); /* wait main thread to be completed */
  785. ret = i2c_read_bytes(i2c_client_point, GTP_REG_CONFIG_DATA, &temp_data, 1);
  786. if (ret < 0) {
  787. GTP_ERROR("GTP read config failed!");
  788. return -1;
  789. }
  790. GTP_INFO("IC config version: 0x%x; Driver config version: 0x%x", temp_data,
  791. config[GTP_ADDR_LENGTH]);
  792. if ((temp_data < (u8) 0x5A) && (temp_data > config[GTP_ADDR_LENGTH])) {
  793. memset(&config_1st[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
  794. memcpy(&config_1st[GTP_ADDR_LENGTH], &config[GTP_ADDR_LENGTH], cfg_len);
  795. config_1st[GTP_ADDR_LENGTH] = 0;
  796. check_sum = 0;
  797. for (i = GTP_ADDR_LENGTH; i < cfg_len; i++)
  798. check_sum += config_1st[i];
  799. config_1st[cfg_len] = (~check_sum) + 1;
  800. ret =
  801. gtp_i2c_write(i2c_client_point, config_1st,
  802. GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH);
  803. if (ret < 0)
  804. GTP_ERROR("GTP write 00 config failed!");
  805. else
  806. GTP_INFO("Force clear cfg done");
  807. } else {
  808. GTP_INFO("No need clear cfg");
  809. }
  810. return 0;
  811. }
  812. #endif
  813. static const struct file_operations gt_upgrade_proc_fops = {
  814. .write = gt91xx_config_write_proc,
  815. .read = gt91xx_config_read_proc
  816. };
  817. static int tpd_irq_registration(void)
  818. {
  819. struct device_node *node = NULL;
  820. int ret = 0;
  821. TPD_DEBUG("Device Tree Tpd_irq_registration!");
  822. node = of_find_compatible_node(NULL, NULL, "mediatek,cap_touch");
  823. if (node) {
  824. /*touch_irq = gpio_to_irq(tpd_int_gpio_number);*/
  825. touch_irq = irq_of_parse_and_map(node, 0);
  826. TPD_DEBUG("touch_irq number %d\n", touch_irq);
  827. if (!int_type) {/* EINTF_TRIGGER */
  828. ret =
  829. request_irq(touch_irq, tpd_interrupt_handler, IRQF_TRIGGER_RISING,
  830. TPD_DEVICE, NULL);
  831. gtp_eint_trigger_type = IRQF_TRIGGER_RISING;
  832. if (ret > 0)
  833. GTP_ERROR("tpd request_irq IRQ LINE NOT AVAILABLE!.");
  834. } else {
  835. ret =
  836. request_irq(touch_irq, tpd_interrupt_handler,
  837. IRQF_TRIGGER_FALLING, TPD_DEVICE, NULL);
  838. gtp_eint_trigger_type = IRQF_TRIGGER_FALLING;
  839. if (ret > 0)
  840. GTP_ERROR("tpd request_irq IRQ LINE NOT AVAILABLE!.");
  841. }
  842. } else {
  843. TPD_DMESG("tpd request_irq can not find touch eint device node!.");
  844. }
  845. return ret;
  846. }
  847. static s32 tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
  848. {
  849. s32 err = 0;
  850. s32 ret = 0;
  851. /*int i;*/
  852. u16 version_info;
  853. struct task_struct *thread = NULL;
  854. #if 0 /* GTP_HAVE_TOUCH_KEY */
  855. s32 idx = 0;
  856. #endif
  857. #ifdef TPD_PROXIMITY
  858. struct hwmsen_object obj_ps;
  859. #endif
  860. of_get_gt9xx_platform_data(&client->dev);
  861. /* configure the gpio pins */
  862. ret = gpio_request_one(tpd_rst_gpio_number, GPIOF_OUT_INIT_LOW,
  863. "touchp_reset");
  864. if (ret < 0) {
  865. GTP_ERROR("Unable to request gpio reset_pin\n");
  866. return -1;
  867. }
  868. ret = gpio_request_one(tpd_int_gpio_number, GPIOF_IN,
  869. "tpd_int");
  870. if (ret < 0) {
  871. GTP_ERROR("Unable to request gpio int_pin\n");
  872. gpio_free(tpd_rst_gpio_number);
  873. return -1;
  874. }
  875. i2c_client_point = client;
  876. ret = tpd_power_on(client);
  877. if (ret < 0) {
  878. GTP_ERROR("I2C communication ERROR!");
  879. goto out;
  880. }
  881. #ifdef MTK_CTP_RESET_CONFIG
  882. thread = kthread_run(tpd_clear_config, 0, "mtk-tpd-clear-config");
  883. if (IS_ERR(thread)) {
  884. err = PTR_ERR(thread);
  885. GTP_INFO(TPD_DEVICE " failed to create kernel thread for clearing config: %d", err);
  886. }
  887. thread = NULL;
  888. #endif
  889. #if GTP_AUTO_UPDATE
  890. ret = gup_init_update_proc(client);
  891. if (ret < 0) {
  892. GTP_ERROR("Create update thread error.");
  893. goto out;
  894. }
  895. #endif
  896. #ifdef VELOCITY_CUSTOM
  897. tpd_v_magnify_x = TPD_VELOCITY_CUSTOM_X;
  898. tpd_v_magnify_y = TPD_VELOCITY_CUSTOM_Y;
  899. #endif
  900. ret = gtp_read_version(client, &version_info);
  901. if (ret < 0) {
  902. GTP_ERROR("Read version failed.");
  903. goto out;
  904. }
  905. ret = gtp_init_panel(client);
  906. if (ret < 0) {
  907. GTP_ERROR("GTP init panel failed.");
  908. goto out;
  909. }
  910. GTP_DEBUG("gtp_init_panel success");
  911. /* Create proc file system */
  912. gt91xx_config_proc =
  913. proc_create(GT91XX_CONFIG_PROC_FILE, 0660, NULL, &gt_upgrade_proc_fops);
  914. if (gt91xx_config_proc == NULL) {
  915. GTP_ERROR("create_proc_entry %s failed", GT91XX_CONFIG_PROC_FILE);
  916. goto out;
  917. }
  918. #if GTP_CREATE_WR_NODE
  919. init_wr_node(client);
  920. #endif
  921. thread = kthread_run(touch_event_handler, 0, TPD_DEVICE);
  922. if (IS_ERR(thread)) {
  923. err = PTR_ERR(thread);
  924. GTP_ERROR(TPD_DEVICE " failed to create kernel thread: %d", err);
  925. goto out;
  926. }
  927. #if 0 /* GTP_HAVE_TOUCH_KEY */
  928. for (idx = 0; idx < TPD_KEY_COUNT; idx++)
  929. input_set_capability(tpd->dev, EV_KEY, touch_key_array[idx]);
  930. #endif
  931. tpd_irq_registration();
  932. /*enable_irq(touch_irq);*/
  933. #ifdef TPD_PROXIMITY
  934. /* obj_ps.self = cm3623_obj; */
  935. obj_ps.polling = 0; /* 0--interrupt mode;1--polling mode; */
  936. obj_ps.sensor_operate = tpd_ps_operate;
  937. err = hwmsen_attach(ID_PROXIMITY, &obj_ps);
  938. if (err)
  939. GTP_ERROR("hwmsen attach fail, return:%d.", err);
  940. #endif
  941. #if GTP_ESD_PROTECT
  942. INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
  943. gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
  944. queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, TPD_ESD_CHECK_CIRCLE);
  945. #endif
  946. #ifdef GTP_CHARGER_DETECT
  947. INIT_DELAYED_WORK(&gtp_charger_check_work, gtp_charger_check_func);
  948. gtp_charger_check_workqueue = create_workqueue("gtp_charger_check");
  949. queue_delayed_work(gtp_charger_check_workqueue, &gtp_charger_check_work,
  950. TPD_CHARGER_CHECK_CIRCLE);
  951. #endif
  952. tpd_load_status = 1;
  953. GTP_INFO("%s, success run Done", __func__);
  954. return 0;
  955. out:
  956. gpio_free(tpd_rst_gpio_number);
  957. gpio_free(tpd_int_gpio_number);
  958. return -1;
  959. }
  960. static irqreturn_t tpd_interrupt_handler(int irq, void *dev_id)
  961. {
  962. TPD_DEBUG_PRINT_INT;
  963. tpd_flag = 1;
  964. wake_up_interruptible(&waiter);
  965. return IRQ_HANDLED;
  966. }
  967. static int tpd_i2c_remove(struct i2c_client *client)
  968. {
  969. #if GTP_CREATE_WR_NODE
  970. uninit_wr_node();
  971. #endif
  972. #if GTP_ESD_PROTECT
  973. destroy_workqueue(gtp_esd_check_workqueue);
  974. #endif
  975. #if GTP_ESD_PROTECT
  976. destroy_workqueue(gtp_charger_check_workqueue);
  977. #endif
  978. gpio_free(tpd_rst_gpio_number);
  979. gpio_free(tpd_int_gpio_number);
  980. return 0;
  981. }
  982. #ifdef GTP_CHARGER_DETECT
  983. static void gtp_charger_check_func(struct work_struct *work)
  984. {
  985. int cur_charger_state;
  986. cur_charger_state = upmu_get_pchr_chrdet();
  987. GTP_DEBUG("Charger mode = %d", cur_charger_state);
  988. if (gtp_charger_mode != cur_charger_state) {
  989. GTP_DEBUG("Charger state change detected~!");
  990. GTP_DEBUG("Charger mode = %d", cur_charger_state);
  991. gtp_charger_mode = cur_charger_state;
  992. gtp_send_cfg(i2c_client_point);
  993. }
  994. if (!tpd_halt)
  995. queue_delayed_work(gtp_charger_check_workqueue, &gtp_charger_check_work,
  996. TPD_CHARGER_CHECK_CIRCLE);
  997. }
  998. #endif
  999. #if GTP_ESD_PROTECT
  1000. static void force_reset_guitar(void)
  1001. {
  1002. s32 i;
  1003. s32 ret;
  1004. GTP_INFO("force_reset_guitar");
  1005. /* Power off TP */
  1006. ret = regulator_disable(tpd->reg);
  1007. if (ret != 0)
  1008. TPD_DMESG("Failed to disable reg-vgp6: %d\n", ret);
  1009. ret = regulator_disable(tpd->io_reg);
  1010. if (ret != 0)
  1011. TPD_DMESG("Failed to disable reg-vgp4: %d\n", ret);
  1012. msleep(30);
  1013. /* Power on TP */
  1014. ret = regulator_enable(tpd->reg);
  1015. if (ret != 0)
  1016. TPD_DMESG("Failed to enable reg-vgp6: %d\n", ret);
  1017. ret = regulator_enable(tpd->io_reg);
  1018. if (ret != 0)
  1019. TPD_DMESG("Failed to enable reg-vgp4: %d\n", ret);
  1020. msleep(30);
  1021. for (i = 0; i < 5; i++) {
  1022. /* Reset Guitar */
  1023. gtp_reset_guitar(i2c_client_point, 20);
  1024. /* Send config */
  1025. ret = gtp_send_cfg(i2c_client_point);
  1026. if (ret < 0)
  1027. continue;
  1028. break;
  1029. }
  1030. }
  1031. static void gtp_esd_check_func(struct work_struct *work)
  1032. {
  1033. int i;
  1034. int ret = -1;
  1035. u8 test[3] = { GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff };
  1036. if (tpd_halt)
  1037. return;
  1038. for (i = 0; i < 3; i++) {
  1039. ret = gtp_i2c_read(i2c_client_point, test, 3);
  1040. if (ret > 0)
  1041. break;
  1042. }
  1043. if (i >= 3)
  1044. force_reset_guitar();
  1045. if (!tpd_halt) {
  1046. queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work,
  1047. TPD_ESD_CHECK_CIRCLE);
  1048. }
  1049. }
  1050. #endif
  1051. static int tpd_history_x = 0, tpd_history_y;
  1052. static void tpd_down(s32 x, s32 y, s32 size, s32 id)
  1053. {
  1054. if ((!size) && (!id)) {
  1055. input_report_abs(tpd->dev, ABS_MT_PRESSURE, 100);
  1056. input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 100);
  1057. } else {
  1058. input_report_abs(tpd->dev, ABS_MT_PRESSURE, size);
  1059. input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, size);
  1060. /* track id Start 0 */
  1061. input_report_abs(tpd->dev, ABS_MT_TRACKING_ID, id);
  1062. }
  1063. input_report_key(tpd->dev, BTN_TOUCH, 1);
  1064. input_report_abs(tpd->dev, ABS_MT_POSITION_X, x);
  1065. input_report_abs(tpd->dev, ABS_MT_POSITION_Y, y);
  1066. input_mt_sync(tpd->dev);
  1067. TPD_DEBUG_SET_TIME;
  1068. TPD_EM_PRINT(x, y, x, y, id, 1);
  1069. tpd_history_x = x;
  1070. tpd_history_y = y;
  1071. /* MMProfileLogEx(MMP_TouchPanelEvent, MMProfileFlagPulse, 1, x + y); */
  1072. #ifdef TPD_HAVE_BUTTON
  1073. if (FACTORY_BOOT == get_boot_mode() || RECOVERY_BOOT == get_boot_mode())
  1074. tpd_button(x, y, 1);
  1075. #endif
  1076. }
  1077. static void tpd_up(s32 x, s32 y, s32 id)
  1078. {
  1079. /* input_report_abs(tpd->dev, ABS_MT_PRESSURE, 0); */
  1080. input_report_key(tpd->dev, BTN_TOUCH, 0);
  1081. /* input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 0); */
  1082. input_mt_sync(tpd->dev);
  1083. TPD_DEBUG_SET_TIME;
  1084. TPD_EM_PRINT(tpd_history_x, tpd_history_y, tpd_history_x, tpd_history_y, id, 0);
  1085. tpd_history_x = 0;
  1086. tpd_history_y = 0;
  1087. /* MMProfileLogEx(MMP_TouchPanelEvent, MMProfileFlagPulse, 0, x + y); */
  1088. #ifdef TPD_HAVE_BUTTON
  1089. if (FACTORY_BOOT == get_boot_mode() || RECOVERY_BOOT == get_boot_mode())
  1090. tpd_button(x, y, 0);
  1091. #endif
  1092. }
  1093. /*Coordination mapping*/
  1094. static void tpd_calibrate_driver(int *x, int *y)
  1095. {
  1096. int tx;
  1097. GTP_DEBUG("Call tpd_calibrate of this driver ..\n");
  1098. tx = ((tpd_def_calmat[0] * (*x)) + (tpd_def_calmat[1] * (*y)) + (tpd_def_calmat[2])) >> 12;
  1099. *y = ((tpd_def_calmat[3] * (*x)) + (tpd_def_calmat[4] * (*y)) + (tpd_def_calmat[5])) >> 12;
  1100. *x = tx;
  1101. }
  1102. static int touch_event_handler(void *unused)
  1103. {
  1104. struct sched_param param = {.sched_priority = RTPM_PRIO_TPD };
  1105. u8 end_cmd[3] = { GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0 };
  1106. u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1] = { GTP_READ_COOR_ADDR >> 8,
  1107. GTP_READ_COOR_ADDR & 0xFF };
  1108. u8 touch_num = 0;
  1109. u8 finger = 0;
  1110. static u8 pre_touch;
  1111. static u8 pre_key;
  1112. u8 key_value = 0;
  1113. u8 *coor_data = NULL;
  1114. s32 input_x = 0;
  1115. s32 input_y = 0;
  1116. s32 input_w = 0;
  1117. s32 id = 0;
  1118. s32 i = 0;
  1119. s32 ret = -1;
  1120. #ifdef TPD_PROXIMITY
  1121. s32 err = 0;
  1122. hwm_sensor_data sensor_data;
  1123. u8 proximity_status;
  1124. #endif
  1125. #if GTP_CHANGE_X2Y
  1126. s32 temp;
  1127. #endif
  1128. sched_setscheduler(current, SCHED_RR, &param);
  1129. do {
  1130. set_current_state(TASK_INTERRUPTIBLE);
  1131. if (tpd_eint_mode) {
  1132. wait_event_interruptible(waiter, tpd_flag != 0);
  1133. tpd_flag = 0;
  1134. } else {
  1135. msleep(tpd_polling_time);
  1136. }
  1137. set_current_state(TASK_RUNNING);
  1138. mutex_lock(&i2c_access);
  1139. disable_irq(touch_irq);
  1140. if (tpd_halt) {
  1141. mutex_unlock(&i2c_access);
  1142. GTP_DEBUG("return for interrupt after suspend... ");
  1143. continue;
  1144. }
  1145. ret = gtp_i2c_read(i2c_client_point, point_data, 12);
  1146. if (ret < 0) {
  1147. GTP_ERROR("I2C transfer error. errno:%d ", ret);
  1148. goto exit_work_func;
  1149. }
  1150. finger = point_data[GTP_ADDR_LENGTH];
  1151. if ((finger & 0x80) == 0) {
  1152. enable_irq(touch_irq);
  1153. mutex_unlock(&i2c_access);
  1154. GTP_ERROR("buffer not ready");
  1155. continue;
  1156. }
  1157. #ifdef TPD_PROXIMITY
  1158. if (tpd_proximity_flag == 1) {
  1159. proximity_status = point_data[GTP_ADDR_LENGTH];
  1160. GTP_DEBUG("REG INDEX[0x814E]:0x%02X", proximity_status);
  1161. if (proximity_status & 0x60) { /* proximity or large touch detect,enable hwm_sensor. */
  1162. tpd_proximity_detect = 0;
  1163. /* sensor_data.values[0] = 0; */
  1164. } else {
  1165. tpd_proximity_detect = 1;
  1166. /* sensor_data.values[0] = 1; */
  1167. }
  1168. /* get raw data */
  1169. GTP_DEBUG(" ps change");
  1170. GTP_DEBUG("PROXIMITY STATUS:0x%02X", tpd_proximity_detect);
  1171. /* map and store data to hwm_sensor_data */
  1172. sensor_data.values[0] = tpd_get_ps_value();
  1173. sensor_data.value_divide = 1;
  1174. sensor_data.status = SENSOR_STATUS_ACCURACY_MEDIUM;
  1175. /* report to the up-layer */
  1176. ret = hwmsen_get_interrupt_data(ID_PROXIMITY, &sensor_data);
  1177. if (ret)
  1178. GTP_ERROR("Call hwmsen_get_interrupt_data fail = %d", err);
  1179. }
  1180. #endif
  1181. touch_num = finger & 0x0f;
  1182. if (touch_num > GTP_MAX_TOUCH) {
  1183. GTP_ERROR("Bad number of fingers!");
  1184. goto exit_work_func;
  1185. }
  1186. if (touch_num > 1) {
  1187. u8 buf[8 * GTP_MAX_TOUCH] = { (GTP_READ_COOR_ADDR + 10) >> 8,
  1188. (GTP_READ_COOR_ADDR + 10) & 0xff };
  1189. ret = gtp_i2c_read(i2c_client_point, buf, 2 + 8 * (touch_num - 1));
  1190. memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1));
  1191. }
  1192. #if GTP_HAVE_TOUCH_KEY
  1193. key_value = point_data[3 + 8 * touch_num];
  1194. if (key_value || pre_key) {
  1195. for (i = 0; i < TPD_KEY_COUNT; i++) {
  1196. /* input_report_key(tpd->dev, touch_key_array[i], key_value & (0x01 << i)); */
  1197. if (key_value & (0x01 << i)) { /* key=1 menu ;key=2 home; key =4 back; */
  1198. input_x = touch_key_point_maping_array[i].point_x;
  1199. input_y = touch_key_point_maping_array[i].point_y;
  1200. GTP_DEBUG("button =%d %d", input_x, input_y);
  1201. tpd_down(input_x, input_y, 0, 0);
  1202. }
  1203. }
  1204. if ((pre_key != 0) && (key_value == 0))
  1205. tpd_up(0, 0, 0);
  1206. touch_num = 0;
  1207. pre_touch = 0;
  1208. }
  1209. #endif
  1210. pre_key = key_value;
  1211. GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger);
  1212. if (touch_num) {
  1213. for (i = 0; i < touch_num; i++) {
  1214. coor_data = &point_data[i * 8 + 3];
  1215. id = coor_data[0] & 0x0F;
  1216. input_x = coor_data[1] | coor_data[2] << 8;
  1217. input_y = coor_data[3] | coor_data[4] << 8;
  1218. input_w = coor_data[5] | coor_data[6] << 8;
  1219. GTP_DEBUG("Original touch point : [X:%04d, Y:%04d]", input_x,
  1220. input_y);
  1221. input_x = TPD_WARP_X(abs_x_max, input_x);
  1222. input_y = TPD_WARP_Y(abs_y_max, input_y);
  1223. tpd_calibrate_driver(&input_x, &input_y);
  1224. GTP_DEBUG("Touch point after calibration: [X:%04d, Y:%04d]",
  1225. input_x, input_y);
  1226. #if GTP_CHANGE_X2Y
  1227. temp = input_x;
  1228. input_x = input_y;
  1229. input_y = temp;
  1230. #endif
  1231. tpd_down(input_x, input_y, input_w, id);
  1232. }
  1233. } else if (pre_touch) {
  1234. GTP_DEBUG("Touch Release!");
  1235. tpd_up(0, 0, 0);
  1236. } else {
  1237. GTP_DEBUG("Additional Eint!");
  1238. }
  1239. pre_touch = touch_num;
  1240. /* input_report_key(tpd->dev, BTN_TOUCH, (touch_num || key_value)); */
  1241. if (tpd != NULL && tpd->dev != NULL)
  1242. input_sync(tpd->dev);
  1243. exit_work_func:
  1244. if (!gtp_rawdiff_mode) {
  1245. ret = gtp_i2c_write(i2c_client_point, end_cmd, 3);
  1246. if (ret < 0)
  1247. GTP_INFO("I2C write end_cmd error!");
  1248. }
  1249. enable_irq(touch_irq);
  1250. mutex_unlock(&i2c_access);
  1251. } while (!kthread_should_stop());
  1252. return 0;
  1253. }
  1254. static int tpd_local_init(void)
  1255. {
  1256. int retval;
  1257. tpd->reg = regulator_get(tpd->tpd_dev, "vtouch");
  1258. tpd->io_reg = regulator_get(tpd->tpd_dev, "vtouchio");
  1259. retval = regulator_set_voltage(tpd->reg, 3300000, 3300000);
  1260. if (retval != 0) {
  1261. TPD_DMESG("Failed to set reg-vgp6 voltage: %d\n", retval);
  1262. return -1;
  1263. }
  1264. retval = regulator_set_voltage(tpd->io_reg, 1800000, 1800000);
  1265. if (retval != 0) {
  1266. TPD_DMESG("Failed to set reg-vgp4 voltage: %d\n", retval);
  1267. return -1;
  1268. }
  1269. if (i2c_add_driver(&tpd_i2c_driver) != 0) {
  1270. GTP_INFO("unable to add i2c driver.");
  1271. return -1;
  1272. }
  1273. if (tpd_load_status == 0) {
  1274. /* if(tpd_load_status == 0) disable auto load touch driver for linux3.0 porting */
  1275. GTP_INFO("add error touch panel driver.");
  1276. i2c_del_driver(&tpd_i2c_driver);
  1277. return -1;
  1278. }
  1279. input_set_abs_params(tpd->dev, ABS_MT_TRACKING_ID, 0, (GTP_MAX_TOUCH - 1), 0, 0);
  1280. #ifdef TPD_HAVE_BUTTON
  1281. tpd_button_setting(TPD_KEY_COUNT, tpd_keys_local, tpd_keys_dim_local); /* initialize tpd button data */
  1282. #endif
  1283. #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
  1284. TPD_DO_WARP = 1;
  1285. memcpy(tpd_wb_start, tpd_wb_start_local, TPD_WARP_CNT * 4);
  1286. memcpy(tpd_wb_end, tpd_wb_start_local, TPD_WARP_CNT * 4);
  1287. #endif
  1288. #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
  1289. /* memcpy(tpd_calmat, tpd_def_calmat_local, 8 * 4); */
  1290. /* memcpy(tpd_def_calmat, tpd_def_calmat_local, 8 * 4); */
  1291. if (FACTORY_BOOT == get_boot_mode()) {
  1292. TPD_DEBUG("Factory mode is detected!\n");
  1293. memcpy(tpd_calmat, tpd_def_calmat_local_factory, 8 * 4);
  1294. memcpy(tpd_def_calmat, tpd_def_calmat_local_factory, 8 * 4);
  1295. } else {
  1296. TPD_DEBUG("Normal mode is detected!\n");
  1297. memcpy(tpd_calmat, tpd_def_calmat_local_normal, 8 * 4);
  1298. memcpy(tpd_def_calmat, tpd_def_calmat_local_normal, 8 * 4);
  1299. }
  1300. #endif
  1301. /* set vendor string */
  1302. tpd->dev->id.vendor = 0x00;
  1303. tpd->dev->id.product = tpd_info.pid;
  1304. tpd->dev->id.version = tpd_info.vid;
  1305. GTP_INFO("end %s, %d", __func__, __LINE__);
  1306. tpd_type_cap = 1;
  1307. return 0;
  1308. }
  1309. /*******************************************************
  1310. Function:
  1311. Eter sleep function.
  1312. Input:
  1313. client:i2c_client.
  1314. Output:
  1315. Executive outcomes.0--success,non-0--fail.
  1316. *******************************************************/
  1317. static s8 gtp_enter_sleep(struct i2c_client *client)
  1318. {
  1319. s8 ret = -1;
  1320. #if !GTP_POWER_CTRL_SLEEP
  1321. s8 retry = 0;
  1322. u8 i2c_control_buf[3] = { (u8) (GTP_REG_SLEEP >> 8), (u8) GTP_REG_SLEEP, 5 };
  1323. gpio_direction_output(tpd_int_gpio_number, 0);
  1324. msleep(20);
  1325. while (retry++ < 5) {
  1326. ret = gtp_i2c_write(client, i2c_control_buf, 3);
  1327. if (ret > 0) {
  1328. GTP_INFO("GTP enter sleep!");
  1329. return ret;
  1330. }
  1331. msleep(20);
  1332. }
  1333. #else
  1334. gpio_direction_output(tpd_int_gpio_number, 0);
  1335. gpio_direction_output(tpd_rst_gpio_number, 0);
  1336. msleep(20);
  1337. ret = regulator_disable(tpd->io_reg);
  1338. if (ret != 0)
  1339. TPD_DMESG("Failed to disable reg-vgp4: %d\n", ret);
  1340. ret = regulator_disable(tpd->reg);
  1341. if (ret != 0)
  1342. TPD_DMESG("Failed to disable reg-vgp6: %d\n", ret);
  1343. GTP_INFO("GTP enter sleep!");
  1344. return 0;
  1345. #endif
  1346. GTP_ERROR("GTP send sleep cmd failed.");
  1347. return ret;
  1348. }
  1349. /*******************************************************
  1350. Function:
  1351. Wakeup from sleep mode Function.
  1352. Input:
  1353. client:i2c_client.
  1354. Output:
  1355. Executive outcomes.0--success,non-0--fail.
  1356. *******************************************************/
  1357. static s8 gtp_wakeup_sleep(struct i2c_client *client)
  1358. {
  1359. u8 retry = 0;
  1360. s8 ret = -1;
  1361. GTP_INFO("GTP wakeup begin.");
  1362. #if GTP_POWER_CTRL_SLEEP
  1363. while (retry++ < 5) {
  1364. ret = tpd_power_on(client);
  1365. if (ret < 0)
  1366. GTP_ERROR("I2C Power on ERROR!");
  1367. ret = gtp_send_cfg(client);
  1368. if (ret > 0) {
  1369. GTP_DEBUG("Wakeup sleep send config success.");
  1370. return ret;
  1371. }
  1372. }
  1373. #else
  1374. while (retry++ < 10) {
  1375. gpio_direction_output(tpd_int_gpio_number, 1);
  1376. msleep(20);
  1377. gpio_direction_output(tpd_int_gpio_number, 0);
  1378. msleep(20);
  1379. ret = gtp_i2c_test(client);
  1380. if (ret >= 0) {
  1381. gtp_int_sync();
  1382. return ret;
  1383. }
  1384. gtp_reset_guitar(client, 20);
  1385. }
  1386. #endif
  1387. GTP_ERROR("GTP wakeup sleep failed.");
  1388. return ret;
  1389. }
  1390. /* Function to manage low power suspend */
  1391. static void tpd_suspend(struct device *h)
  1392. {
  1393. s32 ret = -1;
  1394. mutex_lock(&i2c_access);
  1395. disable_irq(touch_irq);
  1396. tpd_halt = 1;
  1397. mutex_unlock(&i2c_access);
  1398. ret = gtp_enter_sleep(i2c_client_point);
  1399. if (ret < 0)
  1400. GTP_ERROR("GTP early suspend failed.");
  1401. #if GTP_ESD_PROTECT
  1402. cancel_delayed_work_sync(&gtp_esd_check_work);
  1403. #endif
  1404. #ifdef GTP_CHARGER_DETECT
  1405. cancel_delayed_work_sync(&gtp_charger_check_work);
  1406. #endif
  1407. #ifdef TPD_PROXIMITY
  1408. if (tpd_proximity_flag == 1)
  1409. return;
  1410. #endif
  1411. }
  1412. /* Function to manage power-on resume */
  1413. static void tpd_resume(struct device *h)
  1414. {
  1415. s32 ret = -1;
  1416. ret = gtp_wakeup_sleep(i2c_client_point);
  1417. if (ret < 0)
  1418. GTP_ERROR("GTP later resume failed.");
  1419. GTP_INFO("GTP wakeup sleep.");
  1420. mutex_lock(&i2c_access);
  1421. tpd_halt = 0;
  1422. enable_irq(touch_irq);
  1423. mutex_unlock(&i2c_access);
  1424. #ifdef TPD_PROXIMITY
  1425. if (tpd_proximity_flag == 1)
  1426. return;
  1427. #endif
  1428. #if GTP_ESD_PROTECT
  1429. queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, TPD_ESD_CHECK_CIRCLE);
  1430. #endif
  1431. #ifdef GTP_CHARGER_DETECT
  1432. queue_delayed_work(gtp_charger_check_workqueue, &gtp_charger_check_work,
  1433. TPD_CHARGER_CHECK_CIRCLE);
  1434. #endif
  1435. }
  1436. static void tpd_off(void)
  1437. {
  1438. int ret;
  1439. ret = regulator_disable(tpd->reg);
  1440. if (ret != 0)
  1441. TPD_DMESG("Failed to disable reg-vgp6: %d\n", ret);
  1442. ret = regulator_disable(tpd->io_reg);
  1443. if (ret != 0)
  1444. TPD_DMESG("Failed to disable reg-vgp4: %d\n", ret);
  1445. GTP_INFO("GTP enter sleep!");
  1446. tpd_halt = 1;
  1447. disable_irq(touch_irq);
  1448. }
  1449. static void tpd_on(void)
  1450. {
  1451. s32 ret = -1, retry = 0;
  1452. while (retry++ < 5) {
  1453. ret = tpd_power_on(i2c_client_point);
  1454. if (ret < 0)
  1455. GTP_ERROR("I2C Power on ERROR!");
  1456. ret = gtp_send_cfg(i2c_client_point);
  1457. if (ret > 0)
  1458. GTP_DEBUG("Wakeup sleep send config success.");
  1459. }
  1460. if (ret < 0)
  1461. GTP_ERROR("GTP later resume failed.");
  1462. enable_irq(touch_irq);
  1463. tpd_halt = 0;
  1464. }
  1465. static struct tpd_driver_t tpd_device_driver = {
  1466. .tpd_device_name = "gt9xx",
  1467. .tpd_local_init = tpd_local_init,
  1468. .suspend = tpd_suspend,
  1469. .resume = tpd_resume,
  1470. #ifdef TPD_HAVE_BUTTON
  1471. .tpd_have_button = 1,
  1472. #else
  1473. .tpd_have_button = 0,
  1474. #endif
  1475. .attrs = {
  1476. .attr = gt9xx_attrs,
  1477. .num = ARRAY_SIZE(gt9xx_attrs),
  1478. },
  1479. };
  1480. /* called when loaded into kernel */
  1481. static int __init tpd_driver_init(void)
  1482. {
  1483. GTP_INFO("MediaTek gt91xx touch panel driver init");
  1484. tpd_get_dts_info();
  1485. if (tpd_driver_add(&tpd_device_driver) < 0)
  1486. GTP_INFO("add generic driver failed");
  1487. return 0;
  1488. }
  1489. /* should never be called */
  1490. static void __exit tpd_driver_exit(void)
  1491. {
  1492. GTP_INFO("MediaTek gt91xx touch panel driver exit");
  1493. /* input_unregister_device(tpd->dev); */
  1494. tpd_driver_remove(&tpd_device_driver);
  1495. }
  1496. module_init(tpd_driver_init);
  1497. module_exit(tpd_driver_exit);