1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * drivers/mmc/host/via-sdmmc.c - VIA SD/MMC Card Reader driver
4 * Copyright (c) 2008, VIA Technologies Inc. All Rights Reserved.
8 #include <linux/module.h>
9 #include <linux/dma-mapping.h>
10 #include <linux/highmem.h>
11 #include <linux/delay.h>
12 #include <linux/interrupt.h>
14 #include <linux/mmc/host.h>
15 #include <linux/workqueue.h>
17 #define DRV_NAME "via_sdmmc"
19 #define PCI_DEVICE_ID_VIA_9530 0x9530
21 #define VIA_CRDR_SDC_OFF 0x200
22 #define VIA_CRDR_DDMA_OFF 0x400
23 #define VIA_CRDR_PCICTRL_OFF 0x600
25 #define VIA_CRDR_MIN_CLOCK 375000
26 #define VIA_CRDR_MAX_CLOCK 48000000
32 #define VIA_CRDR_PCI_WORK_MODE 0x40
33 #define VIA_CRDR_PCI_DBG_MODE 0x41
39 #define VIA_CRDR_SDCTRL 0x0
40 #define VIA_CRDR_SDCTRL_START 0x01
41 #define VIA_CRDR_SDCTRL_WRITE 0x04
42 #define VIA_CRDR_SDCTRL_SINGLE_WR 0x10
43 #define VIA_CRDR_SDCTRL_SINGLE_RD 0x20
44 #define VIA_CRDR_SDCTRL_MULTI_WR 0x30
45 #define VIA_CRDR_SDCTRL_MULTI_RD 0x40
46 #define VIA_CRDR_SDCTRL_STOP 0x70
48 #define VIA_CRDR_SDCTRL_RSP_NONE 0x0
49 #define VIA_CRDR_SDCTRL_RSP_R1 0x10000
50 #define VIA_CRDR_SDCTRL_RSP_R2 0x20000
51 #define VIA_CRDR_SDCTRL_RSP_R3 0x30000
52 #define VIA_CRDR_SDCTRL_RSP_R1B 0x90000
54 #define VIA_CRDR_SDCARG 0x4
56 #define VIA_CRDR_SDBUSMODE 0x8
57 #define VIA_CRDR_SDMODE_4BIT 0x02
58 #define VIA_CRDR_SDMODE_CLK_ON 0x40
60 #define VIA_CRDR_SDBLKLEN 0xc
62 * Bit 0 -Bit 10 : Block length. So, the maximum block length should be 2048.
63 * Bit 11 - Bit 13 : Reserved.
64 * GPIDET : Select GPI pin to detect card, GPI means CR_CD# in top design.
65 * INTEN : Enable SD host interrupt.
66 * Bit 16 - Bit 31 : Block count. So, the maximun block count should be 65536.
68 #define VIA_CRDR_SDBLKLEN_GPIDET 0x2000
69 #define VIA_CRDR_SDBLKLEN_INTEN 0x8000
70 #define VIA_CRDR_MAX_BLOCK_COUNT 65536
71 #define VIA_CRDR_MAX_BLOCK_LENGTH 2048
73 #define VIA_CRDR_SDRESP0 0x10
74 #define VIA_CRDR_SDRESP1 0x14
75 #define VIA_CRDR_SDRESP2 0x18
76 #define VIA_CRDR_SDRESP3 0x1c
78 #define VIA_CRDR_SDCURBLKCNT 0x20
80 #define VIA_CRDR_SDINTMASK 0x24
82 * MBDIE : Multiple Blocks transfer Done Interrupt Enable
83 * BDDIE : Block Data transfer Done Interrupt Enable
84 * CIRIE : Card Insertion or Removal Interrupt Enable
85 * CRDIE : Command-Response transfer Done Interrupt Enable
86 * CRTOIE : Command-Response response TimeOut Interrupt Enable
87 * ASCRDIE : Auto Stop Command-Response transfer Done Interrupt Enable
88 * DTIE : Data access Timeout Interrupt Enable
89 * SCIE : reSponse CRC error Interrupt Enable
90 * RCIE : Read data CRC error Interrupt Enable
91 * WCIE : Write data CRC error Interrupt Enable
93 #define VIA_CRDR_SDINTMASK_MBDIE 0x10
94 #define VIA_CRDR_SDINTMASK_BDDIE 0x20
95 #define VIA_CRDR_SDINTMASK_CIRIE 0x80
96 #define VIA_CRDR_SDINTMASK_CRDIE 0x200
97 #define VIA_CRDR_SDINTMASK_CRTOIE 0x400
98 #define VIA_CRDR_SDINTMASK_ASCRDIE 0x800
99 #define VIA_CRDR_SDINTMASK_DTIE 0x1000
100 #define VIA_CRDR_SDINTMASK_SCIE 0x2000
101 #define VIA_CRDR_SDINTMASK_RCIE 0x4000
102 #define VIA_CRDR_SDINTMASK_WCIE 0x8000
104 #define VIA_CRDR_SDACTIVE_INTMASK \
105 (VIA_CRDR_SDINTMASK_MBDIE | VIA_CRDR_SDINTMASK_CIRIE \
106 | VIA_CRDR_SDINTMASK_CRDIE | VIA_CRDR_SDINTMASK_CRTOIE \
107 | VIA_CRDR_SDINTMASK_DTIE | VIA_CRDR_SDINTMASK_SCIE \
108 | VIA_CRDR_SDINTMASK_RCIE | VIA_CRDR_SDINTMASK_WCIE)
110 #define VIA_CRDR_SDSTATUS 0x28
113 * WP : SD card Write Protect status
115 * SLOTG : SD SLOT status(Gpi pin status)
116 * MBD : Multiple Blocks transfer Done interrupt status
117 * BDD : Block Data transfer Done interrupt status
119 * CIR : Card Insertion or Removal interrupt detected on GPI pin
121 * CRD : Command-Response transfer Done interrupt status
122 * CRTO : Command-Response response TimeOut interrupt status
123 * ASCRDIE : Auto Stop Command-Response transfer Done interrupt status
124 * DT : Data access Timeout interrupt status
125 * SC : reSponse CRC error interrupt status
126 * RC : Read data CRC error interrupt status
127 * WC : Write data CRC error interrupt status
129 #define VIA_CRDR_SDSTS_CECC 0x01
130 #define VIA_CRDR_SDSTS_WP 0x02
131 #define VIA_CRDR_SDSTS_SLOTD 0x04
132 #define VIA_CRDR_SDSTS_SLOTG 0x08
133 #define VIA_CRDR_SDSTS_MBD 0x10
134 #define VIA_CRDR_SDSTS_BDD 0x20
135 #define VIA_CRDR_SDSTS_CD 0x40
136 #define VIA_CRDR_SDSTS_CIR 0x80
137 #define VIA_CRDR_SDSTS_IO 0x100
138 #define VIA_CRDR_SDSTS_CRD 0x200
139 #define VIA_CRDR_SDSTS_CRTO 0x400
140 #define VIA_CRDR_SDSTS_ASCRDIE 0x800
141 #define VIA_CRDR_SDSTS_DT 0x1000
142 #define VIA_CRDR_SDSTS_SC 0x2000
143 #define VIA_CRDR_SDSTS_RC 0x4000
144 #define VIA_CRDR_SDSTS_WC 0x8000
146 #define VIA_CRDR_SDSTS_IGN_MASK\
147 (VIA_CRDR_SDSTS_BDD | VIA_CRDR_SDSTS_ASCRDIE | VIA_CRDR_SDSTS_IO)
148 #define VIA_CRDR_SDSTS_INT_MASK \
149 (VIA_CRDR_SDSTS_MBD | VIA_CRDR_SDSTS_BDD | VIA_CRDR_SDSTS_CD \
150 | VIA_CRDR_SDSTS_CIR | VIA_CRDR_SDSTS_IO | VIA_CRDR_SDSTS_CRD \
151 | VIA_CRDR_SDSTS_CRTO | VIA_CRDR_SDSTS_ASCRDIE | VIA_CRDR_SDSTS_DT \
152 | VIA_CRDR_SDSTS_SC | VIA_CRDR_SDSTS_RC | VIA_CRDR_SDSTS_WC)
153 #define VIA_CRDR_SDSTS_W1C_MASK \
154 (VIA_CRDR_SDSTS_CECC | VIA_CRDR_SDSTS_MBD | VIA_CRDR_SDSTS_BDD \
155 | VIA_CRDR_SDSTS_CD | VIA_CRDR_SDSTS_CIR | VIA_CRDR_SDSTS_CRD \
156 | VIA_CRDR_SDSTS_CRTO | VIA_CRDR_SDSTS_ASCRDIE | VIA_CRDR_SDSTS_DT \
157 | VIA_CRDR_SDSTS_SC | VIA_CRDR_SDSTS_RC | VIA_CRDR_SDSTS_WC)
158 #define VIA_CRDR_SDSTS_CMD_MASK \
159 (VIA_CRDR_SDSTS_CRD | VIA_CRDR_SDSTS_CRTO | VIA_CRDR_SDSTS_SC)
160 #define VIA_CRDR_SDSTS_DATA_MASK\
161 (VIA_CRDR_SDSTS_MBD | VIA_CRDR_SDSTS_DT \
162 | VIA_CRDR_SDSTS_RC | VIA_CRDR_SDSTS_WC)
164 #define VIA_CRDR_SDSTATUS2 0x2a
166 * CFE : Enable SD host automatic Clock FReezing
168 #define VIA_CRDR_SDSTS_CFE 0x80
170 #define VIA_CRDR_SDRSPTMO 0x2C
172 #define VIA_CRDR_SDCLKSEL 0x30
174 #define VIA_CRDR_SDEXTCTRL 0x34
175 #define VIS_CRDR_SDEXTCTRL_AUTOSTOP_SD 0x01
176 #define VIS_CRDR_SDEXTCTRL_SHIFT_9 0x02
177 #define VIS_CRDR_SDEXTCTRL_MMC_8BIT 0x04
178 #define VIS_CRDR_SDEXTCTRL_RELD_BLK 0x08
179 #define VIS_CRDR_SDEXTCTRL_BAD_CMDA 0x10
180 #define VIS_CRDR_SDEXTCTRL_BAD_DATA 0x20
181 #define VIS_CRDR_SDEXTCTRL_AUTOSTOP_SPI 0x40
182 #define VIA_CRDR_SDEXTCTRL_HISPD 0x80
183 /* 0x38-0xFF reserved */
186 * Data DMA Control Registers
189 #define VIA_CRDR_DMABASEADD 0x0
190 #define VIA_CRDR_DMACOUNTER 0x4
192 #define VIA_CRDR_DMACTRL 0x8
194 * DIR :Transaction Direction
195 * 0 : From card to memory
196 * 1 : From memory to card
198 #define VIA_CRDR_DMACTRL_DIR 0x100
199 #define VIA_CRDR_DMACTRL_ENIRQ 0x10000
200 #define VIA_CRDR_DMACTRL_SFTRST 0x1000000
202 #define VIA_CRDR_DMASTS 0xc
204 #define VIA_CRDR_DMASTART 0x10
205 /*0x14-0xFF reserved*/
208 * PCI Control Registers
211 /*0x0 - 0x1 reserved*/
212 #define VIA_CRDR_PCICLKGATT 0x2
215 * 0 : Soft reset all the controller and it will be de-asserted automatically
216 * 1 : Soft reset is de-asserted
218 #define VIA_CRDR_PCICLKGATT_SFTRST 0x01
220 * 3V3 : Pad power select
223 * NOTE : No mater what the actual value should be, this bit always
224 * read as 0. This is a hardware bug.
226 #define VIA_CRDR_PCICLKGATT_3V3 0x10
228 * PAD_PWRON : Pad Power on/off select
231 * NOTE : No mater what the actual value should be, this bit always
232 * read as 0. This is a hardware bug.
234 #define VIA_CRDR_PCICLKGATT_PAD_PWRON 0x20
236 #define VIA_CRDR_PCISDCCLK 0x5
238 #define VIA_CRDR_PCIDMACLK 0x7
239 #define VIA_CRDR_PCIDMACLK_SDC 0x2
241 #define VIA_CRDR_PCIINTCTRL 0x8
242 #define VIA_CRDR_PCIINTCTRL_SDCIRQEN 0x04
244 #define VIA_CRDR_PCIINTSTATUS 0x9
245 #define VIA_CRDR_PCIINTSTATUS_SDC 0x04
247 #define VIA_CRDR_PCITMOCTRL 0xa
248 #define VIA_CRDR_PCITMOCTRL_NO 0x0
249 #define VIA_CRDR_PCITMOCTRL_32US 0x1
250 #define VIA_CRDR_PCITMOCTRL_256US 0x2
251 #define VIA_CRDR_PCITMOCTRL_1024US 0x3
252 #define VIA_CRDR_PCITMOCTRL_256MS 0x4
253 #define VIA_CRDR_PCITMOCTRL_512MS 0x5
254 #define VIA_CRDR_PCITMOCTRL_1024MS 0x6
256 /*0xB-0xFF reserved*/
258 enum PCI_HOST_CLK_CONTROL
{
296 struct via_crdr_mmc_host
{
297 struct mmc_host
*mmc
;
298 struct mmc_request
*mrq
;
299 struct mmc_command
*cmd
;
300 struct mmc_data
*data
;
302 void __iomem
*mmiobase
;
303 void __iomem
*sdhc_mmiobase
;
304 void __iomem
*ddma_mmiobase
;
305 void __iomem
*pcictrl_mmiobase
;
307 struct pcictrlreg pm_pcictrl_reg
;
308 struct sdhcreg pm_sdhc_reg
;
310 struct work_struct carddet_work
;
311 struct work_struct finish_bh_work
;
313 struct timer_list timer
;
320 /* some devices need a very long delay for power to stabilize */
321 #define VIA_CRDR_QUIRK_300MS_PWRDELAY 0x0001
323 #define VIA_CMD_TIMEOUT_MS 1000
325 static const struct pci_device_id via_ids
[] = {
326 {PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_9530
,
327 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0,},
331 MODULE_DEVICE_TABLE(pci
, via_ids
);
333 static void via_print_sdchc(struct via_crdr_mmc_host
*host
)
335 void __iomem
*addrbase
= host
->sdhc_mmiobase
;
337 pr_debug("SDC MMIO Registers:\n");
338 pr_debug("SDCONTROL=%08x, SDCMDARG=%08x, SDBUSMODE=%08x\n",
339 readl(addrbase
+ VIA_CRDR_SDCTRL
),
340 readl(addrbase
+ VIA_CRDR_SDCARG
),
341 readl(addrbase
+ VIA_CRDR_SDBUSMODE
));
342 pr_debug("SDBLKLEN=%08x, SDCURBLKCNT=%08x, SDINTMASK=%08x\n",
343 readl(addrbase
+ VIA_CRDR_SDBLKLEN
),
344 readl(addrbase
+ VIA_CRDR_SDCURBLKCNT
),
345 readl(addrbase
+ VIA_CRDR_SDINTMASK
));
346 pr_debug("SDSTATUS=%08x, SDCLKSEL=%08x, SDEXTCTRL=%08x\n",
347 readl(addrbase
+ VIA_CRDR_SDSTATUS
),
348 readl(addrbase
+ VIA_CRDR_SDCLKSEL
),
349 readl(addrbase
+ VIA_CRDR_SDEXTCTRL
));
352 static void via_print_pcictrl(struct via_crdr_mmc_host
*host
)
354 void __iomem
*addrbase
= host
->pcictrl_mmiobase
;
356 pr_debug("PCI Control Registers:\n");
357 pr_debug("PCICLKGATT=%02x, PCISDCCLK=%02x, PCIDMACLK=%02x\n",
358 readb(addrbase
+ VIA_CRDR_PCICLKGATT
),
359 readb(addrbase
+ VIA_CRDR_PCISDCCLK
),
360 readb(addrbase
+ VIA_CRDR_PCIDMACLK
));
361 pr_debug("PCIINTCTRL=%02x, PCIINTSTATUS=%02x\n",
362 readb(addrbase
+ VIA_CRDR_PCIINTCTRL
),
363 readb(addrbase
+ VIA_CRDR_PCIINTSTATUS
));
366 static void via_save_pcictrlreg(struct via_crdr_mmc_host
*host
)
368 struct pcictrlreg
*pm_pcictrl_reg
;
369 void __iomem
*addrbase
;
371 pm_pcictrl_reg
= &(host
->pm_pcictrl_reg
);
372 addrbase
= host
->pcictrl_mmiobase
;
374 pm_pcictrl_reg
->pciclkgat_reg
= readb(addrbase
+ VIA_CRDR_PCICLKGATT
);
375 pm_pcictrl_reg
->pciclkgat_reg
|=
376 VIA_CRDR_PCICLKGATT_3V3
| VIA_CRDR_PCICLKGATT_PAD_PWRON
;
377 pm_pcictrl_reg
->pcisdclk_reg
= readb(addrbase
+ VIA_CRDR_PCISDCCLK
);
378 pm_pcictrl_reg
->pcidmaclk_reg
= readb(addrbase
+ VIA_CRDR_PCIDMACLK
);
379 pm_pcictrl_reg
->pciintctrl_reg
= readb(addrbase
+ VIA_CRDR_PCIINTCTRL
);
380 pm_pcictrl_reg
->pciintstatus_reg
=
381 readb(addrbase
+ VIA_CRDR_PCIINTSTATUS
);
382 pm_pcictrl_reg
->pcitmoctrl_reg
= readb(addrbase
+ VIA_CRDR_PCITMOCTRL
);
385 static void via_restore_pcictrlreg(struct via_crdr_mmc_host
*host
)
387 struct pcictrlreg
*pm_pcictrl_reg
;
388 void __iomem
*addrbase
;
390 pm_pcictrl_reg
= &(host
->pm_pcictrl_reg
);
391 addrbase
= host
->pcictrl_mmiobase
;
393 writeb(pm_pcictrl_reg
->pciclkgat_reg
, addrbase
+ VIA_CRDR_PCICLKGATT
);
394 writeb(pm_pcictrl_reg
->pcisdclk_reg
, addrbase
+ VIA_CRDR_PCISDCCLK
);
395 writeb(pm_pcictrl_reg
->pcidmaclk_reg
, addrbase
+ VIA_CRDR_PCIDMACLK
);
396 writeb(pm_pcictrl_reg
->pciintctrl_reg
, addrbase
+ VIA_CRDR_PCIINTCTRL
);
397 writeb(pm_pcictrl_reg
->pciintstatus_reg
,
398 addrbase
+ VIA_CRDR_PCIINTSTATUS
);
399 writeb(pm_pcictrl_reg
->pcitmoctrl_reg
, addrbase
+ VIA_CRDR_PCITMOCTRL
);
402 static void via_save_sdcreg(struct via_crdr_mmc_host
*host
)
404 struct sdhcreg
*pm_sdhc_reg
;
405 void __iomem
*addrbase
;
407 pm_sdhc_reg
= &(host
->pm_sdhc_reg
);
408 addrbase
= host
->sdhc_mmiobase
;
410 pm_sdhc_reg
->sdcontrol_reg
= readl(addrbase
+ VIA_CRDR_SDCTRL
);
411 pm_sdhc_reg
->sdcmdarg_reg
= readl(addrbase
+ VIA_CRDR_SDCARG
);
412 pm_sdhc_reg
->sdbusmode_reg
= readl(addrbase
+ VIA_CRDR_SDBUSMODE
);
413 pm_sdhc_reg
->sdblklen_reg
= readl(addrbase
+ VIA_CRDR_SDBLKLEN
);
414 pm_sdhc_reg
->sdcurblkcnt_reg
= readl(addrbase
+ VIA_CRDR_SDCURBLKCNT
);
415 pm_sdhc_reg
->sdintmask_reg
= readl(addrbase
+ VIA_CRDR_SDINTMASK
);
416 pm_sdhc_reg
->sdstatus_reg
= readl(addrbase
+ VIA_CRDR_SDSTATUS
);
417 pm_sdhc_reg
->sdrsptmo_reg
= readl(addrbase
+ VIA_CRDR_SDRSPTMO
);
418 pm_sdhc_reg
->sdclksel_reg
= readl(addrbase
+ VIA_CRDR_SDCLKSEL
);
419 pm_sdhc_reg
->sdextctrl_reg
= readl(addrbase
+ VIA_CRDR_SDEXTCTRL
);
422 static void via_restore_sdcreg(struct via_crdr_mmc_host
*host
)
424 struct sdhcreg
*pm_sdhc_reg
;
425 void __iomem
*addrbase
;
427 pm_sdhc_reg
= &(host
->pm_sdhc_reg
);
428 addrbase
= host
->sdhc_mmiobase
;
430 writel(pm_sdhc_reg
->sdcontrol_reg
, addrbase
+ VIA_CRDR_SDCTRL
);
431 writel(pm_sdhc_reg
->sdcmdarg_reg
, addrbase
+ VIA_CRDR_SDCARG
);
432 writel(pm_sdhc_reg
->sdbusmode_reg
, addrbase
+ VIA_CRDR_SDBUSMODE
);
433 writel(pm_sdhc_reg
->sdblklen_reg
, addrbase
+ VIA_CRDR_SDBLKLEN
);
434 writel(pm_sdhc_reg
->sdcurblkcnt_reg
, addrbase
+ VIA_CRDR_SDCURBLKCNT
);
435 writel(pm_sdhc_reg
->sdintmask_reg
, addrbase
+ VIA_CRDR_SDINTMASK
);
436 writel(pm_sdhc_reg
->sdstatus_reg
, addrbase
+ VIA_CRDR_SDSTATUS
);
437 writel(pm_sdhc_reg
->sdrsptmo_reg
, addrbase
+ VIA_CRDR_SDRSPTMO
);
438 writel(pm_sdhc_reg
->sdclksel_reg
, addrbase
+ VIA_CRDR_SDCLKSEL
);
439 writel(pm_sdhc_reg
->sdextctrl_reg
, addrbase
+ VIA_CRDR_SDEXTCTRL
);
442 static void via_pwron_sleep(struct via_crdr_mmc_host
*sdhost
)
444 if (sdhost
->quirks
& VIA_CRDR_QUIRK_300MS_PWRDELAY
)
450 static void via_set_ddma(struct via_crdr_mmc_host
*host
,
451 dma_addr_t dmaaddr
, u32 count
, int dir
, int enirq
)
453 void __iomem
*addrbase
;
457 ctrl_data
|= VIA_CRDR_DMACTRL_ENIRQ
;
460 ctrl_data
|= VIA_CRDR_DMACTRL_DIR
;
462 addrbase
= host
->ddma_mmiobase
;
464 writel(dmaaddr
, addrbase
+ VIA_CRDR_DMABASEADD
);
465 writel(count
, addrbase
+ VIA_CRDR_DMACOUNTER
);
466 writel(ctrl_data
, addrbase
+ VIA_CRDR_DMACTRL
);
467 writel(0x01, addrbase
+ VIA_CRDR_DMASTART
);
469 /* It seems that our DMA can not work normally with 375kHz clock */
470 /* FIXME: don't brute-force 8MHz but use PIO at 375kHz !! */
471 addrbase
= host
->pcictrl_mmiobase
;
472 if (readb(addrbase
+ VIA_CRDR_PCISDCCLK
) == PCI_CLK_375K
) {
473 dev_info(host
->mmc
->parent
, "forcing card speed to 8MHz\n");
474 writeb(PCI_CLK_8M
, addrbase
+ VIA_CRDR_PCISDCCLK
);
478 static void via_sdc_preparedata(struct via_crdr_mmc_host
*host
,
479 struct mmc_data
*data
)
481 void __iomem
*addrbase
;
488 BUG_ON(data
->blksz
> host
->mmc
->max_blk_size
);
489 BUG_ON(data
->blocks
> host
->mmc
->max_blk_count
);
493 count
= dma_map_sg(mmc_dev(host
->mmc
), data
->sg
, data
->sg_len
,
494 ((data
->flags
& MMC_DATA_READ
) ?
495 DMA_FROM_DEVICE
: DMA_TO_DEVICE
));
498 via_set_ddma(host
, sg_dma_address(data
->sg
), sg_dma_len(data
->sg
),
499 (data
->flags
& MMC_DATA_WRITE
) ? 1 : 0, 1);
501 addrbase
= host
->sdhc_mmiobase
;
503 blk_reg
= data
->blksz
- 1;
504 blk_reg
|= VIA_CRDR_SDBLKLEN_GPIDET
| VIA_CRDR_SDBLKLEN_INTEN
;
505 blk_reg
|= (data
->blocks
) << 16;
507 writel(blk_reg
, addrbase
+ VIA_CRDR_SDBLKLEN
);
510 static void via_sdc_get_response(struct via_crdr_mmc_host
*host
,
511 struct mmc_command
*cmd
)
513 void __iomem
*addrbase
= host
->sdhc_mmiobase
;
514 u32 dwdata0
= readl(addrbase
+ VIA_CRDR_SDRESP0
);
515 u32 dwdata1
= readl(addrbase
+ VIA_CRDR_SDRESP1
);
516 u32 dwdata2
= readl(addrbase
+ VIA_CRDR_SDRESP2
);
517 u32 dwdata3
= readl(addrbase
+ VIA_CRDR_SDRESP3
);
519 if (cmd
->flags
& MMC_RSP_136
) {
520 cmd
->resp
[0] = ((u8
) (dwdata1
)) |
521 (((u8
) (dwdata0
>> 24)) << 8) |
522 (((u8
) (dwdata0
>> 16)) << 16) |
523 (((u8
) (dwdata0
>> 8)) << 24);
525 cmd
->resp
[1] = ((u8
) (dwdata2
)) |
526 (((u8
) (dwdata1
>> 24)) << 8) |
527 (((u8
) (dwdata1
>> 16)) << 16) |
528 (((u8
) (dwdata1
>> 8)) << 24);
530 cmd
->resp
[2] = ((u8
) (dwdata3
)) |
531 (((u8
) (dwdata2
>> 24)) << 8) |
532 (((u8
) (dwdata2
>> 16)) << 16) |
533 (((u8
) (dwdata2
>> 8)) << 24);
535 cmd
->resp
[3] = 0xff |
536 ((((u8
) (dwdata3
>> 24))) << 8) |
537 (((u8
) (dwdata3
>> 16)) << 16) |
538 (((u8
) (dwdata3
>> 8)) << 24);
541 cmd
->resp
[0] = ((dwdata0
& 0xff) << 24) |
542 (((dwdata0
>> 8) & 0xff) << 16) |
543 (((dwdata0
>> 16) & 0xff) << 8) | (dwdata1
& 0xff);
546 cmd
->resp
[1] = ((dwdata1
& 0xff) << 24) |
547 (((dwdata1
>> 8) & 0xff) << 16) |
548 (((dwdata1
>> 16) & 0xff) << 8);
552 static void via_sdc_send_command(struct via_crdr_mmc_host
*host
,
553 struct mmc_command
*cmd
)
555 void __iomem
*addrbase
;
556 struct mmc_data
*data
;
557 unsigned int timeout_ms
;
565 timeout_ms
= cmd
->busy_timeout
? cmd
->busy_timeout
: VIA_CMD_TIMEOUT_MS
;
566 mod_timer(&host
->timer
, jiffies
+ msecs_to_jiffies(timeout_ms
));
569 cmdctrl
= cmd
->opcode
<< 8;
572 switch (mmc_resp_type(cmd
)) {
574 cmdctrl
|= VIA_CRDR_SDCTRL_RSP_NONE
;
577 cmdctrl
|= VIA_CRDR_SDCTRL_RSP_R1
;
580 cmdctrl
|= VIA_CRDR_SDCTRL_RSP_R1B
;
583 cmdctrl
|= VIA_CRDR_SDCTRL_RSP_R2
;
586 cmdctrl
|= VIA_CRDR_SDCTRL_RSP_R3
;
589 pr_err("%s: cmd->flag is not valid\n", mmc_hostname(host
->mmc
));
596 via_sdc_preparedata(host
, data
);
599 if (data
->blocks
> 1) {
600 if (data
->flags
& MMC_DATA_WRITE
) {
601 cmdctrl
|= VIA_CRDR_SDCTRL_WRITE
;
602 cmdctrl
|= VIA_CRDR_SDCTRL_MULTI_WR
;
604 cmdctrl
|= VIA_CRDR_SDCTRL_MULTI_RD
;
607 if (data
->flags
& MMC_DATA_WRITE
) {
608 cmdctrl
|= VIA_CRDR_SDCTRL_WRITE
;
609 cmdctrl
|= VIA_CRDR_SDCTRL_SINGLE_WR
;
611 cmdctrl
|= VIA_CRDR_SDCTRL_SINGLE_RD
;
616 if (cmd
== host
->mrq
->stop
)
617 cmdctrl
|= VIA_CRDR_SDCTRL_STOP
;
619 cmdctrl
|= VIA_CRDR_SDCTRL_START
;
621 addrbase
= host
->sdhc_mmiobase
;
622 writel(cmd
->arg
, addrbase
+ VIA_CRDR_SDCARG
);
623 writel(cmdctrl
, addrbase
+ VIA_CRDR_SDCTRL
);
626 static void via_sdc_finish_data(struct via_crdr_mmc_host
*host
)
628 struct mmc_data
*data
;
636 data
->bytes_xfered
= 0;
638 data
->bytes_xfered
= data
->blocks
* data
->blksz
;
640 dma_unmap_sg(mmc_dev(host
->mmc
), data
->sg
, data
->sg_len
,
641 ((data
->flags
& MMC_DATA_READ
) ?
642 DMA_FROM_DEVICE
: DMA_TO_DEVICE
));
645 via_sdc_send_command(host
, data
->stop
);
647 queue_work(system_bh_wq
, &host
->finish_bh_work
);
650 static void via_sdc_finish_command(struct via_crdr_mmc_host
*host
)
652 via_sdc_get_response(host
, host
->cmd
);
654 host
->cmd
->error
= 0;
656 if (!host
->cmd
->data
)
657 queue_work(system_bh_wq
, &host
->finish_bh_work
);
662 static void via_sdc_request(struct mmc_host
*mmc
, struct mmc_request
*mrq
)
664 void __iomem
*addrbase
;
665 struct via_crdr_mmc_host
*host
;
669 host
= mmc_priv(mmc
);
671 spin_lock_irqsave(&host
->lock
, flags
);
673 addrbase
= host
->pcictrl_mmiobase
;
674 writeb(VIA_CRDR_PCIDMACLK_SDC
, addrbase
+ VIA_CRDR_PCIDMACLK
);
676 status
= readw(host
->sdhc_mmiobase
+ VIA_CRDR_SDSTATUS
);
677 status
&= VIA_CRDR_SDSTS_W1C_MASK
;
678 writew(status
, host
->sdhc_mmiobase
+ VIA_CRDR_SDSTATUS
);
680 WARN_ON(host
->mrq
!= NULL
);
683 status
= readw(host
->sdhc_mmiobase
+ VIA_CRDR_SDSTATUS
);
684 if (!(status
& VIA_CRDR_SDSTS_SLOTG
) || host
->reject
) {
685 host
->mrq
->cmd
->error
= -ENOMEDIUM
;
686 queue_work(system_bh_wq
, &host
->finish_bh_work
);
688 via_sdc_send_command(host
, mrq
->cmd
);
691 spin_unlock_irqrestore(&host
->lock
, flags
);
694 static void via_sdc_set_power(struct via_crdr_mmc_host
*host
,
695 unsigned short power
, unsigned int on
)
700 spin_lock_irqsave(&host
->lock
, flags
);
702 host
->power
= (1 << power
);
704 gatt
= readb(host
->pcictrl_mmiobase
+ VIA_CRDR_PCICLKGATT
);
705 if (host
->power
== MMC_VDD_165_195
)
706 gatt
&= ~VIA_CRDR_PCICLKGATT_3V3
;
708 gatt
|= VIA_CRDR_PCICLKGATT_3V3
;
710 gatt
|= VIA_CRDR_PCICLKGATT_PAD_PWRON
;
712 gatt
&= ~VIA_CRDR_PCICLKGATT_PAD_PWRON
;
713 writeb(gatt
, host
->pcictrl_mmiobase
+ VIA_CRDR_PCICLKGATT
);
715 spin_unlock_irqrestore(&host
->lock
, flags
);
717 via_pwron_sleep(host
);
720 static void via_sdc_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
722 struct via_crdr_mmc_host
*host
;
724 void __iomem
*addrbase
;
725 u32 org_data
, sdextctrl
;
728 host
= mmc_priv(mmc
);
730 spin_lock_irqsave(&host
->lock
, flags
);
732 addrbase
= host
->sdhc_mmiobase
;
733 org_data
= readl(addrbase
+ VIA_CRDR_SDBUSMODE
);
734 sdextctrl
= readl(addrbase
+ VIA_CRDR_SDEXTCTRL
);
736 if (ios
->bus_width
== MMC_BUS_WIDTH_1
)
737 org_data
&= ~VIA_CRDR_SDMODE_4BIT
;
739 org_data
|= VIA_CRDR_SDMODE_4BIT
;
741 if (ios
->power_mode
== MMC_POWER_OFF
)
742 org_data
&= ~VIA_CRDR_SDMODE_CLK_ON
;
744 org_data
|= VIA_CRDR_SDMODE_CLK_ON
;
746 if (ios
->timing
== MMC_TIMING_SD_HS
)
747 sdextctrl
|= VIA_CRDR_SDEXTCTRL_HISPD
;
749 sdextctrl
&= ~VIA_CRDR_SDEXTCTRL_HISPD
;
751 writel(org_data
, addrbase
+ VIA_CRDR_SDBUSMODE
);
752 writel(sdextctrl
, addrbase
+ VIA_CRDR_SDEXTCTRL
);
754 if (ios
->clock
>= 48000000)
756 else if (ios
->clock
>= 33000000)
758 else if (ios
->clock
>= 24000000)
760 else if (ios
->clock
>= 16000000)
762 else if (ios
->clock
>= 12000000)
764 else if (ios
->clock
>= 8000000)
767 clock
= PCI_CLK_375K
;
769 addrbase
= host
->pcictrl_mmiobase
;
770 if (readb(addrbase
+ VIA_CRDR_PCISDCCLK
) != clock
)
771 writeb(clock
, addrbase
+ VIA_CRDR_PCISDCCLK
);
773 spin_unlock_irqrestore(&host
->lock
, flags
);
775 if (ios
->power_mode
!= MMC_POWER_OFF
)
776 via_sdc_set_power(host
, ios
->vdd
, 1);
778 via_sdc_set_power(host
, ios
->vdd
, 0);
781 static int via_sdc_get_ro(struct mmc_host
*mmc
)
783 struct via_crdr_mmc_host
*host
;
787 host
= mmc_priv(mmc
);
789 spin_lock_irqsave(&host
->lock
, flags
);
791 status
= readw(host
->sdhc_mmiobase
+ VIA_CRDR_SDSTATUS
);
793 spin_unlock_irqrestore(&host
->lock
, flags
);
795 return !(status
& VIA_CRDR_SDSTS_WP
);
798 static const struct mmc_host_ops via_sdc_ops
= {
799 .request
= via_sdc_request
,
800 .set_ios
= via_sdc_set_ios
,
801 .get_ro
= via_sdc_get_ro
,
804 static void via_reset_pcictrl(struct via_crdr_mmc_host
*host
)
809 spin_lock_irqsave(&host
->lock
, flags
);
811 via_save_pcictrlreg(host
);
812 via_save_sdcreg(host
);
814 spin_unlock_irqrestore(&host
->lock
, flags
);
816 gatt
= VIA_CRDR_PCICLKGATT_PAD_PWRON
;
817 if (host
->power
== MMC_VDD_165_195
)
818 gatt
&= VIA_CRDR_PCICLKGATT_3V3
;
820 gatt
|= VIA_CRDR_PCICLKGATT_3V3
;
821 writeb(gatt
, host
->pcictrl_mmiobase
+ VIA_CRDR_PCICLKGATT
);
822 via_pwron_sleep(host
);
823 gatt
|= VIA_CRDR_PCICLKGATT_SFTRST
;
824 writeb(gatt
, host
->pcictrl_mmiobase
+ VIA_CRDR_PCICLKGATT
);
827 spin_lock_irqsave(&host
->lock
, flags
);
829 via_restore_pcictrlreg(host
);
830 via_restore_sdcreg(host
);
832 spin_unlock_irqrestore(&host
->lock
, flags
);
835 static void via_sdc_cmd_isr(struct via_crdr_mmc_host
*host
, u16 intmask
)
837 BUG_ON(intmask
== 0);
840 pr_err("%s: Got command interrupt 0x%x even "
841 "though no command operation was in progress.\n",
842 mmc_hostname(host
->mmc
), intmask
);
846 if (intmask
& VIA_CRDR_SDSTS_CRTO
)
847 host
->cmd
->error
= -ETIMEDOUT
;
848 else if (intmask
& VIA_CRDR_SDSTS_SC
)
849 host
->cmd
->error
= -EILSEQ
;
851 if (host
->cmd
->error
)
852 queue_work(system_bh_wq
, &host
->finish_bh_work
);
853 else if (intmask
& VIA_CRDR_SDSTS_CRD
)
854 via_sdc_finish_command(host
);
857 static void via_sdc_data_isr(struct via_crdr_mmc_host
*host
, u16 intmask
)
859 BUG_ON(intmask
== 0);
864 if (intmask
& VIA_CRDR_SDSTS_DT
)
865 host
->data
->error
= -ETIMEDOUT
;
866 else if (intmask
& (VIA_CRDR_SDSTS_RC
| VIA_CRDR_SDSTS_WC
))
867 host
->data
->error
= -EILSEQ
;
869 via_sdc_finish_data(host
);
872 static irqreturn_t
via_sdc_isr(int irq
, void *dev_id
)
874 struct via_crdr_mmc_host
*sdhost
= dev_id
;
875 void __iomem
*addrbase
;
883 spin_lock(&sdhost
->lock
);
885 addrbase
= sdhost
->pcictrl_mmiobase
;
886 pci_status
= readb(addrbase
+ VIA_CRDR_PCIINTSTATUS
);
887 if (!(pci_status
& VIA_CRDR_PCIINTSTATUS_SDC
)) {
892 addrbase
= sdhost
->sdhc_mmiobase
;
893 sd_status
= readw(addrbase
+ VIA_CRDR_SDSTATUS
);
894 sd_status
&= VIA_CRDR_SDSTS_INT_MASK
;
895 sd_status
&= ~VIA_CRDR_SDSTS_IGN_MASK
;
901 if (sd_status
& VIA_CRDR_SDSTS_CIR
) {
902 writew(sd_status
& VIA_CRDR_SDSTS_CIR
,
903 addrbase
+ VIA_CRDR_SDSTATUS
);
905 schedule_work(&sdhost
->carddet_work
);
908 sd_status
&= ~VIA_CRDR_SDSTS_CIR
;
909 if (sd_status
& VIA_CRDR_SDSTS_CMD_MASK
) {
910 writew(sd_status
& VIA_CRDR_SDSTS_CMD_MASK
,
911 addrbase
+ VIA_CRDR_SDSTATUS
);
912 via_sdc_cmd_isr(sdhost
, sd_status
& VIA_CRDR_SDSTS_CMD_MASK
);
914 if (sd_status
& VIA_CRDR_SDSTS_DATA_MASK
) {
915 writew(sd_status
& VIA_CRDR_SDSTS_DATA_MASK
,
916 addrbase
+ VIA_CRDR_SDSTATUS
);
917 via_sdc_data_isr(sdhost
, sd_status
& VIA_CRDR_SDSTS_DATA_MASK
);
920 sd_status
&= ~(VIA_CRDR_SDSTS_CMD_MASK
| VIA_CRDR_SDSTS_DATA_MASK
);
922 pr_err("%s: Unexpected interrupt 0x%x\n",
923 mmc_hostname(sdhost
->mmc
), sd_status
);
924 writew(sd_status
, addrbase
+ VIA_CRDR_SDSTATUS
);
927 result
= IRQ_HANDLED
;
930 spin_unlock(&sdhost
->lock
);
935 static void via_sdc_timeout(struct timer_list
*t
)
937 struct via_crdr_mmc_host
*sdhost
;
940 sdhost
= from_timer(sdhost
, t
, timer
);
942 spin_lock_irqsave(&sdhost
->lock
, flags
);
945 pr_err("%s: Timeout waiting for hardware interrupt."
946 "cmd:0x%x\n", mmc_hostname(sdhost
->mmc
),
947 sdhost
->mrq
->cmd
->opcode
);
950 writel(VIA_CRDR_DMACTRL_SFTRST
,
951 sdhost
->ddma_mmiobase
+ VIA_CRDR_DMACTRL
);
952 sdhost
->data
->error
= -ETIMEDOUT
;
953 via_sdc_finish_data(sdhost
);
956 sdhost
->cmd
->error
= -ETIMEDOUT
;
958 sdhost
->mrq
->cmd
->error
= -ETIMEDOUT
;
959 queue_work(system_bh_wq
, &sdhost
->finish_bh_work
);
963 spin_unlock_irqrestore(&sdhost
->lock
, flags
);
966 static void via_sdc_finish_bh_work(struct work_struct
*t
)
968 struct via_crdr_mmc_host
*host
= from_work(host
, t
, finish_bh_work
);
970 struct mmc_request
*mrq
;
972 spin_lock_irqsave(&host
->lock
, flags
);
974 del_timer(&host
->timer
);
980 spin_unlock_irqrestore(&host
->lock
, flags
);
982 mmc_request_done(host
->mmc
, mrq
);
985 static void via_sdc_card_detect(struct work_struct
*work
)
987 struct via_crdr_mmc_host
*host
;
988 void __iomem
*addrbase
;
992 host
= container_of(work
, struct via_crdr_mmc_host
, carddet_work
);
994 addrbase
= host
->ddma_mmiobase
;
995 writel(VIA_CRDR_DMACTRL_SFTRST
, addrbase
+ VIA_CRDR_DMACTRL
);
997 spin_lock_irqsave(&host
->lock
, flags
);
999 addrbase
= host
->pcictrl_mmiobase
;
1000 writeb(VIA_CRDR_PCIDMACLK_SDC
, addrbase
+ VIA_CRDR_PCIDMACLK
);
1002 addrbase
= host
->sdhc_mmiobase
;
1003 status
= readw(addrbase
+ VIA_CRDR_SDSTATUS
);
1004 if (!(status
& VIA_CRDR_SDSTS_SLOTG
)) {
1006 pr_err("%s: Card removed during transfer!\n",
1007 mmc_hostname(host
->mmc
));
1008 host
->mrq
->cmd
->error
= -ENOMEDIUM
;
1009 queue_work(system_bh_wq
, &host
->finish_bh_work
);
1012 spin_unlock_irqrestore(&host
->lock
, flags
);
1014 via_reset_pcictrl(host
);
1016 spin_lock_irqsave(&host
->lock
, flags
);
1019 spin_unlock_irqrestore(&host
->lock
, flags
);
1021 via_print_pcictrl(host
);
1022 via_print_sdchc(host
);
1024 mmc_detect_change(host
->mmc
, msecs_to_jiffies(500));
1027 static void via_init_mmc_host(struct via_crdr_mmc_host
*host
)
1029 struct mmc_host
*mmc
= host
->mmc
;
1030 void __iomem
*addrbase
;
1034 timer_setup(&host
->timer
, via_sdc_timeout
, 0);
1036 spin_lock_init(&host
->lock
);
1038 mmc
->f_min
= VIA_CRDR_MIN_CLOCK
;
1039 mmc
->f_max
= VIA_CRDR_MAX_CLOCK
;
1040 mmc
->ocr_avail
= MMC_VDD_32_33
| MMC_VDD_33_34
| MMC_VDD_165_195
;
1041 mmc
->caps
= MMC_CAP_4_BIT_DATA
| MMC_CAP_SD_HIGHSPEED
;
1042 mmc
->ops
= &via_sdc_ops
;
1044 /*Hardware cannot do scatter lists*/
1047 mmc
->max_blk_size
= VIA_CRDR_MAX_BLOCK_LENGTH
;
1048 mmc
->max_blk_count
= VIA_CRDR_MAX_BLOCK_COUNT
;
1050 mmc
->max_seg_size
= mmc
->max_blk_size
* mmc
->max_blk_count
;
1051 mmc
->max_req_size
= mmc
->max_seg_size
;
1053 INIT_WORK(&host
->carddet_work
, via_sdc_card_detect
);
1055 INIT_WORK(&host
->finish_bh_work
, via_sdc_finish_bh_work
);
1057 addrbase
= host
->sdhc_mmiobase
;
1058 writel(0x0, addrbase
+ VIA_CRDR_SDINTMASK
);
1061 lenreg
= VIA_CRDR_SDBLKLEN_GPIDET
| VIA_CRDR_SDBLKLEN_INTEN
;
1062 writel(lenreg
, addrbase
+ VIA_CRDR_SDBLKLEN
);
1064 status
= readw(addrbase
+ VIA_CRDR_SDSTATUS
);
1065 status
&= VIA_CRDR_SDSTS_W1C_MASK
;
1066 writew(status
, addrbase
+ VIA_CRDR_SDSTATUS
);
1068 status
= readw(addrbase
+ VIA_CRDR_SDSTATUS2
);
1069 status
|= VIA_CRDR_SDSTS_CFE
;
1070 writew(status
, addrbase
+ VIA_CRDR_SDSTATUS2
);
1072 writeb(0x0, addrbase
+ VIA_CRDR_SDEXTCTRL
);
1074 writel(VIA_CRDR_SDACTIVE_INTMASK
, addrbase
+ VIA_CRDR_SDINTMASK
);
1078 static int via_sd_probe(struct pci_dev
*pcidev
,
1079 const struct pci_device_id
*id
)
1081 struct mmc_host
*mmc
;
1082 struct via_crdr_mmc_host
*sdhost
;
1088 ": VIA SDMMC controller found at %s [%04x:%04x] (rev %x)\n",
1089 pci_name(pcidev
), (int)pcidev
->vendor
, (int)pcidev
->device
,
1090 (int)pcidev
->revision
);
1092 ret
= pci_enable_device(pcidev
);
1096 ret
= pci_request_regions(pcidev
, DRV_NAME
);
1100 pci_write_config_byte(pcidev
, VIA_CRDR_PCI_WORK_MODE
, 0);
1101 pci_write_config_byte(pcidev
, VIA_CRDR_PCI_DBG_MODE
, 0);
1103 mmc
= mmc_alloc_host(sizeof(struct via_crdr_mmc_host
), &pcidev
->dev
);
1109 sdhost
= mmc_priv(mmc
);
1111 dev_set_drvdata(&pcidev
->dev
, sdhost
);
1113 len
= pci_resource_len(pcidev
, 0);
1114 base
= pci_resource_start(pcidev
, 0);
1115 sdhost
->mmiobase
= ioremap(base
, len
);
1116 if (!sdhost
->mmiobase
) {
1121 sdhost
->sdhc_mmiobase
=
1122 sdhost
->mmiobase
+ VIA_CRDR_SDC_OFF
;
1123 sdhost
->ddma_mmiobase
=
1124 sdhost
->mmiobase
+ VIA_CRDR_DDMA_OFF
;
1125 sdhost
->pcictrl_mmiobase
=
1126 sdhost
->mmiobase
+ VIA_CRDR_PCICTRL_OFF
;
1128 sdhost
->power
= MMC_VDD_165_195
;
1130 gatt
= VIA_CRDR_PCICLKGATT_3V3
| VIA_CRDR_PCICLKGATT_PAD_PWRON
;
1131 writeb(gatt
, sdhost
->pcictrl_mmiobase
+ VIA_CRDR_PCICLKGATT
);
1132 via_pwron_sleep(sdhost
);
1133 gatt
|= VIA_CRDR_PCICLKGATT_SFTRST
;
1134 writeb(gatt
, sdhost
->pcictrl_mmiobase
+ VIA_CRDR_PCICLKGATT
);
1137 via_init_mmc_host(sdhost
);
1140 request_irq(pcidev
->irq
, via_sdc_isr
, IRQF_SHARED
, DRV_NAME
,
1145 writeb(VIA_CRDR_PCIINTCTRL_SDCIRQEN
,
1146 sdhost
->pcictrl_mmiobase
+ VIA_CRDR_PCIINTCTRL
);
1147 writeb(VIA_CRDR_PCITMOCTRL_1024MS
,
1148 sdhost
->pcictrl_mmiobase
+ VIA_CRDR_PCITMOCTRL
);
1150 /* device-specific quirks */
1151 if (pcidev
->subsystem_vendor
== PCI_VENDOR_ID_LENOVO
&&
1152 pcidev
->subsystem_device
== 0x3891)
1153 sdhost
->quirks
= VIA_CRDR_QUIRK_300MS_PWRDELAY
;
1155 ret
= mmc_add_host(mmc
);
1162 iounmap(sdhost
->mmiobase
);
1166 pci_release_regions(pcidev
);
1168 pci_disable_device(pcidev
);
1173 static void via_sd_remove(struct pci_dev
*pcidev
)
1175 struct via_crdr_mmc_host
*sdhost
= pci_get_drvdata(pcidev
);
1176 unsigned long flags
;
1179 spin_lock_irqsave(&sdhost
->lock
, flags
);
1181 /* Ensure we don't accept more commands from mmc layer */
1184 /* Disable generating further interrupts */
1185 writeb(0x0, sdhost
->pcictrl_mmiobase
+ VIA_CRDR_PCIINTCTRL
);
1188 pr_err("%s: Controller removed during "
1189 "transfer\n", mmc_hostname(sdhost
->mmc
));
1191 /* make sure all DMA is stopped */
1192 writel(VIA_CRDR_DMACTRL_SFTRST
,
1193 sdhost
->ddma_mmiobase
+ VIA_CRDR_DMACTRL
);
1194 sdhost
->mrq
->cmd
->error
= -ENOMEDIUM
;
1195 if (sdhost
->mrq
->stop
)
1196 sdhost
->mrq
->stop
->error
= -ENOMEDIUM
;
1197 queue_work(system_bh_wq
, &sdhost
->finish_bh_work
);
1199 spin_unlock_irqrestore(&sdhost
->lock
, flags
);
1201 mmc_remove_host(sdhost
->mmc
);
1203 free_irq(pcidev
->irq
, sdhost
);
1205 del_timer_sync(&sdhost
->timer
);
1207 cancel_work_sync(&sdhost
->finish_bh_work
);
1209 /* switch off power */
1210 gatt
= readb(sdhost
->pcictrl_mmiobase
+ VIA_CRDR_PCICLKGATT
);
1211 gatt
&= ~VIA_CRDR_PCICLKGATT_PAD_PWRON
;
1212 writeb(gatt
, sdhost
->pcictrl_mmiobase
+ VIA_CRDR_PCICLKGATT
);
1214 iounmap(sdhost
->mmiobase
);
1215 mmc_free_host(sdhost
->mmc
);
1216 pci_release_regions(pcidev
);
1217 pci_disable_device(pcidev
);
1220 ": VIA SDMMC controller at %s [%04x:%04x] has been removed\n",
1221 pci_name(pcidev
), (int)pcidev
->vendor
, (int)pcidev
->device
);
1224 static void __maybe_unused
via_init_sdc_pm(struct via_crdr_mmc_host
*host
)
1226 struct sdhcreg
*pm_sdhcreg
;
1227 void __iomem
*addrbase
;
1231 pm_sdhcreg
= &(host
->pm_sdhc_reg
);
1232 addrbase
= host
->sdhc_mmiobase
;
1234 writel(0x0, addrbase
+ VIA_CRDR_SDINTMASK
);
1236 lenreg
= VIA_CRDR_SDBLKLEN_GPIDET
| VIA_CRDR_SDBLKLEN_INTEN
;
1237 writel(lenreg
, addrbase
+ VIA_CRDR_SDBLKLEN
);
1239 status
= readw(addrbase
+ VIA_CRDR_SDSTATUS
);
1240 status
&= VIA_CRDR_SDSTS_W1C_MASK
;
1241 writew(status
, addrbase
+ VIA_CRDR_SDSTATUS
);
1243 status
= readw(addrbase
+ VIA_CRDR_SDSTATUS2
);
1244 status
|= VIA_CRDR_SDSTS_CFE
;
1245 writew(status
, addrbase
+ VIA_CRDR_SDSTATUS2
);
1247 writel(pm_sdhcreg
->sdcontrol_reg
, addrbase
+ VIA_CRDR_SDCTRL
);
1248 writel(pm_sdhcreg
->sdcmdarg_reg
, addrbase
+ VIA_CRDR_SDCARG
);
1249 writel(pm_sdhcreg
->sdintmask_reg
, addrbase
+ VIA_CRDR_SDINTMASK
);
1250 writel(pm_sdhcreg
->sdrsptmo_reg
, addrbase
+ VIA_CRDR_SDRSPTMO
);
1251 writel(pm_sdhcreg
->sdclksel_reg
, addrbase
+ VIA_CRDR_SDCLKSEL
);
1252 writel(pm_sdhcreg
->sdextctrl_reg
, addrbase
+ VIA_CRDR_SDEXTCTRL
);
1254 via_print_pcictrl(host
);
1255 via_print_sdchc(host
);
1258 static int __maybe_unused
via_sd_suspend(struct device
*dev
)
1260 struct via_crdr_mmc_host
*host
;
1261 unsigned long flags
;
1263 host
= dev_get_drvdata(dev
);
1265 spin_lock_irqsave(&host
->lock
, flags
);
1266 via_save_pcictrlreg(host
);
1267 via_save_sdcreg(host
);
1268 spin_unlock_irqrestore(&host
->lock
, flags
);
1270 device_wakeup_enable(dev
);
1275 static int __maybe_unused
via_sd_resume(struct device
*dev
)
1277 struct via_crdr_mmc_host
*sdhost
;
1280 sdhost
= dev_get_drvdata(dev
);
1282 gatt
= VIA_CRDR_PCICLKGATT_PAD_PWRON
;
1283 if (sdhost
->power
== MMC_VDD_165_195
)
1284 gatt
&= ~VIA_CRDR_PCICLKGATT_3V3
;
1286 gatt
|= VIA_CRDR_PCICLKGATT_3V3
;
1287 writeb(gatt
, sdhost
->pcictrl_mmiobase
+ VIA_CRDR_PCICLKGATT
);
1288 via_pwron_sleep(sdhost
);
1289 gatt
|= VIA_CRDR_PCICLKGATT_SFTRST
;
1290 writeb(gatt
, sdhost
->pcictrl_mmiobase
+ VIA_CRDR_PCICLKGATT
);
1295 via_restore_pcictrlreg(sdhost
);
1296 via_init_sdc_pm(sdhost
);
1301 static SIMPLE_DEV_PM_OPS(via_sd_pm_ops
, via_sd_suspend
, via_sd_resume
);
1303 static struct pci_driver via_sd_driver
= {
1305 .id_table
= via_ids
,
1306 .probe
= via_sd_probe
,
1307 .remove
= via_sd_remove
,
1308 .driver
.pm
= &via_sd_pm_ops
,
1311 module_pci_driver(via_sd_driver
);
1313 MODULE_LICENSE("GPL");
1314 MODULE_AUTHOR("VIA Technologies Inc.");
1315 MODULE_DESCRIPTION("VIA SD/MMC Card Interface driver");