synaptics_driver.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023
  1. #include <linux/interrupt.h>
  2. #include <linux/i2c.h>
  3. #include <linux/sched.h>
  4. #include <linux/kthread.h>
  5. /*#include <linux/rtpm_prio.h>*/
  6. #include <linux/wait.h>
  7. #include <linux/time.h>
  8. #include <linux/delay.h>
  9. #include <linux/slab.h>
  10. #include "tpd.h"
  11. #include "include/synaptics_dsx_rmi4_i2c.h"
  12. #include "SynaImage.h"
  13. #include <linux/gpio.h>
  14. /*#include <mach/mt_pm_ldo.h>
  15. #include <mach/mt_typedefs.h>*/
  16. #include <mt_boot_common.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include <linux/of_device.h>
  20. #include <linux/of_gpio.h>
  21. #include <linux/of_irq.h>
  22. /* #define HAVE_TOUCH_KEY */
  23. #define CONFIG_ID 0x30303033
  24. /* DTS2012031404176 linghai 20120314 end */
  25. /* add by huxin */
  26. #ifdef HAVE_TOUCH_KEY
  27. const u16 touch_key_array[] = { KEY_MENU, KEY_HOMEPAGE, KEY_BACK };
  28. #define MAX_KEY_NUM (sizeof(touch_key_array)/sizeof(touch_key_array[0]))
  29. #endif
  30. #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
  31. static int tpd_wb_start_local[TPD_WARP_CNT] = TPD_WARP_START;
  32. static int tpd_wb_end_local[TPD_WARP_CNT] = TPD_WARP_END;
  33. #endif
  34. #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
  35. static int tpd_calmat_local[8] = TPD_CALIBRATION_MATRIX;
  36. static int tpd_def_calmat_local[8] = TPD_CALIBRATION_MATRIX;
  37. #endif
  38. unsigned int touch_irq = 0;
  39. struct point {
  40. int x;
  41. int raw_x;
  42. int y;
  43. int raw_y;
  44. int z;
  45. int status;
  46. };
  47. struct function_descriptor {
  48. u16 query_base;
  49. u16 cmd_base;
  50. u16 ctrl_base;
  51. u16 data_base;
  52. u8 intSrc;
  53. #define FUNCTION_VERSION(x) ((x >> 5) & 3)
  54. #define INTERRUPT_SOURCE_COUNT(x) (x & 7)
  55. u8 functionNumber;
  56. };
  57. struct tpd_data {
  58. struct i2c_client *client;
  59. struct function_descriptor f01;
  60. struct function_descriptor f11;
  61. struct function_descriptor f1a;
  62. u8 fn11_mask;
  63. u8 fn1a_mask;
  64. struct point *cur_points;
  65. struct point *pre_points;
  66. struct mutex io_ctrl_mutex;
  67. struct work_struct work;
  68. int f11_max_x, f11_max_y;
  69. u8 points_supported;
  70. u8 data_length;
  71. u8 current_page;
  72. };
  73. struct tpd_debug {
  74. u8 button_0d_enabled;
  75. };
  76. static DECLARE_WAIT_QUEUE_HEAD(waiter);
  77. static struct tpd_data *ts;
  78. static struct tpd_debug *td;
  79. static u8 boot_mode;
  80. static int tpd_flag;
  81. static int tpd_halt;
  82. static DEFINE_MUTEX(i2c_access);
  83. /* Function extern */
  84. static int tpd_probe(struct i2c_client *client, const struct i2c_device_id *id);
  85. static int tpd_detect(struct i2c_client *client, struct i2c_board_info *info);
  86. static int tpd_remove(struct i2c_client *client);
  87. /* static void tpd_work_func(struct work_struct *work); */
  88. static void tpd_down(int x, int y, int p, int id);
  89. static void tpd_up(int x, int y);
  90. /* static int tpd_sw_power(struct i2c_client *client, int on); */
  91. static int tpd_clear_interrupt(struct i2c_client *client);
  92. /* static u8 get_config_version(void); */
  93. static const struct i2c_device_id tpd_id[] = { {TPD_DEVICE, 0}, {} };
  94. /* DTS2012040603460 gkf61766 20120406 begin */
  95. static unsigned short force[] = { 0, 0x40, I2C_CLIENT_END, I2C_CLIENT_END };
  96. /* DTS2012040603460 gkf61766 20120406 end */
  97. static const unsigned short *const forces[] = { force, NULL };
  98. /* static struct i2c_client_address_data addr_data = { .forces = forces, }; */
  99. static const struct of_device_id synaptics_dt_match[] = {
  100. {.compatible = "mediatek,cap_touch"},
  101. {},
  102. };
  103. MODULE_DEVICE_TABLE(of, synaptics_dt_match);
  104. static struct i2c_driver tpd_i2c_driver = {
  105. .driver = {
  106. .name = TPD_DEVICE,
  107. .owner = THIS_MODULE,
  108. .of_match_table = of_match_ptr(synaptics_dt_match),
  109. },
  110. .probe = tpd_probe,
  111. .remove = tpd_remove,
  112. .id_table = tpd_id,
  113. .detect = tpd_detect,
  114. .address_list = (const unsigned short *)forces,
  115. /* .address_data = &addr_data, */
  116. };
  117. #if 0
  118. #ifdef CONFIG_HAS_EARLYSUSPEND
  119. static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev,
  120. struct device_attribute *attr, char *buf);
  121. static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev,
  122. struct device_attribute *attr, const char *buf,
  123. size_t count);
  124. #endif
  125. #endif
  126. unsigned int tpd_rst_gpio_number = 0;
  127. unsigned int tpd_int_gpio_number = 0;
  128. #ifdef CONFIG_OF
  129. static int of_get_synaptic_platform_data(struct device *dev)
  130. {
  131. /*int ret, num;*/
  132. if (dev->of_node) {
  133. const struct of_device_id *match;
  134. match = of_match_device(of_match_ptr(synaptics_dt_match), dev);
  135. if (!match) {
  136. TPD_DEBUG("Error: No device match found\n");
  137. return -ENODEV;
  138. }
  139. }
  140. tpd_rst_gpio_number = of_get_named_gpio(dev->of_node, "rst-gpio", 0);
  141. tpd_int_gpio_number = of_get_named_gpio(dev->of_node, "int-gpio", 0);
  142. TPD_DEBUG("g_vproc_en_gpio_number %d\n", tpd_rst_gpio_number);
  143. TPD_DEBUG("g_vproc_vsel_gpio_number %d\n", tpd_int_gpio_number);
  144. return 0;
  145. }
  146. #else
  147. static int of_get_synaptic_platform_data(struct device *dev)
  148. {
  149. return 0;
  150. }
  151. #endif
  152. #if PROXIMITY
  153. static ssize_t synaptics_rmi4_f51_enables_show(struct device *dev,
  154. struct device_attribute *attr, char *buf);
  155. static ssize_t synaptics_rmi4_f51_enables_store(struct device *dev,
  156. struct device_attribute *attr, const char *buf,
  157. size_t count);
  158. #endif
  159. #if 0
  160. static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
  161. struct device_attribute *attr, const char *buf,
  162. size_t count);
  163. static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
  164. struct device_attribute *attr, char *buf);
  165. static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
  166. struct device_attribute *attr, char *buf);
  167. static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
  168. struct device_attribute *attr, char *buf);
  169. static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev,
  170. struct device_attribute *attr, const char *buf,
  171. size_t count);
  172. #endif
  173. static irqreturn_t tpd_eint_handler(int irq, void *dev_id);
  174. /*
  175. struct kobject *attr_kobj;
  176. #ifdef CONFIG_HAS_EARLYSUSPEND
  177. static struct kobj_attribute synaptics_pm_cycle_attr = {
  178. .attr = {
  179. .name = "full_pm_cycle",
  180. .mode = (S_IRUGO | S_IWUGO),
  181. },
  182. .show = &synaptics_rmi4_full_pm_cycle_show,
  183. .store = &synaptics_rmi4_full_pm_cycle_store,
  184. };
  185. #endif
  186. #if PROXIMITY
  187. static struct kobj_attribute synaptics_f51_enables_attr = {
  188. .attr = {
  189. .name = "proximity_enables",
  190. .mode = (S_IRUGO | S_IWUGO),
  191. },
  192. .show = &synaptics_rmi4_f51_enables_show,
  193. .store = &synaptics_rmi4_f51_enables_store,
  194. };
  195. #endif
  196. static struct kobj_attribute synaptics_show_error_attr = {
  197. .attr = {
  198. .name = "reset",
  199. .mode = (S_IRUGO | S_IWUGO),
  200. },
  201. .show = &synaptics_rmi4_show_error,
  202. .store = &synaptics_rmi4_f01_reset_store,
  203. };
  204. static struct kobj_attribute synaptics_productinfo_attr = {
  205. .attr = {
  206. .name = "productinfo",
  207. .mode = (S_IRUGO | S_IWUGO),
  208. },
  209. .show = &synaptics_rmi4_f01_productinfo_show,
  210. .store = &synaptics_rmi4_store_error,
  211. };
  212. static struct kobj_attribute synaptics_flashprog_attr = {
  213. .attr = {
  214. .name = "prog",
  215. .mode = (S_IRUGO | S_IWUGO),
  216. },
  217. .show = &synaptics_rmi4_f01_flashprog_show,
  218. .store = &synaptics_rmi4_store_error,
  219. };
  220. static struct kobj_attribute synaptics_0dbutton_attr = {
  221. .attr = {
  222. .name = "0dbutton",
  223. .mode = (S_IRUGO | S_IWUGO),
  224. },
  225. .show = &synaptics_rmi4_0dbutton_show,
  226. .store = &synaptics_rmi4_0dbutton_store,
  227. };
  228. static struct attribute *syna_attrs[] = {
  229. #ifdef CONFIG_HAS_EARLYSUSPEND
  230. &synaptics_pm_cycle_attr.attr,
  231. #endif
  232. #if PROXIMITY
  233. &synaptics_f51_enables_attr.attr,
  234. #endif
  235. &synaptics_show_error_attr.attr,
  236. &synaptics_productinfo_attr.attr,
  237. &synaptics_0dbutton_attr.attr,
  238. &synaptics_flashprog_attr.attr,
  239. NULL
  240. };
  241. static struct attribute_group syna_attr_group = {
  242. .attrs = syna_attrs,
  243. };
  244. */
  245. struct kobject *properties_kobj_synap;
  246. struct kobject *properties_kobj_driver;
  247. static struct device_attribute attrs[] = {
  248. /*
  249. #ifdef CONFIG_HAS_EARLYSUSPEND
  250. __ATTR(full_pm_cycle, (S_IRUGO | S_IWUGO),
  251. synaptics_rmi4_full_pm_cycle_show,
  252. synaptics_rmi4_full_pm_cycle_store),
  253. #endif
  254. */
  255. #if PROXIMITY
  256. __ATTR(proximity_enables, (S_IRUGO | S_IWUGO),
  257. synaptics_rmi4_f51_enables_show,
  258. synaptics_rmi4_f51_enables_store),
  259. #endif
  260. /*
  261. __ATTR(reset, S_IWUGO,
  262. synaptics_rmi4_show_error,
  263. synaptics_rmi4_f01_reset_store),
  264. __ATTR(productinfo, S_IRUGO,
  265. synaptics_rmi4_f01_productinfo_show,
  266. synaptics_rmi4_store_error),
  267. __ATTR(flashprog, S_IRUGO,
  268. synaptics_rmi4_f01_flashprog_show,
  269. synaptics_rmi4_store_error),
  270. __ATTR(0dbutton, (S_IRUGO | S_IWUGO),
  271. synaptics_rmi4_0dbutton_show,
  272. synaptics_rmi4_0dbutton_store),
  273. */
  274. };
  275. static int tpd_irq_registration(void)
  276. {
  277. struct device_node *node = NULL;
  278. int ret = 0;
  279. TPD_DEBUG("Device Tree Tpd_irq_registration!");
  280. node = of_find_compatible_node(NULL, NULL, "mediatek,cap_touch");
  281. if (node) {
  282. /*touch_irq = gpio_to_irq(tpd_int_gpio_number);*/
  283. touch_irq = irq_of_parse_and_map(node, 0);
  284. TPD_DEBUG("touch_irq number %d\n", touch_irq);
  285. ret = request_irq(touch_irq, tpd_eint_handler, IRQF_TRIGGER_FALLING,
  286. TPD_DEVICE, NULL);
  287. if (ret > 0)
  288. TPD_DMESG("tpd request_irq IRQ LINE NOT AVAILABLE!.");
  289. } else {
  290. TPD_DMESG("tpd request_irq can not find touch eint device node!.");
  291. }
  292. return ret;
  293. }
  294. static bool exp_fn_inited;
  295. static struct mutex exp_fn_list_mutex;
  296. static struct list_head exp_fn_list;
  297. #if PROXIMITY
  298. static struct synaptics_rmi4_f51_handle *f51;
  299. #endif
  300. #if 0
  301. #ifdef CONFIG_HAS_EARLYSUSPEND
  302. static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev,
  303. struct device_attribute *attr, char *buf)
  304. {
  305. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  306. return snprintf(buf, PAGE_SIZE, "%u\n", rmi4_data->full_pm_cycle);
  307. }
  308. static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev,
  309. struct device_attribute *attr, const char *buf,
  310. size_t count)
  311. {
  312. unsigned int input;
  313. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  314. if (kstrtoint(buf, 10, &input))
  315. return -EINVAL;
  316. rmi4_data->full_pm_cycle = input > 0 ? 1 : 0;
  317. return count;
  318. }
  319. #endif
  320. #endif
  321. #if PROXIMITY
  322. static ssize_t synaptics_rmi4_f51_enables_show(struct device *dev,
  323. struct device_attribute *attr, char *buf)
  324. {
  325. int retval;
  326. unsigned char proximity_enables;
  327. if (!f51)
  328. return -ENODEV;
  329. retval = synaptics_rmi4_i2c_read(f51->rmi4_data,
  330. f51->proximity_enables_addr,
  331. &proximity_enables, sizeof(proximity_enables));
  332. if (retval < 0) {
  333. dev_err(dev,
  334. "%s: Failed to read proximity enables, error = %d\n", __func__, retval);
  335. return retval;
  336. }
  337. return snprintf(buf, PAGE_SIZE, "0x%02x\n", proximity_enables);
  338. }
  339. static ssize_t synaptics_rmi4_f51_enables_store(struct device *dev,
  340. struct device_attribute *attr, const char *buf,
  341. size_t count)
  342. {
  343. int retval;
  344. unsigned int input;
  345. unsigned char proximity_enables;
  346. if (!f51)
  347. return -ENODEV;
  348. if (kstrtoint(buf, 10, &input))
  349. return -EINVAL;
  350. proximity_enables = input;
  351. retval = synaptics_rmi4_i2c_write(f51->rmi4_data,
  352. f51->proximity_enables_addr,
  353. &proximity_enables, sizeof(proximity_enables));
  354. if (retval < 0) {
  355. dev_err(dev,
  356. "%s: Failed to write proximity enables, error = %d\n", __func__, retval);
  357. return retval;
  358. }
  359. return count;
  360. }
  361. #endif
  362. #if 0
  363. static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
  364. struct device_attribute *attr, const char *buf,
  365. size_t count)
  366. {
  367. /* int retval;
  368. unsigned int reset;
  369. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  370. if (sscanf(buf, "%u", &reset) != 1)
  371. return -EINVAL;
  372. if (reset != 1)
  373. return -EINVAL;
  374. retval = synaptics_rmi4_reset_device(rmi4_data);
  375. if (retval < 0) {
  376. dev_err(dev,
  377. "%s: Failed to issue reset command, error = %d\n",
  378. __func__, retval);
  379. return retval;
  380. }
  381. return count;*/
  382. return 0;
  383. }
  384. static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
  385. struct device_attribute *attr, char *buf)
  386. {
  387. /*struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  388. return snprintf(buf, PAGE_SIZE, "0x%02x 0x%02x\n",
  389. (rmi4_data->rmi4_mod_info.product_info[0]),
  390. (rmi4_data->rmi4_mod_info.product_info[1])); */
  391. return 0;
  392. }
  393. static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
  394. struct device_attribute *attr, char *buf)
  395. {
  396. /*int retval;
  397. struct synaptics_rmi4_f01_device_status device_status;
  398. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  399. retval = synaptics_rmi4_i2c_read(rmi4_data,
  400. rmi4_data->f01_data_base_addr,
  401. device_status.data,
  402. sizeof(device_status.data));
  403. if (retval < 0) {
  404. dev_err(dev,
  405. "%s: Failed to read device status, error = %d\n",
  406. __func__, retval);
  407. return retval;
  408. }
  409. return snprintf(buf, PAGE_SIZE, "%u\n",
  410. device_status.flash_prog); */
  411. return 0;
  412. }
  413. static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
  414. struct device_attribute *attr, char *buf)
  415. {
  416. /* struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  417. return snprintf(buf, PAGE_SIZE, "%d\n",
  418. rmi4_data->button_0d_enabled);*/
  419. return 0;
  420. }
  421. static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev,
  422. struct device_attribute *attr, const char *buf,
  423. size_t count)
  424. {
  425. #if 0
  426. int retval;
  427. unsigned int input;
  428. unsigned char ii;
  429. unsigned char intr_enable;
  430. struct synaptics_rmi4_fn *fhandler;
  431. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  432. struct synaptics_rmi4_device_info *rmi;
  433. rmi = &(rmi4_data->rmi4_mod_info);
  434. if (kstrtoint(buf, 10, &input))
  435. return -EINVAL;
  436. input = input > 0 ? 1 : 0;
  437. if (rmi4_data->button_0d_enabled == input)
  438. return count;
  439. list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
  440. if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) {
  441. ii = fhandler->intr_reg_num;
  442. retval = synaptics_rmi4_i2c_read(rmi4_data,
  443. rmi4_data->f01_ctrl_base_addr + 1 + ii,
  444. &intr_enable, sizeof(intr_enable));
  445. if (retval < 0)
  446. return retval;
  447. if (input == 1)
  448. intr_enable |= fhandler->intr_mask;
  449. else
  450. intr_enable &= ~fhandler->intr_mask;
  451. retval = synaptics_rmi4_i2c_write(rmi4_data,
  452. rmi4_data->f01_ctrl_base_addr + 1 + ii,
  453. &intr_enable, sizeof(intr_enable));
  454. if (retval < 0)
  455. return retval;
  456. }
  457. }
  458. rmi4_data->button_0d_enabled = input;
  459. #endif
  460. return 0;
  461. }
  462. #endif
  463. static int tpd_set_page(struct i2c_client *client, unsigned int address)
  464. {
  465. int retval = 0;
  466. unsigned char retry;
  467. unsigned char buf[PAGE_SELECT_LEN];
  468. unsigned char page;
  469. page = ((address >> 8) & MASK_8BIT);
  470. if (page != ts->current_page) {
  471. buf[0] = MASK_8BIT;
  472. buf[1] = page;
  473. for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
  474. retval = i2c_master_send(client, buf, PAGE_SELECT_LEN);
  475. if (retval != PAGE_SELECT_LEN) {
  476. dev_err(&client->dev, "%s: I2C retry %d\n", __func__, retry + 1);
  477. msleep(20);
  478. } else {
  479. ts->current_page = page;
  480. break;
  481. }
  482. }
  483. } else {
  484. retval = PAGE_SELECT_LEN;
  485. }
  486. return retval;
  487. }
  488. int tpd_i2c_read_data(struct i2c_client *client,
  489. unsigned short addr, unsigned char *data, unsigned short length)
  490. {
  491. u8 retval = 0;
  492. u8 retry = 0;
  493. u8 *pData = data;
  494. int tmp_addr = addr;
  495. int left_len = length;
  496. /* u16 old_flag; */
  497. mutex_lock(&(ts->io_ctrl_mutex));
  498. retval = tpd_set_page(client, addr);
  499. if (retval != PAGE_SELECT_LEN)
  500. goto exit;
  501. /* old_flag = client->ext_flag; */
  502. /* client->addr = client->addr & I2C_MASK_FLAG ; */
  503. /* client->ext_flag =client->ext_flag | I2C_WR_FLAG | I2C_RS_FLAG | I2C_ENEXT_FLAG; */
  504. #if 0
  505. while (left_len > 0) {
  506. pData[0] = tmp_addr;
  507. for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
  508. if (left_len > 8)
  509. retval = i2c_master_send(client, pData, (8 << 8 | 1));
  510. else
  511. retval = i2c_master_send(client, pData, (left_len << 8 | 1));
  512. if (retval > 0) {
  513. break;
  514. dev_err(&client->dev, "%s: I2C retry %d\n", __func__, retry + 1);
  515. msleep(20);
  516. }
  517. left_len -= 8;
  518. pData += 8;
  519. tmp_addr += 8;
  520. }
  521. #else
  522. while (left_len > 0) {
  523. pData[0] = tmp_addr;
  524. for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
  525. retval = i2c_master_send(client, pData, 1);
  526. if (retval <= 0) {
  527. dev_err(&client->dev, "%s: I2C retry %d\n", __func__, retry + 1);
  528. msleep(20);
  529. continue;
  530. }
  531. if (left_len > 8)
  532. retval = i2c_master_recv(client, pData, 8);
  533. else
  534. retval = i2c_master_recv(client, pData, left_len);
  535. if (retval <= 0) {
  536. dev_err(&client->dev, "%s: I2C retry %d\n", __func__, retry + 1);
  537. msleep(20);
  538. continue;
  539. } else
  540. break;
  541. }
  542. left_len -= 8;
  543. pData += 8;
  544. tmp_addr += 8;
  545. }
  546. #endif
  547. /* client->ext_flag = old_flag; */
  548. exit:
  549. mutex_unlock(&(ts->io_ctrl_mutex));
  550. return retval;
  551. }
  552. EXPORT_SYMBOL(tpd_i2c_read_data);
  553. int tpd_i2c_write_data(struct i2c_client *client,
  554. unsigned short addr, unsigned char *data, unsigned short length)
  555. {
  556. u8 retval = 0;
  557. u8 retry = 0;
  558. u8 *pData = data;
  559. u8 buf[5] = { 0 };
  560. int tmp_addr = addr;
  561. int left_len = length;
  562. mutex_lock(&(ts->io_ctrl_mutex));
  563. retval = tpd_set_page(client, addr);
  564. if (retval != PAGE_SELECT_LEN) {
  565. TPD_DMESG("tpd_set_page fail, retval = %d\n", retval);
  566. retval = -EIO;
  567. goto exit;
  568. }
  569. while (left_len > 0) {
  570. buf[0] = tmp_addr;
  571. for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
  572. if (left_len > 4) {
  573. memcpy(buf + 1, pData, 4);
  574. retval = i2c_master_send(client, buf, 5);
  575. } else {
  576. memcpy(buf + 1, pData, left_len);
  577. retval = i2c_master_send(client, buf, left_len + 1);
  578. }
  579. if (retval > 0)
  580. break;
  581. TPD_DMESG("%s: I2C retry %d\n", __func__, retry + 1);
  582. msleep(20);
  583. }
  584. left_len -= 4;
  585. pData += 4;
  586. tmp_addr += 4;
  587. }
  588. exit:
  589. mutex_unlock(&(ts->io_ctrl_mutex));
  590. return retval;
  591. }
  592. EXPORT_SYMBOL(tpd_i2c_write_data);
  593. #if 0
  594. /**
  595. * synaptics_rmi4_f12_abs_report()
  596. *
  597. * Called by synaptics_rmi4_report_touch() when valid Function $12
  598. * finger data has been detected.
  599. *
  600. * This function reads the Function $12 data registers, determines the
  601. * status of each finger supported by the Function, processes any
  602. * necessary coordinate manipulation, reports the finger data to
  603. * the input subsystem, and returns the number of fingers detected.
  604. */
  605. static int synaptics_rmi4_f12_abs_report(struct synaptics_rmi4_data *rmi4_data,
  606. struct synaptics_rmi4_fn *fhandler)
  607. {
  608. int retval;
  609. unsigned char touch_count = 0; /* number of touch points */
  610. unsigned char finger;
  611. unsigned char fingers_supported;
  612. unsigned char finger_status;
  613. unsigned short data_addr;
  614. int x;
  615. int y;
  616. int wx;
  617. int wy;
  618. struct synaptics_rmi4_f12_finger_data *data;
  619. struct synaptics_rmi4_f12_finger_data *finger_data;
  620. fingers_supported = fhandler->num_of_data_points;
  621. data_addr = fhandler->full_addr.data_base;
  622. retval = synaptics_rmi4_i2c_read(rmi4_data,
  623. data_addr + fhandler->data1_offset,
  624. (unsigned char *)fhandler->data, fhandler->data_size);
  625. if (retval < 0)
  626. return 0;
  627. data = (struct synaptics_rmi4_f12_finger_data *)fhandler->data;
  628. for (finger = 0; finger < fingers_supported; finger++) {
  629. finger_data = data + finger;
  630. finger_status = finger_data->object_type_and_status & MASK_2BIT;
  631. /*
  632. * Each 2-bit finger status field represents the following:
  633. * 00 = finger not present
  634. * 01 = finger present and data accurate
  635. * 10 = finger present but data may be inaccurate
  636. * 11 = reserved
  637. */
  638. if ((finger_status == 0x01) || (finger_status == 0x02)) {
  639. x = (finger_data->x_msb << 8) | (finger_data->x_lsb);
  640. y = (finger_data->y_msb << 8) | (finger_data->y_lsb);
  641. wx = finger_data->wx;
  642. wy = finger_data->wy;
  643. if (rmi4_data->board->x_flip)
  644. x = rmi4_data->sensor_max_x - x;
  645. if (rmi4_data->board->y_flip)
  646. y = rmi4_data->sensor_max_y - y;
  647. dev_dbg(&rmi4_data->i2c_client->dev,
  648. "%s: Finger %d:\n"
  649. "status = 0x%02x\n"
  650. "x = %d\n"
  651. "y = %d\n"
  652. "wx = %d\n"
  653. "wy = %d\n", __func__, finger, finger_status, x, y, wx, wy);
  654. input_report_abs(rmi4_data->input_dev, ABS_MT_POSITION_X, x);
  655. input_report_abs(rmi4_data->input_dev, ABS_MT_POSITION_Y, y);
  656. input_report_abs(rmi4_data->input_dev, ABS_MT_TOUCH_MAJOR, max(wx, wy));
  657. input_report_abs(rmi4_data->input_dev, ABS_MT_TOUCH_MINOR, min(wx, wy));
  658. input_mt_sync(rmi4_data->input_dev);
  659. touch_count++;
  660. }
  661. }
  662. if (!touch_count)
  663. input_mt_sync(tpd->dev);
  664. input_sync(tpd->dev);
  665. return touch_count;
  666. }
  667. #endif
  668. #if PROXIMITY
  669. static int synaptics_rmi4_f51_report(struct synaptics_rmi4_data *rmi4_data,
  670. struct synaptics_rmi4_fn *fhandler)
  671. {
  672. int retval;
  673. unsigned char touch_count = 0; /* number of touch points */
  674. unsigned short data_base_addr;
  675. int x;
  676. int y;
  677. int z;
  678. struct synaptics_rmi4_f51_data *data_reg;
  679. data_base_addr = fhandler->full_addr.data_base;
  680. data_reg = (struct synaptics_rmi4_f51_data *)fhandler->data;
  681. retval = tpd_i2c_read(rmi4_data, data_base_addr, data_reg->data, sizeof(data_reg->data));
  682. if (retval < 0)
  683. return 0;
  684. if (data_reg->data[0] == 0x00)
  685. return 0;
  686. #if sdfsdfadf
  687. if (data_reg->finger_hover_det) {
  688. if (data_reg->hover_finger_z > 0) {
  689. x = (data_reg->hover_finger_x_4__11 << 4) |
  690. (data_reg->hover_finger_xy_0__3 & 0x0f);
  691. y = (data_reg->hover_finger_y_4__11 << 4) |
  692. (data_reg->hover_finger_xy_0__3 >> 4);
  693. z = HOVER_Z_MAX - data_reg->hover_finger_z;
  694. dev_dbg(&rmi4_data->i2c_client->dev,
  695. "%s: Hover finger:\n"
  696. "x = %d\n" "y = %d\n" "z = %d\n", __func__, x, y, z);
  697. input_report_abs(tpd->dev, ABS_MT_POSITION_X, x);
  698. input_report_abs(tpd->dev, ABS_MT_POSITION_Y, y);
  699. #ifdef INPUT_MULTITOUCH
  700. input_report_abs(tpd->dev, ABS_MT_DISTANCE, z);
  701. #endif
  702. input_mt_sync(tpd->dev);
  703. touch_count++;
  704. }
  705. }
  706. if (data_reg->air_swipe_det) {
  707. dev_dbg(&rmi4_data->i2c_client->dev,
  708. "%s: Swipe direction 0 = %d\n", __func__, data_reg->air_swipe_dir_0);
  709. dev_dbg(&rmi4_data->i2c_client->dev,
  710. "%s: Swipe direction 1 = %d\n", __func__, data_reg->air_swipe_dir_1);
  711. }
  712. if (data_reg->large_obj_det) {
  713. dev_dbg(&rmi4_data->i2c_client->dev,
  714. "%s: Large object activity = %d\n", __func__, data_reg->large_obj_act);
  715. }
  716. if (data_reg->hover_pinch_det) {
  717. dev_dbg(&rmi4_data->i2c_client->dev,
  718. "%s: Hover pinch direction = %d\n", __func__, data_reg->hover_pinch_dir);
  719. }
  720. #endif
  721. if (!touch_count)
  722. input_mt_sync(tpd->dev);
  723. input_sync(tpd->dev);
  724. return touch_count;
  725. }
  726. #endif
  727. #if 0
  728. /*
  729. * synaptics_rmi4_f12_init()
  730. *
  731. * Called by synaptics_rmi4_query_device().
  732. *
  733. * This function parses information from the Function 12 registers and
  734. * determines the number of fingers supported, offset to the data1
  735. * register, x and y data ranges, offset to the associated interrupt
  736. * status register, interrupt bit mask, and allocates memory resources
  737. * for finger data acquisition.
  738. */
  739. static int synaptics_rmi4_f12_init(struct synaptics_rmi4_data *rmi4_data,
  740. struct synaptics_rmi4_fn *fhandler,
  741. struct synaptics_rmi4_fn_desc *fd, unsigned int intr_count)
  742. {
  743. int retval;
  744. unsigned char ii;
  745. unsigned char intr_offset;
  746. unsigned char ctrl_8_offset;
  747. unsigned char ctrl_23_offset;
  748. struct synaptics_rmi4_f12_query_5 query_5;
  749. struct synaptics_rmi4_f12_query_8 query_8;
  750. struct synaptics_rmi4_f12_ctrl_8 ctrl_8;
  751. struct synaptics_rmi4_f12_ctrl_23 ctrl_23;
  752. struct synaptics_rmi4_f12_finger_data *finger_data_list;
  753. fhandler->fn_number = fd->fn_number;
  754. fhandler->num_of_data_sources = fd->intr_src_count;
  755. retval = synaptics_rmi4_i2c_read(rmi4_data,
  756. fhandler->full_addr.query_base + 5,
  757. query_5.data, sizeof(query_5.data));
  758. if (retval < 0)
  759. return retval;
  760. ctrl_8_offset = query_5.ctrl0_is_present +
  761. query_5.ctrl1_is_present +
  762. query_5.ctrl2_is_present +
  763. query_5.ctrl3_is_present +
  764. query_5.ctrl4_is_present +
  765. query_5.ctrl5_is_present + query_5.ctrl6_is_present + query_5.ctrl7_is_present;
  766. ctrl_23_offset = ctrl_8_offset +
  767. query_5.ctrl8_is_present +
  768. query_5.ctrl9_is_present +
  769. query_5.ctrl10_is_present +
  770. query_5.ctrl11_is_present +
  771. query_5.ctrl12_is_present +
  772. query_5.ctrl13_is_present +
  773. query_5.ctrl14_is_present +
  774. query_5.ctrl15_is_present +
  775. query_5.ctrl16_is_present +
  776. query_5.ctrl17_is_present +
  777. query_5.ctrl18_is_present +
  778. query_5.ctrl19_is_present +
  779. query_5.ctrl20_is_present + query_5.ctrl21_is_present + query_5.ctrl22_is_present;
  780. retval = synaptics_rmi4_i2c_read(rmi4_data,
  781. fhandler->full_addr.ctrl_base + ctrl_23_offset,
  782. ctrl_23.data, sizeof(ctrl_23.data));
  783. if (retval < 0)
  784. return retval;
  785. /* Maximum number of fingers supported */
  786. fhandler->num_of_data_points = ctrl_23.max_reported_objects;
  787. retval = synaptics_rmi4_i2c_read(rmi4_data,
  788. fhandler->full_addr.query_base + 8,
  789. query_8.data, sizeof(query_8.data));
  790. if (retval < 0)
  791. return retval;
  792. /* Determine the presence of the Data0 register */
  793. fhandler->data1_offset = query_8.data0_is_present;
  794. retval = synaptics_rmi4_i2c_read(rmi4_data,
  795. fhandler->full_addr.ctrl_base + ctrl_8_offset,
  796. ctrl_8.data, sizeof(ctrl_8.data));
  797. if (retval < 0)
  798. return retval;
  799. /* Maximum x and y */
  800. rmi4_data->sensor_max_x =
  801. ((unsigned short)ctrl_8.max_x_coord_lsb << 0) |
  802. ((unsigned short)ctrl_8.max_x_coord_msb << 8);
  803. rmi4_data->sensor_max_y =
  804. ((unsigned short)ctrl_8.max_y_coord_lsb << 0) |
  805. ((unsigned short)ctrl_8.max_y_coord_msb << 8);
  806. dev_dbg(&rmi4_data->i2c_client->dev,
  807. "%s: Function %02x max x = %d max y = %d\n",
  808. __func__, fhandler->fn_number, rmi4_data->sensor_max_x, rmi4_data->sensor_max_y);
  809. rmi4_data->num_of_rx = ctrl_8.num_of_rx;
  810. rmi4_data->num_of_tx = ctrl_8.num_of_tx;
  811. fhandler->intr_reg_num = (intr_count + 7) / 8;
  812. if (fhandler->intr_reg_num != 0)
  813. fhandler->intr_reg_num -= 1;
  814. /* Set an enable bit for each data source */
  815. intr_offset = intr_count % 8;
  816. fhandler->intr_mask = 0;
  817. for (ii = intr_offset; ii < ((fd->intr_src_count & MASK_3BIT) + intr_offset); ii++)
  818. fhandler->intr_mask |= 1 << ii;
  819. /* Allocate memory for finger data storage space */
  820. fhandler->data_size = fhandler->num_of_data_points *
  821. sizeof(struct synaptics_rmi4_f12_finger_data);
  822. finger_data_list = kmalloc(fhandler->data_size, GFP_KERNEL);
  823. fhandler->data = (void *)finger_data_list;
  824. return retval;
  825. }
  826. #endif
  827. #if PROXIMITY
  828. static int synaptics_rmi4_f51_init(struct synaptics_rmi4_data *rmi4_data,
  829. struct synaptics_rmi4_fn *fhandler,
  830. struct synaptics_rmi4_fn_desc *fd, unsigned int intr_count)
  831. {
  832. int retval;
  833. unsigned char ii;
  834. unsigned short intr_offset;
  835. unsigned char proximity_enable_mask = PROXIMITY_ENABLE;
  836. struct synaptics_rmi4_f51_query query_register;
  837. struct synaptics_rmi4_f51_data *data_register;
  838. fhandler->fn_number = fd->fn_number;
  839. fhandler->num_of_data_sources = fd->intr_src_count;
  840. fhandler->intr_reg_num = (intr_count + 7) / 8;
  841. if (fhandler->intr_reg_num != 0)
  842. fhandler->intr_reg_num -= 1;
  843. /* Set an enable bit for each data source */
  844. intr_offset = intr_count % 8;
  845. fhandler->intr_mask = 0;
  846. for (ii = intr_offset; ii < ((fd->intr_src_count & MASK_3BIT) + intr_offset); ii++)
  847. fhandler->intr_mask |= 1 << ii;
  848. retval = synaptics_rmi4_i2c_read(rmi4_data,
  849. fhandler->full_addr.query_base,
  850. query_register.data, sizeof(query_register.data));
  851. if (retval < 0)
  852. return retval;
  853. fhandler->data_size = sizeof(data_register->data);
  854. data_register = kmalloc(fhandler->data_size, GFP_KERNEL);
  855. fhandler->data = (void *)data_register;
  856. retval = synaptics_rmi4_i2c_write(rmi4_data,
  857. fhandler->full_addr.ctrl_base +
  858. query_register.control_register_count - 1,
  859. &proximity_enable_mask, sizeof(proximity_enable_mask));
  860. if (retval < 0)
  861. return retval;
  862. f51 = kmalloc(sizeof(*f51), GFP_KERNEL);
  863. f51->rmi4_data = rmi4_data;
  864. f51->proximity_enables_addr = fhandler->full_addr.ctrl_base +
  865. query_register.control_register_count - 1;
  866. return 0;
  867. }
  868. int synaptics_rmi4_proximity_enables(unsigned char enables)
  869. {
  870. int retval;
  871. unsigned char proximity_enables = enables;
  872. if (!f51)
  873. return -ENODEV;
  874. retval = synaptics_rmi4_i2c_write(f51->rmi4_data,
  875. f51->proximity_enables_addr,
  876. &proximity_enables, sizeof(proximity_enables));
  877. if (retval < 0)
  878. return retval;
  879. return 0;
  880. }
  881. EXPORT_SYMBOL(synaptics_rmi4_proximity_enables);
  882. #endif
  883. static int tpd_rmi4_read_pdt(struct tpd_data *ts)
  884. {
  885. int retval;
  886. unsigned char ii;
  887. unsigned char offset = 0;
  888. unsigned char page_number;
  889. unsigned char intr_count = 0;
  890. /* unsigned char data_sources = 0; */
  891. /* unsigned char f01_query[F01_STD_QUERY_LEN]; */
  892. unsigned char f11_query[F11_STD_QUERY_LEN];
  893. unsigned int f11_max_xy;
  894. /* u8 point_length; */
  895. unsigned short pdt_entry_addr;
  896. /* unsigned short intr_addr; */
  897. static unsigned char intsrc = 1;
  898. /* struct synaptics_rmi4_f01_device_status status; */
  899. struct synaptics_rmi4_fn_desc rmi_fd;
  900. /* Scan the page description tables of the pages to service */
  901. for (page_number = 0; page_number < PAGES_TO_SERVICE; page_number++) {
  902. for (pdt_entry_addr = PDT_START; pdt_entry_addr > PDT_END;
  903. pdt_entry_addr -= PDT_ENTRY_SIZE) {
  904. pdt_entry_addr |= (page_number << 8);
  905. retval = tpd_i2c_read_data(ts->client,
  906. pdt_entry_addr,
  907. (unsigned char *)&rmi_fd, sizeof(rmi_fd));
  908. if (retval < 0)
  909. return retval;
  910. if (rmi_fd.fn_number == 0) {
  911. dev_dbg(&ts->client->dev, "%s: Reached end of PDT\n", __func__);
  912. break;
  913. }
  914. dev_dbg(&ts->client->dev,
  915. "%s: F%02x found (page %d)\n",
  916. __func__, rmi_fd.fn_number, page_number);
  917. switch (rmi_fd.fn_number) {
  918. case SYNAPTICS_RMI4_F01:
  919. ts->f01.query_base = rmi_fd.query_base_addr;
  920. ts->f01.ctrl_base = rmi_fd.ctrl_base_addr;
  921. ts->f01.cmd_base = rmi_fd.cmd_base_addr;
  922. ts->f01.data_base = rmi_fd.data_base_addr;
  923. ts->f01.intSrc = intsrc++;
  924. ts->f01.functionNumber = rmi_fd.fn_number;
  925. break;
  926. case SYNAPTICS_RMI4_F11:
  927. if (rmi_fd.intr_src_count == 0)
  928. break;
  929. ts->f11.query_base = rmi_fd.query_base_addr;
  930. ts->f11.ctrl_base = rmi_fd.ctrl_base_addr;
  931. ts->f11.cmd_base = rmi_fd.cmd_base_addr;
  932. ts->f11.data_base = rmi_fd.data_base_addr;
  933. ts->f11.intSrc = intsrc++;
  934. ts->f11.functionNumber = rmi_fd.fn_number;
  935. ts->fn11_mask = 0;
  936. offset = intr_count % 8;
  937. for (ii = offset; ii < (rmi_fd.intr_src_count + offset); ii++)
  938. ts->fn11_mask |= 1 << ii;
  939. retval =
  940. tpd_i2c_read_data(ts->client, ts->f11.query_base, f11_query,
  941. sizeof(f11_query));
  942. if (retval < 0)
  943. return retval;
  944. TPD_DEBUG("f11 query base=%d\n", ts->f11.query_base);
  945. /* Maximum number of fingers supported */
  946. if ((f11_query[1] & MASK_3BIT) <= 4) {
  947. ts->points_supported = (f11_query[1] & MASK_3BIT) + 1;
  948. TPD_DEBUG("points_supported=%d\n", ts->points_supported);
  949. } else if ((f11_query[1] & MASK_3BIT) == 5) {
  950. ts->points_supported = 10;
  951. TPD_DEBUG("points_supported=%d\n", ts->points_supported);
  952. }
  953. retval =
  954. tpd_i2c_read_data(ts->client, ts->f11.ctrl_base + 6,
  955. (char *)(&f11_max_xy), sizeof(f11_max_xy));
  956. if (retval < 0)
  957. return retval;
  958. /* Maximum x and y */
  959. ts->f11_max_x = f11_max_xy & 0xFFF;
  960. ts->f11_max_y = (f11_max_xy >> 16) & 0xFFF;
  961. ts->pre_points =
  962. kzalloc(ts->points_supported * sizeof(struct point),
  963. GFP_KERNEL);
  964. if (ts->pre_points == NULL) {
  965. TPD_DMESG("Error zalloc failed!\n");
  966. retval = -ENOMEM;
  967. return retval;
  968. }
  969. ts->cur_points =
  970. kzalloc(ts->points_supported * sizeof(struct point),
  971. GFP_KERNEL);
  972. if (ts->cur_points == NULL) {
  973. TPD_DMESG("Error zalloc failed!\n");
  974. retval = -ENOMEM;
  975. return retval;
  976. }
  977. ts->data_length =
  978. 3 + (2 * ((f11_query[5] & MASK_2BIT) == 0 ? 1 : 0));
  979. break;
  980. case SYNAPTICS_RMI4_F12:
  981. /*if (rmi_fd.intr_src_count == 0)
  982. break;
  983. retval = synaptics_rmi4_alloc_fh(&fhandler,
  984. &rmi_fd, page_number);
  985. if (retval < 0) {
  986. dev_err(&rmi4_data->i2c_client->dev,
  987. "%s: Failed to alloc for F%d\n",
  988. __func__,
  989. rmi_fd.fn_number);
  990. return retval;
  991. }
  992. retval = synaptics_rmi4_f12_init(rmi4_data,
  993. fhandler, &rmi_fd, intr_count);
  994. if (retval < 0)
  995. return retval; */
  996. break;
  997. case SYNAPTICS_RMI4_F1A:
  998. if (rmi_fd.intr_src_count == 0)
  999. break;
  1000. ts->f1a.query_base = rmi_fd.query_base_addr;
  1001. ts->f1a.ctrl_base = rmi_fd.ctrl_base_addr;
  1002. ts->f1a.cmd_base = rmi_fd.cmd_base_addr;
  1003. ts->f1a.data_base = rmi_fd.data_base_addr;
  1004. ts->f01.intSrc = intsrc++;
  1005. ts->f01.functionNumber = rmi_fd.fn_number;
  1006. td->button_0d_enabled = 1;
  1007. ts->fn1a_mask = 0;
  1008. offset = intr_count % 8;
  1009. for (ii = offset; ii < (rmi_fd.intr_src_count + offset); ii++)
  1010. ts->fn1a_mask |= 1 << ii;
  1011. break;
  1012. #if PROXIMITY
  1013. case SYNAPTICS_RMI4_F51:
  1014. if (rmi_fd.intr_src_count == 0)
  1015. break;
  1016. /*retval = synaptics_rmi4_alloc_fh(&fhandler,
  1017. &rmi_fd, page_number);
  1018. if (retval < 0) {
  1019. dev_err(&rmi4_data->i2c_client->dev,
  1020. "%s: Failed to alloc for F%d\n",
  1021. __func__,
  1022. rmi_fd.fn_number);
  1023. return retval;
  1024. }
  1025. retval = synaptics_rmi4_f51_init(rmi4_data,
  1026. fhandler, &rmi_fd, intr_count);
  1027. if (retval < 0)
  1028. return retval; */
  1029. break;
  1030. #endif
  1031. }
  1032. if (rmi_fd.intr_src_count & 0x03)
  1033. intr_count += rmi_fd.intr_src_count & 0x03;
  1034. }
  1035. }
  1036. #if 0
  1037. flash_prog_mode:
  1038. rmi4_data->num_of_intr_regs = (intr_count + 7) / 8;
  1039. dev_dbg(&rmi4_data->i2c_client->dev,
  1040. "%s: Number of interrupt registers = %d\n", __func__, rmi4_data->num_of_intr_regs);
  1041. retval = synaptics_rmi4_i2c_read(rmi4_data,
  1042. rmi4_data->f01_query_base_addr,
  1043. f01_query, sizeof(f01_query));
  1044. if (retval < 0)
  1045. return retval;
  1046. /* RMI Version 4.0 currently supported */
  1047. rmi->version_major = 4;
  1048. rmi->version_minor = 0;
  1049. rmi->manufacturer_id = f01_query[0];
  1050. rmi->product_props = f01_query[1];
  1051. rmi->product_info[0] = f01_query[2] & MASK_7BIT;
  1052. rmi->product_info[1] = f01_query[3] & MASK_7BIT;
  1053. rmi->date_code[0] = f01_query[4] & MASK_5BIT;
  1054. rmi->date_code[1] = f01_query[5] & MASK_4BIT;
  1055. rmi->date_code[2] = f01_query[6] & MASK_5BIT;
  1056. rmi->tester_id = ((f01_query[7] & MASK_7BIT) << 8) | (f01_query[8] & MASK_7BIT);
  1057. rmi->serial_number = ((f01_query[9] & MASK_7BIT) << 8) | (f01_query[10] & MASK_7BIT);
  1058. memcpy(rmi->product_id_string, &f01_query[11], 10);
  1059. if (rmi->manufacturer_id != 1) {
  1060. dev_err(&rmi4_data->i2c_client->dev,
  1061. "%s: Non-Synaptics device found, manufacturer ID = %d\n",
  1062. __func__, rmi->manufacturer_id);
  1063. }
  1064. memset(rmi4_data->intr_mask, 0x00, sizeof(rmi4_data->intr_mask));
  1065. /*
  1066. * Map out the interrupt bit masks for the interrupt sources
  1067. * from the registered function handlers.
  1068. */
  1069. list_for_each_entry(fhandler, &rmi->support_fn_list, link)
  1070. data_sources += fhandler->num_of_data_sources;
  1071. if (data_sources) {
  1072. list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
  1073. if (fhandler->num_of_data_sources)
  1074. rmi4_data->intr_mask[fhandler->intr_reg_num] |= fhandler->intr_mask;
  1075. }
  1076. }
  1077. /* Enable the interrupt sources */
  1078. for (ii = 0; ii < rmi4_data->num_of_intr_regs; ii++) {
  1079. if (rmi4_data->intr_mask[ii] != 0x00) {
  1080. dev_dbg(&rmi4_data->i2c_client->dev,
  1081. "%s: Interrupt enable mask %d = 0x%02x\n",
  1082. __func__, ii, rmi4_data->intr_mask[ii]);
  1083. intr_addr = rmi4_data->f01_ctrl_base_addr + 1 + ii;
  1084. retval = synaptics_rmi4_i2c_write(rmi4_data,
  1085. intr_addr,
  1086. &(rmi4_data->intr_mask[ii]),
  1087. sizeof(rmi4_data->intr_mask[ii]));
  1088. if (retval < 0)
  1089. return retval;
  1090. }
  1091. }
  1092. #endif
  1093. return 0;
  1094. }
  1095. /**
  1096. * synaptics_rmi4_detection_work()
  1097. *
  1098. * Called by the kernel at the scheduled time.
  1099. *
  1100. * This function is a self-rearming work thread that checks for the
  1101. * insertion and removal of other expansion Function modules such as
  1102. * rmi_dev and calls their initialization and removal callback functions
  1103. * accordingly.
  1104. */
  1105. #ifdef TPD_UPDATE_FIRMWARE
  1106. static void synaptics_rmi4_detection_work(struct work_struct *work)
  1107. {
  1108. struct synaptics_rmi4_exp_fn *exp_fhandler, *next_list_entry;
  1109. /* queue_delayed_work(det_workqueue,&det_work,msecs_to_jiffies(EXP_FN_DET_INTERVAL)); */
  1110. mutex_lock(&exp_fn_list_mutex);
  1111. if (!list_empty(&exp_fn_list)) {
  1112. list_for_each_entry_safe(exp_fhandler, next_list_entry, &exp_fn_list, link) {
  1113. if ((exp_fhandler->func_init != NULL) && (exp_fhandler->inserted == false)) {
  1114. exp_fhandler->func_init(ts->client);
  1115. exp_fhandler->inserted = true;
  1116. } else if ((exp_fhandler->func_init == NULL) &&
  1117. (exp_fhandler->inserted == true)) {
  1118. exp_fhandler->func_remove(ts->client);
  1119. list_del(&exp_fhandler->link);
  1120. kfree(exp_fhandler);
  1121. }
  1122. }
  1123. }
  1124. mutex_unlock(&exp_fn_list_mutex);
  1125. }
  1126. static int touch_update_handler(void *unused)
  1127. {
  1128. int retval = 0;
  1129. msleep(10000);
  1130. TPD_DEBUG("start to touch_update_handler\n");
  1131. mutex_lock(&i2c_access);
  1132. if (tpd_halt) {
  1133. mutex_unlock(&i2c_access);
  1134. TPD_DMESG("the touch has been suspend\n");
  1135. return 0;
  1136. }
  1137. disable_irq(touch_irq);
  1138. synaptics_rmi4_detection_work(NULL);
  1139. /* synaptics_fw_updater(synaImage); */
  1140. synaptics_fw_updater(NULL); /* auto detect by sensor id */
  1141. retval = tpd_rmi4_read_pdt(ts);
  1142. if (retval < 0)
  1143. TPD_DMESG("Failed to query device\n");
  1144. tpd_clear_interrupt(ts->client);
  1145. enable_irq(touch_irq);
  1146. mutex_unlock(&i2c_access);
  1147. return 0;
  1148. }
  1149. #endif
  1150. /**
  1151. * synaptics_rmi4_new_function()
  1152. *
  1153. * Called by other expansion Function modules in their module init and
  1154. * module exit functions.
  1155. *
  1156. * This function is used by other expansion Function modules such as
  1157. * rmi_dev to register themselves with the driver by providing their
  1158. * initialization and removal callback function pointers so that they
  1159. * can be inserted or removed dynamically at module init and exit times,
  1160. * respectively.
  1161. */
  1162. void synaptics_rmi4_new_function(enum exp_fn fn_type, bool insert,
  1163. int (*func_init)(struct i2c_client *client),
  1164. void (*func_remove)(struct i2c_client *client),
  1165. void (*func_attn)(struct i2c_client *client,
  1166. unsigned char intr_mask))
  1167. {
  1168. struct synaptics_rmi4_exp_fn *exp_fhandler;
  1169. if (!exp_fn_inited) {
  1170. mutex_init(&exp_fn_list_mutex);
  1171. INIT_LIST_HEAD(&exp_fn_list);
  1172. exp_fn_inited = 1;
  1173. }
  1174. mutex_lock(&exp_fn_list_mutex);
  1175. if (insert) {
  1176. exp_fhandler = kzalloc(sizeof(*exp_fhandler), GFP_KERNEL);
  1177. if (!exp_fhandler) {
  1178. pr_err("%s: Failed to alloc mem for expansion function\n", __func__);
  1179. goto exit;
  1180. }
  1181. exp_fhandler->fn_type = fn_type;
  1182. exp_fhandler->func_init = func_init;
  1183. exp_fhandler->func_attn = func_attn;
  1184. exp_fhandler->func_remove = func_remove;
  1185. exp_fhandler->inserted = false;
  1186. list_add_tail(&exp_fhandler->link, &exp_fn_list);
  1187. } else {
  1188. list_for_each_entry(exp_fhandler, &exp_fn_list, link) {
  1189. if (exp_fhandler->func_init == func_init) {
  1190. exp_fhandler->inserted = false;
  1191. exp_fhandler->func_init = NULL;
  1192. exp_fhandler->func_attn = NULL;
  1193. goto exit;
  1194. }
  1195. }
  1196. }
  1197. exit:
  1198. mutex_unlock(&exp_fn_list_mutex);
  1199. }
  1200. EXPORT_SYMBOL(synaptics_rmi4_new_function);
  1201. static void tpd_down(int x, int y, int p, int id)
  1202. {
  1203. input_report_key(tpd->dev, BTN_TOUCH, 1);
  1204. input_report_abs(tpd->dev, ABS_MT_TRACKING_ID, id);
  1205. /* input_report_abs(tpd->dev, ABS_PRESSURE, p); */
  1206. input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, p);
  1207. input_report_abs(tpd->dev, ABS_MT_POSITION_X, x);
  1208. input_report_abs(tpd->dev, ABS_MT_POSITION_Y, y);
  1209. input_mt_sync(tpd->dev);
  1210. TPD_DEBUG_SET_TIME;
  1211. TPD_EM_PRINT(x, y, x, y, 0, 1);
  1212. if (tpd_dts_data.use_tpd_button) {
  1213. if (FACTORY_BOOT == boot_mode || RECOVERY_BOOT == boot_mode)
  1214. tpd_button(x, y, 1);
  1215. }
  1216. }
  1217. static void tpd_up(int x, int y)
  1218. {
  1219. input_report_key(tpd->dev, BTN_TOUCH, 0);
  1220. TPD_DEBUG_SET_TIME;
  1221. TPD_EM_PRINT(x, y, x, y, 0, 0);
  1222. if (tpd_dts_data.use_tpd_button) {
  1223. if (FACTORY_BOOT == boot_mode || RECOVERY_BOOT == boot_mode)
  1224. tpd_button(x, y, 0);
  1225. }
  1226. }
  1227. static int touch_event_handler(void *unused)
  1228. {
  1229. struct sched_param param = {.sched_priority = 4 };
  1230. u16 temp = 0;
  1231. u8 i = 0;
  1232. u8 status = 0;
  1233. u8 retval = 0;
  1234. u8 finger_num = 0;
  1235. u8 finger_status = 0;
  1236. u8 finger_status_reg[3];
  1237. u8 data[F11_STD_DATA_LEN];
  1238. u8 num_of_finger_status_regs = 0;
  1239. u8 button = 0;
  1240. struct point *ppt = NULL;
  1241. #ifdef HAVE_TOUCH_KEY
  1242. struct point ppt_v = { 0 };
  1243. #endif
  1244. sched_setscheduler(current, SCHED_RR, &param);
  1245. do {
  1246. set_current_state(TASK_INTERRUPTIBLE);
  1247. wait_event_interruptible(waiter, tpd_flag != 0);
  1248. tpd_flag = 0;
  1249. set_current_state(TASK_RUNNING);
  1250. mutex_lock(&i2c_access);
  1251. if (tpd_halt) {
  1252. mutex_unlock(&i2c_access);
  1253. TPD_DEBUG("return for interrupt after suspend...");
  1254. continue;
  1255. }
  1256. /* clear interrupt bit */
  1257. retval = tpd_i2c_read_data(ts->client, ts->f01.data_base + 1, &status, 1);
  1258. if (retval < 0) {
  1259. /* disable_irq_nosync(touch_irq);*/
  1260. mutex_unlock(&i2c_access);
  1261. /* enable_irq(touch_irq);*/
  1262. continue;
  1263. }
  1264. if (status & ts->fn11_mask) {
  1265. tpd_i2c_read_data(ts->client, ts->f11.data_base, finger_status_reg,
  1266. (ts->points_supported + 3) / 4);
  1267. num_of_finger_status_regs = (ts->points_supported + 3) / 4;
  1268. finger_num = ts->points_supported;
  1269. for (i = 0; i < ts->points_supported; i++) {
  1270. finger_status = finger_status_reg[i / 4];
  1271. finger_status = (finger_status >> ((i % 4) * 2)) & 3;
  1272. ppt = &ts->cur_points[i];
  1273. ppt->status = finger_status;
  1274. if (0x01 == finger_status || 0x02 == finger_status) {
  1275. temp =
  1276. ts->f11.data_base + num_of_finger_status_regs +
  1277. i * ts->data_length;
  1278. tpd_i2c_read_data(ts->client,
  1279. ts->f11.data_base +
  1280. num_of_finger_status_regs +
  1281. i * ts->data_length, data,
  1282. ts->data_length);
  1283. ppt->raw_x = ppt->x =
  1284. (((u16) (data[0]) << 4) | (data[2] & 0x0F));
  1285. ppt->raw_y = ppt->y =
  1286. (((u16) (data[1]) << 4) | ((data[2] >> 4) & 0x0F));
  1287. ppt->z = data[4];
  1288. TPD_DEBUG("Touch point %d: [X:%04d, Y:%04d]",
  1289. i, ppt->x, ppt->y);
  1290. tpd_down(ppt->x, ppt->y, ppt->z, i);
  1291. } else {
  1292. finger_num--;
  1293. }
  1294. }
  1295. }
  1296. #ifdef HAVE_TOUCH_KEY
  1297. if (status & ts->fn1a_mask)
  1298. retval = tpd_i2c_read_data(ts->client, 0x200, &button, 1);
  1299. if (button) {
  1300. for (i = 0; i < MAX_KEY_NUM; i++) {
  1301. if (button & (0x01 << i)) {
  1302. ppt_v.x = tpd_keys_dim_local_wvga[i][0];
  1303. ppt_v.y = tpd_keys_dim_local_wvga[i][1];
  1304. tpd_down(ppt_v.x, ppt_v.y, 20, 10 + i);
  1305. }
  1306. }
  1307. }
  1308. #endif
  1309. mutex_unlock(&i2c_access);
  1310. if (!finger_num && !button)
  1311. tpd_up(0, 0);
  1312. input_sync(tpd->dev);
  1313. /* ts->pre_points = ts->cur_points; */
  1314. /* disable_irq_nosync(touch_irq);*/
  1315. /* enable_irq(touch_irq);*/
  1316. } while (!kthread_should_stop());
  1317. return 0;
  1318. }
  1319. static irqreturn_t tpd_eint_handler(int irq, void *dev_id)
  1320. {
  1321. TPD_DEBUG_PRINT_INT;
  1322. tpd_flag = 1;
  1323. wake_up_interruptible(&waiter);
  1324. return IRQ_HANDLED;
  1325. }
  1326. #if 0
  1327. static int tpd_sw_power(struct i2c_client *client, int on)
  1328. {
  1329. int retval = 0;
  1330. u8 device_ctrl = 0;
  1331. retval = tpd_i2c_read_data(client, ts->f01.ctrl_base, &device_ctrl, sizeof(device_ctrl));
  1332. if (retval < 0) {
  1333. TPD_DMESG("Error sensor can not wake up\n");
  1334. goto out;
  1335. }
  1336. if (on) {
  1337. device_ctrl = (device_ctrl & ~MASK_3BIT);
  1338. device_ctrl = (device_ctrl | NO_SLEEP_OFF | NORMAL_OPERATION);
  1339. retval = tpd_i2c_write_data(client,
  1340. ts->f01.ctrl_base, &device_ctrl, sizeof(device_ctrl));
  1341. if (retval < 0) {
  1342. TPD_DMESG("Error touch can not leave very-low power state\n");
  1343. goto out;
  1344. }
  1345. } else {
  1346. device_ctrl = (device_ctrl & ~MASK_3BIT);
  1347. device_ctrl = (device_ctrl | NO_SLEEP_OFF | SENSOR_SLEEP);
  1348. retval = tpd_i2c_write_data(client,
  1349. ts->f01.ctrl_base, &device_ctrl, sizeof(device_ctrl));
  1350. if (retval < 0) {
  1351. TPD_DMESG("Error touch can not enter very-low power state\n");
  1352. goto out;
  1353. }
  1354. }
  1355. out:
  1356. return retval;
  1357. }
  1358. #endif
  1359. static int tpd_detect(struct i2c_client *client, struct i2c_board_info *info)
  1360. {
  1361. strcpy(info->type, TPD_DEVICE);
  1362. return 0;
  1363. }
  1364. static int tpd_remove(struct i2c_client *client)
  1365. {
  1366. TPD_DEBUG("TPD removed\n");
  1367. return 0;
  1368. }
  1369. static int tpd_clear_interrupt(struct i2c_client *client)
  1370. {
  1371. int retval = 0;
  1372. u8 status = 0;
  1373. retval = tpd_i2c_read_data(client, ts->f01.data_base + 1, &status, 1);
  1374. if (retval < 0)
  1375. dev_err(&client->dev, "%s: Failed to enable attention interrupt\n", __func__);
  1376. return retval;
  1377. }
  1378. static int tpd_probe(struct i2c_client *client, const struct i2c_device_id *id)
  1379. {
  1380. /* u8 ii; */
  1381. u8 attr_count;
  1382. /* u8 status = 0; */
  1383. int retval;
  1384. /* int i; */
  1385. u8 data;
  1386. int reset_count = 3;
  1387. /* unsigned char config_id[4]; */
  1388. /* unsigned char tp_id[8]; */
  1389. /* unsigned int config_id_no = 0; */
  1390. /* u16 tp_x_for_lcd=0; */
  1391. /* u16 tp_y_for_lcd=0; */
  1392. /* struct synaptics_rmi4_fn *fhandler; */
  1393. /* struct synaptics_rmi4_data *rmi4_data; */
  1394. /* struct synaptics_rmi4_device_info *rmi; */
  1395. struct task_struct *thread = NULL;
  1396. TPD_DMESG("%s:enter\n", __func__);
  1397. TPD_RESET_PROBE:
  1398. #if 0
  1399. if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
  1400. dev_err(&client->dev, "SMBus byte data not supported\n");
  1401. return -EIO;
  1402. }
  1403. #endif
  1404. ts = kzalloc(sizeof(struct tpd_data), GFP_KERNEL);
  1405. if (!ts) {
  1406. TPD_DMESG("Failed to alloc mem for tpd_data\n");
  1407. return -ENOMEM;
  1408. }
  1409. td = kzalloc(sizeof(struct tpd_debug), GFP_KERNEL);
  1410. if (!td)
  1411. TPD_DMESG("Failed to alloc mem for tpd_debug\n");
  1412. ts->client = client;
  1413. mutex_init(&(ts->io_ctrl_mutex));
  1414. of_get_synaptic_platform_data(&client->dev);
  1415. /* configure the gpio pins */
  1416. retval = gpio_request_one(tpd_rst_gpio_number, GPIOF_OUT_INIT_LOW,
  1417. "touchp_reset");
  1418. if (retval < 0) {
  1419. TPD_DMESG("Unable to request gpio reset_pin\n");
  1420. return -1;
  1421. }
  1422. retval = gpio_request_one(tpd_int_gpio_number, GPIOF_IN,
  1423. "tpd_int");
  1424. if (retval < 0) {
  1425. TPD_DMESG("Unable to request gpio int_pin\n");
  1426. gpio_free(tpd_rst_gpio_number);
  1427. return -1;
  1428. }
  1429. retval = regulator_enable(tpd->reg);
  1430. if (retval != 0) {
  1431. dev_err(&client->dev, "Failed to enable reg-vgp6: %d\n", retval);
  1432. goto err_query_device;
  1433. }
  1434. retval = regulator_enable(tpd->io_reg);
  1435. if (retval != 0) {
  1436. dev_err(&client->dev, "Failed to enable reg-vgp4: %d\n", retval);
  1437. goto err_query_device;
  1438. }
  1439. msleep(20);
  1440. /*tpd_gpio_output(GTP_RST_PORT, 0);*/
  1441. gpio_direction_output(tpd_rst_gpio_number, 0);
  1442. msleep(50);
  1443. /*tpd_gpio_output(GTP_RST_PORT, 1);*/
  1444. gpio_direction_output(tpd_rst_gpio_number, 1);
  1445. msleep(50);
  1446. if ((tpd_i2c_read_data(ts->client, 0xEE, &data, 1)) < 0) {
  1447. if (reset_count-- > 0)
  1448. goto TPD_RESET_PROBE;
  1449. dev_err(&client->dev, "Can't connect touch panel.\n");
  1450. return -1;
  1451. }
  1452. retval = tpd_rmi4_read_pdt(ts);
  1453. if (retval < 0) {
  1454. dev_err(&client->dev, "Failed to query device\n");
  1455. goto err_query_device;
  1456. }
  1457. if (!exp_fn_inited) {
  1458. mutex_init(&exp_fn_list_mutex);
  1459. INIT_LIST_HEAD(&exp_fn_list);
  1460. exp_fn_inited = 1;
  1461. }
  1462. tpd_clear_interrupt(client);
  1463. properties_kobj_synap = kobject_create_and_add("synapics", NULL);
  1464. #ifdef HAVE_TOUCH_KEY
  1465. set_bit(EV_KEY, tpd->dev->evbit);
  1466. for (i = 0; i < MAX_KEY_NUM; i++)
  1467. __set_bit(touch_key_array[i], tpd->dev->keybit);
  1468. #endif
  1469. #ifdef VELOCITY_CUSTOM
  1470. tpd_v_magnify_x = TPD_VELOCITY_CUSTOM_X;
  1471. tpd_v_magnify_y = TPD_VELOCITY_CUSTOM_Y;
  1472. #endif
  1473. #ifdef TPD_UPDATE_FIRMWARE
  1474. thread = kthread_run(touch_update_handler, 0, TPD_DEVICE);
  1475. if (IS_ERR(thread)) {
  1476. retval = PTR_ERR(thread);
  1477. TPD_DMESG("failed to create kernel thread: %d\n", retval);
  1478. goto error_kthread_creat_failed;
  1479. }
  1480. #if 0
  1481. retval = tpd_i2c_read_data(ts->client, 0x004b, config_id, sizeof(config_id));
  1482. if (retval < 0) {
  1483. dev_err(&client->dev, "Failed to read config (code %d).\n", retval);
  1484. return retval;
  1485. }
  1486. TPD_DEBUG("Device config ID 0x%02X, 0x%02X, 0x%02X, 0x%02X\n",
  1487. config_id[0], config_id[1], config_id[2], config_id[3]);
  1488. for (i = 0; i < sizeof(config_id); i++) {
  1489. TPD_DEBUG("[wj]the [%d] is 0x%08x ...\n", i, (int)config_id[i]);
  1490. config_id_no += ((int)config_id[i] << ((sizeof(config_id) - i - 1) * 8));
  1491. }
  1492. TPD_DEBUG("[wj]the config_id_no is 0x%08x .\n", config_id_no);
  1493. /* Need to implement in a kthread */
  1494. if (config_id_no < 0x30303033) {
  1495. synaptics_rmi4_detection_work(NULL);
  1496. synaptics_fw_updater(synaImage);
  1497. }
  1498. #endif
  1499. #endif
  1500. #if 0
  1501. tpd_i2c_read_data(client, ts->f11.ctrl_base + 6, &tp_x_for_lcd, 2);
  1502. tpd_i2c_read_data(client, ts->f11.ctrl_base + 8, &tp_y_for_lcd, 2);
  1503. TPD_DEBUG("tp_x_for_lcd = %d, tp_y_for_lcd = %d\n", tp_x_for_lcd, tp_y_for_lcd);
  1504. if (tp_x_for_lcd != (u16) TPD_RES_X || tp_y_for_lcd != (u16) TPD_RES_Y) {
  1505. TPD_DEBUG("Reset the resolution for LCM\n");
  1506. tpd_i2c_write_data(client, ts->f11.ctrl_base + 6, &(u16) TPD_RES_X, 2);
  1507. tpd_i2c_write_data(client, ts->f11.ctrl_base + 8, &(u16) TPD_RES_Y, 2);
  1508. }
  1509. #endif
  1510. properties_kobj_driver = kobject_create_and_add("driver", properties_kobj_synap);
  1511. for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
  1512. retval = sysfs_create_file(properties_kobj_driver, &attrs[attr_count].attr);
  1513. if (retval < 0) {
  1514. dev_err(&client->dev, "%s: Failed to create sysfs attributes\n", __func__);
  1515. goto err_sysfs;
  1516. }
  1517. }
  1518. thread = kthread_run(touch_event_handler, 0, TPD_DEVICE);
  1519. if (IS_ERR(thread)) {
  1520. retval = PTR_ERR(thread);
  1521. TPD_DMESG("failed to create kernel thread: %d\n", retval);
  1522. goto error_kthread_creat_failed;
  1523. }
  1524. tpd_irq_registration();
  1525. /* disable_irq_nosync(touch_irq);*/
  1526. /* enable_irq(touch_irq);*/
  1527. tpd_load_status = 1;
  1528. TPD_DMESG("%s: TouchPanel Device Probe %s\n", __func__, (retval < 0) ? "FAIL" : "PASS");
  1529. return 0;
  1530. err_sysfs:
  1531. for (attr_count--; attr_count >= 0; attr_count--)
  1532. sysfs_remove_file(properties_kobj_driver, &attrs[attr_count].attr);
  1533. error_kthread_creat_failed:
  1534. err_query_device:
  1535. kfree(td);
  1536. kfree(ts);
  1537. /* hwPowerDown(MT65XX_POWER_LDO_VGP2, "TP"); */
  1538. return retval;
  1539. }
  1540. static int tpd_local_init(void)
  1541. {
  1542. int retval;
  1543. TPD_DEBUG("Synaptics I2C Touchscreen Driver load\n");
  1544. tpd->reg = regulator_get(tpd->tpd_dev, "vtouch");
  1545. tpd->io_reg = regulator_get(tpd->tpd_dev, "vtouchio");
  1546. retval = regulator_set_voltage(tpd->reg, 3300000, 3300000);
  1547. if (retval != 0) {
  1548. TPD_DMESG("Failed to set reg-vgp6 voltage: %d\n", retval);
  1549. return -1;
  1550. }
  1551. retval = regulator_set_voltage(tpd->io_reg, 1800000, 1800000);
  1552. if (retval != 0) {
  1553. TPD_DMESG("Failed to set reg-vgp4 voltage: %d\n", retval);
  1554. return -1;
  1555. }
  1556. if (i2c_add_driver(&tpd_i2c_driver) != 0) {
  1557. TPD_DMESG("Error unable to add i2c driver.\n");
  1558. return -1;
  1559. }
  1560. if (tpd_load_status == 0) {
  1561. TPD_DMESG("Synaptics add error touch panel driver.\n");
  1562. i2c_del_driver(&tpd_i2c_driver);
  1563. return -1;
  1564. }
  1565. if (tpd_dts_data.use_tpd_button) {
  1566. /*initialize tpd button data*/
  1567. tpd_button_setting(tpd_dts_data.tpd_key_num, tpd_dts_data.tpd_key_local,
  1568. tpd_dts_data.tpd_key_dim_local);
  1569. }
  1570. #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
  1571. TPD_DO_WARP = 1;
  1572. memcpy(tpd_wb_start, tpd_wb_start_local, TPD_WARP_CNT * 4);
  1573. memcpy(tpd_wb_end, tpd_wb_start_local, TPD_WARP_CNT * 4);
  1574. #endif
  1575. #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
  1576. memcpy(tpd_calmat, tpd_def_calmat_local, 8 * 4);
  1577. memcpy(tpd_def_calmat, tpd_def_calmat_local, 8 * 4);
  1578. #endif
  1579. boot_mode = get_boot_mode();
  1580. /* if (boot_mode == 3) boot_mode = NORMAL_BOOT; */ /*No need */
  1581. input_set_abs_params(tpd->dev, ABS_MT_TRACKING_ID, 0, (10 - 1), 0, 0);
  1582. TPD_DEBUG("end %s, %d\n", __func__, __LINE__);
  1583. tpd_type_cap = 1;
  1584. return 0;
  1585. }
  1586. static void tpd_resume(struct device *h)
  1587. {
  1588. /* u16 tp_x_for_lcd=0; */
  1589. /* u16 tp_y_for_lcd=0; */
  1590. u8 data;
  1591. int reset_count = 5;
  1592. int retval;
  1593. #if 0
  1594. tpd_sw_power(ts->client, 1);
  1595. #else
  1596. TPD_RESET_RESUME:
  1597. retval = regulator_enable(tpd->reg);
  1598. if (retval != 0)
  1599. TPD_DMESG("Failed to enable reg-vgp6: %d\n", retval);
  1600. retval = regulator_enable(tpd->io_reg);
  1601. if (retval != 0)
  1602. TPD_DMESG("Failed to enable reg-vgp4: %d\n", retval);
  1603. /* hwPowerOn(MT6323_POWER_LDO_VGP2, VOL_1800, "TP"); */
  1604. msleep(20);
  1605. #endif
  1606. /*tpd_gpio_output(GTP_RST_PORT, 0);*/
  1607. gpio_direction_output(tpd_rst_gpio_number, 0);
  1608. msleep(50);
  1609. /*tpd_gpio_output(GTP_RST_PORT, 1);*/
  1610. gpio_direction_output(tpd_rst_gpio_number, 1);
  1611. msleep(50);
  1612. /* Recovery EINT Mode */
  1613. /*tpd_gpio_as_int(GTP_INT_PORT);*/
  1614. gpio_direction_input(tpd_int_gpio_number);
  1615. if ((tpd_i2c_read_data(ts->client, 0xEE, &data, 1)) < 0) {
  1616. if (reset_count-- > 0)
  1617. goto TPD_RESET_RESUME;
  1618. TPD_DMESG("Can't connect touch panel.\n");
  1619. }
  1620. #if 0
  1621. tpd_i2c_read_data(ts->client, ts->f11.ctrl_base + 6, &tp_x_for_lcd, 2);
  1622. tpd_i2c_read_data(ts->client, ts->f11.ctrl_base + 8, &tp_y_for_lcd, 2);
  1623. if (tp_x_for_lcd != (u16) TPD_RES_X || tp_y_for_lcd != (u16) TPD_RES_Y) {
  1624. TPD_DMESG("Reset the resolution for LCM\n");
  1625. tpd_i2c_write_data(ts->client, ts->f11.ctrl_base + 6, &TPD_RES_X, 2);
  1626. tpd_i2c_write_data(ts->client, ts->f11.ctrl_base + 8, &TPD_RES_Y, 2);
  1627. }
  1628. #endif
  1629. tpd_clear_interrupt(ts->client);
  1630. mutex_lock(&i2c_access);
  1631. tpd_halt = 0;
  1632. enable_irq(touch_irq);
  1633. mutex_unlock(&i2c_access);
  1634. }
  1635. static void tpd_suspend(struct device *h)
  1636. {
  1637. int retval;
  1638. mutex_lock(&i2c_access);
  1639. disable_irq(touch_irq);
  1640. tpd_halt = 1;
  1641. mutex_unlock(&i2c_access);
  1642. #if 0
  1643. tpd_sw_power(ts->client, 0);
  1644. #else
  1645. /* Set EINT PIN to low */
  1646. /*tpd_gpio_output(GTP_INT_PORT, 0);*/
  1647. gpio_direction_output(tpd_int_gpio_number, 0);
  1648. /* Set RST PIN to low */
  1649. /*tpd_gpio_output(GTP_RST_PORT, 0);*/
  1650. gpio_direction_output(tpd_rst_gpio_number, 0);
  1651. retval = regulator_disable(tpd->io_reg);
  1652. if (retval != 0)
  1653. TPD_DMESG("Failed to disable reg-vgp4: %d\n", retval);
  1654. retval = regulator_disable(tpd->reg);
  1655. if (retval != 0)
  1656. TPD_DMESG("Failed to disable reg-vgp6: %d\n", retval);
  1657. #endif
  1658. TPD_DEBUG("TPD enter sleep\n");
  1659. }
  1660. static struct tpd_driver_t tpd_device_driver = {
  1661. .tpd_device_name = "synaptics",
  1662. .tpd_local_init = tpd_local_init,
  1663. .suspend = tpd_suspend,
  1664. .resume = tpd_resume,
  1665. };
  1666. static int __init tpd_driver_init(void)
  1667. {
  1668. TPD_DEBUG("Synaptics touch panel driver init\n");
  1669. tpd_get_dts_info();
  1670. if (tpd_driver_add(&tpd_device_driver) < 0)
  1671. TPD_DMESG("Error Add Synaptics driver failed\n");
  1672. return 0;
  1673. }
  1674. static void __exit tpd_driver_exit(void)
  1675. {
  1676. TPD_DEBUG("Synaptics touch panel driver exit\n");
  1677. tpd_driver_remove(&tpd_device_driver);
  1678. }
  1679. module_init(tpd_driver_init);
  1680. module_exit(tpd_driver_exit);
  1681. MODULE_DESCRIPTION("Mediatek Synaptics Driver");