abov_touchkey_patek.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668
  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/io.h>
  31. #include <mach/gpio.h>
  32. #include <asm/unaligned.h>
  33. #include <linux/regulator/consumer.h>
  34. #include <linux/wakelock.h>
  35. #ifdef CONFIG_OF
  36. #include <linux/of_gpio.h>
  37. #endif
  38. /* registers */
  39. #define ABOV_BTNSTATUS 0x00
  40. #define ABOV_FW_VER 0x01
  41. #define ABOV_PCB_VER 0x02
  42. #define ABOV_COMMAND 0x03
  43. #define ABOV_THRESHOLD 0x04
  44. #define ABOV_SETIDAC 0x06
  45. #define ABOV_DIFFDATA 0x0A
  46. #define ABOV_GLOVE 0x12
  47. #define ABOV_VENDORID 0x13
  48. #define ABOV_MODELNO 0x14
  49. #define ABOV_RAWDATA 0x15
  50. /* command */
  51. #define CMD_LED_ON 0x10
  52. #define CMD_LED_OFF 0x20
  53. #define CMD_DATA_UPDATE 0x40
  54. #define CMD_LED_CTRL_ON 0x60
  55. #define CMD_LED_CTRL_OFF 0x70
  56. #define CMD_STOP_MODE 0x80
  57. #define CMD_GLOVE_ON 0x20
  58. #define CMD_GLOVE_OFF 0x10
  59. #define ABOV_BOOT_DELAY 26
  60. #define ABOV_RESET_DELAY 150
  61. struct device *sec_touchkey;
  62. #define ABOV_TK_NAME "abov-touchkey"
  63. #define FW_VERSION 0x07
  64. #define FW_CHECKSUM_H 0xA2
  65. #define FW_CHECKSUM_L 0xD2
  66. #define TK_FW_PATH_BIN "abov/abov_tk_patek.fw"
  67. #define TK_FW_PATH_SDCARD "/sdcard/abov_fw.bin"
  68. #define I2C_M_WR 0 /* for i2c */
  69. enum {
  70. BUILT_IN = 0,
  71. SDCARD,
  72. };
  73. enum flip_status{
  74. FLIP_OPEN = 0,
  75. FLIP_CLOSE,
  76. };
  77. enum fw_update_status{
  78. FW_UP_SUCCESS = 0,
  79. FW_DOWNLOADING,
  80. FW_UP_FAILED,
  81. };
  82. #ifdef CONFIG_SAMSUNG_LPM_MODE
  83. extern int poweroff_charging;
  84. #endif
  85. extern unsigned int system_rev;
  86. extern struct class *sec_class;
  87. static int touchkey_keycode[] = { 0,
  88. KEY_RECENT, KEY_BACK, KEY_HOMEPAGE, KEY_TKEY_WAKEUP,
  89. };
  90. struct abov_touchkey_platform_data {
  91. unsigned long irq_flag;
  92. int gpio_int;
  93. int gpio_sda;
  94. int gpio_scl;
  95. int gpio_rst;
  96. int gpio_hall;
  97. int gpio_tkey_led_en;
  98. struct regulator *vdd_io_vreg;
  99. struct regulator *avdd_vreg;
  100. const char *supply_name;
  101. struct regulator *vtouch_3p3;
  102. void (*input_event) (void *data);
  103. int (*power) (struct abov_touchkey_platform_data *pdata, bool on);
  104. int (*keyled) (bool on);
  105. };
  106. struct abov_tk_info {
  107. struct i2c_client *client;
  108. struct input_dev *input_dev;
  109. struct abov_touchkey_platform_data *pdata;
  110. struct mutex lock;
  111. const struct firmware *firm_data_bin;
  112. const u8 *firm_data_ums;
  113. char phys[32];
  114. long firm_size;
  115. int irq;
  116. u16 menu_s;
  117. u16 back_s;
  118. u16 home_s;
  119. u16 menu_raw;
  120. u16 back_raw;
  121. u16 home_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 wakeup_mode;
  133. bool wakeup_state;
  134. struct wake_lock report_wake_lock;
  135. #ifdef CONFIG_DUAL_LCD
  136. int flip_status;
  137. #endif
  138. bool probe_done;
  139. };
  140. static int abov_touchkey_led_status;
  141. static int abov_touchled_cmd_reserved;
  142. static int abov_tk_suspend(struct device *dev);
  143. static int abov_tk_input_open(struct input_dev *dev);
  144. static void abov_tk_input_close(struct input_dev *dev);
  145. int abov_power(struct abov_touchkey_platform_data *pdata, bool on);
  146. #ifdef CONFIG_DUAL_LCD
  147. static struct abov_tk_info *tkey_driver = NULL;
  148. void abov_set_tkey_info(struct abov_tk_info *info)
  149. {
  150. if(info != NULL)
  151. tkey_driver = info;
  152. else
  153. pr_info("%s : tkey info is null\n", __func__);
  154. }
  155. static struct abov_tk_info *abov_get_tkey_info(void)
  156. {
  157. return tkey_driver;
  158. }
  159. #endif
  160. static int abov_glove_mode_enable(struct i2c_client *client, u8 cmd)
  161. {
  162. return i2c_smbus_write_byte_data(client, ABOV_GLOVE, cmd);
  163. }
  164. static int abov_tk_i2c_read(struct i2c_client *client,
  165. u8 reg, u8 *val, unsigned int len)
  166. {
  167. struct abov_tk_info *info = i2c_get_clientdata(client);
  168. struct i2c_msg msg;
  169. int ret;
  170. int retry = 3;
  171. mutex_lock(&info->lock);
  172. msg.addr = client->addr;
  173. msg.flags = I2C_M_WR;
  174. msg.len = 1;
  175. msg.buf = &reg;
  176. while (retry--) {
  177. ret = i2c_transfer(client->adapter, &msg, 1);
  178. if (ret >= 0)
  179. break;
  180. dev_err(&client->dev, "%s fail(address set)(%d)\n",
  181. __func__, retry);
  182. msleep(10);
  183. }
  184. if (ret < 0) {
  185. mutex_unlock(&info->lock);
  186. return ret;
  187. }
  188. retry = 3;
  189. msg.flags = 1;/*I2C_M_RD*/
  190. msg.len = len;
  191. msg.buf = val;
  192. while (retry--) {
  193. ret = i2c_transfer(client->adapter, &msg, 1);
  194. if (ret >= 0) {
  195. mutex_unlock(&info->lock);
  196. return 0;
  197. }
  198. dev_err(&client->dev, "%s fail(data read)(%d)\n",
  199. __func__, retry);
  200. msleep(10);
  201. }
  202. mutex_unlock(&info->lock);
  203. return ret;
  204. }
  205. static int abov_tk_i2c_write(struct i2c_client *client,
  206. u8 reg, u8 *val, unsigned int len)
  207. {
  208. struct abov_tk_info *info = i2c_get_clientdata(client);
  209. struct i2c_msg msg[1];
  210. unsigned char data[2];
  211. int ret;
  212. int retry = 3;
  213. mutex_lock(&info->lock);
  214. data[0] = reg;
  215. data[1] = *val;
  216. msg->addr = client->addr;
  217. msg->flags = I2C_M_WR;
  218. msg->len = 2;
  219. msg->buf = data;
  220. while (retry--) {
  221. ret = i2c_transfer(client->adapter, msg, 1);
  222. if (ret >= 0) {
  223. mutex_unlock(&info->lock);
  224. return 0;
  225. }
  226. dev_err(&client->dev, "%s fail(%d)\n",
  227. __func__, retry);
  228. msleep(10);
  229. }
  230. mutex_unlock(&info->lock);
  231. return ret;
  232. }
  233. static void release_all_fingers(struct abov_tk_info *info)
  234. {
  235. struct i2c_client *client = info->client;
  236. int i;
  237. dev_dbg(&client->dev, "[TK] %s\n", __func__);
  238. for (i = 1; i < info->touchkey_count; i++) {
  239. input_report_key(info->input_dev,
  240. touchkey_keycode[i], 0);
  241. }
  242. input_sync(info->input_dev);
  243. }
  244. static int abov_tk_reset_for_bootmode(struct abov_tk_info *info)
  245. {
  246. struct i2c_client *client = info->client;
  247. int rc = -1;
  248. if(info->pdata->vtouch_3p3){
  249. if(regulator_is_enabled(info->pdata->vtouch_3p3)){
  250. rc = regulator_disable(info->pdata->vtouch_3p3);
  251. if(rc)
  252. dev_err(&client->dev,
  253. "%s: failed to disable vtouch_3p3[%d]\n",__func__,rc);
  254. } else {
  255. dev_err(&client->dev,
  256. "%s: vtouch_3p3 is already disabled\n",__func__);
  257. }
  258. msleep(50);
  259. rc = regulator_enable(info->pdata->vtouch_3p3);
  260. if(rc)
  261. dev_err(&client->dev,
  262. "%s: failed to enable vtouch_3p3[%d]\n",__func__,rc);
  263. }
  264. return rc;
  265. }
  266. static void abov_tk_reset(struct abov_tk_info *info)
  267. {
  268. struct i2c_client *client = info->client;
  269. if (info->enabled == false)
  270. return;
  271. dev_notice(&client->dev, "%s++\n", __func__);
  272. disable_irq_nosync(info->irq);
  273. info->enabled = false;
  274. release_all_fingers(info);
  275. abov_tk_reset_for_bootmode(info);
  276. msleep(ABOV_RESET_DELAY);
  277. if (info->glovemode)
  278. abov_glove_mode_enable(client, CMD_GLOVE_ON);
  279. info->enabled = true;
  280. enable_irq(info->irq);
  281. dev_notice(&client->dev, "%s--\n", __func__);
  282. }
  283. static irqreturn_t abov_tk_interrupt(int irq, void *dev_id)
  284. {
  285. struct abov_tk_info *info = dev_id;
  286. struct i2c_client *client = info->client;
  287. int ret, retry;
  288. u8 buf, button;
  289. bool press;
  290. ret = abov_tk_i2c_read(client, ABOV_BTNSTATUS, &buf, 1);
  291. if (ret < 0) {
  292. retry = 3;
  293. while (retry--) {
  294. dev_err(&client->dev, "%s read fail(%d)\n",
  295. __func__, retry);
  296. ret = abov_tk_i2c_read(client, ABOV_BTNSTATUS, &buf, 1);
  297. if (ret == 0)
  298. break;
  299. else
  300. msleep(10);
  301. }
  302. if (retry == 0) {
  303. abov_tk_reset(info);
  304. return IRQ_HANDLED;
  305. }
  306. }
  307. button = buf & 0x07;
  308. press = !!(buf & 0x8);
  309. if (press) {
  310. input_report_key(info->input_dev,
  311. touchkey_keycode[button], 0);
  312. #ifdef CONFIG_SAMSUNG_PRODUCT_SHIP
  313. dev_notice(&client->dev,
  314. "key R\n");
  315. #else
  316. dev_notice(&client->dev,
  317. "key R : %d(%d) ver:0x%x\n",
  318. touchkey_keycode[button], buf, info->fw_ver);
  319. #endif
  320. } else {
  321. input_report_key(info->input_dev,
  322. touchkey_keycode[button], 1);
  323. #ifdef CONFIG_SAMSUNG_PRODUCT_SHIP
  324. dev_notice(&client->dev,
  325. "key P\n");
  326. #else
  327. dev_notice(&client->dev,
  328. "key P : %d(%d)\n",
  329. touchkey_keycode[button], buf);
  330. #endif
  331. }
  332. input_sync(info->input_dev);
  333. if (button == 4 && press){
  334. dev_info(&client->dev, "Double tab wakeup\n");
  335. wake_lock_timeout(&info->report_wake_lock, 3 * HZ);
  336. }
  337. return IRQ_HANDLED;
  338. }
  339. static ssize_t touchkey_led_control(struct device *dev,
  340. struct device_attribute *attr, const char *buf,
  341. size_t count)
  342. {
  343. struct abov_tk_info *info = dev_get_drvdata(dev);
  344. struct i2c_client *client = info->client;
  345. int data;
  346. int ret;
  347. u8 cmd;
  348. ret = sscanf(buf, "%d", &data);
  349. if (ret != 1) {
  350. dev_err(&client->dev, "%s: cmd read err\n", __func__);
  351. return count;
  352. }
  353. if (!(data == 0 || data == 1)) {
  354. dev_err(&client->dev, "%s: wrong command(%d)\n",
  355. __func__, data);
  356. return count;
  357. }
  358. if (data == 1)
  359. cmd = CMD_LED_ON;
  360. else
  361. cmd = CMD_LED_OFF;
  362. if (!info->enabled){
  363. abov_touchled_cmd_reserved = 1;
  364. goto out;
  365. }
  366. ret = abov_tk_i2c_write(client, ABOV_BTNSTATUS, &cmd, 1);
  367. if (ret < 0){
  368. dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
  369. abov_touchled_cmd_reserved = 1;
  370. goto out;
  371. }
  372. abov_touchled_cmd_reserved = 0;
  373. dev_info(&client->dev, "%s %s\n", __func__, data ? "ON" : "OFF");
  374. out:
  375. abov_touchkey_led_status = cmd;
  376. return count;
  377. }
  378. static ssize_t touchkey_threshold_show(struct device *dev,
  379. struct device_attribute *attr, char *buf)
  380. {
  381. struct abov_tk_info *info = dev_get_drvdata(dev);
  382. struct i2c_client *client = info->client;
  383. u8 r_buf;
  384. int ret;
  385. ret = abov_tk_i2c_read(client, ABOV_THRESHOLD, &r_buf, 1);
  386. if (ret < 0) {
  387. dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
  388. r_buf = 0;
  389. }
  390. return sprintf(buf, "%d\n", r_buf);
  391. }
  392. static void get_diff_data(struct abov_tk_info *info)
  393. {
  394. struct i2c_client *client = info->client;
  395. u8 r_buf[6];
  396. int ret;
  397. ret = abov_tk_i2c_read(client, ABOV_DIFFDATA, r_buf, 6);
  398. if (ret < 0) {
  399. dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
  400. info->menu_s = 0;
  401. info->back_s = 0;
  402. info->home_s = 0;
  403. return;
  404. }
  405. info->menu_s = (r_buf[0] << 8) | r_buf[1];
  406. info->back_s = (r_buf[2] << 8) | r_buf[3];
  407. info->home_s = (r_buf[4] << 8) | r_buf[5];
  408. }
  409. static ssize_t touchkey_menu_show(struct device *dev,
  410. struct device_attribute *attr, char *buf)
  411. {
  412. struct abov_tk_info *info = dev_get_drvdata(dev);
  413. get_diff_data(info);
  414. return sprintf(buf, "%d\n", info->menu_s);
  415. }
  416. static ssize_t touchkey_back_show(struct device *dev,
  417. struct device_attribute *attr, char *buf)
  418. {
  419. struct abov_tk_info *info = dev_get_drvdata(dev);
  420. get_diff_data(info);
  421. return sprintf(buf, "%d\n", info->back_s);
  422. }
  423. static ssize_t touchkey_home_show(struct device *dev,
  424. struct device_attribute *attr, char *buf)
  425. {
  426. struct abov_tk_info *info = dev_get_drvdata(dev);
  427. get_diff_data(info);
  428. return sprintf(buf, "%d\n", info->home_s);
  429. }
  430. static void get_raw_data(struct abov_tk_info *info)
  431. {
  432. struct i2c_client *client = info->client;
  433. u8 r_buf[6];
  434. int ret;
  435. ret = abov_tk_i2c_read(client, ABOV_RAWDATA, r_buf, 6);
  436. if (ret < 0) {
  437. dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
  438. info->menu_raw = 0;
  439. info->back_raw = 0;
  440. info->home_raw = 0;
  441. return;
  442. }
  443. info->menu_raw = (r_buf[0] << 8) | r_buf[1];
  444. info->back_raw = (r_buf[2] << 8) | r_buf[3];
  445. info->home_raw = (r_buf[4] << 8) | r_buf[5];
  446. }
  447. static ssize_t touchkey_menu_raw_show(struct device *dev,
  448. struct device_attribute *attr, char *buf)
  449. {
  450. struct abov_tk_info *info = dev_get_drvdata(dev);
  451. get_raw_data(info);
  452. return sprintf(buf, "%d\n", info->menu_raw);
  453. }
  454. static ssize_t touchkey_back_raw_show(struct device *dev,
  455. struct device_attribute *attr, char *buf)
  456. {
  457. struct abov_tk_info *info = dev_get_drvdata(dev);
  458. get_raw_data(info);
  459. return sprintf(buf, "%d\n", info->back_raw);
  460. }
  461. static ssize_t touchkey_home_raw_show(struct device *dev,
  462. struct device_attribute *attr, char *buf)
  463. {
  464. struct abov_tk_info *info = dev_get_drvdata(dev);
  465. get_raw_data(info);
  466. return sprintf(buf, "%d\n", info->home_raw);
  467. }
  468. static ssize_t bin_fw_ver(struct device *dev,
  469. struct device_attribute *attr, char *buf)
  470. {
  471. struct abov_tk_info *info = dev_get_drvdata(dev);
  472. struct i2c_client *client = info->client;
  473. dev_dbg(&client->dev, "fw version bin : 0x%x\n", FW_VERSION);
  474. return sprintf(buf, "0x%02x\n", FW_VERSION);
  475. }
  476. int get_tk_fw_version(struct abov_tk_info *info, bool bootmode)
  477. {
  478. struct i2c_client *client = info->client;
  479. u8 buf;
  480. int ret;
  481. int retry = 3;
  482. ret = abov_tk_i2c_read(client, ABOV_FW_VER, &buf, 1);
  483. if (ret < 0) {
  484. while (retry--) {
  485. dev_err(&client->dev, "%s read fail(%d)\n",
  486. __func__, retry);
  487. if (!bootmode)
  488. abov_tk_reset(info);
  489. else
  490. return -1;
  491. ret = abov_tk_i2c_read(client, ABOV_FW_VER, &buf, 1);
  492. if (ret == 0)
  493. break;
  494. }
  495. if (retry == 0)
  496. return -1;
  497. }
  498. info->fw_ver = buf;
  499. dev_info(&client->dev, "%s : 0x%x\n", __func__, buf);
  500. return 0;
  501. }
  502. static ssize_t read_fw_ver(struct device *dev,
  503. struct device_attribute *attr, char *buf)
  504. {
  505. struct abov_tk_info *info = dev_get_drvdata(dev);
  506. struct i2c_client *client = info->client;
  507. int ret;
  508. if(info->flip_status == FLIP_CLOSE || !info->fw_ver){
  509. ret = get_tk_fw_version(info, false);
  510. if (ret < 0) {
  511. dev_err(&client->dev, "%s read fail\n", __func__);
  512. info->fw_ver = 0;
  513. }
  514. }
  515. return sprintf(buf, "0x%02x\n", info->fw_ver);
  516. }
  517. static int abov_load_fw(struct abov_tk_info *info, u8 cmd)
  518. {
  519. struct i2c_client *client = info->client;
  520. struct file *fp;
  521. mm_segment_t old_fs;
  522. long fsize, nread;
  523. int ret = 0;
  524. switch(cmd) {
  525. case BUILT_IN:
  526. ret = request_firmware(&info->firm_data_bin,
  527. TK_FW_PATH_BIN, &client->dev);
  528. if (ret) {
  529. dev_err(&client->dev,
  530. "%s request_firmware fail(%d)\n", __func__, cmd);
  531. return ret;
  532. }
  533. info->firm_size = info->firm_data_bin->size;
  534. break;
  535. case SDCARD:
  536. old_fs = get_fs();
  537. set_fs(get_ds());
  538. fp = filp_open(TK_FW_PATH_SDCARD, O_RDONLY, S_IRUSR);
  539. if (IS_ERR(fp)) {
  540. dev_err(&client->dev,
  541. "%s %s open error\n", __func__, TK_FW_PATH_SDCARD);
  542. ret = -ENOENT;
  543. goto fail_sdcard_open;
  544. }
  545. fsize = fp->f_path.dentry->d_inode->i_size;
  546. info->firm_data_ums = kzalloc((size_t)fsize, GFP_KERNEL);
  547. if (!info->firm_data_ums) {
  548. dev_err(&client->dev,
  549. "%s fail to kzalloc for fw\n", __func__);
  550. ret = -ENOMEM;
  551. goto fail_sdcard_kzalloc;
  552. }
  553. nread = vfs_read(fp,
  554. (char __user *)info->firm_data_ums, fsize, &fp->f_pos);
  555. if (nread != fsize) {
  556. dev_err(&client->dev,
  557. "%s fail to vfs_read file\n", __func__);
  558. ret = -EINVAL;
  559. goto fail_sdcard_size;
  560. }
  561. filp_close(fp, current->files);
  562. set_fs(old_fs);
  563. info->firm_size = nread;
  564. break;
  565. default:
  566. ret = -1;
  567. break;
  568. }
  569. dev_notice(&client->dev, "fw_size : %lu\n", info->firm_size);
  570. dev_notice(&client->dev, "%s success\n", __func__);
  571. return ret;
  572. fail_sdcard_size:
  573. kfree(&info->firm_data_ums);
  574. fail_sdcard_kzalloc:
  575. filp_close(fp, current->files);
  576. fail_sdcard_open:
  577. set_fs(old_fs);
  578. return ret;
  579. }
  580. static void abov_release_fw(struct abov_tk_info *info, u8 cmd)
  581. {
  582. switch(cmd) {
  583. case BUILT_IN:
  584. release_firmware(info->firm_data_bin);
  585. break;
  586. case SDCARD:
  587. kfree(info->firm_data_ums);
  588. break;
  589. default:
  590. break;
  591. }
  592. }
  593. static int abov_tk_check_busy(struct abov_tk_info *info)
  594. {
  595. int ret, count = 0;
  596. unsigned char val = 0x00;
  597. do {
  598. ret = i2c_master_recv(info->client, &val, sizeof(val));
  599. if (val) {
  600. count++;
  601. } else {
  602. break;
  603. }
  604. } while(1);
  605. if (count > 1000)
  606. pr_err("%s: busy %d\n", __func__, count);
  607. return ret;
  608. }
  609. static int abov_tk_i2c_read_checksum(struct abov_tk_info *info)
  610. {
  611. unsigned char data[6] = {0xAC, 0x9E, 0x10, 0x00, 0x3F, 0xFF};
  612. unsigned char checksum[5] = {0, };
  613. int ret;
  614. unsigned char reg = 0x00;
  615. i2c_master_send(info->client, data, 6);
  616. usleep(5 * 1000);
  617. abov_tk_check_busy(info);
  618. ret = abov_tk_i2c_read(info->client, reg, checksum, 5);
  619. dev_info(&info->client->dev, "%s: ret:%d [%X][%X][%X][%X][%X]\n",
  620. __func__, ret, checksum[0], checksum[1], checksum[2]
  621. , checksum[3], checksum[4]);
  622. info->checksum_h = checksum[3];
  623. info->checksum_l = checksum[4];
  624. return 0;
  625. }
  626. static int abov_tk_fw_write(struct abov_tk_info *info, unsigned char *addrH,
  627. unsigned char *addrL, unsigned char *val)
  628. {
  629. int length = 36, ret = 0;
  630. unsigned char data[36];
  631. data[0] = 0xAC;
  632. data[1] = 0x7A;
  633. memcpy(&data[2], addrH, 1);
  634. memcpy(&data[3], addrL, 1);
  635. memcpy(&data[4], val, 32);
  636. ret = i2c_master_send(info->client, data, length);
  637. if (ret != length) {
  638. pr_err("%s: write fail[%x%x], %d\n", __func__, *addrH, *addrL, ret);
  639. return ret;
  640. }
  641. usleep(2 * 1000);
  642. abov_tk_check_busy(info);
  643. return 0;
  644. }
  645. static int abov_tk_fw_mode_enter(struct abov_tk_info *info)
  646. {
  647. unsigned char data[3] = {0xAC, 0x5B, 0x2D};
  648. int ret = 0;
  649. ret = i2c_master_send(info->client, data, 3);
  650. if (ret != 3) {
  651. pr_err("%s: write fail %d\n", __func__, ret);
  652. return ret;
  653. }
  654. return 0;
  655. }
  656. static int abov_tk_fw_update(struct abov_tk_info *info, u8 cmd)
  657. {
  658. int ret, ii = 0;
  659. int count;
  660. unsigned short address;
  661. unsigned char addrH, addrL;
  662. unsigned char data[32] = {0, };
  663. count = info->firm_size / 32;
  664. address = 0x1000;
  665. abov_power(info->pdata, 0);
  666. msleep(30);
  667. abov_power(info->pdata, 1);
  668. usleep(26 * 1000);
  669. ret = abov_tk_fw_mode_enter(info);
  670. pr_info("%s: enter BL mode, ret = %d\n", __func__, ret);
  671. msleep(700);
  672. for (ii = 0; ii < count; ii++) {
  673. addrH = (unsigned char)((address >> 8) & 0xFF);
  674. addrL = (unsigned char)(address & 0xFF);
  675. if (cmd == BUILT_IN)
  676. memcpy(data, &info->firm_data_bin->data[ii * 32], 32);
  677. else if(cmd == SDCARD)
  678. memcpy(data, &info->firm_data_ums[ii * 32], 32);
  679. ret = abov_tk_fw_write(info, &addrH, &addrL, data);
  680. if (ret < 0) {
  681. pr_err("%s: err, no device : %d\n", __func__, ret);
  682. return ret;
  683. }
  684. usleep(2 * 1000);
  685. abov_tk_check_busy(info);
  686. address += 0x20;
  687. memset(data, 0, 32);
  688. }
  689. ret = abov_tk_i2c_read_checksum(info);
  690. return ret;
  691. }
  692. static int abov_flash_fw(struct abov_tk_info *info, bool probe, u8 cmd)
  693. {
  694. struct i2c_client *client = info->client;
  695. int retry = 3;
  696. int ret;
  697. ret = get_tk_fw_version(info, probe);
  698. if (ret)
  699. info->fw_ver = 0;
  700. ret = abov_load_fw(info, cmd);
  701. if (ret) {
  702. dev_err(&client->dev,
  703. "%s fw load fail\n", __func__);
  704. return ret;
  705. }
  706. while (retry--) {
  707. ret = abov_tk_fw_update(info, cmd);
  708. if (ret < 0)
  709. break;
  710. if (cmd == BUILT_IN) {
  711. if ((info->checksum_h != FW_CHECKSUM_H) ||
  712. (info->checksum_l != FW_CHECKSUM_L)) {
  713. dev_err(&client->dev,
  714. "%s checksum fail. IC(0x%x,0x%x), BN(0x%x,0x%x) retry:%d\n",
  715. __func__, info->checksum_h, info->checksum_l,
  716. FW_CHECKSUM_H, FW_CHECKSUM_L, retry);
  717. ret = -1;
  718. continue;
  719. }
  720. }
  721. abov_tk_reset_for_bootmode(info);
  722. msleep(ABOV_RESET_DELAY);
  723. ret = get_tk_fw_version(info, true);
  724. if (ret) {
  725. dev_err(&client->dev, "%s fw version read fail\n", __func__);
  726. ret = -1;
  727. continue;
  728. }
  729. if (info->fw_ver == 0) {
  730. dev_err(&client->dev, "%s fw version fail (0x%x)\n",
  731. __func__, info->fw_ver);
  732. ret = -1;
  733. continue;
  734. }
  735. if ((cmd == BUILT_IN) && (info->fw_ver != FW_VERSION)) {
  736. dev_err(&client->dev, "%s fw version fail 0x%x, 0x%x\n",
  737. __func__, info->fw_ver, FW_VERSION);
  738. ret = -1;
  739. continue;
  740. }
  741. ret = 0;
  742. break;
  743. }
  744. abov_release_fw(info, cmd);
  745. return ret;
  746. }
  747. static ssize_t touchkey_fw_update(struct device *dev,
  748. struct device_attribute *attr, const char *buf, size_t count)
  749. {
  750. struct abov_tk_info *info = dev_get_drvdata(dev);
  751. struct i2c_client *client = info->client;
  752. int ret;
  753. u8 cmd;
  754. if (info->fw_update_possible == false) {
  755. dev_err(&client->dev, "%s fail (no reset pin)\n", __func__);
  756. info->fw_update_state = FW_UP_FAILED;
  757. goto touchkey_fw_update_out;
  758. }
  759. switch(*buf) {
  760. case 's':
  761. case 'S':
  762. cmd = BUILT_IN;
  763. break;
  764. case 'i':
  765. case 'I':
  766. cmd = SDCARD;
  767. break;
  768. default:
  769. info->fw_update_state = FW_UP_FAILED;
  770. goto touchkey_fw_update_out;
  771. }
  772. info->fw_update_state = FW_DOWNLOADING;
  773. disable_irq(info->irq);
  774. info->enabled = false;
  775. ret = abov_flash_fw(info, false, cmd);
  776. if (info->glovemode)
  777. abov_glove_mode_enable(client, CMD_GLOVE_ON);
  778. info->enabled = true;
  779. enable_irq(info->irq);
  780. if (ret) {
  781. dev_err(&client->dev, "%s fail\n", __func__);
  782. info->fw_update_state = FW_UP_FAILED;
  783. } else {
  784. dev_notice(&client->dev, "%s success\n", __func__);
  785. info->fw_update_state = FW_UP_SUCCESS;
  786. }
  787. touchkey_fw_update_out:
  788. dev_dbg(&client->dev, "%s : %d\n", __func__, info->fw_update_state);
  789. return count;
  790. }
  791. static ssize_t touchkey_fw_update_status(struct device *dev,
  792. struct device_attribute *attr, char *buf)
  793. {
  794. struct abov_tk_info *info = dev_get_drvdata(dev);
  795. struct i2c_client *client = info->client;
  796. int count = 0;
  797. dev_info(&client->dev, "%s : %d\n", __func__, info->fw_update_state);
  798. if (info->fw_update_state == FW_UP_SUCCESS)
  799. count = sprintf(buf, "PASS\n");
  800. else if (info->fw_update_state == FW_DOWNLOADING)
  801. count = sprintf(buf, "Downloading\n");
  802. else if (info->fw_update_state == FW_UP_FAILED)
  803. count = sprintf(buf, "Fail\n");
  804. return count;
  805. }
  806. static ssize_t abov_glove_mode(struct device *dev,
  807. struct device_attribute *attr, const char *buf, size_t count)
  808. {
  809. struct abov_tk_info *info = dev_get_drvdata(dev);
  810. struct i2c_client *client = info->client;
  811. int scan_buffer;
  812. int ret;
  813. u8 cmd;
  814. ret = sscanf(buf, "%d", &scan_buffer);
  815. if (ret != 1) {
  816. dev_err(&client->dev, "%s: cmd read err\n", __func__);
  817. return count;
  818. }
  819. if (!(scan_buffer == 0 || scan_buffer == 1)) {
  820. dev_err(&client->dev, "%s: wrong command(%d)\n",
  821. __func__, scan_buffer);
  822. return count;
  823. }
  824. if (!info->enabled)
  825. return count;
  826. if (info->glovemode == scan_buffer) {
  827. dev_info(&client->dev, "%s same command(%d)\n",
  828. __func__, scan_buffer);
  829. return count;
  830. }
  831. if (scan_buffer == 1) {
  832. dev_notice(&client->dev, "%s glove mode\n", __func__);
  833. cmd = CMD_GLOVE_ON;
  834. } else {
  835. dev_notice(&client->dev, "%s normal mode\n", __func__);
  836. cmd = CMD_GLOVE_OFF;
  837. }
  838. ret = abov_glove_mode_enable(client, cmd);
  839. if (ret < 0) {
  840. dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
  841. return count;
  842. }
  843. info->glovemode = scan_buffer;
  844. return count;
  845. }
  846. static ssize_t abov_glove_mode_show(struct device *dev,
  847. struct device_attribute *attr, char *buf)
  848. {
  849. struct abov_tk_info *info = dev_get_drvdata(dev);
  850. return sprintf(buf, "%d\n", info->glovemode);
  851. }
  852. static ssize_t abov_wakeup_mode(struct device *dev,
  853. struct device_attribute *attr, const char *buf, size_t count)
  854. {
  855. struct abov_tk_info *info = dev_get_drvdata(dev);
  856. int scan_buffer;
  857. int ret;
  858. ret = sscanf(buf, "%d", &scan_buffer);
  859. if (ret != 1)
  860. goto err;
  861. if (!(scan_buffer == 0 || scan_buffer == 1))
  862. goto err;
  863. if(scan_buffer == 1)
  864. info->wakeup_mode = true;
  865. else
  866. info->wakeup_mode = false;
  867. dev_info(dev, "%s : Set to %s mode\n",
  868. __func__, info->wakeup_mode ? "wakeup" : "normal");
  869. err:
  870. return count;
  871. }
  872. static ssize_t abov_wakeup_mode_show(struct device *dev,
  873. struct device_attribute *attr, char *buf)
  874. {
  875. struct abov_tk_info *info = dev_get_drvdata(dev);
  876. return sprintf(buf, "%d\n", info->wakeup_mode);
  877. }
  878. static DEVICE_ATTR(touchkey_threshold, S_IRUGO, touchkey_threshold_show, NULL);
  879. static DEVICE_ATTR(brightness, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  880. touchkey_led_control);
  881. static DEVICE_ATTR(touchkey_recent, S_IRUGO, touchkey_menu_show, NULL);
  882. static DEVICE_ATTR(touchkey_back, S_IRUGO, touchkey_back_show, NULL);
  883. static DEVICE_ATTR(touchkey_home, S_IRUGO, touchkey_home_show, NULL);
  884. static DEVICE_ATTR(touchkey_raw_recent, S_IRUGO, touchkey_menu_raw_show, NULL);
  885. static DEVICE_ATTR(touchkey_raw_back, S_IRUGO, touchkey_back_raw_show, NULL);
  886. static DEVICE_ATTR(touchkey_raw_home, S_IRUGO, touchkey_home_raw_show, NULL);
  887. static DEVICE_ATTR(touchkey_firm_version_phone, S_IRUGO, bin_fw_ver, NULL);
  888. static DEVICE_ATTR(touchkey_firm_version_panel, S_IRUGO, read_fw_ver, NULL);
  889. static DEVICE_ATTR(touchkey_firm_update, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  890. touchkey_fw_update);
  891. static DEVICE_ATTR(touchkey_firm_update_status, S_IRUGO | S_IWUSR | S_IWGRP,
  892. touchkey_fw_update_status, NULL);
  893. static DEVICE_ATTR(glove_mode, S_IRUGO | S_IWUSR | S_IWGRP,
  894. abov_glove_mode_show, abov_glove_mode);
  895. static DEVICE_ATTR(two_touch_wakeup_mode, S_IRUGO | S_IWUSR | S_IWGRP,
  896. abov_wakeup_mode_show, abov_wakeup_mode);
  897. static struct attribute *sec_touchkey_attributes[] = {
  898. &dev_attr_touchkey_threshold.attr,
  899. &dev_attr_brightness.attr,
  900. &dev_attr_touchkey_recent.attr,
  901. &dev_attr_touchkey_back.attr,
  902. &dev_attr_touchkey_home.attr,
  903. &dev_attr_touchkey_raw_recent.attr,
  904. &dev_attr_touchkey_raw_back.attr,
  905. &dev_attr_touchkey_raw_home.attr,
  906. &dev_attr_touchkey_firm_version_phone.attr,
  907. &dev_attr_touchkey_firm_version_panel.attr,
  908. &dev_attr_touchkey_firm_update.attr,
  909. &dev_attr_touchkey_firm_update_status.attr,
  910. &dev_attr_glove_mode.attr,
  911. &dev_attr_two_touch_wakeup_mode.attr,
  912. NULL,
  913. };
  914. static struct attribute_group sec_touchkey_attr_group = {
  915. .attrs = sec_touchkey_attributes,
  916. };
  917. static int abov_tk_fw_check(struct abov_tk_info *info)
  918. {
  919. struct i2c_client *client = info->client;
  920. int ret;
  921. ret = get_tk_fw_version(info, true);
  922. if (ret) {
  923. dev_err(&client->dev,
  924. "%s: i2c fail...[%d], addr[%d]\n",
  925. __func__, ret, info->client->addr);
  926. }
  927. if (!info->fw_update_possible)
  928. return ret;
  929. if (ret || info->fw_ver < FW_VERSION || info->fw_ver > 0xf0) {
  930. dev_err(&client->dev, "excute tk firmware update (0x%x -> 0x%x\n",
  931. info->fw_ver, FW_VERSION);
  932. ret = abov_flash_fw(info, true, BUILT_IN);
  933. if (ret) {
  934. dev_err(&client->dev,
  935. "failed to abov_flash_fw (%d)\n", ret);
  936. } else {
  937. dev_info(&client->dev,
  938. "fw update success\n");
  939. }
  940. }
  941. return ret;
  942. }
  943. int abov_power(struct abov_touchkey_platform_data *pdata, bool on)
  944. {
  945. int ret = 0;
  946. if(pdata->vtouch_3p3){
  947. if(on){
  948. if(regulator_is_enabled(pdata->vtouch_3p3))
  949. pr_err("%s: vtouch_3p3 is already enabled.\n",__func__);
  950. else {
  951. ret = regulator_enable(pdata->vtouch_3p3);
  952. if(ret){
  953. pr_err("%s: failed to enable vtouch_3p3. %d\n",
  954. __func__, ret);
  955. goto err;
  956. }
  957. }
  958. } else {
  959. if(regulator_is_enabled(pdata->vtouch_3p3)){
  960. ret = regulator_disable(pdata->vtouch_3p3);
  961. if(ret){
  962. pr_err("%s: failed to disable vtouch_3p3. %d\n",
  963. __func__, ret);
  964. goto err;
  965. }
  966. } else {
  967. pr_err("%s: vtouch_3p3 is already disabled.\n",__func__);
  968. }
  969. }
  970. pr_info("%s: vtouch_3p3 is %s\n", __func__,
  971. regulator_is_enabled(pdata->vtouch_3p3) ? "enabled" : "disabled");
  972. }
  973. err:
  974. return ret;
  975. }
  976. int abov_gpio_reg_init(struct device *dev,
  977. struct abov_touchkey_platform_data *pdata)
  978. {
  979. int ret = 0;
  980. ret = gpio_request(pdata->gpio_int, "tkey_gpio_int");
  981. if(ret < 0){
  982. dev_err(dev, "unable to request gpio_int\n");
  983. return ret;
  984. }
  985. gpio_tlmm_config(GPIO_CFG(pdata->gpio_int, 0, GPIO_CFG_INPUT,
  986. GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  987. pdata->vtouch_3p3 = regulator_get(dev, pdata->supply_name);
  988. if (IS_ERR(pdata->vtouch_3p3)){
  989. pdata->vtouch_3p3 = NULL;
  990. dev_err(dev, "pdata->vtouch_3p3 get error\n");
  991. return -1;
  992. }
  993. if(pdata->vtouch_3p3){
  994. ret = regulator_set_voltage(pdata->vtouch_3p3, 3300000, 3300000);
  995. if (ret)
  996. dev_err(dev, "unable to set voltage for 3.3v, %d\n", ret);
  997. }
  998. pdata->power = abov_power;
  999. return ret;
  1000. }
  1001. #ifdef CONFIG_OF
  1002. static int abov_parse_dt(struct device *dev,
  1003. struct abov_touchkey_platform_data *pdata)
  1004. {
  1005. struct device_node *np = dev->of_node;
  1006. int retval = 0;
  1007. pdata->gpio_int = of_get_named_gpio(np, "abov,irq-gpio", 0);
  1008. if(pdata->gpio_int < 0){
  1009. dev_err(dev, "unable to get gpio_int\n");
  1010. return pdata->gpio_int;
  1011. }
  1012. pdata->gpio_scl = of_get_named_gpio(np, "abov,scl-gpio", 0);
  1013. if(pdata->gpio_scl < 0){
  1014. dev_err(dev, "unable to get gpio_scl\n");
  1015. return pdata->gpio_scl;
  1016. }
  1017. pdata->gpio_sda = of_get_named_gpio(np, "abov,sda-gpio", 0);
  1018. if(pdata->gpio_sda < 0){
  1019. dev_err(dev, "unable to get gpio_sda\n");
  1020. return pdata->gpio_sda;
  1021. }
  1022. pdata->gpio_hall = of_get_named_gpio(np, "abov,hall_flip-gpio", 0);
  1023. if(pdata->gpio_hall < 0){
  1024. dev_err(dev, "unable to get gpio_hall\n");
  1025. }
  1026. retval = of_property_read_string(np, "abov,vtouch_3p3", &pdata->supply_name);
  1027. if (retval)
  1028. dev_err(dev, "unable to get name of vtouch_3p3, %d\n", retval);
  1029. dev_info(dev, "%s: gpio_int:%d, gpio_scl:%d, gpio_sda:%d\n",
  1030. __func__, pdata->gpio_int, pdata->gpio_scl, pdata->gpio_sda);
  1031. return retval;
  1032. }
  1033. #else
  1034. static int abov_parse_dt(struct device *dev,
  1035. struct abov_touchkey_platform_data *pdata)
  1036. {
  1037. return -ENODEV;
  1038. }
  1039. #endif
  1040. static int __devinit abov_tk_probe(struct i2c_client *client,
  1041. const struct i2c_device_id *id)
  1042. {
  1043. struct abov_tk_info *info;
  1044. struct input_dev *input_dev;
  1045. int ret = 0;
  1046. pr_info("%s\n",__func__);
  1047. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  1048. dev_err(&client->dev,
  1049. "i2c_check_functionality fail\n");
  1050. return -EIO;
  1051. }
  1052. info = kzalloc(sizeof(struct abov_tk_info), GFP_KERNEL);
  1053. if (!info) {
  1054. dev_err(&client->dev, "Failed to allocate memory\n");
  1055. ret = -ENOMEM;
  1056. goto err_alloc;
  1057. }
  1058. input_dev = input_allocate_device();
  1059. if (!input_dev) {
  1060. dev_err(&client->dev,
  1061. "Failed to allocate memory for input device\n");
  1062. ret = -ENOMEM;
  1063. goto err_input_alloc;
  1064. }
  1065. info->probe_done = false;
  1066. #ifdef CONFIG_DUAL_LCD
  1067. abov_set_tkey_info(info);
  1068. info->flip_status = -1;
  1069. #endif
  1070. info->client = client;
  1071. info->input_dev = input_dev;
  1072. info->wakeup_mode = false;
  1073. if (client->dev.of_node) {
  1074. struct abov_touchkey_platform_data *pdata;
  1075. pdata = devm_kzalloc(&client->dev,
  1076. sizeof(struct abov_touchkey_platform_data), GFP_KERNEL);
  1077. if (!pdata) {
  1078. dev_err(&client->dev, "Failed to allocate memory\n");
  1079. return -ENOMEM;
  1080. }
  1081. ret = abov_parse_dt(&client->dev, pdata);
  1082. if (ret)
  1083. return ret;
  1084. info->pdata = pdata;
  1085. } else
  1086. info->pdata = client->dev.platform_data;
  1087. if (info->pdata == NULL) {
  1088. pr_err("failed to get platform data\n");
  1089. goto err_config;
  1090. }
  1091. pr_info("%s %d\n",__func__,__LINE__);
  1092. ret = abov_gpio_reg_init(&client->dev, info->pdata);
  1093. if(ret){
  1094. dev_err(&client->dev, "failed to init reg\n");
  1095. goto pwr_config;
  1096. }
  1097. if (info->pdata->power)
  1098. info->pdata->power(info->pdata, true);
  1099. client->irq = gpio_to_irq(info->pdata->gpio_int);
  1100. pr_info("%s irq = %d\n",__func__,client->irq);
  1101. info->irq = -1;
  1102. mutex_init(&info->lock);
  1103. wake_lock_init(&info->report_wake_lock, WAKE_LOCK_SUSPEND, "report_wake_lock");
  1104. info->fw_update_possible = true;
  1105. abov_tk_reset_for_bootmode(info);
  1106. msleep(ABOV_RESET_DELAY);
  1107. pr_info("%s %d\n",__func__,__LINE__);
  1108. info->input_event = info->pdata->input_event;
  1109. info->touchkey_count = sizeof(touchkey_keycode) / sizeof(int);
  1110. i2c_set_clientdata(client, info);
  1111. ret = abov_tk_fw_check(info);
  1112. if (ret) {
  1113. dev_err(&client->dev,
  1114. "failed to firmware check (%d)\n", ret);
  1115. goto err_reg_input_dev;
  1116. }
  1117. snprintf(info->phys, sizeof(info->phys),
  1118. "%s/input0", dev_name(&client->dev));
  1119. input_dev->name = "sec_touchkey";
  1120. input_dev->phys = info->phys;
  1121. input_dev->id.bustype = BUS_HOST;
  1122. input_dev->dev.parent = &client->dev;
  1123. input_dev->open = abov_tk_input_open;
  1124. input_dev->close = abov_tk_input_close;
  1125. set_bit(EV_KEY, input_dev->evbit);
  1126. set_bit(KEY_RECENT, input_dev->keybit);
  1127. set_bit(KEY_BACK, input_dev->keybit);
  1128. set_bit(KEY_HOMEPAGE, input_dev->keybit);
  1129. set_bit(KEY_TKEY_WAKEUP, input_dev->keybit);
  1130. set_bit(EV_LED, input_dev->evbit);
  1131. set_bit(LED_MISC, input_dev->ledbit);
  1132. input_set_drvdata(input_dev, info);
  1133. ret = input_register_device(input_dev);
  1134. if (ret) {
  1135. dev_err(&client->dev, "failed to register input dev (%d)\n",
  1136. ret);
  1137. goto err_reg_input_dev;
  1138. }
  1139. info->enabled = true;
  1140. if (!info->pdata->irq_flag) {
  1141. dev_err(&client->dev, "no irq_flag\n");
  1142. ret = request_threaded_irq(client->irq, NULL, abov_tk_interrupt,
  1143. IRQF_TRIGGER_FALLING, ABOV_TK_NAME, info);
  1144. } else {
  1145. ret = request_threaded_irq(client->irq, NULL, abov_tk_interrupt,
  1146. info->pdata->irq_flag, ABOV_TK_NAME, info);
  1147. }
  1148. if (ret < 0) {
  1149. dev_err(&client->dev, "Failed to register interrupt %d\n", ret);
  1150. goto err_req_irq;
  1151. }
  1152. info->irq = client->irq;
  1153. pr_info("%s %d\n",__func__,__LINE__);
  1154. sec_touchkey = device_create(sec_class,
  1155. NULL, 0, info, "sec_touchkey");
  1156. if (IS_ERR(sec_touchkey))
  1157. dev_err(&client->dev,
  1158. "Failed to create device for the touchkey sysfs\n");
  1159. ret = sysfs_create_group(&sec_touchkey->kobj,
  1160. &sec_touchkey_attr_group);
  1161. if (ret)
  1162. dev_err(&client->dev, "Failed to create sysfs group\n");
  1163. ret = sysfs_create_link(&sec_touchkey->kobj,
  1164. &info->input_dev->dev.kobj, "input");
  1165. if (ret < 0) {
  1166. dev_err(&info->client->dev,
  1167. "%s: Failed to create input symbolic link\n",
  1168. __func__);
  1169. }
  1170. #ifdef CONFIG_DUAL_LCD
  1171. if(info->pdata->gpio_hall < 0)
  1172. /* default set : tkey enable */
  1173. info->flip_status = FLIP_CLOSE;
  1174. else
  1175. info->flip_status = !(gpio_get_value(info->pdata->gpio_hall));
  1176. dev_info(&client->dev, "%s: Folder is %sed now.\n",
  1177. __func__, info->flip_status ? "clos":"open");
  1178. if (!info->flip_status)
  1179. abov_tk_suspend(&client->dev);
  1180. #endif
  1181. info->probe_done = true;
  1182. pr_info("%s done\n", __func__);
  1183. return 0;
  1184. err_req_irq:
  1185. input_unregister_device(input_dev);
  1186. err_reg_input_dev:
  1187. mutex_destroy(&info->lock);
  1188. pwr_config:
  1189. err_config:
  1190. #ifdef CONFIG_DUAL_LCD
  1191. tkey_driver = NULL;
  1192. #endif
  1193. input_free_device(input_dev);
  1194. err_input_alloc:
  1195. kfree(info);
  1196. err_alloc:
  1197. return ret;
  1198. }
  1199. static int __devexit abov_tk_remove(struct i2c_client *client)
  1200. {
  1201. struct abov_tk_info *info = i2c_get_clientdata(client);
  1202. /* if (info->enabled)
  1203. info->pdata->power(0);
  1204. */
  1205. info->enabled = false;
  1206. if (info->irq >= 0)
  1207. free_irq(info->irq, info);
  1208. input_unregister_device(info->input_dev);
  1209. input_free_device(info->input_dev);
  1210. kfree(info);
  1211. return 0;
  1212. }
  1213. static void abov_tk_shutdown(struct i2c_client *client)
  1214. {
  1215. struct abov_tk_info *info = i2c_get_clientdata(client);
  1216. u8 cmd = CMD_LED_OFF;
  1217. info->enabled = false;
  1218. abov_tk_i2c_write(client, ABOV_BTNSTATUS, &cmd, 1);
  1219. }
  1220. static int abov_tk_suspend(struct device *dev)
  1221. {
  1222. struct i2c_client *client = to_i2c_client(dev);
  1223. struct abov_tk_info *info = i2c_get_clientdata(client);
  1224. u8 cmd;
  1225. int ret;
  1226. if (!info->enabled)
  1227. return 0;
  1228. printk("Inside abov_tk_suspend \n");
  1229. dev_dbg(&info->client->dev, "%s: users=%d\n", __func__,
  1230. info->input_dev->users);
  1231. if (info->wakeup_mode && info->flip_status == FLIP_CLOSE){
  1232. /*Enter WAKEUP mode*/
  1233. cmd = CMD_STOP_MODE;
  1234. ret = abov_tk_i2c_write(client, ABOV_BTNSTATUS, &cmd, 1);
  1235. if (ret < 0){
  1236. dev_err(dev,
  1237. "%s : failed to write wakeup mode(%d)\n",
  1238. __func__, ret);
  1239. return 0;
  1240. }
  1241. dev_info(dev,
  1242. "%s : success to enter tkey wakeup state\n",
  1243. __func__);
  1244. release_all_fingers(info);
  1245. enable_irq_wake(info->irq);
  1246. info->enabled = false;
  1247. info->wakeup_state = true;
  1248. }
  1249. else {
  1250. disable_irq(info->irq);
  1251. info->enabled = false;
  1252. info->wakeup_state = false;
  1253. release_all_fingers(info);
  1254. if (info->pdata->power)
  1255. info->pdata->power(info->pdata, false);
  1256. }
  1257. return 0;
  1258. }
  1259. static int abov_tk_resume(struct device *dev)
  1260. {
  1261. struct i2c_client *client = to_i2c_client(dev);
  1262. struct abov_tk_info *info = i2c_get_clientdata(client);
  1263. u8 led_data;
  1264. if (info->enabled)
  1265. return 0;
  1266. #ifdef CONFIG_DUAL_LCD
  1267. if (info->flip_status == FLIP_OPEN){
  1268. dev_err(&info->client->dev,
  1269. "%s: flip is opened, so resume is ignored.\n", __func__);
  1270. return 0;
  1271. }
  1272. #endif
  1273. printk("Inside abov_tk_resume \n");
  1274. dev_dbg(&info->client->dev, "%s: users=%d\n", __func__,
  1275. info->input_dev->users);
  1276. if (info->wakeup_state){
  1277. dev_info(dev, "%s: tkey wakeup\n", __func__);
  1278. disable_irq_wake(info->irq);
  1279. info->wakeup_state = false;
  1280. disable_irq(info->irq);
  1281. if(info->pdata->power)
  1282. info->pdata->power(info->pdata, false);
  1283. usleep(5 * 1000);
  1284. }
  1285. #if 0
  1286. abov_tk_reset_for_bootmode(info);
  1287. msleep(ABOV_RESET_DELAY);
  1288. if (info->glovemode)
  1289. abov_glove_mode_enable(client, CMD_GLOVE_ON);
  1290. #else
  1291. if (info->pdata->power) {
  1292. info->pdata->power(info->pdata, true);
  1293. msleep(ABOV_RESET_DELAY);
  1294. } else
  1295. /* touchkey on by i2c */
  1296. get_tk_fw_version(info, true);
  1297. #endif
  1298. info->enabled = true;
  1299. if (abov_touchled_cmd_reserved && \
  1300. abov_touchkey_led_status == CMD_LED_ON) {
  1301. abov_touchled_cmd_reserved = 0;
  1302. led_data = abov_touchkey_led_status;
  1303. abov_tk_i2c_write(client, ABOV_BTNSTATUS, &led_data, 1);
  1304. dev_info(&info->client->dev, "%s: LED reserved on\n", __func__);
  1305. }
  1306. enable_irq(info->irq);
  1307. return 0;
  1308. }
  1309. #ifdef CONFIG_DUAL_LCD
  1310. void samsung_switching_tkey(int flip)
  1311. {
  1312. struct abov_tk_info *info;
  1313. info = abov_get_tkey_info();
  1314. if (info == NULL){
  1315. pr_err("[tkey] %s: tkey info is null\n", __func__);
  1316. return;
  1317. }
  1318. if (!info->probe_done){
  1319. dev_err(&info->client->dev,
  1320. "%s: touchkey probe is not done yet\n",
  1321. __func__);
  1322. return;
  1323. }
  1324. if(info->fw_update_state == FW_DOWNLOADING){
  1325. dev_err(&info->client->dev,
  1326. "%s: tk fw update is running. switching is ignored.\n",
  1327. __func__);
  1328. return;
  1329. }
  1330. dev_info(&info->client->dev,
  1331. "%s : flip: %d(now) change to %d, tk_enabled : %d\n",
  1332. __func__,info->flip_status, flip, info->enabled);
  1333. if (info->flip_status != flip)
  1334. {
  1335. info->flip_status = flip;
  1336. if (flip == FLIP_CLOSE) {
  1337. dev_info(&info->client->dev,
  1338. "%s : flip closed. tkey must be resumed.\n",
  1339. __func__);
  1340. abov_tk_resume(&info->client->dev);
  1341. }
  1342. else {
  1343. dev_info(&info->client->dev,
  1344. "%s : flip opened. tkey must be suspended\n",
  1345. __func__);
  1346. abov_tk_suspend(&info->client->dev);
  1347. }
  1348. }
  1349. }
  1350. EXPORT_SYMBOL(samsung_switching_tkey);
  1351. #endif
  1352. static int abov_tk_input_open(struct input_dev *dev)
  1353. {
  1354. struct abov_tk_info *info = input_get_drvdata(dev);
  1355. dev_info(&info->client->dev, "%s: users=%d\n", __func__,
  1356. info->input_dev->users);
  1357. abov_tk_resume(&info->client->dev);
  1358. return 0;
  1359. }
  1360. static void abov_tk_input_close(struct input_dev *dev)
  1361. {
  1362. struct abov_tk_info *info = input_get_drvdata(dev);
  1363. dev_info(&info->client->dev, "%s: users=%d\n", __func__,
  1364. info->input_dev->users);
  1365. abov_tk_suspend(&info->client->dev);
  1366. }
  1367. static const struct i2c_device_id abov_tk_id[] = {
  1368. {ABOV_TK_NAME, 0},
  1369. {}
  1370. };
  1371. MODULE_DEVICE_TABLE(i2c, abov_tk_id);
  1372. #ifdef CONFIG_OF
  1373. static struct of_device_id abov_match_table[] = {
  1374. { .compatible = "abov,mc96ft16xx",},
  1375. { },
  1376. };
  1377. #else
  1378. #define abov_match_table NULL
  1379. #endif
  1380. static struct i2c_driver abov_tk_driver = {
  1381. .probe = abov_tk_probe,
  1382. .remove = __devexit_p(abov_tk_remove),
  1383. .shutdown = abov_tk_shutdown,
  1384. .driver = {
  1385. .name = ABOV_TK_NAME,
  1386. .of_match_table = abov_match_table,
  1387. },
  1388. .id_table = abov_tk_id,
  1389. };
  1390. static int __init touchkey_init(void)
  1391. {
  1392. #ifdef CONFIG_SAMSUNG_LPM_MODE
  1393. if (poweroff_charging) {
  1394. pr_notice("%s : LPM Charging Mode!!\n", __func__);
  1395. return 0;
  1396. }
  1397. #endif
  1398. return i2c_add_driver(&abov_tk_driver);
  1399. }
  1400. static void __exit touchkey_exit(void)
  1401. {
  1402. i2c_del_driver(&abov_tk_driver);
  1403. }
  1404. module_init(touchkey_init);
  1405. module_exit(touchkey_exit);
  1406. /* Module information */
  1407. MODULE_AUTHOR("Samsung Electronics");
  1408. MODULE_DESCRIPTION("Touchkey driver for Abov MF16xx chip");
  1409. MODULE_LICENSE("GPL");