Commit 38a8dda9 authored by Daniel Mack's avatar Daniel Mack Committed by Ulf Hansson

mmc: pxamci: make GPIO lookups from pdata optional

A recent commit introduced a call to mmc_of_parse() and removed the
explicit assignment of GPIOs in the pdata structure. This will leave
them set to 0, which is a valid GPIO per se, so the code that looks
at these members will try to allocate them and fail.

To fix this properly, make the following changes:

a) Refrain from allocating and assiging a pdata struct from
   pxamci_of_init(). It's a hack to do it this way anyway.
   Instead, move the only remaining member of interest in
   'struct pxamci_host' and assign the value from either
   the passed in pdata pointer or with the value read from DT.

b) Let the only user of 'detect_delay_ms' look at the member of
   'struct pxamci_host', not the pdata.

c) Make more code in pxamci_probe() dependent on the presence of
   actual pdata.

This will also ease the removal of pdata one day.
Signed-off-by: default avatarDaniel Mack <daniel@zonque.org>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent 61951fd6
...@@ -62,6 +62,7 @@ struct pxamci_host { ...@@ -62,6 +62,7 @@ struct pxamci_host {
unsigned int cmdat; unsigned int cmdat;
unsigned int imask; unsigned int imask;
unsigned int power_mode; unsigned int power_mode;
unsigned long detect_delay_ms;
struct pxamci_platform_data *pdata; struct pxamci_platform_data *pdata;
struct mmc_request *mrq; struct mmc_request *mrq;
...@@ -567,7 +568,7 @@ static irqreturn_t pxamci_detect_irq(int irq, void *devid) ...@@ -567,7 +568,7 @@ static irqreturn_t pxamci_detect_irq(int irq, void *devid)
{ {
struct pxamci_host *host = mmc_priv(devid); struct pxamci_host *host = mmc_priv(devid);
mmc_detect_change(devid, msecs_to_jiffies(host->pdata->detect_delay_ms)); mmc_detect_change(devid, msecs_to_jiffies(host->detect_delay_ms));
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -583,27 +584,21 @@ static int pxamci_of_init(struct platform_device *pdev, ...@@ -583,27 +584,21 @@ static int pxamci_of_init(struct platform_device *pdev,
struct mmc_host *mmc) struct mmc_host *mmc)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct pxamci_platform_data *pdata; struct pxamci_host *host = mmc_priv(mmc);
u32 tmp; u32 tmp;
int ret; int ret;
if (!np) if (!np)
return 0; return 0;
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
/* pxa-mmc specific */ /* pxa-mmc specific */
if (of_property_read_u32(np, "pxa-mmc,detect-delay-ms", &tmp) == 0) if (of_property_read_u32(np, "pxa-mmc,detect-delay-ms", &tmp) == 0)
pdata->detect_delay_ms = tmp; host->detect_delay_ms = tmp;
ret = mmc_of_parse(mmc); ret = mmc_of_parse(mmc);
if (ret < 0) if (ret < 0)
return ret; return ret;
pdev->dev.platform_data = pdata;
return 0; return 0;
} }
#else #else
...@@ -619,7 +614,7 @@ static int pxamci_probe(struct platform_device *pdev) ...@@ -619,7 +614,7 @@ static int pxamci_probe(struct platform_device *pdev)
struct mmc_host *mmc; struct mmc_host *mmc;
struct pxamci_host *host = NULL; struct pxamci_host *host = NULL;
struct resource *r; struct resource *r;
int ret, irq, gpio_cd = -1, gpio_ro = -1, gpio_power = -1; int ret, irq;
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
...@@ -734,47 +729,54 @@ static int pxamci_probe(struct platform_device *pdev) ...@@ -734,47 +729,54 @@ static int pxamci_probe(struct platform_device *pdev)
} }
if (host->pdata) { if (host->pdata) {
gpio_cd = host->pdata->gpio_card_detect; int gpio_cd = host->pdata->gpio_card_detect;
gpio_ro = host->pdata->gpio_card_ro; int gpio_ro = host->pdata->gpio_card_ro;
gpio_power = host->pdata->gpio_power; int gpio_power = host->pdata->gpio_power;
}
if (gpio_is_valid(gpio_power)) { host->detect_delay_ms = host->pdata->detect_delay_ms;
ret = devm_gpio_request(&pdev->dev, gpio_power,
"mmc card power"); if (gpio_is_valid(gpio_power)) {
if (ret) { ret = devm_gpio_request(&pdev->dev, gpio_power,
dev_err(&pdev->dev, "Failed requesting gpio_power %d\n", "mmc card power");
gpio_power); if (ret) {
goto out; dev_err(&pdev->dev,
"Failed requesting gpio_power %d\n",
gpio_power);
goto out;
}
gpio_direction_output(gpio_power,
host->pdata->gpio_power_invert);
} }
gpio_direction_output(gpio_power,
host->pdata->gpio_power_invert); if (gpio_is_valid(gpio_ro)) {
} ret = mmc_gpio_request_ro(mmc, gpio_ro);
if (gpio_is_valid(gpio_ro)) { if (ret) {
ret = mmc_gpio_request_ro(mmc, gpio_ro); dev_err(&pdev->dev,
"Failed requesting gpio_ro %d\n",
gpio_ro);
goto out;
} else {
mmc->caps2 |= host->pdata->gpio_card_ro_invert ?
0 : MMC_CAP2_RO_ACTIVE_HIGH;
}
}
if (gpio_is_valid(gpio_cd))
ret = mmc_gpio_request_cd(mmc, gpio_cd, 0);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed requesting gpio_ro %d\n", dev_err(&pdev->dev, "Failed requesting gpio_cd %d\n",
gpio_ro); gpio_cd);
goto out; goto out;
} else {
mmc->caps2 |= host->pdata->gpio_card_ro_invert ?
0 : MMC_CAP2_RO_ACTIVE_HIGH;
} }
}
if (gpio_is_valid(gpio_cd)) if (host->pdata->init)
ret = mmc_gpio_request_cd(mmc, gpio_cd, 0); host->pdata->init(&pdev->dev, pxamci_detect_irq, mmc);
if (ret) {
dev_err(&pdev->dev, "Failed requesting gpio_cd %d\n", gpio_cd);
goto out;
}
if (host->pdata && host->pdata->init) if (gpio_is_valid(gpio_power) && host->pdata->setpower)
host->pdata->init(&pdev->dev, pxamci_detect_irq, mmc); dev_warn(&pdev->dev, "gpio_power and setpower() both defined\n");
if (gpio_is_valid(gpio_ro) && host->pdata->get_ro)
if (gpio_is_valid(gpio_power) && host->pdata->setpower) dev_warn(&pdev->dev, "gpio_ro and get_ro() both defined\n");
dev_warn(&pdev->dev, "gpio_power and setpower() both defined\n"); }
if (gpio_is_valid(gpio_ro) && host->pdata->get_ro)
dev_warn(&pdev->dev, "gpio_ro and get_ro() both defined\n");
mmc_add_host(mmc); mmc_add_host(mmc);
......
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