X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=drivers%2Fusb%2Fhost%2Fehci-mx5.c;h=c11279867c7ca0d2412d9cea5105763419729df3;hb=dd11fdc31fb82f63258c1970a6d8d22b8ffd3173;hp=adbed5c90ca54717baa7e42d42a41fdf3599716f;hpb=a098cf41fdb2a6607c675f7fe4f3164617c9367e;p=platform%2Fkernel%2Fu-boot.git diff --git a/drivers/usb/host/ehci-mx5.c b/drivers/usb/host/ehci-mx5.c index adbed5c..c112798 100644 --- a/drivers/usb/host/ehci-mx5.c +++ b/drivers/usb/host/ehci-mx5.c @@ -1,28 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (c) 2009 Daniel Mack * Copyright (C) 2010 Freescale Semiconductor, Inc. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. */ #include +#include #include #include #include -#include +#include +#include +#include #include #include #include -#include -#include +#include +#include #include "ehci.h" @@ -87,77 +81,6 @@ /* USB_CTRL_1 */ #define MXC_USB_CTRL_UH1_EXT_CLK_EN (1 << 25) -/* USB pin configuration */ -#define USB_PAD_CONFIG (PAD_CTL_PKE_ENABLE | PAD_CTL_SRE_FAST | \ - PAD_CTL_DRV_HIGH | PAD_CTL_100K_PU | \ - PAD_CTL_HYS_ENABLE | PAD_CTL_PUE_PULL) - -#ifdef CONFIG_MX51 -/* - * Configure the MX51 USB H1 IOMUX - */ -void setup_iomux_usb_h1(void) -{ - mxc_request_iomux(MX51_PIN_USBH1_STP, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_STP, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_USBH1_CLK, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_CLK, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_USBH1_DIR, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_DIR, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_USBH1_NXT, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_NXT, USB_PAD_CONFIG); - - mxc_request_iomux(MX51_PIN_USBH1_DATA0, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_DATA0, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_USBH1_DATA1, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_DATA1, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_USBH1_DATA2, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_DATA2, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_USBH1_DATA3, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_DATA3, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_USBH1_DATA4, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_DATA4, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_USBH1_DATA5, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_DATA5, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_USBH1_DATA6, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_DATA6, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_USBH1_DATA7, IOMUX_CONFIG_ALT0); - mxc_iomux_set_pad(MX51_PIN_USBH1_DATA7, USB_PAD_CONFIG); -} - -/* - * Configure the MX51 USB H2 IOMUX - */ -void setup_iomux_usb_h2(void) -{ - mxc_request_iomux(MX51_PIN_EIM_A24, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_A24, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_EIM_A25, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_A25, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_EIM_A26, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_A26, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_EIM_A27, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_A27, USB_PAD_CONFIG); - - mxc_request_iomux(MX51_PIN_EIM_D16, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_D16, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_EIM_D17, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_D17, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_EIM_D18, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_D18, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_EIM_D19, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_D19, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_EIM_D20, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_D20, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_EIM_D21, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_D21, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_EIM_D22, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_D22, USB_PAD_CONFIG); - mxc_request_iomux(MX51_PIN_EIM_D23, IOMUX_CONFIG_ALT2); - mxc_iomux_set_pad(MX51_PIN_EIM_D23, USB_PAD_CONFIG); -} -#endif - int mxc_set_usbcontrol(int port, unsigned int flags) { unsigned int v; @@ -299,49 +222,107 @@ void __weak board_ehci_hcd_postinit(struct usb_ehci *ehci, int port) { } -int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor) +__weak void mx5_ehci_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg, + uint32_t *reg) { + mdelay(50); +} + +struct ehci_mx5_priv_data { + struct ehci_ctrl ctrl; struct usb_ehci *ehci; -#ifdef CONFIG_MX53 - struct clkctl *sc_regs = (struct clkctl *)CCM_BASE_ADDR; - u32 reg; + struct udevice *vbus_supply; + enum usb_init_type init_type; + int portnr; +}; - reg = __raw_readl(&sc_regs->cscmr1) & ~(1 << 26); - /* derive USB PHY clock multiplexer from PLL3 */ - reg |= 1 << 26; - __raw_writel(reg, &sc_regs->cscmr1); -#endif +static const struct ehci_ops mx5_ehci_ops = { + .powerup_fixup = mx5_ehci_powerup_fixup, +}; + +static int ehci_usb_of_to_plat(struct udevice *dev) +{ + struct usb_plat *plat = dev_get_plat(dev); + const char *mode; + + mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "dr_mode", NULL); + if (mode) { + if (strcmp(mode, "peripheral") == 0) + plat->init_type = USB_INIT_DEVICE; + else if (strcmp(mode, "host") == 0) + plat->init_type = USB_INIT_HOST; + else + return -EINVAL; + } + + return 0; +} + +static int ehci_usb_probe(struct udevice *dev) +{ + struct usb_plat *plat = dev_get_plat(dev); + struct usb_ehci *ehci = dev_read_addr_ptr(dev); + struct ehci_mx5_priv_data *priv = dev_get_priv(dev); + enum usb_init_type type = plat->init_type; + struct ehci_hccr *hccr; + struct ehci_hcor *hcor; + int ret; set_usboh3_clk(); - enable_usboh3_clk(1); + enable_usboh3_clk(true); set_usb_phy_clk(); - enable_usb_phy1_clk(1); - enable_usb_phy2_clk(1); + enable_usb_phy1_clk(true); + enable_usb_phy2_clk(true); mdelay(1); - /* Do board specific initialization */ - board_ehci_hcd_init(CONFIG_MXC_USB_PORT); + priv->ehci = ehci; + priv->portnr = dev_seq(dev); + priv->init_type = type; + + ret = device_get_supply_regulator(dev, "vbus-supply", + &priv->vbus_supply); + if (ret) + debug("%s: No vbus supply\n", dev->name); + + if (!ret && priv->vbus_supply) { + ret = regulator_set_enable(priv->vbus_supply, + (type == USB_INIT_DEVICE) ? + false : true); + if (ret) { + puts("Error enabling VBUS supply\n"); + return ret; + } + } - ehci = (struct usb_ehci *)(OTG_BASE_ADDR + - (0x200 * CONFIG_MXC_USB_PORT)); - *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); - *hcor = (struct ehci_hcor *)((uint32_t)*hccr + - HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); + hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); + hcor = (struct ehci_hcor *)((uint32_t)hccr + + HC_LENGTH(ehci_readl(&(hccr)->cr_capbase))); setbits_le32(&ehci->usbmode, CM_HOST); - __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc); + __raw_writel(CFG_MXC_USB_PORTSC, &ehci->portsc); setbits_le32(&ehci->portsc, USB_EN); - mxc_set_usbcontrol(CONFIG_MXC_USB_PORT, CONFIG_MXC_USB_FLAGS); + mxc_set_usbcontrol(priv->portnr, CFG_MXC_USB_FLAGS); mdelay(10); - /* Do board specific post-initialization */ - board_ehci_hcd_postinit(ehci, CONFIG_MXC_USB_PORT); - - return 0; + return ehci_register(dev, hccr, hcor, &mx5_ehci_ops, 0, + priv->init_type); } -int ehci_hcd_stop(int index) -{ - return 0; -} +static const struct udevice_id mx5_usb_ids[] = { + { .compatible = "fsl,imx53-usb" }, + { } +}; + +U_BOOT_DRIVER(usb_mx5) = { + .name = "ehci_mx5", + .id = UCLASS_USB, + .of_match = mx5_usb_ids, + .of_to_plat = ehci_usb_of_to_plat, + .probe = ehci_usb_probe, + .remove = ehci_deregister, + .ops = &ehci_usb_ops, + .plat_auto = sizeof(struct usb_plat), + .priv_auto = sizeof(struct ehci_mx5_priv_data), + .flags = DM_FLAG_ALLOC_PRIV_DMA, +};