问题描述
RK3588取消usb-typec的pd充电功能
解决方案:
在dts中fusb302节点下usb_con: connector子节点下添加如下熟悉:
打上如下2个补丁
diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index c8a4e57c9f9b..173f8cb75b8e 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -317,6 +317,7 @@ struct tcpm_port {struct typec_partner *partner;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 cc2;
@@ -324,6 +325,7 @@ struct tcpm_port {bool attached;bool connected;
+ bool pd_supported;enum typec_port_type port_type;/*
@@ -827,6 +829,9 @@ static enum typec_cc_status tcpm_rp_cc(struct tcpm_port *port)int nr_pdo = port->nr_src_pdo;int i;+ if (!port->pd_supported)
+ return port->src_rp;
+/** Search for first entry with matching voltage.* It should report the maximum supported current.
@@ -3682,9 +3687,11 @@ static int tcpm_src_attach(struct tcpm_port *port)if (ret < 0)return ret;- ret = port->tcpc->set_pd_rx(port->tcpc, true);
- if (ret < 0)
- goto out_disable_mux;
+ if (port->pd_supported) {
+ ret = port->tcpc->set_pd_rx(port->tcpc, true);
+ if (ret < 0)
+ goto out_disable_mux;
+ }/** USB Type-C specification, version 1.2,
@@ -3715,7 +3722,8 @@ static int tcpm_src_attach(struct tcpm_port *port)out_disable_vconn:tcpm_set_vconn(port, false);out_disable_pd:
- port->tcpc->set_pd_rx(port->tcpc, false);
+ if (port->pd_supported)
+ port->tcpc->set_pd_rx(port->tcpc, false);out_disable_mux:tcpm_mux_set(port, TYPEC_STATE_SAFE, USB_ROLE_NONE,TYPEC_ORIENTATION_NONE);
@@ -3931,6 +3939,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){int ret;
@@ -4061,6 +4083,10 @@ static void run_state_machine(struct tcpm_port *port)if (port->ams == POWER_ROLE_SWAP ||port->ams == FAST_ROLE_SWAP)tcpm_ams_finish(port);
+ if (!port->pd_supported) {
+ tcpm_set_state(port, SRC_READY, 0);
+ break;
+ }port->upcoming_state = SRC_SEND_CAPABILITIES;tcpm_ams_start(port, POWER_NEGOTIATION);break;
@@ -4333,7 +4359,10 @@ static void run_state_machine(struct tcpm_port *port)current_limit = PD_P_SNK_STDBY_MW / 5;tcpm_set_current_limit(port, current_limit, 5000);tcpm_set_charge(port, true);
- tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0);
+ if (!port->pd_supported)
+ tcpm_set_state(port, SNK_READY, 0);
+ else
+ tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0);break;}/*
@@ -4582,7 +4611,8 @@ static void run_state_machine(struct tcpm_port *port)tcpm_set_vbus(port, true);if (port->ams == HARD_RESET)tcpm_ams_finish(port);
- port->tcpc->set_pd_rx(port->tcpc, true);
+ if (port->pd_supported)
+ port->tcpc->set_pd_rx(port->tcpc, true);tcpm_set_attached_state(port, true);tcpm_set_state(port, SRC_UNATTACHED, PD_T_PS_SOURCE_ON);break;
@@ -6121,6 +6151,7 @@ EXPORT_SYMBOL_GPL(tcpm_tcpc_reset);static int tcpm_fw_get_caps(struct tcpm_port *port,struct fwnode_handle *fwnode){
+ const char *opmode_str;const char *cap_str;int ret;u32 mw, frs_current, pd_revision;
@@ -6153,22 +6184,37 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,return ret;port->typec_caps.type = ret;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");if (port->port_type == TYPEC_PORT_SNK)goto sink;- /* Get source pdos */
- ret = fwnode_property_count_u32(fwnode, "source-pdos");
- if (ret <= 0)
- return -EINVAL;
+ /* 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");
+ if (ret == 0)
+ return -EINVAL;
+ else if (ret < 0)
+ return ret;- port->nr_src_pdo = min(ret, PDO_MAX_OBJECTS);
- ret = fwnode_property_read_u32_array(fwnode, "source-pdos",
- port->src_pdo, port->nr_src_pdo);
- if ((ret < 0) || tcpm_validate_caps(port, port->src_pdo,
- port->nr_src_pdo))
- return -EINVAL;
+ port->nr_src_pdo = min(ret, PDO_MAX_OBJECTS);
+ ret = fwnode_property_read_u32_array(fwnode, "source-pdos",
+ port->src_pdo, port->nr_src_pdo);
+ if (ret)
+ return ret;
+ 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)return 0;
@@ -6182,6 +6228,11 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,if (port->typec_caps.prefer_role < 0)return -EINVAL;sink:
+ port->self_powered = fwnode_property_read_bool(fwnode, "self-powered");
+
+ if (!port->pd_supported)
+ return 0;
+/* Get sink pdos */ret = fwnode_property_count_u32(fwnode, "sink-pdos");if (ret <= 0)
@@ -6198,9 +6249,7 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,return -EINVAL;port->operating_snk_mw = mw / 1000;- port->self_powered = fwnode_property_read_bool(fwnode, "self-powered");
-
- /* FRS can only be supported byb DRP ports */
+ /* FRS can only be supported by DRP ports */if (port->port_type == TYPEC_PORT_DRP) {ret = fwnode_property_read_u32(fwnode, "new-source-frs-typec-current",&frs_current);
--
diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 173f8cb75b8e..afeed1a05545 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -6512,6 +6512,13 @@ static int tcpm_psy_set_prop(struct power_supply *psy,struct tcpm_port *port = power_supply_get_drvdata(psy);int ret;+ /*
+ * All the properties below are related to USB PD. The check needs to be
+ * property specific when a non-pd related property is added.
+ */
+ if (!port->pd_supported)
+ return -EOPNOTSUPP;
+switch (psp) {case POWER_SUPPLY_PROP_ONLINE:ret = tcpm_psy_set_online(port, val);
--