2017-11-03 18:28:30 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-04-27 14:59:44 +08:00
|
|
|
/*
|
|
|
|
* c67x00-drv.c: Cypress C67X00 USB Common infrastructure
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2008 Barco N.V.
|
|
|
|
* Derived from the Cypress cy7c67200/300 ezusb linux driver and
|
|
|
|
* based on multiple host controller drivers inside the linux kernel.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file implements the common infrastructure for using the c67x00.
|
|
|
|
* It is both the link between the platform configuration and subdrivers and
|
|
|
|
* the link between the common hardware parts and the subdrivers (e.g.
|
|
|
|
* interrupt handling).
|
|
|
|
*
|
2011-03-31 09:57:33 +08:00
|
|
|
* The c67x00 has 2 SIE's (serial interface engine) which can be configured
|
2008-04-27 14:59:44 +08:00
|
|
|
* to be host, device or OTG (with some limitations, E.G. only SIE1 can be OTG).
|
|
|
|
*
|
|
|
|
* Depending on the platform configuration, the SIE's are created and
|
|
|
|
* the corresponding subdriver is initialized (c67x00_probe_sie).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/list.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-07-04 04:09:31 +08:00
|
|
|
#include <linux/module.h>
|
2008-04-27 14:59:44 +08:00
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/usb/c67x00.h>
|
|
|
|
|
|
|
|
#include "c67x00.h"
|
2008-04-27 14:59:45 +08:00
|
|
|
#include "c67x00-hcd.h"
|
2008-04-27 14:59:44 +08:00
|
|
|
|
|
|
|
static void c67x00_probe_sie(struct c67x00_sie *sie,
|
|
|
|
struct c67x00_device *dev, int sie_num)
|
|
|
|
{
|
|
|
|
spin_lock_init(&sie->lock);
|
|
|
|
sie->dev = dev;
|
|
|
|
sie->sie_num = sie_num;
|
|
|
|
sie->mode = c67x00_sie_config(dev->pdata->sie_config, sie_num);
|
|
|
|
|
|
|
|
switch (sie->mode) {
|
2008-04-27 14:59:45 +08:00
|
|
|
case C67X00_SIE_HOST:
|
|
|
|
c67x00_hcd_probe(sie);
|
|
|
|
break;
|
|
|
|
|
2008-04-27 14:59:44 +08:00
|
|
|
case C67X00_SIE_UNUSED:
|
|
|
|
dev_info(sie_dev(sie),
|
|
|
|
"Not using SIE %d as requested\n", sie->sie_num);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dev_err(sie_dev(sie),
|
|
|
|
"Unsupported configuration: 0x%x for SIE %d\n",
|
|
|
|
sie->mode, sie->sie_num);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void c67x00_remove_sie(struct c67x00_sie *sie)
|
|
|
|
{
|
2008-04-27 14:59:45 +08:00
|
|
|
switch (sie->mode) {
|
|
|
|
case C67X00_SIE_HOST:
|
|
|
|
c67x00_hcd_remove(sie);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-04-27 14:59:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t c67x00_irq(int irq, void *__dev)
|
|
|
|
{
|
|
|
|
struct c67x00_device *c67x00 = __dev;
|
|
|
|
struct c67x00_sie *sie;
|
|
|
|
u16 msg, int_status;
|
|
|
|
int i, count = 8;
|
|
|
|
|
|
|
|
int_status = c67x00_ll_hpi_status(c67x00);
|
|
|
|
if (!int_status)
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
while (int_status != 0 && (count-- >= 0)) {
|
|
|
|
c67x00_ll_irq(c67x00, int_status);
|
|
|
|
for (i = 0; i < C67X00_SIES; i++) {
|
|
|
|
sie = &c67x00->sie[i];
|
|
|
|
msg = 0;
|
|
|
|
if (int_status & SIEMSG_FLG(i))
|
|
|
|
msg = c67x00_ll_fetch_siemsg(c67x00, i);
|
|
|
|
if (sie->irq)
|
|
|
|
sie->irq(sie, int_status, msg);
|
|
|
|
}
|
|
|
|
int_status = c67x00_ll_hpi_status(c67x00);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (int_status)
|
|
|
|
dev_warn(&c67x00->pdev->dev, "Not all interrupts handled! "
|
|
|
|
"status = 0x%04x\n", int_status);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2012-11-20 02:21:48 +08:00
|
|
|
static int c67x00_drv_probe(struct platform_device *pdev)
|
2008-04-27 14:59:44 +08:00
|
|
|
{
|
|
|
|
struct c67x00_device *c67x00;
|
|
|
|
struct c67x00_platform_data *pdata;
|
|
|
|
struct resource *res, *res2;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
|
|
|
if (!res2)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2013-07-30 16:25:19 +08:00
|
|
|
pdata = dev_get_platdata(&pdev->dev);
|
2008-04-27 14:59:44 +08:00
|
|
|
if (!pdata)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
c67x00 = kzalloc(sizeof(*c67x00), GFP_KERNEL);
|
|
|
|
if (!c67x00)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-01-02 05:42:34 +08:00
|
|
|
if (!request_mem_region(res->start, resource_size(res),
|
2008-04-27 14:59:44 +08:00
|
|
|
pdev->name)) {
|
|
|
|
dev_err(&pdev->dev, "Memory region busy\n");
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto request_mem_failed;
|
|
|
|
}
|
2010-01-02 05:42:34 +08:00
|
|
|
c67x00->hpi.base = ioremap(res->start, resource_size(res));
|
2008-04-27 14:59:44 +08:00
|
|
|
if (!c67x00->hpi.base) {
|
|
|
|
dev_err(&pdev->dev, "Unable to map HPI registers\n");
|
|
|
|
ret = -EIO;
|
|
|
|
goto map_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_init(&c67x00->hpi.lock);
|
|
|
|
c67x00->hpi.regstep = pdata->hpi_regstep;
|
2013-07-30 16:25:19 +08:00
|
|
|
c67x00->pdata = dev_get_platdata(&pdev->dev);
|
2008-04-27 14:59:44 +08:00
|
|
|
c67x00->pdev = pdev;
|
|
|
|
|
|
|
|
c67x00_ll_init(c67x00);
|
|
|
|
c67x00_ll_hpi_reg_init(c67x00);
|
|
|
|
|
|
|
|
ret = request_irq(res2->start, c67x00_irq, 0, pdev->name, c67x00);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Cannot claim IRQ\n");
|
|
|
|
goto request_irq_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = c67x00_ll_reset(c67x00);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Device reset failed\n");
|
|
|
|
goto reset_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < C67X00_SIES; i++)
|
|
|
|
c67x00_probe_sie(&c67x00->sie[i], c67x00, i);
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, c67x00);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
reset_failed:
|
|
|
|
free_irq(res2->start, c67x00);
|
|
|
|
request_irq_failed:
|
|
|
|
iounmap(c67x00->hpi.base);
|
|
|
|
map_failed:
|
2010-01-02 05:42:34 +08:00
|
|
|
release_mem_region(res->start, resource_size(res));
|
2008-04-27 14:59:44 +08:00
|
|
|
request_mem_failed:
|
|
|
|
kfree(c67x00);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:26:20 +08:00
|
|
|
static int c67x00_drv_remove(struct platform_device *pdev)
|
2008-04-27 14:59:44 +08:00
|
|
|
{
|
|
|
|
struct c67x00_device *c67x00 = platform_get_drvdata(pdev);
|
|
|
|
struct resource *res;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < C67X00_SIES; i++)
|
|
|
|
c67x00_remove_sie(&c67x00->sie[i]);
|
|
|
|
|
|
|
|
c67x00_ll_release(c67x00);
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
|
|
|
if (res)
|
|
|
|
free_irq(res->start, c67x00);
|
|
|
|
|
|
|
|
iounmap(c67x00->hpi.base);
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (res)
|
2010-01-02 05:42:34 +08:00
|
|
|
release_mem_region(res->start, resource_size(res));
|
2008-04-27 14:59:44 +08:00
|
|
|
|
|
|
|
kfree(c67x00);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver c67x00_driver = {
|
|
|
|
.probe = c67x00_drv_probe,
|
2012-11-20 02:21:08 +08:00
|
|
|
.remove = c67x00_drv_remove,
|
2008-04-27 14:59:44 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "c67x00",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-11-27 20:16:27 +08:00
|
|
|
module_platform_driver(c67x00_driver);
|
2008-04-27 14:59:44 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Peter Korsgaard, Jan Veldeman, Grant Likely");
|
|
|
|
MODULE_DESCRIPTION("Cypress C67X00 USB Controller Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2011-11-27 20:16:27 +08:00
|
|
|
MODULE_ALIAS("platform:c67x00");
|