29 #include <linux/module.h>
30 #include <linux/pci.h>
40 #define DRIVER_NAME "sdricoh_cs"
42 static unsigned int switchlocked;
45 #define SDRICOH_PCI_REGION 0
46 #define SDRICOH_PCI_REGION_SIZE 0x1000
49 #define R104_VERSION 0x104
50 #define R200_CMD 0x200
51 #define R204_CMD_ARG 0x204
52 #define R208_DATAIO 0x208
53 #define R20C_RESP 0x20c
54 #define R21C_STATUS 0x21c
55 #define R2E0_INIT 0x2e0
56 #define R2E4_STATUS_RESP 0x2e4
57 #define R2F0_RESET 0x2f0
58 #define R224_MODE 0x224
59 #define R226_BLOCKSIZE 0x226
60 #define R228_POWER 0x228
61 #define R230_DATA 0x230
64 #define STATUS_CMD_FINISHED 0x00000001
65 #define STATUS_TRANSFER_FINISHED 0x00000004
66 #define STATUS_CARD_INSERTED 0x00000020
67 #define STATUS_CARD_LOCKED 0x00000080
68 #define STATUS_CMD_TIMEOUT 0x00400000
69 #define STATUS_READY_TO_READ 0x01000000
70 #define STATUS_READY_TO_WRITE 0x02000000
71 #define STATUS_BUSY 0x40000000
74 #define INIT_TIMEOUT 100
75 #define CMD_TIMEOUT 100000
76 #define TRANSFER_TIMEOUT 100000
77 #define BUSY_TIMEOUT 32767
82 PCMCIA_DEVICE_PROD_ID12(
"RICOH",
"Bay1Controller", 0xd9f522ed,
84 PCMCIA_DEVICE_PROD_ID12(
"RICOH",
"Bay Controller", 0xd9f522ed,
127 unsigned short value)
142 unsigned int timeout){
146 for (loop = 0; loop < timeout; loop++) {
153 if (loop == timeout) {
154 dev_err(dev,
"query_status: timeout waiting for %x\n", wanted);
159 if (status & 0x7F0000) {
160 dev_err(dev,
"waiting for status bit %x failed\n", wanted);
172 unsigned int loop = 0;
177 sdricoh_writel(host,
R200_CMD, (0x10000 << 8) | opcode);
202 sdricoh_writel(host,
R2E0_INIT, 0x10000);
203 if (sdricoh_readl(host,
R2E0_INIT) != 0x10000)
205 sdricoh_writel(host,
R2E0_INIT, 0x10007);
207 sdricoh_writel(host,
R224_MODE, 0x2000000);
251 data |= (
u32)*buf << 24;
271 unsigned char opcode = cmd->
opcode;
274 dev_dbg(dev,
"=============================\n");
275 dev_dbg(dev,
"sdricoh_request opcode=%i\n", opcode);
283 }
else if (opcode == 55)
292 cmd->
error = sdricoh_mmc_cmd(host, opcode, cmd->
arg);
298 for (i = 0; i < 4; i++) {
312 if (data && cmd->
error == 0) {
313 dev_dbg(dev,
"transfer: blksz %i blocks %i sg_len %i "
319 for (i = 0; i < data->
blocks; i++) {
320 size_t len = data->
blksz;
324 page = sg_page(data->
sg);
326 buf =
kmap(page) + data->
sg->offset + (len *
i);
328 sdricoh_blockio(host,
333 dev_err(dev,
"sdricoh_request: cmd %i "
334 "block transfer failed\n", cmd->
opcode);
345 dev_err(dev,
"sdricoh_request: transfer end error\n");
352 dev_dbg(dev,
"=============================\n");
364 sdricoh_writel(host,
R224_MODE, 0x2000300);
367 sdricoh_writel(host,
R224_MODE, 0x2000340);
371 sdricoh_writel(host,
R224_MODE, 0x2000320);
376 static int sdricoh_get_ro(
struct mmc_host *mmc)
392 .request = sdricoh_request,
393 .set_ios = sdricoh_set_ios,
394 .get_ro = sdricoh_get_ro,
399 struct pcmcia_device *pcmcia_dev)
405 struct device *dev = &pcmcia_dev->dev;
409 dev_dbg(dev,
"unexpected pci resource len\n");
415 dev_err(dev,
"unable to map iobase\n");
420 dev_dbg(dev,
"no supported mmc controller found\n");
425 mmc = pcmcia_dev->priv =
428 dev_err(dev,
"mmc_alloc_host failed\n");
432 host = mmc_priv(mmc);
438 mmc->
ops = &sdricoh_ops;
443 mmc->
f_max = 24000000;
451 if (sdricoh_reset(host)) {
452 dev_dbg(dev,
"could not reset\n");
461 dev_dbg(dev,
"mmc host registered\n");
475 static int sdricoh_pcmcia_probe(
struct pcmcia_device *pcmcia_dev)
477 struct pci_dev *pci_dev =
NULL;
479 dev_info(&pcmcia_dev->dev,
"Searching MMC controller for pcmcia device"
480 " %s %s ...\n", pcmcia_dev->prod_id[0], pcmcia_dev->prod_id[1]);
488 if (!sdricoh_init_mmc(pci_dev, pcmcia_dev)) {
489 dev_info(&pcmcia_dev->dev,
"MMC controller found\n");
494 dev_err(&pcmcia_dev->dev,
"No MMC controller was found.\n");
498 static void sdricoh_pcmcia_detach(
struct pcmcia_device *
link)
502 dev_dbg(&link->dev,
"detach\n");
520 dev_dbg(&link->dev,
"suspend\n");
528 dev_dbg(&link->dev,
"resume\n");
529 sdricoh_reset(mmc_priv(mmc));
534 #define sdricoh_pcmcia_suspend NULL
535 #define sdricoh_pcmcia_resume NULL
538 static struct pcmcia_driver sdricoh_driver = {
540 .probe = sdricoh_pcmcia_probe,
541 .remove = sdricoh_pcmcia_detach,
542 .id_table = pcmcia_ids,
553 static int __init sdricoh_drv_init(
void)
558 static void __exit sdricoh_drv_exit(
void)
573 "Use this when unlocked cards are shown readonly (default 0)");