2012-11-22 14:35:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>
|
|
|
|
*
|
|
|
|
* 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 <common.h>
|
|
|
|
#include <init.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <driver.h>
|
2013-05-27 13:53:27 +00:00
|
|
|
#include <usb/usb.h>
|
2012-11-22 14:35:22 +00:00
|
|
|
#include <usb/ehci.h>
|
|
|
|
#include <usb/chipidea-imx.h>
|
|
|
|
#include <usb/ulpi.h>
|
2013-02-05 14:50:31 +00:00
|
|
|
#include <usb/fsl_usb2.h>
|
2012-11-22 14:35:22 +00:00
|
|
|
|
2013-01-31 14:33:38 +00:00
|
|
|
#define MXC_EHCI_PORTSC_MASK ((0xf << 28) | (1 << 25))
|
2012-11-22 14:35:22 +00:00
|
|
|
|
2013-05-27 13:53:27 +00:00
|
|
|
struct imx_chipidea {
|
|
|
|
struct device_d *dev;
|
2013-06-11 21:58:53 +00:00
|
|
|
void __iomem *base;
|
2013-05-27 13:53:27 +00:00
|
|
|
struct ehci_data data;
|
|
|
|
unsigned long flags;
|
|
|
|
enum imx_usb_mode mode;
|
|
|
|
int (*init)(int port);
|
|
|
|
int portno;
|
|
|
|
};
|
|
|
|
|
2013-01-31 14:20:41 +00:00
|
|
|
static int imx_chipidea_port_init(void *drvdata)
|
|
|
|
{
|
2013-05-27 13:53:27 +00:00
|
|
|
struct imx_chipidea *ci = drvdata;
|
2013-01-31 14:20:41 +00:00
|
|
|
int ret;
|
|
|
|
|
2013-06-11 21:58:53 +00:00
|
|
|
if ((ci->flags & MXC_EHCI_PORTSC_MASK) == MXC_EHCI_MODE_ULPI) {
|
|
|
|
dev_dbg(ci->dev, "using ULPI phy\n");
|
|
|
|
if (IS_ENABLED(CONFIG_USB_ULPI)) {
|
|
|
|
ret = ulpi_setup(ci->base + 0x170, 1);
|
|
|
|
} else {
|
|
|
|
dev_err(ci->dev, "no ULPI support available\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-27 13:53:27 +00:00
|
|
|
ret = imx_usbmisc_port_init(ci->portno, ci->flags);
|
2013-01-31 14:20:41 +00:00
|
|
|
if (ret)
|
2013-05-27 13:53:27 +00:00
|
|
|
dev_err(ci->dev, "misc init failed: %s\n", strerror(-ret));
|
2013-01-31 14:20:41 +00:00
|
|
|
|
2013-05-27 13:53:27 +00:00
|
|
|
if (ci->init)
|
|
|
|
ci->init(ci->portno);
|
2013-01-31 14:20:41 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_chipidea_port_post_init(void *drvdata)
|
|
|
|
{
|
2013-05-27 13:53:27 +00:00
|
|
|
struct imx_chipidea *ci = drvdata;
|
2013-01-31 14:20:41 +00:00
|
|
|
int ret;
|
|
|
|
|
2013-05-27 13:53:27 +00:00
|
|
|
ret = imx_usbmisc_port_post_init(ci->portno, ci->flags);
|
2013-01-31 14:20:41 +00:00
|
|
|
if (ret)
|
2013-05-27 13:53:27 +00:00
|
|
|
dev_err(ci->dev, "post misc init failed: %s\n", strerror(-ret));
|
2013-01-31 14:20:41 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2012-11-22 14:35:22 +00:00
|
|
|
|
2013-05-27 13:53:27 +00:00
|
|
|
static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
|
|
|
|
{
|
2013-06-14 13:36:38 +00:00
|
|
|
struct of_phandle_args out_args;
|
2013-05-27 13:53:27 +00:00
|
|
|
enum usb_dr_mode mode;
|
|
|
|
enum usb_phy_interface phymode;
|
|
|
|
|
2013-06-14 13:36:38 +00:00
|
|
|
if (of_parse_phandle_with_args(ci->dev->device_node, "fsl,usbmisc",
|
|
|
|
"#index-cells", 0, &out_args))
|
|
|
|
return -ENODEV;
|
2013-05-27 13:53:27 +00:00
|
|
|
|
2013-06-14 13:36:38 +00:00
|
|
|
ci->portno = out_args.args[0];
|
2013-05-27 13:53:27 +00:00
|
|
|
ci->flags = MXC_EHCI_MODE_UTMI_8BIT;
|
|
|
|
|
|
|
|
mode = of_usb_get_dr_mode(ci->dev->device_node, NULL);
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case USB_DR_MODE_HOST:
|
|
|
|
default:
|
|
|
|
ci->mode = IMX_USB_MODE_HOST;
|
|
|
|
break;
|
|
|
|
case USB_DR_MODE_PERIPHERAL:
|
|
|
|
ci->mode = IMX_USB_MODE_DEVICE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
phymode = of_usb_get_phy_mode(ci->dev->device_node, NULL);
|
|
|
|
switch (phymode) {
|
|
|
|
case USBPHY_INTERFACE_MODE_UTMI:
|
|
|
|
ci->flags = MXC_EHCI_MODE_UTMI_8BIT;
|
|
|
|
break;
|
|
|
|
case USBPHY_INTERFACE_MODE_UTMIW:
|
|
|
|
ci->flags = MXC_EHCI_MODE_UTMI_16_BIT;
|
|
|
|
break;
|
|
|
|
case USBPHY_INTERFACE_MODE_ULPI:
|
|
|
|
ci->flags = MXC_EHCI_MODE_ULPI;
|
|
|
|
break;
|
|
|
|
case USBPHY_INTERFACE_MODE_SERIAL:
|
|
|
|
ci->flags = MXC_EHCI_MODE_SERIAL;
|
|
|
|
break;
|
|
|
|
case USBPHY_INTERFACE_MODE_HSIC:
|
|
|
|
ci->flags = MXC_EHCI_MODE_HSIC;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(ci->dev, "no or invalid phy mode setting\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-06-18 09:21:19 +00:00
|
|
|
if (of_find_property(ci->dev->device_node,
|
|
|
|
"disable-over-current", NULL))
|
2013-05-28 10:14:59 +00:00
|
|
|
ci->flags |= MXC_EHCI_DISABLE_OVERCURRENT;
|
|
|
|
|
2013-05-27 13:53:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-22 14:35:22 +00:00
|
|
|
static int imx_chipidea_probe(struct device_d *dev)
|
|
|
|
{
|
|
|
|
struct imxusb_platformdata *pdata = dev->platform_data;
|
|
|
|
int ret;
|
|
|
|
void __iomem *base;
|
2013-05-27 13:53:27 +00:00
|
|
|
struct imx_chipidea *ci;
|
2012-11-22 14:35:22 +00:00
|
|
|
uint32_t portsc;
|
|
|
|
|
2013-05-27 13:53:27 +00:00
|
|
|
ci = xzalloc(sizeof(*ci));
|
|
|
|
ci->dev = dev;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node) {
|
|
|
|
ret = imx_chipidea_probe_dt(ci);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
if (!pdata) {
|
|
|
|
dev_err(dev, "no pdata!\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
ci->portno = dev->id;
|
|
|
|
ci->flags = pdata->flags;
|
|
|
|
ci->init = pdata->init;
|
|
|
|
ci->mode = pdata->mode;
|
2012-11-22 14:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
base = dev_request_mem_region(dev, 0);
|
|
|
|
if (!base)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2013-06-11 21:58:53 +00:00
|
|
|
ci->base = base;
|
|
|
|
|
2013-05-27 13:53:27 +00:00
|
|
|
ci->data.init = imx_chipidea_port_init;
|
|
|
|
ci->data.post_init = imx_chipidea_port_post_init;
|
|
|
|
ci->data.drvdata = ci;
|
2013-01-31 14:20:41 +00:00
|
|
|
|
2013-06-05 13:26:08 +00:00
|
|
|
imx_chipidea_port_init(ci);
|
|
|
|
|
2012-11-22 14:35:22 +00:00
|
|
|
portsc = readl(base + 0x184);
|
|
|
|
portsc &= ~MXC_EHCI_PORTSC_MASK;
|
2013-05-27 13:53:27 +00:00
|
|
|
portsc |= ci->flags & MXC_EHCI_PORTSC_MASK;
|
2012-11-22 14:35:22 +00:00
|
|
|
writel(portsc, base + 0x184);
|
|
|
|
|
2013-05-27 13:53:27 +00:00
|
|
|
ci->data.hccr = base + 0x100;
|
|
|
|
ci->data.hcor = base + 0x140;
|
|
|
|
ci->data.flags = EHCI_HAS_TT;
|
2012-11-22 14:35:22 +00:00
|
|
|
|
2013-05-27 13:53:27 +00:00
|
|
|
if (ci->mode == IMX_USB_MODE_HOST && IS_ENABLED(CONFIG_USB_EHCI)) {
|
|
|
|
ret = ehci_register(dev, &ci->data);
|
|
|
|
} else if (ci->mode == IMX_USB_MODE_DEVICE && IS_ENABLED(CONFIG_USB_GADGET_DRIVER_ARC)) {
|
2013-02-05 14:50:31 +00:00
|
|
|
ret = ci_udc_register(dev, base);
|
2012-11-22 14:35:22 +00:00
|
|
|
} else {
|
2013-02-05 14:50:31 +00:00
|
|
|
dev_err(dev, "No supported role\n");
|
|
|
|
ret = -ENODEV;
|
2012-11-22 14:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2013-05-27 13:53:27 +00:00
|
|
|
static __maybe_unused struct of_device_id imx_chipidea_dt_ids[] = {
|
|
|
|
{
|
|
|
|
.compatible = "fsl,imx27-usb",
|
|
|
|
}, {
|
|
|
|
/* sentinel */
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-11-22 14:35:22 +00:00
|
|
|
static struct driver_d imx_chipidea_driver = {
|
|
|
|
.name = "imx-usb",
|
|
|
|
.probe = imx_chipidea_probe,
|
2013-05-27 13:53:27 +00:00
|
|
|
.of_compatible = DRV_OF_COMPAT(imx_chipidea_dt_ids),
|
2012-11-22 14:35:22 +00:00
|
|
|
};
|
2013-02-12 18:08:57 +00:00
|
|
|
device_platform_driver(imx_chipidea_driver);
|