2 * include/linux/mfd/rt5025.h
3 * Include header file for Richtek RT5025 Core file
5 * Copyright (C) 2013 Richtek Electronics
6 * cy_huang <cy_huang@richtek.com>
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.
13 #ifndef __LINUX_MFD_RT5025_H
14 #define __LINUX_MFD_RT5025_H
16 #include <linux/power_supply.h>
18 #define RT5025_DEVICE_NAME "RT5025"
21 RT5025_RSTDELAY1_100MS,
22 RT5025_RSTDELAY1_500MS,
28 RT5025_RSTDELAY2_100MS,
29 RT5025_RSTDELAY2_500MS,
46 RT5025_STARTIME_100MS,
160 RT5025_MAX_REGULATOR,
163 struct rt5025_power_data {
166 unsigned char Resv1:1;
167 unsigned char CHGBC_EN:1;
169 unsigned char Resv2:1;
170 unsigned char CCCHG_TIMEOUT:2;
171 unsigned char PRECHG_TIMEOUT:2;
177 unsigned char Resv:2;
178 unsigned char VOREG:6;
184 unsigned char AICR_CON:1;
185 unsigned char AICR:2;
187 unsigned char CHG_RST:1;
193 unsigned char Resv1:4;
195 unsigned char Resv2:2;
201 unsigned char IPREC:1;
202 unsigned char IEOC:1;
203 unsigned char VPREC:3;
204 unsigned char Resv:3;
210 unsigned char Resv1:4;
211 unsigned char CHGC_EN:1;
212 unsigned char CHG_DCDC_MODE:1;
213 unsigned char BATD_EN:1;
214 unsigned char Resv2:1;
221 struct rt5025_gpio_data {
226 struct rt5025_misc_data {
229 unsigned char Action:2;
230 unsigned char Delayed1:2;
231 unsigned char Delayed2:2;
232 unsigned char Resv:2;
238 unsigned char Resv:5;
239 unsigned char VOFF:3;
245 unsigned char PG_DLY:2;
246 unsigned char SHDN_PRESS:2;
247 unsigned char LPRESS_TIME:2;
248 unsigned char START_TIME:2;
254 unsigned char Resv:4;
255 unsigned char SHDN_DLYTIME:2;
256 unsigned char SHDN_TIMING:1;
257 unsigned char SHDN_CTRL:1;
263 unsigned char Resv:2;
264 unsigned char OT_ENSHDN:1;
265 unsigned char PWRON_ENSHDN:1;
266 unsigned char DCDC3LV_ENSHDN:1;
267 unsigned char DCDC2LV_ENSHDN:1;
268 unsigned char DCDC1LV_ENSHDN:1;
269 unsigned char SYSLV_ENSHDN:1;
275 struct rt5025_irq_data {
278 unsigned char BATABS:1;
279 unsigned char Resv1:2;
280 unsigned char INUSB_PLUGIN:1;
281 unsigned char INUSBOVP:1;
282 unsigned char Resv2:1;
283 unsigned char INAC_PLUGIN:1;
284 unsigned char INACOVP:1;
290 unsigned char CHTERMI:1;
291 unsigned char CHBATOVI:1;
292 unsigned char CHGOODI_INUSB:1;
293 unsigned char CHBADI_INUSB:1;
294 unsigned char CHSLPI_INUSB:1;
295 unsigned char CHGOODI_INAC:1;
296 unsigned char CHBADI_INAC:1;
297 unsigned char CHSLPI_INAC:1;
303 unsigned char TIMEOUT_CC:1;
304 unsigned char TIMEOUT_PC:1;
305 unsigned char Resv:3;
306 unsigned char CHVSREGI:1;
307 unsigned char CHTREGI:1;
308 unsigned char CHRCHGI:1;
314 unsigned char SYSLV:1;
315 unsigned char DCDC4LVHV:1;
316 unsigned char PWRONLP:1;
317 unsigned char PWRONSP:1;
318 unsigned char DCDC3LV:1;
319 unsigned char DCDC2LV:1;
320 unsigned char DCDC1LV:1;
327 unsigned char Resv:1;
328 unsigned char GPIO0_IE:1;
329 unsigned char GPIO1_IE:1;
330 unsigned char GPIO2_IE:1;
331 unsigned char RESETB:1;
332 unsigned char PWRONF:1;
333 unsigned char PWRONR:1;
334 unsigned char KPSHDN:1;
340 #define CHG_EVENT_INACOVP (0x80<<16)
341 #define CHG_EVENT_INAC_PLUGIN (0x40<<16)
342 #define CHG_EVENT_INUSBOVP (0x10<<16)
343 #define CHG_EVENT_INUSB_PLUGIN (0x08<<16)
344 #define CHG_EVENT_BAT_ABS (0x01<<16)
346 #define CHG_EVENT_CHSLPI_INAC (0x80<<8)
347 #define CHG_EVENT_CHBADI_INAC (0x40<<8)
348 #define CHG_EVENT_CHGOODI_INAC (0x20<<8)
349 #define CHG_EVENT_CHSLPI_INUSB (0x10<<8)
350 #define CHG_EVENT_CHBADI_INUSB (0x08<<8)
351 #define CHG_EVENT_CHGOODI_INUSB (0x04<<8)
352 #define CHG_EVENT_CHBATOVI (0x02<<8)
353 #define CHG_EVENT_CHTERMI (0x01<<8)
355 #define CHG_EVENT_CHRCHGI (0x80<<0)
356 #define CHG_EVENT_CHTREGI (0x40<<0)
357 #define CHG_EVENT_CHVSREGI (0x20<<0)
358 #define CHG_EVENT_TIMEOUTPC (0x02<<0)
359 #define CHG_EVENT_TIMEOUTCC (0x01<<0)
361 #define CHARGER_DETECT_MASK (CHG_EVENT_INAC_PLUGIN | CHG_EVENT_INUSB_PLUGIN | \
362 CHG_EVENT_CHSLPI_INAC | CHG_EVENT_CHSLPI_INUSB | \
363 CHG_EVENT_CHBADI_INAC | CHG_EVENT_CHBADI_INUSB)
365 #define PWR_EVENT_OTIQ (0x80<<8)
366 #define PWR_EVENT_DCDC1LV (0x40<<8)
367 #define PWR_EVENT_DCDC2LV (0x20<<8)
368 #define PWR_EVENT_DCDC3LV (0x10<<8)
369 #define PWR_EVENT_PWRONSP (0x08<<8)
370 #define PWR_EVENT_PWRONLP (0x04<<8)
371 #define PWR_EVENT_DCDC4LVHV (0x02<<8)
372 #define PWR_EVENT_SYSLV (0x01<<8)
374 #define PWR_EVENT_KPSHDN (0x80<<0)
375 #define PWR_EVNET_PWRONR (0x40<<0)
376 #define PWR_EVENT_PWRONF (0x20<<0)
377 #define PWR_EVENT_RESETB (0x10<<0)
378 #define PWR_EVENT_GPIO2IE (0x08<<0)
379 #define PWR_EVENT_GPIO1IE (0x04<<0)
380 #define PWR_EVENT_GPIO0IE (0x02<<0)
382 struct rt5025_event_callback {
384 void (*charger_event_callback)(uint32_t detected);
385 void (*power_event_callkback)(uint32_t detected);
387 void (*over_temperature_callback)(uint8_t detected);
388 void (*charging_complete_callback)(void);
389 void (*over_voltage_callback)(uint8_t detected);
390 void (*under_voltage_callback)(uint8_t detected);
391 void (*charge_fault_callback)(uint8_t detected);
392 void (*charge_warning_callback)(uint8_t detected);
396 struct rt5025_power_info {
397 struct i2c_client *i2c;
399 struct rt5025_gauge_callbacks *event_callback;
400 struct power_supply ac;
401 struct power_supply usb;
402 struct mutex var_lock;
403 struct delayed_work usb_detect_work;
406 unsigned ac_online:1;
407 unsigned usb_online:1;
412 struct i2c_client *i2c;
413 struct workqueue_struct *wq;
415 struct rt5025_power_info *power_info;
418 struct delayed_work delayed_work;
419 struct mutex io_lock;
422 struct rt5025_platform_data {
423 struct regulator_init_data* regulator[RT5025_MAX_REGULATOR];
424 struct rt5025_power_data* power_data;
425 struct rt5025_gpio_data* gpio_data;
426 struct rt5025_misc_data* misc_data;
427 struct rt5025_irq_data* irq_data;
428 struct rt5025_event_callback *cb;
429 int (*pre_init)(struct rt5025_chip *rt5025_chip);
430 /** Called after subdevices are set up */
431 int (*post_init)(void);
435 #ifdef CONFIG_MFD_RT5025_MISC
436 extern void rt5025_power_off(void);
437 #endif /* CONFIG_MFD_RT5025_MISC */
439 #ifdef CONFIG_POWER_RT5025
440 extern int rt5025_gauge_init(struct rt5025_power_info *);
441 extern int rt5025_power_passirq_to_gauge(struct rt5025_power_info *);
442 extern int rt5025_power_charge_detect(struct rt5025_power_info *);
443 #endif /* CONFIG_POEWR_RT5025 */
445 extern int rt5025_reg_block_read(struct i2c_client *, int, int, void *);
446 extern int rt5025_reg_block_write(struct i2c_client *, int, int, void *);
447 extern int rt5025_reg_read(struct i2c_client *, int);
448 extern int rt5025_reg_write(struct i2c_client *, int, unsigned char);
449 extern int rt5025_assign_bits(struct i2c_client *, int, unsigned char, unsigned char);
450 extern int rt5025_set_bits(struct i2c_client *, int, unsigned char);
451 extern int rt5025_clr_bits(struct i2c_client *, int, unsigned char);
453 extern int rt5025_core_init(struct rt5025_chip *, struct rt5025_platform_data *);
454 extern int rt5025_core_deinit(struct rt5025_chip *);
456 #ifdef CONFIG_MFD_RT_SHOW_INFO
457 #define RTINFO(format, args...) \
458 printk(KERN_INFO "%s:%s() line-%d: " format, RT5025_DEVICE_NAME,__FUNCTION__,__LINE__, ##args)
460 #define RTINFO(format,args...)
461 #endif /* CONFIG_MFD_RT_SHOW_INFO */
463 #endif /* __LINUX_MFD_RT5025_H */