Message ID | 1352446306-19945-3-git-send-email-horms@verge.net.au (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hello. On 11/09/2012 10:31 AM, Simon Horman wrote: > From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> > > This patch supports CN21/CN22 USB 2.0 (port 0/1/2), > and enable USB momery on defconfig Sorry for late comment but I'm studying this code just now (in order to add R-Car M1A USB support). > Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> > Signed-off-by: Simon Horman <horms@verge.net.au> > --- > arch/arm/configs/marzen_defconfig | 6 ++ > arch/arm/mach-shmobile/Kconfig | 1 + > arch/arm/mach-shmobile/board-marzen.c | 108 ++++++++++++++++++++++++++++++++- > 3 files changed, 114 insertions(+), 1 deletion(-) > > diff --git a/arch/arm/mach-shmobile/board-marzen.c b/arch/arm/mach-shmobile/board-marzen.c > index 74c7f0b..707b3bd 100644 > --- a/arch/arm/mach-shmobile/board-marzen.c > +++ b/arch/arm/mach-shmobile/board-marzen.c > @@ -34,6 +34,9 @@ [...] > @@ -172,6 +175,101 @@ static struct platform_device *marzen_devices[] __initdata = { > &usb_phy_device, > }; > > +/* USB */ > +static struct usb_phy *phy; > +static int usb_power_on(struct platform_device *pdev) > +{ > + if (!phy) > + return -EIO; > + > + pm_runtime_enable(&pdev->dev); > + pm_runtime_get_sync(&pdev->dev); > + > + usb_phy_init(phy); > + > + return 0; > +} > + > +static void usb_power_off(struct platform_device *pdev) > +{ > + if (!phy) > + return; > + > + usb_phy_shutdown(phy); > + > + pm_runtime_put_sync(&pdev->dev); > + pm_runtime_disable(&pdev->dev); > +} > + > +static struct usb_ehci_pdata ehcix_pdata = { > + .power_on = usb_power_on, > + .power_off = usb_power_off, > + .power_suspend = usb_power_off, > +}; > + > +static struct resource ehci0_resources[] = { > + [0] = { > + .start = 0xffe70000, > + .end = 0xffe70400 - 1, > + .flags = IORESOURCE_MEM, > + }, > + [1] = { > + .start = gic_spi(44), > + .flags = IORESOURCE_IRQ, > + }, > +}; > + > +static struct platform_device ehci0_device = { > + .name = "ehci-platform", > + .id = 0, > + .dev = { > + .dma_mask = &ehci0_device.dev.coherent_dma_mask, > + .coherent_dma_mask = 0xffffffff, > + .platform_data = &ehcix_pdata, > + }, > + .num_resources = ARRAY_SIZE(ehci0_resources), > + .resource = ehci0_resources, > +}; > + > +static struct resource ehci1_resources[] = { > + [0] = { > + .start = 0xfff70000, > + .end = 0xfff70400 - 1, > + .flags = IORESOURCE_MEM, > + }, > + [1] = { > + .start = gic_spi(45), > + .flags = IORESOURCE_IRQ, > + }, > +}; > + > +static struct platform_device ehci1_device = { > + .name = "ehci-platform", > + .id = 1, > + .dev = { > + .dma_mask = &ehci1_device.dev.coherent_dma_mask, > + .coherent_dma_mask = 0xffffffff, > + .platform_data = &ehcix_pdata, > + }, > + .num_resources = ARRAY_SIZE(ehci1_resources), > + .resource = ehci1_resources, > +}; > + > +static struct platform_device *marzen_late_devices[] __initdata = { > + &ehci0_device, > + &ehci1_device, > +}; > + > +void __init marzen_init_late(void) > +{ > + /* get usb phy */ > + phy = usb_get_phy(USB_PHY_TYPE_USB2); > + > + shmobile_init_late(); > + platform_add_devices(marzen_late_devices, > + ARRAY_SIZE(marzen_late_devices)); > +} > + > Morimoto-san, I don't understand why this SoC specific platform device ended up in the board file? Could you explain your reasons please? I think this is generally a bad practice as this approach scales badly. WVR, Sergei
Hi Sergei > > +/* USB */ > > +static struct usb_phy *phy; > > +static int usb_power_on(struct platform_device *pdev) > > +{ > > + if (!phy) > > + return -EIO; > > + > > + pm_runtime_enable(&pdev->dev); > > + pm_runtime_get_sync(&pdev->dev); > > + > > + usb_phy_init(phy); > > + > > + return 0; > > +} > > + > > +static void usb_power_off(struct platform_device *pdev) > > +{ > > + if (!phy) > > + return; > > + > > + usb_phy_shutdown(phy); > > + > > + pm_runtime_put_sync(&pdev->dev); > > + pm_runtime_disable(&pdev->dev); > > +} > > + > > +static struct usb_ehci_pdata ehcix_pdata = { > > + .power_on = usb_power_on, > > + .power_off = usb_power_off, > > + .power_suspend = usb_power_off, > > +}; (snip) > Morimoto-san, I don't understand why this SoC specific platform device > ended up in the board file? Could you explain your reasons please? > I think this is generally a bad practice as this approach scales badly. Do you mean it should exist in setup-r8a7779.c ? I forgot detail of it, but these usb is using callback function, and it is using *phy*. This phy came from marzen_init_late() with usb_get_phy(USB_PHY_TYPE_USB2); This usb_get_phy() is not needed if board doesn't have USB. You can modify it if you want Best regards --- Kuninori Morimoto
Hi Sergei > > Morimoto-san, I don't understand why this SoC specific platform device > > ended up in the board file? Could you explain your reasons please? > > I think this is generally a bad practice as this approach scales badly. > > Do you mean it should exist in setup-r8a7779.c ? > > I forgot detail of it, but these usb is using callback function, > and it is using *phy*. > This phy came from marzen_init_late() with usb_get_phy(USB_PHY_TYPE_USB2); > This usb_get_phy() is not needed if board doesn't have USB. > > You can modify it if you want And, as you pointed in USB ML, This rcar_usb_phy driver will need board specific initialization. (it is not implemented at this point...) Best regards --- Kuninori Morimoto
Hello. On 14-03-2013 4:29, Kuninori Morimoto wrote: >>> +/* USB */ >>> +static struct usb_phy *phy; >>> +static int usb_power_on(struct platform_device *pdev) >>> +{ >>> + if (!phy) >>> + return -EIO; >>> + >>> + pm_runtime_enable(&pdev->dev); >>> + pm_runtime_get_sync(&pdev->dev); >>> + >>> + usb_phy_init(phy); >>> + >>> + return 0; >>> +} >>> + >>> +static void usb_power_off(struct platform_device *pdev) >>> +{ >>> + if (!phy) >>> + return; >>> + >>> + usb_phy_shutdown(phy); >>> + >>> + pm_runtime_put_sync(&pdev->dev); >>> + pm_runtime_disable(&pdev->dev); >>> +} >>> + >>> +static struct usb_ehci_pdata ehcix_pdata = { >>> + .power_on = usb_power_on, >>> + .power_off = usb_power_off, >>> + .power_suspend = usb_power_off, >>> +}; > (snip) >> Morimoto-san, I don't understand why this SoC specific platform device >> ended up in the board file? Could you explain your reasons please? >> I think this is generally a bad practice as this approach scales badly. > Do you mean it should exist in setup-r8a7779.c ? Yes. > I forgot detail of it, but these usb is using callback function, > and it is using *phy*. But this PHY also belongs to SoC. > This phy came from marzen_init_late() with usb_get_phy(USB_PHY_TYPE_USB2); > This usb_get_phy() is not needed if board doesn't have USB. Anyway, there should be ways to separate the board specific platform code and the SoC specific one. That's what other subarches do. > You can modify it if you want Yes, I definitely would like to try. WBR, Sergei
Hi Sergei > > I forgot detail of it, but these usb is using callback function, > > and it is using *phy*. > > But this PHY also belongs to SoC. > > > This phy came from marzen_init_late() with usb_get_phy(USB_PHY_TYPE_USB2); > > This usb_get_phy() is not needed if board doesn't have USB. > > Anyway, there should be ways to separate the board specific platform code > and the SoC specific one. That's what other subarches do. > > > You can modify it if you want > > Yes, I definitely would like to try. I checked CPG :: MSTP for USB0/1/2 and USB Host/Function, and GIC number for it. It seems no conflict each other I guess EHCI/OHCI goes to setup seems no problem. But, as you pointed on USB ML, USB-PHY :: USBPCTRL0 depends on platform (Host/Function selection, and OVC pin setting) rcar_usb_phy driver belongs to platform Best regards --- Kuninori Morimoto
Hello. On 15-03-2013 4:52, Kuninori Morimoto wrote: >>> I forgot detail of it, but these usb is using callback function, >>> and it is using *phy*. >> But this PHY also belongs to SoC. >>> This phy came from marzen_init_late() with usb_get_phy(USB_PHY_TYPE_USB2); >>> This usb_get_phy() is not needed if board doesn't have USB. >> Anyway, there should be ways to separate the board specific platform code >> and the SoC specific one. That's what other subarches do. >>> You can modify it if you want >> Yes, I definitely would like to try. > I checked CPG :: MSTP for USB0/1/2 and USB Host/Function, > and GIC number for it. > It seems no conflict each other > I guess EHCI/OHCI goes to setup seems no problem. > But, as you pointed on USB ML, > USB-PHY :: USBPCTRL0 depends on platform > (Host/Function selection, and OVC pin setting) > rcar_usb_phy driver belongs to platform No, it doesn't. Only it's (future) platform data will belong to the board -- that's what they were designed for. WBR, Sergei
diff --git a/arch/arm/configs/marzen_defconfig b/arch/arm/configs/marzen_defconfig index 8a861b7..6540dfb 100644 --- a/arch/arm/configs/marzen_defconfig +++ b/arch/arm/configs/marzen_defconfig @@ -47,6 +47,8 @@ CONFIG_DEVTMPFS_MOUNT=y # CONFIG_STANDALONE is not set # CONFIG_PREVENT_FIRMWARE_BUILD is not set # CONFIG_FW_LOADER is not set +CONFIG_SCSI=y +CONFIG_BLK_DEV_SD=y CONFIG_NETDEVICES=y # CONFIG_NET_VENDOR_BROADCOM is not set # CONFIG_NET_VENDOR_FARADAY is not set @@ -82,6 +84,10 @@ CONFIG_USB=y CONFIG_USB_RCAR_PHY=y CONFIG_MMC=y CONFIG_MMC_SDHI=y +CONFIG_USB=y +CONFIG_USB_EHCI_HCD=y +CONFIG_USB_EHCI_HCD_PLATFORM=y +CONFIG_USB_STORAGE=y CONFIG_UIO=y CONFIG_UIO_PDRV_GENIRQ=y # CONFIG_IOMMU_SUPPORT is not set diff --git a/arch/arm/mach-shmobile/Kconfig b/arch/arm/mach-shmobile/Kconfig index 4eddca1..4eae11c 100644 --- a/arch/arm/mach-shmobile/Kconfig +++ b/arch/arm/mach-shmobile/Kconfig @@ -29,6 +29,7 @@ config ARCH_R8A7779 select ARM_GIC select CPU_V7 select SH_CLK_CPG + select USB_ARCH_HAS_EHCI config ARCH_EMEV2 bool "Emma Mobile EV2" diff --git a/arch/arm/mach-shmobile/board-marzen.c b/arch/arm/mach-shmobile/board-marzen.c index 74c7f0b..707b3bd 100644 --- a/arch/arm/mach-shmobile/board-marzen.c +++ b/arch/arm/mach-shmobile/board-marzen.c @@ -34,6 +34,9 @@ #include <linux/spi/sh_hspi.h> #include <linux/mmc/sh_mobile_sdhi.h> #include <linux/mfd/tmio.h> +#include <linux/usb/otg.h> +#include <linux/usb/ehci_pdriver.h> +#include <linux/pm_runtime.h> #include <mach/hardware.h> #include <mach/r8a7779.h> #include <mach/common.h> @@ -172,6 +175,101 @@ static struct platform_device *marzen_devices[] __initdata = { &usb_phy_device, }; +/* USB */ +static struct usb_phy *phy; +static int usb_power_on(struct platform_device *pdev) +{ + if (!phy) + return -EIO; + + pm_runtime_enable(&pdev->dev); + pm_runtime_get_sync(&pdev->dev); + + usb_phy_init(phy); + + return 0; +} + +static void usb_power_off(struct platform_device *pdev) +{ + if (!phy) + return; + + usb_phy_shutdown(phy); + + pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); +} + +static struct usb_ehci_pdata ehcix_pdata = { + .power_on = usb_power_on, + .power_off = usb_power_off, + .power_suspend = usb_power_off, +}; + +static struct resource ehci0_resources[] = { + [0] = { + .start = 0xffe70000, + .end = 0xffe70400 - 1, + .flags = IORESOURCE_MEM, + }, + [1] = { + .start = gic_spi(44), + .flags = IORESOURCE_IRQ, + }, +}; + +static struct platform_device ehci0_device = { + .name = "ehci-platform", + .id = 0, + .dev = { + .dma_mask = &ehci0_device.dev.coherent_dma_mask, + .coherent_dma_mask = 0xffffffff, + .platform_data = &ehcix_pdata, + }, + .num_resources = ARRAY_SIZE(ehci0_resources), + .resource = ehci0_resources, +}; + +static struct resource ehci1_resources[] = { + [0] = { + .start = 0xfff70000, + .end = 0xfff70400 - 1, + .flags = IORESOURCE_MEM, + }, + [1] = { + .start = gic_spi(45), + .flags = IORESOURCE_IRQ, + }, +}; + +static struct platform_device ehci1_device = { + .name = "ehci-platform", + .id = 1, + .dev = { + .dma_mask = &ehci1_device.dev.coherent_dma_mask, + .coherent_dma_mask = 0xffffffff, + .platform_data = &ehcix_pdata, + }, + .num_resources = ARRAY_SIZE(ehci1_resources), + .resource = ehci1_resources, +}; + +static struct platform_device *marzen_late_devices[] __initdata = { + &ehci0_device, + &ehci1_device, +}; + +void __init marzen_init_late(void) +{ + /* get usb phy */ + phy = usb_get_phy(USB_PHY_TYPE_USB2); + + shmobile_init_late(); + platform_add_devices(marzen_late_devices, + ARRAY_SIZE(marzen_late_devices)); +} + static void __init marzen_init(void) { regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers, @@ -209,6 +307,14 @@ static void __init marzen_init(void) gpio_request(GPIO_FN_HSPI_TX0, NULL); gpio_request(GPIO_FN_HSPI_RX0, NULL); + /* USB (CN21) */ + gpio_request(GPIO_FN_USB_OVC0, NULL); + gpio_request(GPIO_FN_USB_OVC1, NULL); + gpio_request(GPIO_FN_USB_OVC2, NULL); + + /* USB (CN22) */ + gpio_request(GPIO_FN_USB_PENC2, NULL); + r8a7779_add_standard_devices(); platform_add_devices(marzen_devices, ARRAY_SIZE(marzen_devices)); } @@ -221,6 +327,6 @@ MACHINE_START(MARZEN, "marzen") .init_irq = r8a7779_init_irq, .handle_irq = gic_handle_irq, .init_machine = marzen_init, - .init_late = shmobile_init_late, + .init_late = marzen_init_late, .timer = &shmobile_timer, MACHINE_END