staging: typec: tcpci: move out of staging
Subsystems (5)
PATCH v8 1/14 dt-bindings: connector: add properties for typec
In reply to Li JunAdd bindings supported by current typec driver, so user can pass all those properties via dt.
--- .../bindings/connector/usb-connector.txt | 44 +++++++++++++++ include/dt-bindings/usb/pd.h | 62 ++++++++++++++++++++++ 2 files changed, 106 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.txt +44 -0
@@ -15,6 +15,33 @@ Optional properties: - type: size of the connector, should be specified in case of USB-A, USB-B non-fullsize connectors: "mini", "micro". +Optional properties for usb-c-connector: +- power-role: should be one of "source", "sink" or "dual"(DRP) if typec + connector has power support. +- try-power-role: preferred power role if "dual"(DRP) can support Try.SNK + or Try.SRC, should be "sink" for Try.SNK or "source" for Try.SRC. +- data-role: should be one of "host", "device", "dual"(DRD) if typec + connector supports USB data. + +Required properties for usb-c-connector with power delivery support: +- source-pdos: An array of u32 with each entry providing supported power + source data object(PDO), the detailed bit definitions of PDO can be found + in "Universal Serial Bus Power Delivery Specification" chapter 6.4.1.2 + Source_Capabilities Message, the order of each entry(PDO) should follow + the PD spec chapter 6.4.1. Required for power source and power dual role. + User can specify the source PDO array via PDO_FIXED/BATT/VAR() defined in + dt-bindings/usb/pd.h. +- sink-pdos: An array of u32 with each entry providing supported power + sink data object(PDO), the detailed bit definitions of PDO can be found + in "Universal Serial Bus Power Delivery Specification" chapter 6.4.1.3 + Sink Capabilities Message, the order of each entry(PDO) should follow + the PD spec chapter 6.4.1. Required for power sink and power dual role. + User can specify the sink PDO array via PDO_FIXED/BATT/VAR() defined in + dt-bindings/usb/pd.h. +- op-sink-microwatt: Sink required operating power in microwatt, if source + can't offer the power, Capability Mismatch is set. Required for power + sink and power dual role. + Required nodes: - any data bus to the connector should be modeled using the OF graph bindings specified in bindings/graph.txt, unless the bus is between parent node and
@@ -73,3 +100,20 @@ ccic: s2mm005@33 { }; }; }; + +3. USB-C connector attached to a typec port controller(ptn5110), which has +power delivery support and enables drp. + +typec: ptn5110@50 { + ... + usb_con: connector { + compatible = "usb-c-connector"; + label = "USB-C"; + power-role = "dual"; + try-power-role = "sink"; + source-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM)>; + sink-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM) + PDO_VAR(5000, 12000, 2000)>; + op-sink-microwatt = <10000000>; + }; +};
include/dt-bindings/usb/pd.h new file +62 -0
62 lines not on this page · raw message
PATCH v8 2/14 dt-bindings: usb: add documentation for typec port controller(TCPCI)
In reply to Li JunTCPCI stands for typec port controller interface, its implementation has full typec port control with power delivery support, it's a standard i2c slave with GPIO input as irq interface, detail see spec "Universal Serial Bus Type-C Port Controller Interface Specification Revision 1.0, Version 1.1"
--- .../devicetree/bindings/usb/typec-tcpci.txt | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+)
Documentation/devicetree/bindings/usb/typec-tcpci.txt new file +49 -0
@@ -0,0 +1,49 @@ +TCPCI(Typec port cotroller interface) binding +--------------------------------------------- + +Required properties: +- compatible: should be set one of following: + - "nxp,ptn5110" for NXP USB PD TCPC PHY IC ptn5110. + +- reg: the i2c slave address of typec port controller device. +- interrupt-parent: the phandle to the interrupt controller which provides + the interrupt. +- interrupts: interrupt specification for tcpci alert. + +Required sub-node: +- connector: The "usb-c-connector" attached to the tcpci chip, the bindings + of connector node are specified in + Documentation/devicetree/bindings/connector/usb-connector.txt + +Example: + +ptn5110@50 { + compatible = "nxp,ptn5110"; + reg = <0x50>; + interrupt-parent = <&gpio3>; + interrupts = <3 IRQ_TYPE_LEVEL_LOW>; + + usb_con: connector { + compatible = "usb-c-connector"; + label = "USB-C"; + data-role = "dual"; + power-role = "dual"; + try-power-role = "sink"; + source-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM)>; + sink-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM) + PDO_VAR(5000, 12000, 2000)>; + op-sink-microwatt = <10000000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + usb_con_ss: endpoint { + remote-endpoint = <&usb3_data_ss>; + }; + }; + }; + }; +};
PATCH v8 3/14 staging: typec: tcpci: add compatible string for nxp ptn5110
In reply to Li JunAdd nxp ptn5110 typec controller compatible string: "nxp,ptn5110", which is a standard tcpci chip with power delivery support. Meanwhile remove "usb,tcpci" because it doesn't follow the binding format rule and has not been used yet.
--- drivers/staging/typec/tcpci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/typec/tcpci.c +1 -1
@@ -575,7 +575,7 @@ MODULE_DEVICE_TABLE(i2c, tcpci_id);#ifdef CONFIG_OF static const struct of_device_id tcpci_of_match[] = { - { .compatible ="usb,tcpci" , }, + { .compatible ="nxp,ptn5110" , }, {}, };MODULE_DEVICE_TABLE (of, tcpci_of_match);
PATCH v8 4/14 usb: typec: add fwnode to tcpc
In reply to Li JunAdd fwnode handle to get the fwnode so we can get typec configs it contains.
--- drivers/staging/typec/tcpci.c | 7 +++++++ drivers/usb/typec/tcpm.c | 1 + include/linux/usb/tcpm.h | 2 ++ 3 files changed, 10 insertions(+)
drivers/staging/typec/tcpci.c +7 -0
@@ -10,6 +10,7 @@#include <linux/module.h> #include <linux/i2c.h> #include <linux/interrupt.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/usb/pd.h> #include <linux/usb/tcpm.h>
@@ -474,6 +475,12 @@ static int tcpci_parse_config(struct tcpci *tcpci)/* TODO: Populate struct tcpc_config from ACPI/device-tree */ tcpci->tcpc.config = &tcpci_tcpc_config; + tcpci->tcpc.fwnode =device_get_named_child_node (tcpci->dev, +"connector" ); +if (!tcpci->tcpc.fwnode) { +dev_err (tcpci->dev,"Can't find connector node.\n" ); +return -EINVAL ; + }return 0 ; }
drivers/usb/typec/tcpm.c +1 -0
@@ -4576,6 +4576,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)else port->try_role =TYPEC_NO_PREFERRED_ROLE ; + port->typec_caps.fwnode = tcpc->fwnode; port->typec_caps.prefer_role = tcpc->config->default_role; port->typec_caps.type = tcpc->config->type; port->typec_caps.data = tcpc->config->data;
include/linux/usb/tcpm.h +2 -0
@@ -110,6 +110,7 @@ enum tcpc_mux_mode {/** * struct tcpc_dev - Port configuration and callback functions * @config: Pointer to port configuration +* @fwnode: Pointer to port fwnode * @get_vbus: Called to read current VBUS state * @get_current_limit: * Optional; called by the tcpm core when configured as a snk
@@ -138,6 +139,7 @@ enum tcpc_mux_mode {*/ struct tcpc_dev {const struct tcpc_config *config; +struct fwnode_handle *fwnode;int (*init)(struct tcpc_dev *dev);int (*get_vbus)(struct tcpc_dev *dev);
PATCH v8 5/14 usb: typec: add API to get typec basic port power and data config
In reply to Li JunThis patch adds 3 APIs to get the typec port power and data type, and preferred power role by its name string.
--- drivers/usb/typec/class.c | 58 +++++++++++++++++++++++++++++++++++++++++++---- include/linux/usb/typec.h | 3 +++ 2 files changed, 57 insertions(+), 4 deletions(-)
drivers/usb/typec/class.c +54 -4
@@ -796,12 +796,18 @@ static const char * const typec_data_roles[] = { [TYPEC_HOST] = "host", }; -static const char *const typec_port_types[] = { +static const char *const typec_port_power_roles[] = { [TYPEC_PORT_SRC ] ="source" , [TYPEC_PORT_SNK ] ="sink" , [TYPEC_PORT_DRP ] ="dual" , }; +static const char *const typec_port_data_roles[] = { + [TYPEC_PORT_DFP ] ="host" , + [TYPEC_PORT_UFP ] ="device" , + [TYPEC_PORT_DRD ] ="dual" , +}; +static const char *const typec_port_types_drp[] = { [TYPEC_PORT_SRC ] ="dual [source] sink" , [TYPEC_PORT_SNK ] ="dual source [sink]" ,
@@ -932,7 +938,7 @@ static ssize_t power_role_store(struct device *dev,mutex_lock (&port->port_type_lock);if (port->port_type !=TYPEC_PORT_DRP ) {dev_dbg (dev,"port type fixed at \"%s\"" , - typec_port_types[port->port_type]); + typec_port_power_roles[port->port_type]); ret = -EOPNOTSUPP ; goto unlock_and_ret; }
@@ -973,7 +979,7 @@ port_type_store(struct device *dev, struct device_attribute *attr,return -EOPNOTSUPP ; } - ret =sysfs_match_string (typec_port_types, buf); + ret =sysfs_match_string (typec_port_power_roles, buf);if (ret <0 )return ret;
@@ -1007,7 +1013,7 @@ port_type_show(struct device *dev, struct device_attribute *attr,return sprintf (buf,"%s\n" , typec_port_types_drp[port->port_type]); -return sprintf (buf,"[%s]\n" , typec_port_types[port->cap->type]); +return sprintf (buf,"[%s]\n" , typec_port_power_roles[port->cap->type]); }static DEVICE_ATTR_RW (port_type);
@@ -1252,6 +1258,50 @@ void typec_set_pwr_opmode(struct typec_port *port, }EXPORT_SYMBOL_GPL (typec_set_pwr_opmode); +/** +* typec_find_port_power_role - Get the typec port power capability +* @name: port power capability string +* +* This routine is used to find the typec_port_type by its string name. +* +* Returns typec_port_type if success, otherwise negative error code. +*/ +int typec_find_port_power_role (const char *name) +{ +return match_string (typec_port_power_roles, +ARRAY_SIZE (typec_port_power_roles), name); +} +EXPORT_SYMBOL_GPL (typec_find_port_power_role); + +/** +* typec_find_power_role - Find the typec one specific power role +* @name: power role string +* +* This routine is used to find the typec_role by its string name. +* +* Returns typec_role if success, otherwise negative error code. +*/ +int typec_find_power_role (const char *name) +{ +return match_string (typec_roles,ARRAY_SIZE (typec_roles), name); +} +EXPORT_SYMBOL_GPL (typec_find_power_role); + +/** +* typec_find_port_data_role - Get the typec port data capability +* @name: port data capability string +* +* This routine is used to find the typec_port_data by its string name. +* +* Returns typec_port_data if success, otherwise negative error code. +*/ +int typec_find_port_data_role (const char *name) +{ +return match_string (typec_port_data_roles, +ARRAY_SIZE (typec_port_data_roles), name); +} +EXPORT_SYMBOL_GPL (typec_find_port_data_role); +/* ------------------------------------------ */ /* API for Multiplexer/DeMultiplexer Switches */
include/linux/usb/typec.h +3 -0
@@ -267,4 +267,7 @@ int typec_set_orientation(struct typec_port *port, enum typec_orientation orientation);int typec_set_mode (struct typec_port *port,int mode); +int typec_find_port_power_role (const char *name); +int typec_find_power_role (const char *name); +int typec_find_port_data_role (const char *name);#endif /* __LINUX_USB_TYPEC_H */
PATCH v8 6/14 usb: typec: tcpm: support get typec and pd config from device properties
In reply to Li JunThis patch adds support of get typec and power delivery config from firmware description.
--- drivers/usb/typec/tcpm.c | 131 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 109 insertions(+), 22 deletions(-)
drivers/usb/typec/tcpm.c +109 -22
@@ -4236,6 +4236,81 @@ static int tcpm_copy_vdos(u32 *dest_vdo, const u32 *src_vdo,return nr_vdo; } +static int tcpm_fw_get_caps (struct tcpm_port *port, +struct fwnode_handle *fwnode) +{ +const char *cap_str; +int ret; +u32 mw; + +if (!fwnode) +return -EINVAL ; + +/* USB data support is optional */ + ret =fwnode_property_read_string (fwnode,"data-role" , &cap_str); +if (ret ==0 ) { + port->typec_caps.data =typec_find_port_data_role (cap_str); +if (port->typec_caps.data <0 ) +return -EINVAL ; + } + + ret =fwnode_property_read_string (fwnode,"power-role" , &cap_str); +if (ret <0 ) +return ret; + + port->typec_caps.type =typec_find_port_power_role (cap_str); +if (port->typec_caps.type <0 ) +return -EINVAL ; + port->port_type = port->typec_caps.type; + +if (port->port_type ==TYPEC_PORT_SNK ) + goto sink; + +/* Get source pdos */ + ret =fwnode_property_read_u32_array (fwnode,"source-pdos" , +NULL ,0 ); +if (ret <=0 ) +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 <0 ) ||tcpm_validate_caps (port, port->src_pdo, + port->nr_src_pdo)) +return -EINVAL ; + +if (port->port_type ==TYPEC_PORT_SRC ) +return 0 ; + +/* Get the preferred power role for DRP */ + ret =fwnode_property_read_string (fwnode,"try-power-role" , &cap_str); +if (ret <0 ) +return ret; + + port->typec_caps.prefer_role =typec_find_power_role (cap_str); +if (port->typec_caps.prefer_role <0 ) +return -EINVAL ; +sink: +/* Get sink pdos */ + ret =fwnode_property_read_u32_array (fwnode,"sink-pdos" , +NULL ,0 ); +if (ret <=0 ) +return -EINVAL ; + + port->nr_snk_pdo =min (ret,PDO_MAX_OBJECTS ); + ret =fwnode_property_read_u32_array (fwnode,"sink-pdos" , + port->snk_pdo, port->nr_snk_pdo); +if ((ret <0 ) ||tcpm_validate_caps (port, port->snk_pdo, + port->nr_snk_pdo)) +return -EINVAL ; + +if (fwnode_property_read_u32 (fwnode,"op-sink-microwatt" , &mw) <0 ) +return -EINVAL ; + port->operating_snk_mw = mw /1000 ; + +return 0 ; +} +int tcpm_update_source_capabilities (struct tcpm_port *port,const u32 *pdo,unsigned int nr_pdo) {
@@ -4521,12 +4596,36 @@ static int devm_tcpm_psy_register(struct tcpm_port *port)return PTR_ERR_OR_ZERO (port->psy); } +static int tcpm_copy_caps (struct tcpm_port *port, +const struct tcpc_config *tcfg) +{ +if (tcpm_validate_caps (port, tcfg->src_pdo, tcfg->nr_src_pdo) || +tcpm_validate_caps (port, tcfg->snk_pdo, tcfg->nr_snk_pdo)) +return -EINVAL ; + + port->nr_src_pdo =tcpm_copy_pdos (port->src_pdo, tcfg->src_pdo, + tcfg->nr_src_pdo); + port->nr_snk_pdo =tcpm_copy_pdos (port->snk_pdo, tcfg->snk_pdo, + tcfg->nr_snk_pdo); + + port->nr_snk_vdo =tcpm_copy_vdos (port->snk_vdo, tcfg->snk_vdo, + tcfg->nr_snk_vdo); + + port->operating_snk_mw = tcfg->operating_snk_mw; + + port->typec_caps.prefer_role = tcfg->default_role; + port->typec_caps.type = tcfg->type; + port->typec_caps.data = tcfg->data; + +return 0 ; +} +struct tcpm_port *tcpm_register_port (struct device *dev,struct tcpc_dev *tcpc) {struct tcpm_port *port;int i, err; -if (!dev || !tcpc || !tcpc->config || +if (!dev || !tcpc || !tcpc->get_vbus || !tcpc->set_cc || !tcpc->get_cc || !tcpc->set_polarity || !tcpc->set_vconn || !tcpc->set_vbus || !tcpc->set_pd_rx || !tcpc->set_roles || !tcpc->pd_transmit)
@@ -4556,30 +4655,18 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)init_completion (&port->pps_complete);tcpm_debugfs_init (port); -if (tcpm_validate_caps (port, tcpc->config->src_pdo, - tcpc->config->nr_src_pdo) || -tcpm_validate_caps (port, tcpc->config->snk_pdo, - tcpc->config->nr_snk_pdo)) { - err = -EINVAL ; + err =tcpm_fw_get_caps (port, tcpc->fwnode); +if ((err <0 ) && tcpc->config) + err =tcpm_copy_caps (port, tcpc->config); +if (err <0 ) goto out_destroy_wq; - } - port->nr_src_pdo =tcpm_copy_pdos (port->src_pdo, tcpc->config->src_pdo, - tcpc->config->nr_src_pdo); - port->nr_snk_pdo =tcpm_copy_pdos (port->snk_pdo, tcpc->config->snk_pdo, - tcpc->config->nr_snk_pdo); - port->nr_snk_vdo =tcpm_copy_vdos (port->snk_vdo, tcpc->config->snk_vdo, - tcpc->config->nr_snk_vdo); - - port->operating_snk_mw = tcpc->config->operating_snk_mw; -if (!tcpc->config->try_role_hw) - port->try_role = tcpc->config->default_role; + +if (!tcpc->config || !tcpc->config->try_role_hw) + port->try_role = port->typec_caps.prefer_role;else port->try_role =TYPEC_NO_PREFERRED_ROLE ; port->typec_caps.fwnode = tcpc->fwnode; - port->typec_caps.prefer_role = tcpc->config->default_role; - port->typec_caps.type = tcpc->config->type; - port->typec_caps.data = tcpc->config->data; port->typec_caps.revision =0x0120 ;/* Type-C spec release 1.2 */ port->typec_caps.pd_revision =0x0300 ;/* USB-PD spec release 3.0 */ port->typec_caps.dr_set = tcpm_dr_set;
@@ -4589,7 +4676,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) port->typec_caps.port_type_set = tcpm_port_type_set; port->partner_desc.identity = &port->partner_ident; - port->port_type = tcpc->config->type; + port->port_type = port->typec_caps.type; port->role_sw =usb_role_switch_get (port->dev);if (IS_ERR (port->role_sw)) {
@@ -4607,7 +4694,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) goto out_destroy_wq; } -if (tcpc->config->alt_modes) { +if (tcpc->config && tcpc->config->alt_modes) {const struct typec_altmode_desc *paltmode = tcpc->config->alt_modes; i =0 ;
PATCH v8 7/14 staging: typec: tcpci: remove unused tcpci_tcpc_config
In reply to Li JunSince we will use config settings via device properties, so remove the hard code tcpci_tcpc_config.
--- drivers/staging/typec/tcpci.c | 7 ------- 1 file changed, 7 deletions(-)
drivers/staging/typec/tcpci.c +0 -7
@@ -464,17 +464,10 @@ static const struct regmap_config tcpci_regmap_config = { .max_register = 0x7F, /* 0x80 .. 0xFF are vendor defined */ }; -static const struct tcpc_config tcpci_tcpc_config = { - .type =TYPEC_PORT_DFP , - .default_role =TYPEC_SINK , -}; -static int tcpci_parse_config (struct tcpci *tcpci) { tcpci->controls_vbus = true;/* XXX */ -/* TODO: Populate struct tcpc_config from ACPI/device-tree */ - tcpci->tcpc.config = &tcpci_tcpc_config; tcpci->tcpc.fwnode =device_get_named_child_node (tcpci->dev,"connector" );if (!tcpci->tcpc.fwnode) {
PATCH v8 8/14 staging: typec: tcpci: use IS_ERR() instead of PTR_ERR_OR_ZERO()
In reply to Li JunAs tcpm_register_port() and tcpci_register_port() never return NULL and NULL is not a success in this case, use IS_ERR() to check the return value of both.
--- drivers/staging/typec/tcpci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/typec/tcpci.c +2 -2
@@ -509,7 +509,7 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)return ERR_PTR (err); tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); -if (PTR_ERR_OR_ZERO (tcpci->port)) +if (IS_ERR (tcpci->port))return ERR_CAST (tcpci->port);return tcpci;
@@ -551,7 +551,7 @@ static int tcpci_probe(struct i2c_client *client,return err; chip->tcpci =tcpci_register_port (&client->dev, &chip->data); -if (PTR_ERR_OR_ZERO (chip->tcpci)) +if (IS_ERR (chip->tcpci))return PTR_ERR (chip->tcpci);i2c_set_clientdata (client, chip);
PATCH v8 9/14 staging: typec: tcpci: register port before request irq
In reply to Li JunFrom: Peter Chen <[email protected]>
With that we can clear any pending events and the port is registered so driver can be ready to handle typec events once we request irq.
--- drivers/staging/typec/tcpci.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/staging/typec/tcpci.c +9 -6
@@ -537,24 +537,27 @@ static int tcpci_probe(struct i2c_client *client,if (IS_ERR (chip->data.regmap))return PTR_ERR (chip->data.regmap); +i2c_set_clientdata (client, chip); +/* Disable chip interrupts before requesting irq */ err =regmap_raw_write (chip->data.regmap,TCPC_ALERT_MASK , &val,sizeof (u16));if (err <0 )return err; + chip->tcpci =tcpci_register_port (&client->dev, &chip->data); +if (IS_ERR (chip->tcpci)) +return PTR_ERR (chip->tcpci); + err =devm_request_threaded_irq (&client->dev, client->irq,NULL , _tcpci_irq,IRQF_ONESHOT |IRQF_TRIGGER_LOW ,dev_name (&client->dev), chip); -if (err <0 ) +if (err <0 ) { +tcpci_unregister_port (chip->tcpci);return err; + } - chip->tcpci =tcpci_register_port (&client->dev, &chip->data); -if (IS_ERR (chip->tcpci)) -return PTR_ERR (chip->tcpci); - -i2c_set_clientdata (client, chip);return 0 ; }
PATCH v8 10/14 staging: typec: tcpci: enable vbus detection
In reply to Li JunTCPCI implementation may need SW to enable VBUS detection to generate power status events.
--- drivers/staging/typec/tcpci.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/staging/typec/tcpci.c +6 -0
@@ -373,6 +373,12 @@ static int tcpci_init(struct tcpc_dev *tcpc)if (ret <0 )return ret; +/* Enable Vbus detection */ + ret =regmap_write (tcpci->regmap,TCPC_COMMAND , +TCPC_CMD_ENABLE_VBUS_DETECT ); +if (ret <0 ) +return ret; + reg =TCPC_ALERT_TX_SUCCESS |TCPC_ALERT_TX_FAILED |TCPC_ALERT_TX_DISCARDED |TCPC_ALERT_RX_STATUS |TCPC_ALERT_RX_HARD_RST |TCPC_ALERT_CC_STATUS ;
PATCH v8 11/14 typec: tcpm: add starting value for drp toggling
In reply to Li JunAs DRP port autonomously toggles the Rp/Rd need a start value to begin with, so add one parameter for it in tcpm_start_drp_toggling.
--- drivers/usb/typec/tcpm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/usb/typec/tcpm.c +5 -5
@@ -2431,15 +2431,15 @@ static int tcpm_set_charge(struct tcpm_port *port, bool charge)return 0 ; } -static bool tcpm_start_drp_toggling (struct tcpm_port *port) +static bool tcpm_start_drp_toggling (struct tcpm_port *port, +enum typec_cc_status cc) {int ret;if (port->tcpc->start_drp_toggling && port->port_type ==TYPEC_PORT_DRP ) {tcpm_log_force (port,"Start DRP toggling" ); - ret = port->tcpc->start_drp_toggling (port->tcpc, -tcpm_rp_cc (port)); + ret = port->tcpc->start_drp_toggling (port->tcpc, cc);if (!ret)return true; }
@@ -2747,7 +2747,7 @@ static void run_state_machine(struct tcpm_port *port)if (!port->non_pd_role_swap)tcpm_swap_complete (port, -ENOTCONN );tcpm_src_detach (port); -if (tcpm_start_drp_toggling (port)) { +if (tcpm_start_drp_toggling (port,tcpm_rp_cc (port))) {tcpm_set_state (port,DRP_TOGGLING ,0 );break ; }
@@ -2922,7 +2922,7 @@ static void run_state_machine(struct tcpm_port *port)tcpm_swap_complete (port, -ENOTCONN );tcpm_pps_complete (port, -ENOTCONN );tcpm_snk_detach (port); -if (tcpm_start_drp_toggling (port)) { +if (tcpm_start_drp_toggling (port,TYPEC_CC_RD )) {tcpm_set_state (port,DRP_TOGGLING ,0 );break ; }
PATCH v8 12/14 staging: typec: tcpci: keep the disconnected cc line open
In reply to Li JunWhile set polarity, we should keep the disconnected cc line to be open.
--- drivers/staging/typec/tcpci.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/staging/typec/tcpci.c +14 -4
@@ -185,15 +185,25 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc, enum typec_cc_polarity polarity) {struct tcpci *tcpci =tcpc_to_tcpci (tcpc); +unsigned int reg;int ret; - ret =regmap_write (tcpci->regmap,TCPC_TCPC_CTRL , - (polarity ==TYPEC_POLARITY_CC2 ) ? -TCPC_TCPC_CTRL_ORIENTATION :0 ); +/* Keep the disconnect cc line open */ + ret =regmap_read (tcpci->regmap,TCPC_ROLE_CTRL , ®);if (ret <0 )return ret; -return 0 ; +if (polarity ==TYPEC_POLARITY_CC2 ) + reg |=TCPC_ROLE_CTRL_CC_OPEN <<TCPC_ROLE_CTRL_CC1_SHIFT ; +else + reg |=TCPC_ROLE_CTRL_CC_OPEN <<TCPC_ROLE_CTRL_CC2_SHIFT ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; + +return regmap_write (tcpci->regmap,TCPC_TCPC_CTRL , + (polarity ==TYPEC_POLARITY_CC2 ) ? +TCPC_TCPC_CTRL_ORIENTATION :0 ); }static int tcpci_set_vconn (struct tcpc_dev *tcpc,bool enable)
Signature · 1 line
2.7.4
PATCH v8 13/14 staging: typec: tcpci: Only touch target bit when enable vconn
In reply to Li JunWe need regmap_update_bits to avoid touch any other bits when enable or disable vconn.
--- drivers/staging/typec/tcpci.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/staging/typec/tcpci.c +3 -6
@@ -218,12 +218,9 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)return ret; } - ret =regmap_write (tcpci->regmap,TCPC_POWER_CTRL , - enable ?TCPC_POWER_CTRL_VCONN_ENABLE :0 ); -if (ret <0 ) -return ret; - -return 0 ; +return regmap_update_bits (tcpci->regmap,TCPC_POWER_CTRL , +TCPC_POWER_CTRL_VCONN_ENABLE , + enable ?TCPC_POWER_CTRL_VCONN_ENABLE :0 ); } static int tcpci_set_roles(struct tcpc_dev *tcpc, bool attached,
PATCH v8 14/14 staging: typec: tcpci: move tcpci drivers out of staging
In reply to Li JunMove TCPCI(Typec port controller interface) driver and rt1711h driver out of staging.
---
drivers/staging/Kconfig | 2 --
drivers/staging/Makefile | 1 -
drivers/staging/typec/Kconfig | 22 ----------------------
drivers/staging/typec/Makefile | 2 --
drivers/staging/typec/TODO | 5 -----
drivers/usb/typec/Kconfig | 15 +++++++++++++++
drivers/usb/typec/Makefile | 2 ++
drivers/{staging => usb}/typec/tcpci.c | 0
drivers/{staging => usb}/typec/tcpci.h | 0
drivers/{staging => usb}/typec/tcpci_rt1711h.c | 0
10 files changed, 17 insertions(+), 32 deletions(-)drivers/staging/Kconfig +0 -2
@@ -106,8 +106,6 @@ source "drivers/staging/greybus/Kconfig" source "drivers/staging/vc04_services/Kconfig" -source "drivers/staging/typec/Kconfig" - source "drivers/staging/vboxvideo/Kconfig" source "drivers/staging/pi433/Kconfig"
drivers/staging/Makefile +0 -1
@@ -2,7 +2,6 @@ # Makefile for staging directory obj-y += media/ -obj-y += typec/ obj-$(CONFIG_PRISM2_USB) += wlan-ng/ obj-$(CONFIG_COMEDI) += comedi/ obj-$(CONFIG_FB_OLPC_DCON) += olpc_dcon/
drivers/staging/typec/Kconfig deleted +0 -22
@@ -1,22 +0,0 @@ -menu "USB Power Delivery and Type-C drivers" - -if TYPEC_TCPM - -config TYPEC_TCPCI - tristate "Type-C Port Controller Interface driver" - depends on I2C - select REGMAP_I2C - help - Type-C Port Controller driver for TCPCI-compliant controller. - -config TYPEC_RT1711H - tristate "Richtek RT1711H Type-C chip driver" - select TYPEC_TCPCI - help - Richtek RT1711H Type-C chip driver that works with - Type-C Port Controller Manager to provide USB PD and USB - Type-C functionalities. - -endif - -endmenu
drivers/staging/typec/Makefile deleted +0 -2
@@ -1,2 +0,0 @@ -obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o -obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o
drivers/staging/typec/TODO deleted +0 -5
@@ -1,5 +0,0 @@ -tcpci: -- Test with real hardware - -Please send patches to Guenter Roeck <[email protected]> and copy -Heikki Krogerus <[email protected]>.
drivers/usb/typec/Kconfig +15 -0
@@ -56,6 +56,21 @@ config TYPEC_TCPM if TYPEC_TCPM +config TYPEC_TCPCI + tristate "Type-C Port Controller Interface driver" + depends on I2C + select REGMAP_I2C + help + Type-C Port Controller driver for TCPCI-compliant controller. + +config TYPEC_RT1711H + tristate "Richtek RT1711H Type-C chip driver" + select TYPEC_TCPCI + help + Richtek RT1711H Type-C chip driver that works with + Type-C Port Controller Manager to provide USB PD and USB + Type-C functionalities. + source "drivers/usb/typec/fusb302/Kconfig" config TYPEC_WCOVE
drivers/usb/typec/Makefile +2 -0
@@ -7,3 +7,5 @@ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o obj-$(CONFIG_TYPEC_UCSI) += ucsi/ obj-$(CONFIG_TYPEC_TPS6598X) += tps6598x.o obj-$(CONFIG_TYPEC) += mux/ +obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o +obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o
drivers/usb/typec/tcpci.c renamed from drivers/staging/typec/tcpci.c +0 -0
drivers/usb/typec/tcpci.h renamed from drivers/staging/typec/tcpci.h +0 -0
drivers/usb/typec/tcpci_rt1711h.c renamed from drivers/staging/typec/tcpci_rt1711h.c +0 -0
v8 cover staging: typec: tcpci: move out of staging
This patch set attempts to move the tcpci drivers out of staging by fix some tcpci driver issues and define typec and power delivery device properties, the changes are verified on NXP PTN5110, which is a standard tcpci typec port controller device with power delivery support, tested power source and sink with drp config.
Changes for v8:
- Favouring the generic FW based capabilities(tcpc_dev->fwnode) over values defined in a Type C port controller driver(tcpc_dev->config)
- Add Heikki's Reviewed-by for patch:
usb: typec: add API to get typec basic port power and data config
Changes for v7:
- Fix export symbols mismatch in patch:
usb: typec: add API to get typec basic port power and data config rename typec_port_types to be typec_port_power_roles.
- Drop patch:
usb: typec: tcpm: set cc for drp toggling attach
It's arguable as it's only to address specific HW problem, and which can be resolved by add try.src/snk property.
Changes for v6:
- Change function name to be typec_find_port_power/data_role for find capability, and typec_find_power_role for find one specific power role.
- Fix rt1711h driver move missing.
- Add one patch to improve the error checking in tcpci driver, use IS_ERR() instead of PTR_ERR_OR_ZERO().
- Add Rob's Reviewed-by for patch [2/15].
- Misc typos fix.
Changes for v5:
- Use "power-role" and "data-role" for typec port power and data capability property name.
- Use macro definition instead of cryptic numbers for readability of power delivery properties(PDO).
- Add one tcpci driver binding string to be "nxp,ptn5110" to follow binding name rule "<vendor prefix>,<device>".
- Change operating power property name to be op-sink-microwatt.
- Add one patch(remove unused tcpci_tcpc_config) to resolve bisectablitity issue of patch usb: typec: add fwnode to tcpc.
- A minor error handling change to keep the error path and success path separate in patch: register port before request irq
- Rebase to latest Greg's tree with max_snk_* removed.
Changes for v4:
- Remove max-sink-* properties as we will purge max_snk_* in tcpm, see patch set[4].
- Get typec power and data type value via name string(patch 5).
- Move finding typec and pd properties code from tcpci to tcpm(patch 6)
- Add a compatible string for nxp ptn5110 typec controller in tcpci driver. (patch 3)
- Add set cc for drp toggling without try.src/snk in tcpm(patch 10), then patch 11 can only update CCx bits for keep disconnect cc line open.
- Update op-sink-microwatt-hours example value to be the right value in micorwatts, and accordingly divide 1000 to get its miliwatts value in patch 6.
- Add Guenter's Reviewed-by for patch(8/9/12)
[4] https://www.spinics.net/lists/linux-usb/msg167261.html
Changes for v3:
- Use 2 properties to separate power and data capability of typec port:
"power-type" and "data-type", this is based on Heikki's typec class code change[2]. use "try-power-role" to present if the typec port can support Try.SNK or Try.SRC.
- 4 sink properties(max_sink_mv/ma/mw and op_sink_mw) are kept because the counterpart code is back, see revert patch[3], meanwhile I post a patch to fix the reported problem of current source pdo select machinism(which completely ignored those 4 sink settings), to see if we can keep current code, once it was discussed and have conclusion I can update this accordingly.
- Use fwnode to get the connector node for dt setting parse.
Main changes for v2:
- Typec properties are based on general usb connector bindings[1] proposed by Andrzej Hajda, use the standard unit suffixes as defined in property-units.txt.
- Add 2 infra APIs to get power sink and source config from dt.
- Don't change the set_cc api, to keep the uncontacted cc line open, set cc1/cc2 to be open in tcpci driver when set polarity.
- Directly enable vbus detect in tcpci driver rather than add a API.
- Details added in each patch.
[1] https://patchwork.kernel.org/patch/10231447/
[2] https://patchwork.kernel.org/patch/10276483/
[3] https://www.spinics.net/lists/linux-usb/msg166366.html
Li Jun (13):
dt-bindings: connector: add properties for typec
dt-bindings: usb: add documentation for typec port controller(TCPCI)
staging: typec: tcpci: add compatible string for nxp ptn5110
usb: typec: add fwnode to tcpc
usb: typec: add API to get typec basic port power and data config
usb: typec: tcpm: support get typec and pd config from device
properties
staging: typec: tcpci: remove unused tcpci_tcpc_config
staging: typec: tcpci: use IS_ERR() instead of PTR_ERR_OR_ZERO()
staging: typec: tcpci: enable vbus detection
typec: tcpm: add starting value for drp toggling
staging: typec: tcpci: keep the disconnected cc line open
staging: typec: tcpci: Only touch target bit when enable vconn
staging: typec: tcpci: move tcpci drivers out of staging
Peter Chen (1):
staging: typec: tcpci: register port before request irq
.../bindings/connector/usb-connector.txt | 44 +++++++
.../devicetree/bindings/usb/typec-tcpci.txt | 49 +++++++
drivers/staging/Kconfig | 2 -
drivers/staging/Makefile | 1 -
drivers/staging/typec/Kconfig | 22 ----
drivers/staging/typec/Makefile | 2 -
drivers/staging/typec/TODO | 5 -
drivers/usb/typec/Kconfig | 15 +++
drivers/usb/typec/Makefile | 2 +
drivers/usb/typec/class.c | 58 ++++++++-
drivers/{staging => usb}/typec/tcpci.c | 66 ++++++----
drivers/{staging => usb}/typec/tcpci.h | 0
drivers/{staging => usb}/typec/tcpci_rt1711h.c | 0
drivers/usb/typec/tcpm.c | 142 +++++++++++++++++----
include/dt-bindings/usb/pd.h | 62 +++++++++
include/linux/usb/tcpm.h | 2 +
include/linux/usb/typec.h | 3 +
17 files changed, 387 insertions(+), 88 deletions(-)
create mode 100644 Documentation/devicetree/bindings/usb/typec-tcpci.txt
delete mode 100644 drivers/staging/typec/Kconfig
delete mode 100644 drivers/staging/typec/Makefile
delete mode 100644 drivers/staging/typec/TODO
rename drivers/{staging => usb}/typec/tcpci.c (92%)
rename drivers/{staging => usb}/typec/tcpci.h (100%)
rename drivers/{staging => usb}/typec/tcpci_rt1711h.c (100%)
create mode 100644 include/dt-bindings/usb/pd.hSignature · 1 line
2.7.4
Re: [PATCH v8 03/14] staging: typec: tcpci: add compatible string for nxp ptn5110
In reply to Li JunQuoted 7 lines · Li Jun
Add nxp ptn5110 typec controller compatible string: "nxp,ptn5110", which is a standard tcpci chip with power delivery support. Meanwhile remove "usb,tcpci" because it doesn't follow the binding format rule and has not been used yet.
Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Li Jun <[email protected]>
Quoted 18 lines
--- drivers/staging/typec/tcpci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/typec/tcpci.c +1
-1@@ -575,7 +575,7 @@ MODULE_DEVICE_TABLE(i2c, tcpci_id);#ifdef CONFIG_OF static const struct of_device_id tcpci_of_match[] = { - { .compatible ="usb,tcpci" , }, + { .compatible ="nxp,ptn5110" , }, {}, };MODULE_DEVICE_TABLE (of, tcpci_of_match);
Re: [PATCH v8 04/14] usb: typec: add fwnode to tcpc
In reply to Li JunQuoted 6 lines · Li Jun
Add fwnode handle to get the fwnode so we can get typec configs it contains.
Suggested-by Heikki Krogerus <[email protected]>Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Li Jun <[email protected]>
Quoted 64 lines
--- drivers/staging/typec/tcpci.c | 7 +++++++ drivers/usb/typec/tcpm.c | 1 + include/linux/usb/tcpm.h | 2 ++ 3 files changed, 10 insertions(+)drivers/staging/typec/tcpci.c +7
-0@@ -10,6 +10,7 @@#include <linux/module.h> #include <linux/i2c.h> #include <linux/interrupt.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/usb/pd.h> #include <linux/usb/tcpm.h> @@ -474,6 +475,12 @@ static int tcpci_parse_config(struct tcpci *tcpci)/* TODO: Populate struct tcpc_config from ACPI/device-tree */ tcpci->tcpc.config = &tcpci_tcpc_config; + tcpci->tcpc.fwnode =device_get_named_child_node (tcpci->dev, +"connector" ); +if (!tcpci->tcpc.fwnode) { +dev_err (tcpci->dev,"Can't find connector node.\n" ); +return -EINVAL ; + }return 0 ; }drivers/usb/typec/tcpm.c +1
-0@@ -4576,6 +4576,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)else port->try_role =TYPEC_NO_PREFERRED_ROLE ; + port->typec_caps.fwnode = tcpc->fwnode; port->typec_caps.prefer_role = tcpc->config->default_role; port->typec_caps.type = tcpc->config->type; port->typec_caps.data = tcpc->config->data;include/linux/usb/tcpm.h +2
-0@@ -110,6 +110,7 @@ enum tcpc_mux_mode {/** * struct tcpc_dev - Port configuration and callback functions * @config: Pointer to port configuration +* @fwnode: Pointer to port fwnode * @get_vbus: Called to read current VBUS state * @get_current_limit: * Optional; called by the tcpm core when configured as a snk @@ -138,6 +139,7 @@ enum tcpc_mux_mode {*/ struct tcpc_dev {const struct tcpc_config *config; +struct fwnode_handle *fwnode;int (*init)(struct tcpc_dev *dev);int (*get_vbus)(struct tcpc_dev *dev);
Re: [PATCH v8 07/14] staging: typec: tcpci: remove unused tcpci_tcpc_config
In reply to Li JunQuoted 5 lines · Li Jun
Since we will use config settings via device properties, so remove the hard code
tcpci_tcpc_config.Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Li Jun <[email protected]>
Quoted 27 lines
--- drivers/staging/typec/tcpci.c | 7 ------- 1 file changed, 7 deletions(-)drivers/staging/typec/tcpci.c +0
-7@@ -464,17 +464,10 @@ static const struct regmap_config tcpci_regmap_config = { .max_register = 0x7F, /* 0x80 .. 0xFF are vendor defined */ }; -static const struct tcpc_config tcpci_tcpc_config = { - .type =TYPEC_PORT_DFP , - .default_role =TYPEC_SINK , -}; -static int tcpci_parse_config (struct tcpci *tcpci) { tcpci->controls_vbus = true;/* XXX */ -/* TODO: Populate struct tcpc_config from ACPI/device-tree */ - tcpci->tcpc.config = &tcpci_tcpc_config; tcpci->tcpc.fwnode =device_get_named_child_node (tcpci->dev,"connector" );if (!tcpci->tcpc.fwnode) {
Re: [PATCH v8 08/14] staging: typec: tcpci: use IS_ERR() instead of PTR_ERR_OR_ZERO()
In reply to Li JunQuoted 6 lines · Li Jun
As
tcpm_register_port()andtcpci_register_port()never return NULL and NULL is not a success in this case, useIS_ERR()to check the return value of both.Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Li Jun <[email protected]>
Quoted 27 lines
--- drivers/staging/typec/tcpci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/typec/tcpci.c +2
-2@@ -509,7 +509,7 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)return ERR_PTR (err); tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); -if (PTR_ERR_OR_ZERO (tcpci->port)) +if (IS_ERR (tcpci->port))return ERR_CAST (tcpci->port);return tcpci;@@ -551,7 +551,7 @@ static int tcpci_probe(struct i2c_client *client,return err; chip->tcpci =tcpci_register_port (&client->dev, &chip->data); -if (PTR_ERR_OR_ZERO (chip->tcpci)) +if (IS_ERR (chip->tcpci))return PTR_ERR (chip->tcpci);i2c_set_clientdata (client, chip);
Re: [PATCH v8 09/14] staging: typec: tcpci: register port before request irq
In reply to Li JunQuoted 8 lines · Li Jun
From: Peter Chen <[email protected]>
With that we can clear any pending events and the port is registered so driver can be ready to handle typec events once we request irq.
Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Peter Chen <[email protected]>Signed-off-by Li Jun <[email protected]>
Quoted 43 lines
--- drivers/staging/typec/tcpci.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/staging/typec/tcpci.c +9
-6@@ -537,24 +537,27 @@ static int tcpci_probe(struct i2c_client *client,if (IS_ERR (chip->data.regmap))return PTR_ERR (chip->data.regmap); +i2c_set_clientdata (client, chip); +/* Disable chip interrupts before requesting irq */ err =regmap_raw_write (chip->data.regmap,TCPC_ALERT_MASK , &val,sizeof (u16));if (err <0 )return err; + chip->tcpci =tcpci_register_port (&client->dev, &chip->data); +if (IS_ERR (chip->tcpci)) +return PTR_ERR (chip->tcpci); + err =devm_request_threaded_irq (&client->dev, client->irq,NULL , _tcpci_irq,IRQF_ONESHOT |IRQF_TRIGGER_LOW ,dev_name (&client->dev), chip); -if (err <0 ) +if (err <0 ) { +tcpci_unregister_port (chip->tcpci);return err; + } - chip->tcpci =tcpci_register_port (&client->dev, &chip->data); -if (IS_ERR (chip->tcpci)) -return PTR_ERR (chip->tcpci); - -i2c_set_clientdata (client, chip);return 0 ; }
Re: [PATCH v8 12/14] staging: typec: tcpci: keep the disconnected cc line open
In reply to Li JunQuoted 5 lines · Li Jun
While set polarity, we should keep the disconnected cc line to be open.
Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Li Jun <[email protected]>
Quoted 39 lines
--- drivers/staging/typec/tcpci.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)drivers/staging/typec/tcpci.c +14
-4@@ -185,15 +185,25 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc, enum typec_cc_polarity polarity) {struct tcpci *tcpci =tcpc_to_tcpci (tcpc); +unsigned int reg;int ret; - ret =regmap_write (tcpci->regmap,TCPC_TCPC_CTRL , - (polarity ==TYPEC_POLARITY_CC2 ) ? -TCPC_TCPC_CTRL_ORIENTATION :0 ); +/* Keep the disconnect cc line open */ + ret =regmap_read (tcpci->regmap,TCPC_ROLE_CTRL , ®);if (ret <0 )return ret; -return 0 ; +if (polarity ==TYPEC_POLARITY_CC2 ) + reg |=TCPC_ROLE_CTRL_CC_OPEN <<TCPC_ROLE_CTRL_CC1_SHIFT ; +else + reg |=TCPC_ROLE_CTRL_CC_OPEN <<TCPC_ROLE_CTRL_CC2_SHIFT ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; + +return regmap_write (tcpci->regmap,TCPC_TCPC_CTRL , + (polarity ==TYPEC_POLARITY_CC2 ) ? +TCPC_TCPC_CTRL_ORIENTATION :0 ); }static int tcpci_set_vconn (struct tcpc_dev *tcpc,bool enable)
Re: [PATCH v8 14/14] staging: typec: tcpci: move tcpci drivers out of staging
In reply to Li JunQuoted 4 lines · Li Jun
Move TCPCI(Typec port controller interface) driver and rt1711h driver out of staging.
Signed-off-by Li Jun <[email protected]>
Quoted 134 lines
--- drivers/staging/Kconfig | 2 -- drivers/staging/Makefile | 1 - drivers/staging/typec/Kconfig | 22 ---------------------- drivers/staging/typec/Makefile | 2 -- drivers/staging/typec/TODO | 5 ----- drivers/usb/typec/Kconfig | 15 +++++++++++++++ drivers/usb/typec/Makefile | 2 ++ drivers/{staging => usb}/typec/tcpci.c | 0 drivers/{staging => usb}/typec/tcpci.h | 0 drivers/{staging => usb}/typec/tcpci_rt1711h.c | 0 10 files changed, 17 insertions(+), 32 deletions(-)drivers/staging/Kconfig +0
-2@@ -106,8 +106,6 @@ source "drivers/staging/greybus/Kconfig" source "drivers/staging/vc04_services/Kconfig" -source "drivers/staging/typec/Kconfig" - source "drivers/staging/vboxvideo/Kconfig" source "drivers/staging/pi433/Kconfig"drivers/staging/Makefile +0
-1@@ -2,7 +2,6 @@ # Makefile for staging directory obj-y += media/ -obj-y += typec/ obj-$(CONFIG_PRISM2_USB) += wlan-ng/ obj-$(CONFIG_COMEDI) += comedi/ obj-$(CONFIG_FB_OLPC_DCON) += olpc_dcon/drivers/staging/typec/Kconfig deleted +0
-22@@ -1,22 +0,0 @@ -menu "USB Power Delivery and Type-C drivers" - -if TYPEC_TCPM - -config TYPEC_TCPCI - tristate "Type-C Port Controller Interface driver" - depends on I2C - select REGMAP_I2C - help - Type-C Port Controller driver for TCPCI-compliant controller. - -config TYPEC_RT1711H - tristate "Richtek RT1711H Type-C chip driver" - select TYPEC_TCPCI - help - Richtek RT1711H Type-C chip driver that works with - Type-C Port Controller Manager to provide USB PD and USB - Type-C functionalities. - -endif - -endmenudrivers/staging/typec/Makefile deleted +0
-2@@ -1,2 +0,0 @@ -obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o -obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.odrivers/staging/typec/TODO deleted +0
-5@@ -1,5 +0,0 @@ -tcpci: -- Test with real hardware - -Please send patches to Guenter Roeck <[email protected]> and copy -Heikki Krogerus <[email protected]>.drivers/usb/typec/Kconfig +15
-0@@ -56,6 +56,21 @@ config TYPEC_TCPM if TYPEC_TCPM +config TYPEC_TCPCI + tristate "Type-C Port Controller Interface driver" + depends on I2C + select REGMAP_I2C + help + Type-C Port Controller driver for TCPCI-compliant controller. + +config TYPEC_RT1711H + tristate "Richtek RT1711H Type-C chip driver" + select TYPEC_TCPCI + help + Richtek RT1711H Type-C chip driver that works with + Type-C Port Controller Manager to provide USB PD and USB + Type-C functionalities. + source "drivers/usb/typec/fusb302/Kconfig" config TYPEC_WCOVEdrivers/usb/typec/Makefile +2
-0@@ -7,3 +7,5 @@ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o obj-$(CONFIG_TYPEC_UCSI) += ucsi/ obj-$(CONFIG_TYPEC_TPS6598X) += tps6598x.o obj-$(CONFIG_TYPEC) += mux/ +obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o +obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.odrivers/usb/typec/tcpci.c renamed from drivers/staging/typec/tcpci.c +0
-0drivers/usb/typec/tcpci.h renamed from drivers/staging/typec/tcpci.h +0
-0drivers/usb/typec/tcpci_rt1711h.c renamed from drivers/staging/typec/tcpci_rt1711h.c +0
-0
RE: [PATCH v8 06/14] usb: typec: tcpm: support get typec and pd config from device properties
In reply to Li JunQuoted 6 lines · Li Jun
This patch adds support of get typec and power delivery config from firmware description.
Reviewed-by Heikki Krogerus <[email protected]>Reviewed-by Guenter Roeck <[email protected]>Signed-off-by Li Jun <[email protected]>
Quoted 200 lines
--- drivers/usb/typec/tcpm.c | 131 +++++++++++++++++++++++++++++++++++++++----- --- 1 file changed, 109 insertions(+), 22 deletions(-)drivers/usb/typec/tcpm.c +75
-0@@ -4236,6 +4236,81 @@ static int tcpm_copy_vdos(u32 *dest_vdo, const u32 *src_vdo, return nr_vdo; } +static int tcpm_fw_get_caps (struct tcpm_port *port, +struct fwnode_handle *fwnode) +{ +const char *cap_str; +int ret; +u32 mw; + +if (!fwnode) +return -EINVAL ; + +/* USB data support is optional */ + ret =fwnode_property_read_string (fwnode,"data-role" , &cap_str); +if (ret ==0 ) { + port->typec_caps.data =typec_find_port_data_role (cap_str); +if (port->typec_caps.data <0 ) +return -EINVAL ; + } + + ret =fwnode_property_read_string (fwnode,"power-role" , &cap_str); +if (ret <0 ) +return ret; + + port->typec_caps.type =typec_find_port_power_role (cap_str); +if (port->typec_caps.type <0 ) +return -EINVAL ; + port->port_type = port->typec_caps.type; + +if (port->port_type ==TYPEC_PORT_SNK ) + goto sink; + +/* Get source pdos */ + ret =fwnode_property_read_u32_array (fwnode,"source-pdos" , +NULL ,0 ); +if (ret <=0 ) +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 <0 ) ||tcpm_validate_caps (port, port->src_pdo, + port->nr_src_pdo)) +return -EINVAL ; + +if (port->port_type ==TYPEC_PORT_SRC ) +return 0 ; + +/* Get the preferred power role for DRP */ + ret =fwnode_property_read_string (fwnode,"try-power-role" , &cap_str); +if (ret <0 ) +return ret; + + port->typec_caps.prefer_role =typec_find_power_role (cap_str); +if (port->typec_caps.prefer_role <0 ) +return -EINVAL ; +sink: +/* Get sink pdos */ + ret =fwnode_property_read_u32_array (fwnode,"sink-pdos" , +NULL ,0 ); +if (ret <=0 ) +return -EINVAL ; + + port->nr_snk_pdo =min (ret,PDO_MAX_OBJECTS ); + ret =fwnode_property_read_u32_array (fwnode,"sink-pdos" , + port->snk_pdo, port->nr_snk_pdo); +if ((ret <0 ) ||tcpm_validate_caps (port, port->snk_pdo, + port->nr_snk_pdo)) +return -EINVAL ; + +if (fwnode_property_read_u32 (fwnode,"op-sink-microwatt" , &mw) <0 ) +return -EINVAL ; + port->operating_snk_mw = mw /1000 ; + +return 0 ; +} +int tcpm_update_source_capabilities (struct tcpm_port *port,const u32 *pdo,unsigned int nr_pdo){
drivers/usb/typec/tcpm.c +25
-1@@ -4521,12 +4596,36 @@ static int devm_tcpm_psy_register(struct tcpm_port *port)return PTR_ERR_OR_ZERO (port->psy); } +static int tcpm_copy_caps (struct tcpm_port *port, +const struct tcpc_config *tcfg) +{ +if (tcpm_validate_caps (port, tcfg->src_pdo, tcfg->nr_src_pdo) || +tcpm_validate_caps (port, tcfg->snk_pdo, tcfg->nr_snk_pdo)) +return -EINVAL ; + + port->nr_src_pdo =tcpm_copy_pdos (port->src_pdo, tcfg->src_pdo, + tcfg->nr_src_pdo); + port->nr_snk_pdo =tcpm_copy_pdos (port->snk_pdo, tcfg->snk_pdo, + tcfg->nr_snk_pdo); + + port->nr_snk_vdo =tcpm_copy_vdos (port->snk_vdo, tcfg->snk_vdo, + tcfg->nr_snk_vdo); + + port->operating_snk_mw = tcfg->operating_snk_mw; + + port->typec_caps.prefer_role = tcfg->default_role; + port->typec_caps.type = tcfg->type; + port->typec_caps.data = tcfg->data; + +return 0 ; +} +struct tcpm_port *tcpm_register_port (struct device *dev,struct tcpc_dev *tcpc) {struct tcpm_port *port;int i, err; - if (!dev || !tcpc || !tcpc->config || + if (!dev || !tcpc || !tcpc->get_vbus || !tcpc->set_cc || !tcpc->get_cc || !tcpc->set_polarity || !tcpc->set_vconn || !tcpc->set_vbus ||drivers/usb/typec/tcpm.c +7
-19!tcpc->set_pd_rx || !tcpc->set_roles || !tcpc->pd_transmit)@@ -4556,30 +4655,18 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) init_completion(&port->pps_complete);tcpm_debugfs_init (port); -if (tcpm_validate_caps (port, tcpc->config->src_pdo, - tcpc->config->nr_src_pdo) || -tcpm_validate_caps (port, tcpc->config->snk_pdo, - tcpc->config->nr_snk_pdo)) { - err = -EINVAL ; + err =tcpm_fw_get_caps (port, tcpc->fwnode); +if ((err <0 ) && tcpc->config) + err =tcpm_copy_caps (port, tcpc->config); +if (err <0 ) goto out_destroy_wq; - } - port->nr_src_pdo =tcpm_copy_pdos (port->src_pdo, tcpc->config->src_pdo, - tcpc->config->nr_src_pdo); - port->nr_snk_pdo =tcpm_copy_pdos (port->snk_pdo, tcpc->config- >snk_pdo, - tcpc->config->nr_snk_pdo); - port->nr_snk_vdo =tcpm_copy_vdos (port->snk_vdo, tcpc->config- >snk_vdo, - tcpc->config->nr_snk_vdo); - - port->operating_snk_mw = tcpc->config->operating_snk_mw; -if (!tcpc->config->try_role_hw) - port->try_role = tcpc->config->default_role; + +if (!tcpc->config || !tcpc->config->try_role_hw) + port->try_role = port->typec_caps.prefer_role;else port->try_role =TYPEC_NO_PREFERRED_ROLE ; port->typec_caps.fwnode = tcpc->fwnode; - port->typec_caps.prefer_role = tcpc->config->default_role; - port->typec_caps.type = tcpc->config->type; - port->typec_caps.data = tcpc->config->data;drivers/usb/typec/tcpm.c +1
-1port->typec_caps.revision =0x0120 ;/* Type-C spec release 1.2 */ port->typec_caps.pd_revision =0x0300 ;/* USB-PD spec release 3.0 */ port->typec_caps.dr_set = tcpm_dr_set;@@ -4589,7 +4676,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) port->typec_caps.port_type_set = tcpm_port_type_set; port->partner_desc.identity = &port->partner_ident; - port->port_type = tcpc->config->type; + port->port_type = port->typec_caps.type; port->role_sw =usb_role_switch_get (port->dev);drivers/usb/typec/tcpm.c +1
-1if (IS_ERR (port->role_sw)) {@@ -4607,7 +4694,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) goto out_destroy_wq; } -if (tcpc->config->alt_modes) { +if (tcpc->config && tcpc->config->alt_modes) {const struct typec_altmode_desc *paltmode = tcpc->config- >alt_modes;i = 0;
--
2.7.4--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v8 14/14] staging: typec: tcpci: move tcpci drivers out of staging
In reply to Li JunQuoted 4 lines · Li Jun
Move TCPCI(Typec port controller interface) driver and rt1711h driver out of staging.
Signed-off-by Li Jun <[email protected]>
Thanks Li!
Quoted 133 lines
--- drivers/staging/Kconfig | 2 -- drivers/staging/Makefile | 1 - drivers/staging/typec/Kconfig | 22 ---------------------- drivers/staging/typec/Makefile | 2 -- drivers/staging/typec/TODO | 5 ----- drivers/usb/typec/Kconfig | 15 +++++++++++++++ drivers/usb/typec/Makefile | 2 ++ drivers/{staging => usb}/typec/tcpci.c | 0 drivers/{staging => usb}/typec/tcpci.h | 0 drivers/{staging => usb}/typec/tcpci_rt1711h.c | 0 10 files changed, 17 insertions(+), 32 deletions(-)drivers/staging/Kconfig +0
-2@@ -106,8 +106,6 @@ source "drivers/staging/greybus/Kconfig" source "drivers/staging/vc04_services/Kconfig" -source "drivers/staging/typec/Kconfig" - source "drivers/staging/vboxvideo/Kconfig" source "drivers/staging/pi433/Kconfig"drivers/staging/Makefile +0
-1@@ -2,7 +2,6 @@ # Makefile for staging directory obj-y += media/ -obj-y += typec/ obj-$(CONFIG_PRISM2_USB) += wlan-ng/ obj-$(CONFIG_COMEDI) += comedi/ obj-$(CONFIG_FB_OLPC_DCON) += olpc_dcon/drivers/staging/typec/Kconfig deleted +0
-22@@ -1,22 +0,0 @@ -menu "USB Power Delivery and Type-C drivers" - -if TYPEC_TCPM - -config TYPEC_TCPCI - tristate "Type-C Port Controller Interface driver" - depends on I2C - select REGMAP_I2C - help - Type-C Port Controller driver for TCPCI-compliant controller. - -config TYPEC_RT1711H - tristate "Richtek RT1711H Type-C chip driver" - select TYPEC_TCPCI - help - Richtek RT1711H Type-C chip driver that works with - Type-C Port Controller Manager to provide USB PD and USB - Type-C functionalities. - -endif - -endmenudrivers/staging/typec/Makefile deleted +0
-2@@ -1,2 +0,0 @@ -obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o -obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.odrivers/staging/typec/TODO deleted +0
-5@@ -1,5 +0,0 @@ -tcpci: -- Test with real hardware - -Please send patches to Guenter Roeck <[email protected]> and copy -Heikki Krogerus <[email protected]>.drivers/usb/typec/Kconfig +15
-0@@ -56,6 +56,21 @@ config TYPEC_TCPM if TYPEC_TCPM +config TYPEC_TCPCI + tristate "Type-C Port Controller Interface driver" + depends on I2C + select REGMAP_I2C + help + Type-C Port Controller driver for TCPCI-compliant controller. + +config TYPEC_RT1711H + tristate "Richtek RT1711H Type-C chip driver" + select TYPEC_TCPCI + help + Richtek RT1711H Type-C chip driver that works with + Type-C Port Controller Manager to provide USB PD and USB + Type-C functionalities. + source "drivers/usb/typec/fusb302/Kconfig" config TYPEC_WCOVEdrivers/usb/typec/Makefile +2
-0@@ -7,3 +7,5 @@ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o obj-$(CONFIG_TYPEC_UCSI) += ucsi/ obj-$(CONFIG_TYPEC_TPS6598X) += tps6598x.o obj-$(CONFIG_TYPEC) += mux/ +obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o +obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.odrivers/usb/typec/tcpci.c renamed from drivers/staging/typec/tcpci.c +0
-0drivers/usb/typec/tcpci.h renamed from drivers/staging/typec/tcpci.h +0
-0drivers/usb/typec/tcpci_rt1711h.c renamed from drivers/staging/typec/tcpci_rt1711h.c +0
-0
Signature · 1 line
heikki
Greg KH
maintainerQuoted 5 lines · Li Jun
This patch set attempts to move the tcpci drivers out of staging by fix some tcpci driver issues and define typec and power delivery device properties, the changes are verified on NXP PTN5110, which is a standard tcpci typec port controller device with power delivery support, tested power source and sink with drp config.
Nice work, thanks for sticking with this. All now merged.
greg k-h