Commit 275173b2 authored by Grant Likely's avatar Grant Likely Committed by Chris Ball

mmc: sdhci-tegra: Add Device Tree probing support

Add hooks to read gpio configuration out of the device tree node.

[grant.likely: Rewrite of original patch from John Bonesio]
Signed-off-by: default avatarGrant Likely <grant.likely@secretlab.ca>
[swarren: Fixed tegra_sdhci_get_ro() to retrieve pdata correctly]
[swarren: Reworked to avoid #ifdef CONFIG_OF]
[swarren: Reworked binding based on fsl-imx-esdhc.txt]
[swarren: Documented binding]
Signed-off-by: default avatarStephen Warren <swarren@nvidia.com>
Signed-off-by: default avatarChris Ball <cjb@laptop.org>
parent 08da834a
* NVIDIA Tegra Secure Digital Host Controller
This controller on Tegra family SoCs provides an interface for MMC, SD,
and SDIO types of memory cards.
Required properties:
- compatible : Should be "nvidia,<chip>-sdhci"
- reg : Should contain eSDHC registers location and length
- interrupts : Should contain eSDHC interrupt
Optional properties:
- cd-gpios : Specify GPIOs for card detection
- wp-gpios : Specify GPIOs for write protection
- power-gpios : Specify GPIOs for power control
Example:
sdhci@c8000200 {
compatible = "nvidia,tegra20-sdhci";
reg = <0xc8000200 0x200>;
interrupts = <47>;
cd-gpios = <&gpio 69 0>; /* gpio PI5 */
wp-gpios = <&gpio 57 0>; /* gpio PH1 */
power-gpios = <&gpio 155 0>; /* gpio PT3 */
};
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/of_gpio.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/mmc/card.h> #include <linux/mmc/card.h>
#include <linux/mmc/host.h> #include <linux/mmc/host.h>
...@@ -73,10 +74,8 @@ static void tegra_sdhci_writel(struct sdhci_host *host, u32 val, int reg) ...@@ -73,10 +74,8 @@ static void tegra_sdhci_writel(struct sdhci_host *host, u32 val, int reg)
static unsigned int tegra_sdhci_get_ro(struct sdhci_host *sdhci) static unsigned int tegra_sdhci_get_ro(struct sdhci_host *sdhci)
{ {
struct platform_device *pdev = to_platform_device(mmc_dev(sdhci->mmc)); struct sdhci_pltfm_host *pltfm_host = sdhci_priv(sdhci);
struct tegra_sdhci_platform_data *plat; struct tegra_sdhci_platform_data *plat = pltfm_host->priv;
plat = pdev->dev.platform_data;
if (!gpio_is_valid(plat->wp_gpio)) if (!gpio_is_valid(plat->wp_gpio))
return -1; return -1;
...@@ -94,12 +93,10 @@ static irqreturn_t carddetect_irq(int irq, void *data) ...@@ -94,12 +93,10 @@ static irqreturn_t carddetect_irq(int irq, void *data)
static int tegra_sdhci_8bit(struct sdhci_host *host, int bus_width) static int tegra_sdhci_8bit(struct sdhci_host *host, int bus_width)
{ {
struct platform_device *pdev = to_platform_device(mmc_dev(host->mmc)); struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct tegra_sdhci_platform_data *plat; struct tegra_sdhci_platform_data *plat = pltfm_host->priv;
u32 ctrl; u32 ctrl;
plat = pdev->dev.platform_data;
ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
if (plat->is_8bit && bus_width == MMC_BUS_WIDTH_8) { if (plat->is_8bit && bus_width == MMC_BUS_WIDTH_8) {
ctrl &= ~SDHCI_CTRL_4BITBUS; ctrl &= ~SDHCI_CTRL_4BITBUS;
...@@ -131,6 +128,34 @@ static struct sdhci_pltfm_data sdhci_tegra_pdata = { ...@@ -131,6 +128,34 @@ static struct sdhci_pltfm_data sdhci_tegra_pdata = {
.ops = &tegra_sdhci_ops, .ops = &tegra_sdhci_ops,
}; };
static const struct of_device_id sdhci_tegra_dt_match[] __devinitdata = {
{ .compatible = "nvidia,tegra20-sdhci", },
{}
};
MODULE_DEVICE_TABLE(of, sdhci_dt_ids);
static struct tegra_sdhci_platform_data * __devinit sdhci_tegra_dt_parse_pdata(
struct platform_device *pdev)
{
struct tegra_sdhci_platform_data *plat;
struct device_node *np = pdev->dev.of_node;
if (!np)
return NULL;
plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
if (!plat) {
dev_err(&pdev->dev, "Can't allocate platform data\n");
return NULL;
}
plat->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0);
plat->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0);
plat->power_gpio = of_get_named_gpio(np, "power-gpios", 0);
return plat;
}
static int __devinit sdhci_tegra_probe(struct platform_device *pdev) static int __devinit sdhci_tegra_probe(struct platform_device *pdev)
{ {
struct sdhci_pltfm_host *pltfm_host; struct sdhci_pltfm_host *pltfm_host;
...@@ -147,12 +172,17 @@ static int __devinit sdhci_tegra_probe(struct platform_device *pdev) ...@@ -147,12 +172,17 @@ static int __devinit sdhci_tegra_probe(struct platform_device *pdev)
plat = pdev->dev.platform_data; plat = pdev->dev.platform_data;
if (plat == NULL)
plat = sdhci_tegra_dt_parse_pdata(pdev);
if (plat == NULL) { if (plat == NULL) {
dev_err(mmc_dev(host->mmc), "missing platform data\n"); dev_err(mmc_dev(host->mmc), "missing platform data\n");
rc = -ENXIO; rc = -ENXIO;
goto err_no_plat; goto err_no_plat;
} }
pltfm_host->priv = plat;
if (gpio_is_valid(plat->power_gpio)) { if (gpio_is_valid(plat->power_gpio)) {
rc = gpio_request(plat->power_gpio, "sdhci_power"); rc = gpio_request(plat->power_gpio, "sdhci_power");
if (rc) { if (rc) {
...@@ -247,13 +277,11 @@ static int __devexit sdhci_tegra_remove(struct platform_device *pdev) ...@@ -247,13 +277,11 @@ static int __devexit sdhci_tegra_remove(struct platform_device *pdev)
{ {
struct sdhci_host *host = platform_get_drvdata(pdev); struct sdhci_host *host = platform_get_drvdata(pdev);
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct tegra_sdhci_platform_data *plat; struct tegra_sdhci_platform_data *plat = pltfm_host->priv;
int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff); int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
sdhci_remove_host(host, dead); sdhci_remove_host(host, dead);
plat = pdev->dev.platform_data;
if (gpio_is_valid(plat->wp_gpio)) { if (gpio_is_valid(plat->wp_gpio)) {
tegra_gpio_disable(plat->wp_gpio); tegra_gpio_disable(plat->wp_gpio);
gpio_free(plat->wp_gpio); gpio_free(plat->wp_gpio);
...@@ -282,6 +310,7 @@ static struct platform_driver sdhci_tegra_driver = { ...@@ -282,6 +310,7 @@ static struct platform_driver sdhci_tegra_driver = {
.driver = { .driver = {
.name = "sdhci-tegra", .name = "sdhci-tegra",
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = sdhci_tegra_dt_match,
}, },
.probe = sdhci_tegra_probe, .probe = sdhci_tegra_probe,
.remove = __devexit_p(sdhci_tegra_remove), .remove = __devexit_p(sdhci_tegra_remove),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment