usb: dwc3: add power down scale setting
Subsystems (2)
PATCH 1/1 usb: dwc3: add power down scale setting
Some SoC(e.g NXP imx8MQ) may have a wrong default power down scale setting so need init it to be the correct value, the power down scale setting description in DWC3 databook:
Power Down Scale (PwrDnScale)
The USB3 suspend_clk input replaces pipe3_rx_pclk as a clock source to a small part of the USB3 core that operates when the SS PHY is in its lowest power (P3) state, and therefore does not provide a clock. The Power Down Scale field specifies how many suspend_clk periods fit into a 16 kHz clock period. When performing the division, round up the remainder.
For example, when using an 8-bit/16-bit/32-bit PHY and 25-MHz Suspend clock,
Power Down Scale = 25000 kHz/16 kHz = 13'd1563 (rounder up)
So use the suspend clock rate to calculate it.
--- drivers/usb/dwc3/core.c | 22 ++++++++++++++++++++++ drivers/usb/dwc3/core.h | 1 + 2 files changed, 23 insertions(+)
drivers/usb/dwc3/core.c +22 -0
@@ -1029,6 +1029,25 @@ static void dwc3_set_incr_burst_type(struct dwc3 *dwc)dwc3_writel (dwc->regs,DWC3_GSBUSCFG0 , cfg); } +static void dwc3_set_power_down_clk_scale (struct dwc3 *dwc) +{ +u32 reg, scale; + +if (!dwc->susp_clk) +return ; + +/* +* The power down scale field specifies how many suspend_clk +* periods fit into a 16KHz clock period. When performing +* the division, round up the remainder. +*/ + scale =DIV_ROUND_UP (clk_get_rate (dwc->susp_clk),16384 ); + reg =dwc3_readl (dwc->regs,DWC3_GCTL ); + reg &= ~(DWC3_GCTL_PWRDNSCALE_MASK ); + reg |=DWC3_GCTL_PWRDNSCALE (scale); +dwc3_writel (dwc->regs,DWC3_GCTL , reg); +} +/** * dwc3_core_init - Low-level initialization of DWC3 Core * @dwc: Pointer to our controller context structure
@@ -1105,6 +1124,9 @@ static int dwc3_core_init(struct dwc3 *dwc)if (ret) goto err1; +/* Set power down scale of suspend_clk */ +dwc3_set_power_down_clk_scale (dwc); +/* Adjust Frame Length */ dwc3_frame_length_adjustment (dwc);
drivers/usb/dwc3/core.h +1 -0
@@ -231,6 +231,7 @@/* Global Configuration Register */ #define DWC3_GCTL_PWRDNSCALE (n) ((n) << 19) +#define DWC3_GCTL_PWRDNSCALE_MASK GENMASK(31, 19)#define DWC3_GCTL_U2RSTECN BIT(16)#define DWC3_GCTL_RAMCLKSEL (x) (((x) & DWC3_GCTL_CLK_MASK) << 6)#define DWC3_GCTL_CLK_BUS (0)
Signature · 1 line
2.25.1
Thinh Nguyen
maintainerQuoted 28 lines · Li Jun
Some SoC(e.g NXP imx8MQ) may have a wrong default power down scale setting so need init it to be the correct value, the power down scale setting description in DWC3 databook:
Power Down Scale (PwrDnScale)
The USB3suspend_clkinput replacespipe3_rx_pclkas a clock source to a small part of the USB3 core that operates when the SS PHY is in its lowest power (P3) state, and therefore does not provide a clock. The Power Down Scale field specifies how manysuspend_clkperiods fit into a 16 kHz clock period. When performing the division, round up the remainder.
For example, when using an 8-bit/16-bit/32-bit PHY and 25-MHz Suspend clock,
Power Down Scale = 25000 kHz/16 kHz = 13'd1563 (rounder up)So use the suspend clock rate to calculate it.
Signed-off-by Li Jun <[email protected]>--- drivers/usb/dwc3/core.c | 22 ++++++++++++++++++++++ drivers/usb/dwc3/core.h | 1 + 2 files changed, 23 insertions(+)drivers/usb/dwc3/core.c +0
-0
drivers/usb/dwc3/core.c static void dwc3_set_incr_burst_type(struct dwc3 *dwc) · line 1034
Quoted 6 lines
drivers/usb/dwc3/core.c +3
-0@@ -1029,6 +1029,25 @@ static void dwc3_set_incr_burst_type(struct dwc3 *dwc)dwc3_writel (dwc->regs,DWC3_GSBUSCFG0 , cfg); } +static void dwc3_set_power_down_clk_scale (struct dwc3 *dwc) +{ +u32 reg, scale;
Can we declare these variables in separate lines? Preferably reverse Christmas tree style.
drivers/usb/dwc3/core.c static void dwc3_set_incr_burst_type(struct dwc3 *dwc) · line 1044
Quoted 10 lines
drivers/usb/dwc3/core.c +10
-0+ +if (!dwc->susp_clk) +return ; + +/* +* The power down scale field specifies how many suspend_clk +* periods fit into a 16KHz clock period. When performing +* the division, round up the remainder. +*/ + scale =DIV_ROUND_UP (clk_get_rate (dwc->susp_clk),16384 );
16kHz == 16000Hz right?
Quoted 24 lines
drivers/usb/dwc3/core.c +9
-0+ reg =dwc3_readl (dwc->regs,DWC3_GCTL ); + reg &= ~(DWC3_GCTL_PWRDNSCALE_MASK ); + reg |=DWC3_GCTL_PWRDNSCALE (scale); +dwc3_writel (dwc->regs,DWC3_GCTL , reg); +} +/** * dwc3_core_init - Low-level initialization of DWC3 Core * @dwc: Pointer to our controller context structure @@ -1105,6 +1124,9 @@ static int dwc3_core_init(struct dwc3 *dwc)if (ret) goto err1; +/* Set power down scale of suspend_clk */ +dwc3_set_power_down_clk_scale (dwc); +/* Adjust Frame Length */ dwc3_frame_length_adjustment (dwc);drivers/usb/dwc3/core.h +0
-0
drivers/usb/dwc3/core.h line 237
Quoted 7 lines
drivers/usb/dwc3/core.h +1
-0@@ -231,6 +231,7 @@/* Global Configuration Register */ #define DWC3_GCTL_PWRDNSCALE (n) ((n) << 19) +#define DWC3_GCTL_PWRDNSCALE_MASK GENMASK(31, 19)#define DWC3_GCTL_U2RSTECN BIT(16)#define DWC3_GCTL_RAMCLKSEL (x) (((x) & DWC3_GCTL_CLK_MASK) << 6)#define DWC3_GCTL_CLK_BUS (0)
Thanks,
Thinh
Thinh Nguyen
maintainerQuoted 16 lines · Thinh Nguyen
Quoted 15 lines · Li Jun
Some SoC(e.g NXP imx8MQ) may have a wrong default power down scale setting so need init it to be the correct value, the power down scale setting description in DWC3 databook:
Power Down Scale (PwrDnScale)
The USB3suspend_clkinput replacespipe3_rx_pclkas a clock source to a small part of the USB3 core that operates when the SS PHY is in its lowest power (P3) state, and therefore does not provide a clock. The Power Down Scale field specifies how manysuspend_clkperiods fit into a 16 kHz clock period. When performing the division, round up the remainder.
For example, when using an 8-bit/16-bit/32-bit PHY and 25-MHz Suspend clock,
Power Down Scale = 25000 kHz/16 kHz = 13'd1563 (rounder up)
Quoted 1 line
Quoted 1 line
So use the suspend clock rate to calculate it.
Also, shouldn't the value selected be the max_rate of the suspend clock and not just the value from clk_get_rate()?
Quoted 60 lines
Quoted 12 lines
Signed-off-by Li Jun <[email protected]>--- drivers/usb/dwc3/core.c | 22 ++++++++++++++++++++++ drivers/usb/dwc3/core.h | 1 + 2 files changed, 23 insertions(+)drivers/usb/dwc3/core.c +0
-0drivers/usb/dwc3/core.c static void dwc3_set_incr_burst_type(struct dwc3 *dwc) · line 1034
Quoted 6 lines
drivers/usb/dwc3/core.c +3
-0@@ -1029,6 +1029,25 @@ static void dwc3_set_incr_burst_type(struct dwc3 *dwc)dwc3_writel (dwc->regs,DWC3_GSBUSCFG0 , cfg); } +static void dwc3_set_power_down_clk_scale (struct dwc3 *dwc) +{ +u32 reg, scale;Can we declare these variables in separate lines? Preferably reverse Christmas tree style.
drivers/usb/dwc3/core.c static void dwc3_set_incr_burst_type(struct dwc3 *dwc) · line 1044
Quoted 10 lines
drivers/usb/dwc3/core.c +10
-0+ +if (!dwc->susp_clk) +return ; + +/* +* The power down scale field specifies how many suspend_clk +* periods fit into a 16KHz clock period. When performing +* the division, round up the remainder. +*/ + scale =DIV_ROUND_UP (clk_get_rate (dwc->susp_clk),16384 );16kHz == 16000Hz right?
Quoted 25 lines
drivers/usb/dwc3/core.c +9
-0+ reg =dwc3_readl (dwc->regs,DWC3_GCTL ); + reg &= ~(DWC3_GCTL_PWRDNSCALE_MASK ); + reg |=DWC3_GCTL_PWRDNSCALE (scale); +dwc3_writel (dwc->regs,DWC3_GCTL , reg); +} +/** * dwc3_core_init - Low-level initialization of DWC3 Core * @dwc: Pointer to our controller context structure @@ -1105,6 +1124,9 @@ static int dwc3_core_init(struct dwc3 *dwc)if (ret) goto err1; +/* Set power down scale of suspend_clk */ +dwc3_set_power_down_clk_scale (dwc); +/* Adjust Frame Length */ dwc3_frame_length_adjustment (dwc);drivers/usb/dwc3/core.h +0
-0@@ -231,6 +231,7 @@
Quoted 7 lines
drivers/usb/dwc3/core.h line 237
Quoted 6 lines
drivers/usb/dwc3/core.h +1
-0/* Global Configuration Register */ #define DWC3_GCTL_PWRDNSCALE (n) ((n) << 19) +#define DWC3_GCTL_PWRDNSCALE_MASK GENMASK(31, 19)#define DWC3_GCTL_U2RSTECN BIT(16)#define DWC3_GCTL_RAMCLKSEL (x) (((x) & DWC3_GCTL_CLK_MASK) << 6)#define DWC3_GCTL_CLK_BUS (0)
BR,
Thinh
Quoted 26 lines
-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Saturday, May 28, 2022 9:46 AM
To: Jun Li <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; J.D. Yue <[email protected]>
Subject: Re: [PATCH] usb: dwc3: add power down scale settingQuoted 16 lines · Thinh Nguyen
Quoted 15 lines · Li Jun
Some SoC(e.g NXP imx8MQ) may have a wrong default power down scale setting so need init it to be the correct value, the power down scale setting description in DWC3 databook:
Power Down Scale (PwrDnScale)
The USB3suspend_clkinput replacespipe3_rx_pclkas a clock source to a small part of the USB3 core that operates when the SS PHY is in its lowest power (P3) state, and therefore does not provide a clock. The Power Down Scale field specifies how manysuspend_clkperiods fit into a 16 kHz clock period. When performing the division, round up the remainder.
For example, when using an 8-bit/16-bit/32-bit PHY and 25-MHz Suspend clock,
Power Down Scale = 25000 kHz/16 kHz = 13'd1563 (rounder up)
Quoted 4 lines
Quoted 1 line
Quoted 1 line
So use the suspend clock rate to calculate it.
Also, shouldn't the value selected be the
max_rateof the suspend clock and not just the value fromclk_get_rate()?
In my case, the suspend_clk is fixed, seems max rate is only Used by clock provider and there is no API to get max_rate for clock users.
Thanks
Li Jun
Quoted 72 lines
Quoted 8 lines
Quoted 8 lines
Signed-off-by Li Jun <[email protected]>--- drivers/usb/dwc3/core.c | 22 ++++++++++++++++++++++ drivers/usb/dwc3/core.h | 1 + 2 files changed, 23 insertions(+)Quoted 5 lines
drivers/usb/dwc3/core.c static void dwc3_set_incr_burst_type(struct dwc3
Quoted 5 lines
drivers/usb/dwc3/core.c +0
-0@@ -1029,6 +1029,25 @@ static void dwc3_set_incr_burst_type(struct dwc3*dwc)
Quoted 48 lines
drivers/usb/dwc3/core.c static void dwc3_set_incr_burst_type(struct dwc3 *dwc) · line 1034
Quoted 6 lines
drivers/usb/dwc3/core.c +3
-0dwc3_writel (dwc->regs,DWC3_GSBUSCFG0 , cfg); } +static void dwc3_set_power_down_clk_scale (struct dwc3 *dwc) +{ +u32 reg, scale;Can we declare these variables in separate lines? Preferably reverse Christmas tree style.
drivers/usb/dwc3/core.c static void dwc3_set_incr_burst_type(struct dwc3 *dwc) · line 1044
Quoted 10 lines
drivers/usb/dwc3/core.c +10
-0+ +if (!dwc->susp_clk) +return ; + +/* +* The power down scale field specifies how many suspend_clk +* periods fit into a 16KHz clock period. When performing +* the division, round up the remainder. +*/ + scale =DIV_ROUND_UP (clk_get_rate (dwc->susp_clk),16384 );16kHz == 16000Hz right?
Quoted 25 lines
drivers/usb/dwc3/core.c +9
-0+ reg =dwc3_readl (dwc->regs,DWC3_GCTL ); + reg &= ~(DWC3_GCTL_PWRDNSCALE_MASK ); + reg |=DWC3_GCTL_PWRDNSCALE (scale); +dwc3_writel (dwc->regs,DWC3_GCTL , reg); +} +/** * dwc3_core_init - Low-level initialization of DWC3 Core * @dwc: Pointer to our controller context structure @@ -1105,6 +1124,9 @@ static int dwc3_core_init(struct dwc3 *dwc)if (ret) goto err1; +/* Set power down scale of suspend_clk */ +dwc3_set_power_down_clk_scale (dwc); +/* Adjust Frame Length */ dwc3_frame_length_adjustment (dwc);drivers/usb/dwc3/core.h +0
-0@@ -231,6 +231,7 @@Quoted 7 lines
drivers/usb/dwc3/core.h line 237
Quoted 6 lines
drivers/usb/dwc3/core.h +1
-0/* Global Configuration Register */ #define DWC3_GCTL_PWRDNSCALE (n) ((n) << 19) +#define DWC3_GCTL_PWRDNSCALE_MASK GENMASK(31, 19)#define DWC3_GCTL_U2RSTECN BIT(16)#define DWC3_GCTL_RAMCLKSEL (x) (((x) & DWC3_GCTL_CLK_MASK) << 6)#define DWC3_GCTL_CLK_BUS (0)BR,
Thinh
Thinh Nguyen
maintainerQuoted 26 lines · Jun Li (OSS)
Quoted 26 lines
-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Saturday, May 28, 2022 9:46 AM
To: Jun Li <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; J.D. Yue <[email protected]>
Subject: Re: [PATCH] usb: dwc3: add power down scale settingQuoted 16 lines · Thinh Nguyen
Quoted 15 lines · Li Jun
Some SoC(e.g NXP imx8MQ) may have a wrong default power down scale setting so need init it to be the correct value, the power down scale setting description in DWC3 databook:
Power Down Scale (PwrDnScale)
The USB3suspend_clkinput replacespipe3_rx_pclkas a clock source to a small part of the USB3 core that operates when the SS PHY is in its lowest power (P3) state, and therefore does not provide a clock. The Power Down Scale field specifies how manysuspend_clkperiods fit into a 16 kHz clock period. When performing the division, round up the remainder.
For example, when using an 8-bit/16-bit/32-bit PHY and 25-MHz Suspend clock,
Power Down Scale = 25000 kHz/16 kHz = 13'd1563 (rounder up)
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
So use the suspend clock rate to calculate it.
Also, shouldn't the value selected be the
max_rateof the suspend clock and not just the value fromclk_get_rate()?In my case, the
suspend_clkis fixed, seems max rate is only Used by clock provider and there is no API to getmax_ratefor clock users.
Seems like only the user/designer of the device knows the max rate for the suspend_clk if the clock frequency varies. We may not want to inadvertently overwrite the correct/tested default value for all devices. Maybe we also need a new device property to inform the controller of the power down scale value and give the user an option to override the calculated value here.
Thanks,
Thinh
Hi,
Quoted 46 lines
-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Wednesday, June 1, 2022 12:48 AM
To: Jun Li (OSS) <[email protected]>; Thinh Nguyen <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; J.D. Yue <[email protected]>
Subject: Re: [PATCH] usb: dwc3: add power down scale settingQuoted 27 lines · Jun Li (OSS)
Quoted 27 lines
-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Saturday, May 28, 2022 9:46 AM
To: Jun Li <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; J.D. Yue <[email protected]>
Subject: Re: [PATCH] usb: dwc3: add power down scale settingQuoted 16 lines · Thinh Nguyen
Quoted 15 lines · Li Jun
Some SoC(e.g NXP imx8MQ) may have a wrong default power down scale setting so need init it to be the correct value, the power down scale setting description in DWC3 databook:
Power Down Scale (PwrDnScale)
The USB3suspend_clkinput replacespipe3_rx_pclkas a clock source to a small part of the USB3 core that operates when the SS PHY is in its lowest power (P3) state, and therefore does not provide a clock. The Power Down Scale field specifies how manysuspend_clkperiods fit into a 16 kHz clock period. When performing the division, round up the remainder.
For example, when using an 8-bit/16-bit/32-bit PHY and 25-MHz Suspend clock, Power Down Scale = 25000 kHz/16 kHz = 13'd1563 (rounder up)Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
So use the suspend clock rate to calculate it.
Also, shouldn't the value selected be the
max_rateof the suspend clock and not just the value fromclk_get_rate()?In my case, the
suspend_clkis fixed, seems max rate is only Used by clock provider and there is no API to getmax_ratefor clock users.
Quoted 6 lines
Seems like only the user/designer of the device knows the max rate for the
suspend_clkif the clock frequency varies. We may not want to inadvertently overwrite the correct/tested default value for all devices. Maybe we also need a new device property to inform the controller of the power down scale value and give the user an option to override the calculated value here.
Understood, considering this is a rare case(wrong default value), and DT maintainer Rob does not like continue expand dwc3 huge property list for this kind of soc level thing, instead, propose implies by compatible, do you think is it acceptable to use compatible check like below for this?
if (of_device_is_compatible(node, "fsl,imx8mq-dwc3"))
thanks
Li Jun
Quoted 3 lines
Thanks,
Thinh
Thinh Nguyen
maintainerQuoted 55 lines · Jun Li (OSS)
Hi,
Quoted 46 lines
-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Wednesday, June 1, 2022 12:48 AM
To: Jun Li (OSS) <[email protected]>; Thinh Nguyen <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; J.D. Yue <[email protected]>
Subject: Re: [PATCH] usb: dwc3: add power down scale settingQuoted 27 lines · Jun Li (OSS)
Quoted 27 lines
-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Saturday, May 28, 2022 9:46 AM
To: Jun Li <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; J.D. Yue <[email protected]>
Subject: Re: [PATCH] usb: dwc3: add power down scale settingQuoted 16 lines · Thinh Nguyen
Quoted 15 lines · Li Jun
Some SoC(e.g NXP imx8MQ) may have a wrong default power down scale setting so need init it to be the correct value, the power down scale setting description in DWC3 databook:
Power Down Scale (PwrDnScale)
The USB3suspend_clkinput replacespipe3_rx_pclkas a clock source to a small part of the USB3 core that operates when the SS PHY is in its lowest power (P3) state, and therefore does not provide a clock. The Power Down Scale field specifies how manysuspend_clkperiods fit into a 16 kHz clock period. When performing the division, round up the remainder.
For example, when using an 8-bit/16-bit/32-bit PHY and 25-MHz Suspend clock, Power Down Scale = 25000 kHz/16 kHz = 13'd1563 (rounder up)Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
So use the suspend clock rate to calculate it.
Also, shouldn't the value selected be the
max_rateof the suspend clock and not just the value fromclk_get_rate()?In my case, the
suspend_clkis fixed, seems max rate is only Used by clock provider and there is no API to getmax_ratefor clock users.Quoted 6 lines
Seems like only the user/designer of the device knows the max rate for the
suspend_clkif the clock frequency varies. We may not want to inadvertently overwrite the correct/tested default value for all devices. Maybe we also need a new device property to inform the controller of the power down scale value and give the user an option to override the calculated value here.
Quoted 2 lines
Understood, considering this is a rare case(wrong default value), and DT maintainer Rob does not like continue expand dwc3 huge property list
Last I check, Rob does not like expanding quirks in dwc3 only (but I could be wrong here). I don't think this is a quirk as nothing is really broken. It's just something the user needs to inform the controller.
Quoted 5 lines
for this kind of soc level thing, instead, propose implies by compatible, do you think is it acceptable to use compatible check like below for this?
if (
of_device_is_compatible(node, "fsl,imx8mq-dwc3"))
I don't think we should do that. This is a common calculation for dwc3x controller and not unique to just your platform.
How about this: check the default setting to see if it makes sense before overwriting it. That is, only overwrite it if the default value of GCTL.PWRDNSCALE is
* Less than the calculated value from clk_get_rate()
* Ridiculously high that's (maybe 3x) more than the calculated value
Let me know what you think.
Thanks,
Thinh
Quoted 86 lines
-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Thursday, June 2, 2022 2:12 AM
To: Jun Li (OSS) <[email protected]>; Thinh Nguyen <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; J.D. Yue <[email protected]>
Subject: Re: [PATCH] usb: dwc3: add power down scale settingQuoted 32 lines · Jun Li (OSS)
Hi,
Quoted 30 lines
-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Wednesday, June 1, 2022 12:48 AM
To: Jun Li (OSS) <[email protected]>; Thinh Nguyen <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; J.D. Yue <[email protected]>
Subject: Re: [PATCH] usb: dwc3: add power down scale settingQuoted 20 lines · Jun Li (OSS)
Quoted 20 lines
-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Saturday, May 28, 2022 9:46 AM
To: Jun Li <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; J.D. Yue <[email protected]>
Subject: Re: [PATCH] usb: dwc3: add power down scale settingQuoted 9 lines · Thinh Nguyen
Quoted 8 lines · Li Jun
Some SoC(e.g NXP imx8MQ) may have a wrong default power down scale setting so need init it to be the correct value, the power down scale setting description in DWC3 databook:
Power Down Scale (PwrDnScale)
The USB3suspend_clkinput replacespipe3_rx_pclkas a clock source to a small part of the USB3 core that operates when the SS PHY is in its lowest power (P3) state, and therefore does not providea clock.
Quoted 23 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
The Power Down Scale field specifies how many
suspend_clkperiods fit into a 16 kHz clock period. When performing the division, round up the remainder.
For example, when using an 8-bit/16-bit/32-bit PHY and 25-MHz Suspend clock, Power Down Scale = 25000 kHz/16 kHz = 13'd1563 (rounder up)Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
So use the suspend clock rate to calculate it.
Also, shouldn't the value selected be the
max_rateof the suspend clock and not just the value fromclk_get_rate()?In my case, the
suspend_clkis fixed, seems max rate is only Used by clock provider and there is no API to getmax_ratefor clock users.Quoted 6 lines
Seems like only the user/designer of the device knows the max rate for the
suspend_clkif the clock frequency varies. We may not want to inadvertently overwrite the correct/tested default value for all devices. Maybe we also need a new device property to inform the controller of the power down scale value and give the user an option to override the calculated value here.Quoted 3 lines
Understood, considering this is a rare case(wrong default value), and DT maintainer Rob does not like continue expand dwc3 huge property list
Last I check, Rob does not like expanding quirks in dwc3 only (but I could be wrong here). I don't think this is a quirk as nothing is really broken. It's just something the user needs to inform the controller.
Quoted 2 lines
for this kind of soc level thing, instead, propose implies by compatible, do you think is it acceptable to use compatible check like
below for this?
Quoted 3 lines
if (
of_device_is_compatible(node, "fsl,imx8mq-dwc3"))I don't think we should do that. This is a common calculation for dwc3x controller and not unique to just your platform.
Quoted 8 lines
How about this: check the default setting to see if it makes sense before overwriting it. That is, only overwrite it if the default value of GCTL.PWRDNSCALE is
* Less than the calculated value from
clk_get_rate()
* Ridiculously high that's (maybe 3x) more than the calculated valueLet me know what you think.
This makes sense to me, I will send out v2.
Thanks
Li Jun
Quoted 3 lines
Thanks,
Thinh
Quoted 43 lines
-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Saturday, May 28, 2022 9:06 AM
To: Jun Li <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; Thinh Nguyen <[email protected]>; J.D. Yue <[email protected]>
Subject: Re: [PATCH] usb: dwc3: add power down scale settingdrivers/usb/dwc3/core.c static void dwc3_set_incr_burst_type(struct dwc3
Quoted 28 lines · Li Jun
Some SoC(e.g NXP imx8MQ) may have a wrong default power down scale setting so need init it to be the correct value, the power down scale setting description in DWC3 databook:
Power Down Scale (PwrDnScale)
The USB3suspend_clkinput replacespipe3_rx_pclkas a clock source to a small part of the USB3 core that operates when the SS PHY is in its lowest power (P3) state, and therefore does not provide a clock. The Power Down Scale field specifies how manysuspend_clkperiods fit into a 16 kHz clock period. When performing the division, round up the remainder.
For example, when using an 8-bit/16-bit/32-bit PHY and 25-MHz Suspend clock,
Power Down Scale = 25000 kHz/16 kHz = 13'd1563 (rounder up)So use the suspend clock rate to calculate it.
Signed-off-by Li Jun <[email protected]>--- drivers/usb/dwc3/core.c | 22 ++++++++++++++++++++++ drivers/usb/dwc3/core.h | 1 + 2 files changed, 23 insertions(+)drivers/usb/dwc3/core.c +0
-0@@ -1029,6 +1029,25 @@ static void dwc3_set_incr_burst_type(struct dwc3*dwc)
Quoted 3 lines
drivers/usb/dwc3/core.c +0
-0dwc3_writel (dwc->regs,DWC3_GSBUSCFG0 , cfg); }
Quoted 6 lines
drivers/usb/dwc3/core.c static void dwc3_set_incr_burst_type(struct dwc3 *dwc) · line 1034
Quoted 3 lines
drivers/usb/dwc3/core.c +3
-0+static void dwc3_set_power_down_clk_scale (struct dwc3 *dwc) +{ +u32 reg, scale;Can we declare these variables in separate lines? Preferably reverse Christmas tree style.
Okay, will update in v2.
Quoted 13 lines
drivers/usb/dwc3/core.c static void dwc3_set_incr_burst_type(struct dwc3 *dwc) · line 1044
Quoted 11 lines
drivers/usb/dwc3/core.c +10
-0+ +if (!dwc->susp_clk) +return ; + +/* +* The power down scale field specifies how many suspend_clk +* periods fit into a 16KHz clock period. When performing +* the division, round up the remainder. +*/ + scale =DIV_ROUND_UP (clk_get_rate (dwc->susp_clk),16384 );16kHz == 16000Hz right?
yes, I misunderstood it, will update in v2.
Thanks
Li Jun
Quoted 35 lines
Quoted 25 lines
drivers/usb/dwc3/core.c +9
-0+ reg =dwc3_readl (dwc->regs,DWC3_GCTL ); + reg &= ~(DWC3_GCTL_PWRDNSCALE_MASK ); + reg |=DWC3_GCTL_PWRDNSCALE (scale); +dwc3_writel (dwc->regs,DWC3_GCTL , reg); +} +/** * dwc3_core_init - Low-level initialization of DWC3 Core * @dwc: Pointer to our controller context structure @@ -1105,6 +1124,9 @@ static int dwc3_core_init(struct dwc3 *dwc)if (ret) goto err1; +/* Set power down scale of suspend_clk */ +dwc3_set_power_down_clk_scale (dwc); +/* Adjust Frame Length */ dwc3_frame_length_adjustment (dwc);drivers/usb/dwc3/core.h +0
-0drivers/usb/dwc3/core.h line 237
Quoted 7 lines
drivers/usb/dwc3/core.h +1
-0@@ -231,6 +231,7 @@/* Global Configuration Register */ #define DWC3_GCTL_PWRDNSCALE (n) ((n) << 19) +#define DWC3_GCTL_PWRDNSCALE_MASK GENMASK(31, 19)#define DWC3_GCTL_U2RSTECN BIT(16)#define DWC3_GCTL_RAMCLKSEL (x) (((x) & DWC3_GCTL_CLK_MASK) << 6)#define DWC3_GCTL_CLK_BUS (0)Thanks,
Thinh