diff options
author | Keith Short <keithshort@chromium.org> | 2020-07-01 17:38:40 -0600 |
---|---|---|
committer | Evan Benn <evanbenn@chromium.org> | 2020-07-02 03:50:09 +0000 |
commit | 765f30881ec3e21a5724d16ffc32e25aecfe2f24 (patch) | |
tree | 54495e2172890caac3f9fd5fb921fba5d1828e80 | |
parent | 02fa7aa3134cab7a616069e7259cb63664aa1983 (diff) | |
download | chrome-ec-765f30881ec3e21a5724d16ffc32e25aecfe2f24.tar.gz |
ppc: string de-duplication
De-duplicate strings in PPC drivers. Saves 312 bytes on Volteer.
Average flash increase of 211 bytes.
BUG=b:158572770
BRANCH=none
TEST=make buildall
Signed-off-by: Keith Short <keithshort@chromium.org>
Change-Id: I5ca5c935f974b04216ce4d90e6f6d6b9103e8b75
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2278586
Commit-Queue: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r-- | common/usbc_ppc.c | 20 | ||||
-rw-r--r-- | driver/ppc/aoz1380.c | 2 | ||||
-rw-r--r-- | driver/ppc/nx20p348x.c | 10 | ||||
-rw-r--r-- | driver/ppc/sn5s330.c | 61 | ||||
-rw-r--r-- | driver/ppc/syv682x.c | 10 | ||||
-rw-r--r-- | include/usbc_ppc.h | 17 |
6 files changed, 74 insertions, 46 deletions
diff --git a/common/usbc_ppc.c b/common/usbc_ppc.c index 17dacf7c09..765e028a65 100644 --- a/common/usbc_ppc.c +++ b/common/usbc_ppc.c @@ -16,9 +16,21 @@ #ifndef TEST_BUILD #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) + +int ppc_prints(const char *string, int port) +{ + return CPRINTS("ppc p%d %s", port, string); +} + +int ppc_err_prints(const char *string, int port, int error) +{ + return CPRINTS("ppc p%d %s (%d)", port, string, error); +} #else #define CPRINTF(args...) #define CPRINTS(args...) +#define ppc_prints(string, port) +#define ppc_err_prints(string, port, error) #endif /* @@ -46,9 +58,9 @@ int ppc_init(int port) if (ppc->drv->init) { rv = ppc->drv->init(port); if (rv) - CPRINTS("p%d: PPC init failed! (%d)", port, rv); + ppc_err_prints("init failed!", port, rv); else - CPRINTS("p%d: PPC init'd.", port); + ppc_prints("init'd.", port); } return rv; @@ -67,7 +79,7 @@ int ppc_add_oc_event(int port) atomic_clear(&connected_ports, 1 << port); if (oc_event_cnt_tbl[port] >= PPC_OC_CNT_THRESH) - CPRINTS("C%d: OC event limit reached! " + ppc_prints("OC event limit reached! " "Source path disabled until physical disconnect.", port); return EC_SUCCESS; @@ -85,7 +97,7 @@ static void clear_oc_tbl(void) if ((!(BIT(port) & connected_ports)) && oc_event_cnt_tbl[port]) { oc_event_cnt_tbl[port] = 0; - CPRINTS("C%d: OC events cleared", port); + ppc_prints("OC events cleared", port); } } DECLARE_DEFERRED(clear_oc_tbl); diff --git a/driver/ppc/aoz1380.c b/driver/ppc/aoz1380.c index 990bd41a73..67ad00c5e8 100644 --- a/driver/ppc/aoz1380.c +++ b/driver/ppc/aoz1380.c @@ -115,7 +115,7 @@ static void aoz1380_handle_interrupt(int port) /* * This is a over current/temperature condition */ - CPRINTS("C%d PPC Vbus overcurrent/temperature", port); + ppc_prints("Vbus overcurrent/temperature", port); pd_handle_overcurrent(port); } else { /* diff --git a/driver/ppc/nx20p348x.c b/driver/ppc/nx20p348x.c index 69edcafbe5..8142681bb4 100644 --- a/driver/ppc/nx20p348x.c +++ b/driver/ppc/nx20p348x.c @@ -312,7 +312,7 @@ static void nx20p348x_handle_interrupt(int port) */ if (++db_exit_fail_count[port] >= NX20P348X_DB_EXIT_FAIL_THRESHOLD) { - CPRINTS("Port %d PPC failed to exit DB mode", port); + ppc_prints("failed to exit DB mode", port); if (read_reg(port, NX20P348X_INTERRUPT1_MASK_REG, &mask_reg)) { mask_reg |= NX20P348X_INT1_DBEXIT_ERR; @@ -333,17 +333,17 @@ static void nx20p348x_handle_interrupt(int port) /* Check for 5V OC interrupt */ if (reg & NX20P348X_INT1_OC_5VSRC) { - CPRINTS("C%d: PPC detected Vbus overcurrent!", port); + ppc_prints("detected Vbus overcurrent!", port); pd_handle_overcurrent(port); } /* Check for Vbus reverse current protection */ if (reg & NX20P348X_INT1_RCP_5VSRC) - CPRINTS("C%d: PPC detected Vbus reverse current!", port); + ppc_prints("detected Vbus reverse current!", port); /* Check for Vbus short protection */ if (reg & NX20P348X_INT1_SC_5VSRC) - CPRINTS("C%d: PPC Vbus short detected!", port); + ppc_prints("Vbus short detected!", port); #ifdef CONFIG_USBC_PPC_NX20P3481 /* Check for FRS detection */ @@ -362,7 +362,7 @@ static void nx20p348x_handle_interrupt(int port) * False detect, disable SRC mode which was enabled by * NX20P3481. */ - CPRINTS("C%d: PPC FRS false detect, disabling SRC mode!", port); + ppc_prints("FRS false detect, disabling SRC mode!", port); nx20p348x_vbus_source_enable(port, 0); } #endif diff --git a/driver/ppc/sn5s330.c b/driver/ppc/sn5s330.c index 0aaabdfeca..f177efa10c 100644 --- a/driver/ppc/sn5s330.c +++ b/driver/ppc/sn5s330.c @@ -167,7 +167,7 @@ static int sn5s330_pp_fet_enable(uint8_t port, enum sn5s330_pp_idx pp, : clr_flags(port, SN5S330_FUNC_SET3, pp_bit); if (status) { - CPRINTS("ppc p%d: Failed to set FUNC_SET3!", port); + ppc_prints("Failed to set FUNC_SET3!", port); return status; } @@ -214,7 +214,7 @@ static int sn5s330_init(int port) status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_FUNC_SET1, regval); if (status) { - CPRINTS("ppc p%d: Failed to set FUNC_SET1! Retrying..", + ppc_prints("Failed to set FUNC_SET1! Retrying..", port); retries++; msleep(1); @@ -228,7 +228,7 @@ static int sn5s330_init(int port) status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_FUNC_SET5, regval); if (status) { - CPRINTS("ppc p%d: Failed to set FUNC_SET5!", port); + ppc_prints("Failed to set FUNC_SET5!", port); return status; } @@ -236,7 +236,7 @@ static int sn5s330_init(int port) status = i2c_read8(i2c_port, i2c_addr_flags, SN5S330_FUNC_SET6, ®val); if (status) { - CPRINTS("ppc p%d: Failed to read FUNC_SET6!", port); + ppc_prints("Failed to read FUNC_SET6!", port); return status; } regval &= ~0x3F; @@ -244,7 +244,7 @@ static int sn5s330_init(int port) status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_FUNC_SET6, regval); if (status) { - CPRINTS("ppc p%d: Failed to write FUNC_SET6!", port); + ppc_prints("Failed to write FUNC_SET6!", port); return status; } @@ -253,7 +253,7 @@ static int sn5s330_init(int port) status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_FUNC_SET2, regval); if (status) { - CPRINTS("ppc p%d: Failed to set FUNC_SET2!", port); + ppc_prints("Failed to set FUNC_SET2!", port); return status; } @@ -273,7 +273,7 @@ static int sn5s330_init(int port) status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_FUNC_SET9, regval); if (status) { - CPRINTS("ppc p%d: Failed to set FUNC_SET9!", port); + ppc_prints("Failed to set FUNC_SET9!", port); return status; } @@ -286,7 +286,7 @@ static int sn5s330_init(int port) status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_FUNC_SET11, regval); if (status) { - CPRINTS("ppc p%d: Failed to set FUNC_SET11", port); + ppc_prints("Failed to set FUNC_SET11", port); return status; } @@ -300,7 +300,7 @@ static int sn5s330_init(int port) status = i2c_read8(i2c_port, i2c_addr_flags, SN5S330_FUNC_SET8, ®val); if (status) { - CPRINTS("ppc p%d: Failed to read FUNC_SET8!", port); + ppc_prints("Failed to read FUNC_SET8!", port); return status; } regval &= ~SN5S330_VCONN_DEGLITCH_MASK; @@ -308,7 +308,7 @@ static int sn5s330_init(int port) status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_FUNC_SET8, regval); if (status) { - CPRINTS("ppc p%d: Failed to set FUNC_SET8!", port); + ppc_prints("Failed to set FUNC_SET8!", port); return status; } #endif /* CONFIG_USBC_PPC_VCONN */ @@ -321,7 +321,7 @@ static int sn5s330_init(int port) status = set_flags(port, SN5S330_FUNC_SET4, SN5S330_CC_EN | SN5S330_VCONN_ILIM_SEL); if (status) { - CPRINTS("ppc p%d: Failed to set FUNC_SET4!", port); + ppc_prints("Failed to set FUNC_SET4!", port); return status; } @@ -329,14 +329,14 @@ static int sn5s330_init(int port) status = set_flags(port, SN5S330_FUNC_SET3, SN5S330_SET_RCP_MODE_PP1 | SN5S330_SET_RCP_MODE_PP2); if (status) { - CPRINTS("ppc p%d: Failed to set FUNC_SET3!", port); + ppc_prints("Failed to set FUNC_SET3!", port); return status; } /* Turn off PP1 FET. */ status = sn5s330_pp_fet_enable(port, SN5S330_PP1, 0); if (status) { - CPRINTS("ppc p%d: Failed to turn off PP1 FET!", port); + ppc_prints("Failed to turn off PP1 FET!", port); } /* @@ -355,7 +355,7 @@ static int sn5s330_init(int port) status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_INT_STATUS_REG4, regval); if (status) { - CPRINTS("ppc p%d: Failed to write INT_STATUS_REG4!", port); + ppc_prints("Failed to write INT_STATUS_REG4!", port); return status; } @@ -372,14 +372,14 @@ static int sn5s330_init(int port) status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_INT_MASK_RISE_REG1, regval); if (status) { - CPRINTS("ppc p%d: Failed to write INT_MASK_RISE1!", port); + ppc_prints("Failed to write INT_MASK_RISE1!", port); return status; } status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_INT_MASK_FALL_REG1, 0xFF); if (status) { - CPRINTS("ppc p%d: Failed to write INT_MASK_FALL1!", port); + ppc_prints("Failed to write INT_MASK_FALL1!", port); return status; } @@ -388,14 +388,14 @@ static int sn5s330_init(int port) status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_INT_MASK_RISE_REG2, regval); if (status) { - CPRINTS("ppc p%d: Failed to write INT_MASK_RISE2!", port); + ppc_prints("Failed to write INT_MASK_RISE2!", port); return status; } status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_INT_MASK_FALL_REG2, 0xFF); if (status) { - CPRINTS("ppc p%d: Failed to write INT_MASK_FALL2!", port); + ppc_prints("Failed to write INT_MASK_FALL2!", port); return status; } @@ -409,14 +409,14 @@ static int sn5s330_init(int port) status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_INT_MASK_RISE_REG3, regval); if (status) { - CPRINTS("ppc p%d: Failed to write INT_MASK_RISE3!", port); + ppc_prints("Failed to write INT_MASK_RISE3!", port); return status; } status = i2c_write8(i2c_port, i2c_addr_flags, SN5S330_INT_MASK_FALL_REG3, regval); if (status) { - CPRINTS("ppc p%d: Failed to write INT_MASK_FALL3!", port); + ppc_prints("Failed to write INT_MASK_FALL3!", port); return status; } @@ -441,7 +441,7 @@ static int sn5s330_init(int port) status = i2c_read8(i2c_port, i2c_addr_flags, SN5S330_INT_STATUS_REG4, ®val); if (status) { - CPRINTS("ppc p%d: Failed to read INT_STATUS_REG4!", port); + ppc_prints("Failed to read INT_STATUS_REG4!", port); return status; } @@ -456,7 +456,7 @@ static int sn5s330_init(int port) /* Turn on PP2 FET. */ status = sn5s330_pp_fet_enable(port, SN5S330_PP2, 1); if (status) { - CPRINTS("ppc p%d: Failed to turn on PP2 FET!", port); + ppc_prints("Failed to turn on PP2 FET!", port); return status; } } @@ -472,7 +472,7 @@ static int sn5s330_is_vbus_present(int port) rv = read_reg(port, SN5S330_INT_STATUS_REG3, ®val); if (rv) { - CPRINTS("ppc p%d: VBUS present error (%d)", port, rv); + ppc_err_prints("VBUS present error", port, rv); return 0; } @@ -558,7 +558,7 @@ static int sn5s330_enter_low_power_mode(int port) SN5S330_PP1_EN | SN5S330_PP2_EN); if (rv) { - CPRINTS("ppc p%d: Could not disable both FETS (%d)", port, rv); + ppc_err_prints("Could not disable both FETS", port, rv); return rv; } @@ -566,7 +566,7 @@ static int sn5s330_enter_low_power_mode(int port) rv = clr_flags(port, SN5S330_FUNC_SET4, SN5S330_VCONN_EN); if (rv) { - CPRINTS("ppc p%d: Could not disable Vconn (%d)", port, rv); + ppc_err_prints("Could not disable Vconn", port, rv); return rv; } @@ -574,7 +574,7 @@ static int sn5s330_enter_low_power_mode(int port) rv = clr_flags(port, SN5S330_FUNC_SET2, SN5S330_SBU_EN); if (rv) { - CPRINTS("ppc p%d: Could not disable SBU path (%d)", port, rv); + ppc_err_prints("Could not disable SBU path", port, rv); return rv; } @@ -589,8 +589,7 @@ static int sn5s330_enter_low_power_mode(int port) SN5S330_FORCE_ON_VBUS_UVP); if (rv) { - CPRINTS("ppc p%d: Could not disable OVP circuit (%d)", port, - rv); + ppc_err_prints("Could not disable OVP circuit", port, rv); return rv; } @@ -658,7 +657,7 @@ static void sn5s330_handle_interrupt(int port) attempt++; if (attempt > 1) - CPRINTS("ppc p%d: Could not clear interrupts on first " + ppc_prints("Could not clear interrupts on first " "try, retrying", port); read_reg(port, SN5S330_INT_TRIP_RISE_REG1, &rise); @@ -680,11 +679,11 @@ static void sn5s330_handle_interrupt(int port) * when the VCONN overcurrent happens. */ if (rise & SN5S330_VCONN_ILIM) - CPRINTS("ppc p%d: VCONN OC!", port); + ppc_prints("VCONN OC!", port); /* Notify the system about the CC overvoltage event. */ if (rise & SN5S330_CC1_CON || rise & SN5S330_CC2_CON) { - CPRINTS("ppc p%d: CC OV!", port); + ppc_prints("CC OV!", port); pd_handle_cc_overvoltage(port); } diff --git a/driver/ppc/syv682x.c b/driver/ppc/syv682x.c index 48a24947df..c692d921e0 100644 --- a/driver/ppc/syv682x.c +++ b/driver/ppc/syv682x.c @@ -69,7 +69,7 @@ static int syv682x_wait_for_ready(int port) break; if (timestamp_expired(deadline, NULL)) { - CPRINTS("syv682x p%d: busy timeout", port); + ppc_prints("busy timeout", port); return EC_ERROR_TIMEOUT; } @@ -148,11 +148,11 @@ static void syv682x_handle_status_interrupt(int port, int regval) /* No PD handler for VBUS OVP/RVS events */ if (syv682x_interrupt_filter(port, regval, SYV682X_STATUS_OVP, SYV682X_FLAGS_OVP)) { - CPRINTS("ppc p%d: VBUS OVP!", port); + ppc_prints("VBUS OVP!", port); } if (syv682x_interrupt_filter(port, regval, SYV682X_STATUS_RVS, SYV682X_FLAGS_RVS)) { - CPRINTS("ppc p%d: VBUS Reverse Voltage!", port); + ppc_prints("VBUS Reverse Voltage!", port); } } @@ -160,12 +160,12 @@ static void syv682x_handle_control_4_interrupt(int port, int regval) { if (syv682x_interrupt_filter(port, regval, SYV682X_CONTROL_4_VCONN_OCP, SYV682X_FLAGS_VCONN_OCP)) { - CPRINTS("ppc p%d: VCONN OC!", port); + ppc_prints("VCONN OC!", port); } /* This should never happen unless something really bad happened */ if (regval & SYV682X_CONTROL_4_VBAT_OVP) { - CPRINTS("ppc p%d: VBAT OVP!", port); + ppc_prints("VBAT OVP!", port); } } diff --git a/include/usbc_ppc.h b/include/usbc_ppc.h index b794792d31..00a2911363 100644 --- a/include/usbc_ppc.h +++ b/include/usbc_ppc.h @@ -165,6 +165,23 @@ extern struct ppc_config_t ppc_chips[]; extern unsigned int ppc_cnt; /** + * Common CPRINTS implementation so that PPC driver messages are consistent. + * + * @param string: message string to display on the console. + * @param port: The Type-C port number + */ +int ppc_prints(const char *string, int port); + +/** + * Common CPRINTS for PPC drivers with an error code. + * + * @param string: message string to display on the console. + * @param port: The Type-C port number + * @param error: The error code to display at the end of the message. + */ +int ppc_err_prints(const char *string, int port, int error); + +/** * Increment the overcurrent event counter. * * @param port: The Type-C port that has overcurrented. |