]> git.kernelconcepts.de Git - mv-sheeva.git/commitdiff
of: refactor of_modalias_node() and remove explicit match table.
authorGrant Likely <grant.likely@secretlab.ca>
Tue, 8 Jun 2010 13:48:19 +0000 (07:48 -0600)
committerGrant Likely <grant.likely@secretlab.ca>
Mon, 5 Jul 2010 22:14:52 +0000 (16:14 -0600)
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>
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
drivers/mmc/host/mmc_spi.c
drivers/of/base.c

index 59b0ed1a56b1d18ffe86f8d8b00b21ef95212987..70798ac911ef056b73eba4fccce9db0c157b37e8 100644 (file)
@@ -160,10 +160,16 @@ static const struct i2c_device_id mcu_ids[] = {
 };
 MODULE_DEVICE_TABLE(i2c, mcu_ids);
 
+static struct of_device_id mcu_of_match_table[] __devinitdata = {
+       { .compatible = "fsl,mcu-mpc8349emitx", },
+       { },
+};
+
 static struct i2c_driver mcu_driver = {
        .driver = {
                .name = "mcu-mpc8349emitx",
                .owner = THIS_MODULE,
+               .of_match_table = mcu_of_match_table,
        },
        .probe = mcu_probe,
        .remove = __devexit_p(mcu_remove),
index ad847a24a6756f8f88ec97f6ea8031b8a7169842..7b0f3ef50f9650241918a24cd50f330b2c9c8701 100644 (file)
@@ -1533,12 +1533,20 @@ static int __devexit mmc_spi_remove(struct spi_device *spi)
        return 0;
 }
 
+#if defined(CONFIG_OF)
+static struct of_device_id mmc_spi_of_match_table[] __devinitdata = {
+       { .compatible = "mmc-spi-slot", },
+};
+#endif
 
 static struct spi_driver mmc_spi_driver = {
        .driver = {
                .name =         "mmc_spi",
                .bus =          &spi_bus_type,
                .owner =        THIS_MODULE,
+#if defined(CONFIG_OF)
+               .of_match_table = mmc_spi_of_match_table,
+#endif
        },
        .probe =        mmc_spi_probe,
        .remove =       __devexit_p(mmc_spi_remove),
index b5ad9740d8b21a6eb6b3e3f3bd1586e8a5645426..e3f7af882e455e47be73f3ccc07499eb94169068 100644 (file)
@@ -544,75 +544,29 @@ struct device_node *of_find_matching_node(struct device_node *from,
 }
 EXPORT_SYMBOL(of_find_matching_node);
 
-/**
- * of_modalias_table: Table of explicit compatible ==> modalias mappings
- *
- * This table allows particulare compatible property values to be mapped
- * to modalias strings.  This is useful for busses which do not directly
- * understand the OF device tree but are populated based on data contained
- * within the device tree.  SPI and I2C are the two current users of this
- * table.
- *
- * In most cases, devices do not need to be listed in this table because
- * the modalias value can be derived directly from the compatible table.
- * However, if for any reason a value cannot be derived, then this table
- * provides a method to override the implicit derivation.
- *
- * At the moment, a single table is used for all bus types because it is
- * assumed that the data size is small and that the compatible values
- * should already be distinct enough to differentiate between SPI, I2C
- * and other devices.
- */
-struct of_modalias_table {
-       char *of_device;
-       char *modalias;
-};
-static struct of_modalias_table of_modalias_table[] = {
-       { "fsl,mcu-mpc8349emitx", "mcu-mpc8349emitx" },
-       { "mmc-spi-slot", "mmc_spi" },
-};
-
 /**
  * of_modalias_node - Lookup appropriate modalias for a device node
  * @node:      pointer to a device tree node
  * @modalias:  Pointer to buffer that modalias value will be copied into
  * @len:       Length of modalias value
  *
- * Based on the value of the compatible property, this routine will determine
- * an appropriate modalias value for a particular device tree node.  Two
- * separate methods are attempted to derive a modalias value.
+ * Based on the value of the compatible property, this routine will attempt
+ * to choose an appropriate modalias value for a particular device tree node.
+ * It does this by stripping the manufacturer prefix (as delimited by a ',')
+ * from the first entry in the compatible list property.
  *
- * First method is to lookup the compatible value in of_modalias_table.
- * Second is to strip off the manufacturer prefix from the first
- * compatible entry and use the remainder as modalias
- *
- * This routine returns 0 on success
+ * This routine returns 0 on success, <0 on failure.
  */
 int of_modalias_node(struct device_node *node, char *modalias, int len)
 {
-       int i, cplen;
-       const char *compatible;
-       const char *p;
-
-       /* 1. search for exception list entry */
-       for (i = 0; i < ARRAY_SIZE(of_modalias_table); i++) {
-               compatible = of_modalias_table[i].of_device;
-               if (!of_device_is_compatible(node, compatible))
-                       continue;
-               strlcpy(modalias, of_modalias_table[i].modalias, len);
-               return 0;
-       }
+       const char *compatible, *p;
+       int cplen;
 
        compatible = of_get_property(node, "compatible", &cplen);
-       if (!compatible)
+       if (!compatible || strlen(compatible) > cplen)
                return -ENODEV;
-
-       /* 2. take first compatible entry and strip manufacturer */
        p = strchr(compatible, ',');
-       if (!p)
-               return -ENODEV;
-       p++;
-       strlcpy(modalias, p, len);
+       strlcpy(modalias, p ? p + 1 : compatible, len);
        return 0;
 }
 EXPORT_SYMBOL_GPL(of_modalias_node);