Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 
0003 #ifndef _AB8500_CHARGER_H_
0004 #define _AB8500_CHARGER_H_
0005 
0006 #include <linux/kernel.h>
0007 
0008 /*
0009  * System control 2 register offsets.
0010  * bank = 0x02
0011  */
0012 #define AB8500_MAIN_WDOG_CTRL_REG   0x01
0013 #define AB8500_LOW_BAT_REG      0x03
0014 #define AB8500_BATT_OK_REG      0x04
0015 /*
0016  * USB/ULPI register offsets
0017  * Bank : 0x5
0018  */
0019 #define AB8500_USB_LINE_STAT_REG    0x80
0020 #define AB8500_USB_LINE_CTRL2_REG   0x82
0021 #define AB8500_USB_LINK1_STAT_REG   0x94
0022 
0023 /*
0024  * Charger / status register offfsets
0025  * Bank : 0x0B
0026  */
0027 #define AB8500_CH_STATUS1_REG       0x00
0028 #define AB8500_CH_STATUS2_REG       0x01
0029 #define AB8500_CH_USBCH_STAT1_REG   0x02
0030 #define AB8500_CH_USBCH_STAT2_REG   0x03
0031 #define AB8540_CH_USBCH_STAT3_REG   0x04
0032 #define AB8500_CH_STAT_REG      0x05
0033 
0034 /*
0035  * Charger / control register offfsets
0036  * Bank : 0x0B
0037  */
0038 #define AB8500_CH_VOLT_LVL_REG      0x40
0039 #define AB8500_CH_VOLT_LVL_MAX_REG  0x41  /*Only in Cut2.0*/
0040 #define AB8500_CH_OPT_CRNTLVL_REG   0x42
0041 #define AB8500_CH_OPT_CRNTLVL_MAX_REG   0x43  /*Only in Cut2.0*/
0042 #define AB8500_CH_WD_TIMER_REG      0x50
0043 #define AB8500_CHARG_WD_CTRL        0x51
0044 #define AB8500_BTEMP_HIGH_TH        0x52
0045 #define AB8500_LED_INDICATOR_PWM_CTRL   0x53
0046 #define AB8500_LED_INDICATOR_PWM_DUTY   0x54
0047 #define AB8500_BATT_OVV         0x55
0048 #define AB8500_CHARGER_CTRL     0x56
0049 #define AB8500_BAT_CTRL_CURRENT_SOURCE  0x60  /*Only in Cut2.0*/
0050 
0051 /*
0052  * Charger / main control register offsets
0053  * Bank : 0x0B
0054  */
0055 #define AB8500_MCH_CTRL1        0x80
0056 #define AB8500_MCH_CTRL2        0x81
0057 #define AB8500_MCH_IPT_CURLVL_REG   0x82
0058 #define AB8500_CH_WD_REG        0x83
0059 
0060 /*
0061  * Charger / USB control register offsets
0062  * Bank : 0x0B
0063  */
0064 #define AB8500_USBCH_CTRL1_REG      0xC0
0065 #define AB8500_USBCH_CTRL2_REG      0xC1
0066 #define AB8500_USBCH_IPT_CRNTLVL_REG    0xC2
0067 #define AB8540_USB_PP_MODE_REG      0xC5
0068 #define AB8540_USB_PP_CHR_REG       0xC6
0069 
0070 /*
0071  * Gas Gauge register offsets
0072  * Bank : 0x0C
0073  */
0074 #define AB8500_GASG_CC_CTRL_REG     0x00
0075 #define AB8500_GASG_CC_ACCU1_REG    0x01
0076 #define AB8500_GASG_CC_ACCU2_REG    0x02
0077 #define AB8500_GASG_CC_ACCU3_REG    0x03
0078 #define AB8500_GASG_CC_ACCU4_REG    0x04
0079 #define AB8500_GASG_CC_SMPL_CNTRL_REG   0x05
0080 #define AB8500_GASG_CC_SMPL_CNTRH_REG   0x06
0081 #define AB8500_GASG_CC_SMPL_CNVL_REG    0x07
0082 #define AB8500_GASG_CC_SMPL_CNVH_REG    0x08
0083 #define AB8500_GASG_CC_CNTR_AVGOFF_REG  0x09
0084 #define AB8500_GASG_CC_OFFSET_REG   0x0A
0085 #define AB8500_GASG_CC_NCOV_ACCU    0x10
0086 #define AB8500_GASG_CC_NCOV_ACCU_CTRL   0x11
0087 #define AB8500_GASG_CC_NCOV_ACCU_LOW    0x12
0088 #define AB8500_GASG_CC_NCOV_ACCU_MED    0x13
0089 #define AB8500_GASG_CC_NCOV_ACCU_HIGH   0x14
0090 
0091 /*
0092  * Interrupt register offsets
0093  * Bank : 0x0E
0094  */
0095 #define AB8500_IT_SOURCE2_REG       0x01
0096 #define AB8500_IT_SOURCE21_REG      0x14
0097 
0098 /*
0099  * RTC register offsets
0100  * Bank: 0x0F
0101  */
0102 #define AB8500_RTC_BACKUP_CHG_REG   0x0C
0103 #define AB8500_RTC_CC_CONF_REG      0x01
0104 #define AB8500_RTC_CTRL_REG     0x0B
0105 #define AB8500_RTC_CTRL1_REG        0x11
0106 
0107 /*
0108  * OTP register offsets
0109  * Bank : 0x15
0110  */
0111 #define AB8500_OTP_CONF_15      0x0E
0112 
0113 /* GPADC constants from AB8500 spec, UM0836 */
0114 #define ADC_RESOLUTION          1024
0115 #define ADC_CH_MAIN_MIN         0
0116 #define ADC_CH_MAIN_MAX         20030
0117 #define ADC_CH_VBUS_MIN         0
0118 #define ADC_CH_VBUS_MAX         20030
0119 #define ADC_CH_VBAT_MIN         2300
0120 #define ADC_CH_VBAT_MAX         4800
0121 #define ADC_CH_BKBAT_MIN        0
0122 #define ADC_CH_BKBAT_MAX        3200
0123 
0124 /* Main charge i/p current */
0125 #define MAIN_CH_IP_CUR_0P9A     0x80
0126 #define MAIN_CH_IP_CUR_1P0A     0x90
0127 #define MAIN_CH_IP_CUR_1P1A     0xA0
0128 #define MAIN_CH_IP_CUR_1P2A     0xB0
0129 #define MAIN_CH_IP_CUR_1P3A     0xC0
0130 #define MAIN_CH_IP_CUR_1P4A     0xD0
0131 #define MAIN_CH_IP_CUR_1P5A     0xE0
0132 
0133 /* ChVoltLevel */
0134 #define CH_VOL_LVL_3P5          0x00
0135 #define CH_VOL_LVL_4P0          0x14
0136 #define CH_VOL_LVL_4P05         0x16
0137 #define CH_VOL_LVL_4P1          0x1B
0138 #define CH_VOL_LVL_4P15         0x20
0139 #define CH_VOL_LVL_4P2          0x25
0140 #define CH_VOL_LVL_4P6          0x4D
0141 
0142 /* ChOutputCurrentLevel */
0143 #define CH_OP_CUR_LVL_0P1       0x00
0144 #define CH_OP_CUR_LVL_0P2       0x01
0145 #define CH_OP_CUR_LVL_0P3       0x02
0146 #define CH_OP_CUR_LVL_0P4       0x03
0147 #define CH_OP_CUR_LVL_0P5       0x04
0148 #define CH_OP_CUR_LVL_0P6       0x05
0149 #define CH_OP_CUR_LVL_0P7       0x06
0150 #define CH_OP_CUR_LVL_0P8       0x07
0151 #define CH_OP_CUR_LVL_0P9       0x08
0152 #define CH_OP_CUR_LVL_1P4       0x0D
0153 #define CH_OP_CUR_LVL_1P5       0x0E
0154 #define CH_OP_CUR_LVL_1P6       0x0F
0155 #define CH_OP_CUR_LVL_2P        0x3F
0156 
0157 /* BTEMP High thermal limits */
0158 #define BTEMP_HIGH_TH_57_0      0x00
0159 #define BTEMP_HIGH_TH_52        0x01
0160 #define BTEMP_HIGH_TH_57_1      0x02
0161 #define BTEMP_HIGH_TH_62        0x03
0162 
0163 #define LOW_BAT_3P1V            0x20
0164 #define LOW_BAT_2P3V            0x00
0165 #define LOW_BAT_RESET           0x01
0166 #define LOW_BAT_ENABLE          0x01
0167 
0168 /* Backup battery constants */
0169 #define BUP_ICH_SEL_50UA        0x00
0170 #define BUP_ICH_SEL_150UA       0x04
0171 #define BUP_ICH_SEL_300UA       0x08
0172 #define BUP_ICH_SEL_700UA       0x0C
0173 
0174 enum bup_vch_sel {
0175     BUP_VCH_SEL_2P5V,
0176     BUP_VCH_SEL_2P6V,
0177     BUP_VCH_SEL_2P8V,
0178     BUP_VCH_SEL_3P1V,
0179     /*
0180      * Note that the following 5 values 2.7v, 2.9v, 3.0v, 3.2v, 3.3v
0181      * are only available on ab8540. You can't choose these 5
0182      * voltage on ab8500/ab8505/ab9540.
0183      */
0184     BUP_VCH_SEL_2P7V,
0185     BUP_VCH_SEL_2P9V,
0186     BUP_VCH_SEL_3P0V,
0187     BUP_VCH_SEL_3P2V,
0188     BUP_VCH_SEL_3P3V,
0189 };
0190 
0191 #define BUP_VCH_RANGE       0x02
0192 #define VBUP33_VRTCN        0x01
0193 
0194 /* Battery OVV constants */
0195 #define BATT_OVV_ENA            0x02
0196 #define BATT_OVV_TH_3P7         0x00
0197 #define BATT_OVV_TH_4P75        0x01
0198 
0199 /* A value to indicate over voltage (microvolts) */
0200 #define BATT_OVV_VALUE          4750000
0201 
0202 /* VBUS OVV constants */
0203 #define VBUS_OVV_SELECT_MASK        0x78
0204 #define VBUS_OVV_SELECT_5P6V        0x00
0205 #define VBUS_OVV_SELECT_5P7V        0x08
0206 #define VBUS_OVV_SELECT_5P8V        0x10
0207 #define VBUS_OVV_SELECT_5P9V        0x18
0208 #define VBUS_OVV_SELECT_6P0V        0x20
0209 #define VBUS_OVV_SELECT_6P1V        0x28
0210 #define VBUS_OVV_SELECT_6P2V        0x30
0211 #define VBUS_OVV_SELECT_6P3V        0x38
0212 
0213 #define VBUS_AUTO_IN_CURR_LIM_ENA   0x04
0214 
0215 /* Fuel Gauge constants */
0216 #define RESET_ACCU          0x02
0217 #define READ_REQ            0x01
0218 #define CC_DEEP_SLEEP_ENA       0x02
0219 #define CC_PWR_UP_ENA           0x01
0220 #define CC_SAMPLES_40           0x28
0221 #define RD_NCONV_ACCU_REQ       0x01
0222 #define CC_CALIB            0x08
0223 #define CC_INTAVGOFFSET_ENA     0x10
0224 #define CC_MUXOFFSET            0x80
0225 #define CC_INT_CAL_N_AVG_MASK       0x60
0226 #define CC_INT_CAL_SAMPLES_16       0x40
0227 #define CC_INT_CAL_SAMPLES_8        0x20
0228 #define CC_INT_CAL_SAMPLES_4        0x00
0229 
0230 /* RTC constants */
0231 #define RTC_BUP_CH_ENA          0x10
0232 
0233 /* BatCtrl Current Source Constants */
0234 #define BAT_CTRL_7U_ENA         0x01
0235 #define BAT_CTRL_20U_ENA        0x02
0236 #define BAT_CTRL_18U_ENA        0x01
0237 #define BAT_CTRL_16U_ENA        0x02
0238 #define BAT_CTRL_CMP_ENA        0x04
0239 #define FORCE_BAT_CTRL_CMP_HIGH     0x08
0240 #define BAT_CTRL_PULL_UP_ENA        0x10
0241 
0242 /* Battery type */
0243 #define BATTERY_UNKNOWN         00
0244 
0245 /* Registers for pcut feature in ab8505 and ab9540 */
0246 #define AB8505_RTC_PCUT_CTL_STATUS_REG  0x12
0247 #define AB8505_RTC_PCUT_TIME_REG    0x13
0248 #define AB8505_RTC_PCUT_MAX_TIME_REG    0x14
0249 #define AB8505_RTC_PCUT_FLAG_TIME_REG   0x15
0250 #define AB8505_RTC_PCUT_RESTART_REG 0x16
0251 #define AB8505_RTC_PCUT_DEBOUNCE_REG    0x17
0252 
0253 /* USB Power Path constants for ab8540 */
0254 #define BUS_VSYS_VOL_SELECT_MASK        0x06
0255 #define BUS_VSYS_VOL_SELECT_3P6V        0x00
0256 #define BUS_VSYS_VOL_SELECT_3P325V      0x02
0257 #define BUS_VSYS_VOL_SELECT_3P9V        0x04
0258 #define BUS_VSYS_VOL_SELECT_4P3V        0x06
0259 #define BUS_POWER_PATH_MODE_ENA         0x01
0260 #define BUS_PP_PRECHG_CURRENT_MASK      0x0E
0261 #define BUS_POWER_PATH_PRECHG_ENA       0x01
0262 
0263 /* Forward declaration */
0264 struct ab8500_fg;
0265 
0266 /**
0267  * struct ab8500_fg_parameters - Fuel gauge algorithm parameters, in seconds
0268  * if not specified
0269  * @recovery_sleep_timer:   Time between measurements while recovering
0270  * @recovery_total_time:    Total recovery time
0271  * @init_timer:         Measurement interval during startup
0272  * @init_discard_time:      Time we discard voltage measurement at startup
0273  * @init_total_time:        Total init time during startup
0274  * @high_curr_time:     Time current has to be high to go to recovery
0275  * @accu_charging:      FG accumulation time while charging
0276  * @accu_high_curr_ua:      FG accumulation time in high current mode
0277  * @high_curr_threshold_ua: High current threshold, in uA
0278  * @lowbat_threshold_uv:    Low battery threshold, in uV
0279  * @battok_falling_th_sel0  Threshold in mV for battOk signal sel0
0280  *              Resolution in 50 mV step.
0281  * @battok_raising_th_sel1  Threshold in mV for battOk signal sel1
0282  *              Resolution in 50 mV step.
0283  * @user_cap_limit      Capacity reported from user must be within this
0284  *              limit to be considered as sane, in percentage
0285  *              points.
0286  * @maint_thres         This is the threshold where we stop reporting
0287  *              battery full while in maintenance, in per cent
0288  * @pcut_enable:            Enable power cut feature in ab8505
0289  * @pcut_max_time:      Max time threshold
0290  * @pcut_flag_time:     Flagtime threshold
0291  * @pcut_max_restart:       Max number of restarts
0292  * @pcut_debounce_time:     Sets battery debounce time
0293  */
0294 struct ab8500_fg_parameters {
0295     int recovery_sleep_timer;
0296     int recovery_total_time;
0297     int init_timer;
0298     int init_discard_time;
0299     int init_total_time;
0300     int high_curr_time;
0301     int accu_charging;
0302     int accu_high_curr;
0303     int high_curr_threshold_ua;
0304     int lowbat_threshold_uv;
0305     int battok_falling_th_sel0;
0306     int battok_raising_th_sel1;
0307     int user_cap_limit;
0308     int maint_thres;
0309     bool pcut_enable;
0310     u8 pcut_max_time;
0311     u8 pcut_flag_time;
0312     u8 pcut_max_restart;
0313     u8 pcut_debounce_time;
0314 };
0315 
0316 /**
0317  * struct ab8500_charger_maximization - struct used by the board config.
0318  * @use_maxi:       Enable maximization for this battery type
0319  * @maxi_chg_curr_ua:   Maximum charger current allowed in microampere
0320  * @maxi_wait_cycles:   cycles to wait before setting charger current
0321  * @charger_curr_step_ua: delta between two charger current settings (uA)
0322  */
0323 struct ab8500_maxim_parameters {
0324     bool ena_maxi;
0325     int chg_curr_ua;
0326     int wait_cycles;
0327     int charger_curr_step_ua;
0328 };
0329 
0330 /**
0331  * struct ab8500_bm_capacity_levels - ab8500 capacity level data
0332  * @critical:       critical capacity level in percent
0333  * @low:        low capacity level in percent
0334  * @normal:     normal capacity level in percent
0335  * @high:       high capacity level in percent
0336  * @full:       full capacity level in percent
0337  */
0338 struct ab8500_bm_capacity_levels {
0339     int critical;
0340     int low;
0341     int normal;
0342     int high;
0343     int full;
0344 };
0345 
0346 /**
0347  * struct ab8500_bm_charger_parameters - Charger specific parameters
0348  * @usb_volt_max_uv:    maximum allowed USB charger voltage in uV
0349  * @usb_curr_max_ua:    maximum allowed USB charger current in uA
0350  * @ac_volt_max_uv: maximum allowed AC charger voltage in uV
0351  * @ac_curr_max_ua: maximum allowed AC charger current in uA
0352  */
0353 struct ab8500_bm_charger_parameters {
0354     int usb_volt_max_uv;
0355     int usb_curr_max_ua;
0356     int ac_volt_max_uv;
0357     int ac_curr_max_ua;
0358 };
0359 
0360 /**
0361  * struct ab8500_bm_data - ab8500 battery management data
0362  * @bi          battery info from device tree
0363  * @temp_now        present battery temperature
0364  * @temp_interval_chg   temperature measurement interval in s when charging
0365  * @temp_interval_nochg temperature measurement interval in s when not charging
0366  * @main_safety_tmr_h   safety timer for main charger
0367  * @usb_safety_tmr_h    safety timer for usb charger
0368  * @bkup_bat_v      voltage which we charge the backup battery with
0369  * @bkup_bat_i      current which we charge the backup battery with
0370  * @capacity_scaling    indicates whether capacity scaling is to be used
0371  * @chg_unknown_bat flag to enable charging of unknown batteries
0372  * @enable_overshoot    flag to enable VBAT overshoot control
0373  * @auto_trig       flag to enable auto adc trigger
0374  * @fg_res      resistance of FG resistor in 0.1mOhm
0375  * @interval_charging   charge alg cycle period time when charging (sec)
0376  * @interval_not_charging charge alg cycle period time when not charging (sec)
0377  * @temp_hysteresis temperature hysteresis
0378  * @maxi        maximization parameters
0379  * @cap_levels      capacity in percent for the different capacity levels
0380  * @chg_params      charger parameters
0381  * @fg_params       fuel gauge parameters
0382  */
0383 struct ab8500_bm_data {
0384     struct power_supply_battery_info *bi;
0385     int temp_now;
0386     int temp_interval_chg;
0387     int temp_interval_nochg;
0388     int main_safety_tmr_h;
0389     int usb_safety_tmr_h;
0390     int bkup_bat_v;
0391     int bkup_bat_i;
0392     bool capacity_scaling;
0393     bool chg_unknown_bat;
0394     bool enable_overshoot;
0395     bool auto_trig;
0396     int fg_res;
0397     int interval_charging;
0398     int interval_not_charging;
0399     int temp_hysteresis;
0400     const struct ab8500_maxim_parameters *maxi;
0401     const struct ab8500_bm_capacity_levels *cap_levels;
0402     const struct ab8500_bm_charger_parameters *chg_params;
0403     const struct ab8500_fg_parameters *fg_params;
0404 };
0405 
0406 /* Forward declaration */
0407 struct ab8500_fg;
0408 
0409 extern struct ab8500_bm_data ab8500_bm_data;
0410 
0411 void ab8500_charger_usb_state_changed(u8 bm_usb_state, u16 mA);
0412 struct ab8500_fg *ab8500_fg_get(void);
0413 int ab8500_fg_inst_curr_blocking(struct ab8500_fg *dev);
0414 int ab8500_fg_inst_curr_start(struct ab8500_fg *di);
0415 int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res);
0416 int ab8500_fg_inst_curr_started(struct ab8500_fg *di);
0417 int ab8500_fg_inst_curr_done(struct ab8500_fg *di);
0418 int ab8500_bm_of_probe(struct power_supply *psy,
0419                struct ab8500_bm_data *bm);
0420 void ab8500_bm_of_remove(struct power_supply *psy,
0421              struct ab8500_bm_data *bm);
0422 
0423 extern struct platform_driver ab8500_fg_driver;
0424 extern struct platform_driver ab8500_btemp_driver;
0425 extern struct platform_driver ab8500_chargalg_driver;
0426 
0427 #endif /* _AB8500_CHARGER_H_ */