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>
17 #include <linux/android_alarm.h>
19 #define RT5025_DEVICE_NAME "RT5025"
20 #define RT5025_DRV_VER "1.0.8_R"
23 RT5025_RSTDELAY1_100MS,
24 RT5025_RSTDELAY1_500MS,
30 RT5025_RSTDELAY2_100MS,
31 RT5025_RSTDELAY2_500MS,
48 RT5025_STARTIME_100MS,
162 RT5025_MAX_REGULATOR,
165 struct rt5025_power_data {
168 unsigned char Resv1:1;
169 unsigned char CHGBC_EN:1;
171 unsigned char Resv2:1;
172 unsigned char CCCHG_TIMEOUT:2;
173 unsigned char PRECHG_TIMEOUT:2;
179 unsigned char Resv:2;
180 unsigned char VOREG:6;
186 unsigned char AICR_CON:1;
187 unsigned char AICR:2;
189 unsigned char CHG_RST:1;
195 unsigned char Resv1:4;
197 unsigned char Resv2:2;
203 unsigned char IPREC:1;
204 unsigned char IEOC:1;
205 unsigned char VPREC:3;
206 unsigned char Resv:3;
212 unsigned char Resv1:4;
213 unsigned char CHGC_EN:1;
214 unsigned char CHG_DCDC_MODE:1;
215 unsigned char BATD_EN:1;
216 unsigned char Resv2:1;
222 struct rt5025_gpio_data {
227 struct rt5025_misc_data {
230 unsigned char Action:2;
231 unsigned char Delayed1:2;
232 unsigned char Delayed2:2;
233 unsigned char Resv:2;
239 unsigned char Resv:5;
240 unsigned char VOFF:3;
246 unsigned char PG_DLY:2;
247 unsigned char SHDN_PRESS:2;
248 unsigned char LPRESS_TIME:2;
249 unsigned char START_TIME:2;
255 unsigned char Resv:4;
256 unsigned char SHDN_DLYTIME:2;
257 unsigned char SHDN_TIMING:1;
258 unsigned char SHDN_CTRL:1;
264 unsigned char Resv:2;
265 unsigned char OT_ENSHDN:1;
266 unsigned char PWRON_ENSHDN:1;
267 unsigned char DCDC3LV_ENSHDN:1;
268 unsigned char DCDC2LV_ENSHDN:1;
269 unsigned char DCDC1LV_ENSHDN:1;
270 unsigned char SYSLV_ENSHDN:1;
276 struct rt5025_irq_data {
279 unsigned char BATABS:1;
280 unsigned char Resv1:2;
281 unsigned char INUSB_PLUGIN:1;
282 unsigned char INUSBOVP:1;
283 unsigned char Resv2:1;
284 unsigned char INAC_PLUGIN:1;
285 unsigned char INACOVP:1;
291 unsigned char CHTERMI:1;
292 unsigned char CHBATOVI:1;
293 unsigned char CHGOODI_INUSB:1;
294 unsigned char CHBADI_INUSB:1;
295 unsigned char CHSLPI_INUSB:1;
296 unsigned char CHGOODI_INAC:1;
297 unsigned char CHBADI_INAC:1;
298 unsigned char CHSLPI_INAC:1;
304 unsigned char TIMEOUT_CC:1;
305 unsigned char TIMEOUT_PC:1;
306 unsigned char Resv:3;
307 unsigned char CHVSREGI:1;
308 unsigned char CHTREGI:1;
309 unsigned char CHRCHGI:1;
315 unsigned char SYSLV:1;
316 unsigned char DCDC4LVHV:1;
317 unsigned char PWRONLP:1;
318 unsigned char PWRONSP:1;
319 unsigned char DCDC3LV:1;
320 unsigned char DCDC2LV:1;
321 unsigned char DCDC1LV:1;
328 unsigned char Resv:1;
329 unsigned char GPIO0_IE:1;
330 unsigned char GPIO1_IE:1;
331 unsigned char GPIO2_IE:1;
332 unsigned char RESETB:1;
333 unsigned char PWRONF:1;
334 unsigned char PWRONR:1;
335 unsigned char KPSHDN:1;
349 struct rt5025_jeita_data {
356 #define CHG_EVENT_INACOVP (0x80<<16)
357 #define CHG_EVENT_INAC_PLUGIN (0x40<<16)
358 #define CHG_EVENT_INUSBOVP (0x10<<16)
359 #define CHG_EVENT_INUSB_PLUGIN (0x08<<16)
360 #define CHG_EVENT_BAT_ABS (0x01<<16)
362 #define CHG_EVENT_CHSLPI_INAC (0x80<<8)
363 #define CHG_EVENT_CHBADI_INAC (0x40<<8)
364 #define CHG_EVENT_CHGOODI_INAC (0x20<<8)
365 #define CHG_EVENT_CHSLPI_INUSB (0x10<<8)
366 #define CHG_EVENT_CHBADI_INUSB (0x08<<8)
367 #define CHG_EVENT_CHGOODI_INUSB (0x04<<8)
368 #define CHG_EVENT_CHBATOVI (0x02<<8)
369 #define CHG_EVENT_CHTERMI (0x01<<8)
371 #define CHG_EVENT_CHRCHGI (0x80<<0)
372 #define CHG_EVENT_CHTREGI (0x40<<0)
373 #define CHG_EVENT_CHVSREGI (0x20<<0)
374 #define CHG_EVENT_TIMEOUTPC (0x02<<0)
375 #define CHG_EVENT_TIMEOUTCC (0x01<<0)
377 #define CHARGER_DETECT_MASK (CHG_EVENT_INAC_PLUGIN | CHG_EVENT_INUSB_PLUGIN | \
378 CHG_EVENT_CHSLPI_INAC | CHG_EVENT_CHSLPI_INUSB | \
379 CHG_EVENT_CHBADI_INAC | CHG_EVENT_CHBADI_INUSB | \
380 CHG_EVENT_CHTERMI | CHG_EVENT_CHRCHGI)
383 #define PWR_EVENT_OTIQ (0x80<<8)
384 #define PWR_EVENT_DCDC1LV (0x40<<8)
385 #define PWR_EVENT_DCDC2LV (0x20<<8)
386 #define PWR_EVENT_DCDC3LV (0x10<<8)
387 #define PWR_EVENT_PWRONSP (0x08<<8)
388 #define PWR_EVENT_PWRONLP (0x04<<8)
389 #define PWR_EVENT_DCDC4LVHV (0x02<<8)
390 #define PWR_EVENT_SYSLV (0x01<<8)
392 #define PWR_EVENT_KPSHDN (0x80<<0)
393 #define PWR_EVNET_PWRONR (0x40<<0)
394 #define PWR_EVENT_PWRONF (0x20<<0)
395 #define PWR_EVENT_RESETB (0x10<<0)
396 #define PWR_EVENT_GPIO2IE (0x08<<0)
397 #define PWR_EVENT_GPIO1IE (0x04<<0)
398 #define PWR_EVENT_GPIO0IE (0x02<<0)
400 struct rt5025_event_callback {
402 void (*charger_event_callback)(uint32_t detected);
403 void (*power_event_callkback)(uint32_t detected);
405 void (*over_temperature_callback)(uint8_t detected);
406 void (*charging_complete_callback)(void);
407 void (*over_voltage_callback)(uint8_t detected);
408 void (*under_voltage_callback)(uint8_t detected);
409 void (*charge_fault_callback)(uint8_t detected);
410 void (*charge_warning_callback)(uint8_t detected);
414 struct rt5025_power_info {
415 struct i2c_client *i2c;
417 struct rt5025_chip *chip;
418 //struct rt5025_gauge_callbacks *event_callback;
419 struct power_supply ac;
420 struct power_supply usb;
421 struct mutex var_lock;
422 struct delayed_work usb_detect_work;
426 unsigned ac_online:1;
427 unsigned usb_online:1;
431 struct rt5025_swjeita_info {
432 struct i2c_client *i2c;
433 struct rt5025_chip *chip;
434 struct delayed_work thermal_reg_work;
441 int cur_therm_region;
449 struct rt5025_battery_info {
450 struct i2c_client *client;
451 struct rt5025_chip *chip;
452 //struct rt5025_gauge_callbacks cb;
454 struct power_supply battery;
456 struct delayed_work monitor_work;
457 struct wake_lock monitor_wake_lock;
458 struct wake_lock low_battery_wake_lock;
459 struct wake_lock status_wake_lock;
460 //#if RT5025_TEST_WAKE_LOCK
461 struct wake_lock test_wake_lock;
463 struct alarm wakeup_alarm;
466 bool temp_range_5_10;
467 bool temp_range_10_15;
468 bool temp_range_15_20;
469 bool temp_range_20_30;
470 bool temp_range_30_35;
471 bool temp_range_35_40;
472 bool temp_range_40_45;
473 bool temp_range_45_50;
476 bool range_5_10_done;
477 bool range_10_15_done;
478 bool range_15_20_done;
479 bool range_20_30_done;
480 bool range_30_35_done;
481 bool range_35_40_done;
482 bool range_40_45_done;
483 bool range_45_50_done;
489 // ktime_t last_event;
490 struct timespec last_event;
494 /* previous battery voltage */
496 /* previous battery current */
498 /* battery voltage */
500 /* battery current */
502 /* battery current offset */
506 /* battery internal temperature */
508 /* battery external temperature */
510 /* charge coulomb counter */
513 /* discharge coulomb counter */
516 /* battery capacity */
533 /* max voltage IRQ flag */
535 /* min voltage1 IRQ flag */
537 /* min voltage2 IRQ flag */
539 /* max temperature IRQ flag */
541 /* min temperature IRQ flag */
544 bool min_volt2_alert;
553 /* remain capacity */
593 struct i2c_client *i2c;
594 struct workqueue_struct *wq;
596 struct rt5025_power_info *power_info;
597 struct rt5025_swjeita_info *jeita_info;
598 struct rt5025_battery_info *battery_info;
601 struct delayed_work delayed_work;
602 struct mutex io_lock;
605 struct rt5025_platform_data {
606 struct regulator_init_data* regulator[RT5025_MAX_REGULATOR];
607 struct rt5025_power_data* power_data;
608 struct rt5025_gpio_data* gpio_data;
609 struct rt5025_misc_data* misc_data;
610 struct rt5025_irq_data* irq_data;
611 struct rt5025_jeita_data* jeita_data;
612 struct rt5025_event_callback *cb;
613 int (*pre_init)(struct rt5025_chip *rt5025_chip);
614 /** Called after subdevices are set up */
615 int (*post_init)(void);
616 int (*set_otg_enable)(int);
620 #ifdef CONFIG_MFD_RT5025_MISC
621 extern void rt5025_power_off(void);
622 extern int rt5025_cable_exist(void);
623 #endif /* CONFIG_MFD_RT5025_MISC */
625 #ifdef CONFIG_POWER_RT5025
626 extern int rt5025_charger_reset_and_reinit(struct rt5025_power_info *);
627 extern int rt5025_ext_set_charging_buck(int);
628 extern int rt5025_set_charging_buck(struct i2c_client *, int);
629 extern int rt5025_set_charging_current_switch(struct i2c_client *, int);
630 extern void rt5025_gauge_set_status(struct rt5025_battery_info *, int);
631 extern void rt5025_gauge_set_online(struct rt5025_battery_info *, bool);
632 extern void rt5025_gauge_irq_handler(struct rt5025_battery_info *, u8);
633 extern int rt5025_power_charge_detect(struct rt5025_power_info *);
634 extern int rt5025_notify_charging_cable(struct rt5025_swjeita_info *, int);
635 extern int rt5025_swjeita_irq_handler(struct rt5025_swjeita_info *, unsigned char);
636 #endif /* CONFIG_POEWR_RT5025 */
638 extern int rt5025_reg_block_read(struct i2c_client *, int, int, void *);
639 extern int rt5025_reg_block_write(struct i2c_client *, int, int, void *);
640 extern int rt5025_reg_read(struct i2c_client *, int);
641 extern int rt5025_reg_write(struct i2c_client *, int, unsigned char);
642 extern int rt5025_assign_bits(struct i2c_client *, int, unsigned char, unsigned char);
643 extern int rt5025_set_bits(struct i2c_client *, int, unsigned char);
644 extern int rt5025_clr_bits(struct i2c_client *, int, unsigned char);
646 extern int rt5025_core_init(struct rt5025_chip *, struct rt5025_platform_data *);
647 extern int rt5025_core_deinit(struct rt5025_chip *);
649 #ifdef CONFIG_MFD_RT_SHOW_INFO
650 #define RTINFO(format, args...) \
651 printk(KERN_INFO "%s:%s() line-%d: " format, RT5025_DEVICE_NAME,__FUNCTION__,__LINE__, ##args)
653 #define RTINFO(format,args...)
654 #endif /* CONFIG_MFD_RT_SHOW_INFO */
656 #endif /* __LINUX_MFD_RT5025_H */