提交 2ffe8c5f 编写于 作者: G Grant Likely

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: NGrant Likely <grant.likely@secretlab.ca>
上级 959e85f7
...@@ -160,10 +160,16 @@ static const struct i2c_device_id mcu_ids[] = { ...@@ -160,10 +160,16 @@ static const struct i2c_device_id mcu_ids[] = {
}; };
MODULE_DEVICE_TABLE(i2c, 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 = { static struct i2c_driver mcu_driver = {
.driver = { .driver = {
.name = "mcu-mpc8349emitx", .name = "mcu-mpc8349emitx",
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = mcu_of_match_table,
}, },
.probe = mcu_probe, .probe = mcu_probe,
.remove = __devexit_p(mcu_remove), .remove = __devexit_p(mcu_remove),
......
...@@ -1533,12 +1533,20 @@ static int __devexit mmc_spi_remove(struct spi_device *spi) ...@@ -1533,12 +1533,20 @@ static int __devexit mmc_spi_remove(struct spi_device *spi)
return 0; 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 = { static struct spi_driver mmc_spi_driver = {
.driver = { .driver = {
.name = "mmc_spi", .name = "mmc_spi",
.bus = &spi_bus_type, .bus = &spi_bus_type,
.owner = THIS_MODULE, .owner = THIS_MODULE,
#if defined(CONFIG_OF)
.of_match_table = mmc_spi_of_match_table,
#endif
}, },
.probe = mmc_spi_probe, .probe = mmc_spi_probe,
.remove = __devexit_p(mmc_spi_remove), .remove = __devexit_p(mmc_spi_remove),
......
...@@ -544,75 +544,29 @@ struct device_node *of_find_matching_node(struct device_node *from, ...@@ -544,75 +544,29 @@ struct device_node *of_find_matching_node(struct device_node *from,
} }
EXPORT_SYMBOL(of_find_matching_node); 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 * of_modalias_node - Lookup appropriate modalias for a device node
* @node: pointer to a device tree node * @node: pointer to a device tree node
* @modalias: Pointer to buffer that modalias value will be copied into * @modalias: Pointer to buffer that modalias value will be copied into
* @len: Length of modalias value * @len: Length of modalias value
* *
* Based on the value of the compatible property, this routine will determine * Based on the value of the compatible property, this routine will attempt
* an appropriate modalias value for a particular device tree node. Two * to choose an appropriate modalias value for a particular device tree node.
* separate methods are attempted to derive a modalias value. * 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. * This routine returns 0 on success, <0 on failure.
* 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
*/ */
int of_modalias_node(struct device_node *node, char *modalias, int len) int of_modalias_node(struct device_node *node, char *modalias, int len)
{ {
int i, cplen; const char *compatible, *p;
const char *compatible; int cplen;
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;
}
compatible = of_get_property(node, "compatible", &cplen); compatible = of_get_property(node, "compatible", &cplen);
if (!compatible) if (!compatible || strlen(compatible) > cplen)
return -ENODEV; return -ENODEV;
/* 2. take first compatible entry and strip manufacturer */
p = strchr(compatible, ','); p = strchr(compatible, ',');
if (!p) strlcpy(modalias, p ? p + 1 : compatible, len);
return -ENODEV;
p++;
strlcpy(modalias, p, len);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(of_modalias_node); EXPORT_SYMBOL_GPL(of_modalias_node);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册