phy: add support for STM32 usb phy controller
Subsystems (2)
PATCH RESEND 1/1 phy: add support for STM32 usb phy controller
From: Christophe Kerello <[email protected]>
This patch adds phy tranceiver driver for STM32 USB PHY Controller (usbphyc) that provides dual port High-Speed phy for OTG (single port) and EHCI/OHCI host controller (two ports).
One port of the phy is shared between the two USB controllers through a UTMI+ switch.
---
drivers/phy/Kconfig | 13 ++ drivers/phy/Makefile | 1 + drivers/phy/phy-stm32-usbphyc.c | 403 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 417 insertions(+) create mode 100644 drivers/phy/phy-stm32-usbphyc.c
drivers/phy/Kconfig +13 -0
@@ -110,4 +110,17 @@ config STI_USB_PHY used by USB2 and USB3 Host controllers available on STiH407 SoC families. +config PHY_STM32_USBPHYC + tristate "STMicroelectronics STM32 SoC USB HS PHY driver" + depends on PHY && ARCH_STM32MP + help + Enable this to support the High-Speed USB transceiver that is part of + STMicroelectronics STM32 SoCs. + + This driver controls the entire USB PHY block: the USB PHY controller + (USBPHYC) and the two 8-bit wide UTMI+ interface. First interface is + used by an HS USB Host controller, and the second one is shared + between an HS USB OTG controller and an HS USB Host controller, + selected by an USB switch. + endmenu
drivers/phy/Makefile +1 -0
@@ -14,3 +14,4 @@ obj-$(CONFIG_BCM6368_USBH_PHY) += bcm6368-usbh-phy.o obj-$(CONFIG_PHY_SANDBOX) += sandbox-phy.o obj-$(CONFIG_$(SPL_)PIPE3_PHY) += ti-pipe3-phy.o obj-$(CONFIG_STI_USB_PHY) += sti_usb_phy.o +obj-$(CONFIG_PHY_STM32_USBPHYC) += phy-stm32-usbphyc.o
drivers/phy/phy-stm32-usbphyc.c new file +403 -0
403 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH RESEND 1/1 phy: add support for STM32 usb phy controller
Quoted 11 lines · Patrice Chotard
From: Christophe Kerello <[email protected]>
This patch adds phy tranceiver driver for STM32 USB PHY Controller (usbphyc) that provides dual port High-Speed phy for OTG (single port) and EHCI/OHCI host controller (two ports).
One port of the phy is shared between the two USB controllers through a UTMI+ switch.Signed-off-by Christophe Kerello <[email protected]>Signed-off-by Patrice Chotard <[email protected]>
[...]
Quoted 6 lines
drivers/phy/phy-stm32-usbphyc.c new file +6
-0+struct pll_params { +u8 ndiv; +u16 frac; +}; + +struct stm32_usbphyc {
drivers/phy/phy-stm32-usbphyc.c line 62
Quoted 10 lines
drivers/phy/phy-stm32-usbphyc.c new file +10
-0+fdt_addr_t base; +struct clk clk; +struct stm32_usbphyc_phy { +struct udevice *vdd; +struct udevice *vdda1v1; +struct udevice *vdda1v8; +int index; +bool init; +bool powered; + } phys[MAX_PHYS ];
Shouldn't there be one driver instance per PHY ?
Quoted 43 lines
drivers/phy/phy-stm32-usbphyc.c new file +43
-0+}; + +void stm32_usbphyc_get_pll_params (u32 clk_rate,struct pll_params *pll_params) +{ +unsigned long long fvco, ndiv, frac; + +/* +* | FVCO = INFF*2*(NDIV + FRACT/2^16 ) when DITHER_DISABLE[1] = 1 +* | FVCO = 2880MHz +* | NDIV = integer part of input bits to set the LDF +* | FRACT = fractional part of input bits to set the LDF +* => PLLNDIV = integer part of (FVCO / (INFF*2)) +* => PLLFRACIN = fractional part of(FVCO / INFF*2) * 2^16 +* <=> PLLFRACIN = ((FVCO / (INFF*2)) - PLLNDIV) * 2^16 +*/ + fvco = (unsigned long long )PLL_FVCO *1000000 ;/* In Hz */ + + ndiv = fvco; +do_div (ndiv, (clk_rate *2 )); + pll_params->ndiv = (u8 )ndiv; + + frac = fvco * (1 <<16 ); +do_div (frac, (clk_rate *2 )); + frac = frac - (ndiv * (1 <<16 )); + pll_params->frac = (u16 )frac; +} + +static int stm32_usbphyc_pll_init (struct stm32_usbphyc *usbphyc) +{ +struct pll_params pll_params; +u32 clk_rate =clk_get_rate (&usbphyc->clk); +u32 usbphyc_pll; + +if ((clk_rate <PLL_INFF_MIN_RATE ) || (clk_rate >PLL_INFF_MAX_RATE )) { +pr_debug ("%s: input clk freq (%dHz) out of range\n" , + __func__, clk_rate); +return -EINVAL ; + } + +stm32_usbphyc_get_pll_params (clk_rate, &pll_params); + + usbphyc_pll =PLLDITHEN1 |PLLDITHEN0 |PLLSTRBYP ; + usbphyc_pll |= ((pll_params.ndiv <<PLLNDIV_SHIFT ) &PLLNDIV );
drivers/phy/phy-stm32-usbphyc.c line 115
Quoted 10 lines
drivers/phy/phy-stm32-usbphyc.c new file +10
-0+ +if (pll_params.frac) { + usbphyc_pll |=PLLFRACCTL ; + usbphyc_pll |= ((pll_params.frac <<PLLFRACIN_SHIFT ) + &PLLFRACIN ); + } + +writel (usbphyc_pll, usbphyc->base +STM32_USBPHYC_PLL ); + + pr_debug("%s: input clk freq=%dHz, ndiv=%d, frac=%d\n", __func__,
dev_dbg
Quoted 4 lines
drivers/phy/phy-stm32-usbphyc.c new file +4
-0+ clk_rate, pll_params.ndiv, pll_params.frac); + +return 0 ; +}
[...]
Signature · 2 lines
Best regards, Marek Vasut
PATCH RESEND 1/1 phy: add support for STM32 usb phy controller
Hi Marek
Quoted 25 lines · Marek Vasut
Quoted 11 lines · Patrice Chotard
From: Christophe Kerello <[email protected]>
This patch adds phy tranceiver driver for STM32 USB PHY Controller (usbphyc) that provides dual port High-Speed phy for OTG (single port) and EHCI/OHCI host controller (two ports).
One port of the phy is shared between the two USB controllers through a UTMI+ switch.Signed-off-by Christophe Kerello <[email protected]>Signed-off-by Patrice Chotard <[email protected]>[...]
Quoted 10 lines
drivers/phy/phy-stm32-usbphyc.c new file +10
-0+struct pll_params { +u8 ndiv; +u16 frac; +}; + +struct stm32_usbphyc { +fdt_addr_t base; +struct clk clk; +struct stm32_usbphyc_phy { +struct udevice *vdd;
Quoted 8 lines
drivers/phy/phy-stm32-usbphyc.c line 62
Quoted 6 lines
drivers/phy/phy-stm32-usbphyc.c new file +6
-0+struct udevice *vdda1v1; +struct udevice *vdda1v8; +int index; +bool init; +bool powered; + } phys[MAX_PHYS ];Shouldn't there be one driver instance per PHY ?
This driver manages a PHY provider + PHY child sub nodes as requested by Kernel maintainer.
more details here : https://lkml.org/lkml/2018/3/2/670
If you want i can add more details in v2 by including the DT bindings documentation ?
Quoted 48 lines
Quoted 48 lines
drivers/phy/phy-stm32-usbphyc.c new file +47
-0+}; + +void stm32_usbphyc_get_pll_params (u32 clk_rate,struct pll_params *pll_params) +{ +unsigned long long fvco, ndiv, frac; + +/* +* | FVCO = INFF*2*(NDIV + FRACT/2^16 ) when DITHER_DISABLE[1] = 1 +* | FVCO = 2880MHz +* | NDIV = integer part of input bits to set the LDF +* | FRACT = fractional part of input bits to set the LDF +* => PLLNDIV = integer part of (FVCO / (INFF*2)) +* => PLLFRACIN = fractional part of(FVCO / INFF*2) * 2^16 +* <=> PLLFRACIN = ((FVCO / (INFF*2)) - PLLNDIV) * 2^16 +*/ + fvco = (unsigned long long )PLL_FVCO *1000000 ;/* In Hz */ + + ndiv = fvco; +do_div (ndiv, (clk_rate *2 )); + pll_params->ndiv = (u8 )ndiv; + + frac = fvco * (1 <<16 ); +do_div (frac, (clk_rate *2 )); + frac = frac - (ndiv * (1 <<16 )); + pll_params->frac = (u16 )frac; +} + +static int stm32_usbphyc_pll_init (struct stm32_usbphyc *usbphyc) +{ +struct pll_params pll_params; +u32 clk_rate =clk_get_rate (&usbphyc->clk); +u32 usbphyc_pll; + +if ((clk_rate <PLL_INFF_MIN_RATE ) || (clk_rate >PLL_INFF_MAX_RATE )) { +pr_debug ("%s: input clk freq (%dHz) out of range\n" , + __func__, clk_rate); +return -EINVAL ; + } + +stm32_usbphyc_get_pll_params (clk_rate, &pll_params); + + usbphyc_pll =PLLDITHEN1 |PLLDITHEN0 |PLLSTRBYP ; + usbphyc_pll |= ((pll_params.ndiv <<PLLNDIV_SHIFT ) &PLLNDIV ); + +if (pll_params.frac) { + usbphyc_pll |=PLLFRACCTL ; + usbphyc_pll |= ((pll_params.frac << PLLFRACIN_SHIFT)
Quoted 8 lines
drivers/phy/phy-stm32-usbphyc.c line 115
Quoted 6 lines
drivers/phy/phy-stm32-usbphyc.c new file +6
-0+ & PLLFRACIN); + } + +writel (usbphyc_pll, usbphyc->base +STM32_USBPHYC_PLL ); + + pr_debug("%s: input clk freq=%dHz, ndiv=%d, frac=%d\n", __func__,
dev_dbg
There's no access to udevice struct here that's why pr_debug() is used.
Thanks
Quoted 7 lines
Quoted 5 lines
drivers/phy/phy-stm32-usbphyc.c new file +4
-0+ clk_rate, pll_params.ndiv, pll_params.frac); + +return 0 ; +}[...]
PATCH RESEND 1/1 phy: add support for STM32 usb phy controller
Quoted 37 lines · Patrice CHOTARD
Hi Marek
Quoted 25 lines · Marek Vasut
Quoted 11 lines · Patrice Chotard
From: Christophe Kerello <[email protected]>
This patch adds phy tranceiver driver for STM32 USB PHY Controller (usbphyc) that provides dual port High-Speed phy for OTG (single port) and EHCI/OHCI host controller (two ports).
One port of the phy is shared between the two USB controllers through a UTMI+ switch.Signed-off-by Christophe Kerello <[email protected]>Signed-off-by Patrice Chotard <[email protected]>[...]
Quoted 10 lines
drivers/phy/phy-stm32-usbphyc.c new file +10
-0+struct pll_params { +u8 ndiv; +u16 frac; +}; + +struct stm32_usbphyc { +fdt_addr_t base; +struct clk clk; +struct stm32_usbphyc_phy { +struct udevice *vdd;Quoted 8 lines
drivers/phy/phy-stm32-usbphyc.c line 62
Quoted 6 lines
drivers/phy/phy-stm32-usbphyc.c new file +6
-0+struct udevice *vdda1v1; +struct udevice *vdda1v8; +int index; +bool init; +bool powered; + } phys[MAX_PHYS ];Shouldn't there be one driver instance per PHY ?
Quoted 4 lines
This driver manages a PHY provider + PHY child sub nodes as requested by Kernel maintainer.
more details here : https://lkml.org/lkml/2018/3/2/670
What am I looking for ?
Quoted 2 lines
If you want i can add more details in v2 by including the DT bindings documentation ?
Yes, please do, it's quite inobvious.
Quoted 67 lines
Quoted 48 lines
Quoted 48 lines
drivers/phy/phy-stm32-usbphyc.c new file +47
-0+}; + +void stm32_usbphyc_get_pll_params (u32 clk_rate,struct pll_params *pll_params) +{ +unsigned long long fvco, ndiv, frac; + +/* +* | FVCO = INFF*2*(NDIV + FRACT/2^16 ) when DITHER_DISABLE[1] = 1 +* | FVCO = 2880MHz +* | NDIV = integer part of input bits to set the LDF +* | FRACT = fractional part of input bits to set the LDF +* => PLLNDIV = integer part of (FVCO / (INFF*2)) +* => PLLFRACIN = fractional part of(FVCO / INFF*2) * 2^16 +* <=> PLLFRACIN = ((FVCO / (INFF*2)) - PLLNDIV) * 2^16 +*/ + fvco = (unsigned long long )PLL_FVCO *1000000 ;/* In Hz */ + + ndiv = fvco; +do_div (ndiv, (clk_rate *2 )); + pll_params->ndiv = (u8 )ndiv; + + frac = fvco * (1 <<16 ); +do_div (frac, (clk_rate *2 )); + frac = frac - (ndiv * (1 <<16 )); + pll_params->frac = (u16 )frac; +} + +static int stm32_usbphyc_pll_init (struct stm32_usbphyc *usbphyc) +{ +struct pll_params pll_params; +u32 clk_rate =clk_get_rate (&usbphyc->clk); +u32 usbphyc_pll; + +if ((clk_rate <PLL_INFF_MIN_RATE ) || (clk_rate >PLL_INFF_MAX_RATE )) { +pr_debug ("%s: input clk freq (%dHz) out of range\n" , + __func__, clk_rate); +return -EINVAL ; + } + +stm32_usbphyc_get_pll_params (clk_rate, &pll_params); + + usbphyc_pll =PLLDITHEN1 |PLLDITHEN0 |PLLSTRBYP ; + usbphyc_pll |= ((pll_params.ndiv <<PLLNDIV_SHIFT ) &PLLNDIV ); + +if (pll_params.frac) { + usbphyc_pll |=PLLFRACCTL ; + usbphyc_pll |= ((pll_params.frac << PLLFRACIN_SHIFT)Quoted 8 lines
drivers/phy/phy-stm32-usbphyc.c line 115
Quoted 6 lines
drivers/phy/phy-stm32-usbphyc.c new file +6
-0+ & PLLFRACIN); + } + +writel (usbphyc_pll, usbphyc->base +STM32_USBPHYC_PLL ); + + pr_debug("%s: input clk freq=%dHz, ndiv=%d, frac=%d\n", __func__,
dev_dbgThere's no access to udevice struct here that's why
pr_debug()is used.Thanks
Quoted 6 lines
Quoted 5 lines
drivers/phy/phy-stm32-usbphyc.c new file +4
-0+ clk_rate, pll_params.ndiv, pll_params.frac); + +return 0 ; +}[...]
Signature · 2 lines
Best regards, Marek Vasut