diff options
author | Vijay Hiremath <vijay.p.hiremath@intel.com> | 2016-09-20 12:52:10 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-09-21 19:38:13 -0700 |
commit | 420b4230968c16c6fb856874a6fd78730c8fd397 (patch) | |
tree | 837e00761540e2fa668e82d455db35708ac5b7cc /driver | |
parent | d94fd4faf554eb5cd48d50bc8ce307e03bc87904 (diff) | |
download | chrome-ec-420b4230968c16c6fb856874a6fd78730c8fd397.tar.gz |
BD9995X: Rename common code of BD99955 and BD99956 as BD9995X
Except the CHIP_ID and charger name code is common between BD99955
and BD99956. Hence renamed the code to BD9995X so that valid
output is printed from console commands.
BUG=chrome-os-partner:57519
BRANCH=none
TEST=Manually tested on Reef. 'charger' console command prints
charger name as 'bd99956'
Change-Id: I3c995757941bcc5a6a8026dd807d76a7a47c9911
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/387119
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/build.mk | 3 | ||||
-rw-r--r-- | driver/charger/bd99955.h | 354 | ||||
-rw-r--r-- | driver/charger/bd9995x.c (renamed from driver/charger/bd99955.c) | 664 | ||||
-rw-r--r-- | driver/charger/bd9995x.h | 362 |
4 files changed, 696 insertions, 687 deletions
diff --git a/driver/build.mk b/driver/build.mk index 09d2552b19..281afc92d0 100644 --- a/driver/build.mk +++ b/driver/build.mk @@ -33,7 +33,8 @@ driver-$(CONFIG_BATTERY_BQ27621)+=battery/bq27621_g1.o driver-$(CONFIG_BATTERY_SMART)+=battery/smart.o # Battery charger ICs -driver-$(CONFIG_CHARGER_BD99955)+=charger/bd99955.o +driver-$(CONFIG_CHARGER_BD99955)+=charger/bd9995x.o +driver-$(CONFIG_CHARGER_BD99956)+=charger/bd9995x.o driver-$(CONFIG_CHARGER_BQ24192)+=charger/bq24192.o driver-$(CONFIG_CHARGER_BQ24707A)+=charger/bq24707a.o driver-$(CONFIG_CHARGER_BQ24715)+=charger/bq24715.o diff --git a/driver/charger/bd99955.h b/driver/charger/bd99955.h deleted file mode 100644 index 2c38d5878f..0000000000 --- a/driver/charger/bd99955.h +++ /dev/null @@ -1,354 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * ROHM BD99955 battery charger driver. - */ - -#ifndef __CROS_EC_BD99955_H -#define __CROS_EC_BD99955_H - -#define BD99955_ADDR 0x12 /* 7bit address 0001_001 */ -#define I2C_ADDR_CHARGER BD99955_ADDR - -/* BD99955 commands to change the command code map */ -enum bd99955_command { - BD99955_BAT_CHG_COMMAND, - BD99955_EXTENDED_COMMAND, - BD99955_DEBUG_COMMAND, - BD99955_INVALID_COMMAND -}; - -enum bd99955_charge_port { - BD99955_CHARGE_PORT_VBUS, - BD99955_CHARGE_PORT_VCC, - BD99955_CHARGE_PORT_BOTH, - BD99955_CHARGE_PORT_NONE, -}; - -/* Charger parameters */ -#define CHARGER_NAME "bd99955" -#define CHARGE_V_MAX 19200 -#define CHARGE_V_MIN 3072 -#define CHARGE_V_STEP 16 -#define CHARGE_I_MAX 16320 -#define CHARGE_I_MIN 128 -#define CHARGE_I_OFF 0 -#define CHARGE_I_STEP 64 -#define INPUT_I_MAX 16352 -#define INPUT_I_MIN 512 -#define INPUT_I_STEP 32 - -/* Min. charge current w/ no battery to prevent collapse */ -#define BD99955_NO_BATTERY_CHARGE_I_MIN 512 - -/* VSYSREG settings */ -#define BD99955_DISCHARGE_VSYSREG 8960 -#define BD99955_CHARGE_VSYSREG 6144 - -/* - * BC1.2 minimum voltage threshold. - * BC1.2 charging port output voltage range is 4.75V to 5.25V, - * BD99955 Anti-Collapse Threshold Voltage Accuracy is -100mV to +100mV, - * and Delta of 50mV. - */ -#define BD99955_BC12_MIN_VOLTAGE 4600 - -/* Battery Charger Commands */ -#define BD99955_CMD_CHG_CURRENT 0x14 -#define BD99955_CMD_CHG_VOLTAGE 0x15 -#define BD99955_CMD_IBUS_LIM_SET 0x3C -#define BD99955_CMD_ICC_LIM_SET 0x3D -#define BD99955_CMD_PROTECT_SET 0x3E -#define BD99955_CMD_MAP_SET 0x3F - -/* Extended commands */ -#define BD99955_CMD_CHGSTM_STATUS 0x00 -#define BD99955_CMD_VBAT_VSYS_STATUS 0x01 -#define BD99955_CMD_VBUS_VCC_STATUS 0x02 -#define BD99955_CMD_VBUS_VCC_STATUS_VCC_DETECT (1 << 8) -#define BD99955_CMD_VBUS_VCC_STATUS_VBUS_DETECT (1 << 0) - -#define BD99955_CMD_CHGOP_STATUS 0x03 -#define BD99955_CMD_CHGOP_STATUS_BATTEMP2 (1 << 10) -#define BD99955_CMD_CHGOP_STATUS_BATTEMP1 (1 << 9) -#define BD99955_CMD_CHGOP_STATUS_BATTEMP0 (1 << 8) -#define BD99955_BATTTEMP_MASK 0x700 -#define BD99955_CMD_CHGOP_STATUS_BATTEMP_ROOMTEMP 0 -#define BD99955_CMD_CHGOP_STATUS_BATTEMP_HOT1 1 -#define BD99955_CMD_CHGOP_STATUS_BATTEMP_HOT2 2 -#define BD99955_CMD_CHGOP_STATUS_BATTEMP_HOT3 3 -#define BD99955_CMD_CHGOP_STATUS_BATTEMP_COLD1 4 -#define BD99955_CMD_CHGOP_STATUS_BATTEMP_COLD2 5 -#define BD99955_CMD_CHGOP_STATUS_BATTEMP_DISABLE 6 -#define BD99955_CMD_CHGOP_STATUS_BATTEMP_BATOPEN 7 -#define BD99955_CMD_CHGOP_STATUS_RBOOST_UV (1 << 1) - -#define BD99955_CMD_WDT_STATUS 0x04 -#define BD99955_CMD_CUR_ILIM_VAL 0x05 -#define BD99955_CMD_SEL_ILIM_VAL 0x06 -#define BD99955_CMD_EXT_IBUS_LIM_SET 0x07 -#define BD99955_CMD_EXT_ICC_LIM_SET 0x08 -#define BD99955_CMD_IOTG_LIM_SET 0x09 -#define BD99955_CMD_VIN_CTRL_SET 0x0A -#define BD99955_CMD_VIN_CTRL_SET_PP_BOTH_THRU (1 << 11) -#define BD99955_CMD_VIN_CTRL_SET_VBUS_PRIORITY (1 << 7) -#define BD99955_CMD_VIN_CTRL_SET_VBUS_EN (1 << 6) -#define BD99955_CMD_VIN_CTRL_SET_VCC_EN (1 << 5) - -#define BD99955_CMD_CHGOP_SET1 0x0B -#define BD99955_CMD_CHGOP_SET1_ILIM_AUTO_DISEN (1 << 13) -#define BD99955_CMD_CHGOP_SET1_VCC_BC_DISEN (1 << 11) -#define BD99955_CMD_CHGOP_SET1_VBUS_BC_DISEN (1 << 10) -#define BD99955_CMD_CHGOP_SET1_SDP_CHG_TRIG_EN (1 << 9) -#define BD99955_CMD_CHGOP_SET1_SDP_CHG_TRIG (1 << 8) - -#define BD99955_CMD_CHGOP_SET2 0x0C -#define BD99955_CMD_CHGOP_SET2_BATT_LEARN (1 << 8) -#define BD99955_CMD_CHGOP_SET2_CHG_EN (1 << 7) -#define BD99955_CMD_CHGOP_SET2_USB_SUS (1 << 6) -#define BD99955_CMD_CHGOP_SET2_DCDC_CLK_SEL (3 << 2) -#define BD99955_CMD_CHGOP_SET2_DCDC_CLK_SEL_600 (0 << 2) -#define BD99955_CMD_CHGOP_SET2_DCDC_CLK_SEL_857 (1 << 2) -#define BD99955_CMD_CHGOP_SET2_DCDC_CLK_SEL_1000 (2 << 2) -#define BD99955_CMD_CHGOP_SET2_DCDC_CLK_SEL_1200 (3 << 2) - -#define BD99955_CMD_VBUSCLPS_TH_SET 0x0D -#define BD99955_CMD_VCCCLPS_TH_SET 0x0E -#define BD99955_CMD_CHGWDT_SET 0x0F -#define BD99955_CMD_BATTWDT_SET 0x10 -#define BD99955_CMD_VSYSREG_SET 0x11 -#define BD99955_CMD_VSYSVAL_THH_SET 0x12 -#define BD99955_CMD_VSYSVAL_THL_SET 0x13 -#define BD99955_CMD_ITRICH_SET 0x14 - -#define BD99955_CMD_IPRECH_SET 0x15 -#define BD99955_IPRECH_MAX 1024 - -#define BD99955_CMD_ICHG_SET 0x16 -#define BD99955_CMD_ITERM_SET 0x17 -#define BD99955_CMD_VPRECHG_TH_SET 0x18 -#define BD99955_CMD_VRBOOST_SET 0x19 -#define BD99955_CMD_VFASTCHG_REG_SET1 0x1A -#define BD99955_CMD_VFASTCHG_REG_SET2 0x1B -#define BD99955_CMD_VFASTCHG_REG_SET3 0x1C -#define BD99955_CMD_VRECHG_SET 0x1D -#define BD99955_CMD_VBATOVP_SET 0x1E -#define BD99955_CMD_IBATSHORT_SET 0x1F -#define BD99955_CMD_PROCHOT_CTRL_SET 0x20 -#define BD99955_CMD_PROCHOT_CTRL_SET_PROCHOT_EN4 (1 << 4) -#define BD99955_CMD_PROCHOT_CTRL_SET_PROCHOT_EN3 (1 << 3) -#define BD99955_CMD_PROCHOT_CTRL_SET_PROCHOT_EN2 (1 << 2) -#define BD99955_CMD_PROCHOT_CTRL_SET_PROCHOT_EN1 (1 << 1) -#define BD99955_CMD_PROCHOT_CTRL_SET_PROCHOT_EN0 (1 << 0) - -#define BD99955_CMD_PROCHOT_ICRIT_SET 0x21 -#define BD99955_CMD_PROCHOT_INORM_SET 0x22 -#define BD99955_CMD_PROCHOT_IDCHG_SET 0x23 -#define BD99955_CMD_PROCHOT_VSYS_SET 0x24 -#define BD99955_CMD_PMON_IOUT_CTRL_SET 0x25 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_IMON_INSEL (1 << 9) -#define BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_INSEL (1 << 8) -#define BD99955_CMD_PMON_IOUT_CTRL_SET_IOUT_OUT_EN (1 << 7) -#define BD99955_CMD_PMON_IOUT_CTRL_SET_IOUT_SOURCE_SEL (1 << 6) -#define BD99955_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_MASK 0x30 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_40V 0x03 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_20V 0x02 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_10V 0x01 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_05V 0x00 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_OUT_EN (1 << 3) -#define BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_MASK 0x07 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_64UAW 0x06 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_32UAW 0x05 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_16UAW 0x04 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_08UAW 0x03 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_04UAW 0x02 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_02UAW 0x01 -#define BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_01UAW 0x00 -#define BD99955_PMON_IOUT_ADC_READ_COUNT 100 - -#define BD99955_CMD_PMON_DACIN_VAL 0x26 -#define BD99955_CMD_IOUT_DACIN_VAL 0x27 -#define BD99955_CMD_VCC_UCD_SET 0x28 -/* Bits for both VCC_UCD_SET and VBUS_UCD_SET regs */ -#define BD99955_CMD_UCD_SET_BCSRETRY (1 << 12) -#define BD99955_CMD_UCD_SET_USBDETEN (1 << 7) -#define BD99955_CMD_UCD_SET_USB_SW_EN (1 << 1) - -#define BD99955_CMD_VCC_UCD_STATUS 0x29 -/* Bits for both VCC_UCD_STATUS and VBUS_UCD_STATUS regs */ -#define BD99955_CMD_UCD_STATUS_DCDFAIL (1 << 15) -#define BD99955_CMD_UCD_STATUS_CHGPORT1 (1 << 13) -#define BD99955_CMD_UCD_STATUS_CHGPORT0 (1 << 12) -#define BD99955_CMD_UCD_STATUS_PUPDET (1 << 11) -#define BD99955_CMD_UCD_STATUS_CHGDET (1 << 6) -#define BD99955_TYPE_MASK (BD99955_CMD_UCD_STATUS_DCDFAIL | \ - BD99955_CMD_UCD_STATUS_CHGPORT1 | \ - BD99955_CMD_UCD_STATUS_CHGPORT0 | \ - BD99955_CMD_UCD_STATUS_PUPDET | \ - BD99955_CMD_UCD_STATUS_CHGDET) - -/* BC1.2 chargers */ -#define BD99955_TYPE_CDP (BD99955_CMD_UCD_STATUS_CHGPORT1 | \ - BD99955_CMD_UCD_STATUS_CHGDET) -#define BD99955_TYPE_DCP (BD99955_CMD_UCD_STATUS_CHGPORT1 | \ - BD99955_CMD_UCD_STATUS_CHGPORT0 | \ - BD99955_CMD_UCD_STATUS_CHGDET) -#define BD99955_TYPE_SDP (BD99955_CMD_UCD_STATUS_CHGPORT0) -/* non-standard BC1.2 chargers */ -#define BD99955_TYPE_OTHER (BD99955_CMD_UCD_STATUS_DCDFAIL | \ - BD99955_CMD_UCD_STATUS_CHGPORT1 | \ - BD99955_CMD_UCD_STATUS_CHGPORT0 | \ - BD99955_CMD_UCD_STATUS_CHGDET) -#define BD99955_TYPE_PUP_PORT (BD99955_CMD_UCD_STATUS_DCDFAIL | \ - BD99955_CMD_UCD_STATUS_CHGPORT0 | \ - BD99955_CMD_UCD_STATUS_PUPDET) -/* Open ports */ -#define BD99955_TYPE_OPEN_PORT (BD99955_CMD_UCD_STATUS_DCDFAIL | \ - BD99955_CMD_UCD_STATUS_CHGPORT0) -#define BD99955_TYPE_VBUS_OPEN 0 - -#define BD99955_CMD_VCC_IDD_STATUS 0x2A -#define BD99955_CMD_VCC_UCD_FCTRL_SET 0x2B -#define BD99955_CMD_VCC_UCD_FCTRL_EN 0x2C -#define BD99955_CMD_VBUS_UCD_SET 0x30 -#define BD99955_CMD_VBUS_UCD_STATUS 0x31 -#define BD99955_CMD_VBUS_IDD_STATUS 0x32 -#define BD99955_CMD_VBUS_UCD_FCTRL_SET 0x33 -#define BD99955_CMD_VBUS_UCD_FCTRL_EN 0x34 -#define BD99955_CMD_CHIP_ID 0x38 -#define BD99955_CMD_CHIP_REV 0x39 -#define BD99955_CMD_IC_SET1 0x3A -#define BD99955_CMD_IC_SET2 0x3B -#define BD99955_CMD_SYSTEM_STATUS 0x3C -#define BD99955_CMD_SYSTEM_STATUS_OTPLD_STATE (1 << 1) -#define BD99955_CMD_SYSTEM_STATUS_ALLRST_STATE (1 << 0) - -#define BD99955_CMD_SYSTEM_CTRL_SET 0x3D -#define BD99955_CMD_SYSTEM_CTRL_SET_OTPLD (1 << 1) -#define BD99955_CMD_SYSTEM_CTRL_SET_ALLRST (1 << 0) - -#define BD99955_CMD_EXT_PROTECT_SET 0x3E -#define BD99955_CMD_EXT_MAP_SET 0x3F -#define BD99955_CMD_VM_CTRL_SET 0x40 -#define BD99955_CMD_VM_CTRL_SET_EXTIADPEN (1 << 9) -#define BD99955_CMD_THERM_WINDOW_SET1 0x41 -#define BD99955_CMD_THERM_WINDOW_SET2 0x42 -#define BD99955_CMD_THERM_WINDOW_SET3 0x43 -#define BD99955_CMD_THERM_WINDOW_SET4 0x44 -#define BD99955_CMD_THERM_WINDOW_SET5 0x45 -#define BD99955_CMD_IBATP_TH_SET 0x46 -#define BD99955_CMD_IBATM_TH_SET 0x47 -#define BD99955_CMD_VBAT_TH_SET 0x48 -#define BD99955_CMD_THERM_TH_SET 0x49 -#define BD99955_CMD_IACP_TH_SET 0x4A -#define BD99955_CMD_VACP_TH_SET 0x4B - -/* Enable discharge when VBUS falls below BD99955_VBUS_DISCHARGE_TH */ -#define BD99955_VBUS_DISCHARGE_TH 3900 -#define BD99955_CMD_VBUS_TH_SET 0x4C -#define BD99955_CMD_VCC_TH_SET 0x4D - -#define BD99955_CMD_VSYS_TH_SET 0x4E -#define BD99955_CMD_EXTIADP_TH_SET 0x4F -#define BD99955_CMD_IBATP_VAL 0x50 -#define BD99955_CMD_IBATP_AVE_VAL 0x51 -#define BD99955_CMD_IBATM_VAL 0x52 -#define BD99955_CMD_IBATM_AVE_VAL 0x53 -#define BD99955_CMD_VBAT_VAL 0x54 -#define BD99955_CMD_VBAT_AVE_VAL 0x55 -#define BD99955_CMD_THERM_VAL 0x56 -#define BD99955_CMD_VTH_VAL 0x57 -#define BD99955_CMD_IACP_VAL 0x58 -#define BD99955_CMD_IACP_AVE_VAL 0x59 -#define BD99955_CMD_VACP_VAL 0x5A -#define BD99955_CMD_VACP_AVE_VAL 0x5B -#define BD99955_CMD_VBUS_VAL 0x5C -#define BD99955_CMD_VBUS_AVE_VAL 0x5D -#define BD99955_CMD_VCC_VAL 0x5E -#define BD99955_CMD_VCC_AVE_VAL 0x5F -#define BD99955_CMD_VSYS_VAL 0x60 -#define BD99955_CMD_VSYS_AVE_VAL 0x61 -#define BD99955_CMD_EXTIADP_VAL 0x62 -#define BD99955_CMD_EXTIADP_AVE_VAL 0x63 -#define BD99955_CMD_VACPCLPS_TH_SET 0x64 -#define BD99955_CMD_INT0_SET 0x68 -#define BD99955_CMD_INT0_SET_INT2_EN (1 << 2) -#define BD99955_CMD_INT0_SET_INT1_EN (1 << 1) -#define BD99955_CMD_INT0_SET_INT0_EN (1 << 0) - -#define BD99955_CMD_INT1_SET 0x69 -/* Bits for both INT1 & INT2 reg */ -#define BD99955_CMD_INT_SET_TH_DET (1 << 9) -#define BD99955_CMD_INT_SET_TH_RES (1 << 8) -#define BD99955_CMD_INT_SET_DET (1 << 1) -#define BD99955_CMD_INT_SET_RES (1 << 0) -#define BD99955_CMD_INT_VBUS_DET (BD99955_CMD_INT_SET_RES | \ - BD99955_CMD_INT_SET_DET) -#define BD99955_CMD_INT_VBUS_TH (BD99955_CMD_INT_SET_TH_RES | \ - BD99955_CMD_INT_SET_TH_DET) - -#define BD99955_CMD_INT2_SET 0x6A -#define BD99955_CMD_INT3_SET 0x6B -#define BD99955_CMD_INT4_SET 0x6C -#define BD99955_CMD_INT5_SET 0x6D -#define BD99955_CMD_INT6_SET 0x6E -#define BD99955_CMD_INT7_SET 0x6F -#define BD99955_CMD_INT0_STATUS 0x70 -#define BD99955_CMD_INT1_STATUS 0x71 -/* Bits for both INT1_STATUS & INT2_STATUS reg */ -#define BD99955_CMD_INT_STATUS_DET (1 << 1) -#define BD99955_CMD_INT_STATUS_RES (1 << 0) - -#define BD99955_CMD_INT2_STATUS 0x72 -#define BD99955_CMD_INT3_STATUS 0x73 -#define BD99955_CMD_INT4_STATUS 0x74 -#define BD99955_CMD_INT5_STATUS 0x75 -#define BD99955_CMD_INT6_STATUS 0x76 -#define BD99955_CMD_INT7_STATUS 0x77 -#define BD99955_CMD_REG0 0x78 -#define BD99955_CMD_REG1 0x79 -#define BD99955_CMD_OTPREG0 0x7A -#define BD99955_CMD_OTPREG1 0x7B -#define BD99955_CMD_SMBREG 0x7C -/* Normal functionality - power save mode disabled. */ -#define BD99955_PWR_SAVE_OFF 0 -/* BGATE ON w/ PROCHOT# monitored only system voltage. */ -#define BD99955_PWR_SAVE_LOW 0x1 -/* BGATE ON w/ PROCHOT# monitored only system voltage every 1ms. */ -#define BD99955_PWR_SAVE_MED 0x2 -/* BGATE ON w/o PROCHOT# monitoring. */ -#define BD99955_PWR_SAVE_HIGH 0x5 -/* BGATE OFF */ -#define BD99955_PWR_SAVE_MAX 0x6 -#define BD99955_CMD_DEBUG_MODE_SET 0x7F - -/* Map PD port number to charge port number */ -static inline enum bd99955_charge_port bd99955_pd_port_to_chg_port(int port) -{ -#ifdef CONFIG_BD99955_PRIMARY_CHARGE_PORT_VCC - return port ? BD99955_CHARGE_PORT_VBUS : BD99955_CHARGE_PORT_VCC; -#else - return port ? BD99955_CHARGE_PORT_VCC : BD99955_CHARGE_PORT_VBUS; -#endif -} - -/* - * Non-standard interface functions - bd99955 integrates additional - * functionality not part of the standard charger interface. - */ - -/* Is VBUS provided or external power present */ -int bd99955_is_vbus_provided(int port); -/* Select input port from {VCC, VBUS, VCC&VBUS, NONE}. */ -int bd99955_select_input_port(enum bd99955_charge_port port); -/* Get input current limit for BC1.2 suppliers */ -int bd99955_get_bc12_ilim(int charge_supplier); -/* Enable/Disable charging triggered by BC1.2 */ -int bd99955_bc12_enable_charging(enum bd99955_charge_port port, int enable); -/* Interrupt handler for USB charger VBUS */ -void bd99955_vbus_interrupt(enum gpio_signal signal); -/* Read temperature measurement value (in Celsius) */ -int bd99955_get_battery_temp(int *temp_ptr); - -#endif /* __CROS_EC_BD99955_H */ diff --git a/driver/charger/bd99955.c b/driver/charger/bd9995x.c index 110e03103a..cbc8d04132 100644 --- a/driver/charger/bd99955.c +++ b/driver/charger/bd9995x.c @@ -2,12 +2,12 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * - * ROHM BD99955 battery charger driver. + * ROHM BD9995X battery charger driver. */ #include "battery.h" #include "battery_smart.h" -#include "bd99955.h" +#include "bd9995x.h" #include "charge_manager.h" #include "charger.h" #include "console.h" @@ -22,7 +22,7 @@ #define OTPROM_LOAD_WAIT_RETRY 3 -#define BD99955_CHARGE_PORT_COUNT 2 +#define BD9995X_CHARGE_PORT_COUNT 2 /* Console output macros */ #define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args) @@ -31,7 +31,7 @@ #define BC12_DETECT_RETRY 10 /* Charger parameters */ -static const struct charger_info bd99955_charger_info = { +static const struct charger_info bd9995x_charger_info = { .name = CHARGER_NAME, .voltage_max = CHARGE_V_MAX, .voltage_min = CHARGE_V_MIN, @@ -45,108 +45,108 @@ static const struct charger_info bd99955_charger_info = { }; /* Charge command code map */ -static enum bd99955_command charger_map_cmd = BD99955_INVALID_COMMAND; +static enum bd9995x_command charger_map_cmd = BD9995X_INVALID_COMMAND; -static struct mutex bd99955_map_mutex; +static struct mutex bd9995x_map_mutex; #ifdef HAS_TASK_USB_CHG /* USB switch */ -static enum usb_switch usb_switch_state[BD99955_CHARGE_PORT_COUNT] = { +static enum usb_switch usb_switch_state[BD9995X_CHARGE_PORT_COUNT] = { USB_SWITCH_DISCONNECT, USB_SWITCH_DISCONNECT, }; #endif static inline int ch_raw_read16(int cmd, int *param, - enum bd99955_command map_cmd) + enum bd9995x_command map_cmd) { int rv; /* Map the Charge command code to appropriate region */ - mutex_lock(&bd99955_map_mutex); + mutex_lock(&bd9995x_map_mutex); if (charger_map_cmd != map_cmd) { rv = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, - BD99955_CMD_MAP_SET, map_cmd); + BD9995X_CMD_MAP_SET, map_cmd); if (rv) - goto bd99955_read_cleanup; + goto bd9995x_read_cleanup; charger_map_cmd = map_cmd; } rv = i2c_read16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, cmd, param); -bd99955_read_cleanup: - mutex_unlock(&bd99955_map_mutex); +bd9995x_read_cleanup: + mutex_unlock(&bd9995x_map_mutex); return rv; } static inline int ch_raw_write16(int cmd, int param, - enum bd99955_command map_cmd) + enum bd9995x_command map_cmd) { int rv; /* Map the Charge command code to appropriate region */ - mutex_lock(&bd99955_map_mutex); + mutex_lock(&bd9995x_map_mutex); if (charger_map_cmd != map_cmd) { rv = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, - BD99955_CMD_MAP_SET, map_cmd); + BD9995X_CMD_MAP_SET, map_cmd); if (rv) - goto bd99955_write_cleanup; + goto bd9995x_write_cleanup; charger_map_cmd = map_cmd; } rv = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, cmd, param); -bd99955_write_cleanup: - mutex_unlock(&bd99955_map_mutex); +bd9995x_write_cleanup: + mutex_unlock(&bd9995x_map_mutex); return rv; } -/* BD99955 local interfaces */ +/* BD9995X local interfaces */ -static int bd99955_charger_enable(int enable) +static int bd9995x_charger_enable(int enable) { int rv; int reg; - rv = ch_raw_read16(BD99955_CMD_CHGOP_SET2, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_CHGOP_SET2, ®, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; if (enable) - reg |= BD99955_CMD_CHGOP_SET2_CHG_EN; + reg |= BD9995X_CMD_CHGOP_SET2_CHG_EN; else - reg &= ~BD99955_CMD_CHGOP_SET2_CHG_EN; + reg &= ~BD9995X_CMD_CHGOP_SET2_CHG_EN; - return ch_raw_write16(BD99955_CMD_CHGOP_SET2, reg, - BD99955_EXTENDED_COMMAND); + return ch_raw_write16(BD9995X_CMD_CHGOP_SET2, reg, + BD9995X_EXTENDED_COMMAND); } -static int bd99955_por_reset(void) +static int bd9995x_por_reset(void) { int rv; int reg; int i; - rv = ch_raw_write16(BD99955_CMD_SYSTEM_CTRL_SET, - BD99955_CMD_SYSTEM_CTRL_SET_OTPLD | - BD99955_CMD_SYSTEM_CTRL_SET_ALLRST, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_write16(BD9995X_CMD_SYSTEM_CTRL_SET, + BD9995X_CMD_SYSTEM_CTRL_SET_OTPLD | + BD9995X_CMD_SYSTEM_CTRL_SET_ALLRST, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; /* Wait until OTPROM loading is finished */ for (i = 0; i < OTPROM_LOAD_WAIT_RETRY; i++) { msleep(10); - rv = ch_raw_read16(BD99955_CMD_SYSTEM_STATUS, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_SYSTEM_STATUS, ®, + BD9995X_EXTENDED_COMMAND); - if (!rv && (reg & BD99955_CMD_SYSTEM_STATUS_OTPLD_STATE) && - (reg & BD99955_CMD_SYSTEM_STATUS_ALLRST_STATE)) + if (!rv && (reg & BD9995X_CMD_SYSTEM_STATUS_OTPLD_STATE) && + (reg & BD9995X_CMD_SYSTEM_STATUS_ALLRST_STATE)) break; } @@ -155,11 +155,11 @@ static int bd99955_por_reset(void) if (i == OTPROM_LOAD_WAIT_RETRY) return EC_ERROR_TIMEOUT; - return ch_raw_write16(BD99955_CMD_SYSTEM_CTRL_SET, 0, - BD99955_EXTENDED_COMMAND); + return ch_raw_write16(BD9995X_CMD_SYSTEM_CTRL_SET, 0, + BD9995X_EXTENDED_COMMAND); } -static int bd99955_reset_to_zero(void) +static int bd9995x_reset_to_zero(void) { int rv; @@ -170,67 +170,67 @@ static int bd99955_reset_to_zero(void) return charger_set_voltage(0); } -static int bd99955_get_charger_op_status(int *status) +static int bd9995x_get_charger_op_status(int *status) { - return ch_raw_read16(BD99955_CMD_CHGOP_STATUS, status, - BD99955_EXTENDED_COMMAND); + return ch_raw_read16(BD9995X_CMD_CHGOP_STATUS, status, + BD9995X_EXTENDED_COMMAND); } #ifdef HAS_TASK_USB_CHG static int bc12_detected_type[CONFIG_USB_PD_PORT_COUNT]; -static int bd99955_get_bc12_device_type(enum bd99955_charge_port port) +static int bd9995x_get_bc12_device_type(enum bd9995x_charge_port port) { int rv; int reg; - rv = ch_raw_read16((port == BD99955_CHARGE_PORT_VBUS) ? - BD99955_CMD_VBUS_UCD_STATUS : - BD99955_CMD_VCC_UCD_STATUS, - ®, BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16((port == BD9995X_CHARGE_PORT_VBUS) ? + BD9995X_CMD_VBUS_UCD_STATUS : + BD9995X_CMD_VCC_UCD_STATUS, + ®, BD9995X_EXTENDED_COMMAND); if (rv) return CHARGE_SUPPLIER_NONE; - switch (reg & BD99955_TYPE_MASK) { - case BD99955_TYPE_CDP: + switch (reg & BD9995X_TYPE_MASK) { + case BD9995X_TYPE_CDP: return CHARGE_SUPPLIER_BC12_CDP; - case BD99955_TYPE_DCP: + case BD9995X_TYPE_DCP: return CHARGE_SUPPLIER_BC12_DCP; - case BD99955_TYPE_SDP: + case BD9995X_TYPE_SDP: return CHARGE_SUPPLIER_BC12_SDP; - case BD99955_TYPE_PUP_PORT: - case BD99955_TYPE_OTHER: + case BD9995X_TYPE_PUP_PORT: + case BD9995X_TYPE_OTHER: return CHARGE_SUPPLIER_OTHER; - case BD99955_TYPE_OPEN_PORT: - case BD99955_TYPE_VBUS_OPEN: + case BD9995X_TYPE_OPEN_PORT: + case BD9995X_TYPE_VBUS_OPEN: default: return CHARGE_SUPPLIER_NONE; } } -static int bd99955_enable_usb_switch(enum bd99955_charge_port port, +static int bd9995x_enable_usb_switch(enum bd9995x_charge_port port, enum usb_switch setting) { int rv; int reg; int port_reg; - port_reg = (port == BD99955_CHARGE_PORT_VBUS) ? - BD99955_CMD_VBUS_UCD_SET : BD99955_CMD_VCC_UCD_SET; + port_reg = (port == BD9995X_CHARGE_PORT_VBUS) ? + BD9995X_CMD_VBUS_UCD_SET : BD9995X_CMD_VCC_UCD_SET; - rv = ch_raw_read16(port_reg, ®, BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(port_reg, ®, BD9995X_EXTENDED_COMMAND); if (rv) return rv; if (setting == USB_SWITCH_CONNECT) - reg |= BD99955_CMD_UCD_SET_USB_SW_EN; + reg |= BD9995X_CMD_UCD_SET_USB_SW_EN; else - reg &= ~BD99955_CMD_UCD_SET_USB_SW_EN; + reg &= ~BD9995X_CMD_UCD_SET_USB_SW_EN; - return ch_raw_write16(port_reg, reg, BD99955_EXTENDED_COMMAND); + return ch_raw_write16(port_reg, reg, BD9995X_EXTENDED_COMMAND); } -static int bd99955_bc12_detect(int port) +static int bd9995x_bc12_detect(int port) { int i; int bc12_type; @@ -243,7 +243,7 @@ static int bd99955_bc12_detect(int port) msleep(312); for (i = 0; i < BC12_DETECT_RETRY; i++) { /* get device type */ - bc12_type = bd99955_get_bc12_device_type(port); + bc12_type = bd9995x_get_bc12_device_type(port); /* Detected BC1.2 */ if (bc12_type != CHARGE_SUPPLIER_NONE) @@ -257,14 +257,14 @@ static int bd99955_bc12_detect(int port) if (bc12_type != CHARGE_SUPPLIER_NONE) { /* Update charge manager */ charge.voltage = USB_CHARGER_VOLTAGE_MV; - charge.current = bd99955_get_bc12_ilim(bc12_type); + charge.current = bd9995x_get_bc12_ilim(bc12_type); charge_manager_update_charge(bc12_type, port, &charge); } return bc12_type; } -static void bd99955_bc12_detach(int port, int type) +static void bd9995x_bc12_detach(int port, int type) { struct charge_port_info charge = { .voltage = USB_CHARGER_VOLTAGE_MV, @@ -275,10 +275,10 @@ static void bd99955_bc12_detach(int port, int type) charge_manager_update_charge(type, port, &charge); /* Disable charging trigger by BC1.2 detection */ - bd99955_bc12_enable_charging(port, 0); + bd9995x_bc12_enable_charging(port, 0); } -static int bd99955_enable_vbus_detect_interrupts(int port, int enable) +static int bd9995x_enable_vbus_detect_interrupts(int port, int enable) { int reg; int rv; @@ -286,71 +286,71 @@ static int bd99955_enable_vbus_detect_interrupts(int port, int enable) int mask_val; /* 1st Level Interrupt Setting */ - rv = ch_raw_read16(BD99955_CMD_INT0_SET, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_INT0_SET, ®, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; - mask_val = ((port == BD99955_CHARGE_PORT_VBUS) ? - BD99955_CMD_INT0_SET_INT1_EN : - BD99955_CMD_INT0_SET_INT2_EN) | - BD99955_CMD_INT0_SET_INT0_EN; + mask_val = ((port == BD9995X_CHARGE_PORT_VBUS) ? + BD9995X_CMD_INT0_SET_INT1_EN : + BD9995X_CMD_INT0_SET_INT2_EN) | + BD9995X_CMD_INT0_SET_INT0_EN; if (enable) reg |= mask_val; else reg &= ~mask_val; - rv = ch_raw_write16(BD99955_CMD_INT0_SET, reg, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_write16(BD9995X_CMD_INT0_SET, reg, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; /* 2nd Level Interrupt Setting */ - port_reg = (port == BD99955_CHARGE_PORT_VBUS) ? - BD99955_CMD_INT1_SET : BD99955_CMD_INT2_SET; - rv = ch_raw_read16(port_reg, ®, BD99955_EXTENDED_COMMAND); + port_reg = (port == BD9995X_CHARGE_PORT_VBUS) ? + BD9995X_CMD_INT1_SET : BD9995X_CMD_INT2_SET; + rv = ch_raw_read16(port_reg, ®, BD9995X_EXTENDED_COMMAND); if (rv) return rv; /* Enable threshold interrupts if we need to control discharge */ #ifdef CONFIG_USB_PD_DISCHARGE - mask_val = BD99955_CMD_INT_VBUS_DET | BD99955_CMD_INT_VBUS_TH; + mask_val = BD9995X_CMD_INT_VBUS_DET | BD9995X_CMD_INT_VBUS_TH; #else - mask_val = BD99955_CMD_INT_VBUS_DET; + mask_val = BD9995X_CMD_INT_VBUS_DET; #endif if (enable) reg |= mask_val; else reg &= ~mask_val; - return ch_raw_write16(port_reg, reg, BD99955_EXTENDED_COMMAND); + return ch_raw_write16(port_reg, reg, BD9995X_EXTENDED_COMMAND); } /* Read + clear active interrupt bits for a given port */ -static int bd99955_get_interrupts(int port) +static int bd9995x_get_interrupts(int port) { int rv; int reg; int port_reg; - port_reg = (port == BD99955_CHARGE_PORT_VBUS) ? - BD99955_CMD_INT1_STATUS : BD99955_CMD_INT2_STATUS; + port_reg = (port == BD9995X_CHARGE_PORT_VBUS) ? + BD9995X_CMD_INT1_STATUS : BD9995X_CMD_INT2_STATUS; - rv = ch_raw_read16(port_reg, ®, BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(port_reg, ®, BD9995X_EXTENDED_COMMAND); if (rv) return 0; /* Clear the interrupt status bits we just read */ - ch_raw_write16(port_reg, reg, BD99955_EXTENDED_COMMAND); + ch_raw_write16(port_reg, reg, BD9995X_EXTENDED_COMMAND); return reg; } -static void usb_charger_process(enum bd99955_charge_port port) +static void usb_charger_process(enum bd9995x_charge_port port) { - int chg_port = bd99955_pd_port_to_chg_port(port); - int vbus_provided = bd99955_is_vbus_provided(port) && + int chg_port = bd9995x_pd_port_to_chg_port(port); + int vbus_provided = bd9995x_is_vbus_provided(port) && !usb_charger_port_is_sourcing_vbus(chg_port); /* Inform other modules about VBUS level */ @@ -359,22 +359,22 @@ static void usb_charger_process(enum bd99955_charge_port port) /* Do BC1.2 detection */ if (vbus_provided) { /* Charger/sink attached */ - bc12_detected_type[port] = bd99955_bc12_detect(port); + bc12_detected_type[port] = bd9995x_bc12_detect(port); } else if (bc12_detected_type[port] != CHARGE_SUPPLIER_NONE) { /* Charger/sink detached */ - bd99955_bc12_detach(port, bc12_detected_type[port]); + bd9995x_bc12_detach(port, bc12_detected_type[port]); bc12_detected_type[port] = CHARGE_SUPPLIER_NONE; } } #endif /* HAS_TASK_USB_CHG */ -static int bd99955_set_vsysreg(int voltage) +static int bd9995x_set_vsysreg(int voltage) { /* VSYS Regulation voltage is in 64mV steps. */ voltage &= ~0x3F; - return ch_raw_write16(BD99955_CMD_VSYSREG_SET, voltage, - BD99955_EXTENDED_COMMAND); + return ch_raw_write16(BD9995X_CMD_VSYSREG_SET, voltage, + BD9995X_EXTENDED_COMMAND); } /* chip specific interfaces */ @@ -386,22 +386,22 @@ int charger_set_input_current(int input_current) /* Input current step 32 mA */ input_current &= ~0x1F; - if (input_current < bd99955_charger_info.input_current_min) - input_current = bd99955_charger_info.input_current_min; + if (input_current < bd9995x_charger_info.input_current_min) + input_current = bd9995x_charger_info.input_current_min; - rv = ch_raw_write16(BD99955_CMD_IBUS_LIM_SET, input_current, - BD99955_BAT_CHG_COMMAND); + rv = ch_raw_write16(BD9995X_CMD_IBUS_LIM_SET, input_current, + BD9995X_BAT_CHG_COMMAND); if (rv) return rv; - return ch_raw_write16(BD99955_CMD_ICC_LIM_SET, input_current, - BD99955_BAT_CHG_COMMAND); + return ch_raw_write16(BD9995X_CMD_ICC_LIM_SET, input_current, + BD9995X_BAT_CHG_COMMAND); } int charger_get_input_current(int *input_current) { - return ch_raw_read16(BD99955_CMD_CUR_ILIM_VAL, input_current, - BD99955_EXTENDED_COMMAND); + return ch_raw_read16(BD9995X_CMD_CUR_ILIM_VAL, input_current, + BD9995X_EXTENDED_COMMAND); } int charger_manufacturer_id(int *id) @@ -411,7 +411,7 @@ int charger_manufacturer_id(int *id) int charger_device_id(int *id) { - return ch_raw_read16(BD99955_CMD_CHIP_ID, id, BD99955_EXTENDED_COMMAND); + return ch_raw_read16(BD9995X_CMD_CHIP_ID, id, BD9995X_EXTENDED_COMMAND); } int charger_get_option(int *option) @@ -419,13 +419,13 @@ int charger_get_option(int *option) int rv; int reg; - rv = ch_raw_read16(BD99955_CMD_CHGOP_SET1, option, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_CHGOP_SET1, option, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; - rv = ch_raw_read16(BD99955_CMD_CHGOP_SET2, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_CHGOP_SET2, ®, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; @@ -438,20 +438,20 @@ int charger_set_option(int option) { int rv; - rv = ch_raw_write16(BD99955_CMD_CHGOP_SET1, option & 0xFFFF, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_write16(BD9995X_CMD_CHGOP_SET1, option & 0xFFFF, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; - return ch_raw_write16(BD99955_CMD_CHGOP_SET2, (option >> 16) & 0xFFFF, - BD99955_EXTENDED_COMMAND); + return ch_raw_write16(BD9995X_CMD_CHGOP_SET2, (option >> 16) & 0xFFFF, + BD9995X_EXTENDED_COMMAND); } /* Charger interfaces */ const struct charger_info *charger_get_info(void) { - return &bd99955_charger_info; + return &bd9995x_charger_info; } int charger_get_status(int *status) @@ -464,64 +464,64 @@ int charger_get_status(int *status) *status = CHARGER_LEVEL_2; /* charger enable/inhibit */ - rv = ch_raw_read16(BD99955_CMD_CHGOP_SET2, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_CHGOP_SET2, ®, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; - if (!(reg & BD99955_CMD_CHGOP_SET2_CHG_EN)) + if (!(reg & BD9995X_CMD_CHGOP_SET2_CHG_EN)) *status |= CHARGER_CHARGE_INHIBITED; /* charger alarm enable/inhibit */ - rv = ch_raw_read16(BD99955_CMD_PROCHOT_CTRL_SET, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_PROCHOT_CTRL_SET, ®, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; - if (!(reg & (BD99955_CMD_PROCHOT_CTRL_SET_PROCHOT_EN4 | - BD99955_CMD_PROCHOT_CTRL_SET_PROCHOT_EN3 | - BD99955_CMD_PROCHOT_CTRL_SET_PROCHOT_EN2 | - BD99955_CMD_PROCHOT_CTRL_SET_PROCHOT_EN1 | - BD99955_CMD_PROCHOT_CTRL_SET_PROCHOT_EN0))) + if (!(reg & (BD9995X_CMD_PROCHOT_CTRL_SET_PROCHOT_EN4 | + BD9995X_CMD_PROCHOT_CTRL_SET_PROCHOT_EN3 | + BD9995X_CMD_PROCHOT_CTRL_SET_PROCHOT_EN2 | + BD9995X_CMD_PROCHOT_CTRL_SET_PROCHOT_EN1 | + BD9995X_CMD_PROCHOT_CTRL_SET_PROCHOT_EN0))) *status |= CHARGER_ALARM_INHIBITED; - rv = bd99955_get_charger_op_status(®); + rv = bd9995x_get_charger_op_status(®); if (rv) return rv; /* power fail */ - if (!(reg & BD99955_CMD_CHGOP_STATUS_RBOOST_UV)) + if (!(reg & BD9995X_CMD_CHGOP_STATUS_RBOOST_UV)) *status |= CHARGER_POWER_FAIL; /* Safety signal ranges & battery presence */ - ch_status = (reg & BD99955_BATTTEMP_MASK) >> 8; + ch_status = (reg & BD9995X_BATTTEMP_MASK) >> 8; *status |= CHARGER_BATTERY_PRESENT; switch (ch_status) { - case BD99955_CMD_CHGOP_STATUS_BATTEMP_COLD1: + case BD9995X_CMD_CHGOP_STATUS_BATTEMP_COLD1: *status |= CHARGER_RES_COLD; break; - case BD99955_CMD_CHGOP_STATUS_BATTEMP_COLD2: + case BD9995X_CMD_CHGOP_STATUS_BATTEMP_COLD2: *status |= CHARGER_RES_COLD; *status |= CHARGER_RES_UR; break; - case BD99955_CMD_CHGOP_STATUS_BATTEMP_HOT1: - case BD99955_CMD_CHGOP_STATUS_BATTEMP_HOT2: + case BD9995X_CMD_CHGOP_STATUS_BATTEMP_HOT1: + case BD9995X_CMD_CHGOP_STATUS_BATTEMP_HOT2: *status |= CHARGER_RES_HOT; break; - case BD99955_CMD_CHGOP_STATUS_BATTEMP_HOT3: + case BD9995X_CMD_CHGOP_STATUS_BATTEMP_HOT3: *status |= CHARGER_RES_HOT; *status |= CHARGER_RES_OR; break; - case BD99955_CMD_CHGOP_STATUS_BATTEMP_BATOPEN: + case BD9995X_CMD_CHGOP_STATUS_BATTEMP_BATOPEN: *status &= ~CHARGER_BATTERY_PRESENT; default: break; } /* source of power */ - if (bd99955_is_vbus_provided(BD99955_CHARGE_PORT_BOTH)) + if (bd9995x_is_vbus_provided(BD9995X_CHARGE_PORT_BOTH)) *status |= CHARGER_AC_PRESENT; return EC_SUCCESS; @@ -532,25 +532,25 @@ int charger_set_mode(int mode) int rv; if (mode & CHARGE_FLAG_INHIBIT_CHARGE) { - rv = bd99955_set_vsysreg(BD99955_DISCHARGE_VSYSREG); + rv = bd9995x_set_vsysreg(BD9995X_DISCHARGE_VSYSREG); msleep(50); - rv |= bd99955_charger_enable(0); + rv |= bd9995x_charger_enable(0); } else { - rv = bd99955_charger_enable(1); + rv = bd9995x_charger_enable(1); msleep(1); - rv |= bd99955_set_vsysreg(BD99955_CHARGE_VSYSREG); + rv |= bd9995x_set_vsysreg(BD9995X_CHARGE_VSYSREG); } if (rv) return rv; if (mode & CHARGE_FLAG_POR_RESET) { - rv = bd99955_por_reset(); + rv = bd9995x_por_reset(); if (rv) return rv; } if (mode & CHARGE_FLAG_RESET_TO_ZERO) { - rv = bd99955_reset_to_zero(); + rv = bd9995x_reset_to_zero(); if (rv) return rv; } @@ -560,8 +560,8 @@ int charger_set_mode(int mode) int charger_get_current(int *current) { - return ch_raw_read16(BD99955_CMD_CHG_CURRENT, current, - BD99955_BAT_CHG_COMMAND); + return ch_raw_read16(BD9995X_CMD_CHG_CURRENT, current, + BD9995X_BAT_CHG_COMMAND); } int charger_set_current(int current) @@ -571,26 +571,26 @@ int charger_set_current(int current) /* Charge current step 64 mA */ current &= ~0x3F; - if (current < BD99955_NO_BATTERY_CHARGE_I_MIN && + if (current < BD9995X_NO_BATTERY_CHARGE_I_MIN && (battery_is_present() != BP_YES || battery_is_cut_off())) - current = BD99955_NO_BATTERY_CHARGE_I_MIN; - else if (current < bd99955_charger_info.current_min) - current = bd99955_charger_info.current_min; + current = BD9995X_NO_BATTERY_CHARGE_I_MIN; + else if (current < bd9995x_charger_info.current_min) + current = bd9995x_charger_info.current_min; - rv = ch_raw_write16(BD99955_CMD_CHG_CURRENT, current, - BD99955_BAT_CHG_COMMAND); + rv = ch_raw_write16(BD9995X_CMD_CHG_CURRENT, current, + BD9995X_BAT_CHG_COMMAND); if (rv) return rv; - return ch_raw_write16(BD99955_CMD_IPRECH_SET, - MIN(current, BD99955_IPRECH_MAX), - BD99955_EXTENDED_COMMAND); + return ch_raw_write16(BD9995X_CMD_IPRECH_SET, + MIN(current, BD9995X_IPRECH_MAX), + BD9995X_EXTENDED_COMMAND); } int charger_get_voltage(int *voltage) { - return ch_raw_read16(BD99955_CMD_CHG_VOLTAGE, voltage, - BD99955_BAT_CHG_COMMAND); + return ch_raw_read16(BD9995X_CMD_CHG_VOLTAGE, voltage, + BD9995X_BAT_CHG_COMMAND); } int charger_set_voltage(int voltage) @@ -603,12 +603,12 @@ int charger_set_voltage(int voltage) * Regulate the system voltage to battery max if the battery * is not present or the battery is discharging on AC. */ - rv = ch_raw_read16(BD99955_CMD_CHGOP_SET2, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_CHGOP_SET2, ®, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; - if (reg & BD99955_CMD_CHGOP_SET2_BATT_LEARN || + if (reg & BD9995X_CMD_CHGOP_SET2_BATT_LEARN || battery_is_present() != BP_YES || battery_is_cut_off()) voltage = bi->voltage_max; @@ -616,119 +616,119 @@ int charger_set_voltage(int voltage) /* Charge voltage step 16 mV */ voltage &= ~0x0F; - if (voltage < bd99955_charger_info.voltage_min) - voltage = bd99955_charger_info.voltage_min; + if (voltage < bd9995x_charger_info.voltage_min) + voltage = bd9995x_charger_info.voltage_min; - return ch_raw_write16(BD99955_CMD_CHG_VOLTAGE, voltage, - BD99955_BAT_CHG_COMMAND); + return ch_raw_write16(BD9995X_CMD_CHG_VOLTAGE, voltage, + BD9995X_BAT_CHG_COMMAND); } static void bd99995_init(void) { int reg; - int power_save_mode = BD99955_PWR_SAVE_OFF; + int power_save_mode = BD9995X_PWR_SAVE_OFF; const struct battery_info *bi = battery_get_info(); /* Enable BC1.2 detection on VCC */ - if (ch_raw_read16(BD99955_CMD_VCC_UCD_SET, ®, - BD99955_EXTENDED_COMMAND)) + if (ch_raw_read16(BD9995X_CMD_VCC_UCD_SET, ®, + BD9995X_EXTENDED_COMMAND)) return; - reg |= BD99955_CMD_UCD_SET_USBDETEN; - reg &= ~BD99955_CMD_UCD_SET_USB_SW_EN; - ch_raw_write16(BD99955_CMD_VCC_UCD_SET, reg, - BD99955_EXTENDED_COMMAND); + reg |= BD9995X_CMD_UCD_SET_USBDETEN; + reg &= ~BD9995X_CMD_UCD_SET_USB_SW_EN; + ch_raw_write16(BD9995X_CMD_VCC_UCD_SET, reg, + BD9995X_EXTENDED_COMMAND); /* Enable BC1.2 detection on VBUS */ - if (ch_raw_read16(BD99955_CMD_VBUS_UCD_SET, ®, - BD99955_EXTENDED_COMMAND)) + if (ch_raw_read16(BD9995X_CMD_VBUS_UCD_SET, ®, + BD9995X_EXTENDED_COMMAND)) return; - reg |= BD99955_CMD_UCD_SET_USBDETEN; - reg &= ~BD99955_CMD_UCD_SET_USB_SW_EN; - ch_raw_write16(BD99955_CMD_VBUS_UCD_SET, reg, - BD99955_EXTENDED_COMMAND); + reg |= BD9995X_CMD_UCD_SET_USBDETEN; + reg &= ~BD9995X_CMD_UCD_SET_USB_SW_EN; + ch_raw_write16(BD9995X_CMD_VBUS_UCD_SET, reg, + BD9995X_EXTENDED_COMMAND); /* Disable charging trigger by BC1.2 on VCC & VBUS. */ - if (ch_raw_read16(BD99955_CMD_CHGOP_SET1, ®, - BD99955_EXTENDED_COMMAND)) + if (ch_raw_read16(BD9995X_CMD_CHGOP_SET1, ®, + BD9995X_EXTENDED_COMMAND)) return; - reg |= (BD99955_CMD_CHGOP_SET1_SDP_CHG_TRIG_EN | - BD99955_CMD_CHGOP_SET1_SDP_CHG_TRIG | - BD99955_CMD_CHGOP_SET1_VBUS_BC_DISEN | - BD99955_CMD_CHGOP_SET1_VCC_BC_DISEN | - BD99955_CMD_CHGOP_SET1_ILIM_AUTO_DISEN); - ch_raw_write16(BD99955_CMD_CHGOP_SET1, reg, - BD99955_EXTENDED_COMMAND); + reg |= (BD9995X_CMD_CHGOP_SET1_SDP_CHG_TRIG_EN | + BD9995X_CMD_CHGOP_SET1_SDP_CHG_TRIG | + BD9995X_CMD_CHGOP_SET1_VBUS_BC_DISEN | + BD9995X_CMD_CHGOP_SET1_VCC_BC_DISEN | + BD9995X_CMD_CHGOP_SET1_ILIM_AUTO_DISEN); + ch_raw_write16(BD9995X_CMD_CHGOP_SET1, reg, + BD9995X_EXTENDED_COMMAND); /* Enable BC1.2 USB charging and DC/DC converter @ 1200KHz */ - if (ch_raw_read16(BD99955_CMD_CHGOP_SET2, ®, - BD99955_EXTENDED_COMMAND)) + if (ch_raw_read16(BD9995X_CMD_CHGOP_SET2, ®, + BD9995X_EXTENDED_COMMAND)) return; - reg &= ~(BD99955_CMD_CHGOP_SET2_USB_SUS | - BD99955_CMD_CHGOP_SET2_DCDC_CLK_SEL); - reg |= BD99955_CMD_CHGOP_SET2_DCDC_CLK_SEL_1200; - ch_raw_write16(BD99955_CMD_CHGOP_SET2, reg, - BD99955_EXTENDED_COMMAND); + reg &= ~(BD9995X_CMD_CHGOP_SET2_USB_SUS | + BD9995X_CMD_CHGOP_SET2_DCDC_CLK_SEL); + reg |= BD9995X_CMD_CHGOP_SET2_DCDC_CLK_SEL_1200; + ch_raw_write16(BD9995X_CMD_CHGOP_SET2, reg, + BD9995X_EXTENDED_COMMAND); /* TODO(crosbug.com/p/55626): Set VSYSVAL_THH/THL appropriately */ /* Set battery OVP to 500 + maximum battery voltage */ - ch_raw_write16(BD99955_CMD_VBATOVP_SET, + ch_raw_write16(BD9995X_CMD_VBATOVP_SET, (bi->voltage_max + 500) & 0x7ff0, - BD99955_EXTENDED_COMMAND); + BD9995X_EXTENDED_COMMAND); /* Disable IADP pin current limit */ - if (ch_raw_read16(BD99955_CMD_VM_CTRL_SET, ®, - BD99955_EXTENDED_COMMAND)) + if (ch_raw_read16(BD9995X_CMD_VM_CTRL_SET, ®, + BD9995X_EXTENDED_COMMAND)) return; - reg &= ~BD99955_CMD_VM_CTRL_SET_EXTIADPEN; - ch_raw_write16(BD99955_CMD_VM_CTRL_SET, reg, - BD99955_EXTENDED_COMMAND); + reg &= ~BD9995X_CMD_VM_CTRL_SET_EXTIADPEN; + ch_raw_write16(BD9995X_CMD_VM_CTRL_SET, reg, + BD9995X_EXTENDED_COMMAND); /* Set fast charging watchdog to 1020 minutes. */ - ch_raw_write16(BD99955_CMD_CHGWDT_SET, 0xFF10, - BD99955_EXTENDED_COMMAND); + ch_raw_write16(BD9995X_CMD_CHGWDT_SET, 0xFF10, + BD9995X_EXTENDED_COMMAND); /* Set charge termination current to 0 mA. */ - ch_raw_write16(BD99955_CMD_ITERM_SET, 0, - BD99955_EXTENDED_COMMAND); + ch_raw_write16(BD9995X_CMD_ITERM_SET, 0, + BD9995X_EXTENDED_COMMAND); /* Set Pre-charge Voltage Threshold for trickle charging. */ - ch_raw_write16(BD99955_CMD_VPRECHG_TH_SET, + ch_raw_write16(BD9995X_CMD_VPRECHG_TH_SET, bi->voltage_min & 0x7FC0, - BD99955_EXTENDED_COMMAND); + BD9995X_EXTENDED_COMMAND); /* Trickle-charge Current Setting */ - ch_raw_write16(BD99955_CMD_ITRICH_SET, + ch_raw_write16(BD9995X_CMD_ITRICH_SET, bi->precharge_current & 0x07C0, - BD99955_EXTENDED_COMMAND); + BD9995X_EXTENDED_COMMAND); /* Power save mode when VBUS/VCC is removed. */ -#ifdef CONFIG_BD99955_POWER_SAVE_MODE - power_save_mode = CONFIG_BD99955_POWER_SAVE_MODE; +#ifdef CONFIG_BD9995X_POWER_SAVE_MODE + power_save_mode = CONFIG_BD9995X_POWER_SAVE_MODE; #endif - ch_raw_write16(BD99955_CMD_SMBREG, power_save_mode, - BD99955_EXTENDED_COMMAND); + ch_raw_write16(BD9995X_CMD_SMBREG, power_save_mode, + BD9995X_EXTENDED_COMMAND); #ifdef CONFIG_USB_PD_DISCHARGE /* Set VBUS / VCC detection threshold for discharge enable */ - ch_raw_write16(BD99955_CMD_VBUS_TH_SET, BD99955_VBUS_DISCHARGE_TH, - BD99955_EXTENDED_COMMAND); - ch_raw_write16(BD99955_CMD_VCC_TH_SET, BD99955_VBUS_DISCHARGE_TH, - BD99955_EXTENDED_COMMAND); + ch_raw_write16(BD9995X_CMD_VBUS_TH_SET, BD9995X_VBUS_DISCHARGE_TH, + BD9995X_EXTENDED_COMMAND); + ch_raw_write16(BD9995X_CMD_VCC_TH_SET, BD9995X_VBUS_DISCHARGE_TH, + BD9995X_EXTENDED_COMMAND); #endif /* Unlock debug regs */ - ch_raw_write16(BD99955_CMD_PROTECT_SET, 0x3c, BD99955_EXTENDED_COMMAND); - ch_raw_write16(BD99955_CMD_MAP_SET, 0x2, BD99955_EXTENDED_COMMAND); + ch_raw_write16(BD9995X_CMD_PROTECT_SET, 0x3c, BD9995X_EXTENDED_COMMAND); + ch_raw_write16(BD9995X_CMD_MAP_SET, 0x2, BD9995X_EXTENDED_COMMAND); /* Undocumented - reverse current threshold = -50mV */ - ch_raw_write16(0x14, 0x0202, BD99955_DEBUG_COMMAND); + ch_raw_write16(0x14, 0x0202, BD9995X_DEBUG_COMMAND); /* Undocumented - internal gain = 2x */ - ch_raw_write16(0x1a, 0x80, BD99955_DEBUG_COMMAND); + ch_raw_write16(0x1a, 0x80, BD9995X_DEBUG_COMMAND); /* Re-lock debug regs */ - ch_raw_write16(BD99955_CMD_PROTECT_SET, 0x0, BD99955_EXTENDED_COMMAND); - ch_raw_write16(BD99955_CMD_MAP_SET, 0x1, BD99955_EXTENDED_COMMAND); + ch_raw_write16(BD9995X_CMD_PROTECT_SET, 0x0, BD9995X_EXTENDED_COMMAND); + ch_raw_write16(BD9995X_CMD_MAP_SET, 0x1, BD9995X_EXTENDED_COMMAND); } DECLARE_HOOK(HOOK_INIT, bd99995_init, HOOK_PRIO_INIT_EXTPOWER); @@ -742,18 +742,18 @@ int charger_discharge_on_ac(int enable) int rv; int reg; - rv = ch_raw_read16(BD99955_CMD_CHGOP_SET2, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_CHGOP_SET2, ®, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; if (enable) - reg |= BD99955_CMD_CHGOP_SET2_BATT_LEARN; + reg |= BD9995X_CMD_CHGOP_SET2_BATT_LEARN; else - reg &= ~BD99955_CMD_CHGOP_SET2_BATT_LEARN; + reg &= ~BD9995X_CMD_CHGOP_SET2_BATT_LEARN; - return ch_raw_write16(BD99955_CMD_CHGOP_SET2, reg, - BD99955_EXTENDED_COMMAND); + return ch_raw_write16(BD9995X_CMD_CHGOP_SET2, reg, + BD9995X_EXTENDED_COMMAND); } int charger_get_vbus_level(void) @@ -762,11 +762,11 @@ int charger_get_vbus_level(void) int vcc_val; int rv; - rv = ch_raw_read16(BD99955_CMD_VBUS_VAL, &vbus_val, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_VBUS_VAL, &vbus_val, + BD9995X_EXTENDED_COMMAND); - rv += ch_raw_read16(BD99955_CMD_VCC_VAL, &vcc_val, - BD99955_EXTENDED_COMMAND); + rv += ch_raw_read16(BD9995X_CMD_VCC_VAL, &vcc_val, + BD9995X_EXTENDED_COMMAND); return rv ? 0 : MAX(vbus_val, vcc_val); } @@ -774,67 +774,67 @@ int charger_get_vbus_level(void) /*** Non-standard interface functions ***/ -int bd99955_is_vbus_provided(int port) +int bd9995x_is_vbus_provided(int port) { int reg; - if (ch_raw_read16(BD99955_CMD_VBUS_VCC_STATUS, ®, - BD99955_EXTENDED_COMMAND)) + if (ch_raw_read16(BD9995X_CMD_VBUS_VCC_STATUS, ®, + BD9995X_EXTENDED_COMMAND)) return 0; - if (port == BD99955_CHARGE_PORT_VBUS) - reg &= BD99955_CMD_VBUS_VCC_STATUS_VBUS_DETECT; - else if (port == BD99955_CHARGE_PORT_VCC) - reg &= BD99955_CMD_VBUS_VCC_STATUS_VCC_DETECT; - else if (port == BD99955_CHARGE_PORT_BOTH) { + if (port == BD9995X_CHARGE_PORT_VBUS) + reg &= BD9995X_CMD_VBUS_VCC_STATUS_VBUS_DETECT; + else if (port == BD9995X_CHARGE_PORT_VCC) + reg &= BD9995X_CMD_VBUS_VCC_STATUS_VCC_DETECT; + else if (port == BD9995X_CHARGE_PORT_BOTH) { /* Check VBUS on either port */ - reg &= (BD99955_CMD_VBUS_VCC_STATUS_VCC_DETECT | - BD99955_CMD_VBUS_VCC_STATUS_VBUS_DETECT); + reg &= (BD9995X_CMD_VBUS_VCC_STATUS_VCC_DETECT | + BD9995X_CMD_VBUS_VCC_STATUS_VBUS_DETECT); } else reg = 0; return !!reg; } -int bd99955_select_input_port(enum bd99955_charge_port port) +int bd9995x_select_input_port(enum bd9995x_charge_port port) { int rv; int reg; - rv = ch_raw_read16(BD99955_CMD_VIN_CTRL_SET, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_VIN_CTRL_SET, ®, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; - if (port == BD99955_CHARGE_PORT_NONE) { - reg &= ~(BD99955_CMD_VIN_CTRL_SET_VBUS_EN | - BD99955_CMD_VIN_CTRL_SET_VCC_EN); - } else if (port == BD99955_CHARGE_PORT_VBUS) { - reg |= BD99955_CMD_VIN_CTRL_SET_VBUS_EN; - reg &= ~BD99955_CMD_VIN_CTRL_SET_VCC_EN; - } else if (port == BD99955_CHARGE_PORT_VCC) { - reg |= BD99955_CMD_VIN_CTRL_SET_VCC_EN; - reg &= ~BD99955_CMD_VIN_CTRL_SET_VBUS_EN; - } else if (port == BD99955_CHARGE_PORT_BOTH) { + if (port == BD9995X_CHARGE_PORT_NONE) { + reg &= ~(BD9995X_CMD_VIN_CTRL_SET_VBUS_EN | + BD9995X_CMD_VIN_CTRL_SET_VCC_EN); + } else if (port == BD9995X_CHARGE_PORT_VBUS) { + reg |= BD9995X_CMD_VIN_CTRL_SET_VBUS_EN; + reg &= ~BD9995X_CMD_VIN_CTRL_SET_VCC_EN; + } else if (port == BD9995X_CHARGE_PORT_VCC) { + reg |= BD9995X_CMD_VIN_CTRL_SET_VCC_EN; + reg &= ~BD9995X_CMD_VIN_CTRL_SET_VBUS_EN; + } else if (port == BD9995X_CHARGE_PORT_BOTH) { /* Enable both the ports for PG3 */ - reg |= BD99955_CMD_VIN_CTRL_SET_VBUS_EN | - BD99955_CMD_VIN_CTRL_SET_VCC_EN; + reg |= BD9995X_CMD_VIN_CTRL_SET_VBUS_EN | + BD9995X_CMD_VIN_CTRL_SET_VCC_EN; } else { /* Invalid charge port */ panic("Invalid charge port"); } - return ch_raw_write16(BD99955_CMD_VIN_CTRL_SET, reg, - BD99955_EXTENDED_COMMAND); + return ch_raw_write16(BD9995X_CMD_VIN_CTRL_SET, reg, + BD9995X_EXTENDED_COMMAND); } #ifdef CONFIG_CHARGER_BATTERY_TSENSE -int bd99955_get_battery_temp(int *temp_ptr) +int bd9995x_get_battery_temp(int *temp_ptr) { int rv; - rv = ch_raw_read16(BD99955_CMD_THERM_VAL, temp_ptr, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_THERM_VAL, temp_ptr, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; @@ -845,7 +845,7 @@ int bd99955_get_battery_temp(int *temp_ptr) #endif #ifdef HAS_TASK_USB_CHG -int bd99955_get_bc12_ilim(int charge_supplier) +int bd9995x_get_bc12_ilim(int charge_supplier) { switch (charge_supplier) { case CHARGE_SUPPLIER_BC12_CDP: @@ -869,7 +869,7 @@ int bd99955_get_bc12_ilim(int charge_supplier) } } -int bd99955_bc12_enable_charging(enum bd99955_charge_port port, int enable) +int bd9995x_bc12_enable_charging(enum bd9995x_charge_port port, int enable) { int rv; int reg; @@ -880,29 +880,29 @@ int bd99955_bc12_enable_charging(enum bd99955_charge_port port, int enable) * detection and disable SDP_CHG_TRIG, SDP_CHG_TRIG_EN. Vice versa * for USB-C. */ - rv = ch_raw_read16(BD99955_CMD_CHGOP_SET1, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_CHGOP_SET1, ®, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; - mask_val = (BD99955_CMD_CHGOP_SET1_SDP_CHG_TRIG_EN | - BD99955_CMD_CHGOP_SET1_SDP_CHG_TRIG | - ((port == BD99955_CHARGE_PORT_VBUS) ? - BD99955_CMD_CHGOP_SET1_VBUS_BC_DISEN : - BD99955_CMD_CHGOP_SET1_VCC_BC_DISEN)); + mask_val = (BD9995X_CMD_CHGOP_SET1_SDP_CHG_TRIG_EN | + BD9995X_CMD_CHGOP_SET1_SDP_CHG_TRIG | + ((port == BD9995X_CHARGE_PORT_VBUS) ? + BD9995X_CMD_CHGOP_SET1_VBUS_BC_DISEN : + BD9995X_CMD_CHGOP_SET1_VCC_BC_DISEN)); if (enable) reg &= ~mask_val; else reg |= mask_val; - return ch_raw_write16(BD99955_CMD_CHGOP_SET1, reg, - BD99955_EXTENDED_COMMAND); + return ch_raw_write16(BD9995X_CMD_CHGOP_SET1, reg, + BD9995X_EXTENDED_COMMAND); } void usb_charger_set_switches(int port, enum usb_switch setting) { - int power_save_mode = BD99955_PWR_SAVE_OFF; + int power_save_mode = BD9995X_PWR_SAVE_OFF; /* If switch is not changing then return */ if (setting == usb_switch_state[port]) @@ -911,18 +911,18 @@ void usb_charger_set_switches(int port, enum usb_switch setting) if (setting != USB_SWITCH_RESTORE) usb_switch_state[port] = setting; /* ensure we disable power saving when we are using DP/DN */ -#ifdef CONFIG_BD99955_POWER_SAVE_MODE +#ifdef CONFIG_BD9995X_POWER_SAVE_MODE power_save_mode = (usb_switch_state[0] == USB_SWITCH_DISCONNECT && usb_switch_state[1] == USB_SWITCH_DISCONNECT) - ? CONFIG_BD99955_POWER_SAVE_MODE - : BD99955_PWR_SAVE_OFF; + ? CONFIG_BD9995X_POWER_SAVE_MODE + : BD9995X_PWR_SAVE_OFF; #endif - ch_raw_write16(BD99955_CMD_SMBREG, power_save_mode, - BD99955_EXTENDED_COMMAND); - bd99955_enable_usb_switch(port, usb_switch_state[port]); + ch_raw_write16(BD9995X_CMD_SMBREG, power_save_mode, + BD9995X_EXTENDED_COMMAND); + bd9995x_enable_usb_switch(port, usb_switch_state[port]); } -void bd99955_vbus_interrupt(enum gpio_signal signal) +void bd9995x_vbus_interrupt(enum gpio_signal signal) { task_wake(TASK_ID_USB_CHG); } @@ -937,36 +937,36 @@ void usb_charger_task(void) for (port = 0; port < CONFIG_USB_PD_PORT_COUNT; port++) { bc12_detected_type[port] = CHARGE_SUPPLIER_NONE; - bd99955_enable_vbus_detect_interrupts(port, 1); + bd9995x_enable_vbus_detect_interrupts(port, 1); } while (1) { changed = 0; for (port = 0; port < CONFIG_USB_PD_PORT_COUNT; port++) { /* Get port interrupts */ - interrupts = bd99955_get_interrupts(port); - if (interrupts & BD99955_CMD_INT_VBUS_DET || + interrupts = bd9995x_get_interrupts(port); + if (interrupts & BD9995X_CMD_INT_VBUS_DET || !initialized) { /* Detect based on current state of VBUS */ usb_charger_process(port); changed = 1; } #ifdef CONFIG_USB_PD_DISCHARGE - if (interrupts & BD99955_CMD_INT_VBUS_TH || + if (interrupts & BD9995X_CMD_INT_VBUS_TH || !initialized) { /* Get VBUS voltage */ - vbus_reg = (port == BD99955_CHARGE_PORT_VBUS) ? - BD99955_CMD_VBUS_VAL : - BD99955_CMD_VCC_VAL; + vbus_reg = (port == BD9995X_CHARGE_PORT_VBUS) ? + BD9995X_CMD_VBUS_VAL : + BD9995X_CMD_VCC_VAL; if (ch_raw_read16(vbus_reg, &voltage, - BD99955_EXTENDED_COMMAND)) + BD9995X_EXTENDED_COMMAND)) voltage = 0; /* Set discharge accordingly */ pd_set_vbus_discharge( - bd99955_pd_port_to_chg_port(port), - voltage < BD99955_VBUS_DISCHARGE_TH); + bd9995x_pd_port_to_chg_port(port), + voltage < BD9995X_VBUS_DISCHARGE_TH); changed = 1; } #endif @@ -996,7 +996,7 @@ static int read_bat(uint8_t cmd) { int read = 0; - ch_raw_read16(cmd, &read, BD99955_BAT_CHG_COMMAND); + ch_raw_read16(cmd, &read, BD9995X_BAT_CHG_COMMAND); return read; } @@ -1004,12 +1004,12 @@ static int read_ext(uint8_t cmd) { int read = 0; - ch_raw_read16(cmd, &read, BD99955_EXTENDED_COMMAND); + ch_raw_read16(cmd, &read, BD9995X_EXTENDED_COMMAND); return read; } -/* Dump all readable registers on bd99955 */ -static int console_bd99955_dump_regs(int argc, char **argv) +/* Dump all readable registers on bd9995x */ +static int console_bd9995x_dump_regs(int argc, char **argv) { int i; uint8_t regs[] = { 0x14, 0x15, 0x3c, 0x3d, 0x3e, 0x3f }; @@ -1026,15 +1026,15 @@ static int console_bd99955_dump_regs(int argc, char **argv) return 0; } -DECLARE_CONSOLE_COMMAND(bd99955_dump, console_bd99955_dump_regs, +DECLARE_CONSOLE_COMMAND(bd9995x_dump, console_bd9995x_dump_regs, NULL, "Dump all charger registers"); -static int console_command_bd99955(int argc, char **argv) +static int console_command_bd9995x(int argc, char **argv) { int rv, reg, data, val; char rw, *e; - enum bd99955_command cmd; + enum bd9995x_command cmd; if (argc < 4) return EC_ERROR_PARAM_COUNT; @@ -1070,21 +1070,21 @@ static int console_command_bd99955(int argc, char **argv) return rv; } -DECLARE_CONSOLE_COMMAND(bd99955, console_command_bd99955, - "bd99955 <r/w> <reg_hex> <cmd_type> | <val_hex>", +DECLARE_CONSOLE_COMMAND(bd9995x, console_command_bd9995x, + "bd9995x <r/w> <reg_hex> <cmd_type> | <val_hex>", "Read or write a charger register"); #endif /* CONFIG_CMD_CHARGER */ #ifdef CONFIG_CMD_CHARGER_PSYS -static int bd99955_psys_charger_adc(void) +static int bd9995x_psys_charger_adc(void) { int i; int reg; uint64_t ipmon = 0; - for (i = 0; i < BD99955_PMON_IOUT_ADC_READ_COUNT; i++) { - if (ch_raw_read16(BD99955_CMD_PMON_DACIN_VAL, ®, - BD99955_EXTENDED_COMMAND)) + for (i = 0; i < BD9995X_PMON_IOUT_ADC_READ_COUNT; i++) { + if (ch_raw_read16(BD9995X_CMD_PMON_DACIN_VAL, ®, + BD9995X_EXTENDED_COMMAND)) return 0; /* Conversion Interval is 200us */ @@ -1096,28 +1096,28 @@ static int bd99955_psys_charger_adc(void) * Calculate power in mW * PSYS = VACP×IACP+VBAT×IBAT = IPMON / GPMON */ - return (int) ((ipmon * 1000) / ((1 << BD99955_PSYS_GAIN_SELECT) * - BD99955_PMON_IOUT_ADC_READ_COUNT)); + return (int) ((ipmon * 1000) / ((1 << BD9995X_PSYS_GAIN_SELECT) * + BD9995X_PMON_IOUT_ADC_READ_COUNT)); } -static int bd99955_enable_psys(void) +static int bd9995x_enable_psys(void) { int rv; int reg; - rv = ch_raw_read16(BD99955_CMD_PMON_IOUT_CTRL_SET, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_PMON_IOUT_CTRL_SET, ®, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; /* Enable PSYS & Select PSYS Gain */ - reg &= ~BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_MASK; - reg |= (BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_INSEL | - BD99955_CMD_PMON_IOUT_CTRL_SET_PMON_OUT_EN | - BD99955_PSYS_GAIN_SELECT); + reg &= ~BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_MASK; + reg |= (BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_INSEL | + BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_OUT_EN | + BD9995X_PSYS_GAIN_SELECT); - return ch_raw_write16(BD99955_CMD_PMON_IOUT_CTRL_SET, reg, - BD99955_EXTENDED_COMMAND); + return ch_raw_write16(BD9995X_CMD_PMON_IOUT_CTRL_SET, reg, + BD9995X_EXTENDED_COMMAND); } /** @@ -1127,12 +1127,12 @@ static int console_command_psys(int argc, char **argv) { int rv; - rv = bd99955_enable_psys(); + rv = bd9995x_enable_psys(); if (rv) return rv; CPRINTS("PSYS from chg_adc: %d mW", - bd99955_psys_charger_adc()); + bd9995x_psys_charger_adc()); return EC_SUCCESS; } @@ -1142,15 +1142,15 @@ DECLARE_CONSOLE_COMMAND(psys, console_command_psys, #endif /* CONFIG_CMD_CHARGER_PSYS */ #ifdef CONFIG_CMD_CHARGER_ADC_AMON_BMON -static int bd99955_amon_bmon_chg_adc(void) +static int bd9995x_amon_bmon_chg_adc(void) { int i; int reg; int iout = 0; - for (i = 0; i < BD99955_PMON_IOUT_ADC_READ_COUNT; i++) { - ch_raw_read16(BD99955_CMD_IOUT_DACIN_VAL, ®, - BD99955_EXTENDED_COMMAND); + for (i = 0; i < BD9995X_PMON_IOUT_ADC_READ_COUNT; i++) { + ch_raw_read16(BD9995X_CMD_IOUT_DACIN_VAL, ®, + BD9995X_EXTENDED_COMMAND); iout += reg; /* Conversion Interval is 200us */ @@ -1165,42 +1165,42 @@ static int bd99955_amon_bmon_chg_adc(void) * VIDCHG = GIDCHG * (VSRN- VSRP) = GIDCHG * IDCHG / IDCHG_RES * VIADP = GIADP * (VACP- VACN) = GIADP * IADP / IADP_RES */ - return (iout * (5 << BD99955_IOUT_GAIN_SELECT)) / - (10 * BD99955_PMON_IOUT_ADC_READ_COUNT); + return (iout * (5 << BD9995X_IOUT_GAIN_SELECT)) / + (10 * BD9995X_PMON_IOUT_ADC_READ_COUNT); } -static int bd99955_amon_bmon(int amon_bmon) +static int bd9995x_amon_bmon(int amon_bmon) { int rv; int reg; int imon; int sns_res; - rv = ch_raw_read16(BD99955_CMD_PMON_IOUT_CTRL_SET, ®, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_read16(BD9995X_CMD_PMON_IOUT_CTRL_SET, ®, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; /* Enable monitor */ - reg &= ~BD99955_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_MASK; - reg |= (BD99955_CMD_PMON_IOUT_CTRL_SET_IMON_INSEL | - BD99955_CMD_PMON_IOUT_CTRL_SET_IOUT_OUT_EN | - (BD99955_IOUT_GAIN_SELECT << 4)); + reg &= ~BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_MASK; + reg |= (BD9995X_CMD_PMON_IOUT_CTRL_SET_IMON_INSEL | + BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_OUT_EN | + (BD9995X_IOUT_GAIN_SELECT << 4)); if (amon_bmon) { - reg |= BD99955_CMD_PMON_IOUT_CTRL_SET_IOUT_SOURCE_SEL; + reg |= BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_SOURCE_SEL; sns_res = CONFIG_CHARGER_SENSE_RESISTOR_AC; } else { - reg &= ~BD99955_CMD_PMON_IOUT_CTRL_SET_IOUT_SOURCE_SEL; + reg &= ~BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_SOURCE_SEL; sns_res = CONFIG_CHARGER_SENSE_RESISTOR; } - rv = ch_raw_write16(BD99955_CMD_PMON_IOUT_CTRL_SET, reg, - BD99955_EXTENDED_COMMAND); + rv = ch_raw_write16(BD9995X_CMD_PMON_IOUT_CTRL_SET, reg, + BD9995X_EXTENDED_COMMAND); if (rv) return rv; - imon = bd99955_amon_bmon_chg_adc(); + imon = bd9995x_amon_bmon_chg_adc(); CPRINTS("%cMON from chg_adc: %d uV, %d mA]", amon_bmon ? 'A' : 'B', @@ -1219,11 +1219,11 @@ static int console_command_amon_bmon(int argc, char **argv) /* Switch to AMON */ if (argc == 1 || (argc >= 2 && argv[1][0] == 'a')) - rv = bd99955_amon_bmon(1); + rv = bd9995x_amon_bmon(1); /* Switch to BMON */ if (argc == 1 || (argc >= 2 && argv[1][0] == 'b')) - rv = bd99955_amon_bmon(0); + rv = bd9995x_amon_bmon(0); return rv; } diff --git a/driver/charger/bd9995x.h b/driver/charger/bd9995x.h new file mode 100644 index 0000000000..91a0ac1bbd --- /dev/null +++ b/driver/charger/bd9995x.h @@ -0,0 +1,362 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * ROHM BD9995X battery charger driver. + */ + +#ifndef __CROS_EC_BD9995X_H +#define __CROS_EC_BD9995X_H + +#define BD9995X_ADDR 0x12 /* 7bit address 0001_001 */ +#define I2C_ADDR_CHARGER BD9995X_ADDR + +#ifdef CONFIG_CHARGER_BD99955 +#define BD9995X_CHARGER_NAME "bd99955" +#define BD9995X_CHIP_ID 0x221 +#elif defined(CONFIG_CHARGER_BD99956) +#define BD9995X_CHARGER_NAME "bd99956" +#define BD9995X_CHIP_ID 0x331 +#endif + +/* BD9995X commands to change the command code map */ +enum bd9995x_command { + BD9995X_BAT_CHG_COMMAND, + BD9995X_EXTENDED_COMMAND, + BD9995X_DEBUG_COMMAND, + BD9995X_INVALID_COMMAND +}; + +enum bd9995x_charge_port { + BD9995X_CHARGE_PORT_VBUS, + BD9995X_CHARGE_PORT_VCC, + BD9995X_CHARGE_PORT_BOTH, + BD9995X_CHARGE_PORT_NONE, +}; + +/* Charger parameters */ +#define CHARGER_NAME BD9995X_CHARGER_NAME +#define CHARGE_V_MAX 19200 +#define CHARGE_V_MIN 3072 +#define CHARGE_V_STEP 16 +#define CHARGE_I_MAX 16320 +#define CHARGE_I_MIN 128 +#define CHARGE_I_OFF 0 +#define CHARGE_I_STEP 64 +#define INPUT_I_MAX 16352 +#define INPUT_I_MIN 512 +#define INPUT_I_STEP 32 + +/* Min. charge current w/ no battery to prevent collapse */ +#define BD9995X_NO_BATTERY_CHARGE_I_MIN 512 + +/* VSYSREG settings */ +#define BD9995X_DISCHARGE_VSYSREG 8960 +#define BD9995X_CHARGE_VSYSREG 6144 + +/* + * BC1.2 minimum voltage threshold. + * BC1.2 charging port output voltage range is 4.75V to 5.25V, + * BD9995X Anti-Collapse Threshold Voltage Accuracy is -100mV to +100mV, + * and Delta of 50mV. + */ +#define BD9995X_BC12_MIN_VOLTAGE 4600 + +/* Battery Charger Commands */ +#define BD9995X_CMD_CHG_CURRENT 0x14 +#define BD9995X_CMD_CHG_VOLTAGE 0x15 +#define BD9995X_CMD_IBUS_LIM_SET 0x3C +#define BD9995X_CMD_ICC_LIM_SET 0x3D +#define BD9995X_CMD_PROTECT_SET 0x3E +#define BD9995X_CMD_MAP_SET 0x3F + +/* Extended commands */ +#define BD9995X_CMD_CHGSTM_STATUS 0x00 +#define BD9995X_CMD_VBAT_VSYS_STATUS 0x01 +#define BD9995X_CMD_VBUS_VCC_STATUS 0x02 +#define BD9995X_CMD_VBUS_VCC_STATUS_VCC_DETECT (1 << 8) +#define BD9995X_CMD_VBUS_VCC_STATUS_VBUS_DETECT (1 << 0) + +#define BD9995X_CMD_CHGOP_STATUS 0x03 +#define BD9995X_CMD_CHGOP_STATUS_BATTEMP2 (1 << 10) +#define BD9995X_CMD_CHGOP_STATUS_BATTEMP1 (1 << 9) +#define BD9995X_CMD_CHGOP_STATUS_BATTEMP0 (1 << 8) +#define BD9995X_BATTTEMP_MASK 0x700 +#define BD9995X_CMD_CHGOP_STATUS_BATTEMP_ROOMTEMP 0 +#define BD9995X_CMD_CHGOP_STATUS_BATTEMP_HOT1 1 +#define BD9995X_CMD_CHGOP_STATUS_BATTEMP_HOT2 2 +#define BD9995X_CMD_CHGOP_STATUS_BATTEMP_HOT3 3 +#define BD9995X_CMD_CHGOP_STATUS_BATTEMP_COLD1 4 +#define BD9995X_CMD_CHGOP_STATUS_BATTEMP_COLD2 5 +#define BD9995X_CMD_CHGOP_STATUS_BATTEMP_DISABLE 6 +#define BD9995X_CMD_CHGOP_STATUS_BATTEMP_BATOPEN 7 +#define BD9995X_CMD_CHGOP_STATUS_RBOOST_UV (1 << 1) + +#define BD9995X_CMD_WDT_STATUS 0x04 +#define BD9995X_CMD_CUR_ILIM_VAL 0x05 +#define BD9995X_CMD_SEL_ILIM_VAL 0x06 +#define BD9995X_CMD_EXT_IBUS_LIM_SET 0x07 +#define BD9995X_CMD_EXT_ICC_LIM_SET 0x08 +#define BD9995X_CMD_IOTG_LIM_SET 0x09 +#define BD9995X_CMD_VIN_CTRL_SET 0x0A +#define BD9995X_CMD_VIN_CTRL_SET_PP_BOTH_THRU (1 << 11) +#define BD9995X_CMD_VIN_CTRL_SET_VBUS_PRIORITY (1 << 7) +#define BD9995X_CMD_VIN_CTRL_SET_VBUS_EN (1 << 6) +#define BD9995X_CMD_VIN_CTRL_SET_VCC_EN (1 << 5) + +#define BD9995X_CMD_CHGOP_SET1 0x0B +#define BD9995X_CMD_CHGOP_SET1_ILIM_AUTO_DISEN (1 << 13) +#define BD9995X_CMD_CHGOP_SET1_VCC_BC_DISEN (1 << 11) +#define BD9995X_CMD_CHGOP_SET1_VBUS_BC_DISEN (1 << 10) +#define BD9995X_CMD_CHGOP_SET1_SDP_CHG_TRIG_EN (1 << 9) +#define BD9995X_CMD_CHGOP_SET1_SDP_CHG_TRIG (1 << 8) + +#define BD9995X_CMD_CHGOP_SET2 0x0C +#define BD9995X_CMD_CHGOP_SET2_BATT_LEARN (1 << 8) +#define BD9995X_CMD_CHGOP_SET2_CHG_EN (1 << 7) +#define BD9995X_CMD_CHGOP_SET2_USB_SUS (1 << 6) +#define BD9995X_CMD_CHGOP_SET2_DCDC_CLK_SEL (3 << 2) +#define BD9995X_CMD_CHGOP_SET2_DCDC_CLK_SEL_600 (0 << 2) +#define BD9995X_CMD_CHGOP_SET2_DCDC_CLK_SEL_857 (1 << 2) +#define BD9995X_CMD_CHGOP_SET2_DCDC_CLK_SEL_1000 (2 << 2) +#define BD9995X_CMD_CHGOP_SET2_DCDC_CLK_SEL_1200 (3 << 2) + +#define BD9995X_CMD_VBUSCLPS_TH_SET 0x0D +#define BD9995X_CMD_VCCCLPS_TH_SET 0x0E +#define BD9995X_CMD_CHGWDT_SET 0x0F +#define BD9995X_CMD_BATTWDT_SET 0x10 +#define BD9995X_CMD_VSYSREG_SET 0x11 +#define BD9995X_CMD_VSYSVAL_THH_SET 0x12 +#define BD9995X_CMD_VSYSVAL_THL_SET 0x13 +#define BD9995X_CMD_ITRICH_SET 0x14 + +#define BD9995X_CMD_IPRECH_SET 0x15 +#define BD9995X_IPRECH_MAX 1024 + +#define BD9995X_CMD_ICHG_SET 0x16 +#define BD9995X_CMD_ITERM_SET 0x17 +#define BD9995X_CMD_VPRECHG_TH_SET 0x18 +#define BD9995X_CMD_VRBOOST_SET 0x19 +#define BD9995X_CMD_VFASTCHG_REG_SET1 0x1A +#define BD9995X_CMD_VFASTCHG_REG_SET2 0x1B +#define BD9995X_CMD_VFASTCHG_REG_SET3 0x1C +#define BD9995X_CMD_VRECHG_SET 0x1D +#define BD9995X_CMD_VBATOVP_SET 0x1E +#define BD9995X_CMD_IBATSHORT_SET 0x1F +#define BD9995X_CMD_PROCHOT_CTRL_SET 0x20 +#define BD9995X_CMD_PROCHOT_CTRL_SET_PROCHOT_EN4 (1 << 4) +#define BD9995X_CMD_PROCHOT_CTRL_SET_PROCHOT_EN3 (1 << 3) +#define BD9995X_CMD_PROCHOT_CTRL_SET_PROCHOT_EN2 (1 << 2) +#define BD9995X_CMD_PROCHOT_CTRL_SET_PROCHOT_EN1 (1 << 1) +#define BD9995X_CMD_PROCHOT_CTRL_SET_PROCHOT_EN0 (1 << 0) + +#define BD9995X_CMD_PROCHOT_ICRIT_SET 0x21 +#define BD9995X_CMD_PROCHOT_INORM_SET 0x22 +#define BD9995X_CMD_PROCHOT_IDCHG_SET 0x23 +#define BD9995X_CMD_PROCHOT_VSYS_SET 0x24 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET 0x25 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_IMON_INSEL (1 << 9) +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_INSEL (1 << 8) +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_OUT_EN (1 << 7) +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_SOURCE_SEL (1 << 6) +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_MASK 0x30 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_40V 0x03 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_20V 0x02 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_10V 0x01 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_05V 0x00 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_OUT_EN (1 << 3) +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_MASK 0x07 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_64UAW 0x06 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_32UAW 0x05 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_16UAW 0x04 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_08UAW 0x03 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_04UAW 0x02 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_02UAW 0x01 +#define BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_01UAW 0x00 +#define BD9995X_PMON_IOUT_ADC_READ_COUNT 100 + +#define BD9995X_CMD_PMON_DACIN_VAL 0x26 +#define BD9995X_CMD_IOUT_DACIN_VAL 0x27 +#define BD9995X_CMD_VCC_UCD_SET 0x28 +/* Bits for both VCC_UCD_SET and VBUS_UCD_SET regs */ +#define BD9995X_CMD_UCD_SET_BCSRETRY (1 << 12) +#define BD9995X_CMD_UCD_SET_USBDETEN (1 << 7) +#define BD9995X_CMD_UCD_SET_USB_SW_EN (1 << 1) + +#define BD9995X_CMD_VCC_UCD_STATUS 0x29 +/* Bits for both VCC_UCD_STATUS and VBUS_UCD_STATUS regs */ +#define BD9995X_CMD_UCD_STATUS_DCDFAIL (1 << 15) +#define BD9995X_CMD_UCD_STATUS_CHGPORT1 (1 << 13) +#define BD9995X_CMD_UCD_STATUS_CHGPORT0 (1 << 12) +#define BD9995X_CMD_UCD_STATUS_PUPDET (1 << 11) +#define BD9995X_CMD_UCD_STATUS_CHGDET (1 << 6) +#define BD9995X_TYPE_MASK (BD9995X_CMD_UCD_STATUS_DCDFAIL | \ + BD9995X_CMD_UCD_STATUS_CHGPORT1 | \ + BD9995X_CMD_UCD_STATUS_CHGPORT0 | \ + BD9995X_CMD_UCD_STATUS_PUPDET | \ + BD9995X_CMD_UCD_STATUS_CHGDET) + +/* BC1.2 chargers */ +#define BD9995X_TYPE_CDP (BD9995X_CMD_UCD_STATUS_CHGPORT1 | \ + BD9995X_CMD_UCD_STATUS_CHGDET) +#define BD9995X_TYPE_DCP (BD9995X_CMD_UCD_STATUS_CHGPORT1 | \ + BD9995X_CMD_UCD_STATUS_CHGPORT0 | \ + BD9995X_CMD_UCD_STATUS_CHGDET) +#define BD9995X_TYPE_SDP (BD9995X_CMD_UCD_STATUS_CHGPORT0) +/* non-standard BC1.2 chargers */ +#define BD9995X_TYPE_OTHER (BD9995X_CMD_UCD_STATUS_DCDFAIL | \ + BD9995X_CMD_UCD_STATUS_CHGPORT1 | \ + BD9995X_CMD_UCD_STATUS_CHGPORT0 | \ + BD9995X_CMD_UCD_STATUS_CHGDET) +#define BD9995X_TYPE_PUP_PORT (BD9995X_CMD_UCD_STATUS_DCDFAIL | \ + BD9995X_CMD_UCD_STATUS_CHGPORT0 | \ + BD9995X_CMD_UCD_STATUS_PUPDET) +/* Open ports */ +#define BD9995X_TYPE_OPEN_PORT (BD9995X_CMD_UCD_STATUS_DCDFAIL | \ + BD9995X_CMD_UCD_STATUS_CHGPORT0) +#define BD9995X_TYPE_VBUS_OPEN 0 + +#define BD9995X_CMD_VCC_IDD_STATUS 0x2A +#define BD9995X_CMD_VCC_UCD_FCTRL_SET 0x2B +#define BD9995X_CMD_VCC_UCD_FCTRL_EN 0x2C +#define BD9995X_CMD_VBUS_UCD_SET 0x30 +#define BD9995X_CMD_VBUS_UCD_STATUS 0x31 +#define BD9995X_CMD_VBUS_IDD_STATUS 0x32 +#define BD9995X_CMD_VBUS_UCD_FCTRL_SET 0x33 +#define BD9995X_CMD_VBUS_UCD_FCTRL_EN 0x34 +#define BD9995X_CMD_CHIP_ID 0x38 +#define BD9995X_CMD_CHIP_REV 0x39 +#define BD9995X_CMD_IC_SET1 0x3A +#define BD9995X_CMD_IC_SET2 0x3B +#define BD9995X_CMD_SYSTEM_STATUS 0x3C +#define BD9995X_CMD_SYSTEM_STATUS_OTPLD_STATE (1 << 1) +#define BD9995X_CMD_SYSTEM_STATUS_ALLRST_STATE (1 << 0) + +#define BD9995X_CMD_SYSTEM_CTRL_SET 0x3D +#define BD9995X_CMD_SYSTEM_CTRL_SET_OTPLD (1 << 1) +#define BD9995X_CMD_SYSTEM_CTRL_SET_ALLRST (1 << 0) + +#define BD9995X_CMD_EXT_PROTECT_SET 0x3E +#define BD9995X_CMD_EXT_MAP_SET 0x3F +#define BD9995X_CMD_VM_CTRL_SET 0x40 +#define BD9995X_CMD_VM_CTRL_SET_EXTIADPEN (1 << 9) +#define BD9995X_CMD_THERM_WINDOW_SET1 0x41 +#define BD9995X_CMD_THERM_WINDOW_SET2 0x42 +#define BD9995X_CMD_THERM_WINDOW_SET3 0x43 +#define BD9995X_CMD_THERM_WINDOW_SET4 0x44 +#define BD9995X_CMD_THERM_WINDOW_SET5 0x45 +#define BD9995X_CMD_IBATP_TH_SET 0x46 +#define BD9995X_CMD_IBATM_TH_SET 0x47 +#define BD9995X_CMD_VBAT_TH_SET 0x48 +#define BD9995X_CMD_THERM_TH_SET 0x49 +#define BD9995X_CMD_IACP_TH_SET 0x4A +#define BD9995X_CMD_VACP_TH_SET 0x4B + +/* Enable discharge when VBUS falls below BD9995X_VBUS_DISCHARGE_TH */ +#define BD9995X_VBUS_DISCHARGE_TH 3900 +#define BD9995X_CMD_VBUS_TH_SET 0x4C +#define BD9995X_CMD_VCC_TH_SET 0x4D + +#define BD9995X_CMD_VSYS_TH_SET 0x4E +#define BD9995X_CMD_EXTIADP_TH_SET 0x4F +#define BD9995X_CMD_IBATP_VAL 0x50 +#define BD9995X_CMD_IBATP_AVE_VAL 0x51 +#define BD9995X_CMD_IBATM_VAL 0x52 +#define BD9995X_CMD_IBATM_AVE_VAL 0x53 +#define BD9995X_CMD_VBAT_VAL 0x54 +#define BD9995X_CMD_VBAT_AVE_VAL 0x55 +#define BD9995X_CMD_THERM_VAL 0x56 +#define BD9995X_CMD_VTH_VAL 0x57 +#define BD9995X_CMD_IACP_VAL 0x58 +#define BD9995X_CMD_IACP_AVE_VAL 0x59 +#define BD9995X_CMD_VACP_VAL 0x5A +#define BD9995X_CMD_VACP_AVE_VAL 0x5B +#define BD9995X_CMD_VBUS_VAL 0x5C +#define BD9995X_CMD_VBUS_AVE_VAL 0x5D +#define BD9995X_CMD_VCC_VAL 0x5E +#define BD9995X_CMD_VCC_AVE_VAL 0x5F +#define BD9995X_CMD_VSYS_VAL 0x60 +#define BD9995X_CMD_VSYS_AVE_VAL 0x61 +#define BD9995X_CMD_EXTIADP_VAL 0x62 +#define BD9995X_CMD_EXTIADP_AVE_VAL 0x63 +#define BD9995X_CMD_VACPCLPS_TH_SET 0x64 +#define BD9995X_CMD_INT0_SET 0x68 +#define BD9995X_CMD_INT0_SET_INT2_EN (1 << 2) +#define BD9995X_CMD_INT0_SET_INT1_EN (1 << 1) +#define BD9995X_CMD_INT0_SET_INT0_EN (1 << 0) + +#define BD9995X_CMD_INT1_SET 0x69 +/* Bits for both INT1 & INT2 reg */ +#define BD9995X_CMD_INT_SET_TH_DET (1 << 9) +#define BD9995X_CMD_INT_SET_TH_RES (1 << 8) +#define BD9995X_CMD_INT_SET_DET (1 << 1) +#define BD9995X_CMD_INT_SET_RES (1 << 0) +#define BD9995X_CMD_INT_VBUS_DET (BD9995X_CMD_INT_SET_RES | \ + BD9995X_CMD_INT_SET_DET) +#define BD9995X_CMD_INT_VBUS_TH (BD9995X_CMD_INT_SET_TH_RES | \ + BD9995X_CMD_INT_SET_TH_DET) + +#define BD9995X_CMD_INT2_SET 0x6A +#define BD9995X_CMD_INT3_SET 0x6B +#define BD9995X_CMD_INT4_SET 0x6C +#define BD9995X_CMD_INT5_SET 0x6D +#define BD9995X_CMD_INT6_SET 0x6E +#define BD9995X_CMD_INT7_SET 0x6F +#define BD9995X_CMD_INT0_STATUS 0x70 +#define BD9995X_CMD_INT1_STATUS 0x71 +/* Bits for both INT1_STATUS & INT2_STATUS reg */ +#define BD9995X_CMD_INT_STATUS_DET (1 << 1) +#define BD9995X_CMD_INT_STATUS_RES (1 << 0) + +#define BD9995X_CMD_INT2_STATUS 0x72 +#define BD9995X_CMD_INT3_STATUS 0x73 +#define BD9995X_CMD_INT4_STATUS 0x74 +#define BD9995X_CMD_INT5_STATUS 0x75 +#define BD9995X_CMD_INT6_STATUS 0x76 +#define BD9995X_CMD_INT7_STATUS 0x77 +#define BD9995X_CMD_REG0 0x78 +#define BD9995X_CMD_REG1 0x79 +#define BD9995X_CMD_OTPREG0 0x7A +#define BD9995X_CMD_OTPREG1 0x7B +#define BD9995X_CMD_SMBREG 0x7C +/* Normal functionality - power save mode disabled. */ +#define BD9995X_PWR_SAVE_OFF 0 +/* BGATE ON w/ PROCHOT# monitored only system voltage. */ +#define BD9995X_PWR_SAVE_LOW 0x1 +/* BGATE ON w/ PROCHOT# monitored only system voltage every 1ms. */ +#define BD9995X_PWR_SAVE_MED 0x2 +/* BGATE ON w/o PROCHOT# monitoring. */ +#define BD9995X_PWR_SAVE_HIGH 0x5 +/* BGATE OFF */ +#define BD9995X_PWR_SAVE_MAX 0x6 +#define BD9995X_CMD_DEBUG_MODE_SET 0x7F + +/* Map PD port number to charge port number */ +static inline enum bd9995x_charge_port bd9995x_pd_port_to_chg_port(int port) +{ +#ifdef CONFIG_BD9995X_PRIMARY_CHARGE_PORT_VCC + return port ? BD9995X_CHARGE_PORT_VBUS : BD9995X_CHARGE_PORT_VCC; +#else + return port ? BD9995X_CHARGE_PORT_VCC : BD9995X_CHARGE_PORT_VBUS; +#endif +} + +/* + * Non-standard interface functions - bd9995x integrates additional + * functionality not part of the standard charger interface. + */ + +/* Is VBUS provided or external power present */ +int bd9995x_is_vbus_provided(int port); +/* Select input port from {VCC, VBUS, VCC&VBUS, NONE}. */ +int bd9995x_select_input_port(enum bd9995x_charge_port port); +/* Get input current limit for BC1.2 suppliers */ +int bd9995x_get_bc12_ilim(int charge_supplier); +/* Enable/Disable charging triggered by BC1.2 */ +int bd9995x_bc12_enable_charging(enum bd9995x_charge_port port, int enable); +/* Interrupt handler for USB charger VBUS */ +void bd9995x_vbus_interrupt(enum gpio_signal signal); +/* Read temperature measurement value (in Celsius) */ +int bd9995x_get_battery_temp(int *temp_ptr); + +#endif /* __CROS_EC_BD9995X_H */ |