Skip to content

Commit 37d8435

Browse files
authored
Merge pull request #557 from FrameworkComputer/hx20-hx30
merge pull request
2 parents bb99c94 + c560e20 commit 37d8435

6 files changed

Lines changed: 96 additions & 0 deletions

File tree

board/hx30/board.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
#define CONFIG_USB_PD_REV30
177177
#define CONFIG_USB_PD_EXTENDED_MESSAGES
178178
#define CONFIG_CHARGER_DISCHARGE_ON_AC
179+
#define CONFIG_USB_PD_VBUS_CTRL_BY_PD_CHIP
179180

180181
/* Charger parameter */
181182
#define CONFIG_CHARGER_ISL9241

board/hx30/cypress5525.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static int pd_port0_1_5A;
9595
static int pd_port1_1_5A;
9696
static int pd_port2_1_5A;
9797
static int pd_port3_1_5A;
98+
static int ac_port = -1;
9899

99100
void set_pd_fw_update(bool update)
100101
{
@@ -228,6 +229,7 @@ int cypd_write_reg8_wait_ack(int controller, int reg, int data)
228229
{
229230
int rv = EC_SUCCESS;
230231
int intr_status;
232+
int event;
231233
rv = cypd_write_reg8(controller, reg, data);
232234
if (rv != EC_SUCCESS)
233235
CPRINTS("Write Reg8 0x%x fail!", reg);
@@ -237,7 +239,30 @@ int cypd_write_reg8_wait_ack(int controller, int reg, int data)
237239
return EC_ERROR_INVAL;
238240
}
239241
rv = cypd_get_int(controller, &intr_status);
242+
if (rv != EC_SUCCESS)
243+
return rv;
240244
if (intr_status & CYP5525_DEV_INTR) {
245+
CPRINTS("data = %d", data);
246+
if (data == CYP5525_AC_AT_PORT) {
247+
rv = cypd_read_reg8(controller, CYP5525_RESPONSE_REG, &event);
248+
CPRINTS("event = %d", event);
249+
if (rv != EC_SUCCESS)
250+
CPRINTS("fail to read response");
251+
switch (event) {
252+
case CYPD_RESPONSE_AC_AT_P0:
253+
ac_port = (controller * 2) + 0;
254+
break;
255+
case CYPD_RESPONSE_AC_AT_P1:
256+
ac_port = (controller * 2) + 1;
257+
break;
258+
case CYPD_RESPONSE_NO_AC:
259+
case CYPD_RESPONSE_EC_MODE:
260+
ac_port = -1;
261+
break;
262+
}
263+
CPRINTS("ac_port = %d", ac_port);
264+
} else
265+
CPRINTS("unknown event");
241266
cypd_clear_int(controller, CYP5525_DEV_INTR);
242267
}
243268
usleep(50);
@@ -1745,6 +1770,27 @@ static void update_power_limit_deferred(void)
17451770
}
17461771
DECLARE_DEFERRED(update_power_limit_deferred);
17471772

