mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-09 08:02:05 +00:00
sdio: split up common and function CIS parsing
Add a more clean separation between global, common CIS information and the function specific one as we need the common information in places where no specific function is specified. Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
This commit is contained in:
parent
b1538bcf75
commit
1a632f8cdc
7 changed files with 206 additions and 27 deletions
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "sysfs.h"
|
#include "sysfs.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
#include "sdio_cis.h"
|
||||||
#include "bus.h"
|
#include "bus.h"
|
||||||
|
|
||||||
#define dev_to_mmc_card(d) container_of(d, struct mmc_card, dev)
|
#define dev_to_mmc_card(d) container_of(d, struct mmc_card, dev)
|
||||||
|
@ -181,6 +182,8 @@ static void mmc_release_card(struct device *dev)
|
||||||
{
|
{
|
||||||
struct mmc_card *card = dev_to_mmc_card(dev);
|
struct mmc_card *card = dev_to_mmc_card(dev);
|
||||||
|
|
||||||
|
sdio_free_common_cis(card);
|
||||||
|
|
||||||
kfree(card);
|
kfree(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ static int sdio_init_func(struct mmc_card *card, unsigned int fn)
|
||||||
if (ret)
|
if (ret)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
ret = sdio_read_cis(func);
|
ret = sdio_read_func_cis(func);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
@ -286,6 +286,13 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
|
||||||
if (err)
|
if (err)
|
||||||
goto remove;
|
goto remove;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read the common CIS tuples.
|
||||||
|
*/
|
||||||
|
err = sdio_read_common_cis(card);
|
||||||
|
if (err)
|
||||||
|
goto remove;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize (but don't add) all present functions.
|
* Initialize (but don't add) all present functions.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -95,7 +95,7 @@ static void sdio_release_func(struct device *dev)
|
||||||
{
|
{
|
||||||
struct sdio_func *func = dev_to_sdio_func(dev);
|
struct sdio_func *func = dev_to_sdio_func(dev);
|
||||||
|
|
||||||
sdio_free_cis(func);
|
sdio_free_func_cis(func);
|
||||||
|
|
||||||
kfree(func);
|
kfree(func);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,60 +16,152 @@
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
|
|
||||||
#include <linux/mmc/host.h>
|
#include <linux/mmc/host.h>
|
||||||
|
#include <linux/mmc/card.h>
|
||||||
#include <linux/mmc/sdio.h>
|
#include <linux/mmc/sdio.h>
|
||||||
#include <linux/mmc/sdio_func.h>
|
#include <linux/mmc/sdio_func.h>
|
||||||
|
|
||||||
#include "sdio_cis.h"
|
#include "sdio_cis.h"
|
||||||
#include "sdio_ops.h"
|
#include "sdio_ops.h"
|
||||||
|
|
||||||
static int cistpl_manfid(struct sdio_func *func,
|
static int cistpl_manfid(struct mmc_card *card, struct sdio_func *func,
|
||||||
const unsigned char *buf,
|
const unsigned char *buf, unsigned size)
|
||||||
unsigned size)
|
|
||||||
{
|
{
|
||||||
|
unsigned int vendor, device;
|
||||||
|
|
||||||
/* TPLMID_MANF */
|
/* TPLMID_MANF */
|
||||||
func->vendor = buf[0] | (buf[1] << 8);
|
vendor = buf[0] | (buf[1] << 8);
|
||||||
|
|
||||||
/* TPLMID_CARD */
|
/* TPLMID_CARD */
|
||||||
func->device = buf[2] | (buf[3] << 8);
|
device = buf[2] | (buf[3] << 8);
|
||||||
|
|
||||||
|
if (func) {
|
||||||
|
func->vendor = vendor;
|
||||||
|
func->device = device;
|
||||||
|
} else {
|
||||||
|
card->cis.vendor = vendor;
|
||||||
|
card->cis.device = device;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const unsigned char speed_val[16] =
|
||||||
|
{ 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 };
|
||||||
|
static const unsigned int speed_unit[8] =
|
||||||
|
{ 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
static int cistpl_funce_common(struct mmc_card *card,
|
||||||
|
const unsigned char *buf, unsigned size)
|
||||||
|
{
|
||||||
|
if (size < 0x04 || buf[0] != 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
/* TPLFE_FN0_BLK_SIZE */
|
||||||
|
card->cis.blksize = buf[1] | (buf[2] << 8);
|
||||||
|
|
||||||
|
/* TPLFE_MAX_TRAN_SPEED */
|
||||||
|
card->cis.max_dtr = speed_val[(buf[3] >> 3) & 15] *
|
||||||
|
speed_unit[buf[3] & 7];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cistpl_funce_func(struct sdio_func *func,
|
||||||
|
const unsigned char *buf, unsigned size)
|
||||||
|
{
|
||||||
|
unsigned vsn;
|
||||||
|
unsigned min_size;
|
||||||
|
|
||||||
|
vsn = func->card->cccr.sdio_vsn;
|
||||||
|
min_size = (vsn == SDIO_SDIO_REV_1_00) ? 28 : 42;
|
||||||
|
|
||||||
|
if (size < min_size || buf[0] != 1)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
/* TPLFE_MAX_BLK_SIZE */
|
||||||
|
func->blksize = buf[12] | (buf[13] << 8);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cistpl_funce(struct mmc_card *card, struct sdio_func *func,
|
||||||
|
const unsigned char *buf, unsigned size)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* There should be two versions of the CISTPL_FUNCE tuple,
|
||||||
|
* one for the common CIS (function 0) and a version used by
|
||||||
|
* the individual function's CIS (1-7). Yet, the later has a
|
||||||
|
* different length depending on the SDIO spec version.
|
||||||
|
*/
|
||||||
|
if (func)
|
||||||
|
ret = cistpl_funce_func(func, buf, size);
|
||||||
|
else
|
||||||
|
ret = cistpl_funce_common(card, buf, size);
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
printk(KERN_ERR "%s: bad CISTPL_FUNCE size %u "
|
||||||
|
"type %u\n", mmc_hostname(card->host), size, buf[0]);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef int (tpl_parse_t)(struct mmc_card *, struct sdio_func *,
|
||||||
|
const unsigned char *, unsigned);
|
||||||
|
|
||||||
struct cis_tpl {
|
struct cis_tpl {
|
||||||
unsigned char code;
|
unsigned char code;
|
||||||
unsigned char min_size;
|
unsigned char min_size;
|
||||||
int (*parse)(struct sdio_func *, const unsigned char *buf, unsigned size);
|
tpl_parse_t *parse;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct cis_tpl cis_tpl_list[] = {
|
static const struct cis_tpl cis_tpl_list[] = {
|
||||||
{ 0x15, 3, /* cistpl_vers_1 */ },
|
{ 0x15, 3, /* cistpl_vers_1 */ },
|
||||||
{ 0x20, 4, cistpl_manfid },
|
{ 0x20, 4, cistpl_manfid },
|
||||||
{ 0x21, 2, /* cistpl_funcid */ },
|
{ 0x21, 2, /* cistpl_funcid */ },
|
||||||
{ 0x22, 0, /* cistpl_funce */ },
|
{ 0x22, 0, cistpl_funce },
|
||||||
};
|
};
|
||||||
|
|
||||||
int sdio_read_cis(struct sdio_func *func)
|
static int sdio_read_cis(struct mmc_card *card, struct sdio_func *func)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct sdio_func_tuple *this, **prev;
|
struct sdio_func_tuple *this, **prev;
|
||||||
unsigned i, ptr = 0;
|
unsigned i, ptr = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note that this works for the common CIS (function number 0) as
|
||||||
|
* well as a function's CIS * since SDIO_CCCR_CIS and SDIO_FBR_CIS
|
||||||
|
* have the same offset.
|
||||||
|
*/
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
unsigned char x;
|
unsigned char x, fn;
|
||||||
ret = mmc_io_rw_direct(func->card, 0, 0,
|
|
||||||
func->num * 0x100 + SDIO_FBR_CIS + i, 0, &x);
|
if (func)
|
||||||
|
fn = func->num;
|
||||||
|
else
|
||||||
|
fn = 0;
|
||||||
|
|
||||||
|
ret = mmc_io_rw_direct(card, 0, 0,
|
||||||
|
fn * 0x100 + SDIO_FBR_CIS + i, 0, &x);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
ptr |= x << (i * 8);
|
ptr |= x << (i * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find the list tail */
|
if (func)
|
||||||
for (prev = &func->tuples; *prev; prev = &(*prev)->next);
|
prev = &func->tuples;
|
||||||
|
else
|
||||||
|
prev = &card->tuples;
|
||||||
|
|
||||||
|
BUG_ON(*prev);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
unsigned char tpl_code, tpl_link;
|
unsigned char tpl_code, tpl_link;
|
||||||
|
|
||||||
ret = mmc_io_rw_direct(func->card, 0, 0, ptr++, 0, &tpl_code);
|
ret = mmc_io_rw_direct(card, 0, 0, ptr++, 0, &tpl_code);
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -77,7 +169,7 @@ int sdio_read_cis(struct sdio_func *func)
|
||||||
if (tpl_code == 0xff)
|
if (tpl_code == 0xff)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ret = mmc_io_rw_direct(func->card, 0, 0, ptr++, 0, &tpl_link);
|
ret = mmc_io_rw_direct(card, 0, 0, ptr++, 0, &tpl_link);
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -86,7 +178,7 @@ int sdio_read_cis(struct sdio_func *func)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
for (i = 0; i < tpl_link; i++) {
|
for (i = 0; i < tpl_link; i++) {
|
||||||
ret = mmc_io_rw_direct(func->card, 0, 0,
|
ret = mmc_io_rw_direct(card, 0, 0,
|
||||||
ptr + i, 0, &this->data[i]);
|
ptr + i, 0, &this->data[i]);
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
|
@ -108,30 +200,45 @@ int sdio_read_cis(struct sdio_func *func)
|
||||||
prev = &this->next;
|
prev = &this->next;
|
||||||
printk(KERN_DEBUG
|
printk(KERN_DEBUG
|
||||||
"%s: queuing CIS tuple 0x%02x length %u\n",
|
"%s: queuing CIS tuple 0x%02x length %u\n",
|
||||||
sdio_func_id(func), tpl_code, tpl_link);
|
mmc_hostname(card->host), tpl_code, tpl_link);
|
||||||
} else {
|
} else {
|
||||||
const struct cis_tpl *tpl = cis_tpl_list + i;
|
const struct cis_tpl *tpl = cis_tpl_list + i;
|
||||||
if (tpl_link < tpl->min_size) {
|
if (tpl_link < tpl->min_size) {
|
||||||
printk(KERN_ERR
|
printk(KERN_ERR
|
||||||
"%s: bad CIS tuple 0x%02x (length = %u, expected >= %u)\n",
|
"%s: bad CIS tuple 0x%02x (length = %u, expected >= %u)\n",
|
||||||
sdio_func_id(func), tpl_code, tpl_link, tpl->min_size);
|
mmc_hostname(card->host),
|
||||||
|
tpl_code, tpl_link, tpl->min_size);
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
} else if (tpl->parse)
|
} else if (tpl->parse) {
|
||||||
ret = tpl->parse(func, this->data, tpl_link);
|
ret = tpl->parse(card, func,
|
||||||
|
this->data, tpl_link);
|
||||||
|
}
|
||||||
kfree(this);
|
kfree(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr += tpl_link;
|
ptr += tpl_link;
|
||||||
} while (!ret);
|
} while (!ret);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Link in all unknown tuples found in the common CIS so that
|
||||||
|
* drivers don't have to go digging in two places.
|
||||||
|
*/
|
||||||
|
if (func)
|
||||||
|
*prev = card->tuples;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdio_free_cis(struct sdio_func *func)
|
int sdio_read_common_cis(struct mmc_card *card)
|
||||||
|
{
|
||||||
|
return sdio_read_cis(card, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sdio_free_common_cis(struct mmc_card *card)
|
||||||
{
|
{
|
||||||
struct sdio_func_tuple *tuple, *victim;
|
struct sdio_func_tuple *tuple, *victim;
|
||||||
|
|
||||||
tuple = func->tuples;
|
tuple = card->tuples;
|
||||||
|
|
||||||
while (tuple) {
|
while (tuple) {
|
||||||
victim = tuple;
|
victim = tuple;
|
||||||
|
@ -139,6 +246,53 @@ void sdio_free_cis(struct sdio_func *func)
|
||||||
kfree(victim);
|
kfree(victim);
|
||||||
}
|
}
|
||||||
|
|
||||||
func->tuples = NULL;
|
card->tuples = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sdio_read_func_cis(struct sdio_func *func)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = sdio_read_cis(func->card, func);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Since we've linked to tuples in the card structure,
|
||||||
|
* we must make sure we have a reference to it.
|
||||||
|
*/
|
||||||
|
get_device(&func->card->dev);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Vendor/device id is optional for function CIS, so
|
||||||
|
* copy it from the card structure as needed.
|
||||||
|
*/
|
||||||
|
if (func->vendor == 0) {
|
||||||
|
func->vendor = func->card->cis.vendor;
|
||||||
|
func->device = func->card->cis.device;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sdio_free_func_cis(struct sdio_func *func)
|
||||||
|
{
|
||||||
|
struct sdio_func_tuple *tuple, *victim;
|
||||||
|
|
||||||
|
tuple = func->tuples;
|
||||||
|
|
||||||
|
while (tuple && tuple != func->card->tuples) {
|
||||||
|
victim = tuple;
|
||||||
|
tuple = tuple->next;
|
||||||
|
kfree(victim);
|
||||||
|
}
|
||||||
|
|
||||||
|
func->tuples = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We have now removed the link to the tuples in the
|
||||||
|
* card structure, so remove the reference.
|
||||||
|
*/
|
||||||
|
put_device(&func->card->dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,10 @@
|
||||||
#ifndef _MMC_SDIO_CIS_H
|
#ifndef _MMC_SDIO_CIS_H
|
||||||
#define _MMC_SDIO_CIS_H
|
#define _MMC_SDIO_CIS_H
|
||||||
|
|
||||||
int sdio_read_cis(struct sdio_func *func);
|
int sdio_read_common_cis(struct mmc_card *card);
|
||||||
void sdio_free_cis(struct sdio_func *func);
|
void sdio_free_common_cis(struct mmc_card *card);
|
||||||
|
|
||||||
|
int sdio_read_func_cis(struct sdio_func *func);
|
||||||
|
void sdio_free_func_cis(struct sdio_func *func);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -65,8 +65,16 @@ struct sdio_cccr {
|
||||||
high_speed:1;
|
high_speed:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct sdio_cis {
|
||||||
|
unsigned short vendor;
|
||||||
|
unsigned short device;
|
||||||
|
unsigned short blksize;
|
||||||
|
unsigned int max_dtr;
|
||||||
|
};
|
||||||
|
|
||||||
struct mmc_host;
|
struct mmc_host;
|
||||||
struct sdio_func;
|
struct sdio_func;
|
||||||
|
struct sdio_func_tuple;
|
||||||
|
|
||||||
#define SDIO_MAX_FUNCS 7
|
#define SDIO_MAX_FUNCS 7
|
||||||
|
|
||||||
|
@ -98,7 +106,9 @@ struct mmc_card {
|
||||||
|
|
||||||
unsigned int sdio_funcs; /* number of SDIO functions */
|
unsigned int sdio_funcs; /* number of SDIO functions */
|
||||||
struct sdio_cccr cccr; /* common card info */
|
struct sdio_cccr cccr; /* common card info */
|
||||||
|
struct sdio_cis cis; /* common tuple info */
|
||||||
struct sdio_func *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */
|
struct sdio_func *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */
|
||||||
|
struct sdio_func_tuple *tuples; /* unknown common tuples */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
|
#define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
|
||||||
|
|
|
@ -36,6 +36,8 @@ struct sdio_func {
|
||||||
unsigned short vendor; /* vendor id */
|
unsigned short vendor; /* vendor id */
|
||||||
unsigned short device; /* device id */
|
unsigned short device; /* device id */
|
||||||
|
|
||||||
|
unsigned short blksize; /* maximum block size */
|
||||||
|
|
||||||
unsigned int state; /* function state */
|
unsigned int state; /* function state */
|
||||||
#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */
|
#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue