wacom_i2c.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926
  1. /*
  2. * wacom_i2c.c - Wacom G5 Digitizer Controller (I2C bus)
  3. *
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/input.h>
  21. #include <linux/i2c.h>
  22. #include <linux/wacom_i2c.h>
  23. #include <linux/earlysuspend.h>
  24. #include <linux/uaccess.h>
  25. #include "wacom_i2c_func.h"
  26. #include "wacom_i2c_flash.h"
  27. #ifdef WACOM_IMPORT_FW_ALGO
  28. #include "wacom_i2c_coord_tables.h"
  29. #endif
  30. #include <linux/of_gpio.h>
  31. #ifdef CONFIG_FB
  32. #include <linux/fb.h>
  33. #endif
  34. bool ums_binary;
  35. unsigned char screen_rotate;
  36. unsigned char user_hand = 1;
  37. static struct wacom_features wacom_feature_EMR = {
  38. .comstat = COM_QUERY,
  39. .data = {0, 0, 0, 0, 0, 0, 0},
  40. .fw_version = 0x0,
  41. .fw_ic_version = 0x0,
  42. .firm_update_status = 0,
  43. };
  44. static void wacom_enable_irq(struct wacom_i2c *wac_i2c, bool enable)
  45. {
  46. static int depth;
  47. #if defined(CONFIG_SEC_LT03_PROJECT) || defined(CONFIG_SEC_VIENNA_PROJECT)
  48. mutex_lock(&wac_i2c->irq_lock);
  49. #endif
  50. if (enable) {
  51. if (depth) {
  52. --depth;
  53. enable_irq(wac_i2c->irq);
  54. #ifdef WACOM_PDCT_WORK_AROUND
  55. enable_irq(wac_i2c->irq_pdct);
  56. #endif
  57. }
  58. } else {
  59. if (!depth) {
  60. ++depth;
  61. disable_irq(wac_i2c->irq);
  62. #ifdef WACOM_PDCT_WORK_AROUND
  63. disable_irq(wac_i2c->irq_pdct);
  64. #endif
  65. }
  66. }
  67. #if defined(CONFIG_SEC_LT03_PROJECT) || defined(CONFIG_SEC_VIENNA_PROJECT)
  68. mutex_unlock(&wac_i2c->irq_lock);
  69. #endif
  70. #ifdef WACOM_IRQ_DEBUG
  71. dev_info(&wac_i2c->client->dev,
  72. "%s: Enable %d, depth %d\n",
  73. __func__, (int)enable, depth);
  74. #endif
  75. }
  76. static int wacom_start(struct wacom_i2c *wac_i2c)
  77. {
  78. dev_info(&wac_i2c->client->dev, "%s\n", __func__);
  79. if (wac_i2c->wac_pdata->gpio_pen_reset_n > 0)
  80. gpio_direction_output(wac_i2c->wac_pdata->gpio_pen_reset_n, 1);
  81. gpio_direction_output(wac_i2c->wac_pdata->vdd_en, 1);
  82. wac_i2c->power_enable = true;
  83. return 0;
  84. }
  85. static int wacom_stop(struct wacom_i2c *wac_i2c)
  86. {
  87. dev_info(&wac_i2c->client->dev, "%s\n", __func__);
  88. if (wac_i2c->wac_pdata->gpio_pen_reset_n > 0)
  89. gpio_direction_output(wac_i2c->wac_pdata->gpio_pen_reset_n, 0);
  90. gpio_direction_output(wac_i2c->wac_pdata->vdd_en, 0);
  91. #ifdef WACOM_BOOSTER
  92. if (wac_i2c->dvfs_lock_status)
  93. wacom_set_dvfs_lock(wac_i2c, -1);
  94. #endif
  95. #ifdef USE_WACOM_BLOCK_KEYEVENT
  96. wac_i2c->touch_pressed = false;
  97. wac_i2c->touchkey_skipped = false;
  98. #endif
  99. wac_i2c->power_enable = false;
  100. return 0;
  101. }
  102. static int wacom_reset_hw(struct wacom_i2c *wac_i2c)
  103. {
  104. wacom_stop(wac_i2c);
  105. #ifdef WACOM_RESETPIN_DELAY
  106. msleep(300);
  107. #else
  108. msleep(30);
  109. #endif
  110. wacom_start(wac_i2c);
  111. msleep(200);
  112. return 0;
  113. }
  114. #ifdef WACOM_HAVE_FWE_PIN
  115. static void wacom_compulsory_flash_mode(struct wacom_i2c *wac_i2c, bool en)
  116. {
  117. gpio_direction_output(wac_i2c->wac_pdata->gpio_pen_fwe1, en ? 1 : 0);
  118. dev_info(&wac_i2c->client->dev, "%s: FWE1 is %s\n",
  119. __func__, en ? "HIGH" : "LOW");
  120. }
  121. #endif
  122. static void wacom_i2c_enable(struct wacom_i2c *wac_i2c)
  123. {
  124. bool en = true;
  125. dev_info(&wac_i2c->client->dev,
  126. "%s\n", __func__);
  127. #ifdef BATTERY_SAVING_MODE
  128. if (wac_i2c->battery_saving_mode
  129. && wac_i2c->pen_insert)
  130. en = false;
  131. #endif
  132. if (en) {
  133. if (!wac_i2c->power_enable)
  134. wac_i2c->wac_pdata->wacom_start(wac_i2c);
  135. cancel_delayed_work_sync(&wac_i2c->resume_work);
  136. schedule_delayed_work(&wac_i2c->resume_work, HZ / 5);
  137. }
  138. }
  139. static void wacom_i2c_disable(struct wacom_i2c *wac_i2c)
  140. {
  141. if (wac_i2c->power_enable) {
  142. wacom_enable_irq(wac_i2c, false);
  143. /* release pen, if it is pressed */
  144. if (wac_i2c->pen_pressed || wac_i2c->side_pressed
  145. || wac_i2c->pen_prox)
  146. forced_release(wac_i2c);
  147. wac_i2c->wac_pdata->wacom_stop(wac_i2c);
  148. }
  149. }
  150. static irqreturn_t wacom_interrupt(int irq, void *dev_id)
  151. {
  152. struct wacom_i2c *wac_i2c = dev_id;
  153. wacom_i2c_coord(wac_i2c);
  154. return IRQ_HANDLED;
  155. }
  156. #if defined(WACOM_PDCT_WORK_AROUND)
  157. static irqreturn_t wacom_interrupt_pdct(int irq, void *dev_id)
  158. {
  159. struct wacom_i2c *wac_i2c = dev_id;
  160. if (wac_i2c->query_status == false)
  161. return IRQ_HANDLED;
  162. wac_i2c->pen_pdct = gpio_get_value(wac_i2c->wac_pdata->gpio_pen_pdct);
  163. dev_info(&wac_i2c->client->dev, "%s: pdct %d(%d) [%s]\n",
  164. __func__, wac_i2c->pen_pdct, wac_i2c->pen_prox,
  165. wac_i2c->pen_pdct ? "Released" : "Pressed");
  166. #if 0
  167. if (wac_i2c->pen_pdct == PDCT_NOSIGNAL) {
  168. /* If rdy is 1, pen is still working*/
  169. if (wac_i2c->pen_prox == 0)
  170. forced_release(wac_i2c);
  171. } else if (wac_i2c->pen_prox == 0)
  172. forced_hover(wac_i2c);
  173. #endif
  174. return IRQ_HANDLED;
  175. }
  176. #endif
  177. #ifdef WACOM_PEN_DETECT
  178. static void pen_insert_work(struct work_struct *work)
  179. {
  180. struct wacom_i2c *wac_i2c =
  181. container_of(work, struct wacom_i2c, pen_insert_dwork.work);
  182. if (wac_i2c->init_fail)
  183. return;
  184. wac_i2c->pen_insert = !gpio_get_value(wac_i2c->gpio_pen_insert);
  185. dev_info(&wac_i2c->client->dev, "%s: pen %s\n",
  186. __func__, wac_i2c->pen_insert ? "instert" : "remove");
  187. if (!wac_i2c->pen_insert) {
  188. input_report_key(wac_i2c->input_dev, KEY_WAKEUP, 1);
  189. input_sync(wac_i2c->input_dev);
  190. input_report_key(wac_i2c->input_dev, KEY_WAKEUP, 0);
  191. input_sync(wac_i2c->input_dev);
  192. }
  193. #ifdef BATTERY_SAVING_MODE
  194. if (wac_i2c->pen_insert) {
  195. if (wac_i2c->battery_saving_mode)
  196. wacom_i2c_disable(wac_i2c);
  197. #ifdef CONFIG_FB
  198. } else if (!wac_i2c->fb_disabled) {
  199. #else
  200. } else {
  201. #endif
  202. wacom_i2c_enable(wac_i2c);
  203. }
  204. #endif
  205. }
  206. static irqreturn_t wacom_pen_detect(int irq, void *dev_id)
  207. {
  208. struct wacom_i2c *wac_i2c = dev_id;
  209. cancel_delayed_work_sync(&wac_i2c->pen_insert_dwork);
  210. schedule_delayed_work(&wac_i2c->pen_insert_dwork, HZ / 20);
  211. return IRQ_HANDLED;
  212. }
  213. #endif
  214. static int wacom_i2c_input_open(struct input_dev *dev)
  215. {
  216. struct wacom_i2c *wac_i2c = input_get_drvdata(dev);
  217. dev_info(&wac_i2c->client->dev,
  218. "%s\n", __func__);
  219. wacom_i2c_enable(wac_i2c);
  220. wac_i2c->enabled = true;
  221. return 0;
  222. }
  223. static void wacom_i2c_input_close(struct input_dev *dev)
  224. {
  225. struct wacom_i2c *wac_i2c = input_get_drvdata(dev);
  226. dev_info(&wac_i2c->client->dev,
  227. "%s\n", __func__);
  228. wacom_i2c_disable(wac_i2c);
  229. wac_i2c->enabled = false;
  230. }
  231. static void wacom_i2c_set_input_values(struct i2c_client *client,
  232. struct wacom_i2c *wac_i2c,
  233. struct input_dev *input_dev)
  234. {
  235. /*Set input values before registering input device */
  236. input_dev->name = "sec_e-pen";
  237. input_dev->id.bustype = BUS_I2C;
  238. input_dev->dev.parent = &client->dev;
  239. input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  240. #ifdef WACOM_PEN_DETECT
  241. input_dev->open = wacom_i2c_input_open;
  242. input_dev->close = wacom_i2c_input_close;
  243. #endif
  244. __set_bit(ABS_X, input_dev->absbit);
  245. __set_bit(ABS_Y, input_dev->absbit);
  246. __set_bit(ABS_PRESSURE, input_dev->absbit);
  247. __set_bit(BTN_TOUCH, input_dev->keybit);
  248. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  249. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  250. __set_bit(BTN_STYLUS, input_dev->keybit);
  251. __set_bit(KEY_UNKNOWN, input_dev->keybit);
  252. __set_bit(KEY_PEN_PDCT, input_dev->keybit);
  253. __set_bit(KEY_WAKEUP, input_dev->keybit);
  254. __set_bit(KEY_PEN_UTD, input_dev->keybit);
  255. __set_bit(KEY_PEN_DTU, input_dev->keybit);
  256. __set_bit(KEY_PEN_RTL, input_dev->keybit);
  257. __set_bit(KEY_PEN_LTR, input_dev->keybit);
  258. __set_bit(KEY_PEN_LP, input_dev->keybit);
  259. #ifdef WACOM_USE_GAIN
  260. __set_bit(ABS_DISTANCE, input_dev->absbit);
  261. #endif
  262. /* __set_bit(BTN_STYLUS2, input_dev->keybit); */
  263. /* __set_bit(ABS_MISC, input_dev->absbit); */
  264. /*softkey*/
  265. #ifdef WACOM_USE_SOFTKEY
  266. #if defined(CONFIG_SEC_VIENNA_PROJECT) || defined(CONFIG_SEC_LT03_PROJECT)
  267. __set_bit(KEY_RECENT, input_dev->keybit);
  268. #else
  269. __set_bit(KEY_MENU, input_dev->keybit);
  270. #endif
  271. __set_bit(KEY_BACK, input_dev->keybit);
  272. #endif
  273. }
  274. #ifdef USE_WACOM_CALLBACK
  275. static int wacom_check_emr_prox(struct wacom_g5_callbacks *cb)
  276. {
  277. struct wacom_i2c *wac = container_of(cb, struct wacom_i2c, callbacks);
  278. dev_info(&wac_i2c->client->dev,
  279. "%s\n", __func__);
  280. return wac->pen_prox;
  281. }
  282. #endif
  283. static void wacom_i2c_resume_work(struct work_struct *work)
  284. {
  285. struct wacom_i2c *wac_i2c =
  286. container_of(work, struct wacom_i2c, resume_work.work);
  287. if (wac_i2c->init_fail)
  288. return;
  289. /* This Code is workaround code for S.LSI AP models. */
  290. /*
  291. #if defined(WACOM_PDCT_WORK_AROUND)
  292. //irq_set_irq_type(wac_i2c->irq_pdct, IRQ_TYPE_EDGE_BOTH);
  293. #endif
  294. */
  295. wacom_enable_irq(wac_i2c, true);
  296. dev_info(&wac_i2c->client->dev,
  297. "%s\n", __func__);
  298. }
  299. #ifdef USE_WACOM_BLOCK_KEYEVENT
  300. static void wacom_i2c_touch_pressed_work(struct work_struct *work)
  301. {
  302. struct wacom_i2c *wac_i2c =
  303. container_of(work, struct wacom_i2c, touch_pressed_work.work);
  304. cancel_delayed_work(&wac_i2c->touch_pressed_work);
  305. wac_i2c->touch_pressed = false;
  306. }
  307. #endif
  308. #ifdef WACOM_RESETPIN_DELAY
  309. static void wacom_reset(struct work_struct *work)
  310. {
  311. struct wacom_i2c *wac_i2c =
  312. container_of(work, struct wacom_i2c, work_wacom_reset.work);
  313. dev_err(&wac_i2c->client->dev,
  314. "%s: reset\n",
  315. __func__);
  316. wacom_enable_irq(wac_i2c, false);
  317. /* Reset IC */
  318. wacom_reset_hw(wac_i2c);
  319. wacom_enable_irq(wac_i2c, true);
  320. }
  321. #endif
  322. #ifdef USE_WACOM_LCD_WORKAROUND
  323. extern int ldi_fps(unsigned int input_fps);
  324. void wacom_i2c_write_vsync(struct wacom_i2c *wac_i2c)
  325. {
  326. int retval;
  327. if (wac_i2c->wait_done) {
  328. dev_info(&wac_i2c->client->dev, "%s write %d\n", __func__, wac_i2c->vsync);
  329. #if defined(CONFIG_MACH_FRESCOLTESKT) || defined(CONFIG_MACH_FRESCOLTEKTT) || defined(CONFIG_MACH_FRESCOLTELGT)
  330. retval = 0; // kyNam_131228_ ldi_fps(wac_i2c->vsync);
  331. #else
  332. retval = ldi_fps(wac_i2c->vsync);
  333. #endif
  334. if (!retval)
  335. dev_info(&wac_i2c->client->dev, "%s failed\n", __func__);
  336. wac_i2c->wait_done = false;
  337. schedule_delayed_work(&wac_i2c->read_vsync_work,
  338. msecs_to_jiffies(wac_i2c->delay_time * 1000));
  339. } else {
  340. dev_info(&wac_i2c->client->dev, "%s vsync waiting time..\n", __func__);
  341. }
  342. }
  343. static void wacom_i2c_read_vsync_work(struct work_struct *work)
  344. {
  345. struct wacom_i2c *wac_i2c =
  346. container_of(work, struct wacom_i2c, read_vsync_work.work);
  347. wac_i2c->wait_done = true;
  348. }
  349. static void wacom_i2c_boot_done_work(struct work_struct *work)
  350. {
  351. struct wacom_i2c *wac_i2c =
  352. container_of(work, struct wacom_i2c, boot_done_work.work);
  353. wac_i2c->boot_done = true;
  354. }
  355. static ssize_t epen_read_freq_show(struct device *dev,
  356. struct device_attribute *attr,
  357. char *buf)
  358. {
  359. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  360. return sprintf(buf, "%d\n", wac_i2c->delay_time);
  361. }
  362. static ssize_t epen_read_freq_data_store(struct device *dev,
  363. struct device_attribute *attr,
  364. const char *buf, size_t count)
  365. {
  366. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  367. unsigned int val;
  368. sscanf(buf, "%d", &val);
  369. wac_i2c->delay_time = val;
  370. dev_info(&wac_i2c->client->dev, "%s: lcd noise workaround delay time is %d\n",
  371. __func__, wac_i2c->delay_time);
  372. return count;
  373. }
  374. #endif
  375. #ifdef CONFIG_HAS_EARLYSUSPEND
  376. #define wacom_i2c_suspend NULL
  377. #define wacom_i2c_resume NULL
  378. #endif
  379. static ssize_t epen_firm_update_status_show(struct device *dev,
  380. struct device_attribute *attr,
  381. char *buf)
  382. {
  383. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  384. dev_info(&wac_i2c->client->dev,
  385. "%s:(%d)\n", __func__,
  386. wac_i2c->wac_feature->firm_update_status);
  387. if (wac_i2c->wac_feature->firm_update_status == 2)
  388. return sprintf(buf, "PASS\n");
  389. else if (wac_i2c->wac_feature->firm_update_status == 1)
  390. return sprintf(buf, "DOWNLOADING\n");
  391. else if (wac_i2c->wac_feature->firm_update_status == -1)
  392. return sprintf(buf, "FAIL\n");
  393. else
  394. return 0;
  395. }
  396. static ssize_t epen_firm_version_show(struct device *dev,
  397. struct device_attribute *attr, char *buf)
  398. {
  399. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  400. dev_info(&wac_i2c->client->dev,
  401. "%s: 0x%x|0x%X\n", __func__,
  402. wac_i2c->wac_feature->fw_ic_version,
  403. wac_i2c->wac_feature->fw_version);
  404. return sprintf(buf, "%04X\t%04X\n",
  405. wac_i2c->wac_feature->fw_ic_version,
  406. wac_i2c->wac_feature->fw_version);
  407. }
  408. #if defined(WACOM_IMPORT_FW_ALGO)
  409. static ssize_t epen_tuning_version_show(struct device *dev,
  410. struct device_attribute *attr, char *buf)
  411. {
  412. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  413. dev_info(&wac_i2c->client->dev,
  414. "%s: %s\n", __func__,
  415. wac_i2c->wac_pdata->basic_model);
  416. return sprintf(buf, "%s_%04X\n",
  417. wac_i2c->wac_pdata->basic_model,
  418. wac_i2c->wac_feature->fw_version);
  419. }
  420. static ssize_t epen_rotation_store(struct device *dev,
  421. struct device_attribute *attr,
  422. const char *buf, size_t count)
  423. {
  424. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  425. static bool factory_test;
  426. static unsigned char last_rotation;
  427. unsigned int val;
  428. sscanf(buf, "%u", &val);
  429. /* Fix the rotation value to 0(Portrait) when factory test(15 mode) */
  430. if (val == 100 && !factory_test) {
  431. factory_test = true;
  432. screen_rotate = 0;
  433. dev_info(&wac_i2c->client->dev,
  434. "%s, enter factory test mode\n",
  435. __func__);
  436. } else if (val == 200 && factory_test) {
  437. factory_test = false;
  438. screen_rotate = last_rotation;
  439. dev_info(&wac_i2c->client->dev,
  440. "%s, exit factory test mode\n",
  441. __func__);
  442. }
  443. /* Framework use index 0, 1, 2, 3 for rotation 0, 90, 180, 270 */
  444. /* Driver use same rotation index */
  445. if (val >= 0 && val <= 3) {
  446. if (factory_test)
  447. last_rotation = val;
  448. else
  449. screen_rotate = val;
  450. }
  451. /* 0: Portrait 0, 1: Landscape 90, 2: Portrait 180 3: Landscape 270 */
  452. dev_info(&wac_i2c->client->dev,
  453. "%s: rotate=%d\n", __func__, screen_rotate);
  454. return count;
  455. }
  456. static ssize_t epen_hand_store(struct device *dev,
  457. struct device_attribute *attr, const char *buf,
  458. size_t count)
  459. {
  460. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  461. unsigned int val;
  462. sscanf(buf, "%u", &val);
  463. if (val == 0 || val == 1)
  464. user_hand = (unsigned char)val;
  465. /* 0:Left hand, 1:Right Hand */
  466. dev_info(&wac_i2c->client->dev,
  467. "%s: hand=%u\n", __func__, user_hand);
  468. return count;
  469. }
  470. #endif
  471. static ssize_t epen_gestures_show(struct device *dev,
  472. struct device_attribute *attr, char *buf)
  473. {
  474. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  475. dev_info(&wac_i2c->client->dev,
  476. "%s: enabled_gestures=%d\n", __func__,
  477. wac_i2c->enabled_gestures);
  478. return sprintf(buf, "%d\n", wac_i2c->enabled_gestures);
  479. }
  480. static ssize_t epen_gestures_store(struct device *dev,
  481. struct device_attribute *attr, const char *buf,
  482. size_t count)
  483. {
  484. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  485. int val;
  486. sscanf(buf, "%d", &val);
  487. wac_i2c->enabled_gestures = val;
  488. dev_info(&wac_i2c->client->dev,
  489. "%s: enabled_gestures=%d\n", __func__, val);
  490. return count;
  491. }
  492. static bool check_update_condition(struct wacom_i2c *wac_i2c, const char buf)
  493. {
  494. u32 fw_ic_ver = wac_i2c->wac_feature->fw_ic_version;
  495. bool bUpdate = false;
  496. dev_info(&wac_i2c->client->dev,
  497. "%s: system rev is 0x%02x, Dig_rev(0x%02x)\n",
  498. __func__, system_rev, WACOM_FW_UPDATE_REVISION);
  499. switch (buf) {
  500. case 'I':
  501. case 'K':
  502. bUpdate = true;
  503. break;
  504. case 'R':
  505. case 'W':
  506. if (fw_ic_ver <
  507. wac_i2c->wac_feature->fw_version)
  508. bUpdate = true;
  509. break;
  510. default:
  511. dev_info(&wac_i2c->client->dev,
  512. "%s: wrong parameter\n", __func__);
  513. bUpdate = false;
  514. break;
  515. }
  516. return bUpdate;
  517. }
  518. int wacom_i2c_firm_update(struct wacom_i2c *wac_i2c)
  519. {
  520. int ret = 0;
  521. int retry = 3;
  522. while (retry--) {
  523. ret = wacom_i2c_select_flash_code(wac_i2c);
  524. if (ret < 0)
  525. dev_err(&wac_i2c->client->dev,
  526. "%s: failed to write firmware(%d)\n",
  527. __func__, ret);
  528. else
  529. dev_err(&wac_i2c->client->dev,
  530. "%s: Successed to write firmware(%d)\n",
  531. __func__, ret);
  532. /* Reset IC */
  533. wacom_reset_hw(wac_i2c);
  534. if (ret >= 0)
  535. return 0;
  536. }
  537. return ret;
  538. }
  539. static ssize_t epen_firmware_update_store(struct device *dev,
  540. struct device_attribute *attr,
  541. const char *buf, size_t count)
  542. {
  543. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  544. int ret = 1;
  545. u32 fw_ic_ver = wac_i2c->wac_feature->fw_ic_version;
  546. bool need_update = false;
  547. need_update = check_update_condition(wac_i2c, *buf);
  548. if (need_update == false) {
  549. dev_info(&wac_i2c->client->dev,
  550. "%s:Pass Update. Cmd %c, IC ver %04x, Ker ver %04x\n",
  551. __func__, *buf, fw_ic_ver, wac_i2c->wac_feature->fw_version);
  552. return count;
  553. } else {
  554. dev_info(&wac_i2c->client->dev,
  555. "%s:Update Start. IC fw ver : 0x%x, new fw ver : 0x%x\n",
  556. __func__, wac_i2c->wac_feature->fw_ic_version,
  557. wac_i2c->wac_feature->fw_version);
  558. }
  559. switch (*buf) {
  560. /*ums*/
  561. case 'I':
  562. ret = wacom_fw_load_from_UMS(wac_i2c);
  563. if (ret)
  564. goto failure;
  565. dev_info(&wac_i2c->client->dev,
  566. "%s: Start firmware flashing (UMS image).\n",
  567. __func__);
  568. ums_binary = true;
  569. break;
  570. /*kernel*/
  571. case 'K':
  572. ret = wacom_load_fw_from_req_fw(wac_i2c);
  573. if (ret)
  574. goto failure;
  575. break;
  576. /*booting*/
  577. case 'R':
  578. ret = wacom_load_fw_from_req_fw(wac_i2c);
  579. if (ret)
  580. goto failure;
  581. dev_info(&wac_i2c->client->dev,
  582. "%s: Start firmware flashing (kernel image).\n",
  583. __func__);
  584. break;
  585. default:
  586. /*There's no default case*/
  587. break;
  588. }
  589. /*start firm update*/
  590. mutex_lock(&wac_i2c->lock);
  591. wacom_enable_irq(wac_i2c, false);
  592. wac_i2c->wac_feature->firm_update_status = 1;
  593. ret = wacom_i2c_firm_update(wac_i2c);
  594. if (ret)
  595. goto update_err;
  596. wacom_i2c_set_firm_data(NULL);
  597. wacom_i2c_query(wac_i2c);
  598. wac_i2c->wac_feature->firm_update_status = 2;
  599. wacom_enable_irq(wac_i2c, true);
  600. mutex_unlock(&wac_i2c->lock);
  601. return count;
  602. update_err:
  603. wacom_i2c_set_firm_data(NULL);
  604. failure:
  605. wac_i2c->wac_feature->firm_update_status = -1;
  606. wacom_enable_irq(wac_i2c, true);
  607. mutex_unlock(&wac_i2c->lock);
  608. return -1;
  609. }
  610. static ssize_t epen_reset_store(struct device *dev,
  611. struct device_attribute *attr, const char *buf,
  612. size_t count)
  613. {
  614. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  615. int val;
  616. sscanf(buf, "%d", &val);
  617. if (val == 1) {
  618. wacom_enable_irq(wac_i2c, false);
  619. /* Reset IC */
  620. wacom_reset_hw(wac_i2c);
  621. /* I2C Test */
  622. wacom_i2c_query(wac_i2c);
  623. wacom_enable_irq(wac_i2c, true);
  624. dev_info(&wac_i2c->client->dev,
  625. "%s, result %d\n", __func__,
  626. wac_i2c->query_status);
  627. }
  628. return count;
  629. }
  630. static ssize_t epen_reset_result_show(struct device *dev,
  631. struct device_attribute *attr, char *buf)
  632. {
  633. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  634. if (wac_i2c->query_status) {
  635. dev_info(&wac_i2c->client->dev,
  636. "%s, PASS\n", __func__);
  637. return sprintf(buf, "PASS\n");
  638. } else {
  639. dev_info(&wac_i2c->client->dev,
  640. "%s, FAIL\n", __func__);
  641. return sprintf(buf, "FAIL\n");
  642. }
  643. }
  644. #ifdef WACOM_USE_AVE_TRANSITION
  645. static ssize_t epen_ave_store(struct device *dev,
  646. struct device_attribute *attr,
  647. const char *buf, size_t count)
  648. {
  649. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  650. int v1, v2, v3, v4, v5;
  651. int height;
  652. sscanf(buf, "%d%d%d%d%d%d", &height, &v1, &v2, &v3, &v4, &v5);
  653. if (height < 0 || height > 2) {
  654. dev_info(&wac_i2c->client->dev,
  655. "%s: Height err %d\n", __func__, height);
  656. return count;
  657. }
  658. g_aveLevel_C[height] = v1;
  659. g_aveLevel_X[height] = v2;
  660. g_aveLevel_Y[height] = v3;
  661. g_aveLevel_Trs[height] = v4;
  662. g_aveLevel_Cor[height] = v5;
  663. dev_info(&wac_i2c->client->dev,
  664. "%s: v1 %d v2 %d v3 %d v4 %d\n", __func__,
  665. v1, v2, v3, v4);
  666. return count;
  667. }
  668. static ssize_t epen_ave_result_show(struct device *dev,
  669. struct device_attribute *attr,
  670. char *buf)
  671. {
  672. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  673. dev_info(&wac_i2c->client->dev,
  674. "%s: %d %d %d %d, %d %d %d %d, %d %d %d %d\n",
  675. __func__,
  676. g_aveLevel_C[0], g_aveLevel_X[0],
  677. g_aveLevel_Y[0], g_aveLevel_Trs[0],
  678. g_aveLevel_C[1], g_aveLevel_X[1],
  679. g_aveLevel_Y[1], g_aveLevel_Trs[1],
  680. g_aveLevel_C[2], g_aveLevel_X[2],
  681. g_aveLevel_Y[2], g_aveLevel_Trs[2]);
  682. return sprintf(buf, "%d %d %d %d\n%d %d %d %d\n%d %d %d %d\n",
  683. g_aveLevel_C[0], g_aveLevel_X[0],
  684. g_aveLevel_Y[0], g_aveLevel_Trs[0],
  685. g_aveLevel_C[1], g_aveLevel_X[1],
  686. g_aveLevel_Y[1], g_aveLevel_Trs[1],
  687. g_aveLevel_C[2], g_aveLevel_X[2],
  688. g_aveLevel_Y[2], g_aveLevel_Trs[2]);
  689. }
  690. #endif
  691. static ssize_t epen_checksum_store(struct device *dev,
  692. struct device_attribute *attr,
  693. const char *buf, size_t count)
  694. {
  695. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  696. int val;
  697. sscanf(buf, "%d", &val);
  698. if (val != 1) {
  699. dev_info(&wac_i2c->client->dev,
  700. "%s: wrong cmd %d\n", __func__, val);
  701. return count;
  702. }
  703. wacom_enable_irq(wac_i2c, false);
  704. wacom_checksum(wac_i2c);
  705. wacom_enable_irq(wac_i2c, true);
  706. dev_info(&wac_i2c->client->dev,
  707. "%s: result %d\n",
  708. __func__, wac_i2c->checksum_result);
  709. return count;
  710. }
  711. static ssize_t epen_checksum_result_show(struct device *dev,
  712. struct device_attribute *attr,
  713. char *buf)
  714. {
  715. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  716. if (wac_i2c->checksum_result) {
  717. dev_info(&wac_i2c->client->dev,
  718. "%s: checksum, PASS\n", __func__);
  719. return sprintf(buf, "PASS\n");
  720. } else {
  721. dev_info(&wac_i2c->client->dev,
  722. "%s: checksum, FAIL\n", __func__);
  723. return sprintf(buf, "FAIL\n");
  724. }
  725. }
  726. #ifdef WACOM_CONNECTION_CHECK
  727. static ssize_t epen_connection_show(struct device *dev,
  728. struct device_attribute *attr,
  729. char *buff)
  730. {
  731. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  732. u8 cmd = 0;
  733. u8 buf[2] = {0,};
  734. int ret = 0, cnt = 10;
  735. disable_irq(wac_i2c->client->irq);
  736. cmd = WACOM_I2C_STOP;
  737. ret = wacom_i2c_send(wac_i2c, &cmd, 1, false);
  738. if (ret <= 0) {
  739. dev_err(&wac_i2c->client->dev,
  740. "%s: failed to send stop command\n",
  741. __func__);
  742. goto grid_check_error;
  743. }
  744. cmd = WACOM_I2C_GRID_CHECK;
  745. ret = wacom_i2c_send(wac_i2c, &cmd, 1, false);
  746. if (ret <= 0) {
  747. dev_err(&wac_i2c->client->dev,
  748. "%s: failed to send stop command\n",
  749. __func__);
  750. goto grid_check_error;
  751. }
  752. cmd = WACOM_STATUS;
  753. do {
  754. msleep(50);
  755. if (1 == wacom_i2c_send(wac_i2c, &cmd, 1, false)) {
  756. if (2 == wacom_i2c_recv(wac_i2c,
  757. buf, 2, false)) {
  758. switch (buf[0]) {
  759. /*
  760. * status value
  761. * 0 : data is not ready
  762. * 1 : PASS
  763. * 2 : Fail (coil function error)
  764. * 3 : Fail (All coil function error)
  765. */
  766. case 1:
  767. case 2:
  768. case 3:
  769. cnt = 0;
  770. break;
  771. default:
  772. break;
  773. }
  774. }
  775. }
  776. } while (cnt--);
  777. dev_info(&wac_i2c->client->dev,
  778. "%s : status: %x, error code: %x\n",
  779. __func__, buf[0], buf[1]);
  780. grid_check_error:
  781. cmd = WACOM_I2C_STOP;
  782. ret = wacom_i2c_send(wac_i2c, &cmd, 1, false);
  783. if (ret <= 0)
  784. dev_err(&wac_i2c->client->dev,
  785. "%s: failed to send stop command\n",
  786. __func__);
  787. cmd = WACOM_I2C_START;
  788. wacom_i2c_send(wac_i2c, &cmd, 1, false);
  789. if (ret <= 0)
  790. dev_err(&wac_i2c->client->dev,
  791. "%s: failed to send stop command\n",
  792. __func__);
  793. enable_irq(wac_i2c->client->irq);
  794. if ((buf[0] == 0x1) && (buf[1] == 0))
  795. return sprintf(buff, "%s\n", "OK");
  796. else
  797. return sprintf(buff, "%s\n", "NG");
  798. }
  799. #endif
  800. #ifdef BATTERY_SAVING_MODE
  801. static ssize_t epen_saving_mode_store(struct device *dev,
  802. struct device_attribute *attr, const char *buf,
  803. size_t count)
  804. {
  805. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  806. int val;
  807. if (sscanf(buf, "%u", &val) == 1)
  808. wac_i2c->battery_saving_mode = !!val;
  809. dev_info(&wac_i2c->client->dev, "%s: %s\n",
  810. __func__, val ? "checked" : "unchecked");
  811. if (wac_i2c->battery_saving_mode) {
  812. if (wac_i2c->pen_insert)
  813. wacom_i2c_disable(wac_i2c);
  814. } else {
  815. if (wac_i2c->enabled)
  816. wacom_i2c_enable(wac_i2c);
  817. }
  818. return count;
  819. }
  820. #endif
  821. #ifdef WACOM_BOOSTER
  822. static ssize_t boost_level_store(struct device *dev,
  823. struct device_attribute *attr,
  824. const char *buf, size_t count)
  825. {
  826. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  827. int val, retval;
  828. dev_info(&wac_i2c->client->dev, "%s\n", __func__);
  829. sscanf(buf, "%d", &val);
  830. if (val != 1 && val != 2 && val != 3 && val != 0) {
  831. dev_info(&wac_i2c->client->dev,
  832. "%s: wrong cmd %d\n", __func__, val);
  833. return count;
  834. }
  835. wac_i2c->dvfs_boost_mode = val;
  836. dev_info(&wac_i2c->client->dev,
  837. "%s: dvfs_boost_mode = %d\n",
  838. __func__, wac_i2c->dvfs_boost_mode);
  839. if (wac_i2c->dvfs_boost_mode != DVFS_STAGE_TRIPLE) {
  840. wac_i2c->dvfs_freq = -1;
  841. } else if (wac_i2c->dvfs_boost_mode == DVFS_STAGE_NONE) {
  842. retval = set_freq_limit(DVFS_TOUCH_ID, -1);
  843. if (retval < 0) {
  844. dev_err(&wac_i2c->client->dev,
  845. "%s: booster stop failed(%d).\n",
  846. __func__, retval);
  847. wac_i2c->dvfs_lock_status = false;
  848. }
  849. }
  850. return count;
  851. }
  852. #endif
  853. #ifdef USE_WACOM_BLOCK_KEYEVENT
  854. static ssize_t epen_delay_time_show(struct device *dev,
  855. struct device_attribute *attr,
  856. char *buf)
  857. {
  858. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  859. return snprintf(buf, PAGE_SIZE, "%u msec\n", wac_i2c->key_delay_time);
  860. }
  861. static ssize_t epen_delay_time_store(struct device *dev,
  862. struct device_attribute *attr,
  863. const char *buf, size_t count)
  864. {
  865. struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
  866. unsigned int val;
  867. sscanf(buf, "%u", &val);
  868. if (val > 0)
  869. wac_i2c->key_delay_time = val;
  870. dev_info(&wac_i2c->client->dev, "%s: delay time : %d\n",
  871. __func__, wac_i2c->key_delay_time);
  872. return count;
  873. }
  874. #endif
  875. #ifdef USE_WACOM_BLOCK_KEYEVENT
  876. static DEVICE_ATTR(epen_delay_time,
  877. S_IRUGO| S_IWUSR | S_IWGRP, epen_delay_time_show, epen_delay_time_store);
  878. #endif
  879. #ifdef USE_WACOM_LCD_WORKAROUND
  880. static DEVICE_ATTR(epen_read_freq,
  881. S_IRUGO| S_IWUSR | S_IWGRP, epen_read_freq_show, epen_read_freq_data_store);
  882. #endif
  883. /* firmware update */
  884. static DEVICE_ATTR(epen_firm_update,
  885. S_IWUSR | S_IWGRP, NULL, epen_firmware_update_store);
  886. /* return firmware update status */
  887. static DEVICE_ATTR(epen_firm_update_status,
  888. S_IRUGO, epen_firm_update_status_show, NULL);
  889. /* return firmware version */
  890. static DEVICE_ATTR(epen_firm_version, S_IRUGO, epen_firm_version_show, NULL);
  891. #if defined(WACOM_IMPORT_FW_ALGO)
  892. /* return tuning data version */
  893. static DEVICE_ATTR(epen_tuning_version, S_IRUGO,
  894. epen_tuning_version_show, NULL);
  895. /* screen rotation */
  896. static DEVICE_ATTR(epen_rotation, S_IWUSR | S_IWGRP, NULL, epen_rotation_store);
  897. /* hand type */
  898. static DEVICE_ATTR(epen_hand, S_IWUSR | S_IWGRP, NULL, epen_hand_store);
  899. #endif
  900. /* For SMD Test */
  901. static DEVICE_ATTR(epen_reset, S_IWUSR | S_IWGRP, NULL, epen_reset_store);
  902. static DEVICE_ATTR(epen_reset_result,
  903. S_IRUSR | S_IRGRP, epen_reset_result_show, NULL);
  904. /* For SMD Test. Check checksum */
  905. static DEVICE_ATTR(epen_checksum, S_IWUSR | S_IWGRP, NULL, epen_checksum_store);
  906. static DEVICE_ATTR(epen_checksum_result, S_IRUSR | S_IRGRP,
  907. epen_checksum_result_show, NULL);
  908. #ifdef WACOM_USE_AVE_TRANSITION
  909. static DEVICE_ATTR(epen_ave, S_IWUSR | S_IWGRP, NULL, epen_ave_store);
  910. static DEVICE_ATTR(epen_ave_result, S_IRUSR | S_IRGRP,
  911. epen_ave_result_show, NULL);
  912. #endif
  913. #ifdef WACOM_CONNECTION_CHECK
  914. static DEVICE_ATTR(epen_connection,
  915. S_IRUGO, epen_connection_show, NULL);
  916. #endif
  917. #ifdef BATTERY_SAVING_MODE
  918. static DEVICE_ATTR(epen_saving_mode,
  919. S_IWUSR | S_IWGRP, NULL, epen_saving_mode_store);
  920. #endif
  921. #ifdef WACOM_BOOSTER
  922. static DEVICE_ATTR(boost_level,
  923. S_IWUSR | S_IWGRP, NULL, boost_level_store);
  924. #endif
  925. static DEVICE_ATTR(epen_gestures, S_IWUSR | S_IWGRP | S_IRUGO,
  926. epen_gestures_show, epen_gestures_store);
  927. static struct attribute *epen_attributes[] = {
  928. #ifdef USE_WACOM_BLOCK_KEYEVENT
  929. &dev_attr_epen_delay_time.attr,
  930. #endif
  931. #ifdef USE_WACOM_LCD_WORKAROUND
  932. &dev_attr_epen_read_freq.attr,
  933. #endif
  934. &dev_attr_epen_firm_update.attr,
  935. &dev_attr_epen_firm_update_status.attr,
  936. &dev_attr_epen_firm_version.attr,
  937. #if defined(WACOM_IMPORT_FW_ALGO)
  938. &dev_attr_epen_tuning_version.attr,
  939. &dev_attr_epen_rotation.attr,
  940. &dev_attr_epen_hand.attr,
  941. #endif
  942. &dev_attr_epen_reset.attr,
  943. &dev_attr_epen_reset_result.attr,
  944. &dev_attr_epen_checksum.attr,
  945. &dev_attr_epen_checksum_result.attr,
  946. #ifdef WACOM_USE_AVE_TRANSITION
  947. &dev_attr_epen_ave.attr,
  948. &dev_attr_epen_ave_result.attr,
  949. #endif
  950. #ifdef WACOM_CONNECTION_CHECK
  951. &dev_attr_epen_connection.attr,
  952. #endif
  953. #ifdef BATTERY_SAVING_MODE
  954. &dev_attr_epen_saving_mode.attr,
  955. #endif
  956. #ifdef WACOM_BOOSTER
  957. &dev_attr_boost_level.attr,
  958. #endif
  959. &dev_attr_epen_gestures.attr,
  960. NULL,
  961. };
  962. static struct attribute_group epen_attr_group = {
  963. .attrs = epen_attributes,
  964. };
  965. static int wacom_firmware_update(struct wacom_i2c *wac_i2c)
  966. {
  967. int ret = 0;
  968. ret = wacom_load_fw_from_req_fw(wac_i2c);
  969. if (ret)
  970. goto failure;
  971. if (wac_i2c->wac_feature->fw_ic_version < wac_i2c->wac_feature->fw_version) {
  972. /*start firm update*/
  973. dev_info(&wac_i2c->client->dev,
  974. "%s: Start firmware flashing (kernel image).\n",
  975. __func__);
  976. mutex_lock(&wac_i2c->lock);
  977. wacom_enable_irq(wac_i2c, false);
  978. wac_i2c->wac_feature->firm_update_status = 1;
  979. ret = wacom_i2c_firm_update(wac_i2c);
  980. if (ret)
  981. goto update_err;
  982. wacom_i2c_set_firm_data(NULL);
  983. wacom_i2c_query(wac_i2c);
  984. wac_i2c->wac_feature->firm_update_status = 2;
  985. wacom_enable_irq(wac_i2c, true);
  986. mutex_unlock(&wac_i2c->lock);
  987. } else {
  988. dev_info(&wac_i2c->client->dev,
  989. "%s: firmware update does not need.\n",
  990. __func__);
  991. }
  992. return ret;
  993. update_err:
  994. wacom_i2c_set_firm_data(NULL);
  995. wac_i2c->wac_feature->firm_update_status = -1;
  996. wacom_enable_irq(wac_i2c, true);
  997. mutex_unlock(&wac_i2c->lock);
  998. failure:
  999. return ret;
  1000. }
  1001. static void wacom_init_abs_params(struct wacom_i2c *wac_i2c)
  1002. {
  1003. wac_i2c->wac_feature->x_max = wac_i2c->wac_pdata->max_x;
  1004. wac_i2c->wac_feature->y_max = wac_i2c->wac_pdata->max_y;
  1005. wac_i2c->wac_feature->pressure_max = wac_i2c->wac_pdata->max_pressure;
  1006. if (wac_i2c->wac_pdata->xy_switch) {
  1007. input_set_abs_params(wac_i2c->input_dev, ABS_X, 0,
  1008. wac_i2c->wac_feature->y_max, 4, 0);
  1009. input_set_abs_params(wac_i2c->input_dev, ABS_Y, 0,
  1010. wac_i2c->wac_feature->x_max, 4, 0);
  1011. } else {
  1012. input_set_abs_params(wac_i2c->input_dev, ABS_X, 0,
  1013. wac_i2c->wac_feature->x_max, 4, 0);
  1014. input_set_abs_params(wac_i2c->input_dev, ABS_Y, 0,
  1015. wac_i2c->wac_feature->y_max, 4, 0);
  1016. }
  1017. input_set_abs_params(wac_i2c->input_dev, ABS_PRESSURE, 0,
  1018. wac_i2c->wac_feature->pressure_max, 0, 0);
  1019. #ifdef WACOM_USE_GAIN
  1020. input_set_abs_params(wac_i2c->input_dev, ABS_DISTANCE, 0,
  1021. 1024, 0, 0);
  1022. #endif
  1023. }
  1024. static void wacom_request_gpio(struct wacom_g5_platform_data *pdata)
  1025. {
  1026. int ret;
  1027. printk(KERN_INFO "%s: request gpio\n", __func__);
  1028. ret = gpio_request(pdata->gpio_int, "wacom_irq");
  1029. if (ret) {
  1030. pr_err("%s: unable to request wacom_irq [%d]\n",
  1031. __func__, pdata->gpio_int);
  1032. return;
  1033. }
  1034. ret = gpio_request(pdata->vdd_en, "wacom_vdd_en");
  1035. if (ret) {
  1036. pr_err("%s: unable to request wacom_vdd_en [%d]\n",
  1037. __func__, pdata->vdd_en);
  1038. return;
  1039. }
  1040. if (pdata->gpio_pen_reset_n > 0) {
  1041. ret = gpio_request(pdata->gpio_pen_reset_n, "wacom_pen_reset_n");
  1042. if (ret) {
  1043. pr_err("%s: unable to request wacom_pen_reset_n [%d]\n",
  1044. __func__, pdata->gpio_pen_reset_n);
  1045. return;
  1046. }
  1047. gpio_tlmm_config(GPIO_CFG(pdata->gpio_pen_reset_n, 0,
  1048. GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1049. }
  1050. ret = gpio_request(pdata->gpio_pen_pdct, "pen_pdct-gpio");
  1051. if (ret) {
  1052. pr_err("%s: unable to request pen_pdct-gpio [%d]\n",
  1053. __func__, pdata->gpio_pen_pdct);
  1054. return;
  1055. }
  1056. ret = gpio_request(pdata->gpio_pen_fwe1, "wacom_pen_fwe1");
  1057. if (ret) {
  1058. pr_err("%s: unable to request wacom_pen_fwe1 [%d]\n",
  1059. __func__, pdata->gpio_pen_fwe1);
  1060. return;
  1061. }
  1062. gpio_tlmm_config(GPIO_CFG(pdata->gpio_pen_fwe1, 0,
  1063. GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  1064. gpio_direction_output(pdata->gpio_pen_fwe1, 0);
  1065. ret = gpio_request(pdata->gpio_pen_insert, "wacom_pen_insert");
  1066. if (ret) {
  1067. pr_err("[WACOM]%s: unable to request wacom_pen_insert [%d]\n",
  1068. __func__, pdata->gpio_pen_insert);
  1069. return;
  1070. }
  1071. gpio_tlmm_config(GPIO_CFG(pdata->gpio_pen_insert, 0,
  1072. GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA), 1);
  1073. }
  1074. #ifdef CONFIG_OF
  1075. static int wacom_get_dt_coords(struct device *dev, char *name,
  1076. struct wacom_g5_platform_data *pdata)
  1077. {
  1078. u32 coords[WACOM_COORDS_ARR_SIZE];
  1079. struct property *prop;
  1080. struct device_node *np = dev->of_node;
  1081. int coords_size, rc;
  1082. prop = of_find_property(np, name, NULL);
  1083. if (!prop)
  1084. return -EINVAL;
  1085. if (!prop->value)
  1086. return -ENODATA;
  1087. coords_size = prop->length / sizeof(u32);
  1088. if (coords_size != WACOM_COORDS_ARR_SIZE) {
  1089. dev_err(dev, "invalid %s\n", name);
  1090. return -EINVAL;
  1091. }
  1092. rc = of_property_read_u32_array(np, name, coords, coords_size);
  1093. if (rc && (rc != -EINVAL)) {
  1094. dev_err(dev, "%s: Unable to read %s\n", __func__, name);
  1095. return rc;
  1096. }
  1097. if (strncmp(name, "wacom,panel-coords",
  1098. sizeof("wacom,panel-coords")) == 0) {
  1099. pdata->x_invert = coords[0];
  1100. pdata->y_invert = coords[1];
  1101. pdata->min_x = coords[2];
  1102. pdata->max_x = coords[3];
  1103. pdata->min_y = coords[4];
  1104. pdata->max_y = coords[5];
  1105. pdata->xy_switch = coords[6];
  1106. pdata->min_pressure = coords[7];
  1107. pdata->max_pressure = coords[8];
  1108. printk(KERN_ERR "%s: x_invert = %d, y_invert = %d, xy_switch = %d\n",
  1109. __func__, pdata->x_invert, pdata->y_invert, pdata->xy_switch);
  1110. } else {
  1111. dev_err(dev, "%s: nsupported property %s\n", __func__, name);
  1112. return -EINVAL;
  1113. }
  1114. return 0;
  1115. }
  1116. static void wacom_connect_platform_data(struct wacom_g5_platform_data *pdata)
  1117. {
  1118. pdata->reset_platform_hw = wacom_reset_hw;
  1119. pdata->wacom_start = wacom_start;
  1120. pdata->wacom_stop = wacom_stop;
  1121. #ifdef WACOM_HAVE_FWE_PIN
  1122. pdata->compulsory_flash_mode = wacom_compulsory_flash_mode;
  1123. #endif
  1124. }
  1125. static int wacom_parse_dt(struct device *dev,
  1126. struct wacom_g5_platform_data *pdata)
  1127. {
  1128. int rc;
  1129. struct device_node *np = dev->of_node;
  1130. rc = wacom_get_dt_coords(dev, "wacom,panel-coords", pdata);
  1131. if (rc)
  1132. return rc;
  1133. /* regulator info */
  1134. pdata->i2c_pull_up = of_property_read_bool(np, "wacom,i2c-pull-up");
  1135. pdata->vdd_en = of_get_named_gpio(np, "vdd_en-gpio", 0);
  1136. /* reset, irq gpio info */
  1137. pdata->gpio_int = of_get_named_gpio_flags(np, "wacom,irq-gpio",
  1138. 0, &pdata->irq_gpio_flags);
  1139. pdata->gpio_pen_fwe1 = of_get_named_gpio_flags(np,
  1140. "wacom,pen_fwe1-gpio", 0, &pdata->pen_fwe1_gpio_flags);
  1141. pdata->gpio_pen_reset_n = of_get_named_gpio_flags(np,
  1142. "wacom,reset_n-gpio", 0, &pdata->pen_reset_n_gpio_flags);
  1143. pdata->gpio_pen_pdct = of_get_named_gpio_flags(np,
  1144. "wacom,pen_pdct-gpio", 0, &pdata->pen_pdct_gpio_flags);
  1145. pdata->gpio_pen_insert = of_get_named_gpio(np, "wacom,sense-gpio", 0);
  1146. #if defined(CONFIG_MACH_HLTECHNTWU)
  1147. pdata->basic_model = "N900U";
  1148. #else
  1149. rc = of_property_read_string(np, "wacom,basic_model", &pdata->basic_model);
  1150. if (rc < 0) {
  1151. dev_info(dev, "%s: Unable to read wacom,basic_model\n", __func__);
  1152. pdata->basic_model = "NULL";
  1153. }
  1154. #endif
  1155. rc = of_property_read_u32(np, "wacom,ic_mpu_ver", &pdata->ic_mpu_ver);
  1156. if (rc < 0)
  1157. dev_info(dev, "%s: Unable to read wacom,ic_mpu_ver\n", __func__);
  1158. /*Change below if irq is needed */
  1159. rc = of_property_read_u32(np, "wacom,irq_flags", &pdata->irq_flags);
  1160. if (rc < 0)
  1161. dev_info(dev, "%s: Unable to read wacom,irq_flags\n", __func__);
  1162. printk(KERN_ERR "%s: fwe1: %d, reset_n: %d, pdct: %d, insert: %d, model: %s, mpu: %x, irq_flags=%x \n",
  1163. __func__, pdata->gpio_pen_fwe1, pdata->gpio_pen_reset_n,
  1164. pdata->gpio_pen_pdct, pdata->gpio_pen_insert, pdata->basic_model, pdata->ic_mpu_ver, pdata->irq_flags);
  1165. return 0;
  1166. }
  1167. #else
  1168. static int wacom_parse_dt(struct device *dev,
  1169. struct wacom_g5_platform_data *pdata)
  1170. {
  1171. return -ENODEV;
  1172. }
  1173. #endif
  1174. static int wacom_i2c_remove(struct i2c_client *client)
  1175. {
  1176. struct wacom_i2c *wac_i2c = i2c_get_clientdata(client);
  1177. free_irq(client->irq, wac_i2c);
  1178. #ifdef WACOM_PDCT_WORK_AROUND
  1179. free_irq(wac_i2c->irq_pdct, wac_i2c);
  1180. #endif
  1181. free_irq(wac_i2c->irq_pen_insert, wac_i2c);
  1182. cancel_delayed_work_sync(&wac_i2c->resume_work);
  1183. cancel_delayed_work_sync(&wac_i2c->touch_pressed_work);
  1184. #ifdef USE_WACOM_LCD_WORKAROUND
  1185. cancel_delayed_work_sync(&wac_i2c->read_vsync_work);
  1186. cancel_delayed_work_sync(&wac_i2c->boot_done_work);
  1187. #endif
  1188. #ifdef WACOM_RESETPIN_DELAY
  1189. cancel_delayed_work_sync(&wac_i2c->work_wacom_reset);
  1190. #endif
  1191. cancel_delayed_work_sync(&wac_i2c->pen_insert_dwork);
  1192. #ifdef WACOM_BOOSTER
  1193. cancel_delayed_work_sync(&wac_i2c->work_dvfs_off);
  1194. cancel_delayed_work_sync(&wac_i2c->work_dvfs_chg);
  1195. mutex_destroy(&wac_i2c->dvfs_lock);
  1196. #endif
  1197. mutex_destroy(&wac_i2c->lock);
  1198. sysfs_remove_group(&wac_i2c->dev->kobj, &epen_attr_group);
  1199. input_unregister_device(wac_i2c->input_dev);
  1200. input_free_device(wac_i2c->input_dev);
  1201. #ifdef CONFIG_FB
  1202. fb_unregister_client(&wac_i2c->fb_notif);
  1203. #endif
  1204. kfree(wac_i2c);
  1205. return 0;
  1206. }
  1207. #ifdef CONFIG_HAS_EARLYSUSPEND
  1208. static void wacom_i2c_early_suspend(struct early_suspend *h)
  1209. {
  1210. struct wacom_i2c *wac_i2c =
  1211. container_of(h, struct wacom_i2c, early_suspend);
  1212. dev_info(&wac_i2c->client->dev,
  1213. "%s\n", __func__);
  1214. wacom_i2c_disable(wac_i2c);
  1215. }
  1216. static void wacom_i2c_late_resume(struct early_suspend *h)
  1217. {
  1218. struct wacom_i2c *wac_i2c =
  1219. container_of(h, struct wacom_i2c, early_suspend);
  1220. dev_info(&wac_i2c->client->dev,
  1221. "%s\n", __func__);
  1222. wacom_i2c_enable(wac_i2c);
  1223. }
  1224. #endif
  1225. #ifdef CONFIG_FB
  1226. static int fb_notifier_callback(struct notifier_block *self,
  1227. unsigned long event, void *data);
  1228. #endif
  1229. static int wacom_i2c_probe(struct i2c_client *client,
  1230. const struct i2c_device_id *id)
  1231. {
  1232. struct wacom_g5_platform_data *pdata;
  1233. struct wacom_i2c *wac_i2c;
  1234. struct input_dev *input;
  1235. int ret = 0;
  1236. int error;
  1237. int fw_ver;
  1238. /*Check I2C functionality */
  1239. ret = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
  1240. if (!ret) {
  1241. printk(KERN_ERR "%s: No I2C functionality found\n", __func__);
  1242. ret = -ENODEV;
  1243. goto err_i2c_fail;
  1244. }
  1245. /*Obtain kernel memory space for wacom i2c */
  1246. if (client->dev.of_node) {
  1247. pdata = devm_kzalloc(&client->dev,
  1248. sizeof(struct wacom_g5_platform_data), GFP_KERNEL);
  1249. if (!pdata) {
  1250. dev_err(&client->dev,
  1251. "%s: Failed to allocate memory\n",
  1252. __func__);
  1253. return -ENOMEM;
  1254. }
  1255. error = wacom_parse_dt(&client->dev, pdata);
  1256. if (error)
  1257. return error;
  1258. } else {
  1259. pdata = client->dev.platform_data;
  1260. if (pdata == NULL) {
  1261. dev_err(&client->dev, "%s: no pdata\n", __func__);
  1262. ret = -ENODEV;
  1263. goto err_i2c_fail;
  1264. }
  1265. }
  1266. wacom_connect_platform_data(pdata);
  1267. wacom_request_gpio(pdata);
  1268. wac_i2c = kzalloc(sizeof(struct wacom_i2c), GFP_KERNEL);
  1269. if (NULL == wac_i2c) {
  1270. dev_err(&client->dev,
  1271. "%s: failed to allocate wac_i2c.\n",
  1272. __func__);
  1273. ret = -ENOMEM;
  1274. goto err_i2c_fail;
  1275. }
  1276. wac_i2c->client_boot = i2c_new_dummy(client->adapter,
  1277. WACOM_I2C_BOOT);
  1278. if (!wac_i2c->client_boot) {
  1279. dev_err(&client->dev, "Fail to register sub client[0x%x]\n",
  1280. WACOM_I2C_BOOT);
  1281. }
  1282. input = input_allocate_device();
  1283. if (NULL == input) {
  1284. dev_err(&client->dev,
  1285. "%s: failed to allocate input device.\n",
  1286. __func__);
  1287. ret = -ENOMEM;
  1288. goto err_freemem;
  1289. }
  1290. wacom_i2c_set_input_values(client, wac_i2c, input);
  1291. wac_i2c->wac_feature = &wacom_feature_EMR;
  1292. wac_i2c->wac_pdata = pdata;
  1293. wac_i2c->input_dev = input;
  1294. wac_i2c->client = client;
  1295. client->irq = gpio_to_irq(pdata->gpio_int);
  1296. printk(KERN_ERR "%s: wacom : gpio_to_irq : %d\n",
  1297. __func__, client->irq);
  1298. wac_i2c->irq = client->irq;
  1299. /*Set client data */
  1300. i2c_set_clientdata(client, wac_i2c);
  1301. i2c_set_clientdata(wac_i2c->client_boot, wac_i2c);
  1302. #ifdef WACOM_PDCT_WORK_AROUND
  1303. wac_i2c->irq_pdct = gpio_to_irq(pdata->gpio_pen_pdct);
  1304. wac_i2c->pen_pdct = PDCT_NOSIGNAL;
  1305. #endif
  1306. #ifdef WACOM_PEN_DETECT
  1307. wac_i2c->gpio_pen_insert = pdata->gpio_pen_insert;
  1308. wac_i2c->irq_pen_insert = gpio_to_irq(wac_i2c->gpio_pen_insert);
  1309. #endif
  1310. #ifdef WACOM_IMPORT_FW_ALGO
  1311. wac_i2c->use_offset_table = true;
  1312. wac_i2c->use_aveTransition = false;
  1313. #endif
  1314. #ifdef USE_WACOM_CALLBACK
  1315. /*Register callbacks */
  1316. wac_i2c->callbacks.check_prox = wacom_check_emr_prox;
  1317. if (wac_i2c->wac_pdata->register_cb)
  1318. wac_i2c->wac_pdata->register_cb(&wac_i2c->callbacks);
  1319. #endif
  1320. #ifdef CONFIG_SEC_VIENNA_PROJECT
  1321. if (system_rev >= WACOM_BOOT_REVISION) {
  1322. wac_i2c->wac_pdata->ic_mpu_ver = MPU_W9007;
  1323. wac_i2c->boot_ver = 0x92;
  1324. }
  1325. #endif
  1326. #ifdef CONFIG_SEC_LT03_PROJECT
  1327. wac_i2c->boot_ver = 0x92;
  1328. #endif
  1329. if (wac_i2c->wac_pdata->ic_mpu_ver > 0) {
  1330. wac_i2c->ic_mpu_ver = wac_i2c->wac_pdata->ic_mpu_ver;
  1331. wac_i2c->wac_pdata->compulsory_flash_mode(wac_i2c, false);
  1332. wac_i2c->wac_pdata->wacom_start(wac_i2c);
  1333. msleep(200);
  1334. } else {
  1335. wac_i2c->wac_pdata->compulsory_flash_mode(wac_i2c, true);
  1336. /*Reset */
  1337. wac_i2c->wac_pdata->wacom_start(wac_i2c);
  1338. msleep(200);
  1339. ret = wacom_check_mpu_version(wac_i2c);
  1340. if (ret == -ETIMEDOUT)
  1341. #if defined(CONFIG_SEC_H_PROJECT) || defined(CONFIG_SEC_FRESCO_PROJECT)
  1342. goto err_wacom_i2c_send_timeout;
  1343. #else
  1344. pr_err("[E-PEN] wacom_i2c_send failed.\n");
  1345. #endif
  1346. wac_i2c->ic_mpu_ver = wacom_check_flash_mode(wac_i2c, BOOT_MPU);
  1347. dev_info(&wac_i2c->client->dev,
  1348. "%s: mpu version: %x\n", __func__, ret);
  1349. if (wac_i2c->ic_mpu_ver == MPU_W9001)
  1350. wac_i2c->client_boot = i2c_new_dummy(client->adapter,
  1351. WACOM_I2C_9001_BOOT);
  1352. else if (wac_i2c->ic_mpu_ver == MPU_W9007) {
  1353. ret = wacom_enter_bootloader(wac_i2c);
  1354. if (ret < 0) {
  1355. dev_info(&wac_i2c->client->dev,
  1356. "%s: failed to get BootLoader version, %d\n", __func__, ret);
  1357. goto err_wacom_i2c_bootloader_ver;
  1358. } else {
  1359. dev_info(&wac_i2c->client->dev,
  1360. "%s: BootLoader version: %x\n", __func__, ret);
  1361. }
  1362. }
  1363. wac_i2c->wac_pdata->compulsory_flash_mode(wac_i2c, false);
  1364. wac_i2c->wac_pdata->reset_platform_hw(wac_i2c);
  1365. wac_i2c->power_enable = true;
  1366. }
  1367. /* Firmware Feature */
  1368. wacom_i2c_init_firm_data();
  1369. pr_err("%s: wacon ic turn on\n", __func__);
  1370. fw_ver = wacom_i2c_query(wac_i2c);
  1371. wacom_init_abs_params(wac_i2c);
  1372. input_set_drvdata(input, wac_i2c);
  1373. /*Initializing for semaphor */
  1374. mutex_init(&wac_i2c->lock);
  1375. #if defined(CONFIG_SEC_LT03_PROJECT) || defined(CONFIG_SEC_VIENNA_PROJECT)
  1376. mutex_init(&wac_i2c->irq_lock);
  1377. #endif
  1378. #ifdef WACOM_BOOSTER
  1379. wacom_init_dvfs(wac_i2c);
  1380. #endif
  1381. INIT_DELAYED_WORK(&wac_i2c->resume_work, wacom_i2c_resume_work);
  1382. #ifdef USE_WACOM_BLOCK_KEYEVENT
  1383. INIT_DELAYED_WORK(&wac_i2c->touch_pressed_work, wacom_i2c_touch_pressed_work);
  1384. wac_i2c->key_delay_time = 100;
  1385. #endif
  1386. #ifdef USE_WACOM_LCD_WORKAROUND
  1387. wac_i2c->wait_done = true;
  1388. wac_i2c->delay_time = 5;
  1389. INIT_DELAYED_WORK(&wac_i2c->read_vsync_work, wacom_i2c_read_vsync_work);
  1390. wac_i2c->boot_done = false;
  1391. INIT_DELAYED_WORK(&wac_i2c->boot_done_work, wacom_i2c_boot_done_work);
  1392. #endif
  1393. #ifdef WACOM_PEN_DETECT
  1394. INIT_DELAYED_WORK(&wac_i2c->pen_insert_dwork, pen_insert_work);
  1395. #endif
  1396. #ifdef WACOM_RESETPIN_DELAY
  1397. INIT_DELAYED_WORK(&wac_i2c->work_wacom_reset, wacom_reset);
  1398. #endif
  1399. /*Before registering input device, data in each input_dev must be set */
  1400. ret = input_register_device(input);
  1401. if (ret) {
  1402. pr_err("[E-PEN] failed to register input device.\n");
  1403. goto err_input_allocate_device;
  1404. }
  1405. #ifdef CONFIG_HAS_EARLYSUSPEND
  1406. wac_i2c->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
  1407. wac_i2c->early_suspend.suspend = wacom_i2c_early_suspend;
  1408. wac_i2c->early_suspend.resume = wacom_i2c_late_resume;
  1409. register_early_suspend(&wac_i2c->early_suspend);
  1410. #endif
  1411. wac_i2c->dev = device_create(sec_class, NULL, 0, NULL, "sec_epen");
  1412. if (IS_ERR(wac_i2c->dev)) {
  1413. dev_err(&wac_i2c->client->dev,
  1414. "%s: Failed to create device(wac_i2c->dev)!\n",
  1415. __func__);
  1416. goto err_sysfs_create_group;
  1417. }
  1418. dev_set_drvdata(wac_i2c->dev, wac_i2c);
  1419. ret = sysfs_create_group(&wac_i2c->dev->kobj, &epen_attr_group);
  1420. if (ret) {
  1421. dev_err(&wac_i2c->client->dev,
  1422. "%s: failed to create sysfs group\n",
  1423. __func__);
  1424. goto err_sysfs_create_group;
  1425. }
  1426. ret = sysfs_create_link(&wac_i2c->dev->kobj, &wac_i2c->input_dev->dev.kobj, "input");
  1427. if (ret < 0) {
  1428. dev_err(&client->dev,
  1429. "%s: Failed to create input symbolic link\n",
  1430. __func__);
  1431. }
  1432. ret = wacom_firmware_update(wac_i2c);
  1433. if (ret) {
  1434. dev_err(&wac_i2c->client->dev,
  1435. "%s: firmware update failed.\n",
  1436. __func__);
  1437. if (fw_ver > 0 && wac_i2c->ic_mpu_ver < 0)
  1438. dev_err(&wac_i2c->client->dev,
  1439. "%s: read query but not enter boot mode[%x,%x]\n",
  1440. __func__, fw_ver, wac_i2c->ic_mpu_ver);
  1441. else
  1442. goto err_fw_update;
  1443. }
  1444. /*Request IRQ */
  1445. if (pdata->irq_flags) {
  1446. ret =
  1447. request_threaded_irq(wac_i2c->irq, NULL, wacom_interrupt,
  1448. IRQF_DISABLED | pdata->irq_flags |
  1449. IRQF_ONESHOT, wac_i2c->name, wac_i2c);
  1450. if (ret < 0) {
  1451. dev_err(&wac_i2c->client->dev,
  1452. "%s: failed to request irq(%d) - %d\n",
  1453. __func__, wac_i2c->irq, ret);
  1454. goto err_fw_update;
  1455. }
  1456. #if defined(WACOM_PDCT_WORK_AROUND)
  1457. ret = request_threaded_irq(wac_i2c->irq_pdct, NULL,
  1458. wacom_interrupt_pdct,
  1459. IRQF_DISABLED | IRQF_TRIGGER_RISING |
  1460. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  1461. wac_i2c->name, wac_i2c);
  1462. if (ret < 0) {
  1463. dev_err(&wac_i2c->client->dev,
  1464. "%s: failed to request irq(%d) - %d\n",
  1465. __func__, wac_i2c->irq_pdct, ret);
  1466. goto err_request_irq_pdct;
  1467. }
  1468. #endif
  1469. #ifdef WACOM_PEN_DETECT
  1470. ret = request_threaded_irq(
  1471. wac_i2c->irq_pen_insert, NULL,
  1472. wacom_pen_detect,
  1473. IRQF_DISABLED | IRQF_TRIGGER_RISING |
  1474. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  1475. "pen_insert", wac_i2c);
  1476. if (ret < 0) {
  1477. dev_err(&wac_i2c->client->dev,
  1478. "%s: failed to request irq(%d) - %d\n",
  1479. __func__, wac_i2c->irq_pen_insert, ret);
  1480. goto err_request_irq_pen_inster;
  1481. }
  1482. enable_irq_wake(wac_i2c->irq_pen_insert);
  1483. /* update the current status */
  1484. schedule_delayed_work(&wac_i2c->pen_insert_dwork, HZ / 2);
  1485. #endif
  1486. }
  1487. #ifdef USE_WACOM_LCD_WORKAROUND
  1488. schedule_delayed_work(&wac_i2c->boot_done_work,
  1489. msecs_to_jiffies(20 * 1000));
  1490. #endif
  1491. #ifdef WACOM_RESETPIN_DELAY
  1492. schedule_delayed_work(&wac_i2c->work_wacom_reset, msecs_to_jiffies(5000));
  1493. #endif
  1494. #ifdef CONFIG_FB
  1495. wac_i2c->fb_disabled = false;
  1496. wac_i2c->fb_notif.notifier_call = fb_notifier_callback;
  1497. if (fb_register_client(&wac_i2c->fb_notif))
  1498. pr_err("%s: could not create fb notifier\n", __func__);
  1499. #endif
  1500. return 0;
  1501. err_request_irq_pen_inster:
  1502. #ifdef WACOM_PDCT_WORK_AROUND
  1503. free_irq(wac_i2c->irq_pdct, wac_i2c);
  1504. err_request_irq_pdct:
  1505. #endif
  1506. free_irq(wac_i2c->irq, wac_i2c);
  1507. err_fw_update:
  1508. sysfs_remove_group(&wac_i2c->dev->kobj, &epen_attr_group);
  1509. err_sysfs_create_group:
  1510. wac_i2c->init_fail = true;
  1511. input_unregister_device(input);
  1512. err_input_allocate_device:
  1513. cancel_delayed_work_sync(&wac_i2c->resume_work);
  1514. cancel_delayed_work_sync(&wac_i2c->touch_pressed_work);
  1515. #ifdef USE_WACOM_LCD_WORKAROUND
  1516. cancel_delayed_work_sync(&wac_i2c->read_vsync_work);
  1517. cancel_delayed_work_sync(&wac_i2c->boot_done_work);
  1518. #endif
  1519. cancel_delayed_work_sync(&wac_i2c->pen_insert_dwork);
  1520. #ifdef WACOM_RESETPIN_DELAY
  1521. cancel_delayed_work_sync(&wac_i2c->work_wacom_reset);
  1522. #endif
  1523. #ifdef WACOM_BOOSTER
  1524. cancel_delayed_work_sync(&wac_i2c->work_dvfs_off);
  1525. cancel_delayed_work_sync(&wac_i2c->work_dvfs_chg);
  1526. mutex_destroy(&wac_i2c->dvfs_lock);
  1527. #endif
  1528. wac_i2c->wac_pdata->wacom_stop(wac_i2c);
  1529. mutex_destroy(&wac_i2c->lock);
  1530. err_wacom_i2c_bootloader_ver:
  1531. #if defined(CONFIG_SEC_H_PROJECT) || defined(CONFIG_SEC_FRESCO_PROJECT)
  1532. err_wacom_i2c_send_timeout:
  1533. #endif
  1534. input_free_device(input);
  1535. err_freemem:
  1536. kfree(wac_i2c);
  1537. err_i2c_fail:
  1538. return ret;
  1539. }
  1540. #ifdef CONFIG_FB
  1541. static int fb_notifier_callback(struct notifier_block *self,
  1542. unsigned long event, void *data)
  1543. {
  1544. struct fb_event *evdata = data;
  1545. struct wacom_i2c *wac_i2c = container_of(self, struct wacom_i2c, fb_notif);
  1546. if (evdata && evdata->data && event == FB_EVENT_BLANK) {
  1547. int *blank = evdata->data;
  1548. switch (*blank) {
  1549. case FB_BLANK_UNBLANK:
  1550. case FB_BLANK_NORMAL:
  1551. case FB_BLANK_VSYNC_SUSPEND:
  1552. case FB_BLANK_HSYNC_SUSPEND:
  1553. wac_i2c->fb_disabled = false;
  1554. wacom_i2c_enable(wac_i2c);
  1555. break;
  1556. case FB_BLANK_POWERDOWN:
  1557. wac_i2c->fb_disabled = true;
  1558. wacom_i2c_disable(wac_i2c);
  1559. break;
  1560. default:
  1561. /* Don't handle what we don't understand */
  1562. break;
  1563. }
  1564. }
  1565. return 0;
  1566. }
  1567. #endif
  1568. static const struct i2c_device_id wacom_i2c_id[] = {
  1569. {"wacom_g5sp_i2c", 0},
  1570. {},
  1571. };
  1572. #ifdef CONFIG_OF
  1573. static struct of_device_id wacom_match_table[] = {
  1574. { .compatible = "wacom,wacom_i2c-ts",},
  1575. { },
  1576. };
  1577. #else
  1578. #define wacom_match_table NULL
  1579. #endif
  1580. /*Create handler for wacom_i2c_driver*/
  1581. static struct i2c_driver wacom_i2c_driver = {
  1582. .driver = {
  1583. .name = "wacom_g5sp_i2c",
  1584. #ifdef CONFIG_OF
  1585. .of_match_table = wacom_match_table,
  1586. #endif
  1587. },
  1588. .probe = wacom_i2c_probe,
  1589. .remove = wacom_i2c_remove,
  1590. .id_table = wacom_i2c_id,
  1591. };
  1592. /*
  1593. module_i2c_driver(wacom_i2c_driver);
  1594. */
  1595. static int __init wacom_i2c_init(void)
  1596. {
  1597. int ret = 0;
  1598. /*
  1599. #if defined(WACOM_SLEEP_WITH_PEN_SLP)
  1600. printk(KERN_ERR "[E-PEN] %s: Sleep type-PEN_SLP pin\n", __func__);
  1601. #elif defined(WACOM_SLEEP_WITH_PEN_LDO_EN)
  1602. printk(KERN_ERR "[E-PEN] %s: Sleep type-PEN_LDO_EN pin\n", __func__);
  1603. #endif
  1604. */
  1605. #ifdef CONFIG_SAMSUNG_LPM_MODE
  1606. if (poweroff_charging) {
  1607. pr_notice("%s : LPM Charging Mode!!\n", __func__);
  1608. return 0;
  1609. }
  1610. #endif
  1611. ret = i2c_add_driver(&wacom_i2c_driver);
  1612. if (ret)
  1613. printk(KERN_ERR "[E-PEN] fail to i2c_add_driver\n");
  1614. return ret;
  1615. }
  1616. static void __exit wacom_i2c_exit(void)
  1617. {
  1618. i2c_del_driver(&wacom_i2c_driver);
  1619. }
  1620. module_init(wacom_i2c_init);
  1621. module_exit(wacom_i2c_exit);
  1622. MODULE_AUTHOR("Samsung");
  1623. MODULE_DESCRIPTION("Driver for Wacom G5SP Digitizer Controller");
  1624. MODULE_LICENSE("GPL");