adp5520.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Definitions and platform data for Analog Devices
  3. * ADP5520/ADP5501 MFD PMICs (Backlight, LED, GPIO and Keys)
  4. *
  5. * Copyright 2009 Analog Devices Inc.
  6. *
  7. * Licensed under the GPL-2 or later.
  8. */
  9. #ifndef __LINUX_MFD_ADP5520_H
  10. #define __LINUX_MFD_ADP5520_H
  11. #define ID_ADP5520 5520
  12. #define ID_ADP5501 5501
  13. /*
  14. * ADP5520/ADP5501 Register Map
  15. */
  16. #define ADP5520_MODE_STATUS 0x00
  17. #define ADP5520_INTERRUPT_ENABLE 0x01
  18. #define ADP5520_BL_CONTROL 0x02
  19. #define ADP5520_BL_TIME 0x03
  20. #define ADP5520_BL_FADE 0x04
  21. #define ADP5520_DAYLIGHT_MAX 0x05
  22. #define ADP5520_DAYLIGHT_DIM 0x06
  23. #define ADP5520_OFFICE_MAX 0x07
  24. #define ADP5520_OFFICE_DIM 0x08
  25. #define ADP5520_DARK_MAX 0x09
  26. #define ADP5520_DARK_DIM 0x0A
  27. #define ADP5520_BL_VALUE 0x0B
  28. #define ADP5520_ALS_CMPR_CFG 0x0C
  29. #define ADP5520_L2_TRIP 0x0D
  30. #define ADP5520_L2_HYS 0x0E
  31. #define ADP5520_L3_TRIP 0x0F
  32. #define ADP5520_L3_HYS 0x10
  33. #define ADP5520_LED_CONTROL 0x11
  34. #define ADP5520_LED_TIME 0x12
  35. #define ADP5520_LED_FADE 0x13
  36. #define ADP5520_LED1_CURRENT 0x14
  37. #define ADP5520_LED2_CURRENT 0x15
  38. #define ADP5520_LED3_CURRENT 0x16
  39. /*
  40. * ADP5520 Register Map
  41. */
  42. #define ADP5520_GPIO_CFG_1 0x17
  43. #define ADP5520_GPIO_CFG_2 0x18
  44. #define ADP5520_GPIO_IN 0x19
  45. #define ADP5520_GPIO_OUT 0x1A
  46. #define ADP5520_GPIO_INT_EN 0x1B
  47. #define ADP5520_GPIO_INT_STAT 0x1C
  48. #define ADP5520_GPIO_INT_LVL 0x1D
  49. #define ADP5520_GPIO_DEBOUNCE 0x1E
  50. #define ADP5520_GPIO_PULLUP 0x1F
  51. #define ADP5520_KP_INT_STAT_1 0x20
  52. #define ADP5520_KP_INT_STAT_2 0x21
  53. #define ADP5520_KR_INT_STAT_1 0x22
  54. #define ADP5520_KR_INT_STAT_2 0x23
  55. #define ADP5520_KEY_STAT_1 0x24
  56. #define ADP5520_KEY_STAT_2 0x25
  57. /*
  58. * MODE_STATUS bits
  59. */
  60. #define ADP5520_nSTNBY (1 << 7)
  61. #define ADP5520_BL_EN (1 << 6)
  62. #define ADP5520_DIM_EN (1 << 5)
  63. #define ADP5520_OVP_INT (1 << 4)
  64. #define ADP5520_CMPR_INT (1 << 3)
  65. #define ADP5520_GPI_INT (1 << 2)
  66. #define ADP5520_KR_INT (1 << 1)
  67. #define ADP5520_KP_INT (1 << 0)
  68. /*
  69. * INTERRUPT_ENABLE bits
  70. */
  71. #define ADP5520_AUTO_LD_EN (1 << 4)
  72. #define ADP5520_CMPR_IEN (1 << 3)
  73. #define ADP5520_OVP_IEN (1 << 2)
  74. #define ADP5520_KR_IEN (1 << 1)
  75. #define ADP5520_KP_IEN (1 << 0)
  76. /*
  77. * BL_CONTROL bits
  78. */
  79. #define ADP5520_BL_LVL ((x) << 5)
  80. #define ADP5520_BL_LAW ((x) << 4)
  81. #define ADP5520_BL_AUTO_ADJ (1 << 3)
  82. #define ADP5520_OVP_EN (1 << 2)
  83. #define ADP5520_FOVR (1 << 1)
  84. #define ADP5520_KP_BL_EN (1 << 0)
  85. /*
  86. * ALS_CMPR_CFG bits
  87. */
  88. #define ADP5520_L3_OUT (1 << 3)
  89. #define ADP5520_L2_OUT (1 << 2)
  90. #define ADP5520_L3_EN (1 << 1)
  91. #define ADP5020_MAX_BRIGHTNESS 0x7F
  92. #define FADE_VAL(in, out) ((0xF & (in)) | ((0xF & (out)) << 4))
  93. #define BL_CTRL_VAL(law, auto) (((1 & (auto)) << 3) | ((0x3 & (law)) << 4))
  94. #define ALS_CMPR_CFG_VAL(filt, l3_en) (((0x7 & filt) << 5) | l3_en)
  95. /*
  96. * LEDs subdevice bits and masks
  97. */
  98. #define ADP5520_01_MAXLEDS 3
  99. #define ADP5520_FLAG_LED_MASK 0x3
  100. #define ADP5520_FLAG_OFFT_SHIFT 8
  101. #define ADP5520_FLAG_OFFT_MASK 0x3
  102. #define ADP5520_R3_MODE (1 << 5)
  103. #define ADP5520_C3_MODE (1 << 4)
  104. #define ADP5520_LED_LAW (1 << 3)
  105. #define ADP5520_LED3_EN (1 << 2)
  106. #define ADP5520_LED2_EN (1 << 1)
  107. #define ADP5520_LED1_EN (1 << 0)
  108. /*
  109. * GPIO subdevice bits and masks
  110. */
  111. #define ADP5520_MAXGPIOS 8
  112. #define ADP5520_GPIO_C3 (1 << 7) /* LED2 or GPIO7 aka C3 */
  113. #define ADP5520_GPIO_C2 (1 << 6)
  114. #define ADP5520_GPIO_C1 (1 << 5)
  115. #define ADP5520_GPIO_C0 (1 << 4)
  116. #define ADP5520_GPIO_R3 (1 << 3) /* LED3 or GPIO3 aka R3 */
  117. #define ADP5520_GPIO_R2 (1 << 2)
  118. #define ADP5520_GPIO_R1 (1 << 1)
  119. #define ADP5520_GPIO_R0 (1 << 0)
  120. struct adp5520_gpio_platform_data {
  121. unsigned gpio_start;
  122. u8 gpio_en_mask;
  123. u8 gpio_pullup_mask;
  124. };
  125. /*
  126. * Keypad subdevice bits and masks
  127. */
  128. #define ADP5520_MAXKEYS 16
  129. #define ADP5520_COL_C3 (1 << 7) /* LED2 or GPIO7 aka C3 */
  130. #define ADP5520_COL_C2 (1 << 6)
  131. #define ADP5520_COL_C1 (1 << 5)
  132. #define ADP5520_COL_C0 (1 << 4)
  133. #define ADP5520_ROW_R3 (1 << 3) /* LED3 or GPIO3 aka R3 */
  134. #define ADP5520_ROW_R2 (1 << 2)
  135. #define ADP5520_ROW_R1 (1 << 1)
  136. #define ADP5520_ROW_R0 (1 << 0)
  137. #define ADP5520_KEY(row, col) (col + row * 4)
  138. #define ADP5520_KEYMAPSIZE ADP5520_MAXKEYS
  139. struct adp5520_keys_platform_data {
  140. int rows_en_mask; /* Number of rows */
  141. int cols_en_mask; /* Number of columns */
  142. const unsigned short *keymap; /* Pointer to keymap */
  143. unsigned short keymapsize; /* Keymap size */
  144. unsigned repeat:1; /* Enable key repeat */
  145. };
  146. /*
  147. * LEDs subdevice platform data
  148. */
  149. #define FLAG_ID_ADP5520_LED1_ADP5501_LED0 1 /* ADP5520 PIN ILED */
  150. #define FLAG_ID_ADP5520_LED2_ADP5501_LED1 2 /* ADP5520 PIN C3 */
  151. #define FLAG_ID_ADP5520_LED3_ADP5501_LED2 3 /* ADP5520 PIN R3 */
  152. #define ADP5520_LED_DIS_BLINK (0 << ADP5520_FLAG_OFFT_SHIFT)
  153. #define ADP5520_LED_OFFT_600ms (1 << ADP5520_FLAG_OFFT_SHIFT)
  154. #define ADP5520_LED_OFFT_800ms (2 << ADP5520_FLAG_OFFT_SHIFT)
  155. #define ADP5520_LED_OFFT_1200ms (3 << ADP5520_FLAG_OFFT_SHIFT)
  156. #define ADP5520_LED_ONT_200ms 0
  157. #define ADP5520_LED_ONT_600ms 1
  158. #define ADP5520_LED_ONT_800ms 2
  159. #define ADP5520_LED_ONT_1200ms 3
  160. struct adp5520_leds_platform_data {
  161. int num_leds;
  162. struct led_info *leds;
  163. u8 fade_in; /* Backlight Fade-In Timer */
  164. u8 fade_out; /* Backlight Fade-Out Timer */
  165. u8 led_on_time;
  166. };
  167. /*
  168. * Backlight subdevice platform data
  169. */
  170. #define ADP5520_FADE_T_DIS 0 /* Fade Timer Disabled */
  171. #define ADP5520_FADE_T_300ms 1 /* 0.3 Sec */
  172. #define ADP5520_FADE_T_600ms 2
  173. #define ADP5520_FADE_T_900ms 3
  174. #define ADP5520_FADE_T_1200ms 4
  175. #define ADP5520_FADE_T_1500ms 5
  176. #define ADP5520_FADE_T_1800ms 6
  177. #define ADP5520_FADE_T_2100ms 7
  178. #define ADP5520_FADE_T_2400ms 8
  179. #define ADP5520_FADE_T_2700ms 9
  180. #define ADP5520_FADE_T_3000ms 10
  181. #define ADP5520_FADE_T_3500ms 11
  182. #define ADP5520_FADE_T_4000ms 12
  183. #define ADP5520_FADE_T_4500ms 13
  184. #define ADP5520_FADE_T_5000ms 14
  185. #define ADP5520_FADE_T_5500ms 15 /* 5.5 Sec */
  186. #define ADP5520_BL_LAW_LINEAR 0
  187. #define ADP5520_BL_LAW_SQUARE 1
  188. #define ADP5520_BL_LAW_CUBIC1 2
  189. #define ADP5520_BL_LAW_CUBIC2 3
  190. #define ADP5520_BL_AMBL_FILT_80ms 0 /* Light sensor filter time */
  191. #define ADP5520_BL_AMBL_FILT_160ms 1
  192. #define ADP5520_BL_AMBL_FILT_320ms 2
  193. #define ADP5520_BL_AMBL_FILT_640ms 3
  194. #define ADP5520_BL_AMBL_FILT_1280ms 4
  195. #define ADP5520_BL_AMBL_FILT_2560ms 5
  196. #define ADP5520_BL_AMBL_FILT_5120ms 6
  197. #define ADP5520_BL_AMBL_FILT_10240ms 7 /* 10.24 sec */
  198. /*
  199. * Blacklight current 0..30mA
  200. */
  201. #define ADP5520_BL_CUR_mA(I) ((I * 127) / 30)
  202. /*
  203. * L2 comparator current 0..1000uA
  204. */
  205. #define ADP5520_L2_COMP_CURR_uA(I) ((I * 255) / 1000)
  206. /*
  207. * L3 comparator current 0..127uA
  208. */
  209. #define ADP5520_L3_COMP_CURR_uA(I) ((I * 255) / 127)
  210. struct adp5520_backlight_platform_data {
  211. u8 fade_in; /* Backlight Fade-In Timer */
  212. u8 fade_out; /* Backlight Fade-Out Timer */
  213. u8 fade_led_law; /* fade-on/fade-off transfer characteristic */
  214. u8 en_ambl_sens; /* 1 = enable ambient light sensor */
  215. u8 abml_filt; /* Light sensor filter time */
  216. u8 l1_daylight_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
  217. u8 l1_daylight_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
  218. u8 l2_office_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
  219. u8 l2_office_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
  220. u8 l3_dark_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
  221. u8 l3_dark_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
  222. u8 l2_trip; /* use L2_COMP_CURR_uA(I) 0 <= I <= 1000 uA */
  223. u8 l2_hyst; /* use L2_COMP_CURR_uA(I) 0 <= I <= 1000 uA */
  224. u8 l3_trip; /* use L3_COMP_CURR_uA(I) 0 <= I <= 127 uA */
  225. u8 l3_hyst; /* use L3_COMP_CURR_uA(I) 0 <= I <= 127 uA */
  226. };
  227. /*
  228. * MFD chip platform data
  229. */
  230. struct adp5520_platform_data {
  231. struct adp5520_keys_platform_data *keys;
  232. struct adp5520_gpio_platform_data *gpio;
  233. struct adp5520_leds_platform_data *leds;
  234. struct adp5520_backlight_platform_data *backlight;
  235. };
  236. /*
  237. * MFD chip functions
  238. */
  239. extern int adp5520_read(struct device *dev, int reg, uint8_t *val);
  240. extern int adp5520_write(struct device *dev, int reg, u8 val);
  241. extern int adp5520_clr_bits(struct device *dev, int reg, uint8_t bit_mask);
  242. extern int adp5520_set_bits(struct device *dev, int reg, uint8_t bit_mask);
  243. extern int adp5520_register_notifier(struct device *dev,
  244. struct notifier_block *nb, unsigned int events);
  245. extern int adp5520_unregister_notifier(struct device *dev,
  246. struct notifier_block *nb, unsigned int events);
  247. #endif /* __LINUX_MFD_ADP5520_H */