adp5588.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Analog Devices ADP5588 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 _ADP5588_H
  9. #define _ADP5588_H
  10. #define DEV_ID 0x00 /* Device ID */
  11. #define CFG 0x01 /* Configuration Register1 */
  12. #define INT_STAT 0x02 /* Interrupt Status Register */
  13. #define KEY_LCK_EC_STAT 0x03 /* Key Lock and Event Counter Register */
  14. #define Key_EVENTA 0x04 /* Key Event Register A */
  15. #define Key_EVENTB 0x05 /* Key Event Register B */
  16. #define Key_EVENTC 0x06 /* Key Event Register C */
  17. #define Key_EVENTD 0x07 /* Key Event Register D */
  18. #define Key_EVENTE 0x08 /* Key Event Register E */
  19. #define Key_EVENTF 0x09 /* Key Event Register F */
  20. #define Key_EVENTG 0x0A /* Key Event Register G */
  21. #define Key_EVENTH 0x0B /* Key Event Register H */
  22. #define Key_EVENTI 0x0C /* Key Event Register I */
  23. #define Key_EVENTJ 0x0D /* Key Event Register J */
  24. #define KP_LCK_TMR 0x0E /* Keypad Lock1 to Lock2 Timer */
  25. #define UNLOCK1 0x0F /* Unlock Key1 */
  26. #define UNLOCK2 0x10 /* Unlock Key2 */
  27. #define GPIO_INT_STAT1 0x11 /* GPIO Interrupt Status */
  28. #define GPIO_INT_STAT2 0x12 /* GPIO Interrupt Status */
  29. #define GPIO_INT_STAT3 0x13 /* GPIO Interrupt Status */
  30. #define GPIO_DAT_STAT1 0x14 /* GPIO Data Status, Read twice to clear */
  31. #define GPIO_DAT_STAT2 0x15 /* GPIO Data Status, Read twice to clear */
  32. #define GPIO_DAT_STAT3 0x16 /* GPIO Data Status, Read twice to clear */
  33. #define GPIO_DAT_OUT1 0x17 /* GPIO DATA OUT */
  34. #define GPIO_DAT_OUT2 0x18 /* GPIO DATA OUT */
  35. #define GPIO_DAT_OUT3 0x19 /* GPIO DATA OUT */
  36. #define GPIO_INT_EN1 0x1A /* GPIO Interrupt Enable */
  37. #define GPIO_INT_EN2 0x1B /* GPIO Interrupt Enable */
  38. #define GPIO_INT_EN3 0x1C /* GPIO Interrupt Enable */
  39. #define KP_GPIO1 0x1D /* Keypad or GPIO Selection */
  40. #define KP_GPIO2 0x1E /* Keypad or GPIO Selection */
  41. #define KP_GPIO3 0x1F /* Keypad or GPIO Selection */
  42. #define GPI_EM1 0x20 /* GPI Event Mode 1 */
  43. #define GPI_EM2 0x21 /* GPI Event Mode 2 */
  44. #define GPI_EM3 0x22 /* GPI Event Mode 3 */
  45. #define GPIO_DIR1 0x23 /* GPIO Data Direction */
  46. #define GPIO_DIR2 0x24 /* GPIO Data Direction */
  47. #define GPIO_DIR3 0x25 /* GPIO Data Direction */
  48. #define GPIO_INT_LVL1 0x26 /* GPIO Edge/Level Detect */
  49. #define GPIO_INT_LVL2 0x27 /* GPIO Edge/Level Detect */
  50. #define GPIO_INT_LVL3 0x28 /* GPIO Edge/Level Detect */
  51. #define Debounce_DIS1 0x29 /* Debounce Disable */
  52. #define Debounce_DIS2 0x2A /* Debounce Disable */
  53. #define Debounce_DIS3 0x2B /* Debounce Disable */
  54. #define GPIO_PULL1 0x2C /* GPIO Pull Disable */
  55. #define GPIO_PULL2 0x2D /* GPIO Pull Disable */
  56. #define GPIO_PULL3 0x2E /* GPIO Pull Disable */
  57. #define CMP_CFG_STAT 0x30 /* Comparator Configuration and Status Register */
  58. #define CMP_CONFG_SENS1 0x31 /* Sensor1 Comparator Configuration Register */
  59. #define CMP_CONFG_SENS2 0x32 /* L2 Light Sensor Reference Level, Output Falling for Sensor 1 */
  60. #define CMP1_LVL2_TRIP 0x33 /* L2 Light Sensor Hysteresis (Active when Output Rising) for Sensor 1 */
  61. #define CMP1_LVL2_HYS 0x34 /* L3 Light Sensor Reference Level, Output Falling For Sensor 1 */
  62. #define CMP1_LVL3_TRIP 0x35 /* L3 Light Sensor Hysteresis (Active when Output Rising) For Sensor 1 */
  63. #define CMP1_LVL3_HYS 0x36 /* Sensor 2 Comparator Configuration Register */
  64. #define CMP2_LVL2_TRIP 0x37 /* L2 Light Sensor Reference Level, Output Falling for Sensor 2 */
  65. #define CMP2_LVL2_HYS 0x38 /* L2 Light Sensor Hysteresis (Active when Output Rising) for Sensor 2 */
  66. #define CMP2_LVL3_TRIP 0x39 /* L3 Light Sensor Reference Level, Output Falling For Sensor 2 */
  67. #define CMP2_LVL3_HYS 0x3A /* L3 Light Sensor Hysteresis (Active when Output Rising) For Sensor 2 */
  68. #define CMP1_ADC_DAT_R1 0x3B /* Comparator 1 ADC data Register1 */
  69. #define CMP1_ADC_DAT_R2 0x3C /* Comparator 1 ADC data Register2 */
  70. #define CMP2_ADC_DAT_R1 0x3D /* Comparator 2 ADC data Register1 */
  71. #define CMP2_ADC_DAT_R2 0x3E /* Comparator 2 ADC data Register2 */
  72. #define ADP5588_DEVICE_ID_MASK 0xF
  73. /* Configuration Register1 */
  74. #define ADP5588_AUTO_INC (1 << 7)
  75. #define ADP5588_GPIEM_CFG (1 << 6)
  76. #define ADP5588_OVR_FLOW_M (1 << 5)
  77. #define ADP5588_INT_CFG (1 << 4)
  78. #define ADP5588_OVR_FLOW_IEN (1 << 3)
  79. #define ADP5588_K_LCK_IM (1 << 2)
  80. #define ADP5588_GPI_IEN (1 << 1)
  81. #define ADP5588_KE_IEN (1 << 0)
  82. /* Interrupt Status Register */
  83. #define ADP5588_CMP2_INT (1 << 5)
  84. #define ADP5588_CMP1_INT (1 << 4)
  85. #define ADP5588_OVR_FLOW_INT (1 << 3)
  86. #define ADP5588_K_LCK_INT (1 << 2)
  87. #define ADP5588_GPI_INT (1 << 1)
  88. #define ADP5588_KE_INT (1 << 0)
  89. /* Key Lock and Event Counter Register */
  90. #define ADP5588_K_LCK_EN (1 << 6)
  91. #define ADP5588_LCK21 0x30
  92. #define ADP5588_KEC 0xF
  93. #define ADP5588_MAXGPIO 18
  94. #define ADP5588_BANK(offs) ((offs) >> 3)
  95. #define ADP5588_BIT(offs) (1u << ((offs) & 0x7))
  96. /* Put one of these structures in i2c_board_info platform_data */
  97. #define ADP5588_KEYMAPSIZE 80
  98. #define GPI_PIN_ROW0 97
  99. #define GPI_PIN_ROW1 98
  100. #define GPI_PIN_ROW2 99
  101. #define GPI_PIN_ROW3 100
  102. #define GPI_PIN_ROW4 101
  103. #define GPI_PIN_ROW5 102
  104. #define GPI_PIN_ROW6 103
  105. #define GPI_PIN_ROW7 104
  106. #define GPI_PIN_COL0 105
  107. #define GPI_PIN_COL1 106
  108. #define GPI_PIN_COL2 107
  109. #define GPI_PIN_COL3 108
  110. #define GPI_PIN_COL4 109
  111. #define GPI_PIN_COL5 110
  112. #define GPI_PIN_COL6 111
  113. #define GPI_PIN_COL7 112
  114. #define GPI_PIN_COL8 113
  115. #define GPI_PIN_COL9 114
  116. #define GPI_PIN_ROW_BASE GPI_PIN_ROW0
  117. #define GPI_PIN_ROW_END GPI_PIN_ROW7
  118. #define GPI_PIN_COL_BASE GPI_PIN_COL0
  119. #define GPI_PIN_COL_END GPI_PIN_COL9
  120. #define GPI_PIN_BASE GPI_PIN_ROW_BASE
  121. #define GPI_PIN_END GPI_PIN_COL_END
  122. #define ADP5588_GPIMAPSIZE_MAX (GPI_PIN_END - GPI_PIN_BASE + 1)
  123. struct adp5588_gpi_map {
  124. unsigned short pin;
  125. unsigned short sw_evt;
  126. };
  127. struct adp5588_kpad_platform_data {
  128. int rows; /* Number of rows */
  129. int cols; /* Number of columns */
  130. const unsigned short *keymap; /* Pointer to keymap */
  131. unsigned short keymapsize; /* Keymap size */
  132. unsigned repeat:1; /* Enable key repeat */
  133. unsigned en_keylock:1; /* Enable Key Lock feature */
  134. unsigned short unlock_key1; /* Unlock Key 1 */
  135. unsigned short unlock_key2; /* Unlock Key 2 */
  136. const struct adp5588_gpi_map *gpimap;
  137. unsigned short gpimapsize;
  138. const struct adp5588_gpio_platform_data *gpio_data;
  139. };
  140. struct i2c_client; /* forward declaration */
  141. struct adp5588_gpio_platform_data {
  142. int gpio_start; /* GPIO Chip base # */
  143. const char *const *names;
  144. unsigned irq_base; /* interrupt base # */
  145. unsigned pullup_dis_mask; /* Pull-Up Disable Mask */
  146. int (*setup)(struct i2c_client *client,
  147. unsigned gpio, unsigned ngpio,
  148. void *context);
  149. int (*teardown)(struct i2c_client *client,
  150. unsigned gpio, unsigned ngpio,
  151. void *context);
  152. void *context;
  153. };
  154. #endif