xref: /openbmc/linux/include/linux/mfd/lp8788.h (revision cfbb9be8)
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_ldo_enable_pin
186  *
187  *   Basically, all LDOs are enabled through the I2C commands.
188  *   But ALDO 1 ~ 5, 7, DLDO 7, 9, 11 can be enabled by external gpio pins.
189  *
190  * @gpio         : gpio number which is used for enabling ldos
191  * @init_state   : initial gpio state (ex. GPIOF_OUT_INIT_LOW)
192  */
193 struct lp8788_ldo_enable_pin {
194 	int gpio;
195 	int init_state;
196 };
197 
198 /*
199  * struct lp8788_chg_param
200  * @addr         : charging control register address (range : 0x11 ~ 0x1C)
201  * @val          : charging parameter value
202  */
203 struct lp8788_chg_param {
204 	u8 addr;
205 	u8 val;
206 };
207 
208 /*
209  * struct lp8788_charger_platform_data
210  * @adc_vbatt         : adc channel name for battery voltage
211  * @adc_batt_temp     : adc channel name for battery temperature
212  * @max_vbatt_mv      : used for calculating battery capacity
213  * @chg_params        : initial charging parameters
214  * @num_chg_params    : numbers of charging parameters
215  * @charger_event     : the charger event can be reported to the platform side
216  */
217 struct lp8788_charger_platform_data {
218 	const char *adc_vbatt;
219 	const char *adc_batt_temp;
220 	unsigned int max_vbatt_mv;
221 	struct lp8788_chg_param *chg_params;
222 	int num_chg_params;
223 	void (*charger_event) (struct lp8788 *lp,
224 				enum lp8788_charger_event event);
225 };
226 
227 /*
228  * struct lp8788_backlight_platform_data
229  * @name                  : backlight driver name. (default: "lcd-backlight")
230  * @initial_brightness    : initial value of backlight brightness
231  * @bl_mode               : brightness control by pwm or lp8788 register
232  * @dim_mode              : dimming mode selection
233  * @full_scale            : full scale current setting
234  * @rise_time             : brightness ramp up step time
235  * @fall_time             : brightness ramp down step time
236  * @pwm_pol               : pwm polarity setting when bl_mode is pwm based
237  * @period_ns             : platform specific pwm period value. unit is nano.
238 			    Only valid when bl_mode is LP8788_BL_COMB_PWM_BASED
239  */
240 struct lp8788_backlight_platform_data {
241 	char *name;
242 	int initial_brightness;
243 	enum lp8788_bl_ctrl_mode bl_mode;
244 	enum lp8788_bl_dim_mode dim_mode;
245 	enum lp8788_bl_full_scale_current full_scale;
246 	enum lp8788_bl_ramp_step rise_time;
247 	enum lp8788_bl_ramp_step fall_time;
248 	enum pwm_polarity pwm_pol;
249 	unsigned int period_ns;
250 };
251 
252 /*
253  * struct lp8788_led_platform_data
254  * @name         : led driver name. (default: "keyboard-backlight")
255  * @scale        : current scale
256  * @num          : current sink number
257  * @iout_code    : current output value (Addr 9Ah ~ 9Bh)
258  */
259 struct lp8788_led_platform_data {
260 	char *name;
261 	enum lp8788_isink_scale scale;
262 	enum lp8788_isink_number num;
263 	int iout_code;
264 };
265 
266 /*
267  * struct lp8788_vib_platform_data
268  * @name         : vibrator driver name
269  * @scale        : current scale
270  * @num          : current sink number
271  * @iout_code    : current output value (Addr 9Ah ~ 9Bh)
272  * @pwm_code     : PWM code value (Addr 9Ch ~ 9Eh)
273  */
274 struct lp8788_vib_platform_data {
275 	char *name;
276 	enum lp8788_isink_scale scale;
277 	enum lp8788_isink_number num;
278 	int iout_code;
279 	int pwm_code;
280 };
281 
282 /*
283  * struct lp8788_platform_data
284  * @init_func    : used for initializing registers
285  *                 before mfd driver is registered
286  * @buck_data    : regulator initial data for buck
287  * @dldo_data    : regulator initial data for digital ldo
288  * @aldo_data    : regulator initial data for analog ldo
289  * @buck1_dvs    : gpio configurations for buck1 dvs
290  * @buck2_dvs    : gpio configurations for buck2 dvs
291  * @ldo_pin      : gpio configurations for enabling LDOs
292  * @chg_pdata    : platform data for charger driver
293  * @alarm_sel    : rtc alarm selection (1 or 2)
294  * @bl_pdata     : configurable data for backlight driver
295  * @led_pdata    : configurable data for led driver
296  * @vib_pdata    : configurable data for vibrator driver
297  * @adc_pdata    : iio map data for adc driver
298  */
299 struct lp8788_platform_data {
300 	/* general system information */
301 	int (*init_func) (struct lp8788 *lp);
302 
303 	/* regulators */
304 	struct regulator_init_data *buck_data[LP8788_NUM_BUCKS];
305 	struct regulator_init_data *dldo_data[LP8788_NUM_DLDOS];
306 	struct regulator_init_data *aldo_data[LP8788_NUM_ALDOS];
307 	struct lp8788_buck1_dvs *buck1_dvs;
308 	struct lp8788_buck2_dvs *buck2_dvs;
309 	struct lp8788_ldo_enable_pin *ldo_pin[EN_LDOS_MAX];
310 
311 	/* charger */
312 	struct lp8788_charger_platform_data *chg_pdata;
313 
314 	/* rtc alarm */
315 	enum lp8788_alarm_sel alarm_sel;
316 
317 	/* backlight */
318 	struct lp8788_backlight_platform_data *bl_pdata;
319 
320 	/* current sinks */
321 	struct lp8788_led_platform_data *led_pdata;
322 	struct lp8788_vib_platform_data *vib_pdata;
323 
324 	/* adc iio map data */
325 	struct iio_map *adc_pdata;
326 };
327 
328 /*
329  * struct lp8788
330  * @dev          : parent device pointer
331  * @regmap       : used for i2c communcation on accessing registers
332  * @irqdm        : interrupt domain for handling nested interrupt
333  * @irq          : pin number of IRQ_N
334  * @pdata        : lp8788 platform specific data
335  */
336 struct lp8788 {
337 	struct device *dev;
338 	struct regmap *regmap;
339 	struct irq_domain *irqdm;
340 	int irq;
341 	struct lp8788_platform_data *pdata;
342 };
343 
344 int lp8788_irq_init(struct lp8788 *lp, int chip_irq);
345 void lp8788_irq_exit(struct lp8788 *lp);
346 int lp8788_read_byte(struct lp8788 *lp, u8 reg, u8 *data);
347 int lp8788_read_multi_bytes(struct lp8788 *lp, u8 reg, u8 *data, size_t count);
348 int lp8788_write_byte(struct lp8788 *lp, u8 reg, u8 data);
349 int lp8788_update_bits(struct lp8788 *lp, u8 reg, u8 mask, u8 data);
350 #endif
351