mc5587.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Analog Devices MC5587 I/O Expander and QWERTY Keypad Controller
  3. *
  4. * Copyright 2009-2010 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #ifndef _MC5587_H
  9. #define _MC5587_H
  10. #define DEVID 0x00 /* Device ID */
  11. #define CFGREG 0x01 /* Configuration Register1 */
  12. #define INTPND 0x02 /* Interrupt Status Register */
  13. #define KLCK_EC 0x03 /* Key Lock and Event Counter Register */
  14. #define KEYEVNT0 0x04 /* Key Event Register A */
  15. #define KEYEVNT1 0x05 /* Key Event Register B */
  16. #define KEYEVNT2 0x06 /* Key Event Register C */
  17. #define KEYEVNT3 0x07 /* Key Event Register D */
  18. #define KEYEVNT4 0x08 /* Key Event Register E */
  19. #define KEYEVNT5 0x09 /* Key Event Register F */
  20. #define KEYEVNT6 0x0A /* Key Event Register G */
  21. #define KEYEVNT7 0x0B /* Key Event Register H */
  22. #define KEYEVNT8 0x0C /* Key Event Register I */
  23. #define KEYEVNT9 0x0D /* Key Event Register J */
  24. #define KLCKTMR 0x0E /* Keypad Lock1 to Lock2 Timer */
  25. #define UNLCK1 0x0F /* Unlock Key1 */
  26. #define UNLCK2 0x10 /* Unlock Key2 */
  27. #define GPINTST1 0x11 /* GPIO Interrupt Status */
  28. #define GPINTST2 0x12 /* GPIO Interrupt Status */
  29. #define GPINTST3 0x13 /* GPIO Interrupt Status */
  30. #define GPIDAT1 0x14 /* GPIO Data Status, Read twice to clear */
  31. #define GPIDAT2 0x15 /* GPIO Data Status, Read twice to clear */
  32. #define GPIDAT3 0x16 /* GPIO Data Status, Read twice to clear */
  33. #define GPODAT1 0x17 /* GPIO DATA OUT */
  34. #define GPODAT2 0x18 /* GPIO DATA OUT */
  35. #define GPODAT3 0x19 /* GPIO DATA OUT */
  36. #define GPINTEN1 0x1A /* GPIO Interrupt Enable */
  37. #define GPINTEN2 0x1B /* GPIO Interrupt Enable */
  38. #define GPINTEN3 0x1C /* GPIO Interrupt Enable */
  39. #define KPMSEL1 0x1D /* Keypad or GPIO Selection */
  40. #define KPMSEL2 0x1E /* Keypad or GPIO Selection */
  41. #define KPMSEL3 0x1F /* Keypad or GPIO Selection */
  42. #define GPIEMSEL1 0x20 /* GPI Event Mode 1 */
  43. #define GPIEMSEL2 0x21 /* GPI Event Mode 2 */
  44. #define GPIEMSEL3 0x22 /* GPI Event Mode 3 */
  45. #define GPIODIR1 0x23 /* GPIO Data Direction */
  46. #define GPIODIR2 0x24 /* GPIO Data Direction */
  47. #define GPIODIR3 0x25 /* GPIO Data Direction */
  48. #define GPINTLVL1 0x26 /* GPIO Edge/Level Detect */
  49. #define GPINTLVL2 0x27 /* GPIO Edge/Level Detect */
  50. #define GPINTLVL3 0x28 /* GPIO Edge/Level Detect */
  51. #define DBNCON1 0x29 /* Debounce Disable */
  52. #define DBNCON2 0x2A /* Debounce Disable */
  53. #define DBNCON3 0x2B /* Debounce Disable */
  54. #define GPIPU1 0x2C /* GPIO Pull Disable */
  55. #define GPIPU2 0x2D /* GPIO Pull Disable */
  56. #define GPIPU3 0x2E /* GPIO Pull Disable */
  57. #define MC5587_DEVICE_ID_MASK 0x0F
  58. #define MC5587_MFG_ID_MASK 0xF0
  59. /* Configuration Register 0x01 */
  60. #define MC5587_AUTOINC (1 << 7)
  61. #define MC5587_GPGEVTCFG (1 << 6)
  62. #define MC5587_OVFMD (1 << 5)
  63. #define MC5587_INTCFG (1 << 4)
  64. #define MC5587_OVFIEN (1 << 3)
  65. #define MC5587_KLCKIEN (1 << 2)
  66. #define MC5587_GPIIEN (1 << 1)
  67. #define MC5587_KEIEN (1 << 0)
  68. /* Interrupt Status Register 0x02 */
  69. #define MC5587_OVFPND (1 << 3)
  70. #define MC5587_KLCKPND (1 << 2)
  71. #define MC5587_GPIPND (1 << 1)
  72. #define MC5587_KEPND (1 << 0)
  73. /* Keylock and Event Counter Register */
  74. #define MC5587_KLCKEN (1 << 6)
  75. #define MC5587_LCKST 0x30
  76. #define MC5587_KECNT 0x0F
  77. #define MC5587_MAXGPIO 18
  78. #define MC5587_BANK(offs) ((offs) >> 3)
  79. #define MC5587_BIT(offs) (1u << ((offs) & 0x7))
  80. /* Put one of these structures in i2c_board_info platform_data */
  81. #define MC5587_KEYMAPSIZE 80
  82. #define GPI_PIN_ROW0 97
  83. #define GPI_PIN_ROW1 98
  84. #define GPI_PIN_ROW2 99
  85. #define GPI_PIN_ROW3 100
  86. #define GPI_PIN_ROW4 101
  87. #define GPI_PIN_ROW5 102
  88. #define GPI_PIN_ROW6 103
  89. #define GPI_PIN_ROW7 104
  90. #define GPI_PIN_COL0 105
  91. #define GPI_PIN_COL1 106
  92. #define GPI_PIN_COL2 107
  93. #define GPI_PIN_COL3 108
  94. #define GPI_PIN_COL4 109
  95. #define GPI_PIN_COL5 110
  96. #define GPI_PIN_COL6 111
  97. #define GPI_PIN_COL7 112
  98. #define GPI_PIN_COL8 113
  99. #define GPI_PIN_COL9 114
  100. #define GPO_PIN_VT_CAM_12_EN 0
  101. #define GPO_PIN_MAIN_CAM_A_EN 8
  102. #define GPI_PIN_CAM_SENSOR_DET 9
  103. #define GPO_PIN_NFC_EN 10
  104. #define GPO_PIN_FLASH_LED_SET 11
  105. #define GPI_PIN_TX_GTR_THRES 12
  106. #define GPO_PIN_VT_CAM_STBY 13
  107. #define GPO_PIN_VT_CAM_A_EN 14
  108. #define GPO_PIN_CRESET_B 15
  109. #define GPO_PIN_VT_CAM_IO_EN 16
  110. #define GPO_PIN_VT_CAM_NRST 17
  111. #define GPI_PIN_ROW_BASE GPI_PIN_ROW0
  112. #define GPI_PIN_ROW_END GPI_PIN_ROW7
  113. #define GPI_PIN_COL_BASE GPI_PIN_COL0
  114. #define GPI_PIN_COL_END GPI_PIN_COL9
  115. #define GPI_PIN_BASE GPI_PIN_ROW_BASE
  116. #define GPI_PIN_END GPI_PIN_COL_END
  117. #define MC5587_GPIMAPSIZE_MAX (GPI_PIN_END - GPI_PIN_BASE + 1)
  118. struct mc5587_gpi_map {
  119. unsigned short pin;
  120. unsigned short sw_evt;
  121. };
  122. struct mc5587_kpad_platform_data {
  123. int rows; /* Number of rows */
  124. int cols; /* Number of columns */
  125. const unsigned short *keymap; /* Pointer to keymap */
  126. unsigned short keymapsize; /* Keymap size */
  127. unsigned repeat:1; /* Enable key repeat */
  128. unsigned en_keylock:1; /* Enable Key Lock feature */
  129. unsigned short unlock_key1; /* Unlock Key 1 */
  130. unsigned short unlock_key2; /* Unlock Key 2 */
  131. const struct mc5587_gpi_map *gpimap;
  132. unsigned short gpimapsize;
  133. const struct mc5587_gpio_platform_data *gpio_data;
  134. int hall_gpio;
  135. int led_gpio;
  136. };
  137. struct i2c_client; /* forward declaration */
  138. struct mc5587_gpio_platform_data {
  139. int gpio_start; /* GPIO Chip base # */
  140. int ngpio;
  141. unsigned irq_base; /* interrupt base # */
  142. int reset_gpio; /* reset gpio pin */
  143. int irq_gpio; /* irq gpio pin */
  144. unsigned pullup_dis_mask; /* Pull-Up Disable Mask */
  145. int (*setup)(struct i2c_client *client,
  146. int gpio, unsigned ngpio,
  147. void *context);
  148. int (*teardown)(struct i2c_client *client,
  149. int gpio, unsigned ngpio,
  150. void *context);
  151. void *context;
  152. };
  153. #endif