diff options
author | Aseda Aboagye <aaboagye@google.com> | 2020-01-14 11:04:01 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-18 07:11:07 +0000 |
commit | 8d68c7915e0494d11b7c8564668205262fe1fe60 (patch) | |
tree | 187c5d6892a6fd336aeed10bd64779f7c64c2157 /driver/tcpm/raa489000.c | |
parent | 153afcb289a02c3d794fefd02ef5819d3a9fa669 (diff) | |
download | chrome-ec-8d68c7915e0494d11b7c8564668205262fe1fe60.tar.gz |
tcpm/raa489000: Revise the init function
The datatsheet for the RAA489000 talks about an unlock sequence that
should be done after POR. This commit adds the unlock sequence to the
init. Additionally, a number of ADCs and comparators are enabled such
that we can actually detect CC_STATUS changes along with VBUS presence.
BUG=b:147316570
BRANCH=None
TEST=build and flash on waddledoo, verify that we can read CC status and
VBUS.
Change-Id: I685febaa13c54462055909d31f95b1f8f9199eb0
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2001126
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/tcpm/raa489000.c')
-rw-r--r-- | driver/tcpm/raa489000.c | 98 |
1 files changed, 96 insertions, 2 deletions
diff --git a/driver/tcpm/raa489000.c b/driver/tcpm/raa489000.c index 30f6b768df..3948692457 100644 --- a/driver/tcpm/raa489000.c +++ b/driver/tcpm/raa489000.c @@ -5,11 +5,106 @@ * Renesas RAA489000 TCPC driver */ +#include "common.h" +#include "console.h" +#include "driver/charger/isl923x.h" #include "i2c.h" #include "raa489000.h" #include "tcpci.h" #include "tcpm.h" +#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) +#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) + +int raa489000_init(int port) +{ + int rv; + int regval; + int i2c_port; + + /* Perform unlock sequence */ + rv = tcpc_write16(port, 0xAA, 0xDAA0); + if (rv) + CPRINTS("c%d: failed unlock step1", port); + rv = tcpc_write16(port, 0xAA, 0xACE0); + if (rv) + CPRINTS("c%d: failed unlock step2", port); + rv = tcpc_write16(port, 0xAA, 0x0D0B); + if (rv) + CPRINTS("c%d: failed unlock step3", port); + + /* Note: registers may not be ready until TCPCI init succeeds */ + rv = tcpci_tcpm_init(port); + if (rv) + return rv; + + /* + * Set some vendor defined registers to enable the CC comparators and + * remove the dead battery resistors. + */ + rv = tcpc_write16(port, RAA489000_TYPEC_SETTING1, + RAA489000_SETTING1_RDOE | RAA489000_SETTING1_CC2_CMP3_EN | + RAA489000_SETTING1_CC2_CMP2_EN | + RAA489000_SETTING1_CC2_CMP1_EN | + RAA489000_SETTING1_CC1_CMP3_EN | + RAA489000_SETTING1_CC1_CMP2_EN | + RAA489000_SETTING1_CC1_CMP1_EN | + RAA489000_SETTING1_CC_DB_EN); + if (rv) + CPRINTS("c%d: failed to enable CC comparators", port); + + /* Enable the ADC */ + /* + * TODO(b:147316511) Since this register can be accessed by multiple + * tasks, we should add a mutex when modifying this register. + */ + i2c_port = tcpc_config[port].i2c_info.port; + rv = i2c_read16(i2c_port, ISL923X_ADDR_FLAGS, ISL9238_REG_CONTROL3, + ®val); + regval |= RAA489000_ENABLE_ADC; + rv |= i2c_write16(i2c_port, ISL923X_ADDR_FLAGS, ISL9238_REG_CONTROL3, + regval); + if (rv) + CPRINTS("c%d: failed to enable ADCs", port); + + /* Enable Vbus detection */ + rv = tcpc_write(port, TCPC_REG_COMMAND, + TCPC_REG_COMMAND_ENABLE_VBUS_DETECT); + if (rv) + CPRINTS("c%d: failed to enable vbus detect cmd", port); + + + /* Set Rx enable for receiver comparator */ + rv = tcpc_read16(port, RAA489000_PD_PHYSICAL_SETTING1, ®val); + regval |= RAA489000_PD_PHY_SETTING1_RECEIVER_EN | + RAA489000_PD_PHY_SETTING1_SQUELCH_EN | + RAA489000_PD_PHY_SETTING1_TX_LDO11_EN; + rv |= tcpc_write16(port, RAA489000_PD_PHYSICAL_SETTING1, regval); + if (rv) + CPRINTS("c%d: failed to set PD PHY setting1", port); + + /* Enable VBUS auto discharge. needed to goodcrc */ + rv = tcpc_read(port, TCPC_REG_POWER_CTRL, ®val); + regval |= TCPC_REG_POWER_CTRL_AUTO_DISCHARGE_DISCONNECT; + rv |= tcpc_write(port, TCPC_REG_POWER_CTRL, regval); + if (rv) + CPRINTS("c%d: failed to set auto discharge", port); + + /* The vendor says to set this setting. */ + rv = tcpc_write16(port, RAA489000_PD_PHYSICAL_PARAMETER1, 0x6C07); + if (rv) + CPRINTS("c%d: failed to set PD PHY PARAM1", port); + + /* Enable TCPCIv1.0 */ + rv = tcpc_read16(port, RAA489000_TCPC_SETTING1, ®val); + regval |= RAA489000_TCPCV1_0_EN; + rv = tcpc_write16(port, RAA489000_TCPC_SETTING1, regval); + if (rv) + CPRINTS("c%d: failed to set TCPCIv1.0 mode", port); + + return rv; +} + int raa489000_tcpm_set_cc(int port, int pull) { int rv; @@ -28,7 +123,7 @@ int raa489000_tcpm_set_cc(int port, int pull) /* RAA489000 is a TCPCI compatible port controller */ const struct tcpm_drv raa489000_tcpm_drv = { - .init = &tcpci_tcpm_init, + .init = &raa489000_init, .release = &tcpci_tcpm_release, .get_cc = &tcpci_tcpm_get_cc, #ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC @@ -54,4 +149,3 @@ const struct tcpm_drv raa489000_tcpm_drv = { .enter_low_power_mode = &tcpci_enter_low_power_mode, #endif }; - |