cypress-touchkey.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  1. /*
  2. * cypress_touchkey.c - Platform data for cypress touchkey driver
  3. *
  4. * Copyright (C) 2011 Samsung Electronics
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #define SEC_TOUCHKEY_DEBUG
  12. /* #define SEC_TOUCHKEY_VERBOSE_DEBUG */
  13. #include <linux/module.h>
  14. #include <linux/input.h>
  15. #include <linux/init.h>
  16. #include <linux/slab.h>
  17. #include <linux/i2c.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/irq.h>
  20. #include <linux/delay.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/gpio.h>
  23. #include <linux/miscdevice.h>
  24. #include <linux/earlysuspend.h>
  25. #include "cypress_tkey_fw.h"
  26. #include <linux/regulator/consumer.h>
  27. #include <linux/mutex.h>
  28. #include <linux/workqueue.h>
  29. #include <linux/leds.h>
  30. #include <asm/mach-types.h>
  31. #include <linux/of_gpio.h>
  32. #include "cypress_touchkey.h"
  33. #if defined(CONFIG_LCD_CONNECTION_CHECK)
  34. extern int is_lcd_attached(void);
  35. #endif
  36. #if 0 // enable if you use home-touchkey
  37. #define HOME_KEY_USE
  38. #endif
  39. #define CYPRESS_GEN 0X00
  40. #define CYPRESS_FW_VER 0X01
  41. #define CYPRESS_MODULE_VER 0X02
  42. #define CYPRESS_2ND_HOST 0X03
  43. #define CYPRESS_THRESHOLD 0X04
  44. #define CYPRESS_AUTO_CAL_FLG 0X05
  45. #define CYPRESS_IDAC_MENU 0X07
  46. #define CYPRESS_IDAC_BACK 0X06
  47. #ifdef HOME_KEY_USE
  48. #define CYPRESS_IDAC_HOME 0X08
  49. #endif
  50. #define CYPRESS_DIFF_MENU 0x0C
  51. #define CYPRESS_DIFF_BACK 0x0A
  52. #ifdef HOME_KEY_USE
  53. #define CYPRESS_DIFF_HOME 0x0E
  54. #endif
  55. #define CYPRESS_RAW_DATA_MENU 0x10
  56. #define CYPRESS_RAW_DATA_BACK 0x0E
  57. #ifdef HOME_KEY_USE
  58. #define CYPRESS_RAW_DATA_HOME 0x12
  59. #endif
  60. #define CYPRESS_RAW_DATA_BACK_GOGH 0x14
  61. #define CYPRESS_LED_ON 0X10
  62. #define CYPRESS_LED_OFF 0X20
  63. #define CYPRESS_DATA_UPDATE 0X40
  64. #define CYPRESS_AUTO_CAL 0X50
  65. #define CYPRESS_LED_CONTROL_ON 0X60
  66. #define CYPRESS_LED_CONTROL_OFF 0X70
  67. #define CYPRESS_SLEEP 0X80
  68. static int vol_mv_level = 33;
  69. #define USE_OPEN_CLOSE
  70. #define TOUCHKEY_BACKLIGHT "button-backlight"
  71. /* bit masks*/
  72. #define PRESS_BIT_MASK 0X08
  73. #define KEYCODE_BIT_MASK 0X07
  74. #define TOUCHKEY_LOG(k, v) dev_notice(&info->client->dev, "key[%d] %d\n", k, v);
  75. #define FUNC_CALLED dev_notice(&info->client->dev, "%s: called.\n", __func__);
  76. #define NUM_OF_RETRY_UPDATE 3
  77. #define NUM_OF_KEY 4
  78. #ifdef USE_OPEN_CLOSE
  79. static int cypress_input_open(struct input_dev *dev);
  80. static void cypress_input_close(struct input_dev *dev);
  81. #endif
  82. /*
  83. struct cypress_touchkey_info {
  84. struct i2c_client *client;
  85. struct cypress_touchkey_platform_data *pdata;
  86. struct input_dev *input_dev;
  87. struct early_suspend early_suspend;
  88. char phys[32];
  89. unsigned char keycode[NUM_OF_KEY];
  90. u8 sensitivity[NUM_OF_KEY];
  91. int irq;
  92. u8 fw_ver;
  93. void (*power_onoff)(int);
  94. int touchkey_update_status;
  95. struct led_classdev leds;
  96. enum led_brightness brightness;
  97. struct mutex touchkey_led_mutex;
  98. struct workqueue_struct *led_wq;
  99. struct work_struct led_work;
  100. bool is_powering_on;
  101. };
  102. */
  103. #ifdef CONFIG_HAS_EARLYSUSPEND
  104. static void cypress_touchkey_early_suspend(struct early_suspend *h);
  105. static void cypress_touchkey_late_resume(struct early_suspend *h);
  106. #endif
  107. static int touchkey_led_status;
  108. static int touchled_cmd_reversed;
  109. static void cypress_touchkey_led_work(struct work_struct *work)
  110. {
  111. struct cypress_touchkey_info *info =
  112. container_of(work, struct cypress_touchkey_info, led_work);
  113. u8 buf;
  114. int ret;
  115. if (info->brightness == LED_OFF)
  116. buf = CYPRESS_LED_OFF;
  117. else
  118. buf = CYPRESS_LED_ON;
  119. mutex_lock(&info->touchkey_mutex);
  120. ret = i2c_smbus_write_byte_data(info->client, CYPRESS_GEN, buf);
  121. if (ret < 0)
  122. touchled_cmd_reversed = 1;
  123. touchkey_led_status = buf;
  124. mutex_unlock(&info->touchkey_mutex);
  125. }
  126. static void cypress_touchkey_brightness_set(struct led_classdev *led_cdev,
  127. enum led_brightness brightness)
  128. {
  129. /* Must not sleep, use a workqueue if needed */
  130. struct cypress_touchkey_info *info =
  131. container_of(led_cdev, struct cypress_touchkey_info, leds);
  132. info->brightness = brightness;
  133. queue_work(info->led_wq, &info->led_work);
  134. }
  135. static int reg_set_optimum_mode_check(struct regulator *reg, int load_uA)
  136. {
  137. return (regulator_count_voltages(reg) > 0) ?
  138. regulator_set_optimum_mode(reg, load_uA) : 0;
  139. }
  140. void cypress_power_onoff(struct cypress_touchkey_info *info, int onoff)
  141. {
  142. int ret = 0, rc = 0;
  143. dev_info(&info->client->dev, "%s: power %s\n",
  144. __func__, onoff ? "on" : "off");
  145. if (info->pdata->vdd_led < 0) {
  146. if (!info->vdd_led) {
  147. info->vdd_led = regulator_get(&info->client->dev,
  148. "vdd_led");
  149. if (IS_ERR(info->vdd_led)) {
  150. rc = PTR_ERR(info->vdd_led);
  151. dev_info(&info->client->dev,
  152. "Regulator(vdd_led) get failed rc=%d\n", rc);
  153. goto error_get_vtg_i2c;
  154. }
  155. }
  156. }
  157. if (onoff) {
  158. if (info->pdata->i2c_pull_up) {
  159. if (info->pdata->vdd_led < 0) {
  160. rc = reg_set_optimum_mode_check(info->vdd_led,
  161. 10000);
  162. if (rc < 0) {
  163. dev_info(&info->client->dev,
  164. "Regulator vdd_led set_opt failed rc=%d\n",
  165. rc);
  166. goto error_reg_opt_i2c;
  167. }
  168. rc = regulator_enable(info->vdd_led);
  169. if (rc) {
  170. dev_info(&info->client->dev,
  171. "Regulator vdd_led enable failed rc=%d\n",
  172. rc);
  173. goto error_reg_en_vcc_en;
  174. }
  175. }
  176. }
  177. } else {
  178. if (info->pdata->i2c_pull_up) {
  179. if (info->pdata->vdd_led < 0) {
  180. reg_set_optimum_mode_check(info->vdd_led, 0);
  181. regulator_disable(info->vdd_led);
  182. }
  183. }
  184. }
  185. //msleep(50);
  186. ret = gpio_direction_output(info->pdata->vdd_en, onoff);
  187. if (ret) {
  188. pr_err("[TKEY]%s: unable to set_direction for mms_vdd_en [%d]\n",
  189. __func__, info->pdata->vdd_en);
  190. }
  191. if (info->pdata->vdd_led > 0) {
  192. ret = gpio_direction_output(info->pdata->vdd_led, onoff);
  193. if (ret) {
  194. dev_info(&info->client->dev,
  195. "[TKEY]%s: unable to set_direction for vdd_led [%d]\n",
  196. __func__, info->pdata->vdd_led);
  197. }
  198. //msleep(30);
  199. }
  200. return;
  201. error_reg_en_vcc_en:
  202. if (info->pdata->i2c_pull_up) {
  203. // reg_set_optimum_mode_check(info->vcc_en, 0);
  204. if (info->pdata->vdd_led < 0)
  205. reg_set_optimum_mode_check(info->vdd_led, 0);
  206. }
  207. error_reg_opt_i2c:
  208. //error_set_vtg_i2c:
  209. // regulator_put(info->vcc_en);
  210. if (info->pdata->vdd_led < 0)
  211. regulator_put(info->vdd_led);
  212. error_get_vtg_i2c:
  213. return;
  214. }
  215. static void change_touch_key_led_voltage(int vol_mv)
  216. {
  217. struct regulator *tled_regulator;
  218. int ret;
  219. vol_mv_level = vol_mv;
  220. tled_regulator = regulator_get(NULL, "8921_l10");
  221. if (IS_ERR(tled_regulator)) {
  222. pr_err("%s: failed to get resource %s\n", __func__,
  223. "touch_led");
  224. return;
  225. }
  226. ret = regulator_set_voltage(tled_regulator,
  227. vol_mv * 100000, vol_mv * 100000);
  228. if (ret)
  229. printk(KERN_ERR"error setting voltage\n");
  230. regulator_put(tled_regulator);
  231. }
  232. static ssize_t brightness_control(struct device *dev,
  233. struct device_attribute *attr, const char *buf, size_t size)
  234. {
  235. int data;
  236. if (sscanf(buf, "%2d\n", &data) == 1) {
  237. printk(KERN_ERR"[TouchKey] touch_led_brightness: %d\n", data);
  238. change_touch_key_led_voltage(data);
  239. } else {
  240. printk(KERN_ERR "[TouchKey] touch_led_brightness Error\n");
  241. }
  242. return size;
  243. }
  244. static ssize_t brightness_level_show(struct device *dev,
  245. struct device_attribute *attr, char *buf)
  246. {
  247. int count;
  248. count = sprintf(buf, "%d\n", vol_mv_level);
  249. printk(KERN_DEBUG "[TouchKey] Touch LED voltage = %d\n", vol_mv_level);
  250. return count;
  251. }
  252. static irqreturn_t cypress_touchkey_interrupt(int irq, void *dev_id)
  253. {
  254. struct cypress_touchkey_info *info = dev_id;
  255. u8 buf[10] = {0,};
  256. int code;
  257. int press;
  258. int ret;
  259. ret = gpio_get_value(info->pdata->gpio_int);
  260. if (ret) {
  261. dev_err(&info->client->dev, "not real interrupt (%d).\n", ret);
  262. goto out;
  263. }
  264. if (info->is_powering_on) {
  265. dev_err(&info->client->dev, "%s: ignoring spurious boot "
  266. "interrupt\n", __func__);
  267. return IRQ_HANDLED;
  268. }
  269. #if defined(SEC_TOUCHKEY_VERBOSE_DEBUG)
  270. ret = i2c_smbus_read_i2c_block_data(info->client,
  271. CYPRESS_GEN, ARRAY_SIZE(buf), buf);
  272. if (ret != ARRAY_SIZE(buf)) {
  273. dev_err(&info->client->dev, "interrupt failed with %d.\n", ret);
  274. goto out;
  275. }
  276. print_hex_dump(KERN_DEBUG, "cypress_touchkey: ",
  277. DUMP_PREFIX_OFFSET, 32, 1, buf, 10, false);
  278. #else
  279. buf[0] = i2c_smbus_read_byte_data(info->client, CYPRESS_GEN);
  280. if (buf[0] < 0) {
  281. dev_err(&info->client->dev, "interrupt failed with %d.\n", ret);
  282. goto out;
  283. }
  284. #endif
  285. press = !(buf[0] & PRESS_BIT_MASK);
  286. code = (int)(buf[0] & KEYCODE_BIT_MASK) - 1;
  287. dev_dbg(&info->client->dev,
  288. "[TouchKey]press=%d, code=%d\n", press, code);
  289. if (code < 0) {
  290. dev_err(&info->client->dev,
  291. "not profer interrupt 0x%2X.\n", buf[0]);
  292. goto out;
  293. }
  294. #if defined(SEC_TOUCHKEY_DEBUG)
  295. TOUCHKEY_LOG(info->keycode[code], press);
  296. #endif
  297. // if (touch_is_pressed && press) {
  298. // printk(KERN_ERR "[TouchKey] don't send event because touch is pressed.\n");
  299. // printk(KERN_ERR "[TouchKey] touch_pressed = %d\n",
  300. // touch_is_pressed);
  301. // } else {
  302. input_report_key(info->input_dev, info->keycode[code], press);
  303. input_sync(info->input_dev);
  304. // }
  305. out:
  306. return IRQ_HANDLED;
  307. }
  308. static void cypress_touchkey_con_hw(struct cypress_touchkey_info *dev_info,
  309. bool flag)
  310. {
  311. struct cypress_touchkey_info *info = dev_info;
  312. gpio_set_value(info->pdata->gpio_led_en, flag ? 1 : 0);
  313. #if defined(SEC_TOUCHKEY_DEBUG)
  314. dev_notice(&info->client->dev,
  315. "%s : called with flag %d.\n", __func__, flag);
  316. #endif
  317. }
  318. static int cypress_touchkey_auto_cal(struct cypress_touchkey_info *dev_info)
  319. {
  320. struct cypress_touchkey_info *info = dev_info;
  321. u8 data[6] = { 0, };
  322. int count = 0;
  323. unsigned short retry = 0;
  324. while (retry < 3) {
  325. int ret = 0;
  326. ret = i2c_smbus_read_i2c_block_data(info->client,
  327. CYPRESS_GEN, 4, data);
  328. if (ret < 0) {
  329. printk(KERN_ERR "[TouchKey]i2c read fail.\n");
  330. return ret;
  331. }
  332. data[0] = 0x50;
  333. data[3] = 0x01;
  334. count = i2c_smbus_write_i2c_block_data(info->client,
  335. CYPRESS_GEN, 4, data);
  336. printk(KERN_DEBUG
  337. "[TouchKey] data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
  338. data[0], data[1], data[2], data[3]);
  339. msleep(50);
  340. ret = i2c_smbus_read_i2c_block_data(info->client,
  341. CYPRESS_GEN, 6, data);
  342. if ((data[5] & 0x80)) {
  343. printk(KERN_DEBUG "[Touchkey] autocal Enabled\n");
  344. break;
  345. } else {
  346. printk(KERN_DEBUG "[Touchkey] autocal disabled, retry %d\n",
  347. retry);
  348. }
  349. retry = retry + 1;
  350. }
  351. if (retry == 3)
  352. printk(KERN_DEBUG "[Touchkey] autocal failed\n");
  353. return count;
  354. }
  355. static int cypress_touchkey_led_on(struct cypress_touchkey_info *dev_info)
  356. {
  357. struct cypress_touchkey_info *info = dev_info;
  358. u8 buf = CYPRESS_LED_ON;
  359. int ret;
  360. ret = i2c_smbus_write_byte_data(info->client, CYPRESS_GEN, buf);
  361. if (ret < 0) {
  362. dev_err(&info->client->dev,
  363. "[Touchkey] i2c write error [%d]\n", ret);
  364. }
  365. return ret;
  366. }
  367. static int cypress_touchkey_led_off(struct cypress_touchkey_info *dev_info)
  368. {
  369. struct cypress_touchkey_info *info = dev_info;
  370. u8 buf = CYPRESS_LED_OFF;
  371. int ret;
  372. ret = i2c_smbus_write_byte_data(info->client, CYPRESS_GEN, buf);
  373. if (ret < 0) {
  374. dev_err(&info->client->dev,
  375. "[Touchkey] i2c write error [%d]\n", ret);
  376. }
  377. return ret;
  378. }
  379. static ssize_t touch_version_read(struct device *dev,
  380. struct device_attribute *attr, char *buf)
  381. {
  382. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  383. u8 data;
  384. int count;
  385. data = i2c_smbus_read_byte_data(info->client, CYPRESS_FW_VER);
  386. count = snprintf(buf, 20, "0x%02x\n", data);
  387. dev_dbg(&info->client->dev,
  388. "[TouchKey] %s : FW Ver 0x%02x\n", __func__, data);
  389. return count;
  390. }
  391. static ssize_t touch_version_show(struct device *dev,
  392. struct device_attribute *attr, char *buf)
  393. {
  394. int count;
  395. count = snprintf(buf, 20, "0x%02x\n", BIN_FW_VERSION);
  396. return count;
  397. }
  398. static ssize_t touchkey_firm_status_show(struct device *dev,
  399. struct device_attribute *attr, char *buf)
  400. {
  401. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  402. int count = 0;
  403. #if defined(CONFIG_MACH_JAGUAR)
  404. // char buff[16] = {0};
  405. #else
  406. char buff[16] = {0};
  407. #endif
  408. dev_dbg(&info->client->dev, "[TouchKey] touchkey_update_status: %d\n",
  409. info->touchkey_update_status);
  410. #if defined(CONFIG_MACH_JAGUAR)
  411. if (info->touchkey_update_status == 0)
  412. count = sprintf(buf, "PASS\n");
  413. else if (info->touchkey_update_status == 1)
  414. count = sprintf(buf, "Downloading\n");
  415. else if (info->touchkey_update_status == -1)
  416. count = sprintf(buf, "Fail\n");
  417. #else
  418. if (info->touchkey_update_status == 0)
  419. count = snprintf(buff, sizeof(buff), "PASS\n");
  420. else if (info->touchkey_update_status == 1)
  421. count = snprintf(buff, sizeof(buff), "Downloading\n");
  422. else if (info->touchkey_update_status == -1)
  423. count = snprintf(buff, sizeof(buff), "Fail\n");
  424. #endif
  425. return count;
  426. }
  427. static ssize_t touch_update_read(struct device *dev,
  428. struct device_attribute *attr, char *buf)
  429. {
  430. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  431. int count = 0;
  432. char buff[16] = {0};
  433. dev_dbg(&info->client->dev, "[TouchKey] touchkey_update_read: %d\n",
  434. info->touchkey_update_status);
  435. if (info->touchkey_update_status == 0)
  436. count = snprintf(buff, sizeof(buff), "PASS\n");
  437. else if (info->touchkey_update_status == 1)
  438. count = snprintf(buff, sizeof(buff), "Downloading\n");
  439. else if (info->touchkey_update_status == -1)
  440. count = snprintf(buff, sizeof(buff), "Fail\n");
  441. return count;
  442. }
  443. static ssize_t touch_update_write(struct device *dev,
  444. struct device_attribute *attr,
  445. const char *buf, size_t size)
  446. {
  447. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  448. int count = 0;
  449. int retry = NUM_OF_RETRY_UPDATE;
  450. char buff[16] = {0};
  451. u8 data;
  452. info->touchkey_update_status = 1;
  453. dev_err(dev, "[TOUCHKEY] touch_update_write!\n");
  454. disable_irq(info->irq);
  455. while (retry--) {
  456. if (ISSP_main() == 0) {
  457. dev_err(&info->client->dev,
  458. "[TOUCHKEY] Update success!\n");
  459. msleep(50);
  460. cypress_touchkey_auto_cal(info);
  461. info->touchkey_update_status = 0;
  462. count = 1;
  463. enable_irq(info->irq);
  464. break;
  465. }
  466. dev_err(&info->client->dev,
  467. "[TOUCHKEY] Touchkey_update failed... retry...\n");
  468. }
  469. if (retry <= 0) {
  470. if (info->pdata->gpio_led_en)
  471. cypress_touchkey_con_hw(info, false);
  472. msleep(300);
  473. count = 0;
  474. dev_err(&info->client->dev, "[TOUCHKEY]Touchkey_update fail\n");
  475. info->touchkey_update_status = -1;
  476. return count;
  477. }
  478. msleep(500);
  479. data = i2c_smbus_read_byte_data(info->client, CYPRESS_FW_VER);
  480. count = snprintf(buff, sizeof(buff), "0x%02x\n", data);
  481. dev_err(&info->client->dev,
  482. "[TouchKey] %s : FW Ver 0x%02x\n", __func__, data);
  483. return count;
  484. }
  485. static ssize_t touch_led_control(struct device *dev,
  486. struct device_attribute *attr, const char *buf,
  487. size_t size)
  488. {
  489. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  490. int data;
  491. dev_dbg(&info->client->dev, "called %s\n", __func__);
  492. data = kstrtoul(buf, (int)NULL, 0);
  493. if (data == 1) {
  494. if (data)
  495. cypress_touchkey_led_on(info);
  496. else
  497. cypress_touchkey_led_off(info);
  498. #if defined(SEC_TOUCHKEY_DEBUG)
  499. dev_dbg(&info->client->dev,
  500. "[TouchKey] touch_led_control : %d\n", data);
  501. #endif
  502. } else
  503. dev_dbg(&info->client->dev, "[TouchKey] touch_led_control Error\n");
  504. return size;
  505. }
  506. static ssize_t touch_sensitivity_control(struct device *dev,
  507. struct device_attribute *attr, const char *buf,
  508. size_t size)
  509. {
  510. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  511. int ret;
  512. ret = i2c_smbus_write_byte_data(info->client,
  513. CYPRESS_GEN, CYPRESS_DATA_UPDATE);
  514. if (ret < 0) {
  515. dev_err(&info->client->dev,
  516. "[Touchkey] fail to CYPRESS_DATA_UPDATE.\n");
  517. return ret;
  518. }
  519. msleep(150);
  520. return size;
  521. }
  522. static ssize_t touchkey_menu_show(struct device *dev,
  523. struct device_attribute *attr, char *buf)
  524. {
  525. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  526. static u8 menu_sensitivity;
  527. u8 data[2] = {0,};
  528. int ret;
  529. bool touchkey;
  530. touchkey = info->pdata->touchkey_order;
  531. ret = i2c_smbus_write_byte_data(info->client,
  532. CYPRESS_GEN, CYPRESS_DATA_UPDATE);
  533. if (ret < 0) {
  534. dev_err(&info->client->dev,
  535. "[TouchKey] fail to write menu sensitivity.\n");
  536. return ret;
  537. }
  538. // if (machine_is_GOGH()) {
  539. // ret = i2c_smbus_read_i2c_block_data(info->client,
  540. // CYPRESS_DIFF_BACK, ARRAY_SIZE(data), data);
  541. // } else {
  542. ret = i2c_smbus_read_i2c_block_data(info->client,
  543. touchkey ? CYPRESS_DIFF_BACK : CYPRESS_DIFF_MENU,
  544. ARRAY_SIZE(data), data);
  545. // }
  546. if (ret != ARRAY_SIZE(data)) {
  547. dev_err(&info->client->dev,
  548. "[TouchKey] fail to read menu sensitivity.\n");
  549. return ret;
  550. }
  551. menu_sensitivity = ((0x00FF & data[0])<<8) | data[1];
  552. dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
  553. __func__, data[0], data[1]);
  554. return snprintf(buf, 20, "%d\n", menu_sensitivity);
  555. }
  556. static ssize_t touchkey_back_show(struct device *dev,
  557. struct device_attribute *attr, char *buf)
  558. {
  559. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  560. static u8 back_sensitivity;
  561. u8 data[2] = {0,};
  562. int ret;
  563. bool touchkey;
  564. touchkey = info->pdata->touchkey_order;
  565. ret = i2c_smbus_write_byte_data(info->client,
  566. CYPRESS_GEN, CYPRESS_DATA_UPDATE);
  567. if (ret < 0) {
  568. dev_err(&info->client->dev,
  569. "[TouchKey] fail to write back sensitivity.\n");
  570. return ret;
  571. }
  572. // if (machine_is_GOGH()) {
  573. // ret = i2c_smbus_read_i2c_block_data(info->client,
  574. // CYPRESS_DIFF_HOME, ARRAY_SIZE(data), data);
  575. // } else {
  576. ret = i2c_smbus_read_i2c_block_data(info->client,
  577. touchkey ? CYPRESS_DIFF_MENU : CYPRESS_DIFF_BACK,
  578. ARRAY_SIZE(data), data);
  579. // }
  580. if (ret != ARRAY_SIZE(data)) {
  581. dev_err(&info->client->dev,
  582. "[TouchKey] fail to read back sensitivity.\n");
  583. return ret;
  584. }
  585. back_sensitivity = ((0x00FF & data[0])<<8) | data[1];
  586. dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
  587. __func__, data[0], data[1]);
  588. return snprintf(buf, 20, "%d\n", back_sensitivity);
  589. }
  590. #ifdef HOME_KEY_USE
  591. static ssize_t touchkey_home_show(struct device *dev,
  592. struct device_attribute *attr, char *buf)
  593. {
  594. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  595. static u8 home_sensitivity;
  596. u8 data[2] = {0,};
  597. int ret;
  598. ret = i2c_smbus_read_i2c_block_data(info->client,
  599. CYPRESS_DIFF_MENU, ARRAY_SIZE(data), data);
  600. if (ret != ARRAY_SIZE(data)) {
  601. dev_err(&info->client->dev,
  602. "[TouchKey] fail to read home sensitivity.\n");
  603. return ret;
  604. }
  605. home_sensitivity = ((0x00FF & data[0])<<8) | data[1];
  606. dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
  607. __func__, data[0], data[1]);
  608. return snprintf(buf, 20, "%d\n", home_sensitivity);
  609. }
  610. #endif
  611. static ssize_t touchkey_raw_data0_show(struct device *dev,
  612. struct device_attribute *attr, char *buf)
  613. {
  614. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  615. static u16 raw_data0;
  616. u8 data[2] = {0,};
  617. int ret;
  618. bool touchkey;
  619. touchkey = info->pdata->touchkey_order;
  620. // if (machine_is_GOGH()) {
  621. // ret = i2c_smbus_read_i2c_block_data(info->client,
  622. // CYPRESS_RAW_DATA_MENU, ARRAY_SIZE(data), data);
  623. // } else {
  624. ret = i2c_smbus_read_i2c_block_data(info->client,
  625. touchkey ? CYPRESS_RAW_DATA_BACK : CYPRESS_RAW_DATA_MENU,
  626. ARRAY_SIZE(data), data);
  627. // }
  628. if (ret != ARRAY_SIZE(data)) {
  629. dev_err(&info->client->dev,
  630. "[TouchKey] fail to read MENU raw data.\n");
  631. return ret;
  632. }
  633. raw_data0 = ((0x00FF & data[0])<<8) | data[1];
  634. dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
  635. __func__, data[0], data[1]);
  636. return snprintf(buf, 20, "%d\n", raw_data0);
  637. }
  638. static ssize_t touchkey_raw_data1_show(struct device *dev,
  639. struct device_attribute *attr, char *buf)
  640. {
  641. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  642. static u16 raw_data1;
  643. u8 data[2] = {0,};
  644. int ret;
  645. bool touchkey;
  646. touchkey = info->pdata->touchkey_order;
  647. // if (machine_is_GOGH()) {
  648. // ret = i2c_smbus_read_i2c_block_data(info->client,
  649. // CYPRESS_RAW_DATA_BACK_GOGH, ARRAY_SIZE(data), data);
  650. // } else {
  651. ret = i2c_smbus_read_i2c_block_data(info->client,
  652. touchkey ? CYPRESS_RAW_DATA_MENU : CYPRESS_RAW_DATA_BACK,
  653. ARRAY_SIZE(data), data);
  654. // }
  655. if (ret != ARRAY_SIZE(data)) {
  656. dev_err(&info->client->dev,
  657. "[TouchKey] fail to read HOME raw data.\n");
  658. return ret;
  659. }
  660. raw_data1 = ((0x00FF & data[0])<<8) | data[1];
  661. dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
  662. __func__, data[0], data[1]);
  663. return snprintf(buf, 20, "%d\n", raw_data1);
  664. }
  665. #ifdef HOME_KEY_USE
  666. static ssize_t touchkey_raw_data2_show(struct device *dev,
  667. struct device_attribute *attr, char *buf)
  668. {
  669. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  670. static u16 raw_data1;
  671. u8 data[2] = {0,};
  672. int ret;
  673. ret = i2c_smbus_read_i2c_block_data(info->client,
  674. CYPRESS_RAW_DATA_HOME, ARRAY_SIZE(data), data);
  675. if (ret != ARRAY_SIZE(data)) {
  676. dev_err(&info->client->dev,
  677. "[TouchKey] fail to read HOME raw data.\n");
  678. return ret;
  679. }
  680. raw_data1 = ((0x00FF & data[0])<<8) | data[1];
  681. dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
  682. __func__, data[0], data[1]);
  683. return snprintf(buf, 20, "%d\n", raw_data1);
  684. }
  685. #endif
  686. static ssize_t touchkey_idac0_show(struct device *dev,
  687. struct device_attribute *attr, char *buf)
  688. {
  689. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  690. static u8 idac0;
  691. u8 data = 0;
  692. bool touchkey;
  693. touchkey = info->pdata->touchkey_order;
  694. // if (machine_is_GOGH()) {
  695. // data = i2c_smbus_read_byte_data(info->client,
  696. // CYPRESS_IDAC_BACK);
  697. // } else {
  698. data = i2c_smbus_read_byte_data(info->client,
  699. touchkey ? CYPRESS_IDAC_BACK : CYPRESS_IDAC_MENU);
  700. // }
  701. dev_dbg(&info->client->dev, "called %s , data : %d\n", __func__, data);
  702. idac0 = data;
  703. return snprintf(buf, 20, "%d\n", idac0);
  704. }
  705. static ssize_t touchkey_idac1_show(struct device *dev,
  706. struct device_attribute *attr, char *buf)
  707. {
  708. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  709. static u8 idac1;
  710. u8 data = 0;
  711. bool touchkey;
  712. touchkey = info->pdata->touchkey_order;
  713. // if (machine_is_GOGH()) {
  714. // data = i2c_smbus_read_byte_data(info->client,
  715. // CYPRESS_IDAC_MENU);
  716. // } else {
  717. data = i2c_smbus_read_byte_data(info->client,
  718. touchkey ? CYPRESS_IDAC_MENU : CYPRESS_IDAC_BACK);
  719. // }
  720. dev_dbg(&info->client->dev, "called %s , data : %d\n", __func__, data);
  721. idac1 = data;
  722. return snprintf(buf, 20, "%d\n", idac1);
  723. }
  724. #ifdef HOME_KEY_USE
  725. static ssize_t touchkey_idac2_show(struct device *dev,
  726. struct device_attribute *attr, char *buf)
  727. {
  728. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  729. static u8 idac1;
  730. u8 data = 0;
  731. data = i2c_smbus_read_byte_data(info->client, CYPRESS_IDAC_HOME);
  732. dev_dbg(&info->client->dev, "called %s , data : %d\n", __func__, data);
  733. idac1 = data;
  734. return snprintf(buf, 20, "%d\n", idac1);
  735. }
  736. #endif
  737. static ssize_t touchkey_threshold_show(struct device *dev,
  738. struct device_attribute *attr, char *buf)
  739. {
  740. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  741. static u8 touchkey_threshold;
  742. u8 data = 0;
  743. data = i2c_smbus_read_byte_data(info->client, CYPRESS_THRESHOLD);
  744. dev_dbg(&info->client->dev, "called %s , data : %d\n", __func__, data);
  745. touchkey_threshold = data;
  746. return snprintf(buf, 20, "%d\n", touchkey_threshold);
  747. }
  748. static ssize_t touch_autocal_testmode(struct device *dev,
  749. struct device_attribute *attr, const char *buf,
  750. size_t size)
  751. {
  752. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  753. int count = 0;
  754. int on_off;
  755. if (sscanf(buf, "%2d\n", &on_off) == 1) {
  756. printk(KERN_ERR "[TouchKey] Test Mode : %d\n", on_off);
  757. if (on_off == 1) {
  758. count = i2c_smbus_write_byte_data(info->client,
  759. CYPRESS_GEN, CYPRESS_DATA_UPDATE);
  760. }
  761. } else {
  762. if (info->pdata->gpio_led_en) {
  763. cypress_touchkey_con_hw(info, false);
  764. msleep(50);
  765. cypress_touchkey_con_hw(info, true);
  766. msleep(50);
  767. }
  768. cypress_touchkey_auto_cal(info);
  769. }
  770. return count;
  771. }
  772. static ssize_t autocalibration_enable(struct device *dev,
  773. struct device_attribute *attr,
  774. const char *buf, size_t size)
  775. {
  776. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  777. int data;
  778. sscanf(buf, "%2d\n", &data);
  779. if (data == 1)
  780. cypress_touchkey_auto_cal(info);
  781. return 0;
  782. }
  783. static ssize_t autocalibration_status(struct device *dev,
  784. struct device_attribute *attr, char *buf)
  785. {
  786. u8 data[6];
  787. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  788. printk(KERN_DEBUG "[Touchkey] %s\n", __func__);
  789. i2c_smbus_read_i2c_block_data(info->client, CYPRESS_GEN, 6, data);
  790. if ((data[5] & 0x80))
  791. return sprintf(buf, "Enabled\n");
  792. else
  793. return sprintf(buf, "Disabled\n");
  794. }
  795. static DEVICE_ATTR(touchkey_firm_update_status,
  796. S_IRUGO | S_IWUSR | S_IWGRP, touchkey_firm_status_show, NULL);
  797. static DEVICE_ATTR(touchkey_firm_version_panel, S_IRUGO,
  798. touch_version_read, NULL);
  799. static DEVICE_ATTR(touchkey_firm_version_phone, S_IRUGO,
  800. touch_version_show, NULL);
  801. static DEVICE_ATTR(touchkey_firm_update, S_IRUGO | S_IWUSR | S_IWGRP,
  802. touch_update_read, touch_update_write);
  803. static DEVICE_ATTR(touchkey_brightness, S_IRUGO,
  804. NULL, touch_led_control);
  805. static DEVICE_ATTR(touch_sensitivity, S_IRUGO | S_IWUSR | S_IWGRP,
  806. NULL, touch_sensitivity_control);
  807. static DEVICE_ATTR(touchkey_menu, S_IRUGO, touchkey_menu_show, NULL);
  808. static DEVICE_ATTR(touchkey_back, S_IRUGO, touchkey_back_show, NULL);
  809. #ifdef HOME_KEY_USE
  810. static DEVICE_ATTR(touchkey_home, S_IRUGO, touchkey_home_show, NULL);
  811. #endif
  812. static DEVICE_ATTR(touchkey_raw_data0, S_IRUGO, touchkey_raw_data0_show, NULL);
  813. static DEVICE_ATTR(touchkey_raw_data1, S_IRUGO, touchkey_raw_data1_show, NULL);
  814. #ifdef HOME_KEY_USE
  815. static DEVICE_ATTR(touchkey_raw_data2, S_IRUGO, touchkey_raw_data2_show, NULL);
  816. #endif
  817. static DEVICE_ATTR(touchkey_idac0, S_IRUGO, touchkey_idac0_show, NULL);
  818. static DEVICE_ATTR(touchkey_idac1, S_IRUGO, touchkey_idac1_show, NULL);
  819. #ifdef HOME_KEY_USE
  820. static DEVICE_ATTR(touchkey_idac2, S_IRUGO, touchkey_idac2_show, NULL);
  821. #endif
  822. static DEVICE_ATTR(touchkey_threshold, S_IRUGO, touchkey_threshold_show, NULL);
  823. static DEVICE_ATTR(touchkey_autocal_start, S_IRUGO | S_IWUSR | S_IWGRP,
  824. NULL, touch_autocal_testmode);
  825. static DEVICE_ATTR(autocal_enable, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  826. autocalibration_enable);
  827. static DEVICE_ATTR(autocal_stat, S_IRUGO | S_IWUSR | S_IWGRP,
  828. autocalibration_status, NULL);
  829. static DEVICE_ATTR(touchkey_brightness_level, S_IRUGO | S_IWUSR | S_IWGRP,
  830. brightness_level_show, brightness_control);
  831. #ifdef CONFIG_OF
  832. static void cypress_request_gpio(struct cypress_touchkey_platform_data *pdata)
  833. {
  834. int ret;
  835. ret = gpio_request(pdata->gpio_scl, "touchkey_scl");
  836. if (ret) {
  837. printk(KERN_ERR "%s: unable to request touchkey_scl [%d]\n",
  838. __func__, pdata->gpio_scl);
  839. return;
  840. }
  841. gpio_tlmm_config(GPIO_CFG(pdata->gpio_scl, 3, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  842. ret = gpio_request(pdata->gpio_sda, "touchkey_sda");
  843. if (ret) {
  844. printk(KERN_ERR "%s: unable to request touchkey_sda [%d]\n",
  845. __func__, pdata->gpio_sda);
  846. return;
  847. }
  848. gpio_tlmm_config(GPIO_CFG(pdata->gpio_sda, 3, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  849. ret = gpio_request(pdata->gpio_int, "touchkey_irq");
  850. if (ret) {
  851. printk(KERN_ERR "%s: unable to request touchkey_irq [%d]\n",
  852. __func__, pdata->gpio_int);
  853. return;
  854. }
  855. ret = gpio_request(pdata->vdd_en, "melfas_vdd_en");
  856. if (ret) {
  857. pr_err("[TKEY]%s: unable to request melfas_vdd_en [%d]\n",
  858. __func__, pdata->vdd_en);
  859. return;
  860. }
  861. if (pdata->vdd_led > 0) {
  862. ret = gpio_request(pdata->vdd_led, "touchkey_vdd_led");
  863. if (ret) {
  864. printk(KERN_ERR "%s: unable to request touchkey_vdd_led [%d]\n",
  865. __func__, pdata->vdd_led);
  866. return;
  867. }
  868. }
  869. }
  870. static int cypress_get_keycodes(struct device *dev, char *name,
  871. struct cypress_touchkey_platform_data *pdata)
  872. {
  873. struct property *prop;
  874. struct device_node *np = dev->of_node;
  875. int rc;
  876. prop = of_find_property(np, name, NULL);
  877. if (!prop)
  878. return -EINVAL;
  879. if (!prop->value)
  880. return -ENODATA;
  881. pdata->keycodes_size = prop->length / sizeof(u32);
  882. rc = of_property_read_u32_array(np, name, pdata->touchkey_keycode,
  883. pdata->keycodes_size);
  884. if (rc && (rc != -EINVAL)) {
  885. dev_info(dev, "%s: Unable to read %s\n", __func__, name);
  886. return rc;
  887. }
  888. return 0;
  889. }
  890. static int cypress_parse_dt(struct device *dev,
  891. struct cypress_touchkey_platform_data *pdata)
  892. {
  893. int rc;
  894. struct device_node *np = dev->of_node;
  895. rc = cypress_get_keycodes(dev, "cypress,tkey-keycodes", pdata);
  896. if (rc)
  897. return rc;
  898. /* regulator info */
  899. pdata->i2c_pull_up = of_property_read_bool(np, "cypress,i2c-pull-up");
  900. pdata->vdd_led = of_get_named_gpio(np, "vdd_led-gpio", 0);
  901. pdata->vdd_en = of_get_named_gpio(np, "vdd_en-gpio", 0);
  902. /* reset, irq gpio info */
  903. pdata->gpio_scl = of_get_named_gpio_flags(np, "cypress,scl-gpio",
  904. 0, &pdata->scl_gpio_flags);
  905. pdata->gpio_sda = of_get_named_gpio_flags(np, "cypress,sda-gpio",
  906. 0, &pdata->sda_gpio_flags);
  907. pdata->gpio_int = of_get_named_gpio_flags(np, "cypress,irq-gpio",
  908. 0, &pdata->irq_gpio_flags);
  909. return 0;
  910. }
  911. #else
  912. static int cypress_parse_dt(struct device *dev,
  913. struct cypress_touchkey_platform_data *pdata)
  914. {
  915. return -ENODEV;
  916. }
  917. #endif
  918. static int __devinit cypress_touchkey_probe(struct i2c_client *client,
  919. const struct i2c_device_id *id)
  920. {
  921. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  922. struct cypress_touchkey_platform_data *pdata =
  923. client->dev.platform_data;
  924. struct cypress_touchkey_info *info;
  925. struct input_dev *input_dev;
  926. int ret = 0;
  927. int i;
  928. // int retry = NUM_OF_RETRY_UPDATE;
  929. int ic_fw_ver;
  930. int error;
  931. struct device *sec_touchkey;
  932. printk("[TKEY] %s _ %d\n",__func__,__LINE__);
  933. if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
  934. return -EIO;
  935. #ifdef CONFIG_OF
  936. if (client->dev.of_node) {
  937. pdata = devm_kzalloc(&client->dev,
  938. sizeof(struct cypress_touchkey_platform_data),
  939. GFP_KERNEL);
  940. if (!pdata) {
  941. dev_info(&client->dev, "Failed to allocate memory\n");
  942. return -ENOMEM;
  943. }
  944. error = cypress_parse_dt(&client->dev, pdata);
  945. if (error)
  946. return error;
  947. } else
  948. pdata = client->dev.platform_data;
  949. cypress_request_gpio(pdata);
  950. #endif
  951. info = kzalloc(sizeof(*info), GFP_KERNEL);
  952. if (!info) {
  953. dev_err(&client->dev, "fail to memory allocation.\n");
  954. goto err_mem_alloc;
  955. }
  956. input_dev = input_allocate_device();
  957. if (!input_dev) {
  958. dev_err(&client->dev, "fail to allocate input device.\n");
  959. goto err_input_dev_alloc;
  960. }
  961. client->irq = gpio_to_irq(pdata->gpio_int);
  962. info->client = client;
  963. info->input_dev = input_dev;
  964. info->pdata = pdata;
  965. info->irq = client->irq;
  966. info->touchkey_update_status = 0;
  967. input_dev->name = "sec_touchkey";
  968. input_dev->phys = info->phys;
  969. input_dev->id.bustype = BUS_I2C;
  970. input_dev->dev.parent = &client->dev;
  971. info->is_powering_on = true;
  972. cypress_power_onoff(info, 1);
  973. msleep(50);
  974. set_bit(EV_SYN, input_dev->evbit);
  975. set_bit(EV_KEY, input_dev->evbit);
  976. set_bit(EV_LED, input_dev->evbit);
  977. set_bit(LED_MISC, input_dev->ledbit);
  978. for (i = 0; i < pdata->keycodes_size; i++) {
  979. info->keycode[i] = pdata->touchkey_keycode[i];
  980. set_bit(info->keycode[i], input_dev->keybit);
  981. }
  982. input_set_drvdata(input_dev, info);
  983. mutex_init(&info->touchkey_mutex);
  984. ret = input_register_device(input_dev);
  985. if (ret) {
  986. dev_err(&client->dev, "[TOUCHKEY] failed to register input dev (%d).\n",
  987. ret);
  988. goto err_reg_input_dev;
  989. }
  990. i2c_set_clientdata(client, info);
  991. if (info->pdata->gpio_led_en) {
  992. ret = gpio_request(info->pdata->gpio_led_en,
  993. "gpio_touchkey_led");
  994. if (ret < 0) {
  995. dev_err(&client->dev,
  996. "gpio_touchkey_led gpio_request is failed\n");
  997. goto err_gpio_request;
  998. }
  999. gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_led_en, 0,
  1000. GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1001. cypress_touchkey_con_hw(info, true);
  1002. }
  1003. #ifdef USE_OPEN_CLOSE
  1004. input_dev->open = cypress_input_open;
  1005. input_dev->close = cypress_input_close;
  1006. #endif
  1007. dev_info(&info->client->dev, "gpio_to_irq IRQ %d\n",
  1008. client->irq);
  1009. ret = request_threaded_irq(client->irq, NULL,
  1010. cypress_touchkey_interrupt,
  1011. IRQF_TRIGGER_FALLING, client->dev.driver->name, info);
  1012. if (ret < 0) {
  1013. dev_err(&client->dev, "Failed to request IRQ %d (err: %d).\n",
  1014. client->irq, ret);
  1015. goto err_req_irq;
  1016. }
  1017. #ifdef CONFIG_HAS_EARLYSUSPEND
  1018. info->early_suspend.suspend = cypress_touchkey_early_suspend;
  1019. info->early_suspend.resume = cypress_touchkey_late_resume;
  1020. register_early_suspend(&info->early_suspend);
  1021. #endif /* CONFIG_HAS_EARLYSUSPEND */
  1022. info->led_wq = create_singlethread_workqueue("cypress_touchkey");
  1023. INIT_WORK(&info->led_work, cypress_touchkey_led_work);
  1024. info->leds.name = TOUCHKEY_BACKLIGHT;
  1025. info->leds.brightness = LED_FULL;
  1026. info->leds.max_brightness = LED_FULL;
  1027. info->leds.brightness_set = cypress_touchkey_brightness_set;
  1028. ret = led_classdev_register(&client->dev, &info->leds);
  1029. if (ret)
  1030. goto err_req_irq;
  1031. #if defined(CONFIG_LCD_CONNECTION_CHECK) //for SMD test
  1032. if (is_lcd_attached() == 0) {
  1033. disable_irq(client->irq);
  1034. printk("[TSK] %s : is_lcd_attached()=0 \n",__func__);
  1035. }
  1036. else{
  1037. #endif
  1038. msleep(20);
  1039. ic_fw_ver = i2c_smbus_read_byte_data(client, CYPRESS_FW_VER);
  1040. dev_err(&client->dev, "Touchkey FW Version: 0x%02x\n", ic_fw_ver);
  1041. #if defined(CONFIG_MACH_M2_ATT) || defined(CONFIG_MACH_M2_DCM) \
  1042. || defined(CONFIG_MACH_M2_SKT) || defined(CONFIG_MACH_M2_KDI)
  1043. dev_err(&client->dev, "Touchkey FW Version: 0x%02x, system_rev: %x\n",
  1044. ic_fw_ver, system_rev);
  1045. if (0 /* ic_fw_ver < BIN_FW_VERSION */) {
  1046. dev_err(&client->dev, "[TOUCHKEY] touchkey_update Start!!\n");
  1047. disable_irq(client->irq);
  1048. while (retry--) {
  1049. if (ISSP_main() == 0) {
  1050. dev_err(&client->dev, "[TOUCHKEY] Update success!\n");
  1051. enable_irq(client->irq);
  1052. break;
  1053. }
  1054. dev_err(&client->dev,
  1055. "[TOUCHKEY] Touchkey_update failed... retry...\n");
  1056. }
  1057. if (retry <= 0) {
  1058. if (info->pdata->gpio_led_en)
  1059. cypress_touchkey_con_hw(info, false);
  1060. msleep(300);
  1061. dev_err(&client->dev, "[TOUCHKEY]Touchkey_update fail\n");
  1062. }
  1063. msleep(500);
  1064. ic_fw_ver = i2c_smbus_read_byte_data(info->client,
  1065. CYPRESS_FW_VER);
  1066. dev_err(&client->dev,
  1067. "[TouchKey] %s : FW Ver 0x%02x\n", __func__, ic_fw_ver);
  1068. } else {
  1069. dev_err(&client->dev, "[TouchKey] FW update does not need!\n");
  1070. }
  1071. #endif
  1072. cypress_touchkey_auto_cal(info);
  1073. #if defined(CONFIG_LCD_CONNECTION_CHECK) //for SMD test
  1074. }
  1075. #endif
  1076. sec_touchkey = device_create(sec_class, NULL, 0, NULL, "sec_touchkey");
  1077. if (IS_ERR(sec_touchkey)) {
  1078. pr_err("Failed to create device(sec_touchkey)!\n");
  1079. goto err_sysfs;
  1080. }
  1081. dev_set_drvdata(sec_touchkey, info);
  1082. if (device_create_file(sec_touchkey,
  1083. &dev_attr_touchkey_firm_update_status) < 0) {
  1084. pr_err("Failed to create device file(%s)!\n",
  1085. dev_attr_touchkey_firm_update.attr.name);
  1086. goto err_sysfs;
  1087. }
  1088. if (device_create_file(sec_touchkey,
  1089. &dev_attr_touchkey_firm_update) < 0) {
  1090. pr_err("Failed to create device file(%s)!\n",
  1091. dev_attr_touchkey_firm_update.attr.name);
  1092. goto err_sysfs;
  1093. }
  1094. if (device_create_file(sec_touchkey,
  1095. &dev_attr_touchkey_firm_version_panel) < 0) {
  1096. pr_err("Failed to create device file(%s)!\n",
  1097. dev_attr_touchkey_firm_version_panel.attr.name);
  1098. goto err_sysfs;
  1099. }
  1100. if (device_create_file(sec_touchkey,
  1101. &dev_attr_touchkey_firm_version_phone) < 0) {
  1102. pr_err("Failed to create device file(%s)!\n",
  1103. dev_attr_touchkey_firm_version_phone.attr.name);
  1104. goto err_sysfs;
  1105. }
  1106. if (device_create_file(sec_touchkey,
  1107. &dev_attr_touchkey_brightness) < 0) {
  1108. pr_err("Failed to create device file(%s)!\n",
  1109. dev_attr_touchkey_brightness.attr.name);
  1110. goto err_sysfs;
  1111. }
  1112. if (device_create_file(sec_touchkey,
  1113. &dev_attr_touch_sensitivity) < 0) {
  1114. pr_err("Failed to create device file(%s)!\n",
  1115. dev_attr_touch_sensitivity.attr.name);
  1116. goto err_sysfs;
  1117. }
  1118. if (device_create_file(sec_touchkey,
  1119. &dev_attr_touchkey_menu) < 0) {
  1120. pr_err("Failed to create device file(%s)!\n",
  1121. dev_attr_touchkey_menu.attr.name);
  1122. goto err_sysfs;
  1123. }
  1124. if (device_create_file(sec_touchkey,
  1125. &dev_attr_touchkey_back) < 0) {
  1126. pr_err("Failed to create device file(%s)!\n",
  1127. dev_attr_touchkey_back.attr.name);
  1128. goto err_sysfs;
  1129. }
  1130. #ifdef HOME_KEY_USE
  1131. if (device_create_file(sec_touchkey,
  1132. &dev_attr_touchkey_home) < 0) {
  1133. pr_err("Failed to create device file(%s)!\n",
  1134. dev_attr_touchkey_home.attr.name);
  1135. goto err_sysfs;
  1136. }
  1137. #endif
  1138. if (device_create_file(sec_touchkey,
  1139. &dev_attr_touchkey_raw_data0) < 0) {
  1140. pr_err("Failed to create device file(%s)!\n",
  1141. dev_attr_touchkey_raw_data0.attr.name);
  1142. goto err_sysfs;
  1143. }
  1144. if (device_create_file(sec_touchkey,
  1145. &dev_attr_touchkey_raw_data1) < 0) {
  1146. pr_err("Failed to create device file(%s)!\n",
  1147. dev_attr_touchkey_raw_data1.attr.name);
  1148. goto err_sysfs;
  1149. }
  1150. #ifdef HOME_KEY_USE
  1151. if (device_create_file(sec_touchkey,
  1152. &dev_attr_touchkey_raw_data2) < 0) {
  1153. pr_err("Failed to create device file(%s)!\n",
  1154. dev_attr_touchkey_raw_data2.attr.name);
  1155. goto err_sysfs;
  1156. }
  1157. #endif
  1158. if (device_create_file(sec_touchkey, &dev_attr_touchkey_idac0) < 0) {
  1159. pr_err("Failed to create device file(%s)!\n",
  1160. dev_attr_touchkey_idac0.attr.name);
  1161. goto err_sysfs;
  1162. }
  1163. if (device_create_file(sec_touchkey, &dev_attr_touchkey_idac1) < 0) {
  1164. pr_err("Failed to create device file(%s)!\n",
  1165. dev_attr_touchkey_idac1.attr.name);
  1166. goto err_sysfs;
  1167. }
  1168. #ifdef HOME_KEY_USE
  1169. if (device_create_file(sec_touchkey, &dev_attr_touchkey_idac2) < 0) {
  1170. pr_err("Failed to create device file(%s)!\n",
  1171. dev_attr_touchkey_idac2.attr.name);
  1172. goto err_sysfs;
  1173. }
  1174. #endif
  1175. if (device_create_file(sec_touchkey,
  1176. &dev_attr_touchkey_threshold) < 0) {
  1177. pr_err("Failed to create device file(%s)!\n",
  1178. dev_attr_touchkey_threshold.attr.name);
  1179. goto err_sysfs;
  1180. }
  1181. if (device_create_file(sec_touchkey,
  1182. &dev_attr_touchkey_autocal_start) < 0) {
  1183. pr_err("Failed to create device file(%s)!\n",
  1184. dev_attr_touchkey_autocal_start.attr.name);
  1185. goto err_sysfs;
  1186. }
  1187. if (device_create_file(sec_touchkey,
  1188. &dev_attr_autocal_enable) < 0) {
  1189. pr_err("Failed to create device file(%s)!\n",
  1190. dev_attr_autocal_enable.attr.name);
  1191. goto err_sysfs;
  1192. }
  1193. if (device_create_file(sec_touchkey,
  1194. &dev_attr_autocal_stat) < 0) {
  1195. pr_err("Failed to create device file(%s)!\n",
  1196. dev_attr_autocal_stat.attr.name);
  1197. goto err_sysfs;
  1198. }
  1199. if (device_create_file(sec_touchkey,
  1200. &dev_attr_touchkey_brightness_level) < 0) {
  1201. printk(KERN_ERR "Failed to create device file(%s)!\n",
  1202. dev_attr_touchkey_brightness_level.attr.name);
  1203. goto err_sysfs;
  1204. }
  1205. info->is_powering_on = false;
  1206. return 0;
  1207. err_req_irq:
  1208. err_gpio_request:
  1209. input_unregister_device(input_dev);
  1210. err_reg_input_dev:
  1211. input_free_device(input_dev);
  1212. input_dev = NULL;
  1213. mutex_destroy(&info->touchkey_mutex);
  1214. err_input_dev_alloc:
  1215. kfree(info);
  1216. err_sysfs:
  1217. return -ENXIO;
  1218. err_mem_alloc:
  1219. return ret;
  1220. }
  1221. static int __devexit cypress_touchkey_remove(struct i2c_client *client)
  1222. {
  1223. struct cypress_touchkey_info *info = i2c_get_clientdata(client);
  1224. if (info->irq >= 0)
  1225. free_irq(info->irq, info);
  1226. mutex_destroy(&info->touchkey_mutex);
  1227. led_classdev_unregister(&info->leds);
  1228. input_unregister_device(info->input_dev);
  1229. input_free_device(info->input_dev);
  1230. kfree(info);
  1231. return 0;
  1232. }
  1233. #if defined(CONFIG_PM) || defined(CONFIG_HAS_EARLYSUSPEND)
  1234. static int cypress_touchkey_suspend(struct device *dev)
  1235. {
  1236. struct i2c_client *client = to_i2c_client(dev);
  1237. struct cypress_touchkey_info *info = i2c_get_clientdata(client);
  1238. int ret = 0;
  1239. info->is_powering_on = true;
  1240. disable_irq(info->irq);
  1241. if (info->pdata->gpio_led_en)
  1242. cypress_touchkey_con_hw(info, false);
  1243. cypress_power_onoff(info, 0);
  1244. return ret;
  1245. }
  1246. static int cypress_touchkey_resume(struct device *dev)
  1247. {
  1248. struct i2c_client *client = to_i2c_client(dev);
  1249. struct cypress_touchkey_info *info = i2c_get_clientdata(client);
  1250. int ret = 0;
  1251. cypress_power_onoff(info, 1);
  1252. if (info->pdata->gpio_led_en)
  1253. cypress_touchkey_con_hw(info, true);
  1254. msleep(50);
  1255. cypress_touchkey_auto_cal(info);
  1256. if (touchled_cmd_reversed) {
  1257. touchled_cmd_reversed = 0;
  1258. i2c_smbus_write_byte_data(info->client,
  1259. CYPRESS_GEN, touchkey_led_status);
  1260. printk(KERN_DEBUG "LED returned on\n");
  1261. }
  1262. enable_irq(info->irq);
  1263. info->is_powering_on = false;
  1264. return ret;
  1265. }
  1266. #endif
  1267. #ifdef CONFIG_HAS_EARLYSUSPEND
  1268. static void cypress_touchkey_early_suspend(struct early_suspend *h)
  1269. {
  1270. struct cypress_touchkey_info *info;
  1271. info = container_of(h, struct cypress_touchkey_info, early_suspend);
  1272. cypress_touchkey_suspend(&info->client->dev);
  1273. }
  1274. static void cypress_touchkey_late_resume(struct early_suspend *h)
  1275. {
  1276. struct cypress_touchkey_info *info;
  1277. info = container_of(h, struct cypress_touchkey_info, early_suspend);
  1278. cypress_touchkey_resume(&info->client->dev);
  1279. }
  1280. #endif
  1281. static const struct i2c_device_id cypress_touchkey_id[] = {
  1282. {"cypress_touchkey", 0},
  1283. {}
  1284. };
  1285. MODULE_DEVICE_TABLE(i2c, cypress_touchkey_id);
  1286. #ifdef CONFIG_OF
  1287. static struct of_device_id cypress_match_table[] = {
  1288. { .compatible = "cypress,cypress-tkey",},
  1289. { },
  1290. };
  1291. #else
  1292. #define cypress_match_table NULL
  1293. #endif
  1294. #ifdef USE_OPEN_CLOSE
  1295. static int cypress_input_open(struct input_dev *dev)
  1296. {
  1297. struct cypress_touchkey_info *info = input_get_drvdata(dev);
  1298. dev_info(&info->client->dev, "%s.\n", __func__);
  1299. cypress_touchkey_resume(&info->client->dev);
  1300. gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_scl, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1301. gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_sda, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1302. return 0;
  1303. }
  1304. static void cypress_input_close(struct input_dev *dev)
  1305. {
  1306. struct cypress_touchkey_info *info = input_get_drvdata(dev);
  1307. dev_info(&info->client->dev, "%s.\n", __func__);
  1308. gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_scl, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), 1);
  1309. gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_sda, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), 1);
  1310. cypress_touchkey_suspend(&info->client->dev);
  1311. }
  1312. #endif
  1313. #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND) && !defined(USE_OPEN_CLOSE)
  1314. static const struct dev_pm_ops cypress_touchkey_pm_ops = {
  1315. .suspend = cypress_touchkey_suspend,
  1316. .resume = cypress_touchkey_resume,
  1317. };
  1318. #endif
  1319. struct i2c_driver cypress_touchkey_driver = {
  1320. .probe = cypress_touchkey_probe,
  1321. .remove = cypress_touchkey_remove,
  1322. .driver = {
  1323. .name = "cypress_touchkey",
  1324. #ifdef CONFIG_OF
  1325. .of_match_table = cypress_match_table,
  1326. #endif
  1327. #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND) && !defined(USE_OPEN_CLOSE)
  1328. .pm = &cypress_touchkey_pm_ops,
  1329. #endif
  1330. },
  1331. .id_table = cypress_touchkey_id,
  1332. };
  1333. module_i2c_driver(cypress_touchkey_driver);
  1334. /*t cypress_touchkey_init(void)
  1335. {
  1336. int ret = 0;
  1337. ret = i2c_add_driver(&cypress_touchkey_driver);
  1338. if (ret) {
  1339. pr_err("[TouchKey] cypress touch keypad registration failed. ret= %d\n",
  1340. ret);
  1341. }
  1342. return ret;
  1343. }
  1344. static void __exit cypress_touchkey_exit(void)
  1345. {
  1346. i2c_del_driver(&cypress_touchkey_driver);
  1347. }
  1348. late_initcall(cypress_touchkey_init);
  1349. module_exit(cypress_touchkey_exit);
  1350. */
  1351. MODULE_DESCRIPTION("Touchkey driver for Cypress touchkey controller ");
  1352. MODULE_LICENSE("GPL");