mms134S_ts.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863
  1. /*
  2. * Copyright (C) 2010 Melfas, Inc.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/delay.h>
  16. #include <linux/earlysuspend.h>
  17. #include <linux/hrtimer.h>
  18. #include <linux/i2c.h>
  19. #include <linux/input.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/io.h>
  22. #include <linux/slab.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/i2c/mms134S_ts.h>
  25. #include <linux/mfd/pmic8058.h>
  26. #include <linux/cpufreq.h>
  27. #include <asm-generic/uaccess.h>
  28. #include <asm/unaligned.h>
  29. #include <linux/gpio.h>
  30. #include <linux/of_gpio.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <linux/miscdevice.h>
  33. #include <linux/ioctl.h>
  34. #include <linux/string.h>
  35. #include <linux/semaphore.h>
  36. #include <linux/kthread.h>
  37. #include <linux/timer.h>
  38. #include <linux/workqueue.h>
  39. #include <linux/firmware.h>
  40. #include <linux/input/mt.h>
  41. #include <asm/io.h>
  42. #include <../mach-msm/smd_private.h>
  43. #include <../mach-msm/smd_rpcrouter.h>
  44. #define USE_OPEN_CLOSE
  45. #define TOUCH_BOOSTER
  46. #undef TSP_PATTERN_TRACTKING
  47. #define SEC_TSP_FACTORY_TEST
  48. #define SEC_TKEY_FACTORY_TEST
  49. #define TSP_BUF_SIZE 1024
  50. #undef ENABLE_NOISE_TEST_MODE
  51. #define FW_IMAGE_NAME_UMS "/sdcard/melfas.fw"
  52. #define FW_IMAGE_NAME_OLD "tsp_melfas/kanas_mms134s_old.fw"
  53. #define FW_IMAGE_NAME_NEW "tsp_melfas/kanas_mms134s_new.fw"
  54. #define FW_IMAGE_NAME_NULL NULL
  55. #define TS_WRITE_REGS_LEN 16
  56. #define TS_READ_REGS_LEN 66
  57. #ifdef TOUCH_BOOSTER
  58. #define TOUCH_BOOSTER_OFF_TIME 100
  59. #define TOUCH_BOOSTER_CHG_TIME 200
  60. #endif
  61. #define TS_MAX_Z_TOUCH 255
  62. #define TS_MAX_W_TOUCH 100
  63. #define FW_IMAGE_NAME_UMS "/sdcard/melfas.fw"
  64. #define FW_IMAGE_NAME_OLD "tsp_melfas/kanas_mms134s_old.fw"
  65. #define FW_IMAGE_NAME_NEW "tsp_melfas/kanas_mms134s_new.fw"
  66. #define FW_IMAGE_NAME_NULL NULL
  67. #define NUM_OF_TOUCHKEY 2
  68. #define PRESS_KEY 1
  69. #define RELEASE_KEY 0
  70. #define MELFAS_MAX_TOUCH 5
  71. #define DOWNLOAD_RETRY_CNT 1
  72. /* Melfas RMI Map */
  73. #define MMS_MIP_CONTACT_ON_EVENT_THRES 0x05
  74. #define MMS_MIP_MOVING_EVENT_THRES 0x06
  75. #define MMS_MIP_ACTIVE_REPORT_RATE 0x07
  76. #define MMS_MIP_POSITION_FILTER_LEVEL 0x08
  77. #define MMS_MIP_EVENT_PACKET_LENGTH 0x0F
  78. #define MMS_MIP_EVENT_PACKET 0x10
  79. #define MMS_CMD_ENTER_ISC 0x5F
  80. #define MMS_FW_VERSION 0xE1
  81. #define MMS_UNIVERSAL_CMD 0xA0
  82. #define MMS_UNIVERSAL_RESULT 0xAF
  83. #define MMS_UNIVERSAL_RESULT_LENGTH 0xAE
  84. #define MMS_UNIV_ENTER_TEST 0x40
  85. #define MMS_UNIV_TEST_CM_DELTA 0x41
  86. #define MMS_UNIV_GET_CM_DELTA 0x42
  87. #define MMS_UNIV_TEST_CM_ABS 0x43
  88. #define MMS_UNIV_GET_CM_ABS 0x44
  89. #define MMS_UNIV_TEST_CM_JITTER 0x45
  90. #define MMS_UNIV_GET_CM_JITTER 0x46
  91. #define MMS_UNIV_KEY_GET_CM_DELTA 0x4A
  92. #define MMS_UNIV_KEY_GET_CM_ABS 0x4B
  93. #define MMS_UNIV_KEY_GET_CM_JITTER 0x4C
  94. #define MMS_UNIV_EXIT_TEST 0x4F
  95. #define MMS_UNIV_INTENSITY 0x70
  96. #define MMS_UNIV_KEY_INTENSITY 0x71
  97. #define MMS_UNIV_REFERENCE 0x72
  98. #define MMS_UNIV_KEY_REFERENCE 0x73
  99. #ifdef CONFIG_SAMSUNG_PRODUCT_SHIP
  100. #define MELFAS_DEBUG_PRINT 0
  101. #define FLASH_VERBOSE_DEBUG 0
  102. #else
  103. #define MELFAS_DEBUG_PRINT 1
  104. #define FLASH_VERBOSE_DEBUG 1
  105. #endif
  106. #ifdef SEC_TSP_FACTORY_TEST
  107. #define TEST_CODE 0
  108. #define TSP_CMD_STR_LEN 32
  109. #define TSP_CMD_RESULT_STR_LEN 512
  110. #define TSP_CMD_PARAM_NUM 8
  111. #endif /* SEC_TSP_FACTORY_TEST */
  112. /* FW_UPDATE define START*/
  113. enum {
  114. FW_UPDATE_BUILT_IN = 0,
  115. FW_UPDATE_UMS,
  116. };
  117. /* ISC_XFER_LEN - ISC unit transfer length. Give number of 2 power n, where n is between 2 and 10 */
  118. #define ISC_XFER_LEN 256
  119. #define MMS_FLASH_PAGE_SZ 1024
  120. #define ISC_BLOCK_NUM (MMS_FLASH_PAGE_SZ / ISC_XFER_LEN)
  121. enum {
  122. BOOT_SECTION = 0,
  123. CORE_SECTION = 1,
  124. CONFIG_SECTION = 2,
  125. MAX_SECTION_NUM = 3,
  126. };
  127. enum {
  128. ISC_ADDR = 0xD5,
  129. ISC_CMD_READ_STATUS = 0xD9,
  130. ISC_CMD_READ = 0x4000,
  131. ISC_CMD_EXIT = 0x8200,
  132. ISC_CMD_PAGE_ERASE = 0xC000,
  133. ISC_CMD_ERASE = 0xC100,
  134. ISC_PAGE_ERASE_DONE = 0x10000,
  135. ISC_PAGE_ERASE_ENTER = 0x20000,
  136. };
  137. struct mms_bin_hdr {
  138. char tag[8];
  139. u16 core_version;
  140. u16 section_num;
  141. u16 contains_full_binary;
  142. u16 reserved0;
  143. u32 binary_offset;
  144. u32 binary_length;
  145. u32 extention_offset;
  146. u32 reserved1;
  147. } __attribute__ ((packed));
  148. struct mms_fw_img {
  149. u16 type;
  150. u16 version;
  151. u16 start_page;
  152. u16 end_page;
  153. u32 offset;
  154. u32 length;
  155. } __attribute__ ((packed));
  156. struct isc_packet {
  157. u8 cmd;
  158. u32 addr;
  159. u8 data[0];
  160. } __attribute__ ((packed));
  161. /* FW_UPDATE define END*/
  162. int touch_is_pressed;
  163. bool mms134s_initialized = 0;
  164. #define TSP_DEVICE_NAME "sec_touchscreen"
  165. #define TSP_DEVICE_NAME2 "mms_ts"
  166. enum {
  167. None = 0,
  168. TOUCH_SCREEN,
  169. TOUCH_KEY
  170. };
  171. struct mms_ts_touch_info {
  172. int strength;
  173. int width;
  174. int posX;
  175. int posY;
  176. unsigned char state;
  177. unsigned short mcount;
  178. };
  179. struct mms_btn_map {
  180. unsigned char nbuttons;
  181. u32 map[NUM_OF_TOUCHKEY];
  182. s16 intensity[NUM_OF_TOUCHKEY];
  183. bool pressed[NUM_OF_TOUCHKEY];
  184. };
  185. struct mms_ts_dt_data {
  186. int coords[2];
  187. int irq_gpio;
  188. int scl_gpio;
  189. int sda_gpio;
  190. int vdd_gpio;
  191. struct mms_btn_map *btn;
  192. };
  193. struct mms_ts_info {
  194. uint16_t addr;
  195. struct i2c_client *client;
  196. struct input_dev *input_dev;
  197. struct mms_ts_dt_data *dt_data;
  198. struct mms_ts_touch_info finger[MELFAS_MAX_TOUCH];
  199. int irq;
  200. bool tsp_enabled;
  201. struct mutex lock;
  202. bool noise_mode;
  203. bool ta_status;
  204. u8 fw_ic_ver;
  205. const u8 *config_fw_version;
  206. int tx_num;
  207. int rx_num;
  208. u8 fw_ver_boot_bin;
  209. u8 fw_ver_core_bin;
  210. u8 fw_ver_config_bin;
  211. u8 fw_ver_boot_ic;
  212. u8 fw_ver_core_ic;
  213. u8 fw_ver_config_ic;
  214. const char *fw_path;
  215. const struct firmware *fw_img;
  216. #ifdef CONFIG_HAS_EARLYSUSPEND
  217. struct early_suspend early_suspend;
  218. #endif
  219. #ifdef TOUCH_BOOSTER
  220. struct delayed_work work_dvfs_off;
  221. struct delayed_work work_dvfs_chg;
  222. bool dvfs_lock_status;
  223. struct mutex dvfs_lock;
  224. #endif
  225. #ifdef SEC_TSP_FACTORY_TEST
  226. struct list_head cmd_list_head;
  227. u8 cmd_state;
  228. char cmd[TSP_CMD_STR_LEN];
  229. int cmd_param[TSP_CMD_PARAM_NUM];
  230. char cmd_result[TSP_CMD_RESULT_STR_LEN];
  231. struct mutex cmd_lock;
  232. bool cmd_is_running;
  233. s16 *reference;
  234. s16 *cm_abs;
  235. s16 *cm_delta;
  236. s16 *intensity;
  237. struct device *tsp_dev;
  238. #endif /* SEC_TSP_FACTORY_TEST */
  239. #ifdef SEC_TKEY_FACTORY_TEST
  240. struct device *tkey_dev;
  241. #endif
  242. };
  243. static struct mms_ts_info *g_info = NULL;
  244. extern struct class *sec_class;
  245. #define SEC_CLASS_DEVT_TSP 10
  246. #define SEC_CLASS_DEVT_TKEY 11
  247. static int melfas_ts_start(struct mms_ts_info *info);
  248. static int melfas_ts_stop(struct mms_ts_info *info);
  249. #ifdef CONFIG_HAS_EARLYSUSPEND
  250. static void melfas_ts_early_suspend(struct early_suspend *h);
  251. static void melfas_ts_late_resume(struct early_suspend *h);
  252. #endif
  253. #ifdef USE_OPEN_CLOSE
  254. static void melfas_ts_input_close(struct input_dev *dev);
  255. static int melfas_ts_input_open(struct input_dev *dev);
  256. #endif
  257. #ifdef SEC_TSP_FACTORY_TEST
  258. enum CMD_STATUS {
  259. CMD_STATUS_WAITING = 0,
  260. CMD_STATUS_RUNNING,
  261. CMD_STATUS_OK,
  262. CMD_STATUS_FAIL,
  263. CMD_STATUS_NOT_APPLICABLE,
  264. };
  265. #define TSP_CMD(name, func) .cmd_name = name, .cmd_func = func
  266. struct tsp_cmd {
  267. struct list_head list;
  268. const char *cmd_name;
  269. void (*cmd_func)(void *device_data);
  270. };
  271. static void fw_update(void *device_data);
  272. static void get_fw_ver_bin(void *device_data);
  273. static void get_fw_ver_ic(void *device_data);
  274. static void get_config_ver(void *device_data);
  275. static void get_threshold(void *device_data);
  276. static void module_off_master(void *device_data);
  277. static void module_on_master(void *device_data);
  278. static void get_chip_vendor(void *device_data);
  279. static void get_chip_name(void *device_data);
  280. static void get_reference(void *device_data);
  281. static void get_cm_abs(void *device_data);
  282. static void get_cm_delta(void *device_data);
  283. static void get_intensity(void *device_data);
  284. static void get_x_num(void *device_data);
  285. static void get_y_num(void *device_data);
  286. static void run_reference_read(void *device_data);
  287. static void run_cm_abs_read(void *device_data);
  288. static void run_cm_delta_read(void *device_data);
  289. static void run_intensity_read(void *device_data);
  290. static void not_support_cmd(void *device_data);
  291. static struct tsp_cmd tsp_cmds[] = {
  292. {TSP_CMD("fw_update", fw_update),},
  293. {TSP_CMD("get_fw_ver_bin", get_fw_ver_bin),},
  294. {TSP_CMD("get_fw_ver_ic", get_fw_ver_ic),},
  295. {TSP_CMD("get_config_ver", get_config_ver),},
  296. {TSP_CMD("get_threshold", get_threshold),},
  297. {TSP_CMD("module_off_master", module_off_master),},
  298. {TSP_CMD("module_on_master", module_on_master),},
  299. {TSP_CMD("module_off_slave", not_support_cmd),},
  300. {TSP_CMD("module_on_slave", not_support_cmd),},
  301. {TSP_CMD("get_chip_vendor", get_chip_vendor),},
  302. {TSP_CMD("get_chip_name", get_chip_name),},
  303. {TSP_CMD("get_x_num", get_x_num),},
  304. {TSP_CMD("get_y_num", get_y_num),},
  305. {TSP_CMD("get_reference", get_reference),},
  306. {TSP_CMD("get_cm_abs", get_cm_abs),},
  307. {TSP_CMD("get_cm_delta", get_cm_delta),},
  308. {TSP_CMD("get_intensity", get_intensity),},
  309. {TSP_CMD("run_reference_read", run_reference_read),},
  310. {TSP_CMD("run_cm_abs_read", run_cm_abs_read),},
  311. {TSP_CMD("run_cm_delta_read", run_cm_delta_read),},
  312. {TSP_CMD("run_intensity_read", run_intensity_read),},
  313. {TSP_CMD("not_support_cmd", not_support_cmd),},
  314. };
  315. #endif
  316. #ifdef TOUCH_BOOSTER
  317. static void change_dvfs_lock(struct work_struct *work)
  318. {
  319. struct mms_ts_info *info = container_of(work,
  320. struct mms_ts_info, work_dvfs_chg.work);
  321. int ret;
  322. mutex_lock(&info->dvfs_lock);
  323. ret = set_freq_limit(DVFS_TOUCH_ID, 998400);
  324. mutex_unlock(&info->dvfs_lock);
  325. if (ret < 0)
  326. dev_err(&info->client->dev, "%s: 1booster stop failed(%d)\n",
  327. __func__, __LINE__);
  328. else
  329. dev_info(&info->client->dev, "%s\n", __func__);
  330. }
  331. static void set_dvfs_off(struct work_struct *work)
  332. {
  333. struct mms_ts_info *info = container_of(work,
  334. struct mms_ts_info, work_dvfs_off.work);
  335. mutex_lock(&info->dvfs_lock);
  336. set_freq_limit(DVFS_TOUCH_ID, -1);
  337. info->dvfs_lock_status = false;
  338. mutex_unlock(&info->dvfs_lock);
  339. }
  340. static void set_dvfs_lock(struct mms_ts_info *info, uint32_t on)
  341. {
  342. int ret = 0;
  343. mutex_lock(&info->dvfs_lock);
  344. if (on == 0) {
  345. if (info->dvfs_lock_status) {
  346. schedule_delayed_work(&info->work_dvfs_off,
  347. msecs_to_jiffies(TOUCH_BOOSTER_OFF_TIME));
  348. }
  349. } else if (on == 1) {
  350. cancel_delayed_work(&info->work_dvfs_off);
  351. if (!info->dvfs_lock_status) {
  352. ret = set_freq_limit(DVFS_TOUCH_ID, 998400);
  353. if (ret < 0)
  354. dev_err(&info->client->dev, "%s: cpu lock failed(%d)\n",
  355. __func__, ret);
  356. info->dvfs_lock_status = true;
  357. }
  358. } else if (on == 2) {
  359. cancel_delayed_work(&info->work_dvfs_off);
  360. schedule_work(&info->work_dvfs_off.work);
  361. }
  362. mutex_unlock(&info->dvfs_lock);
  363. }
  364. #endif
  365. static int melfas_i2c_write(struct i2c_client *client, char *buf, int length);
  366. static void melfas_ts_reboot(void);
  367. static void melfas_ts_reboot_after_update(void);
  368. static void melfas_ts_power_enable(int en)
  369. {
  370. #if defined(CONFIG_MACH_KANAS3G_CTC)
  371. static struct regulator* ldo22;
  372. int rc = 0;
  373. printk(KERN_ERR "%s: (%d)\n", __func__, en);
  374. if(!ldo22){
  375. ldo22 = regulator_get(NULL,"vdd_l22");
  376. rc = regulator_set_voltage(ldo22,3000000,3000000);
  377. if (rc){
  378. printk(KERN_ERR "%s: TSP set_level failed (%d)\n",__func__, rc);
  379. }
  380. }
  381. if(en){
  382. if(regulator_is_enabled(ldo22))
  383. {
  384. printk(KERN_ERR "%s: TSP power already enable\n", __func__);
  385. return;
  386. }
  387. rc = regulator_enable(ldo22);
  388. if(rc)
  389. printk(KERN_ERR "%s: TSP power enable failed (%d)\n", __func__, rc);
  390. } else {
  391. if(!regulator_is_enabled(ldo22))
  392. {
  393. printk(KERN_ERR "%s: TSP power already disable\n", __func__);
  394. return;
  395. }
  396. rc = regulator_disable(ldo22);
  397. if(rc)
  398. printk(KERN_ERR "%s: TSP power disable failed (%d)\n", __func__, rc);
  399. }
  400. #else
  401. dev_info(&g_info->client->dev, "%s: (%d)\n", __func__, en);
  402. gpio_direction_output(g_info->dt_data->vdd_gpio, en);
  403. #endif
  404. }
  405. #ifdef TSP_PATTERN_TRACTKING
  406. /* To do forced calibration when ghost touch occured at the same point
  407. for several second. */
  408. #define MAX_GHOSTCHECK_FINGER 10
  409. #define MAX_GHOSTTOUCH_COUNT 300
  410. #define MAX_GHOSTTOUCH_BY_PATTERNTRACKING 5
  411. static int tcount_finger[MAX_GHOSTCHECK_FINGER] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  412. static int touchbx[MAX_GHOSTCHECK_FINGER] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  413. static int touchby[MAX_GHOSTCHECK_FINGER] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  414. static int ghosttouchcount;
  415. static int cFailbyPattenTracking;
  416. static void clear_tcount(void)
  417. {
  418. int i;
  419. for (i = 0; i < MAX_GHOSTCHECK_FINGER; i++) {
  420. tcount_finger[i] = 0;
  421. touchbx[i] = 0;
  422. touchby[i] = 0;
  423. }
  424. }
  425. static int diff_two_point(int x, int y, int oldx, int oldy)
  426. {
  427. int diffx, diffy;
  428. int distance;
  429. diffx = x-oldx;
  430. diffy = y-oldy;
  431. distance = abs(diffx) + abs(diffy);
  432. if (distance < 3)
  433. return 1;
  434. else
  435. return 0;
  436. }
  437. static int tsp_pattern_tracking(struct mms_ts_info *info, int fingerindex, int x, int y)
  438. {
  439. int i;
  440. int ghosttouch = 0;
  441. if (i == fingerindex) {
  442. if (diff_two_point (x, y, touchbx[i], touchby[i])) {
  443. tcount_finger[i] = tcount_finger[i]+1;
  444. } else {
  445. tcount_finger[i] = 0;
  446. }
  447. touchbx[i] = x;
  448. touchby[i] = y;
  449. if (tcount_finger[i] > MAX_GHOSTTOUCH_COUNT) {
  450. ghosttouch = 1;
  451. ghosttouchcount++;
  452. dev_dbg(&info->client->dev, "SUNFLOWER (PATTERN TRACKING) %d\n", ghosttouchcount);
  453. clear_tcount();
  454. cFailbyPattenTracking++;
  455. if (cFailbyPattenTracking > MAX_GHOSTTOUCH_BY_PATTERNTRACKING) {
  456. cFailbyPattenTracking = 0;
  457. dev_info(&info->client->dev, "Reboot.\n");
  458. melfas_ts_reboot();
  459. } else {
  460. /* Do something for calibration */
  461. }
  462. }
  463. }
  464. return ghosttouch;
  465. }
  466. #endif
  467. static int mms_isc_read_status(struct i2c_client *client, u32 val)
  468. {
  469. u8 cmd = ISC_CMD_READ_STATUS;
  470. u32 result = 0;
  471. int cnt = 100;
  472. int ret = 0;
  473. do {
  474. i2c_smbus_read_i2c_block_data(client, cmd, 4, (u8 *)&result);
  475. if (result == val)
  476. break;
  477. msleep(1);
  478. } while (--cnt);
  479. if (!cnt) {
  480. dev_err(&client->dev,
  481. "status read fail. cnt : %d, val : 0x%x != 0x%x\n",
  482. cnt, result, val);
  483. }
  484. return ret;
  485. }
  486. static int mms_isc_transfer_cmd(struct i2c_client *client, int cmd)
  487. {
  488. struct isc_packet pkt = { ISC_ADDR, cmd };
  489. struct i2c_msg msg = {
  490. .addr = client->addr,
  491. .flags = 0,
  492. .len = sizeof(struct isc_packet),
  493. .buf = (u8 *)&pkt,
  494. };
  495. return (i2c_transfer(client->adapter, &msg, 1) != 1);
  496. }
  497. static int mms_isc_erase_page(struct i2c_client *client, int page)
  498. {
  499. return mms_isc_transfer_cmd(client, ISC_CMD_PAGE_ERASE | page) ||
  500. mms_isc_read_status(client, ISC_PAGE_ERASE_DONE | ISC_PAGE_ERASE_ENTER | page);
  501. }
  502. static int mms_isc_enter(struct i2c_client *client)
  503. {
  504. dev_info(&client->dev, "%s\n", __func__);
  505. return i2c_smbus_write_byte_data(client, MMS_CMD_ENTER_ISC, true);
  506. }
  507. static int mms_isc_exit(struct i2c_client *client)
  508. {
  509. dev_info(&client->dev, "%s\n", __func__);
  510. return mms_isc_transfer_cmd(client, ISC_CMD_EXIT);
  511. }
  512. static int mms_flash_section(struct i2c_client *client, struct mms_fw_img *img, const u8 *data)
  513. {
  514. struct isc_packet *isc_packet;
  515. int ret;
  516. int page, i;
  517. struct i2c_msg msg[2] = {
  518. {
  519. .addr = client->addr,
  520. .flags = 0,
  521. }, {
  522. .addr = client->addr,
  523. .flags = I2C_M_RD,
  524. .len = ISC_XFER_LEN,
  525. },
  526. };
  527. int ptr = img->offset;
  528. isc_packet = kzalloc(sizeof(*isc_packet) + ISC_XFER_LEN, GFP_KERNEL);
  529. isc_packet->cmd = ISC_ADDR;
  530. msg[0].buf = (u8 *)isc_packet;
  531. msg[1].buf = kzalloc(ISC_XFER_LEN, GFP_KERNEL);
  532. for (page = img->start_page; page <= img->end_page; page++) {
  533. mms_isc_erase_page(client, page);
  534. for (i = 0; i < ISC_BLOCK_NUM; i++, ptr += ISC_XFER_LEN) {
  535. /* flash firmware */
  536. u32 tmp = page * 256 + i * (ISC_XFER_LEN / 4);
  537. put_unaligned_le32(tmp, &isc_packet->addr);
  538. msg[0].len = sizeof(struct isc_packet) + ISC_XFER_LEN;
  539. memcpy(isc_packet->data, data + ptr, ISC_XFER_LEN);
  540. if (i2c_transfer(client->adapter, msg, 1) != 1)
  541. goto i2c_err;
  542. /* verify firmware */
  543. tmp |= ISC_CMD_READ;
  544. put_unaligned_le32(tmp, &isc_packet->addr);
  545. msg[0].len = sizeof(struct isc_packet);
  546. if (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) != ARRAY_SIZE(msg))
  547. goto i2c_err;
  548. if (memcmp(isc_packet->data, msg[1].buf, ISC_XFER_LEN)) {
  549. #if FLASH_VERBOSE_DEBUG
  550. print_hex_dump(KERN_ERR, "mms fw wr : ",
  551. DUMP_PREFIX_OFFSET, 16, 1,
  552. isc_packet->data, ISC_XFER_LEN, false);
  553. print_hex_dump(KERN_ERR, "mms fw rd : ",
  554. DUMP_PREFIX_OFFSET, 16, 1,
  555. msg[1].buf, ISC_XFER_LEN, false);
  556. #endif
  557. dev_err(&client->dev, "flash verify failed\n");
  558. ret = -1;
  559. goto out;
  560. }
  561. }
  562. }
  563. dev_info(&client->dev, "%s: section[%d] update succeeded\n", __func__, img->type);
  564. ret = 0;
  565. goto out;
  566. i2c_err:
  567. dev_err(&client->dev, "%s: i2c failed\n", __func__);
  568. ret = -1;
  569. out:
  570. kfree(isc_packet);
  571. kfree(msg[1].buf);
  572. return ret;
  573. }
  574. static int get_fw_version(struct i2c_client *client, u8 *buf)
  575. {
  576. u8 cmd = MMS_FW_VERSION;
  577. struct i2c_msg msg[2] = {
  578. {
  579. .addr = client->addr,
  580. .flags = 0,
  581. .buf = &cmd,
  582. .len = 1,
  583. }, {
  584. .addr = client->addr,
  585. .flags = I2C_M_RD,
  586. .buf = buf,
  587. .len = MAX_SECTION_NUM,
  588. },
  589. };
  590. return (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) != ARRAY_SIZE(msg));
  591. }
  592. static int mms_flash_fw(struct mms_ts_info *info, bool force)
  593. {
  594. struct i2c_client *client = info->client;
  595. int ret =0;
  596. int i;
  597. struct mms_bin_hdr *fw_hdr;
  598. struct mms_fw_img **img;
  599. u8 ver[MAX_SECTION_NUM];
  600. u8 target[MAX_SECTION_NUM];
  601. int offset = sizeof(struct mms_bin_hdr);
  602. int retires = 3;
  603. bool update_flag = false;
  604. bool isc_flag = true;
  605. fw_hdr = (struct mms_bin_hdr *)info->fw_img->data;
  606. img = kzalloc(sizeof(*img) * fw_hdr->section_num, GFP_KERNEL);
  607. dev_info(&client->dev, "%s[%d]: FW:(%d,%d,%d,%d) \n", __func__, force,
  608. (u8)fw_hdr->core_version, (u8)fw_hdr->contains_full_binary,
  609. (u8)fw_hdr->reserved0, (u8)fw_hdr->section_num);
  610. while (retires--) {
  611. if (!get_fw_version(client, ver))
  612. break;
  613. else
  614. melfas_ts_reboot_after_update();
  615. }
  616. if (retires < 0) {
  617. dev_warn(&client->dev, "failed to obtain ver. info\n");
  618. isc_flag = false;
  619. memset(ver, 0xff, sizeof(ver));
  620. } else {
  621. dev_err(&client->dev, "%s: IC Ver %02x,%02x,%02x \n", __func__, ver[0], ver[1], ver[2]);
  622. }
  623. info->fw_ver_boot_ic = ver[BOOT_SECTION];
  624. info->fw_ver_core_ic = ver[CORE_SECTION];
  625. info->fw_ver_config_ic = ver[CONFIG_SECTION];
  626. info->fw_ver_core_bin = fw_hdr->core_version;
  627. for (i = 0; i < fw_hdr->section_num; i++, offset += sizeof(struct mms_fw_img)) {
  628. img[i] = (struct mms_fw_img *)(info->fw_img->data + offset);
  629. target[i] = img[i]->version;
  630. dev_info(&client->dev, "%s: section[%d] Check IC:0x%02x, BIN:0x%02x\n",
  631. __func__, img[i]->type, (ver[img[i]->type]), target[i]);
  632. if (!force) {
  633. if (i == 0)
  634. info->fw_ver_boot_bin = target[i];
  635. else if (i == 1)
  636. info->fw_ver_config_bin = target[i];
  637. }
  638. /* Update condition
  639. * - IC ver: 0xff: fw crack, cannot read ver
  640. * - IC ver < BIN ver
  641. * - force: true */
  642. if ((ver[img[i]->type] == 0xff) || (ver[img[i]->type] < target[i]) || force) {
  643. if (isc_flag) {
  644. mms_isc_enter(client);
  645. isc_flag = false;
  646. }
  647. update_flag = true;
  648. ret = mms_flash_section(client, img[i], info->fw_img->data + fw_hdr->binary_offset);
  649. if (ret < 0) {
  650. dev_err(&client->dev,
  651. "%s: section[%d] fw update is failed.\n",
  652. __func__, img[i]->type);
  653. melfas_ts_reboot_after_update();
  654. goto out;
  655. }
  656. } else {
  657. dev_info(&client->dev, "%s: section[%d] do not update\n",
  658. __func__, img[i]->type);
  659. }
  660. }
  661. if (update_flag){
  662. mms_isc_exit(client);
  663. msleep(5);
  664. melfas_ts_reboot_after_update();
  665. } else {
  666. ret = 0;
  667. goto out;
  668. }
  669. if (get_fw_version(client, ver)) {
  670. dev_err(&client->dev, "%s: failed to obtain version after flash\n", __func__);
  671. ret = -1;
  672. goto out;
  673. } else {
  674. info->fw_ver_boot_ic = ver[BOOT_SECTION];
  675. info->fw_ver_core_ic = ver[CORE_SECTION];
  676. info->fw_ver_config_ic = ver[CONFIG_SECTION];
  677. for (i = 0; i < fw_hdr->section_num; i++) {
  678. if (ver[img[i]->type] != target[i]) {
  679. dev_err(&client->dev,
  680. "%s: version mismatch after flash. [%d] 0x%02x != 0x%02x\n",
  681. __func__, img[i]->type, ver[img[i]->type], target[i]);
  682. ret = -1;
  683. goto out;
  684. }
  685. }
  686. }
  687. ret = 0;
  688. out:
  689. dev_info(&info->client->dev, "%s: succeeded. IC[%02x%02x%02x], BIN[%02x%02x%02x]\n", __func__,
  690. info->fw_ver_boot_ic, info->fw_ver_core_ic, info->fw_ver_config_ic,
  691. info->fw_ver_boot_bin,info->fw_ver_core_bin, info->fw_ver_config_bin);
  692. kfree(img);
  693. return ret;
  694. }
  695. static int melfas_ts_fw_update(struct mms_ts_info *info,
  696. const struct firmware *fw_data, bool force)
  697. {
  698. int retires = 3;
  699. int ret;
  700. if (!fw_data) {
  701. dev_err(&info->client->dev, "%s: Firmware data is NULL\n", __func__);
  702. return -ENODEV;
  703. }
  704. info->fw_img = fw_data;
  705. do {
  706. ret = mms_flash_fw(info, force);
  707. } while (ret && --retires);
  708. if (!retires) {
  709. dev_err(&info->client->dev,
  710. "%s: failed to flash firmware after retries\n", __func__);
  711. ret = -1;
  712. }
  713. info->fw_img = NULL;
  714. return ret;
  715. }
  716. static int melfas_ts_set_fw_name(struct mms_ts_info *info)
  717. {
  718. u8 ver[MAX_SECTION_NUM];
  719. int ret;
  720. #if defined(CONFIG_MACH_KANAS3G_CTC)
  721. int retries = 3;
  722. #endif
  723. /* Need 150ms to configure old/new firmware version in IC after power-on */
  724. msleep(150);
  725. #if defined(CONFIG_MACH_KANAS3G_CTC)
  726. while(retries--) {
  727. ret = get_fw_version(info->client, ver);
  728. if(!ret)
  729. break;
  730. else if(ret == -5 || ret == -6) {
  731. dev_err(&info->client->dev, "%s: it is not melfas IC\n",
  732. __func__);
  733. mdelay(5);
  734. continue;
  735. } else {
  736. dev_err(&info->client->dev, "%s: Failed to get config_fw_ver from IC\n",
  737. __func__);
  738. info->fw_path = FW_IMAGE_NAME_NULL;
  739. return -1;
  740. }
  741. }
  742. if(retries == 0)
  743. return ret;
  744. #else
  745. ret = get_fw_version(info->client, ver);
  746. if (ret) {
  747. dev_err(&info->client->dev, "%s: Failed to get config_fw_ver from IC\n",
  748. __func__);
  749. info->fw_path = FW_IMAGE_NAME_NULL;
  750. return -1;
  751. }
  752. #endif
  753. if (ver[CONFIG_SECTION] >= 0x50) {
  754. info->fw_path = FW_IMAGE_NAME_NEW;
  755. } else if (ver[CONFIG_SECTION] > 0x00) {
  756. info->fw_path = FW_IMAGE_NAME_OLD;
  757. } else {
  758. info->fw_path = FW_IMAGE_NAME_NULL;
  759. }
  760. info->fw_ver_boot_ic = ver[BOOT_SECTION];
  761. info->fw_ver_config_ic = ver[CONFIG_SECTION];
  762. info->config_fw_version = "N/A";
  763. dev_info(&info->client->dev, "%s: FW_NAME: %s [%02x%02x]\n", __func__,
  764. info->fw_path, info->fw_ver_boot_ic, info->fw_ver_config_ic);
  765. return 0;
  766. }
  767. static int melfas_ts_fw_update_probe(struct mms_ts_info *info)
  768. {
  769. int ret, i;
  770. const struct firmware *fw_entry = NULL;
  771. #if defined(CONFIG_MACH_KANAS3G_CTC)
  772. ret = melfas_ts_set_fw_name(info);
  773. if(ret == -EIO || ret == -ENXIO) {
  774. return -ENXIO;
  775. }
  776. #else
  777. melfas_ts_set_fw_name(info);
  778. #endif
  779. if (!info->fw_path) {
  780. dev_err(&info->client->dev, "%s: Firmware name is not defined\n",
  781. __func__);
  782. return -EINVAL;
  783. }
  784. dev_info(&info->client->dev, "%s: Load firmware : %s\n", __func__, info->fw_path);
  785. ret = request_firmware(&fw_entry, info->fw_path, &info->client->dev);
  786. if (ret) {
  787. dev_err(&info->client->dev, "%s: Firmware image %s not available\n",
  788. __func__, info->fw_path);
  789. ret = -EINVAL;
  790. goto done;
  791. }
  792. for (i = 0; i < DOWNLOAD_RETRY_CNT; i++) {
  793. ret = melfas_ts_fw_update(info, fw_entry, false);
  794. if (ret < 0)
  795. dev_err(&info->client->dev, "%s: Failed to fw update[%d]\n", __func__, ret);
  796. else
  797. break;
  798. }
  799. done:
  800. if (fw_entry)
  801. release_firmware(fw_entry);
  802. return ret;
  803. }
  804. static int mms_load_fw_from_kernel(struct mms_ts_info *info, const char *fw_path)
  805. {
  806. int retval;
  807. const struct firmware *fw_entry = NULL;
  808. if (!fw_path) {
  809. dev_err(&info->client->dev, "%s: Firmware name is not defined\n",
  810. __func__);
  811. return -EINVAL;
  812. }
  813. dev_info(&info->client->dev, "%s: Load firmware : %s\n", __func__, fw_path);
  814. retval = request_firmware(&fw_entry, fw_path, &info->client->dev);
  815. if (retval) {
  816. dev_err(&info->client->dev, "%s: Firmware image %s not available\n",
  817. __func__, fw_path);
  818. goto done;
  819. }
  820. retval = melfas_ts_fw_update(info, fw_entry, true);
  821. if (retval < 0)
  822. dev_err(&info->client->dev, "%s: failed update firmware\n", __func__);
  823. done:
  824. if (fw_entry)
  825. release_firmware(fw_entry);
  826. return retval;
  827. }
  828. static int mms_load_fw_from_ums(struct mms_ts_info *info)
  829. {
  830. struct file *fp;
  831. mm_segment_t old_fs;
  832. int nread;
  833. int error = 0;
  834. struct firmware fw;
  835. old_fs = get_fs();
  836. set_fs(KERNEL_DS);
  837. fp = filp_open(FW_IMAGE_NAME_UMS, O_RDONLY, S_IRUSR);
  838. if (IS_ERR(fp)) {
  839. dev_err(&info->client->dev,
  840. "%s: failed to open %s.\n", __func__, FW_IMAGE_NAME_UMS);
  841. error = -ENOENT;
  842. goto open_err;
  843. }
  844. fw.size = fp->f_path.dentry->d_inode->i_size;
  845. if (fw.size > 0) {
  846. unsigned char *fw_data;
  847. fw_data = kzalloc(fw.size, GFP_KERNEL);
  848. nread = vfs_read(fp, (char __user *)fw_data,
  849. fw.size, &fp->f_pos);
  850. dev_info(&info->client->dev,
  851. "%s: start, file path %s, size %u Bytes\n", __func__,
  852. FW_IMAGE_NAME_UMS, fw.size);
  853. if (nread != fw.size) {
  854. dev_err(&info->client->dev,
  855. "%s: failed to read firmware file, nread %u Bytes\n",
  856. __func__,
  857. nread);
  858. error = -EIO;
  859. } else {
  860. /* UMS case */
  861. fw.data = fw_data;
  862. error = melfas_ts_fw_update(info, &fw, true);
  863. }
  864. if (error < 0)
  865. dev_err(&info->client->dev, "%s: failed update firmware\n",
  866. __func__);
  867. kfree(fw_data);
  868. }
  869. filp_close(fp, current->files);
  870. open_err:
  871. set_fs(old_fs);
  872. return error;
  873. }
  874. static void mms_set_noise_mode(struct mms_ts_info *info)
  875. {
  876. int ret;
  877. u8 setLowLevelData[2];
  878. int bit1 = 0;
  879. int bit2 = 0;
  880. dev_info(&info->client->dev, "%s: Noise mode:%d, TA:%d \n",
  881. __func__, info->noise_mode, info->ta_status );
  882. if (!info->noise_mode) {
  883. bit1 = 0x04;
  884. }
  885. if (info->ta_status) {
  886. bit2 = 0x01;
  887. } else {
  888. bit2 = 0x02;
  889. info->noise_mode = 0;
  890. }
  891. // 1xx , noise mode is 0, 1 is not
  892. // x01 , insert TA
  893. // x10 , pull out TA
  894. setLowLevelData[0] = 0x30;
  895. setLowLevelData[1] = (bit1 | bit2);
  896. ret = melfas_i2c_write(info->client, setLowLevelData, 2);
  897. dev_info(&info->client->dev, "%s, Reg:%d, ret:%d\n", __func__, (bit1 | bit2), ret);
  898. }
  899. static void melfas_ts_get_data(struct mms_ts_info *info)
  900. {
  901. int ret = 0, i, j;
  902. uint8_t buf[TS_READ_REGS_LEN];
  903. int read_num, FingerID;
  904. int _touch_is_pressed, line;
  905. int keyID = 0, touchType = 0, touchState = 0;
  906. u8 setLowLevelData[2];
  907. if (info == NULL) {
  908. pr_err("%s : TS NULL\n", __func__);
  909. return;
  910. }
  911. if (!info->tsp_enabled) {
  912. dev_err(&info->client->dev, "[TSP ]%s. tsp_disabled.\n", __func__);
  913. msleep(500);
  914. return;
  915. }
  916. for (j = 0; j < 3; j++) {
  917. buf[0] = MMS_MIP_EVENT_PACKET_LENGTH;
  918. ret = i2c_master_send(info->client, buf, 1);
  919. if (ret < 0) {
  920. line = __LINE__;
  921. goto tsp_error;
  922. }
  923. ret = i2c_master_recv(info->client, buf, 1);
  924. if (ret < 0) {
  925. line = __LINE__;
  926. goto tsp_error;
  927. }
  928. read_num = buf[0];
  929. if (read_num < 60)
  930. break;
  931. }
  932. if (read_num > TS_READ_REGS_LEN)
  933. read_num = TS_READ_REGS_LEN;
  934. if (read_num > 0) {
  935. buf[0] = MMS_MIP_EVENT_PACKET;
  936. ret = i2c_master_send(info->client, buf, 1);
  937. if (ret < 0) {
  938. line = __LINE__;
  939. goto tsp_error;
  940. }
  941. ret = i2c_master_recv(info->client, buf, read_num);
  942. if (ret < 0) {
  943. line = __LINE__;
  944. goto tsp_error;
  945. }
  946. if (buf[0] == 0x0E) {
  947. dev_info(&info->client->dev, "%s: noise mode enter!!\n", __func__);
  948. info->noise_mode = 1 ;
  949. setLowLevelData[0] = 0x10;
  950. setLowLevelData[1] = 0x00;
  951. ret = melfas_i2c_write(info->client, setLowLevelData, 2);
  952. mms_set_noise_mode(info);
  953. }
  954. for (i = 0; i < read_num; i = i + 6) {
  955. if (buf[i] == 0x0F) {
  956. dev_err(&info->client->dev, "%s : ESD-DETECTED!!!\n", __func__);
  957. line = __LINE__;
  958. goto tsp_error;
  959. }
  960. touchType = (buf[i] >> 5) & 0x03;
  961. if (touchType == TOUCH_SCREEN) {
  962. FingerID = (buf[i] & 0x0F) - 1;
  963. info->finger[FingerID].posX = (uint16_t)(buf[i + 1] & 0x0F) << 8 | buf[i + 2];
  964. info->finger[FingerID].posY = (uint16_t)(buf[i + 1] & 0xF0) << 4 | buf[i + 3];
  965. if ((buf[i] & 0x80) == 0)
  966. info->finger[FingerID].strength = 0;
  967. else
  968. info->finger[FingerID].strength = buf[i + 4];
  969. info->finger[FingerID].width = buf[i + 5];
  970. } else if (touchType == TOUCH_KEY) {
  971. keyID = (buf[i] & 0x0F) - 1;
  972. touchState = !!(buf[i] & 0x80);
  973. info->dt_data->btn->pressed[keyID] = touchState ? true : false;
  974. input_report_key(info->input_dev, info->dt_data->btn->map[keyID],
  975. touchState ? PRESS_KEY : RELEASE_KEY);
  976. dev_err(&info->client->dev, "Button %d[%d] is %s\n",
  977. keyID, info->dt_data->btn->map[keyID],
  978. touchState ? "pressed" : "released");
  979. // When happend tkey and tsp event same time, input fw can't get, so added sync and 1ms delay time.
  980. input_sync(info->input_dev);
  981. msleep(1);
  982. }
  983. }
  984. }
  985. _touch_is_pressed = 0;
  986. for (i = 0; i < MELFAS_MAX_TOUCH; i++) {
  987. if (info->finger[i].strength == -1)
  988. continue;
  989. #ifdef TSP_PATTERN_TRACTKING
  990. tsp_pattern_tracking(info, i, info->finger[i].posX, info->finger[i].posY);
  991. #endif
  992. if (info->finger[i].strength) {
  993. input_mt_slot(info->input_dev, i);
  994. input_mt_report_slot_state(info->input_dev, MT_TOOL_FINGER, true);
  995. input_report_abs(info->input_dev, ABS_MT_PRESSURE, info->finger[i].strength);
  996. input_report_abs(info->input_dev, ABS_MT_POSITION_X, info->finger[i].posX);
  997. input_report_abs(info->input_dev, ABS_MT_POSITION_Y, info->finger[i].posY);
  998. input_report_key(info->input_dev, BTN_TOUCH, info->finger[i].strength);
  999. if (info->finger[i].state == 0){
  1000. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1001. dev_info(&info->client->dev, "P[%d] (%d,%d), z:%d w:%d\n",
  1002. i, info->finger[i].posX, info->finger[i].posY,
  1003. info->finger[i].strength, info->finger[i].width);
  1004. #else
  1005. dev_info(&info->client->dev, "P[%d]\n", i);
  1006. #endif
  1007. } else
  1008. info->finger[i].mcount++;
  1009. info->finger[i].state = 1;
  1010. } else {
  1011. input_mt_slot(info->input_dev, i);
  1012. input_mt_report_slot_state(info->input_dev, MT_TOOL_FINGER, false);
  1013. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1014. dev_info(&info->client->dev, "R[%d] (%d,%d), M[%d], Ver[%02x]\n",
  1015. i, info->finger[i].posX, info->finger[i].posY,
  1016. info->finger[i].mcount, info->fw_ver_config_ic);
  1017. #else
  1018. dev_info(&info->client->dev, "R[%d] M[%d], Ver[%02x]\n",
  1019. i, info->finger[i].mcount, info->fw_ver_config_ic);
  1020. #endif
  1021. info->finger[i].mcount = 0;
  1022. info->finger[i].state = 0;
  1023. }
  1024. if (info->finger[i].strength == 0)
  1025. info->finger[i].strength = -1;
  1026. if (info->finger[i].strength > 0)
  1027. _touch_is_pressed = 1;
  1028. }
  1029. input_sync(info->input_dev);
  1030. touch_is_pressed = _touch_is_pressed;
  1031. #ifdef TOUCH_BOOSTER
  1032. set_dvfs_lock(info, !!touch_is_pressed);
  1033. #endif
  1034. return;
  1035. tsp_error:
  1036. dev_err(&info->client->dev, "[TSP] %s: i2c failed(%d)\n", __func__, line);
  1037. melfas_ts_reboot();
  1038. }
  1039. static irqreturn_t melfas_ts_irq_handler(int irq, void *handle)
  1040. {
  1041. struct mms_ts_info *info = (struct mms_ts_info *)handle;
  1042. melfas_ts_get_data(info);
  1043. return IRQ_HANDLED;
  1044. }
  1045. #if TEST_CODE
  1046. static int melfas_i2c_read(struct i2c_client *client, u16 addr, u16 length, u8 *value)
  1047. {
  1048. struct i2c_adapter *adapter = client->adapter;
  1049. struct i2c_msg msg[2];
  1050. msg[0].addr = client->addr;
  1051. msg[0].flags = 0x00;
  1052. msg[0].len = 1;
  1053. msg[0].buf = (u8 *) &addr;
  1054. msg[1].addr = client->addr;
  1055. msg[1].flags = I2C_M_RD;
  1056. msg[1].len = length;
  1057. msg[1].buf = (u8 *) value;
  1058. if (i2c_transfer(adapter, msg, 2) == 2)
  1059. return 0;
  1060. else
  1061. return -EIO;
  1062. }
  1063. #endif
  1064. static int melfas_i2c_write(struct i2c_client *client, char *buf, int length)
  1065. {
  1066. int i;
  1067. char data[TS_WRITE_REGS_LEN];
  1068. if (length > TS_WRITE_REGS_LEN) {
  1069. dev_err(&client->dev, "[TSP] size error - %s\n", __func__);
  1070. return -EINVAL;
  1071. }
  1072. for (i = 0; i < length; i++)
  1073. data[i] = *buf++;
  1074. i = i2c_master_send(client, (char *)data, length);
  1075. if (i == length)
  1076. return length;
  1077. else
  1078. return -EIO;
  1079. }
  1080. static void release_all_fingers(struct mms_ts_info *info)
  1081. {
  1082. int i;
  1083. dev_err(&info->client->dev, "%s start.\n", __func__);
  1084. for (i = 0; i < MELFAS_MAX_TOUCH; i++) {
  1085. info->finger[i].state = 0;
  1086. info->finger[i].strength = 0;
  1087. input_mt_slot(info->input_dev, i);
  1088. input_mt_report_slot_state(info->input_dev,
  1089. MT_TOOL_FINGER, false);
  1090. info->finger[i].posX = 0;
  1091. info->finger[i].posY = 0;
  1092. if (info->finger[i].strength == 0)
  1093. info->finger[i].strength = -1;
  1094. }
  1095. input_sync(info->input_dev);
  1096. #ifdef TOUCH_BOOSTER
  1097. set_dvfs_lock(info, 2);
  1098. dev_info(&info->client->dev, "[TSP] dvfs_lock free.\n ");
  1099. #endif
  1100. }
  1101. static void melfas_ts_reboot(void)
  1102. {
  1103. dev_info(&g_info->client->dev, "%s\n", __func__);
  1104. disable_irq_nosync(g_info->irq);
  1105. g_info->tsp_enabled = false;
  1106. melfas_ts_power_enable(0);
  1107. msleep(60);
  1108. release_all_fingers(g_info);
  1109. msleep(60);
  1110. melfas_ts_power_enable(1);
  1111. msleep(60);
  1112. enable_irq(g_info->irq);
  1113. g_info->tsp_enabled = true;
  1114. };
  1115. static void melfas_ts_reboot_after_update(void)
  1116. {
  1117. dev_info(&g_info->client->dev, "%s\n", __func__);
  1118. msleep(50);
  1119. melfas_ts_power_enable(0);
  1120. msleep(1000);
  1121. melfas_ts_power_enable(1);
  1122. msleep(300);
  1123. }
  1124. #ifdef SEC_TSP_FACTORY_TEST
  1125. static void set_default_result(struct mms_ts_info *info)
  1126. {
  1127. char delim = ':';
  1128. memset(info->cmd_result, 0x00, ARRAY_SIZE(info->cmd_result));
  1129. memcpy(info->cmd_result, info->cmd, strlen(info->cmd));
  1130. strncat(info->cmd_result, &delim, 1);
  1131. }
  1132. static void set_cmd_result(struct mms_ts_info *info, char *buff, int len)
  1133. {
  1134. strncat(info->cmd_result, buff, len);
  1135. }
  1136. static int check_rx_tx_num(void *device_data)
  1137. {
  1138. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1139. char buff[TSP_CMD_STR_LEN] = {0};
  1140. int node;
  1141. if (info->cmd_param[0] < 0 ||
  1142. info->cmd_param[0] >= info->tx_num ||
  1143. info->cmd_param[1] < 0 ||
  1144. info->cmd_param[1] >= info->rx_num) {
  1145. snprintf(buff, sizeof(buff) , "%s", "NG");
  1146. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1147. info->cmd_state = CMD_STATUS_FAIL;
  1148. dev_info(&info->client->dev, "%s: parameter error: %u,%u\n",
  1149. __func__, info->cmd_param[0],
  1150. info->cmd_param[1]);
  1151. node = -1;
  1152. return node;
  1153. }
  1154. node = info->cmd_param[1] * info->tx_num+ info->cmd_param[0];
  1155. dev_info(&info->client->dev, "%s: node = %d\n", __func__, node);
  1156. return node;
  1157. }
  1158. static void not_support_cmd(void *device_data)
  1159. {
  1160. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1161. char buff[16] = {0};
  1162. set_default_result(info);
  1163. snprintf(buff, sizeof(buff), "%s", "NA");
  1164. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1165. mutex_lock(&info->cmd_lock);
  1166. info->cmd_is_running = false;
  1167. mutex_unlock(&info->cmd_lock);
  1168. info->cmd_state = CMD_STATUS_WAITING;
  1169. dev_info(&info->client->dev, "%s: \"%s(%d)\"\n", __func__,
  1170. buff, strnlen(buff, sizeof(buff)));
  1171. return;
  1172. }
  1173. static void fw_update(void *device_data)
  1174. {
  1175. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1176. struct i2c_client *client = info->client;
  1177. int ret, i;
  1178. char buff[16] = {0};
  1179. set_default_result(info);
  1180. for (i = 0; i < DOWNLOAD_RETRY_CNT; i++) {
  1181. switch (info->cmd_param[0]) {
  1182. case FW_UPDATE_BUILT_IN:
  1183. ret = mms_load_fw_from_kernel(info, info->fw_path);
  1184. break;
  1185. case FW_UPDATE_UMS:
  1186. ret = mms_load_fw_from_ums(info);
  1187. break;
  1188. default:
  1189. dev_err(&client->dev,"%s: not support fw_update mode:%d\n", __func__, info->cmd_param[0]);
  1190. snprintf(buff, sizeof(buff), "%s", "NA");
  1191. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1192. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1193. return;
  1194. }
  1195. if (ret != 0) {
  1196. dev_err(&info->client->dev, "%s: failed to fw update[%d]\n", __func__, ret);
  1197. snprintf(buff, sizeof(buff), "%s", "NG");
  1198. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1199. info->cmd_state = CMD_STATUS_FAIL;
  1200. } else {
  1201. snprintf(buff, sizeof(buff), "%s", "OK");
  1202. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1203. info->cmd_state = CMD_STATUS_OK;
  1204. break;
  1205. }
  1206. }
  1207. return;
  1208. }
  1209. static void get_fw_ver_bin(void *device_data)
  1210. {
  1211. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1212. char buff[16] = {0};
  1213. set_default_result(info);
  1214. snprintf(buff, sizeof(buff), "ME%02x%02x%02x",
  1215. info->fw_ver_boot_bin, info->fw_ver_core_bin, info->fw_ver_config_bin);
  1216. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1217. info->cmd_state = CMD_STATUS_OK;
  1218. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
  1219. buff, strnlen(buff, sizeof(buff)));
  1220. }
  1221. static void get_fw_ver_ic(void *device_data)
  1222. {
  1223. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1224. char buff[16] = {0};
  1225. set_default_result(info);
  1226. snprintf(buff, sizeof(buff), "ME%02x%02x%02x",
  1227. info->fw_ver_boot_ic, info->fw_ver_core_ic, info->fw_ver_config_ic);
  1228. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1229. info->cmd_state = CMD_STATUS_OK;
  1230. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
  1231. buff, strnlen(buff, sizeof(buff)));
  1232. }
  1233. static void get_config_ver(void *device_data)
  1234. {
  1235. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1236. char buff[20] = {0};
  1237. set_default_result(info);
  1238. snprintf(buff, sizeof(buff), "%s", info->config_fw_version);
  1239. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1240. info->cmd_state = CMD_STATUS_OK;
  1241. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
  1242. buff, strnlen(buff, sizeof(buff)));
  1243. }
  1244. static void get_threshold(void *device_data)
  1245. {
  1246. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1247. char buff[16] = {0};
  1248. int threshold;
  1249. threshold = 25; //TSP
  1250. set_default_result(info);
  1251. /*
  1252. melfas_i2c_read(info->client, MMS_MIP_CONTACT_ON_EVENT_THRES, 1, &threshold);
  1253. */
  1254. if (threshold < 0) {
  1255. snprintf(buff, sizeof(buff), "%s", "NG");
  1256. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1257. info->cmd_state = CMD_STATUS_FAIL;
  1258. return;
  1259. }
  1260. snprintf(buff, sizeof(buff), "%d", threshold);
  1261. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1262. info->cmd_state = CMD_STATUS_OK;
  1263. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
  1264. buff, strnlen(buff, sizeof(buff)));
  1265. }
  1266. static void module_off_master(void *device_data)
  1267. {
  1268. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1269. char buff[3] = {0};
  1270. int ret;
  1271. set_default_result(info);
  1272. ret = melfas_ts_stop(info);
  1273. if (ret < 0) {
  1274. snprintf(buff, sizeof(buff), "%s", "NG");
  1275. info->cmd_state = CMD_STATUS_FAIL;
  1276. } else {
  1277. snprintf(buff, sizeof(buff), "%s", "OK");
  1278. info->cmd_state = CMD_STATUS_OK;
  1279. }
  1280. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1281. dev_info(&info->client->dev, "%s: %s\n", __func__, buff);
  1282. }
  1283. static void module_on_master(void *device_data)
  1284. {
  1285. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1286. char buff[3] = {0};
  1287. int ret;
  1288. set_default_result(info);
  1289. ret = melfas_ts_start(info);
  1290. if (ret < 0) {
  1291. snprintf(buff, sizeof(buff), "%s", "NG");
  1292. info->cmd_state = CMD_STATUS_FAIL;
  1293. } else {
  1294. snprintf(buff, sizeof(buff), "%s", "OK");
  1295. info->cmd_state = CMD_STATUS_OK;
  1296. }
  1297. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1298. dev_info(&info->client->dev, "%s: %s\n", __func__, buff);
  1299. }
  1300. static void get_chip_vendor(void *device_data)
  1301. {
  1302. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1303. char buff[16] = {0};
  1304. set_default_result(info);
  1305. snprintf(buff, sizeof(buff), "%s", "MELFAS");
  1306. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1307. info->cmd_state = CMD_STATUS_OK;
  1308. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
  1309. buff, strnlen(buff, sizeof(buff)));
  1310. }
  1311. static void get_chip_name(void *device_data)
  1312. {
  1313. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1314. char buff[16] = {0};
  1315. set_default_result(info);
  1316. snprintf(buff, sizeof(buff), "%s", "MMS134S");
  1317. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1318. info->cmd_state = CMD_STATUS_OK;
  1319. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
  1320. buff, strnlen(buff, sizeof(buff)));
  1321. }
  1322. static void get_reference(void *device_data)
  1323. {
  1324. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1325. char buff[16] = {0};
  1326. s16 val;
  1327. int node;
  1328. set_default_result(info);
  1329. node = check_rx_tx_num(info);
  1330. if (node < 0)
  1331. return ;
  1332. val = info->reference[node];
  1333. snprintf(buff, sizeof(buff), "%d", val);
  1334. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1335. info->cmd_state = CMD_STATUS_OK;
  1336. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
  1337. buff, strnlen(buff, sizeof(buff)));
  1338. }
  1339. static void get_cm_abs(void *device_data)
  1340. {
  1341. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1342. char buff[16] = {0};
  1343. s16 val;
  1344. int node;
  1345. set_default_result(info);
  1346. node = check_rx_tx_num(info);
  1347. if (node < 0)
  1348. return;
  1349. val = info->cm_abs[node];
  1350. snprintf(buff, sizeof(buff), "%d", val);
  1351. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1352. info->cmd_state = CMD_STATUS_OK;
  1353. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__, buff,
  1354. strnlen(buff, sizeof(buff)));
  1355. }
  1356. static void get_cm_delta(void *device_data)
  1357. {
  1358. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1359. char buff[16] = {0};
  1360. s16 val;
  1361. int node;
  1362. set_default_result(info);
  1363. node = check_rx_tx_num(info);
  1364. if (node < 0)
  1365. return;
  1366. val = info->cm_delta[node];
  1367. snprintf(buff, sizeof(buff), "%d", val);
  1368. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1369. info->cmd_state = CMD_STATUS_OK;
  1370. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__, buff,
  1371. strnlen(buff, sizeof(buff)));
  1372. }
  1373. static void get_intensity(void *device_data)
  1374. {
  1375. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1376. char buff[16] = {0};
  1377. s16 val;
  1378. int node;
  1379. set_default_result(info);
  1380. node = check_rx_tx_num(info);
  1381. if (node < 0)
  1382. return;
  1383. val = info->intensity[node];
  1384. snprintf(buff, sizeof(buff), "%d", val);
  1385. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1386. info->cmd_state = CMD_STATUS_OK;
  1387. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__, buff,
  1388. strnlen(buff, sizeof(buff)));
  1389. }
  1390. static void get_x_num(void *device_data)
  1391. {
  1392. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1393. char buff[16] = {0};
  1394. int val;
  1395. set_default_result(info);
  1396. val = i2c_smbus_read_byte_data(info->client, 0x0B);
  1397. info->tx_num = val;
  1398. if (val < 0) {
  1399. snprintf(buff, sizeof(buff), "%s", "NG");
  1400. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1401. info->cmd_state = CMD_STATUS_FAIL;
  1402. dev_err(&info->client->dev,
  1403. "%s: fail to read num of x (%d).\n", __func__, val);
  1404. return ;
  1405. }
  1406. snprintf(buff, sizeof(buff), "%u", val);
  1407. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1408. info->cmd_state = CMD_STATUS_OK;
  1409. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__, buff,
  1410. strnlen(buff, sizeof(buff)));
  1411. }
  1412. static void get_y_num(void *device_data)
  1413. {
  1414. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1415. char buff[16] = {0};
  1416. int val;
  1417. set_default_result(info);
  1418. val = i2c_smbus_read_byte_data(info->client, 0x0C);
  1419. info->rx_num = val;
  1420. if (val < 0) {
  1421. snprintf(buff, sizeof(buff), "%s", "NG");
  1422. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1423. info->cmd_state = CMD_STATUS_FAIL;
  1424. dev_err(&info->client->dev,
  1425. "%s: fail to read num of y (%d).\n", __func__, val);
  1426. return ;
  1427. }
  1428. snprintf(buff, sizeof(buff), "%u", val);
  1429. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1430. info->cmd_state = CMD_STATUS_OK;
  1431. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__, buff,
  1432. strnlen(buff, sizeof(buff)));
  1433. }
  1434. int get_cm_test_init(struct mms_ts_info *info)
  1435. {
  1436. struct i2c_client *client = info->client;
  1437. int ret = 0;
  1438. u8 sz = 0;
  1439. disable_irq(info->irq);
  1440. if (i2c_smbus_write_byte_data(client, MMS_UNIVERSAL_CMD, MMS_UNIV_ENTER_TEST)) {
  1441. dev_err(&client->dev, "%s: i2c failed\n", __func__);
  1442. }
  1443. do {
  1444. udelay(100);
  1445. } while (gpio_get_value(info->dt_data->irq_gpio));
  1446. sz = i2c_smbus_read_byte_data(client, MMS_MIP_EVENT_PACKET_LENGTH);
  1447. sz = i2c_smbus_read_byte_data(client, MMS_MIP_EVENT_PACKET);
  1448. if (sz != 0x0C) {
  1449. dev_err(&client->dev, "%s: maker\n", __func__);
  1450. return -1;
  1451. }
  1452. sz = i2c_smbus_read_byte_data(client, MMS_UNIVERSAL_RESULT_LENGTH);
  1453. sz = i2c_smbus_read_byte_data(client, MMS_UNIVERSAL_RESULT);
  1454. return ret;
  1455. }
  1456. int get_cm_test_exit(struct mms_ts_info *info)
  1457. {
  1458. struct i2c_client *client = info->client;
  1459. int ret = 0;
  1460. if(i2c_smbus_write_byte_data(client, MMS_UNIVERSAL_CMD, MMS_UNIV_EXIT_TEST)){
  1461. dev_err(&client->dev, "%s: i2c failed\n", __func__);
  1462. return -1;
  1463. }
  1464. enable_irq(info->irq);
  1465. return ret;
  1466. }
  1467. static int test_to_get_raw_data_all(struct mms_ts_info *info, u8 cmd)
  1468. {
  1469. int sz, result;
  1470. if (i2c_smbus_write_byte_data(info->client, MMS_UNIVERSAL_CMD, cmd)) {
  1471. dev_err(&info->client->dev, "%s: i2c failed\n", __func__);
  1472. }
  1473. do {
  1474. udelay(100);
  1475. } while (gpio_get_value(info->dt_data->irq_gpio));
  1476. sz = i2c_smbus_read_byte_data(info->client, MMS_UNIVERSAL_RESULT_LENGTH);
  1477. result = i2c_smbus_read_byte_data(info->client, MMS_UNIVERSAL_RESULT);
  1478. dev_info(&info->client->dev, "%s: result: %s\n", __func__, result ? "pass" : "fail");
  1479. return result;
  1480. }
  1481. static int get_raw_data_all(struct mms_ts_info *info, u8 cmd)
  1482. {
  1483. struct i2c_client *client = info->client;
  1484. int r, t, ii;
  1485. int ret = 0;
  1486. u8 sz = 0;
  1487. u8 buf[256] = {0, };
  1488. u8 reg[4] = { 0, };
  1489. s16 cmdata, max_value = 0, min_value = 0;
  1490. char buff[TSP_CMD_STR_LEN] = {0};
  1491. s16 *raw_data;
  1492. struct i2c_msg msg[] = {
  1493. {
  1494. .addr = client->addr,
  1495. .flags = 0,
  1496. .buf = reg,
  1497. },{
  1498. .addr = client->addr,
  1499. .flags = I2C_M_RD,
  1500. },
  1501. };
  1502. switch (cmd) {
  1503. case MMS_UNIV_GET_CM_DELTA:
  1504. dev_info(&info->client->dev, "%s: CM_DELTA: 0x%02x\n", __func__, cmd);
  1505. raw_data = info->cm_delta;
  1506. goto test_raw_data;
  1507. case MMS_UNIV_GET_CM_ABS:
  1508. dev_info(&info->client->dev, "%s: CM_ABS: 0x%02x\n", __func__, cmd);
  1509. raw_data = info->cm_abs;
  1510. goto test_raw_data;
  1511. case MMS_UNIV_INTENSITY:
  1512. disable_irq(info->irq);
  1513. dev_info(&info->client->dev, "%s: INTENSITY: 0x%02x\n", __func__, cmd);
  1514. raw_data = info->intensity;
  1515. goto get_raw_data;
  1516. case MMS_UNIV_REFERENCE:
  1517. disable_irq(info->irq);
  1518. dev_info(&info->client->dev, "%s: REFERENCE: 0x%02x\n", __func__, cmd);
  1519. raw_data = info->reference;
  1520. goto get_raw_data;
  1521. default:
  1522. dev_err(&info->client->dev, "%s: unsupported cmd: 0x%02x\n", __func__, cmd);
  1523. ret = -EINVAL;
  1524. goto err;
  1525. }
  1526. test_raw_data:
  1527. ret = test_to_get_raw_data_all(info, cmd - 1);
  1528. if (ret != 1) {
  1529. dev_err(&client->dev, "%s: test failed, %d\n", __func__, ret);
  1530. ret = -1;
  1531. goto err;
  1532. }
  1533. msleep(1);
  1534. get_raw_data:
  1535. dev_info(&info->client->dev, "\t");
  1536. for (t = 0; t < info->tx_num ; t++) {
  1537. pr_cont("[%2d] ", t);
  1538. }
  1539. pr_cont("\n");
  1540. for (r = 0, ii = 0; r < info->rx_num; r++) {
  1541. dev_info(&info->client->dev, "[%2d]", r);
  1542. reg[0] = MMS_UNIVERSAL_CMD;
  1543. reg[1] = cmd;
  1544. reg[2] = 0xFF;
  1545. reg[3] = r;
  1546. msg[0].len = 4;
  1547. if (i2c_transfer(client->adapter, &msg[0], 1) != 1) {
  1548. dev_err(&client->dev, "%s: i2c transfer failed, cmd\n", __func__);
  1549. ret = -1;
  1550. goto err;
  1551. }
  1552. while (gpio_get_value(info->dt_data->irq_gpio));
  1553. sz = i2c_smbus_read_byte_data(client, MMS_UNIVERSAL_RESULT_LENGTH);
  1554. reg[0] = MMS_UNIVERSAL_RESULT;
  1555. msg[0].len = 1;
  1556. msg[1].len = sz;
  1557. msg[1].buf = buf;
  1558. if (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) != ARRAY_SIZE(msg)) {
  1559. dev_err(&client->dev, "%s: i2c transfer failed, result\n", __func__);
  1560. ret = -1;
  1561. goto err;
  1562. }
  1563. for (t = 0; t < info->tx_num; t++, ii++) {
  1564. cmdata = (s16)(buf[2 * t] | (buf[2 * t + 1] << 8));
  1565. pr_cont("%5d", cmdata);
  1566. raw_data[ii] = cmdata;
  1567. if (r == 0 && t == 0) {
  1568. max_value = min_value = cmdata;
  1569. } else {
  1570. max_value = max(max_value, cmdata);
  1571. min_value = min(min_value, cmdata);
  1572. }
  1573. }
  1574. pr_cont("\n");
  1575. }
  1576. ret = 0;
  1577. err:
  1578. snprintf(buff, sizeof(buff), "%d,%d", min_value, max_value);
  1579. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1580. dev_err(&info->client->dev, "%s: %d,%d\n", __func__, min_value, max_value);
  1581. if (cmd == MMS_UNIV_INTENSITY || cmd == MMS_UNIV_REFERENCE)
  1582. enable_irq(info->irq);
  1583. return ret;
  1584. }
  1585. static void run_reference_read(void *device_data)
  1586. {
  1587. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1588. set_default_result(info);
  1589. get_raw_data_all(info, MMS_UNIV_REFERENCE);
  1590. info->cmd_state = CMD_STATUS_OK;
  1591. }
  1592. static void run_cm_abs_read(void *device_data)
  1593. {
  1594. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1595. set_default_result(info);
  1596. get_cm_test_init(info);
  1597. get_raw_data_all(info, MMS_UNIV_GET_CM_ABS);
  1598. get_cm_test_exit(info);
  1599. info->cmd_state = CMD_STATUS_OK;
  1600. }
  1601. static void run_cm_delta_read(void *device_data)
  1602. {
  1603. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1604. set_default_result(info);
  1605. get_cm_test_init(info);
  1606. get_raw_data_all(info, MMS_UNIV_GET_CM_DELTA);
  1607. get_cm_test_exit(info);
  1608. info->cmd_state = CMD_STATUS_OK;
  1609. }
  1610. static void run_intensity_read(void *device_data)
  1611. {
  1612. struct mms_ts_info *info = (struct mms_ts_info *)device_data;
  1613. set_default_result(info);
  1614. get_raw_data_all(info, MMS_UNIV_INTENSITY);
  1615. info->cmd_state = CMD_STATUS_OK;
  1616. }
  1617. static ssize_t store_cmd(struct device *dev, struct device_attribute *devattr,
  1618. const char *buf, size_t count)
  1619. {
  1620. struct mms_ts_info *info = g_info;
  1621. struct i2c_client *client = info->client;
  1622. char *cur, *start, *end;
  1623. char buff[TSP_CMD_STR_LEN] = {0};
  1624. int len, i;
  1625. struct tsp_cmd *tsp_cmd_ptr = NULL;
  1626. char delim = ',';
  1627. bool cmd_found = false;
  1628. int param_cnt = 0;
  1629. if (strlen(buf) >= TSP_CMD_STR_LEN) {
  1630. dev_err(&info->client->dev, "%s: cmd length is over(%s,%d)!!\n", __func__, buf, (int)strlen(buf));
  1631. return -EINVAL;
  1632. }
  1633. if (info->cmd_is_running == true) {
  1634. dev_err(&client->dev, "tsp_cmd: other cmd is running.\n");
  1635. goto err_out;
  1636. }
  1637. /* check lock */
  1638. mutex_lock(&info->cmd_lock);
  1639. info->cmd_is_running = true;
  1640. mutex_unlock(&info->cmd_lock);
  1641. info->cmd_state = CMD_STATUS_RUNNING;
  1642. for (i = 0; i < ARRAY_SIZE(info->cmd_param); i++)
  1643. info->cmd_param[i] = 0;
  1644. len = (int)count;
  1645. if (*(buf + len - 1) == '\n')
  1646. len--;
  1647. memset(info->cmd, 0x00, ARRAY_SIZE(info->cmd));
  1648. memcpy(info->cmd, buf, len);
  1649. cur = strchr(buf, (int)delim);
  1650. if (cur)
  1651. memcpy(buff, buf, cur - buf);
  1652. else
  1653. memcpy(buff, buf, len);
  1654. /* find command */
  1655. list_for_each_entry(tsp_cmd_ptr, &info->cmd_list_head, list) {
  1656. if (!strcmp(buff, tsp_cmd_ptr->cmd_name)) {
  1657. cmd_found = true;
  1658. break;
  1659. }
  1660. }
  1661. /* set not_support_cmd */
  1662. if (!cmd_found) {
  1663. list_for_each_entry(tsp_cmd_ptr, &info->cmd_list_head, list) {
  1664. if (!strcmp("not_support_cmd", tsp_cmd_ptr->cmd_name))
  1665. break;
  1666. }
  1667. }
  1668. /* parsing parameters */
  1669. if (cur && cmd_found) {
  1670. cur++;
  1671. start = cur;
  1672. memset(buff, 0x00, ARRAY_SIZE(buff));
  1673. do {
  1674. if (*cur == delim || cur - buf == len) {
  1675. end = cur;
  1676. memcpy(buff, start, end - start);
  1677. *(buff + strlen(buff)) = '\0';
  1678. if (kstrtoint(buff, 10,
  1679. info->cmd_param + param_cnt) < 0)
  1680. goto err_out;
  1681. start = cur + 1;
  1682. memset(buff, 0x00, ARRAY_SIZE(buff));
  1683. param_cnt++;
  1684. }
  1685. cur++;
  1686. } while ((cur - buf <= len) && (param_cnt < TSP_CMD_PARAM_NUM));
  1687. }
  1688. dev_info(&client->dev, "cmd = %s\n", tsp_cmd_ptr->cmd_name);
  1689. for (i = 0; i < param_cnt; i++)
  1690. dev_info(&client->dev, "cmd param %d= %d\n", i,
  1691. info->cmd_param[i]);
  1692. /*for*/
  1693. tsp_cmd_ptr->cmd_func(info);
  1694. err_out:
  1695. return count;
  1696. }
  1697. static ssize_t show_cmd_status(struct device *dev,
  1698. struct device_attribute *devattr, char *buf)
  1699. {
  1700. struct mms_ts_info *info = g_info;
  1701. char buff[16] = {0};
  1702. dev_info(&info->client->dev, "tsp cmd: status:%d\n",
  1703. info->cmd_state);
  1704. switch (info->cmd_state) {
  1705. case CMD_STATUS_WAITING:
  1706. snprintf(buff, sizeof(buff), "WAITING");
  1707. break;
  1708. case CMD_STATUS_RUNNING:
  1709. snprintf(buff, sizeof(buff), "RUNNING");
  1710. break;
  1711. case CMD_STATUS_OK:
  1712. snprintf(buff, sizeof(buff), "OK");
  1713. break;
  1714. case CMD_STATUS_FAIL:
  1715. snprintf(buff, sizeof(buff), "FAIL");
  1716. break;
  1717. case CMD_STATUS_NOT_APPLICABLE:
  1718. default:
  1719. snprintf(buff, sizeof(buff), "NOT_APPLICABLE");
  1720. break;
  1721. }
  1722. return snprintf(buf, TSP_BUF_SIZE, "%s\n", buff);
  1723. }
  1724. static ssize_t show_cmd_result(struct device *dev,
  1725. struct device_attribute *devattr, char *buf)
  1726. {
  1727. struct mms_ts_info *info = g_info;
  1728. dev_info(&info->client->dev, "tsp cmd: result: %s\n", info->cmd_result);
  1729. mutex_lock(&info->cmd_lock);
  1730. info->cmd_is_running = false;
  1731. mutex_unlock(&info->cmd_lock);
  1732. info->cmd_state = CMD_STATUS_WAITING;
  1733. return snprintf(buf, TSP_BUF_SIZE, "%s\n", info->cmd_result);
  1734. }
  1735. static ssize_t show_cmd_list(struct device *dev,
  1736. struct device_attribute *devattr, char *buf)
  1737. {
  1738. struct mms_ts_info *info = g_info;
  1739. char buffer[TSP_CMD_RESULT_STR_LEN];
  1740. char buffer_name[TSP_CMD_STR_LEN];
  1741. struct tsp_cmd *tsp_cmd_ptr = NULL;
  1742. snprintf(buffer, 30, "++ factory command list ++\n");
  1743. list_for_each_entry(tsp_cmd_ptr, &info->cmd_list_head, list) {
  1744. if (strncmp(tsp_cmd_ptr->cmd_name, "not_support_cmd", 16)) {
  1745. snprintf(buffer_name, TSP_CMD_STR_LEN, "%s\n", tsp_cmd_ptr->cmd_name);
  1746. strncat(buffer, buffer_name, strlen(buffer_name));
  1747. }
  1748. }
  1749. dev_info(&info->client->dev,
  1750. "%s: length : %u / %d\n", __func__,
  1751. strlen(buffer), TSP_CMD_RESULT_STR_LEN);
  1752. return snprintf(buf, PAGE_SIZE, "%s\n", buffer);
  1753. }
  1754. static DEVICE_ATTR(cmd, S_IWUSR | S_IWGRP, NULL, store_cmd);
  1755. static DEVICE_ATTR(cmd_status, S_IRUGO, show_cmd_status, NULL);
  1756. static DEVICE_ATTR(cmd_result, S_IRUGO, show_cmd_result, NULL);
  1757. static DEVICE_ATTR(cmd_list, S_IRUGO, show_cmd_list, NULL);
  1758. static struct attribute *sec_touch_facotry_attributes[] = {
  1759. &dev_attr_cmd.attr,
  1760. &dev_attr_cmd_status.attr,
  1761. &dev_attr_cmd_result.attr,
  1762. &dev_attr_cmd_list.attr,
  1763. NULL,
  1764. };
  1765. static struct attribute_group sec_touch_factory_attr_group = {
  1766. .attrs = sec_touch_facotry_attributes,
  1767. };
  1768. static int factory_init_tsp(struct mms_ts_info *info)
  1769. {
  1770. int ret, i;
  1771. INIT_LIST_HEAD(&info->cmd_list_head);
  1772. for (i = 0; i < ARRAY_SIZE(tsp_cmds); i++)
  1773. list_add_tail(&tsp_cmds[i].list, &info->cmd_list_head);
  1774. mutex_init(&info->cmd_lock);
  1775. info->cmd_is_running = false;
  1776. info->cmd_state = CMD_STATUS_WAITING;
  1777. info->noise_mode = 0;
  1778. info->tsp_dev = device_create(sec_class,
  1779. NULL, SEC_CLASS_DEVT_TSP, info, "tsp");
  1780. if (IS_ERR(info->tsp_dev)) {
  1781. dev_err(&info->client->dev, "Failed to create device(tsp)\n");
  1782. ret = -ENODEV;
  1783. goto err_create_device;
  1784. }
  1785. ret = sysfs_create_group(&info->tsp_dev->kobj,
  1786. &sec_touch_factory_attr_group);
  1787. if (ret) {
  1788. dev_err(&info->client->dev, "Failed to create sysfs group\n");
  1789. ret = (ret > 0) ? -ret : ret;
  1790. goto err_create_group;
  1791. }
  1792. ret = sysfs_create_link(&info->tsp_dev->kobj, &info->input_dev->dev.kobj, "input");
  1793. if (ret < 0)
  1794. dev_err(&info->client->dev, "%s: Failed to create input symbolic link[%d]\n",
  1795. __func__, ret);
  1796. info->tx_num = i2c_smbus_read_byte_data(info->client, 0x0B);
  1797. info->rx_num = i2c_smbus_read_byte_data(info->client, 0x0C);
  1798. info->reference = kzalloc(2 * info->rx_num * info->tx_num, GFP_KERNEL);
  1799. if (!info->reference) {
  1800. dev_err(&info->client->dev,
  1801. "%s: Failed to alloc mem for reference\n",
  1802. __func__);
  1803. ret = -ENOMEM;
  1804. goto err_mem_reference;
  1805. }
  1806. info->cm_abs = kzalloc(2 * info->rx_num * info->tx_num, GFP_KERNEL);
  1807. if (!info->cm_abs) {
  1808. dev_err(&info->client->dev,
  1809. "%s: Failed to alloc mem for cm_abs\n",
  1810. __func__);
  1811. ret = -ENOMEM;
  1812. goto err_mem_cm_abs;
  1813. }
  1814. info->cm_delta = kzalloc(2 * info->rx_num * info->tx_num, GFP_KERNEL);
  1815. if (!info->cm_delta) {
  1816. dev_err(&info->client->dev,
  1817. "%s: Failed to alloc mem for cm_delta\n",
  1818. __func__);
  1819. ret = -ENOMEM;
  1820. goto err_mem_cm_delta;
  1821. }
  1822. info->intensity = kzalloc(2 * info->rx_num * info->tx_num, GFP_KERNEL);
  1823. if (!info->intensity) {
  1824. dev_err(&info->client->dev,
  1825. "%s: Failed to alloc mem for intensity\n",
  1826. __func__);
  1827. ret = -ENOMEM;
  1828. goto err_mem_intensity;
  1829. }
  1830. return ret;
  1831. err_mem_intensity:
  1832. kfree(info->cm_delta);
  1833. err_mem_cm_delta:
  1834. kfree(info->cm_abs);
  1835. err_mem_cm_abs:
  1836. kfree(info->reference);
  1837. err_mem_reference:
  1838. sysfs_remove_group(&info->tsp_dev->kobj,
  1839. &sec_touch_factory_attr_group);
  1840. err_create_group:
  1841. device_destroy(sec_class, SEC_CLASS_DEVT_TSP);
  1842. err_create_device:
  1843. info->tsp_dev = NULL;
  1844. return ret;
  1845. }
  1846. #endif /* SEC_TSP_FACTORY_TEST */
  1847. #ifdef SEC_TKEY_FACTORY_TEST
  1848. static int get_raw_data_one(struct mms_ts_info *info, u8 cmd)
  1849. {
  1850. struct i2c_client *client = info->client;
  1851. int t;
  1852. int ret = 0;
  1853. u8 sz = 0;
  1854. u8 buf[256] = {0, };
  1855. u8 reg[4] = { 0, };
  1856. s16 cmdata;
  1857. u8 key_num;
  1858. struct i2c_msg msg[] = {
  1859. {
  1860. .addr = client->addr,
  1861. .flags = 0,
  1862. .buf = reg,
  1863. },{
  1864. .addr = client->addr,
  1865. .flags = I2C_M_RD,
  1866. },
  1867. };
  1868. disable_irq(info->irq);
  1869. key_num = i2c_smbus_read_byte_data(client, 0x0D);
  1870. if (key_num) {
  1871. reg[0] = MMS_UNIVERSAL_CMD;
  1872. reg[1] = cmd;
  1873. reg[2] = 0xFF;
  1874. reg[3] = 0x00;
  1875. msg[0].len = 4;
  1876. if (i2c_transfer(client->adapter, &msg[0], 1) != 1) {
  1877. dev_err(&client->dev, "%s: i2c transfer failed, cmd\n", __func__);
  1878. ret = -1;
  1879. goto out;
  1880. }
  1881. while (gpio_get_value(info->dt_data->irq_gpio));
  1882. sz = i2c_smbus_read_byte_data(client, MMS_UNIVERSAL_RESULT_LENGTH);
  1883. reg[0] = MMS_UNIVERSAL_RESULT;
  1884. msg[0].len = 1;
  1885. msg[1].len = sz;
  1886. msg[1].buf = buf;
  1887. if (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) != ARRAY_SIZE(msg)) {
  1888. dev_err(&client->dev, "%s: i2c transfer failed, result\n", __func__);
  1889. ret = -1;
  1890. goto out;
  1891. }
  1892. dev_info(&client->dev, "%s: ", __func__);
  1893. for (t = 0; t < key_num; t++) {
  1894. cmdata = (s16)(buf[2 * t] | (buf[2 * t + 1] << 8));
  1895. info->dt_data->btn->intensity[t] = cmdata;
  1896. pr_cont("%-5d", cmdata);
  1897. }
  1898. pr_cont("\n");
  1899. }
  1900. out:
  1901. enable_irq(info->irq);
  1902. return ret;
  1903. }
  1904. static ssize_t touchkey_threshold_show(struct device *dev,
  1905. struct device_attribute *attr, char *buf)
  1906. {
  1907. int threshold;
  1908. threshold = 22; //TSK
  1909. return snprintf(buf, sizeof(buf), "%d\n", threshold);
  1910. }
  1911. static ssize_t touchkey_back_show(struct device *dev,
  1912. struct device_attribute *attr, char *buf)
  1913. {
  1914. u16 intensity;
  1915. get_raw_data_one(g_info, MMS_UNIV_KEY_INTENSITY);
  1916. intensity = (g_info->dt_data->btn->intensity[1] < 0) ?
  1917. 0 : g_info->dt_data->btn->intensity[1];
  1918. return snprintf(buf, 10, "%d\n", intensity);
  1919. }
  1920. static ssize_t touchkey_recent_show(struct device *dev,
  1921. struct device_attribute *attr, char *buf)
  1922. {
  1923. u16 intensity;
  1924. get_raw_data_one(g_info, MMS_UNIV_KEY_INTENSITY);
  1925. intensity = (g_info->dt_data->btn->intensity[0] < 0) ?
  1926. 0 : g_info->dt_data->btn->intensity[0];
  1927. return snprintf(buf, 10, "%d\n", intensity);
  1928. }
  1929. static DEVICE_ATTR(touchkey_back, S_IRUGO | S_IWUSR | S_IWGRP,
  1930. touchkey_back_show, NULL);
  1931. static DEVICE_ATTR(touchkey_recent, S_IRUGO | S_IWUSR | S_IWGRP,
  1932. touchkey_recent_show, NULL);
  1933. static DEVICE_ATTR(touchkey_threshold, S_IRUGO | S_IWUSR | S_IWGRP,
  1934. touchkey_threshold_show, NULL);
  1935. static struct attribute *touchkey_attributes[] = {
  1936. &dev_attr_touchkey_threshold.attr,
  1937. &dev_attr_touchkey_back.attr,
  1938. &dev_attr_touchkey_recent.attr,
  1939. NULL,
  1940. };
  1941. static struct attribute_group touchkey_attr_group = {
  1942. .attrs = touchkey_attributes,
  1943. };
  1944. static int factory_init_tk(struct mms_ts_info *info)
  1945. {
  1946. struct i2c_client *client = info->client;
  1947. int ret;
  1948. info->tkey_dev= device_create(sec_class, NULL, SEC_CLASS_DEVT_TKEY,
  1949. info, "sec_touchkey");
  1950. if (IS_ERR(info->tkey_dev)) {
  1951. dev_err(&client->dev, "Failed to create fac touchkey dev\n");
  1952. ret = -ENODEV;
  1953. goto err_create_device_tk;
  1954. }
  1955. ret = sysfs_create_group(&info->tkey_dev->kobj, &touchkey_attr_group);
  1956. if (ret) {
  1957. dev_err(&client->dev,
  1958. "Failed to create sysfs (touchkey_attr_group).\n");
  1959. ret = (ret > 0) ? -ret : ret;
  1960. goto err_create_group_tk;
  1961. }
  1962. return 0;
  1963. err_create_group_tk:
  1964. device_destroy(sec_class, SEC_CLASS_DEVT_TKEY);
  1965. err_create_device_tk:
  1966. info->tkey_dev = NULL;
  1967. return ret;
  1968. }
  1969. #endif /* SEC_TKEY_FACTORY_TEST */
  1970. #ifdef CONFIG_OF
  1971. static int melfas_ts_parse_dt(struct device *dev,
  1972. struct mms_ts_dt_data *dt_data)
  1973. {
  1974. struct device_node *np = dev->of_node;
  1975. struct property *prop;
  1976. int rc;
  1977. int i;
  1978. u32 coords[2];
  1979. struct mms_btn_map *btn;
  1980. /* vdd, irq gpio info */
  1981. dt_data->irq_gpio = of_get_named_gpio(np, "melfas,irq-gpio", 0);
  1982. dt_data->scl_gpio = of_get_named_gpio(np, "melfas,scl-gpio", 0);
  1983. dt_data->sda_gpio = of_get_named_gpio(np, "melfas,sda-gpio", 0);
  1984. dt_data->vdd_gpio = of_get_named_gpio(np, "melfas,vdd-gpio", 0);
  1985. rc = of_property_read_u32_array(np, "melfas,tsp-coords", coords, 2);
  1986. if (rc < 0) {
  1987. dev_info(dev, "%s: Unable to read synaptics,tsp-coords\n", __func__);
  1988. return rc;
  1989. }
  1990. dt_data->coords[0] = coords[0];
  1991. dt_data->coords[1] = coords[1];
  1992. prop = of_find_property(np, "melfas,tkey-keycodes", NULL);
  1993. if (prop && prop->value) {
  1994. btn = kzalloc(sizeof(*btn), GFP_KERNEL);
  1995. if (!btn) {
  1996. dev_err(dev, "Failed to allocate f1a memory\n");
  1997. return -ENOMEM;
  1998. }
  1999. btn->nbuttons = prop->length / sizeof(u32);
  2000. rc = of_property_read_u32_array(np, "melfas,tkey-keycodes",
  2001. btn->map, btn->nbuttons);
  2002. if (rc && (rc != -EINVAL)) {
  2003. dev_info(dev, "%s: Unable to read %s, free button map memory\n", __func__,
  2004. "melfas,tkey-keycodes");
  2005. kfree(btn);
  2006. return rc;
  2007. }
  2008. dt_data->btn = btn;
  2009. pr_err("%s tkey enabled! ", __func__);
  2010. for (i = 0; i < dt_data->btn->nbuttons; i++)
  2011. pr_cont("keycode[%d] = %d ", i, dt_data->btn->map[i]);
  2012. pr_cont("\n");
  2013. }
  2014. pr_err("%s: tsp_int= %d, vdd= %d, x= %d, y= %d\n",
  2015. __func__, dt_data->irq_gpio, dt_data->vdd_gpio, dt_data->coords[0], dt_data->coords[1]);
  2016. return 0;
  2017. }
  2018. #else
  2019. static int melfas_ts_parse_dt(struct device *dev,
  2020. struct mms_ts_dt_data *dt_data)
  2021. {
  2022. return -ENODEV;
  2023. }
  2024. #endif
  2025. static void melfas_ts_request_gpio(struct mms_ts_dt_data *dt_data)
  2026. {
  2027. int error;
  2028. if (dt_data->irq_gpio > 0) {
  2029. error = gpio_request(dt_data->irq_gpio, "tsp_irq_gpio");
  2030. if (error) {
  2031. pr_err("[TSP] %s: unable to request irq-gpio[%d]\n", __func__, dt_data->irq_gpio);
  2032. }
  2033. }
  2034. if (dt_data->vdd_gpio > 0) {
  2035. error = gpio_request(dt_data->vdd_gpio, "tsp_en_gpio");
  2036. if (error) {
  2037. pr_err("[TSP] %s: unable to request vdd-gpio[%d]\n", __func__, dt_data->vdd_gpio);
  2038. }
  2039. }
  2040. }
  2041. #if defined(CONFIG_GET_LCD_ATTACHED)
  2042. extern int get_lcd_attached(void);
  2043. #endif
  2044. #if defined(CONFIG_TOUCHSCREEN_IST30XX) && defined(CONFIG_MACH_KANAS3G_CTC)
  2045. extern bool ist30xx_initialized;
  2046. #endif
  2047. static int melfas_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
  2048. {
  2049. struct mms_ts_info *info;
  2050. struct mms_ts_dt_data *dt_data;
  2051. int ret = 0, i;
  2052. dev_err(&client->dev, "%s\n", __func__);
  2053. #if defined(CONFIG_GET_LCD_ATTACHED)
  2054. if (get_lcd_attached() == 0) {
  2055. dev_err(&client->dev, "%s : get_lcd_attached()=0 \n", __func__);
  2056. return -EIO;
  2057. }
  2058. #endif
  2059. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  2060. dev_err(&client->dev, "%s: need I2C_FUNC_I2C\n", __func__);
  2061. return -ENODEV;
  2062. }
  2063. if (client->dev.of_node) {
  2064. dt_data = devm_kzalloc(&client->dev,
  2065. sizeof(struct mms_ts_dt_data), GFP_KERNEL);
  2066. if (!dt_data) {
  2067. dev_err(&client->dev, "%s: Failed to allocate memory\n", __func__);
  2068. return -ENOMEM;
  2069. }
  2070. ret = melfas_ts_parse_dt(&client->dev, dt_data);
  2071. if (ret < 0) {
  2072. devm_kfree(&client->dev, (void *)dt_data);
  2073. return ret;
  2074. }
  2075. } else {
  2076. dt_data = client->dev.platform_data;
  2077. dev_err(&client->dev, "TSP failed to align dtsi %s", __func__);
  2078. }
  2079. if (!dt_data) {
  2080. dev_err(&client->dev,
  2081. "%s: device tree data is not found\n", __func__);
  2082. return -EINVAL;
  2083. }
  2084. melfas_ts_request_gpio(dt_data);
  2085. info = kzalloc(sizeof(*info), GFP_KERNEL);
  2086. if (!info) {
  2087. dev_err(&client->dev,
  2088. "%s: Failed to alloc mem for melfas-ts\n", __func__);
  2089. return -ENOMEM;
  2090. goto err_alloc_data_failed;
  2091. }
  2092. g_info = info;
  2093. info->tsp_enabled = false;
  2094. info->irq = client->irq = gpio_to_irq(dt_data->irq_gpio);
  2095. info->dt_data = dt_data;
  2096. mutex_init(&info->lock);
  2097. info->client = client;
  2098. i2c_set_clientdata(client, info);
  2099. melfas_ts_power_enable(0);
  2100. msleep(60);
  2101. melfas_ts_power_enable(1);
  2102. msleep(60);
  2103. ret = melfas_ts_fw_update_probe(info);
  2104. if (ret < 0) {
  2105. dev_err(&info->client->dev,
  2106. "%s: Failed to Firmware update\n", __func__);
  2107. goto err_fw_update_failed;
  2108. };
  2109. info->input_dev = input_allocate_device();
  2110. if (!info->input_dev) {
  2111. dev_err(&info->client->dev,
  2112. "%s: Failed to alloc mem for input_dev\n", __func__);
  2113. ret = -ENOMEM;
  2114. goto err_input_dev_alloc_failed;
  2115. }
  2116. info->input_dev->name = TSP_DEVICE_NAME;
  2117. info->input_dev->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY);
  2118. info->input_dev->dev.parent = &client->dev;
  2119. #ifdef USE_OPEN_CLOSE
  2120. info->input_dev->open = melfas_ts_input_open;
  2121. info->input_dev->close = melfas_ts_input_close;
  2122. #endif
  2123. set_bit(INPUT_PROP_DIRECT, info->input_dev->propbit); //JB touch mode setting
  2124. for (i = 0; i < dt_data->btn->nbuttons; i++)
  2125. info->input_dev->keybit[BIT_WORD(dt_data->btn->map[i])] |= BIT_MASK(dt_data->btn->map[i]);
  2126. input_mt_init_slots(info->input_dev, MELFAS_MAX_TOUCH);
  2127. input_set_abs_params(info->input_dev, ABS_MT_POSITION_X,
  2128. 0, info->dt_data->coords[0], 0, 0);
  2129. input_set_abs_params(info->input_dev, ABS_MT_POSITION_Y,
  2130. 0, info->dt_data->coords[1], 0, 0);
  2131. input_set_abs_params(info->input_dev, ABS_MT_TOUCH_MAJOR,
  2132. 0, TS_MAX_Z_TOUCH, 0, 0);
  2133. input_set_abs_params(info->input_dev, ABS_MT_TRACKING_ID,
  2134. 0, MELFAS_MAX_TOUCH - 1, 0, 0);
  2135. input_set_abs_params(info->input_dev, ABS_MT_WIDTH_MAJOR,
  2136. 0, TS_MAX_W_TOUCH, 0, 0);
  2137. //__set_bit(EV_LED, info->input_dev->evbit);
  2138. //__set_bit(LED_MISC, info->input_dev->ledbit);
  2139. set_bit(EV_SYN, info->input_dev->evbit);
  2140. set_bit(EV_KEY, info->input_dev->evbit);
  2141. set_bit(EV_LED, info->input_dev->evbit);
  2142. set_bit(LED_MISC, info->input_dev->ledbit);
  2143. set_bit(EV_ABS, info->input_dev->evbit);
  2144. set_bit(INPUT_PROP_DIRECT, info->input_dev->propbit);
  2145. input_set_drvdata(info->input_dev, info);
  2146. ret = input_register_device(info->input_dev);
  2147. if (ret) {
  2148. dev_err(&info->client->dev, "%s: Failed to register input device\n", __func__);
  2149. ret = -ENODEV;
  2150. goto err_input_register_device_failed;
  2151. }
  2152. #ifdef TOUCH_BOOSTER
  2153. mutex_init(&info->dvfs_lock);
  2154. INIT_DELAYED_WORK(&info->work_dvfs_off, set_dvfs_off);
  2155. INIT_DELAYED_WORK(&info->work_dvfs_chg, change_dvfs_lock);
  2156. info->dvfs_lock_status = false;
  2157. #endif
  2158. if (info->client->irq) {
  2159. #if MELFAS_DEBUG_PRINT
  2160. dev_info(&info->client->dev, "%s: trying to request irq: %s-%d\n", __func__,
  2161. info->client->name, info->client->irq);
  2162. #endif
  2163. ret = request_threaded_irq(client->irq, NULL, melfas_ts_irq_handler,
  2164. IRQF_TRIGGER_LOW | IRQF_ONESHOT,
  2165. info->client->name, info);
  2166. if (ret > 0) {
  2167. dev_err(&info->client->dev, "%s: failed to request irq %d, ret %d\n",
  2168. __func__, info->client->irq, ret);
  2169. ret = -EBUSY;
  2170. goto err_request_irq;
  2171. }
  2172. }
  2173. for (i = 0; i < MELFAS_MAX_TOUCH ; i++)
  2174. info->finger[i].strength = -1;
  2175. #ifdef CONFIG_HAS_EARLYSUSPEND
  2176. dev_info(&info->client->dev, "%s: register earlysuspend.\n", __func__);
  2177. info->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
  2178. info->early_suspend.suspend = melfas_ts_early_suspend;
  2179. info->early_suspend.resume = melfas_ts_late_resume;
  2180. register_early_suspend(&info->early_suspend);
  2181. #endif
  2182. #ifdef SEC_TSP_FACTORY_TEST
  2183. ret = factory_init_tsp(info);
  2184. if (ret < 0) {
  2185. dev_err(&info->client->dev, "%s: Failed to factory_init_tsp, %d\n",
  2186. __func__, ret);
  2187. goto err_init_factory_tsp;
  2188. }
  2189. #endif
  2190. #ifdef SEC_TKEY_FACTORY_TEST
  2191. ret = factory_init_tk(info);
  2192. if (ret < 0) {
  2193. dev_err(&info->client->dev, "%s: Failed to factory_init_tk, %d\n",
  2194. __func__, ret);
  2195. goto err_init_factory_tk;
  2196. }
  2197. #endif
  2198. info->tsp_enabled = true;
  2199. mms134s_initialized = 1;
  2200. #if MELFAS_DEBUG_PRINT
  2201. dev_err(&info->client->dev, "%s: Start touchscreen. name: %s, irq: %d\n",
  2202. __func__, info->client->name, info->client->irq);
  2203. #endif
  2204. return 0;
  2205. #ifdef SEC_TKEY_FACTORY_TEST
  2206. sysfs_remove_group(&info->tkey_dev->kobj, &touchkey_attr_group);
  2207. device_destroy(sec_class, SEC_CLASS_DEVT_TKEY);
  2208. err_init_factory_tk:
  2209. #endif
  2210. #ifdef SEC_TSP_FACTORY_TEST
  2211. kfree(info->intensity);
  2212. kfree(info->cm_delta);
  2213. kfree(info->cm_abs);
  2214. kfree(info->reference);
  2215. sysfs_remove_group(&info->tsp_dev->kobj,
  2216. &sec_touch_factory_attr_group);
  2217. device_destroy(sec_class, SEC_CLASS_DEVT_TSP);
  2218. err_init_factory_tsp:
  2219. #endif
  2220. err_request_irq:
  2221. free_irq(client->irq, info);
  2222. input_unregister_device(info->input_dev);
  2223. err_input_register_device_failed:
  2224. input_free_device(info->input_dev);
  2225. err_input_dev_alloc_failed:
  2226. err_fw_update_failed:
  2227. #if defined(CONFIG_TOUCHSCREEN_IST30XX) && defined(CONFIG_MACH_KANAS3G_CTC)
  2228. if(!ist30xx_initialized)
  2229. #endif
  2230. melfas_ts_power_enable(0);
  2231. kfree(info);
  2232. err_alloc_data_failed:
  2233. devm_kfree(&client->dev, (void *)dt_data);
  2234. return ret;
  2235. }
  2236. static int melfas_ts_remove(struct i2c_client *client)
  2237. {
  2238. struct mms_ts_info *info = i2c_get_clientdata(client);
  2239. unregister_early_suspend(&info->early_suspend);
  2240. free_irq(client->irq, info);
  2241. melfas_ts_power_enable(0);
  2242. input_unregister_device(info->input_dev);
  2243. kfree(info);
  2244. return 0;
  2245. }
  2246. static int melfas_ts_start(struct mms_ts_info *info)
  2247. {
  2248. int ret = 0;
  2249. mutex_lock(&info->lock);
  2250. if (info->tsp_enabled) {
  2251. dev_err(&info->client->dev, "%s: already powered on\n", __func__);
  2252. ret = -1;
  2253. goto out;
  2254. }
  2255. melfas_ts_power_enable(1);
  2256. msleep(50);
  2257. mms_set_noise_mode(info);
  2258. info->tsp_enabled = true;
  2259. enable_irq(info->irq);
  2260. out:
  2261. mutex_unlock(&info->lock);
  2262. return ret;
  2263. }
  2264. static int melfas_ts_stop(struct mms_ts_info *info)
  2265. {
  2266. int ret;
  2267. u8 setLowLevelData[2];
  2268. mutex_lock(&info->lock);
  2269. if (!info->tsp_enabled) {
  2270. dev_err(&info->client->dev, "%s: already powered off\n", __func__);
  2271. ret = -1;
  2272. goto out;
  2273. }
  2274. info->tsp_enabled = false;
  2275. disable_irq(info->irq);
  2276. release_all_fingers(info);
  2277. touch_is_pressed = 0;
  2278. setLowLevelData[0] = 0xB0;
  2279. setLowLevelData[1] = 0x01;
  2280. ret = melfas_i2c_write(info->client, setLowLevelData, 2);
  2281. msleep(100);
  2282. melfas_ts_power_enable(0);
  2283. out:
  2284. mutex_unlock(&info->lock);
  2285. return ret;
  2286. }
  2287. #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND) && !defined(USE_OPEN_CLOSE)
  2288. static int melfas_ts_suspend(struct i2c_client *client, pm_message_t mesg)
  2289. {
  2290. struct mms_ts_info *info = i2c_get_clientdata(client);
  2291. return melfas_ts_stop(info);
  2292. }
  2293. static int melfas_ts_resume(struct i2c_client *client)
  2294. {
  2295. struct mms_ts_info *info = i2c_get_clientdata(client);
  2296. return melfas_ts_start(info);
  2297. }
  2298. #endif
  2299. #ifdef CONFIG_HAS_EARLYSUSPEND
  2300. static void melfas_ts_early_suspend(struct early_suspend *h)
  2301. {
  2302. struct mms_ts_info *info = container_of(h, struct mms_ts_info, early_suspend);
  2303. melfas_ts_stop(info);
  2304. }
  2305. static void melfas_ts_late_resume(struct early_suspend *h)
  2306. {
  2307. struct mms_ts_info *info = container_of(h, struct mms_ts_info, early_suspend);
  2308. melfas_ts_start(info);
  2309. }
  2310. #endif
  2311. #ifdef USE_OPEN_CLOSE
  2312. static void melfas_ts_input_close(struct input_dev *dev)
  2313. {
  2314. struct mms_ts_info *info = input_get_drvdata(dev);
  2315. dev_err(&info->client->dev, "%s\n",__func__);
  2316. melfas_ts_stop(info);
  2317. }
  2318. static int melfas_ts_input_open(struct input_dev *dev)
  2319. {
  2320. struct mms_ts_info *info = input_get_drvdata(dev);
  2321. dev_err(&info->client->dev, "%s\n",__func__);
  2322. melfas_ts_start(info);
  2323. return 0;
  2324. }
  2325. #endif
  2326. static const struct i2c_device_id melfas_ts_id[] = {
  2327. { TSP_DEVICE_NAME2, 0 },
  2328. { }
  2329. };
  2330. #ifdef CONFIG_OF
  2331. static struct of_device_id mms_match_table[] = {
  2332. { .compatible = "melfas,mms-ts",},
  2333. { },
  2334. };
  2335. #else
  2336. #define mms_match_table NULL
  2337. #endif
  2338. static struct i2c_driver melfas_ts_driver = {
  2339. .driver = {
  2340. .name = TSP_DEVICE_NAME2,
  2341. .owner = THIS_MODULE,
  2342. .of_match_table = mms_match_table,
  2343. },
  2344. .id_table = melfas_ts_id,
  2345. .probe = melfas_ts_probe,
  2346. .remove = __devexit_p(melfas_ts_remove),
  2347. #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND) && !defined(USE_OPEN_CLOSE)
  2348. .suspend = melfas_ts_suspend,
  2349. .resume = melfas_ts_resume,
  2350. #endif
  2351. };
  2352. #ifdef CONFIG_SAMSUNG_LPM_MODE
  2353. extern bool poweroff_charging;
  2354. #endif
  2355. static int __devinit melfas_ts_init(void)
  2356. {
  2357. #ifdef CONFIG_SAMSUNG_LPM_MODE
  2358. if (poweroff_charging){
  2359. pr_notice("%s : LPM Charging Mode!!\n", __func__);
  2360. return 0;
  2361. }
  2362. #endif
  2363. return i2c_add_driver(&melfas_ts_driver);
  2364. }
  2365. static void __exit melfas_ts_exit(void)
  2366. {
  2367. i2c_del_driver(&melfas_ts_driver);
  2368. }
  2369. module_init(melfas_ts_init);
  2370. module_exit(melfas_ts_exit);
  2371. MODULE_DESCRIPTION("Driver for Melfas MTSI Touchscreen Controller");
  2372. MODULE_AUTHOR("MinSang, Kim <kimms@melfas.com>");
  2373. MODULE_VERSION("0.1");
  2374. MODULE_LICENSE("GPL");