1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * TI LP8788 MFD Device 4 * 5 * Copyright 2012 Texas Instruments 6 * 7 * Author: Milo(Woogyom) Kim <milo.kim@ti.com> 8 */ 9 10 #ifndef __MFD_LP8788_H__ 11 #define __MFD_LP8788_H__ 12 13 #include <linux/irqdomain.h> 14 #include <linux/regmap.h> 15 16 #define LP8788_DEV_BUCK "lp8788-buck" 17 #define LP8788_DEV_DLDO "lp8788-dldo" 18 #define LP8788_DEV_ALDO "lp8788-aldo" 19 #define LP8788_DEV_CHARGER "lp8788-charger" 20 #define LP8788_DEV_RTC "lp8788-rtc" 21 #define LP8788_DEV_BACKLIGHT "lp8788-backlight" 22 #define LP8788_DEV_VIBRATOR "lp8788-vibrator" 23 #define LP8788_DEV_KEYLED "lp8788-keyled" 24 #define LP8788_DEV_ADC "lp8788-adc" 25 26 #define LP8788_NUM_BUCKS 4 27 #define LP8788_NUM_DLDOS 12 28 #define LP8788_NUM_ALDOS 10 29 #define LP8788_NUM_BUCK2_DVS 2 30 31 #define LP8788_CHG_IRQ "CHG_IRQ" 32 #define LP8788_PRSW_IRQ "PRSW_IRQ" 33 #define LP8788_BATT_IRQ "BATT_IRQ" 34 #define LP8788_ALM_IRQ "ALARM_IRQ" 35 36 enum lp8788_int_id { 37 /* interrup register 1 : Addr 00h */ 38 LP8788_INT_TSDL, 39 LP8788_INT_TSDH, 40 LP8788_INT_UVLO, 41 LP8788_INT_FLAGMON, 42 LP8788_INT_PWRON_TIME, 43 LP8788_INT_PWRON, 44 LP8788_INT_COMP1, 45 LP8788_INT_COMP2, 46 47 /* interrupt register 2 : Addr 01h */ 48 LP8788_INT_CHG_INPUT_STATE, 49 LP8788_INT_CHG_STATE, 50 LP8788_INT_EOC, 51 LP8788_INT_CHG_RESTART, 52 LP8788_INT_RESTART_TIMEOUT, 53 LP8788_INT_FULLCHG_TIMEOUT, 54 LP8788_INT_PRECHG_TIMEOUT, 55 56 /* interrupt register 3 : Addr 02h */ 57 LP8788_INT_RTC_ALARM1 = 17, 58 LP8788_INT_RTC_ALARM2, 59 LP8788_INT_ENTER_SYS_SUPPORT, 60 LP8788_INT_EXIT_SYS_SUPPORT, 61 LP8788_INT_BATT_LOW, 62 LP8788_INT_NO_BATT, 63 64 LP8788_INT_MAX = 24, 65 }; 66 67 enum lp8788_dvs_sel { 68 DVS_SEL_V0, 69 DVS_SEL_V1, 70 DVS_SEL_V2, 71 DVS_SEL_V3, 72 }; 73 74 enum lp8788_ext_ldo_en_id { 75 EN_ALDO1, 76 EN_ALDO234, 77 EN_ALDO5, 78 EN_ALDO7, 79 EN_DLDO7, 80 EN_DLDO911, 81 EN_LDOS_MAX, 82 }; 83 84 enum lp8788_charger_event { 85 NO_CHARGER, 86 CHARGER_DETECTED, 87 }; 88 89 enum lp8788_bl_dim_mode { 90 LP8788_DIM_EXPONENTIAL, 91 LP8788_DIM_LINEAR, 92 }; 93 94 enum lp8788_bl_full_scale_current { 95 LP8788_FULLSCALE_5000uA, 96 LP8788_FULLSCALE_8500uA, 97 LP8788_FULLSCALE_1200uA, 98 LP8788_FULLSCALE_1550uA, 99 LP8788_FULLSCALE_1900uA, 100 LP8788_FULLSCALE_2250uA, 101 LP8788_FULLSCALE_2600uA, 102 LP8788_FULLSCALE_2950uA, 103 }; 104 105 enum lp8788_bl_ramp_step { 106 LP8788_RAMP_8us, 107 LP8788_RAMP_1024us, 108 LP8788_RAMP_2048us, 109 LP8788_RAMP_4096us, 110 LP8788_RAMP_8192us, 111 LP8788_RAMP_16384us, 112 LP8788_RAMP_32768us, 113 LP8788_RAMP_65538us, 114 }; 115 116 enum lp8788_isink_scale { 117 LP8788_ISINK_SCALE_100mA, 118 LP8788_ISINK_SCALE_120mA, 119 }; 120 121 enum lp8788_isink_number { 122 LP8788_ISINK_1, 123 LP8788_ISINK_2, 124 LP8788_ISINK_3, 125 }; 126 127 enum lp8788_alarm_sel { 128 LP8788_ALARM_1, 129 LP8788_ALARM_2, 130 LP8788_ALARM_MAX, 131 }; 132 133 enum lp8788_adc_id { 134 LPADC_VBATT_5P5, 135 LPADC_VIN_CHG, 136 LPADC_IBATT, 137 LPADC_IC_TEMP, 138 LPADC_VBATT_6P0, 139 LPADC_VBATT_5P0, 140 LPADC_ADC1, 141 LPADC_ADC2, 142 LPADC_VDD, 143 LPADC_VCOIN, 144 LPADC_VDD_LDO, 145 LPADC_ADC3, 146 LPADC_ADC4, 147 LPADC_MAX, 148 }; 149 150 struct lp8788; 151 152 /* 153 * lp8788_buck1_dvs 154 * @vsel : dvs selector for buck v1 register 155 */ 156 struct lp8788_buck1_dvs { 157 enum lp8788_dvs_sel vsel; 158 }; 159 160 /* 161 * lp8788_buck2_dvs 162 * @vsel : dvs selector for buck v2 register 163 */ 164 struct lp8788_buck2_dvs { 165 enum lp8788_dvs_sel vsel; 166 }; 167 168 /* 169 * struct lp8788_chg_param 170 * @addr : charging control register address (range : 0x11 ~ 0x1C) 171 * @val : charging parameter value 172 */ 173 struct lp8788_chg_param { 174 u8 addr; 175 u8 val; 176 }; 177 178 /* 179 * struct lp8788_charger_platform_data 180 * @adc_vbatt : adc channel name for battery voltage 181 * @adc_batt_temp : adc channel name for battery temperature 182 * @max_vbatt_mv : used for calculating battery capacity 183 * @chg_params : initial charging parameters 184 * @num_chg_params : numbers of charging parameters 185 * @charger_event : the charger event can be reported to the platform side 186 */ 187 struct lp8788_charger_platform_data { 188 const char *adc_vbatt; 189 const char *adc_batt_temp; 190 unsigned int max_vbatt_mv; 191 struct lp8788_chg_param *chg_params; 192 int num_chg_params; 193 void (*charger_event) (struct lp8788 *lp, 194 enum lp8788_charger_event event); 195 }; 196 197 /* 198 * struct lp8788_led_platform_data 199 * @name : led driver name. (default: "keyboard-backlight") 200 * @scale : current scale 201 * @num : current sink number 202 * @iout_code : current output value (Addr 9Ah ~ 9Bh) 203 */ 204 struct lp8788_led_platform_data { 205 char *name; 206 enum lp8788_isink_scale scale; 207 enum lp8788_isink_number num; 208 int iout_code; 209 }; 210 211 /* 212 * struct lp8788_vib_platform_data 213 * @name : vibrator driver name 214 * @scale : current scale 215 * @num : current sink number 216 * @iout_code : current output value (Addr 9Ah ~ 9Bh) 217 * @pwm_code : PWM code value (Addr 9Ch ~ 9Eh) 218 */ 219 struct lp8788_vib_platform_data { 220 char *name; 221 enum lp8788_isink_scale scale; 222 enum lp8788_isink_number num; 223 int iout_code; 224 int pwm_code; 225 }; 226 227 /* 228 * struct lp8788_platform_data 229 * @init_func : used for initializing registers 230 * before mfd driver is registered 231 * @buck_data : regulator initial data for buck 232 * @dldo_data : regulator initial data for digital ldo 233 * @aldo_data : regulator initial data for analog ldo 234 * @buck1_dvs : configurations for buck1 dvs 235 * @buck2_dvs : configurations for buck2 dvs 236 * @chg_pdata : platform data for charger driver 237 * @alarm_sel : rtc alarm selection (1 or 2) 238 * @led_pdata : configurable data for led driver 239 * @vib_pdata : configurable data for vibrator driver 240 * @adc_pdata : iio map data for adc driver 241 */ 242 struct lp8788_platform_data { 243 /* general system information */ 244 int (*init_func) (struct lp8788 *lp); 245 246 /* regulators */ 247 struct regulator_init_data *buck_data[LP8788_NUM_BUCKS]; 248 struct regulator_init_data *dldo_data[LP8788_NUM_DLDOS]; 249 struct regulator_init_data *aldo_data[LP8788_NUM_ALDOS]; 250 struct lp8788_buck1_dvs *buck1_dvs; 251 struct lp8788_buck2_dvs *buck2_dvs; 252 253 /* charger */ 254 struct lp8788_charger_platform_data *chg_pdata; 255 256 /* rtc alarm */ 257 enum lp8788_alarm_sel alarm_sel; 258 259 /* current sinks */ 260 struct lp8788_led_platform_data *led_pdata; 261 struct lp8788_vib_platform_data *vib_pdata; 262 263 /* adc iio map data */ 264 struct iio_map *adc_pdata; 265 }; 266 267 /* 268 * struct lp8788 269 * @dev : parent device pointer 270 * @regmap : used for i2c communcation on accessing registers 271 * @irqdm : interrupt domain for handling nested interrupt 272 * @irq : pin number of IRQ_N 273 * @pdata : lp8788 platform specific data 274 */ 275 struct lp8788 { 276 struct device *dev; 277 struct regmap *regmap; 278 struct irq_domain *irqdm; 279 int irq; 280 struct lp8788_platform_data *pdata; 281 }; 282 283 int lp8788_irq_init(struct lp8788 *lp, int chip_irq); 284 void lp8788_irq_exit(struct lp8788 *lp); 285 int lp8788_read_byte(struct lp8788 *lp, u8 reg, u8 *data); 286 int lp8788_read_multi_bytes(struct lp8788 *lp, u8 reg, u8 *data, size_t count); 287 int lp8788_write_byte(struct lp8788 *lp, u8 reg, u8 data); 288 int lp8788_update_bits(struct lp8788 *lp, u8 reg, u8 mask, u8 data); 289 #endif 290