2009-03-28 01:16:57 +08:00
|
|
|
/*
|
|
|
|
* smssdio.c - Siano 1xxx SDIO interface driver
|
|
|
|
*
|
|
|
|
* Copyright 2008 Pierre Ossman
|
|
|
|
*
|
|
|
|
* Based on code by Siano Mobile Silicon, Inc.,
|
|
|
|
* Copyright (C) 2006-2008, Uri Shkolnik
|
|
|
|
*
|
|
|
|
* 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 hardware is a bit odd in that all transfers should be done
|
|
|
|
* to/from the SMSSDIO_DATA register, yet the "increase address" bit
|
|
|
|
* always needs to be set.
|
|
|
|
*
|
|
|
|
* Also, buffers from the card are always aligned to 128 byte
|
|
|
|
* boundaries.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* General cleanup notes:
|
|
|
|
*
|
|
|
|
* - only typedefs should be name *_t
|
|
|
|
*
|
|
|
|
* - use ERR_PTR and friends for smscore_register_device()
|
|
|
|
*
|
|
|
|
* - smscore_getbuffer should zero fields
|
|
|
|
*
|
|
|
|
* Fix stop command
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/moduleparam.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>
|
2009-03-28 01:16:57 +08:00
|
|
|
#include <linux/firmware.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/mmc/card.h>
|
|
|
|
#include <linux/mmc/sdio_func.h>
|
|
|
|
#include <linux/mmc/sdio_ids.h>
|
2011-07-04 02:03:12 +08:00
|
|
|
#include <linux/module.h>
|
2009-03-28 01:16:57 +08:00
|
|
|
|
|
|
|
#include "smscoreapi.h"
|
|
|
|
#include "sms-cards.h"
|
2013-03-09 22:34:56 +08:00
|
|
|
#include "smsendian.h"
|
2009-03-28 01:16:57 +08:00
|
|
|
|
|
|
|
/* Registers */
|
|
|
|
|
|
|
|
#define SMSSDIO_DATA 0x00
|
|
|
|
#define SMSSDIO_INT 0x04
|
2009-06-28 15:22:55 +08:00
|
|
|
#define SMSSDIO_BLOCK_SIZE 128
|
2009-03-28 01:16:57 +08:00
|
|
|
|
2012-12-22 05:17:53 +08:00
|
|
|
static const struct sdio_device_id smssdio_ids[] = {
|
2009-03-28 01:16:57 +08:00
|
|
|
{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_STELLAR),
|
|
|
|
.driver_data = SMS1XXX_BOARD_SIANO_STELLAR},
|
|
|
|
{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_NOVA_A0),
|
|
|
|
.driver_data = SMS1XXX_BOARD_SIANO_NOVA_A},
|
|
|
|
{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_NOVA_B0),
|
|
|
|
.driver_data = SMS1XXX_BOARD_SIANO_NOVA_B},
|
|
|
|
{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_VEGA_A0),
|
|
|
|
.driver_data = SMS1XXX_BOARD_SIANO_VEGA},
|
|
|
|
{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_VENICE),
|
|
|
|
.driver_data = SMS1XXX_BOARD_SIANO_VEGA},
|
2013-03-06 09:35:44 +08:00
|
|
|
{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, 0x302),
|
|
|
|
.driver_data = SMS1XXX_BOARD_SIANO_MING},
|
|
|
|
{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, 0x500),
|
|
|
|
.driver_data = SMS1XXX_BOARD_SIANO_PELE},
|
|
|
|
{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, 0x600),
|
|
|
|
.driver_data = SMS1XXX_BOARD_SIANO_RIO},
|
|
|
|
{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, 0x700),
|
|
|
|
.driver_data = SMS1XXX_BOARD_SIANO_DENVER_2160},
|
|
|
|
{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, 0x800),
|
|
|
|
.driver_data = SMS1XXX_BOARD_SIANO_DENVER_1530},
|
2009-03-28 01:16:57 +08:00
|
|
|
{ /* end: all zeroes */ },
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(sdio, smssdio_ids);
|
|
|
|
|
|
|
|
struct smssdio_device {
|
|
|
|
struct sdio_func *func;
|
|
|
|
|
|
|
|
struct smscore_device_t *coredev;
|
|
|
|
|
|
|
|
struct smscore_buffer_t *split_cb;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
/* Siano core callbacks */
|
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
static int smssdio_sendrequest(void *context, void *buffer, size_t size)
|
|
|
|
{
|
2009-11-23 05:52:31 +08:00
|
|
|
int ret = 0;
|
2009-03-28 01:16:57 +08:00
|
|
|
struct smssdio_device *smsdev;
|
|
|
|
|
|
|
|
smsdev = context;
|
|
|
|
|
|
|
|
sdio_claim_host(smsdev->func);
|
|
|
|
|
2013-03-21 19:49:43 +08:00
|
|
|
smsendian_handle_tx_message((struct sms_msg_data *) buffer);
|
2009-03-28 01:16:57 +08:00
|
|
|
while (size >= smsdev->func->cur_blksize) {
|
2009-06-28 15:22:55 +08:00
|
|
|
ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA,
|
|
|
|
buffer, smsdev->func->cur_blksize);
|
2009-03-28 01:16:57 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
buffer += smsdev->func->cur_blksize;
|
|
|
|
size -= smsdev->func->cur_blksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size) {
|
2009-06-28 15:22:55 +08:00
|
|
|
ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA,
|
|
|
|
buffer, size);
|
2009-03-28 01:16:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
sdio_release_host(smsdev->func);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
/* SDIO callbacks */
|
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
static void smssdio_interrupt(struct sdio_func *func)
|
|
|
|
{
|
2012-04-20 19:04:48 +08:00
|
|
|
int ret;
|
2009-03-28 01:16:57 +08:00
|
|
|
|
|
|
|
struct smssdio_device *smsdev;
|
|
|
|
struct smscore_buffer_t *cb;
|
2013-03-21 19:49:43 +08:00
|
|
|
struct sms_msg_hdr *hdr;
|
2009-03-28 01:16:57 +08:00
|
|
|
size_t size;
|
|
|
|
|
|
|
|
smsdev = sdio_get_drvdata(func);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The interrupt register has no defined meaning. It is just
|
|
|
|
* a way of turning of the level triggered interrupt.
|
|
|
|
*/
|
2012-04-20 19:04:48 +08:00
|
|
|
(void)sdio_readb(func, SMSSDIO_INT, &ret);
|
2009-03-28 01:16:57 +08:00
|
|
|
if (ret) {
|
2009-06-28 15:22:55 +08:00
|
|
|
sms_err("Unable to read interrupt register!\n");
|
2009-03-28 01:16:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (smsdev->split_cb == NULL) {
|
|
|
|
cb = smscore_getbuffer(smsdev->coredev);
|
|
|
|
if (!cb) {
|
2009-06-28 15:22:55 +08:00
|
|
|
sms_err("Unable to allocate data buffer!\n");
|
2009-03-28 01:16:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-28 15:22:55 +08:00
|
|
|
ret = sdio_memcpy_fromio(smsdev->func,
|
|
|
|
cb->p,
|
|
|
|
SMSSDIO_DATA,
|
|
|
|
SMSSDIO_BLOCK_SIZE);
|
2009-03-28 01:16:57 +08:00
|
|
|
if (ret) {
|
2009-06-28 15:22:55 +08:00
|
|
|
sms_err("Error %d reading initial block!\n", ret);
|
2009-03-28 01:16:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hdr = cb->p;
|
|
|
|
|
2013-03-21 19:49:43 +08:00
|
|
|
if (hdr->msg_flags & MSG_HDR_FLAG_SPLIT_MSG) {
|
2009-03-28 01:16:57 +08:00
|
|
|
smsdev->split_cb = cb;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-21 19:49:43 +08:00
|
|
|
if (hdr->msg_length > smsdev->func->cur_blksize)
|
|
|
|
size = hdr->msg_length - smsdev->func->cur_blksize;
|
2009-06-28 15:22:55 +08:00
|
|
|
else
|
|
|
|
size = 0;
|
2009-03-28 01:16:57 +08:00
|
|
|
} else {
|
|
|
|
cb = smsdev->split_cb;
|
|
|
|
hdr = cb->p;
|
|
|
|
|
2013-03-21 19:49:43 +08:00
|
|
|
size = hdr->msg_length - sizeof(struct sms_msg_hdr);
|
2009-03-28 01:16:57 +08:00
|
|
|
|
|
|
|
smsdev->split_cb = NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-28 15:22:55 +08:00
|
|
|
if (size) {
|
2009-03-28 01:16:57 +08:00
|
|
|
void *buffer;
|
|
|
|
|
2013-03-21 19:49:43 +08:00
|
|
|
buffer = cb->p + (hdr->msg_length - size);
|
2009-06-28 15:22:55 +08:00
|
|
|
size = ALIGN(size, SMSSDIO_BLOCK_SIZE);
|
2009-03-28 01:16:57 +08:00
|
|
|
|
2009-06-28 15:22:55 +08:00
|
|
|
BUG_ON(smsdev->func->cur_blksize != SMSSDIO_BLOCK_SIZE);
|
2009-03-28 01:16:57 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First attempt to transfer all of it in one go...
|
|
|
|
*/
|
2009-06-28 15:22:55 +08:00
|
|
|
ret = sdio_memcpy_fromio(smsdev->func,
|
|
|
|
buffer,
|
|
|
|
SMSSDIO_DATA,
|
|
|
|
size);
|
2009-03-28 01:16:57 +08:00
|
|
|
if (ret && ret != -EINVAL) {
|
|
|
|
smscore_putbuffer(smsdev->coredev, cb);
|
2009-06-28 15:22:55 +08:00
|
|
|
sms_err("Error %d reading data from card!\n", ret);
|
2009-03-28 01:16:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ..then fall back to one block at a time if that is
|
|
|
|
* not possible...
|
|
|
|
*
|
|
|
|
* (we have to do this manually because of the
|
|
|
|
* problem with the "increase address" bit)
|
|
|
|
*/
|
|
|
|
if (ret == -EINVAL) {
|
|
|
|
while (size) {
|
2009-06-28 15:22:55 +08:00
|
|
|
ret = sdio_memcpy_fromio(smsdev->func,
|
|
|
|
buffer, SMSSDIO_DATA,
|
|
|
|
smsdev->func->cur_blksize);
|
2009-03-28 01:16:57 +08:00
|
|
|
if (ret) {
|
|
|
|
smscore_putbuffer(smsdev->coredev, cb);
|
2009-06-28 15:22:55 +08:00
|
|
|
sms_err("Error %d reading "
|
2009-03-28 01:16:57 +08:00
|
|
|
"data from card!\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer += smsdev->func->cur_blksize;
|
|
|
|
if (size > smsdev->func->cur_blksize)
|
|
|
|
size -= smsdev->func->cur_blksize;
|
|
|
|
else
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-21 19:49:43 +08:00
|
|
|
cb->size = hdr->msg_length;
|
2009-03-28 01:16:57 +08:00
|
|
|
cb->offset = 0;
|
|
|
|
|
2013-03-21 19:49:43 +08:00
|
|
|
smsendian_handle_rx_message((struct sms_msg_data *) cb->p);
|
2009-03-28 01:16:57 +08:00
|
|
|
smscore_onresponse(smsdev->coredev, cb);
|
|
|
|
}
|
|
|
|
|
2012-12-22 05:17:53 +08:00
|
|
|
static int smssdio_probe(struct sdio_func *func,
|
2009-03-28 01:16:57 +08:00
|
|
|
const struct sdio_device_id *id)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
int board_id;
|
|
|
|
struct smssdio_device *smsdev;
|
|
|
|
struct smsdevice_params_t params;
|
|
|
|
|
|
|
|
board_id = id->driver_data;
|
|
|
|
|
|
|
|
smsdev = kzalloc(sizeof(struct smssdio_device), GFP_KERNEL);
|
|
|
|
if (!smsdev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
smsdev->func = func;
|
|
|
|
|
|
|
|
memset(¶ms, 0, sizeof(struct smsdevice_params_t));
|
|
|
|
|
|
|
|
params.device = &func->dev;
|
|
|
|
params.buffer_size = 0x5000; /* ?? */
|
|
|
|
params.num_buffers = 22; /* ?? */
|
|
|
|
params.context = smsdev;
|
|
|
|
|
|
|
|
snprintf(params.devpath, sizeof(params.devpath),
|
|
|
|
"sdio\\%s", sdio_func_id(func));
|
|
|
|
|
|
|
|
params.sendrequest_handler = smssdio_sendrequest;
|
|
|
|
|
|
|
|
params.device_type = sms_get_board(board_id)->type;
|
|
|
|
|
|
|
|
if (params.device_type != SMS_STELLAR)
|
|
|
|
params.flags |= SMS_DEVICE_FAMILY2;
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* FIXME: Stellar needs special handling...
|
|
|
|
*/
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = smscore_register_device(¶ms, &smsdev->coredev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto free;
|
|
|
|
|
|
|
|
smscore_set_board_id(smsdev->coredev, board_id);
|
|
|
|
|
|
|
|
sdio_claim_host(func);
|
|
|
|
|
|
|
|
ret = sdio_enable_func(func);
|
|
|
|
if (ret)
|
|
|
|
goto release;
|
|
|
|
|
2009-06-28 15:22:55 +08:00
|
|
|
ret = sdio_set_block_size(func, SMSSDIO_BLOCK_SIZE);
|
2009-03-28 01:16:57 +08:00
|
|
|
if (ret)
|
|
|
|
goto disable;
|
|
|
|
|
|
|
|
ret = sdio_claim_irq(func, smssdio_interrupt);
|
|
|
|
if (ret)
|
|
|
|
goto disable;
|
|
|
|
|
|
|
|
sdio_set_drvdata(func, smsdev);
|
|
|
|
|
|
|
|
sdio_release_host(func);
|
|
|
|
|
|
|
|
ret = smscore_start_device(smsdev->coredev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto reclaim;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
reclaim:
|
|
|
|
sdio_claim_host(func);
|
|
|
|
sdio_release_irq(func);
|
|
|
|
disable:
|
|
|
|
sdio_disable_func(func);
|
|
|
|
release:
|
|
|
|
sdio_release_host(func);
|
|
|
|
smscore_unregister_device(smsdev->coredev);
|
|
|
|
free:
|
|
|
|
kfree(smsdev);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smssdio_remove(struct sdio_func *func)
|
|
|
|
{
|
|
|
|
struct smssdio_device *smsdev;
|
|
|
|
|
|
|
|
smsdev = sdio_get_drvdata(func);
|
|
|
|
|
|
|
|
/* FIXME: racy! */
|
|
|
|
if (smsdev->split_cb)
|
|
|
|
smscore_putbuffer(smsdev->coredev, smsdev->split_cb);
|
|
|
|
|
|
|
|
smscore_unregister_device(smsdev->coredev);
|
|
|
|
|
|
|
|
sdio_claim_host(func);
|
|
|
|
sdio_release_irq(func);
|
|
|
|
sdio_disable_func(func);
|
|
|
|
sdio_release_host(func);
|
|
|
|
|
|
|
|
kfree(smsdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sdio_driver smssdio_driver = {
|
|
|
|
.name = "smssdio",
|
|
|
|
.id_table = smssdio_ids,
|
|
|
|
.probe = smssdio_probe,
|
|
|
|
.remove = smssdio_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
/* Module functions */
|
|
|
|
/*******************************************************************/
|
|
|
|
|
2009-12-12 07:05:10 +08:00
|
|
|
static int __init smssdio_module_init(void)
|
2009-03-28 01:16:57 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
printk(KERN_INFO "smssdio: Siano SMS1xxx SDIO driver\n");
|
|
|
|
printk(KERN_INFO "smssdio: Copyright Pierre Ossman\n");
|
|
|
|
|
|
|
|
ret = sdio_register_driver(&smssdio_driver);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-12 07:05:10 +08:00
|
|
|
static void __exit smssdio_module_exit(void)
|
2009-03-28 01:16:57 +08:00
|
|
|
{
|
|
|
|
sdio_unregister_driver(&smssdio_driver);
|
|
|
|
}
|
|
|
|
|
2009-05-19 22:15:01 +08:00
|
|
|
module_init(smssdio_module_init);
|
|
|
|
module_exit(smssdio_module_exit);
|
|
|
|
|
2009-03-28 01:16:57 +08:00
|
|
|
MODULE_DESCRIPTION("Siano SMS1xxx SDIO driver");
|
|
|
|
MODULE_AUTHOR("Pierre Ossman");
|
|
|
|
MODULE_LICENSE("GPL");
|