2009-10-28 00:14:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
|
|
|
|
* Copyright (c) 2009 Daniel Mack <daniel@caiaq.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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/usb/otg.h>
|
2011-01-17 23:04:12 +00:00
|
|
|
#include <linux/usb/ulpi.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2009-10-28 00:14:59 +00:00
|
|
|
|
2011-07-21 14:24:10 +00:00
|
|
|
#include <mach/hardware.h>
|
2009-10-28 00:14:59 +00:00
|
|
|
#include <mach/mxc_ehci.h>
|
|
|
|
|
2011-01-17 23:04:12 +00:00
|
|
|
#include <asm/mach-types.h>
|
|
|
|
|
2009-10-28 00:14:59 +00:00
|
|
|
#define ULPI_VIEWPORT_OFFSET 0x170
|
|
|
|
|
|
|
|
struct ehci_mxc_priv {
|
2010-12-20 15:48:58 +00:00
|
|
|
struct clk *usbclk, *ahbclk, *phy1clk;
|
2009-10-28 00:14:59 +00:00
|
|
|
struct usb_hcd *hcd;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* called during probe() after chip reset completes */
|
|
|
|
static int ehci_mxc_setup(struct usb_hcd *hcd)
|
|
|
|
{
|
|
|
|
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
dbg_hcs_params(ehci, "reset");
|
|
|
|
dbg_hcc_params(ehci, "reset");
|
|
|
|
|
|
|
|
/* cache this readonly data; minimize chip reads */
|
|
|
|
ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
|
|
|
|
|
2010-09-06 16:26:56 +00:00
|
|
|
hcd->has_tt = 1;
|
|
|
|
|
2009-10-28 00:14:59 +00:00
|
|
|
retval = ehci_halt(ehci);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* data structure init */
|
|
|
|
retval = ehci_init(hcd);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
ehci->sbrn = 0x20;
|
|
|
|
|
|
|
|
ehci_reset(ehci);
|
|
|
|
|
|
|
|
ehci_port_power(ehci, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct hc_driver ehci_mxc_hc_driver = {
|
|
|
|
.description = hcd_name,
|
|
|
|
.product_desc = "Freescale On-Chip EHCI Host Controller",
|
|
|
|
.hcd_priv_size = sizeof(struct ehci_hcd),
|
|
|
|
|
|
|
|
/*
|
|
|
|
* generic hardware linkage
|
|
|
|
*/
|
|
|
|
.irq = ehci_irq,
|
|
|
|
.flags = HCD_USB2 | HCD_MEMORY,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* basic lifecycle operations
|
|
|
|
*/
|
|
|
|
.reset = ehci_mxc_setup,
|
|
|
|
.start = ehci_run,
|
|
|
|
.stop = ehci_stop,
|
|
|
|
.shutdown = ehci_shutdown,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* managing i/o requests and associated device resources
|
|
|
|
*/
|
|
|
|
.urb_enqueue = ehci_urb_enqueue,
|
|
|
|
.urb_dequeue = ehci_urb_dequeue,
|
|
|
|
.endpoint_disable = ehci_endpoint_disable,
|
2010-11-30 08:57:02 +00:00
|
|
|
.endpoint_reset = ehci_endpoint_reset,
|
2009-10-28 00:14:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* scheduling support
|
|
|
|
*/
|
|
|
|
.get_frame_number = ehci_get_frame,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* root hub support
|
|
|
|
*/
|
|
|
|
.hub_status_data = ehci_hub_status_data,
|
|
|
|
.hub_control = ehci_hub_control,
|
|
|
|
.bus_suspend = ehci_bus_suspend,
|
|
|
|
.bus_resume = ehci_bus_resume,
|
|
|
|
.relinquish_port = ehci_relinquish_port,
|
|
|
|
.port_handed_over = ehci_port_handed_over,
|
2010-11-30 08:57:02 +00:00
|
|
|
|
|
|
|
.clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
|
2009-10-28 00:14:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int ehci_mxc_drv_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
|
|
|
|
struct usb_hcd *hcd;
|
|
|
|
struct resource *res;
|
2010-11-02 09:30:57 +00:00
|
|
|
int irq, ret;
|
2011-01-17 23:04:12 +00:00
|
|
|
unsigned int flags;
|
2009-10-28 00:14:59 +00:00
|
|
|
struct ehci_mxc_priv *priv;
|
|
|
|
struct device *dev = &pdev->dev;
|
2010-12-16 00:31:28 +00:00
|
|
|
struct ehci_hcd *ehci;
|
2009-10-28 00:14:59 +00:00
|
|
|
|
|
|
|
dev_info(&pdev->dev, "initializing i.MX USB Controller\n");
|
|
|
|
|
|
|
|
if (!pdata) {
|
|
|
|
dev_err(dev, "No platform data given, bailing out.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
|
|
|
|
hcd = usb_create_hcd(&ehci_mxc_hc_driver, dev, dev_name(dev));
|
|
|
|
if (!hcd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res) {
|
|
|
|
dev_err(dev, "Found HC with no register addr. Check setup!\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto err_get_resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
hcd->rsrc_start = res->start;
|
|
|
|
hcd->rsrc_len = resource_size(res);
|
|
|
|
|
|
|
|
if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
|
|
|
|
dev_dbg(dev, "controller already in use\n");
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto err_request_mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
|
|
|
|
if (!hcd->regs) {
|
|
|
|
dev_err(dev, "error mapping memory\n");
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err_ioremap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* enable clocks */
|
|
|
|
priv->usbclk = clk_get(dev, "usb");
|
|
|
|
if (IS_ERR(priv->usbclk)) {
|
|
|
|
ret = PTR_ERR(priv->usbclk);
|
|
|
|
goto err_clk;
|
|
|
|
}
|
|
|
|
clk_enable(priv->usbclk);
|
|
|
|
|
2010-06-08 09:02:58 +00:00
|
|
|
if (!cpu_is_mx35() && !cpu_is_mx25()) {
|
2009-10-28 00:14:59 +00:00
|
|
|
priv->ahbclk = clk_get(dev, "usb_ahb");
|
|
|
|
if (IS_ERR(priv->ahbclk)) {
|
|
|
|
ret = PTR_ERR(priv->ahbclk);
|
|
|
|
goto err_clk_ahb;
|
|
|
|
}
|
|
|
|
clk_enable(priv->ahbclk);
|
|
|
|
}
|
|
|
|
|
2011-01-13 13:53:17 +00:00
|
|
|
/* "dr" device has its own clock on i.MX51 */
|
|
|
|
if (cpu_is_mx51() && (pdev->id == 0)) {
|
2010-12-20 15:48:58 +00:00
|
|
|
priv->phy1clk = clk_get(dev, "usb_phy1");
|
|
|
|
if (IS_ERR(priv->phy1clk)) {
|
|
|
|
ret = PTR_ERR(priv->phy1clk);
|
|
|
|
goto err_clk_phy;
|
|
|
|
}
|
|
|
|
clk_enable(priv->phy1clk);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* call platform specific init function */
|
|
|
|
if (pdata->init) {
|
|
|
|
ret = pdata->init(pdev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "platform init failed\n");
|
|
|
|
goto err_init;
|
|
|
|
}
|
|
|
|
/* platforms need some time to settle changed IO settings */
|
|
|
|
mdelay(10);
|
|
|
|
}
|
|
|
|
|
2010-12-16 00:31:28 +00:00
|
|
|
ehci = hcd_to_ehci(hcd);
|
|
|
|
|
|
|
|
/* EHCI registers start at offset 0x100 */
|
|
|
|
ehci->caps = hcd->regs + 0x100;
|
|
|
|
ehci->regs = hcd->regs + 0x100 +
|
2011-05-03 18:11:57 +00:00
|
|
|
HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
|
2010-12-16 00:31:28 +00:00
|
|
|
|
|
|
|
/* set up the PORTSCx register */
|
|
|
|
ehci_writel(ehci, pdata->portsc, &ehci->regs->port_status[0]);
|
|
|
|
|
|
|
|
/* is this really needed? */
|
|
|
|
msleep(10);
|
|
|
|
|
2009-10-28 00:14:59 +00:00
|
|
|
/* Initialize the transceiver */
|
|
|
|
if (pdata->otg) {
|
|
|
|
pdata->otg->io_priv = hcd->regs + ULPI_VIEWPORT_OFFSET;
|
2010-06-15 10:34:23 +00:00
|
|
|
ret = otg_init(pdata->otg);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "unable to init transceiver, probably missing\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto err_add;
|
|
|
|
}
|
|
|
|
ret = otg_set_vbus(pdata->otg, 1);
|
|
|
|
if (ret) {
|
2009-10-28 00:14:59 +00:00
|
|
|
dev_err(dev, "unable to enable vbus on transceiver\n");
|
2010-06-15 10:34:23 +00:00
|
|
|
goto err_add;
|
|
|
|
}
|
2009-10-28 00:14:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
priv->hcd = hcd;
|
|
|
|
platform_set_drvdata(pdev, priv);
|
|
|
|
|
2011-09-07 08:10:52 +00:00
|
|
|
ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
|
2009-10-28 00:14:59 +00:00
|
|
|
if (ret)
|
|
|
|
goto err_add;
|
|
|
|
|
2011-01-17 23:04:12 +00:00
|
|
|
if (pdata->otg) {
|
|
|
|
/*
|
|
|
|
* efikamx and efikasb have some hardware bug which is
|
|
|
|
* preventing usb to work unless CHRGVBUS is set.
|
|
|
|
* It's in violation of USB specs
|
|
|
|
*/
|
|
|
|
if (machine_is_mx51_efikamx() || machine_is_mx51_efikasb()) {
|
|
|
|
flags = otg_io_read(pdata->otg, ULPI_OTG_CTRL);
|
|
|
|
flags |= ULPI_OTG_CTRL_CHRGVBUS;
|
|
|
|
ret = otg_io_write(pdata->otg, flags, ULPI_OTG_CTRL);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "unable to set CHRVBUS\n");
|
|
|
|
goto err_add;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-28 00:14:59 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_add:
|
|
|
|
if (pdata && pdata->exit)
|
|
|
|
pdata->exit(pdev);
|
|
|
|
err_init:
|
2010-12-20 15:48:58 +00:00
|
|
|
if (priv->phy1clk) {
|
|
|
|
clk_disable(priv->phy1clk);
|
|
|
|
clk_put(priv->phy1clk);
|
|
|
|
}
|
|
|
|
err_clk_phy:
|
2009-10-28 00:14:59 +00:00
|
|
|
if (priv->ahbclk) {
|
|
|
|
clk_disable(priv->ahbclk);
|
|
|
|
clk_put(priv->ahbclk);
|
|
|
|
}
|
|
|
|
err_clk_ahb:
|
|
|
|
clk_disable(priv->usbclk);
|
|
|
|
clk_put(priv->usbclk);
|
|
|
|
err_clk:
|
|
|
|
iounmap(hcd->regs);
|
|
|
|
err_ioremap:
|
|
|
|
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
|
|
|
|
err_request_mem:
|
|
|
|
err_get_resource:
|
|
|
|
kfree(priv);
|
|
|
|
err_alloc:
|
|
|
|
usb_put_hcd(hcd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __exit ehci_mxc_drv_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
|
|
|
|
struct ehci_mxc_priv *priv = platform_get_drvdata(pdev);
|
|
|
|
struct usb_hcd *hcd = priv->hcd;
|
|
|
|
|
|
|
|
if (pdata && pdata->exit)
|
|
|
|
pdata->exit(pdev);
|
|
|
|
|
|
|
|
if (pdata->otg)
|
|
|
|
otg_shutdown(pdata->otg);
|
|
|
|
|
|
|
|
usb_remove_hcd(hcd);
|
|
|
|
iounmap(hcd->regs);
|
|
|
|
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
|
|
|
|
usb_put_hcd(hcd);
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
|
|
|
|
clk_disable(priv->usbclk);
|
|
|
|
clk_put(priv->usbclk);
|
|
|
|
if (priv->ahbclk) {
|
|
|
|
clk_disable(priv->ahbclk);
|
|
|
|
clk_put(priv->ahbclk);
|
|
|
|
}
|
2010-12-20 15:48:58 +00:00
|
|
|
if (priv->phy1clk) {
|
|
|
|
clk_disable(priv->phy1clk);
|
|
|
|
clk_put(priv->phy1clk);
|
|
|
|
}
|
2009-10-28 00:14:59 +00:00
|
|
|
|
|
|
|
kfree(priv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ehci_mxc_drv_shutdown(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct ehci_mxc_priv *priv = platform_get_drvdata(pdev);
|
|
|
|
struct usb_hcd *hcd = priv->hcd;
|
|
|
|
|
|
|
|
if (hcd->driver->shutdown)
|
|
|
|
hcd->driver->shutdown(hcd);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_ALIAS("platform:mxc-ehci");
|
|
|
|
|
|
|
|
static struct platform_driver ehci_mxc_driver = {
|
|
|
|
.probe = ehci_mxc_drv_probe,
|
|
|
|
.remove = __exit_p(ehci_mxc_drv_remove),
|
|
|
|
.shutdown = ehci_mxc_drv_shutdown,
|
|
|
|
.driver = {
|
|
|
|
.name = "mxc-ehci",
|
|
|
|
},
|
|
|
|
};
|