adp5589-keys.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. /*
  2. * Description: keypad driver for ADP5589, ADP5585
  3. * I2C QWERTY Keypad and IO Expander
  4. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  5. *
  6. * Copyright (C) 2010-2011 Analog Devices Inc.
  7. * Licensed under the GPL-2.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/irq.h>
  12. #include <linux/workqueue.h>
  13. #include <linux/errno.h>
  14. #include <linux/pm.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/input.h>
  17. #include <linux/i2c.h>
  18. #include <linux/gpio.h>
  19. #include <linux/slab.h>
  20. #include <linux/input/adp5589.h>
  21. /* ADP5589/ADP5585 Common Registers */
  22. #define ADP5589_5_ID 0x00
  23. #define ADP5589_5_INT_STATUS 0x01
  24. #define ADP5589_5_STATUS 0x02
  25. #define ADP5589_5_FIFO_1 0x03
  26. #define ADP5589_5_FIFO_2 0x04
  27. #define ADP5589_5_FIFO_3 0x05
  28. #define ADP5589_5_FIFO_4 0x06
  29. #define ADP5589_5_FIFO_5 0x07
  30. #define ADP5589_5_FIFO_6 0x08
  31. #define ADP5589_5_FIFO_7 0x09
  32. #define ADP5589_5_FIFO_8 0x0A
  33. #define ADP5589_5_FIFO_9 0x0B
  34. #define ADP5589_5_FIFO_10 0x0C
  35. #define ADP5589_5_FIFO_11 0x0D
  36. #define ADP5589_5_FIFO_12 0x0E
  37. #define ADP5589_5_FIFO_13 0x0F
  38. #define ADP5589_5_FIFO_14 0x10
  39. #define ADP5589_5_FIFO_15 0x11
  40. #define ADP5589_5_FIFO_16 0x12
  41. #define ADP5589_5_GPI_INT_STAT_A 0x13
  42. #define ADP5589_5_GPI_INT_STAT_B 0x14
  43. /* ADP5589 Registers */
  44. #define ADP5589_GPI_INT_STAT_C 0x15
  45. #define ADP5589_GPI_STATUS_A 0x16
  46. #define ADP5589_GPI_STATUS_B 0x17
  47. #define ADP5589_GPI_STATUS_C 0x18
  48. #define ADP5589_RPULL_CONFIG_A 0x19
  49. #define ADP5589_RPULL_CONFIG_B 0x1A
  50. #define ADP5589_RPULL_CONFIG_C 0x1B
  51. #define ADP5589_RPULL_CONFIG_D 0x1C
  52. #define ADP5589_RPULL_CONFIG_E 0x1D
  53. #define ADP5589_GPI_INT_LEVEL_A 0x1E
  54. #define ADP5589_GPI_INT_LEVEL_B 0x1F
  55. #define ADP5589_GPI_INT_LEVEL_C 0x20
  56. #define ADP5589_GPI_EVENT_EN_A 0x21
  57. #define ADP5589_GPI_EVENT_EN_B 0x22
  58. #define ADP5589_GPI_EVENT_EN_C 0x23
  59. #define ADP5589_GPI_INTERRUPT_EN_A 0x24
  60. #define ADP5589_GPI_INTERRUPT_EN_B 0x25
  61. #define ADP5589_GPI_INTERRUPT_EN_C 0x26
  62. #define ADP5589_DEBOUNCE_DIS_A 0x27
  63. #define ADP5589_DEBOUNCE_DIS_B 0x28
  64. #define ADP5589_DEBOUNCE_DIS_C 0x29
  65. #define ADP5589_GPO_DATA_OUT_A 0x2A
  66. #define ADP5589_GPO_DATA_OUT_B 0x2B
  67. #define ADP5589_GPO_DATA_OUT_C 0x2C
  68. #define ADP5589_GPO_OUT_MODE_A 0x2D
  69. #define ADP5589_GPO_OUT_MODE_B 0x2E
  70. #define ADP5589_GPO_OUT_MODE_C 0x2F
  71. #define ADP5589_GPIO_DIRECTION_A 0x30
  72. #define ADP5589_GPIO_DIRECTION_B 0x31
  73. #define ADP5589_GPIO_DIRECTION_C 0x32
  74. #define ADP5589_UNLOCK1 0x33
  75. #define ADP5589_UNLOCK2 0x34
  76. #define ADP5589_EXT_LOCK_EVENT 0x35
  77. #define ADP5589_UNLOCK_TIMERS 0x36
  78. #define ADP5589_LOCK_CFG 0x37
  79. #define ADP5589_RESET1_EVENT_A 0x38
  80. #define ADP5589_RESET1_EVENT_B 0x39
  81. #define ADP5589_RESET1_EVENT_C 0x3A
  82. #define ADP5589_RESET2_EVENT_A 0x3B
  83. #define ADP5589_RESET2_EVENT_B 0x3C
  84. #define ADP5589_RESET_CFG 0x3D
  85. #define ADP5589_PWM_OFFT_LOW 0x3E
  86. #define ADP5589_PWM_OFFT_HIGH 0x3F
  87. #define ADP5589_PWM_ONT_LOW 0x40
  88. #define ADP5589_PWM_ONT_HIGH 0x41
  89. #define ADP5589_PWM_CFG 0x42
  90. #define ADP5589_CLOCK_DIV_CFG 0x43
  91. #define ADP5589_LOGIC_1_CFG 0x44
  92. #define ADP5589_LOGIC_2_CFG 0x45
  93. #define ADP5589_LOGIC_FF_CFG 0x46
  94. #define ADP5589_LOGIC_INT_EVENT_EN 0x47
  95. #define ADP5589_POLL_PTIME_CFG 0x48
  96. #define ADP5589_PIN_CONFIG_A 0x49
  97. #define ADP5589_PIN_CONFIG_B 0x4A
  98. #define ADP5589_PIN_CONFIG_C 0x4B
  99. #define ADP5589_PIN_CONFIG_D 0x4C
  100. #define ADP5589_GENERAL_CFG 0x4D
  101. #define ADP5589_INT_EN 0x4E
  102. /* ADP5585 Registers */
  103. #define ADP5585_GPI_STATUS_A 0x15
  104. #define ADP5585_GPI_STATUS_B 0x16
  105. #define ADP5585_RPULL_CONFIG_A 0x17
  106. #define ADP5585_RPULL_CONFIG_B 0x18
  107. #define ADP5585_RPULL_CONFIG_C 0x19
  108. #define ADP5585_RPULL_CONFIG_D 0x1A
  109. #define ADP5585_GPI_INT_LEVEL_A 0x1B
  110. #define ADP5585_GPI_INT_LEVEL_B 0x1C
  111. #define ADP5585_GPI_EVENT_EN_A 0x1D
  112. #define ADP5585_GPI_EVENT_EN_B 0x1E
  113. #define ADP5585_GPI_INTERRUPT_EN_A 0x1F
  114. #define ADP5585_GPI_INTERRUPT_EN_B 0x20
  115. #define ADP5585_DEBOUNCE_DIS_A 0x21
  116. #define ADP5585_DEBOUNCE_DIS_B 0x22
  117. #define ADP5585_GPO_DATA_OUT_A 0x23
  118. #define ADP5585_GPO_DATA_OUT_B 0x24
  119. #define ADP5585_GPO_OUT_MODE_A 0x25
  120. #define ADP5585_GPO_OUT_MODE_B 0x26
  121. #define ADP5585_GPIO_DIRECTION_A 0x27
  122. #define ADP5585_GPIO_DIRECTION_B 0x28
  123. #define ADP5585_RESET1_EVENT_A 0x29
  124. #define ADP5585_RESET1_EVENT_B 0x2A
  125. #define ADP5585_RESET1_EVENT_C 0x2B
  126. #define ADP5585_RESET2_EVENT_A 0x2C
  127. #define ADP5585_RESET2_EVENT_B 0x2D
  128. #define ADP5585_RESET_CFG 0x2E
  129. #define ADP5585_PWM_OFFT_LOW 0x2F
  130. #define ADP5585_PWM_OFFT_HIGH 0x30
  131. #define ADP5585_PWM_ONT_LOW 0x31
  132. #define ADP5585_PWM_ONT_HIGH 0x32
  133. #define ADP5585_PWM_CFG 0x33
  134. #define ADP5585_LOGIC_CFG 0x34
  135. #define ADP5585_LOGIC_FF_CFG 0x35
  136. #define ADP5585_LOGIC_INT_EVENT_EN 0x36
  137. #define ADP5585_POLL_PTIME_CFG 0x37
  138. #define ADP5585_PIN_CONFIG_A 0x38
  139. #define ADP5585_PIN_CONFIG_B 0x39
  140. #define ADP5585_PIN_CONFIG_D 0x3A
  141. #define ADP5585_GENERAL_CFG 0x3B
  142. #define ADP5585_INT_EN 0x3C
  143. /* ID Register */
  144. #define ADP5589_5_DEVICE_ID_MASK 0xF
  145. #define ADP5589_5_MAN_ID_MASK 0xF
  146. #define ADP5589_5_MAN_ID_SHIFT 4
  147. #define ADP5589_5_MAN_ID 0x02
  148. /* GENERAL_CFG Register */
  149. #define OSC_EN (1 << 7)
  150. #define CORE_CLK(x) (((x) & 0x3) << 5)
  151. #define LCK_TRK_LOGIC (1 << 4) /* ADP5589 only */
  152. #define LCK_TRK_GPI (1 << 3) /* ADP5589 only */
  153. #define INT_CFG (1 << 1)
  154. #define RST_CFG (1 << 0)
  155. /* INT_EN Register */
  156. #define LOGIC2_IEN (1 << 5) /* ADP5589 only */
  157. #define LOGIC1_IEN (1 << 4)
  158. #define LOCK_IEN (1 << 3) /* ADP5589 only */
  159. #define OVRFLOW_IEN (1 << 2)
  160. #define GPI_IEN (1 << 1)
  161. #define EVENT_IEN (1 << 0)
  162. /* Interrupt Status Register */
  163. #define LOGIC2_INT (1 << 5) /* ADP5589 only */
  164. #define LOGIC1_INT (1 << 4)
  165. #define LOCK_INT (1 << 3) /* ADP5589 only */
  166. #define OVRFLOW_INT (1 << 2)
  167. #define GPI_INT (1 << 1)
  168. #define EVENT_INT (1 << 0)
  169. /* STATUS Register */
  170. #define LOGIC2_STAT (1 << 7) /* ADP5589 only */
  171. #define LOGIC1_STAT (1 << 6)
  172. #define LOCK_STAT (1 << 5) /* ADP5589 only */
  173. #define KEC 0x1F
  174. /* PIN_CONFIG_D Register */
  175. #define C4_EXTEND_CFG (1 << 6) /* RESET2 */
  176. #define R4_EXTEND_CFG (1 << 5) /* RESET1 */
  177. /* LOCK_CFG */
  178. #define LOCK_EN (1 << 0)
  179. #define PTIME_MASK 0x3
  180. #define LTIME_MASK 0x3 /* ADP5589 only */
  181. /* Key Event Register xy */
  182. #define KEY_EV_PRESSED (1 << 7)
  183. #define KEY_EV_MASK (0x7F)
  184. #define KEYP_MAX_EVENT 16
  185. #define ADP5589_MAXGPIO 19
  186. #define ADP5585_MAXGPIO 11 /* 10 on the ADP5585-01, 11 on ADP5585-02 */
  187. enum {
  188. ADP5589,
  189. ADP5585_01,
  190. ADP5585_02
  191. };
  192. struct adp_constants {
  193. u8 maxgpio;
  194. u8 keymapsize;
  195. u8 gpi_pin_row_base;
  196. u8 gpi_pin_row_end;
  197. u8 gpi_pin_col_base;
  198. u8 gpi_pin_base;
  199. u8 gpi_pin_end;
  200. u8 gpimapsize_max;
  201. u8 max_row_num;
  202. u8 max_col_num;
  203. u8 row_mask;
  204. u8 col_mask;
  205. u8 col_shift;
  206. u8 c4_extend_cfg;
  207. u8 (*bank) (u8 offset);
  208. u8 (*bit) (u8 offset);
  209. u8 (*reg) (u8 reg);
  210. };
  211. struct adp5589_kpad {
  212. struct i2c_client *client;
  213. struct input_dev *input;
  214. const struct adp_constants *var;
  215. unsigned short keycode[ADP5589_KEYMAPSIZE];
  216. const struct adp5589_gpi_map *gpimap;
  217. unsigned short gpimapsize;
  218. unsigned extend_cfg;
  219. bool is_adp5585;
  220. bool adp5585_support_row5;
  221. #ifdef CONFIG_GPIOLIB
  222. unsigned char gpiomap[ADP5589_MAXGPIO];
  223. bool export_gpio;
  224. struct gpio_chip gc;
  225. struct mutex gpio_lock; /* Protect cached dir, dat_out */
  226. u8 dat_out[3];
  227. u8 dir[3];
  228. #endif
  229. };
  230. /*
  231. * ADP5589 / ADP5585 derivative / variant handling
  232. */
  233. /* ADP5589 */
  234. static unsigned char adp5589_bank(unsigned char offset)
  235. {
  236. return offset >> 3;
  237. }
  238. static unsigned char adp5589_bit(unsigned char offset)
  239. {
  240. return 1u << (offset & 0x7);
  241. }
  242. static unsigned char adp5589_reg(unsigned char reg)
  243. {
  244. return reg;
  245. }
  246. static const struct adp_constants const_adp5589 = {
  247. .maxgpio = ADP5589_MAXGPIO,
  248. .keymapsize = ADP5589_KEYMAPSIZE,
  249. .gpi_pin_row_base = ADP5589_GPI_PIN_ROW_BASE,
  250. .gpi_pin_row_end = ADP5589_GPI_PIN_ROW_END,
  251. .gpi_pin_col_base = ADP5589_GPI_PIN_COL_BASE,
  252. .gpi_pin_base = ADP5589_GPI_PIN_BASE,
  253. .gpi_pin_end = ADP5589_GPI_PIN_END,
  254. .gpimapsize_max = ADP5589_GPIMAPSIZE_MAX,
  255. .c4_extend_cfg = 12,
  256. .max_row_num = ADP5589_MAX_ROW_NUM,
  257. .max_col_num = ADP5589_MAX_COL_NUM,
  258. .row_mask = ADP5589_ROW_MASK,
  259. .col_mask = ADP5589_COL_MASK,
  260. .col_shift = ADP5589_COL_SHIFT,
  261. .bank = adp5589_bank,
  262. .bit = adp5589_bit,
  263. .reg = adp5589_reg,
  264. };
  265. /* ADP5585 */
  266. static unsigned char adp5585_bank(unsigned char offset)
  267. {
  268. return offset > ADP5585_MAX_ROW_NUM;
  269. }
  270. static unsigned char adp5585_bit(unsigned char offset)
  271. {
  272. return (offset > ADP5585_MAX_ROW_NUM) ?
  273. 1u << (offset - ADP5585_COL_SHIFT) : 1u << offset;
  274. }
  275. static const unsigned char adp5585_reg_lut[] = {
  276. [ADP5589_GPI_STATUS_A] = ADP5585_GPI_STATUS_A,
  277. [ADP5589_GPI_STATUS_B] = ADP5585_GPI_STATUS_B,
  278. [ADP5589_RPULL_CONFIG_A] = ADP5585_RPULL_CONFIG_A,
  279. [ADP5589_RPULL_CONFIG_B] = ADP5585_RPULL_CONFIG_B,
  280. [ADP5589_RPULL_CONFIG_C] = ADP5585_RPULL_CONFIG_C,
  281. [ADP5589_RPULL_CONFIG_D] = ADP5585_RPULL_CONFIG_D,
  282. [ADP5589_GPI_INT_LEVEL_A] = ADP5585_GPI_INT_LEVEL_A,
  283. [ADP5589_GPI_INT_LEVEL_B] = ADP5585_GPI_INT_LEVEL_B,
  284. [ADP5589_GPI_EVENT_EN_A] = ADP5585_GPI_EVENT_EN_A,
  285. [ADP5589_GPI_EVENT_EN_B] = ADP5585_GPI_EVENT_EN_B,
  286. [ADP5589_GPI_INTERRUPT_EN_A] = ADP5585_GPI_INTERRUPT_EN_A,
  287. [ADP5589_GPI_INTERRUPT_EN_B] = ADP5585_GPI_INTERRUPT_EN_B,
  288. [ADP5589_DEBOUNCE_DIS_A] = ADP5585_DEBOUNCE_DIS_A,
  289. [ADP5589_DEBOUNCE_DIS_B] = ADP5585_DEBOUNCE_DIS_B,
  290. [ADP5589_GPO_DATA_OUT_A] = ADP5585_GPO_DATA_OUT_A,
  291. [ADP5589_GPO_DATA_OUT_B] = ADP5585_GPO_DATA_OUT_B,
  292. [ADP5589_GPO_OUT_MODE_A] = ADP5585_GPO_OUT_MODE_A,
  293. [ADP5589_GPO_OUT_MODE_B] = ADP5585_GPO_OUT_MODE_B,
  294. [ADP5589_GPIO_DIRECTION_A] = ADP5585_GPIO_DIRECTION_A,
  295. [ADP5589_GPIO_DIRECTION_B] = ADP5585_GPIO_DIRECTION_B,
  296. [ADP5589_RESET1_EVENT_A] = ADP5585_RESET1_EVENT_A,
  297. [ADP5589_RESET1_EVENT_B] = ADP5585_RESET1_EVENT_B,
  298. [ADP5589_RESET1_EVENT_C] = ADP5585_RESET1_EVENT_C,
  299. [ADP5589_RESET2_EVENT_A] = ADP5585_RESET2_EVENT_A,
  300. [ADP5589_RESET2_EVENT_B] = ADP5585_RESET2_EVENT_B,
  301. [ADP5589_RESET_CFG] = ADP5585_RESET_CFG,
  302. [ADP5589_PWM_OFFT_LOW] = ADP5585_PWM_OFFT_LOW,
  303. [ADP5589_PWM_OFFT_HIGH] = ADP5585_PWM_OFFT_HIGH,
  304. [ADP5589_PWM_ONT_LOW] = ADP5585_PWM_ONT_LOW,
  305. [ADP5589_PWM_ONT_HIGH] = ADP5585_PWM_ONT_HIGH,
  306. [ADP5589_PWM_CFG] = ADP5585_PWM_CFG,
  307. [ADP5589_LOGIC_1_CFG] = ADP5585_LOGIC_CFG,
  308. [ADP5589_LOGIC_FF_CFG] = ADP5585_LOGIC_FF_CFG,
  309. [ADP5589_LOGIC_INT_EVENT_EN] = ADP5585_LOGIC_INT_EVENT_EN,
  310. [ADP5589_POLL_PTIME_CFG] = ADP5585_POLL_PTIME_CFG,
  311. [ADP5589_PIN_CONFIG_A] = ADP5585_PIN_CONFIG_A,
  312. [ADP5589_PIN_CONFIG_B] = ADP5585_PIN_CONFIG_B,
  313. [ADP5589_PIN_CONFIG_D] = ADP5585_PIN_CONFIG_D,
  314. [ADP5589_GENERAL_CFG] = ADP5585_GENERAL_CFG,
  315. [ADP5589_INT_EN] = ADP5585_INT_EN,
  316. };
  317. static unsigned char adp5585_reg(unsigned char reg)
  318. {
  319. return adp5585_reg_lut[reg];
  320. }
  321. static const struct adp_constants const_adp5585 = {
  322. .maxgpio = ADP5585_MAXGPIO,
  323. .keymapsize = ADP5585_KEYMAPSIZE,
  324. .gpi_pin_row_base = ADP5585_GPI_PIN_ROW_BASE,
  325. .gpi_pin_row_end = ADP5585_GPI_PIN_ROW_END,
  326. .gpi_pin_col_base = ADP5585_GPI_PIN_COL_BASE,
  327. .gpi_pin_base = ADP5585_GPI_PIN_BASE,
  328. .gpi_pin_end = ADP5585_GPI_PIN_END,
  329. .gpimapsize_max = ADP5585_GPIMAPSIZE_MAX,
  330. .c4_extend_cfg = 10,
  331. .max_row_num = ADP5585_MAX_ROW_NUM,
  332. .max_col_num = ADP5585_MAX_COL_NUM,
  333. .row_mask = ADP5585_ROW_MASK,
  334. .col_mask = ADP5585_COL_MASK,
  335. .col_shift = ADP5585_COL_SHIFT,
  336. .bank = adp5585_bank,
  337. .bit = adp5585_bit,
  338. .reg = adp5585_reg,
  339. };
  340. static int adp5589_read(struct i2c_client *client, u8 reg)
  341. {
  342. int ret = i2c_smbus_read_byte_data(client, reg);
  343. if (ret < 0)
  344. dev_err(&client->dev, "Read Error\n");
  345. return ret;
  346. }
  347. static int adp5589_write(struct i2c_client *client, u8 reg, u8 val)
  348. {
  349. return i2c_smbus_write_byte_data(client, reg, val);
  350. }
  351. #ifdef CONFIG_GPIOLIB
  352. static int adp5589_gpio_get_value(struct gpio_chip *chip, unsigned off)
  353. {
  354. struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
  355. unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
  356. unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
  357. return !!(adp5589_read(kpad->client,
  358. kpad->var->reg(ADP5589_GPI_STATUS_A) + bank) &
  359. bit);
  360. }
  361. static void adp5589_gpio_set_value(struct gpio_chip *chip,
  362. unsigned off, int val)
  363. {
  364. struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
  365. unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
  366. unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
  367. mutex_lock(&kpad->gpio_lock);
  368. if (val)
  369. kpad->dat_out[bank] |= bit;
  370. else
  371. kpad->dat_out[bank] &= ~bit;
  372. adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A) +
  373. bank, kpad->dat_out[bank]);
  374. mutex_unlock(&kpad->gpio_lock);
  375. }
  376. static int adp5589_gpio_direction_input(struct gpio_chip *chip, unsigned off)
  377. {
  378. struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
  379. unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
  380. unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
  381. int ret;
  382. mutex_lock(&kpad->gpio_lock);
  383. kpad->dir[bank] &= ~bit;
  384. ret = adp5589_write(kpad->client,
  385. kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank,
  386. kpad->dir[bank]);
  387. mutex_unlock(&kpad->gpio_lock);
  388. return ret;
  389. }
  390. static int adp5589_gpio_direction_output(struct gpio_chip *chip,
  391. unsigned off, int val)
  392. {
  393. struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
  394. unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
  395. unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
  396. int ret;
  397. mutex_lock(&kpad->gpio_lock);
  398. kpad->dir[bank] |= bit;
  399. if (val)
  400. kpad->dat_out[bank] |= bit;
  401. else
  402. kpad->dat_out[bank] &= ~bit;
  403. ret = adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A)
  404. + bank, kpad->dat_out[bank]);
  405. ret |= adp5589_write(kpad->client,
  406. kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank,
  407. kpad->dir[bank]);
  408. mutex_unlock(&kpad->gpio_lock);
  409. return ret;
  410. }
  411. static int adp5589_build_gpiomap(struct adp5589_kpad *kpad,
  412. const struct adp5589_kpad_platform_data *pdata)
  413. {
  414. bool pin_used[ADP5589_MAXGPIO];
  415. int n_unused = 0;
  416. int i;
  417. memset(pin_used, false, sizeof(pin_used));
  418. for (i = 0; i < kpad->var->maxgpio; i++)
  419. if (pdata->keypad_en_mask & (1 << i))
  420. pin_used[i] = true;
  421. for (i = 0; i < kpad->gpimapsize; i++)
  422. pin_used[kpad->gpimap[i].pin - kpad->var->gpi_pin_base] = true;
  423. if (kpad->extend_cfg & R4_EXTEND_CFG)
  424. pin_used[4] = true;
  425. if (kpad->extend_cfg & C4_EXTEND_CFG)
  426. pin_used[kpad->var->c4_extend_cfg] = true;
  427. if (!kpad->adp5585_support_row5)
  428. pin_used[5] = true;
  429. for (i = 0; i < kpad->var->maxgpio; i++)
  430. if (!pin_used[i])
  431. kpad->gpiomap[n_unused++] = i;
  432. return n_unused;
  433. }
  434. static int adp5589_gpio_add(struct adp5589_kpad *kpad)
  435. {
  436. struct device *dev = &kpad->client->dev;
  437. const struct adp5589_kpad_platform_data *pdata = dev_get_platdata(dev);
  438. const struct adp5589_gpio_platform_data *gpio_data = pdata->gpio_data;
  439. int i, error;
  440. if (!gpio_data)
  441. return 0;
  442. kpad->gc.ngpio = adp5589_build_gpiomap(kpad, pdata);
  443. if (kpad->gc.ngpio == 0) {
  444. dev_info(dev, "No unused gpios left to export\n");
  445. return 0;
  446. }
  447. kpad->export_gpio = true;
  448. kpad->gc.direction_input = adp5589_gpio_direction_input;
  449. kpad->gc.direction_output = adp5589_gpio_direction_output;
  450. kpad->gc.get = adp5589_gpio_get_value;
  451. kpad->gc.set = adp5589_gpio_set_value;
  452. kpad->gc.can_sleep = 1;
  453. kpad->gc.base = gpio_data->gpio_start;
  454. kpad->gc.label = kpad->client->name;
  455. kpad->gc.owner = THIS_MODULE;
  456. mutex_init(&kpad->gpio_lock);
  457. error = gpiochip_add(&kpad->gc);
  458. if (error) {
  459. dev_err(dev, "gpiochip_add failed, err: %d\n", error);
  460. return error;
  461. }
  462. for (i = 0; i <= kpad->var->bank(kpad->var->maxgpio); i++) {
  463. kpad->dat_out[i] = adp5589_read(kpad->client, kpad->var->reg(
  464. ADP5589_GPO_DATA_OUT_A) + i);
  465. kpad->dir[i] = adp5589_read(kpad->client, kpad->var->reg(
  466. ADP5589_GPIO_DIRECTION_A) + i);
  467. }
  468. if (gpio_data->setup) {
  469. error = gpio_data->setup(kpad->client,
  470. kpad->gc.base, kpad->gc.ngpio,
  471. gpio_data->context);
  472. if (error)
  473. dev_warn(dev, "setup failed, %d\n", error);
  474. }
  475. return 0;
  476. }
  477. static void adp5589_gpio_remove(struct adp5589_kpad *kpad)
  478. {
  479. struct device *dev = &kpad->client->dev;
  480. const struct adp5589_kpad_platform_data *pdata = dev_get_platdata(dev);
  481. const struct adp5589_gpio_platform_data *gpio_data = pdata->gpio_data;
  482. int error;
  483. if (!kpad->export_gpio)
  484. return;
  485. if (gpio_data->teardown) {
  486. error = gpio_data->teardown(kpad->client,
  487. kpad->gc.base, kpad->gc.ngpio,
  488. gpio_data->context);
  489. if (error)
  490. dev_warn(dev, "teardown failed %d\n", error);
  491. }
  492. gpiochip_remove(&kpad->gc);
  493. }
  494. #else
  495. static inline int adp5589_gpio_add(struct adp5589_kpad *kpad)
  496. {
  497. return 0;
  498. }
  499. static inline void adp5589_gpio_remove(struct adp5589_kpad *kpad)
  500. {
  501. }
  502. #endif
  503. static void adp5589_report_switches(struct adp5589_kpad *kpad,
  504. int key, int key_val)
  505. {
  506. int i;
  507. for (i = 0; i < kpad->gpimapsize; i++) {
  508. if (key_val == kpad->gpimap[i].pin) {
  509. input_report_switch(kpad->input,
  510. kpad->gpimap[i].sw_evt,
  511. key & KEY_EV_PRESSED);
  512. break;
  513. }
  514. }
  515. }
  516. static void adp5589_report_events(struct adp5589_kpad *kpad, int ev_cnt)
  517. {
  518. int i;
  519. for (i = 0; i < ev_cnt; i++) {
  520. int key = adp5589_read(kpad->client, ADP5589_5_FIFO_1 + i);
  521. int key_val = key & KEY_EV_MASK;
  522. if (key_val >= kpad->var->gpi_pin_base &&
  523. key_val <= kpad->var->gpi_pin_end) {
  524. adp5589_report_switches(kpad, key, key_val);
  525. } else {
  526. input_report_key(kpad->input,
  527. kpad->keycode[key_val - 1],
  528. key & KEY_EV_PRESSED);
  529. }
  530. }
  531. }
  532. static irqreturn_t adp5589_irq(int irq, void *handle)
  533. {
  534. struct adp5589_kpad *kpad = handle;
  535. struct i2c_client *client = kpad->client;
  536. int status, ev_cnt;
  537. status = adp5589_read(client, ADP5589_5_INT_STATUS);
  538. if (status & OVRFLOW_INT) /* Unlikely and should never happen */
  539. dev_err(&client->dev, "Event Overflow Error\n");
  540. if (status & EVENT_INT) {
  541. ev_cnt = adp5589_read(client, ADP5589_5_STATUS) & KEC;
  542. if (ev_cnt) {
  543. adp5589_report_events(kpad, ev_cnt);
  544. input_sync(kpad->input);
  545. }
  546. }
  547. adp5589_write(client, ADP5589_5_INT_STATUS, status); /* Status is W1C */
  548. return IRQ_HANDLED;
  549. }
  550. static int adp5589_get_evcode(struct adp5589_kpad *kpad, unsigned short key)
  551. {
  552. int i;
  553. for (i = 0; i < kpad->var->keymapsize; i++)
  554. if (key == kpad->keycode[i])
  555. return (i + 1) | KEY_EV_PRESSED;
  556. dev_err(&kpad->client->dev, "RESET/UNLOCK key not in keycode map\n");
  557. return -EINVAL;
  558. }
  559. static int adp5589_setup(struct adp5589_kpad *kpad)
  560. {
  561. struct i2c_client *client = kpad->client;
  562. const struct adp5589_kpad_platform_data *pdata =
  563. dev_get_platdata(&client->dev);
  564. u8 (*reg) (u8) = kpad->var->reg;
  565. unsigned char evt_mode1 = 0, evt_mode2 = 0, evt_mode3 = 0;
  566. unsigned char pull_mask = 0;
  567. int i, ret;
  568. ret = adp5589_write(client, reg(ADP5589_PIN_CONFIG_A),
  569. pdata->keypad_en_mask & kpad->var->row_mask);
  570. ret |= adp5589_write(client, reg(ADP5589_PIN_CONFIG_B),
  571. (pdata->keypad_en_mask >> kpad->var->col_shift) &
  572. kpad->var->col_mask);
  573. if (!kpad->is_adp5585)
  574. ret |= adp5589_write(client, ADP5589_PIN_CONFIG_C,
  575. (pdata->keypad_en_mask >> 16) & 0xFF);
  576. if (!kpad->is_adp5585 && pdata->en_keylock) {
  577. ret |= adp5589_write(client, ADP5589_UNLOCK1,
  578. pdata->unlock_key1);
  579. ret |= adp5589_write(client, ADP5589_UNLOCK2,
  580. pdata->unlock_key2);
  581. ret |= adp5589_write(client, ADP5589_UNLOCK_TIMERS,
  582. pdata->unlock_timer & LTIME_MASK);
  583. ret |= adp5589_write(client, ADP5589_LOCK_CFG, LOCK_EN);
  584. }
  585. for (i = 0; i < KEYP_MAX_EVENT; i++)
  586. ret |= adp5589_read(client, ADP5589_5_FIFO_1 + i);
  587. for (i = 0; i < pdata->gpimapsize; i++) {
  588. unsigned short pin = pdata->gpimap[i].pin;
  589. if (pin <= kpad->var->gpi_pin_row_end) {
  590. evt_mode1 |= (1 << (pin - kpad->var->gpi_pin_row_base));
  591. } else {
  592. evt_mode2 |=
  593. ((1 << (pin - kpad->var->gpi_pin_col_base)) & 0xFF);
  594. if (!kpad->is_adp5585)
  595. evt_mode3 |= ((1 << (pin -
  596. kpad->var->gpi_pin_col_base)) >> 8);
  597. }
  598. }
  599. if (pdata->gpimapsize) {
  600. ret |= adp5589_write(client, reg(ADP5589_GPI_EVENT_EN_A),
  601. evt_mode1);
  602. ret |= adp5589_write(client, reg(ADP5589_GPI_EVENT_EN_B),
  603. evt_mode2);
  604. if (!kpad->is_adp5585)
  605. ret |= adp5589_write(client,
  606. reg(ADP5589_GPI_EVENT_EN_C),
  607. evt_mode3);
  608. }
  609. if (pdata->pull_dis_mask & pdata->pullup_en_100k &
  610. pdata->pullup_en_300k & pdata->pulldown_en_300k)
  611. dev_warn(&client->dev, "Conflicting pull resistor config\n");
  612. for (i = 0; i <= kpad->var->max_row_num; i++) {
  613. unsigned val = 0, bit = (1 << i);
  614. if (pdata->pullup_en_300k & bit)
  615. val = 0;
  616. else if (pdata->pulldown_en_300k & bit)
  617. val = 1;
  618. else if (pdata->pullup_en_100k & bit)
  619. val = 2;
  620. else if (pdata->pull_dis_mask & bit)
  621. val = 3;
  622. pull_mask |= val << (2 * (i & 0x3));
  623. if (i % 4 == 3 || i == kpad->var->max_row_num) {
  624. ret |= adp5589_write(client, reg(ADP5585_RPULL_CONFIG_A)
  625. + (i >> 2), pull_mask);
  626. pull_mask = 0;
  627. }
  628. }
  629. for (i = 0; i <= kpad->var->max_col_num; i++) {
  630. unsigned val = 0, bit = 1 << (i + kpad->var->col_shift);
  631. if (pdata->pullup_en_300k & bit)
  632. val = 0;
  633. else if (pdata->pulldown_en_300k & bit)
  634. val = 1;
  635. else if (pdata->pullup_en_100k & bit)
  636. val = 2;
  637. else if (pdata->pull_dis_mask & bit)
  638. val = 3;
  639. pull_mask |= val << (2 * (i & 0x3));
  640. if (i % 4 == 3 || i == kpad->var->max_col_num) {
  641. ret |= adp5589_write(client,
  642. reg(ADP5585_RPULL_CONFIG_C) +
  643. (i >> 2), pull_mask);
  644. pull_mask = 0;
  645. }
  646. }
  647. if (pdata->reset1_key_1 && pdata->reset1_key_2 && pdata->reset1_key_3) {
  648. ret |= adp5589_write(client, reg(ADP5589_RESET1_EVENT_A),
  649. adp5589_get_evcode(kpad,
  650. pdata->reset1_key_1));
  651. ret |= adp5589_write(client, reg(ADP5589_RESET1_EVENT_B),
  652. adp5589_get_evcode(kpad,
  653. pdata->reset1_key_2));
  654. ret |= adp5589_write(client, reg(ADP5589_RESET1_EVENT_C),
  655. adp5589_get_evcode(kpad,
  656. pdata->reset1_key_3));
  657. kpad->extend_cfg |= R4_EXTEND_CFG;
  658. }
  659. if (pdata->reset2_key_1 && pdata->reset2_key_2) {
  660. ret |= adp5589_write(client, reg(ADP5589_RESET2_EVENT_A),
  661. adp5589_get_evcode(kpad,
  662. pdata->reset2_key_1));
  663. ret |= adp5589_write(client, reg(ADP5589_RESET2_EVENT_B),
  664. adp5589_get_evcode(kpad,
  665. pdata->reset2_key_2));
  666. kpad->extend_cfg |= C4_EXTEND_CFG;
  667. }
  668. if (kpad->extend_cfg) {
  669. ret |= adp5589_write(client, reg(ADP5589_RESET_CFG),
  670. pdata->reset_cfg);
  671. ret |= adp5589_write(client, reg(ADP5589_PIN_CONFIG_D),
  672. kpad->extend_cfg);
  673. }
  674. ret |= adp5589_write(client, reg(ADP5589_DEBOUNCE_DIS_A),
  675. pdata->debounce_dis_mask & kpad->var->row_mask);
  676. ret |= adp5589_write(client, reg(ADP5589_DEBOUNCE_DIS_B),
  677. (pdata->debounce_dis_mask >> kpad->var->col_shift)
  678. & kpad->var->col_mask);
  679. if (!kpad->is_adp5585)
  680. ret |= adp5589_write(client, reg(ADP5589_DEBOUNCE_DIS_C),
  681. (pdata->debounce_dis_mask >> 16) & 0xFF);
  682. ret |= adp5589_write(client, reg(ADP5589_POLL_PTIME_CFG),
  683. pdata->scan_cycle_time & PTIME_MASK);
  684. ret |= adp5589_write(client, ADP5589_5_INT_STATUS,
  685. (kpad->is_adp5585 ? 0 : LOGIC2_INT) |
  686. LOGIC1_INT | OVRFLOW_INT |
  687. (kpad->is_adp5585 ? 0 : LOCK_INT) |
  688. GPI_INT | EVENT_INT); /* Status is W1C */
  689. ret |= adp5589_write(client, reg(ADP5589_GENERAL_CFG),
  690. INT_CFG | OSC_EN | CORE_CLK(3));
  691. ret |= adp5589_write(client, reg(ADP5589_INT_EN),
  692. OVRFLOW_IEN | GPI_IEN | EVENT_IEN);
  693. if (ret < 0) {
  694. dev_err(&client->dev, "Write Error\n");
  695. return ret;
  696. }
  697. return 0;
  698. }
  699. static void adp5589_report_switch_state(struct adp5589_kpad *kpad)
  700. {
  701. int gpi_stat_tmp, pin_loc;
  702. int i;
  703. int gpi_stat1 = adp5589_read(kpad->client,
  704. kpad->var->reg(ADP5589_GPI_STATUS_A));
  705. int gpi_stat2 = adp5589_read(kpad->client,
  706. kpad->var->reg(ADP5589_GPI_STATUS_B));
  707. int gpi_stat3 = !kpad->is_adp5585 ?
  708. adp5589_read(kpad->client, ADP5589_GPI_STATUS_C) : 0;
  709. for (i = 0; i < kpad->gpimapsize; i++) {
  710. unsigned short pin = kpad->gpimap[i].pin;
  711. if (pin <= kpad->var->gpi_pin_row_end) {
  712. gpi_stat_tmp = gpi_stat1;
  713. pin_loc = pin - kpad->var->gpi_pin_row_base;
  714. } else if ((pin - kpad->var->gpi_pin_col_base) < 8) {
  715. gpi_stat_tmp = gpi_stat2;
  716. pin_loc = pin - kpad->var->gpi_pin_col_base;
  717. } else {
  718. gpi_stat_tmp = gpi_stat3;
  719. pin_loc = pin - kpad->var->gpi_pin_col_base - 8;
  720. }
  721. if (gpi_stat_tmp < 0) {
  722. dev_err(&kpad->client->dev,
  723. "Can't read GPIO_DAT_STAT switch %d, default to OFF\n",
  724. pin);
  725. gpi_stat_tmp = 0;
  726. }
  727. input_report_switch(kpad->input,
  728. kpad->gpimap[i].sw_evt,
  729. !(gpi_stat_tmp & (1 << pin_loc)));
  730. }
  731. input_sync(kpad->input);
  732. }
  733. static int adp5589_probe(struct i2c_client *client,
  734. const struct i2c_device_id *id)
  735. {
  736. struct adp5589_kpad *kpad;
  737. const struct adp5589_kpad_platform_data *pdata =
  738. dev_get_platdata(&client->dev);
  739. struct input_dev *input;
  740. unsigned int revid;
  741. int ret, i;
  742. int error;
  743. if (!i2c_check_functionality(client->adapter,
  744. I2C_FUNC_SMBUS_BYTE_DATA)) {
  745. dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
  746. return -EIO;
  747. }
  748. if (!pdata) {
  749. dev_err(&client->dev, "no platform data?\n");
  750. return -EINVAL;
  751. }
  752. kpad = kzalloc(sizeof(*kpad), GFP_KERNEL);
  753. if (!kpad)
  754. return -ENOMEM;
  755. switch (id->driver_data) {
  756. case ADP5585_02:
  757. kpad->adp5585_support_row5 = true;
  758. case ADP5585_01:
  759. kpad->is_adp5585 = true;
  760. kpad->var = &const_adp5585;
  761. break;
  762. case ADP5589:
  763. kpad->var = &const_adp5589;
  764. break;
  765. }
  766. if (!((pdata->keypad_en_mask & kpad->var->row_mask) &&
  767. (pdata->keypad_en_mask >> kpad->var->col_shift)) ||
  768. !pdata->keymap) {
  769. dev_err(&client->dev, "no rows, cols or keymap from pdata\n");
  770. error = -EINVAL;
  771. goto err_free_mem;
  772. }
  773. if (pdata->keymapsize != kpad->var->keymapsize) {
  774. dev_err(&client->dev, "invalid keymapsize\n");
  775. error = -EINVAL;
  776. goto err_free_mem;
  777. }
  778. if (!pdata->gpimap && pdata->gpimapsize) {
  779. dev_err(&client->dev, "invalid gpimap from pdata\n");
  780. error = -EINVAL;
  781. goto err_free_mem;
  782. }
  783. if (pdata->gpimapsize > kpad->var->gpimapsize_max) {
  784. dev_err(&client->dev, "invalid gpimapsize\n");
  785. error = -EINVAL;
  786. goto err_free_mem;
  787. }
  788. for (i = 0; i < pdata->gpimapsize; i++) {
  789. unsigned short pin = pdata->gpimap[i].pin;
  790. if (pin < kpad->var->gpi_pin_base ||
  791. pin > kpad->var->gpi_pin_end) {
  792. dev_err(&client->dev, "invalid gpi pin data\n");
  793. error = -EINVAL;
  794. goto err_free_mem;
  795. }
  796. if ((1 << (pin - kpad->var->gpi_pin_row_base)) &
  797. pdata->keypad_en_mask) {
  798. dev_err(&client->dev, "invalid gpi row/col data\n");
  799. error = -EINVAL;
  800. goto err_free_mem;
  801. }
  802. }
  803. if (!client->irq) {
  804. dev_err(&client->dev, "no IRQ?\n");
  805. error = -EINVAL;
  806. goto err_free_mem;
  807. }
  808. input = input_allocate_device();
  809. if (!input) {
  810. error = -ENOMEM;
  811. goto err_free_mem;
  812. }
  813. kpad->client = client;
  814. kpad->input = input;
  815. ret = adp5589_read(client, ADP5589_5_ID);
  816. if (ret < 0) {
  817. error = ret;
  818. goto err_free_input;
  819. }
  820. revid = (u8) ret & ADP5589_5_DEVICE_ID_MASK;
  821. input->name = client->name;
  822. input->phys = "adp5589-keys/input0";
  823. input->dev.parent = &client->dev;
  824. input_set_drvdata(input, kpad);
  825. input->id.bustype = BUS_I2C;
  826. input->id.vendor = 0x0001;
  827. input->id.product = 0x0001;
  828. input->id.version = revid;
  829. input->keycodesize = sizeof(kpad->keycode[0]);
  830. input->keycodemax = pdata->keymapsize;
  831. input->keycode = kpad->keycode;
  832. memcpy(kpad->keycode, pdata->keymap,
  833. pdata->keymapsize * input->keycodesize);
  834. kpad->gpimap = pdata->gpimap;
  835. kpad->gpimapsize = pdata->gpimapsize;
  836. /* setup input device */
  837. __set_bit(EV_KEY, input->evbit);
  838. if (pdata->repeat)
  839. __set_bit(EV_REP, input->evbit);
  840. for (i = 0; i < input->keycodemax; i++)
  841. if (kpad->keycode[i] <= KEY_MAX)
  842. __set_bit(kpad->keycode[i], input->keybit);
  843. __clear_bit(KEY_RESERVED, input->keybit);
  844. if (kpad->gpimapsize)
  845. __set_bit(EV_SW, input->evbit);
  846. for (i = 0; i < kpad->gpimapsize; i++)
  847. __set_bit(kpad->gpimap[i].sw_evt, input->swbit);
  848. error = input_register_device(input);
  849. if (error) {
  850. dev_err(&client->dev, "unable to register input device\n");
  851. goto err_free_input;
  852. }
  853. error = request_threaded_irq(client->irq, NULL, adp5589_irq,
  854. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  855. client->dev.driver->name, kpad);
  856. if (error) {
  857. dev_err(&client->dev, "irq %d busy?\n", client->irq);
  858. goto err_unreg_dev;
  859. }
  860. error = adp5589_setup(kpad);
  861. if (error)
  862. goto err_free_irq;
  863. if (kpad->gpimapsize)
  864. adp5589_report_switch_state(kpad);
  865. error = adp5589_gpio_add(kpad);
  866. if (error)
  867. goto err_free_irq;
  868. device_init_wakeup(&client->dev, 1);
  869. i2c_set_clientdata(client, kpad);
  870. dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq);
  871. return 0;
  872. err_free_irq:
  873. free_irq(client->irq, kpad);
  874. err_unreg_dev:
  875. input_unregister_device(input);
  876. input = NULL;
  877. err_free_input:
  878. input_free_device(input);
  879. err_free_mem:
  880. kfree(kpad);
  881. return error;
  882. }
  883. static int adp5589_remove(struct i2c_client *client)
  884. {
  885. struct adp5589_kpad *kpad = i2c_get_clientdata(client);
  886. adp5589_write(client, kpad->var->reg(ADP5589_GENERAL_CFG), 0);
  887. free_irq(client->irq, kpad);
  888. input_unregister_device(kpad->input);
  889. adp5589_gpio_remove(kpad);
  890. kfree(kpad);
  891. return 0;
  892. }
  893. #ifdef CONFIG_PM_SLEEP
  894. static int adp5589_suspend(struct device *dev)
  895. {
  896. struct adp5589_kpad *kpad = dev_get_drvdata(dev);
  897. struct i2c_client *client = kpad->client;
  898. disable_irq(client->irq);
  899. if (device_may_wakeup(&client->dev))
  900. enable_irq_wake(client->irq);
  901. return 0;
  902. }
  903. static int adp5589_resume(struct device *dev)
  904. {
  905. struct adp5589_kpad *kpad = dev_get_drvdata(dev);
  906. struct i2c_client *client = kpad->client;
  907. if (device_may_wakeup(&client->dev))
  908. disable_irq_wake(client->irq);
  909. enable_irq(client->irq);
  910. return 0;
  911. }
  912. #endif
  913. static SIMPLE_DEV_PM_OPS(adp5589_dev_pm_ops, adp5589_suspend, adp5589_resume);
  914. static const struct i2c_device_id adp5589_id[] = {
  915. {"adp5589-keys", ADP5589},
  916. {"adp5585-keys", ADP5585_01},
  917. {"adp5585-02-keys", ADP5585_02}, /* Adds ROW5 to ADP5585 */
  918. {}
  919. };
  920. MODULE_DEVICE_TABLE(i2c, adp5589_id);
  921. static struct i2c_driver adp5589_driver = {
  922. .driver = {
  923. .name = KBUILD_MODNAME,
  924. .pm = &adp5589_dev_pm_ops,
  925. },
  926. .probe = adp5589_probe,
  927. .remove = adp5589_remove,
  928. .id_table = adp5589_id,
  929. };
  930. module_i2c_driver(adp5589_driver);
  931. MODULE_LICENSE("GPL");
  932. MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
  933. MODULE_DESCRIPTION("ADP5589/ADP5585 Keypad driver");