Skip to content

Commit bba1594

Browse files
author
Russell King
committed
Merge branch 'mmci' into amba
2 parents 9e5ed09 + 7437cfa commit bba1594

4 files changed

Lines changed: 151 additions & 73 deletions

File tree

‎arch/arm/mach-ux500/board-mop500-sdi.c‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,13 @@
3131
* SDI 0 (MicroSD slot)
3232
*/
3333

34-
/* MMCIPOWER bits */
35-
#define MCI_DATA2DIREN (1 << 2)
36-
#define MCI_CMDDIREN (1 << 3)
37-
#define MCI_DATA0DIREN (1 << 4)
38-
#define MCI_DATA31DIREN (1 << 5)
39-
#define MCI_FBCLKEN (1 << 7)
40-
4134
/* GPIO pins used by the sdi0 level shifter */
4235
static int sdi0_en = -1;
4336
static int sdi0_vsel = -1;
4437

45-
static u32 mop500_sdi0_vdd_handler(struct device *dev, unsigned int vdd,
46-
unsigned char power_mode)
38+
static int mop500_sdi0_ios_handler(struct device *dev, struct mmc_ios *ios)
4739
{
48-
switch (power_mode) {
40+
switch (ios->power_mode) {
4941
case MMC_POWER_UP:
5042
case MMC_POWER_ON:
5143
/*
@@ -65,8 +57,7 @@ static u32 mop500_sdi0_vdd_handler(struct device *dev, unsigned int vdd,
6557
break;
6658
}
6759

68-
return MCI_FBCLKEN | MCI_CMDDIREN | MCI_DATA0DIREN |
69-
MCI_DATA2DIREN | MCI_DATA31DIREN;
60+
return 0;
7061
}
7162

7263
#ifdef CONFIG_STE_DMA40
@@ -90,13 +81,17 @@ static struct stedma40_chan_cfg mop500_sdi0_dma_cfg_tx = {
9081
#endif
9182

9283
static struct mmci_platform_data mop500_sdi0_data = {
93-
.vdd_handler = mop500_sdi0_vdd_handler,
84+
.ios_handler = mop500_sdi0_ios_handler,
9485
.ocr_mask = MMC_VDD_29_30,
9586
.f_max = 50000000,
9687
.capabilities = MMC_CAP_4_BIT_DATA |
9788
MMC_CAP_SD_HIGHSPEED |
9889
MMC_CAP_MMC_HIGHSPEED,
9990
.gpio_wp = -1,
91+
.sigdir = MCI_ST_FBCLKEN |
92+
MCI_ST_CMDDIREN |
93+
MCI_ST_DATA0DIREN |
94+
MCI_ST_DATA2DIREN,
10095
#ifdef CONFIG_STE_DMA40
10196
.dma_filter = stedma40_filter,
10297
.dma_rx_param = &mop500_sdi0_dma_cfg_rx,

‎drivers/mmc/host/mmci.c‎

Lines changed: 121 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static unsigned int fmax = 515633;
5353
* @sdio: variant supports SDIO
5454
* @st_clkdiv: true if using a ST-specific clock divider algorithm
5555
* @blksz_datactrl16: true if Block size is at b16..b30 position in datactrl register
56+
* @pwrreg_powerup: power up value for MMCIPOWER register
57+
* @signal_direction: input/out direction of bus signals can be indicated
5658
*/
5759
struct variant_data {
5860
unsigned int clkreg;
@@ -63,18 +65,22 @@ struct variant_data {
6365
bool sdio;
6466
bool st_clkdiv;
6567
bool blksz_datactrl16;
68+
u32 pwrreg_powerup;
69+
bool signal_direction;
6670
};
6771

6872
static struct variant_data variant_arm = {
6973
.fifosize = 16 * 4,
7074
.fifohalfsize = 8 * 4,
7175
.datalength_bits = 16,
76+
.pwrreg_powerup = MCI_PWR_UP,
7277
};
7378

7479
static struct variant_data variant_arm_extended_fifo = {
7580
.fifosize = 128 * 4,
7681
.fifohalfsize = 64 * 4,
7782
.datalength_bits = 16,
83+
.pwrreg_powerup = MCI_PWR_UP,
7884
};
7985

8086
static struct variant_data variant_u300 = {
@@ -83,6 +89,8 @@ static struct variant_data variant_u300 = {
8389
.clkreg_enable = MCI_ST_U300_HWFCEN,
8490
.datalength_bits = 16,
8591
.sdio = true,
92+
.pwrreg_powerup = MCI_PWR_ON,
93+
.signal_direction = true,
8694
};
8795

8896
static struct variant_data variant_ux500 = {
@@ -93,6 +101,8 @@ static struct variant_data variant_ux500 = {
93101
.datalength_bits = 24,
94102
.sdio = true,
95103
.st_clkdiv = true,
104+
.pwrreg_powerup = MCI_PWR_ON,
105+
.signal_direction = true,
96106
};
97107

98108
static struct variant_data variant_ux500v2 = {
@@ -104,8 +114,32 @@ static struct variant_data variant_ux500v2 = {
104114
.sdio = true,
105115
.st_clkdiv = true,
106116
.blksz_datactrl16 = true,
117+
.pwrreg_powerup = MCI_PWR_ON,
118+
.signal_direction = true,
107119
};
108120

121+
/*
122+
* This must be called with host->lock held
123+
*/
124+
static void mmci_write_clkreg(struct mmci_host *host, u32 clk)
125+
{
126+
if (host->clk_reg != clk) {
127+
host->clk_reg = clk;
128+
writel(clk, host->base + MMCICLOCK);
129+
}
130+
}
131+
132+
/*
133+
* This must be called with host->lock held
134+
*/
135+
static void mmci_write_pwrreg(struct mmci_host *host, u32 pwr)
136+
{
137+
if (host->pwr_reg != pwr) {
138+
host->pwr_reg = pwr;
139+
writel(pwr, host->base + MMCIPOWER);
140+
}
141+
}
142+
109143
/*
110144
* This must be called with host->lock held
111145
*/
@@ -153,7 +187,7 @@ static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired)
153187
if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_8)
154188
clk |= MCI_ST_8BIT_BUS;
155189

156-
writel(clk, host->base + MMCICLOCK);
190+
mmci_write_clkreg(host, clk);
157191
}
158192

159193
static void
@@ -166,14 +200,10 @@ mmci_request_end(struct mmci_host *host, struct mmc_request *mrq)
166200
host->mrq = NULL;
167201
host->cmd = NULL;
168202

169-
/*
170-
* Need to drop the host lock here; mmc_request_done may call
171-
* back into the driver...
172-
*/
173-
spin_unlock(&host->lock);
174-
pm_runtime_put(mmc_dev(host->mmc));
175203
mmc_request_done(host->mmc, mrq);
176-
spin_lock(&host->lock);
204+
205+
pm_runtime_mark_last_busy(mmc_dev(host->mmc));
206+
pm_runtime_put_autosuspend(mmc_dev(host->mmc));
177207
}
178208

179209
static void mmci_set_mask1(struct mmci_host *host, unsigned int mask)
@@ -607,6 +637,11 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
607637
if (data->flags & MMC_DATA_READ)
608638
datactrl |= MCI_DPSM_DIRECTION;
609639

640+
/* The ST Micro variants has a special bit to enable SDIO */
641+
if (variant->sdio && host->mmc->card)
642+
if (mmc_card_sdio(host->mmc->card))
643+
datactrl |= MCI_ST_DPSM_SDIOEN;
644+
610645
/*
611646
* Attempt to use DMA operation mode, if this
612647
* should fail, fall back to PIO mode
@@ -635,11 +670,6 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
635670
irqmask = MCI_TXFIFOHALFEMPTYMASK;
636671
}
637672

638-
/* The ST Micro variants has a special bit to enable SDIO */
639-
if (variant->sdio && host->mmc->card)
640-
if (mmc_card_sdio(host->mmc->card))
641-
datactrl |= MCI_ST_DPSM_SDIOEN;
642-
643673
writel(datactrl, base + MMCIDATACTRL);
644674
writel(readl(base + MMCIMASK0) & ~MCI_DATAENDMASK, base + MMCIMASK0);
645675
mmci_set_mask1(host, irqmask);
@@ -786,7 +816,24 @@ static int mmci_pio_read(struct mmci_host *host, char *buffer, unsigned int rema
786816
if (count <= 0)
787817
break;
788818

789-
readsl(base + MMCIFIFO, ptr, count >> 2);
819+
/*
820+
* SDIO especially may want to send something that is
821+
* not divisible by 4 (as opposed to card sectors
822+
* etc). Therefore make sure to always read the last bytes
823+
* while only doing full 32-bit reads towards the FIFO.
824+
*/
825+
if (unlikely(count & 0x3)) {
826+
if (count < 4) {
827+
unsigned char buf[4];
828+
readsl(base + MMCIFIFO, buf, 1);
829+
memcpy(ptr, buf, count);
830+
} else {
831+
readsl(base + MMCIFIFO, ptr, count >> 2);
832+
count &= ~0x3;
833+
}
834+
} else {
835+
readsl(base + MMCIFIFO, ptr, count >> 2);
836+
}
790837

791838
ptr += count;
792839
remain -= count;
@@ -821,14 +868,13 @@ static int mmci_pio_write(struct mmci_host *host, char *buffer, unsigned int rem
821868
*/
822869
if (variant->sdio &&
823870
mmc_card_sdio(host->mmc->card)) {
871+
u32 clk;
824872
if (count < 8)
825-
writel(readl(host->base + MMCICLOCK) &
826-
~variant->clkreg_enable,
827-
host->base + MMCICLOCK);
873+
clk = host->clk_reg & ~variant->clkreg_enable;
828874
else
829-
writel(readl(host->base + MMCICLOCK) |
830-
variant->clkreg_enable,
831-
host->base + MMCICLOCK);
875+
clk = host->clk_reg | variant->clkreg_enable;
876+
877+
mmci_write_clkreg(host, clk);
832878
}
833879

834880
/*
@@ -1015,10 +1061,17 @@ static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
10151061
static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
10161062
{
10171063
struct mmci_host *host = mmc_priv(mmc);
1064+
struct variant_data *variant = host->variant;
10181065
u32 pwr = 0;
10191066
unsigned long flags;
10201067
int ret;
10211068

1069+
pm_runtime_get_sync(mmc_dev(mmc));
1070+
1071+
if (host->plat->ios_handler &&
1072+
host->plat->ios_handler(mmc_dev(mmc), ios))
1073+
dev_err(mmc_dev(mmc), "platform ios_handler failed\n");
1074+
10221075
switch (ios->power_mode) {
10231076
case MMC_POWER_OFF:
10241077
if (host->vcc)
@@ -1035,22 +1088,38 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
10351088
* power should be rare so we print an error
10361089
* and return here.
10371090
*/
1038-
return;
1091+
goto out;
10391092
}
10401093
}
1041-
if (host->plat->vdd_handler)
1042-
pwr |= host->plat->vdd_handler(mmc_dev(mmc), ios->vdd,
1043-
ios->power_mode);
1044-
/* The ST version does not have this, fall through to POWER_ON */
1045-
if (host->hw_designer != AMBA_VENDOR_ST) {
1046-
pwr |= MCI_PWR_UP;
1047-
break;
1048-
}
1094+
/*
1095+
* The ST Micro variant doesn't have the PL180s MCI_PWR_UP
1096+
* and instead uses MCI_PWR_ON so apply whatever value is
1097+
* configured in the variant data.
1098+
*/
1099+
pwr |= variant->pwrreg_powerup;
1100+
1101+
break;
10491102
case MMC_POWER_ON:
10501103
pwr |= MCI_PWR_ON;
10511104
break;
10521105
}
10531106

1107+
if (variant->signal_direction && ios->power_mode != MMC_POWER_OFF) {
1108+
/*
1109+
* The ST Micro variant has some additional bits
1110+
* indicating signal direction for the signals in
1111+
* the SD/MMC bus and feedback-clock usage.
1112+
*/
1113+
pwr |= host->plat->sigdir;
1114+
1115+
if (ios->bus_width == MMC_BUS_WIDTH_4)
1116+
pwr &= ~MCI_ST_DATA74DIREN;
1117+
else if (ios->bus_width == MMC_BUS_WIDTH_1)
1118+
pwr &= (~MCI_ST_DATA74DIREN &
1119+
~MCI_ST_DATA31DIREN &
1120+
~MCI_ST_DATA2DIREN);
1121+
}
1122+
10541123
if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
10551124
if (host->hw_designer != AMBA_VENDOR_ST)
10561125
pwr |= MCI_ROD;
@@ -1066,13 +1135,13 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
10661135
spin_lock_irqsave(&host->lock, flags);
10671136

10681137
mmci_set_clkreg(host, ios->clock);
1069-
1070-
if (host->pwr != pwr) {
1071-
host->pwr = pwr;
1072-
writel(pwr, host->base + MMCIPOWER);
1073-
}
1138+
mmci_write_pwrreg(host, pwr);
10741139

10751140
spin_unlock_irqrestore(&host->lock, flags);
1141+
1142+
out:
1143+
pm_runtime_mark_last_busy(mmc_dev(mmc));
1144+
pm_runtime_put_autosuspend(mmc_dev(mmc));
10761145
}
10771146

10781147
static int mmci_get_ro(struct mmc_host *mmc)
@@ -1345,6 +1414,8 @@ static int __devinit mmci_probe(struct amba_device *dev,
13451414

13461415
mmci_dma_setup(host);
13471416

1417+
pm_runtime_set_autosuspend_delay(&dev->dev, 50);
1418+
pm_runtime_use_autosuspend(&dev->dev);
13481419
pm_runtime_put(&dev->dev);
13491420

13501421
mmc_add_host(mmc);
@@ -1429,43 +1500,49 @@ static int __devexit mmci_remove(struct amba_device *dev)
14291500
return 0;
14301501
}
14311502

1432-
#ifdef CONFIG_PM
1433-
static int mmci_suspend(struct amba_device *dev, pm_message_t state)
1503+
#ifdef CONFIG_SUSPEND
1504+
static int mmci_suspend(struct device *dev)
14341505
{
1435-
struct mmc_host *mmc = amba_get_drvdata(dev);
1506+
struct amba_device *adev = to_amba_device(dev);
1507+
struct mmc_host *mmc = amba_get_drvdata(adev);
14361508
int ret = 0;
14371509

14381510
if (mmc) {
14391511
struct mmci_host *host = mmc_priv(mmc);
14401512

14411513
ret = mmc_suspend_host(mmc);
1442-
if (ret == 0)
1514+
if (ret == 0) {
1515+
pm_runtime_get_sync(dev);
14431516
writel(0, host->base + MMCIMASK0);
1517+
}
14441518
}
14451519

14461520
return ret;
14471521
}
14481522

1449-
static int mmci_resume(struct amba_device *dev)
1523+
static int mmci_resume(struct device *dev)
14501524
{
1451-
struct mmc_host *mmc = amba_get_drvdata(dev);
1525+
struct amba_device *adev = to_amba_device(dev);
1526+
struct mmc_host *mmc = amba_get_drvdata(adev);
14521527
int ret = 0;
14531528

14541529
if (mmc) {
14551530
struct mmci_host *host = mmc_priv(mmc);
14561531

14571532
writel(MCI_IRQENABLE, host->base + MMCIMASK0);
1533+
pm_runtime_put(dev);
14581534

14591535
ret = mmc_resume_host(mmc);
14601536
}
14611537

14621538
return ret;
14631539
}
1464-
#else
1465-
#define mmci_suspend NULL
1466-
#define mmci_resume NULL
14671540
#endif
14681541

1542+
static const struct dev_pm_ops mmci_dev_pm_ops = {
1543+
SET_SYSTEM_SLEEP_PM_OPS(mmci_suspend, mmci_resume)
1544+
};
1545+
14691546
static struct amba_id mmci_ids[] = {
14701547
{
14711548
.id = 0x00041180,
@@ -1511,11 +1588,10 @@ MODULE_DEVICE_TABLE(amba, mmci_ids);
15111588
static struct amba_driver mmci_driver = {
15121589
.drv = {
15131590
.name = DRIVER_NAME,
1591+
.pm = &mmci_dev_pm_ops,
15141592
},
15151593
.probe = mmci_probe,
15161594
.remove = __devexit_p(mmci_remove),
1517-
.suspend = mmci_suspend,
1518-
.resume = mmci_resume,
15191595
.id_table = mmci_ids,
15201596
};
15211597

0 commit comments

Comments
 (0)