2008-09-17 23:34:28 +08:00
|
|
|
/*
|
|
|
|
* Wireless Host Controller (WHC) initialization.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Cambridge Silicon Radio Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version
|
|
|
|
* 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.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/gfp.h>
|
2008-09-17 23:34:28 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/uwb/umc.h>
|
|
|
|
|
|
|
|
#include "../../wusbcore/wusbhc.h"
|
|
|
|
|
|
|
|
#include "whcd.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the host controller.
|
|
|
|
*/
|
|
|
|
static void whc_hw_reset(struct whc *whc)
|
|
|
|
{
|
|
|
|
le_writel(WUSBCMD_WHCRESET, whc->base + WUSBCMD);
|
|
|
|
whci_wait_for(&whc->umc->dev, whc->base + WUSBCMD, WUSBCMD_WHCRESET, 0,
|
|
|
|
100, "reset");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void whc_hw_init_di_buf(struct whc *whc)
|
|
|
|
{
|
|
|
|
int d;
|
|
|
|
|
|
|
|
/* Disable all entries in the Device Information buffer. */
|
|
|
|
for (d = 0; d < whc->n_devices; d++)
|
|
|
|
whc->di_buf[d].addr_sec_info = WHC_DI_DISABLE;
|
|
|
|
|
|
|
|
le_writeq(whc->di_buf_dma, whc->base + WUSBDEVICEINFOADDR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void whc_hw_init_dn_buf(struct whc *whc)
|
|
|
|
{
|
|
|
|
/* Clear the Device Notification buffer to ensure the V (valid)
|
|
|
|
* bits are clear. */
|
|
|
|
memset(whc->dn_buf, 0, 4096);
|
|
|
|
|
|
|
|
le_writeq(whc->dn_buf_dma, whc->base + WUSBDNTSBUFADDR);
|
|
|
|
}
|
|
|
|
|
|
|
|
int whc_init(struct whc *whc)
|
|
|
|
{
|
|
|
|
u32 whcsparams;
|
|
|
|
int ret, i;
|
|
|
|
resource_size_t start, len;
|
|
|
|
|
|
|
|
spin_lock_init(&whc->lock);
|
|
|
|
mutex_init(&whc->mutex);
|
|
|
|
init_waitqueue_head(&whc->cmd_wq);
|
|
|
|
init_waitqueue_head(&whc->async_list_wq);
|
|
|
|
init_waitqueue_head(&whc->periodic_list_wq);
|
|
|
|
whc->workqueue = create_singlethread_workqueue(dev_name(&whc->umc->dev));
|
|
|
|
if (whc->workqueue == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
INIT_WORK(&whc->dn_work, whc_dn_work);
|
|
|
|
|
|
|
|
INIT_WORK(&whc->async_work, scan_async_work);
|
|
|
|
INIT_LIST_HEAD(&whc->async_list);
|
|
|
|
INIT_LIST_HEAD(&whc->async_removed_list);
|
|
|
|
|
|
|
|
INIT_WORK(&whc->periodic_work, scan_periodic_work);
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
INIT_LIST_HEAD(&whc->periodic_list[i]);
|
|
|
|
INIT_LIST_HEAD(&whc->periodic_removed_list);
|
|
|
|
|
|
|
|
/* Map HC registers. */
|
|
|
|
start = whc->umc->resource.start;
|
|
|
|
len = whc->umc->resource.end - start + 1;
|
|
|
|
if (!request_mem_region(start, len, "whci-hc")) {
|
|
|
|
dev_err(&whc->umc->dev, "can't request HC region\n");
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
whc->base_phys = start;
|
|
|
|
whc->base = ioremap(start, len);
|
|
|
|
if (!whc->base) {
|
|
|
|
dev_err(&whc->umc->dev, "ioremap\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
whc_hw_reset(whc);
|
|
|
|
|
|
|
|
/* Read maximum number of devices, keys and MMC IEs. */
|
|
|
|
whcsparams = le_readl(whc->base + WHCSPARAMS);
|
|
|
|
whc->n_devices = WHCSPARAMS_TO_N_DEVICES(whcsparams);
|
|
|
|
whc->n_keys = WHCSPARAMS_TO_N_KEYS(whcsparams);
|
|
|
|
whc->n_mmc_ies = WHCSPARAMS_TO_N_MMC_IES(whcsparams);
|
|
|
|
|
|
|
|
dev_dbg(&whc->umc->dev, "N_DEVICES = %d, N_KEYS = %d, N_MMC_IES = %d\n",
|
|
|
|
whc->n_devices, whc->n_keys, whc->n_mmc_ies);
|
|
|
|
|
|
|
|
whc->qset_pool = dma_pool_create("qset", &whc->umc->dev,
|
|
|
|
sizeof(struct whc_qset), 64, 0);
|
|
|
|
if (whc->qset_pool == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = asl_init(whc);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
ret = pzl_init(whc);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Allocate and initialize a buffer for generic commands, the
|
|
|
|
Device Information buffer, and the Device Notification
|
|
|
|
buffer. */
|
|
|
|
|
|
|
|
whc->gen_cmd_buf = dma_alloc_coherent(&whc->umc->dev, WHC_GEN_CMD_DATA_LEN,
|
|
|
|
&whc->gen_cmd_buf_dma, GFP_KERNEL);
|
|
|
|
if (whc->gen_cmd_buf == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
whc->dn_buf = dma_alloc_coherent(&whc->umc->dev,
|
|
|
|
sizeof(struct dn_buf_entry) * WHC_N_DN_ENTRIES,
|
|
|
|
&whc->dn_buf_dma, GFP_KERNEL);
|
|
|
|
if (!whc->dn_buf) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
whc_hw_init_dn_buf(whc);
|
|
|
|
|
|
|
|
whc->di_buf = dma_alloc_coherent(&whc->umc->dev,
|
|
|
|
sizeof(struct di_buf_entry) * whc->n_devices,
|
|
|
|
&whc->di_buf_dma, GFP_KERNEL);
|
|
|
|
if (!whc->di_buf) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
whc_hw_init_di_buf(whc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
whc_clean_up(whc);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void whc_clean_up(struct whc *whc)
|
|
|
|
{
|
|
|
|
resource_size_t len;
|
|
|
|
|
|
|
|
if (whc->di_buf)
|
|
|
|
dma_free_coherent(&whc->umc->dev, sizeof(struct di_buf_entry) * whc->n_devices,
|
|
|
|
whc->di_buf, whc->di_buf_dma);
|
|
|
|
if (whc->dn_buf)
|
|
|
|
dma_free_coherent(&whc->umc->dev, sizeof(struct dn_buf_entry) * WHC_N_DN_ENTRIES,
|
|
|
|
whc->dn_buf, whc->dn_buf_dma);
|
|
|
|
if (whc->gen_cmd_buf)
|
|
|
|
dma_free_coherent(&whc->umc->dev, WHC_GEN_CMD_DATA_LEN,
|
|
|
|
whc->gen_cmd_buf, whc->gen_cmd_buf_dma);
|
|
|
|
|
|
|
|
pzl_clean_up(whc);
|
|
|
|
asl_clean_up(whc);
|
|
|
|
|
|
|
|
if (whc->qset_pool)
|
|
|
|
dma_pool_destroy(whc->qset_pool);
|
|
|
|
|
|
|
|
len = whc->umc->resource.end - whc->umc->resource.start + 1;
|
|
|
|
if (whc->base)
|
|
|
|
iounmap(whc->base);
|
|
|
|
if (whc->base_phys)
|
|
|
|
release_mem_region(whc->base_phys, len);
|
|
|
|
|
|
|
|
if (whc->workqueue)
|
|
|
|
destroy_workqueue(whc->workqueue);
|
|
|
|
}
|