Skip to content

Commit 36f8daf

Browse files
committed
Merge tag 'mmc-v4.3-rc3' of git://git.linaro.org/people/ulf.hansson/mmc
Pull MMC fixes from Ulf Hansson: "Here are some mmc fixes intended for v4.3 rc4: MMC core: - Allow users of mmc_of_parse() to succeed when CONFIG_GPIOLIB is unset - Prevent infinite loop of re-tuning for CRC-errors for CMD19 and CMD21 MMC host: - pxamci: Fix issues with card detect - sunxi: Fix clk-delay settings" * tag 'mmc-v4.3-rc3' of git://git.linaro.org/people/ulf.hansson/mmc: mmc: core: fix dead loop of mmc_retune mmc: pxamci: fix card detect with slot-gpio API mmc: sunxi: Fix clk-delay settings mmc: core: Don't return an error for CD/WP GPIOs when GPIOLIB is unset
2 parents 8c25ab8 + 031277d commit 36f8daf

File tree

4 files changed

+67
-62
lines changed

4 files changed

+67
-62
lines changed

drivers/mmc/core/core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
134134
int err = cmd->error;
135135

136136
/* Flag re-tuning needed on CRC errors */
137-
if (err == -EILSEQ || (mrq->sbc && mrq->sbc->error == -EILSEQ) ||
137+
if ((cmd->opcode != MMC_SEND_TUNING_BLOCK &&
138+
cmd->opcode != MMC_SEND_TUNING_BLOCK_HS200) &&
139+
(err == -EILSEQ || (mrq->sbc && mrq->sbc->error == -EILSEQ) ||
138140
(mrq->data && mrq->data->error == -EILSEQ) ||
139-
(mrq->stop && mrq->stop->error == -EILSEQ))
141+
(mrq->stop && mrq->stop->error == -EILSEQ)))
140142
mmc_retune_needed(host);
141143

142144
if (err && cmd->retries && mmc_host_is_spi(host)) {

drivers/mmc/core/host.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ int mmc_of_parse(struct mmc_host *host)
457457
0, &cd_gpio_invert);
458458
if (!ret)
459459
dev_info(host->parent, "Got CD GPIO\n");
460-
else if (ret != -ENOENT)
460+
else if (ret != -ENOENT && ret != -ENOSYS)
461461
return ret;
462462

