diff options
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 |