1 /* 2 * Fuel gauge driver for CellWise 2013 / 2015 3 * 4 * Copyright (C) 2012, RockChip 5 * 6 * Authors: xuhuicong <xhc@rock-chips.com> 7 * 8 * Based on rk30_adc_battery.c 9 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License version 2 as 12 * published by the Free Software Foundation. 13 * 14 */ 15 16 #ifndef CW2015_BATTERY_H 17 #define CW2015_BATTERY_H 18 19 #define SIZE_BATINFO 64 20 21 #define CW2015_GPIO_HIGH 1 22 #define CW2015_GPIO_LOW 0 23 24 #define REG_VERSION 0x0 25 #define REG_VCELL 0x2 26 #define REG_SOC 0x4 27 #define REG_RRT_ALERT 0x6 28 #define REG_CONFIG 0x8 29 #define REG_MODE 0xA 30 #define REG_BATINFO 0x10 31 32 #define MODE_SLEEP_MASK (0x3<<6) 33 #define MODE_SLEEP (0x3<<6) 34 #define MODE_NORMAL (0x0<<6) 35 #define MODE_QUICK_START (0x3<<4) 36 #define MODE_RESTART (0xf<<0) 37 38 #define CONFIG_UPDATE_FLG (0x1<<1) 39 #define ATHD (0x0<<3) 40 41 #define CW_I2C_SPEED 100000 42 #define BATTERY_UP_MAX_CHANGE (420 * 1000) 43 #define BATTERY_DOWN_MAX_CHANGE (120 * 1000) 44 #define BATTERY_DOWN_CHANGE 60 45 #define BATTERY_DOWN_MIN_CHANGE_RUN 30 46 #define BATTERY_DOWN_MIN_CHANGE_SLEEP 1800 47 #define BATTERY_JUMP_TO_ZERO (30 * 1000) 48 #define BATTERY_CAPACITY_ERROR (40 * 1000) 49 #define BATTERY_CHARGING_ZERO (1800 * 1000) 50 51 #define DOUBLE_SERIES_BATTERY 0 52 53 #define CHARGING_ON 1 54 #define NO_CHARGING 0 55 56 #define BATTERY_DOWN_MAX_CHANGE_RUN_AC_ONLINE 3600 57 58 #define NO_STANDARD_AC_BIG_CHARGE_MODE 1 59 /* #define SYSTEM_SHUTDOWN_VOLTAGE 3400000 */ 60 #define BAT_LOW_INTERRUPT 1 61 62 #define USB_CHARGER_MODE 1 63 #define AC_CHARGER_MODE 2 64 #define CW_QUICKSTART 0 65 66 #define TIMER_MS_COUNTS 1000 67 #define DEFAULT_MONITOR_SEC 8 68 69 /* virtual params */ 70 #define VIRTUAL_CURRENT 1000 71 #define VIRTUAL_VOLTAGE 3888 72 #define VIRTUAL_SOC 66 73 #define VIRTUAL_PRESET 1 74 #define VIRTUAL_TEMPERATURE 188 75 #define VIRTUAL_TIME2EMPTY 60 76 #define VIRTUAL_STATUS POWER_SUPPLY_STATUS_CHARGING 77 78 enum bat_mode { 79 MODE_BATTARY = 0, 80 MODE_VIRTUAL, 81 }; 82 83 struct cw_bat_platform_data { 84 int divider_res1; 85 int divider_res2; 86 u32 *cw_bat_config_info; 87 int design_capacity; 88 }; 89 90 struct cw_battery { 91 struct i2c_client *client; 92 struct workqueue_struct *battery_workqueue; 93 struct delayed_work battery_delay_work; 94 struct cw_bat_platform_data plat_data; 95 96 struct power_supply *rk_bat; 97 98 struct power_supply *chrg_usb_psy; 99 struct power_supply *chrg_ac_psy; 100 101 #ifdef CONFIG_PM 102 struct timespec suspend_time_before; 103 struct timespec after; 104 int suspend_resume_mark; 105 #endif 106 int charger_mode; 107 int capacity; 108 int voltage; 109 int status; 110 int time_to_empty; 111 int alt; 112 u32 monitor_sec; 113 u32 bat_mode; 114 int bat_change; 115 bool dual_battery; 116 int charge_count; 117 }; 118 119 #endif 120