Linux-USB Archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] usb: typec: tcpci: clear the fault status bit
@ 2023-08-16 17:25 Fabio Estevam
  2023-08-16 20:16 ` Guenter Roeck
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Fabio Estevam @ 2023-08-16 17:25 UTC (permalink / raw
  To: linux
  Cc: heikki.krogerus, gregkh, linux-usb, m.felsch, jun.li, xu.yang_2,
	angus, stable, Christian Bach, Fabio Estevam

From: Marco Felsch <m.felsch@pengutronix.de>

According the "USB Type-C Port Controller Interface Specification v2.0"
the TCPC sets the fault status register bit-7
(AllRegistersResetToDefault) once the registers have been reset to
their default values.

This triggers an alert(-irq) on PTN5110 devices albeit we do mask the
fault-irq, which may cause a kernel hang. Fix this generically by writing
a one to the corresponding bit-7.

Cc: stable@vger.kernel.org
Fixes: 74e656d6b055 ("staging: typec: Type-C Port Controller Interface driver (tcpci)")
Reported-by: Angus Ainslie (Purism) <angus@akkea.ca>
Closes: https://lore.kernel.org/all/20190508002749.14816-2-angus@akkea.ca/
Reported-by: Christian Bach <christian.bach@scs.ch>
Closes: https://lore.kernel.org/regressions/ZR0P278MB07737E5F1D48632897D51AC3EB329@ZR0P278MB0773.CHEP278.PROD.OUTLOOK.COM/t/
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Signed-off-by: Fabio Estevam <festevam@denx.de>
---
Changes since v2:
- Submitted it as a standalone patch.
- Explain that it may cause a kernel hang.
- Fixed typos in the commit log. (Guenter)
- Check the tcpci_write16() return value. (Guenter)
- Write to TCPC_FAULT_STATUS unconditionally. (Guenter)
- Added Fixes, Reported-by and Closes tags.
- CCed stable

 drivers/usb/typec/tcpm/tcpci.c | 4 ++++
 include/linux/usb/tcpci.h      | 1 +
 2 files changed, 5 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index fc708c289a73..0ee3e6e29bb1 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -602,6 +602,10 @@ static int tcpci_init(struct tcpc_dev *tcpc)
 	if (time_after(jiffies, timeout))
 		return -ETIMEDOUT;
 
+	ret = tcpci_write16(tcpci, TCPC_FAULT_STATUS, TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT);
+	if (ret < 0)
+		return ret;
+
 	/* Handle vendor init */
 	if (tcpci->data->init) {
 		ret = tcpci->data->init(tcpci, tcpci->data);
diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h
index 85e95a3251d3..83376473ac76 100644
--- a/include/linux/usb/tcpci.h
+++ b/include/linux/usb/tcpci.h
@@ -103,6 +103,7 @@
 #define TCPC_POWER_STATUS_SINKING_VBUS	BIT(0)
 
 #define TCPC_FAULT_STATUS		0x1f
+#define TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT BIT(7)
 
 #define TCPC_ALERT_EXTENDED		0x21
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] usb: typec: tcpci: clear the fault status bit
  2023-08-16 17:25 [PATCH v3] usb: typec: tcpci: clear the fault status bit Fabio Estevam
@ 2023-08-16 20:16 ` Guenter Roeck
  2023-08-17  7:58 ` Marco Felsch
  2023-08-22 13:57 ` Heikki Krogerus
  2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2023-08-16 20:16 UTC (permalink / raw
  To: Fabio Estevam
  Cc: heikki.krogerus, gregkh, linux-usb, m.felsch, jun.li, xu.yang_2,
	angus, stable, Christian Bach, Fabio Estevam

On Wed, Aug 16, 2023 at 02:25:02PM -0300, Fabio Estevam wrote:
> From: Marco Felsch <m.felsch@pengutronix.de>
> 
> According the "USB Type-C Port Controller Interface Specification v2.0"
> the TCPC sets the fault status register bit-7
> (AllRegistersResetToDefault) once the registers have been reset to
> their default values.
> 
> This triggers an alert(-irq) on PTN5110 devices albeit we do mask the
> fault-irq, which may cause a kernel hang. Fix this generically by writing
> a one to the corresponding bit-7.
> 
> Cc: stable@vger.kernel.org
> Fixes: 74e656d6b055 ("staging: typec: Type-C Port Controller Interface driver (tcpci)")
> Reported-by: Angus Ainslie (Purism) <angus@akkea.ca>
> Closes: https://lore.kernel.org/all/20190508002749.14816-2-angus@akkea.ca/
> Reported-by: Christian Bach <christian.bach@scs.ch>
> Closes: https://lore.kernel.org/regressions/ZR0P278MB07737E5F1D48632897D51AC3EB329@ZR0P278MB0773.CHEP278.PROD.OUTLOOK.COM/t/
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> Signed-off-by: Fabio Estevam <festevam@denx.de>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
> Changes since v2:
> - Submitted it as a standalone patch.
> - Explain that it may cause a kernel hang.
> - Fixed typos in the commit log. (Guenter)
> - Check the tcpci_write16() return value. (Guenter)
> - Write to TCPC_FAULT_STATUS unconditionally. (Guenter)
> - Added Fixes, Reported-by and Closes tags.
> - CCed stable
> 
>  drivers/usb/typec/tcpm/tcpci.c | 4 ++++
>  include/linux/usb/tcpci.h      | 1 +
>  2 files changed, 5 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
> index fc708c289a73..0ee3e6e29bb1 100644
> --- a/drivers/usb/typec/tcpm/tcpci.c
> +++ b/drivers/usb/typec/tcpm/tcpci.c
> @@ -602,6 +602,10 @@ static int tcpci_init(struct tcpc_dev *tcpc)
>  	if (time_after(jiffies, timeout))
>  		return -ETIMEDOUT;
>  
> +	ret = tcpci_write16(tcpci, TCPC_FAULT_STATUS, TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT);
> +	if (ret < 0)
> +		return ret;
> +
>  	/* Handle vendor init */
>  	if (tcpci->data->init) {
>  		ret = tcpci->data->init(tcpci, tcpci->data);
> diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h
> index 85e95a3251d3..83376473ac76 100644
> --- a/include/linux/usb/tcpci.h
> +++ b/include/linux/usb/tcpci.h
> @@ -103,6 +103,7 @@
>  #define TCPC_POWER_STATUS_SINKING_VBUS	BIT(0)
>  
>  #define TCPC_FAULT_STATUS		0x1f
> +#define TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT BIT(7)
>  
>  #define TCPC_ALERT_EXTENDED		0x21
>  
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] usb: typec: tcpci: clear the fault status bit
  2023-08-16 17:25 [PATCH v3] usb: typec: tcpci: clear the fault status bit Fabio Estevam
  2023-08-16 20:16 ` Guenter Roeck
@ 2023-08-17  7:58 ` Marco Felsch
  2023-08-22 13:57 ` Heikki Krogerus
  2 siblings, 0 replies; 4+ messages in thread
From: Marco Felsch @ 2023-08-17  7:58 UTC (permalink / raw
  To: Fabio Estevam
  Cc: linux, heikki.krogerus, gregkh, linux-usb, jun.li, xu.yang_2,
	angus, stable, Christian Bach, Fabio Estevam

On 23-08-16, Fabio Estevam wrote:
> From: Marco Felsch <m.felsch@pengutronix.de>
> 
> According the "USB Type-C Port Controller Interface Specification v2.0"
> the TCPC sets the fault status register bit-7
> (AllRegistersResetToDefault) once the registers have been reset to
> their default values.
> 
> This triggers an alert(-irq) on PTN5110 devices albeit we do mask the
> fault-irq, which may cause a kernel hang. Fix this generically by writing
> a one to the corresponding bit-7.
> 
> Cc: stable@vger.kernel.org
> Fixes: 74e656d6b055 ("staging: typec: Type-C Port Controller Interface driver (tcpci)")
> Reported-by: Angus Ainslie (Purism) <angus@akkea.ca>
> Closes: https://lore.kernel.org/all/20190508002749.14816-2-angus@akkea.ca/
> Reported-by: Christian Bach <christian.bach@scs.ch>
> Closes: https://lore.kernel.org/regressions/ZR0P278MB07737E5F1D48632897D51AC3EB329@ZR0P278MB0773.CHEP278.PROD.OUTLOOK.COM/t/
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> Signed-off-by: Fabio Estevam <festevam@denx.de>
> ---
> Changes since v2:
> - Submitted it as a standalone patch.
> - Explain that it may cause a kernel hang.
> - Fixed typos in the commit log. (Guenter)
> - Check the tcpci_write16() return value. (Guenter)
> - Write to TCPC_FAULT_STATUS unconditionally. (Guenter)
> - Added Fixes, Reported-by and Closes tags.
> - CCed stable

thanks for the work Fabio :)

Regards,
  Marco

> 
>  drivers/usb/typec/tcpm/tcpci.c | 4 ++++
>  include/linux/usb/tcpci.h      | 1 +
>  2 files changed, 5 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
> index fc708c289a73..0ee3e6e29bb1 100644
> --- a/drivers/usb/typec/tcpm/tcpci.c
> +++ b/drivers/usb/typec/tcpm/tcpci.c
> @@ -602,6 +602,10 @@ static int tcpci_init(struct tcpc_dev *tcpc)
>  	if (time_after(jiffies, timeout))
>  		return -ETIMEDOUT;
>  
> +	ret = tcpci_write16(tcpci, TCPC_FAULT_STATUS, TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT);
> +	if (ret < 0)
> +		return ret;
> +
>  	/* Handle vendor init */
>  	if (tcpci->data->init) {
>  		ret = tcpci->data->init(tcpci, tcpci->data);
> diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h
> index 85e95a3251d3..83376473ac76 100644
> --- a/include/linux/usb/tcpci.h
> +++ b/include/linux/usb/tcpci.h
> @@ -103,6 +103,7 @@
>  #define TCPC_POWER_STATUS_SINKING_VBUS	BIT(0)
>  
>  #define TCPC_FAULT_STATUS		0x1f
> +#define TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT BIT(7)
>  
>  #define TCPC_ALERT_EXTENDED		0x21
>  
> -- 
> 2.34.1
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] usb: typec: tcpci: clear the fault status bit
  2023-08-16 17:25 [PATCH v3] usb: typec: tcpci: clear the fault status bit Fabio Estevam
  2023-08-16 20:16 ` Guenter Roeck
  2023-08-17  7:58 ` Marco Felsch
@ 2023-08-22 13:57 ` Heikki Krogerus
  2 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2023-08-22 13:57 UTC (permalink / raw
  To: Fabio Estevam
  Cc: linux, gregkh, linux-usb, m.felsch, jun.li, xu.yang_2, angus,
	stable, Christian Bach, Fabio Estevam

On Wed, Aug 16, 2023 at 02:25:02PM -0300, Fabio Estevam wrote:
> From: Marco Felsch <m.felsch@pengutronix.de>
> 
> According the "USB Type-C Port Controller Interface Specification v2.0"
> the TCPC sets the fault status register bit-7
> (AllRegistersResetToDefault) once the registers have been reset to
> their default values.
> 
> This triggers an alert(-irq) on PTN5110 devices albeit we do mask the
> fault-irq, which may cause a kernel hang. Fix this generically by writing
> a one to the corresponding bit-7.
> 
> Cc: stable@vger.kernel.org
> Fixes: 74e656d6b055 ("staging: typec: Type-C Port Controller Interface driver (tcpci)")
> Reported-by: Angus Ainslie (Purism) <angus@akkea.ca>
> Closes: https://lore.kernel.org/all/20190508002749.14816-2-angus@akkea.ca/
> Reported-by: Christian Bach <christian.bach@scs.ch>
> Closes: https://lore.kernel.org/regressions/ZR0P278MB07737E5F1D48632897D51AC3EB329@ZR0P278MB0773.CHEP278.PROD.OUTLOOK.COM/t/
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> Signed-off-by: Fabio Estevam <festevam@denx.de>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> Changes since v2:
> - Submitted it as a standalone patch.
> - Explain that it may cause a kernel hang.
> - Fixed typos in the commit log. (Guenter)
> - Check the tcpci_write16() return value. (Guenter)
> - Write to TCPC_FAULT_STATUS unconditionally. (Guenter)
> - Added Fixes, Reported-by and Closes tags.
> - CCed stable
> 
>  drivers/usb/typec/tcpm/tcpci.c | 4 ++++
>  include/linux/usb/tcpci.h      | 1 +
>  2 files changed, 5 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
> index fc708c289a73..0ee3e6e29bb1 100644
> --- a/drivers/usb/typec/tcpm/tcpci.c
> +++ b/drivers/usb/typec/tcpm/tcpci.c
> @@ -602,6 +602,10 @@ static int tcpci_init(struct tcpc_dev *tcpc)
>  	if (time_after(jiffies, timeout))
>  		return -ETIMEDOUT;
>  
> +	ret = tcpci_write16(tcpci, TCPC_FAULT_STATUS, TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT);
> +	if (ret < 0)
> +		return ret;
> +
>  	/* Handle vendor init */
>  	if (tcpci->data->init) {
>  		ret = tcpci->data->init(tcpci, tcpci->data);
> diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h
> index 85e95a3251d3..83376473ac76 100644
> --- a/include/linux/usb/tcpci.h
> +++ b/include/linux/usb/tcpci.h
> @@ -103,6 +103,7 @@
>  #define TCPC_POWER_STATUS_SINKING_VBUS	BIT(0)
>  
>  #define TCPC_FAULT_STATUS		0x1f
> +#define TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT BIT(7)
>  
>  #define TCPC_ALERT_EXTENDED		0x21
>  
> -- 
> 2.34.1

-- 
heikki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-22 13:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-16 17:25 [PATCH v3] usb: typec: tcpci: clear the fault status bit Fabio Estevam
2023-08-16 20:16 ` Guenter Roeck
2023-08-17  7:58 ` Marco Felsch
2023-08-22 13:57 ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).