cypress-touchkey.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086
  1. /*
  2. * Driver for keys on GPIO lines capable of generating interrupts.
  3. *
  4. * Copyright 2005 Phil Blundell
  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. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/fs.h>
  13. #include <linux/i2c.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/irq.h>
  16. #include <linux/sched.h>
  17. #include <linux/pm.h>
  18. #include <linux/sysctl.h>
  19. #include <linux/proc_fs.h>
  20. #include <linux/delay.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/input.h>
  23. #include <linux/gpio.h>
  24. #include <linux/miscdevice.h>
  25. #include <linux/uaccess.h>
  26. #ifdef CONFIG_HAS_EARLYSUSPEND
  27. #include <linux/earlysuspend.h>
  28. #endif
  29. #include <linux/io.h>
  30. #include <linux/regulator/consumer.h>
  31. #include <linux/firmware.h>
  32. #include <linux/of_gpio.h>
  33. #include <linux/mfd/pm8xxx/pm8921.h>
  34. #include "issp_extern.h"
  35. #include "cypress_touchkey.h"
  36. #ifdef TK_HAS_FIRMWARE_UPDATE
  37. u8 *tk_fw_name = FW_PATH;
  38. /*For HA-3G*/
  39. static u8 fw_ver_file = 0x0;
  40. static u8 md_ver_file = 0x0;
  41. #if defined(CONFIG_KEYBOARD_CYPRESS_TKEY_HL)
  42. u8 module_divider[] = {0, 0xfe, 0xff};
  43. #else
  44. u8 module_divider[] = {0, 0xff};
  45. #endif
  46. u8 *firmware_data;
  47. #endif
  48. #define MODE_NORMAL 0
  49. #define MODE_GLOVE 1
  50. #define MODE_FLIP 2
  51. static int touchkey_keycode[] = { 0, KEY_MENU, KEY_BACK,};
  52. static const int touchkey_count = ARRAY_SIZE(touchkey_keycode);
  53. #if defined(TK_HAS_AUTOCAL)
  54. static int touchkey_autocalibration(struct touchkey_i2c *tkey_i2c);
  55. #endif
  56. static int touchkey_i2c_check(struct touchkey_i2c *tkey_i2c);
  57. static bool is_same_module_class(struct touchkey_i2c *tkey_i2c);
  58. #ifdef TK_INFORM_CHARGER
  59. extern void touchkey_register_callback(void *cb);
  60. #endif
  61. #if defined(TK_USE_4KEY)
  62. static u8 home_sensitivity;
  63. static u8 search_sensitivity;
  64. #endif
  65. static bool touchkey_probe;
  66. static const struct i2c_device_id sec_touchkey_id[] = {
  67. {"cypress_touchkey", 0},
  68. {}
  69. };
  70. MODULE_DEVICE_TABLE(i2c, sec_touchkey_id);
  71. int tkey_gpio_sda;
  72. int tkey_gpio_scl;
  73. int tkey_gpio_int;
  74. int tkey_gpio_rst;
  75. int tkey_gpio_id;
  76. int tkey_gpio_grip;
  77. #ifndef TK_USE_LDO_CONTROL
  78. int tkey_gpio_i2cldo;
  79. int tkey_gpio_vddldo;
  80. #else
  81. static int cypress_ldo_onoff(bool on);
  82. #if defined(TK_USE_MAX_SUBPM_CONTROL)
  83. struct regulator_bulk_data *cyp_supplies;
  84. enum {
  85. CYP_IC = 0,
  86. CYP_LED,
  87. };
  88. #endif
  89. #endif
  90. extern int get_touchkey_firmware(char *version);
  91. static int touchkey_led_status;
  92. static int touchled_cmd_reversed;
  93. static void touchkey_enable_irq(struct touchkey_i2c *tkey_i2c, int enable)
  94. {
  95. static int depth = 0;
  96. mutex_lock(&tkey_i2c->irq_lock);
  97. if (enable == 1) {
  98. if (depth == 1)
  99. enable_irq(tkey_i2c->irq);
  100. if (depth)
  101. --depth;
  102. } else if (enable == 0){
  103. if (depth == 0)
  104. disable_irq(tkey_i2c->irq);
  105. ++depth;
  106. /* forced enable */
  107. } else {
  108. if (depth) {
  109. depth = 0;
  110. enable_irq(tkey_i2c->irq);
  111. }
  112. }
  113. mutex_unlock(&tkey_i2c->irq_lock);
  114. #ifdef WACOM_IRQ_DEBUG
  115. printk(KERN_DEBUG"touchkey:Enable %d, depth %d\n", (int)enable, depth);
  116. #endif
  117. }
  118. #ifdef LED_LDO_WITH_REGULATOR
  119. static void change_touch_key_led_voltage(int vol_mv)
  120. {
  121. struct regulator *tled_regulator;
  122. tled_regulator = regulator_get(NULL, TKEY_LED_REGULATOR);
  123. if (IS_ERR(tled_regulator)) {
  124. pr_err("%s: failed to get resource %s\n", __func__,
  125. "touchkey_led");
  126. return;
  127. }
  128. regulator_set_voltage(tled_regulator, vol_mv * 1000, vol_mv * 1000);
  129. regulator_put(tled_regulator);
  130. }
  131. static ssize_t brightness_control(struct device *dev,
  132. struct device_attribute *attr,
  133. const char *buf, size_t size)
  134. {
  135. int data;
  136. if (sscanf(buf, "%d\n", &data) == 1) {
  137. dev_err(dev, "%s: %d\n", __func__, data);
  138. change_touch_key_led_voltage(data);
  139. } else {
  140. dev_err(dev, "%s Error\n", __func__);
  141. }
  142. return size;
  143. }
  144. #endif
  145. static int i2c_touchkey_read(struct touchkey_i2c *tkey_i2c,
  146. u8 reg, u8 *val, unsigned int len)
  147. {
  148. struct i2c_client *client = tkey_i2c->client;
  149. int ret = 0;
  150. int retry = 3;
  151. #if !defined(TK_USE_GENERAL_SMBUS)
  152. struct i2c_msg msg[1];
  153. #endif
  154. mutex_lock(&tkey_i2c->i2c_lock);
  155. while (retry--) {
  156. if ((client == NULL) || !(tkey_i2c->enabled)) {
  157. dev_err(&client->dev, "Touchkey is not enabled. %d\n",
  158. __LINE__);
  159. ret = -ENODEV;
  160. goto out_i2c_read;
  161. }
  162. #if defined(TK_USE_GENERAL_SMBUS)
  163. ret = i2c_smbus_read_i2c_block_data(client,
  164. reg, len, val);
  165. #else
  166. msg->addr = client->addr;
  167. msg->flags = I2C_M_RD;
  168. msg->len = len;
  169. msg->buf = val;
  170. ret = i2c_transfer(client->adapter, msg, 1);
  171. #endif
  172. if (ret < 0) {
  173. dev_err(&client->dev, "%s:error(%d)\n", __func__, ret);
  174. if (!(tkey_i2c->enabled)) {
  175. dev_err(&client->dev, "Touchkey is not enabled.. %d\n",
  176. __LINE__);
  177. ret = -ENODEV;
  178. goto out_i2c_read;
  179. }
  180. usleep_range(10000, 10000);
  181. continue;
  182. }
  183. break;
  184. }
  185. out_i2c_read:
  186. mutex_unlock(&tkey_i2c->i2c_lock);
  187. return ret;
  188. }
  189. static int i2c_touchkey_write(struct touchkey_i2c *tkey_i2c,
  190. u8 reg, u8 *val, unsigned int len)
  191. {
  192. struct i2c_client *client = tkey_i2c->client;
  193. int ret = 0;
  194. int retry = 3;
  195. #if !defined(TK_USE_GENERAL_SMBUS)
  196. struct i2c_msg msg[1];
  197. #endif
  198. mutex_lock(&tkey_i2c->i2c_lock);
  199. while (retry--) {
  200. if ((client == NULL) || !(tkey_i2c->enabled)) {
  201. dev_err(&client->dev, "Touchkey is not enabled. %d\n",
  202. __LINE__);
  203. ret = -ENODEV;
  204. goto out_i2c_write;
  205. }
  206. #if defined(TK_USE_GENERAL_SMBUS)
  207. ret = i2c_smbus_write_i2c_block_data(client,
  208. reg, len, val);
  209. #else
  210. msg->addr = client->addr;
  211. msg->flags = I2C_M_WR;
  212. msg->len = len;
  213. msg->buf = val;
  214. ret = i2c_transfer(client->adapter, msg, 1);
  215. #endif
  216. if (ret < 0) {
  217. dev_err(&client->dev, "%s:error(%d)\n", __func__, ret);
  218. if (!(tkey_i2c->enabled)) {
  219. dev_err(&client->dev, "Touchkey is not enabled.. %d\n",
  220. __LINE__);
  221. ret = -ENODEV;
  222. goto out_i2c_write;
  223. }
  224. usleep_range(10000, 10000);
  225. continue;
  226. }
  227. break;
  228. }
  229. out_i2c_write:
  230. mutex_unlock(&tkey_i2c->i2c_lock);
  231. return ret;
  232. }
  233. static void cypress_touchkey_interrupt_set_dual(struct touchkey_i2c *tkey_i2c)
  234. {
  235. struct i2c_client *client = tkey_i2c->client;
  236. int ret = 0;
  237. int retry = 5;
  238. u8 data[3] = {0, };
  239. ret = is_same_module_class(tkey_i2c);
  240. if (!ret) {
  241. dev_err(&client->dev,
  242. "%s: not support this module 0x%02x\n",
  243. __func__, tkey_i2c->md_ver_ic);
  244. return;
  245. }
  246. if (tkey_i2c->fw_ver_ic <= CYPRESS_RECENT_BACK_REPORT_FW_VER) {
  247. dev_err(&client->dev,
  248. "%s: not support this version 0x%02x\n",
  249. __func__, tkey_i2c->fw_ver_ic);
  250. return;
  251. }
  252. while (retry--) {
  253. data[0] = TK_CMD_DUAL_DETECTION;
  254. data[1] = 0x00;
  255. data[2] = TK_BIT_DETECTION_CONFIRM;
  256. //ret = i2c_touchkey_write(tkey_i2c, CYPRESS_REG_DETECTION, &data[0], 3);
  257. ret = i2c_smbus_write_i2c_block_data(client, 0x18, 3, &data[0]);
  258. if (ret < 0) {
  259. dev_err(&client->dev,
  260. "%s: i2c write error. (%d)\n", __func__, ret);
  261. msleep(30);
  262. continue;
  263. }
  264. msleep(30);
  265. data[0] = CYPRESS_REG_DETECTION_FLAG;
  266. //ret = i2c_touchkey_read(tkey_i2c, data[0], &data[1], 1);
  267. ret = i2c_smbus_read_i2c_block_data(client, data[0], 1, &data[1]);
  268. if (ret < 0) {
  269. dev_err(&client->dev,
  270. "%s: i2c read error. (%d)\n", __func__, ret);
  271. msleep(30);
  272. continue;
  273. }
  274. if (data[1] != 1) {
  275. dev_err(&client->dev,
  276. "%s: interrupt set: 0x%X, failed.\n",
  277. __func__, data[1]);
  278. continue;
  279. }
  280. dev_info(&client->dev,
  281. "%s: interrupt set: 0x%X\n", __func__, data[1]);
  282. break;
  283. }
  284. }
  285. #if defined(TK_HAS_AUTOCAL)
  286. static int touchkey_autocalibration(struct touchkey_i2c *tkey_i2c)
  287. {
  288. u8 data[6] = { 0, };
  289. int count = 0;
  290. int ret = 0;
  291. unsigned short retry = 0;
  292. if (wake_lock_active(&tkey_i2c->fw_wakelock)) {
  293. printk(KERN_DEBUG"touchkey:wakelock active\n");
  294. return 0;
  295. }
  296. while (retry < 3) {
  297. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 4);
  298. if (ret < 0) {
  299. dev_err(&tkey_i2c->client->dev, "%s: Failed to read Keycode_reg %d times\n",
  300. __func__, retry);
  301. return ret;
  302. }
  303. dev_dbg(&tkey_i2c->client->dev,
  304. "data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
  305. data[0], data[1], data[2], data[3]);
  306. /* Send autocal Command */
  307. data[0] = 0x50;
  308. data[3] = 0x01;
  309. count = i2c_touchkey_write(tkey_i2c, KEYCODE_REG, data, 4);
  310. msleep(130);
  311. /* Check autocal status */
  312. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 6);
  313. if (data[5] & TK_BIT_AUTOCAL) {
  314. dev_info(&tkey_i2c->client->dev, "%s: Run Autocal\n", __func__);
  315. break;
  316. } else {
  317. dev_err(&tkey_i2c->client->dev, "%s: Error to set Autocal, retry %d\n",
  318. __func__, retry);
  319. }
  320. retry = retry + 1;
  321. }
  322. if (retry == 3)
  323. dev_err(&tkey_i2c->client->dev, "%s: Failed to Set the Autocalibration\n", __func__);
  324. return count;
  325. }
  326. #endif
  327. #if defined(TK_INFORM_CHARGER)
  328. static int touchkey_ta_setting(struct touchkey_i2c *tkey_i2c)
  329. {
  330. u8 data[6] = { 0, };
  331. int count = 0;
  332. int ret = 0;
  333. unsigned short retry = 0;
  334. if (wake_lock_active(&tkey_i2c->fw_wakelock)) {
  335. printk(KERN_DEBUG"touchkey:wakelock active\n");
  336. return 0;
  337. }
  338. while (retry < 3) {
  339. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 4);
  340. if (ret < 0) {
  341. dev_err(&tkey_i2c->client->dev, "%s: Failed to read Keycode_reg %d times\n",
  342. __func__, retry);
  343. return ret;
  344. }
  345. dev_dbg(&tkey_i2c->client->dev,
  346. "data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
  347. data[0], data[1], data[2], data[3]);
  348. /* Send autocal Command */
  349. if (tkey_i2c->charging_mode) {
  350. dev_info(&tkey_i2c->client->dev, "%s: TA connected!!!\n", __func__);
  351. data[0] = 0x90;
  352. data[3] = 0x10;
  353. } else {
  354. dev_info(&tkey_i2c->client->dev, "%s: TA disconnected!!!\n", __func__);
  355. data[0] = 0x90;
  356. data[3] = 0x20;
  357. }
  358. count = i2c_touchkey_write(tkey_i2c, KEYCODE_REG, data, 4);
  359. msleep(100);
  360. dev_dbg(&tkey_i2c->client->dev,
  361. "write data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
  362. data[0], data[1], data[2], data[3]);
  363. /* Check autocal status */
  364. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 6);
  365. if (tkey_i2c->charging_mode) {
  366. if (data[5] & TK_BIT_TA_ON) {
  367. dev_dbg(&tkey_i2c->client->dev, "%s: TA mode is Enabled\n", __func__);
  368. break;
  369. } else {
  370. dev_err(&tkey_i2c->client->dev, "%s: Error to enable TA mode, retry %d\n",
  371. __func__, retry);
  372. }
  373. } else {
  374. if (!(data[5] & TK_BIT_TA_ON)) {
  375. dev_dbg(&tkey_i2c->client->dev, "%s: TA mode is Disabled\n", __func__);
  376. break;
  377. } else {
  378. dev_err(&tkey_i2c->client->dev, "%s: Error to disable TA mode, retry %d\n",
  379. __func__, retry);
  380. }
  381. }
  382. retry = retry + 1;
  383. }
  384. if (retry == 3)
  385. dev_err(&tkey_i2c->client->dev, "%s: Failed to set the TA mode\n", __func__);
  386. return count;
  387. }
  388. static void touchkey_ta_cb(struct touchkey_callbacks *cb, bool ta_status)
  389. {
  390. struct touchkey_i2c *tkey_i2c =
  391. container_of(cb, struct touchkey_i2c, callbacks);
  392. tkey_i2c->charging_mode = ta_status;
  393. if (tkey_i2c->enabled)
  394. touchkey_ta_setting(tkey_i2c);
  395. }
  396. #endif
  397. #if defined(CONFIG_GLOVE_TOUCH)
  398. static void touchkey_glove_change_work(struct work_struct *work)
  399. {
  400. u8 data[6] = { 0, };
  401. int ret = 0;
  402. unsigned short retry = 0;
  403. bool value;
  404. u8 glove_bit;
  405. struct touchkey_i2c *tkey_i2c =
  406. container_of(work, struct touchkey_i2c,
  407. glove_change_work);
  408. #ifdef TKEY_FLIP_MODE
  409. if (tkey_i2c->ic_mode == MODE_FLIP) {
  410. dev_info(&tkey_i2c->client->dev,"As flip cover mode enabled, skip glove mode set\n");
  411. return;
  412. }
  413. #endif
  414. mutex_lock(&tkey_i2c->tsk_glove_lock);
  415. value = tkey_i2c->tsk_cmd_glove;
  416. while (retry < 3) {
  417. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 4);
  418. if (ret < 0) {
  419. dev_err(&tkey_i2c->client->dev, "%s: Failed to read Keycode_reg %d times\n",
  420. __func__, retry);
  421. goto out_glove_change_work;
  422. }
  423. dev_dbg(&tkey_i2c->client->dev,
  424. "data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
  425. data[0], data[1], data[2], data[3]);
  426. if (value) {
  427. /* Send glove Command */
  428. data[0] = 0xA0;
  429. data[3] = 0x30;
  430. } else {
  431. data[0] = 0xA0;
  432. data[3] = 0x40;
  433. }
  434. i2c_touchkey_write(tkey_i2c, KEYCODE_REG, data, 4);
  435. msleep(130);
  436. dev_dbg(&tkey_i2c->client->dev,
  437. "data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
  438. data[0], data[1], data[2], data[3]);
  439. /* Check autocal status */
  440. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 6);
  441. glove_bit = !!(data[5] & TK_BIT_GLOVE);
  442. if (value == glove_bit) {
  443. dev_info(&tkey_i2c->client->dev, "%s:Glove mode is %s\n",
  444. __func__, value ? "enabled" : "disabled");
  445. tkey_i2c->ic_mode = value ? MODE_GLOVE : MODE_NORMAL;
  446. break;
  447. } else
  448. dev_err(&tkey_i2c->client->dev, "%s:Error to set glove_mode val %d, bit %d, retry %d\n",
  449. __func__, value, glove_bit, retry);
  450. retry = retry + 1;
  451. }
  452. if (retry == 3)
  453. dev_err(&tkey_i2c->client->dev, "%s: Failed to set the glove mode\n", __func__);
  454. out_glove_change_work:
  455. mutex_unlock(&tkey_i2c->tsk_glove_lock);
  456. }
  457. static struct touchkey_i2c *tkey_i2c_global;
  458. void touchkey_glovemode(int on)
  459. {
  460. struct touchkey_i2c *tkey_i2c = tkey_i2c_global;
  461. if (!touchkey_probe) {
  462. dev_err(&tkey_i2c->client->dev, "%s: Touchkey is not probed\n", __func__);
  463. return;
  464. }
  465. if (!tkey_i2c->enabled) {
  466. dev_err(&tkey_i2c->client->dev, "%s: Touchkey is not enabled\n", __func__);
  467. return ;
  468. }
  469. if (wake_lock_active(&tkey_i2c->fw_wakelock)) {
  470. printk(KERN_DEBUG"touchkey:%s, wakelock active\n", __func__);
  471. return ;
  472. }
  473. cancel_work_sync(&tkey_i2c->glove_change_work);
  474. /* protect duplicated execution */
  475. if (tkey_i2c->ic_mode == MODE_FLIP) {
  476. dev_info(&tkey_i2c->client->dev, "%s pass. flip enabled\n",
  477. __func__);
  478. goto end_glovemode;
  479. }
  480. if (on == (tkey_i2c->ic_mode == MODE_GLOVE)) {
  481. dev_info(&tkey_i2c->client->dev, "%s pass. cmd %d, cur mode %d\n",
  482. __func__, on, tkey_i2c->ic_mode);
  483. if(!on) dump_stack();
  484. goto end_glovemode;
  485. }
  486. tkey_i2c->tsk_cmd_glove = on;
  487. schedule_work(&tkey_i2c->glove_change_work);
  488. dev_info(&tkey_i2c->client->dev, "Touchkey glove %s\n", on ? "On" : "Off");
  489. end_glovemode:
  490. return ;
  491. }
  492. #endif
  493. #ifdef TKEY_FLIP_MODE
  494. void touchkey_flip_cover(int value)
  495. {
  496. struct touchkey_i2c *tkey_i2c = tkey_i2c_global;
  497. u8 data[6] = { 0, };
  498. int ret = 0;
  499. unsigned short retry = 0;
  500. u8 flip_status;
  501. tkey_i2c->enabled_flip = value;
  502. if (!touchkey_probe) {
  503. dev_err(&tkey_i2c->client->dev, "%s: Touchkey is not probed\n", __func__);
  504. return;
  505. }
  506. if (!tkey_i2c->enabled) {
  507. dev_err(&tkey_i2c->client->dev, "%s: Touchkey is not enabled\n", __func__);
  508. if (value)
  509. tkey_i2c->ic_mode = MODE_FLIP;
  510. else
  511. tkey_i2c->ic_mode = MODE_NORMAL;
  512. return;
  513. }
  514. if (wake_lock_active(&tkey_i2c->fw_wakelock)) {
  515. printk(KERN_DEBUG"touchkey:%s, wakelock active\n", __func__);
  516. return ;
  517. }
  518. #if 0
  519. if (tkey_i2c->firmware_id != TK_MODULE_20065) {
  520. dev_err(&tkey_i2c->client->dev,
  521. "%s: Do not support old module\n",
  522. __func__);
  523. return;
  524. }
  525. #endif
  526. mutex_lock(&tkey_i2c->tsk_glove_lock);
  527. while (retry < 3) {
  528. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 4);
  529. if (ret < 0) {
  530. dev_err(&tkey_i2c->client->dev, "%s: Failed to read Keycode_reg %d times\n",
  531. __func__, retry);
  532. goto out_flip_cover;
  533. }
  534. dev_dbg(&tkey_i2c->client->dev,
  535. "data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
  536. data[0], data[1], data[2], data[3]);
  537. if (value == 1) {
  538. /* Send filp mode Command */
  539. data[0] = 0xA0;
  540. data[3] = 0x50;
  541. } else {
  542. data[0] = 0xA0;
  543. data[3] = 0x40;
  544. }
  545. i2c_touchkey_write(tkey_i2c, KEYCODE_REG, data, 4);
  546. msleep(130);
  547. dev_dbg(&tkey_i2c->client->dev,
  548. "data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
  549. data[0], data[1], data[2], data[3]);
  550. /* Check status */
  551. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 6);
  552. flip_status = !!(data[5] & TK_BIT_FLIP);
  553. dev_dbg(&tkey_i2c->client->dev,
  554. "data[5]=%x",data[5] & TK_BIT_FLIP);
  555. if (value == flip_status) {
  556. dev_info(&tkey_i2c->client->dev, "%s: Flip mode is %s\n", __func__, flip_status ? "enabled" : "disabled");
  557. tkey_i2c->ic_mode = flip_status ? MODE_FLIP : MODE_NORMAL;
  558. break;
  559. } else
  560. dev_err(&tkey_i2c->client->dev, "%s: Error to set Flip mode, val %d, flip bit %d, retry %d\n",
  561. __func__, value, flip_status, retry);
  562. retry = retry + 1;
  563. }
  564. if (retry == 3) {
  565. dev_err(&tkey_i2c->client->dev, "%s: Failed to set the Flip mode\n", __func__);
  566. if (value == 0) {
  567. tkey_i2c->pdata->power_on(0);
  568. usleep_range(1000, 1000);
  569. tkey_i2c->pdata->power_on(1);
  570. msleep(300);
  571. printk(KERN_DEBUG"touchkey:%s, reset ic\n", __func__);
  572. /* CYPRESS Firmware setting interrupt type : dual or single interrupt */
  573. cypress_touchkey_interrupt_set_dual(tkey_i2c);
  574. }
  575. }
  576. out_flip_cover:
  577. mutex_unlock(&tkey_i2c->tsk_glove_lock);
  578. }
  579. #endif
  580. #ifdef TKEY_GRIP_MODE
  581. void touchkey_grip_mode_ctr(struct touchkey_i2c *tkey_i2c)
  582. {
  583. u8 buf = TKEY_CMD_GRIP;
  584. int ret;
  585. int retry = 3;
  586. mutex_lock(&tkey_i2c->grip_mode_lock);
  587. ret = wake_lock_active(&tkey_i2c->fw_wakelock);
  588. if (unlikely(ret)) {
  589. printk(KERN_DEBUG"touchkey:%s, wakelock active\n", __func__);
  590. goto out_grip_mode_ctr;
  591. }
  592. if (tkey_i2c->ic_mode == tkey_i2c->grip_mode) {
  593. printk(KERN_DEBUG"touchkey:pass grip cmd. ic mode %d, cmd %d\n",
  594. tkey_i2c->ic_mode, tkey_i2c->grip_mode);
  595. goto out_grip_mode_ctr;
  596. }
  597. if (tkey_i2c->grip_mode) {
  598. tkey_i2c->pdata->power_on(1);
  599. msleep(300); //50);
  600. /* set as grip mode */
  601. /* to avoid i2c write lock */
  602. while (retry--) {
  603. ret = i2c_smbus_write_i2c_block_data(tkey_i2c->client, KEYCODE_REG, 1, &buf);
  604. if (ret < 0) {
  605. printk(KERN_DEBUG"touchkey:failed to set grip mode ret(%d),retry(%d)\n",
  606. ret, retry);
  607. tkey_i2c->pdata->power_on(0);
  608. msleep(30);
  609. tkey_i2c->pdata->power_on(1);
  610. msleep(300); //50);
  611. continue;
  612. }
  613. break;
  614. }
  615. if (ret < 0) {
  616. tkey_i2c->pdata->power_on(0);
  617. goto out_grip_mode_ctr;
  618. }
  619. tkey_i2c->ic_mode = MODE_GRIP;
  620. /* CYPRESS Firmware setting interrupt type : dual or single interrupt */
  621. cypress_touchkey_interrupt_set_dual(tkey_i2c);
  622. } else {
  623. tkey_i2c->pdata->power_on(0);
  624. tkey_i2c->ic_mode = MODE_NORMAL;
  625. }
  626. printk(KERN_DEBUG"touchkey:set as %s mode\n",
  627. (tkey_i2c->ic_mode == MODE_GRIP) ? "grip" : "normal");
  628. out_grip_mode_ctr:
  629. mutex_unlock(&tkey_i2c->grip_mode_lock);
  630. }
  631. #endif
  632. static int touchkey_enable_status_update(struct touchkey_i2c *tkey_i2c)
  633. {
  634. unsigned char data = 0x40;
  635. int ret;
  636. ret = i2c_touchkey_write(tkey_i2c, KEYCODE_REG, &data, 1);
  637. if (ret < 0) {
  638. dev_err(&tkey_i2c->client->dev, "%s, err(%d)\n", __func__, ret);
  639. tkey_i2c->status_update = false;
  640. return ret;
  641. }
  642. tkey_i2c->status_update = true;
  643. dev_dbg(&tkey_i2c->client->dev, "%s\n", __func__);
  644. msleep(20);
  645. return 0;
  646. }
  647. #if defined(TK_HAS_AUTOCAL)
  648. enum {
  649. TK_CMD_READ_THRESHOLD = 0,
  650. TK_CMD_READ_IDAC,
  651. TK_CMD_READ_SENSITIVITY,
  652. TK_CMD_READ_RAW,
  653. };
  654. const u8 fac_reg_index[] = {
  655. CYPRESS_REG_THRESHOLD,
  656. CYPRESS_REG_IDAC,
  657. CYPRESS_REG_DIFF,
  658. CYPRESS_REG_RAW,
  659. };
  660. struct FAC_CMD {
  661. u8 cmd;
  662. u8 opt1; // 0, 1, 2, 3
  663. u16 result;
  664. };
  665. static u8 touchkey_get_read_size(u8 cmd)
  666. {
  667. switch (cmd) {
  668. case TK_CMD_READ_RAW:
  669. case TK_CMD_READ_SENSITIVITY:
  670. return 2;
  671. case TK_CMD_READ_IDAC:
  672. case TK_CMD_READ_THRESHOLD:
  673. return 1;
  674. break;
  675. default:
  676. break;
  677. }
  678. return 0;
  679. }
  680. static int touchkey_fac_read_data(struct device *dev,
  681. char *buf, struct FAC_CMD *cmd)
  682. {
  683. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  684. int ret;
  685. u8 size;
  686. u8 base_index;
  687. u8 data[26] = { 0, };
  688. int i;
  689. u16 max_val = 0;
  690. if (unlikely(!tkey_i2c->status_update)) {
  691. ret = touchkey_enable_status_update(tkey_i2c);
  692. if (ret < 0)
  693. goto out_fac_read_data;
  694. }
  695. size = touchkey_get_read_size(cmd->cmd);
  696. if (size == 0) {
  697. printk(KERN_DEBUG"touchkey:wrong size %d\n", size);
  698. goto out_fac_read_data;
  699. }
  700. if (cmd->opt1 > 4) {
  701. printk(KERN_DEBUG"touchkey:wrong opt1 %d\n", cmd->opt1);
  702. goto out_fac_read_data;
  703. }
  704. base_index = fac_reg_index[cmd->cmd] + size * cmd->opt1;
  705. if (base_index > 25) {
  706. printk(KERN_DEBUG"touchkey:wrong index %d, cmd %d, size %d, opt1 %d\n",
  707. base_index, cmd->cmd, size, cmd->opt1);
  708. goto out_fac_read_data;
  709. }
  710. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, base_index + size);
  711. if (ret < 0) {
  712. printk(KERN_DEBUG"touchkey:i2c read failed\n");
  713. goto out_fac_read_data;
  714. }
  715. /* make value */
  716. cmd->result = 0;
  717. for (i = size - 1; i >= 0; --i) {
  718. cmd->result = cmd->result | (data[base_index++] << (8 * i));
  719. max_val |= 0xff << (8 * i);
  720. }
  721. /* garbage check */
  722. if (unlikely(cmd->result == max_val)) {
  723. printk(KERN_DEBUG"touchkey:cmd %d opt1 %d, max value\n", cmd->cmd, cmd->opt1);
  724. cmd->result = 0;
  725. }
  726. out_fac_read_data:
  727. return sprintf(buf, "%d\n", cmd->result);
  728. }
  729. static ssize_t touchkey_raw_data0_show(struct device *dev,
  730. struct device_attribute *attr, char *buf)
  731. {
  732. struct FAC_CMD cmd = {TK_CMD_READ_RAW, 0, 0};
  733. return touchkey_fac_read_data(dev, buf, &cmd);
  734. }
  735. static ssize_t touchkey_raw_data1_show(struct device *dev,
  736. struct device_attribute *attr, char *buf)
  737. {
  738. struct FAC_CMD cmd = {TK_CMD_READ_RAW, 1, 0};
  739. return touchkey_fac_read_data(dev, buf, &cmd);
  740. }
  741. #if !defined(TK_USE_RECENT)
  742. static ssize_t touchkey_raw_data2_show(struct device *dev,
  743. struct device_attribute *attr, char *buf)
  744. {
  745. struct FAC_CMD cmd = {TK_CMD_READ_RAW, 2, 0};
  746. return touchkey_fac_read_data(dev, buf, &cmd);
  747. }
  748. static ssize_t touchkey_raw_data3_show(struct device *dev,
  749. struct device_attribute *attr, char *buf)
  750. {
  751. struct FAC_CMD cmd = {TK_CMD_READ_RAW, 3, 0};
  752. return touchkey_fac_read_data(dev, buf, &cmd);
  753. }
  754. #endif
  755. static ssize_t touchkey_idac0_show(struct device *dev,
  756. struct device_attribute *attr, char *buf)
  757. {
  758. struct FAC_CMD cmd = {TK_CMD_READ_IDAC, 0, 0};
  759. return touchkey_fac_read_data(dev, buf, &cmd);
  760. }
  761. static ssize_t touchkey_idac1_show(struct device *dev,
  762. struct device_attribute *attr, char *buf)
  763. {
  764. struct FAC_CMD cmd = {TK_CMD_READ_IDAC, 1, 0};
  765. return touchkey_fac_read_data(dev, buf, &cmd);
  766. }
  767. #if !defined(TK_USE_RECENT)
  768. static ssize_t touchkey_idac2_show(struct device *dev,
  769. struct device_attribute *attr, char *buf)
  770. {
  771. struct FAC_CMD cmd = {TK_CMD_READ_IDAC, 2, 0};
  772. return touchkey_fac_read_data(dev, buf, &cmd);
  773. }
  774. static ssize_t touchkey_idac3_show(struct device *dev,
  775. struct device_attribute *attr, char *buf)
  776. {
  777. struct FAC_CMD cmd = {TK_CMD_READ_IDAC, 3, 0};
  778. return touchkey_fac_read_data(dev, buf, &cmd);
  779. }
  780. #endif
  781. static ssize_t touchkey_threshold_show(struct device *dev,
  782. struct device_attribute *attr, char *buf)
  783. {
  784. struct FAC_CMD cmd = {TK_CMD_READ_THRESHOLD, 0, 0};
  785. return touchkey_fac_read_data(dev, buf, &cmd);
  786. }
  787. #endif
  788. #ifdef TOUCHKEY_BOOSTER
  789. static void touchkey_change_dvfs_lock(struct work_struct *work)
  790. {
  791. struct touchkey_i2c *tkey_i2c =
  792. container_of(work,
  793. struct touchkey_i2c, work_dvfs_chg.work);
  794. int retval = 0;
  795. mutex_lock(&tkey_i2c->dvfs_lock);
  796. retval = set_freq_limit(DVFS_TOUCH_ID, tkey_i2c->dvfs_freq);
  797. if (retval < 0)
  798. pr_info("%s: booster change failed(%d).\n",
  799. __func__, retval);
  800. tkey_i2c->dvfs_lock_status = false;
  801. mutex_unlock(&tkey_i2c->dvfs_lock);
  802. }
  803. static void touchkey_set_dvfs_off(struct touchkey_i2c *tkey_i2c)
  804. {
  805. int retval;
  806. mutex_lock(&tkey_i2c->dvfs_lock);
  807. retval = set_freq_limit(DVFS_TOUCH_ID, -1);
  808. if (retval < 0){
  809. pr_err("%s: booster stop failed(%d).\n",
  810. __func__, retval);
  811. tkey_i2c->dvfs_lock_status = false;
  812. }
  813. else
  814. tkey_i2c->dvfs_lock_status = true;
  815. mutex_unlock(&tkey_i2c->dvfs_lock);
  816. }
  817. static void touchkey_set_dvfs_off_work(struct work_struct *work)
  818. {
  819. struct touchkey_i2c *tkey_i2c =
  820. container_of(work,
  821. struct touchkey_i2c, work_dvfs_off.work);
  822. touchkey_set_dvfs_off(tkey_i2c);
  823. }
  824. static void touchkey_set_dvfs_lock(struct touchkey_i2c *tkey_i2c,
  825. uint32_t on)
  826. {
  827. int retval;
  828. if (TKEY_BOOSTER_DISABLE == tkey_i2c->dvfs_boost_mode)
  829. return;
  830. mutex_lock(&tkey_i2c->dvfs_lock);
  831. if (on == 0) {
  832. cancel_delayed_work(&tkey_i2c->work_dvfs_chg);
  833. if (tkey_i2c->dvfs_lock_status) {
  834. retval = set_freq_limit(DVFS_TOUCH_ID, tkey_i2c->dvfs_freq);
  835. if (retval < 0)
  836. pr_info("%s: cpu first lock failed(%d)\n", __func__, retval);
  837. tkey_i2c->dvfs_lock_status = false;
  838. }
  839. schedule_delayed_work(&tkey_i2c->work_dvfs_off,
  840. msecs_to_jiffies(TKEY_BOOSTER_OFF_TIME));
  841. } else if (on == 1) {
  842. cancel_delayed_work(&tkey_i2c->work_dvfs_off);
  843. schedule_delayed_work(&tkey_i2c->work_dvfs_chg,
  844. msecs_to_jiffies(TKEY_BOOSTER_CHG_TIME));
  845. } else if (on == 2) {
  846. if (tkey_i2c->dvfs_lock_status) {
  847. cancel_delayed_work(&tkey_i2c->work_dvfs_off);
  848. cancel_delayed_work(&tkey_i2c->work_dvfs_chg);
  849. schedule_work(&tkey_i2c->work_dvfs_off.work);
  850. }
  851. }
  852. mutex_unlock(&tkey_i2c->dvfs_lock);
  853. }
  854. static int touchkey_init_dvfs(struct touchkey_i2c *tkey_i2c)
  855. {
  856. mutex_init(&tkey_i2c->dvfs_lock);
  857. INIT_DELAYED_WORK(&tkey_i2c->work_dvfs_off, touchkey_set_dvfs_off_work);
  858. INIT_DELAYED_WORK(&tkey_i2c->work_dvfs_chg, touchkey_change_dvfs_lock);
  859. tkey_i2c->dvfs_boost_mode = TKEY_BOOSTER_LEVEL2;
  860. tkey_i2c->dvfs_freq = MIN_TOUCH_LIMIT_SECOND;
  861. tkey_i2c->dvfs_lock_status = true;
  862. return 0;
  863. }
  864. #endif
  865. #if defined(TK_HAS_FIRMWARE_UPDATE)
  866. /* To check firmware compatibility */
  867. int get_module_class(u8 ver)
  868. {
  869. static int size = ARRAY_SIZE(module_divider);
  870. int i;
  871. if (size == 2)
  872. return 0;
  873. for (i = size - 1; i > 0; --i) {
  874. if (ver < module_divider[i] &&
  875. ver >= module_divider[i-1])
  876. return i;
  877. }
  878. return 0;
  879. }
  880. bool is_same_module_class(struct touchkey_i2c *tkey_i2c)
  881. {
  882. int class_ic, class_file;
  883. if (md_ver_file == tkey_i2c->md_ver_ic)
  884. return true;
  885. class_file = get_module_class(md_ver_file);
  886. class_ic = get_module_class(tkey_i2c->md_ver_ic);
  887. printk(KERN_DEBUG"touchkey:module class, IC %d, File %d\n", class_ic, class_file);
  888. if (class_file == class_ic)
  889. return true;
  890. return false;
  891. }
  892. int tkey_load_fw_built_in(struct touchkey_i2c *tkey_i2c)
  893. {
  894. int retry = 3;
  895. int ret;
  896. while (retry--) {
  897. ret =
  898. request_firmware(&tkey_i2c->firm_data, tk_fw_name,
  899. &tkey_i2c->client->dev);
  900. if (ret < 0) {
  901. printk(KERN_ERR
  902. "touchkey:Unable to open firmware. ret %d retry %d\n",
  903. ret, retry);
  904. continue;
  905. }
  906. break;
  907. }
  908. if (ret < 0)
  909. return ret;
  910. tkey_i2c->fw_img = (struct fw_image *)tkey_i2c->firm_data->data;
  911. return ret;
  912. }
  913. int tkey_load_fw_sdcard(struct touchkey_i2c *tkey_i2c)
  914. {
  915. struct file *fp;
  916. mm_segment_t old_fs;
  917. long fsize, nread;
  918. int ret = 0;
  919. u8 *ums_data = NULL;
  920. old_fs = get_fs();
  921. set_fs(KERNEL_DS);
  922. fp = filp_open(TKEY_FW_PATH, O_RDONLY, S_IRUSR);
  923. if (IS_ERR(fp)) {
  924. printk(KERN_ERR "touchkey:failed to open %s.\n", TKEY_FW_PATH);
  925. ret = -ENOENT;
  926. set_fs(old_fs);
  927. return ret;
  928. }
  929. fsize = fp->f_path.dentry->d_inode->i_size;
  930. printk(KERN_NOTICE
  931. "touchkey:start, file path %s, size %ld Bytes\n",
  932. TKEY_FW_PATH, fsize);
  933. ums_data = kmalloc(fsize, GFP_KERNEL);
  934. if (IS_ERR(ums_data)) {
  935. printk(KERN_ERR
  936. "touchkey:%s, kmalloc failed\n", __func__);
  937. ret = -EFAULT;
  938. goto malloc_error;
  939. }
  940. nread = vfs_read(fp, (char __user *)ums_data,
  941. fsize, &fp->f_pos);
  942. printk(KERN_NOTICE "touchkey:nread %ld Bytes\n", nread);
  943. if (nread != fsize) {
  944. printk(KERN_ERR
  945. "touchkey:failed to read firmware file, nread %ld Bytes\n",
  946. nread);
  947. ret = -EIO;
  948. kfree(ums_data);
  949. goto read_err;
  950. }
  951. filp_close(fp, current->files);
  952. set_fs(old_fs);
  953. tkey_i2c->fw_img = (struct fw_image *)ums_data;
  954. return 0;
  955. read_err:
  956. malloc_error:
  957. filp_close(fp, current->files);
  958. set_fs(old_fs);
  959. return ret;
  960. }
  961. void touchkey_unload_fw(struct touchkey_i2c *tkey_i2c)
  962. {
  963. switch (tkey_i2c->fw_path) {
  964. case FW_BUILT_IN:
  965. release_firmware(tkey_i2c->firm_data);
  966. break;
  967. case FW_IN_SDCARD:
  968. kfree(tkey_i2c->fw_img);
  969. break;
  970. default:
  971. break;
  972. }
  973. tkey_i2c->fw_path = FW_NONE;
  974. tkey_i2c->fw_img = NULL;
  975. tkey_i2c->firm_data = NULL;
  976. firmware_data = NULL;
  977. }
  978. int touchkey_load_fw(struct touchkey_i2c *tkey_i2c, u8 fw_path)
  979. {
  980. int ret = 0;
  981. struct fw_image *fw_img;
  982. switch (fw_path) {
  983. case FW_BUILT_IN:
  984. ret = tkey_load_fw_built_in(tkey_i2c);
  985. break;
  986. case FW_IN_SDCARD:
  987. ret = tkey_load_fw_sdcard(tkey_i2c);
  988. break;
  989. default:
  990. printk(KERN_DEBUG"touchkey:unknown path(%d)\n", fw_path);
  991. goto err_load_fw;
  992. }
  993. if (ret < 0)
  994. goto err_load_fw;
  995. fw_img = tkey_i2c->fw_img;
  996. /* header check */
  997. if (fw_img->hdr_ver == 1 && fw_img->hdr_len == 16) {
  998. printk(KERN_DEBUG"touchkey:detect hdr\n");
  999. firmware_data = (u8 *)fw_img->data;
  1000. fw_ver_file = fw_img->first_fw_ver;
  1001. md_ver_file = fw_img->second_fw_ver;
  1002. } else {
  1003. printk(KERN_DEBUG"touchkey:no hdr\n");
  1004. firmware_data = (u8 *)fw_img;
  1005. }
  1006. return ret;
  1007. err_load_fw:
  1008. firmware_data = NULL;
  1009. return ret;
  1010. }
  1011. #ifdef CYPRESS_CRC_CHECK
  1012. int tkey_crc_check(struct touchkey_i2c *tkey_i2c)
  1013. {
  1014. char data[3] = {0, };
  1015. int retry = 3;
  1016. int ret;
  1017. unsigned short chk_ic;
  1018. while (retry--) {
  1019. ret = i2c_touchkey_read(tkey_i2c, CYPRESS_REG_CRC, data, 2);
  1020. if (ret < 0) {
  1021. dev_err(&tkey_i2c->client->dev, "retry crc read(%d)\n", retry);
  1022. msleep(10);
  1023. continue;
  1024. }
  1025. break;
  1026. }
  1027. if (ret < 0) {
  1028. dev_err(&tkey_i2c->client->dev, "Failed to read CRC\n");
  1029. return 0;
  1030. }
  1031. chk_ic = (data[0] << 8) | data[1];
  1032. dev_info(&tkey_i2c->client->dev, "checksum, ic:%#x, bin:%#x\n",
  1033. chk_ic, tkey_i2c->fw_img->checksum);
  1034. return (tkey_i2c->fw_img->checksum == chk_ic);
  1035. }
  1036. #endif
  1037. int touchkey_fw_update(struct touchkey_i2c *tkey_i2c, u8 fw_path, bool bforced)
  1038. {
  1039. int ret;
  1040. ret = touchkey_load_fw(tkey_i2c, fw_path);
  1041. if (ret < 0) {
  1042. printk(KERN_DEBUG"touchkey:failed to load fw data\n");
  1043. return ret;
  1044. }
  1045. tkey_i2c->fw_path = fw_path;
  1046. /* f/w info */
  1047. dev_info(&tkey_i2c->client->dev, "fw ver %#x, new fw ver %#x\n",
  1048. tkey_i2c->fw_ver_ic, fw_ver_file);
  1049. dev_info(&tkey_i2c->client->dev, "module ver %#x, new module ver %#x\n",
  1050. tkey_i2c->md_ver_ic, md_ver_file);
  1051. dev_info(&tkey_i2c->client->dev, "new checksum %#x\n",
  1052. tkey_i2c->fw_img->checksum);
  1053. if (unlikely(bforced)) {
  1054. printk(KERN_DEBUG"touchkey:forced update\n");
  1055. goto run_fw_update;
  1056. }
  1057. /* check update condition */
  1058. ret = is_same_module_class(tkey_i2c);
  1059. if (ret == false)
  1060. goto out_fw_update;
  1061. #if defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1062. if (tkey_i2c->fw_ver_ic != fw_ver_file)
  1063. goto run_fw_update;
  1064. #else
  1065. if (tkey_i2c->fw_ver_ic < fw_ver_file)
  1066. goto run_fw_update;
  1067. if (tkey_i2c->fw_ver_ic > fw_ver_file)
  1068. goto out_fw_update;
  1069. #endif
  1070. /* do not need to update f/w */
  1071. /* if bin = ic version, check checksum */
  1072. #ifdef CYPRESS_CRC_CHECK
  1073. ret = tkey_crc_check(tkey_i2c);
  1074. if (ret == false) {
  1075. dev_info(&tkey_i2c->client->dev, "crc error, run fw update\n");
  1076. goto run_fw_update;
  1077. }else{
  1078. dev_info(&tkey_i2c->client->dev, "crc ok, pass fw update\n");
  1079. goto out_fw_update;
  1080. }
  1081. #endif
  1082. tkey_i2c->do_checksum = true;
  1083. // goto run_fw_update;
  1084. out_fw_update:
  1085. /* pass update */
  1086. dev_info(&tkey_i2c->client->dev, "pass fw update\n");
  1087. touchkey_unload_fw(tkey_i2c);
  1088. run_fw_update:
  1089. queue_work(tkey_i2c->fw_wq, &tkey_i2c->update_work);
  1090. return 0;
  1091. }
  1092. static void touchkey_i2c_update_work(struct work_struct *work)
  1093. {
  1094. struct touchkey_i2c *tkey_i2c =
  1095. container_of(work, struct touchkey_i2c, update_work);
  1096. int ret = 0;
  1097. int retry = 3;
  1098. touchkey_enable_irq(tkey_i2c, false);
  1099. wake_lock(&tkey_i2c->fw_wakelock);
  1100. if (tkey_i2c->fw_path == FW_NONE)
  1101. goto end_fw_update;
  1102. printk(KERN_DEBUG"touchkey:%s\n", __func__);
  1103. tkey_i2c->update_status = TK_UPDATE_DOWN;
  1104. while (retry--) {
  1105. ret = ISSP_main(tkey_i2c);
  1106. if (ret != 0) {
  1107. msleep(50);
  1108. dev_err(&tkey_i2c->client->dev, "failed to update f/w. retry\n");
  1109. continue;
  1110. }
  1111. dev_info(&tkey_i2c->client->dev, "finish f/w update\n");
  1112. tkey_i2c->update_status = TK_UPDATE_PASS;
  1113. break;
  1114. }
  1115. if (retry <= 0 && ret != 0) {
  1116. tkey_i2c->pdata->power_on(0);
  1117. tkey_i2c->update_status = TK_UPDATE_FAIL;
  1118. dev_err(&tkey_i2c->client->dev, "failed to update f/w\n");
  1119. goto err_fw_update;
  1120. }else{
  1121. msleep(50);
  1122. tkey_i2c->pdata->power_on(0);
  1123. msleep(10);
  1124. tkey_i2c->pdata->power_on(1);
  1125. msleep(300);
  1126. }
  1127. ret = touchkey_i2c_check(tkey_i2c);
  1128. if (ret < 0)
  1129. goto err_fw_update;
  1130. dev_info(&tkey_i2c->client->dev, "f/w ver = %#X, module ver = %#X\n",
  1131. tkey_i2c->fw_ver_ic, tkey_i2c->md_ver_ic);
  1132. err_fw_update:
  1133. touchkey_unload_fw(tkey_i2c);
  1134. end_fw_update:
  1135. wake_unlock(&tkey_i2c->fw_wakelock);
  1136. if (ret < 0) {
  1137. printk(KERN_DEBUG"touchkey:do not enable irq\n");
  1138. return ;
  1139. }
  1140. #if defined(TK_HAS_AUTOCAL)
  1141. //touchkey_autocalibration(tkey_i2c);
  1142. #endif
  1143. touchkey_enable_irq(tkey_i2c, true);
  1144. }
  1145. #endif
  1146. int PrevMenuValue = 0xFF, PrevBackValue = 0xFF; /*Dummy value*/
  1147. static irqreturn_t touchkey_interrupt(int irq, void *dev_id)
  1148. {
  1149. struct touchkey_i2c *tkey_i2c = dev_id;
  1150. u8 data[3];
  1151. int ret;
  1152. int keycode_type = 0;
  1153. int pressed = 0;
  1154. bool ic_mode;
  1155. int keycode_data[3];
  1156. int i;
  1157. #if !defined(CONFIG_SEC_S_PROJECT)
  1158. int CurrMenuValue, CurrBackValue;
  1159. #endif
  1160. #ifdef TK_KEYPAD_ENABLE
  1161. if (!tkey_i2c->keypad_enable) {
  1162. return IRQ_HANDLED;
  1163. }
  1164. #endif
  1165. if (unlikely(!touchkey_probe)) {
  1166. dev_err(&tkey_i2c->client->dev, "%s: Touchkey is not probed\n", __func__);
  1167. return IRQ_HANDLED;
  1168. }
  1169. #ifdef CONFIG_GLOVE_TOUCH
  1170. ic_mode = tkey_i2c->ic_mode;
  1171. #else
  1172. ic_mode = 0;
  1173. #endif
  1174. /* L OS support Screen Pinning feature.
  1175. * "recent + back key" event is CombinationKey for exit Screen Pinning mode.
  1176. * If touchkey firmware version is higher than CYPRESS_RECENT_BACK_REPORT_FW_VER,
  1177. * touchkey can make interrupt "back key" and "recent key" in same time.
  1178. * lower version firmware can make interrupt only one key event.
  1179. */
  1180. if (tkey_i2c->fw_ver_ic >= CYPRESS_RECENT_BACK_REPORT_FW_VER) {
  1181. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 1);
  1182. if (ret < 0){
  1183. dev_err(&tkey_i2c->client->dev, "%s: i2c read fail, ret:%d\n", __func__, ret);
  1184. return IRQ_HANDLED;
  1185. }
  1186. keycode_data[1] = data[0] & 0x3;
  1187. keycode_data[2] = (data[0] >> 2) & 0x3;
  1188. for (i = 1; i < 3; i++) {
  1189. if (keycode_data[i]) {
  1190. input_report_key(tkey_i2c->input_dev, touchkey_keycode[i], (keycode_data[i] % 2));
  1191. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1192. dev_info(&tkey_i2c->client->dev, "keycode: %d %s %d\n", touchkey_keycode[i],
  1193. (keycode_data[i] % 2) ? "P" : "R", ic_mode);
  1194. #else
  1195. dev_info(&tkey_i2c->client->dev, " %s %d\n",
  1196. (keycode_data[i] % 2) ? "P" : "R", ic_mode);
  1197. #endif
  1198. if (keycode_data[i] % 2) pressed++;
  1199. }
  1200. }
  1201. input_sync(tkey_i2c->input_dev);
  1202. #ifdef TOUCHKEY_BOOSTER
  1203. touchkey_set_dvfs_lock(tkey_i2c, !!pressed);
  1204. #endif
  1205. } else { /* old version. */
  1206. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 3);
  1207. if (ret < 0){
  1208. dev_err(&tkey_i2c->client->dev, "%s: i2c read fail, ret:%d\n", __func__, ret);
  1209. return IRQ_HANDLED;
  1210. }
  1211. #if !defined(CONFIG_SEC_S_PROJECT)
  1212. if (tkey_i2c->fw_ver_ic >= 0x07) {
  1213. keycode_type = (data[0] & TK_BIT_KEYCODE);
  1214. if (keycode_type < 0 || keycode_type > touchkey_count) {
  1215. dev_dbg(&tkey_i2c->client->dev, "keycode_type err\n");
  1216. return IRQ_HANDLED;
  1217. }
  1218. CurrMenuValue = (data[0] & 0x1);
  1219. CurrBackValue = (data[0] & 0x2) >> 1;
  1220. if (CurrMenuValue != PrevMenuValue) {
  1221. input_report_key(tkey_i2c->input_dev, KEY_MENU, CurrMenuValue);
  1222. keycode_type = 1;
  1223. pressed = CurrMenuValue;
  1224. }
  1225. if (CurrBackValue != PrevBackValue) {
  1226. input_report_key(tkey_i2c->input_dev, KEY_BACK, CurrBackValue);
  1227. keycode_type = 2;
  1228. pressed = CurrBackValue;
  1229. }
  1230. input_sync(tkey_i2c->input_dev);
  1231. /* Backup data*/
  1232. PrevMenuValue = CurrMenuValue;
  1233. PrevBackValue = CurrBackValue;
  1234. }
  1235. else
  1236. #endif
  1237. {
  1238. keycode_type = (data[0] & TK_BIT_KEYCODE);
  1239. pressed = !(data[0] & TK_BIT_PRESS_EV);
  1240. if (keycode_type <= 0 || keycode_type >= touchkey_count) {
  1241. dev_dbg(&tkey_i2c->client->dev, "keycode_type err\n");
  1242. return IRQ_HANDLED;
  1243. }
  1244. input_report_key(tkey_i2c->input_dev,
  1245. touchkey_keycode[keycode_type], pressed);
  1246. input_sync(tkey_i2c->input_dev);
  1247. }
  1248. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1249. dev_info(&tkey_i2c->client->dev, "keycode:%d pressed:%d %d\n",
  1250. touchkey_keycode[keycode_type], pressed, ic_mode);
  1251. #else
  1252. dev_info(&tkey_i2c->client->dev, "pressed:%d %d\n",
  1253. pressed, ic_mode);
  1254. #endif
  1255. #ifdef TOUCHKEY_BOOSTER
  1256. touchkey_set_dvfs_lock(tkey_i2c, !!pressed);
  1257. #endif
  1258. }
  1259. return IRQ_HANDLED;
  1260. }
  1261. static int touchkey_stop(struct touchkey_i2c *tkey_i2c)
  1262. {
  1263. int i;
  1264. mutex_lock(&tkey_i2c->lock);
  1265. if (!tkey_i2c->enabled) {
  1266. dev_err(&tkey_i2c->client->dev, "Touch key already disabled\n");
  1267. goto err_stop_out;
  1268. }
  1269. if (wake_lock_active(&tkey_i2c->fw_wakelock)) {
  1270. printk(KERN_DEBUG"touchkey:wake_lock active\n");
  1271. goto err_stop_out;
  1272. }
  1273. touchkey_enable_irq(tkey_i2c, false);
  1274. /* release keys */
  1275. for (i = 1; i < touchkey_count; ++i) {
  1276. input_report_key(tkey_i2c->input_dev,
  1277. touchkey_keycode[i], 0);
  1278. }
  1279. input_sync(tkey_i2c->input_dev);
  1280. #if defined(CONFIG_GLOVE_TOUCH)
  1281. /*cancel or waiting before pwr off*/
  1282. cancel_work_sync(&tkey_i2c->glove_change_work);
  1283. if (tkey_i2c->ic_mode != MODE_FLIP)
  1284. tkey_i2c->ic_mode = MODE_NORMAL;
  1285. #endif
  1286. #ifdef TKEY_GRIP_MODE
  1287. if (tkey_i2c->grip_mode)
  1288. touchkey_grip_mode_ctr(tkey_i2c);
  1289. else {
  1290. tkey_i2c->pdata->led_power_on(0);
  1291. tkey_i2c->pdata->power_on(0);
  1292. }
  1293. #else
  1294. tkey_i2c->pdata->led_power_on(0);
  1295. tkey_i2c->pdata->power_on(0);
  1296. #endif
  1297. tkey_i2c->enabled = false;
  1298. tkey_i2c->status_update = false;
  1299. #ifdef TOUCHKEY_BOOSTER
  1300. touchkey_set_dvfs_lock(tkey_i2c, 2);
  1301. #endif
  1302. err_stop_out:
  1303. mutex_unlock(&tkey_i2c->lock);
  1304. return 0;
  1305. }
  1306. static int touchkey_start(struct touchkey_i2c *tkey_i2c)
  1307. {
  1308. #ifdef TEST_JIG_MODE
  1309. unsigned char get_touch = 0x40;
  1310. #endif
  1311. mutex_lock(&tkey_i2c->lock);
  1312. if (tkey_i2c->enabled) {
  1313. dev_err(&tkey_i2c->client->dev, "Touch key already enabled\n");
  1314. goto err_start_out;
  1315. }
  1316. if (wake_lock_active(&tkey_i2c->fw_wakelock)) {
  1317. printk(KERN_DEBUG"touchkey:wake_lock active\n");
  1318. goto err_start_out;
  1319. }
  1320. #ifdef TKEY_GRIP_MODE
  1321. tkey_i2c->ic_mode = MODE_NORMAL;
  1322. tkey_i2c->pdata->power_on(0);
  1323. msleep(10);
  1324. #endif
  1325. // Initialize variable
  1326. PrevMenuValue = 0xFF; // Dummy value
  1327. PrevBackValue = 0xFF; // Dummy value
  1328. /* enable ldo11 */
  1329. tkey_i2c->pdata->power_on(1);
  1330. msleep(300); //50
  1331. /* CYPRESS Firmware setting interrupt type : dual or single interrupt */
  1332. cypress_touchkey_interrupt_set_dual(tkey_i2c);
  1333. #if !defined(TK_LED_DIRECT_CONTORL)
  1334. tkey_i2c->pdata->led_power_on(1);
  1335. tkey_i2c->enabled = true;
  1336. #if defined(TK_HAS_AUTOCAL)
  1337. //touchkey_autocalibration(tkey_i2c);
  1338. #endif
  1339. if (touchled_cmd_reversed) {
  1340. touchled_cmd_reversed = 0;
  1341. i2c_touchkey_write(tkey_i2c, KEYCODE_REG, (u8 *) &touchkey_led_status, 1);
  1342. dev_err(&tkey_i2c->client->dev, "%s: Turning LED is reserved\n", __func__);
  1343. msleep(30);
  1344. }
  1345. #else
  1346. tkey_i2c->enabled = true;
  1347. if (touchled_cmd_reversed) {
  1348. touchled_cmd_reversed = 0;
  1349. tkey_i2c->pdata->led_power_on(touchkey_led_status);
  1350. dev_err(&tkey_i2c->client->dev, "%s: Turning LED is reserved\n", __func__);
  1351. }
  1352. #if defined(TK_HAS_AUTOCAL)
  1353. //touchkey_autocalibration(tkey_i2c);
  1354. #endif
  1355. #endif
  1356. #ifdef TEST_JIG_MODE
  1357. i2c_touchkey_write(tkey_i2c, KEYCODE_REG, &get_touch, 1);
  1358. #endif
  1359. #if defined(TK_INFORM_CHARGER)
  1360. touchkey_ta_setting(tkey_i2c);
  1361. #endif
  1362. if (tkey_i2c->ic_mode == MODE_FLIP) {
  1363. tkey_i2c->ic_mode = MODE_NORMAL;
  1364. touchkey_flip_cover(1);
  1365. }
  1366. #if defined(CONFIG_GLOVE_TOUCH)
  1367. if (tkey_i2c->tsk_enable_glove_mode)
  1368. touchkey_glovemode(1);
  1369. #endif
  1370. touchkey_enable_irq(tkey_i2c, true);
  1371. err_start_out:
  1372. mutex_unlock(&tkey_i2c->lock);
  1373. return 0;
  1374. }
  1375. #ifdef TK_USE_OPEN_DWORK
  1376. static void touchkey_open_work(struct work_struct *work)
  1377. {
  1378. int retval;
  1379. struct touchkey_i2c *tkey_i2c =
  1380. container_of(work, struct touchkey_i2c,
  1381. open_work.work);
  1382. if (tkey_i2c->enabled) {
  1383. dev_err(&tkey_i2c->client->dev, "Touch key already enabled\n");
  1384. return;
  1385. }
  1386. retval = touchkey_start(tkey_i2c);
  1387. if (retval < 0)
  1388. dev_err(&tkey_i2c->client->dev,
  1389. "%s: Failed to start device\n", __func__);
  1390. }
  1391. #endif
  1392. #define USE_OPEN_CLOSE
  1393. static int touchkey_input_open(struct input_dev *dev)
  1394. {
  1395. struct touchkey_i2c *data = input_get_drvdata(dev);
  1396. int ret;
  1397. if (touchkey_probe != true) {
  1398. printk(KERN_ERR "%s, not yet init. \n", __func__);
  1399. return 0;
  1400. }
  1401. #ifdef TK_USE_OPEN_DWORK
  1402. schedule_delayed_work(&data->open_work,
  1403. msecs_to_jiffies(TK_OPEN_DWORK_TIME));
  1404. #else
  1405. #ifdef TKEY_GRIP_MODE
  1406. data->pwr_flag = true;
  1407. #endif
  1408. gpio_tlmm_config(GPIO_CFG(tkey_gpio_scl, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1409. gpio_tlmm_config(GPIO_CFG(tkey_gpio_sda, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1410. ret = touchkey_start(data);
  1411. if (ret)
  1412. goto err_open;
  1413. #endif
  1414. dev_info(&data->client->dev, "%s\n", __func__);
  1415. return 0;
  1416. err_open:
  1417. return ret;
  1418. }
  1419. static void touchkey_input_close(struct input_dev *dev)
  1420. {
  1421. struct touchkey_i2c *data = input_get_drvdata(dev);
  1422. #ifdef TK_USE_OPEN_DWORK
  1423. cancel_delayed_work_sync(&data->open_work);
  1424. #endif
  1425. #ifdef TKEY_GRIP_MODE
  1426. data->pwr_flag = false;
  1427. #endif
  1428. touchkey_stop(data);
  1429. gpio_tlmm_config(GPIO_CFG(tkey_gpio_scl, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), 1);
  1430. gpio_tlmm_config(GPIO_CFG(tkey_gpio_sda, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), 1);
  1431. dev_info(&data->client->dev, "%s\n", __func__);
  1432. }
  1433. #if defined(CONFIG_PM) && !defined(USE_OPEN_CLOSE)
  1434. #ifdef CONFIG_HAS_EARLYSUSPEND
  1435. #define touchkey_suspend NULL
  1436. #define touchkey_resume NULL
  1437. static int sec_touchkey_early_suspend(struct early_suspend *h)
  1438. {
  1439. struct touchkey_i2c *tkey_i2c =
  1440. container_of(h, struct touchkey_i2c, early_suspend);
  1441. touchkey_stop(tkey_i2c);
  1442. dev_dbg(&tkey_i2c->client->dev, "%s\n", __func__);
  1443. return 0;
  1444. }
  1445. static int sec_touchkey_late_resume(struct early_suspend *h)
  1446. {
  1447. struct touchkey_i2c *tkey_i2c =
  1448. container_of(h, struct touchkey_i2c, early_suspend);
  1449. dev_dbg(&tkey_i2c->client->dev, "%s\n", __func__);
  1450. touchkey_start(tkey_i2c);
  1451. return 0;
  1452. }
  1453. #else
  1454. static int touchkey_suspend(struct device *dev)
  1455. {
  1456. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1457. if (touchkey_probe != true) {
  1458. printk(KERN_ERR "%s Touchkey is not enabled. \n",
  1459. __func__);
  1460. return 0;
  1461. }
  1462. mutex_lock(&tkey_i2c->input_dev->mutex);
  1463. if (tkey_i2c->input_dev->users)
  1464. touchkey_stop(tkey_i2c);
  1465. mutex_unlock(&tkey_i2c->input_dev->mutex);
  1466. dev_dbg(&tkey_i2c->client->dev, "%s\n", __func__);
  1467. return 0;
  1468. }
  1469. static int touchkey_resume(struct device *dev)
  1470. {
  1471. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1472. if (touchkey_probe != true) {
  1473. printk(KERN_ERR "%s Touchkey is not enabled. \n",
  1474. __func__);
  1475. return 0;
  1476. }
  1477. mutex_lock(&tkey_i2c->input_dev->mutex);
  1478. if (tkey_i2c->input_dev->users)
  1479. touchkey_start(tkey_i2c);
  1480. mutex_unlock(&tkey_i2c->input_dev->mutex);
  1481. dev_dbg(&tkey_i2c->client->dev, "%s\n", __func__);
  1482. return 0;
  1483. }
  1484. #endif
  1485. static SIMPLE_DEV_PM_OPS(touchkey_pm_ops, touchkey_suspend, touchkey_resume);
  1486. #endif
  1487. static int touchkey_i2c_check(struct touchkey_i2c *tkey_i2c)
  1488. {
  1489. char data[3] = { 0, };
  1490. int ret = 0;
  1491. int retry = 3;
  1492. while (retry--) {
  1493. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 3);
  1494. if (ret < 0) {
  1495. dev_err(&tkey_i2c->client->dev, "retry i2c check(%d)\n", retry);
  1496. msleep(30);
  1497. continue;
  1498. }
  1499. break;
  1500. }
  1501. if (ret < 0) {
  1502. dev_err(&tkey_i2c->client->dev, "Failed to read Module version\n");
  1503. tkey_i2c->fw_ver_ic = 0;
  1504. tkey_i2c->md_ver_ic = 0;
  1505. return ret;
  1506. }
  1507. tkey_i2c->fw_ver_ic = data[1];
  1508. tkey_i2c->md_ver_ic = data[2];
  1509. dev_info(&tkey_i2c->client->dev, "%s: fw ver = 0x%02x, md ver = 0x%02x\n",
  1510. __func__, tkey_i2c->fw_ver_ic, tkey_i2c->md_ver_ic);
  1511. /* CYPRESS Firmware setting interrupt type : dual or single interrupt */
  1512. cypress_touchkey_interrupt_set_dual(tkey_i2c);
  1513. return ret;
  1514. }
  1515. static ssize_t touchkey_led_control(struct device *dev,
  1516. struct device_attribute *attr, const char *buf,
  1517. size_t size)
  1518. {
  1519. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1520. int data;
  1521. int ret;
  1522. #if !defined(TK_LED_DIRECT_CONTORL)
  1523. static const int ledCmd[] = {TK_CMD_LED_OFF, TK_CMD_LED_ON};
  1524. #endif
  1525. if (wake_lock_active(&tkey_i2c->fw_wakelock)) {
  1526. printk(KERN_DEBUG"touchkey:%s, wakelock active\n", __func__);
  1527. return size;
  1528. }
  1529. ret = sscanf(buf, "%d", &data);
  1530. if (ret != 1) {
  1531. dev_err(&tkey_i2c->client->dev, "%s, %d err\n",
  1532. __func__, __LINE__);
  1533. return size;
  1534. }
  1535. if (data != 0 && data != 1) {
  1536. dev_err(&tkey_i2c->client->dev, "%s wrong cmd %x\n",
  1537. __func__, data);
  1538. return size;
  1539. }
  1540. #if !defined(TK_LED_DIRECT_CONTORL)
  1541. data = ledCmd[data];
  1542. if (!tkey_i2c->enabled) {
  1543. touchled_cmd_reversed = 1;
  1544. goto out;
  1545. }
  1546. ret = i2c_touchkey_write(tkey_i2c, KEYCODE_REG, (u8 *) &data, 1);
  1547. if (ret < 0) {
  1548. dev_err(&tkey_i2c->client->dev, "%s: Error turn on led %d\n",
  1549. __func__, ret);
  1550. touchled_cmd_reversed = 1;
  1551. goto out;
  1552. }
  1553. msleep(30);
  1554. #else
  1555. if (!tkey_i2c->enabled) {
  1556. touchled_cmd_reversed = 1;
  1557. goto out;
  1558. }
  1559. tkey_i2c->pdata->led_power_on(data);
  1560. #endif
  1561. out:
  1562. touchkey_led_status = data;
  1563. return size;
  1564. }
  1565. #if defined(TK_USE_4KEY)
  1566. static ssize_t touchkey_menu_show(struct device *dev,
  1567. struct device_attribute *attr, char *buf)
  1568. {
  1569. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1570. u8 data[18] = { 0, };
  1571. int ret;
  1572. dev_dbg(&tkey_i2c->client->dev, "called %s\n", __func__);
  1573. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 18);
  1574. dev_dbg(&tkey_i2c->client->dev, "called %s data[10] =%d,data[11] = %d\n", __func__,
  1575. data[10], data[11]);
  1576. menu_sensitivity = ((0x00FF & data[10]) << 8) | data[11];
  1577. return sprintf(buf, "%d\n", menu_sensitivity);
  1578. }
  1579. static ssize_t touchkey_home_show(struct device *dev,
  1580. struct device_attribute *attr, char *buf)
  1581. {
  1582. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1583. u8 data[18] = { 0, };
  1584. int ret;
  1585. dev_dbg(&tkey_i2c->client->dev, "called %s\n", __func__);
  1586. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 18);
  1587. dev_dbg(&tkey_i2c->client->dev, "called %s data[12] =%d,data[13] = %d\n", __func__,
  1588. data[12], data[13]);
  1589. home_sensitivity = ((0x00FF & data[12]) << 8) | data[13];
  1590. return sprintf(buf, "%d\n", home_sensitivity);
  1591. }
  1592. static ssize_t touchkey_back_show(struct device *dev,
  1593. struct device_attribute *attr, char *buf)
  1594. {
  1595. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1596. u8 data[18] = { 0, };
  1597. int ret;
  1598. dev_dbg(&tkey_i2c->client->dev, "called %s\n", __func__);
  1599. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 18);
  1600. dev_dbg(&tkey_i2c->client->dev, "called %s data[14] =%d,data[15] = %d\n", __func__,
  1601. data[14], data[15]);
  1602. back_sensitivity = ((0x00FF & data[14]) << 8) | data[15];
  1603. return sprintf(buf, "%d\n", back_sensitivity);
  1604. }
  1605. static ssize_t touchkey_search_show(struct device *dev,
  1606. struct device_attribute *attr, char *buf)
  1607. {
  1608. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1609. u8 data[18] = { 0, };
  1610. int ret;
  1611. dev_dbg(&tkey_i2c->client->dev, "called %s\n", __func__);
  1612. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 18);
  1613. dev_dbg(&tkey_i2c->client->dev, "called %s data[16] =%d,data[17] = %d\n", __func__,
  1614. data[16], data[17]);
  1615. search_sensitivity = ((0x00FF & data[16]) << 8) | data[17];
  1616. return sprintf(buf, "%d\n", search_sensitivity);
  1617. }
  1618. #else
  1619. static ssize_t touchkey_menu_show(struct device *dev,
  1620. struct device_attribute *attr, char *buf)
  1621. {
  1622. struct FAC_CMD cmd = {TK_CMD_READ_SENSITIVITY, 0, 0};
  1623. return touchkey_fac_read_data(dev, buf, &cmd);
  1624. }
  1625. static ssize_t touchkey_back_show(struct device *dev,
  1626. struct device_attribute *attr, char *buf)
  1627. {
  1628. struct FAC_CMD cmd = {TK_CMD_READ_SENSITIVITY, 1, 0};
  1629. return touchkey_fac_read_data(dev, buf, &cmd);
  1630. }
  1631. #endif
  1632. #if defined(TK_HAS_AUTOCAL)
  1633. static ssize_t autocalibration_enable(struct device *dev,
  1634. struct device_attribute *attr,
  1635. const char *buf, size_t size)
  1636. {
  1637. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1638. int data;
  1639. sscanf(buf, "%d\n", &data);
  1640. dev_dbg(&tkey_i2c->client->dev, "%s %d\n", __func__, data);
  1641. if (data == 1)
  1642. touchkey_autocalibration(tkey_i2c);
  1643. return size;
  1644. }
  1645. static ssize_t autocalibration_status(struct device *dev,
  1646. struct device_attribute *attr, char *buf)
  1647. {
  1648. u8 data[6];
  1649. int ret;
  1650. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1651. dev_dbg(&tkey_i2c->client->dev, "%s\n", __func__);
  1652. ret = i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 6);
  1653. if ((data[5] & TK_BIT_AUTOCAL))
  1654. return sprintf(buf, "Enabled\n");
  1655. else
  1656. return sprintf(buf, "Disabled\n");
  1657. }
  1658. #endif
  1659. #if defined(CONFIG_GLOVE_TOUCH)
  1660. static ssize_t glove_mode_enable(struct device *dev,
  1661. struct device_attribute *attr,
  1662. const char *buf, size_t size)
  1663. {
  1664. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1665. int data;
  1666. sscanf(buf, "%d\n", &data);
  1667. dev_dbg(&tkey_i2c->client->dev, "%s %d\n", __func__, data);
  1668. tkey_i2c->tsk_enable_glove_mode = data;
  1669. touchkey_glovemode(data);
  1670. return size;
  1671. }
  1672. #endif
  1673. #ifdef TKEY_FLIP_MODE
  1674. static ssize_t flip_cover_mode_enable(struct device *dev,
  1675. struct device_attribute *attr,
  1676. const char *buf, size_t size)
  1677. {
  1678. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1679. int flip_mode_on;
  1680. sscanf(buf, "%d\n", &flip_mode_on);
  1681. dev_info(&tkey_i2c->client->dev, "%s %d\n", __func__, flip_mode_on);
  1682. /* glove mode control */
  1683. if (flip_mode_on) {
  1684. touchkey_flip_cover(flip_mode_on);
  1685. } else {
  1686. #if defined(CONFIG_GLOVE_TOUCH)
  1687. if (tkey_i2c->tsk_enable_glove_mode) {
  1688. tkey_i2c->ic_mode = MODE_NORMAL;
  1689. touchkey_glovemode(1);
  1690. }
  1691. else
  1692. #endif
  1693. touchkey_flip_cover(0);
  1694. }
  1695. return size;
  1696. }
  1697. #endif
  1698. static ssize_t touch_sensitivity_control(struct device *dev,
  1699. struct device_attribute *attr,
  1700. const char *buf, size_t size)
  1701. {
  1702. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1703. unsigned char data = 0x40;
  1704. i2c_touchkey_write(tkey_i2c, KEYCODE_REG, &data, 1);
  1705. dev_dbg(&tkey_i2c->client->dev, "%s\n", __func__);
  1706. msleep(20);
  1707. return size;
  1708. }
  1709. static ssize_t set_touchkey_update_store(struct device *dev,
  1710. struct device_attribute *attr,
  1711. const char *buf, size_t size)
  1712. {
  1713. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1714. u8 fw_path;
  1715. switch(*buf) {
  1716. case 's':
  1717. case 'S':
  1718. fw_path = FW_BUILT_IN;
  1719. break;
  1720. case 'i':
  1721. case 'I':
  1722. fw_path = FW_IN_SDCARD;
  1723. break;
  1724. default:
  1725. return size;
  1726. }
  1727. touchkey_fw_update(tkey_i2c, fw_path, true);
  1728. msleep(3000);
  1729. cancel_work_sync(&tkey_i2c->update_work);
  1730. return size;
  1731. }
  1732. static ssize_t set_touchkey_firm_version_show(struct device *dev,
  1733. struct device_attribute *attr,
  1734. char *buf)
  1735. {
  1736. printk(KERN_DEBUG"touchkey:firm_ver_bin %0#4x\n", fw_ver_file);
  1737. return sprintf(buf, "%0#4x\n", fw_ver_file);
  1738. }
  1739. static ssize_t set_touchkey_firm_version_read_show(struct device *dev,
  1740. struct device_attribute
  1741. *attr, char *buf)
  1742. {
  1743. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1744. char data[3] = { 0, };
  1745. int count;
  1746. i2c_touchkey_read(tkey_i2c, KEYCODE_REG, data, 3);
  1747. count = sprintf(buf, "0x%02x\n", data[1]);
  1748. dev_info(&tkey_i2c->client->dev, "Touch_version_read 0x%02x\n", data[1]);
  1749. dev_info(&tkey_i2c->client->dev, "Module_version_read 0x%02x\n", data[2]);
  1750. return count;
  1751. }
  1752. static ssize_t set_touchkey_firm_status_show(struct device *dev,
  1753. struct device_attribute *attr,
  1754. char *buf)
  1755. {
  1756. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1757. int count = 0;
  1758. dev_info(&tkey_i2c->client->dev, "Touch_update_read: update_status %d\n",
  1759. tkey_i2c->update_status);
  1760. if (tkey_i2c->update_status == TK_UPDATE_PASS)
  1761. count = sprintf(buf, "PASS\n");
  1762. else if (tkey_i2c->update_status == TK_UPDATE_DOWN)
  1763. count = sprintf(buf, "Downloading\n");
  1764. else if (tkey_i2c->update_status == TK_UPDATE_FAIL)
  1765. count = sprintf(buf, "Fail\n");
  1766. return count;
  1767. }
  1768. #if defined(TOUCHKEY_BOOSTER)
  1769. static ssize_t touchkey_boost_level(struct device *dev,
  1770. struct device_attribute *attr, const char *buf,
  1771. size_t count)
  1772. {
  1773. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1774. unsigned int level;
  1775. sscanf(buf, "%d", &level);
  1776. if (level > 2) {
  1777. dev_err(dev, "err to set boost_level %d\n", level);
  1778. return count;
  1779. }
  1780. #ifdef TOUCHKEY_BOOSTER
  1781. tkey_i2c->dvfs_boost_mode = level;
  1782. #endif
  1783. dev_info(dev, "%s %d\n", __func__, level);
  1784. if (tkey_i2c->dvfs_boost_mode == TKEY_BOOSTER_LEVEL2) {
  1785. tkey_i2c->dvfs_freq = MIN_TOUCH_LIMIT_SECOND;
  1786. dev_info(dev,
  1787. "%s: boost_mode DUAL, dvfs_freq = %d\n",
  1788. __func__, tkey_i2c->dvfs_freq);
  1789. } else if (tkey_i2c->dvfs_boost_mode == TKEY_BOOSTER_LEVEL1) {
  1790. tkey_i2c->dvfs_freq = MIN_TOUCH_LIMIT;
  1791. dev_info(dev,
  1792. "%s: boost_mode SINGLE, dvfs_freq = %d\n",
  1793. __func__, tkey_i2c->dvfs_freq);
  1794. } else if (tkey_i2c->dvfs_boost_mode == TKEY_BOOSTER_DISABLE) {
  1795. touchkey_set_dvfs_off(tkey_i2c);
  1796. }
  1797. return count;
  1798. }
  1799. #endif
  1800. #if defined(TKEY_GRIP_MODE)
  1801. static ssize_t touchkey_grip_mode_show(struct device *dev,
  1802. struct device_attribute *attr,
  1803. char *buf)
  1804. {
  1805. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1806. return sprintf(buf, "%s\n", tkey_i2c->grip_mode ? "ON" : "OFF");
  1807. }
  1808. static ssize_t touchkey_grip_mode(struct device *dev,
  1809. struct device_attribute *attr, const char *buf,
  1810. size_t count)
  1811. {
  1812. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1813. int mode = 0;
  1814. mutex_lock(&tkey_i2c->lock);
  1815. sscanf(buf, "%d", &mode);
  1816. tkey_i2c->grip_mode = (mode == 1) ? true : false;
  1817. printk(KERN_DEBUG"touchkey:%s, grip_mode %d, enabled %d\n",
  1818. __func__, tkey_i2c->grip_mode, tkey_i2c->ic_mode);
  1819. if (tkey_i2c->pwr_flag == false)
  1820. touchkey_grip_mode_ctr(tkey_i2c);
  1821. else
  1822. printk(KERN_DEBUG"touchkey:pwr enabled, skip grip mode\n");
  1823. mutex_unlock(&tkey_i2c->lock);
  1824. return count;
  1825. }
  1826. #endif
  1827. #ifdef TK_KEYPAD_ENABLE
  1828. static ssize_t sec_keypad_enable_show(struct device *dev,
  1829. struct device_attribute *attr, char *buf)
  1830. {
  1831. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1832. return sprintf(buf, "%d\n", tkey_i2c->keypad_enable ? 1 : 0);
  1833. }
  1834. static ssize_t sec_keypad_enable_store(struct device *dev,
  1835. struct device_attribute *attr, const char *buf, size_t count)
  1836. {
  1837. struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev);
  1838. bool val;
  1839. if (sysfs_streq(buf, "0"))
  1840. val = false;
  1841. else if (sysfs_streq(buf, "1"))
  1842. val = true;
  1843. else
  1844. return -EINVAL;
  1845. tkey_i2c->keypad_enable = val;
  1846. //input_sync(tkey_i2c->input_dev);
  1847. return count;
  1848. }
  1849. #endif
  1850. static DEVICE_ATTR(brightness, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  1851. touchkey_led_control);
  1852. #ifdef TK_USE_RECENT
  1853. static DEVICE_ATTR(touchkey_recent, S_IRUGO | S_IWUSR | S_IWGRP,
  1854. touchkey_menu_show, NULL);
  1855. #else
  1856. static DEVICE_ATTR(touchkey_menu, S_IRUGO | S_IWUSR | S_IWGRP,
  1857. touchkey_menu_show, NULL);
  1858. #endif
  1859. static DEVICE_ATTR(touchkey_back, S_IRUGO | S_IWUSR | S_IWGRP,
  1860. touchkey_back_show, NULL);
  1861. #if defined(TK_USE_4KEY)
  1862. static DEVICE_ATTR(touchkey_home, S_IRUGO, touchkey_home_show, NULL);
  1863. static DEVICE_ATTR(touchkey_search, S_IRUGO, touchkey_search_show, NULL);
  1864. #endif
  1865. static DEVICE_ATTR(touch_sensitivity, S_IRUGO | S_IWUSR | S_IWGRP,
  1866. NULL, touch_sensitivity_control);
  1867. static DEVICE_ATTR(touchkey_firm_update, S_IRUGO | S_IWUSR | S_IWGRP,
  1868. NULL, set_touchkey_update_store);
  1869. static DEVICE_ATTR(touchkey_firm_update_status, S_IRUGO | S_IWUSR | S_IWGRP,
  1870. set_touchkey_firm_status_show, NULL);
  1871. static DEVICE_ATTR(touchkey_firm_version_phone, S_IRUGO | S_IWUSR | S_IWGRP,
  1872. set_touchkey_firm_version_show, NULL);
  1873. static DEVICE_ATTR(touchkey_firm_version_panel, S_IRUGO | S_IWUSR | S_IWGRP,
  1874. set_touchkey_firm_version_read_show, NULL);
  1875. #ifdef LED_LDO_WITH_REGULATOR
  1876. static DEVICE_ATTR(touchkey_brightness, S_IRUGO | S_IWUSR | S_IWGRP,
  1877. NULL, brightness_control);
  1878. #endif
  1879. #if defined(TK_HAS_AUTOCAL)
  1880. #ifdef TK_USE_RECENT
  1881. static DEVICE_ATTR(touchkey_recent_raw, S_IRUGO, touchkey_raw_data0_show, NULL);
  1882. static DEVICE_ATTR(touchkey_back_raw, S_IRUGO, touchkey_raw_data1_show, NULL);
  1883. static DEVICE_ATTR(touchkey_recent_idac, S_IRUGO, touchkey_idac0_show, NULL);
  1884. static DEVICE_ATTR(touchkey_back_idac, S_IRUGO, touchkey_idac1_show, NULL);
  1885. #else
  1886. static DEVICE_ATTR(touchkey_raw_data0, S_IRUGO, touchkey_raw_data0_show, NULL);
  1887. static DEVICE_ATTR(touchkey_raw_data1, S_IRUGO, touchkey_raw_data1_show, NULL);
  1888. static DEVICE_ATTR(touchkey_raw_data2, S_IRUGO, touchkey_raw_data2_show, NULL);
  1889. static DEVICE_ATTR(touchkey_raw_data3, S_IRUGO, touchkey_raw_data3_show, NULL);
  1890. static DEVICE_ATTR(touchkey_idac0, S_IRUGO, touchkey_idac0_show, NULL);
  1891. static DEVICE_ATTR(touchkey_idac1, S_IRUGO, touchkey_idac1_show, NULL);
  1892. static DEVICE_ATTR(touchkey_idac2, S_IRUGO, touchkey_idac2_show, NULL);
  1893. static DEVICE_ATTR(touchkey_idac3, S_IRUGO, touchkey_idac3_show, NULL);
  1894. #endif
  1895. static DEVICE_ATTR(touchkey_threshold, S_IRUGO, touchkey_threshold_show, NULL);
  1896. static DEVICE_ATTR(autocal_enable, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  1897. autocalibration_enable);
  1898. static DEVICE_ATTR(autocal_stat, S_IRUGO | S_IWUSR | S_IWGRP,
  1899. autocalibration_status, NULL);
  1900. #endif
  1901. #if defined(CONFIG_GLOVE_TOUCH)
  1902. static DEVICE_ATTR(glove_mode, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  1903. glove_mode_enable);
  1904. #endif
  1905. #ifdef TKEY_FLIP_MODE
  1906. static DEVICE_ATTR(flip_mode, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
  1907. flip_cover_mode_enable);
  1908. #endif
  1909. #if defined(TOUCHKEY_BOOSTER)
  1910. static DEVICE_ATTR(boost_level, S_IWUSR | S_IWGRP, NULL, touchkey_boost_level);
  1911. #endif
  1912. #ifdef TK_KEYPAD_ENABLE
  1913. static DEVICE_ATTR(keypad_enable, S_IRUGO | S_IWUSR | S_IWGRP,
  1914. sec_keypad_enable_show, sec_keypad_enable_store);
  1915. #endif
  1916. #ifdef TKEY_GRIP_MODE
  1917. static DEVICE_ATTR(grip_mode, S_IRUGO | S_IWUSR | S_IWGRP, touchkey_grip_mode_show,
  1918. touchkey_grip_mode);
  1919. #endif
  1920. static struct attribute *touchkey_attributes[] = {
  1921. &dev_attr_brightness.attr,
  1922. #ifdef TK_USE_RECENT
  1923. &dev_attr_touchkey_recent.attr,
  1924. #else
  1925. &dev_attr_touchkey_menu.attr,
  1926. #endif
  1927. &dev_attr_touchkey_back.attr,
  1928. #if defined(TK_USE_4KEY)
  1929. &dev_attr_touchkey_home.attr,
  1930. &dev_attr_touchkey_search.attr,
  1931. #endif
  1932. &dev_attr_touch_sensitivity.attr,
  1933. &dev_attr_touchkey_firm_update.attr,
  1934. &dev_attr_touchkey_firm_update_status.attr,
  1935. &dev_attr_touchkey_firm_version_phone.attr,
  1936. &dev_attr_touchkey_firm_version_panel.attr,
  1937. #ifdef LED_LDO_WITH_REGULATOR
  1938. &dev_attr_touchkey_brightness.attr,
  1939. #endif
  1940. #if defined(TK_HAS_AUTOCAL)
  1941. #ifdef TK_USE_RECENT
  1942. &dev_attr_touchkey_recent_raw.attr,
  1943. &dev_attr_touchkey_back_raw.attr,
  1944. &dev_attr_touchkey_recent_idac.attr,
  1945. &dev_attr_touchkey_back_idac.attr,
  1946. #else
  1947. &dev_attr_touchkey_raw_data0.attr,
  1948. &dev_attr_touchkey_raw_data1.attr,
  1949. &dev_attr_touchkey_raw_data2.attr,
  1950. &dev_attr_touchkey_raw_data3.attr,
  1951. &dev_attr_touchkey_idac0.attr,
  1952. &dev_attr_touchkey_idac1.attr,
  1953. &dev_attr_touchkey_idac2.attr,
  1954. &dev_attr_touchkey_idac3.attr,
  1955. #endif
  1956. &dev_attr_touchkey_threshold.attr,
  1957. &dev_attr_autocal_enable.attr,
  1958. &dev_attr_autocal_stat.attr,
  1959. #endif
  1960. #if defined(CONFIG_GLOVE_TOUCH)
  1961. &dev_attr_glove_mode.attr,
  1962. #endif
  1963. #ifdef TKEY_FLIP_MODE
  1964. &dev_attr_flip_mode.attr,
  1965. #endif
  1966. #if defined(TOUCHKEY_BOOSTER)
  1967. &dev_attr_boost_level.attr,
  1968. #endif
  1969. #ifdef TKEY_GRIP_MODE
  1970. &dev_attr_grip_mode.attr,
  1971. #endif
  1972. #ifdef TK_KEYPAD_ENABLE
  1973. &dev_attr_keypad_enable.attr,
  1974. #endif
  1975. NULL,
  1976. };
  1977. static struct attribute_group touchkey_attr_group = {
  1978. .attrs = touchkey_attributes,
  1979. };
  1980. static void touchkey_init_hw(void)
  1981. {
  1982. printk(KERN_ERR "%s, %d\n", __func__, __LINE__);
  1983. #ifndef TK_USE_LDO_CONTROL
  1984. gpio_direction_output(tkey_gpio_i2cldo, 0);
  1985. #else
  1986. cypress_ldo_onoff(0);
  1987. #endif
  1988. gpio_tlmm_config(GPIO_CFG(tkey_gpio_int, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1989. #ifdef GPIO_2TOUCH_RST
  1990. gpio_direction_output(tkey_gpio_rst, 0);
  1991. #endif
  1992. #ifdef GPIO_2_TOUCH_ID
  1993. gpio_tlmm_config(GPIO_CFG(tkey_gpio_id, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1994. #endif
  1995. gpio_tlmm_config(GPIO_CFG(tkey_gpio_scl, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), 1);
  1996. gpio_tlmm_config(GPIO_CFG(tkey_gpio_sda, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), 1);
  1997. }
  1998. static int touchkey_suspend(void)
  1999. {
  2000. #ifndef TK_USE_LDO_CONTROL
  2001. gpio_direction_output(tkey_gpio_i2cldo, 0);
  2002. #else
  2003. cypress_ldo_onoff(0);
  2004. #endif
  2005. return 1;
  2006. }
  2007. static int touchkey_resume(void)
  2008. {
  2009. #ifndef TK_USE_LDO_CONTROL
  2010. gpio_direction_output(tkey_gpio_i2cldo, 1);
  2011. #else
  2012. cypress_ldo_onoff(1);
  2013. #endif
  2014. return 1;
  2015. }
  2016. static int touchkey_power_on(bool on)
  2017. {
  2018. int ret;
  2019. printk(KERN_ERR "%s, on=%d %d\n", __func__,on, __LINE__);
  2020. if (on) {
  2021. gpio_direction_input(tkey_gpio_int);
  2022. irq_set_irq_type(gpio_to_irq(tkey_gpio_int), IRQF_TRIGGER_FALLING);
  2023. gpio_tlmm_config(GPIO_CFG(tkey_gpio_int, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  2024. } else {
  2025. gpio_direction_input(tkey_gpio_int);
  2026. #ifdef GPIO_2TOUCH_RST
  2027. gpio_direction_output(tkey_gpio_rst, 0);
  2028. #endif
  2029. }
  2030. if (on)
  2031. ret = touchkey_resume();
  2032. else
  2033. ret = touchkey_suspend();
  2034. return ret;
  2035. }
  2036. #if defined(TK_USE_MAX_SUBPM_CONTROL)
  2037. static int cypress_vdd_onoff(bool on, int led) // led 3.3V is 1.
  2038. {
  2039. int retval;
  2040. if(on){
  2041. if (regulator_is_enabled(cyp_supplies[led].consumer)) {
  2042. pr_err("%s: %s is already enabled\n", __func__, cyp_supplies[led].supply);
  2043. }else {
  2044. retval = regulator_enable(cyp_supplies[led].consumer);
  2045. if (retval) {
  2046. pr_err("%s: Fail to enable regulator %s (%d)\n", __func__, cyp_supplies[led].supply, retval);
  2047. }
  2048. pr_err("%s: %s is enabled[OK]\n", __func__, cyp_supplies[led].supply);
  2049. }
  2050. }else{
  2051. if (regulator_is_enabled(cyp_supplies[led].consumer)) {
  2052. retval = regulator_disable(cyp_supplies[led].consumer);
  2053. if (retval) {
  2054. pr_err("%s: Fail to disable regulator %s (%d)\n", __func__, cyp_supplies[led].supply, retval);
  2055. }
  2056. pr_err("%s: %s is disabled[OK]\n", __func__, cyp_supplies[led].supply);
  2057. }else {
  2058. pr_err("%s: %s is already disabled\n", __func__, cyp_supplies[led].supply);
  2059. }
  2060. }
  2061. return 1;
  2062. }
  2063. static int cypress_ldo_onoff(bool on)
  2064. {
  2065. pr_err("%s: on:%d\n", __func__, on);
  2066. cypress_vdd_onoff(on, CYP_IC);
  2067. return 1;
  2068. }
  2069. static int touchkey_led_power_on(bool on)
  2070. {
  2071. pr_err("%s: on:%d\n", __func__, on);
  2072. cypress_vdd_onoff(on, CYP_LED);
  2073. return 1;
  2074. }
  2075. #elif !defined(TK_USE_LDO_CONTROL)
  2076. static int touchkey_led_power_on(bool on)
  2077. {
  2078. printk(KERN_ERR "%s, on:%d %d\n", __func__,on, __LINE__);
  2079. if (on)
  2080. gpio_direction_output(tkey_gpio_vddldo, 1);
  2081. else
  2082. gpio_direction_output(tkey_gpio_vddldo, 0);
  2083. return 1;
  2084. }
  2085. #else
  2086. static int cypress_ldo_onoff(bool on)
  2087. {
  2088. int rc = 0;
  2089. static struct regulator *tkey_regulator;
  2090. printk(KERN_ERR "%s, on:%d %d\n", __func__,on, __LINE__);
  2091. if(!tkey_regulator){
  2092. tkey_regulator = regulator_get(NULL, TKEY_I2C_REGULATOR);
  2093. if (IS_ERR(tkey_regulator)) {
  2094. pr_err("%s: failed to get resource %s\n", __func__,
  2095. "touchkey_ldo");
  2096. return 1;
  2097. }
  2098. }
  2099. if (on) {
  2100. if(tkey_regulator){
  2101. if (!regulator_is_enabled(tkey_regulator)) {
  2102. rc = regulator_enable(tkey_regulator);
  2103. if (rc) {
  2104. pr_err("Regulator vcc_en enable failed rc=%d\n",rc);
  2105. return 1;
  2106. }
  2107. }
  2108. }
  2109. } else {
  2110. if(tkey_regulator){
  2111. if (regulator_is_enabled(tkey_regulator)) {
  2112. rc = regulator_disable(tkey_regulator);
  2113. if (rc) {
  2114. pr_err("Regulator vcc_en disable failed rc=%d\n",rc);
  2115. return 1;
  2116. }
  2117. }
  2118. }
  2119. }
  2120. return 1;
  2121. }
  2122. static int touchkey_led_power_on(bool on)
  2123. {
  2124. int rc = 0;
  2125. static struct regulator *tkey_led_regulator;
  2126. printk(KERN_ERR "%s, on:%d %d\n", __func__,on, __LINE__);
  2127. if(!tkey_led_regulator){
  2128. tkey_led_regulator = regulator_get(NULL, TKEY_LED_REGULATOR);
  2129. if (IS_ERR(tkey_led_regulator)) {
  2130. pr_err("%s: failed to get resource %s\n", __func__,
  2131. "touchkey_led_ldo");
  2132. return 1;
  2133. }
  2134. rc = regulator_set_voltage(tkey_led_regulator, 3300000, 3300000);
  2135. if (rc) {
  2136. pr_err("%s: regulator(vdd_led) set_vtg failed %s\n", __func__,
  2137. "touchkey_led_ldo");
  2138. return 1;
  2139. }
  2140. }
  2141. if (on) {
  2142. if(tkey_led_regulator){
  2143. if (!regulator_is_enabled(tkey_led_regulator)) {
  2144. rc = regulator_enable(tkey_led_regulator);
  2145. if (rc) {
  2146. pr_err("Regulator Tkey_LED enable failed rc=%d\n",rc);
  2147. return 1;
  2148. }
  2149. }
  2150. }
  2151. } else {
  2152. if(tkey_led_regulator){
  2153. if (regulator_is_enabled(tkey_led_regulator)) {
  2154. rc = regulator_disable(tkey_led_regulator);
  2155. if (rc) {
  2156. pr_err("Regulator Tkey_LED disable failed rc=%d\n",rc);
  2157. return 1;
  2158. }
  2159. }
  2160. }
  2161. }
  2162. return 1;
  2163. }
  2164. #endif
  2165. #ifdef GPIO_2TOUCH_RST
  2166. static int touchkey_rst_reset(void)
  2167. {
  2168. printk(KERN_ERR "%s, %d\n", __func__, __LINE__);
  2169. gpio_direction_output(tkey_gpio_rst, 1);
  2170. usleep(1000);
  2171. gpio_direction_output(tkey_gpio_rst, 0);
  2172. return 0;
  2173. }
  2174. #endif
  2175. static void cypress_request_gpio(struct touchkey_platform_data *pdata)
  2176. {
  2177. int ret;
  2178. printk(KERN_ERR "%s, %d\n", __func__, __LINE__);
  2179. ret = gpio_request(pdata->gpio_int, "touchkey_irq");
  2180. if (ret) {
  2181. printk(KERN_ERR "%s: unable to request touchkey_irq [%d]\n", __func__, pdata->gpio_int);
  2182. }
  2183. #ifdef GPIO_2_TOUCH_ID
  2184. if (pdata->gpio_id > 0) {
  2185. ret = gpio_request(pdata->gpio_id, "gpio_id");
  2186. if (ret) {
  2187. printk(KERN_ERR "%s: unable to request gpio_id[%d]\n", __func__, pdata->gpio_id);
  2188. }
  2189. }
  2190. #endif
  2191. #ifndef TK_USE_LDO_CONTROL
  2192. if (tkey_gpio_i2cldo > 0) {
  2193. ret = gpio_request(tkey_gpio_i2cldo, "tkey_gpio_i2cldo");
  2194. if (ret) {
  2195. printk(KERN_ERR "%s: unable to request tkey_gpio_i2cldo [%d]\n", __func__, tkey_gpio_i2cldo);
  2196. }
  2197. }
  2198. if (tkey_gpio_vddldo > 0) {
  2199. ret = gpio_request(tkey_gpio_vddldo, "tkey_gpio_vddldo");
  2200. if (ret) {
  2201. printk(KERN_ERR "%s: unable to request tkey_gpio_vddldo [%d]\n", __func__, tkey_gpio_vddldo);
  2202. }
  2203. }
  2204. #endif
  2205. #ifdef GPIO_2TOUCH_RST
  2206. if (pdata->gpio_rst > 0) {
  2207. ret = gpio_request(pdata->gpio_rst, "gpio_rst");
  2208. if (ret) {
  2209. printk(KERN_ERR "%s: unable to request gpio_rst [%d]\n", __func__, pdata->gpio_rst);
  2210. }
  2211. }
  2212. #endif
  2213. #ifdef TKEY_GRIP_MODE
  2214. if (pdata->gpio_grip > 0) {
  2215. ret = gpio_request(pdata->gpio_grip, "gpio_grip");
  2216. if (ret) {
  2217. printk(KERN_ERR "%s: unable to request gpio_grip [%d]\n", __func__, pdata->gpio_grip);
  2218. }
  2219. }
  2220. #endif
  2221. }
  2222. #ifdef CONFIG_OF
  2223. static int cypress_parse_dt(struct device *dev,
  2224. struct touchkey_platform_data *pdata)
  2225. {
  2226. struct device_node *np = dev->of_node;
  2227. printk(KERN_ERR "%s, %d\n", __func__, __LINE__);
  2228. #ifndef TK_USE_LDO_CONTROL
  2229. tkey_gpio_i2cldo = of_get_named_gpio(np, "cypress,touchkey_i2cldo-gpio", 0);
  2230. tkey_gpio_vddldo = of_get_named_gpio(np, "cypress,touchkey_vddldo-gpio", 0);
  2231. #endif
  2232. /* reset, irq gpio info */
  2233. pdata->gpio_scl = of_get_named_gpio(np, "cypress,scl-gpio", 0);
  2234. pdata->gpio_sda = of_get_named_gpio(np, "cypress,sda-gpio", 0);
  2235. pdata->gpio_int = of_get_named_gpio(np, "cypress,irq-gpio", 0);
  2236. tkey_gpio_sda = pdata->gpio_sda;
  2237. tkey_gpio_scl = pdata->gpio_scl;
  2238. tkey_gpio_int = pdata->gpio_int;
  2239. #ifdef GPIO_2_TOUCH_ID
  2240. pdata->gpio_id = of_get_named_gpio(np, "cypress,twotouch_id-gpio", 0);
  2241. tkey_gpio_id = pdata->gpio_id;
  2242. #endif
  2243. #ifdef GPIO_2TOUCH_RST
  2244. pdata->gpio_rst = of_get_named_gpio(np, "cypress,twotouch_rst-gpio", 0);
  2245. tkey_gpio_rst = pdata->gpio_rst;
  2246. #endif
  2247. #ifdef TKEY_GRIP_MODE
  2248. pdata->gpio_grip = of_get_named_gpio(np, "cypress,twotouch_grip-gpio", 0);
  2249. tkey_gpio_grip = pdata->gpio_grip;
  2250. #endif
  2251. #if defined(TK_USE_MAX_SUBPM_CONTROL)
  2252. {
  2253. int rc;
  2254. pdata->name_of_supply = kzalloc(sizeof(char *) * 2, GFP_KERNEL);
  2255. rc = of_property_read_string_index(np, "cypress,supply-name", 0, &pdata->name_of_supply[0]);
  2256. if (rc && (rc != -EINVAL)) {
  2257. printk(KERN_INFO "%s: Unable to read %s\n", __func__,"cypress,supply-name 0");
  2258. return rc;
  2259. }
  2260. rc = of_property_read_string_index(np, "cypress,supply-name", 1, &pdata->name_of_supply[1]);
  2261. if (rc && (rc != -EINVAL)) {
  2262. printk(KERN_INFO "%s: Unable to read %s\n", __func__,"cypress,supply-name 1");
  2263. return rc;
  2264. }
  2265. dev_info(dev, "%s: supply: %s, %s\n", __func__, pdata->name_of_supply[0],pdata->name_of_supply[1]);
  2266. }
  2267. #endif
  2268. #if defined(CONFIG_SEC_S_PROJECT)
  2269. touchkey_keycode[1] = KEY_RECENT;
  2270. #endif
  2271. return 0;
  2272. }
  2273. #endif
  2274. static int i2c_touchkey_probe(struct i2c_client *client,
  2275. const struct i2c_device_id *id)
  2276. {
  2277. struct touchkey_platform_data *pdata;
  2278. struct touchkey_i2c *tkey_i2c;
  2279. #if defined(CONFIG_KEYBOARD_CYPRESS_TKEY_HL)
  2280. bool bforced = false;
  2281. #endif
  2282. struct input_dev *input_dev;
  2283. int i;
  2284. int ret = 0;
  2285. int error = 0;
  2286. /*Check I2C functionality */
  2287. ret = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
  2288. if (ret == 0) {
  2289. dev_err(&client->dev, "No I2C functionality found\n");
  2290. return -ENODEV;
  2291. }
  2292. #ifdef CONFIG_OF
  2293. if (client->dev.of_node) {
  2294. dev_err(&client->dev, "%s, config of, %d\n", __func__, __LINE__);
  2295. pdata = devm_kzalloc(&client->dev,
  2296. sizeof(struct touchkey_platform_data),
  2297. GFP_KERNEL);
  2298. if (!pdata) {
  2299. dev_info(&client->dev, "Failed to allocate memory\n");
  2300. return -ENOMEM;
  2301. }
  2302. error = cypress_parse_dt(&client->dev, pdata);
  2303. if (error)
  2304. return error;
  2305. } else{
  2306. pdata = client->dev.platform_data;
  2307. dev_err(&client->dev, "undefined config of\n");
  2308. }
  2309. cypress_request_gpio(pdata);
  2310. pdata->init_platform_hw = touchkey_init_hw;
  2311. pdata->suspend = touchkey_suspend;
  2312. pdata->resume = touchkey_resume;
  2313. pdata->power_on = touchkey_power_on;
  2314. pdata->led_power_on = touchkey_led_power_on;
  2315. #ifdef GPIO_2TOUCH_RST
  2316. pdata->rst_reset = touchkey_rst_reset;
  2317. #endif
  2318. #if defined(TK_USE_MAX_SUBPM_CONTROL)
  2319. cyp_supplies = kzalloc(sizeof(struct regulator_bulk_data) * 2, GFP_KERNEL);
  2320. if (!cyp_supplies) {
  2321. pr_err("%s: Failed to alloc mem for supplies\n", __func__);
  2322. return -ENOMEM;
  2323. }
  2324. cyp_supplies[0].supply = pdata->name_of_supply[0]; // 1.8V, IC
  2325. cyp_supplies[1].supply = pdata->name_of_supply[1]; // 3.3V, LED
  2326. ret = regulator_bulk_get(&client->dev, 2, cyp_supplies);
  2327. if (ret)
  2328. goto err_get_regulator;
  2329. ret = regulator_set_voltage(cyp_supplies[CYP_IC].consumer,1950000, 1950000);
  2330. if (ret) pr_err("%s, 1.8 set_vtg failed rc=%d\n", __func__, ret);
  2331. ret = regulator_set_voltage(cyp_supplies[CYP_LED].consumer,3300000, 3300000);
  2332. if (ret) pr_err("%s, 3.3 set_vtg failed rc=%d\n", __func__, ret);
  2333. pr_err("%s: Max77826 supplies was seted \n", __func__);
  2334. #endif
  2335. touchkey_init_hw();
  2336. client->irq = gpio_to_irq(tkey_gpio_int);
  2337. irq_set_irq_type(gpio_to_irq(tkey_gpio_int), IRQF_TRIGGER_FALLING);
  2338. #endif
  2339. /*Obtain kernel memory space for touchkey i2c */
  2340. tkey_i2c = kzalloc(sizeof(struct touchkey_i2c), GFP_KERNEL);
  2341. if (NULL == tkey_i2c) {
  2342. dev_err(&client->dev, "Failed to allocate memory\n");
  2343. return -ENOMEM;
  2344. }
  2345. #ifdef CONFIG_GLOVE_TOUCH
  2346. tkey_i2c_global = tkey_i2c;
  2347. #endif
  2348. input_dev = input_allocate_device();
  2349. if (!input_dev) {
  2350. dev_err(&client->dev, "Failed to allocate input device\n");
  2351. ret = -ENOMEM;
  2352. goto err_allocate_input_device;
  2353. }
  2354. input_dev->name = "sec_touchkey";
  2355. input_dev->phys = "sec_touchkey/input0";
  2356. input_dev->id.bustype = BUS_HOST;
  2357. input_dev->dev.parent = &client->dev;
  2358. input_dev->open = touchkey_input_open;
  2359. input_dev->close = touchkey_input_close;
  2360. /*tkey_i2c*/
  2361. tkey_i2c->pdata = pdata;
  2362. tkey_i2c->input_dev = input_dev;
  2363. tkey_i2c->client = client;
  2364. tkey_i2c->irq = client->irq;
  2365. tkey_i2c->name = "sec_touchkey";
  2366. tkey_i2c->status_update = false;
  2367. #ifdef TKEY_GRIP_MODE
  2368. tkey_i2c->grip_mode = false;
  2369. tkey_i2c->ic_mode = MODE_NORMAL;
  2370. mutex_init(&tkey_i2c->grip_mode_lock);
  2371. #endif
  2372. // init_completion(&tkey_i2c->init_done);
  2373. mutex_init(&tkey_i2c->lock);
  2374. mutex_init(&tkey_i2c->i2c_lock);
  2375. mutex_init(&tkey_i2c->irq_lock);
  2376. #ifdef TK_USE_OPEN_DWORK
  2377. INIT_DELAYED_WORK(&tkey_i2c->open_work, touchkey_open_work);
  2378. #endif
  2379. set_bit(EV_SYN, input_dev->evbit);
  2380. set_bit(EV_LED, input_dev->evbit);
  2381. set_bit(LED_MISC, input_dev->ledbit);
  2382. set_bit(EV_KEY, input_dev->evbit);
  2383. #ifdef CONFIG_VT_TKEY_SKIP_MATCH
  2384. set_bit(EV_TOUCHKEY, input_dev->evbit);
  2385. #endif
  2386. INIT_WORK(&tkey_i2c->update_work, touchkey_i2c_update_work);
  2387. wake_lock_init(&tkey_i2c->fw_wakelock, WAKE_LOCK_SUSPEND, "touchkey");
  2388. for (i = 1; i < touchkey_count; i++)
  2389. set_bit(touchkey_keycode[i], input_dev->keybit);
  2390. input_set_drvdata(input_dev, tkey_i2c);
  2391. i2c_set_clientdata(client, tkey_i2c);
  2392. ret = input_register_device(input_dev);
  2393. if (ret) {
  2394. dev_err(&client->dev, "Failed to register input device\n");
  2395. goto err_register_device;
  2396. }
  2397. tkey_i2c->pdata->power_on(1);
  2398. #ifdef TKEY_GRIP_MODE
  2399. tkey_i2c->pwr_flag = true;
  2400. #endif
  2401. msleep(300);//50
  2402. tkey_i2c->enabled = true;
  2403. #ifdef TK_KEYPAD_ENABLE
  2404. tkey_i2c->keypad_enable = true;
  2405. #endif
  2406. ret = touchkey_i2c_check(tkey_i2c);
  2407. if (ret < 0) {
  2408. dev_err(&client->dev, "i2c_check failed\n");
  2409. #if defined(CONFIG_KEYBOARD_CYPRESS_TKEY_HL)
  2410. bforced = true;
  2411. #else
  2412. goto err_i2c_check;
  2413. #endif
  2414. }
  2415. /*sysfs*/
  2416. tkey_i2c->dev = device_create(sec_class, NULL, 0, NULL, "sec_touchkey");
  2417. ret = IS_ERR(tkey_i2c->dev);
  2418. if (ret) {
  2419. dev_err(&client->dev, "Failed to create device(tkey_i2c->dev)!\n");
  2420. goto err_device_create;
  2421. }
  2422. dev_set_drvdata(tkey_i2c->dev, tkey_i2c);
  2423. ret = sysfs_create_group(&tkey_i2c->dev->kobj,
  2424. &touchkey_attr_group);
  2425. if (ret) {
  2426. dev_err(&client->dev, "Failed to create sysfs group\n");
  2427. goto err_sysfs_init;
  2428. }
  2429. ret = sysfs_create_link(&tkey_i2c->dev->kobj,
  2430. &tkey_i2c->input_dev->dev.kobj, "input");
  2431. if (ret) {
  2432. dev_err(&client->dev, "Failed to connect link\n");
  2433. goto err_create_symlink;
  2434. }
  2435. tkey_i2c->fw_wq = create_singlethread_workqueue(client->name);
  2436. if (!tkey_i2c->fw_wq) {
  2437. dev_err(&client->dev, "fail to create workqueue for fw_wq\n");
  2438. ret = -ENOMEM;
  2439. goto err_create_fw_wq;
  2440. }
  2441. #ifdef TOUCHKEY_BOOSTER
  2442. touchkey_init_dvfs(tkey_i2c);
  2443. #endif
  2444. #if defined(CONFIG_GLOVE_TOUCH)
  2445. mutex_init(&tkey_i2c->tsk_glove_lock);
  2446. INIT_WORK(&tkey_i2c->glove_change_work, touchkey_glove_change_work);
  2447. #endif
  2448. ret =
  2449. request_threaded_irq(tkey_i2c->irq, NULL, touchkey_interrupt,
  2450. IRQF_DISABLED | IRQF_TRIGGER_FALLING |
  2451. IRQF_ONESHOT, tkey_i2c->name, tkey_i2c);
  2452. if (ret < 0) {
  2453. dev_err(&client->dev, "Failed to request irq(%d) - %d\n",
  2454. tkey_i2c->irq, ret);
  2455. goto err_request_threaded_irq;
  2456. }
  2457. tkey_i2c->pdata->led_power_on(1);
  2458. #if defined(TK_HAS_FIRMWARE_UPDATE)
  2459. /*tkey_firmupdate_retry_byreboot:*/
  2460. if (system_rev >= TK_UPDATABLE_BD_ID) {
  2461. touchkey_fw_update(tkey_i2c, FW_BUILT_IN, bforced);
  2462. }
  2463. #endif
  2464. #if defined(TK_INFORM_CHARGER)
  2465. tkey_i2c->pdata->register_cb = touchkey_register_callback;
  2466. tkey_i2c->callbacks.inform_charger = touchkey_ta_cb;
  2467. if (tkey_i2c->pdata->register_cb) {
  2468. dev_info(&client->dev, "Touchkey TA information\n");
  2469. tkey_i2c->pdata->register_cb(&tkey_i2c->callbacks);
  2470. }
  2471. #endif
  2472. #ifdef CONFIG_HAS_EARLYSUSPEND
  2473. tkey_i2c->early_suspend.suspend =
  2474. (void *)sec_touchkey_early_suspend;
  2475. tkey_i2c->early_suspend.resume =
  2476. (void *)sec_touchkey_late_resume;
  2477. register_early_suspend(&tkey_i2c->early_suspend);
  2478. #endif
  2479. /* touchkey_stop(tkey_i2c); */
  2480. // complete_all(&tkey_i2c->init_done);
  2481. touchkey_probe = true;
  2482. return 0;
  2483. #if defined(TK_HAS_FIRMWARE_UPDATE)
  2484. /*err_firmware_update:*/
  2485. tkey_i2c->pdata->led_power_on(0);
  2486. touchkey_enable_irq(tkey_i2c, false);
  2487. free_irq(tkey_i2c->irq, tkey_i2c);
  2488. #endif
  2489. err_request_threaded_irq:
  2490. #ifdef CONFIG_GLOVE_TOUCH
  2491. mutex_destroy(&tkey_i2c->tsk_glove_lock);
  2492. #endif
  2493. #ifdef TOUCHKEY_BOOSTER
  2494. mutex_destroy(&tkey_i2c->dvfs_lock);
  2495. #endif
  2496. destroy_workqueue(tkey_i2c->fw_wq);
  2497. err_create_fw_wq:
  2498. sysfs_delete_link(&tkey_i2c->dev->kobj,
  2499. &tkey_i2c->input_dev->dev.kobj, "input");
  2500. err_create_symlink:
  2501. sysfs_remove_group(&tkey_i2c->dev->kobj, &touchkey_attr_group);
  2502. err_sysfs_init:
  2503. device_destroy(sec_class, (dev_t)NULL);
  2504. err_device_create:
  2505. #if !defined(CONFIG_KEYBOARD_CYPRESS_TKEY_HL)
  2506. err_i2c_check:
  2507. #endif
  2508. tkey_i2c->pdata->power_on(0);
  2509. input_unregister_device(input_dev);
  2510. input_dev = NULL;
  2511. err_register_device:
  2512. wake_lock_destroy(&tkey_i2c->fw_wakelock);
  2513. mutex_destroy(&tkey_i2c->irq_lock);
  2514. mutex_destroy(&tkey_i2c->i2c_lock);
  2515. mutex_destroy(&tkey_i2c->lock);
  2516. #ifdef TKEY_GRIP_MODE
  2517. mutex_destroy(&tkey_i2c->grip_mode_lock);
  2518. #endif
  2519. if(input_dev)
  2520. input_free_device(input_dev);
  2521. err_allocate_input_device:
  2522. kfree(tkey_i2c);
  2523. #if defined(TK_USE_MAX_SUBPM_CONTROL)
  2524. err_get_regulator:
  2525. kfree(cyp_supplies);
  2526. #endif
  2527. return ret;
  2528. }
  2529. void touchkey_shutdown(struct i2c_client *client)
  2530. {
  2531. struct touchkey_i2c *tkey_i2c = i2c_get_clientdata(client);
  2532. touchkey_stop(tkey_i2c);
  2533. printk(KERN_DEBUG"touchkey:%s\n", __func__);
  2534. }
  2535. #ifdef CONFIG_OF
  2536. static struct of_device_id cypress_match_table[] = {
  2537. { .compatible = "cypress,cypress-tkey",},
  2538. { },
  2539. };
  2540. #else
  2541. #define cypress_match_table NULL
  2542. #endif
  2543. struct i2c_driver touchkey_i2c_driver = {
  2544. .driver = {
  2545. .name = "cypress_touchkey", //"sec_touchkey",
  2546. .owner = THIS_MODULE,
  2547. #ifdef CONFIG_OF
  2548. .of_match_table = cypress_match_table,
  2549. #endif
  2550. #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND) && !defined(USE_OPEN_CLOSE)
  2551. .pm = &touchkey_pm_ops,
  2552. #endif
  2553. },
  2554. .id_table = sec_touchkey_id,
  2555. .probe = i2c_touchkey_probe,
  2556. .shutdown = &touchkey_shutdown,
  2557. };
  2558. static int __init touchkey_init(void)
  2559. {
  2560. #ifdef TEST_JIG_MODE
  2561. unsigned char get_touch = 0x40;
  2562. #endif
  2563. #ifdef CONFIG_SAMSUNG_LPM_MODE
  2564. extern int poweroff_charging;
  2565. if (poweroff_charging) {
  2566. printk(KERN_ERR "%s : LPM Charging Mode!!\n", __func__);
  2567. return 0;
  2568. }
  2569. #endif
  2570. i2c_add_driver(&touchkey_i2c_driver);
  2571. #ifdef TEST_JIG_MODE
  2572. i2c_touchkey_write(tkey_i2c, KEYCODE_REG, &get_touch, 1);
  2573. #endif
  2574. printk(KERN_ERR "%s: init done %d\n", __func__, __LINE__);
  2575. return 0;
  2576. }
  2577. static void __exit touchkey_exit(void)
  2578. {
  2579. i2c_del_driver(&touchkey_i2c_driver);
  2580. touchkey_probe = false;
  2581. }
  2582. module_init(touchkey_init);
  2583. module_exit(touchkey_exit);
  2584. MODULE_LICENSE("GPL");
  2585. MODULE_AUTHOR("@@@");
  2586. MODULE_DESCRIPTION("touch keypad");