[PATCH] MMC: wbsd update

Updates to the wbsd driver.

* Fix to handle DAT3 card detection.
* Fixed bug which could cause large writes to stall in FIFO mode.
* Plug 'n Play support. In most cases you need ACPI PNP for this to work.
* Uses generic DMA API (ISA dependency removed).

authored by

Pierre Ossman and committed by
Russell King
85bcc130 88d7bd8c

+598 -240
+1 -1
drivers/mmc/Kconfig
··· 51 51 52 52 config MMC_WBSD 53 53 tristate "Winbond W83L51xD SD/MMC Card Interface support" 54 - depends on MMC && ISA && ISA_DMA_API 54 + depends on MMC && ISA_DMA_API 55 55 help 56 56 This selects the Winbond(R) W83L51xD Secure digital and 57 57 Multimedia card Interface.
+585 -239
drivers/mmc/wbsd.c
··· 28 28 #include <linux/ioport.h> 29 29 #include <linux/device.h> 30 30 #include <linux/interrupt.h> 31 + #include <linux/dma-mapping.h> 31 32 #include <linux/delay.h> 33 + #include <linux/pnp.h> 32 34 #include <linux/highmem.h> 33 35 #include <linux/mmc/host.h> 34 36 #include <linux/mmc/protocol.h> ··· 42 40 #include "wbsd.h" 43 41 44 42 #define DRIVER_NAME "wbsd" 45 - #define DRIVER_VERSION "1.1" 43 + #define DRIVER_VERSION "1.2" 46 44 47 45 #ifdef CONFIG_MMC_DEBUG 48 46 #define DBG(x...) \ ··· 53 51 #define DBG(x...) do { } while (0) 54 52 #define DBGF(x...) do { } while (0) 55 53 #endif 56 - 57 - static unsigned int io = 0x248; 58 - static unsigned int irq = 6; 59 - static int dma = 2; 60 54 61 55 #ifdef CONFIG_MMC_DEBUG 62 56 void DBG_REG(int reg, u8 value) ··· 77 79 #endif 78 80 79 81 /* 82 + * Device resources 83 + */ 84 + 85 + #ifdef CONFIG_PNP 86 + 87 + static const struct pnp_device_id pnp_dev_table[] = { 88 + { "WEC0517", 0 }, 89 + { "WEC0518", 0 }, 90 + { "", 0 }, 91 + }; 92 + 93 + MODULE_DEVICE_TABLE(pnp, pnp_dev_table); 94 + 95 + #endif /* CONFIG_PNP */ 96 + 97 + #ifdef CONFIG_PNP 98 + static unsigned int nopnp = 0; 99 + #else 100 + static const unsigned int nopnp = 1; 101 + #endif 102 + static unsigned int io = 0x248; 103 + static unsigned int irq = 6; 104 + static int dma = 2; 105 + 106 + /* 80 107 * Basic functions 81 108 */ 82 109 83 110 static inline void wbsd_unlock_config(struct wbsd_host* host) 84 111 { 112 + BUG_ON(host->config == 0); 113 + 85 114 outb(host->unlock_code, host->config); 86 115 outb(host->unlock_code, host->config); 87 116 } 88 117 89 118 static inline void wbsd_lock_config(struct wbsd_host* host) 90 119 { 120 + BUG_ON(host->config == 0); 121 + 91 122 outb(LOCK_CODE, host->config); 92 123 } 93 124 94 125 static inline void wbsd_write_config(struct wbsd_host* host, u8 reg, u8 value) 95 126 { 127 + BUG_ON(host->config == 0); 128 + 96 129 outb(reg, host->config); 97 130 outb(value, host->config + 1); 98 131 } 99 132 100 133 static inline u8 wbsd_read_config(struct wbsd_host* host, u8 reg) 101 134 { 135 + BUG_ON(host->config == 0); 136 + 102 137 outb(reg, host->config); 103 138 return inb(host->config + 1); 104 139 } ··· 164 133 wbsd_write_index(host, WBSD_IDX_SETUP, setup); 165 134 166 135 /* 136 + * Set DAT3 to input 137 + */ 138 + setup &= ~WBSD_DAT3_H; 139 + wbsd_write_index(host, WBSD_IDX_SETUP, setup); 140 + host->flags &= ~WBSD_FIGNORE_DETECT; 141 + 142 + /* 167 143 * Read back default clock. 168 144 */ 169 145 host->clk = wbsd_read_index(host, WBSD_IDX_CLK); ··· 184 146 * Set maximum timeout. 185 147 */ 186 148 wbsd_write_index(host, WBSD_IDX_TAAC, 0x7F); 149 + 150 + /* 151 + * Test for card presence 152 + */ 153 + if (inb(host->base + WBSD_CSR) & WBSD_CARDPRESENT) 154 + host->flags |= WBSD_FCARD_PRESENT; 155 + else 156 + host->flags &= ~WBSD_FCARD_PRESENT; 187 157 188 158 /* 189 159 * Enable interesting interrupts. ··· 453 407 } 454 408 } 455 409 456 - static irqreturn_t wbsd_irq(int irq, void *dev_id, struct pt_regs *regs); 457 - 458 410 static void wbsd_send_command(struct wbsd_host* host, struct mmc_command* cmd) 459 411 { 460 412 int i; ··· 690 646 } 691 647 692 648 wbsd_kunmap_sg(host); 649 + 650 + /* 651 + * The controller stops sending interrupts for 652 + * 'FIFO empty' under certain conditions. So we 653 + * need to be a bit more pro-active. 654 + */ 655 + tasklet_schedule(&host->fifo_tasklet); 693 656 } 694 657 695 658 static void wbsd_prepare_data(struct wbsd_host* host, struct mmc_data* data) ··· 901 850 wbsd_request_end(host, host->mrq); 902 851 } 903 852 904 - /* 905 - * MMC Callbacks 906 - */ 853 + /*****************************************************************************\ 854 + * * 855 + * MMC layer callbacks * 856 + * * 857 + \*****************************************************************************/ 907 858 908 859 static void wbsd_request(struct mmc_host* mmc, struct mmc_request* mrq) 909 860 { ··· 927 874 * If there is no card in the slot then 928 875 * timeout immediatly. 929 876 */ 930 - if (!(inb(host->base + WBSD_CSR) & WBSD_CARDPRESENT)) 877 + if (!(host->flags & WBSD_FCARD_PRESENT)) 931 878 { 932 879 cmd->error = MMC_ERR_TIMEOUT; 933 880 goto done; ··· 1006 953 host->clk = clk; 1007 954 } 1008 955 956 + /* 957 + * Power up card. 958 + */ 1009 959 if (ios->power_mode != MMC_POWER_OFF) 1010 960 { 1011 - /* 1012 - * Power up card. 1013 - */ 1014 961 pwr = inb(host->base + WBSD_CSR); 1015 962 pwr &= ~WBSD_POWER_N; 1016 963 outb(pwr, host->base + WBSD_CSR); 1017 - 1018 - /* 1019 - * This behaviour is stolen from the 1020 - * Windows driver. Don't know why, but 1021 - * it is needed. 1022 - */ 1023 - setup = wbsd_read_index(host, WBSD_IDX_SETUP); 1024 - if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) 1025 - setup |= WBSD_DAT3_H; 1026 - else 1027 - setup &= ~WBSD_DAT3_H; 1028 - wbsd_write_index(host, WBSD_IDX_SETUP, setup); 1029 - 1030 - mdelay(1); 1031 964 } 1032 965 966 + /* 967 + * MMC cards need to have pin 1 high during init. 968 + * Init time corresponds rather nicely with the bus mode. 969 + * It wreaks havoc with the card detection though so 970 + * that needs to be disabed. 971 + */ 972 + setup = wbsd_read_index(host, WBSD_IDX_SETUP); 973 + if ((ios->power_mode == MMC_POWER_ON) && 974 + (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)) 975 + { 976 + setup |= WBSD_DAT3_H; 977 + host->flags |= WBSD_FIGNORE_DETECT; 978 + } 979 + else 980 + { 981 + setup &= ~WBSD_DAT3_H; 982 + host->flags &= ~WBSD_FIGNORE_DETECT; 983 + } 984 + wbsd_write_index(host, WBSD_IDX_SETUP, setup); 985 + 1033 986 spin_unlock_bh(&host->lock); 1034 987 } 988 + 989 + static struct mmc_host_ops wbsd_ops = { 990 + .request = wbsd_request, 991 + .set_ios = wbsd_set_ios, 992 + }; 993 + 994 + /*****************************************************************************\ 995 + * * 996 + * Interrupt handling * 997 + * * 998 + \*****************************************************************************/ 1035 999 1036 1000 /* 1037 1001 * Tasklets ··· 1075 1005 { 1076 1006 struct wbsd_host* host = (struct wbsd_host*)param; 1077 1007 u8 csr; 1008 + int change = 0; 1078 1009 1079 1010 spin_lock(&host->lock); 1011 + 1012 + if (host->flags & WBSD_FIGNORE_DETECT) 1013 + { 1014 + spin_unlock(&host->lock); 1015 + return; 1016 + } 1080 1017 1081 1018 csr = inb(host->base + WBSD_CSR); 1082 1019 WARN_ON(csr == 0xff); 1083 1020 1084 1021 if (csr & WBSD_CARDPRESENT) 1085 - DBG("Card inserted\n"); 1086 - else 1022 + { 1023 + if (!(host->flags & WBSD_FCARD_PRESENT)) 1024 + { 1025 + DBG("Card inserted\n"); 1026 + host->flags |= WBSD_FCARD_PRESENT; 1027 + change = 1; 1028 + } 1029 + } 1030 + else if (host->flags & WBSD_FCARD_PRESENT) 1087 1031 { 1088 1032 DBG("Card removed\n"); 1033 + host->flags &= ~WBSD_FCARD_PRESENT; 1034 + change = 1; 1089 1035 1090 1036 if (host->mrq) 1091 1037 { ··· 1119 1033 */ 1120 1034 spin_unlock(&host->lock); 1121 1035 1122 - mmc_detect_change(host->mmc); 1036 + if (change) 1037 + mmc_detect_change(host->mmc); 1123 1038 } 1124 1039 1125 1040 static void wbsd_tasklet_fifo(unsigned long param) ··· 1287 1200 return IRQ_HANDLED; 1288 1201 } 1289 1202 1203 + /*****************************************************************************\ 1204 + * * 1205 + * Device initialisation and shutdown * 1206 + * * 1207 + \*****************************************************************************/ 1208 + 1290 1209 /* 1291 - * Support functions for probe 1210 + * Allocate/free MMC structure. 1292 1211 */ 1293 1212 1294 - static int wbsd_scan(struct wbsd_host* host) 1213 + static int __devinit wbsd_alloc_mmc(struct device* dev) 1214 + { 1215 + struct mmc_host* mmc; 1216 + struct wbsd_host* host; 1217 + 1218 + /* 1219 + * Allocate MMC structure. 1220 + */ 1221 + mmc = mmc_alloc_host(sizeof(struct wbsd_host), dev); 1222 + if (!mmc) 1223 + return -ENOMEM; 1224 + 1225 + host = mmc_priv(mmc); 1226 + host->mmc = mmc; 1227 + 1228 + host->dma = -1; 1229 + 1230 + /* 1231 + * Set host parameters. 1232 + */ 1233 + mmc->ops = &wbsd_ops; 1234 + mmc->f_min = 375000; 1235 + mmc->f_max = 24000000; 1236 + mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34; 1237 + 1238 + spin_lock_init(&host->lock); 1239 + 1240 + /* 1241 + * Maximum number of segments. Worst case is one sector per segment 1242 + * so this will be 64kB/512. 1243 + */ 1244 + mmc->max_hw_segs = 128; 1245 + mmc->max_phys_segs = 128; 1246 + 1247 + /* 1248 + * Maximum number of sectors in one transfer. Also limited by 64kB 1249 + * buffer. 1250 + */ 1251 + mmc->max_sectors = 128; 1252 + 1253 + /* 1254 + * Maximum segment size. Could be one segment with the maximum number 1255 + * of segments. 1256 + */ 1257 + mmc->max_seg_size = mmc->max_sectors * 512; 1258 + 1259 + dev_set_drvdata(dev, mmc); 1260 + 1261 + return 0; 1262 + } 1263 + 1264 + static void __devexit wbsd_free_mmc(struct device* dev) 1265 + { 1266 + struct mmc_host* mmc; 1267 + 1268 + mmc = dev_get_drvdata(dev); 1269 + if (!mmc) 1270 + return; 1271 + 1272 + mmc_free_host(mmc); 1273 + 1274 + dev_set_drvdata(dev, NULL); 1275 + } 1276 + 1277 + /* 1278 + * Scan for known chip id:s 1279 + */ 1280 + 1281 + static int __devinit wbsd_scan(struct wbsd_host* host) 1295 1282 { 1296 1283 int i, j, k; 1297 1284 int id; ··· 1419 1258 return -ENODEV; 1420 1259 } 1421 1260 1422 - static int wbsd_request_regions(struct wbsd_host* host) 1261 + /* 1262 + * Allocate/free io port ranges 1263 + */ 1264 + 1265 + static int __devinit wbsd_request_region(struct wbsd_host* host, int base) 1423 1266 { 1424 1267 if (io & 0x7) 1425 1268 return -EINVAL; 1426 1269 1427 - if (!request_region(io, 8, DRIVER_NAME)) 1270 + if (!request_region(base, 8, DRIVER_NAME)) 1428 1271 return -EIO; 1429 1272 1430 1273 host->base = io; ··· 1436 1271 return 0; 1437 1272 } 1438 1273 1439 - static void wbsd_release_regions(struct wbsd_host* host) 1274 + static void __devexit wbsd_release_regions(struct wbsd_host* host) 1440 1275 { 1441 1276 if (host->base) 1442 1277 release_region(host->base, 8); 1278 + 1279 + host->base = 0; 1443 1280 1444 1281 if (host->config) 1445 1282 release_region(host->config, 2); 1283 + 1284 + host->config = 0; 1446 1285 } 1447 1286 1448 - static void wbsd_init_dma(struct wbsd_host* host) 1287 + /* 1288 + * Allocate/free DMA port and buffer 1289 + */ 1290 + 1291 + static void __devinit wbsd_request_dma(struct wbsd_host* host, int dma) 1449 1292 { 1450 - host->dma = -1; 1451 - 1452 1293 if (dma < 0) 1453 1294 return; 1454 1295 ··· 1465 1294 * We need to allocate a special buffer in 1466 1295 * order for ISA to be able to DMA to it. 1467 1296 */ 1468 - host->dma_buffer = kmalloc(65536, 1297 + host->dma_buffer = kmalloc(WBSD_DMA_SIZE, 1469 1298 GFP_NOIO | GFP_DMA | __GFP_REPEAT | __GFP_NOWARN); 1470 1299 if (!host->dma_buffer) 1471 1300 goto free; ··· 1473 1302 /* 1474 1303 * Translate the address to a physical address. 1475 1304 */ 1476 - host->dma_addr = isa_virt_to_bus(host->dma_buffer); 1305 + host->dma_addr = dma_map_single(host->mmc->dev, host->dma_buffer, 1306 + WBSD_DMA_SIZE, DMA_BIDIRECTIONAL); 1477 1307 1478 1308 /* 1479 1309 * ISA DMA must be aligned on a 64k basis. ··· 1497 1325 */ 1498 1326 BUG_ON(1); 1499 1327 1328 + dma_unmap_single(host->mmc->dev, host->dma_addr, WBSD_DMA_SIZE, 1329 + DMA_BIDIRECTIONAL); 1330 + host->dma_addr = (dma_addr_t)NULL; 1331 + 1500 1332 kfree(host->dma_buffer); 1501 1333 host->dma_buffer = NULL; 1502 1334 ··· 1512 1336 "Falling back on FIFO.\n", dma); 1513 1337 } 1514 1338 1515 - static struct mmc_host_ops wbsd_ops = { 1516 - .request = wbsd_request, 1517 - .set_ios = wbsd_set_ios, 1518 - }; 1339 + static void __devexit wbsd_release_dma(struct wbsd_host* host) 1340 + { 1341 + if (host->dma_addr) 1342 + dma_unmap_single(host->mmc->dev, host->dma_addr, WBSD_DMA_SIZE, 1343 + DMA_BIDIRECTIONAL); 1344 + if (host->dma_buffer) 1345 + kfree(host->dma_buffer); 1346 + if (host->dma >= 0) 1347 + free_dma(host->dma); 1348 + 1349 + host->dma = -1; 1350 + host->dma_buffer = NULL; 1351 + host->dma_addr = (dma_addr_t)NULL; 1352 + } 1519 1353 1520 1354 /* 1521 - * Device probe 1355 + * Allocate/free IRQ. 1522 1356 */ 1523 1357 1524 - static int wbsd_probe(struct device* dev) 1358 + static int __devinit wbsd_request_irq(struct wbsd_host* host, int irq) 1525 1359 { 1526 - struct wbsd_host* host = NULL; 1527 - struct mmc_host* mmc = NULL; 1528 1360 int ret; 1529 1361 1530 1362 /* 1531 - * Allocate MMC structure. 1532 - */ 1533 - mmc = mmc_alloc_host(sizeof(struct wbsd_host), dev); 1534 - if (!mmc) 1535 - return -ENOMEM; 1536 - 1537 - host = mmc_priv(mmc); 1538 - host->mmc = mmc; 1539 - 1540 - /* 1541 - * Scan for hardware. 1542 - */ 1543 - ret = wbsd_scan(host); 1544 - if (ret) 1545 - goto freemmc; 1546 - 1547 - /* 1548 - * Reset the chip. 1549 - */ 1550 - wbsd_write_config(host, WBSD_CONF_SWRST, 1); 1551 - wbsd_write_config(host, WBSD_CONF_SWRST, 0); 1552 - 1553 - /* 1554 - * Allocate I/O ports. 1555 - */ 1556 - ret = wbsd_request_regions(host); 1557 - if (ret) 1558 - goto release; 1559 - 1560 - /* 1561 - * Set host parameters. 1562 - */ 1563 - mmc->ops = &wbsd_ops; 1564 - mmc->f_min = 375000; 1565 - mmc->f_max = 24000000; 1566 - mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34; 1567 - 1568 - spin_lock_init(&host->lock); 1569 - 1570 - /* 1571 - * Select SD/MMC function. 1572 - */ 1573 - wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); 1574 - 1575 - /* 1576 - * Set up card detection. 1577 - */ 1578 - wbsd_write_config(host, WBSD_CONF_PINS, 0x02); 1579 - 1580 - /* 1581 - * Configure I/O port. 1582 - */ 1583 - wbsd_write_config(host, WBSD_CONF_PORT_HI, host->base >> 8); 1584 - wbsd_write_config(host, WBSD_CONF_PORT_LO, host->base & 0xff); 1585 - 1586 - /* 1587 1363 * Allocate interrupt. 1588 1364 */ 1365 + 1589 1366 ret = request_irq(irq, wbsd_irq, SA_SHIRQ, DRIVER_NAME, host); 1590 1367 if (ret) 1591 - goto release; 1368 + return ret; 1592 1369 1593 1370 host->irq = irq; 1594 - 1371 + 1595 1372 /* 1596 1373 * Set up tasklets. 1597 1374 */ ··· 1555 1426 tasklet_init(&host->finish_tasklet, wbsd_tasklet_finish, (unsigned long)host); 1556 1427 tasklet_init(&host->block_tasklet, wbsd_tasklet_block, (unsigned long)host); 1557 1428 1558 - /* 1559 - * Configure interrupt. 1560 - */ 1561 - wbsd_write_config(host, WBSD_CONF_IRQ, host->irq); 1562 - 1563 - /* 1564 - * Allocate DMA. 1565 - */ 1566 - wbsd_init_dma(host); 1567 - 1568 - /* 1569 - * If all went well, then configure DMA. 1570 - */ 1571 - if (host->dma >= 0) 1572 - wbsd_write_config(host, WBSD_CONF_DRQ, host->dma); 1573 - 1574 - /* 1575 - * Maximum number of segments. Worst case is one sector per segment 1576 - * so this will be 64kB/512. 1577 - */ 1578 - mmc->max_hw_segs = 128; 1579 - mmc->max_phys_segs = 128; 1580 - 1581 - /* 1582 - * Maximum number of sectors in one transfer. Also limited by 64kB 1583 - * buffer. 1584 - */ 1585 - mmc->max_sectors = 128; 1586 - 1587 - /* 1588 - * Maximum segment size. Could be one segment with the maximum number 1589 - * of segments. 1590 - */ 1591 - mmc->max_seg_size = mmc->max_sectors * 512; 1592 - 1593 - /* 1594 - * Enable chip. 1595 - */ 1596 - wbsd_write_config(host, WBSD_CONF_ENABLE, 1); 1597 - 1598 - /* 1599 - * Power up chip. 1600 - */ 1601 - wbsd_write_config(host, WBSD_CONF_POWER, 0x20); 1602 - 1603 - /* 1604 - * Power Management stuff. No idea how this works. 1605 - * Not tested. 1606 - */ 1607 - #ifdef CONFIG_PM 1608 - wbsd_write_config(host, WBSD_CONF_PME, 0xA0); 1609 - #endif 1610 - 1611 - /* 1612 - * Reset the chip into a known state. 1613 - */ 1614 - wbsd_init_device(host); 1615 - 1616 - dev_set_drvdata(dev, mmc); 1617 - 1618 - /* 1619 - * Add host to MMC layer. 1620 - */ 1621 - mmc_add_host(mmc); 1622 - 1623 - printk(KERN_INFO "%s: W83L51xD id %x at 0x%x irq %d dma %d\n", 1624 - mmc->host_name, (int)host->chip_id, (int)host->base, 1625 - (int)host->irq, (int)host->dma); 1626 - 1627 1429 return 0; 1628 - 1629 - release: 1630 - wbsd_release_regions(host); 1631 - 1632 - freemmc: 1633 - mmc_free_host(mmc); 1634 - 1635 - return ret; 1636 1430 } 1637 1431 1638 - /* 1639 - * Device remove 1640 - */ 1641 - 1642 - static int wbsd_remove(struct device* dev) 1432 + static void __devexit wbsd_release_irq(struct wbsd_host* host) 1643 1433 { 1644 - struct mmc_host* mmc = dev_get_drvdata(dev); 1645 - struct wbsd_host* host; 1646 - 1647 - if (!mmc) 1648 - return 0; 1649 - 1650 - host = mmc_priv(mmc); 1651 - 1652 - /* 1653 - * Unregister host with MMC layer. 1654 - */ 1655 - mmc_remove_host(mmc); 1656 - 1657 - /* 1658 - * Power down the SD/MMC function. 1659 - */ 1660 - wbsd_unlock_config(host); 1661 - wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); 1662 - wbsd_write_config(host, WBSD_CONF_ENABLE, 0); 1663 - wbsd_lock_config(host); 1664 - 1665 - /* 1666 - * Free resources. 1667 - */ 1668 - if (host->dma_buffer) 1669 - kfree(host->dma_buffer); 1670 - 1671 - if (host->dma >= 0) 1672 - free_dma(host->dma); 1434 + if (!host->irq) 1435 + return; 1673 1436 1674 1437 free_irq(host->irq, host); 1675 1438 1439 + host->irq = 0; 1440 + 1676 1441 tasklet_kill(&host->card_tasklet); 1677 1442 tasklet_kill(&host->fifo_tasklet); 1678 1443 tasklet_kill(&host->crc_tasklet); 1679 1444 tasklet_kill(&host->timeout_tasklet); 1680 1445 tasklet_kill(&host->finish_tasklet); 1681 1446 tasklet_kill(&host->block_tasklet); 1447 + } 1448 + 1449 + /* 1450 + * Allocate all resources for the host. 1451 + */ 1452 + 1453 + static int __devinit wbsd_request_resources(struct wbsd_host* host, 1454 + int base, int irq, int dma) 1455 + { 1456 + int ret; 1682 1457 1458 + /* 1459 + * Allocate I/O ports. 1460 + */ 1461 + ret = wbsd_request_region(host, base); 1462 + if (ret) 1463 + return ret; 1464 + 1465 + /* 1466 + * Allocate interrupt. 1467 + */ 1468 + ret = wbsd_request_irq(host, irq); 1469 + if (ret) 1470 + return ret; 1471 + 1472 + /* 1473 + * Allocate DMA. 1474 + */ 1475 + wbsd_request_dma(host, dma); 1476 + 1477 + return 0; 1478 + } 1479 + 1480 + /* 1481 + * Release all resources for the host. 1482 + */ 1483 + 1484 + static void __devexit wbsd_release_resources(struct wbsd_host* host) 1485 + { 1486 + wbsd_release_dma(host); 1487 + wbsd_release_irq(host); 1683 1488 wbsd_release_regions(host); 1489 + } 1490 + 1491 + /* 1492 + * Configure the resources the chip should use. 1493 + */ 1494 + 1495 + static void __devinit wbsd_chip_config(struct wbsd_host* host) 1496 + { 1497 + /* 1498 + * Reset the chip. 1499 + */ 1500 + wbsd_write_config(host, WBSD_CONF_SWRST, 1); 1501 + wbsd_write_config(host, WBSD_CONF_SWRST, 0); 1502 + 1503 + /* 1504 + * Select SD/MMC function. 1505 + */ 1506 + wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); 1684 1507 1685 - mmc_free_host(mmc); 1508 + /* 1509 + * Set up card detection. 1510 + */ 1511 + wbsd_write_config(host, WBSD_CONF_PINS, WBSD_PINS_DETECT_GP11); 1512 + 1513 + /* 1514 + * Configure chip 1515 + */ 1516 + wbsd_write_config(host, WBSD_CONF_PORT_HI, host->base >> 8); 1517 + wbsd_write_config(host, WBSD_CONF_PORT_LO, host->base & 0xff); 1518 + 1519 + wbsd_write_config(host, WBSD_CONF_IRQ, host->irq); 1520 + 1521 + if (host->dma >= 0) 1522 + wbsd_write_config(host, WBSD_CONF_DRQ, host->dma); 1523 + 1524 + /* 1525 + * Enable and power up chip. 1526 + */ 1527 + wbsd_write_config(host, WBSD_CONF_ENABLE, 1); 1528 + wbsd_write_config(host, WBSD_CONF_POWER, 0x20); 1529 + } 1530 + 1531 + /* 1532 + * Check that configured resources are correct. 1533 + */ 1534 + 1535 + static int __devinit wbsd_chip_validate(struct wbsd_host* host) 1536 + { 1537 + int base, irq, dma; 1538 + 1539 + /* 1540 + * Select SD/MMC function. 1541 + */ 1542 + wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); 1543 + 1544 + /* 1545 + * Read configuration. 1546 + */ 1547 + base = wbsd_read_config(host, WBSD_CONF_PORT_HI) << 8; 1548 + base |= wbsd_read_config(host, WBSD_CONF_PORT_LO); 1549 + 1550 + irq = wbsd_read_config(host, WBSD_CONF_IRQ); 1551 + 1552 + dma = wbsd_read_config(host, WBSD_CONF_DRQ); 1553 + 1554 + /* 1555 + * Validate against given configuration. 1556 + */ 1557 + if (base != host->base) 1558 + return 0; 1559 + if (irq != host->irq) 1560 + return 0; 1561 + if ((dma != host->dma) && (host->dma != -1)) 1562 + return 0; 1563 + 1564 + return 1; 1565 + } 1566 + 1567 + /*****************************************************************************\ 1568 + * * 1569 + * Devices setup and shutdown * 1570 + * * 1571 + \*****************************************************************************/ 1572 + 1573 + static int __devinit wbsd_init(struct device* dev, int base, int irq, int dma, 1574 + int pnp) 1575 + { 1576 + struct wbsd_host* host = NULL; 1577 + struct mmc_host* mmc = NULL; 1578 + int ret; 1579 + 1580 + ret = wbsd_alloc_mmc(dev); 1581 + if (ret) 1582 + return ret; 1583 + 1584 + mmc = dev_get_drvdata(dev); 1585 + host = mmc_priv(mmc); 1586 + 1587 + /* 1588 + * Scan for hardware. 1589 + */ 1590 + ret = wbsd_scan(host); 1591 + if (ret) 1592 + { 1593 + if (pnp && (ret == -ENODEV)) 1594 + { 1595 + printk(KERN_WARNING DRIVER_NAME 1596 + ": Unable to confirm device presence. You may " 1597 + "experience lock-ups.\n"); 1598 + } 1599 + else 1600 + { 1601 + wbsd_free_mmc(dev); 1602 + return ret; 1603 + } 1604 + } 1605 + 1606 + /* 1607 + * Request resources. 1608 + */ 1609 + ret = wbsd_request_resources(host, io, irq, dma); 1610 + if (ret) 1611 + { 1612 + wbsd_release_resources(host); 1613 + wbsd_free_mmc(dev); 1614 + return ret; 1615 + } 1616 + 1617 + /* 1618 + * See if chip needs to be configured. 1619 + */ 1620 + if (pnp && (host->config != 0)) 1621 + { 1622 + if (!wbsd_chip_validate(host)) 1623 + { 1624 + printk(KERN_WARNING DRIVER_NAME 1625 + ": PnP active but chip not configured! " 1626 + "You probably have a buggy BIOS. " 1627 + "Configuring chip manually.\n"); 1628 + wbsd_chip_config(host); 1629 + } 1630 + } 1631 + else 1632 + wbsd_chip_config(host); 1633 + 1634 + /* 1635 + * Power Management stuff. No idea how this works. 1636 + * Not tested. 1637 + */ 1638 + #ifdef CONFIG_PM 1639 + if (host->config) 1640 + wbsd_write_config(host, WBSD_CONF_PME, 0xA0); 1641 + #endif 1642 + /* 1643 + * Allow device to initialise itself properly. 1644 + */ 1645 + mdelay(5); 1646 + 1647 + /* 1648 + * Reset the chip into a known state. 1649 + */ 1650 + wbsd_init_device(host); 1651 + 1652 + mmc_add_host(mmc); 1653 + 1654 + printk(KERN_INFO "%s: W83L51xD", mmc->host_name); 1655 + if (host->chip_id != 0) 1656 + printk(" id %x", (int)host->chip_id); 1657 + printk(" at 0x%x irq %d", (int)host->base, (int)host->irq); 1658 + if (host->dma >= 0) 1659 + printk(" dma %d", (int)host->dma); 1660 + else 1661 + printk(" FIFO"); 1662 + if (pnp) 1663 + printk(" PnP"); 1664 + printk("\n"); 1686 1665 1687 1666 return 0; 1688 1667 } 1668 + 1669 + static void __devexit wbsd_shutdown(struct device* dev, int pnp) 1670 + { 1671 + struct mmc_host* mmc = dev_get_drvdata(dev); 1672 + struct wbsd_host* host; 1673 + 1674 + if (!mmc) 1675 + return; 1676 + 1677 + host = mmc_priv(mmc); 1678 + 1679 + mmc_remove_host(mmc); 1680 + 1681 + if (!pnp) 1682 + { 1683 + /* 1684 + * Power down the SD/MMC function. 1685 + */ 1686 + wbsd_unlock_config(host); 1687 + wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD); 1688 + wbsd_write_config(host, WBSD_CONF_ENABLE, 0); 1689 + wbsd_lock_config(host); 1690 + } 1691 + 1692 + wbsd_release_resources(host); 1693 + 1694 + wbsd_free_mmc(dev); 1695 + } 1696 + 1697 + /* 1698 + * Non-PnP 1699 + */ 1700 + 1701 + static int __devinit wbsd_probe(struct device* dev) 1702 + { 1703 + return wbsd_init(dev, io, irq, dma, 0); 1704 + } 1705 + 1706 + static int __devexit wbsd_remove(struct device* dev) 1707 + { 1708 + wbsd_shutdown(dev, 0); 1709 + 1710 + return 0; 1711 + } 1712 + 1713 + /* 1714 + * PnP 1715 + */ 1716 + 1717 + #ifdef CONFIG_PNP 1718 + 1719 + static int __devinit 1720 + wbsd_pnp_probe(struct pnp_dev * pnpdev, const struct pnp_device_id *dev_id) 1721 + { 1722 + int io, irq, dma; 1723 + 1724 + /* 1725 + * Get resources from PnP layer. 1726 + */ 1727 + io = pnp_port_start(pnpdev, 0); 1728 + irq = pnp_irq(pnpdev, 0); 1729 + if (pnp_dma_valid(pnpdev, 0)) 1730 + dma = pnp_dma(pnpdev, 0); 1731 + else 1732 + dma = -1; 1733 + 1734 + DBGF("PnP resources: port %3x irq %d dma %d\n", io, irq, dma); 1735 + 1736 + return wbsd_init(&pnpdev->dev, io, irq, dma, 1); 1737 + } 1738 + 1739 + static void __devexit wbsd_pnp_remove(struct pnp_dev * dev) 1740 + { 1741 + wbsd_shutdown(&dev->dev, 1); 1742 + } 1743 + 1744 + #endif /* CONFIG_PNP */ 1689 1745 1690 1746 /* 1691 1747 * Power management ··· 1895 1581 #define wbsd_resume NULL 1896 1582 #endif 1897 1583 1898 - static void wbsd_release(struct device *dev) 1899 - { 1900 - } 1901 - 1902 - static struct platform_device wbsd_device = { 1903 - .name = DRIVER_NAME, 1904 - .id = -1, 1905 - .dev = { 1906 - .release = wbsd_release, 1907 - }, 1908 - }; 1584 + static struct platform_device *wbsd_device; 1909 1585 1910 1586 static struct device_driver wbsd_driver = { 1911 1587 .name = DRIVER_NAME, ··· 1906 1602 .suspend = wbsd_suspend, 1907 1603 .resume = wbsd_resume, 1908 1604 }; 1605 + 1606 + #ifdef CONFIG_PNP 1607 + 1608 + static struct pnp_driver wbsd_pnp_driver = { 1609 + .name = DRIVER_NAME, 1610 + .id_table = pnp_dev_table, 1611 + .probe = wbsd_pnp_probe, 1612 + .remove = wbsd_pnp_remove, 1613 + }; 1614 + 1615 + #endif /* CONFIG_PNP */ 1909 1616 1910 1617 /* 1911 1618 * Module loading/unloading ··· 1930 1615 ": Winbond W83L51xD SD/MMC card interface driver, " 1931 1616 DRIVER_VERSION "\n"); 1932 1617 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); 1933 - 1934 - result = driver_register(&wbsd_driver); 1935 - if (result < 0) 1936 - return result; 1937 1618 1938 - result = platform_device_register(&wbsd_device); 1939 - if (result < 0) 1940 - return result; 1619 + #ifdef CONFIG_PNP 1620 + 1621 + if (!nopnp) 1622 + { 1623 + result = pnp_register_driver(&wbsd_pnp_driver); 1624 + if (result < 0) 1625 + return result; 1626 + } 1627 + 1628 + #endif /* CONFIG_PNP */ 1629 + 1630 + if (nopnp) 1631 + { 1632 + result = driver_register(&wbsd_driver); 1633 + if (result < 0) 1634 + return result; 1635 + 1636 + wbsd_device = platform_device_register_simple(DRIVER_NAME, -1, 1637 + NULL, 0); 1638 + if (IS_ERR(wbsd_device)) 1639 + return PTR_ERR(wbsd_device); 1640 + } 1941 1641 1942 1642 return 0; 1943 1643 } 1944 1644 1945 1645 static void __exit wbsd_drv_exit(void) 1946 1646 { 1947 - platform_device_unregister(&wbsd_device); 1647 + #ifdef CONFIG_PNP 1648 + 1649 + if (!nopnp) 1650 + pnp_unregister_driver(&wbsd_pnp_driver); 1948 1651 1949 - driver_unregister(&wbsd_driver); 1652 + #endif /* CONFIG_PNP */ 1653 + 1654 + if (nopnp) 1655 + { 1656 + platform_device_unregister(wbsd_device); 1657 + 1658 + driver_unregister(&wbsd_driver); 1659 + } 1950 1660 1951 1661 DBG("unloaded\n"); 1952 1662 } 1953 1663 1954 1664 module_init(wbsd_drv_init); 1955 1665 module_exit(wbsd_drv_exit); 1666 + #ifdef CONFIG_PNP 1667 + module_param(nopnp, uint, 0444); 1668 + #endif 1956 1669 module_param(io, uint, 0444); 1957 1670 module_param(irq, uint, 0444); 1958 1671 module_param(dma, int, 0444); ··· 1989 1646 MODULE_DESCRIPTION("Winbond W83L51xD SD/MMC card interface driver"); 1990 1647 MODULE_VERSION(DRIVER_VERSION); 1991 1648 1649 + #ifdef CONFIG_PNP 1650 + MODULE_PARM_DESC(nopnp, "Scan for device instead of relying on PNP. (default 0)"); 1651 + #endif 1992 1652 MODULE_PARM_DESC(io, "I/O base to allocate. Must be 8 byte aligned. (default 0x248)"); 1993 1653 MODULE_PARM_DESC(irq, "IRQ to allocate. (default 6)"); 1994 1654 MODULE_PARM_DESC(dma, "DMA channel to allocate. -1 for no DMA. (default 2)");
+12
drivers/mmc/wbsd.h
··· 35 35 36 36 #define DEVICE_SD 0x03 37 37 38 + #define WBSD_PINS_DAT3_HI 0x20 39 + #define WBSD_PINS_DAT3_OUT 0x10 40 + #define WBSD_PINS_GP11_HI 0x04 41 + #define WBSD_PINS_DETECT_GP11 0x02 42 + #define WBSD_PINS_DETECT_DAT3 0x01 43 + 38 44 #define WBSD_CMDR 0x00 39 45 #define WBSD_DFR 0x01 40 46 #define WBSD_EIR 0x02 ··· 139 133 #define WBSD_CRC_OK 0x05 /* S010E (00101) */ 140 134 #define WBSD_CRC_FAIL 0x0B /* S101E (01011) */ 141 135 136 + #define WBSD_DMA_SIZE 65536 142 137 143 138 struct wbsd_host 144 139 { ··· 147 140 148 141 spinlock_t lock; /* Mutex */ 149 142 143 + int flags; /* Driver states */ 144 + 145 + #define WBSD_FCARD_PRESENT (1<<0) /* Card is present */ 146 + #define WBSD_FIGNORE_DETECT (1<<1) /* Ignore card detection */ 147 + 150 148 struct mmc_request* mrq; /* Current request */ 151 149 152 150 u8 isr; /* Accumulated ISR */