staging: typec: handle vendor defined part and modify drp toggling flow
PATCH 1/1 staging: typec: handle vendor defined part and modify drp toggling flow
From: ShuFanLee <[email protected]>
Handle vendor defined behavior in tcpci_init, tcpci_set_vconn and export tcpci_irq. More operations can be extended in tcpci_data if needed.
According to TCPCI specification, 4.4.5.2 ROLE_CONTROL,
TCPC shall not start DRP toggling until subsequently the TCPM
writes to the COMMAND register to start DRP toggling.
DRP toggling flow is chagned as following:
- Write DRP = 0 & Rd/Rd
- Write DRP = 1
- Set LOOK4CONNECTION command
--- drivers/staging/typec/tcpci.c | 128 +++++++++++++++++++++++++++++++++--------- drivers/staging/typec/tcpci.h | 13 +++++ 2 files changed, 115 insertions(+), 26 deletions(-)
patch changelogs between v1 & v2
- Remove unnecessary i2c_client in the structure of tcpci
- Rename structure of tcpci_vendor_data to tcpci_data
- Not exporting tcpci read/write wrappers but register i2c regmap in glue driver
- Add set_vconn ops in tcpci_data
(It is necessary for RT1711H to enable/disable idle mode before disabling/enabling vconn)
- Export tcpci_irq so that vendor can call it in their own IRQ handler
patch changelogs between v2 & v3
- Change the return type of tcpci_irq from int to irqreturn_t
drivers/staging/typec/tcpci.c +102 -26
@@ -21,7 +21,6 @@struct tcpci {struct device *dev; -struct i2c_client *client;struct tcpm_port *port;
@@ -30,6 +29,12 @@ struct tcpci {bool controls_vbus;struct tcpc_dev tcpc; +struct tcpci_data *data; +}; + +struct tcpci_chip { +struct tcpci *tcpci; +struct tcpci_data data; };static inline struct tcpci *tcpc_to_tcpci (struct tcpc_dev *tcpc)
@@ -37,8 +42,7 @@ static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) return container_of(tcpc, struct tcpci, tcpc); } -static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg, -u16 *val) +static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg,u16 *val) {return regmap_raw_read (tcpci->regmap, reg, val,sizeof (u16)); }
@@ -98,8 +102,10 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)static int tcpci_start_drp_toggling (struct tcpc_dev *tcpc,enum typec_cc_status cc) { +int ret;struct tcpci *tcpci =tcpc_to_tcpci (tcpc); -unsigned int reg =TCPC_ROLE_CTRL_DRP ; +unsigned int reg = (TCPC_ROLE_CTRL_CC_RD <<TCPC_ROLE_CTRL_CC1_SHIFT ) | + (TCPC_ROLE_CTRL_CC_RD <<TCPC_ROLE_CTRL_CC2_SHIFT );switch (cc) {default :
@@ -117,7 +123,19 @@ static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc,break ; } -return regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; +usleep_range (500 ,1000 ); + reg |=TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; + ret =regmap_write (tcpci->regmap,TCPC_COMMAND , +TCPC_CMD_LOOK4CONNECTION ); +if (ret <0 ) +return ret; +return 0 ; }static enum typec_cc_status tcpci_to_typec_cc (unsigned int cc,bool sink)
@@ -178,6 +196,16 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)struct tcpci *tcpci =tcpc_to_tcpci (tcpc);int ret; +/* Handle vendor set vconn */ +if (tcpci->data) { +if (tcpci->data->set_vconn) { + ret = tcpci->data->set_vconn (tcpci, tcpci->data, + enable); +if (ret <0 ) +return ret; + } + } + ret =regmap_write (tcpci->regmap,TCPC_POWER_CTRL , enable ?TCPC_POWER_CTRL_VCONN_ENABLE :0 );if (ret <0 )
@@ -323,6 +351,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)if (time_after (jiffies, timeout))return -ETIMEDOUT ; +/* Handle vendor init */ +if (tcpci->data) { +if (tcpci->data->init) { + ret = tcpci->data->init (tcpci, tcpci->data); +if (ret <0 ) +return ret; + } + } +/* Clear all events */ ret =tcpci_write16 (tcpci,TCPC_ALERT ,0xffff );if (ret <0 )
@@ -344,9 +381,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)return tcpci_write16 (tcpci,TCPC_ALERT_MASK , reg); } -static irqreturn_t tcpci_irq (int irq,void *dev_id) +static irqreturn_t _tcpci_irq (int irq,void *dev_id) {struct tcpci *tcpci = dev_id; + +return tcpci_irq (tcpci); +} + +irqreturn_t tcpci_irq (struct tcpci *tcpci) +{u16 status;tcpci_read16 (tcpci,TCPC_ALERT , &status);
@@ -412,6 +455,7 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id)return IRQ_HANDLED ; } +EXPORT_SYMBOL_GPL (tcpci_irq);static const struct regmap_config tcpci_regmap_config = { .reg_bits =8 ,
@@ -435,22 +479,18 @@ static int tcpci_parse_config(struct tcpci *tcpci)return 0 ; } -static int tcpci_probe (struct i2c_client *client, -const struct i2c_device_id *i2c_id) +struct tcpci *tcpci_register_port (struct device *dev,struct tcpci_data *data) {struct tcpci *tcpci;int err; - tcpci =devm_kzalloc (&client->dev,sizeof (*tcpci),GFP_KERNEL ); + tcpci =devm_kzalloc (dev,sizeof (*tcpci),GFP_KERNEL );if (!tcpci) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); - tcpci->client = client; - tcpci->dev = &client->dev; -i2c_set_clientdata (client, tcpci); - tcpci->regmap =devm_regmap_init_i2c (client, &tcpci_regmap_config); -if (IS_ERR (tcpci->regmap)) -return PTR_ERR (tcpci->regmap); + tcpci->dev = dev; + tcpci->data = data; + tcpci->regmap = data->regmap; tcpci->tcpc.init = tcpci_init; tcpci->tcpc.get_vbus = tcpci_get_vbus;
@@ -467,27 +507,63 @@ static int tcpci_probe(struct i2c_client *client, err =tcpci_parse_config (tcpci);if (err <0 ) -return err; +return ERR_PTR (err); + + tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); +if (PTR_ERR_OR_ZERO (tcpci->port)) +return ERR_CAST (tcpci->port); -/* Disable chip interrupts */ -tcpci_write16 (tcpci,TCPC_ALERT_MASK ,0 ); +return tcpci; +} +EXPORT_SYMBOL_GPL (tcpci_register_port); + +void tcpci_unregister_port (struct tcpci *tcpci) +{ +tcpm_unregister_port (tcpci->port); +} +EXPORT_SYMBOL_GPL (tcpci_unregister_port); - err =devm_request_threaded_irq (tcpci->dev, client->irq,NULL , - tcpci_irq, +static int tcpci_probe (struct i2c_client *client, +const struct i2c_device_id *i2c_id) +{ +struct tcpci_chip *chip; +int err; +u16 val =0 ; + + chip =devm_kzalloc (&client->dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->data.regmap =devm_regmap_init_i2c (client, &tcpci_regmap_config); +if (IS_ERR (chip->data.regmap)) +return PTR_ERR (chip->data.regmap); + +/* Disable chip interrupts before requesting irq */ + err =regmap_raw_write (chip->data.regmap,TCPC_ALERT_MASK , &val, +sizeof (u16)); +if (err <0 ) +return err; + + err =devm_request_threaded_irq (&client->dev, client->irq,NULL , + _tcpci_irq,IRQF_ONESHOT |IRQF_TRIGGER_LOW , -dev_name (tcpci->dev), tcpci); +dev_name (&client->dev), chip);if (err <0 )return err; - tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); -return PTR_ERR_OR_ZERO (tcpci->port); + chip->tcpci =tcpci_register_port (&client->dev, &chip->data); +if (PTR_ERR_OR_ZERO (chip->tcpci)) +return PTR_ERR (chip->tcpci); + +i2c_set_clientdata (client, chip); +return 0 ; }static int tcpci_remove (struct i2c_client *client) { -struct tcpci *tcpci =i2c_get_clientdata (client); +struct tcpci_chip *chip =i2c_get_clientdata (client); -tcpm_unregister_port (tcpci->port); +tcpci_unregister_port (chip->tcpci);return 0 ; }
drivers/staging/typec/tcpci.h +13 -0
@@ -59,6 +59,7 @@#define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)#define TCPC_CC_STATUS 0x1d +#define TCPC_CC_STATUS_DRPRST BIT(5)#define TCPC_CC_STATUS_TERM BIT(4)#define TCPC_CC_STATUS_CC2_SHIFT 2#define TCPC_CC_STATUS_CC2_MASK 0x3
@@ -121,4 +122,16 @@#define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76#define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78 +struct tcpci ; +struct tcpci_data { +struct regmap *regmap; +int (*init)(struct tcpci *tcpci,struct tcpci_data *data); +int (*set_vconn)(struct tcpci *tcpci,struct tcpci_data *data, +bool enable); +}; + +struct tcpci *tcpci_register_port (struct device *dev,struct tcpci_data *data); +void tcpci_unregister_port (struct tcpci *tcpci); +irqreturn_t tcpci_irq (struct tcpci *tcpci); +#endif /* __LINUX_USB_TCPCI_H */
Quoted 12 lines · ShuFanLee
From: ShuFanLee <[email protected]>
Handle vendor defined behavior in
tcpci_init,tcpci_set_vconnand exporttcpci_irq. More operations can be extended intcpci_dataif needed.
According to TCPCI specification, 4.4.5.2ROLE_CONTROL,
TCPC shall not start DRP toggling until subsequently the TCPM
writes to the COMMAND register to start DRP toggling.
DRP toggling flow is chagned as following:
- Write DRP = 0 & Rd/Rd
- Write DRP = 1
- Set LOOK4CONNECTION command
Quoted 1 line
Signed-off-by ShuFanLee <[email protected]>
Mostly loooks good to me. Couple of nitpicks below.
Guenter
Quoted 71 lines
--- drivers/staging/typec/tcpci.c | 128 +++++++++++++++++++++++++++++++++--------- drivers/staging/typec/tcpci.h | 13 +++++ 2 files changed, 115 insertions(+), 26 deletions(-)patch changelogs between v1 & v2
- Remove unnecessaryi2c_clientin the structure of tcpci
- Rename structure oftcpci_vendor_datatotcpci_data
- Not exporting tcpci read/write wrappers but register i2c regmap in glue driver
- Addset_vconnops intcpci_data
(It is necessary for RT1711H to enable/disable idle mode before disabling/enabling vconn)
- Exporttcpci_irqso that vendor can call it in their own IRQ handlerpatch changelogs between v2 & v3
- Change the return type oftcpci_irqfrom int toirqreturn_tdrivers/staging/typec/tcpci.c +13
-5@@ -21,7 +21,6 @@struct tcpci {struct device *dev; -struct i2c_client *client;struct tcpm_port *port;@@ -30,6 +29,12 @@ struct tcpci {bool controls_vbus;struct tcpc_dev tcpc; +struct tcpci_data *data; +}; + +struct tcpci_chip { +struct tcpci *tcpci; +struct tcpci_data data; };static inline struct tcpci *tcpc_to_tcpci (struct tcpc_dev *tcpc)@@ -37,8 +42,7 @@ static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) return container_of(tcpc, struct tcpci, tcpc); } -static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg, -u16 *val) +static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg,u16 *val) {return regmap_raw_read (tcpci->regmap, reg, val,sizeof (u16)); }@@ -98,8 +102,10 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)static int tcpci_start_drp_toggling (struct tcpc_dev *tcpc,enum typec_cc_status cc) { +int ret;struct tcpci *tcpci =tcpc_to_tcpci (tcpc); -unsigned int reg =TCPC_ROLE_CTRL_DRP ; +unsigned int reg = (TCPC_ROLE_CTRL_CC_RD <<TCPC_ROLE_CTRL_CC1_SHIFT ) | + (TCPC_ROLE_CTRL_CC_RD <<TCPC_ROLE_CTRL_CC2_SHIFT );switch (cc) {default :@@ -117,7 +123,19 @@ static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc,break ; } -return regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret;
drivers/staging/typec/tcpci.c static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc, · line 138
Quoted 10 lines
drivers/staging/typec/tcpci.c +10
-0+usleep_range (500 ,1000 ); + reg |=TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; + ret =regmap_write (tcpci->regmap,TCPC_COMMAND , +TCPC_CMD_LOOK4CONNECTION ); +if (ret <0 ) +return ret; +return 0 ;
regmap_write returns a negative return code or 0, thus this can be simplified to
return regmap_write(...);
Quoted 37 lines
drivers/staging/typec/tcpci.c +19
-0}static enum typec_cc_status tcpci_to_typec_cc (unsigned int cc,bool sink)@@ -178,6 +196,16 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)struct tcpci *tcpci =tcpc_to_tcpci (tcpc);int ret; +/* Handle vendor set vconn */ +if (tcpci->data) { +if (tcpci->data->set_vconn) { + ret = tcpci->data->set_vconn (tcpci, tcpci->data, + enable); +if (ret <0 ) +return ret; + } + } + ret =regmap_write (tcpci->regmap,TCPC_POWER_CTRL , enable ?TCPC_POWER_CTRL_VCONN_ENABLE :0 );if (ret <0 )@@ -323,6 +351,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)if (time_after (jiffies, timeout))return -ETIMEDOUT ; +/* Handle vendor init */ +if (tcpci->data) { +if (tcpci->data->init) { + ret = tcpci->data->init (tcpci, tcpci->data); +if (ret <0 ) +return ret; + } + } +/* Clear all events */ ret =tcpci_write16 (tcpci,TCPC_ALERT ,0xffff );if (ret <0 )
drivers/staging/typec/tcpci.c static int tcpci_init(struct tcpc_dev *tcpc) · line 389
Quoted 10 lines
drivers/staging/typec/tcpci.c +4
-1@@ -344,9 +381,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)return tcpci_write16 (tcpci,TCPC_ALERT_MASK , reg); } -static irqreturn_t tcpci_irq (int irq,void *dev_id) +static irqreturn_t _tcpci_irq (int irq,void *dev_id) {struct tcpci *tcpci = dev_id; + +return tcpci_irq (tcpci); +}
Hmm, normally I'd expect this function _after_ the function it calls. Guess that doesn't matter much here, so I am fine with it as long as Greg is ok with it as well.
Quoted 149 lines
drivers/staging/typec/tcpci.c +56
-20+ +irqreturn_t tcpci_irq (struct tcpci *tcpci) +{u16 status;tcpci_read16 (tcpci,TCPC_ALERT , &status);@@ -412,6 +455,7 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id)return IRQ_HANDLED ; } +EXPORT_SYMBOL_GPL (tcpci_irq);static const struct regmap_config tcpci_regmap_config = { .reg_bits =8 ,@@ -435,22 +479,18 @@ static int tcpci_parse_config(struct tcpci *tcpci)return 0 ; } -static int tcpci_probe (struct i2c_client *client, -const struct i2c_device_id *i2c_id) +struct tcpci *tcpci_register_port (struct device *dev,struct tcpci_data *data) {struct tcpci *tcpci;int err; - tcpci =devm_kzalloc (&client->dev,sizeof (*tcpci),GFP_KERNEL ); + tcpci =devm_kzalloc (dev,sizeof (*tcpci),GFP_KERNEL );if (!tcpci) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); - tcpci->client = client; - tcpci->dev = &client->dev; -i2c_set_clientdata (client, tcpci); - tcpci->regmap =devm_regmap_init_i2c (client, &tcpci_regmap_config); -if (IS_ERR (tcpci->regmap)) -return PTR_ERR (tcpci->regmap); + tcpci->dev = dev; + tcpci->data = data; + tcpci->regmap = data->regmap; tcpci->tcpc.init = tcpci_init; tcpci->tcpc.get_vbus = tcpci_get_vbus;@@ -467,27 +507,63 @@ static int tcpci_probe(struct i2c_client *client, err =tcpci_parse_config (tcpci);if (err <0 ) -return err; +return ERR_PTR (err); + + tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); +if (PTR_ERR_OR_ZERO (tcpci->port)) +return ERR_CAST (tcpci->port); -/* Disable chip interrupts */ -tcpci_write16 (tcpci,TCPC_ALERT_MASK ,0 ); +return tcpci; +} +EXPORT_SYMBOL_GPL (tcpci_register_port); + +void tcpci_unregister_port (struct tcpci *tcpci) +{ +tcpm_unregister_port (tcpci->port); +} +EXPORT_SYMBOL_GPL (tcpci_unregister_port); - err =devm_request_threaded_irq (tcpci->dev, client->irq,NULL , - tcpci_irq, +static int tcpci_probe (struct i2c_client *client, +const struct i2c_device_id *i2c_id) +{ +struct tcpci_chip *chip; +int err; +u16 val =0 ; + + chip =devm_kzalloc (&client->dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->data.regmap =devm_regmap_init_i2c (client, &tcpci_regmap_config); +if (IS_ERR (chip->data.regmap)) +return PTR_ERR (chip->data.regmap); + +/* Disable chip interrupts before requesting irq */ + err =regmap_raw_write (chip->data.regmap,TCPC_ALERT_MASK , &val, +sizeof (u16)); +if (err <0 ) +return err; + + err =devm_request_threaded_irq (&client->dev, client->irq,NULL , + _tcpci_irq,IRQF_ONESHOT |IRQF_TRIGGER_LOW , -dev_name (tcpci->dev), tcpci); +dev_name (&client->dev), chip);if (err <0 )return err; - tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); -return PTR_ERR_OR_ZERO (tcpci->port); + chip->tcpci =tcpci_register_port (&client->dev, &chip->data); +if (PTR_ERR_OR_ZERO (chip->tcpci)) +return PTR_ERR (chip->tcpci); + +i2c_set_clientdata (client, chip); +return 0 ; }static int tcpci_remove (struct i2c_client *client) { -struct tcpci *tcpci =i2c_get_clientdata (client); +struct tcpci_chip *chip =i2c_get_clientdata (client); -tcpm_unregister_port (tcpci->port); +tcpci_unregister_port (chip->tcpci);return 0 ; }drivers/staging/typec/tcpci.h +13
-0@@ -59,6 +59,7 @@#define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)#define TCPC_CC_STATUS 0x1d +#define TCPC_CC_STATUS_DRPRST BIT(5)#define TCPC_CC_STATUS_TERM BIT(4)#define TCPC_CC_STATUS_CC2_SHIFT 2#define TCPC_CC_STATUS_CC2_MASK 0x3@@ -121,4 +122,16 @@#define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76#define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78 +struct tcpci ; +struct tcpci_data { +struct regmap *regmap; +int (*init)(struct tcpci *tcpci,struct tcpci_data *data); +int (*set_vconn)(struct tcpci *tcpci,struct tcpci_data *data, +bool enable); +}; + +struct tcpci *tcpci_register_port (struct device *dev,struct tcpci_data *data); +void tcpci_unregister_port (struct tcpci *tcpci); +irqreturn_t tcpci_irq (struct tcpci *tcpci); +#endif /* __LINUX_USB_TCPCI_H */ Signature · 1 line
1.9.1
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Guenter,
regmap_write returns a negative return code or 0, thus this can be
simplified to
return regmap_write(...);
Ok, I'll modify it in v4
Hmm, normally I'd expect this function _after_ the function it calls. Guess that doesn't matter much here, so I am fine with it as long as Greg is ok with it as well.
Do you mean it maybe better to call vendor's set_vconn after normalset_vconn is finished?
If I understand correctly, I can also modify it in v4. For RT1711H, it
also works by enabling/disabling idle mode after set_vconn.
2018-02-22 6:15 GMT+08:00 Guenter Roeck <[email protected]>:
Quoted 323 lines · ShuFanLee
Quoted 3 lines
From: ShuFanLee <[email protected]>
Handle vendor defined behavior in
tcpci_init,tcpci_set_vconnand export
tcpci_irq.Quoted 10 lines
More operations can be extended in
tcpci_dataif needed. According to TCPCI specification, 4.4.5.2ROLE_CONTROL, TCPC shall not start DRP toggling until subsequently the TCPM writes to the COMMAND register to start DRP toggling. DRP toggling flow is chagned as following:
- Write DRP = 0 & Rd/Rd
- Write DRP = 1
- Set LOOK4CONNECTION commandSigned-off-by ShuFanLee <[email protected]>Mostly loooks good to me. Couple of nitpicks below.
Guenter
Quoted 2 lines
--- drivers/staging/typec/tcpci.c | 128 +++++++++++++++++++++++++++++++++---------
Quoted 7 lines
drivers/staging/typec/tcpci.h | 13 +++++ 2 files changed, 115 insertions(+), 26 deletions(-)patch changelogs between v1 & v2
- Remove unnecessaryi2c_clientin the structure of tcpci
- Rename structure oftcpci_vendor_datatotcpci_data
- Not exporting tcpci read/write wrappers but register i2c regmap inglue driver
Quoted 2 lines
- Add
set_vconnops intcpci_data
(It is necessary for RT1711H to enable/disable idle mode beforedisabling/enabling vconn)
Review
Quoted 6 lines
- Export
tcpci_irqso that vendor can call it in their own IRQ handlerpatch changelogs between v2 & v3
- Change the return type oftcpci_irqfrom int toirqreturn_t(quoted diff) +0
-0
b/drivers/staging/typec/tcpci.cdrivers/staging/typec/tcpci.c static inline struct tcpci *tcpc_to_tcpci(struct
Quoted 25 lines
index 9bd4412..4959c69 100644
drivers/staging/typec/tcpci.c +6
-1@@ -21,7 +21,6 @@struct tcpci {struct device *dev; -struct i2c_client *client;struct tcpm_port *port;@@ -30,6 +29,12 @@ struct tcpci {bool controls_vbus;struct tcpc_dev tcpc; +struct tcpci_data *data; +}; + +struct tcpci_chip { +struct tcpci *tcpci; +struct tcpci_data data; };static inline struct tcpci *tcpc_to_tcpci (struct tcpc_dev *tcpc)@@ -37,8 +42,7 @@ static inline struct tcpci *tcpc_to_tcpci(struct
tcpc_dev*tcpc)drivers/staging/typec/tcpci.c static int tcpci_set_cc(struct tcpc_dev *tcpc, enum
Quoted 10 lines
drivers/staging/typec/tcpci.c +1
-2return container_of(tcpc, struct tcpci, tcpc); } -static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg, -u16 *val) +static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg,u16 *val) {return regmap_raw_read (tcpci->regmap, reg, val,sizeof (u16)); }@@ -98,8 +102,10 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum
typec_cc_statuscc)drivers/staging/typec/tcpci.c static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
Quoted 7 lines
drivers/staging/typec/tcpci.c +2
-1static int tcpci_start_drp_toggling (struct tcpc_dev *tcpc,enum typec_cc_status cc) { +int ret;struct tcpci *tcpci =tcpc_to_tcpci (tcpc); -unsigned int reg =TCPC_ROLE_CTRL_DRP ; + unsigned int reg = (TCPC_ROLE_CTRL_CC_RD <<
TCPC_ROLE_CTRL_CC1_SHIFT) |drivers/staging/typec/tcpci.c static int tcpci_set_cc(struct tcpc_dev *tcpc, enum · line 108
Quoted 1 line
drivers/staging/typec/tcpci.c +1
-0+ (TCPC_ROLE_CTRL_CC_RD <<
TCPC_ROLE_CTRL_CC2_SHIFT);drivers/staging/typec/tcpci.c static int tcpci_start_drp_toggling(struct
Quoted 4 lines
drivers/staging/typec/tcpci.c +0
-0switch (cc) {default :@@ -117,7 +123,19 @@ static int tcpci_start_drp_toggling(struct
tcpc_dev*tcpc,Quoted 7 lines
drivers/staging/typec/tcpci.c +3
-1break ; } -return regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret;drivers/staging/typec/tcpci.c static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc, · line 138
Quoted 10 lines
drivers/staging/typec/tcpci.c +10
-0+usleep_range (500 ,1000 ); + reg |=TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; + ret =regmap_write (tcpci->regmap,TCPC_COMMAND , +TCPC_CMD_LOOK4CONNECTION ); +if (ret <0 ) +return ret; +return 0 ;
regmap_writereturns a negative return code or 0, thus this can be simplified toreturn regmap_write(...);drivers/staging/typec/tcpci.c static int tcpci_start_drp_toggling(struct · line 141
Quoted 3 lines
drivers/staging/typec/tcpci.c +0
-0} static enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, boolsink)
drivers/staging/typec/tcpci.c static int tcpci_set_vconn(struct tcpc_dev *tcpc,
Quoted 1 line
drivers/staging/typec/tcpci.c +0
-0@@ -178,6 +196,16 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc,bool enable)
Quoted 33 lines
drivers/staging/typec/tcpci.c +19
-0struct tcpci *tcpci =tcpc_to_tcpci (tcpc);int ret; +/* Handle vendor set vconn */ +if (tcpci->data) { +if (tcpci->data->set_vconn) { + ret = tcpci->data->set_vconn (tcpci, tcpci->data, + enable); +if (ret <0 ) +return ret; + } + } + ret =regmap_write (tcpci->regmap,TCPC_POWER_CTRL , enable ?TCPC_POWER_CTRL_VCONN_ENABLE :0 );if (ret <0 )@@ -323,6 +351,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)if (time_after (jiffies, timeout))return -ETIMEDOUT ; +/* Handle vendor init */ +if (tcpci->data) { +if (tcpci->data->init) { + ret = tcpci->data->init (tcpci, tcpci->data); +if (ret <0 ) +return ret; + } + } +/* Clear all events */ ret =tcpci_write16 (tcpci,TCPC_ALERT ,0xffff );if (ret <0 )drivers/staging/typec/tcpci.c static int tcpci_init(struct tcpc_dev *tcpc) · line 389
Quoted 10 lines
drivers/staging/typec/tcpci.c +4
-1@@ -344,9 +381,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)return tcpci_write16 (tcpci,TCPC_ALERT_MASK , reg); } -static irqreturn_t tcpci_irq (int irq,void *dev_id) +static irqreturn_t _tcpci_irq (int irq,void *dev_id) {struct tcpci *tcpci = dev_id; + +return tcpci_irq (tcpci); +}Hmm, normally I'd expect this function _after_ the function it calls. Guess that doesn't matter much here, so I am fine with it as long as Greg is ok with it as well.
Quoted 15 lines
drivers/staging/typec/tcpci.c +4
-0+ +irqreturn_t tcpci_irq (struct tcpci *tcpci) +{u16 status;tcpci_read16 (tcpci,TCPC_ALERT , &status);@@ -412,6 +455,7 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id)return IRQ_HANDLED ; } +EXPORT_SYMBOL_GPL (tcpci_irq);static const struct regmap_config tcpci_regmap_config = { .reg_bits =8 ,drivers/staging/typec/tcpci.c static int tcpci_parse_config(struct tcpci *tcpci) · line 482
Quoted 6 lines
drivers/staging/typec/tcpci.c +1
-2@@ -435,22 +479,18 @@ static int tcpci_parse_config(struct tcpci *tcpci)return 0 ; } -static int tcpci_probe (struct i2c_client *client, -const struct i2c_device_id *i2c_id) +struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data*data)
Quoted 49 lines
drivers/staging/typec/tcpci.c +21
-13{struct tcpci *tcpci;int err; - tcpci =devm_kzalloc (&client->dev,sizeof (*tcpci),GFP_KERNEL ); + tcpci =devm_kzalloc (dev,sizeof (*tcpci),GFP_KERNEL );if (!tcpci) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); - tcpci->client = client; - tcpci->dev = &client->dev; -i2c_set_clientdata (client, tcpci); - tcpci->regmap =devm_regmap_init_i2c (client, &tcpci_regmap_config); -if (IS_ERR (tcpci->regmap)) -return PTR_ERR (tcpci->regmap); + tcpci->dev = dev; + tcpci->data = data; + tcpci->regmap = data->regmap; tcpci->tcpc.init = tcpci_init; tcpci->tcpc.get_vbus = tcpci_get_vbus;@@ -467,27 +507,63 @@ static int tcpci_probe(struct i2c_client *client, err =tcpci_parse_config (tcpci);if (err <0 ) -return err; +return ERR_PTR (err); + + tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); +if (PTR_ERR_OR_ZERO (tcpci->port)) +return ERR_CAST (tcpci->port); -/* Disable chip interrupts */ -tcpci_write16 (tcpci,TCPC_ALERT_MASK ,0 ); +return tcpci; +} +EXPORT_SYMBOL_GPL (tcpci_register_port); + +void tcpci_unregister_port (struct tcpci *tcpci) +{ +tcpm_unregister_port (tcpci->port); +} +EXPORT_SYMBOL_GPL (tcpci_unregister_port); - err = devm_request_threaded_irq(tcpci->dev, client->irq, NULL, - tcpci_irq, +static int tcpci_probe (struct i2c_client *client, +const struct i2c_device_id *i2c_id)drivers/staging/typec/tcpci.c static int tcpci_probe(struct i2c_client *client, · line 537
Quoted 10 lines
drivers/staging/typec/tcpci.c +10
-0+{ +struct tcpci_chip *chip; +int err; +u16 val =0 ; + + chip =devm_kzalloc (&client->dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->data.regmap = devm_regmap_init_i2c(client,
&tcpci_regmap_config);Review
Quoted 38 lines
drivers/staging/typec/tcpci.c +20
-5+if (IS_ERR (chip->data.regmap)) +return PTR_ERR (chip->data.regmap); + +/* Disable chip interrupts before requesting irq */ + err =regmap_raw_write (chip->data.regmap,TCPC_ALERT_MASK , &val, +sizeof (u16)); +if (err <0 ) +return err; + + err =devm_request_threaded_irq (&client->dev, client->irq,NULL , + _tcpci_irq,IRQF_ONESHOT |IRQF_TRIGGER_LOW , - dev_name(tcpci->dev), tcpci); +dev_name (&client->dev), chip);if (err <0 )return err; - tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); -return PTR_ERR_OR_ZERO (tcpci->port); + chip->tcpci =tcpci_register_port (&client->dev, &chip->data); +if (PTR_ERR_OR_ZERO (chip->tcpci)) +return PTR_ERR (chip->tcpci); + +i2c_set_clientdata (client, chip); +return 0 ; }static int tcpci_remove (struct i2c_client *client) { -struct tcpci *tcpci =i2c_get_clientdata (client); +struct tcpci_chip *chip =i2c_get_clientdata (client); -tcpm_unregister_port (tcpci->port); +tcpci_unregister_port (chip->tcpci);return 0 ; }(quoted diff) +0
-0
b/drivers/staging/typec/tcpci.hQuoted 14 lines
index fdfb06c..40025b2 100644
drivers/staging/typec/tcpci.h +1
-0@@ -59,6 +59,7 @@#define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)#define TCPC_CC_STATUS 0x1d +#define TCPC_CC_STATUS_DRPRST BIT(5)#define TCPC_CC_STATUS_TERM BIT(4)#define TCPC_CC_STATUS_CC2_SHIFT 2#define TCPC_CC_STATUS_CC2_MASK 0x3@@ -121,4 +122,16 @@#define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76#define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78drivers/staging/typec/tcpci.h line 133
Quoted 10 lines
drivers/staging/typec/tcpci.h +9
-0+struct tcpci ; +struct tcpci_data { +struct regmap *regmap; +int (*init)(struct tcpci *tcpci,struct tcpci_data *data); +int (*set_vconn)(struct tcpci *tcpci,struct tcpci_data *data, +bool enable); +}; + +struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data*data);
Quoted 7 lines
drivers/staging/typec/tcpci.h +3
-1+void tcpci_unregister_port (struct tcpci *tcpci); +irqreturn_t tcpci_irq (struct tcpci *tcpci); +#endif /* __LINUX_USB_TCPCI_H */ --1.9.1
Signature · 2 lines
Best Regards, 書帆
Hi Guenter,
regmap_write returns a negative return code or 0, thus this can be
simplified to
return regmap_write(...);
Ok, I'll modify it in v4
Hmm, normally I'd expect this function _after_ the function it calls. Guess that doesn't matter much here, so I am fine with it as long as Greg is ok with it as well.
Do you mean it maybe better to call vendor's set_vconn after normal set_vconn is finished?
If I understand correctly, I can also modify it in v4. For RT1711H, it also works by enabling/disabling idle mode after set_vconn.
Best Regards,
*****************************************
Shu-Fan Lee
Richtek Technology Corporation
TEL: +886-3-5526789 #2359
FAX: +886-3-5526612
*****************************************
________________________________________
寄件者: Guenter Roeck <[email protected]> 代表 Guenter Roeck <[email protected]>
寄件日期: 2018年2月22日 上午 06:15
收件者: ShuFanLee
副本: [email protected]; [email protected]; shufan_lee(李書帆); cy_huang(黃啟原); [email protected]; [email protected] 主旨: Re: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flow
Quoted 12 lines · ShuFanLee
From: ShuFanLee <[email protected]>
Handle vendor defined behavior in
tcpci_init,tcpci_set_vconnand exporttcpci_irq. More operations can be extended intcpci_dataif needed.
According to TCPCI specification, 4.4.5.2ROLE_CONTROL,
TCPC shall not start DRP toggling until subsequently the TCPM
writes to the COMMAND register to start DRP toggling.
DRP toggling flow is chagned as following:
- Write DRP = 0 & Rd/Rd
- Write DRP = 1
- Set LOOK4CONNECTION command
Quoted 1 line
Signed-off-by ShuFanLee <[email protected]>
Mostly loooks good to me. Couple of nitpicks below.
Guenter
Quoted 71 lines
--- drivers/staging/typec/tcpci.c | 128 +++++++++++++++++++++++++++++++++--------- drivers/staging/typec/tcpci.h | 13 +++++ 2 files changed, 115 insertions(+), 26 deletions(-)patch changelogs between v1 & v2
- Remove unnecessaryi2c_clientin the structure of tcpci
- Rename structure oftcpci_vendor_datatotcpci_data
- Not exporting tcpci read/write wrappers but register i2c regmap in glue driver
- Addset_vconnops intcpci_data
(It is necessary for RT1711H to enable/disable idle mode before disabling/enabling vconn)
- Exporttcpci_irqso that vendor can call it in their own IRQ handlerpatch changelogs between v2 & v3
- Change the return type oftcpci_irqfrom int toirqreturn_tdrivers/staging/typec/tcpci.c +13
-5@@ -21,7 +21,6 @@struct tcpci {struct device *dev; -struct i2c_client *client;struct tcpm_port *port;@@ -30,6 +29,12 @@ struct tcpci {bool controls_vbus;struct tcpc_dev tcpc; +struct tcpci_data *data; +}; + +struct tcpci_chip { +struct tcpci *tcpci; +struct tcpci_data data; };static inline struct tcpci *tcpc_to_tcpci (struct tcpc_dev *tcpc)@@ -37,8 +42,7 @@ static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) return container_of(tcpc, struct tcpci, tcpc); } -static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg, -u16 *val) +static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg,u16 *val) {return regmap_raw_read (tcpci->regmap, reg, val,sizeof (u16)); }@@ -98,8 +102,10 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)static int tcpci_start_drp_toggling (struct tcpc_dev *tcpc,enum typec_cc_status cc) { +int ret;struct tcpci *tcpci =tcpc_to_tcpci (tcpc); -unsigned int reg =TCPC_ROLE_CTRL_DRP ; +unsigned int reg = (TCPC_ROLE_CTRL_CC_RD <<TCPC_ROLE_CTRL_CC1_SHIFT ) | + (TCPC_ROLE_CTRL_CC_RD <<TCPC_ROLE_CTRL_CC2_SHIFT );switch (cc) {default :@@ -117,7 +123,19 @@ static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc,break ; } -return regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret;
drivers/staging/typec/tcpci.c static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc, · line 138
Quoted 10 lines
drivers/staging/typec/tcpci.c +10
-0+usleep_range (500 ,1000 ); + reg |=TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; + ret =regmap_write (tcpci->regmap,TCPC_COMMAND , +TCPC_CMD_LOOK4CONNECTION ); +if (ret <0 ) +return ret; +return 0 ;
regmap_write returns a negative return code or 0, thus this can be simplified to
return regmap_write(...);
Quoted 37 lines
drivers/staging/typec/tcpci.c +19
-0}static enum typec_cc_status tcpci_to_typec_cc (unsigned int cc,bool sink)@@ -178,6 +196,16 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)struct tcpci *tcpci =tcpc_to_tcpci (tcpc);int ret; +/* Handle vendor set vconn */ +if (tcpci->data) { +if (tcpci->data->set_vconn) { + ret = tcpci->data->set_vconn (tcpci, tcpci->data, + enable); +if (ret <0 ) +return ret; + } + } + ret =regmap_write (tcpci->regmap,TCPC_POWER_CTRL , enable ?TCPC_POWER_CTRL_VCONN_ENABLE :0 );if (ret <0 )@@ -323,6 +351,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)if (time_after (jiffies, timeout))return -ETIMEDOUT ; +/* Handle vendor init */ +if (tcpci->data) { +if (tcpci->data->init) { + ret = tcpci->data->init (tcpci, tcpci->data); +if (ret <0 ) +return ret; + } + } +/* Clear all events */ ret =tcpci_write16 (tcpci,TCPC_ALERT ,0xffff );if (ret <0 )
drivers/staging/typec/tcpci.c static int tcpci_init(struct tcpc_dev *tcpc) · line 389
Quoted 10 lines
drivers/staging/typec/tcpci.c +4
-1@@ -344,9 +381,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)return tcpci_write16 (tcpci,TCPC_ALERT_MASK , reg); } -static irqreturn_t tcpci_irq (int irq,void *dev_id) +static irqreturn_t _tcpci_irq (int irq,void *dev_id) {struct tcpci *tcpci = dev_id; + +return tcpci_irq (tcpci); +}
Hmm, normally I'd expect this function _after_ the function it calls. Guess that doesn't matter much here, so I am fine with it as long as Greg is ok with it as well.
Quoted 147 lines
drivers/staging/typec/tcpci.c +56
-20+ +irqreturn_t tcpci_irq (struct tcpci *tcpci) +{u16 status;tcpci_read16 (tcpci,TCPC_ALERT , &status);@@ -412,6 +455,7 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id)return IRQ_HANDLED ; } +EXPORT_SYMBOL_GPL (tcpci_irq);static const struct regmap_config tcpci_regmap_config = { .reg_bits =8 ,@@ -435,22 +479,18 @@ static int tcpci_parse_config(struct tcpci *tcpci)return 0 ; } -static int tcpci_probe (struct i2c_client *client, -const struct i2c_device_id *i2c_id) +struct tcpci *tcpci_register_port (struct device *dev,struct tcpci_data *data) {struct tcpci *tcpci;int err; - tcpci =devm_kzalloc (&client->dev,sizeof (*tcpci),GFP_KERNEL ); + tcpci =devm_kzalloc (dev,sizeof (*tcpci),GFP_KERNEL );if (!tcpci) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); - tcpci->client = client; - tcpci->dev = &client->dev; -i2c_set_clientdata (client, tcpci); - tcpci->regmap =devm_regmap_init_i2c (client, &tcpci_regmap_config); -if (IS_ERR (tcpci->regmap)) -return PTR_ERR (tcpci->regmap); + tcpci->dev = dev; + tcpci->data = data; + tcpci->regmap = data->regmap; tcpci->tcpc.init = tcpci_init; tcpci->tcpc.get_vbus = tcpci_get_vbus;@@ -467,27 +507,63 @@ static int tcpci_probe(struct i2c_client *client, err =tcpci_parse_config (tcpci);if (err <0 ) -return err; +return ERR_PTR (err); + + tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); +if (PTR_ERR_OR_ZERO (tcpci->port)) +return ERR_CAST (tcpci->port); -/* Disable chip interrupts */ -tcpci_write16 (tcpci,TCPC_ALERT_MASK ,0 ); +return tcpci; +} +EXPORT_SYMBOL_GPL (tcpci_register_port); + +void tcpci_unregister_port (struct tcpci *tcpci) +{ +tcpm_unregister_port (tcpci->port); +} +EXPORT_SYMBOL_GPL (tcpci_unregister_port); - err =devm_request_threaded_irq (tcpci->dev, client->irq,NULL , - tcpci_irq, +static int tcpci_probe (struct i2c_client *client, +const struct i2c_device_id *i2c_id) +{ +struct tcpci_chip *chip; +int err; +u16 val =0 ; + + chip =devm_kzalloc (&client->dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->data.regmap =devm_regmap_init_i2c (client, &tcpci_regmap_config); +if (IS_ERR (chip->data.regmap)) +return PTR_ERR (chip->data.regmap); + +/* Disable chip interrupts before requesting irq */ + err =regmap_raw_write (chip->data.regmap,TCPC_ALERT_MASK , &val, +sizeof (u16)); +if (err <0 ) +return err; + + err =devm_request_threaded_irq (&client->dev, client->irq,NULL , + _tcpci_irq,IRQF_ONESHOT |IRQF_TRIGGER_LOW , -dev_name (tcpci->dev), tcpci); +dev_name (&client->dev), chip);if (err <0 )return err; - tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); -return PTR_ERR_OR_ZERO (tcpci->port); + chip->tcpci =tcpci_register_port (&client->dev, &chip->data); +if (PTR_ERR_OR_ZERO (chip->tcpci)) +return PTR_ERR (chip->tcpci); + +i2c_set_clientdata (client, chip); +return 0 ; }static int tcpci_remove (struct i2c_client *client) { -struct tcpci *tcpci =i2c_get_clientdata (client); +struct tcpci_chip *chip =i2c_get_clientdata (client); -tcpm_unregister_port (tcpci->port); +tcpci_unregister_port (chip->tcpci);return 0 ; }drivers/staging/typec/tcpci.h +13
-1@@ -59,6 +59,7 @@#define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)#define TCPC_CC_STATUS 0x1d +#define TCPC_CC_STATUS_DRPRST BIT(5)#define TCPC_CC_STATUS_TERM BIT(4)#define TCPC_CC_STATUS_CC2_SHIFT 2#define TCPC_CC_STATUS_CC2_MASK 0x3@@ -121,4 +122,16 @@#define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76#define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78 +struct tcpci ; +struct tcpci_data { +struct regmap *regmap; +int (*init)(struct tcpci *tcpci,struct tcpci_data *data); +int (*set_vconn)(struct tcpci *tcpci,struct tcpci_data *data, +bool enable); +}; + +struct tcpci *tcpci_register_port (struct device *dev,struct tcpci_data *data); +void tcpci_unregister_port (struct tcpci *tcpci); +irqreturn_t tcpci_irq (struct tcpci *tcpci); +#endif /* __LINUX_USB_TCPCI_H */ --
Quoted 2 lines
1.9.1
************* Email Confidentiality Notice ********************
The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!
Hi,
Quoted 10 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of ShuFanLee
Sent: 2018年2月21日 23:02
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flow
Quoted 8 lines
From: ShuFanLee <[email protected]>
Handle vendor defined behavior in
tcpci_init,tcpci_set_vconnand exporttcpci_irq.
More operations can be extended intcpci_dataif needed. According to TCPCI specification, 4.4.5.2ROLE_CONTROL, TCPC shall not start DRP toggling until subsequently the TCPM writes to the COMMAND register to start DRP toggling.
My understanding of above statement is TCPM(this Linux driver) can enable DRP and CC1/CC2 in one shot, but TCPC(your typec chip internal firmware) needs wait until TCPM writes to COMMAND register to start drp toggling.
Quoted 2 lines
DRP toggling flow is chagned as following:
- Write DRP = 0 & Rd/Rd
Why fixed to be Rd/Rd? in this case, it means the starting value:
Tcpci 4.4.5.2:
"When initiating autonomous DRP toggling, the TCPM shall write B6 (DRP) =1b and the starting value of Rp/Rd to B3..0 (CC1/CC2) to indicate DRP autonomous toggling mode to the TCPC."
Quoted 1 line
- Write DRP = 1
What's your problem if combine above 2 in one shot?
Quoted 72 lines
- Set LOOK4CONNECTION command
Signed-off-by ShuFanLee <[email protected]>--- drivers/staging/typec/tcpci.c | 128 +++++++++++++++++++++++++++++++++--------- drivers/staging/typec/tcpci.h | 13 +++++ 2 files changed, 115 insertions(+), 26 deletions(-)patch changelogs between v1 & v2
- Remove unnecessaryi2c_clientin the structure of tcpci
- Rename structure oftcpci_vendor_datatotcpci_data
- Not exporting tcpci read/write wrappers but register i2c regmap in glue
driver
- Addset_vconnops intcpci_data
(It is necessary for RT1711H to enable/disable idle mode before
disabling/enabling vconn)
- Exporttcpci_irqso that vendor can call it in their own IRQ handlerpatch changelogs between v2 & v3
- Change the return type oftcpci_irqfrom int toirqreturn_tdrivers/staging/typec/tcpci.c +9
-4@@ -21,7 +21,6 @@struct tcpci {struct device *dev; -struct i2c_client *client;struct tcpm_port *port;@@ -30,6 +29,12 @@ struct tcpci {bool controls_vbus;struct tcpc_dev tcpc; +struct tcpci_data *data; +}; + +struct tcpci_chip { +struct tcpci *tcpci; +struct tcpci_data data; }; static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) @@ -37,8 +42,7 @@ static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) return container_of(tcpc, struct tcpci, tcpc); } -static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg, -u16 *val) +static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg,u16 +*val) { return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16)); } @@ -98,8 +102,10 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum
typec_cc_statuscc) static int tcpci_start_drp_toggling(structtcpc_dev*tcpc,drivers/staging/typec/tcpci.c +2
-1enum typec_cc_status cc) { +int ret;struct tcpci *tcpci =tcpc_to_tcpci (tcpc); -unsigned int reg =TCPC_ROLE_CTRL_DRP ; + unsigned int reg = (TCPC_ROLE_CTRL_CC_RD <<
TCPC_ROLE_CTRL_CC1_SHIFT) |drivers/staging/typec/tcpci.c +1
-0+ (TCPC_ROLE_CTRL_CC_RD <<
TCPC_ROLE_CTRL_CC2_SHIFT);drivers/staging/typec/tcpci.c +0
-0switch (cc) {default :
drivers/staging/typec/tcpci.c static int tcpci_start_drp_toggling(struct tcpc_dev · line 130
Quoted 9 lines
drivers/staging/typec/tcpci.c +4
-1@@ -117,7 +123,19 @@ static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc, break; } -return regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; +usleep_range (500 ,1000 );
Why need a wait here? It seems you actually don't want to do autonomously toggling from the very beginning, instead, you begin with a directly control on CC, keep it(Rd) for some time, then switch to use autonomously toggling, why you need such kind of sequence? I think it's special and not following tcpci spec.
Quoted 56 lines
drivers/staging/typec/tcpci.c +9
-0+ reg |=TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; + ret =regmap_write (tcpci->regmap,TCPC_COMMAND , +TCPC_CMD_LOOK4CONNECTION ); +if (ret <0 ) +return ret; +return 0 ; }static enum
typec_cc_statustcpci_to_typec_cc(unsigned int cc, bool sink)drivers/staging/typec/tcpci.c +10
-0@@ -178,6 +196,16 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)struct tcpci *tcpci =tcpc_to_tcpci (tcpc);int ret; +/* Handle vendor set vconn */ +if (tcpci->data) { +if (tcpci->data->set_vconn) { + ret = tcpci->data->set_vconn (tcpci, tcpci->data, + enable); +if (ret <0 ) +return ret; + } + } + ret =regmap_write (tcpci->regmap,TCPC_POWER_CTRL , enable ?TCPC_POWER_CTRL_VCONN_ENABLE :0 );drivers/staging/typec/tcpci.c +13
-1if (ret <0 )@@ -323,6 +351,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)if (time_after (jiffies, timeout))return -ETIMEDOUT ; +/* Handle vendor init */ +if (tcpci->data) { +if (tcpci->data->init) { + ret = tcpci->data->init (tcpci, tcpci->data); +if (ret <0 ) +return ret; + } + } +/* Clear all events */ ret =tcpci_write16 (tcpci,TCPC_ALERT ,0xffff );if (ret <0 )@@ -344,9 +381,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)return tcpci_write16 (tcpci,TCPC_ALERT_MASK , reg); } -static irqreturn_t tcpci_irq (int irq,void *dev_id) +static irqreturn_t _tcpci_irq (int irq,void *dev_id) {struct tcpci *tcpci = dev_id; + +return tcpci_irq (tcpci); +}
drivers/staging/typec/tcpci.c static int tcpci_init(struct tcpc_dev *tcpc)
Quoted 10 lines
drivers/staging/typec/tcpci.c +3
-0+ +irqreturn_t tcpci_irq (struct tcpci *tcpci) {u16 status; tcpci_read16(tcpci, TCPC_ALERT, &status); @@ -412,6 +455,7 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id) return IRQ_HANDLED; } +EXPORT_SYMBOL_GPL (tcpci_irq);
I don't catch the point of how you handle private events by above change, maybe post your RT1711H part as a user in one series can make it clear, I assume this can be done in existing tcpci_irq like above vender specific handling as well:
tcpci->data->priv_events(tcpci, tcpci->data);
Li Jun
Quoted 145 lines
static const struct
regmap_configtcpci_regmap_config= {drivers/staging/typec/tcpci.c +7
-10.reg_bits = 8,@@ -435,22 +479,18 @@ static int tcpci_parse_config(struct tcpci *tcpci)return 0 ; } -static int tcpci_probe (struct i2c_client *client, -const struct i2c_device_id *i2c_id) +struct tcpci *tcpci_register_port (struct device *dev,struct tcpci_data +*data) {struct tcpci *tcpci;int err; - tcpci =devm_kzalloc (&client->dev,sizeof (*tcpci),GFP_KERNEL ); + tcpci =devm_kzalloc (dev,sizeof (*tcpci),GFP_KERNEL );if (!tcpci) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); - tcpci->client = client; - tcpci->dev = &client->dev; -i2c_set_clientdata (client, tcpci); - tcpci->regmap =devm_regmap_init_i2c (client, &tcpci_regmap_config); -if (IS_ERR (tcpci->regmap)) -return PTR_ERR (tcpci->regmap); + tcpci->dev = dev; + tcpci->data = data; + tcpci->regmap = data->regmap; tcpci->tcpc.init = tcpci_init; tcpci->tcpc.get_vbus = tcpci_get_vbus; @@ -467,27 +507,63 @@ staticint tcpci_probe(struct
i2c_client*client,drivers/staging/typec/tcpci.c +24
-5err =tcpci_parse_config (tcpci);if (err <0 ) -return err; +return ERR_PTR (err); + + tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); +if (PTR_ERR_OR_ZERO (tcpci->port)) +return ERR_CAST (tcpci->port); -/* Disable chip interrupts */ -tcpci_write16 (tcpci,TCPC_ALERT_MASK ,0 ); +return tcpci; +} +EXPORT_SYMBOL_GPL (tcpci_register_port); + +void tcpci_unregister_port (struct tcpci *tcpci) { +tcpm_unregister_port (tcpci->port); +} +EXPORT_SYMBOL_GPL (tcpci_unregister_port); - err = devm_request_threaded_irq(tcpci->dev, client->irq, NULL, - tcpci_irq, +static int tcpci_probe (struct i2c_client *client, +const struct i2c_device_id *i2c_id) { +struct tcpci_chip *chip; +int err; +u16 val =0 ; + + chip =devm_kzalloc (&client->dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->data.regmap = devm_regmap_init_i2c(client,
&tcpci_regmap_config);drivers/staging/typec/tcpci.c +20
-5+if (IS_ERR (chip->data.regmap)) +return PTR_ERR (chip->data.regmap); + +/* Disable chip interrupts before requesting irq */ + err =regmap_raw_write (chip->data.regmap,TCPC_ALERT_MASK , &val, +sizeof (u16)); +if (err <0 ) +return err; + + err =devm_request_threaded_irq (&client->dev, client->irq,NULL , + _tcpci_irq,IRQF_ONESHOT |IRQF_TRIGGER_LOW , - dev_name(tcpci->dev), tcpci); +dev_name (&client->dev), chip);if (err <0 )return err; - tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); -return PTR_ERR_OR_ZERO (tcpci->port); + chip->tcpci =tcpci_register_port (&client->dev, &chip->data); +if (PTR_ERR_OR_ZERO (chip->tcpci)) +return PTR_ERR (chip->tcpci); + +i2c_set_clientdata (client, chip); +return 0 ; }static int tcpci_remove (struct i2c_client *client) { -struct tcpci *tcpci =i2c_get_clientdata (client); +struct tcpci_chip *chip =i2c_get_clientdata (client); -tcpm_unregister_port (tcpci->port); +tcpci_unregister_port (chip->tcpci);return 0 ; }drivers/staging/typec/tcpci.h +13
-1@@ -59,6 +59,7 @@#define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)#define TCPC_CC_STATUS 0x1d +#define TCPC_CC_STATUS_DRPRST BIT(5)#define TCPC_CC_STATUS_TERM BIT(4)#define TCPC_CC_STATUS_CC2_SHIFT 2#define TCPC_CC_STATUS_CC2_MASK 0x3@@ -121,4 +122,16 @@#define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76#define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78 +struct tcpci ; +struct tcpci_data { +struct regmap *regmap; +int (*init)(struct tcpci *tcpci,struct tcpci_data *data); +int (*set_vconn)(struct tcpci *tcpci,struct tcpci_data *data, +bool enable); +}; + +struct tcpci *tcpci_register_port (struct device *dev,struct tcpci_data +*data);void tcpci_unregister_port (struct tcpci *tcpci);irqreturn_t +tcpci_irq (struct tcpci *tcpci); +#endif /* __LINUX_USB_TCPCI_H */ --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fvger
.kernel.org%2Fmajordomo-info.html&data=02%7C01%7Cjun.li%40nxp.com %7C44d11af27e0244fa4d1108d5793c3dc4%7C686ea1d3bc2b4c6fa92cd99c 5c301635%7C0%7C1%7C636548222008905206&sdata=zn2ougKRvs%2BbmH Qg2c8Rjj7vNe0ZiiVKdar7GdPa%2B3o%3D&reserved=0
Hi Jun,
For the questions of drp_toggling, our test is as following:
According to TCPCI 4.4.5.2
It is recommended the TCPM write ROLE_CONTROL.DRP=0 before writing to POWER_CONTROL.AutoDischargeDisconnect and starting the DRP toggling using COMMAND.Look4Connection.
We've encounter a situation while testing with RT1711H as following:
We repeatedly plug in/out a device (with Rd), and not to provide VBUS(5V) while plugging in.
If we plug out the device right after TCPC detects it and stops toggling, TCPM will try to restart drp_toggling.
Here, we re-plug in the device before TCPM calls drp_toggling. Under this circumstance, RT1711H reports open/open after drp_toggling is called. For current TCPM, it stops if open/open is reported at drp_toggling state.
The detailed flow that causes RT1711H reporting open/open is described as following:
1. RT1711H detects the device, stops toggling and reports to TCPM.
2. Rd is plugged out before set_cc is called. So, ROLE_CONTROL.DRP is still 1.
3. Plug in the device before TCPM restarts drp_toggling
4. The device is detected by RT1711H's internal firmware again(TCPC chip's internal firmware).
5. TCPM calls drp_toggling before cc_change triggered by step 4 is handled.
6. TCPM sets ROLE_CONTROL.DRP = 1, Rd/Rd and start drp_toggling.
According to TCPCI 4.4.5.2
The TCPM shall write B6 (DRP) = 0b and B3..0 (CC1/CC2) if it wishes to control the Rp/Rd
directly instead of having the TCPC perform DRP toggling autonomousl.
So, Rd/Rd set in step 6 will not work. (Because ROLE_CONTROL.DRP is 1 since the first step.)
7. RT1711H will stop toggling immediately (Because it's internal firmware already detects device at step 4) and report open/open (Because CC1/CC2 will be changed to Rd by RT1711H after LOOK4CONNECTION is set. RT1711H sets to Rd and device is Rd so open is reported)
8. TCPCI reports open/open to TCPM at drp_toggling state
That's why we always set ROLE_CONTROL.DRP to 0 while setting Rd/Rd.
If this circumstance is not a general case, we can also use a vendor ops to replace it.
========================================================================
I don't catch the point of how you handle private events by above change, maybe post your RT1711H part as a user in one series can make it clear, I assume this can be done in existing tcpci_irq like above vender specific handling as well:
For every glue driver, it registers its own irq handler and calls tcpci_irq in the handler.
Take RT1711H as an example:
It registers its own irq handler in probe function and handle vendor defined interrupts before calling general tcpci_irq:
static irqreturn_t _tcpci_irq(int irq, void *dev_id)
{
struct rt1711h_chip *chip = dev_id;
/* handle vendor defined interrupts here */
/* call general tcpci_irq */
return tcpci_irq(chip->tcpci);
}static int rt1711h_probe(struct i2c_client *client, const struct i2c_device_id *i2c_id)
{
....
ret = devm_request_threaded_irq(chip->dev, client->irq, NULL,
_tcpci_irq,
IRQF_ONESHOT | IRQF_TRIGGER_LOW,
dev_name(&client->dev), chip);
}Best Regards,
*****************************************
Shu-Fan Lee
Richtek Technology Corporation
TEL: +886-3-5526789 #2359
FAX: +886-3-5526612
*****************************************
________________________________________
寄件者: Jun Li <[email protected]>
寄件日期: 2018年2月22日 下午 06:16
收件者: ShuFanLee; [email protected]; [email protected]; [email protected]
副本: shufan_lee(李書帆); cy_huang(黃啟原); [email protected]; [email protected]; dl-linux-imx 主旨: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flow
Hi,
Quoted 10 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of ShuFanLee
Sent: 2018年2月21日 23:02
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flow
Quoted 8 lines
From: ShuFanLee <[email protected]>
Handle vendor defined behavior in
tcpci_init,tcpci_set_vconnand exporttcpci_irq.
More operations can be extended intcpci_dataif needed. According to TCPCI specification, 4.4.5.2ROLE_CONTROL, TCPC shall not start DRP toggling until subsequently the TCPM writes to the COMMAND register to start DRP toggling.
My understanding of above statement is TCPM(this Linux driver) can enable DRP and CC1/CC2 in one shot, but TCPC(your typec chip internal firmware) needs wait until TCPM writes to COMMAND register to start drp toggling.
Quoted 2 lines
DRP toggling flow is chagned as following:
- Write DRP = 0 & Rd/Rd
Why fixed to be Rd/Rd? in this case, it means the starting value:
Tcpci 4.4.5.2:
"When initiating autonomous DRP toggling, the TCPM shall write B6 (DRP) =1b and the starting value of Rp/Rd to B3..0 (CC1/CC2) to indicate DRP autonomous toggling mode to the TCPC."
Quoted 1 line
- Write DRP = 1
What's your problem if combine above 2 in one shot?
Quoted 72 lines
- Set LOOK4CONNECTION command
Signed-off-by ShuFanLee <[email protected]>--- drivers/staging/typec/tcpci.c | 128 +++++++++++++++++++++++++++++++++--------- drivers/staging/typec/tcpci.h | 13 +++++ 2 files changed, 115 insertions(+), 26 deletions(-)patch changelogs between v1 & v2
- Remove unnecessaryi2c_clientin the structure of tcpci
- Rename structure oftcpci_vendor_datatotcpci_data
- Not exporting tcpci read/write wrappers but register i2c regmap in glue
driver
- Addset_vconnops intcpci_data
(It is necessary for RT1711H to enable/disable idle mode before
disabling/enabling vconn)
- Exporttcpci_irqso that vendor can call it in their own IRQ handlerpatch changelogs between v2 & v3
- Change the return type oftcpci_irqfrom int toirqreturn_tdrivers/staging/typec/tcpci.c +9
-4@@ -21,7 +21,6 @@struct tcpci {struct device *dev; -struct i2c_client *client;struct tcpm_port *port;@@ -30,6 +29,12 @@ struct tcpci {bool controls_vbus;struct tcpc_dev tcpc; +struct tcpci_data *data; +}; + +struct tcpci_chip { +struct tcpci *tcpci; +struct tcpci_data data; }; static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) @@ -37,8 +42,7 @@ static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) return container_of(tcpc, struct tcpci, tcpc); } -static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg, -u16 *val) +static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg,u16 +*val) { return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16)); } @@ -98,8 +102,10 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum
typec_cc_statuscc) static int tcpci_start_drp_toggling(structtcpc_dev*tcpc,
enumtypec_cc_statuscc)
{drivers/staging/typec/tcpci.c +2
-1+int ret;struct tcpci *tcpci =tcpc_to_tcpci (tcpc); -unsigned int reg =TCPC_ROLE_CTRL_DRP ; + unsigned int reg = (TCPC_ROLE_CTRL_CC_RD <<
TCPC_ROLE_CTRL_CC1_SHIFT) |
+ (TCPC_ROLE_CTRL_CC_RD<<TCPC_ROLE_CTRL_CC2_SHIFT);switch (cc) { default:
drivers/staging/typec/tcpci.c static int tcpci_start_drp_toggling(struct tcpc_dev · line 130
Quoted 9 lines
drivers/staging/typec/tcpci.c +4
-1@@ -117,7 +123,19 @@ static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc, break; } -return regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; +usleep_range (500 ,1000 );
Why need a wait here? It seems you actually don't want to do autonomously toggling from the very beginning, instead, you begin with a directly control on CC, keep it(Rd) for some time, then switch to use autonomously toggling, why you need such kind of sequence? I think it's special and not following tcpci spec.
Quoted 56 lines
drivers/staging/typec/tcpci.c +9
-0+ reg |=TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; + ret =regmap_write (tcpci->regmap,TCPC_COMMAND , +TCPC_CMD_LOOK4CONNECTION ); +if (ret <0 ) +return ret; +return 0 ; }static enum
typec_cc_statustcpci_to_typec_cc(unsigned int cc, bool sink)drivers/staging/typec/tcpci.c +10
-0@@ -178,6 +196,16 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)struct tcpci *tcpci =tcpc_to_tcpci (tcpc);int ret; +/* Handle vendor set vconn */ +if (tcpci->data) { +if (tcpci->data->set_vconn) { + ret = tcpci->data->set_vconn (tcpci, tcpci->data, + enable); +if (ret <0 ) +return ret; + } + } + ret =regmap_write (tcpci->regmap,TCPC_POWER_CTRL , enable ?TCPC_POWER_CTRL_VCONN_ENABLE :0 );if (ret < 0)drivers/staging/typec/tcpci.c +13
-1@@ -323,6 +351,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)if (time_after (jiffies, timeout))return -ETIMEDOUT ; +/* Handle vendor init */ +if (tcpci->data) { +if (tcpci->data->init) { + ret = tcpci->data->init (tcpci, tcpci->data); +if (ret <0 ) +return ret; + } + } +/* Clear all events */ ret =tcpci_write16 (tcpci,TCPC_ALERT ,0xffff );if (ret <0 )@@ -344,9 +381,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)return tcpci_write16 (tcpci,TCPC_ALERT_MASK , reg); } -static irqreturn_t tcpci_irq (int irq,void *dev_id) +static irqreturn_t _tcpci_irq (int irq,void *dev_id) {struct tcpci *tcpci = dev_id; + +return tcpci_irq (tcpci); +}
drivers/staging/typec/tcpci.c static int tcpci_init(struct tcpc_dev *tcpc)
Quoted 10 lines
drivers/staging/typec/tcpci.c +3
-0+ +irqreturn_t tcpci_irq (struct tcpci *tcpci) {u16 status; tcpci_read16(tcpci, TCPC_ALERT, &status); @@ -412,6 +455,7 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id) return IRQ_HANDLED; } +EXPORT_SYMBOL_GPL (tcpci_irq);
I don't catch the point of how you handle private events by above change, maybe post your RT1711H part as a user in one series can make it clear, I assume this can be done in existing tcpci_irq like above vender specific handling as well:
tcpci->data->priv_events(tcpci, tcpci->data);
Li Jun
Quoted 137 lines
static const struct regmap_config tcpci_regmap_config = { .reg_bits = 8,drivers/staging/typec/tcpci.c +7
-10@@ -435,22 +479,18 @@ static int tcpci_parse_config(struct tcpci *tcpci)return 0 ; } -static int tcpci_probe (struct i2c_client *client, -const struct i2c_device_id *i2c_id) +struct tcpci *tcpci_register_port (struct device *dev,struct tcpci_data +*data) {struct tcpci *tcpci;int err; - tcpci =devm_kzalloc (&client->dev,sizeof (*tcpci),GFP_KERNEL ); + tcpci =devm_kzalloc (dev,sizeof (*tcpci),GFP_KERNEL );if (!tcpci) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); - tcpci->client = client; - tcpci->dev = &client->dev; -i2c_set_clientdata (client, tcpci); - tcpci->regmap =devm_regmap_init_i2c (client, &tcpci_regmap_config); -if (IS_ERR (tcpci->regmap)) -return PTR_ERR (tcpci->regmap); + tcpci->dev = dev; + tcpci->data = data; + tcpci->regmap = data->regmap; tcpci->tcpc.init = tcpci_init; tcpci->tcpc.get_vbus = tcpci_get_vbus; @@ -467,27 +507,63 @@ staticint tcpci_probe(struct
i2c_client*client,err = tcpci_parse_config(tcpci); if (err < 0)drivers/staging/typec/tcpci.c +24
-5-return err; +return ERR_PTR (err); + + tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); +if (PTR_ERR_OR_ZERO (tcpci->port)) +return ERR_CAST (tcpci->port); -/* Disable chip interrupts */ -tcpci_write16 (tcpci,TCPC_ALERT_MASK ,0 ); +return tcpci; +} +EXPORT_SYMBOL_GPL (tcpci_register_port); + +void tcpci_unregister_port (struct tcpci *tcpci) { +tcpm_unregister_port (tcpci->port); +} +EXPORT_SYMBOL_GPL (tcpci_unregister_port); - err = devm_request_threaded_irq(tcpci->dev, client->irq, NULL, - tcpci_irq, +static int tcpci_probe (struct i2c_client *client, +const struct i2c_device_id *i2c_id) { +struct tcpci_chip *chip; +int err; +u16 val =0 ; + + chip =devm_kzalloc (&client->dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->data.regmap = devm_regmap_init_i2c(client,
&tcpci_regmap_config);drivers/staging/typec/tcpci.c +20
-5+if (IS_ERR (chip->data.regmap)) +return PTR_ERR (chip->data.regmap); + +/* Disable chip interrupts before requesting irq */ + err =regmap_raw_write (chip->data.regmap,TCPC_ALERT_MASK , &val, +sizeof (u16)); +if (err <0 ) +return err; + + err =devm_request_threaded_irq (&client->dev, client->irq,NULL , + _tcpci_irq,IRQF_ONESHOT |IRQF_TRIGGER_LOW , - dev_name(tcpci->dev), tcpci); +dev_name (&client->dev), chip);if (err <0 )return err; - tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); -return PTR_ERR_OR_ZERO (tcpci->port); + chip->tcpci =tcpci_register_port (&client->dev, &chip->data); +if (PTR_ERR_OR_ZERO (chip->tcpci)) +return PTR_ERR (chip->tcpci); + +i2c_set_clientdata (client, chip); +return 0 ; }static int tcpci_remove (struct i2c_client *client) { -struct tcpci *tcpci =i2c_get_clientdata (client); +struct tcpci_chip *chip =i2c_get_clientdata (client); -tcpm_unregister_port (tcpci->port); +tcpci_unregister_port (chip->tcpci);return 0 ; }drivers/staging/typec/tcpci.h +13
-1@@ -59,6 +59,7 @@#define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)#define TCPC_CC_STATUS 0x1d +#define TCPC_CC_STATUS_DRPRST BIT(5)#define TCPC_CC_STATUS_TERM BIT(4)#define TCPC_CC_STATUS_CC2_SHIFT 2#define TCPC_CC_STATUS_CC2_MASK 0x3@@ -121,4 +122,16 @@#define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76#define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78 +struct tcpci ; +struct tcpci_data { +struct regmap *regmap; +int (*init)(struct tcpci *tcpci,struct tcpci_data *data); +int (*set_vconn)(struct tcpci *tcpci,struct tcpci_data *data, +bool enable); +}; + +struct tcpci *tcpci_register_port (struct device *dev,struct tcpci_data +*data);void tcpci_unregister_port (struct tcpci *tcpci);irqreturn_t +tcpci_irq (struct tcpci *tcpci); +#endif /* __LINUX_USB_TCPCI_H */ --1.9.1
Quoted 8 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fvger
.kernel.org%2Fmajordomo-info.html&data=02%7C01%7Cjun.li%40nxp.com %7C44d11af27e0244fa4d1108d5793c3dc4%7C686ea1d3bc2b4c6fa92cd99c 5c301635%7C0%7C1%7C636548222008905206&sdata=zn2ougKRvs%2BbmH Qg2c8Rjj7vNe0ZiiVKdar7GdPa%2B3o%3D&reserved=0
************* Email Confidentiality Notice ********************
The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!
Hi
Quoted 20 lines
-----Original Message-----
From:shufan_lee(李書帆)[mailto:[email protected]]
Sent: 2018年2月28日 11:41
To: Jun Li <[email protected]>; ShuFanLee <[email protected]>; [email protected]; [email protected]; [email protected]
Cc:cy_huang(黃啟原)<[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: 回覆: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowHi Jun,
For the questions of
drp_toggling, our test is as following:According to TCPCI 4.4.5.2
It is recommended the TCPM write ROLE_CONTROL.DRP=0 before writing to POWER_CONTROL.AutoDischargeDisconnect and starting the DRP toggling using COMMAND.Look4Connection.
Quoted 7 lines
We've encounter a situation while testing with RT1711H as following:
We repeatedly plug in/out a device (with Rd), and not to provide VBUS(5V)
while plugging in.
If we plug out the device right after TCPC detects it and stops toggling,
TCPM will try to restartdrp_toggling.
Here, we re-plug in the device before TCPM callsdrp_toggling. Under this
circumstance, RT1711H reports open/open afterdrp_togglingis called.
Why RT1711H reports open/open after drp_toggling is enabled? This open/open is for you plug out the device, right?
Why RT1711H can't report new cc change events after you plug in the device?
Please use tcpm log to show all the events and state transitions for your above corner case.
cat /sys/kernel/debug/tcpm/xxxxx
Quoted 7 lines
For current TCPM, it stops if open/open is reported at
drp_togglingstate.The detailed flow that causes RT1711H reporting open/open is described
as following:
1. RT1711H detects the device, stops toggling and reports to TCPM.
2. Rd is plugged out beforeset_ccis called. So, ROLE_CONTROL.DRP is
still 1.
So open/open cc change will generate.
Quoted 3 lines
3. Plug in the device before TCPM restarts
drp_toggling
4. The device is detected by RT1711H's internal firmware again(TCPC
chip's internal firmware).
What cc change event tcpc will report on step 4?
Quoted 15 lines
5. TCPM calls
drp_togglingbeforecc_changetriggered by step 4 is
handled.
6. TCPM sets ROLE_CONTROL.DRP = 1, Rd/Rd and startdrp_toggling.
According to TCPCI 4.4.5.2
The TCPM shall write B6 (DRP) = 0b and B3..0 (CC1/CC2) if it wishes to control the Rp/Rd directly instead of having the TCPC perform DRP toggling autonomousl.
So, Rd/Rd set in step 6 will not work. (Because ROLE_CONTROL.DRP is 1 since the first step.)
7. RT1711H will stop toggling immediately (Because it's internal firmware
already detects device at step 4) and report open/open (Because CC1/CC2 will be changed to Rd by RT1711H after LOOK4CONNECTION is set. RT1711H sets to Rd and device is Rd so open is reported)
8. TCPCI reports open/open to TCPM atdrp_togglingstate
Quoted 3 lines
That's why we always set ROLE_CONTROL.DRP to 0 while setting Rd/Rd. If this circumstance is not a general case, we can also use a vendor ops to
replace it.
Thanks for the detailed description, the tcpm full log is required to know what's going on here, you can apply my drp_toggling change patch[1] and run your problem case again, then post the full tcpm log.
Generally, I think you need check further this is a problem on the current tcpm _or_ your tcpc chip, if the problem on the tcpm, you should resolve this issue by improve tcpm, if the problem on your tcpc chip, you can add a vendor ops.
I tested my tcpc HW with my drp_toggling change patch[1] (w/o your change) by quickly pulg-in & plug-out a sink, no problem found.
Did you verify your change can pass the typec compliance test?
[1] https://www.spinics.net/lists/devicetree/msg216851.html
Quoted 25 lines
==============================================================
==========I don't catch the point of how you handle private events by above change, maybe post your RT1711H part as a user in one series can make it clear, I assume this can be done in existing
tcpci_irqlike above vender specific handling as well:For every glue driver, it registers its own irq handler and calls
tcpci_irqin the handler.Take RT1711H as an example:
It registers its own irq handler in probe function and handle vendor defined interrupts before calling generaltcpci_irq:static irqreturn_t _tcpci_irq(int irq, void *dev_id) { struct rt1711h_chip *chip = dev_id; /* handle vendor defined interrupts here */ /* call general tcpci_irq */ return tcpci_irq(chip->tcpci); }static int rt1711h_probe(struct
i2c_client*client, const structi2c_device_id
Quoted 10 lines
*i2c_id) { .... ret = devm_request_threaded_irq(chip->dev, client->irq, NULL, _tcpci_irq, IRQF_ONESHOT | IRQF_TRIGGER_LOW, dev_name(&client->dev),chip); }
Get it, thanks.
Quoted 394 lines
Best Regards,
*****************************************
Shu-Fan Lee
Richtek Technology Corporation
TEL: +886-3-5526789 #2359
FAX: +886-3-5526612
*****************************************________________________________________
寄件者: Jun Li <[email protected]>
寄件日期: 2018年2月22日 下午 06:16
收件者: ShuFanLee; [email protected]; [email protected]; [email protected]
副本:shufan_lee(李書帆);cy_huang(黃啟原); [email protected]; [email protected]; dl-linux-imx
主旨: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowHi,
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of ShuFanLee
Sent: 2018年2月21日 23:02
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowQuoted 8 lines
From: ShuFanLee <[email protected]>
Handle vendor defined behavior in
tcpci_init,tcpci_set_vconnand exporttcpci_irq.
More operations can be extended intcpci_dataif needed. According to TCPCI specification, 4.4.5.2ROLE_CONTROL, TCPC shall not start DRP toggling until subsequently the TCPM writes to the COMMAND register to start DRP toggling.My understanding of above statement is TCPM(this Linux driver) can enable DRP and CC1/CC2 in one shot, but TCPC(your typec chip internal firmware) needs wait until TCPM writes to COMMAND register to start drp toggling.
Quoted 2 lines
DRP toggling flow is chagned as following:
- Write DRP = 0 & Rd/RdWhy fixed to be Rd/Rd? in this case, it means the starting value:
Tcpci 4.4.5.2:
"When initiating autonomous DRP toggling, the TCPM shall write B6 (DRP) =1b and the starting value of Rp/Rd to B3..0 (CC1/CC2) to indicate DRP autonomous toggling mode to the TCPC."Quoted 1 line
- Write DRP = 1
What's your problem if combine above 2 in one shot?
Quoted 75 lines
- Set LOOK4CONNECTION command
Signed-off-by ShuFanLee <[email protected]>--- drivers/staging/typec/tcpci.c | 128 +++++++++++++++++++++++++++++++++--------- drivers/staging/typec/tcpci.h | 13 +++++ 2 files changed, 115 insertions(+), 26 deletions(-)patch changelogs between v1 & v2
- Remove unnecessaryi2c_clientin the structure of tcpci
- Rename structure oftcpci_vendor_datatotcpci_data
- Not exporting tcpci read/write wrappers but register i2c regmap in
glue driver
- Addset_vconnops intcpci_data
(It is necessary for RT1711H to enable/disable idle mode before
disabling/enabling vconn)
- Exporttcpci_irqso that vendor can call it in their own IRQ
handlerpatch changelogs between v2 & v3
- Change the return type oftcpci_irqfrom int toirqreturn_t(quoted diff) +0
-0
b/drivers/staging/typec/tcpci.cindex 9bd4412..4959c69 100644drivers/staging/typec/tcpci.c +10
-4@@ -21,7 +21,6 @@struct tcpci {struct device *dev; -struct i2c_client *client;struct tcpm_port *port;@@ -30,6 +29,12 @@ struct tcpci {bool controls_vbus;struct tcpc_dev tcpc; +struct tcpci_data *data; +}; + +struct tcpci_chip { +struct tcpci *tcpci; +struct tcpci_data data; }; static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) @@ -37,8 +42,7 @@ static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev +*tcpc) return container_of(tcpc, struct tcpci, tcpc); } -static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg, -u16 *val) +static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg,u16 +*val) {return regmap_raw_read (tcpci->regmap, reg, val,sizeof (u16)); }@@
-98,8 +102,10 @@ static inttcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)static int tcpci_start_drp_toggling(structtcpc_dev*tcpc,enum typec_cc_status cc) {drivers/staging/typec/tcpci.c +2
-1+int ret;struct tcpci *tcpci =tcpc_to_tcpci (tcpc); -unsigned int reg =TCPC_ROLE_CTRL_DRP ; + unsigned int reg = (TCPC_ROLE_CTRL_CC_RD <<
TCPC_ROLE_CTRL_CC1_SHIFT) |
+ (TCPC_ROLE_CTRL_CC_RD<<TCPC_ROLE_CTRL_CC2_SHIFT);switch (cc) { default:drivers/staging/typec/tcpci.c static int tcpci_start_drp_toggling(struct · line 130
Quoted 9 lines
drivers/staging/typec/tcpci.c +4
-1@@ -117,7 +123,19 @@ static int tcpci_start_drp_toggling(structtcpc_dev *tcpc, break; } -return regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; +usleep_range (500 ,1000 );Why need a wait here? It seems you actually don't want to do autonomously toggling from the very beginning, instead, you begin with a directly control on CC, keep it(Rd) for some time, then switch to use autonomously toggling, why you need such kind of sequence? I think it's special and not following tcpci spec.
Quoted 19 lines
drivers/staging/typec/tcpci.c +9
-0+ reg |=TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; + ret =regmap_write (tcpci->regmap,TCPC_COMMAND , +TCPC_CMD_LOOK4CONNECTION ); +if (ret <0 ) +return ret; +return 0 ; }static enum
typec_cc_statustcpci_to_typec_cc(unsigned int cc, bool
sink) @@ -178,6 +196,16 @@ static inttcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)struct tcpci *tcpci = tcpc_to_tcpci(tcpc); int ret;drivers/staging/typec/tcpci.c +2
-0+/* Handle vendor set vconn */ +if (tcpci->data) {drivers/staging/typec/tcpci.c static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)
Quoted 10 lines
drivers/staging/typec/tcpci.c +8
-0+if (tcpci->data->set_vconn) { + ret = tcpci->data->set_vconn (tcpci, tcpci->data, + enable); +if (ret <0 ) +return ret; + } + } + ret = regmap_write(tcpci->regmap, TCPC_POWER_CTRL, enable ?
TCPC_POWER_CTRL_VCONN_ENABLE: 0);Quoted 27 lines
if (ret < 0)drivers/staging/typec/tcpci.c +13
-1@@ -323,6 +351,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)if (time_after (jiffies, timeout))return -ETIMEDOUT ; +/* Handle vendor init */ +if (tcpci->data) { +if (tcpci->data->init) { + ret = tcpci->data->init (tcpci, tcpci->data); +if (ret <0 ) +return ret; + } + } +/* Clear all events */ ret =tcpci_write16 (tcpci,TCPC_ALERT ,0xffff );if (ret <0 )@@ -344,9 +381,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)return tcpci_write16 (tcpci,TCPC_ALERT_MASK , reg); } -static irqreturn_t tcpci_irq (int irq,void *dev_id) +static irqreturn_t _tcpci_irq (int irq,void *dev_id) {struct tcpci *tcpci = dev_id; + +return tcpci_irq (tcpci); +}drivers/staging/typec/tcpci.c static int tcpci_init(struct tcpc_dev *tcpc)
Quoted 10 lines
drivers/staging/typec/tcpci.c +3
-0+ +irqreturn_t tcpci_irq (struct tcpci *tcpci) {u16 status; tcpci_read16(tcpci, TCPC_ALERT, &status); @@ -412,6 +455,7 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id) return IRQ_HANDLED; } +EXPORT_SYMBOL_GPL (tcpci_irq);I don't catch the point of how you handle private events by above change, maybe post your RT1711H part as a user in one series can make it clear, I assume this can be done in existing
tcpci_irqlike above vender specific handling as well:tcpci->data->priv_events(tcpci, tcpci->data);Li Jun
Quoted 16 lines
static const struct regmap_config tcpci_regmap_config = { .reg_bits = 8,drivers/staging/typec/tcpci.c +3
-2@@ -435,22 +479,18 @@ static int tcpci_parse_config(struct tcpci *tcpci)return 0 ; } -static int tcpci_probe (struct i2c_client *client, -const struct i2c_device_id *i2c_id) +struct tcpci *tcpci_register_port (struct device *dev,struct +tcpci_data +*data) {struct tcpci *tcpci;int err;drivers/staging/typec/tcpci.c static int tcpci_parse_config(struct tcpci *tcpci) · line 451
Quoted 10 lines
drivers/staging/typec/tcpci.c +2
-6- tcpci =devm_kzalloc (&client->dev,sizeof (*tcpci),GFP_KERNEL ); + tcpci =devm_kzalloc (dev,sizeof (*tcpci),GFP_KERNEL );if (!tcpci) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); - tcpci->client = client; - tcpci->dev = &client->dev; -i2c_set_clientdata (client, tcpci); - tcpci->regmap = devm_regmap_init_i2c(client,
&tcpci_regmap_config);Quoted 44 lines
drivers/staging/typec/tcpci.c +3
-2-if (IS_ERR (tcpci->regmap)) -return PTR_ERR (tcpci->regmap); + tcpci->dev = dev; + tcpci->data = data; + tcpci->regmap = data->regmap; tcpci->tcpc.init = tcpci_init; tcpci->tcpc.get_vbus = tcpci_get_vbus; @@ -467,27 +507,63 @@static int tcpci_probe(struct
i2c_client*client,err = tcpci_parse_config(tcpci); if (err < 0)drivers/staging/typec/tcpci.c +24
-5-return err; +return ERR_PTR (err); + + tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); +if (PTR_ERR_OR_ZERO (tcpci->port)) +return ERR_CAST (tcpci->port); -/* Disable chip interrupts */ -tcpci_write16 (tcpci,TCPC_ALERT_MASK ,0 ); +return tcpci; +} +EXPORT_SYMBOL_GPL (tcpci_register_port); + +void tcpci_unregister_port (struct tcpci *tcpci) { +tcpm_unregister_port (tcpci->port); +} +EXPORT_SYMBOL_GPL (tcpci_unregister_port); - err = devm_request_threaded_irq(tcpci->dev, client->irq, NULL, - tcpci_irq, +static int tcpci_probe (struct i2c_client *client, +const struct i2c_device_id *i2c_id) { +struct tcpci_chip *chip; +int err; +u16 val =0 ; + + chip =devm_kzalloc (&client->dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->data.regmap = devm_regmap_init_i2c(client,
&tcpci_regmap_config);drivers/staging/typec/tcpci.c static int tcpci_probe(struct i2c_client *client,
Quoted 5 lines
drivers/staging/typec/tcpci.c +5
-0+if (IS_ERR (chip->data.regmap)) +return PTR_ERR (chip->data.regmap); + +/* Disable chip interrupts before requesting irq */ + err = regmap_raw_write(chip->data.regmap, TCPC_ALERT_MASK,&val,
drivers/staging/typec/tcpci.c static int tcpci_probe(struct i2c_client *client,
Quoted 7 lines
drivers/staging/typec/tcpci.c +6
-0+ sizeof(u16)); +if (err <0 ) +return err; + + err = devm_request_threaded_irq(&client->dev, client->irq, NULL, + _tcpci_irq, IRQF_ONESHOT |
IRQF_TRIGGER_LOW,Quoted 1 line
-
dev_name(tcpci->dev),tcpci);
Quoted 1 line
+
dev_name(&client->dev),chip);
Quoted 54 lines
if (err < 0) return err;drivers/staging/typec/tcpci.c +8
-4- tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); -return PTR_ERR_OR_ZERO (tcpci->port); + chip->tcpci =tcpci_register_port (&client->dev, &chip->data); +if (PTR_ERR_OR_ZERO (chip->tcpci)) +return PTR_ERR (chip->tcpci); + +i2c_set_clientdata (client, chip); +return 0 ; }static int tcpci_remove (struct i2c_client *client) { -struct tcpci *tcpci =i2c_get_clientdata (client); +struct tcpci_chip *chip =i2c_get_clientdata (client); -tcpm_unregister_port (tcpci->port); +tcpci_unregister_port (chip->tcpci);return 0 ; }(quoted diff) +0
-0
b/drivers/staging/typec/tcpci.hindex fdfb06c..40025b2 100644drivers/staging/typec/tcpci.h +13
-1@@ -59,6 +59,7 @@#define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)#define TCPC_CC_STATUS 0x1d +#define TCPC_CC_STATUS_DRPRST BIT(5)#define TCPC_CC_STATUS_TERM BIT(4)#define TCPC_CC_STATUS_CC2_SHIFT 2#define TCPC_CC_STATUS_CC2_MASK 0x3@@ -121,4 +122,16 @@#define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76#define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78 +struct tcpci ; +struct tcpci_data { +struct regmap *regmap; +int (*init)(struct tcpci *tcpci,struct tcpci_data *data); +int (*set_vconn)(struct tcpci *tcpci,struct tcpci_data *data, +bool enable); +}; + +struct tcpci *tcpci_register_port (struct device *dev,struct +tcpci_data *data);void tcpci_unregister_port (struct tcpci *tcpci); +irqreturn_t tcpci_irq (struct tcpci *tcpci); +#endif /* __LINUX_USB_TCPCI_H */ --1.9.1
Quoted 3 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] Moremajordomo
Quoted 2 lines
info at
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fvger
Quoted 1 line
.kernel.org%2Fmajordomo-info.html&data=02%7C01%7Cjun.li%40nxp.co
m
Quoted 1 line
%7C44d11af27e0244fa4d1108d5793c3dc4%7C686ea1d3bc2b4c6fa92cd99
c
Quoted 1 line
5c301635%7C0%7C1%7C636548222008905206&sdata=zn2ougKRvs%2BbmH
Quoted 1 line
Qg2c8Rjj7vNe0ZiiVKdar7GdPa%2B3o%3D&reserved=0
************* Email Confidentiality Notice ********************
The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!
Hi Jun,
The attachment is waveform of the condition we met but I'm not sure whether you can download the attachment. I add log in RT1711H it shows as following:
[ 914.937340] typec_rt1711h 2-004e: __rt1711h_irq_handler [ 914.943838] typec_rt1711h 2-004e: __tcpm_get_cc cc1 = Open, cc2 = Open
=> Device(Rd) is plugged out
[ 914.958041] typec_rt1711h 2-004e: tcpm_set_pd_rx 0 [ 914.963011] typec_rt1711h 2-004e: tcpm_set_vbus vbus = 0 [ 914.968407] typec_rt1711h 2-004e: tcpm_set_vbus chg is already 0 [ 914.974541] typec_rt1711h 2-004e: tcpm_set_vconn vconn is already 0 [ 914.980921] typec_rt1711h 2-004e: tcpm_set_current_limit 0 ma, 0 mv (not implemented) [ 914.988894] typec_rt1711h 2-004e: tcpm_set_polarity Polarity_CC1 [ 915.003201] typec_rt1711h 2-004e: tcpm_set_roles Source Host [ 915.009264] typec_rt1711h 2-004e: tcpm_start_drp_toggling
=> state_machine_work of TCPM calls start_drp_toggling function but does not set LOOK4CONNECTION command yet
=> (Note1) Device(Rd) is plugged in (RT1711H's internal firmware detects Rd plugged in. cc_change is triggered and it will be vRd-connected at this moment)
=> TCPM writes LOOK4CONNECTION command
- Because RC.DRP is still 1, RT1711H will not pull cc1/cc2 to Rd while writing Rd/Rd to RC.CC1/RC.CC2.
- (Note2) Right after LOOK4CONNECTION command is written, RT1711H pulls CC to Rd's level (because RC.Role is Rd/Rd), stop toggling (because device(Rd) is already connected) and CC status will be open/open now (because RT1711H presents Rd and device is connected(Rd))
[ 915.037263] typec_rt1711h 2-004e: __tcpm_get_cc cc1 = Open, cc2 = Open
=> Enter RT1711H's irq handler and it reports open/open
I think the point is to write RC.DRP = 0 at the beginning of drp_toggling so that RT1711H will pull cc1/cc2 to Rd while writing Rd/Rd to RC.CC1/RC.CC2 This operation will make RT1711H's internal firmware restarts from disconnected state and toggles correctly.
According to TCPCI spec (4.4.5.2):
It is recommended the TCPM write ROLE_CONTROL.DRP=0 before writing to POWER_CONTROL.AutoDischargeDisconnect and starting the DRP toggling using COMMAND.Look4Connection Restart DRP Toggling
=> It is recommended the TCPM write ROLE_CONTROL.DRP=0 here
Set PC.AutoDischargeDisconnect=0b
Set RC.DRP=1b (DRP)
Set RC.RpValue=00b (smallest Rp to save power)
Set RC.CC1=01b
Set RC.CC2=01bCOMMAND.Look4ConnectionNo
It seems like it is not a general case here (because it is only recommended but not necessary), we can move it to vendor_ops in the next patch.
For your question:
Why RT1711H reports open/open after drp_toggling is enabled?
=> See Note2 above.
This open/open is for you plug out the device, right?
=> No, see Note2 above.
Why RT1711H can't report new cc change events after you plug in the device? => RT1711H can generate new cc change events after plugging in the device. What cc change event tcpc will report on step 4?
=> See Note1 above
Did you verify your change can pass the typec compliance test? => We didn't test it yet but try to make all functions work correctly first.
Best Regards,
*****************************
Shu-Fan Lee
Richtek Technology Corporation
TEL: +886-3-5526789 #2359
FAX: +886-3-5526612
*****************************
-----Original Message-----
From: Jun Li [mailto:[email protected]]
Sent: Thursday, March 01, 2018 1:35 PM
To: shufan_lee(李書帆); ShuFanLee; [email protected]; [email protected]; [email protected]
Cc: cy_huang(黃啟原); [email protected]; [email protected]; dl-linux-imx
Subject: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flow
Hi
Quoted 20 lines
-----Original Message-----
From:shufan_lee(李書帆)[mailto:[email protected]]
Sent: 2018年2月28日 11:41
To: Jun Li <[email protected]>; ShuFanLee <[email protected]>; [email protected]; [email protected]; [email protected]
Cc:cy_huang(黃啟原)<[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: 回覆: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowHi Jun,
For the questions of
drp_toggling, our test is as following:According to TCPCI 4.4.5.2
It is recommended the TCPM write ROLE_CONTROL.DRP=0 before writing to POWER_CONTROL.AutoDischargeDisconnect and starting the DRP toggling using COMMAND.Look4Connection.
Quoted 7 lines
We've encounter a situation while testing with RT1711H as following:
We repeatedly plug in/out a device (with Rd), and not to provide
VBUS(5V) while plugging in.
If we plug out the device right after TCPC detects it and stops
toggling, TCPM will try to restartdrp_toggling.
Here, we re-plug in the device before TCPM callsdrp_toggling. Under
this circumstance, RT1711H reports open/open afterdrp_togglingis called.
Why RT1711H reports open/open after drp_toggling is enabled? This open/open is for you plug out the device, right?
Why RT1711H can't report new cc change events after you plug in the device?
Please use tcpm log to show all the events and state transitions for your above corner case. cat /sys/kernel/debug/tcpm/xxxxx
Quoted 7 lines
For current TCPM, it stops if open/open is reported at
drp_togglingstate.The detailed flow that causes RT1711H reporting open/open is
described as following:
1. RT1711H detects the device, stops toggling and reports to TCPM.
2. Rd is plugged out beforeset_ccis called. So, ROLE_CONTROL.DRP
is still 1.
So open/open cc change will generate.
Quoted 3 lines
3. Plug in the device before TCPM restarts
drp_toggling
4. The device is detected by RT1711H's internal firmware again(TCPC
chip's internal firmware).
What cc change event tcpc will report on step 4?
Quoted 15 lines
5. TCPM calls
drp_togglingbeforecc_changetriggered by step 4 is
handled.
6. TCPM sets ROLE_CONTROL.DRP = 1, Rd/Rd and startdrp_toggling.
According to TCPCI 4.4.5.2
The TCPM shall write B6 (DRP) = 0b and B3..0 (CC1/CC2) if it wishes to control the Rp/Rd directly instead of having the TCPC perform DRP toggling autonomousl.
So, Rd/Rd set in step 6 will not work. (Because ROLE_CONTROL.DRP is 1 since the first step.)
7. RT1711H will stop toggling immediately (Because it's internal
firmware already detects device at step 4) and report open/open (Because CC1/CC2 will be changed to Rd by RT1711H after LOOK4CONNECTION is set. RT1711H sets to Rd and device is Rd so open is reported)
8. TCPCI reports open/open to TCPM atdrp_togglingstate
Quoted 3 lines
That's why we always set ROLE_CONTROL.DRP to 0 while setting Rd/Rd. If this circumstance is not a general case, we can also use a vendor
ops to replace it.
Thanks for the detailed description, the tcpm full log is required to know what's going on here, you can apply my drp_toggling change patch[1] and run your problem case again, then post the full tcpm log.
Generally, I think you need check further this is a problem on the current tcpm _or_ your tcpc chip, if the problem on the tcpm, you should resolve this issue by improve tcpm, if the problem on your tcpc chip, you can add a vendor ops.
I tested my tcpc HW with my drp_toggling change patch[1] (w/o your change) by quickly pulg-in & plug-out a sink, no problem found. Did you verify your change can pass the typec compliance test?
[1] https://www.spinics.net/lists/devicetree/msg216851.html
Quoted 25 lines
==============================================================
==========I don't catch the point of how you handle private events by above change, maybe post your RT1711H part as a user in one series can make it clear, I assume this can be done in existing
tcpci_irqlike above vender specific handling as well:For every glue driver, it registers its own irq handler and calls
tcpci_irqin the handler.Take RT1711H as an example:
It registers its own irq handler in probe function and handle vendor defined interrupts before calling generaltcpci_irq:static irqreturn_t _tcpci_irq(int irq, void *dev_id) { struct rt1711h_chip *chip = dev_id; /* handle vendor defined interrupts here */ /* call general tcpci_irq */ return tcpci_irq(chip->tcpci); }static int rt1711h_probe(struct
i2c_client*client, const structi2c_device_id
Quoted 10 lines
*i2c_id) { .... ret = devm_request_threaded_irq(chip->dev, client->irq, NULL, _tcpci_irq, IRQF_ONESHOT | IRQF_TRIGGER_LOW, dev_name(&client->dev),chip); }
Get it, thanks.
Quoted 382 lines
Best Regards,
*****************************************
Shu-Fan Lee
Richtek Technology Corporation
TEL: +886-3-5526789 #2359
FAX: +886-3-5526612
*****************************************________________________________________
寄件者: Jun Li <[email protected]>
寄件日期: 2018年2月22日 下午 06:16
收件者: ShuFanLee; [email protected]; [email protected]; [email protected]
副本:shufan_lee(李書帆);cy_huang(黃啟原); [email protected]; [email protected]; dl-linux-imx
主旨: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowHi,
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of ShuFanLee
Sent: 2018年2月21日 23:02
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowQuoted 8 lines
From: ShuFanLee <[email protected]>
Handle vendor defined behavior in
tcpci_init,tcpci_set_vconnand exporttcpci_irq.
More operations can be extended intcpci_dataif needed. According to TCPCI specification, 4.4.5.2ROLE_CONTROL, TCPC shall not start DRP toggling until subsequently the TCPM writes to the COMMAND register to start DRP toggling.My understanding of above statement is TCPM(this Linux driver) can enable DRP and CC1/CC2 in one shot, but TCPC(your typec chip internal firmware) needs wait until TCPM writes to COMMAND register to start drp toggling.
Quoted 2 lines
DRP toggling flow is chagned as following:
- Write DRP = 0 & Rd/RdWhy fixed to be Rd/Rd? in this case, it means the starting value:
Tcpci 4.4.5.2:
"When initiating autonomous DRP toggling, the TCPM shall write B6 (DRP) =1b and the starting value of Rp/Rd to B3..0 (CC1/CC2) to indicate DRP autonomous toggling mode to the TCPC."Quoted 1 line
- Write DRP = 1
What's your problem if combine above 2 in one shot?
Quoted 75 lines
- Set LOOK4CONNECTION command
Signed-off-by ShuFanLee <[email protected]>--- drivers/staging/typec/tcpci.c | 128 +++++++++++++++++++++++++++++++++--------- drivers/staging/typec/tcpci.h | 13 +++++ 2 files changed, 115 insertions(+), 26 deletions(-)patch changelogs between v1 & v2
- Remove unnecessaryi2c_clientin the structure of tcpci
- Rename structure oftcpci_vendor_datatotcpci_data
- Not exporting tcpci read/write wrappers but register i2c regmap
in glue driver
- Addset_vconnops intcpci_data
(It is necessary for RT1711H to enable/disable idle mode before
disabling/enabling vconn)
- Exporttcpci_irqso that vendor can call it in their own IRQ
handlerpatch changelogs between v2 & v3
- Change the return type oftcpci_irqfrom int toirqreturn_t(quoted diff) +0
-0
b/drivers/staging/typec/tcpci.cindex 9bd4412..4959c69 100644drivers/staging/typec/tcpci.c +10
-4@@ -21,7 +21,6 @@struct tcpci {struct device *dev; -struct i2c_client *client;struct tcpm_port *port;@@ -30,6 +29,12 @@ struct tcpci {bool controls_vbus;struct tcpc_dev tcpc; +struct tcpci_data *data; +}; + +struct tcpci_chip { +struct tcpci *tcpci; +struct tcpci_data data; }; static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) @@ -37,8 +42,7 @@ static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev +*tcpc) return container_of(tcpc, struct tcpci, tcpc); } -static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg, -u16 *val) +static int tcpci_read16 (struct tcpci *tcpci,unsigned int reg,u16 +*val) {return regmap_raw_read (tcpci->regmap, reg, val,sizeof (u16));} @@
-98,8 +102,10 @@ static inttcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)static int tcpci_start_drp_toggling(structtcpc_dev*tcpc,enum typec_cc_status cc) {drivers/staging/typec/tcpci.c +2
-1+int ret;struct tcpci *tcpci =tcpc_to_tcpci (tcpc); -unsigned int reg =TCPC_ROLE_CTRL_DRP ; + unsigned int reg = (TCPC_ROLE_CTRL_CC_RD <<
TCPC_ROLE_CTRL_CC1_SHIFT) |
+ (TCPC_ROLE_CTRL_CC_RD<<TCPC_ROLE_CTRL_CC2_SHIFT);switch (cc) { default:drivers/staging/typec/tcpci.c static int tcpci_start_drp_toggling(struct · line 130
Quoted 9 lines
drivers/staging/typec/tcpci.c +4
-1@@ -117,7 +123,19 @@ static int tcpci_start_drp_toggling(structtcpc_dev *tcpc, break; } -return regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; +usleep_range (500 ,1000 );Why need a wait here? It seems you actually don't want to do autonomously toggling from the very beginning, instead, you begin with a directly control on CC, keep it(Rd) for some time, then switch to use autonomously toggling, why you need such kind of sequence? I think it's special and not following tcpci spec.
Quoted 19 lines
drivers/staging/typec/tcpci.c +9
-0+ reg |=TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; + ret =regmap_write (tcpci->regmap,TCPC_COMMAND , +TCPC_CMD_LOOK4CONNECTION ); +if (ret <0 ) +return ret; +return 0 ; }static enum
typec_cc_statustcpci_to_typec_cc(unsigned int cc, bool
sink) @@ -178,6 +196,16 @@ static inttcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)struct tcpci *tcpci = tcpc_to_tcpci(tcpc); int ret;drivers/staging/typec/tcpci.c +2
-0+/* Handle vendor set vconn */ +if (tcpci->data) {drivers/staging/typec/tcpci.c static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)
Quoted 10 lines
drivers/staging/typec/tcpci.c +8
-0+if (tcpci->data->set_vconn) { + ret = tcpci->data->set_vconn (tcpci, tcpci->data, + enable); +if (ret <0 ) +return ret; + } + } + ret = regmap_write(tcpci->regmap, TCPC_POWER_CTRL, enable ?
TCPC_POWER_CTRL_VCONN_ENABLE: 0);Quoted 27 lines
if (ret < 0)drivers/staging/typec/tcpci.c +13
-1@@ -323,6 +351,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)if (time_after (jiffies, timeout))return -ETIMEDOUT ; +/* Handle vendor init */ +if (tcpci->data) { +if (tcpci->data->init) { + ret = tcpci->data->init (tcpci, tcpci->data); +if (ret <0 ) +return ret; + } + } +/* Clear all events */ ret =tcpci_write16 (tcpci,TCPC_ALERT ,0xffff );if (ret <0 )@@ -344,9 +381,15 @@ static int tcpci_init(struct tcpc_dev *tcpc)return tcpci_write16 (tcpci,TCPC_ALERT_MASK , reg); } -static irqreturn_t tcpci_irq (int irq,void *dev_id) +static irqreturn_t _tcpci_irq (int irq,void *dev_id) {struct tcpci *tcpci = dev_id; + +return tcpci_irq (tcpci); +}drivers/staging/typec/tcpci.c static int tcpci_init(struct tcpc_dev *tcpc)
Quoted 10 lines
drivers/staging/typec/tcpci.c +3
-0+ +irqreturn_t tcpci_irq (struct tcpci *tcpci) {u16 status; tcpci_read16(tcpci, TCPC_ALERT, &status); @@ -412,6 +455,7 @@ static irqreturn_t tcpci_irq(int irq, void *dev_id) return IRQ_HANDLED; } +EXPORT_SYMBOL_GPL (tcpci_irq);I don't catch the point of how you handle private events by above change, maybe post your RT1711H part as a user in one series can make it clear, I assume this can be done in existing
tcpci_irqlike above vender specific handling as well:tcpci->data->priv_events(tcpci, tcpci->data);Li Jun
Quoted 16 lines
static const struct regmap_config tcpci_regmap_config = { .reg_bits = 8,drivers/staging/typec/tcpci.c +3
-2@@ -435,22 +479,18 @@ static int tcpci_parse_config(struct tcpci *tcpci)return 0 ; } -static int tcpci_probe (struct i2c_client *client, -const struct i2c_device_id *i2c_id) +struct tcpci *tcpci_register_port (struct device *dev,struct +tcpci_data +*data) {struct tcpci *tcpci;int err;drivers/staging/typec/tcpci.c static int tcpci_parse_config(struct tcpci *tcpci) · line 451
Quoted 10 lines
drivers/staging/typec/tcpci.c +2
-6- tcpci =devm_kzalloc (&client->dev,sizeof (*tcpci),GFP_KERNEL ); + tcpci =devm_kzalloc (dev,sizeof (*tcpci),GFP_KERNEL );if (!tcpci) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); - tcpci->client = client; - tcpci->dev = &client->dev; -i2c_set_clientdata (client, tcpci); - tcpci->regmap = devm_regmap_init_i2c(client,
&tcpci_regmap_config);Quoted 44 lines
drivers/staging/typec/tcpci.c +3
-2-if (IS_ERR (tcpci->regmap)) -return PTR_ERR (tcpci->regmap); + tcpci->dev = dev; + tcpci->data = data; + tcpci->regmap = data->regmap; tcpci->tcpc.init = tcpci_init; tcpci->tcpc.get_vbus = tcpci_get_vbus; @@ -467,27 +507,63 @@static int tcpci_probe(struct
i2c_client*client,err = tcpci_parse_config(tcpci); if (err < 0)drivers/staging/typec/tcpci.c +24
-5-return err; +return ERR_PTR (err); + + tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); +if (PTR_ERR_OR_ZERO (tcpci->port)) +return ERR_CAST (tcpci->port); -/* Disable chip interrupts */ -tcpci_write16 (tcpci,TCPC_ALERT_MASK ,0 ); +return tcpci; +} +EXPORT_SYMBOL_GPL (tcpci_register_port); + +void tcpci_unregister_port (struct tcpci *tcpci) { +tcpm_unregister_port (tcpci->port); +} +EXPORT_SYMBOL_GPL (tcpci_unregister_port); - err = devm_request_threaded_irq(tcpci->dev, client->irq, NULL, - tcpci_irq, +static int tcpci_probe (struct i2c_client *client, +const struct i2c_device_id *i2c_id) { +struct tcpci_chip *chip; +int err; +u16 val =0 ; + + chip =devm_kzalloc (&client->dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->data.regmap = devm_regmap_init_i2c(client,
&tcpci_regmap_config);drivers/staging/typec/tcpci.c static int tcpci_probe(struct i2c_client *client,
Quoted 5 lines
drivers/staging/typec/tcpci.c +5
-0+if (IS_ERR (chip->data.regmap)) +return PTR_ERR (chip->data.regmap); + +/* Disable chip interrupts before requesting irq */ + err = regmap_raw_write(chip->data.regmap, TCPC_ALERT_MASK,&val,
drivers/staging/typec/tcpci.c static int tcpci_probe(struct i2c_client *client,
Quoted 7 lines
drivers/staging/typec/tcpci.c +6
-0+ sizeof(u16)); +if (err <0 ) +return err; + + err = devm_request_threaded_irq(&client->dev, client->irq, NULL, + _tcpci_irq, IRQF_ONESHOT |
IRQF_TRIGGER_LOW,Quoted 1 line
-
dev_name(tcpci->dev),tcpci);
Quoted 1 line
+
dev_name(&client->dev),chip);
Quoted 53 lines
if (err < 0) return err;drivers/staging/typec/tcpci.c +8
-4- tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); -return PTR_ERR_OR_ZERO (tcpci->port); + chip->tcpci =tcpci_register_port (&client->dev, &chip->data); +if (PTR_ERR_OR_ZERO (chip->tcpci)) +return PTR_ERR (chip->tcpci); + +i2c_set_clientdata (client, chip); +return 0 ; }static int tcpci_remove (struct i2c_client *client) { -struct tcpci *tcpci =i2c_get_clientdata (client); +struct tcpci_chip *chip =i2c_get_clientdata (client); -tcpm_unregister_port (tcpci->port); +tcpci_unregister_port (chip->tcpci);return 0 ; }(quoted diff) +0
-0
b/drivers/staging/typec/tcpci.hindex fdfb06c..40025b2 100644drivers/staging/typec/tcpci.h +12
-1@@ -59,6 +59,7 @@#define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)#define TCPC_CC_STATUS 0x1d +#define TCPC_CC_STATUS_DRPRST BIT(5)#define TCPC_CC_STATUS_TERM BIT(4)#define TCPC_CC_STATUS_CC2_SHIFT 2#define TCPC_CC_STATUS_CC2_MASK 0x3@@ -121,4 +122,16 @@#define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76#define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78 +struct tcpci ; +struct tcpci_data { +struct regmap *regmap; +int (*init)(struct tcpci *tcpci,struct tcpci_data *data); +int (*set_vconn)(struct tcpci *tcpci,struct tcpci_data *data, +bool enable); }; + +struct tcpci *tcpci_register_port (struct device *dev,struct +tcpci_data *data);void tcpci_unregister_port (struct tcpci *tcpci); +irqreturn_t tcpci_irq (struct tcpci *tcpci); +#endif /* __LINUX_USB_TCPCI_H */ --1.9.1
Quoted 3 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] Moremajordomo
Quoted 2 lines
info at
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fvger
Quoted 1 line
.kernel.org%2Fmajordomo-info.html&data=02%7C01%7Cjun.li%40nxp.co
m
Quoted 1 line
%7C44d11af27e0244fa4d1108d5793c3dc4%7C686ea1d3bc2b4c6fa92cd99
c
Quoted 1 line
5c301635%7C0%7C1%7C636548222008905206&sdata=zn2ougKRvs%2BbmH
Quoted 1 line
Qg2c8Rjj7vNe0ZiiVKdar7GdPa%2B3o%3D&reserved=0
************* Email Confidentiality Notice ********************
Quoted 12 lines
The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!
************* Email Confidentiality Notice ********************
The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!
Hi Shufan
Please don't top posting
Quoted 11 lines
-----Original Message-----
From:shufan_lee(李書帆)[mailto:[email protected]]
Sent: 2018年3月1日 16:49
To: Jun Li <[email protected]>; ShuFanLee <[email protected]>; [email protected]; [email protected]; [email protected]
Cc:cy_huang(黃啟原)<[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flow
Quoted 5 lines
Hi Jun,
The attachment is waveform of the condition we met but I'm not sure
whether you can download the attachment.
I add log in RT1711H it shows as following:
You don't need add log by your own.
There is tcpm(./drivers/usb/typec/tcpm.c) log for debug already, which can show all the events and state transitions, you can get it by below command as I commented:
cat /sys/kernel/debug/tcpm/xxxxx(your tcpc i2c device)
Quoted 32 lines
[ 914.937340] typec_rt1711h 2-004e: __rt1711h_irq_handler [ 914.943838]
typec_rt1711h2-004e:__tcpm_get_cccc1 = Open, cc2 = Open => Device(Rd) is plugged out[ 914.958041] typec_rt1711h 2-004e: tcpm_set_pd_rx 0 [ 914.963011]
typec_rt1711h2-004e:tcpm_set_vbusvbus = 0 [ 914.968407]typec_rt1711h2-004e:tcpm_set_vbuschg is already 0 [ 914.974541]typec_rt1711h2-004e:tcpm_set_vconnvconn is already 0 [ 914.980921]typec_rt1711h2-004e:tcpm_set_current_limit0 ma, 0 mv (not implemented) [ 914.988894]typec_rt1711h2-004e:tcpm_set_polarityPolarity_CC1[ 915.003201]typec_rt1711h2-004e:tcpm_set_rolesSource Host [ 915.009264]typec_rt1711h2-004e:tcpm_start_drp_toggling=>state_machine_workof TCPM callsstart_drp_togglingfunction but does not set LOOK4CONNECTION command yet => (Note1) Device(Rd) is plugged in (RT1711H's internal firmware detects Rd plugged in.cc_changeis triggered and it will be vRd-connected at this moment) => TCPM writes LOOK4CONNECTION command
- Because RC.DRP is still 1, RT1711H will not pull cc1/cc2 to Rd while writing Rd/Rd to RC.CC1/RC.CC2.
- (Note2) Right after LOOK4CONNECTION command is written, RT1711H pulls CC to Rd's level (because RC.Role is Rd/Rd), stop toggling (because device(Rd) is already connected) and CC status will be open/open now (because RT1711H presents Rd and device is connected(Rd))[ 915.037263] typec_rt1711h 2-004e: __tcpm_get_cc cc1 = Open, cc2 =Open => Enter RT1711H's irq handler and it reports open/open
I think the point is to write RC.DRP = 0 at the beginning of
drp_togglingso that RT1711H will pull cc1/cc2 to Rd while writing Rd/Rd to RC.CC1/RC.CC2 This operation will make RT1711H's internal firmware restarts from disconnected state and toggles correctly.
Quoted 5 lines
According to TCPCI spec (4.4.5.2):
It is recommended the TCPM write ROLE_CONTROL.DRP=0 before writing to POWER_CONTROL.AutoDischargeDisconnect and starting the DRP toggling using COMMAND.Look4Connection Restart DRP Toggling => It is recommended the TCPM write ROLE_CONTROL.DRP=0 here Set
This statement is_not_ recommend you do this(RC.DRP=0) for start drp toggling, Please carefully check the whole sentence:
"... as shown in Figure 4-16, "
If you look at "Figure 4-16. DRP Initialization and Connection Detection" It gives clear drp toggling start operations:
Set TCPC to DRP
- Read PS.TCPCInitializationStatus
- Write ROLE_CONTROL
- RC.DRP = 1b
- RC.CC2=01b or 10b
- RC.CC1=01b or 10b
- RC.CC1=RC.CC2
- Write COMMAND.Look4ConnectionPS.
Above is all operations required to start drp toggling. You also can see RC.CCx = 01b or 10b, not fixed to be Rd, right?
Go on to check the Figure 4-16
After debounce, we need do following:
ConnectionDetermine CC & VCONN
- Write RC.CC1 & RC.CC2 per decision
- Write RC.DRP=0
- Write TCPC_CONTROl.PlugOrientation
- Write PC.AutoDischargeDisconnect=1
& PC.EnableVconnConnection
Current existing tcpm+tcpci will not clear RC.DRP after attach, That means RC.DRP clear may be done after attach, not in start_drp_toggling. I am not sure if this can resolve your problem, but I think it deserve a try, you can follow above operation sequence while entering attach state, refer to my patch[2]:
[2] https://www.spinics.net/lists/devicetree/msg216852.html
Quoted 6 lines
PC.AutoDischargeDisconnect=0b Set RC.DRP=1b (DRP) Set RC.RpValue=00b (smallest Rp to save power) Set RC.CC1=01b Set RC.CC2=01bCOMMAND.Look4ConnectionNo
It seems like it is not a general case here (because it is only recommended but not necessary), we can move it to
vendor_opsin the next patch.
The TCPM should be able to cover all cases, and we should follow the recommended sequence(if what you are trying to do is really as spec says).
Quoted 14 lines
For your question:
Why RT1711H reports open/open afterdrp_togglingis enabled?
=> See Note2 above.
This open/open is for you plug out the device, right?
=> No, see Note2 above.
Why RT1711H can't report new cc change events after you plug in the device?
=> RT1711H can generate new cc change events after plugging in the device. What cc change event tcpc will report on step 4?
=> See Note1 above
Did you verify your change can pass the typec compliance test? => We didn't test it yet but try to make all functions work correctly first.
Quoted 8 lines
Best Regards,
*****************************
Shu-Fan Lee
Richtek Technology Corporation
TEL: +886-3-5526789 #2359
FAX: +886-3-5526612
*****************************
drivers/staging/typec/tcpci.c +15 -0
@@ -184,6 +184,7 @@ 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,
@@ -192,6 +193,20 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc,if (ret <0 )return ret; + ret =regmap_read (tcpci->regmap,TCPC_ROLE_CTRL , ®); +if (ret <0 ) +return ret; + +if (polarity ==TYPEC_POLARITY_CC2 ) + ret =TCPC_ROLE_CTRL_CC1_SHIFT ; +else + ret =TCPC_ROLE_CTRL_CC2_SHIFT ; + reg |=TCPC_ROLE_CTRL_CC_OPEN << ret; + reg &= ~TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; +return 0 ; }
Hi Jun,
Quoted 24 lines
-----Original Message-----
From: Jun Li [mailto:[email protected]]
Sent: Thursday, March 01, 2018 6:06 PM
To:shufan_lee(李書帆); ShuFanLee; [email protected]; [email protected]; [email protected]
Cc:cy_huang(黃啟原); [email protected]; [email protected]; dl-linux-imx
Subject: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowHi Shufan
Please don't top posting
-----Original Message-----
From:shufan_lee(李書帆)[mailto:[email protected]]
Sent: 2018年3月1日 16:49
To: Jun Li <[email protected]>; ShuFanLee <[email protected]>; [email protected]; [email protected]; [email protected]
Cc:cy_huang(黃啟原)<[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowHi Jun,
Quoted 9 lines
The attachment is waveform of the condition we met but I'm not sure
whether you can download the attachment.
I add log in RT1711H it shows as following:You don't need add log by your own.
There is tcpm(./drivers/usb/typec/tcpm.c) log for debug already, which can show all the events and state transitions, you can get it by below command as I commented:cat /sys/kernel/debug/tcpm/xxxxx(your tcpc i2c device)
After applying your patch[2], TCPM log is as following:
[ 53.050602] CC1: 0 -> 2, CC2: 0 -> 0 [state DRP_TOGGLING, polarity 0, connected] [ 53.050613] state change DRP_TOGGLING -> SRC_ATTACH_WAIT [ 53.050678] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms => Rd is plugged out [ 53.178804] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_ATTACH_WAIT, polarity 0, disconnected] [ 53.178815] state change SRC_ATTACH_WAIT -> SRC_UNATTACHED => Rd is plugged in [ 53.178874] Start DRP toggling [ 53.188472] CC1: 0 -> 0, CC2: 0 -> 0 [state DRP_TOGGLING, polarity 0, disconnected]
If TCPM does not enter SRC_ATTACHED state, RC.DRP will not be cleared.
When TCPM writes Rd/Rd or Rp/Rp in the drp_toggling function, it does not take effect until LOOK4CONNECTION command is set. The above condition causes RT1711H reports open/open at [53.188472]
Quoted 54 lines
[ 914.937340] typec_rt1711h 2-004e: __rt1711h_irq_handler [914.943838]
typec_rt1711h2-004e:__tcpm_get_cccc1 = Open, cc2 = Open => Device(Rd) is plugged out[ 914.958041] typec_rt1711h 2-004e: tcpm_set_pd_rx 0 [ 914.963011]
typec_rt1711h2-004e:tcpm_set_vbusvbus = 0 [ 914.968407]typec_rt1711h
2-004e:tcpm_set_vbuschg is already 0 [ 914.974541]typec_rt1711h2-004e:tcpm_set_vconnvconn is already 0 [ 914.980921]typec_rt1711h2-004e:tcpm_set_current_limit0 ma, 0 mv (not implemented) [ 914.988894]typec_rt1711h2-004e:tcpm_set_polarityPolarity_CC1[ 915.003201]typec_rt1711h2-004e:tcpm_set_rolesSource Host [ 915.009264]typec_rt1711h2-004e:tcpm_start_drp_toggling=>state_machine_workof TCPM callsstart_drp_togglingfunction but does not set LOOK4CONNECTION command yet => (Note1) Device(Rd) is plugged in (RT1711H's internal firmware detects Rd plugged in.cc_changeis triggered and it will be vRd-connected at this moment) => TCPM writes LOOK4CONNECTION command
- Because RC.DRP is still 1, RT1711H will not pull cc1/cc2 to Rd while writing Rd/Rd to RC.CC1/RC.CC2.
- (Note2) Right after LOOK4CONNECTION command is written, RT1711H pulls CC to Rd's level (because RC.Role is Rd/Rd), stop toggling (because
device(Rd) is already connected) and CC status will be open/open now (because RT1711H presents Rd and device is connected(Rd))[ 915.037263] typec_rt1711h 2-004e: __tcpm_get_cc cc1 = Open, cc2 =Open => Enter RT1711H's irq handler and it reports open/open
I think the point is to write RC.DRP = 0 at the beginning of
drp_togglingso that RT1711H will pull cc1/cc2 to Rd while writing Rd/Rd to RC.CC1/RC.CC2 This operation will make RT1711H's internal firmware restarts from disconnected state and toggles correctly.According to TCPCI spec (4.4.5.2):
It is recommended the TCPM write ROLE_CONTROL.DRP=0 before writing to POWER_CONTROL.AutoDischargeDisconnect and starting the DRP toggling using COMMAND.Look4Connection Restart DRP Toggling => It is recommended the TCPM write ROLE_CONTROL.DRP=0 here SetThis statement
is_not_recommend you do this(RC.DRP=0) for start drp toggling, Please carefully check the whole sentence:
"... as shown in Figure 4-16, "
If you look at "Figure 4-16. DRP Initialization and Connection Detection"
It gives clear drp toggling start operations:Set TCPC to DRP
- Read PS.TCPCInitializationStatus
- WriteROLE_CONTROL
- RC.DRP = 1b
- RC.CC2=01b or 10b
- RC.CC1=01b or 10b
- RC.CC1=RC.CC2
- Write COMMAND.Look4ConnectionPS.
Quoted 1 line
Above is all operations required to start drp toggling. You also can see RC.CCx = 01b or 10b, not fixed to be Rd, right?
Yes, this one should be like your patch[07/12]. Write Rd or Rp to RC.CCx according to the cc parameter of drp_toggling function.
Quoted 46 lines
Go on to check the Figure 4-16
After debounce, we need do following:ConnectionDetermine CC & VCONN
- Write RC.CC1 & RC.CC2 per decision
- Write RC.DRP=0
- Write TCPC_CONTROl.PlugOrientation
- Write PC.AutoDischargeDisconnect=1
& PC.EnableVconnConnectionCurrent existing tcpm+tcpci will not clear RC.DRP after attach, That means RC.DRP clear may be done after attach, not in
start_drp_toggling. I am not sure if this can resolve your problem, but I think it deserve a try, you can follow above operation sequence while entering attach state, refer to my patch[2]:[2] https://www.spinics.net/lists/devicetree/msg216852.html
drivers/staging/typec/tcpci.c +1
-0@@ -184,6 +184,7 @@ 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, @@ -192,6 +193,20 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc, if (ret < 0)return ret;drivers/staging/typec/tcpci.c +14
-0+ ret =regmap_read (tcpci->regmap,TCPC_ROLE_CTRL , ®); +if (ret <0 ) +return ret; + +if (polarity ==TYPEC_POLARITY_CC2 ) + ret =TCPC_ROLE_CTRL_CC1_SHIFT ; +else + ret =TCPC_ROLE_CTRL_CC2_SHIFT ; + reg |=TCPC_ROLE_CTRL_CC_OPEN << ret; + reg &= ~TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; +return 0 ; }
Quoted 8 lines
PC.AutoDischargeDisconnect=0b Set RC.DRP=1b (DRP) Set RC.RpValue=00b (smallest Rp to save power) Set RC.CC1=01b Set RC.CC2=01bCOMMAND.Look4ConnectionNo
It seems like it is not a general case here (because it is only recommended but not necessary), we can move it to
vendor_opsin the next patch.The TCPM should be able to cover all cases, and we should follow the recommended sequence(if what you are trying to do is really as spec says).
Agree!
My understanding is that we need to set RC.DRP to 0 every time before TCPM restarts toggling but not just for attached. For RT1711H, it follows above flow. If it is not correct, this operation should be moved to vendor_ops.
Quoted 14 lines
For your question:
Why RT1711H reports open/open afterdrp_togglingis enabled?
=> See Note2 above.
This open/open is for you plug out the device, right?
=> No, see Note2 above.
Why RT1711H can't report new cc change events after you plug in the device?
=> RT1711H can generate new cc change events after plugging in the device. What cc change event tcpc will report on step 4?
=> See Note1 above
Did you verify your change can pass the typec compliance test? => We didn't test it yet but try to make all functions work correctly first.
Quoted 8 lines
Best Regards,
*****************************
Shu-Fan Lee
Richtek Technology Corporation
TEL: +886-3-5526789 #2359
FAX: +886-3-5526612
*****************************
************* Email Confidentiality Notice ********************
The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!
SGk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3NhZ2UgKGluY2x1ZGluZyBhbnkgYXR0YWNo bWVudHMpDQo+IG1heSBiZSBjb25maWRlbnRpYWwsIHByb3ByaWV0YXJ5LCBwcml2aWxlZ2VkLCBv ciBvdGhlcndpc2UgZXhlbXB0IGZyb20NCj4gZGlzY2xvc3VyZSB1bmRlciBhcHBsaWNhYmxlIGxh d3MuIEl0IGlzIGludGVuZGVkIHRvIGJlIGNvbnZleWVkIG9ubHkgdG8gdGhlDQo+IGRlc2lnbmF0 ZWQgcmVjaXBpZW50KHMpLiBBbnkgdXNlLCBkaXNzZW1pbmF0aW9uLCBkaXN0cmlidXRpb24sIHBy aW50aW5nLA0KPiByZXRhaW5pbmcgb3IgY29weWluZyBvZiB0aGlzIGUtbWFpbCAoaW5jbHVkaW5n IGl0cyBhdHRhY2htZW50cykgYnkgdW5pbnRlbmRlZA0KPiByZWNpcGllbnQocykgaXMgc3RyaWN0 bHkgcHJvaGliaXRlZCBhbmQgbWF5IGJlIHVubGF3ZnVsLiBJZiB5b3UgYXJlIG5vdCBhbg0KPiBp bnRlbmRlZCByZWNpcGllbnQgb2YgdGhpcyBlLW1haWwsIG9yIGJlbGlldmUgdGhhdCB5b3UgaGF2 ZSByZWNlaXZlZCB0aGlzDQo+IGUtbWFpbCBpbiBlcnJvciwgcGxlYXNlIG5vdGlmeSB0aGUgc2Vu ZGVyIGltbWVkaWF0ZWx5IChieSByZXBseWluZyB0byB0aGlzDQo+IGUtbWFpbCksIGRlbGV0ZSBh bnkgYW5kIGFsbCBjb3BpZXMgb2YgdGhpcyBlLW1haWwgKGluY2x1ZGluZyBhbnkgYXR0YWNobWVu dHMpDQo+IGZyb20geW91ciBzeXN0ZW0sIGFuZCBkbyBub3QgZGlzY2xvc2UgdGhlIGNvbnRlbnQg b2YgdGhpcyBlLW1haWwgdG8gYW55IG90aGVyDQo+IHBlcnNvbi4gVGhhbmsgeW91IQ0K
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Jun,
I think this operation should be moved to vendor's operation after
rechecking the specification.
2018-03-02 22:38 GMT+08:00 Jun Li <[email protected]>:
Quoted 78 lines
Hi
Quoted 9 lines
-----Original Message-----
From:shufan_lee(李書帆)[mailto:[email protected]]
Sent: 2018年3月1日 19:54
To: Jun Li <[email protected]>; ShuFanLee <[email protected]>; [email protected]; [email protected]; [email protected]
Cc:cy_huang(黃啟原)<[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: RE: [PATCH] staging: typec: handle vendor defined part andmodify
Quoted 37 lines
drp toggling flow
Hi Jun,
Quoted 33 lines
-----Original Message-----
From: Jun Li [mailto:[email protected]]
Sent: Thursday, March 01, 2018 6:06 PM
To:shufan_lee(李書帆); ShuFanLee; [email protected]; [email protected]; [email protected]
Cc:cy_huang(黃啟原); [email protected]; [email protected]; dl-linux-imx
Subject: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowHi Shufan
Please don't top posting
-----Original Message-----
From:shufan_lee(李書帆)[mailto:[email protected]]
Sent: 2018年3月1日 16:49
To: Jun Li <[email protected]>; ShuFanLee <[email protected]>; [email protected]; [email protected]; [email protected]
Cc:cy_huang(黃啟原)<[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowHi Jun,
The attachment is waveform of the condition we met but I'm not sure
whether you can download the attachment.
I add log in RT1711H it shows as following:You don't need add log by your own.
There is tcpm(./drivers/usb/typec/tcpm.c) log for debug already,which can
Quoted 1 line
show all the events and state transitions, you can get it by below
command
Quoted 5 lines
as I commented:
Quoted 3 lines
cat /sys/kernel/debug/tcpm/xxxxx(your tcpc i2c device)
After applying your patch[2], TCPM log is as following:
I assume you also applied my patch [1].
[1] https://www.spinics.net/lists/devicetree/msg216851.htmlYes, this patch is also applied.
Quoted 8 lines
[ 53.050602] CC1: 0 -> 2, CC2: 0 -> 0 [state DRP_TOGGLING, polarity 0, connected] [ 53.050613] state change DRP_TOGGLING -> SRC_ATTACH_WAIT [ 53.050678] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms => Rd is plugged out [ 53.178804] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_ATTACH_WAIT, polarity0,
Quoted 6 lines
disconnected]
[ 53.178815] state change SRC_ATTACH_WAIT -> SRC_UNATTACHED => Rd is plugged in [ 53.178874] Start DRP toggling [ 53.188472] CC1: 0 -> 0, CC2: 0 -> 0 [state DRP_TOGGLING, polarity 0,disconnected]
Quoted 3 lines
1. The plug out and then plug in happens in 10ms? (53.188472 - 53.178804) Was this done manually? Or by some special test method?
It's done manually. If you can download the waveform attached in previous email, you can see Rd is plugged out/in within ms level.
We connect a bridge board with test points of CC1, CC2 and GND to our platform's Typec receptacle. Then we can simulate a device plugging in/out by connecting/disconnecting a 5.1k resistor between CC1 and GND.
Quoted 3 lines
2. This is all tcpm log if you finally keep the Rd-device connected on typec
port? There is no more tcpm log after 53.188472 if you plug in Rd-device
and don't remove it?
Quoted 1 line
Yes, RT1711H reports open/open to TCPM in drp_toggling state and stops toggling. Currently, TCPM does not restart drp_toggling if it receives open/open in drp_toggling state.
I remember the specification of TypeC does not depict what TCPM should do if it receives open/open in drp_toggling state.
Maybe restart toggling is an option.
3. If the answer of Q2 is yes, then I must ask why you tcpc chip+internal
Quoted 7 lines
firmware
can't report further cc change event after your drp toggling starts to present Rp(I know
it firstly present Rd after you write to LOOK4CONNECTION, but then it should change
to present Rp, so it should be able to detect the Rd-device finally)
Because RT1711H's internal firmware changes to attached state when Rd is re-plugged in(cc level is default Rp (around 400mV) now).
Then, LOOK4CONNECTION is set and RT1711H changes CCx to Rd that makes it reports open/open(because cc level changes from default Rp(around 400mV) to 0mV)
Quoted 166 lines
Quoted 3 lines
If TCPM does not enter
SRC_ATTACHEDstate, RC.DRP will not be cleared.In this case, you don’t need clear RC.DRP, see TCPCI spec:
"Figure 4-18. Sink Disconnect"
TCPM sink doesn't clear it in whole sequence, just directly set it:
Restart DRP Toggling
PC.AutoDischargeDisconnect=0b
Set RC.DRP=1b (DRP)
Set RC.CC1=10b (Rd)
Set RC.CC2=10b (Rd)
COMMAND.Look4Connection (DRP toggle)Quoted 43 lines
When TCPM writes Rd/Rd or Rp/Rp in the
drp_togglingfunction, it does not take effect until LOOK4CONNECTION command is set.
The above condition causes RT1711H reports open/open at [53.188472]Quoted 2 lines
[ 914.937340] typec_rt1711h 2-004e: __rt1711h_irq_handler [914.943838]
typec_rt1711h2-004e:__tcpm_get_cccc1 = Open, cc2 =Open
Quoted 6 lines
=> Device(Rd) is plugged out
[ 914.958041] typec_rt1711h 2-004e: tcpm_set_pd_rx 0 [ 914.963011]
typec_rt1711h2-004e:tcpm_set_vbusvbus = 0 [ 914.968407]typec_rt1711h
2-004e:tcpm_set_vbuschg is already 0 [ 914.974541]typec_rt1711h2-004e:
Quoted 5 lines
tcpm_set_vconnvconn is already 0 [ 914.980921]typec_rt1711h2-004e:tcpm_set_current_limit0 ma, 0 mv (not implemented) [ 914.988894]typec_rt1711h2-004e:tcpm_set_polarityPolarity_CC1[ 915.003201]typec_rt1711h2-004e:tcpm_set_rolesSource Host [ 915.009264]typec_rt1711h2-004e:tcpm_start_drp_toggling=>state_machine_workof
Quoted 16 lines
TCPM calls
start_drp_togglingfunction but does not set LOOK4CONNECTION command yet => (Note1) Device(Rd) is plugged in (RT1711H's internal firmware detects Rd plugged in.cc_changeis triggered and it will be vRd-connected at this moment) => TCPM writes LOOK4CONNECTION command
- Because RC.DRP is still 1, RT1711H will not pull cc1/cc2 to Rd while writing Rd/Rd to RC.CC1/RC.CC2.
- (Note2) Right after LOOK4CONNECTION command is written, RT1711H pulls CC to Rd's level (because RC.Role is Rd/Rd), stop toggling (because
device(Rd) is already connected) and CC status will be open/open now (because RT1711H presents Rd and device is connected(Rd))[ 915.037263] typec_rt1711h 2-004e: __tcpm_get_cc cc1 = Open, cc2 =Open => Enter RT1711H's irq handler and it reports open/open
Quoted 7 lines
I think the point is to write RC.DRP = 0 at the beginning of
drp_togglingso that RT1711H will pull cc1/cc2 to Rd while writing Rd/Rd to RC.CC1/RC.CC2 This operation will make RT1711H's internal firmware restarts from disconnected state and toggles correctly.According to TCPCI spec (4.4.5.2):
It is recommended the TCPM write ROLE_CONTROL.DRP=0 before writingQuoted 9 lines
to
Quoted 5 lines
POWER_CONTROL.AutoDischargeDisconnect and starting the DRP toggling using COMMAND.Look4Connection Restart DRP Toggling => It is recommended the TCPM write ROLE_CONTROL.DRP=0 here Set
This statement
is_not_recommend you do this(RC.DRP=0) for start drptoggling, Please carefully check the whole sentence:
Quoted 2 lines
"... as shown in Figure 4-16, "
If you look at "Figure 4-16. DRP Initialization and ConnectionDetection"
Quoted 11 lines
Quoted 11 lines
It gives clear drp toggling start operations:
Set TCPC to DRP
- Read PS.TCPCInitializationStatus
- WriteROLE_CONTROL
- RC.DRP = 1b
- RC.CC2=01b or 10b
- RC.CC1=01b or 10b
- RC.CC1=RC.CC2
- Write COMMAND.Look4ConnectionPS.Quoted 1 line
Quoted 1 line
Above is all operations required to start drp toggling. You also can
see
Quoted 15 lines
RC.CCx = 01b or 10b, not fixed to be Rd, right?
Yes, this one should be like your patch[07/12]. Write Rd or Rp to RC.CCx according to the cc parameter ofdrp_togglingfunction.Quoted 12 lines
Go on to check the Figure 4-16
After debounce, we need do following:ConnectionDetermine CC & VCONN
- Write RC.CC1 & RC.CC2 per decision
- Write RC.DRP=0
- Write TCPC_CONTROl.PlugOrientation
- Write PC.AutoDischargeDisconnect=1
& PC.EnableVconnConnectionCurrent existing tcpm+tcpci will not clear RC.DRP after attach, That
means
Quoted 2 lines
RC.DRP clear may be done after attach, not in
start_drp_toggling.Quoted 1 line
I am not sure if this can resolve your problem, but I think it deserve
a try,
Quoted 1 line
you can follow above operation sequence while entering attach state,
refer
Quoted 14 lines
to my patch[2]:
Quoted 3 lines
[2]
https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fw
wwQuoted 1 line
.spinics.net%2Flists%2Fdevicetree%2Fmsg216852.html&data=02%7C01%7
Cjun.
Quoted 1 line
li%40nxp.com%7C9117425550d24ddc86d808d57f6b1b4e%7C686ea1d3bc2b
4c6fa92cQuoted 1 line
d99c5c301635%7C0%7C0%7C636555020366483456&sdata=9%2BywYl%2BR PYtk60Wg6p
Quoted 7 lines
drivers/staging/typec/tcpci.c static int tcpci_set_polarity(struct tcpc_dev
Quoted 7 lines
R63cCW2AnRXs%2BrINvvqUpqL18%3D&reserved=0
(quoted diff) +0
-0
b/drivers/staging/typec/tcpci.cindex 530a5d7..7145771 100644drivers/staging/typec/tcpci.c +0
-0@@ -184,6 +184,7 @@ static int tcpci_set_polarity(struct tcpc_dev*tcpc,
Quoted 31 lines
drivers/staging/typec/tcpci.c static int tcpci_set_polarity(struct tcpc_dev *tcpc,
Quoted 6 lines
drivers/staging/typec/tcpci.c +1
-0enum typec_cc_polarity polarity) {struct tcpci *tcpci =tcpc_to_tcpci (tcpc); +unsigned int reg;int ret; ret = regmap_write(tcpci->regmap, TCPC_TCPC_CTRL, @@-192,6 +193,20 @@ static int tcpci_set_polarity(struct
tcpc_dev*tcpc,Quoted 24 lines
drivers/staging/typec/tcpci.c +0
-0if (ret <0 )return ret;drivers/staging/typec/tcpci.c +14
-0+ ret =regmap_read (tcpci->regmap,TCPC_ROLE_CTRL , ®); +if (ret <0 ) +return ret; + +if (polarity ==TYPEC_POLARITY_CC2 ) + ret =TCPC_ROLE_CTRL_CC1_SHIFT ; +else + ret =TCPC_ROLE_CTRL_CC2_SHIFT ; + reg |=TCPC_ROLE_CTRL_CC_OPEN << ret; + reg &= ~TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; +return 0 ; }PC.AutoDischargeDisconnect=0b Set RC.DRP=1b (DRP) Set RC.RpValue=00b (smallest Rp to save power) Set RC.CC1=01b Set RC.CC2=01bCOMMAND.Look4ConnectionNo
Quoted 6 lines
Quoted 2 lines
It seems like it is not a general case here (because it is only recommended but not necessary), we can move it to
vendor_opsin thenext patch.
Quoted 2 lines
The TCPM should be able to cover all cases, and we should follow the
recommended sequence(if what you are trying to do is really as spec
says).
Quoted 3 lines
Agree!
My understanding is that we need to set RC.DRP to 0 every time before TCPM restarts toggling but not just for attached.
Quoted 9 lines
Actually I have no objection on adding a RC.DRP clear, the question is where is the right place to do this, till now I don’t see how this DRP bit keep set
while start drp toggling is causing problem, You want to start present Rd after write
CC1/CC2 to be Rd/Rd and before write to LOOK4CONNECTION, this is not required
per tcpci spec.
According to TCPCI's specification, it is recommended the TCPM write RC.DRP = 0 before changing AutoDischargeDisconnecd.
Maybe, an interface for controlling AutoDischargeDisconnecd can be added. Then clear RC.DRP in the beginning of that interface.
Quoted 10 lines
-Behavior after your patch:
//begin with Open as RC.DRP = 1
RC.CCx=Rd & RC.DRP = 0; //Start present Rd Wait 1ms; // Still Rd
RC.CCx=Rd & RC.DRP = 1; //Open? Look4CONNECTION = 1; //DRP toggling continue preset RdIs my above CC state description correct? Is this what you want?
Correct. But the purpose of setting RC.CCx = Rd & RC.DRP = 0 is to make RT1711H's internal firmware leave attached state.
Because RT1711H is still presenting Rp after the device is plugged out, it's internal firmware enters attached state when the device re-plugged in. When we write RC.CCx = Rd & RC.DRP = 0, RT1711H's internal firmware leaves attached state. So it will keep toggling from Rd to Rp but not report open/open when LOOK4CONNECTION is set.
After rechecking the specification of TCPCI, I think TCPC's internal firmware should start toggling from detached state when LOOK4CONNECTION is set even if RC.DRP is not cleared before
I've discussed with my colleagues, we think this should be in vendor ops. I'll update it in the patch v6.
Could I also apply your patch [1] in the patch v6?
Thank you for your time to clarify this condition.
Quoted 55 lines
-Only apply my patches:
//begin with Open as RC.DRP = 1
RC.CCx=Rd & RC.DRP = 1; //still Open
Look4Connection = 1; //Start preset RdQuoted 1 line
For RT1711H, it follows above flow. If it is not correct, this operation
should
Quoted 10 lines
be moved to
vendor_ops.Quoted 9 lines
For your question:
Why RT1711H reports open/open afterdrp_togglingis enabled? => See Note2 above.
This open/open is for you plug out the device, right?
=> No, see Note2 above.
Why RT1711H can't report new cc change events after you plug in the device?
=> RT1711H can generate new cc change events after plugging in theQuoted 5 lines
device.
Quoted 4 lines
What cc change event tcpc will report on step 4?
=> See Note1 above
Did you verify your change can pass the typec compliance test? => We didn't test it yet but try to make all functions work correctlyfirst.
Quoted 10 lines
Quoted 9 lines
Best Regards,
*****************************
Shu-Fan Lee
Richtek Technology Corporation
TEL: +886-3-5526789 #2359
FAX: +886-3-5526612
*****************************Quoted 3 lines
************* Email Confidentiality Notice ********************
The information contained in this e-mail message (including any
attachments)
Quoted 2 lines
may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to
the
Quoted 2 lines
designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by
unintended
Quoted 1 line
recipient(s) is strictly prohibited and may be unlawful. If you are not
an
Quoted 2 lines
intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to
this
Quoted 1 line
e-mail), delete any and all copies of this e-mail (including any
attachments)
Quoted 1 line
from your system, and do not disclose the content of this e-mail to any
other
Quoted 1 line
person. Thank you!
Signature · 2 lines
Best Regards, 書帆
Hi,
Sorry, I modify it to plain text mode and send again
2018-03-03 2:39 GMT+08:00 李書帆 <[email protected]>:
Quoted 343 lines
Hi Jun,
I think this operation should be moved to vendor's operation after rechecking the specification.
2018-03-02 22:38 GMT+08:00 Jun Li <[email protected]>:
Quoted 51 lines
Hi
Quoted 49 lines
-----Original Message-----
From:shufan_lee(李書帆)[mailto:[email protected]]
Sent: 2018年3月1日 19:54
To: Jun Li <[email protected]>; ShuFanLee <[email protected]>; [email protected]; [email protected]; [email protected]
Cc:cy_huang(黃啟原)<[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowHi Jun,
Quoted 25 lines
-----Original Message-----
From: Jun Li [mailto:[email protected]]
Sent: Thursday, March 01, 2018 6:06 PM
To:shufan_lee(李書帆); ShuFanLee; [email protected]; [email protected]; [email protected]
Cc:cy_huang(黃啟原); [email protected]; [email protected]; dl-linux-imx
Subject: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowHi Shufan
Please don't top posting
-----Original Message-----
From:shufan_lee(李書帆)[mailto:[email protected]]
Sent: 2018年3月1日 16:49
To: Jun Li <[email protected]>; ShuFanLee <[email protected]>; [email protected]; [email protected]; [email protected]
Cc:cy_huang(黃啟原)<[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: RE: [PATCH] staging: typec: handle vendor defined part and modify drp toggling flowQuoted 8 lines
Hi Jun,
The attachment is waveform of the condition we met but I'm not sure
whether you can download the attachment.
I add log in RT1711H it shows as following:You don't need add log by your own.
There is tcpm(./drivers/usb/typec/tcpm.c) log for debug already, which canshow all the events and state transitions, you can get it by below command as I commented:
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
cat /sys/kernel/debug/tcpm/xxxxx(your tcpc i2c device)
After applying your patch[2], TCPM log is as following:
I assume you also applied my patch [1].
[1] https://www.spinics.net/lists/devicetree/msg216851.htmlYes, this patch is also applied.
Quoted 16 lines
Quoted 14 lines
[ 53.050602] CC1: 0 -> 2, CC2: 0 -> 0 [state DRP_TOGGLING, polarity 0, connected] [ 53.050613] state change DRP_TOGGLING -> SRC_ATTACH_WAIT [ 53.050678] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms => Rd is plugged out [ 53.178804] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_ATTACH_WAIT, polarity 0, disconnected] [ 53.178815] state change SRC_ATTACH_WAIT -> SRC_UNATTACHED => Rd is plugged in [ 53.178874] Start DRP toggling [ 53.188472] CC1: 0 -> 0, CC2: 0 -> 0 [state DRP_TOGGLING, polarity 0,Quoted 1 line
disconnected]
Quoted 2 lines
1. The plug out and then plug in happens in 10ms? (53.188472 - 53.178804) Was this done manually? Or by some special test method?
It's done manually. If you can download the waveform attached in previous email, you can see Rd is plugged out/in within ms level.
We connect a bridge board with test points of CC1, CC2 and GND to our platform's Typec receptacle. Then we can simulate a device plugging in/out by connecting/disconnecting a 5.1k resistor between CC1 and GND.Quoted 5 lines
2. This is all tcpm log if you finally keep the Rd-device connected on typec port? There is no more tcpm log after 53.188472 if you plug in Rd-device
and don't remove it?
Yes, RT1711H reports open/open to TCPM in
drp_togglingstate and stops toggling. Currently, TCPM does not restartdrp_togglingif it receives open/open indrp_togglingstate. I remember the specification of TypeC does not depict what TCPM should do if it receives open/open indrp_togglingstate.
Maybe restart toggling is an option.Quoted 4 lines
3. If the answer of Q2 is yes, then I must ask why you tcpc chip+internal firmware can't report further cc change event after your drp toggling starts to present Rp(I know it firstly present Rd after you write to LOOK4CONNECTION, but then it should change to present Rp, so it should be able to detect the Rd-device finally)
Because RT1711H's internal firmware changes to attached state when Rd is re-plugged in(cc level is default Rp (around 400mV) now). Then, LOOK4CONNECTION is set and RT1711H changes CCx to Rd that makes it reports open/open(because cc level changes from default Rp(around 400mV) to 0mV)
Quoted 160 lines
Quoted 4 lines
If TCPM does not enter
SRC_ATTACHEDstate, RC.DRP will not be cleared.In this case, you don’t need clear RC.DRP, see TCPCI spec:
"Figure 4-18. Sink Disconnect"
TCPM sink doesn't clear it in whole sequence, just directly set it:
Restart DRP Toggling
PC.AutoDischargeDisconnect=0b
Set RC.DRP=1b (DRP)
Set RC.CC1=10b (Rd)
Set RC.CC2=10b (Rd)
COMMAND.Look4Connection (DRP toggle)Quoted 138 lines
When TCPM writes Rd/Rd or Rp/Rp in the
drp_togglingfunction, it does not take effect until LOOK4CONNECTION command is set.
The above condition causes RT1711H reports open/open at [53.188472]Quoted 2 lines
[ 914.937340] typec_rt1711h 2-004e: __rt1711h_irq_handler [914.943838]
typec_rt1711h2-004e:__tcpm_get_cccc1 = Open, cc2 =Open
Quoted 6 lines
=> Device(Rd) is plugged out
[ 914.958041] typec_rt1711h 2-004e: tcpm_set_pd_rx 0 [ 914.963011]
typec_rt1711h2-004e:tcpm_set_vbusvbus = 0 [ 914.968407]typec_rt1711h
2-004e:tcpm_set_vbuschg is already 0 [ 914.974541]typec_rt1711h2-004e:
Quoted 5 lines
tcpm_set_vconnvconn is already 0 [ 914.980921]typec_rt1711h2-004e:tcpm_set_current_limit0 ma, 0 mv (not implemented) [ 914.988894]typec_rt1711h2-004e:tcpm_set_polarityPolarity_CC1[ 915.003201]typec_rt1711h2-004e:tcpm_set_rolesSource Host [ 915.009264]typec_rt1711h2-004e:tcpm_start_drp_toggling=>state_machine_workof
Quoted 16 lines
TCPM calls
start_drp_togglingfunction but does not set LOOK4CONNECTION command yet => (Note1) Device(Rd) is plugged in (RT1711H's internal firmware detects Rd plugged in.cc_changeis triggered and it will be vRd-connected at this moment) => TCPM writes LOOK4CONNECTION command
- Because RC.DRP is still 1, RT1711H will not pull cc1/cc2 to Rd while writing Rd/Rd to RC.CC1/RC.CC2.
- (Note2) Right after LOOK4CONNECTION command is written, RT1711H pulls CC to Rd's level (because RC.Role is Rd/Rd), stop toggling (because
device(Rd) is already connected) and CC status will be open/open now (because RT1711H presents Rd and device is connected(Rd))[ 915.037263] typec_rt1711h 2-004e: __tcpm_get_cc cc1 = Open, cc2 =Open => Enter RT1711H's irq handler and it reports open/open
Quoted 7 lines
I think the point is to write RC.DRP = 0 at the beginning of
drp_togglingso that RT1711H will pull cc1/cc2 to Rd while writing Rd/Rd to RC.CC1/RC.CC2 This operation will make RT1711H's internal firmware restarts from disconnected state and toggles correctly.According to TCPCI spec (4.4.5.2):
It is recommended the TCPM write ROLE_CONTROL.DRP=0 before writingto
Quoted 5 lines
POWER_CONTROL.AutoDischargeDisconnect and starting the DRP toggling using COMMAND.Look4Connection Restart DRP Toggling => It is recommended the TCPM write ROLE_CONTROL.DRP=0 here Set
This statement
is_not_recommend you do this(RC.DRP=0) for start drptoggling, Please carefully check the whole sentence:
Quoted 13 lines
"... as shown in Figure 4-16, "
If you look at "Figure 4-16. DRP Initialization and Connection Detection" It gives clear drp toggling start operations:Set TCPC to DRP
- Read PS.TCPCInitializationStatus
- WriteROLE_CONTROL
- RC.DRP = 1b
- RC.CC2=01b or 10b
- RC.CC1=01b or 10b
- RC.CC1=RC.CC2
- Write COMMAND.Look4ConnectionPS.Quoted 1 line
Above is all operations required to start drp toggling. You also can see
RC.CCx = 01b or 10b, not fixed to be Rd, right?
Yes, this one should be like your patch[07/12]. Write Rd or Rp to RC.CCx according to the cc parameter ofdrp_togglingfunction.Quoted 4 lines
Go on to check the Figure 4-16
After debounce, we need do following:Quoted 8 lines
ConnectionDetermine CC & VCONN
- Write RC.CC1 & RC.CC2 per decision
- Write RC.DRP=0
- Write TCPC_CONTROl.PlugOrientation
- Write PC.AutoDischargeDisconnect=1
& PC.EnableVconnConnectionCurrent existing tcpm+tcpci will not clear RC.DRP after attach, That means
RC.DRP clear may be done after attach, not in
start_drp_toggling.Quoted 1 line
I am not sure if this can resolve your problem, but I think it deserve a try,
you can follow above operation sequence while entering attach state, refer to my patch[2]:
Quoted 3 lines
[2]
https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fw
wwQuoted 1 line
.spinics.net%2Flists%2Fdevicetree%2Fmsg216852.html&data=02%7C01%7
Cjun.
Quoted 1 line
li%40nxp.com%7C9117425550d24ddc86d808d57f6b1b4e%7C686ea1d3bc2b
4c6fa92cQuoted 1 line
d99c5c301635%7C0%7C0%7C636555020366483456&sdata=9%2BywYl%2BR PYtk60Wg6p
drivers/staging/typec/tcpci.c static int tcpci_set_polarity(struct tcpc_dev *tcpc, · line 189
Quoted 13 lines
R63cCW2AnRXs%2BrINvvqUpqL18%3D&reserved=0
(quoted diff) +0
-0
b/drivers/staging/typec/tcpci.cindex 530a5d7..7145771 100644drivers/staging/typec/tcpci.c +1
-0@@ -184,6 +184,7 @@ 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, @@-192,6 +193,20 @@ static int tcpci_set_polarity(struct
tcpc_dev*tcpc,Quoted 20 lines
drivers/staging/typec/tcpci.c +0
-0if (ret <0 )return ret;drivers/staging/typec/tcpci.c +14
-0+ ret =regmap_read (tcpci->regmap,TCPC_ROLE_CTRL , ®); +if (ret <0 ) +return ret; + +if (polarity ==TYPEC_POLARITY_CC2 ) + ret =TCPC_ROLE_CTRL_CC1_SHIFT ; +else + ret =TCPC_ROLE_CTRL_CC2_SHIFT ; + reg |=TCPC_ROLE_CTRL_CC_OPEN << ret; + reg &= ~TCPC_ROLE_CTRL_DRP ; + ret =regmap_write (tcpci->regmap,TCPC_ROLE_CTRL , reg); +if (ret <0 ) +return ret; +return 0 ; }Quoted 6 lines
PC.AutoDischargeDisconnect=0b Set RC.DRP=1b (DRP) Set RC.RpValue=00b (smallest Rp to save power) Set RC.CC1=01b Set RC.CC2=01bCOMMAND.Look4ConnectionNo
It seems like it is not a general case here (because it is only recommended but not necessary), we can move it to
vendor_opsin thenext patch.
Quoted 1 line
Quoted 5 lines
Quoted 1 line
The TCPM should be able to cover all cases, and we should follow the
recommended sequence(if what you are trying to do is really as spec says). Agree!
My understanding is that we need to set RC.DRP to 0 every time before TCPM restarts toggling but not just for attached.Quoted 5 lines
Actually I have no objection on adding a RC.DRP clear, the question is where is the right place to do this, till now I don’t see how this DRP bit keep set while start drp toggling is causing problem, You want to start present Rd after write CC1/CC2 to be Rd/Rd and before write to LOOK4CONNECTION, this is not required per tcpci spec.
According to TCPCI's specification, it is recommended the TCPM write RC.DRP = 0 before changing AutoDischargeDisconnecd. Maybe, an interface for controlling AutoDischargeDisconnecd can be added. Then clear RC.DRP in the beginning of that interface.
Quoted 10 lines
-Behavior after your patch:
//begin with Open as RC.DRP = 1
RC.CCx=Rd & RC.DRP = 0; //Start present Rd Wait 1ms; // Still Rd
RC.CCx=Rd & RC.DRP = 1; //Open? Look4CONNECTION = 1; //DRP toggling continue preset RdIs my above CC state description correct? Is this what you want?
Correct. But the purpose of setting RC.CCx = Rd & RC.DRP = 0 is to make RT1711H's internal firmware leave attached state.
Because RT1711H is still presenting Rp after the device is plugged out, it's internal firmware enters attached state when the device re-plugged in.
When we write RC.CCx = Rd & RC.DRP = 0, RT1711H's internal firmware leaves attached state. So it will keep toggling from Rd to Rp but not report open/open when LOOK4CONNECTION is set. After rechecking the specification of TCPCI, I think TCPC's internal firmware should start toggling from detached state when LOOK4CONNECTION is set even if RC.DRP is not cleared before I've discussed with my colleagues, we think this should be in vendor ops. I'll update it in the patch v6.
Could I also apply your patch [1] in the patch v6?
Thank you for your time to clarify this condition.Quoted 46 lines
-Only apply my patches:
//begin with Open as RC.DRP = 1
RC.CCx=Rd & RC.DRP = 1; //still Open
Look4Connection = 1; //Start preset RdQuoted 39 lines
For RT1711H, it follows above flow. If it is not correct, this operation should be moved to
vendor_ops.Quoted 9 lines
For your question:
Why RT1711H reports open/open afterdrp_togglingis enabled? => See Note2 above.
This open/open is for you plug out the device, right?
=> No, see Note2 above.
Why RT1711H can't report new cc change events after you plug in the device?
=> RT1711H can generate new cc change events after plugging in thedevice.
Quoted 5 lines
What cc change event tcpc will report on step 4?
=> See Note1 above
Did you verify your change can pass the typec compliance test? => We didn't test it yet but try to make all functions work correctly first.Quoted 8 lines
Best Regards,
*****************************
Shu-Fan Lee
Richtek Technology Corporation
TEL: +886-3-5526789 #2359
FAX: +886-3-5526612
****************************************** Email Confidentiality Notice ********************
The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!
--
Best Regards,
書帆