abov_touchkey.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867
  1. /* abov_touchkey.c -- Linux driver for abov chip as touchkey
  2. *
  3. * Copyright (C) 2013 Samsung Electronics Co.Ltd
  4. * Author: Junkyeong Kim <jk0430.kim@samsung.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. */
  17. #include <linux/delay.h>
  18. #include <linux/firmware.h>
  19. #include <linux/gpio.h>
  20. #include <linux/i2c.h>
  21. #include <linux/init.h>
  22. #include <linux/input.h>
  23. #include <linux/input/mt.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/irq.h>
  26. #include <linux/module.h>
  27. #include <linux/mutex.h>
  28. #include <linux/slab.h>
  29. #include <linux/uaccess.h>
  30. #include <linux/i2c/abov_touchkey.h>
  31. #include <linux/io.h>
  32. #include <mach/gpio.h>
  33. #include <asm/unaligned.h>
  34. #include <linux/regulator/consumer.h>
  35. #ifdef CONFIG_OF
  36. #include <linux/of_gpio.h>
  37. #endif
  38. #ifdef CONFIG_HAS_EARLYSUSPEND
  39. #include <linux/earlysuspend.h>
  40. #endif
  41. /* registers */
  42. #define ABOV_BTNSTATUS 0x00
  43. #define ABOV_FW_VER 0x01
  44. #define ABOV_PCB_VER 0x02
  45. #define ABOV_COMMAND 0x03
  46. #define ABOV_THRESHOLD 0x04
  47. #define ABOV_TH_RECENT 0x04
  48. #define ABOV_TH_BACK 0x05
  49. #define ABOV_SETIDAC 0x06
  50. #define ABOV_DIFFDATA 0x0A
  51. #define ABOV_RAWDATA 0x0E
  52. #define ABOV_VENDORID 0x12
  53. #define ABOV_GLOVE 0x13
  54. #define ABOV_DUAL_DETECT 0x16
  55. /* command */
  56. #define CMD_LED_ON 0x10
  57. #define CMD_LED_OFF 0x20
  58. #define CMD_DATA_UPDATE 0x40
  59. #define CMD_LED_CTRL_ON 0x60
  60. #define CMD_LED_CTRL_OFF 0x70
  61. #define CMD_STOP_MODE 0x80
  62. #define CMD_GLOVE_ON 0x20
  63. #define CMD_GLOVE_OFF 0x10
  64. #define CMD_DUAL_DETECT 0x10
  65. #define CMD_SINGLE_DETECT 0x20
  66. #define ABOV_BOOT_DELAY 45
  67. #define ABOV_RESET_DELAY 94
  68. struct device *sec_touchkey;
  69. #if !defined(CONFIG_SEC_HESTIA_PROJECT)
  70. #define FW_VERSION 0x15
  71. #define FW_CHECKSUM_H 0xB6
  72. #define FW_CHECKSUM_L 0xCE
  73. #define TK_FW_PATH_BIN "abov/abov_tk.fw"
  74. #define TK_FW_PATH_SDCARD "/sdcard/abov_fw.bin"
  75. #define ABOV_DUAL_DETECTION_CMD_FW_VER 0x14
  76. #else
  77. #define FW_VERSION 0x06
  78. #define ABOV_DUAL_DETECTION_CMD_FW_VER 0xFF
  79. #define FW_CHECKSUM_H 0x94
  80. #define FW_CHECKSUM_L 0x86
  81. #define FW_CHECKSUM_H_REV4 0xE4
  82. #define FW_CHECKSUM_L_REV4 0x02
  83. #define TK_FW_PATH_BIN "abov/abov_tk_hestia.fw"
  84. #define TK_FW_PATH_SDCARD "/sdcard/abov_fw_hestia.bin"
  85. #define TK_FW_PATH_BIN_REV4 "abov/abov_tk_hestia_rev4.fw"
  86. #define TK_FW_PATH_SDCARD_REV4 "/sdcard/abov_fw_hestia_rev4.bin"
  87. #endif
  88. #define I2C_M_WR 0 /* for i2c */
  89. enum {
  90. BUILT_IN = 0,
  91. SDCARD,
  92. };
  93. #ifdef CONFIG_SAMSUNG_LPM_MODE
  94. extern int poweroff_charging;
  95. #endif
  96. extern unsigned int system_rev;
  97. extern struct class *sec_class;
  98. #ifdef CONFIG_SEC_ATLANTICLTE_COMMON
  99. extern int expander_gpio_config(unsigned config, unsigned disable);
  100. #endif
  101. static int touchkey_keycode[] = { 0,
  102. KEY_RECENT, KEY_BACK,
  103. };
  104. u8 ABOV_ID = 0x40;
  105. struct abov_tk_info {
  106. struct i2c_client *client;
  107. struct input_dev *input_dev;
  108. struct abov_touchkey_platform_data *pdata;
  109. #ifdef CONFIG_HAS_EARLYSUSPEND
  110. struct early_suspend early_suspend;
  111. #endif
  112. struct mutex lock;
  113. const struct firmware *firm_data_bin;
  114. const u8 *firm_data_ums;
  115. char phys[32];
  116. long firm_size;
  117. int irq;
  118. u16 menu_s;
  119. u16 back_s;
  120. u16 menu_raw;
  121. u16 back_raw;
  122. int (*power) (bool on);
  123. void (*input_event)(void *data);
  124. int touchkey_count;
  125. u8 fw_update_state;
  126. u8 fw_ver;
  127. u8 checksum_h;
  128. u8 checksum_l;
  129. bool enabled;
  130. bool fw_update_possible;
  131. bool glovemode;
  132. bool dual_mode;
  133. };
  134. #ifdef CONFIG_HAS_EARLYSUSPEND
  135. static void abov_tk_early_suspend(struct early_suspend *h);
  136. static void abov_tk_late_resume(struct early_suspend *h);
  137. #endif
  138. #ifdef CONFIG_INPUT_ENABLED
  139. static int abov_tk_input_open(struct input_dev *dev);
  140. static void abov_tk_input_close(struct input_dev *dev);
  141. static void abov_tk_dual_detection_mode(struct abov_tk_info *info, int mode);
  142. #endif
  143. static int abov_glove_mode_enable(struct i2c_client *client, u8 cmd)
  144. {
  145. return i2c_smbus_write_byte_data(client, ABOV_GLOVE, cmd);
  146. }
  147. #if !defined (CONFIG_SEC_HESTIA_PROJECT)
  148. static int abov_sleep_mode(struct i2c_client *client, u8 cmd)
  149. {
  150. return i2c_smbus_write_byte_data(client, ABOV_BTNSTATUS, cmd);
  151. }
  152. #endif
  153. static int abov_tk_i2c_read(struct i2c_client *client,
  154. u8 reg, u8 *val, unsigned int len)
  155. {
  156. struct abov_tk_info *info = i2c_get_clientdata(client);
  157. struct i2c_msg msg;
  158. int ret;
  159. int retry = 3;
  160. mutex_lock(&info->lock);
  161. msg.addr = client->addr;
  162. msg.flags = I2C_M_WR;
  163. msg.len = 1;
  164. msg.buf = &reg;
  165. while (retry--) {
  166. ret = i2c_transfer(client->adapter, &msg, 1);
  167. if (ret >= 0)
  168. break;
  169. dev_err(&client->dev, "%s fail(address set)(%d)\n",
  170. __func__, retry);
  171. msleep(10);
  172. }
  173. if (ret < 0) {
  174. mutex_unlock(&info->lock);
  175. return ret;
  176. }
  177. retry = 3;
  178. msg.flags = 1;/*I2C_M_RD*/
  179. msg.len = len;
  180. msg.buf = val;
  181. while (retry--) {
  182. ret = i2c_transfer(client->adapter, &msg, 1);
  183. if (ret >= 0) {
  184. mutex_unlock(&info->lock);
  185. return 0;
  186. }
  187. dev_err(&client->dev, "%s fail(data read)(%d)\n",
  188. __func__, retry);
  189. msleep(10);
  190. }
  191. mutex_unlock(&info->lock);
  192. return ret;
  193. }
  194. static int abov_tk_i2c_write(struct i2c_client *client,
  195. u8 reg, u8 *val, unsigned int len)
  196. {
  197. struct abov_tk_info *info = i2c_get_clientdata(client);
  198. struct i2c_msg msg[1];
  199. unsigned char data[2];
  200. int ret;
  201. int retry = 3;
  202. mutex_lock(&info->lock);
  203. data[0] = reg;
  204. data[1] = *val;
  205. msg->addr = client->addr;
  206. msg->flags = I2C_M_WR;
  207. msg->len = 2;
  208. msg->buf = data;
  209. while (retry--) {
  210. ret = i2c_transfer(client->adapter, msg, 1);
  211. if (ret >= 0) {
  212. mutex_unlock(&info->lock);
  213. return 0;
  214. }
  215. dev_err(&client->dev, "%s fail(%d) and val is %d\n ",
  216. __func__, retry,*val);
  217. msleep(10);
  218. }
  219. mutex_unlock(&info->lock);
  220. return ret;
  221. }
  222. static void release_all_fingers(struct abov_tk_info *info)
  223. {
  224. struct i2c_client *client = info->client;
  225. int i;
  226. dev_dbg(&client->dev, "[TK] %s\n", __func__);
  227. for (i = 1; i < info->touchkey_count; i++) {
  228. input_report_key(info->input_dev,
  229. touchkey_keycode[i], 0);
  230. }
  231. input_sync(info->input_dev);
  232. }
  233. static int abov_tk_reset_for_bootmode(struct abov_tk_info *info)
  234. {
  235. struct i2c_client *client = info->client;
  236. #if defined(CONFIG_SEC_HESTIA_PROJECT)
  237. if (system_rev < 6) {
  238. if (!info->pdata->gpio_rst) {
  239. dev_err(&client->dev, "%s fail (no reset pin)\n", __func__);
  240. return -1;
  241. }
  242. }
  243. #else
  244. if (!info->pdata->gpio_rst) {
  245. dev_err(&client->dev, "%s fail (no reset pin)\n", __func__);
  246. return -1;
  247. }
  248. #endif
  249. gpio_direction_input(info->pdata->gpio_int);
  250. if (system_rev >=01)
  251. gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_int,0,GPIO_CFG_INPUT,GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  252. else
  253. gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_int,0,GPIO_CFG_INPUT,GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  254. gpio_direction_output(info->pdata->gpio_scl, 0);
  255. gpio_direction_output(info->pdata->gpio_sda, 0);
  256. #if defined(CONFIG_SEC_HESTIA_PROJECT)
  257. if (system_rev < 6)
  258. gpio_direction_output(info->pdata->gpio_rst, 0);
  259. #else
  260. gpio_direction_output(info->pdata->gpio_rst, 0);
  261. #endif
  262. #if defined(CONFIG_SEC_HESTIA_PROJECT)
  263. gpio_direction_output(info->pdata->gpio_tkey_led_en,0);
  264. #endif
  265. msleep(100);
  266. #if defined(CONFIG_SEC_HESTIA_PROJECT)
  267. if (system_rev < 6)
  268. gpio_direction_output(info->pdata->gpio_rst, 1);
  269. #else
  270. gpio_direction_output(info->pdata->gpio_rst, 1);
  271. #endif
  272. #if defined(CONFIG_SEC_HESTIA_PROJECT)
  273. gpio_direction_output(info->pdata->gpio_tkey_led_en,1);
  274. #endif
  275. msleep(ABOV_BOOT_DELAY);
  276. //s3c_gpio_cfgpin(info->pdata->gpio_int, S3C_GPIO_SFN(0xf));
  277. if (system_rev >=01)
  278. gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_int,0,GPIO_CFG_INPUT,GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  279. else
  280. gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_int,0,GPIO_CFG_INPUT,GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  281. gpio_direction_input(info->pdata->gpio_scl);
  282. gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_scl,0,GPIO_CFG_INPUT,GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  283. gpio_direction_input(info->pdata->gpio_sda);
  284. gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_sda,0,GPIO_CFG_INPUT,GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  285. dev_dbg(&client->dev, " %s excute\n", __func__);
  286. return 0;
  287. }
  288. static void abov_tk_reset(struct abov_tk_info *info)
  289. {
  290. struct i2c_client *client = info->client;
  291. if (info->enabled == false)
  292. return;
  293. dev_notice(&client->dev, "%s++\n", __func__);
  294. disable_irq_nosync(info->irq);
  295. info->enabled = false;
  296. release_all_fingers(info);
  297. abov_tk_reset_for_bootmode(info);
  298. msleep(ABOV_RESET_DELAY);
  299. abov_tk_dual_detection_mode(info, 1);
  300. if (info->glovemode)
  301. abov_glove_mode_enable(client, CMD_GLOVE_ON);
  302. info->enabled = true;
  303. enable_irq(info->irq);
  304. dev_notice(&client->dev, "%s--\n", __func__);
  305. }
  306. static irqreturn_t abov_tk_interrupt(int irq, void *dev_id)
  307. {
  308. struct abov_tk_info *info = dev_id;
  309. struct i2c_client *client = info->client;
  310. int ret, retry;
  311. u8 buf;
  312. bool press;
  313. ret = abov_tk_i2c_read(client, ABOV_BTNSTATUS, &buf, 1);
  314. if (ret < 0) {
  315. retry = 3;
  316. while (retry--) {
  317. dev_err(&client->dev, "%s read fail(%d)\n",
  318. __func__, retry);
  319. ret = abov_tk_i2c_read(client, ABOV_BTNSTATUS, &buf, 1);
  320. if (ret == 0)
  321. break;
  322. else
  323. msleep(10);
  324. }
  325. if (retry == 0) {
  326. abov_tk_reset(info);
  327. return IRQ_HANDLED;
  328. }
  329. }
  330. if (info->dual_mode) {
  331. int menu_data = buf & 0x03;
  332. int back_data = (buf >> 2) & 0x03;
  333. u8 menu_press = !(menu_data % 2);
  334. u8 back_press = !(back_data % 2);
  335. if (menu_data)
  336. input_report_key(info->input_dev,
  337. touchkey_keycode[1], menu_press);
  338. if (back_data)
  339. input_report_key(info->input_dev,
  340. touchkey_keycode[2], back_press);
  341. #ifdef CONFIG_SAMSUNG_PRODUCT_SHIP
  342. dev_notice(&client->dev,
  343. "key %s%s ver0x%02x\n",
  344. menu_data ? (menu_press ? "P" : "R") : "",
  345. back_data ? (back_press ? "P" : "R") : "",
  346. info->fw_ver);
  347. #else
  348. dev_notice(&client->dev,
  349. "%s%s%x ver0x%02x\n",
  350. menu_data ? (menu_press ? "menu P " : "menu R ") : "",
  351. back_data ? (back_press ? "back P " : "back R ") : "",
  352. buf, info->fw_ver);
  353. #endif
  354. } else {
  355. u8 button = buf & 0x03;
  356. press = !!(buf & 0x8);
  357. if (press) {
  358. input_report_key(info->input_dev,
  359. touchkey_keycode[button], 0);
  360. #ifdef CONFIG_SAMSUNG_PRODUCT_SHIP
  361. dev_notice(&client->dev,
  362. "key R\n");
  363. #else
  364. dev_notice(&client->dev,
  365. "key R : %d(%d) ver0x%02x\n",
  366. touchkey_keycode[button], buf, info->fw_ver);
  367. #endif
  368. } else {
  369. input_report_key(info->input_dev,
  370. touchkey_keycode[button], 1);
  371. #ifdef CONFIG_SAMSUNG_PRODUCT_SHIP
  372. dev_notice(&client->dev,
  373. "key P\n");
  374. #else
  375. dev_notice(&client->dev,
  376. "key P : %d(%d)\n",
  377. touchkey_keycode[button], buf);
  378. #endif
  379. }
  380. }
  381. input_sync(info->input_dev);
  382. return IRQ_HANDLED;
  383. }
  384. #if defined(CONFIG_SEC_ATLANTIC_PROJECT)
  385. static int led_flag;
  386. #endif
  387. static ssize_t touchkey_led_control(struct device *dev,
  388. struct device_attribute *attr, const char *buf,
  389. size_t count)
  390. {
  391. struct abov_tk_info *info = dev_get_drvdata(dev);
  392. struct i2c_client *client = info->client;
  393. int data;
  394. int ret;
  395. u8 cmd;
  396. ret = sscanf(buf, "%d", &data);
  397. if (ret != 1) {
  398. dev_err(&client->dev, "%s: cmd read err\n", __func__);
  399. return count;
  400. }
  401. if (!(data == 0 || data == 1)) {
  402. dev_err(&client->dev, "%s: wrong command(%d)\n",
  403. __func__, data);
  404. return count;
  405. }
  406. #if defined(CONFIG_SEC_ATLANTIC_PROJECT)
  407. led_flag = data;
  408. #endif
  409. dev_notice(&client->dev, "%s: ,info->enabled = %d \n", __func__,info->enabled);
  410. if (!info->enabled)
  411. return count;
  412. if (data == 1) {
  413. dev_notice(&client->dev, "led on\n");
  414. cmd = CMD_LED_ON;
  415. } else {
  416. dev_notice(&client->dev, "led off\n");
  417. cmd = CMD_LED_OFF;
  418. }
  419. #if !defined(CONFIG_SEC_HESTIA_PROJECT)
  420. if(info->pdata->gpio_tkey_led_en >= 0)
  421. gpio_direction_output(info->pdata->gpio_tkey_led_en,data);
  422. #endif
  423. ret = abov_tk_i2c_write(client, ABOV_BTNSTATUS, &cmd, 1);
  424. if (ret < 0)
  425. dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
  426. return count;
  427. }
  428. static ssize_t touchkey_threshold_show(struct device *dev,
  429. struct device_attribute *attr, char *buf)
  430. {
  431. struct abov_tk_info *info = dev_get_drvdata(dev);
  432. struct i2c_client *client = info->client;
  433. u8 r_buf1, r_buf2;
  434. int ret;
  435. if (info->fw_ver < 0x12) {
  436. ret = abov_tk_i2c_read(client, ABOV_THRESHOLD, &r_buf1, 1);
  437. if (ret < 0) {
  438. dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
  439. r_buf1 = 0;
  440. }
  441. return sprintf(buf, "%d\n", r_buf1);
  442. } else {
  443. ret = abov_tk_i2c_read(client, ABOV_TH_RECENT, &r_buf1, 1);
  444. if (ret < 0) {
  445. dev_err(&client->dev, "%s recent fail(%d)\n", __func__, ret);
  446. r_buf1 = 0;
  447. }
  448. ret = abov_tk_i2c_read(client, ABOV_TH_BACK, &r_buf2, 1);
  449. if (ret < 0) {
  450. dev_err(&client->dev, "%s back fail(%d)\n", __func__, ret);
  451. r_buf2 = 0;
  452. }
  453. return sprintf(buf, "%d,%d\n", r_buf1, r_buf2);
  454. }
  455. }
  456. static void get_diff_data(struct abov_tk_info *info)
  457. {
  458. struct i2c_client *client = info->client;
  459. u8 r_buf[4];
  460. int ret;
  461. ret = abov_tk_i2c_read(client, ABOV_DIFFDATA, r_buf, 4);
  462. if (ret < 0) {
  463. dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
  464. info->menu_s = 0;
  465. info->back_s = 0;
  466. return;
  467. }
  468. info->menu_s = (r_buf[0] << 8) | r_buf[1];
  469. info->back_s = (r_buf[2] << 8) | r_buf[3];
  470. }
  471. static ssize_t touchkey_menu_show(struct device *dev,
  472. struct device_attribute *attr, char *buf)
  473. {
  474. struct abov_tk_info *info = dev_get_drvdata(dev);
  475. get_diff_data(info);
  476. return sprintf(buf, "%d\n", info->menu_s);
  477. }
  478. static ssize_t touchkey_back_show(struct device *dev,
  479. struct device_attribute *attr, char *buf)
  480. {
  481. struct abov_tk_info *info = dev_get_drvdata(dev);
  482. get_diff_data(info);
  483. return sprintf(buf, "%d\n", info->back_s);
  484. }
  485. static void get_raw_data(struct abov_tk_info *info)
  486. {
  487. struct i2c_client *client = info->client;
  488. u8 r_buf[4];
  489. int ret;
  490. ret = abov_tk_i2c_read(client, ABOV_RAWDATA, r_buf, 4);
  491. if (ret < 0) {
  492. dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
  493. info->menu_raw = 0;
  494. info->back_raw = 0;
  495. return;
  496. }
  497. info->menu_raw = (r_buf[0] << 8) | r_buf[1];
  498. info->back_raw = (r_buf[2] << 8) | r_buf[3];
  499. }
  500. static ssize_t touchkey_menu_raw_show(struct device *dev,
  501. struct device_attribute *attr, char *buf)
  502. {
  503. struct abov_tk_info *info = dev_get_drvdata(dev);
  504. get_raw_data(info);
  505. return sprintf(buf, "%d\n", info->menu_raw);
  506. }
  507. static ssize_t touchkey_back_raw_show(struct device *dev,
  508. struct device_attribute *attr, char *buf)
  509. {
  510. struct abov_tk_info *info = dev_get_drvdata(dev);
  511. get_raw_data(info);
  512. return sprintf(buf, "%d\n", info->back_raw);
  513. }
  514. static ssize_t bin_fw_ver(struct device *dev,
  515. struct device_attribute *attr, char *buf)
  516. {
  517. struct abov_tk_info *info = dev_get_drvdata(dev);
  518. struct i2c_client *client = info->client;
  519. dev_dbg(&client->dev, "fw version bin : 0x%x\n", FW_VERSION);
  520. return sprintf(buf, "0x%02x\n", FW_VERSION);
  521. }
  522. int get_tk_fw_version(struct abov_tk_info *info, bool bootmode)
  523. {
  524. struct i2c_client *client = info->client;
  525. u8 buf;
  526. int ret;
  527. int retry = 3;
  528. ret = abov_tk_i2c_read(client, ABOV_FW_VER, &buf, 1);
  529. if (ret < 0) {
  530. while (retry--) {
  531. dev_err(&client->dev, "%s read fail(%d)\n",
  532. __func__, retry);
  533. if (!bootmode)
  534. abov_tk_reset(info);
  535. else
  536. return -1;
  537. ret = abov_tk_i2c_read(client, ABOV_FW_VER, &buf, 1);
  538. if (ret == 0)
  539. break;
  540. }
  541. if (retry == 0)
  542. return -1;
  543. }
  544. info->fw_ver = buf;
  545. dev_notice(&client->dev, "%s : 0x%x\n", __func__, buf);
  546. return 0;
  547. }
  548. static ssize_t read_fw_ver(struct device *dev,
  549. struct device_attribute *attr, char *buf)
  550. {
  551. struct abov_tk_info *info = dev_get_drvdata(dev);
  552. struct i2c_client *client = info->client;
  553. int ret;
  554. ret = get_tk_fw_version(info, false);
  555. if (ret < 0) {
  556. dev_err(&client->dev, "%s read fail\n", __func__);
  557. info->fw_ver = 0;
  558. }
  559. return sprintf(buf, "0x%02x\n", info->fw_ver);
  560. }
  561. static int abov_load_fw(struct abov_tk_info *info, u8 cmd)
  562. {
  563. struct i2c_client *client = info->client;
  564. struct file *fp;
  565. mm_segment_t old_fs;
  566. long fsize, nread;
  567. int ret = 0;
  568. switch(cmd) {
  569. case BUILT_IN:
  570. #if !defined(CONFIG_SEC_HESTIA_PROJECT)
  571. ret = request_firmware(&info->firm_data_bin,
  572. TK_FW_PATH_BIN, &client->dev);
  573. #else
  574. if (system_rev >=04)
  575. ret = request_firmware(&info->firm_data_bin,TK_FW_PATH_BIN_REV4, &client->dev);
  576. else
  577. ret = request_firmware(&info->firm_data_bin,TK_FW_PATH_BIN, &client->dev);
  578. #endif
  579. if (ret) {
  580. dev_err(&client->dev,
  581. "%s request_firmware fail(%d)\n", __func__, cmd);
  582. return ret;
  583. }
  584. info->firm_size = info->firm_data_bin->size;
  585. break;
  586. case SDCARD:
  587. old_fs = get_fs();
  588. set_fs(get_ds());
  589. fp = filp_open(TK_FW_PATH_SDCARD, O_RDONLY, S_IRUSR);
  590. if (IS_ERR(fp)) {
  591. dev_err(&client->dev,
  592. "%s %s open error\n", __func__, TK_FW_PATH_SDCARD);
  593. ret = -ENOENT;
  594. goto fail_sdcard_open;
  595. }
  596. fsize = fp->f_path.dentry->d_inode->i_size;
  597. info->firm_data_ums = kzalloc((size_t)fsize, GFP_KERNEL);
  598. if (!info->firm_data_ums) {
  599. dev_err(&client->dev,
  600. "%s fail to kzalloc for fw\n", __func__);
  601. ret = -ENOMEM;
  602. goto fail_sdcard_kzalloc;
  603. }
  604. nread = vfs_read(fp,
  605. (char __user *)info->firm_data_ums, fsize, &fp->f_pos);
  606. if (nread != fsize) {
  607. dev_err(&client->dev,
  608. "%s fail to vfs_read file\n", __func__);
  609. ret = -EINVAL;
  610. goto fail_sdcard_size;
  611. }
  612. filp_close(fp, current->files);
  613. set_fs(old_fs);
  614. info->firm_size = nread;
  615. break;
  616. default:
  617. ret = -1;
  618. break;
  619. }
  620. dev_notice(&client->dev, "fw_size : %lu\n", info->firm_size);
  621. dev_notice(&client->dev, "%s success\n", __func__);
  622. return ret;
  623. fail_sdcard_size:
  624. kfree(&info->firm_data_ums);
  625. fail_sdcard_kzalloc:
  626. filp_close(fp, current->files);
  627. fail_sdcard_open:
  628. set_fs(old_fs);
  629. return ret;
  630. }
  631. void abov_i2c_start(int scl, int sda)
  632. {
  633. gpio_direction_output(sda, 1);
  634. gpio_direction_output(scl, 1);
  635. usleep_range(15, 17);
  636. gpio_direction_output(sda, 0);
  637. usleep_range(10, 12);
  638. gpio_direction_output(scl, 0);
  639. usleep_range(10, 12);
  640. }
  641. void abov_i2c_stop(int scl, int sda)
  642. {
  643. gpio_direction_output(scl, 0);
  644. usleep_range(10, 12);
  645. gpio_direction_output(sda, 0);
  646. usleep_range(10, 12);
  647. gpio_direction_output(scl, 1);
  648. usleep_range(10, 12);
  649. gpio_direction_output(sda, 1);
  650. }
  651. void abov_testdelay(void)
  652. {
  653. u8 i;
  654. u8 delay;
  655. /* 120nms */
  656. for (i = 0; i < 15; i++)
  657. delay = 0;
  658. }
  659. void abov_byte_send(u8 data, int scl, int sda)
  660. {
  661. u8 i;
  662. for (i = 0x80; i != 0; i >>= 1) {
  663. gpio_direction_output(scl, 0);
  664. usleep_range(5, 6);
  665. if (data & i)
  666. gpio_direction_output(sda, 1);
  667. else
  668. gpio_direction_output(sda, 0);
  669. usleep_range(5, 6);
  670. gpio_direction_output(scl, 1);
  671. usleep_range(5, 6);
  672. }
  673. usleep_range(5, 6);
  674. gpio_direction_output(scl, 0);
  675. gpio_direction_input(sda);
  676. gpio_tlmm_config(GPIO_CFG(sda,0,GPIO_CFG_INPUT,GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  677. usleep_range(5, 6);
  678. gpio_direction_output(scl, 1);
  679. usleep_range(5, 6);
  680. gpio_get_value(sda);
  681. abov_testdelay();
  682. gpio_direction_output(scl, 0);
  683. gpio_direction_output(sda, 0);
  684. usleep_range(20, 22);
  685. }
  686. u8 abov_byte_read(bool type, int scl, int sda)
  687. {
  688. u8 i;
  689. u8 data = 0;
  690. u8 index = 0x7;
  691. gpio_direction_output(scl, 0);
  692. gpio_direction_input(sda);
  693. gpio_tlmm_config(GPIO_CFG(sda,0,GPIO_CFG_INPUT,GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  694. usleep_range(20, 22);
  695. for (i = 0; i < 8; i++) {
  696. gpio_direction_output(scl, 0);
  697. usleep_range(10, 12);
  698. gpio_direction_output(scl, 1);
  699. usleep_range(5, 6);
  700. data = data | (u8)(gpio_get_value(sda) << index);
  701. index -= 1;
  702. }
  703. usleep_range(5, 6);
  704. gpio_direction_output(scl, 0);
  705. gpio_direction_output(sda, 0);
  706. usleep_range(5, 6);
  707. if (type) { /*ACK */
  708. gpio_direction_output(sda, 0);
  709. usleep_range(5, 6);
  710. gpio_direction_output(scl, 1);
  711. usleep_range(5, 6);
  712. gpio_direction_output(scl, 0);
  713. usleep_range(5, 6);
  714. } else { /* NAK */
  715. gpio_direction_output(sda, 1);
  716. usleep_range(5, 6);
  717. gpio_direction_output(scl, 1);
  718. usleep_range(10, 12);
  719. gpio_direction_output(scl, 0);
  720. usleep_range(5, 6);
  721. gpio_direction_output(sda, 0);
  722. usleep_range(5, 6);
  723. }
  724. usleep_range(20, 22);
  725. return data;
  726. }
  727. void abov_enter_mode(int scl, int sda)
  728. {
  729. abov_i2c_start(scl, sda);
  730. abov_testdelay();
  731. abov_byte_send(ABOV_ID, scl, sda);
  732. abov_byte_send(0xAC, scl, sda);
  733. abov_byte_send(0x5B, scl, sda);
  734. abov_byte_send(0x2D, scl, sda);
  735. abov_i2c_stop(scl, sda);
  736. }
  737. void abov_firm_write(const u8 *fw_data, int block, int scl, int sda)
  738. {
  739. int i, j;
  740. u16 pos = 0;
  741. u8 addr[2];
  742. addr[0] = 0x10;
  743. addr[1] = 0x00;
  744. for (i = 0; i < block; i++) {
  745. u8 data[32] = {0, };
  746. if (i % 8 == 0) {
  747. addr[0] = 0x10 + i/8;
  748. addr[1] = 0;
  749. } else
  750. addr[1] = addr[1] + 0x20;
  751. memcpy(data, fw_data + pos, 32);
  752. abov_i2c_start(scl, sda);
  753. abov_testdelay();
  754. abov_byte_send(ABOV_ID, scl, sda);
  755. abov_byte_send(0xAC, scl, sda);
  756. abov_byte_send(0x7A, scl, sda);
  757. abov_byte_send(addr[0], scl, sda);
  758. abov_byte_send(addr[1], scl, sda);
  759. for (j = 0; j < 32; j++)
  760. abov_byte_send(data[j], scl, sda);
  761. abov_i2c_stop(scl, sda);
  762. pos += 0x20;
  763. usleep(3*1000);
  764. }
  765. }
  766. void abov_read_address_set(int scl, int sda)
  767. {
  768. abov_i2c_start(scl, sda);
  769. abov_testdelay();
  770. abov_byte_send(ABOV_ID, scl, sda);
  771. abov_byte_send(0xAC, scl, sda);
  772. abov_byte_send(0x9E, scl, sda);
  773. abov_byte_send(0x10, scl, sda); /* start addr H */
  774. abov_byte_send(0x00, scl, sda); /* start addr L */
  775. abov_byte_send(0x3F, scl, sda); /* end addr H */
  776. abov_byte_send(0xFF, scl, sda); /* end addr L */
  777. abov_i2c_stop(scl, sda);
  778. }
  779. void abov_checksum(struct abov_tk_info *info, int scl, int sda)
  780. {
  781. struct i2c_client *client = info->client;
  782. u8 status;
  783. u8 bootver;
  784. u8 firmver;
  785. u8 checksumh;
  786. u8 checksuml;
  787. abov_read_address_set(scl, sda);
  788. usleep(5*1000);
  789. abov_i2c_start(scl, sda);
  790. abov_testdelay();
  791. abov_byte_send(ABOV_ID, scl, sda);
  792. abov_byte_send(0x00, scl, sda);
  793. abov_i2c_start(scl, sda); /* restart */
  794. abov_testdelay();
  795. abov_byte_send(ABOV_ID + 1, scl, sda);
  796. status = abov_byte_read(true, scl, sda);
  797. bootver = abov_byte_read(true, scl, sda);
  798. firmver = abov_byte_read(true, scl, sda);
  799. checksumh = abov_byte_read(true, scl, sda);
  800. checksuml = abov_byte_read(false, scl, sda);
  801. abov_i2c_stop(scl, sda);
  802. msleep(3);
  803. info->checksum_h = checksumh;
  804. info->checksum_l = checksuml;
  805. dev_err(&client->dev,
  806. "%s status(0x%x), boot(0x%x), firm(0x%x), cs_h(0x%x), cs_l(0x%x)\n",
  807. __func__, status, bootver, firmver, checksumh, checksuml);
  808. }
  809. void abov_exit_mode(int scl, int sda)
  810. {
  811. abov_i2c_start(scl, sda);
  812. abov_testdelay();
  813. abov_byte_send(ABOV_ID, scl, sda);
  814. abov_byte_send(0xAC, scl, sda);
  815. abov_byte_send(0x5B, scl, sda);
  816. abov_byte_send(0xE1, scl, sda);
  817. abov_i2c_stop(scl, sda);
  818. }
  819. static int abov_fw_update(struct abov_tk_info *info,
  820. const u8 *fw_data, int block, int scl, int sda)
  821. {
  822. abov_enter_mode(scl, sda);
  823. msleep(1100);
  824. abov_firm_write(fw_data, block, scl, sda);
  825. abov_checksum(info, scl, sda);
  826. return 0;
  827. }
  828. static void abov_release_fw(struct abov_tk_info *info, u8 cmd)
  829. {
  830. switch(cmd) {
  831. case BUILT_IN:
  832. release_firmware(info->firm_data_bin);
  833. break;
  834. case SDCARD:
  835. kfree(info->firm_data_ums);
  836. break;
  837. default:
  838. break;
  839. }
  840. }
  841. static int abov_flash_fw(struct abov_tk_info *info, bool probe, u8 cmd)
  842. {
  843. struct i2c_client *client = info->client;
  844. int retry = 3;
  845. int ret;
  846. int block_count;
  847. const u8 *fw_data;
  848. ret = get_tk_fw_version(info, probe);
  849. if (ret)
  850. info->fw_ver = 0;
  851. ret = abov_load_fw(info, cmd);
  852. if (ret) {
  853. dev_err(&client->dev,
  854. "%s fw load fail\n", __func__);
  855. return ret;
  856. }
  857. switch(cmd) {
  858. case BUILT_IN:
  859. fw_data = info->firm_data_bin->data;
  860. break;
  861. case SDCARD:
  862. fw_data = info->firm_data_ums;
  863. break;
  864. default:
  865. return -1;
  866. break;
  867. }
  868. block_count = (int)(info->firm_size / 32);
  869. while (retry--) {
  870. abov_tk_reset_for_bootmode(info);
  871. abov_fw_update(info, fw_data, block_count,
  872. info->pdata->gpio_scl, info->pdata->gpio_sda);
  873. if (cmd == BUILT_IN) {
  874. #if !defined(CONFIG_SEC_HESTIA_PROJECT)
  875. if ((info->checksum_h != FW_CHECKSUM_H) ||
  876. (info->checksum_l != FW_CHECKSUM_L)) {
  877. dev_err(&client->dev,
  878. "%s checksum fail.(0x%x,0x%x),(0x%x,0x%x) retry:%d\n",
  879. __func__, info->checksum_h, info->checksum_l,
  880. FW_CHECKSUM_H, FW_CHECKSUM_L, retry);
  881. ret = -1;
  882. continue;
  883. }
  884. #else
  885. if (system_rev >=04) {
  886. if ((info->checksum_h != FW_CHECKSUM_H_REV4) ||
  887. (info->checksum_l != FW_CHECKSUM_L_REV4)) {
  888. dev_err(&client->dev,
  889. "%s checksum fail.(0x%x,0x%x),(0x%x,0x%x) retry:%d\n",
  890. __func__, info->checksum_h, info->checksum_l,
  891. FW_CHECKSUM_H_REV4, FW_CHECKSUM_L_REV4, retry);
  892. ret = -1;
  893. continue;
  894. }
  895. }
  896. else {
  897. if ((info->checksum_h != FW_CHECKSUM_H) ||
  898. (info->checksum_l != FW_CHECKSUM_L)) {
  899. dev_err(&client->dev,
  900. "%s checksum fail.(0x%x,0x%x),(0x%x,0x%x) retry:%d\n",
  901. __func__, info->checksum_h, info->checksum_l,
  902. FW_CHECKSUM_H, FW_CHECKSUM_L, retry);
  903. ret = -1;
  904. continue;
  905. }
  906. }
  907. #endif
  908. }
  909. abov_tk_reset_for_bootmode(info);
  910. msleep(ABOV_RESET_DELAY);
  911. ret = get_tk_fw_version(info, true);
  912. if (ret) {
  913. dev_err(&client->dev, "%s fw version read fail\n", __func__);
  914. ret = -1;
  915. continue;
  916. }
  917. if (info->fw_ver == 0) {
  918. dev_err(&client->dev, "%s fw version fail (0x%x)\n",
  919. __func__, info->fw_ver);
  920. ret = -1;
  921. continue;
  922. }
  923. if ((cmd == BUILT_IN) && (info->fw_ver != FW_VERSION)) {
  924. dev_err(&client->dev, "%s fw version fail 0x%x, 0x%x\n",
  925. __func__, info->fw_ver, FW_VERSION);
  926. ret = -1;
  927. continue;
  928. }
  929. ret = 0;
  930. break;
  931. }
  932. abov_release_fw(info, cmd);
  933. return ret;
  934. }
  935. static ssize_t touchkey_fw_update(struct device *dev,
  936. struct device_attribute *attr, const char *buf, size_t count)
  937. {
  938. struct abov_tk_info *info = dev_get_drvdata(dev);
  939. struct i2c_client *client = info->client;
  940. int ret;
  941. u8 cmd;
  942. if (info->fw_update_possible == false) {
  943. dev_err(&client->dev, "%s fail (no reset pin)\n", __func__);
  944. info->fw_update_state = 2;
  945. goto touchkey_fw_update_out;
  946. }
  947. switch(*buf) {
  948. case 's':
  949. case 'S':
  950. cmd = BUILT_IN;
  951. break;
  952. case 'i':
  953. case 'I':
  954. cmd = SDCARD;
  955. break;
  956. default:
  957. info->fw_update_state = 2;
  958. goto touchkey_fw_update_out;
  959. }
  960. info->fw_update_state = 1;
  961. disable_irq(info->irq);
  962. info->enabled = false;
  963. ret = abov_flash_fw(info, false, cmd);
  964. abov_tk_dual_detection_mode(info, 1);
  965. if (info->glovemode)
  966. abov_glove_mode_enable(client, CMD_GLOVE_ON);
  967. info->enabled = true;
  968. enable_irq(info->irq);
  969. if (ret) {
  970. dev_err(&client->dev, "%s fail\n", __func__);
  971. info->fw_update_state = 2;
  972. } else {
  973. dev_notice(&client->dev, "%s success\n", __func__);
  974. info->fw_update_state = 0;
  975. }
  976. touchkey_fw_update_out:
  977. dev_dbg(&client->dev, "%s : %d\n", __func__, info->fw_update_state);
  978. return count;
  979. }
  980. static ssize_t touchkey_fw_update_status(struct device *dev,
  981. struct device_attribute *attr, char *buf)
  982. {
  983. struct abov_tk_info *info = dev_get_drvdata(dev);
  984. struct i2c_client *client = info->client;
  985. int count = 0;
  986. dev_info(&client->dev, "%s : %d\n", __func__, info->fw_update_state);
  987. if (info->fw_update_state == 0)
  988. count = sprintf(buf, "PASS\n");
  989. else if (info->fw_update_state == 1)
  990. count = sprintf(buf, "Downloading\n");
  991. else if (info->fw_update_state == 2)
  992. count = sprintf(buf, "Fail\n");
  993. return count;
  994. }
  995. static ssize_t abov_glove_mode(struct device *dev,
  996. struct device_attribute *attr, const char *buf, size_t count)
  997. {
  998. struct abov_tk_info *info = dev_get_drvdata(dev);
  999. struct i2c_client *client = info->client;
  1000. int scan_buffer;
  1001. int ret;
  1002. u8 cmd;
  1003. ret = sscanf(buf, "%d", &scan_buffer);
  1004. if (ret != 1) {
  1005. dev_err(&client->dev, "%s: cmd read err\n", __func__);
  1006. return count;
  1007. }
  1008. if (!(scan_buffer == 0 || scan_buffer == 1)) {
  1009. dev_err(&client->dev, "%s: wrong command(%d)\n",
  1010. __func__, scan_buffer);
  1011. return count;
  1012. }
  1013. if (!info->enabled)
  1014. return count;
  1015. if (info->glovemode == scan_buffer) {
  1016. dev_info(&client->dev, "%s same command(%d)\n",
  1017. __func__, scan_buffer);
  1018. return count;
  1019. }
  1020. if (scan_buffer == 1) {
  1021. dev_notice(&client->dev, "%s glove mode\n", __func__);
  1022. cmd = CMD_GLOVE_ON;
  1023. } else {
  1024. dev_notice(&client->dev, "%s normal mode\n", __func__);
  1025. cmd = CMD_GLOVE_OFF;
  1026. }
  1027. ret = abov_glove_mode_enable(client, cmd);
  1028. if (ret < 0) {
  1029. dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
  1030. return count;
  1031. }
  1032. info->glovemode = scan_buffer;
  1033. return count;
  1034. }
  1035. static ssize_t abov_glove_mode_show(struct device *dev,
  1036. struct device_attribute *attr, char *buf)
  1037. {
  1038. struct abov_tk_info *info = dev_get_drvdata(dev);
  1039. return sprintf(buf, "%d\n", info->glovemode);
  1040. }
  1041. static void abov_tk_dual_detection_mode(struct abov_tk_info *info, int mode)
  1042. {
  1043. u8 cmd;
  1044. int ret;
  1045. if (info->fw_ver < ABOV_DUAL_DETECTION_CMD_FW_VER){
  1046. info->dual_mode = false;
  1047. return;
  1048. }
  1049. dev_info(&info->client->dev,
  1050. "%s: %s\n", __func__, mode ? "on" : "off");
  1051. if (mode)
  1052. cmd = CMD_DUAL_DETECT;
  1053. else
  1054. cmd = CMD_SINGLE_DETECT;
  1055. ret = abov_tk_i2c_write(info->client, ABOV_DUAL_DETECT, &cmd, 1);
  1056. if (ret < 0)
  1057. dev_err(&info->client->dev,
  1058. "%s %d : fail %d\n", __func__, __LINE__, ret);
  1059. info->dual_mode = !!mode;
  1060. }
  1061. static ssize_t abov_set_dual_detection_mode(struct device *dev,
  1062. struct device_attribute *attr, const char *buf, size_t count)
  1063. {
  1064. struct abov_tk_info *info = dev_get_drvdata(dev);
  1065. int scan_buffer;
  1066. int ret;
  1067. ret = sscanf(buf, "%d", &scan_buffer);
  1068. if (ret != 1) {
  1069. dev_err(&info->client->dev, "%s: cmd read err\n", __func__);
  1070. return count;
  1071. }
  1072. if (!info->enabled)
  1073. return count;
  1074. abov_tk_dual_detection_mode(info, !!scan_buffer);
  1075. return count;
  1076. }
  1077. static DEVICE_ATTR(touchkey_threshold, S_IRUGO, touchkey_threshold_show, NULL);
  1078. static DEVICE_ATTR(brightness, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  1079. touchkey_led_control);
  1080. static DEVICE_ATTR(touchkey_recent, S_IRUGO, touchkey_menu_show, NULL);
  1081. static DEVICE_ATTR(touchkey_back, S_IRUGO, touchkey_back_show, NULL);
  1082. static DEVICE_ATTR(touchkey_raw_data0, S_IRUGO, touchkey_menu_raw_show, NULL);
  1083. static DEVICE_ATTR(touchkey_raw_data1, S_IRUGO, touchkey_back_raw_show, NULL);
  1084. static DEVICE_ATTR(touchkey_firm_version_phone, S_IRUGO, bin_fw_ver, NULL);
  1085. static DEVICE_ATTR(touchkey_firm_version_panel, S_IRUGO, read_fw_ver, NULL);
  1086. static DEVICE_ATTR(touchkey_firm_update, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  1087. touchkey_fw_update);
  1088. static DEVICE_ATTR(touchkey_firm_update_status, S_IRUGO | S_IWUSR | S_IWGRP,
  1089. touchkey_fw_update_status, NULL);
  1090. static DEVICE_ATTR(glove_mode, S_IRUGO | S_IWUSR | S_IWGRP,
  1091. abov_glove_mode_show, abov_glove_mode);
  1092. static DEVICE_ATTR(detection_mode, S_IRUGO | S_IWUSR | S_IWGRP,
  1093. NULL, abov_set_dual_detection_mode);
  1094. static struct attribute *sec_touchkey_attributes[] = {
  1095. &dev_attr_touchkey_threshold.attr,
  1096. &dev_attr_brightness.attr,
  1097. &dev_attr_touchkey_recent.attr,
  1098. &dev_attr_touchkey_back.attr,
  1099. &dev_attr_touchkey_raw_data0.attr,
  1100. &dev_attr_touchkey_raw_data1.attr,
  1101. &dev_attr_touchkey_firm_version_phone.attr,
  1102. &dev_attr_touchkey_firm_version_panel.attr,
  1103. &dev_attr_touchkey_firm_update.attr,
  1104. &dev_attr_touchkey_firm_update_status.attr,
  1105. &dev_attr_glove_mode.attr,
  1106. &dev_attr_detection_mode.attr,
  1107. NULL,
  1108. };
  1109. static struct attribute_group sec_touchkey_attr_group = {
  1110. .attrs = sec_touchkey_attributes,
  1111. };
  1112. static int abov_tk_fw_check(struct abov_tk_info *info)
  1113. {
  1114. struct i2c_client *client = info->client;
  1115. int ret;
  1116. bool update = false;
  1117. ret = get_tk_fw_version(info, true);
  1118. if (ret) {
  1119. dev_err(&client->dev,
  1120. "%s: i2c fail...[%d], addr[%d]\n",
  1121. __func__, ret, info->client->addr);
  1122. if (!info->fw_update_possible) {
  1123. dev_err(&client->dev,
  1124. "%s: touchkey driver unload\n", __func__);
  1125. return ret;
  1126. } else {
  1127. dev_err(&client->dev,
  1128. "%s: touchkey force firm update\n", __func__);
  1129. update = true;
  1130. }
  1131. }
  1132. if (!info->fw_update_possible)
  1133. return ret;
  1134. if (update || (info->fw_ver == 0) || info->fw_ver < FW_VERSION ||
  1135. (info->fw_ver == 0xFF) || (info->fw_ver == 0xFE)) {
  1136. dev_err(&client->dev, "excute tk firmware update (0x%x -> 0x%x\n",
  1137. info->fw_ver, FW_VERSION);
  1138. ret = abov_flash_fw(info, true, BUILT_IN);
  1139. if (ret) {
  1140. dev_err(&client->dev,
  1141. "failed to abov_flash_fw (%d)\n", ret);
  1142. } else {
  1143. dev_info(&client->dev,
  1144. "fw update success\n");
  1145. }
  1146. }
  1147. return ret;
  1148. }
  1149. int abov_power(struct abov_touchkey_platform_data *pdata, bool on)
  1150. {
  1151. int ret = 0;
  1152. if(pdata->vdd_io_vreg)
  1153. ret = regulator_enable(pdata->vdd_io_vreg);
  1154. if(ret){
  1155. pr_err("[TKEY] %s: iovdd reg enable fail\n", __func__);
  1156. return ret;
  1157. }
  1158. #if defined (CONFIG_SEC_HESTIA_PROJECT)
  1159. gpio_direction_output(pdata->gpio_tkey_led_en,on);
  1160. #endif
  1161. #if !defined (CONFIG_SEC_GNOTE_PROJECT) && !defined (CONFIG_SEC_HESTIA_PROJECT)
  1162. if(pdata->avdd_vreg)
  1163. ret = regulator_enable(pdata->avdd_vreg);
  1164. if(ret){
  1165. pr_err("[TKEY] %s: avdd reg enable fail\n", __func__);
  1166. return ret;
  1167. }
  1168. #endif
  1169. msleep(50);
  1170. return ret;
  1171. }
  1172. int abov_gpio_reg_init(struct device *dev,
  1173. struct abov_touchkey_platform_data *pdata)
  1174. {
  1175. int ret = 0;
  1176. #if defined(CONFIG_SEC_HESTIA_PROJECT)
  1177. if (system_rev < 6) {
  1178. ret = gpio_request(pdata->gpio_rst, "tkey_gpio_rst");
  1179. if(ret < 0){
  1180. dev_err(dev, "unable to request gpio_rst\n");
  1181. return ret;
  1182. }
  1183. }
  1184. #else
  1185. ret = gpio_request(pdata->gpio_rst, "tkey_gpio_rst");
  1186. if(ret < 0){
  1187. dev_err(dev, "unable to request gpio_rst\n");
  1188. return ret;
  1189. }
  1190. #endif
  1191. ret = gpio_request(pdata->gpio_int, "tkey_gpio_int");
  1192. if(ret < 0){
  1193. dev_err(dev, "unable to request gpio_int\n");
  1194. return ret;
  1195. }
  1196. ret = gpio_request(pdata->gpio_tkey_led_en, "gpio_tkey_led_en");
  1197. if(ret < 0){
  1198. dev_err(dev, "unable to request gpio_tkey_led_en..Tkey led will not work...ignoring\n");
  1199. }
  1200. pdata->vdd_io_vreg = regulator_get(dev, "vddo");
  1201. //pdata->vdd_io_vreg = regulator_get(dev, "8226_l6");
  1202. if (IS_ERR(pdata->vdd_io_vreg)){
  1203. pdata->vdd_io_vreg = NULL;
  1204. dev_err(dev, "pdata->vdd_io_vreg get error, ignoring\n");
  1205. }
  1206. regulator_set_voltage(pdata->vdd_io_vreg, 1800000, 1800000);
  1207. #if !defined (CONFIG_SEC_GNOTE_PROJECT) && !defined (CONFIG_SEC_HESTIA_PROJECT)
  1208. //pdata->avdd_vreg = regulator_get(dev, "8226_l19");
  1209. pdata->avdd_vreg = regulator_get(dev, "avdd");
  1210. if (IS_ERR(pdata->avdd_vreg)){
  1211. pdata->avdd_vreg = NULL;
  1212. dev_err(dev, "pdata->avdd_vreg get error, ignoring\n");
  1213. }
  1214. regulator_set_voltage(pdata->avdd_vreg, 2850000, 2850000);
  1215. #endif
  1216. pdata->power = abov_power;
  1217. return ret;
  1218. }
  1219. #ifdef CONFIG_OF
  1220. static int abov_parse_dt(struct device *dev,
  1221. struct abov_touchkey_platform_data *pdata)
  1222. {
  1223. struct device_node *np = dev->of_node;
  1224. #ifdef CONFIG_SEC_ATLANTICLTE_COMMON
  1225. int rc;
  1226. #endif
  1227. pdata->gpio_rst = of_get_named_gpio(np, "abov,rst-gpio", 0);
  1228. if(pdata->gpio_rst < 0){
  1229. dev_err(dev, "unable to get gpio_rst\n");
  1230. #if defined(CONFIG_SEC_HESTIA_PROJECT)
  1231. if (system_rev < 6)
  1232. return pdata->gpio_rst;
  1233. #else
  1234. return pdata->gpio_rst;
  1235. #endif
  1236. }
  1237. #ifdef CONFIG_SEC_ATLANTICLTE_COMMON
  1238. if (system_rev < 03) {
  1239. rc = expander_gpio_config(GPIO_CFG(pdata->gpio_rst, 0, GPIO_CFG_INPUT,
  1240. GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  1241. if (rc < 0) {
  1242. pr_err("%s: expander_tlmm_config is failed\n",__func__);
  1243. return rc;
  1244. }
  1245. }
  1246. #endif
  1247. pdata->gpio_int = of_get_named_gpio(np, "abov,irq-gpio", 0);
  1248. if(pdata->gpio_int < 0){
  1249. dev_err(dev, "unable to get gpio_int\n");
  1250. return pdata->gpio_int;
  1251. }
  1252. pdata->gpio_scl = of_get_named_gpio(np, "abov,scl-gpio", 0);
  1253. if(pdata->gpio_scl < 0){
  1254. dev_err(dev, "unable to get gpio_scl\n");
  1255. return pdata->gpio_scl;
  1256. }
  1257. pdata->gpio_sda = of_get_named_gpio(np, "abov,sda-gpio", 0);
  1258. if(pdata->gpio_sda < 0){
  1259. dev_err(dev, "unable to get gpio_sda\n");
  1260. return pdata->gpio_sda;
  1261. }
  1262. pdata->gpio_tkey_led_en = of_get_named_gpio(np, "abov,tkey_en-gpio", 0);
  1263. if(pdata->gpio_tkey_led_en < 0){
  1264. dev_err(dev, "unable to get gpio_tkey_led_en...ignoring\n");
  1265. }
  1266. return 0;
  1267. }
  1268. #else
  1269. static int abov_parse_dt(struct device *dev,
  1270. struct abov_touchkey_platform_data *pdata)
  1271. {
  1272. return -ENODEV;
  1273. }
  1274. #endif
  1275. #if defined(CONFIG_FB_MSM8x26_MDSS_CHECK_LCD_CONNECTION)
  1276. extern int get_lcd_attached(void);
  1277. #endif
  1278. static int __devinit abov_tk_probe(struct i2c_client *client,
  1279. const struct i2c_device_id *id)
  1280. {
  1281. struct abov_tk_info *info;
  1282. struct input_dev *input_dev;
  1283. #if 0
  1284. struct device *touchkey_dev;
  1285. int i;
  1286. #endif
  1287. int ret = 0;
  1288. #if defined(CONFIG_FB_MSM8x26_MDSS_CHECK_LCD_CONNECTION)
  1289. if (get_lcd_attached() == 0) {
  1290. dev_err(&client->dev, "%s : get_lcd_attached()=0 \n", __func__);
  1291. return -EIO;
  1292. }
  1293. #endif
  1294. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  1295. dev_err(&client->dev,
  1296. "i2c_check_functionality fail\n");
  1297. return -EIO;
  1298. }
  1299. info = kzalloc(sizeof(struct abov_tk_info), GFP_KERNEL);
  1300. if (!info) {
  1301. dev_err(&client->dev, "Failed to allocate memory\n");
  1302. ret = -ENOMEM;
  1303. goto err_alloc;
  1304. }
  1305. input_dev = input_allocate_device();
  1306. if (!input_dev) {
  1307. dev_err(&client->dev,
  1308. "Failed to allocate memory for input device\n");
  1309. ret = -ENOMEM;
  1310. goto err_input_alloc;
  1311. }
  1312. #if defined (CONFIG_SEC_HESTIA_PROJECT)
  1313. if( system_rev < 04 )
  1314. ABOV_ID = 0x26;
  1315. #endif
  1316. info->client = client;
  1317. info->input_dev = input_dev;
  1318. if (client->dev.of_node) {
  1319. struct abov_touchkey_platform_data *pdata;
  1320. pdata = devm_kzalloc(&client->dev,
  1321. sizeof(struct abov_touchkey_platform_data), GFP_KERNEL);
  1322. if (!pdata) {
  1323. dev_err(&client->dev, "Failed to allocate memory\n");
  1324. return -ENOMEM;
  1325. }
  1326. ret = abov_parse_dt(&client->dev, pdata);
  1327. if (ret)
  1328. return ret;
  1329. info->pdata = pdata;
  1330. } else
  1331. info->pdata = client->dev.platform_data;
  1332. if (info->pdata == NULL) {
  1333. pr_err("failed to get platform data\n");
  1334. goto err_config;
  1335. }
  1336. ret = abov_gpio_reg_init(&client->dev, info->pdata);
  1337. if(ret){
  1338. dev_err(&client->dev, "failed to init reg\n");
  1339. goto pwr_config;
  1340. }
  1341. if (info->pdata->power){
  1342. info->fw_update_possible = true;
  1343. info->pdata->power(info->pdata, true);
  1344. }
  1345. info->irq = -1;
  1346. mutex_init(&info->lock);
  1347. if (info->pdata->gpio_rst) {
  1348. info->fw_update_possible = true;
  1349. /*s3c_gpio_setpull(info->pdata->gpio_rst, S3C_GPIO_PULL_UP);*/
  1350. abov_tk_reset_for_bootmode(info);
  1351. msleep(ABOV_RESET_DELAY);
  1352. } else
  1353. info->fw_update_possible = false;
  1354. info->input_event = info->pdata->input_event;
  1355. info->touchkey_count = sizeof(touchkey_keycode) / sizeof(int);
  1356. i2c_set_clientdata(client, info);
  1357. ret = abov_tk_fw_check(info);
  1358. if (ret) {
  1359. dev_err(&client->dev,
  1360. "failed to firmware check (%d)\n", ret);
  1361. goto err_reg_input_dev;
  1362. }
  1363. abov_tk_dual_detection_mode(info, 1);
  1364. snprintf(info->phys, sizeof(info->phys),
  1365. "%s/input0", dev_name(&client->dev));
  1366. input_dev->name = "sec_touchkey";
  1367. input_dev->phys = info->phys;
  1368. input_dev->id.bustype = BUS_HOST;
  1369. input_dev->dev.parent = &client->dev;
  1370. #ifdef CONFIG_INPUT_ENABLED
  1371. input_dev->open = abov_tk_input_open;
  1372. input_dev->close = abov_tk_input_close;
  1373. #endif
  1374. set_bit(EV_KEY, input_dev->evbit);
  1375. set_bit(KEY_RECENT, input_dev->keybit);
  1376. set_bit(KEY_BACK, input_dev->keybit);
  1377. set_bit(EV_LED, input_dev->evbit);
  1378. set_bit(LED_MISC, input_dev->ledbit);
  1379. input_set_drvdata(input_dev, info);
  1380. ret = input_register_device(input_dev);
  1381. if (ret) {
  1382. dev_err(&client->dev, "failed to register input dev (%d)\n",
  1383. ret);
  1384. goto err_reg_input_dev;
  1385. }
  1386. info->enabled = true;
  1387. if (!info->pdata->irq_flag) {
  1388. dev_err(&client->dev, "no irq_flag\n");
  1389. ret = request_threaded_irq(client->irq, NULL, abov_tk_interrupt,
  1390. IRQF_TRIGGER_FALLING, ABOV_TK_NAME, info);
  1391. } else {
  1392. ret = request_threaded_irq(client->irq, NULL, abov_tk_interrupt,
  1393. info->pdata->irq_flag, ABOV_TK_NAME, info);
  1394. }
  1395. if (ret < 0) {
  1396. dev_err(&client->dev, "Failed to register interrupt\n");
  1397. goto err_req_irq;
  1398. }
  1399. info->irq = client->irq;
  1400. #ifdef CONFIG_HAS_EARLYSUSPEND
  1401. info->early_suspend.level = EARLY_SUSPEND_LEVEL_STOP_DRAWING;
  1402. info->early_suspend.suspend = abov_tk_early_suspend;
  1403. info->early_suspend.resume = abov_tk_late_resume;
  1404. register_early_suspend(&info->early_suspend);
  1405. #endif
  1406. sec_touchkey = device_create(sec_class,
  1407. NULL, 0, info, "sec_touchkey");
  1408. if (IS_ERR(sec_touchkey))
  1409. dev_err(&client->dev,
  1410. "Failed to create device for the touchkey sysfs\n");
  1411. ret = sysfs_create_link(&sec_touchkey->kobj,
  1412. &info->input_dev->dev.kobj, "input");
  1413. if (ret < 0) {
  1414. dev_err(&client->dev,
  1415. "%s: Failed to create input symbolic link\n",
  1416. __func__);
  1417. }
  1418. ret = sysfs_create_group(&sec_touchkey->kobj,
  1419. &sec_touchkey_attr_group);
  1420. if (ret)
  1421. dev_err(&client->dev, "Failed to create sysfs group\n");
  1422. dev_dbg(&client->dev, "%s done\n", __func__);
  1423. return 0;
  1424. err_req_irq:
  1425. input_unregister_device(input_dev);
  1426. err_reg_input_dev:
  1427. mutex_destroy(&info->lock);
  1428. pwr_config:
  1429. err_config:
  1430. input_free_device(input_dev);
  1431. err_input_alloc:
  1432. kfree(info);
  1433. err_alloc:
  1434. return ret;
  1435. }
  1436. static int __devexit abov_tk_remove(struct i2c_client *client)
  1437. {
  1438. struct abov_tk_info *info = i2c_get_clientdata(client);
  1439. /* if (info->enabled)
  1440. info->pdata->power(0);
  1441. */
  1442. info->enabled = false;
  1443. #ifdef CONFIG_HAS_EARLYSUSPEND
  1444. unregister_early_suspend(&info->early_suspend);
  1445. #endif
  1446. if (info->irq >= 0)
  1447. free_irq(info->irq, info);
  1448. input_unregister_device(info->input_dev);
  1449. input_free_device(info->input_dev);
  1450. kfree(info);
  1451. return 0;
  1452. }
  1453. static void abov_tk_shutdown(struct i2c_client *client)
  1454. {
  1455. struct abov_tk_info *info = i2c_get_clientdata(client);
  1456. u8 cmd = CMD_LED_OFF;
  1457. info->enabled = false;
  1458. abov_tk_i2c_write(client, ABOV_BTNSTATUS, &cmd, 1);
  1459. }
  1460. #if defined(CONFIG_PM)
  1461. static int abov_tk_suspend(struct device *dev)
  1462. {
  1463. struct i2c_client *client = to_i2c_client(dev);
  1464. struct abov_tk_info *info = i2c_get_clientdata(client);
  1465. #if defined(CONFIG_SEC_ATLANTIC_PROJECT)
  1466. u8 cmd;
  1467. #endif
  1468. if (!info->enabled)
  1469. return 0;
  1470. dev_notice(&info->client->dev, "%s: users=%d\n", __func__,
  1471. info->input_dev->users);
  1472. disable_irq(info->irq);
  1473. #if defined(CONFIG_SEC_ATLANTIC_PROJECT)
  1474. if(led_flag){
  1475. cmd = CMD_LED_OFF;
  1476. led_flag = 0;
  1477. dev_notice(&info->client->dev, "%s: led_flag=%d\n", __func__,
  1478. led_flag);
  1479. if(info->pdata->gpio_tkey_led_en >= 0)
  1480. gpio_direction_output(info->pdata->gpio_tkey_led_en,led_flag);
  1481. abov_tk_i2c_write(client, ABOV_BTNSTATUS, &cmd , 1);
  1482. }
  1483. #endif
  1484. info->enabled = false;
  1485. release_all_fingers(info);
  1486. #if defined (CONFIG_SEC_HESTIA_PROJECT)
  1487. if (info->pdata->power)
  1488. info->pdata->power(info->pdata, false);
  1489. #else
  1490. abov_sleep_mode(client, CMD_STOP_MODE);
  1491. #if defined(CONFIG_SEC_HESTIA_PROJECT)
  1492. if (system_rev < 6) {
  1493. if (info->pdata->gpio_rst)
  1494. gpio_direction_output(info->pdata->gpio_rst, 0);
  1495. }
  1496. #else
  1497. if (info->pdata->gpio_rst)
  1498. gpio_direction_output(info->pdata->gpio_rst, 0);
  1499. #endif
  1500. #endif
  1501. return 0;
  1502. }
  1503. static int abov_tk_resume(struct device *dev)
  1504. {
  1505. struct i2c_client *client = to_i2c_client(dev);
  1506. struct abov_tk_info *info = i2c_get_clientdata(client);
  1507. #if defined(CONFIG_SEC_ATLANTIC_PROJECT)
  1508. u8 cmd;
  1509. #endif
  1510. if (info->enabled)
  1511. return 0;
  1512. dev_notice(&info->client->dev, "%s: users=%d\n", __func__,
  1513. info->input_dev->users);
  1514. #if defined(CONFIG_SEC_ATLANTIC_PROJECT)
  1515. abov_tk_reset_for_bootmode(info);
  1516. msleep(ABOV_RESET_DELAY);
  1517. if (info->glovemode)
  1518. abov_glove_mode_enable(client, CMD_GLOVE_ON);
  1519. #else
  1520. if (info->pdata->power) {
  1521. info->pdata->power(info->pdata, true);
  1522. msleep(ABOV_RESET_DELAY);
  1523. } else
  1524. /* touchkey on by i2c */
  1525. get_tk_fw_version(info, true);
  1526. #endif
  1527. abov_tk_dual_detection_mode(info, 1);
  1528. info->enabled = true;
  1529. #if defined(CONFIG_SEC_ATLANTIC_PROJECT)
  1530. dev_notice(&info->client->dev, "%s: led_flag=%d\n", __func__,
  1531. led_flag);
  1532. if(led_flag){
  1533. cmd = CMD_LED_ON;
  1534. if(info->pdata->gpio_tkey_led_en >= 0)
  1535. gpio_direction_output(info->pdata->gpio_tkey_led_en,led_flag);
  1536. abov_tk_i2c_write(client, ABOV_BTNSTATUS, &cmd , 1);
  1537. led_flag = 0;
  1538. }
  1539. #endif
  1540. enable_irq(info->irq);
  1541. return 0;
  1542. }
  1543. #endif
  1544. #ifdef CONFIG_HAS_EARLYSUSPEND
  1545. static void abov_tk_early_suspend(struct early_suspend *h)
  1546. {
  1547. struct abov_tk_info *info;
  1548. info = container_of(h, struct abov_tk_info, early_suspend);
  1549. abov_tk_suspend(&info->client->dev);
  1550. }
  1551. static void abov_tk_late_resume(struct early_suspend *h)
  1552. {
  1553. struct abov_tk_info *info;
  1554. info = container_of(h, struct abov_tk_info, early_suspend);
  1555. abov_tk_resume(&info->client->dev);
  1556. }
  1557. #endif
  1558. #ifdef CONFIG_INPUT_ENABLED
  1559. static int abov_tk_input_open(struct input_dev *dev)
  1560. {
  1561. struct abov_tk_info *info = input_get_drvdata(dev);
  1562. dev_info(&info->client->dev, "%s: users=%d\n", __func__,
  1563. info->input_dev->users);
  1564. abov_tk_resume(&info->client->dev);
  1565. return 0;
  1566. }
  1567. static void abov_tk_input_close(struct input_dev *dev)
  1568. {
  1569. struct abov_tk_info *info = input_get_drvdata(dev);
  1570. dev_info(&info->client->dev, "%s: users=%d\n", __func__,
  1571. info->input_dev->users);
  1572. abov_tk_suspend(&info->client->dev);
  1573. }
  1574. #endif
  1575. #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND) &&\
  1576. !defined(CONFIG_INPUT_ENABLED)
  1577. static const struct dev_pm_ops abov_tk_pm_ops = {
  1578. .suspend = abov_tk_suspend,
  1579. .resume = abov_tk_resume,
  1580. };
  1581. #endif
  1582. static const struct i2c_device_id abov_tk_id[] = {
  1583. {ABOV_TK_NAME, 0},
  1584. {}
  1585. };
  1586. MODULE_DEVICE_TABLE(i2c, abov_tk_id);
  1587. #ifdef CONFIG_OF
  1588. static struct of_device_id abov_match_table[] = {
  1589. { .compatible = "abov,mc96ft16xx",},
  1590. { },
  1591. };
  1592. #else
  1593. #define abov_match_table NULL
  1594. #endif
  1595. static struct i2c_driver abov_tk_driver = {
  1596. .probe = abov_tk_probe,
  1597. .remove = __devexit_p(abov_tk_remove),
  1598. .shutdown = abov_tk_shutdown,
  1599. .driver = {
  1600. .name = ABOV_TK_NAME,
  1601. .of_match_table = abov_match_table,
  1602. #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND) &&\
  1603. !defined(CONFIG_INPUT_ENABLED)
  1604. .pm = &abov_tk_pm_ops,
  1605. #endif
  1606. },
  1607. .id_table = abov_tk_id,
  1608. };
  1609. static int __init touchkey_init(void)
  1610. {
  1611. #ifdef CONFIG_SAMSUNG_LPM_MODE
  1612. if (poweroff_charging) {
  1613. pr_notice("%s : LPM Charging Mode!!\n", __func__);
  1614. return 0;
  1615. }
  1616. #endif
  1617. return i2c_add_driver(&abov_tk_driver);
  1618. }
  1619. static void __exit touchkey_exit(void)
  1620. {
  1621. i2c_del_driver(&abov_tk_driver);
  1622. }
  1623. late_initcall(touchkey_init);
  1624. module_exit(touchkey_exit);
  1625. /* Module information */
  1626. MODULE_AUTHOR("Samsung Electronics");
  1627. MODULE_DESCRIPTION("Touchkey driver for Abov MF16xx chip");
  1628. MODULE_LICENSE("GPL");