cypress-touchkey.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140
  1. /*
  2. * cypress_touchkey.c - Platform data for cypress touchkey driver
  3. *
  4. * Copyright (C) 2011 Samsung Electronics
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #define SEC_TOUCHKEY_DEBUG
  12. /* #define SEC_TOUCHKEY_VERBOSE_DEBUG */
  13. #include <linux/kernel.h>
  14. #include <asm/unaligned.h>
  15. //#include <mach/cpufreq.h>
  16. #include <linux/input/mt.h>
  17. #include <linux/of_gpio.h>
  18. #include <linux/regulator/consumer.h>
  19. #include <linux/module.h>
  20. #include <linux/input.h>
  21. #include <linux/init.h>
  22. #include <linux/slab.h>
  23. #include <linux/i2c.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/irq.h>
  26. #include <linux/delay.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/gpio.h>
  29. #include <linux/miscdevice.h>
  30. #include <linux/i2c/touchkey_i2c.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <asm/mach-types.h>
  33. #include <linux/device.h>
  34. /* #include <mach/msm8974-gpio.h> */
  35. #include <linux/of_gpio.h>
  36. #include <linux/firmware.h>
  37. #include <linux/uaccess.h>
  38. #include "issp_extern.h"
  39. #include "coreriver_extern.h"
  40. #include <linux/mfd/pm8xxx/pm8921.h>
  41. #ifdef CONFIG_HAS_EARLYSUSPEND
  42. #include <linux/earlysuspend.h>
  43. #endif
  44. /*
  45. #define CYPRESS_GEN 0X00
  46. #define CYPRESS_FW_VER 0X01
  47. #define CYPRESS_MODULE_VER 0X02
  48. #define CYPRESS_2ND_HOST 0X03
  49. #define CYPRESS_THRESHOLD 0X04
  50. #define CYPRESS_AUTO_CAL_FLG 0X05
  51. #define CYPRESS_IDAC_MENU 0X07
  52. #define CYPRESS_IDAC_BACK 0X06
  53. #define CYPRESS_IDAC_HOME 0X08
  54. #define CYPRESS_DIFF_MENU 0x0C
  55. #define CYPRESS_DIFF_BACK 0x0A
  56. #define CYPRESS_DIFF_HOME 0x0E
  57. #define CYPRESS_RAW_DATA_MENU 0x10
  58. #define CYPRESS_RAW_DATA_BACK 0x0E
  59. #define CYPRESS_RAW_DATA_HOME 0x12
  60. #define CYPRESS_RAW_DATA_BACK_GOGH 0x14
  61. #define CYPRESS_DATA_UPDATE 0X40
  62. #define CYPRESS_AUTO_CAL 0X50
  63. #define CYPRESS_SLEEP 0X80
  64. #define CYPRESS_FW_ID_REG 0X05
  65. #define USE_OPEN_CLOSE
  66. #undef DO_NOT_USE_FUNC_PARAM
  67. #define KEYCODE_REG 0x00
  68. */
  69. /* bit masks*/
  70. #define PRESS_BIT_MASK 0X08
  71. #define KEYCODE_BIT_MASK 0X07
  72. /*
  73. #define TOUCHKEY_LOG(k, v) dev_notice(&info->client->dev, "key[%d] %d\n", k, v);
  74. #define FUNC_CALLED dev_notice(&info->client->dev, "%s: called.\n", __func__);
  75. */
  76. /*#define NUM_OF_KEY 4*/
  77. #ifdef USE_OPEN_CLOSE
  78. static int cypress_input_open(struct input_dev *dev);
  79. static void cypress_input_close(struct input_dev *dev);
  80. #endif
  81. #ifdef CONFIG_HAS_EARLYSUSPEND
  82. static void cypress_touchkey_early_suspend(struct early_suspend *h);
  83. static void cypress_touchkey_late_resume(struct early_suspend *h);
  84. #endif
  85. #ifdef TK_INFORM_CHARGER
  86. extern void touchkey_register_callback(void *cb);
  87. #endif
  88. static void cypress_config_gpio_i2c(struct cypress_touchkey_platform_data *pdata, int onoff);
  89. #ifdef TKEY_REQUEST_FW_UPDATE
  90. static int tkey_load_fw(struct cypress_touchkey_info *info, u8 fw_path);
  91. static int tkey_unload_fw(struct cypress_touchkey_info *info, u8 fw_path);
  92. #endif
  93. static int touchkey_led_status;
  94. static int touchled_cmd_reversed;
  95. #ifdef DO_NOT_USE_FUNC_PARAM
  96. static struct pm_gpio tkey_int = {
  97. .direction = PM_GPIO_DIR_IN,
  98. .pull = PM_GPIO_PULL_NO,
  99. .vin_sel = 2,
  100. .function = PM_GPIO_FUNC_NORMAL,
  101. .inv_int_pol = 0,
  102. };
  103. static struct pm_gpio tkey_sleep_int = {
  104. .direction = PM_GPIO_DIR_IN,
  105. .pull = PM_GPIO_PULL_UP_30,
  106. .vin_sel = 2,
  107. .function = PM_GPIO_FUNC_NORMAL,
  108. .inv_int_pol = 0,
  109. };
  110. #endif
  111. #ifdef TSP_BOOSTER
  112. static void cypress_change_dvfs_lock(struct work_struct *work)
  113. {
  114. struct cypress_touchkey_info *info =
  115. container_of(work,
  116. struct cypress_touchkey_info, work_dvfs_chg.work);
  117. int retval = 0;
  118. mutex_lock(&info->dvfs_lock);
  119. retval = set_freq_limit(DVFS_TOUCH_ID, info->dvfs_freq);
  120. if (retval < 0)
  121. dev_info(&info->client->dev,
  122. "%s: booster change failed(%d).\n",
  123. __func__, retval);
  124. info->dvfs_lock_status = false;
  125. mutex_unlock(&info->dvfs_lock);
  126. }
  127. static void cypress_set_dvfs_off(struct work_struct *work)
  128. {
  129. struct cypress_touchkey_info *info =
  130. container_of(work,
  131. struct cypress_touchkey_info, work_dvfs_off.work);
  132. int retval;
  133. mutex_lock(&info->dvfs_lock);
  134. retval = set_freq_limit(DVFS_TOUCH_ID, -1);
  135. if (retval < 0)
  136. dev_info(&info->client->dev,
  137. "%s: booster stop failed(%d).\n",
  138. __func__, retval);
  139. info->dvfs_lock_status = true;
  140. mutex_unlock(&info->dvfs_lock);
  141. }
  142. static void cypress_set_dvfs_lock(struct cypress_touchkey_info *info,
  143. uint32_t on)
  144. {
  145. int ret = 0;
  146. if (info->is_powering_on) {/*0603 - SMD issue*/
  147. dev_info(&info->client->dev,
  148. "%s: ignoring dvfs set.\n", __func__);
  149. return;
  150. }
  151. if (info->dvfs_boost_mode == DVFS_STAGE_NONE) {
  152. dev_dbg(&info->client->dev,
  153. "%s: DVFS stage is none(%d)\n",
  154. __func__, info->dvfs_boost_mode);
  155. return;
  156. }
  157. mutex_lock(&info->dvfs_lock);
  158. if (on == 0) {
  159. cancel_delayed_work(&info->work_dvfs_chg);
  160. if (info->dvfs_lock_status) {
  161. ret = set_freq_limit(DVFS_TOUCH_ID, info->dvfs_freq);
  162. if (ret < 0)
  163. dev_info(&info->client->dev,
  164. "%s: cpu first lock failed(%d)\n", __func__, ret);
  165. info->dvfs_lock_status = false;
  166. }
  167. schedule_delayed_work(&info->work_dvfs_off,
  168. msecs_to_jiffies(TOUCH_BOOSTER_CHG_TIME));
  169. } else if (on == 1) {
  170. cancel_delayed_work(&info->work_dvfs_off);
  171. schedule_delayed_work(&info->work_dvfs_chg,
  172. msecs_to_jiffies(TOUCH_BOOSTER_OFF_TIME));
  173. } else if (on == 2) {
  174. if (info->dvfs_lock_status) {
  175. cancel_delayed_work(&info->work_dvfs_off);
  176. cancel_delayed_work(&info->work_dvfs_chg);
  177. schedule_work(&info->work_dvfs_off.work);
  178. }
  179. }
  180. mutex_unlock(&info->dvfs_lock);
  181. }
  182. static void cypress_init_dvfs(struct cypress_touchkey_info *info)
  183. {
  184. mutex_init(&info->dvfs_lock);
  185. info->dvfs_boost_mode = DVFS_STAGE_DUAL;
  186. info->dvfs_freq = MIN_TOUCH_LIMIT_SECOND;
  187. INIT_DELAYED_WORK(&info->work_dvfs_off, cypress_set_dvfs_off);
  188. INIT_DELAYED_WORK(&info->work_dvfs_chg, cypress_change_dvfs_lock);
  189. info->dvfs_lock_status = true;
  190. }
  191. #endif
  192. static int cypress_touchkey_i2c_read(struct i2c_client *client,
  193. u8 reg, u8 *val, unsigned int len)
  194. {
  195. struct cypress_touchkey_info *info = dev_get_drvdata(&client->dev);
  196. int err = 0;
  197. int retry = 3;
  198. if (!info->enabled) {
  199. dev_info(&client->dev, "%s: touchkey is not enabled\n", __func__);
  200. return 0;
  201. }
  202. while (retry--) {
  203. err = i2c_smbus_read_i2c_block_data(client,
  204. KEYCODE_REG, len, val);
  205. if (err >= 0)
  206. return err;
  207. dev_info(&client->dev, "%s: i2c transfer error.\n", __func__);
  208. msleep(20);
  209. }
  210. return err;
  211. }
  212. static int cypress_touchkey_i2c_write(struct i2c_client *client,
  213. u8 *val, unsigned int len)
  214. {
  215. struct cypress_touchkey_info *info = dev_get_drvdata(&client->dev);
  216. int err = 0;
  217. int retry = 3;
  218. if (!info->enabled) {
  219. dev_info(&client->dev, "%s: touchkey is not enabled\n", __func__);
  220. return 0;
  221. }
  222. while (retry--) {
  223. err = i2c_smbus_write_i2c_block_data(client,
  224. KEYCODE_REG, len, val);
  225. if (err >= 0)
  226. return err;
  227. dev_info(&client->dev, "%s: i2c transfer error.\n", __func__);
  228. msleep(20);
  229. }
  230. return err;
  231. }
  232. static int tkey_i2c_check(struct cypress_touchkey_info *info)
  233. {
  234. struct i2c_client *client = info->client;
  235. int ret = 0;
  236. u8 data[3] = { 0, };
  237. ret = cypress_touchkey_i2c_read(info->client, KEYCODE_REG, data, 4);
  238. if (ret < 0) {
  239. dev_err(&client->dev, "Failed to read Module version\n");
  240. return ret;
  241. }
  242. info->ic_fw_ver = data[1];
  243. info->module_ver = data[2];
  244. dev_info(&client->dev, "%s: ic_fw_ver = %x, module_ver = %x \n",
  245. __func__, info->ic_fw_ver, info->module_ver);
  246. return ret;
  247. }
  248. void cypress_power_onoff(struct cypress_touchkey_info *info, int onoff)
  249. {
  250. int /*ret = 0, */rc = 0;
  251. dev_info(&info->client->dev, "%s: power %s\n",
  252. __func__, onoff ? "on" : "off");
  253. if (!info->vcc_en) {
  254. info->vcc_en = regulator_get(&info->client->dev,
  255. "8226_l6");
  256. if (IS_ERR(info->vcc_en)) {
  257. dev_err(&info->client->dev,
  258. "Regulator(vcc_en) get failed rc = %ld\n", PTR_ERR(info->vcc_en));
  259. return;
  260. }
  261. }
  262. /* if (info->pdata->vdd_led < 0) {
  263. if (!info->vdd_led) {
  264. info->vdd_led = regulator_get(&info->client->dev,
  265. "vdd_led");
  266. if (IS_ERR(info->vdd_led)) {
  267. dev_err(&info->client->dev,
  268. "Regulator(vdd_led) get failed rc = %ld\n", PTR_ERR(info->vdd_led));
  269. return;
  270. }
  271. rc = regulator_set_voltage(info->vdd_led,
  272. 3300000, 3300000);
  273. if (rc) {
  274. dev_err(&info->client->dev,
  275. "regulator(vdd_led) set_vtg failed rc=%d\n", rc);
  276. return;
  277. }
  278. }
  279. }*/
  280. if (onoff) {
  281. if (!regulator_is_enabled(info->vcc_en)) {
  282. rc = regulator_enable(info->vcc_en);
  283. if (rc) {
  284. dev_err(&info->client->dev,
  285. "Regulator vcc_en enable failed rc=%d\n", rc);
  286. return;
  287. }
  288. }
  289. /* if (info->pdata->vdd_led < 0) {
  290. if (!regulator_is_enabled(info->vdd_led)) {
  291. rc = regulator_enable(info->vdd_led);
  292. if (rc) {
  293. dev_err(&info->client->dev,
  294. "Regulator vdd_led enable failed rc=%d\n", rc);
  295. return;
  296. }
  297. }
  298. }*/
  299. } else {
  300. if (regulator_is_enabled(info->vcc_en)) {
  301. rc = regulator_disable(info->vcc_en);
  302. if (rc) {
  303. dev_err(&info->client->dev,
  304. "Regulator vcc_en disable failed rc=%d\n", rc);
  305. return;
  306. }
  307. }
  308. /* if (info->pdata->vdd_led < 0) {
  309. if (regulator_is_enabled(info->vdd_led)) {
  310. rc = regulator_disable(info->vdd_led);
  311. if (rc) {
  312. dev_err(&info->client->dev,
  313. "Regulator vdd_led disable failed rc=%d\n", rc);
  314. return;
  315. }
  316. }
  317. }*/
  318. }
  319. /* if (info->pdata->vdd_led > 0) {
  320. ret = gpio_direction_output(info->pdata->vdd_led, onoff);
  321. if (ret) {
  322. dev_err(&info->client->dev,
  323. "%s: unable to set_direction for vdd_led [%d]\n",
  324. __func__, info->pdata->vdd_led);
  325. }
  326. }*/
  327. }
  328. #ifdef LED_LDO_WITH_REGULATOR
  329. static void change_touch_key_led_voltage(struct cypress_touchkey_info *info, int vol_mv)
  330. {
  331. struct regulator *tled_regulator;
  332. int ret;
  333. vol_mv_level = vol_mv;
  334. tled_regulator = regulator_get(NULL, "8921_l10");
  335. if (IS_ERR(tled_regulator)) {
  336. dev_info(&info->client->dev,
  337. "%s: failed to get resource touch_led\n", __func__);
  338. return;
  339. }
  340. ret = regulator_set_voltage(tled_regulator,
  341. vol_mv * 100000, vol_mv * 100000);
  342. if (ret)
  343. dev_info(&info->client->dev,
  344. "%s: error setting voltage\n", __func__);
  345. regulator_put(tled_regulator);
  346. }
  347. static ssize_t cypress_touchkey_brightness_control(struct device *dev,
  348. struct device_attribute *attr, const char *buf, size_t size)
  349. {
  350. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  351. int data;
  352. if (sscanf(buf, "%d\n", &data) == 1)
  353. change_touch_key_led_voltage(info, data);
  354. else
  355. dev_info(&info->client->dev, "%s: Error[%d]\n",
  356. __func__, data);
  357. return size;
  358. }
  359. #endif
  360. #ifdef TK_INFORM_CHARGER
  361. static int touchkey_ta_setting(struct cypress_touchkey_info *info)
  362. {
  363. u8 data[6] = { 0, };
  364. int count = 0;
  365. int ret = 0;
  366. u8 retry = 0;
  367. while (retry < 3) {
  368. ret = cypress_touchkey_i2c_read(info->client, KEYCODE_REG, data, 4);
  369. if (ret < 0) {
  370. dev_err(&info->client->dev, "Failed to read Keycode_reg.\n");
  371. return ret;
  372. }
  373. /* Send autocal Command */
  374. if (info->charging_mode) {
  375. data[0] = 0x90;
  376. data[3] = 0x10;
  377. } else {
  378. data[0] = 0x90;
  379. data[3] = 0x20;
  380. }
  381. count = cypress_touchkey_i2c_write(info->client, data, 4);
  382. msleep(100);
  383. /* Check autocal status */
  384. ret = cypress_touchkey_i2c_read(info->client, KEYCODE_REG, data, 6);
  385. if (info->charging_mode) {
  386. if (data[5] & TK_BIT_TA_ON) {
  387. dev_dbg(&info->client->dev, "%s: TA mode is Enabled\n", __func__);
  388. break;
  389. } else {
  390. dev_err(&info->client->dev, "%s: TA Enabled Error! retry=%d\n",
  391. __func__, retry);
  392. }
  393. } else {
  394. if (!(data[5] & TK_BIT_TA_ON)) {
  395. dev_dbg(&info->client->dev, "%s: TA mode is Disabled\n", __func__);
  396. break;
  397. } else {
  398. dev_err(&info->client->dev, "%s: TA Disabled Error! retry=%d\n",
  399. __func__, retry);
  400. }
  401. }
  402. retry = retry + 1;
  403. }
  404. if (retry == 3)
  405. dev_err(&info->client->dev, "%s: Failed to set the TA mode\n", __func__);
  406. return count;
  407. }
  408. static void cypress_touchkey_ta_cb(struct touchkey_callbacks *cb, bool ta_status)
  409. {
  410. struct cypress_touchkey_info *info =
  411. container_of(cb, struct cypress_touchkey_info, callbacks);
  412. info->charging_mode = ta_status;
  413. if (!(info->enabled)) {
  414. dev_info(&info->client->dev, "%s: Touchkey is not enabled.\n",
  415. __func__);
  416. info->done_ta_setting = false;
  417. return;
  418. }
  419. dev_info(&info->client->dev, "%s: TA %s\n",
  420. __func__, info->charging_mode ? "connected" : "disconnected");
  421. touchkey_ta_setting(info);
  422. }
  423. #endif
  424. #ifdef CONFIG_GLOVE_TOUCH
  425. static void cypress_touchkey_glove_work(struct work_struct *work)
  426. {
  427. struct cypress_touchkey_info *info =
  428. container_of(work, struct cypress_touchkey_info, glove_work);
  429. u8 data[6] = { 0, };
  430. int count = 0;
  431. int ret = 0;
  432. u8 retry = 0;
  433. while (retry < 3) {
  434. ret = cypress_touchkey_i2c_read(info->client, CYPRESS_GEN, data, 4);
  435. if (ret < 0) {
  436. dev_err(&info->client->dev, "%s: Failed to read Keycode_reg.\n",
  437. __func__);
  438. return;
  439. }
  440. if (info->glove_value == 1) {
  441. /* Send glove Command */
  442. data[0] = 0xA0;
  443. data[3] = 0x30;
  444. } else {
  445. data[0] = 0xA0;
  446. data[3] = 0x40;
  447. }
  448. count = cypress_touchkey_i2c_write(info->client, data, 4);
  449. msleep(50);
  450. /* Check autocal status */
  451. ret = cypress_touchkey_i2c_read(info->client, CYPRESS_GEN, data, 6);
  452. if (info->glove_value == 1) {
  453. if (data[5] & TK_BIT_GLOVE) {
  454. dev_dbg(&info->client->dev, "%s: Glove mode is enabled\n", __func__);
  455. break;
  456. } else {
  457. dev_err(&info->client->dev, "%s: glove_mode Error! retry=%d\n",
  458. __func__, retry);
  459. }
  460. } else {
  461. if (!(data[5] & TK_BIT_GLOVE)) {
  462. dev_dbg(&info->client->dev, "%s: Normal mode from Glove mode\n", __func__);
  463. break;
  464. } else {
  465. dev_err(&info->client->dev, "%s: normal_mode Error! retry=%d\n",
  466. __func__, retry);
  467. }
  468. }
  469. retry = retry + 1;
  470. }
  471. if (retry == 3)
  472. dev_err(&info->client->dev, "%s: Failed to set the glove mode\n", __func__);
  473. return;
  474. }
  475. int cypress_touchkey_glovemode(struct cypress_touchkey_info *info, int value)
  476. {
  477. if (!(info->enabled)) {
  478. dev_info(&info->client->dev, "%s Touchkey is not enabled.\n",
  479. __func__);
  480. return 0;
  481. }
  482. if (info->glove_value == value) {
  483. dev_info(&info->client->dev, "glove mode is already %s\n", value ? "enabled" : "disabled");
  484. return 0;
  485. }
  486. info->glove_value = value;
  487. queue_work(info->glove_wq, &info->glove_work);
  488. return 0;
  489. }
  490. #endif
  491. #ifdef TKEY_FLIP_MODE
  492. void cypress_touchkey_flip_cover(struct cypress_touchkey_info *info, int value)
  493. {
  494. u8 data[6] = { 0, };
  495. int ret = 0;
  496. u8 retry = 0;
  497. if (!(info->enabled)) {
  498. dev_info(&info->client->dev, "%s : Touchkey is not enabled.\n",
  499. __func__);
  500. return ;
  501. }
  502. while (retry < 3) {
  503. ret = cypress_touchkey_i2c_read(info->client, KEYCODE_REG, data, 4);
  504. if (ret <= 0) {
  505. dev_info(&info->client->dev, "%s: Failed to read Keycode_reg.\n",
  506. __func__);
  507. return;
  508. }
  509. if (value == 1) {
  510. /* Send filp mode Command */
  511. data[0] = 0xA0;
  512. data[3] = 0x50;
  513. } else {
  514. data[0] = 0xA0;
  515. data[3] = 0x40;
  516. }
  517. ret = cypress_touchkey_i2c_write(info->client, data, 4);
  518. if (ret < 0) {
  519. dev_info(&info->client->dev, "%s: Failed to write flip mode command.\n",
  520. __func__);
  521. return;
  522. }
  523. msleep(100);
  524. /* Check autocal status */
  525. ret = cypress_touchkey_i2c_read(info->client, KEYCODE_REG, data, 6);
  526. if (ret <= 0) {
  527. dev_info(&info->client->dev, "%s: Failed to check autocal status.\n",
  528. __func__);
  529. return;
  530. }
  531. dev_dbg(&info->client->dev,
  532. "data[5]=%x",data[5] & TK_BIT_FLIP);
  533. if (value == 1) {
  534. if (data[5] & TK_BIT_FLIP) {
  535. dev_dbg(&info->client->dev, "%s: Flip mode is enabled\n", __func__);
  536. info->enabled_flip = true;
  537. break;
  538. } else {
  539. dev_err(&info->client->dev, "%s: flip_mode Enable failed. retry=%d\n",
  540. __func__, retry);
  541. }
  542. } else {
  543. if (!(data[5] & TK_BIT_FLIP)) {
  544. dev_dbg(&info->client->dev, "%s: Normal mode form Flip mode\n", __func__);
  545. info->enabled_flip = false;
  546. break;
  547. } else {
  548. dev_info(&info->client->dev, "%s: normal_mode Enable failed. retry=%d \n",
  549. __func__, retry);
  550. }
  551. }
  552. retry = retry + 1;
  553. }
  554. if (retry == 3)
  555. dev_err(&info->client->dev, "[Touchkey] flip cover failed\n");
  556. return;
  557. }
  558. #endif
  559. static irqreturn_t cypress_touchkey_interrupt(int irq, void *dev_id)
  560. {
  561. struct cypress_touchkey_info *info = dev_id;
  562. u8 buf[10] = {0,};
  563. int code;
  564. int press;
  565. int ret;
  566. ret = gpio_get_value(info->pdata->gpio_int);
  567. if (ret) {
  568. dev_info(&info->client->dev,
  569. "%s: not real interrupt (%d).\n", __func__, ret);
  570. goto out;
  571. }
  572. if (info->is_powering_on) {
  573. dev_info(&info->client->dev,
  574. "%s: ignoring spurious boot interrupt\n", __func__);
  575. goto out;
  576. }
  577. buf[0] = i2c_smbus_read_byte_data(info->client, CYPRESS_GEN);
  578. if (buf[0] < 0) {
  579. dev_info(&info->client->dev, "%s: interrupt failed with %d.\n",
  580. __func__, ret);
  581. goto out;
  582. }
  583. press = !(buf[0] & PRESS_BIT_MASK);
  584. code = (int)(buf[0] & KEYCODE_BIT_MASK) - 1;
  585. dev_info(&info->client->dev,
  586. "%s: code=%d %s. fw_ver=0x%x, module_ver=0x%x \n", __func__,
  587. code, press ? "pressed" : "released", info->ic_fw_ver, info->module_ver);
  588. if (code < 0) {
  589. dev_info(&info->client->dev,
  590. "%s, not profer interrupt 0x%2X.(release all finger)\n",
  591. __func__, buf[0]);
  592. /* need release all finger function. */
  593. goto out;
  594. }
  595. input_report_key(info->input_dev, info->keycode[code], press);
  596. input_sync(info->input_dev);
  597. #ifdef TSP_BOOSTER
  598. cypress_set_dvfs_lock(info, !!press);
  599. #endif
  600. out:
  601. return IRQ_HANDLED;
  602. }
  603. static void cypress_touchkey_con_hw(struct cypress_touchkey_info *dev_info,
  604. bool flag)
  605. {
  606. struct cypress_touchkey_info *info = dev_info;
  607. if (info->pdata->vdd_led > 0)
  608. gpio_set_value(info->pdata->vdd_led, flag ? 1 : 0);
  609. #if defined(SEC_TOUCHKEY_DEBUG)
  610. dev_notice(&info->client->dev,
  611. "%s : called with flag %d.\n", __func__, flag);
  612. #endif
  613. }
  614. static int cypress_touchkey_auto_cal(struct cypress_touchkey_info *info, bool booting)
  615. {
  616. u8 data[6] = { 0, };
  617. int count = 0;
  618. int ret = 0;
  619. u8 retry = 0;
  620. while (retry < 3) {
  621. ret = cypress_touchkey_i2c_read(info->client, CYPRESS_GEN, data, 4);
  622. if (ret < 0) {
  623. dev_info(&info->client->dev, "%s: autocal read fail.\n", __func__);
  624. return ret;
  625. }
  626. data[0] = 0x50;
  627. data[3] = 0x01;
  628. count = cypress_touchkey_i2c_write(info->client, data, 4);
  629. dev_info(&info->client->dev,
  630. "%s: data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
  631. __func__, data[0], data[1], data[2], data[3]);
  632. if (booting)
  633. msleep(100);
  634. else
  635. msleep(130);
  636. ret = cypress_touchkey_i2c_read(info->client, CYPRESS_GEN, data, 6);
  637. if (data[5] & TK_BIT_AUTOCAL) {
  638. dev_dbg(&info->client->dev, "%s: Run Autocal\n", __func__);
  639. break;
  640. } else {
  641. dev_info(&info->client->dev, "%s: autocal failed[%x][%d]\n",
  642. __func__, data[5], ret);
  643. }
  644. retry = retry + 1;
  645. }
  646. if (retry == 3)
  647. dev_err(&info->client->dev, "%s: Failed to Set the Autocalibration\n", __func__);
  648. return count;
  649. }
  650. static int tkey_fw_update(struct cypress_touchkey_info *info, bool force)
  651. {
  652. struct i2c_client *client = info->client;
  653. int retry;
  654. int ret = 0;
  655. dev_info(&client->dev, "%s : touchkey_update Start!!\n", __func__);
  656. if (force == true)
  657. retry = 2;
  658. else
  659. retry = NUM_OF_RETRY_UPDATE;
  660. cypress_config_gpio_i2c(info->pdata, 0);
  661. while (retry--) {
  662. if (ISSP_main(info) == 0) {
  663. dev_info(&client->dev, "%s : touchkey_update pass!!\n", __func__);
  664. msleep(50);
  665. cypress_touchkey_auto_cal(info, false);
  666. break;
  667. }
  668. msleep(50);
  669. dev_err(&client->dev,
  670. "%s : touchkey_update failed... retry...\n", __func__);
  671. }
  672. cypress_config_gpio_i2c(info->pdata, 1);
  673. if (retry <= 0) {
  674. dev_err(&client->dev, "%s : touchkey_update fail\n", __func__);
  675. return -1;
  676. }
  677. msleep(500);
  678. info->ic_fw_ver = i2c_smbus_read_byte_data(info->client,
  679. CYPRESS_FW_VER);
  680. dev_info(&client->dev,
  681. "%s : FW Ver 0x%02x\n", __func__, info->ic_fw_ver);
  682. return ret;
  683. }
  684. static ssize_t cypress_touchkey_ic_version_read(struct device *dev,
  685. struct device_attribute *attr, char *buf)
  686. {
  687. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  688. int count;
  689. dev_info(&info->client->dev,
  690. "%s : FW IC Ver 0x%02x\n", __func__, info->ic_fw_ver);
  691. count = snprintf(buf, 20, "0x%02x\n", info->ic_fw_ver);
  692. return count;
  693. }
  694. static ssize_t cypress_touchkey_src_version_read(struct device *dev,
  695. struct device_attribute *attr, char *buf)
  696. {
  697. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  698. int count;
  699. dev_info(&info->client->dev,
  700. "%s : FW src ver 0x%02x\n", __func__, info->src_fw_ver);
  701. count = snprintf(buf, 20, "0x%02x\n", info->src_fw_ver);
  702. return count;
  703. }
  704. static ssize_t cypress_touchkey_firm_status_show(struct device *dev,
  705. struct device_attribute *attr, char *buf)
  706. {
  707. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  708. int count = 0;
  709. char buff[16] = {0};
  710. dev_info(&info->client->dev, "%s touchkey_update_status: %d\n",
  711. __func__, info->touchkey_update_status);
  712. if (info->touchkey_update_status == DOWNLOADING)
  713. count = snprintf(buff, sizeof(buff), "Downloading\n");
  714. else if (info->touchkey_update_status == UPDATE_FAIL)
  715. count = snprintf(buff, sizeof(buff), "FAIL\n");
  716. else if (info->touchkey_update_status == UPDATE_PASS)
  717. count = snprintf(buff, sizeof(buff), "PASS\n");
  718. return count;
  719. }
  720. static ssize_t cypress_touchkey_update_write(struct device *dev,
  721. struct device_attribute *attr,
  722. const char *buf, size_t size)
  723. {
  724. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  725. struct i2c_client *client = info->client;
  726. int count = 0;
  727. #ifdef TKEY_REQUEST_FW_UPDATE
  728. u8 fw_path;
  729. #endif
  730. dev_info(&info->client->dev, "%s \n", __func__);
  731. #ifdef TKEY_REQUEST_FW_UPDATE
  732. switch (*buf) {
  733. case 's':
  734. case 'S':
  735. fw_path = FW_BUILT_IN;
  736. #if !defined(CONFIG_MACH_JS01LTEDCM) && !defined(CONFIG_MACH_JS01LTESBM)
  737. if(info->touchkeyid == CYPRESS_TOUCHKEY && info->support_fw_update == false) {
  738. dev_err(&client->dev, "%s: module %x does not support fw update\n.", __func__, info->module_ver);
  739. return size;
  740. }
  741. #endif
  742. break;
  743. case 'i':
  744. case 'I':
  745. fw_path = FW_IN_SDCARD;
  746. break;
  747. default:
  748. dev_err(&client->dev, "%s: invalid parameter %c\n.", __func__,
  749. *buf);
  750. return -EINVAL;
  751. }
  752. count = tkey_load_fw(info, fw_path);
  753. if (count < 0) {
  754. dev_err(&client->dev, "fail to load fw in %d (%d)\n",
  755. fw_path, count);
  756. return count;
  757. }
  758. #endif
  759. info->touchkey_update_status = DOWNLOADING;
  760. disable_irq(info->irq);
  761. if (info->touchkeyid == CYPRESS_TOUCHKEY)
  762. count = tkey_fw_update(info, false);
  763. else
  764. count = coreriver_fw_update(info, false);
  765. if (count < 0) {
  766. if (info->pdata->gpio_led_en)
  767. cypress_touchkey_con_hw(info, false);
  768. cypress_power_onoff(info, 0);
  769. info->touchkey_update_status = UPDATE_FAIL;
  770. dev_err(&client->dev, "%s: fail to flash fw (%d)\n.", __func__, count);
  771. return count;
  772. }
  773. info->touchkey_update_status = UPDATE_PASS;
  774. #ifdef TKEY_REQUEST_FW_UPDATE
  775. tkey_unload_fw(info, fw_path);
  776. #endif
  777. enable_irq(info->irq);
  778. return size;
  779. }
  780. static ssize_t cypress_touchkey_led_control(struct device *dev,
  781. struct device_attribute *attr, const char *buf,
  782. size_t size)
  783. {
  784. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  785. int data;
  786. int ret;
  787. static const int ledCmd[] = {TK_CMD_LED_OFF, TK_CMD_LED_ON};
  788. dev_info(&info->client->dev, "called %s\n", __func__);
  789. ret = sscanf(buf, "%d", &data);
  790. if (ret != 1) {
  791. dev_err(&info->client->dev, "%s, %d err\n",
  792. __func__, __LINE__);
  793. return size;
  794. }
  795. if (data != 0 && data != 1) {
  796. dev_err(&info->client->dev, "%s wrong cmd %x\n",
  797. __func__, data);
  798. return size;
  799. }
  800. if (!info->enabled) {
  801. touchled_cmd_reversed = 1;
  802. goto out;
  803. }
  804. ret = i2c_smbus_write_byte_data(info->client, CYPRESS_GEN, ledCmd[data]);
  805. if (ret < 0) {
  806. dev_info(&info->client->dev,
  807. "%s: i2c write error [%d]\n", __func__, ret);
  808. touchled_cmd_reversed = 1;
  809. goto out;
  810. }
  811. #if defined(SEC_TOUCHKEY_DEBUG)
  812. dev_info(&info->client->dev,
  813. "touch_led_control : %d\n", data);
  814. #endif
  815. msleep(30);
  816. out:
  817. touchkey_led_status = ledCmd[data];
  818. return size;
  819. }
  820. static ssize_t cypress_touchkey_sensitivity_control(struct device *dev,
  821. struct device_attribute *attr, const char *buf,
  822. size_t size)
  823. {
  824. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  825. int ret;
  826. ret = i2c_smbus_write_byte_data(info->client,
  827. CYPRESS_GEN, CYPRESS_DATA_UPDATE);
  828. if (ret < 0) {
  829. dev_info(&info->client->dev,
  830. "[Touchkey] fail to CYPRESS_DATA_UPDATE.\n");
  831. return ret;
  832. }
  833. msleep(20);
  834. return size;
  835. }
  836. static ssize_t cypress_touchkey_menu_show(struct device *dev,
  837. struct device_attribute *attr, char *buf)
  838. {
  839. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  840. static u16 menu_sensitivity;
  841. u8 data[14] = { 0, };
  842. int ret;
  843. unsigned char sensitivity_control = 0x40;
  844. cypress_touchkey_i2c_write(info->client, &sensitivity_control, 1);
  845. ret = cypress_touchkey_i2c_read(info->client, KEYCODE_REG, data, 14);
  846. dev_dbg(&info->client->dev, "called %s data[10] =%d,data[11] = %d\n", __func__,
  847. data[10], data[11]);
  848. menu_sensitivity = ((0x00FF & data[10]) << 8) | data[11];
  849. return snprintf(buf, 20, "%d\n", menu_sensitivity);
  850. }
  851. static ssize_t cypress_touchkey_back_show(struct device *dev,
  852. struct device_attribute *attr, char *buf)
  853. {
  854. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  855. static u16 back_sensitivity;
  856. u8 data[14] = { 0, };
  857. int ret;
  858. unsigned char sensitivity_control = 0x40;
  859. cypress_touchkey_i2c_write(info->client, &sensitivity_control, 1);
  860. ret = cypress_touchkey_i2c_read(info->client, KEYCODE_REG, data, 14);
  861. dev_dbg(&info->client->dev, "called %s data[12] =%d,data[13] = %d\n", __func__,
  862. data[12], data[13]);
  863. back_sensitivity = ((0x00FF & data[12]) << 8) | data[13];
  864. return snprintf(buf, 20, "%d\n", back_sensitivity);
  865. }
  866. static ssize_t cypress_touchkey_raw_data0_show(struct device *dev,
  867. struct device_attribute *attr, char *buf)
  868. {
  869. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  870. static u16 raw_data0;
  871. u8 data[2] = {0,};
  872. int ret;
  873. bool touchkey;
  874. touchkey = info->pdata->touchkey_order;
  875. if (0) {
  876. ret = i2c_smbus_read_i2c_block_data(info->client,
  877. CYPRESS_RAW_DATA_MENU, ARRAY_SIZE(data), data);
  878. } else {
  879. ret = i2c_smbus_read_i2c_block_data(info->client,
  880. touchkey ? CYPRESS_RAW_DATA_MENU : CYPRESS_RAW_DATA_BACK,
  881. ARRAY_SIZE(data), data);
  882. }
  883. if (ret != ARRAY_SIZE(data)) {
  884. dev_info(&info->client->dev,
  885. "[TouchKey] fail to read MENU raw data.\n");
  886. return ret;
  887. }
  888. raw_data0 = ((0x00FF & data[0])<<8) | data[1];
  889. dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
  890. __func__, data[0], data[1]);
  891. return snprintf(buf, 20, "%d\n", raw_data0);
  892. }
  893. static ssize_t cypress_touchkey_raw_data1_show(struct device *dev,
  894. struct device_attribute *attr, char *buf)
  895. {
  896. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  897. static u16 raw_data1;
  898. u8 data[2] = {0,};
  899. int ret;
  900. bool touchkey;
  901. touchkey = info->pdata->touchkey_order;
  902. if (0) {
  903. ret = i2c_smbus_read_i2c_block_data(info->client,
  904. CYPRESS_RAW_DATA_BACK_GOGH, ARRAY_SIZE(data), data);
  905. } else {
  906. ret = i2c_smbus_read_i2c_block_data(info->client,
  907. touchkey ? CYPRESS_RAW_DATA_BACK : CYPRESS_RAW_DATA_MENU,
  908. ARRAY_SIZE(data), data);
  909. }
  910. if (ret != ARRAY_SIZE(data)) {
  911. dev_info(&info->client->dev,
  912. "[TouchKey] fail to read HOME raw data.\n");
  913. return ret;
  914. }
  915. raw_data1 = ((0x00FF & data[0])<<8) | data[1];
  916. dev_info(&info->client->dev, "called %s , data : %d %d\n",
  917. __func__, data[0], data[1]);
  918. return snprintf(buf, 20, "%d\n", raw_data1);
  919. }
  920. static ssize_t cypress_touchkey_idac0_show(struct device *dev,
  921. struct device_attribute *attr, char *buf)
  922. {
  923. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  924. static u8 idac0;
  925. u8 data = 0;
  926. bool touchkey;
  927. touchkey = info->pdata->touchkey_order;
  928. if (0) {
  929. data = i2c_smbus_read_byte_data(info->client,
  930. CYPRESS_IDAC_MENU);
  931. } else {
  932. data = i2c_smbus_read_byte_data(info->client,
  933. touchkey ? CYPRESS_IDAC_MENU : CYPRESS_IDAC_BACK);
  934. }
  935. dev_info(&info->client->dev, "called %s , data : %d\n", __func__, data);
  936. idac0 = data;
  937. return snprintf(buf, 20, "%d\n", idac0);
  938. }
  939. static ssize_t cypress_touchkey_idac1_show(struct device *dev,
  940. struct device_attribute *attr, char *buf)
  941. {
  942. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  943. static u8 idac1;
  944. u8 data = 0;
  945. bool touchkey;
  946. touchkey = info->pdata->touchkey_order;
  947. if (0) {
  948. data = i2c_smbus_read_byte_data(info->client,
  949. CYPRESS_IDAC_BACK);
  950. } else {
  951. data = i2c_smbus_read_byte_data(info->client,
  952. touchkey ? CYPRESS_IDAC_BACK : CYPRESS_IDAC_MENU);
  953. }
  954. dev_info(&info->client->dev, "called %s , data : %d\n", __func__, data);
  955. idac1 = data;
  956. return snprintf(buf, 20, "%d\n", idac1);
  957. }
  958. #if defined(TK_HOME_ENABLE)
  959. static ssize_t cypress_touchkey_home_show(struct device *dev,
  960. struct device_attribute *attr, char *buf)
  961. {
  962. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  963. static u8 home_sensitivity;
  964. u8 data[2] = {0,};
  965. int ret;
  966. ret = i2c_smbus_read_i2c_block_data(info->client,
  967. CYPRESS_DIFF_MENU, ARRAY_SIZE(data), data);
  968. if (ret != ARRAY_SIZE(data)) {
  969. dev_info(&info->client->dev,
  970. "[TouchKey] fail to read home sensitivity.\n");
  971. return ret;
  972. }
  973. home_sensitivity = ((0x00FF & data[0])<<8) | data[1];
  974. dev_info(&info->client->dev, "called %s , data : %d %d\n",
  975. __func__, data[0], data[1]);
  976. return snprintf(buf, 20, "%d\n", home_sensitivity);
  977. }
  978. static ssize_t cypress_touchkey_raw_data2_show(struct device *dev,
  979. struct device_attribute *attr, char *buf)
  980. {
  981. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  982. static u16 raw_data1;
  983. u8 data[2] = {0,};
  984. int ret;
  985. ret = i2c_smbus_read_i2c_block_data(info->client,
  986. CYPRESS_RAW_DATA_HOME, ARRAY_SIZE(data), data);
  987. if (ret != ARRAY_SIZE(data)) {
  988. dev_info(&info->client->dev,
  989. "[TouchKey] fail to read HOME raw data.\n");
  990. return ret;
  991. }
  992. raw_data1 = ((0x00FF & data[0])<<8) | data[1];
  993. dev_info(&info->client->dev, "called %s , data : %d %d\n",
  994. __func__, data[0], data[1]);
  995. return snprintf(buf, 20, "%d\n", raw_data1);
  996. }
  997. static ssize_t cypress_touchkey_idac2_show(struct device *dev,
  998. struct device_attribute *attr, char *buf)
  999. {
  1000. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  1001. static u8 idac1;
  1002. u8 data = 0;
  1003. data = i2c_smbus_read_byte_data(info->client, CYPRESS_IDAC_HOME);
  1004. dev_dbg(&info->client->dev, "called %s , data : %d\n", __func__, data);
  1005. idac1 = data;
  1006. return snprintf(buf, 20, "%d\n", idac1);
  1007. }
  1008. #endif
  1009. static ssize_t cypress_touchkey_threshold_show(struct device *dev,
  1010. struct device_attribute *attr, char *buf)
  1011. {
  1012. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  1013. static u8 touchkey_threshold;
  1014. u8 data = 0;
  1015. data = i2c_smbus_read_byte_data(info->client, CYPRESS_THRESHOLD);
  1016. dev_info(&info->client->dev, "called %s , data : %d\n", __func__, data);
  1017. touchkey_threshold = data;
  1018. return snprintf(buf, 20, "%d\n", touchkey_threshold);
  1019. }
  1020. static ssize_t cypress_touchkey_autocal_testmode(struct device *dev,
  1021. struct device_attribute *attr, const char *buf,
  1022. size_t size)
  1023. {
  1024. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  1025. int count = 0;
  1026. int on_off;
  1027. if (sscanf(buf, "%d\n", &on_off) == 1) {
  1028. dev_info(&info->client->dev, "[TouchKey] Test Mode : %d\n", on_off);
  1029. if (on_off == 1) {
  1030. count = i2c_smbus_write_byte_data(info->client,
  1031. CYPRESS_GEN, CYPRESS_DATA_UPDATE);
  1032. }
  1033. } else {
  1034. if (info->pdata->gpio_led_en) {
  1035. cypress_touchkey_con_hw(info, false);
  1036. msleep(50);
  1037. cypress_touchkey_con_hw(info, true);
  1038. msleep(50);
  1039. }
  1040. cypress_touchkey_auto_cal(info, false);
  1041. }
  1042. return count;
  1043. }
  1044. static ssize_t cypress_touchkey_autocal_enable(struct device *dev,
  1045. struct device_attribute *attr,
  1046. const char *buf, size_t size)
  1047. {
  1048. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  1049. int data;
  1050. sscanf(buf, "%d\n", &data);
  1051. dev_dbg(&info->client->dev, "%s %d\n", __func__, data);
  1052. if (data == 1)
  1053. cypress_touchkey_auto_cal(info, false);
  1054. return 0;
  1055. }
  1056. static ssize_t cypress_touchkey_autocal_status(struct device *dev,
  1057. struct device_attribute *attr, char *buf)
  1058. {
  1059. u8 data[6];
  1060. int ret;
  1061. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  1062. dev_dbg(&info->client->dev, "%s\n", __func__);
  1063. ret = i2c_smbus_read_i2c_block_data(info->client,
  1064. CYPRESS_GEN, 6, data);
  1065. if ((data[5] & 0x80))
  1066. return snprintf(buf, 20, "Enabled\n");
  1067. else
  1068. return snprintf(buf, 20, "Disabled\n");
  1069. }
  1070. #if defined(CONFIG_GLOVE_TOUCH)
  1071. static ssize_t cypress_touchkey_glove_mode_enable(struct device *dev,
  1072. struct device_attribute *attr,
  1073. const char *buf, size_t size)
  1074. {
  1075. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  1076. int data;
  1077. sscanf(buf, "%d\n", &data);
  1078. dev_info(&info->client->dev, "%s %d\n", __func__, data);
  1079. cypress_touchkey_glovemode(info, data);
  1080. return size;
  1081. }
  1082. #endif
  1083. #ifdef TKEY_FLIP_MODE
  1084. static ssize_t cypress_touchkey_flip_cover_mode_enable(struct device *dev,
  1085. struct device_attribute *attr,
  1086. const char *buf, size_t size)
  1087. {
  1088. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  1089. int data;
  1090. sscanf(buf, "%d\n", &data);
  1091. dev_info(&info->client->dev, "%s %d\n", __func__, data);
  1092. cypress_touchkey_flip_cover(info, data);
  1093. return size;
  1094. }
  1095. #endif
  1096. #ifdef TSP_BOOSTER
  1097. static ssize_t boost_level_store(struct device *dev,
  1098. struct device_attribute *attr,
  1099. const char *buf, size_t count)
  1100. {
  1101. struct cypress_touchkey_info *info = dev_get_drvdata(dev);
  1102. int val, retval;
  1103. dev_info(&info->client->dev, "%s\n", __func__);
  1104. sscanf(buf, "%d", &val);
  1105. if (val != 1 && val != 2 && val != 0) {
  1106. dev_info(&info->client->dev,
  1107. "%s: wrong cmd %d\n", __func__, val);
  1108. return count;
  1109. }
  1110. info->dvfs_boost_mode = val;
  1111. dev_info(&info->client->dev,
  1112. "%s: dvfs_boost_mode = %d\n",
  1113. __func__, info->dvfs_boost_mode);
  1114. if (info->dvfs_boost_mode == DVFS_STAGE_DUAL) {
  1115. info->dvfs_freq = MIN_TOUCH_LIMIT_SECOND;
  1116. dev_info(&info->client->dev,
  1117. "%s: boost_mode DUAL, dvfs_freq = %d\n",
  1118. __func__, info->dvfs_freq);
  1119. } else if (info->dvfs_boost_mode == DVFS_STAGE_SINGLE) {
  1120. info->dvfs_freq = MIN_TOUCH_LIMIT;
  1121. dev_info(&info->client->dev,
  1122. "%s: boost_mode SINGLE, dvfs_freq = %d\n",
  1123. __func__, info->dvfs_freq);
  1124. } else if (info->dvfs_boost_mode == DVFS_STAGE_NONE) {
  1125. info->dvfs_freq = -1;
  1126. retval = set_freq_limit(DVFS_TOUCH_ID, -1);
  1127. if (retval < 0) {
  1128. dev_err(&info->client->dev,
  1129. "%s: booster stop failed(%d).\n",
  1130. __func__, retval);
  1131. info->dvfs_lock_status = false;
  1132. }
  1133. }
  1134. return count;
  1135. }
  1136. #endif
  1137. static DEVICE_ATTR(touchkey_firm_update_status, S_IRUGO | S_IWUSR | S_IWGRP,
  1138. cypress_touchkey_firm_status_show, NULL);
  1139. static DEVICE_ATTR(touchkey_firm_version_panel, S_IRUGO,
  1140. cypress_touchkey_ic_version_read, NULL);
  1141. static DEVICE_ATTR(touchkey_firm_version_phone, S_IRUGO,
  1142. cypress_touchkey_src_version_read, NULL);
  1143. static DEVICE_ATTR(touchkey_firm_update, S_IRUGO | S_IWUSR | S_IWGRP,
  1144. NULL, cypress_touchkey_update_write);
  1145. static DEVICE_ATTR(brightness, S_IRUGO | S_IWUSR | S_IWGRP,
  1146. NULL, cypress_touchkey_led_control);
  1147. static DEVICE_ATTR(touch_sensitivity, S_IRUGO | S_IWUSR | S_IWGRP,
  1148. NULL, cypress_touchkey_sensitivity_control);
  1149. static DEVICE_ATTR(touchkey_menu, S_IRUGO,
  1150. cypress_touchkey_menu_show, NULL);
  1151. static DEVICE_ATTR(touchkey_raw_data0, S_IRUGO,
  1152. cypress_touchkey_raw_data0_show, NULL);
  1153. static DEVICE_ATTR(touchkey_idac0, S_IRUGO,
  1154. cypress_touchkey_idac0_show, NULL);
  1155. static DEVICE_ATTR(touchkey_back, S_IRUGO,
  1156. cypress_touchkey_back_show, NULL);
  1157. static DEVICE_ATTR(touchkey_raw_data1, S_IRUGO,
  1158. cypress_touchkey_raw_data1_show, NULL);
  1159. static DEVICE_ATTR(touchkey_idac1, S_IRUGO,
  1160. cypress_touchkey_idac1_show, NULL);
  1161. static DEVICE_ATTR(touchkey_threshold, S_IRUGO,
  1162. cypress_touchkey_threshold_show, NULL);
  1163. static DEVICE_ATTR(touchkey_autocal_start, S_IRUGO | S_IWUSR | S_IWGRP,
  1164. NULL, cypress_touchkey_autocal_testmode);
  1165. static DEVICE_ATTR(autocal_enable, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  1166. cypress_touchkey_autocal_enable);
  1167. static DEVICE_ATTR(autocal_stat, S_IRUGO | S_IWUSR | S_IWGRP,
  1168. cypress_touchkey_autocal_status, NULL);
  1169. #ifdef LED_LDO_WITH_REGULATOR
  1170. static DEVICE_ATTR(touchkey_brightness_level, S_IRUGO | S_IWUSR | S_IWGRP,
  1171. NULL, cypress_touchkey_brightness_control);
  1172. #endif
  1173. #if defined(CONFIG_GLOVE_TOUCH)
  1174. static DEVICE_ATTR(glove_mode, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  1175. cypress_touchkey_glove_mode_enable);
  1176. #endif
  1177. #ifdef TKEY_FLIP_MODE
  1178. static DEVICE_ATTR(flip_mode, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  1179. cypress_touchkey_flip_cover_mode_enable);
  1180. #endif
  1181. #ifdef TSP_BOOSTER
  1182. static DEVICE_ATTR(boost_level,
  1183. S_IWUSR | S_IWGRP, NULL, boost_level_store);
  1184. #endif
  1185. static struct attribute *touchkey_attributes[] = {
  1186. &dev_attr_touchkey_firm_update_status.attr,
  1187. &dev_attr_touchkey_firm_version_panel.attr,
  1188. &dev_attr_touchkey_firm_version_phone.attr,
  1189. &dev_attr_touchkey_firm_update.attr,
  1190. &dev_attr_brightness.attr,
  1191. &dev_attr_touch_sensitivity.attr,
  1192. &dev_attr_touchkey_menu.attr,
  1193. &dev_attr_touchkey_raw_data0.attr,
  1194. &dev_attr_touchkey_idac0.attr,
  1195. &dev_attr_touchkey_back.attr,
  1196. &dev_attr_touchkey_raw_data1.attr,
  1197. &dev_attr_touchkey_idac1.attr,
  1198. &dev_attr_touchkey_threshold.attr,
  1199. &dev_attr_touchkey_autocal_start.attr,
  1200. &dev_attr_autocal_enable.attr,
  1201. &dev_attr_autocal_stat.attr,
  1202. #ifdef LED_LDO_WITH_REGULATOR
  1203. &dev_attr_touchkey_brightness_level.attr,
  1204. #endif
  1205. #ifdef CONFIG_GLOVE_TOUCH
  1206. &dev_attr_glove_mode.attr,
  1207. #endif
  1208. #ifdef TKEY_FLIP_MODE
  1209. &dev_attr_flip_mode.attr,
  1210. #endif
  1211. #ifdef TSP_BOOSTER
  1212. &dev_attr_boost_level.attr,
  1213. #endif
  1214. NULL,
  1215. };
  1216. static struct attribute_group touchkey_attr_group = {
  1217. .attrs = touchkey_attributes,
  1218. };
  1219. #ifdef TKEY_REQUEST_FW_UPDATE
  1220. static int load_fw_built_in(struct cypress_touchkey_info *info)
  1221. {
  1222. struct i2c_client *client = info->client;
  1223. int ret;
  1224. char *fw_name;
  1225. if (info->touchkeyid == CYPRESS_TOUCHKEY)
  1226. fw_name = kasprintf(GFP_KERNEL, "%s/%s.fw",
  1227. TKEY_FW_BUILTIN_PATH, TKEY_CYPRESS_FW_NAME);
  1228. else
  1229. fw_name = kasprintf(GFP_KERNEL, "%s/%s.fw",
  1230. TKEY_FW_BUILTIN_PATH, TKEY_CORERIVER_FW_NAME);
  1231. pr_info("%s!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",fw_name);
  1232. ret = request_firmware(&info->fw, fw_name, &client->dev);
  1233. if (ret) {
  1234. dev_err(&client->dev, "error requesting built-in firmware (%d)"
  1235. "\n", ret);
  1236. goto out;
  1237. }
  1238. info->fw_img = (struct fw_image *)info->fw->data;
  1239. info->src_fw_ver = info->fw_img->first_fw_ver;
  1240. dev_info(&client->dev, "the fw 0x%x is loaded (size=%d)\n",
  1241. info->fw_img->first_fw_ver, info->fw_img->fw_len);
  1242. out:
  1243. kfree(fw_name);
  1244. return ret;
  1245. }
  1246. static int load_fw_in_sdcard(struct cypress_touchkey_info *info)
  1247. {
  1248. struct i2c_client *client = info->client;
  1249. int ret;
  1250. mm_segment_t old_fs;
  1251. struct file *fp;
  1252. long nread;
  1253. int len;
  1254. char *fw_name;
  1255. if (info->touchkeyid == CYPRESS_TOUCHKEY)
  1256. fw_name = kasprintf(GFP_KERNEL, "%s/%s.bin",
  1257. TKEY_FW_IN_SDCARD_PATH, TKEY_CYPRESS_FW_NAME);
  1258. else
  1259. fw_name = kasprintf(GFP_KERNEL, "%s/%s.bin",
  1260. TKEY_FW_IN_SDCARD_PATH, TKEY_CORERIVER_FW_NAME);
  1261. old_fs = get_fs();
  1262. set_fs(KERNEL_DS);
  1263. fp = filp_open(fw_name, O_RDONLY, S_IRUSR);
  1264. if (!fp) {
  1265. dev_err(&client->dev, "%s: fail to open fw in %s\n",
  1266. __func__, fw_name);
  1267. ret = -ENOENT;
  1268. goto err_open_fw;
  1269. }
  1270. len = fp->f_path.dentry->d_inode->i_size;
  1271. info->fw_img = kzalloc(len, GFP_KERNEL);
  1272. if (!info->fw_img) {
  1273. dev_err(&client->dev, "%s: fail to alloc mem for fw\n",
  1274. __func__);
  1275. ret = -ENOMEM;
  1276. goto err_alloc;
  1277. }
  1278. nread = vfs_read(fp, (char __user *)info->fw_img, len, &fp->f_pos);
  1279. dev_info(&client->dev, "%s: load fw in internal sd (%ld)\n",
  1280. __func__, nread);
  1281. ret = 0;
  1282. err_alloc:
  1283. filp_close(fp, NULL);
  1284. err_open_fw:
  1285. set_fs(old_fs);
  1286. kfree(fw_name);
  1287. return ret;
  1288. }
  1289. static int tkey_load_fw(struct cypress_touchkey_info *info, u8 fw_path)
  1290. {
  1291. struct i2c_client *client = info->client;
  1292. int ret;
  1293. switch (fw_path) {
  1294. case FW_BUILT_IN:
  1295. ret = load_fw_built_in(info);
  1296. break;
  1297. case FW_IN_SDCARD:
  1298. ret = load_fw_in_sdcard(info);
  1299. break;
  1300. default:
  1301. dev_err(&client->dev, "%s: invalid fw path (%d)\n",
  1302. __func__, fw_path);
  1303. return -ENOENT;
  1304. }
  1305. if (ret < 0) {
  1306. dev_err(&client->dev, "fail to load fw in %d (%d)\n",
  1307. fw_path, ret);
  1308. return ret;
  1309. }
  1310. return 0;
  1311. }
  1312. static int tkey_unload_fw(struct cypress_touchkey_info *info, u8 fw_path)
  1313. {
  1314. struct i2c_client *client = info->client;
  1315. switch (fw_path) {
  1316. case FW_BUILT_IN:
  1317. release_firmware(info->fw);
  1318. break;
  1319. case FW_IN_SDCARD:
  1320. kfree(info->fw_img);
  1321. break;
  1322. default:
  1323. dev_err(&client->dev, "%s: invalid fw path (%d)\n",
  1324. __func__, fw_path);
  1325. return -ENOENT;
  1326. }
  1327. return 0;
  1328. }
  1329. static int tkey_flash_fw(struct cypress_touchkey_info *info, u8 fw_path, bool force)
  1330. {
  1331. struct i2c_client *client = info->client;
  1332. int ret;
  1333. return 0;
  1334. //TEST
  1335. /* firmware load */
  1336. ret = tkey_load_fw(info, fw_path);
  1337. if (ret < 0) {
  1338. dev_err(&client->dev, "%s : fail to load fw (%d)\n", __func__, ret);
  1339. return ret;
  1340. }
  1341. info->cur_fw_path = fw_path;
  1342. if (force == true || info->touchkeyid == CORERIVER_TOUCHKEY ||
  1343. (info->touchkeyid == CYPRESS_TOUCHKEY && (info->module_ver ==0x8 ||info->module_ver == 0x9)))
  1344. info->support_fw_update = true;
  1345. else
  1346. info->support_fw_update = false;
  1347. /* firmware version compare */
  1348. #if defined(CONFIG_MACH_JS01LTEDCM) || defined(CONFIG_MACH_JS01LTESBM)
  1349. if (info->ic_fw_ver >= info->src_fw_ver && !force) {
  1350. #else
  1351. if ((info->ic_fw_ver >= info->src_fw_ver && !force) || info->support_fw_update == false) {
  1352. #endif
  1353. dev_info(&client->dev, "%s : IC aleady have latest firmware (fw:%#x module:%#x)\n",
  1354. __func__ , info->ic_fw_ver, info->module_ver);
  1355. goto out;
  1356. }
  1357. /* firmware update */
  1358. disable_irq(client->irq);
  1359. if (info->touchkeyid == CYPRESS_TOUCHKEY)
  1360. ret = tkey_fw_update(info, force);
  1361. else
  1362. ret = coreriver_fw_update(info, force);
  1363. if (ret < 0) {
  1364. goto err_fw_update;
  1365. }
  1366. enable_irq(client->irq);
  1367. err_fw_update:
  1368. out:
  1369. tkey_unload_fw(info, fw_path);
  1370. return ret;
  1371. }
  1372. #endif
  1373. static void cypress_config_gpio_i2c(struct cypress_touchkey_platform_data *pdata, int onoff)
  1374. {
  1375. if (onoff) {
  1376. gpio_tlmm_config(GPIO_CFG(pdata->gpio_scl, 3, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1377. gpio_tlmm_config(GPIO_CFG(pdata->gpio_sda, 3, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1378. } else {
  1379. gpio_tlmm_config(GPIO_CFG(pdata->gpio_scl, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1380. gpio_tlmm_config(GPIO_CFG(pdata->gpio_sda, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1381. }
  1382. }
  1383. static void cypress_request_gpio(struct cypress_touchkey_platform_data *pdata)
  1384. {
  1385. int ret;
  1386. ret = gpio_request(pdata->gpio_int, "touchkey_irq");
  1387. if (ret) {
  1388. printk(KERN_ERR "%s: unable to request touchkey_irq [%d]\n",
  1389. __func__, pdata->gpio_int);
  1390. }
  1391. if (pdata->gpio_touchkey_id > 0) {
  1392. ret = gpio_request(pdata->gpio_touchkey_id, "touchkey_id");
  1393. if (ret) {
  1394. printk(KERN_ERR "%s: unable to request touchkey_id[%d]\n",
  1395. __func__, pdata->gpio_touchkey_id);
  1396. }
  1397. }
  1398. if (pdata->vdd_led > 0) {
  1399. ret = gpio_request(pdata->vdd_led, "touchkey_vdd_led");
  1400. if (ret) {
  1401. printk(KERN_ERR "%s: unable to request touchkey_vdd_led [%d]\n",
  1402. __func__, pdata->vdd_led);
  1403. }
  1404. }
  1405. }
  1406. #ifdef CONFIG_OF
  1407. static int cypress_get_keycodes(struct device *dev, char *name,
  1408. struct cypress_touchkey_platform_data *pdata)
  1409. {
  1410. struct property *prop;
  1411. struct device_node *np = dev->of_node;
  1412. int rc;
  1413. prop = of_find_property(np, name, NULL);
  1414. if (!prop)
  1415. return -EINVAL;
  1416. if (!prop->value)
  1417. return -ENODATA;
  1418. pdata->keycodes_size = prop->length / sizeof(u32);
  1419. rc = of_property_read_u32_array(np, name, pdata->touchkey_keycode,
  1420. pdata->keycodes_size);
  1421. if (rc && (rc != -EINVAL)) {
  1422. dev_info(dev, "%s: Unable to read %s\n", __func__, name);
  1423. return rc;
  1424. }
  1425. return 0;
  1426. }
  1427. static int cypress_parse_dt(struct device *dev,
  1428. struct cypress_touchkey_platform_data *pdata)
  1429. {
  1430. int rc;
  1431. struct device_node *np = dev->of_node;
  1432. rc = cypress_get_keycodes(dev, "cypress,tkey-keycodes", pdata);
  1433. if (rc)
  1434. return rc;
  1435. /* regulator info */
  1436. pdata->i2c_pull_up = of_property_read_bool(np, "cypress,i2c-pull-up");
  1437. pdata->vdd_led = of_get_named_gpio(np, "vdd_led-gpio", 0);
  1438. /* reset, irq gpio info */
  1439. pdata->gpio_scl = of_get_named_gpio_flags(np, "cypress,scl-gpio",
  1440. 0, &pdata->scl_gpio_flags);
  1441. pdata->gpio_sda = of_get_named_gpio_flags(np, "cypress,sda-gpio",
  1442. 0, &pdata->sda_gpio_flags);
  1443. pdata->gpio_int = of_get_named_gpio_flags(np, "cypress,irq-gpio",
  1444. 0, &pdata->irq_gpio_flags);
  1445. pdata->gpio_touchkey_id = of_get_named_gpio_flags(np, "cypress,touchkey_id-gpio",
  1446. 0, &pdata->gpio_touchkey_id_flags);
  1447. return 0;
  1448. }
  1449. #else
  1450. static int cypress_parse_dt(struct device *dev,
  1451. struct cypress_touchkey_platform_data *pdata)
  1452. {
  1453. return -ENODEV;
  1454. }
  1455. #endif
  1456. static void tkey_check_ic(struct cypress_touchkey_info *info)
  1457. {
  1458. int ret;
  1459. if (info->pdata->gpio_touchkey_id < 0) {
  1460. info->touchkeyid = CYPRESS_TOUCHKEY;
  1461. } else {
  1462. ret = gpio_get_value(info->pdata->gpio_touchkey_id);
  1463. if (ret == 0)
  1464. info->touchkeyid = CORERIVER_TOUCHKEY;
  1465. else
  1466. info->touchkeyid =CYPRESS_TOUCHKEY;
  1467. }
  1468. //TEST
  1469. info->touchkeyid =CYPRESS_TOUCHKEY;
  1470. //TEST
  1471. dev_info(&info->client->dev, "touchkey id = %s\n",
  1472. info->touchkeyid ? "CYPRESS" : "CORERIVER");
  1473. }
  1474. static int cypress_touchkey_probe(struct i2c_client *client,
  1475. const struct i2c_device_id *id)
  1476. {
  1477. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  1478. struct cypress_touchkey_platform_data *pdata;
  1479. struct cypress_touchkey_info *info;
  1480. struct input_dev *input_dev;
  1481. struct device *sec_touchkey;
  1482. int ret = 0;
  1483. int i;
  1484. int error;
  1485. bool bforced = false;
  1486. if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
  1487. return -EIO;
  1488. if (client->dev.of_node) {
  1489. pdata = devm_kzalloc(&client->dev,
  1490. sizeof(struct cypress_touchkey_platform_data),
  1491. GFP_KERNEL);
  1492. if (!pdata) {
  1493. dev_info(&client->dev, "Failed to allocate memory\n");
  1494. return -ENOMEM;
  1495. }
  1496. error = cypress_parse_dt(&client->dev, pdata);
  1497. if (error)
  1498. return error;
  1499. } else
  1500. pdata = client->dev.platform_data;
  1501. cypress_request_gpio(pdata);
  1502. info = kzalloc(sizeof(*info), GFP_KERNEL);
  1503. if (!info) {
  1504. dev_info(&client->dev, "%s: fail to memory allocation.\n", __func__);
  1505. goto err_mem_alloc;
  1506. }
  1507. input_dev = input_allocate_device();
  1508. if (!input_dev) {
  1509. printk(KERN_ERR "%s: fail to allocate input device.\n", __func__);
  1510. goto err_input_dev_alloc;
  1511. }
  1512. client->irq = gpio_to_irq(pdata->gpio_int);
  1513. info->client = client;
  1514. info->input_dev = input_dev;
  1515. info->pdata = pdata;
  1516. info->irq = client->irq;
  1517. info->touchkey_update_status = UPDATE_NONE;
  1518. input_dev->name = "sec_touchkey";
  1519. input_dev->phys = info->phys;
  1520. input_dev->id.bustype = BUS_I2C;
  1521. input_dev->dev.parent = &client->dev;
  1522. set_bit(EV_SYN, input_dev->evbit);
  1523. set_bit(EV_KEY, input_dev->evbit);
  1524. set_bit(EV_LED, input_dev->evbit);
  1525. set_bit(LED_MISC, input_dev->ledbit);
  1526. for (i = 0; i < pdata->keycodes_size; i++) {
  1527. info->keycode[i] = pdata->touchkey_keycode[i];
  1528. set_bit(info->keycode[i], input_dev->keybit);
  1529. }
  1530. i2c_set_clientdata(client, info);
  1531. info->is_powering_on = true;
  1532. if (info->pdata->gpio_led_en)
  1533. cypress_touchkey_con_hw(info, true);
  1534. cypress_power_onoff(info, 1);
  1535. msleep(40);
  1536. tkey_check_ic(info);
  1537. if (info->touchkeyid == CORERIVER_TOUCHKEY)
  1538. msleep(160);
  1539. info->enabled = true;
  1540. ret = tkey_i2c_check(info);
  1541. if (ret < 0) {
  1542. dev_err(&client->dev, "i2c_check failed\n");
  1543. #if defined(CONFIG_SEC_FACTORY)
  1544. info->enabled = false;
  1545. goto err_i2c_check;
  1546. #else
  1547. bforced = true;
  1548. #endif
  1549. }
  1550. input_set_drvdata(input_dev, info);
  1551. ret = input_register_device(input_dev);
  1552. if (ret) {
  1553. dev_info(&client->dev, "failed to register input dev (%d).\n",
  1554. ret);
  1555. goto err_reg_input_dev;
  1556. }
  1557. #ifdef USE_OPEN_CLOSE
  1558. input_dev->open = cypress_input_open;
  1559. input_dev->close = cypress_input_close;
  1560. #endif
  1561. dev_info(&info->client->dev, "gpio_to_irq IRQ %d\n",
  1562. client->irq);
  1563. #ifdef TSP_BOOSTER
  1564. cypress_init_dvfs(info);
  1565. #endif
  1566. ret = request_threaded_irq(client->irq, NULL,
  1567. cypress_touchkey_interrupt,
  1568. IRQF_DISABLED | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  1569. client->dev.driver->name, info);
  1570. if (ret < 0) {
  1571. dev_info(&client->dev, "Failed to request IRQ %d (err: %d).\n",
  1572. client->irq, ret);
  1573. goto err_req_irq;
  1574. }
  1575. #ifdef CONFIG_HAS_EARLYSUSPEND
  1576. info->early_suspend.level =
  1577. EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
  1578. info->early_suspend.suspend = cypress_touchkey_early_suspend;
  1579. info->early_suspend.resume = cypress_touchkey_late_resume;
  1580. register_early_suspend(&info->early_suspend);
  1581. #endif /* CONFIG_HAS_EARLYSUSPEND */
  1582. #if defined(CONFIG_GLOVE_TOUCH)
  1583. info->glove_wq = create_singlethread_workqueue("cypress_touchkey");
  1584. if (!info->glove_wq)
  1585. dev_info(&client->dev, "fail to create glove workquewe.\n");
  1586. else
  1587. INIT_WORK(&info->glove_work, cypress_touchkey_glove_work);
  1588. #endif
  1589. #ifdef TKEY_REQUEST_FW_UPDATE
  1590. ret = tkey_flash_fw(info, FW_BUILT_IN, bforced);
  1591. if (ret < 0) {
  1592. dev_info(&info->client->dev,
  1593. "%s: tkey fw update failed.\n", __func__);
  1594. goto err_fw_update;
  1595. }
  1596. #else
  1597. info->src_fw_ver = BIN_FW_VERSION;
  1598. #endif
  1599. if (info->touchkeyid == CYPRESS_TOUCHKEY)
  1600. cypress_touchkey_auto_cal(info, true);
  1601. sec_touchkey = device_create(sec_class, NULL, 0, NULL, "sec_touchkey");
  1602. if (IS_ERR(sec_touchkey)) {
  1603. dev_info(&info->client->dev,
  1604. "%s: Failed to create device(sec_touchkey)!\n", __func__);
  1605. goto err_sysfs;
  1606. }
  1607. dev_set_drvdata(sec_touchkey, info);
  1608. ret = sysfs_create_group(&sec_touchkey->kobj,
  1609. &touchkey_attr_group);
  1610. if (ret < 0) {
  1611. dev_err(&info->client->dev,
  1612. "%s: Failed to create sysfs attributes\n",
  1613. __func__);
  1614. goto err_sysfs_group;
  1615. }
  1616. #if defined(TK_INFORM_CHARGER)
  1617. info->pdata->register_cb = touchkey_register_callback;
  1618. info->callbacks.inform_charger = cypress_touchkey_ta_cb;
  1619. if (info->pdata->register_cb) {
  1620. dev_info(&client->dev, "[Touchkey] Register TA Callback\n");
  1621. info->pdata->register_cb(&info->callbacks);
  1622. }
  1623. #endif
  1624. info->is_powering_on = false;
  1625. /*
  1626. cypress_power_onoff(info, 0);
  1627. */
  1628. dev_info(&info->client->dev, "%s: done\n", __func__);
  1629. return 0;
  1630. err_sysfs_group:
  1631. device_destroy(sec_class, 0);
  1632. err_sysfs:
  1633. #ifdef TKEY_REQUEST_FW_UPDATE
  1634. err_fw_update:
  1635. #endif
  1636. if (info->irq >= 0)
  1637. free_irq(info->irq, info);
  1638. #if defined(CONFIG_GLOVE_TOUCH)
  1639. destroy_workqueue(info->glove_wq);
  1640. #endif
  1641. err_req_irq:
  1642. /*
  1643. err_gpio_request:
  1644. */
  1645. input_unregister_device(input_dev);
  1646. err_reg_input_dev:
  1647. input_free_device(input_dev);
  1648. input_dev = NULL;
  1649. #if defined(CONFIG_SEC_FACTORY)
  1650. err_i2c_check:
  1651. #endif
  1652. if (info->pdata->gpio_led_en)
  1653. cypress_touchkey_con_hw(info, false);
  1654. cypress_power_onoff(info, 0);
  1655. err_input_dev_alloc:
  1656. kfree(info);
  1657. return -ENXIO;
  1658. err_mem_alloc:
  1659. return -ENOMEM;
  1660. }
  1661. static int cypress_touchkey_remove(struct i2c_client *client)
  1662. {
  1663. struct cypress_touchkey_info *info = i2c_get_clientdata(client);
  1664. if (info->irq >= 0)
  1665. free_irq(info->irq, info);
  1666. if (info->pdata->vdd_led > 0)
  1667. gpio_free(info->pdata->vdd_led);
  1668. input_unregister_device(info->input_dev);
  1669. input_free_device(info->input_dev);
  1670. kfree(info);
  1671. return 0;
  1672. }
  1673. #if defined(CONFIG_PM) || defined(CONFIG_HAS_EARLYSUSPEND)
  1674. static int cypress_touchkey_suspend(struct device *dev)
  1675. {
  1676. struct i2c_client *client = to_i2c_client(dev);
  1677. struct cypress_touchkey_info *info = i2c_get_clientdata(client);
  1678. int ret = 0;
  1679. #ifdef TSP_BOOSTER
  1680. cypress_set_dvfs_lock(info, 2);
  1681. dev_info(&info->client->dev,
  1682. "%s: dvfs_lock free.\n", __func__);
  1683. #endif
  1684. info->is_powering_on = true;
  1685. disable_irq(info->irq);
  1686. if (info->pdata->gpio_led_en)
  1687. cypress_touchkey_con_hw(info, false);
  1688. cypress_power_onoff(info, 0);
  1689. info->enabled = false;
  1690. return ret;
  1691. }
  1692. static int cypress_touchkey_resume(struct device *dev)
  1693. {
  1694. struct i2c_client *client = to_i2c_client(dev);
  1695. struct cypress_touchkey_info *info = i2c_get_clientdata(client);
  1696. int ret = 0;
  1697. cypress_power_onoff(info, 1);
  1698. if (info->pdata->gpio_led_en)
  1699. cypress_touchkey_con_hw(info, true);
  1700. msleep(50);
  1701. if (info->touchkeyid == CYPRESS_TOUCHKEY) {
  1702. info->enabled = true;
  1703. cypress_touchkey_auto_cal(info, false);
  1704. } else {
  1705. msleep(150);
  1706. info->enabled = true;
  1707. }
  1708. if (touchled_cmd_reversed) {
  1709. touchled_cmd_reversed = 0;
  1710. i2c_smbus_write_byte_data(info->client,
  1711. CYPRESS_GEN, touchkey_led_status);
  1712. dev_info(&client->dev,
  1713. "%s: LED returned on\n", __func__);
  1714. msleep(30);
  1715. }
  1716. enable_irq(info->irq);
  1717. info->is_powering_on = false;
  1718. return ret;
  1719. }
  1720. #endif
  1721. #ifdef CONFIG_HAS_EARLYSUSPEND
  1722. static void cypress_touchkey_early_suspend(struct early_suspend *h)
  1723. {
  1724. struct cypress_touchkey_info *info;
  1725. info = container_of(h, struct cypress_touchkey_info, early_suspend);
  1726. cypress_touchkey_suspend(&info->client->dev);
  1727. }
  1728. static void cypress_touchkey_late_resume(struct early_suspend *h)
  1729. {
  1730. struct cypress_touchkey_info *info;
  1731. info = container_of(h, struct cypress_touchkey_info, early_suspend);
  1732. cypress_touchkey_resume(&info->client->dev);
  1733. }
  1734. #endif
  1735. static const struct i2c_device_id cypress_touchkey_id[] = {
  1736. {"cypress_touchkey", 0},
  1737. {}
  1738. };
  1739. MODULE_DEVICE_TABLE(i2c, cypress_touchkey_id);
  1740. #ifdef CONFIG_OF
  1741. static struct of_device_id cypress_match_table[] = {
  1742. { .compatible = "cypress,cypress-tkey",},
  1743. { },
  1744. };
  1745. #else
  1746. #define cypress_match_table NULL
  1747. #endif
  1748. #ifdef USE_OPEN_CLOSE
  1749. static int cypress_input_open(struct input_dev *dev)
  1750. {
  1751. struct cypress_touchkey_info *info = input_get_drvdata(dev);
  1752. dev_info(&info->client->dev, "%s.\n", __func__);
  1753. cypress_touchkey_resume(&info->client->dev);
  1754. return 0;
  1755. }
  1756. static void cypress_input_close(struct input_dev *dev)
  1757. {
  1758. struct cypress_touchkey_info *info = input_get_drvdata(dev);
  1759. dev_info(&info->client->dev, "%s.\n", __func__);
  1760. cypress_touchkey_suspend(&info->client->dev);
  1761. }
  1762. #endif
  1763. #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND) && !defined(USE_OPEN_CLOSE)
  1764. static const struct dev_pm_ops cypress_touchkey_pm_ops = {
  1765. .suspend = cypress_touchkey_suspend,
  1766. .resume = cypress_touchkey_resume,
  1767. };
  1768. #endif
  1769. struct i2c_driver cypress_touchkey_driver = {
  1770. .probe = cypress_touchkey_probe,
  1771. .remove = cypress_touchkey_remove,
  1772. .driver = {
  1773. .name = "cypress_touchkey",
  1774. .owner = THIS_MODULE,
  1775. .of_match_table = cypress_match_table,
  1776. #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND) && !defined(USE_OPEN_CLOSE)
  1777. .pm = &cypress_touchkey_pm_ops,
  1778. #endif
  1779. },
  1780. .id_table = cypress_touchkey_id,
  1781. };
  1782. /*
  1783. module_i2c_driver(cypress_touchkey_driver);
  1784. */
  1785. static int __init cypress_touchkey_init(void)
  1786. {
  1787. int ret = 0;
  1788. /*
  1789. #ifdef CONFIG_SAMSUNG_LPM_MODE
  1790. if (poweroff_charging) {
  1791. pr_notice("%s : LPM Charging Mode!!\n", __func__);
  1792. return 0;
  1793. }
  1794. #endif
  1795. */
  1796. printk(KERN_ERR "%s\n", __func__);
  1797. ret = i2c_add_driver(&cypress_touchkey_driver);
  1798. if (ret) {
  1799. printk(KERN_ERR "cypress touch keypad registration failed. ret= %d\n",
  1800. ret);
  1801. }
  1802. printk(KERN_ERR "%s: init done %d\n", __func__, ret);
  1803. return ret;
  1804. }
  1805. static void __exit cypress_touchkey_exit(void)
  1806. {
  1807. i2c_del_driver(&cypress_touchkey_driver);
  1808. }
  1809. module_init(cypress_touchkey_init);
  1810. module_exit(cypress_touchkey_exit);
  1811. MODULE_DESCRIPTION("Touchkey driver for Cypress touchkey controller ");
  1812. MODULE_LICENSE("GPL");