staging: typec: tcpci: declare private structure as static
PATCH 1/7 staging: typec: tcpci: declare private structure as static
From: Olivier Leveque <[email protected]>
This fixes a sparse warning regarding an undeclared symbol. Since the structure tcpci_tcpc_config is private to tcpci.c, it should be declared as static.
--- drivers/staging/typec/tcpci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/typec/tcpci.c +1 -1
@@ -425,7 +425,7 @@ static const struct regmap_config tcpci_regmap_config = { .max_register = 0x7F, /* 0x80 .. 0xFF are vendor defined */ }; -const struct tcpc_config tcpci_tcpc_config = { +static const struct tcpc_config tcpci_tcpc_config = { .type =TYPEC_PORT_DFP , .default_role =TYPEC_SINK , };
Signature · 1 line
2.7.4
PATCH 2/7 staging: typec: fusb302: Fix module autoload
From: Javier Martinez Canillas <[email protected]>
If the driver is built as a module, autoload won't work because the module alias information is not filled. So user-space can't match the registered device with the corresponding module.
Export the OF and I2C device ID table entries as module aliases, using the MODULE_DEVICE_TABLE() macro.
Before this patch:
$ modinfo drivers/staging/typec/fusb302/fusb302.ko | grep alias $
After this patch:
$ modinfo drivers/staging/typec/fusb302/fusb302.ko | grep alias alias: of:N*T*Cfcs,fusb302C* alias: of:N*T*Cfcs,fusb302 alias: i2c:typec_fusb302
--- drivers/staging/typec/fusb302/fusb302.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/staging/typec/fusb302/fusb302.c +2 -0
@@ -1787,11 +1787,13 @@ static const struct of_device_id fusb302_dt_match[] = { {.compatible = "fcs,fusb302"}, {}, }; +MODULE_DEVICE_TABLE (of, fusb302_dt_match);static const struct i2c_device_id fusb302_i2c_device_id[] = { {"typec_fusb302" ,0 }, {}, }; +MODULE_DEVICE_TABLE (i2c, fusb302_i2c_device_id);static const struct dev_pm_ops fusb302_pm_ops = { .suspend = fusb302_pm_suspend,
Signature · 1 line
2.7.4
PATCH 3/7 staging: typec: fusb302: Fix chip->vbus_present init value
In reply to Guenter RoeckFrom: Yueyao Zhu <[email protected]>
FUSB_REG_STATUS0 & FUSB_REG_STATUS0_VBUSOK = 0x40 & 0x80 is always zero. Fix the code to what it is intended to be: check the VBUSOK bit of the value read from address FUSB_REG_STATUS0.
--- drivers/staging/typec/fusb302/fusb302.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/typec/fusb302/fusb302.c +1 -1
@@ -489,7 +489,7 @@ static int tcpm_init(struct tcpc_dev *dev) ret =fusb302_i2c_read (chip,FUSB_REG_STATUS0 , &data);if (ret <0 )return ret; - chip->vbus_present = !!(FUSB_REG_STATUS0 &FUSB_REG_STATUS0_VBUSOK ); + chip->vbus_present = !!(data &FUSB_REG_STATUS0_VBUSOK ); ret =fusb302_i2c_read (chip,FUSB_REG_DEVICE_ID , &data);if (ret <0 )return ret;
Signature · 1 line
2.7.4
PATCH 4/7 staging: typec: tcpm: Drop duplicate PD messages
In reply to Guenter RoeckPer USB PD standard, we have to drop duplicate PD messages. We can not expect lower protocol layers to drop such messages, since lower layers don't know if a message was dropped somewhere else in the stack.
Originally-from: Puma Hsu <[email protected]>
--- drivers/staging/typec/pd.h | 10 ++++++++++ drivers/staging/typec/tcpm.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
drivers/staging/typec/pd.h +10 -0
@@ -92,6 +92,16 @@ static inline unsigned int pd_header_type_le(__le16 header)return pd_header_type (le16_to_cpu (header)); } +static inline unsigned int pd_header_msgid (u16 header) +{ +return (header >>PD_HEADER_ID_SHIFT ) &PD_HEADER_ID_MASK ; +} + +static inline unsigned int pd_header_msgid_le (__le16 header) +{ +return pd_header_msgid (le16_to_cpu (header)); +} +#define PD_MAX_PAYLOAD 7struct pd_message {
drivers/staging/typec/tcpm.c +29 -0
@@ -238,6 +238,7 @@ struct tcpm_port {unsigned int hard_reset_count;bool pd_capable;bool explicit_contract; +unsigned int rx_msgid;/* Partner capabilities/requests */ u32 sink_request;
@@ -1415,6 +1416,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,break ;case SOFT_RESET_SEND : port->message_id =0 ; + port->rx_msgid =-1 ;if (port->pwr_role ==TYPEC_SOURCE ) next_state =SRC_SEND_CAPABILITIES ;else
@@ -1503,6 +1505,22 @@ static void tcpm_pd_rx_handler(struct work_struct *work) port->attached);if (port->attached) { +enum pd_ctrl_msg_type type =pd_header_type_le (msg->header); +unsigned int msgid =pd_header_msgid_le (msg->header); + +/* +* USB PD standard, 6.6.1.2: +* "... if MessageID value in a received Message is the +* same as the stored value, the receiver shall return a +* GoodCRC Message with that MessageID value and drop +* the Message (this is a retry of an already received +* Message). Note: this shall not apply to the Soft_Reset +* Message which always has a MessageID value of zero." +*/ +if (msgid == port->rx_msgid && type !=PD_CTRL_SOFT_RESET ) + goto done; + port->rx_msgid = msgid; +/* * If both ends believe to be DFP/host, we have a data role * mismatch.
@@ -1520,6 +1538,7 @@ static void tcpm_pd_rx_handler(struct work_struct *work) } } +done:mutex_unlock (&port->lock);kfree (event); }
@@ -1957,6 +1976,12 @@ static void tcpm_reset_port(struct tcpm_port *port) port->attached = false; port->pd_capable = false; +/* +* First Rx ID should be 0; set this to a sentinel of -1 so that +* we can check tcpm_pd_rx_handler() if we had seen it before. +*/ + port->rx_msgid =-1 ; + port->tcpc->set_pd_rx (port->tcpc, false);tcpm_init_vbus (port);/* also disables charging */ tcpm_init_vconn (port);
@@ -2170,6 +2195,7 @@ static void run_state_machine(struct tcpm_port *port) port->pwr_opmode =TYPEC_PWR_MODE_USB ; port->caps_count =0 ; port->message_id =0 ; + port->rx_msgid =-1 ; port->explicit_contract = false;tcpm_set_state (port,SRC_SEND_CAPABILITIES ,0 );break ;
@@ -2329,6 +2355,7 @@ static void run_state_machine(struct tcpm_port *port)typec_set_pwr_opmode (port->typec_port,TYPEC_PWR_MODE_USB ); port->pwr_opmode =TYPEC_PWR_MODE_USB ; port->message_id =0 ; + port->rx_msgid =-1 ; port->explicit_contract = false;tcpm_set_state (port,SNK_DISCOVERY ,0 );break ;
@@ -2496,6 +2523,7 @@ static void run_state_machine(struct tcpm_port *port)/* Soft_Reset states */ case SOFT_RESET : port->message_id =0 ; + port->rx_msgid =-1 ;tcpm_pd_send_control (port,PD_CTRL_ACCEPT );if (port->pwr_role ==TYPEC_SOURCE )tcpm_set_state (port,SRC_SEND_CAPABILITIES ,0 );
@@ -2504,6 +2532,7 @@ static void run_state_machine(struct tcpm_port *port)break ;case SOFT_RESET_SEND : port->message_id =0 ; + port->rx_msgid =-1 ;if (tcpm_pd_send_control (port,PD_CTRL_SOFT_RESET ))tcpm_set_state_cond (port,hard_reset_state (port),0 );else
Signature · 1 line
2.7.4
PATCH 5/7 staging: typec: tcpm: Set correct flags in PD request messages
In reply to Guenter RoeckWe do support USB PD communication, and devices supported by this driver typically use USB power for purposes other than USB communication.
Originally-from: Puma Hsu <[email protected]>
--- drivers/staging/typec/tcpm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/typec/tcpm.c +1 -2
@@ -1738,8 +1738,7 @@ static int tcpm_pd_build_request(struct tcpm_port *port, u32 *rdo) } ma =min (ma, port->max_snk_ma); -/* XXX: Any other flags need to be set? */ - flags =0 ; + flags =RDO_USB_COMM |RDO_NO_SUSPEND ;/* Set mismatch bit if offered power is less than operating power */ mw = ma * mv /1000 ;
Signature · 1 line
2.7.4
PATCH 6/7 staging: typec: tcpm: Respond to Discover Identity commands
In reply to Guenter RoeckIf the lower level driver provided a list of VDOs in its configuration data, send it to the partner as response to a Discover Identity command if in device mode (UFP).
Cc: Yueyao Zhu <[email protected]>
Originally-from: Puma Hsu <[email protected]>
--- drivers/staging/typec/pd_vdo.h | 4 +++- drivers/staging/typec/tcpm.c | 27 +++++++++++++++++++++++++++ drivers/staging/typec/tcpm.h | 3 +++ 3 files changed, 33 insertions(+), 1 deletion(-)
drivers/staging/typec/pd_vdo.h +3 -1
@@ -22,6 +22,9 @@* VDM object is minimum of VDM header + 6 additional data objects. */ +#define VDO_MAX_OBJECTS 6 +#define VDO_MAX_SIZE (VDO_MAX_OBJECTS + 1) +/* * VDM header * ----------
@@ -34,7 +37,6 @@* <5> :: reserved (SVDM), command type (UVDM) * <4:0> :: command */ -#define VDO_MAX_SIZE 7#define VDO (vid, type, custom) \ (((vid) << 16) | \ ((type) << 15) | \
drivers/staging/typec/tcpm.c +27 -0
@@ -252,6 +252,8 @@ struct tcpm_port {unsigned int nr_src_pdo;u32 snk_pdo[PDO_MAX_OBJECTS ];unsigned int nr_snk_pdo; +u32 snk_vdo[VDO_MAX_OBJECTS ]; +unsigned int nr_snk_vdo;unsigned int max_snk_mv;unsigned int max_snk_ma;
@@ -998,6 +1000,7 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt,struct pd_mode_data *modep;int rlen =0 ;u16 svid; +int i;tcpm_log (port,"Rx VDM cmd 0x%x type %d cmd %d len %d" , p0, cmd_type, cmd, cnt);
@@ -1008,6 +1011,14 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt,case CMDT_INIT :switch (cmd) {case CMD_DISCOVER_IDENT : +/* 6.4.4.3.1: Only respond as UFP (device) */ +if (port->data_role ==TYPEC_DEVICE && + port->nr_snk_vdo) { +for (i =0 ; i < port->nr_snk_vdo; i++) + response[i +1 ] + =cpu_to_le32 (port->snk_vdo[i]); + rlen = port->nr_snk_vdo +1 ; + }break ;case CMD_DISCOVER_SVID :break ;
@@ -3320,6 +3331,20 @@ static int tcpm_copy_pdos(u32 *dest_pdo, const u32 *src_pdo,return nr_pdo; } +static int tcpm_copy_vdos (u32 *dest_vdo,const u32 *src_vdo, +unsigned int nr_vdo) +{ +unsigned int i; + +if (nr_vdo >VDO_MAX_OBJECTS ) + nr_vdo =VDO_MAX_OBJECTS ; + +for (i =0 ; i < nr_vdo; i++) + dest_vdo[i] = src_vdo[i]; + +return nr_vdo; +} +void tcpm_update_source_capabilities (struct tcpm_port *port,const u32 *pdo,unsigned int nr_pdo) {
@@ -3410,6 +3435,8 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) 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->max_snk_mv = tcpc->config->max_snk_mv; port->max_snk_ma = tcpc->config->max_snk_ma;
drivers/staging/typec/tcpm.h +3 -0
@@ -60,6 +60,9 @@ struct tcpc_config {const u32 *snk_pdo;unsigned int nr_snk_pdo; +const u32 *snk_vdo; +unsigned int nr_snk_vdo; +unsigned int max_snk_mv;unsigned int max_snk_ma;unsigned int max_snk_mw;
Signature · 1 line
2.7.4
PATCH 7/7 staging: typec: tcpm: Fix Port Power Role field in PS_RDY messages
In reply to Guenter RoeckPS_RDY messages sent during power swap sequences are expected to reflect the new power role.
--- drivers/staging/typec/tcpm.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/staging/typec/tcpm.c +16 -2
@@ -2607,6 +2607,14 @@ static void run_state_machine(struct tcpm_port *port)break ;case PR_SWAP_SRC_SNK_SOURCE_OFF :tcpm_set_cc (port,TYPEC_CC_RD ); +/* +* USB-PD standard, 6.2.1.4, Port Power Role: +* "During the Power Role Swap Sequence, for the initial Source +* Port, the Port Power Role field shall be set to Sink in the +* PS_RDY Message indicating that the initial Source’s power +* supply is turned off" +*/ +tcpm_set_pwr_role (port,TYPEC_SINK );if (tcpm_pd_send_control (port,PD_CTRL_PS_RDY )) {tcpm_set_state (port,ERROR_RECOVERY ,0 );break ;
@@ -2614,7 +2622,6 @@ static void run_state_machine(struct tcpm_port *port)tcpm_set_state_cond (port,SNK_UNATTACHED ,PD_T_PS_SOURCE_ON );break ;case PR_SWAP_SRC_SNK_SINK_ON : -tcpm_set_pwr_role (port,TYPEC_SINK );tcpm_swap_complete (port,0 );tcpm_set_state (port,SNK_STARTUP ,0 );break ;
@@ -2626,8 +2633,15 @@ static void run_state_machine(struct tcpm_port *port)case PR_SWAP_SNK_SRC_SOURCE_ON :tcpm_set_cc (port,tcpm_rp_cc (port));tcpm_set_vbus (port, true); -tcpm_pd_send_control (port,PD_CTRL_PS_RDY ); +/* +* USB PD standard, 6.2.1.4: +* "Subsequent Messages initiated by the Policy Engine, +* such as the PS_RDY Message sent to indicate that Vbus +* is ready, will have the Port Power Role field set to +* Source." +*/ tcpm_set_pwr_role (port,TYPEC_SOURCE ); +tcpm_pd_send_control (port,PD_CTRL_PS_RDY );tcpm_swap_complete (port,0 );tcpm_set_state (port,SRC_STARTUP ,0 );break ;
Signature · 1 line
2.7.4
Greg Kroah-Hartman
maintainerQuoted 11 lines · Guenter Roeck
From: Olivier Leveque <[email protected]>
This fixes a sparse warning regarding an undeclared symbol. Since the structure
tcpci_tcpc_configis private totcpci.c, it should be declared as static.Signed-off-by Olivier Leveque <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/staging/typec/tcpci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Are any of these bugfixes for 4.12-stable, or can they wait for 4.13-rc1?
thanks,
greg k-h
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Guenter Roeck
From: Olivier Leveque <[email protected]>
This fixes a sparse warning regarding an undeclared symbol. Since the structure
tcpci_tcpc_configis private totcpci.c, it should be declared as static.
Quoted 9 lines
Quoted 5 lines
Signed-off-by Olivier Leveque <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/staging/typec/tcpci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Are any of these bugfixes for 4.12-stable, or can they wait for 4.13-rc1?
They should all go into v4.12. There are no functionality enhancements, only real bug fixes.
Thanks,
Guenter