usb: typec: tcpm: Support non-PD mode
Even if the Type-C controller supports PD, it is doable to disable PD capabilities with the current state machine in TCPM. Without enabling RX in low-level drivers and with skipping the power negotiation, the port is eligible to be a non-PD Type-C port. Use new flags whose values are populated from the device tree to decide the port PD capability. Adding "pd-disable" property in device tree indicates that the port does not support PD. If PD is not supported, the device tree property "typec-power-opmode" shall be added to specify the advertised Rp value if the port supports SRC role. Reviewed-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Signed-off-by: Kyle Tso <kyletso@google.com> Link: https://lore.kernel.org/r/20210804081917.3390341-3-kyletso@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
7a4440bc0d
commit
e9e6e164ed
1 changed files with 68 additions and 19 deletions
|
@ -316,6 +316,7 @@ struct tcpm_port {
|
||||||
struct typec_partner *partner;
|
struct typec_partner *partner;
|
||||||
|
|
||||||
enum typec_cc_status cc_req;
|
enum typec_cc_status cc_req;
|
||||||
|
enum typec_cc_status src_rp; /* work only if pd_supported == false */
|
||||||
|
|
||||||
enum typec_cc_status cc1;
|
enum typec_cc_status cc1;
|
||||||
enum typec_cc_status cc2;
|
enum typec_cc_status cc2;
|
||||||
|
@ -323,6 +324,7 @@ struct tcpm_port {
|
||||||
|
|
||||||
bool attached;
|
bool attached;
|
||||||
bool connected;
|
bool connected;
|
||||||
|
bool pd_supported;
|
||||||
enum typec_port_type port_type;
|
enum typec_port_type port_type;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -815,6 +817,9 @@ static enum typec_cc_status tcpm_rp_cc(struct tcpm_port *port)
|
||||||
int nr_pdo = port->nr_src_pdo;
|
int nr_pdo = port->nr_src_pdo;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (!port->pd_supported)
|
||||||
|
return port->src_rp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Search for first entry with matching voltage.
|
* Search for first entry with matching voltage.
|
||||||
* It should report the maximum supported current.
|
* It should report the maximum supported current.
|
||||||
|
@ -3568,9 +3573,11 @@ static int tcpm_src_attach(struct tcpm_port *port)
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
if (port->pd_supported) {
|
||||||
ret = port->tcpc->set_pd_rx(port->tcpc, true);
|
ret = port->tcpc->set_pd_rx(port->tcpc, true);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_disable_mux;
|
goto out_disable_mux;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* USB Type-C specification, version 1.2,
|
* USB Type-C specification, version 1.2,
|
||||||
|
@ -3600,6 +3607,7 @@ static int tcpm_src_attach(struct tcpm_port *port)
|
||||||
out_disable_vconn:
|
out_disable_vconn:
|
||||||
tcpm_set_vconn(port, false);
|
tcpm_set_vconn(port, false);
|
||||||
out_disable_pd:
|
out_disable_pd:
|
||||||
|
if (port->pd_supported)
|
||||||
port->tcpc->set_pd_rx(port->tcpc, false);
|
port->tcpc->set_pd_rx(port->tcpc, false);
|
||||||
out_disable_mux:
|
out_disable_mux:
|
||||||
tcpm_mux_set(port, TYPEC_STATE_SAFE, USB_ROLE_NONE,
|
tcpm_mux_set(port, TYPEC_STATE_SAFE, USB_ROLE_NONE,
|
||||||
|
@ -3804,6 +3812,20 @@ static enum typec_pwr_opmode tcpm_get_pwr_opmode(enum typec_cc_status cc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static enum typec_cc_status tcpm_pwr_opmode_to_rp(enum typec_pwr_opmode opmode)
|
||||||
|
{
|
||||||
|
switch (opmode) {
|
||||||
|
case TYPEC_PWR_MODE_USB:
|
||||||
|
return TYPEC_CC_RP_DEF;
|
||||||
|
case TYPEC_PWR_MODE_1_5A:
|
||||||
|
return TYPEC_CC_RP_1_5;
|
||||||
|
case TYPEC_PWR_MODE_3_0A:
|
||||||
|
case TYPEC_PWR_MODE_PD:
|
||||||
|
default:
|
||||||
|
return TYPEC_CC_RP_3_0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void run_state_machine(struct tcpm_port *port)
|
static void run_state_machine(struct tcpm_port *port)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -3914,6 +3936,10 @@ static void run_state_machine(struct tcpm_port *port)
|
||||||
if (port->ams == POWER_ROLE_SWAP ||
|
if (port->ams == POWER_ROLE_SWAP ||
|
||||||
port->ams == FAST_ROLE_SWAP)
|
port->ams == FAST_ROLE_SWAP)
|
||||||
tcpm_ams_finish(port);
|
tcpm_ams_finish(port);
|
||||||
|
if (!port->pd_supported) {
|
||||||
|
tcpm_set_state(port, SRC_READY, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
port->upcoming_state = SRC_SEND_CAPABILITIES;
|
port->upcoming_state = SRC_SEND_CAPABILITIES;
|
||||||
tcpm_ams_start(port, POWER_NEGOTIATION);
|
tcpm_ams_start(port, POWER_NEGOTIATION);
|
||||||
break;
|
break;
|
||||||
|
@ -4161,6 +4187,9 @@ static void run_state_machine(struct tcpm_port *port)
|
||||||
current_lim = PD_P_SNK_STDBY_MW / 5;
|
current_lim = PD_P_SNK_STDBY_MW / 5;
|
||||||
tcpm_set_current_limit(port, current_lim, 5000);
|
tcpm_set_current_limit(port, current_lim, 5000);
|
||||||
tcpm_set_charge(port, true);
|
tcpm_set_charge(port, true);
|
||||||
|
if (!port->pd_supported)
|
||||||
|
tcpm_set_state(port, SNK_READY, 0);
|
||||||
|
else
|
||||||
tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0);
|
tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4389,6 +4418,7 @@ static void run_state_machine(struct tcpm_port *port)
|
||||||
tcpm_set_vbus(port, true);
|
tcpm_set_vbus(port, true);
|
||||||
if (port->ams == HARD_RESET)
|
if (port->ams == HARD_RESET)
|
||||||
tcpm_ams_finish(port);
|
tcpm_ams_finish(port);
|
||||||
|
if (port->pd_supported)
|
||||||
port->tcpc->set_pd_rx(port->tcpc, true);
|
port->tcpc->set_pd_rx(port->tcpc, true);
|
||||||
tcpm_set_attached_state(port, true);
|
tcpm_set_attached_state(port, true);
|
||||||
tcpm_set_state(port, SRC_UNATTACHED, PD_T_PS_SOURCE_ON);
|
tcpm_set_state(port, SRC_UNATTACHED, PD_T_PS_SOURCE_ON);
|
||||||
|
@ -5898,6 +5928,7 @@ EXPORT_SYMBOL_GPL(tcpm_tcpc_reset);
|
||||||
static int tcpm_fw_get_caps(struct tcpm_port *port,
|
static int tcpm_fw_get_caps(struct tcpm_port *port,
|
||||||
struct fwnode_handle *fwnode)
|
struct fwnode_handle *fwnode)
|
||||||
{
|
{
|
||||||
|
const char *opmode_str;
|
||||||
const char *cap_str;
|
const char *cap_str;
|
||||||
int ret;
|
int ret;
|
||||||
u32 mw, frs_current;
|
u32 mw, frs_current;
|
||||||
|
@ -5932,22 +5963,37 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,
|
||||||
return ret;
|
return ret;
|
||||||
port->typec_caps.type = ret;
|
port->typec_caps.type = ret;
|
||||||
port->port_type = port->typec_caps.type;
|
port->port_type = port->typec_caps.type;
|
||||||
|
port->pd_supported = !fwnode_property_read_bool(fwnode, "pd-disable");
|
||||||
|
|
||||||
port->slow_charger_loop = fwnode_property_read_bool(fwnode, "slow-charger-loop");
|
port->slow_charger_loop = fwnode_property_read_bool(fwnode, "slow-charger-loop");
|
||||||
if (port->port_type == TYPEC_PORT_SNK)
|
if (port->port_type == TYPEC_PORT_SNK)
|
||||||
goto sink;
|
goto sink;
|
||||||
|
|
||||||
/* Get source pdos */
|
/* Get Source PDOs for the PD port or Source Rp value for the non-PD port */
|
||||||
|
if (port->pd_supported) {
|
||||||
ret = fwnode_property_count_u32(fwnode, "source-pdos");
|
ret = fwnode_property_count_u32(fwnode, "source-pdos");
|
||||||
if (ret <= 0)
|
if (ret == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
else if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
port->nr_src_pdo = min(ret, PDO_MAX_OBJECTS);
|
port->nr_src_pdo = min(ret, PDO_MAX_OBJECTS);
|
||||||
ret = fwnode_property_read_u32_array(fwnode, "source-pdos",
|
ret = fwnode_property_read_u32_array(fwnode, "source-pdos",
|
||||||
port->src_pdo, port->nr_src_pdo);
|
port->src_pdo, port->nr_src_pdo);
|
||||||
if ((ret < 0) || tcpm_validate_caps(port, port->src_pdo,
|
if (ret)
|
||||||
port->nr_src_pdo))
|
return ret;
|
||||||
return -EINVAL;
|
ret = tcpm_validate_caps(port, port->src_pdo, port->nr_src_pdo);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
} else {
|
||||||
|
ret = fwnode_property_read_string(fwnode, "typec-power-opmode", &opmode_str);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
ret = typec_find_pwr_opmode(opmode_str);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
port->src_rp = tcpm_pwr_opmode_to_rp(ret);
|
||||||
|
}
|
||||||
|
|
||||||
if (port->port_type == TYPEC_PORT_SRC)
|
if (port->port_type == TYPEC_PORT_SRC)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -5961,6 +6007,11 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,
|
||||||
if (port->typec_caps.prefer_role < 0)
|
if (port->typec_caps.prefer_role < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
sink:
|
sink:
|
||||||
|
port->self_powered = fwnode_property_read_bool(fwnode, "self-powered");
|
||||||
|
|
||||||
|
if (!port->pd_supported)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* Get sink pdos */
|
/* Get sink pdos */
|
||||||
ret = fwnode_property_count_u32(fwnode, "sink-pdos");
|
ret = fwnode_property_count_u32(fwnode, "sink-pdos");
|
||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
|
@ -5977,9 +6028,7 @@ sink:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
port->operating_snk_mw = mw / 1000;
|
port->operating_snk_mw = mw / 1000;
|
||||||
|
|
||||||
port->self_powered = fwnode_property_read_bool(fwnode, "self-powered");
|
/* FRS can only be supported by DRP ports */
|
||||||
|
|
||||||
/* FRS can only be supported byb DRP ports */
|
|
||||||
if (port->port_type == TYPEC_PORT_DRP) {
|
if (port->port_type == TYPEC_PORT_DRP) {
|
||||||
ret = fwnode_property_read_u32(fwnode, "new-source-frs-typec-current",
|
ret = fwnode_property_read_u32(fwnode, "new-source-frs-typec-current",
|
||||||
&frs_current);
|
&frs_current);
|
||||||
|
|
Loading…
Add table
Reference in a new issue