diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-05-30 16:31:14 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-05-31 18:19:11 +0200 |
commit | ea9c911b8f2d72aa076295f4a828597a3ce163de (patch) | |
tree | 8680867b78d005d55db1016e69d9fa4744387ce1 /drivers/mci/mci-core.c | |
parent | 0ea008e15b4ccd8a27e4e23d3ce0466f69e7ed24 (diff) | |
download | barebox-ea9c911b8f2d72aa076295f4a828597a3ce163de.tar.gz barebox-ea9c911b8f2d72aa076295f4a828597a3ce163de.tar.xz |
mci: Add devicetree helper function
This adds helper code to parse the bus-width and max-frequency
property from devicetree.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mci/mci-core.c')
-rw-r--r-- | drivers/mci/mci-core.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c index 50068a7741..ce568df706 100644 --- a/drivers/mci/mci-core.c +++ b/drivers/mci/mci-core.c @@ -1671,3 +1671,41 @@ err_free: return ret; } + +void mci_of_parse(struct mci_host *host) +{ + struct device_node *np; + u32 bus_width; + + if (!IS_ENABLED(CONFIG_OFDEVICE)) + return; + + if (!host->hw_dev || !host->hw_dev->device_node) + return; + + np = host->hw_dev->device_node; + + /* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */ + if (of_property_read_u32(np, "bus-width", &bus_width) < 0) { + dev_dbg(host->hw_dev, + "\"bus-width\" property is missing, assuming 1 bit.\n"); + bus_width = 1; + } + + switch (bus_width) { + case 8: + host->host_caps |= MMC_MODE_8BIT; + /* Hosts capable of 8-bit transfers can also do 4 bits */ + case 4: + host->host_caps |= MMC_MODE_4BIT; + break; + case 1: + break; + default: + dev_err(host->hw_dev, + "Invalid \"bus-width\" value %ud!\n", bus_width); + } + + /* f_max is obtained from the optional "max-frequency" property */ + of_property_read_u32(np, "max-frequency", &host->f_max); +} |