cypress-touchkey.c 54 KB

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