463463
/*
@@ -481,7 +481,7 @@ int mmc_of_parse(struct mmc_host *host)
481481
ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0, &ro_gpio_invert);
482482
if (!ret)
483483
dev_info(host->parent, "Got WP GPIO\n");
484-
else if (ret != -ENOENT)
484+
else if (ret != -ENOENT && ret != -ENOSYS)
485485
return ret;
486486

487487
if (of_property_read_bool(np, "disable-wp"))

drivers/mmc/host/pxamci.c

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/clk.h>
2929
#include <linux/err.h>
3030
#include <linux/mmc/host.h>
31+
#include <linux/mmc/slot-gpio.h>
3132
#include <linux/io.h>
3233
#include <linux/regulator/consumer.h>
3334
#include <linux/gpio.h>
@@ -454,12 +455,8 @@ static int pxamci_get_ro(struct mmc_host *mmc)
454455
{
455456
struct pxamci_host *host = mmc_priv(mmc);
456457

457-
if (host->pdata && gpio_is_valid(host->pdata->gpio_card_ro)) {
458-
if (host->pdata->gpio_card_ro_invert)
459-
return !gpio_get_value(host->pdata->gpio_card_ro);
460-
else
461-
return gpio_get_value(host->pdata->gpio_card_ro);
462-
}
458+
if (host->pdata && gpio_is_valid(host->pdata->gpio_card_ro))
459+
return mmc_gpio_get_ro(mmc);
463460
if (host->pdata && host->pdata->get_ro)
464461
return !!host->pdata->get_ro(mmc_dev(mmc));
465462
/*
@@ -551,6 +548,7 @@ static void pxamci_enable_sdio_irq(struct mmc_host *host, int enable)
551548

552549
static const struct mmc_host_ops pxamci_ops = {
553550
.request = pxamci_request,
551+
.get_cd = mmc_gpio_get_cd,
554552
.get_ro = pxamci_get_ro,
555553
.set_ios = pxamci_set_ios,
556554
.enable_sdio_irq = pxamci_enable_sdio_irq,
@@ -790,37 +788,31 @@ static int pxamci_probe(struct platform_device *pdev)
790788
gpio_power = host->pdata->gpio_power;
791789
}
792790
if (gpio_is_valid(gpio_power)) {
793-
ret = gpio_request(gpio_power, "mmc card power");
791+
ret = devm_gpio_request(&pdev->dev, gpio_power,
792+
"mmc card power");
794793
if (ret) {
795-
dev_err(&pdev->dev, "Failed requesting gpio_power %d\n", gpio_power);
794+
dev_err(&pdev->dev, "Failed requesting gpio_power %d\n",
795+
gpio_power);
796796
goto out;
797797
}
798798
gpio_direction_output(gpio_power,
799799
host->pdata->gpio_power_invert);
800800
}
801-
if (gpio_is_valid(gpio_ro)) {
802-
ret = gpio_request(gpio_ro, "mmc card read only");
803-
if (ret) {
804-
dev_err(&pdev->dev, "Failed requesting gpio_ro %d\n", gpio_ro);
805-
goto err_gpio_ro;
806-
}
807-
gpio_direction_input(gpio_ro);
801+
if (gpio_is_valid(gpio_ro))
802+
ret = mmc_gpio_request_ro(mmc, gpio_ro);
803+
if (ret) {
804+
dev_err(&pdev->dev, "Failed requesting gpio_ro %d\n", gpio_ro);
805+
goto out;
806+
} else {
807+
mmc->caps |= host->pdata->gpio_card_ro_invert ?
808+
MMC_CAP2_RO_ACTIVE_HIGH : 0;
808809
}
809-
if (gpio_is_valid(gpio_cd)) {
810-
ret = gpio_request(gpio_cd, "mmc card detect");
811-
if (ret) {
812-
dev_err(&pdev->dev, "Failed requesting gpio_cd %d\n", gpio_cd);
813-
goto err_gpio_cd;
814-
}
815-
gpio_direction_input(gpio_cd);
816810

817-
ret = request_irq(gpio_to_irq(gpio_cd), pxamci_detect_irq,
818-
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
819-
"mmc card detect", mmc);
820-
if (ret) {
821-
dev_err(&pdev->dev, "failed to request card detect IRQ\n");
822-
goto err_request_irq;
823-
}
811+
if (gpio_is_valid(gpio_cd))
812+
ret = mmc_gpio_request_cd(mmc, gpio_cd, 0);
813+
if (ret) {
814+
dev_err(&pdev->dev, "Failed requesting gpio_cd %d\n", gpio_cd);
815+
goto out;
824816
}
825817

826818
if (host->pdata && host->pdata->init)
@@ -835,13 +827,7 @@ static int pxamci_probe(struct platform_device *pdev)
835827

836828
return 0;
837829

838-
err_request_irq:
839-
gpio_free(gpio_cd);
840-
err_gpio_cd:
841-
gpio_free(gpio_ro);
842-
err_gpio_ro:
843-
gpio_free(gpio_power);
844-
out:
830+
out:
845831
if (host) {
846832
if (host->dma_chan_rx)
847833
dma_release_channel(host->dma_chan_rx);
@@ -873,14 +859,6 @@ static int pxamci_remove(struct platform_device *pdev)
873859
gpio_ro = host->pdata->gpio_card_ro;
874860
gpio_power = host->pdata->gpio_power;
875861
}
876-
if (gpio_is_valid(gpio_cd)) {
877-
free_irq(gpio_to_irq(gpio_cd), mmc);
878-
gpio_free(gpio_cd);
879-
}
880-
if (gpio_is_valid(gpio_ro))
881-
gpio_free(gpio_ro);
882-
if (gpio_is_valid(gpio_power))
883-
gpio_free(gpio_power);
884862
if (host->vcc)
885863
regulator_put(host->vcc);
886864

drivers/mmc/host/sunxi-mmc.c

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@
210210
#define SDXC_IDMAC_DES0_CES BIT(30) /* card error summary */
211211
#define SDXC_IDMAC_DES0_OWN BIT(31) /* 1-idma owns it, 0-host owns it */
212212

