gpio_keys.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774
  1. /*
  2. * Driver for keys on GPIO lines capable of generating interrupts.
  3. *
  4. * Copyright 2005 Phil Blundell
  5. * Copyright 2010, 2011 David Jander <david@protonic.nl>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/fs.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/irq.h>
  16. #include <linux/sched.h>
  17. #include <linux/pm.h>
  18. #include <linux/slab.h>
  19. #include <linux/sysctl.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/delay.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/input.h>
  24. #include <linux/gpio_keys.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/gpio.h>
  27. #include <linux/of_platform.h>
  28. #include <linux/of_gpio.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/wakelock.h>
  31. #if defined(CONFIG_SEC_DEBUG)
  32. #include <mach/sec_debug.h>
  33. #endif
  34. #include <linux/regulator/consumer.h>
  35. /* if you want to check gpio status continually use this */
  36. #if 0
  37. #define PERIODIC_CHECK_GPIOS
  38. #endif
  39. #if defined(PERIODIC_CHECK_GPIOS)
  40. #include <mach/gpiomux.h>
  41. #include <mach/msm_iomap.h>
  42. #include <linux/io.h>
  43. struct delayed_work g_gpio_check_work;
  44. static void sec_gpiocheck_work(struct work_struct *work);
  45. enum {
  46. GPIO_IN_BIT = 0,
  47. GPIO_OUT_BIT = 1
  48. };
  49. #define GPIO_IN_OUT(gpio) (MSM_TLMM_BASE + 0x1004 + (0x10 * (gpio)))
  50. #define PERIODIC_CHECK_GAP 1000
  51. #define PERIODIC_CHECK_GPIONUM 95
  52. #endif
  53. struct gpio_button_data {
  54. struct gpio_keys_button *button;
  55. struct input_dev *input;
  56. struct timer_list timer;
  57. struct work_struct work;
  58. unsigned int timer_debounce; /* in msecs */
  59. unsigned int irq;
  60. spinlock_t lock;
  61. bool disabled;
  62. bool key_pressed;
  63. #ifdef KEY_BOOSTER
  64. struct delayed_work work_dvfs_off;
  65. struct delayed_work work_dvfs_chg;
  66. bool dvfs_lock_status;
  67. struct mutex dvfs_lock;
  68. #endif
  69. };
  70. struct gpio_keys_drvdata {
  71. struct input_dev *input;
  72. struct mutex disable_lock;
  73. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  74. struct mutex irq_lock;
  75. #endif
  76. unsigned int n_buttons;
  77. int (*enable)(struct device *dev);
  78. void (*disable)(struct device *dev);
  79. #ifdef CONFIG_SENSORS_HALL_DEBOUNCE
  80. bool debounce_set;
  81. #endif
  82. #ifdef CONFIG_SENSORS_HALL
  83. int gpio_flip_cover;
  84. int flip_code;
  85. int irq_flip_cover;
  86. bool flip_cover;
  87. struct delayed_work flip_cover_dwork;
  88. struct wake_lock flip_wake_lock;
  89. #endif
  90. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  91. bool gsm_area;
  92. bool irq_state;
  93. bool cover_state;
  94. bool workaround_set;
  95. #endif
  96. struct gpio_button_data data[0];
  97. };
  98. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  99. #define enable_hall_irq() \
  100. do { \
  101. if (drv_data->irq_state == false) { \
  102. drv_data->irq_state = true; \
  103. enable_irq(drv_data->irq_flip_cover); \
  104. pr_info("%s():irq is enabled\n", __func__);\
  105. } else { \
  106. pr_info("%s():irq is already enabled\n",\
  107. __func__);\
  108. }\
  109. } while (0)
  110. #define disable_hall_irq() \
  111. do { \
  112. if (drv_data->irq_state == true) { \
  113. drv_data->irq_state = false; \
  114. disable_irq(drv_data->irq_flip_cover); \
  115. pr_info("%s():irq is disabled\n", __func__);\
  116. } else { \
  117. pr_info("%s():irq is already disabled\n",\
  118. __func__);\
  119. }\
  120. } while (0)
  121. struct gpio_keys_drvdata *drv_data;
  122. #endif
  123. #ifdef PERIODIC_CHECK_GPIOS
  124. static unsigned __msm_gpio_get_inout_lh(unsigned gpio)
  125. {
  126. return __raw_readl(GPIO_IN_OUT(gpio)) & BIT(GPIO_IN_BIT);
  127. }
  128. static void sec_gpiocheck_work(struct work_struct *work)
  129. {
  130. struct gpiomux_setting val;
  131. u32 i = PERIODIC_CHECK_GPIONUM;
  132. __msm_gpiomux_read(i, &val);
  133. printk(KERN_DEBUG "[gpio=%d] func=%d, drv=%d, full=%d, dir=%d dat=%d\n",
  134. i, val.func, val.drv, val.pull, val.dir, __msm_gpio_get_inout_lh(i) );
  135. schedule_delayed_work(&g_gpio_check_work, msecs_to_jiffies(PERIODIC_CHECK_GAP));
  136. }
  137. #endif
  138. /*
  139. * SYSFS interface for enabling/disabling keys and switches:
  140. *
  141. * There are 4 attributes under /sys/devices/platform/gpio-keys/
  142. * keys [ro] - bitmap of keys (EV_KEY) which can be
  143. * disabled
  144. * switches [ro] - bitmap of switches (EV_SW) which can be
  145. * disabled
  146. * disabled_keys [rw] - bitmap of keys currently disabled
  147. * disabled_switches [rw] - bitmap of switches currently disabled
  148. *
  149. * Userland can change these values and hence disable event generation
  150. * for each key (or switch). Disabling a key means its interrupt line
  151. * is disabled.
  152. *
  153. * For example, if we have following switches set up as gpio-keys:
  154. * SW_DOCK = 5
  155. * SW_CAMERA_LENS_COVER = 9
  156. * SW_KEYPAD_SLIDE = 10
  157. * SW_FRONT_PROXIMITY = 11
  158. * This is read from switches:
  159. * 11-9,5
  160. * Next we want to disable proximity (11) and dock (5), we write:
  161. * 11,5
  162. * to file disabled_switches. Now proximity and dock IRQs are disabled.
  163. * This can be verified by reading the file disabled_switches:
  164. * 11,5
  165. * If we now want to enable proximity (11) switch we write:
  166. * 5
  167. * to disabled_switches.
  168. *
  169. * We can disable only those keys which don't allow sharing the irq.
  170. */
  171. /**
  172. * get_n_events_by_type() - returns maximum number of events per @type
  173. * @type: type of button (%EV_KEY, %EV_SW)
  174. *
  175. * Return value of this function can be used to allocate bitmap
  176. * large enough to hold all bits for given type.
  177. */
  178. static inline int get_n_events_by_type(int type)
  179. {
  180. BUG_ON(type != EV_SW && type != EV_KEY);
  181. return (type == EV_KEY) ? KEY_CNT : SW_CNT;
  182. }
  183. /**
  184. * gpio_keys_disable_button() - disables given GPIO button
  185. * @bdata: button data for button to be disabled
  186. *
  187. * Disables button pointed by @bdata. This is done by masking
  188. * IRQ line. After this function is called, button won't generate
  189. * input events anymore. Note that one can only disable buttons
  190. * that don't share IRQs.
  191. *
  192. * Make sure that @bdata->disable_lock is locked when entering
  193. * this function to avoid races when concurrent threads are
  194. * disabling buttons at the same time.
  195. */
  196. static void gpio_keys_disable_button(struct gpio_button_data *bdata)
  197. {
  198. if (!bdata->disabled) {
  199. /*
  200. * Disable IRQ and possible debouncing timer.
  201. */
  202. disable_irq(bdata->irq);
  203. if (bdata->timer_debounce)
  204. del_timer_sync(&bdata->timer);
  205. bdata->disabled = true;
  206. }
  207. }
  208. /**
  209. * gpio_keys_enable_button() - enables given GPIO button
  210. * @bdata: button data for button to be disabled
  211. *
  212. * Enables given button pointed by @bdata.
  213. *
  214. * Make sure that @bdata->disable_lock is locked when entering
  215. * this function to avoid races with concurrent threads trying
  216. * to enable the same button at the same time.
  217. */
  218. static void gpio_keys_enable_button(struct gpio_button_data *bdata)
  219. {
  220. if (bdata->disabled) {
  221. enable_irq(bdata->irq);
  222. bdata->disabled = false;
  223. }
  224. }
  225. /**
  226. * gpio_keys_attr_show_helper() - fill in stringified bitmap of buttons
  227. * @ddata: pointer to drvdata
  228. * @buf: buffer where stringified bitmap is written
  229. * @type: button type (%EV_KEY, %EV_SW)
  230. * @only_disabled: does caller want only those buttons that are
  231. * currently disabled or all buttons that can be
  232. * disabled
  233. *
  234. * This function writes buttons that can be disabled to @buf. If
  235. * @only_disabled is true, then @buf contains only those buttons
  236. * that are currently disabled. Returns 0 on success or negative
  237. * errno on failure.
  238. */
  239. static ssize_t gpio_keys_attr_show_helper(struct gpio_keys_drvdata *ddata,
  240. char *buf, unsigned int type,
  241. bool only_disabled)
  242. {
  243. int n_events = get_n_events_by_type(type);
  244. unsigned long *bits;
  245. ssize_t ret;
  246. int i;
  247. bits = kcalloc(BITS_TO_LONGS(n_events), sizeof(*bits), GFP_KERNEL);
  248. if (!bits)
  249. return -ENOMEM;
  250. for (i = 0; i < ddata->n_buttons; i++) {
  251. struct gpio_button_data *bdata = &ddata->data[i];
  252. if (bdata->button->type != type)
  253. continue;
  254. if (only_disabled && !bdata->disabled)
  255. continue;
  256. __set_bit(bdata->button->code, bits);
  257. }
  258. ret = bitmap_scnlistprintf(buf, PAGE_SIZE - 2, bits, n_events);
  259. buf[ret++] = '\n';
  260. buf[ret] = '\0';
  261. kfree(bits);
  262. return ret;
  263. }
  264. /**
  265. * gpio_keys_attr_store_helper() - enable/disable buttons based on given bitmap
  266. * @ddata: pointer to drvdata
  267. * @buf: buffer from userspace that contains stringified bitmap
  268. * @type: button type (%EV_KEY, %EV_SW)
  269. *
  270. * This function parses stringified bitmap from @buf and disables/enables
  271. * GPIO buttons accordingly. Returns 0 on success and negative error
  272. * on failure.
  273. */
  274. static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata,
  275. const char *buf, unsigned int type)
  276. {
  277. int n_events = get_n_events_by_type(type);
  278. unsigned long *bits;
  279. ssize_t error;
  280. int i;
  281. bits = kcalloc(BITS_TO_LONGS(n_events), sizeof(*bits), GFP_KERNEL);
  282. if (!bits)
  283. return -ENOMEM;
  284. error = bitmap_parselist(buf, bits, n_events);
  285. if (error)
  286. goto out;
  287. /* First validate */
  288. for (i = 0; i < ddata->n_buttons; i++) {
  289. struct gpio_button_data *bdata = &ddata->data[i];
  290. if (bdata->button->type != type)
  291. continue;
  292. if (test_bit(bdata->button->code, bits) &&
  293. !bdata->button->can_disable) {
  294. error = -EINVAL;
  295. goto out;
  296. }
  297. }
  298. mutex_lock(&ddata->disable_lock);
  299. for (i = 0; i < ddata->n_buttons; i++) {
  300. struct gpio_button_data *bdata = &ddata->data[i];
  301. if (bdata->button->type != type)
  302. continue;
  303. if (test_bit(bdata->button->code, bits))
  304. gpio_keys_disable_button(bdata);
  305. else
  306. gpio_keys_enable_button(bdata);
  307. }
  308. mutex_unlock(&ddata->disable_lock);
  309. out:
  310. kfree(bits);
  311. return error;
  312. }
  313. #define ATTR_SHOW_FN(name, type, only_disabled) \
  314. static ssize_t gpio_keys_show_##name(struct device *dev, \
  315. struct device_attribute *attr, \
  316. char *buf) \
  317. { \
  318. struct platform_device *pdev = to_platform_device(dev); \
  319. struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev); \
  320. \
  321. return gpio_keys_attr_show_helper(ddata, buf, \
  322. type, only_disabled); \
  323. }
  324. ATTR_SHOW_FN(keys, EV_KEY, false);
  325. ATTR_SHOW_FN(switches, EV_SW, false);
  326. ATTR_SHOW_FN(disabled_keys, EV_KEY, true);
  327. ATTR_SHOW_FN(disabled_switches, EV_SW, true);
  328. /*
  329. * ATTRIBUTES:
  330. *
  331. * /sys/devices/platform/gpio-keys/keys [ro]
  332. * /sys/devices/platform/gpio-keys/switches [ro]
  333. */
  334. static DEVICE_ATTR(keys, S_IRUGO, gpio_keys_show_keys, NULL);
  335. static DEVICE_ATTR(switches, S_IRUGO, gpio_keys_show_switches, NULL);
  336. #define ATTR_STORE_FN(name, type) \
  337. static ssize_t gpio_keys_store_##name(struct device *dev, \
  338. struct device_attribute *attr, \
  339. const char *buf, \
  340. size_t count) \
  341. { \
  342. struct platform_device *pdev = to_platform_device(dev); \
  343. struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev); \
  344. ssize_t error; \
  345. \
  346. error = gpio_keys_attr_store_helper(ddata, buf, type); \
  347. if (error) \
  348. return error; \
  349. \
  350. return count; \
  351. }
  352. ATTR_STORE_FN(disabled_keys, EV_KEY);
  353. ATTR_STORE_FN(disabled_switches, EV_SW);
  354. /*
  355. * ATTRIBUTES:
  356. *
  357. * /sys/devices/platform/gpio-keys/disabled_keys [rw]
  358. * /sys/devices/platform/gpio-keys/disables_switches [rw]
  359. */
  360. static DEVICE_ATTR(disabled_keys, S_IWUSR | S_IRUGO,
  361. gpio_keys_show_disabled_keys,
  362. gpio_keys_store_disabled_keys);
  363. static DEVICE_ATTR(disabled_switches, S_IWUSR | S_IRUGO,
  364. gpio_keys_show_disabled_switches,
  365. gpio_keys_store_disabled_switches);
  366. static struct attribute *gpio_keys_attrs[] = {
  367. &dev_attr_keys.attr,
  368. &dev_attr_switches.attr,
  369. &dev_attr_disabled_keys.attr,
  370. &dev_attr_disabled_switches.attr,
  371. NULL,
  372. };
  373. static struct attribute_group gpio_keys_attr_group = {
  374. .attrs = gpio_keys_attrs,
  375. };
  376. #ifdef KEY_BOOSTER
  377. static void gpio_key_change_dvfs_lock(struct work_struct *work)
  378. {
  379. struct gpio_button_data *bdata =
  380. container_of(work,
  381. struct gpio_button_data, work_dvfs_chg.work);
  382. int retval;
  383. mutex_lock(&bdata->dvfs_lock);
  384. retval = set_freq_limit(DVFS_TOUCH_ID,
  385. MIN_TOUCH_LIMIT_SECOND);
  386. if (retval < 0)
  387. printk(KERN_ERR
  388. "%s: booster change failed(%d).\n",
  389. __func__, retval);
  390. mutex_unlock(&bdata->dvfs_lock);
  391. }
  392. static void gpio_key_set_dvfs_off(struct work_struct *work)
  393. {
  394. struct gpio_button_data *bdata =
  395. container_of(work,
  396. struct gpio_button_data, work_dvfs_off.work);
  397. int retval;
  398. mutex_lock(&bdata->dvfs_lock);
  399. retval = set_freq_limit(DVFS_TOUCH_ID, -1);
  400. if (retval < 0)
  401. printk(KERN_ERR
  402. "%s: booster stop failed(%d).\n",
  403. __func__, retval);
  404. bdata->dvfs_lock_status = false;
  405. mutex_unlock(&bdata->dvfs_lock);
  406. }
  407. static void gpio_key_set_dvfs_lock(struct gpio_button_data *bdata,
  408. uint32_t on)
  409. {
  410. mutex_lock(&bdata->dvfs_lock);
  411. if (on == 0) {
  412. if (bdata->dvfs_lock_status) {
  413. schedule_delayed_work(&bdata->work_dvfs_off,
  414. msecs_to_jiffies(KEY_BOOSTER_OFF_TIME));
  415. }
  416. } else if (on == 1) {
  417. cancel_delayed_work(&bdata->work_dvfs_off);
  418. if (!bdata->dvfs_lock_status) {
  419. int ret = 0;
  420. ret = set_freq_limit(DVFS_TOUCH_ID,
  421. MIN_TOUCH_LIMIT);
  422. if (ret < 0)
  423. printk(KERN_ERR
  424. "%s: cpu first lock failed(%d)\n",
  425. __func__, ret);
  426. schedule_delayed_work(&bdata->work_dvfs_chg,
  427. msecs_to_jiffies(KEY_BOOSTER_CHG_TIME));
  428. bdata->dvfs_lock_status = true;
  429. }
  430. }
  431. mutex_unlock(&bdata->dvfs_lock);
  432. }
  433. static int gpio_key_init_dvfs(struct gpio_button_data *bdata)
  434. {
  435. mutex_init(&bdata->dvfs_lock);
  436. INIT_DELAYED_WORK(&bdata->work_dvfs_off, gpio_key_set_dvfs_off);
  437. INIT_DELAYED_WORK(&bdata->work_dvfs_chg, gpio_key_change_dvfs_lock);
  438. bdata->dvfs_lock_status = false;
  439. return 0;
  440. }
  441. #endif
  442. static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
  443. {
  444. const struct gpio_keys_button *button = bdata->button;
  445. struct input_dev *input = bdata->input;
  446. unsigned int type = button->type ?: EV_KEY;
  447. int state = (gpio_get_value_cansleep(button->gpio) ? 1 : 0) ^ button->active_low;
  448. printk(KERN_INFO "%s: %s key is %s\n",
  449. __func__, button->desc, state ? "pressed" : "released");
  450. #ifdef CONFIG_SEC_DEBUG
  451. sec_debug_check_crash_key(button->code, state);
  452. #endif
  453. if (type == EV_ABS) {
  454. if (state)
  455. input_event(input, type, button->code, button->value);
  456. } else {
  457. input_event(input, type, button->code, !!state);
  458. }
  459. input_sync(input);
  460. }
  461. static void gpio_keys_gpio_work_func(struct work_struct *work)
  462. {
  463. struct gpio_button_data *bdata =
  464. container_of(work, struct gpio_button_data, work);
  465. #ifdef KEY_BOOSTER
  466. const struct gpio_keys_button *button = bdata->button;
  467. int state = (gpio_get_value_cansleep(button->gpio) ? 1 : 0) ^ button->active_low;
  468. #endif
  469. gpio_keys_gpio_report_event(bdata);
  470. #ifdef KEY_BOOSTER
  471. if (button->code == KEY_HOMEPAGE)
  472. {
  473. gpio_key_set_dvfs_lock(bdata, !!state);
  474. }
  475. #endif
  476. }
  477. static void gpio_keys_gpio_timer(unsigned long _data)
  478. {
  479. struct gpio_button_data *bdata = (struct gpio_button_data *)_data;
  480. schedule_work(&bdata->work);
  481. }
  482. static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id)
  483. {
  484. struct gpio_button_data *bdata = dev_id;
  485. BUG_ON(irq != bdata->irq);
  486. if (bdata->timer_debounce)
  487. mod_timer(&bdata->timer,
  488. jiffies + msecs_to_jiffies(bdata->timer_debounce));
  489. else
  490. schedule_work(&bdata->work);
  491. return IRQ_HANDLED;
  492. }
  493. static void gpio_keys_irq_timer(unsigned long _data)
  494. {
  495. struct gpio_button_data *bdata = (struct gpio_button_data *)_data;
  496. struct input_dev *input = bdata->input;
  497. unsigned long flags;
  498. spin_lock_irqsave(&bdata->lock, flags);
  499. if (bdata->key_pressed) {
  500. input_event(input, EV_KEY, bdata->button->code, 0);
  501. input_sync(input);
  502. bdata->key_pressed = false;
  503. }
  504. spin_unlock_irqrestore(&bdata->lock, flags);
  505. }
  506. static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id)
  507. {
  508. struct gpio_button_data *bdata = dev_id;
  509. const struct gpio_keys_button *button = bdata->button;
  510. struct input_dev *input = bdata->input;
  511. unsigned long flags;
  512. BUG_ON(irq != bdata->irq);
  513. spin_lock_irqsave(&bdata->lock, flags);
  514. if (!bdata->key_pressed) {
  515. input_event(input, EV_KEY, button->code, 1);
  516. input_sync(input);
  517. if (!bdata->timer_debounce) {
  518. input_event(input, EV_KEY, button->code, 0);
  519. input_sync(input);
  520. goto out;
  521. }
  522. bdata->key_pressed = true;
  523. }
  524. if (bdata->timer_debounce)
  525. mod_timer(&bdata->timer,
  526. jiffies + msecs_to_jiffies(bdata->timer_debounce));
  527. out:
  528. spin_unlock_irqrestore(&bdata->lock, flags);
  529. return IRQ_HANDLED;
  530. }
  531. static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
  532. struct input_dev *input,
  533. struct gpio_button_data *bdata,
  534. struct gpio_keys_button *button)
  535. {
  536. const char *desc = button->desc ? button->desc : "gpio_keys";
  537. struct device *dev = &pdev->dev;
  538. irq_handler_t isr;
  539. unsigned long irqflags;
  540. int irq, error;
  541. bdata->input = input;
  542. bdata->button = button;
  543. spin_lock_init(&bdata->lock);
  544. if (gpio_is_valid(button->gpio)) {
  545. error = gpio_request(button->gpio, desc);
  546. if (error < 0) {
  547. dev_err(dev, "Failed to request GPIO %d, error %d\n",
  548. button->gpio, error);
  549. return error;
  550. }
  551. error = gpio_direction_input(button->gpio);
  552. if (error < 0) {
  553. dev_err(dev,
  554. "Failed to configure direction for GPIO %d, error %d\n",
  555. button->gpio, error);
  556. goto fail;
  557. }
  558. if (button->debounce_interval) {
  559. error = gpio_set_debounce(button->gpio,
  560. button->debounce_interval * 1000);
  561. /* use timer if gpiolib doesn't provide debounce */
  562. if (error < 0)
  563. bdata->timer_debounce =
  564. button->debounce_interval;
  565. }
  566. irq = gpio_to_irq(button->gpio);
  567. if (irq < 0) {
  568. error = irq;
  569. dev_err(dev,
  570. "Unable to get irq number for GPIO %d, error %d\n",
  571. button->gpio, error);
  572. goto fail;
  573. }
  574. bdata->irq = irq;
  575. INIT_WORK(&bdata->work, gpio_keys_gpio_work_func);
  576. setup_timer(&bdata->timer,
  577. gpio_keys_gpio_timer, (unsigned long)bdata);
  578. isr = gpio_keys_gpio_isr;
  579. irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;
  580. } else {
  581. if (!button->irq) {
  582. dev_err(dev, "No IRQ specified\n");
  583. return -EINVAL;
  584. }
  585. bdata->irq = button->irq;
  586. if (button->type && button->type != EV_KEY) {
  587. dev_err(dev, "Only EV_KEY allowed for IRQ buttons.\n");
  588. return -EINVAL;
  589. }
  590. bdata->timer_debounce = button->debounce_interval;
  591. setup_timer(&bdata->timer,
  592. gpio_keys_irq_timer, (unsigned long)bdata);
  593. isr = gpio_keys_irq_isr;
  594. irqflags = 0;
  595. }
  596. input_set_capability(input, button->type ?: EV_KEY, button->code);
  597. /*
  598. * If platform has specified that the button can be disabled,
  599. * we don't want it to share the interrupt line.
  600. */
  601. if (!button->can_disable)
  602. irqflags |= IRQF_SHARED;
  603. error = request_any_context_irq(bdata->irq, isr, irqflags, desc, bdata);
  604. if (error < 0) {
  605. dev_err(dev, "Unable to claim irq %d; error %d\n",
  606. bdata->irq, error);
  607. goto fail;
  608. }
  609. return 0;
  610. fail:
  611. if (gpio_is_valid(button->gpio))
  612. gpio_free(button->gpio);
  613. return error;
  614. }
  615. #if defined(CONFIG_DUAL_LCD)
  616. int samsung_switching_lcd(int flip);
  617. int samsung_switching_tsp(int flip);
  618. int samsung_switching_tkey(int flip);
  619. int samsung_switching_ssp(int flip);
  620. #endif
  621. #ifdef CONFIG_SENSORS_HALL
  622. static int flip_status_before;
  623. #ifdef CONFIG_SEC_FACTORY
  624. static void flip_cover_work(struct work_struct *work)
  625. {
  626. struct gpio_keys_drvdata *ddata =
  627. container_of(work, struct gpio_keys_drvdata,
  628. flip_cover_dwork.work);
  629. #if !defined (CONFIG_SEC_MILLET_PROJECT) || !defined (CONFIG_SEC_T8_PROJECT)
  630. int comp_val[2]={0};
  631. #else
  632. int comp_val[3]={0};
  633. #endif
  634. comp_val[0] = gpio_get_value(ddata->gpio_flip_cover);
  635. #if !defined (CONFIG_SEC_MILLET_PROJECT) || !defined (CONFIG_SEC_T8_PROJECT)
  636. mdelay(30);
  637. #else
  638. mdelay(10);
  639. #endif
  640. comp_val[1] = gpio_get_value(ddata->gpio_flip_cover);
  641. #if defined (CONFIG_SEC_MILLET_PROJECT) || defined (CONFIG_SEC_T8_PROJECT)
  642. mdelay(10);
  643. comp_val[2] = gpio_get_value(ddata->gpio_flip_cover);
  644. #endif
  645. #if !defined (CONFIG_SEC_MILLET_PROJECT) || !defined (CONFIG_SEC_T8_PROJECT)
  646. if (comp_val[0] == comp_val[1]) {
  647. #else
  648. if ((comp_val[0] == comp_val[1]) && (comp_val[0] == comp_val[2])) {
  649. #endif
  650. if (ddata->flip_code == SW_LID)
  651. ddata->flip_cover = !gpio_get_value(ddata->gpio_flip_cover);
  652. else
  653. ddata->flip_cover = gpio_get_value(ddata->gpio_flip_cover);
  654. printk(KERN_DEBUG "[keys] %s : %d code 0x%x\n",
  655. __func__, ddata->flip_cover, ddata->flip_code);
  656. input_report_switch(ddata->input,
  657. ddata->flip_code, ddata->flip_cover);
  658. input_sync(ddata->input);
  659. if (ddata->flip_cover != flip_status_before) {
  660. #if defined(CONFIG_DUAL_LCD)
  661. samsung_switching_lcd(ddata->flip_cover);
  662. samsung_switching_tsp(ddata->flip_cover);
  663. samsung_switching_tkey(ddata->flip_cover);
  664. samsung_switching_ssp(ddata->flip_cover);
  665. #endif
  666. }
  667. flip_status_before = ddata->flip_cover;
  668. } else {
  669. printk(KERN_DEBUG "%s : Value is not same!\n", __func__);
  670. }
  671. }
  672. #else // CONFIG_SEC_FACTORY
  673. static void flip_cover_work(struct work_struct *work)
  674. {
  675. struct gpio_keys_drvdata *ddata =
  676. container_of(work, struct gpio_keys_drvdata,
  677. flip_cover_dwork.work);
  678. if (ddata->flip_code == SW_LID)
  679. ddata->flip_cover = !gpio_get_value(ddata->gpio_flip_cover);
  680. else
  681. ddata->flip_cover = gpio_get_value(ddata->gpio_flip_cover);
  682. printk(KERN_DEBUG "[keys] %s : %d code 0x%x\n",
  683. __func__, ddata->flip_cover, ddata->flip_code);
  684. input_report_switch(ddata->input,
  685. ddata->flip_code, ddata->flip_cover);
  686. input_sync(ddata->input);
  687. if (ddata->flip_cover != flip_status_before) {
  688. #if defined(CONFIG_DUAL_LCD)
  689. samsung_switching_lcd(ddata->flip_cover);
  690. samsung_switching_tsp(ddata->flip_cover);
  691. samsung_switching_tkey(ddata->flip_cover);
  692. samsung_switching_ssp(ddata->flip_cover);
  693. #endif
  694. }
  695. flip_status_before = ddata->flip_cover;
  696. }
  697. #endif // CONFIG_SEC_FACTORY
  698. #if defined (CONFIG_SEC_MILLET_PROJECT) || defined (CONFIG_SEC_T8_PROJECT)
  699. static irqreturn_t flip_cover_detect(int irq, void *dev_id)
  700. {
  701. struct gpio_keys_drvdata *ddata = dev_id;
  702. #define HALL_COMPARISONS 6
  703. int comp_val[HALL_COMPARISONS]={0};
  704. int i;
  705. comp_val[0] = gpio_get_value(ddata->gpio_flip_cover);
  706. if(comp_val[0]) {
  707. wake_lock_timeout(&ddata->flip_wake_lock, HZ * 5 / 100); /* 50ms */
  708. } else {
  709. wake_unlock(&ddata->flip_wake_lock);
  710. }
  711. pr_info("[keys] %s flip_status : %d (%s)\n",
  712. __func__, comp_val[0], comp_val[0]?"on":"off");
  713. for(i=1;i<HALL_COMPARISONS;i++){
  714. mdelay(6);
  715. comp_val[i] = gpio_get_value(ddata->gpio_flip_cover);
  716. if(comp_val[i]!=comp_val[0]){
  717. pr_err("%s : Value is not same!\n", __func__);
  718. goto out;
  719. }
  720. }
  721. ddata->flip_cover = comp_val[0];
  722. pr_info("[keys] hall ic reported value: %d (%s)\n",
  723. ddata->flip_cover, ddata->flip_cover?"on":"off");
  724. input_report_switch(ddata->input,
  725. SW_FLIP, ddata->flip_cover);
  726. input_sync(ddata->input);
  727. out:
  728. return IRQ_HANDLED;
  729. }
  730. #else
  731. static irqreturn_t flip_cover_detect(int irq, void *dev_id)
  732. {
  733. bool flip_status;
  734. struct gpio_keys_drvdata *ddata = dev_id;
  735. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  736. bool debounce_status;
  737. #endif
  738. #ifdef CONFIG_SENSORS_HALL_DEBOUNCE
  739. int DTIME_IRQ, DTIME_WAKE;
  740. /* Set Debounce time for HALL IC IRQ(wake_lock / IRQ recheck)
  741. * ON : 140ms / 70ms
  742. * OFF : 50ms / 10ms
  743. */
  744. DTIME_IRQ = ddata->debounce_set ? (HZ*7/100) : (HZ*1/100);
  745. DTIME_WAKE = ddata->debounce_set ? (HZ*14/100) : (HZ*5/100);
  746. #endif
  747. if (ddata->flip_code == SW_LID)
  748. flip_status = !gpio_get_value(ddata->gpio_flip_cover);
  749. else
  750. flip_status = gpio_get_value(ddata->gpio_flip_cover);
  751. cancel_delayed_work_sync(&ddata->flip_cover_dwork);
  752. #ifdef CONFIG_SENSORS_HALL_DEBOUNCE
  753. printk(KERN_DEBUG "[keys] %s flip_satatus : %d, IRQt : %d, WAKEt : %d\n",
  754. __func__, flip_status, DTIME_IRQ, DTIME_WAKE);
  755. if(flip_status) {
  756. wake_lock_timeout(&ddata->flip_wake_lock, HZ * DTIME_WAKE);
  757. schedule_delayed_work(&ddata->flip_cover_dwork, DTIME_IRQ);
  758. } else {
  759. wake_unlock(&ddata->flip_wake_lock);
  760. wake_lock_timeout(&ddata->flip_wake_lock, HZ * DTIME_WAKE);
  761. schedule_delayed_work(&ddata->flip_cover_dwork, DTIME_IRQ);
  762. }
  763. #else /* CONFIG_SENSORS_HALL_DEBOUNCE */
  764. printk(KERN_DEBUG "[keys] %s flip_satatus : %d\n",
  765. __func__, flip_status);
  766. if(flip_status) {
  767. wake_lock_timeout(&ddata->flip_wake_lock, HZ * 5 / 100); /* 50ms */
  768. schedule_delayed_work(&ddata->flip_cover_dwork, HZ * 1 / 100); /* 10ms */
  769. } else {
  770. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  771. if (ddata->gsm_area) {
  772. mdelay(7);
  773. debounce_status = gpio_get_value(ddata->gpio_flip_cover);
  774. if (debounce_status != flip_status) {
  775. printk(KERN_DEBUG "[keys] %s filp ignore IRQ\n",
  776. __func__);
  777. return IRQ_HANDLED;
  778. }
  779. }
  780. #endif /* CONFIG_SENSORS_HALL_IRQ_CTRL */
  781. wake_unlock(&ddata->flip_wake_lock);
  782. schedule_delayed_work(&ddata->flip_cover_dwork, 0);
  783. }
  784. #endif /* CONFIG_SENSORS_HALL_DEBOUNCE */
  785. return IRQ_HANDLED;
  786. }
  787. #endif
  788. #endif /* CONFIG_SENSORS_HALL */
  789. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  790. void gpio_hall_irq_set(int state, bool auth_changed)
  791. {
  792. if (auth_changed)
  793. drv_data->cover_state = state;
  794. if (drv_data->gsm_area) {
  795. pr_info("%s: cover state = %d\n",
  796. __func__, drv_data->cover_state);
  797. mutex_lock(&drv_data->irq_lock);
  798. if (state)
  799. enable_hall_irq();
  800. else
  801. disable_hall_irq();
  802. mutex_unlock(&drv_data->irq_lock);
  803. }
  804. }
  805. #endif
  806. static int gpio_keys_open(struct input_dev *input)
  807. {
  808. struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
  809. #ifdef CONFIG_SENSORS_HALL
  810. int ret = 0;
  811. int irq = gpio_to_irq(ddata->gpio_flip_cover);
  812. if(ddata->gpio_flip_cover == 0) {
  813. printk(KERN_DEBUG"[HALL_IC] : %s skip flip\n", __func__);
  814. goto skip_flip;
  815. }
  816. printk(KERN_DEBUG"[HALL_IC] : %s\n", __func__);
  817. INIT_DELAYED_WORK(&ddata->flip_cover_dwork, flip_cover_work);
  818. ret = request_threaded_irq(
  819. irq, NULL,
  820. flip_cover_detect,
  821. IRQF_DISABLED | IRQF_TRIGGER_RISING |
  822. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  823. "flip_cover", ddata);
  824. if (ret < 0) {
  825. printk(KERN_ERR "keys: failed to request flip cover irq %d gpio %d\n",
  826. irq, ddata->gpio_flip_cover);
  827. } else {
  828. /* update the current status */
  829. schedule_delayed_work(&ddata->flip_cover_dwork, HZ / 2);
  830. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  831. ddata->irq_state = true;
  832. #endif
  833. }
  834. skip_flip:
  835. #endif
  836. return ddata->enable ? ddata->enable(input->dev.parent) : 0;
  837. }
  838. static void gpio_keys_close(struct input_dev *input)
  839. {
  840. struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
  841. if (ddata->disable)
  842. ddata->disable(input->dev.parent);
  843. }
  844. #ifdef CONFIG_USE_VM_KEYBOARD_REJECT
  845. bool reject_keyboard_specific_key;
  846. EXPORT_SYMBOL(reject_keyboard_specific_key);
  847. static ssize_t sysfs_reject_keyboard_spec_key_show(struct device *dev,
  848. struct device_attribute *attr, char *buf)
  849. {
  850. snprintf(buf, 10, "%s\n", reject_keyboard_specific_key ? "ENABLE" : "DISABLE");
  851. return strlen(buf);
  852. }
  853. static ssize_t sysfs_reject_keyboard_spec_key_store(struct device *dev,
  854. struct device_attribute *attr, const char *buf,
  855. size_t count)
  856. {
  857. if (!strncasecmp(buf, "ENABLE", 6))
  858. reject_keyboard_specific_key = true;
  859. else if (!strncasecmp(buf, "DISABLE", 7))
  860. reject_keyboard_specific_key = false;
  861. else
  862. pr_err("%s: Wrong command, current state %s\n",
  863. __func__,
  864. reject_keyboard_specific_key ? "ENABLE" : "DISALBE");
  865. return count;
  866. }
  867. static DEVICE_ATTR(reject_key_comb, 0660, sysfs_reject_keyboard_spec_key_show, sysfs_reject_keyboard_spec_key_store);
  868. #endif
  869. #ifdef CONFIG_SENSORS_HALL_DEBOUNCE
  870. static ssize_t sysfs_hall_debounce_show(struct device *dev,
  871. struct device_attribute *attr, char *buf)
  872. {
  873. struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
  874. const char *mode;
  875. if (ddata->debounce_set)
  876. mode = "DEBOUNCE_TIME_ON";
  877. else
  878. mode = "DEBOUNCE_TIME_OFF";
  879. return sprintf(buf, "%s\n", mode);
  880. }
  881. static ssize_t sysfs_hall_debounce_store(struct device *dev,
  882. struct device_attribute *attr, const char *buf, size_t count)
  883. {
  884. struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
  885. if (!strncasecmp(buf, "ON", 2))
  886. ddata->debounce_set = true;
  887. else if (!strncasecmp(buf, "OFF", 3))
  888. ddata->debounce_set = false;
  889. else
  890. pr_info("%s:Wrong command, current state %s\n", __func__, buf);
  891. return count;
  892. }
  893. static DEVICE_ATTR(hall_irq_ctrl, 0660,
  894. sysfs_hall_debounce_show,
  895. sysfs_hall_debounce_store);
  896. #endif
  897. #ifdef CONFIG_SENSORS_HALL
  898. static ssize_t sysfs_hall_detect_show(struct device *dev,
  899. struct device_attribute *attr, char *buf)
  900. {
  901. struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
  902. if (ddata->flip_cover)
  903. snprintf(buf, 6, "%s\n", "OPEN");
  904. else
  905. snprintf(buf, 7, "%s\n", "CLOSE");
  906. return strlen(buf);
  907. }
  908. static DEVICE_ATTR(hall_detect, 0664, sysfs_hall_detect_show, NULL);
  909. #endif
  910. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  911. static ssize_t sysfs_hall_irq_ctrl_store(struct device *dev,
  912. struct device_attribute *attr, const char *buf,
  913. size_t count)
  914. {
  915. struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
  916. if (ddata->workaround_set) {
  917. if (!strncasecmp(buf, "ON", 2)) {
  918. ddata->gsm_area = true;
  919. if (!ddata->cover_state)
  920. gpio_hall_irq_set(disable, false);
  921. } else if (!strncasecmp(buf, "OFF", 3)) {
  922. gpio_hall_irq_set(enable, false);
  923. ddata->gsm_area = false;
  924. } else {
  925. pr_info("%s: Wrong command, current state %s\n",
  926. __func__, ddata->gsm_area?"ON":"OFF");
  927. }
  928. }
  929. return count;
  930. }
  931. static DEVICE_ATTR(hall_irq_ctrl, S_IWUSR | S_IWGRP, NULL, sysfs_hall_irq_ctrl_store);
  932. #endif
  933. /*
  934. * Handlers for alternative sources of platform_data
  935. */
  936. #ifdef CONFIG_OF
  937. /*
  938. * Translate OpenFirmware node properties into platform_data
  939. */
  940. static int gpio_keys_get_devtree_pdata(struct device *dev,
  941. struct gpio_keys_platform_data *pdata)
  942. {
  943. struct device_node *node, *pp;
  944. int i;
  945. struct gpio_keys_button *buttons;
  946. struct regulator *vddo_vreg;
  947. u32 reg;
  948. node = dev->of_node;
  949. if (node == NULL)
  950. return -ENODEV;
  951. memset(pdata, 0, sizeof *pdata);
  952. pdata->rep = !!of_get_property(node, "autorepeat", NULL);
  953. pdata->name = of_get_property(node, "input-name", NULL);
  954. vddo_vreg = devm_regulator_get(dev, "vddo");
  955. if (IS_ERR(vddo_vreg))
  956. dev_err(dev, "[Keys] no regulator: ignoring\n");
  957. else{
  958. if(!of_property_read_u32(node, "vddo-voltage", &reg))
  959. regulator_set_voltage(vddo_vreg, reg*1000, reg*1000);
  960. if(regulator_enable(vddo_vreg))
  961. return -EINVAL;
  962. }
  963. /* First count the subnodes */
  964. pdata->nbuttons = 0;
  965. pp = NULL;
  966. while ((pp = of_get_next_child(node, pp)))
  967. pdata->nbuttons++;
  968. if (pdata->nbuttons == 0)
  969. return -ENODEV;
  970. buttons = kzalloc(pdata->nbuttons * (sizeof *buttons), GFP_KERNEL);
  971. if (!buttons)
  972. return -ENOMEM;
  973. pp = NULL;
  974. i = 0;
  975. while ((pp = of_get_next_child(node, pp))) {
  976. enum of_gpio_flags flags;
  977. if (!of_find_property(pp, "gpios", NULL)) {
  978. pdata->nbuttons--;
  979. dev_warn(dev, "Found button without gpios\n");
  980. continue;
  981. }
  982. buttons[i].gpio = of_get_gpio_flags(pp, 0, &flags);
  983. buttons[i].active_low = flags & OF_GPIO_ACTIVE_LOW;
  984. if (of_property_read_u32(pp, "linux,code", &reg)) {
  985. dev_err(dev, "Button without keycode: 0x%x\n", buttons[i].gpio);
  986. goto out_fail;
  987. }
  988. buttons[i].code = reg;
  989. buttons[i].desc = of_get_property(pp, "label", NULL);
  990. #ifdef CONFIG_SENSORS_HALL
  991. if ((buttons[i].code == SW_FLIP) || (buttons[i].code == SW_LID)) {
  992. pdata->gpio_flip_cover = buttons[i].gpio;
  993. pdata->flip_code = buttons[i].code;
  994. pdata->nbuttons--;
  995. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  996. pdata->workaround_set = (of_property_read_bool(pp, "hall_wa_disable") ? false : true);
  997. #endif
  998. dev_info(dev, "[Hall_IC] device tree was founded\n");
  999. continue;
  1000. }
  1001. #endif
  1002. if (of_property_read_u32(pp, "linux,input-type", &reg) == 0)
  1003. buttons[i].type = reg;
  1004. else
  1005. buttons[i].type = EV_KEY;
  1006. buttons[i].wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL);
  1007. if (of_property_read_u32(pp, "debounce-interval", &reg) == 0)
  1008. buttons[i].debounce_interval = reg;
  1009. else
  1010. buttons[i].debounce_interval = 5;
  1011. dev_info(dev, "%s: label:%s, gpio:%d, code:%d, type:%d, debounce:%d\n",
  1012. __func__, buttons[i].desc, buttons[i].gpio,
  1013. buttons[i].code, buttons[i].type,
  1014. buttons[i].debounce_interval);
  1015. i++;
  1016. }
  1017. pdata->buttons = buttons;
  1018. return 0;
  1019. out_fail:
  1020. kfree(buttons);
  1021. return -ENODEV;
  1022. }
  1023. static struct of_device_id gpio_keys_of_match[] = {
  1024. { .compatible = "gpio-keys", },
  1025. { },
  1026. };
  1027. MODULE_DEVICE_TABLE(of, gpio_keys_of_match);
  1028. #else
  1029. static int gpio_keys_get_devtree_pdata(struct device *dev,
  1030. struct gpio_keys_platform_data *altp)
  1031. {
  1032. return -ENODEV;
  1033. }
  1034. #define gpio_keys_of_match NULL
  1035. #endif
  1036. static void gpio_remove_key(struct gpio_button_data *bdata)
  1037. {
  1038. free_irq(bdata->irq, bdata);
  1039. if (bdata->timer_debounce)
  1040. del_timer_sync(&bdata->timer);
  1041. cancel_work_sync(&bdata->work);
  1042. if (gpio_is_valid(bdata->button->gpio))
  1043. gpio_free(bdata->button->gpio);
  1044. }
  1045. #ifdef CONFIG_SEC_PATEK_PROJECT
  1046. extern int check_short_key(void);
  1047. #endif
  1048. #if defined(CONFIG_SEC_PATEK_PROJECT) || defined(CONFIG_SEC_S_PROJECT)
  1049. extern int check_short_pkey(void); // using qpnp_power_on.c
  1050. #endif
  1051. static ssize_t sysfs_key_onoff_show(struct device *dev,
  1052. struct device_attribute *attr, char *buf)
  1053. {
  1054. struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
  1055. int index ;
  1056. int state = 0;
  1057. for (index = 0; index < ddata->n_buttons; index++) {
  1058. struct gpio_button_data *button;
  1059. button = &ddata->data[index];
  1060. state = (gpio_get_value_cansleep(button->button->gpio) ? 1 : 0)\
  1061. ^ button->button->active_low;
  1062. if (state == 1)
  1063. break;
  1064. }
  1065. #ifdef CONFIG_SEC_PATEK_PROJECT
  1066. if(state || check_short_key() || check_short_pkey())
  1067. state = 1;
  1068. #endif
  1069. pr_info("key state:%d\n", state);
  1070. return snprintf(buf, 5, "%d\n", state);
  1071. }
  1072. static DEVICE_ATTR(sec_key_pressed, 0664 , sysfs_key_onoff_show, NULL);
  1073. #if defined(CONFIG_SEC_S_PROJECT)
  1074. static ssize_t sysfs_key_code_show(struct device *dev,
  1075. struct device_attribute *attr, char *buf)
  1076. {
  1077. struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
  1078. int i;
  1079. int volume_up=0, volume_down=0, power=0;
  1080. for (i = 0; i < ddata->n_buttons; i++) {
  1081. struct gpio_button_data *bdata = &ddata->data[i];
  1082. if(bdata->button->code==KEY_VOLUMEUP)
  1083. volume_up = (gpio_get_value_cansleep(bdata->button->gpio) ? 1 : 0) ^ bdata->button->active_low;
  1084. else if(bdata->button->code==KEY_VOLUMEDOWN)
  1085. volume_down = (gpio_get_value_cansleep(bdata->button->gpio) ? 1 : 0) ^ bdata->button->active_low;
  1086. //pr_info("%s, code=%d %d/%d\n", __func__,bdata->button->code, i,ddata->n_buttons );
  1087. }
  1088. power = check_short_pkey();
  1089. sprintf(buf, "%d %d %d", volume_up, volume_down, power);
  1090. return strlen(buf);
  1091. }
  1092. static DEVICE_ATTR(sec_key_pressed_code, 0664 , sysfs_key_code_show, NULL);
  1093. #endif
  1094. /* the volume keys can be the wakeup keys in special case */
  1095. static ssize_t wakeup_enable(struct device *dev,
  1096. struct device_attribute *attr, const char *buf, size_t count)
  1097. {
  1098. struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
  1099. int n_events = get_n_events_by_type(EV_KEY);
  1100. unsigned long *bits;
  1101. ssize_t error;
  1102. int i;
  1103. bits = kcalloc(BITS_TO_LONGS(n_events),
  1104. sizeof(*bits), GFP_KERNEL);
  1105. if (!bits)
  1106. return -ENOMEM;
  1107. error = bitmap_parselist(buf, bits, n_events);
  1108. if (error)
  1109. goto out;
  1110. for (i = 0; i < ddata->n_buttons; i++) {
  1111. struct gpio_button_data *button = &ddata->data[i];
  1112. if (button->button->type == EV_KEY) {
  1113. if (test_bit(button->button->code, bits))
  1114. button->button->wakeup = 1;
  1115. else
  1116. button->button->wakeup = 0;
  1117. pr_info("%s wakeup status %d\n", button->button->desc,\
  1118. button->button->wakeup);
  1119. }
  1120. }
  1121. out:
  1122. kfree(bits);
  1123. return count;
  1124. }
  1125. static DEVICE_ATTR(wakeup_keys, 0664, NULL, wakeup_enable);
  1126. #if defined (CONFIG_SEC_MILLET_PROJECT) || defined (CONFIG_SEC_BERLUTI_PROJECT) || defined (CONFIG_SEC_T8_PROJECT)
  1127. struct regulator *lvs1_1p8 = NULL;
  1128. #endif
  1129. #if defined(CONFIG_SEC_PATEK_PROJECT)
  1130. static struct regulator *keyled_3p3=NULL;
  1131. static int keypadled_powerset(struct device *dev)
  1132. {
  1133. int ret;
  1134. printk(KERN_ERR "[Key_LED] %s : %d\n",__func__,__LINE__);
  1135. if(!keyled_3p3)
  1136. keyled_3p3 = regulator_get(NULL, "8084_l22");
  1137. if (IS_ERR(keyled_3p3)) {
  1138. pr_err("%s: could not get vdda vreg, rc=%ld\n",
  1139. __func__, PTR_ERR(keyled_3p3));
  1140. return PTR_ERR(keyled_3p3);
  1141. }
  1142. ret = regulator_set_voltage(keyled_3p3,
  1143. 3300000, 3300000);
  1144. if (ret)
  1145. pr_err("%s: error vreg_l22 set voltage ret=%d\n",
  1146. __func__, ret);
  1147. printk(KERN_ERR "[Key_LED] %s : %d\n",__func__,__LINE__);
  1148. return 0;
  1149. }
  1150. static int keypadled_poweron(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
  1151. {
  1152. int ret;
  1153. int data;
  1154. sscanf(buf, "%d", &data);
  1155. printk(KERN_ERR "[Key_LED] %s : %d data=%d\n",__func__,__LINE__,data);
  1156. if(!keyled_3p3){
  1157. pr_err("%s: keyled_3p3 is null\n",__func__);
  1158. return size;
  1159. }
  1160. if(data){
  1161. ret = regulator_enable(keyled_3p3);
  1162. if (ret)
  1163. pr_err("%s: error l22 enabling regulator\n", __func__);
  1164. }
  1165. else{
  1166. ret = regulator_disable(keyled_3p3);
  1167. if (ret)
  1168. pr_err("%s: error l22 disabling regulator\n", __func__);
  1169. }
  1170. printk(KERN_ERR "[Key_LED] %s : %d\n",__func__,__LINE__);
  1171. return size;
  1172. }
  1173. static DEVICE_ATTR(brightness, 0664, NULL, keypadled_poweron);
  1174. static ssize_t sysfs_flip_status_show(struct device *dev,
  1175. struct device_attribute *attr, char *buf)
  1176. {
  1177. struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
  1178. if (ddata->flip_cover)
  1179. snprintf(buf, 3, "0\n");
  1180. else
  1181. snprintf(buf, 3, "1\n");
  1182. return strlen(buf);
  1183. }
  1184. static DEVICE_ATTR(flipStatus, 0444, sysfs_flip_status_show, NULL);
  1185. #endif
  1186. static int __devinit gpio_keys_probe(struct platform_device *pdev)
  1187. {
  1188. const struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
  1189. struct gpio_keys_drvdata *ddata;
  1190. struct gpio_keys_button *button = NULL;
  1191. struct gpio_button_data *bdata = NULL;
  1192. struct device *dev = &pdev->dev;
  1193. struct gpio_keys_platform_data alt_pdata;
  1194. struct input_dev *input;
  1195. int i, error;
  1196. int wakeup = 0;
  1197. int ret;
  1198. struct device *sec_key;
  1199. #ifdef CONFIG_SEC_PATEK_PROJECT
  1200. struct device *sec_keypad;
  1201. struct device *sec_flip;
  1202. #endif
  1203. if (!pdata) {
  1204. error = gpio_keys_get_devtree_pdata(dev, &alt_pdata);
  1205. if (error)
  1206. return error;
  1207. pdata = &alt_pdata;
  1208. }
  1209. ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
  1210. pdata->nbuttons * sizeof(struct gpio_button_data),
  1211. GFP_KERNEL);
  1212. input = input_allocate_device();
  1213. if (!ddata || !input) {
  1214. dev_err(dev, "failed to allocate state\n");
  1215. error = -ENOMEM;
  1216. goto fail1;
  1217. }
  1218. ddata->input = input;
  1219. ddata->n_buttons = pdata->nbuttons;
  1220. ddata->enable = pdata->enable;
  1221. ddata->disable = pdata->disable;
  1222. #ifdef CONFIG_SENSORS_HALL_DEBOUNCE
  1223. ddata->debounce_set = pdata->debounce_set;
  1224. #endif
  1225. #ifdef CONFIG_SENSORS_HALL
  1226. #if defined (CONFIG_SEC_MILLET_PROJECT) || defined (CONFIG_SEC_BERLUTI_PROJECT)\
  1227. || defined (CONFIG_SEC_MATISSE_PROJECT) || defined (CONFIG_SEC_ATLANTIC_PROJECT)\
  1228. || defined (CONFIG_SEC_MEGA2_PROJECT) || defined (CONFIG_SEC_T8_PROJECT) || defined (CONFIG_SEC_T10_PROJECT) || defined(CONFIG_SEC_HESTIA_PROJECT)
  1229. ret = gpio_request(pdata->gpio_flip_cover,"HALL");
  1230. if(ret)
  1231. printk(KERN_CRIT "[HALL IC] gpio Request FAIL\n");
  1232. else {
  1233. gpio_tlmm_config(GPIO_CFG(pdata->gpio_flip_cover,0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL,GPIO_CFG_2MA),GPIO_CFG_DISABLE);
  1234. }
  1235. #endif
  1236. ddata->gpio_flip_cover = pdata->gpio_flip_cover;
  1237. ddata->flip_code = pdata->flip_code;
  1238. ddata->irq_flip_cover = gpio_to_irq(ddata->gpio_flip_cover);
  1239. wake_lock_init(&ddata->flip_wake_lock, WAKE_LOCK_SUSPEND,
  1240. "flip_wake_lock");
  1241. flip_status_before = -1;
  1242. #endif
  1243. mutex_init(&ddata->disable_lock);
  1244. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  1245. mutex_init(&ddata->irq_lock);
  1246. #endif
  1247. platform_set_drvdata(pdev, ddata);
  1248. input_set_drvdata(input, ddata);
  1249. input->name = pdata->name ? : pdev->name;
  1250. input->phys = "gpio-keys/input0";
  1251. input->dev.parent = &pdev->dev;
  1252. #ifdef CONFIG_SENSORS_HALL
  1253. if(ddata->gpio_flip_cover != 0) {
  1254. input->evbit[0] |= BIT_MASK(EV_SW);
  1255. input_set_capability(input, EV_SW, ddata->flip_code);
  1256. }
  1257. #endif
  1258. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  1259. ddata->gsm_area = false;
  1260. ddata->cover_state = false;
  1261. ddata->workaround_set = pdata->workaround_set;
  1262. drv_data = ddata;
  1263. #endif
  1264. #ifdef CONFIG_SENSORS_HALL_DEBOUNCE
  1265. ddata->debounce_set = false;
  1266. #endif
  1267. input->open = gpio_keys_open;
  1268. input->close = gpio_keys_close;
  1269. input->id.bustype = BUS_HOST;
  1270. input->id.vendor = 0x0001;
  1271. input->id.product = 0x0001;
  1272. input->id.version = 0x0100;
  1273. /* Enable auto repeat feature of Linux input subsystem */
  1274. if (pdata->rep)
  1275. __set_bit(EV_REP, input->evbit);
  1276. for (i = 0; i < pdata->nbuttons; i++) {
  1277. button = &pdata->buttons[i];
  1278. bdata = &ddata->data[i];
  1279. error = gpio_keys_setup_key(pdev, input, bdata, button);
  1280. if (error)
  1281. goto fail2;
  1282. #ifdef KEY_BOOSTER
  1283. error = gpio_key_init_dvfs(bdata);
  1284. if (error < 0) {
  1285. dev_err(dev, "Fail get dvfs level for touch booster\n");
  1286. goto fail2;
  1287. }
  1288. #endif
  1289. if (button->wakeup)
  1290. wakeup = 1;
  1291. }
  1292. error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
  1293. if (error) {
  1294. dev_err(dev, "Unable to export keys/switches, error: %d\n",
  1295. error);
  1296. goto fail2;
  1297. }
  1298. error = input_register_device(input);
  1299. if (error) {
  1300. dev_err(dev, "Unable to register input device, error: %d\n",
  1301. error);
  1302. goto fail3;
  1303. }
  1304. /* get current state of buttons that are connected to GPIOs */
  1305. for (i = 0; i < pdata->nbuttons; i++) {
  1306. bdata = &ddata->data[i];
  1307. if (gpio_is_valid(bdata->button->gpio))
  1308. gpio_keys_gpio_report_event(bdata);
  1309. }
  1310. input_sync(input);
  1311. sec_key = device_create(sec_class, NULL, 0, NULL, "sec_key");
  1312. if (IS_ERR(sec_key))
  1313. pr_err("Failed to create device(sec_key)!\n");
  1314. #ifdef CONFIG_SEC_PATEK_PROJECT
  1315. sec_keypad=device_create(sec_class, NULL, 0, NULL, "sec_keypad");
  1316. if (device_create_file(sec_keypad, &dev_attr_brightness) < 0)
  1317. pr_err("Failed to create device file(%s)!\n", dev_attr_brightness.attr.name);
  1318. sec_flip = device_create(sec_class, NULL, 0, NULL, "sec_flip");
  1319. if (device_create_file(sec_flip, &dev_attr_flipStatus) < 0)
  1320. pr_err("Failed to create device file(%s)!\n", dev_attr_flipStatus.attr.name);
  1321. #endif
  1322. ret = device_create_file(sec_key, &dev_attr_sec_key_pressed);
  1323. if (ret) {
  1324. pr_err("Failed to create device file in sysfs entries(%s)!\n",
  1325. dev_attr_sec_key_pressed.attr.name);
  1326. }
  1327. #if defined(CONFIG_SEC_S_PROJECT)
  1328. ret = device_create_file(sec_key, &dev_attr_sec_key_pressed_code);
  1329. if (ret) {
  1330. pr_err("Failed to create device file in sysfs entries(%s)!\n",
  1331. dev_attr_sec_key_pressed_code.attr.name);
  1332. }
  1333. #endif
  1334. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  1335. if(ddata->gpio_flip_cover != 0) {
  1336. ret = device_create_file(sec_key, &dev_attr_hall_irq_ctrl);
  1337. if (ret < 0) {
  1338. pr_err("Failed to create device file(%s)!, error: %d\n",
  1339. dev_attr_hall_irq_ctrl.attr.name, ret);
  1340. }
  1341. }
  1342. #endif
  1343. #if defined(CONFIG_SENSORS_HALL)
  1344. if(ddata->gpio_flip_cover != 0) {
  1345. ret = device_create_file(sec_key, &dev_attr_hall_detect);
  1346. if (ret < 0) {
  1347. pr_err("Failed to create device file(%s)!, error: %d\n",
  1348. dev_attr_hall_detect.attr.name, ret);
  1349. }
  1350. }
  1351. #if defined(CONFIG_SENSORS_HALL_DEBOUNCE)
  1352. if(ddata->gpio_flip_cover != 0) {
  1353. ret = device_create_file(sec_key, &dev_attr_hall_irq_ctrl);
  1354. if (ret < 0) {
  1355. pr_err("Failed to create device file(%s)!, error: %d\n",
  1356. dev_attr_hall_irq_ctrl.attr.name, ret);
  1357. }
  1358. }
  1359. #endif
  1360. #if defined (CONFIG_SEC_MILLET_PROJECT) || defined (CONFIG_SEC_BERLUTI_PROJECT) || defined (CONFIG_SEC_T8_PROJECT)
  1361. if (!lvs1_1p8) {
  1362. lvs1_1p8 = regulator_get(dev, "8226_lvs1");
  1363. if(!lvs1_1p8)
  1364. printk(KERN_CRIT "%s: regulator_get for 8226_lvs1 failed\n", __func__);
  1365. else {
  1366. ret = regulator_enable(lvs1_1p8);
  1367. if (ret){
  1368. regulator_put(lvs1_1p8);
  1369. printk(KERN_CRIT "%s: Failed to enable regulator lvs1_1p8.\n",__func__);
  1370. }
  1371. }
  1372. }
  1373. #endif
  1374. #endif
  1375. #ifdef CONFIG_USE_VM_KEYBOARD_REJECT
  1376. reject_keyboard_specific_key = false;
  1377. ret = device_create_file(sec_key, &dev_attr_reject_key_comb);
  1378. if (ret < 0) {
  1379. pr_err("Failed to create device file(%s), error: %d\n",
  1380. dev_attr_reject_key_comb.attr.name, ret);
  1381. }
  1382. #endif
  1383. ret = device_create_file(sec_key, &dev_attr_wakeup_keys);
  1384. if (ret < 0) {
  1385. pr_err("Failed to create device file(%s), error: %d\n",
  1386. dev_attr_wakeup_keys.attr.name, ret);
  1387. }
  1388. dev_set_drvdata(sec_key, ddata);
  1389. device_init_wakeup(&pdev->dev, wakeup);
  1390. #if defined(CONFIG_SEC_PATEK_PROJECT)
  1391. keypadled_powerset(&pdev->dev);
  1392. dev_set_drvdata(sec_flip, ddata);
  1393. #endif
  1394. #ifdef PERIODIC_CHECK_GPIOS
  1395. INIT_DELAYED_WORK_DEFERRABLE(&g_gpio_check_work,
  1396. sec_gpiocheck_work);
  1397. schedule_delayed_work(&g_gpio_check_work,
  1398. msecs_to_jiffies(0));
  1399. #endif
  1400. return 0;
  1401. fail3:
  1402. sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
  1403. fail2:
  1404. while (--i >= 0)
  1405. gpio_remove_key(&ddata->data[i]);
  1406. platform_set_drvdata(pdev, NULL);
  1407. #ifdef CONFIG_SENSORS_HALL
  1408. wake_lock_destroy(&ddata->flip_wake_lock);
  1409. #endif
  1410. fail1:
  1411. input_free_device(input);
  1412. kfree(ddata);
  1413. /* If we have no platform_data, we allocated buttons dynamically. */
  1414. if (!pdev->dev.platform_data)
  1415. kfree(pdata->buttons);
  1416. return error;
  1417. }
  1418. static int __devexit gpio_keys_remove(struct platform_device *pdev)
  1419. {
  1420. struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
  1421. struct input_dev *input = ddata->input;
  1422. int i;
  1423. sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
  1424. device_init_wakeup(&pdev->dev, 0);
  1425. for (i = 0; i < ddata->n_buttons; i++)
  1426. gpio_remove_key(&ddata->data[i]);
  1427. input_unregister_device(input);
  1428. #ifdef CONFIG_SENSORS_HALL
  1429. wake_lock_destroy(&ddata->flip_wake_lock);
  1430. #if defined CONFIG_SEC_MILLET_PROJECT || defined (CONFIG_SEC_BERLUTI_PROJECT) || defined (CONFIG_SEC_T8_PROJECT)
  1431. regulator_disable(lvs1_1p8);
  1432. regulator_put(lvs1_1p8);
  1433. #endif
  1434. #endif
  1435. /*
  1436. * If we had no platform_data, we allocated buttons dynamically, and
  1437. * must free them here. ddata->data[0].button is the pointer to the
  1438. * beginning of the allocated array.
  1439. */
  1440. if (!pdev->dev.platform_data)
  1441. kfree(ddata->data[0].button);
  1442. kfree(ddata);
  1443. return 0;
  1444. }
  1445. #ifdef CONFIG_PM_SLEEP
  1446. static int gpio_keys_suspend(struct device *dev)
  1447. {
  1448. struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
  1449. int i;
  1450. if (device_may_wakeup(dev)) {
  1451. for (i = 0; i < ddata->n_buttons; i++) {
  1452. struct gpio_button_data *bdata = &ddata->data[i];
  1453. if (bdata->button->wakeup)
  1454. enable_irq_wake(bdata->irq);
  1455. }
  1456. #ifdef CONFIG_SENSORS_HALL
  1457. if(ddata->gpio_flip_cover != 0) {
  1458. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  1459. if (!ddata->cover_state && ddata->gsm_area)
  1460. disable_irq_wake(ddata->irq_flip_cover);
  1461. else
  1462. #endif
  1463. enable_irq_wake(ddata->irq_flip_cover);
  1464. }
  1465. #endif
  1466. }
  1467. return 0;
  1468. }
  1469. static int gpio_keys_resume(struct device *dev)
  1470. {
  1471. struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
  1472. int i;
  1473. for (i = 0; i < ddata->n_buttons; i++) {
  1474. struct gpio_button_data *bdata = &ddata->data[i];
  1475. if (bdata->button->wakeup && device_may_wakeup(dev))
  1476. disable_irq_wake(bdata->irq);
  1477. if (gpio_is_valid(bdata->button->gpio))
  1478. {
  1479. if(!(bdata->button->code == 172))
  1480. gpio_keys_gpio_report_event(bdata);
  1481. }
  1482. }
  1483. #ifdef CONFIG_SENSORS_HALL
  1484. if (device_may_wakeup(dev) && ddata->gpio_flip_cover != 0) {
  1485. disable_irq_wake(ddata->irq_flip_cover);
  1486. #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
  1487. if (ddata->cover_state && ddata->gsm_area)
  1488. gpio_hall_irq_set(enable, false);
  1489. #endif
  1490. }
  1491. #endif
  1492. input_sync(ddata->input);
  1493. return 0;
  1494. }
  1495. #endif
  1496. static SIMPLE_DEV_PM_OPS(gpio_keys_pm_ops, gpio_keys_suspend, gpio_keys_resume);
  1497. static struct platform_driver gpio_keys_device_driver = {
  1498. .probe = gpio_keys_probe,
  1499. .remove = __devexit_p(gpio_keys_remove),
  1500. .driver = {
  1501. .name = "gpio-keys",
  1502. .owner = THIS_MODULE,
  1503. .pm = &gpio_keys_pm_ops,
  1504. .of_match_table = gpio_keys_of_match,
  1505. }
  1506. };
  1507. static int __init gpio_keys_init(void)
  1508. {
  1509. return platform_driver_register(&gpio_keys_device_driver);
  1510. }
  1511. static void __exit gpio_keys_exit(void)
  1512. {
  1513. platform_driver_unregister(&gpio_keys_device_driver);
  1514. }
  1515. late_initcall(gpio_keys_init);
  1516. module_exit(gpio_keys_exit);
  1517. MODULE_LICENSE("GPL");
  1518. MODULE_AUTHOR("Phil Blundell <pb@handhelds.org>");
  1519. MODULE_DESCRIPTION("Keyboard driver for GPIOs");
  1520. MODULE_ALIAS("platform:gpio-keys");