pd: Move PD_DEFAULT_STATE to a common define in usb_pd.h

Servo_v4 requires the ability to have a different default state per
port. In previous devices, the assumption was that each supported port
had the same default usb pd state and power role. This CL moves the
by the default power role which in turn is derived from
CONFIG_USB_PD_DUAL_ROLE. In addiiton to moving the location, it now
uses 'port' as argument so it can be port specific if required.

PD_DEFAULT_STATE was a board.h specific config, but in practice each
instance used to date was set to PD_STATE_SNK_DISCONNECTED if
CONFIG_USB_PD_DUAL_ROLE was defined and set to
PD_STATE_SRC_DISCONNECTED otherwise.

BUG=chrome-os-partner:61878
BRANCH=servo
TEST=Manual run 'make -j buildall' to verify that all instances of
PD_DEFAULT_STATE were removed.

Change-Id: Iaf40718668732f525485ed7942ee7fc246d3f75d
Signed-off-by: Scott <scollyer@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/431787
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Scott
2017-01-24 10:55:46 -08:00
committed by Scott Collyer
parent 45817826e1
commit 44676699b0
27 changed files with 13 additions and 76 deletions

View File

@@ -185,9 +185,6 @@ enum temp_sensor_id {
TEMP_SENSOR_COUNT
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO: determine the following board specific type-C power constants */
/*
* delay to turn on the power supply max is ~16ms.

View File

@@ -78,9 +78,6 @@ enum usb_strings {
USB_STR_COUNT
};
/* we are acting only as a sink */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* we are never a source : don't care about power supply */
#define PD_POWER_SUPPLY_TURN_ON_DELAY 0 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 0 /* us */

View File

@@ -194,9 +194,6 @@ enum temp_sensor_id {
TEMP_SENSOR_COUNT
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO: determine the following board specific type-C power constants */
/*
* delay to turn on the power supply max is ~16ms.

View File

@@ -230,9 +230,6 @@ enum adc_channel {
ADC_CH_COUNT
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/*
* delay to turn on the power supply max is ~16ms.
* delay to turn off the power supply max is about ~180ms.

View File

@@ -190,9 +190,6 @@ enum als_id {
ALS_COUNT
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO: determine the following board specific type-C power constants */
/*
* delay to turn on the power supply max is ~16ms.

View File

@@ -88,9 +88,6 @@ enum usb_strings {
USB_STR_COUNT
};
/* we are acting only as a sink */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* we are never a source : don't care about power supply */
#define PD_POWER_SUPPLY_TURN_ON_DELAY 0 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 0 /* us */

View File

@@ -92,9 +92,6 @@ enum usb_strings {
#define PD_SRC_VNC PD_SRC_3_0_VNC_MV
#define PD_SRC_RD_THRESHOLD PD_SRC_3_0_RD_THRESH_MV
/* we are acting only as a source */
#define PD_DEFAULT_STATE PD_STATE_SRC_DISCONNECTED
/* delay necessary for the voltage transition on the power supply */
/* TODO (code.google.com/p/chrome-os-partner/issues/detail?id=37078)
* Need to measure these and adjust for honeybuns.

View File

@@ -59,9 +59,6 @@ extern const int supplier_priority[];
#define PD_SRC_VNC PD_SRC_DEF_VNC_MV
#define PD_SRC_RD_THRESHOLD PD_SRC_DEF_RD_THRESH_MV
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* delay necessary for the voltage transition on the power supply */
#define PD_POWER_SUPPLY_TURN_ON_DELAY 20000 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 20000 /* us */

View File

@@ -131,8 +131,6 @@ enum ec2i_setting {
#define PD_MAX_CURRENT_MA 3000
/* Try to negotiate to 20V since i2c noise problems should be fixed. */
#define PD_MAX_VOLTAGE_MV 20000
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO: determine the following board specific type-C power constants */
/*
* delay to turn on the power supply max is ~16ms.

View File

@@ -152,9 +152,6 @@
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 50000 /* us */
#define PD_VCONN_SWAP_DELAY 5000 /* us */
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* Optional features for test commands */
#define CONFIG_CMD_CHARGER_PSYS

View File

@@ -113,8 +113,6 @@ enum temp_sensor_id {
TEMP_SENSOR_COUNT
};
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* we are never a source : don't care about power supply */
#define PD_POWER_SUPPLY_TURN_ON_DELAY 0 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 0 /* us */

View File

@@ -217,9 +217,6 @@ enum als_id {
ALS_COUNT
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO: determine the following board specific type-C power constants */
/*
* delay to turn on the power supply max is ~16ms.

View File

@@ -29,9 +29,6 @@
#define CONFIG_USB_PD_PORT_COUNT 2
#define CONFIG_USB_PD_TCPM_TCPCI
/* start as a sink */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* fake board specific type-C power constants */
#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */

View File

@@ -79,9 +79,6 @@ enum board_src_cap {
#define PD_SRC_VNC PD_SRC_3_0_VNC_MV
#define PD_SNK_RD_THRESHOLD PD_SRC_3_0_RD_THRESH_MV
/* we are acting only as a sink */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* delay necessary for the voltage transition on the power supply */
#define PD_POWER_SUPPLY_TURN_ON_DELAY 50000 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 50000 /* us */

View File

@@ -222,9 +222,6 @@ enum button {
BUTTON_COUNT
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO(crosbug.com/p/61098): Verify the numbers below. */
/*
* delay to turn on the power supply max is ~16ms.

View File

@@ -292,9 +292,6 @@ enum pyro_board_version {
BOARD_VERSION_COUNT,
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO: determine the following board specific type-C power constants */
/* FIXME(dhendrix): verify all of the below PD_* numbers */
/*

View File

@@ -282,9 +282,6 @@ enum reef_board_version {
BOARD_VERSION_COUNT,
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO: determine the following board specific type-C power constants */
/* FIXME(dhendrix): verify all of the below PD_* numbers */
/*

View File

@@ -257,9 +257,6 @@ enum usb_strings {
#define PD_SRC_VNC PD_SRC_1_5_VNC_MV
#define PD_SRC_RD_THRESHOLD PD_SRC_1_5_RD_THRESH_MV
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* delay for the voltage transition on the power supply, BQ25x spec is 30ms */
#define PD_POWER_SUPPLY_TURN_ON_DELAY 40000 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 20000 /* us */

View File

@@ -119,9 +119,6 @@ enum pwm_channel {
#define PD_SRC_VNC PD_SRC_DEF_VNC_MV
#define PD_SRC_RD_THRESHOLD PD_SRC_DEF_RD_THRESH_MV
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/*
* delay to turn on the power supply max is ~16ms.
* delay to turn off the power supply max is about ~180ms.

View File

@@ -88,9 +88,6 @@
#define PD_SRC_VNC PD_SRC_DEF_VNC_MV
#define PD_SRC_RD_THRESHOLD PD_SRC_DEF_RD_THRESH_MV
/* Start as a sink for both CHG/DUT ports */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/*
* TODO(crosbug.com/p/60792): The delay values are currently just place holders
* and the delay will need to be relative to the circuitry that allows VBUS to

View File

@@ -282,9 +282,6 @@ enum snappy_board_version {
BOARD_VERSION_COUNT,
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO: determine the following board specific type-C power constants */
/* FIXME(dhendrix): verify all of the below PD_* numbers */
/*

View File

@@ -174,9 +174,6 @@ enum als_id {
ALS_COUNT,
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO: determine the following board specific type-C power constants */
/*
* delay to turn on the power supply max is ~16ms.

View File

@@ -110,9 +110,6 @@ enum usb_strings {
#define PD_SRC_VNC PD_SRC_DEF_VNC_MV
#define PD_SRC_RD_THRESHOLD PD_SRC_DEF_RD_THRESH_MV
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* delay necessary for the voltage transition on the power supply */
#define PD_POWER_SUPPLY_TURN_ON_DELAY 50000 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 50000 /* us */

View File

@@ -210,9 +210,6 @@ enum sensor_id {
BASE_GYRO,
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO: determine the following board specific type-C power constants */
/*
* delay to turn on the power supply max is ~16ms.

View File

@@ -104,9 +104,6 @@ enum adc_channel {
/* 3.0A Rp */
#define PD_SRC_VNC (PD_SRC_3_0_VNC_MV * 4096 / 3300/* 12-bit ADC, 3.3V range */)
/* we are a power supply, boot as a power source waiting for a sink */
#define PD_DEFAULT_STATE PD_STATE_SRC_DISCONNECTED
/* delay necessary for the voltage transition on the power supply */
#define PD_POWER_SUPPLY_TURN_ON_DELAY 50000 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 50000 /* us */

View File

@@ -1599,7 +1599,7 @@ void pd_task(void)
/* Initialize TCPM driver and wait for TCPC to be ready */
res = tcpm_init(port);
CPRINTS("TCPC p%d init %s", port, res ? "failed" : "ready");
this_state = res ? PD_STATE_SUSPENDED : PD_DEFAULT_STATE;
this_state = res ? PD_STATE_SUSPENDED : PD_DEFAULT_STATE(port);
#ifdef CONFIG_USB_PD_DUAL_ROLE
/*
@@ -1705,7 +1705,7 @@ void pd_task(void)
/* Ensure state variables are at default */
pd[port].power_role = PD_ROLE_DEFAULT;
pd[port].vdm_state = VDM_STATE_DONE;
set_state(port, PD_DEFAULT_STATE);
set_state(port, PD_DEFAULT_STATE(port));
}
}
#endif
@@ -2989,7 +2989,8 @@ void pd_set_suspend(int port, int enable)
int tries = 3;
do {
set_state(port, enable ? PD_STATE_SUSPENDED : PD_DEFAULT_STATE);
set_state(port, enable ? PD_STATE_SUSPENDED :
PD_DEFAULT_STATE(port));
task_wake(PD_PORT_TO_TASK_ID(port));
} while (enable && pd[port].task_state != PD_STATE_SUSPENDED
&& --tries);

View File

@@ -818,6 +818,15 @@ enum pd_data_msg_type {
#define PD_ROLE_DEFAULT PD_ROLE_SOURCE
#endif
/* Port default state at startup */
#ifdef CONFIG_USB_PD_DUAL_ROLE
#define PD_DEFAULT_STATE(port) ((PD_ROLE_DEFAULT == PD_ROLE_SOURCE) ? \
PD_STATE_SRC_DISCONNECTED : \
PD_STATE_SNK_DISCONNECTED)
#else
#define PD_DEFAULT_STATE(port) PD_STATE_SRC_DISCONNECTED
#endif
/* build message header */
#define PD_HEADER(type, prole, drole, id, cnt) \
((type) | (PD_REV20 << 6) | \