diff options
author | Dominik Brodowski <linux@dominikbrodowski.net> | 2009-10-18 17:32:33 -0400 |
---|---|---|
committer | Dominik Brodowski <linux@dominikbrodowski.net> | 2009-11-08 12:06:54 -0500 |
commit | 91284224da5b15ec6c2b45e10fa5eccd1c92a204 (patch) | |
tree | e070902f5119b2eacf79d91cd36de98e3ae8423c /drivers/pcmcia/cistpl.c | |
parent | af757923a92e6e9dbfdb6b0264be14c564e1c466 (diff) |
pcmcia: add new CIS access helpers
As a replacement to pcmcia_get_{first,next}_tuple() and
pcmcia_get_tuple_data(), three new -- and easier to use --
functions are added:
- pcmcia_get_tuple() to get the very first CIS entry of one
type.
- pcmcia_loop_tuple() to loop over all CIS entries of one type.
- pcmcia_get_mac_from_cis() to read out the hardware MAC address
from CISTPL_FUNCE.
Only a handful of drivers need these functions anyway, as most
CIS access is already handled by pcmcia_loop_config(), which
now shares the same backed (pccard_loop_tuple()) with
pcmcia_loop_tuple().
A pcmcia_get_mac_from_cis() bug noted by Komuro
<komurojun-mbn@nifty.com> has been fixed in this revision.
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'drivers/pcmcia/cistpl.c')
-rw-r--r-- | drivers/pcmcia/cistpl.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 6c4a4fc83630..24dd3c1eac0b 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c | |||
@@ -1482,6 +1482,67 @@ done: | |||
1482 | } | 1482 | } |
1483 | EXPORT_SYMBOL(pccard_read_tuple); | 1483 | EXPORT_SYMBOL(pccard_read_tuple); |
1484 | 1484 | ||
1485 | |||
1486 | /** | ||
1487 | * pccard_loop_tuple() - loop over tuples in the CIS | ||
1488 | * @s: the struct pcmcia_socket where the card is inserted | ||
1489 | * @function: the device function we loop for | ||
1490 | * @code: which CIS code shall we look for? | ||
1491 | * @parse: buffer where the tuple shall be parsed (or NULL, if no parse) | ||
1492 | * @priv_data: private data to be passed to the loop_tuple function. | ||
1493 | * @loop_tuple: function to call for each CIS entry of type @function. IT | ||
1494 | * gets passed the raw tuple, the paresed tuple (if @parse is | ||
1495 | * set) and @priv_data. | ||
1496 | * | ||
1497 | * pccard_loop_tuple() loops over all CIS entries of type @function, and | ||
1498 | * calls the @loop_tuple function for each entry. If the call to @loop_tuple | ||
1499 | * returns 0, the loop exits. Returns 0 on success or errorcode otherwise. | ||
1500 | */ | ||
1501 | int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function, | ||
1502 | cisdata_t code, cisparse_t *parse, void *priv_data, | ||
1503 | int (*loop_tuple) (tuple_t *tuple, | ||
1504 | cisparse_t *parse, | ||
1505 | void *priv_data)) | ||
1506 | { | ||
1507 | tuple_t tuple; | ||
1508 | cisdata_t *buf; | ||
1509 | int ret; | ||
1510 | |||
1511 | buf = kzalloc(256, GFP_KERNEL); | ||
1512 | if (buf == NULL) { | ||
1513 | dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n"); | ||
1514 | return -ENOMEM; | ||
1515 | } | ||
1516 | |||
1517 | tuple.TupleData = buf; | ||
1518 | tuple.TupleDataMax = 255; | ||
1519 | tuple.TupleOffset = 0; | ||
1520 | tuple.DesiredTuple = code; | ||
1521 | tuple.Attributes = 0; | ||
1522 | |||
1523 | ret = pccard_get_first_tuple(s, function, &tuple); | ||
1524 | while (!ret) { | ||
1525 | if (pccard_get_tuple_data(s, &tuple)) | ||
1526 | goto next_entry; | ||
1527 | |||
1528 | if (parse) | ||
1529 | if (pcmcia_parse_tuple(&tuple, parse)) | ||
1530 | goto next_entry; | ||
1531 | |||
1532 | ret = loop_tuple(&tuple, parse, priv_data); | ||
1533 | if (!ret) | ||
1534 | break; | ||
1535 | |||
1536 | next_entry: | ||
1537 | ret = pccard_get_next_tuple(s, function, &tuple); | ||
1538 | } | ||
1539 | |||
1540 | kfree(buf); | ||
1541 | return ret; | ||
1542 | } | ||
1543 | EXPORT_SYMBOL(pccard_loop_tuple); | ||
1544 | |||
1545 | |||
1485 | /*====================================================================== | 1546 | /*====================================================================== |
1486 | 1547 | ||
1487 | This tries to determine if a card has a sensible CIS. It returns | 1548 | This tries to determine if a card has a sensible CIS. It returns |