1773+
int check_power_on_port(void)
1774+
{
1775+
int rv;
1776+
1777+
/* only read CYPD when it ready */
1778+
if (pd_chip_config[0].state != CYP5525_STATE_READY)
1779+
return -1;
1780+
1781+
CPRINTS("READ C0");
1782+
rv = cypd_write_reg8_wait_ack(0, CYP5525_CUST_C_CTRL_CONTROL_REG, CYP5525_AC_AT_PORT);
1783+
if (rv != EC_SUCCESS)
1784+
return -1;
1785+
if (ac_port >= 0)
1786+
return ac_port;
1787+
CPRINTS("READ C1");
1788+
rv = cypd_write_reg8_wait_ack(1, CYP5525_CUST_C_CTRL_CONTROL_REG, CYP5525_AC_AT_PORT);
1789+
if (rv != EC_SUCCESS)
1790+
return -1;
1791+
return ac_port;
1792+
}
1793+
17481794
/**
17491795
* Set active charge port -- only one port can be active at a time.
17501796
*
@@ -1758,6 +1804,20 @@ int board_set_active_charge_port(int charge_port)
17581804
{
17591805
CPRINTS("start change port = %d, prev_charge_port = %d", charge_port, prev_charge_port);
17601806

1807+
/* if no battery, EC should not control C_CTRL */
1808+
if (board_batt_is_present() != BP_YES) {
1809+
/* check if CYPD ready */
1810+
if (charge_port == -1)
1811+
return EC_ERROR_TRY_AGAIN;
1812+
1813+
/* store current port and update power limit */
1814+
CPRINTS("No batt, no change");
1815+
prev_charge_port = charge_port;
1816+
hook_call_deferred(&update_power_limit_deferred_data, 100 * MSEC);
1817+
CPRINTS("Updating %s port %d", __func__, charge_port);
1818+
return EC_SUCCESS;
1819+
}
1820+
17611821
/* port need change, stop all power and ready to switch. */
17621822
if (prev_charge_port != -1 && prev_charge_port != charge_port) {
17631823
update_soc_power_limit(false, true);

board/hx30/cypress5525.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@
140140
#define CYP5525_P0_CY_P1_OFF 0xA2
141141
#define CYP5525_P0P1_TURN_OFF_C_CTRL 0xA3
142142

143+
#define CYP5525_AC_AT_PORT 0xC4
144+
143145
/************************************************
144146
* PD COMMAND DEFINITION
145147
* See 001-97863_0N_V.pdf from cypress for the HPI
@@ -192,6 +194,10 @@ enum cypd_response {
192194
CYPD_RESPONSE_DISCOVER_MODE_RESPONSE = 0x1A,
193195
CYPD_RESPONSE_CABLE_COMM_NOT_ALLOWED = 0x1B,
194196
CYPD_RESPONSE_EXT_SNK_CAP = 0x1C,
197+
CYPD_RESPONSE_AC_AT_P0 = 0x33,
198+
CYPD_RESPONSE_AC_AT_P1 = 0x34,
199+
CYPD_RESPONSE_NO_AC = 0x35,
200+
CYPD_RESPONSE_EC_MODE = 0x36,
195201
CYPD_RESPONSE_FWCT_IDENT_INVALID = 0x40,
196202
CYPD_RESPONSE_FWCT_INVALID_GUID = 0x41,
197203
CYPD_RESPONSE_FWCT_INVALID_VERSION = 0x42,
@@ -479,4 +485,13 @@ void cypd_ppm_port_clear(void);
479485

480486
int cypd_check_typec_port(int controller, int port);
481487

488+
/**
489+
* When chromebook power by ac only, the vbus is enabled by CYPD.
490+
* EC should not control it.
491+
* EC should read active port from CYPD and sync active port.
492+
*
493+
* @return active port
494+
*/
495+
int check_power_on_port(void);
496+
482497
#endif /* __CROS_EC_CYPRESS5525_H */

common/charge_manager.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,18 @@ static void charge_manager_get_best_charge_port(int *new_port,
575575
int best_port_power = -1, candidate_port_power;
576576
int i, j;
577577

578+
#ifdef CONFIG_USB_PD_VBUS_CTRL_BY_PD_CHIP
579+
/* If system initially power on w/o dc, CYPD will control C_CTRL */
580+
if ((charge_port == CHARGE_SUPPLIER_NONE) && (board_batt_is_present() != BP_YES)) {
581+
*new_port = check_power_on_port();
582+
CPRINTS("NO DC, choose AC by CYPD: %d", *new_port);
583+
*new_supplier = CHARGE_SUPPLIER_PD;
584+
if (*new_port == -1)
585+
*new_supplier = CHARGE_SUPPLIER_NONE;
586+
return;
587+
}
588+
#endif /* CONFIG_USB_PD_VBUS_CTRL_BY_PD_CHIP */
589+
578590
/* Skip port selection on OVERRIDE_DONT_CHARGE. */
579591
if (override_port != OVERRIDE_DONT_CHARGE) {
580592
/*

include/charge_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,6 @@ __override_proto
315315
void board_fill_source_power_info(int port,
316316
struct ec_response_usb_pd_power_info *r);
317317

318+
extern int check_power_on_port(void);
319+
318320
#endif /* __CROS_EC_CHARGE_MANAGER_H */

include/config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4315,6 +4315,12 @@
43154315
/* Define if tcpc on the board supports VBUS measurement */
43164316
#undef CONFIG_USB_PD_VBUS_MEASURE_TCPC
43174317

4318+
/*
4319+
* Define if system use stand alone pd solution.
4320+
* For stand alone solution, PD control VBUS itself, and will notify ec.
4321+
*/
4322+
#undef CONFIG_USB_PD_VBUS_CTRL_BY_PD_CHIP
4323+
43184324
/* Define the type-c port controller I2C base address. */
43194325
#define CONFIG_TCPC_I2C_BASE_ADDR_FLAGS 0x4E
43204326

0 commit comments

Comments
 (0)