aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/base.c
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-06-08 09:48:19 -0400
committerGrant Likely <grant.likely@secretlab.ca>2010-07-05 18:14:52 -0400
commit2ffe8c5f323c3b9749bf7bc2375d909d20bdbb15 (patch)
treeffbaba1c737fa5da32d9c1a503e58d2896f10be6 /drivers/of/base.c
parent959e85f7751c33d1a2dabc5cc3fe2ed0db7052e5 (diff)
of: refactor of_modalias_node() and remove explicit match table.
This patch tightens up the behaviour of of_modalias_node() to be more predicatable and to eliminate the explicit of_modalias_tablep[] that is currently used to override the first entry in the compatible list of a device. The override table was needed originally because spi and i2c drivers had no way to do of-style matching. Now that all devices can have an of_node pointer, and all drivers can have an of_match_table, the explicit override table is no longer needed because each driver can specify its own OF-style match data. The mpc8349emitx-mcu driver is modified to explicitly specify the correct device to bind against. Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r--drivers/of/base.c64
1 files changed, 9 insertions, 55 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index b5ad9740d8b2..e3f7af882e45 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -545,74 +545,28 @@ struct device_node *of_find_matching_node(struct device_node *from,
545EXPORT_SYMBOL(of_find_matching_node); 545EXPORT_SYMBOL(of_find_matching_node);
546 546
547/** 547/**
548 * of_modalias_table: Table of explicit compatible ==> modalias mappings
549 *
550 * This table allows particulare compatible property values to be mapped
551 * to modalias strings. This is useful for busses which do not directly
552 * understand the OF device tree but are populated based on data contained
553 * within the device tree. SPI and I2C are the two current users of this
554 * table.
555 *
556 * In most cases, devices do not need to be listed in this table because
557 * the modalias value can be derived directly from the compatible table.
558 * However, if for any reason a value cannot be derived, then this table
559 * provides a method to override the implicit derivation.
560 *
561 * At the moment, a single table is used for all bus types because it is
562 * assumed that the data size is small and that the compatible values
563 * should already be distinct enough to differentiate between SPI, I2C
564 * and other devices.
565 */
566struct of_modalias_table {
567 char *of_device;
568 char *modalias;
569};
570static struct of_modalias_table of_modalias_table[] = {
571 { "fsl,mcu-mpc8349emitx", "mcu-mpc8349emitx" },
572 { "mmc-spi-slot", "mmc_spi" },
573};
574
575/**
576 * of_modalias_node - Lookup appropriate modalias for a device node 548 * of_modalias_node - Lookup appropriate modalias for a device node
577 * @node: pointer to a device tree node 549 * @node: pointer to a device tree node
578 * @modalias: Pointer to buffer that modalias value will be copied into 550 * @modalias: Pointer to buffer that modalias value will be copied into
579 * @len: Length of modalias value 551 * @len: Length of modalias value
580 * 552 *
581 * Based on the value of the compatible property, this routine will determine 553 * Based on the value of the compatible property, this routine will attempt
582 * an appropriate modalias value for a particular device tree node. Two 554 * to choose an appropriate modalias value for a particular device tree node.
583 * separate methods are attempted to derive a modalias value. 555 * It does this by stripping the manufacturer prefix (as delimited by a ',')
556 * from the first entry in the compatible list property.
584 * 557 *
585 * First method is to lookup the compatible value in of_modalias_table. 558 * This routine returns 0 on success, <0 on failure.
586 * Second is to strip off the manufacturer prefix from the first
587 * compatible entry and use the remainder as modalias
588 *
589 * This routine returns 0 on success
590 */ 559 */
591int of_modalias_node(struct device_node *node, char *modalias, int len) 560int of_modalias_node(struct device_node *node, char *modalias, int len)
592{ 561{
593 int i, cplen; 562 const char *compatible, *p;
594 const char *compatible; 563 int cplen;
595 const char *p;
596
597 /* 1. search for exception list entry */
598 for (i = 0; i < ARRAY_SIZE(of_modalias_table); i++) {
599 compatible = of_modalias_table[i].of_device;
600 if (!of_device_is_compatible(node, compatible))
601 continue;
602 strlcpy(modalias, of_modalias_table[i].modalias, len);
603 return 0;
604 }
605 564
606 compatible = of_get_property(node, "compatible", &cplen); 565 compatible = of_get_property(node, "compatible", &cplen);
607 if (!compatible) 566 if (!compatible || strlen(compatible) > cplen)
608 return -ENODEV; 567 return -ENODEV;
609
610 /* 2. take first compatible entry and strip manufacturer */
611 p = strchr(compatible, ','); 568 p = strchr(compatible, ',');
612 if (!p) 569 strlcpy(modalias, p ? p + 1 : compatible, len);
613 return -ENODEV;
614 p++;
615 strlcpy(modalias, p, len);
616 return 0; 570 return 0;
617} 571}
618EXPORT_SYMBOL_GPL(of_modalias_node); 572EXPORT_SYMBOL_GPL(of_modalias_node);