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