213+
#define SDXC_CLK_400K 0
214+
#define SDXC_CLK_25M 1
215+
#define SDXC_CLK_50M 2
216+
#define SDXC_CLK_50M_DDR 3
217+
218+
struct sunxi_mmc_clk_delay {
219+
u32 output;
220+
u32 sample;
221+
};
222+
213223
struct sunxi_idma_des {
214224
u32 config;
215225
u32 buf_size;
@@ -229,6 +239,7 @@ struct sunxi_mmc_host {
229239
struct clk *clk_mmc;
230240
struct clk *clk_sample;
231241
struct clk *clk_output;
242+
const struct sunxi_mmc_clk_delay *clk_delays;
232243

233244
/* irq */
234245
spinlock_t lock;
@@ -654,25 +665,19 @@ static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host *host,
654665

655666
/* determine delays */
656667
if (rate <= 400000) {
657-
oclk_dly = 180;
658-
sclk_dly = 42;
668+
oclk_dly = host->clk_delays[SDXC_CLK_400K].output;
669+
sclk_dly = host->clk_delays[SDXC_CLK_400K].sample;
659670
} else if (rate <= 25000000) {
660-
oclk_dly = 180;
661-
sclk_dly = 75;
671+
oclk_dly = host->clk_delays[SDXC_CLK_25M].output;
672+
sclk_dly = host->clk_delays[SDXC_CLK_25M].sample;
662673
} else if (rate <= 50000000) {
663674
if (ios->timing == MMC_TIMING_UHS_DDR50) {
664-
oclk_dly = 60;
665-
sclk_dly = 120;
675+
oclk_dly = host->clk_delays[SDXC_CLK_50M_DDR].output;
676+
sclk_dly = host->clk_delays[SDXC_CLK_50M_DDR].sample;
666677
} else {
667-
oclk_dly = 90;
668-
sclk_dly = 150;
678+
oclk_dly = host->clk_delays[SDXC_CLK_50M].output;
679+
sclk_dly = host->clk_delays[SDXC_CLK_50M].sample;
669680
}
670-
} else if (rate <= 100000000) {
671-
oclk_dly = 6;
672-
sclk_dly = 24;
673-
} else if (rate <= 200000000) {
674-
oclk_dly = 3;
675-
sclk_dly = 12;
676681
} else {
677682
return -EINVAL;
678683
}
@@ -871,6 +876,7 @@ static void sunxi_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
871876
static const struct of_device_id sunxi_mmc_of_match[] = {
872877
{ .compatible = "allwinner,sun4i-a10-mmc", },
873878
{ .compatible = "allwinner,sun5i-a13-mmc", },
879+
{ .compatible = "allwinner,sun9i-a80-mmc", },
874880
{ /* sentinel */ }
875881
};
876882
MODULE_DEVICE_TABLE(of, sunxi_mmc_of_match);
@@ -884,6 +890,20 @@ static struct mmc_host_ops sunxi_mmc_ops = {
884890
.hw_reset = sunxi_mmc_hw_reset,
885891
};
886892

893+
static const struct sunxi_mmc_clk_delay sunxi_mmc_clk_delays[] = {
894+
[SDXC_CLK_400K] = { .output = 180, .sample = 180 },
895+
[SDXC_CLK_25M] = { .output = 180, .sample = 75 },
896+
[SDXC_CLK_50M] = { .output = 90, .sample = 120 },
897+
[SDXC_CLK_50M_DDR] = { .output = 60, .sample = 120 },
898+
};
899+
900+
static const struct sunxi_mmc_clk_delay sun9i_mmc_clk_delays[] = {
901+
[SDXC_CLK_400K] = { .output = 180, .sample = 180 },
902+
[SDXC_CLK_25M] = { .output = 180, .sample = 75 },
903+
[SDXC_CLK_50M] = { .output = 150, .sample = 120 },
904+
[SDXC_CLK_50M_DDR] = { .output = 90, .sample = 120 },
905+
};
906+
887907
static int sunxi_mmc_resource_request(struct sunxi_mmc_host *host,
888908
struct platform_device *pdev)
889909
{
@@ -895,6 +915,11 @@ static int sunxi_mmc_resource_request(struct sunxi_mmc_host *host,
895915
else
896916
host->idma_des_size_bits = 16;
897917

918+
if (of_device_is_compatible(np, "allwinner,sun9i-a80-mmc"))
919+
host->clk_delays = sun9i_mmc_clk_delays;
920+
else
921+
host->clk_delays = sunxi_mmc_clk_delays;
922+
898923
ret = mmc_regulator_get_supply(host->mmc);
899924
if (ret) {
900925
if (ret != -EPROBE_DEFER)

0 commit comments

Comments
 (0)