summaryrefslogtreecommitdiff
path: root/driver/ppc/sn5s330.c
diff options
context:
space:
mode:
Diffstat (limited to 'driver/ppc/sn5s330.c')
-rw-r--r--driver/ppc/sn5s330.c92
1 files changed, 50 insertions, 42 deletions
diff --git a/driver/ppc/sn5s330.c b/driver/ppc/sn5s330.c
index 98c2641440..5cfbace742 100644
--- a/driver/ppc/sn5s330.c
+++ b/driver/ppc/sn5s330.c
@@ -31,16 +31,16 @@ static int source_enabled[CONFIG_USB_PD_PORT_COUNT];
static int read_reg(uint8_t port, int reg, int *regval)
{
- return i2c_read8(ppc_chips[port].i2c_port,
- ppc_chips[port].i2c_addr,
+ return i2c_read8__7bf(ppc_chips[port].i2c_port,
+ ppc_chips[port].i2c_addr__7bf,
reg,
regval);
}
static int write_reg(uint8_t port, int reg, int regval)
{
- return i2c_write8(ppc_chips[port].i2c_port,
- ppc_chips[port].i2c_addr,
+ return i2c_write8__7bf(ppc_chips[port].i2c_port,
+ ppc_chips[port].i2c_addr__7bf,
reg,
regval);
}
@@ -78,12 +78,12 @@ static int sn5s330_dump(int port)
int i;
int data;
const int i2c_port = ppc_chips[port].i2c_port;
- const int i2c_addr = ppc_chips[port].i2c_addr;
+ const uint16_t i2c_addr__7bf = ppc_chips[port].i2c_addr__7bf;
/* Flush after every set otherwise console buffer may get full. */
for (i = SN5S330_FUNC_SET1; i <= SN5S330_FUNC_SET12; i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("FUNC_SET%d [%02Xh] = 0x%02x\n",
i - SN5S330_FUNC_SET1 + 1,
i,
@@ -93,7 +93,7 @@ static int sn5s330_dump(int port)
cflush();
for (i = SN5S330_INT_STATUS_REG1; i <= SN5S330_INT_STATUS_REG4; i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("INT_STATUS_REG%d [%02Xh] = 0x%02x\n",
i - SN5S330_INT_STATUS_REG1 + 1,
i,
@@ -104,7 +104,7 @@ static int sn5s330_dump(int port)
for (i = SN5S330_INT_TRIP_RISE_REG1; i <= SN5S330_INT_TRIP_RISE_REG3;
i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("INT_TRIP_RISE_REG%d [%02Xh] = 0x%02x\n",
i - SN5S330_INT_TRIP_RISE_REG1 + 1,
i,
@@ -115,7 +115,7 @@ static int sn5s330_dump(int port)
for (i = SN5S330_INT_TRIP_FALL_REG1; i <= SN5S330_INT_TRIP_FALL_REG3;
i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("INT_TRIP_FALL_REG%d [%02Xh] = 0x%02x\n",
i - SN5S330_INT_TRIP_FALL_REG1 + 1,
i,
@@ -126,7 +126,7 @@ static int sn5s330_dump(int port)
for (i = SN5S330_INT_MASK_RISE_REG1; i <= SN5S330_INT_MASK_RISE_REG3;
i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("INT_MASK_RISE_REG%d [%02Xh] = 0x%02x\n",
i - SN5S330_INT_MASK_RISE_REG1 + 1,
i,
@@ -137,7 +137,7 @@ static int sn5s330_dump(int port)
for (i = SN5S330_INT_MASK_FALL_REG1; i <= SN5S330_INT_MASK_FALL_REG3;
i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("INT_MASK_FALL_REG%d [%02Xh] = 0x%02x\n",
i - SN5S330_INT_MASK_FALL_REG1 + 1,
i,
@@ -184,7 +184,7 @@ static int sn5s330_init(int port)
int retries;
int reg;
const int i2c_port = ppc_chips[port].i2c_port;
- const int i2c_addr = ppc_chips[port].i2c_addr;
+ const uint16_t i2c_addr__7bf = ppc_chips[port].i2c_addr__7bf;
#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT
/* Set the sourcing current limit value. */
@@ -211,8 +211,8 @@ static int sn5s330_init(int port)
*/
retries = 0;
do {
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET1,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET1, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET1! Retrying..",
port);
@@ -225,21 +225,24 @@ static int sn5s330_init(int port)
/* Set Vbus OVP threshold to ~22.325V. */
regval = 0x37;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET5, regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET5, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET5!", port);
return status;
}
/* Set Vbus UVP threshold to ~2.75V. */
- status = i2c_read8(i2c_port, i2c_addr, SN5S330_FUNC_SET6, &regval);
+ status = i2c_read8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET6, &regval);
if (status) {
CPRINTS("ppc p%d: Failed to read FUNC_SET6!", port);
return status;
}
regval &= ~0x3F;
regval |= 1;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET6, regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET6, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write FUNC_SET6!", port);
return status;
@@ -247,7 +250,8 @@ static int sn5s330_init(int port)
/* Enable SBU Fets and set PP2 current limit to ~3A. */
regval = SN5S330_SBU_EN | 0x8;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET2, regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET2, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET2!", port);
return status;
@@ -266,7 +270,8 @@ static int sn5s330_init(int port)
* low voltage protection).
*/
regval = SN5S330_OVP_EN_CC | SN5S330_PP2_CONFIG | SN5S330_CONFIG_UVP;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET9, regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET9, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET9!", port);
return status;
@@ -274,8 +279,8 @@ static int sn5s330_init(int port)
/* Set analog current limit delay to 200 us for both PP1 & PP2. */
regval = (PPX_ILIM_DEGLITCH_0_US_200 << 3) | PPX_ILIM_DEGLITCH_0_US_200;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET11,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET11, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET11", port);
return status;
@@ -288,14 +293,16 @@ static int sn5s330_init(int port)
* reset default (20 us).
*/
regval = 0;
- status = i2c_read8(i2c_port, i2c_addr, SN5S330_FUNC_SET8, &regval);
+ status = i2c_read8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET8, &regval);
if (status) {
CPRINTS("ppc p%d: Failed to read FUNC_SET8!", port);
return status;
}
regval &= ~SN5S330_VCONN_DEGLITCH_MASK;
regval |= SN5S330_VCONN_DEGLITCH_640_US;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET8, regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET8, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET8!", port);
return status;
@@ -347,8 +354,8 @@ static int sn5s330_init(int port)
* is checked below.
*/
regval = SN5S330_DIG_RES | SN5S330_VSAFE0V_MASK;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_STATUS_REG4,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_STATUS_REG4, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_STATUS_REG4!", port);
return status;
@@ -365,30 +372,30 @@ static int sn5s330_init(int port)
*/
regval = ~SN5S330_ILIM_PP1_MASK;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_RISE_REG1,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_RISE_REG1, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_RISE1!", port);
return status;
}
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_FALL_REG1,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_FALL_REG1, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_FALL1!", port);
return status;
}
/* Now mask all the other interrupts. */
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_RISE_REG2,
- 0xFF);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_RISE_REG2, 0xFF);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_RISE2!", port);
return status;
}
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_FALL_REG2,
- 0xFF);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_FALL_REG2, 0xFF);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_FALL2!", port);
return status;
@@ -401,15 +408,15 @@ static int sn5s330_init(int port)
regval = 0xFF;
#endif /* CONFIG_USB_PD_VBUS_DETECT_PPC && CONFIG_USB_CHARGER */
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_RISE_REG3,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_RISE_REG3, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_RISE3!", port);
return status;
}
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_FALL_REG3,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_FALL_REG3, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_FALL3!", port);
return status;
@@ -419,7 +426,8 @@ static int sn5s330_init(int port)
for (reg = SN5S330_INT_TRIP_RISE_REG1;
reg <= SN5S330_INT_TRIP_FALL_REG3;
reg++) {
- status = i2c_write8(i2c_port, i2c_addr, reg, 0xFF);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ reg, 0xFF);
if (status) {
CPRINTS("ppc p%d: Failed to write reg 0x%2x!", port);
return status;
@@ -431,8 +439,8 @@ static int sn5s330_init(int port)
* For PP2, check to see if we booted in dead battery mode. If we
* booted in dead battery mode, the PP2 FET will already be enabled.
*/
- status = i2c_read8(i2c_port, i2c_addr, SN5S330_INT_STATUS_REG4,
- &regval);
+ status = i2c_read8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_STATUS_REG4, &regval);
if (status) {
CPRINTS("ppc p%d: Failed to read INT_STATUS_REG4!", port);
return status;
@@ -443,8 +451,8 @@ static int sn5s330_init(int port)
* Clear the bit by writing 1 and keep vSafe0V_MASK
* unchanged.
*/
- i2c_write8(i2c_port, i2c_addr, SN5S330_INT_STATUS_REG4,
- regval);
+ i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_STATUS_REG4, regval);
/* Turn on PP2 FET. */
status = sn5s330_pp_fet_enable(port, SN5S330_PP2, 1);