adp5520.h 8.3 KB

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