2 * linux/drivers/mmc/core/sdio_cis.c
4 * Author: Nicolas Pitre
5 * Created: June 11, 2007
6 * Copyright: MontaVista Software Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
14 #include <linux/kernel.h>
16 #include <linux/mmc/host.h>
17 #include <linux/mmc/sdio.h>
18 #include <linux/mmc/sdio_func.h>
23 static int cistpl_manfid(struct sdio_func *func,
24 const unsigned char *buf,
28 func->vendor = buf[0] | (buf[1] << 8);
31 func->device = buf[2] | (buf[3] << 8);
38 unsigned char min_size;
39 int (*parse)(struct sdio_func *, const unsigned char *buf, unsigned size);
42 static const struct cis_tpl cis_tpl_list[] = {
43 { 0x15, 3, /* cistpl_vers_1 */ },
44 { 0x20, 4, cistpl_manfid },
45 { 0x21, 2, /* cistpl_funcid */ },
46 { 0x22, 0, /* cistpl_funce */ },
49 int sdio_read_cis(struct sdio_func *func)
55 for (i = 0; i < 3; i++) {
57 ret = mmc_io_rw_direct(func->card, 0, 0,
58 func->num * 0x100 + SDIO_FBR_CIS + i, 0, &x);
64 buf = kmalloc(256, GFP_KERNEL);
69 unsigned char tpl_code, tpl_link;
70 const struct cis_tpl *tpl;
72 ret = mmc_io_rw_direct(func->card, 0, 0, ptr++, 0, &tpl_code);
76 /* 0xff means we're done */
80 ret = mmc_io_rw_direct(func->card, 0, 0, ptr++, 0, &tpl_link);
84 for (i = 0; i < ARRAY_SIZE(cis_tpl_list); i++)
85 if (cis_tpl_list[i].code == tpl_code)
87 if (i >= ARRAY_SIZE(cis_tpl_list)) {
89 "%s: unknown CIS tuple 0x%02x of length %u\n",
90 sdio_func_id(func), tpl_code, tpl_link);
94 tpl = cis_tpl_list + i;
96 if (tpl_link < tpl->min_size) {
98 "%s: bad CIS tuple 0x%02x (length = %u, expected >= %u\n",
99 sdio_func_id(func), tpl_code, tpl_link, tpl->min_size);
104 for (i = 0; i < tpl_link; i++) {
105 ret = mmc_io_rw_direct(func->card, 0, 0, ptr + i, 0, &buf[i]);
114 ret = tpl->parse(func, buf, tpl_link);