Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'mmc-updates-for-3.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc

Pull MMC updates from Chris Ball:
"MMC highlights for 3.14:

Core:
- Avoid get_cd() on cards marked nonremovable

Drivers:
- arasan: New driver for controllers found in e.g. Xilinx Zynq SoC
- dwmmc: Support Hisilicon K3 SoC controllers
- esdhc-imx: Support for HS200 mode, DDR modes on MX6, runtime PM
- sdhci-pci: Support O2Micro/BayHubTech controllers used in laptops
like Lenovo ThinkPad W540, Dell Latitude E5440, Dell Latitude E6540
- tegra: Support Tegra124 SoCs"

* tag 'mmc-updates-for-3.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc: (55 commits)
mmc: sdhci-pci: Fix possibility of chip->fixes being null
mmc: sdhci-pci: Fix BYT sd card getting stuck in runtime suspend
mmc: sdhci: Allow for long command timeouts
mmc: sdio: add a quirk for broken SDIO_CCCR_INTx polling
mmc: sdhci: fix lockdep error in tuning routine
mmc: dw_mmc: k3: remove clk_table
mmc: dw_mmc: fix dw_mci_get_cd
mmc: dw_mmc: fix sparse non static symbol warning
mmc: sdhci-esdhc-imx: fix warning during module remove function
mmc: sdhci-esdhc-imx: fix access hardirq-unsafe lock in atomic context
mmc: core: sd: implement proper support for sd3.0 au sizes
mmc: atmel-mci: add vmmc-supply support
mmc: sdhci-pci: add broken HS200 quirk for Intel Merrifield
mmc: sdhci: add quirk for broken HS200 support
mmc: arasan: Add driver for Arasan SDHCI
mmc: dw_mmc: add dw_mmc-k3 for k3 platform
mmc: dw_mmc: use slot-gpio to handle cd pin
mmc: sdhci-pci: add support of O2Micro/BayHubTech SD hosts
mmc: sdhci-pci: break out definitions to header file
mmc: tmio: fixup compile error
...

Conflicts:
MAINTAINERS

+1347 -345
+27
Documentation/devicetree/bindings/mmc/arasan,sdhci.txt
··· 1 + Device Tree Bindings for the Arasan SDHCI Controller 2 + 3 + The bindings follow the mmc[1], clock[2] and interrupt[3] bindings. Only 4 + deviations are documented here. 5 + 6 + [1] Documentation/devicetree/bindings/mmc/mmc.txt 7 + [2] Documentation/devicetree/bindings/clock/clock-bindings.txt 8 + [3] Documentation/devicetree/bindings/interrupt-controller/interrupts.txt 9 + 10 + Required Properties: 11 + - compatible: Compatibility string. Must be 'arasan,sdhci-8.9a' 12 + - reg: From mmc bindings: Register location and length. 13 + - clocks: From clock bindings: Handles to clock inputs. 14 + - clock-names: From clock bindings: Tuple including "clk_xin" and "clk_ahb" 15 + - interrupts: Interrupt specifier 16 + - interrupt-parent: Phandle for the interrupt controller that services 17 + interrupts for this device. 18 + 19 + Example: 20 + sdhci@e0100000 { 21 + compatible = "arasan,sdhci-8.9a"; 22 + reg = <0xe0100000 0x1000>; 23 + clock-names = "clk_xin", "clk_ahb"; 24 + clocks = <&clkc 21>, <&clkc 32>; 25 + interrupt-parent = <&gic>; 26 + interrupts = <0 24 4>; 27 + } ;
+46
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt
··· 1 + * Hisilicon specific extensions to the Synopsys Designware Mobile 2 + Storage Host Controller 3 + 4 + Read synopsys-dw-mshc.txt for more details 5 + 6 + The Synopsys designware mobile storage host controller is used to interface 7 + a SoC with storage medium such as eMMC or SD/MMC cards. This file documents 8 + differences between the core Synopsys dw mshc controller properties described 9 + by synopsys-dw-mshc.txt and the properties used by the Hisilicon specific 10 + extensions to the Synopsys Designware Mobile Storage Host Controller. 11 + 12 + Required Properties: 13 + 14 + * compatible: should be one of the following. 15 + - "hisilicon,hi4511-dw-mshc": for controllers with hi4511 specific extentions. 16 + 17 + Example: 18 + 19 + /* for Hi3620 */ 20 + 21 + /* SoC portion */ 22 + dwmmc_0: dwmmc0@fcd03000 { 23 + compatible = "hisilicon,hi4511-dw-mshc"; 24 + reg = <0xfcd03000 0x1000>; 25 + interrupts = <0 16 4>; 26 + #address-cells = <1>; 27 + #size-cells = <0>; 28 + clocks = <&mmc_clock HI3620_SD_CIUCLK>, <&clock HI3620_DDRC_PER_CLK>; 29 + clock-names = "ciu", "biu"; 30 + }; 31 + 32 + /* Board portion */ 33 + dwmmc0@fcd03000 { 34 + num-slots = <1>; 35 + vmmc-supply = <&ldo12>; 36 + fifo-depth = <0x100>; 37 + supports-highspeed; 38 + pinctrl-names = "default"; 39 + pinctrl-0 = <&sd_pmx_pins &sd_cfg_func1 &sd_cfg_func2>; 40 + slot@0 { 41 + reg = <0>; 42 + bus-width = <4>; 43 + disable-wp; 44 + cd-gpios = <&gpio10 3 0>; 45 + }; 46 + };
+3 -3
MAINTAINERS
··· 1409 1409 N: zynq 1410 1410 N: xilinx 1411 1411 F: drivers/clocksource/cadence_ttc_timer.c 1412 + F: drivers/mmc/host/sdhci-of-arasan.c 1412 1413 1413 1414 ARM SMMU DRIVER 1414 1415 M: Will Deacon <will.deacon@arm.com> ··· 5783 5782 F: include/linux/mfd/ 5784 5783 5785 5784 MULTIMEDIA CARD (MMC), SECURE DIGITAL (SD) AND SDIO SUBSYSTEM 5786 - M: Chris Ball <cjb@laptop.org> 5785 + M: Chris Ball <chris@printf.net> 5787 5786 L: linux-mmc@vger.kernel.org 5788 5787 T: git git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc.git 5789 5788 S: Maintained ··· 7610 7609 F: drivers/mmc/host/sdricoh_cs.c 7611 7610 7612 7611 SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) DRIVER 7613 - M: Chris Ball <cjb@laptop.org> 7612 + M: Chris Ball <chris@printf.net> 7614 7613 L: linux-mmc@vger.kernel.org 7615 7614 T: git git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc.git 7616 7615 S: Maintained ··· 8769 8768 F: include/uapi/linux/toshiba.h 8770 8769 8771 8770 TMIO MMC DRIVER 8772 - M: Guennadi Liakhovetski <g.liakhovetski@gmx.de> 8773 8771 M: Ian Molton <ian@mnementh.co.uk> 8774 8772 L: linux-mmc@vger.kernel.org 8775 8773 S: Maintained
+4 -3
drivers/mmc/card/block.c
··· 1959 1959 struct mmc_card *card = md->queue.card; 1960 1960 struct mmc_host *host = card->host; 1961 1961 unsigned long flags; 1962 + unsigned int cmd_flags = req ? req->cmd_flags : 0; 1962 1963 1963 1964 if (req && !mq->mqrq_prev->req) 1964 1965 /* claim host only for the first request */ ··· 1975 1974 } 1976 1975 1977 1976 mq->flags &= ~MMC_QUEUE_NEW_REQUEST; 1978 - if (req && req->cmd_flags & REQ_DISCARD) { 1977 + if (cmd_flags & REQ_DISCARD) { 1979 1978 /* complete ongoing async transfer before issuing discard */ 1980 1979 if (card->host->areq) 1981 1980 mmc_blk_issue_rw_rq(mq, NULL); ··· 1984 1983 ret = mmc_blk_issue_secdiscard_rq(mq, req); 1985 1984 else 1986 1985 ret = mmc_blk_issue_discard_rq(mq, req); 1987 - } else if (req && req->cmd_flags & REQ_FLUSH) { 1986 + } else if (cmd_flags & REQ_FLUSH) { 1988 1987 /* complete ongoing async transfer before issuing flush */ 1989 1988 if (card->host->areq) 1990 1989 mmc_blk_issue_rw_rq(mq, NULL); ··· 2000 1999 2001 2000 out: 2002 2001 if ((!req && !(mq->flags & MMC_QUEUE_NEW_REQUEST)) || 2003 - (req && (req->cmd_flags & MMC_REQ_SPECIAL_MASK))) 2002 + (cmd_flags & MMC_REQ_SPECIAL_MASK)) 2004 2003 /* 2005 2004 * Release host when there are no more requests 2006 2005 * and after special request(discard, flush) is done.
+2 -1
drivers/mmc/core/core.c
··· 2460 2460 */ 2461 2461 mmc_bus_put(host); 2462 2462 2463 - if (host->ops->get_cd && host->ops->get_cd(host) == 0) { 2463 + if (!(host->caps & MMC_CAP_NONREMOVABLE) && host->ops->get_cd && 2464 + host->ops->get_cd(host) == 0) { 2464 2465 mmc_claim_host(host); 2465 2466 mmc_power_off(host); 2466 2467 mmc_release_host(host);
+2 -6
drivers/mmc/core/mmc.c
··· 1119 1119 */ 1120 1120 if (mmc_card_highspeed(card)) { 1121 1121 if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) 1122 - && ((host->caps & (MMC_CAP_1_8V_DDR | 1123 - MMC_CAP_UHS_DDR50)) 1124 - == (MMC_CAP_1_8V_DDR | MMC_CAP_UHS_DDR50))) 1122 + && (host->caps & MMC_CAP_1_8V_DDR)) 1125 1123 ddr = MMC_1_8V_DDR_MODE; 1126 1124 else if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_2V) 1127 - && ((host->caps & (MMC_CAP_1_2V_DDR | 1128 - MMC_CAP_UHS_DDR50)) 1129 - == (MMC_CAP_1_2V_DDR | MMC_CAP_UHS_DDR50))) 1125 + && (host->caps & MMC_CAP_1_2V_DDR)) 1130 1126 ddr = MMC_1_2V_DDR_MODE; 1131 1127 } 1132 1128
+8
drivers/mmc/core/quirks.c
··· 13 13 #include <linux/kernel.h> 14 14 #include <linux/export.h> 15 15 #include <linux/mmc/card.h> 16 + #include <linux/mmc/sdio_ids.h> 16 17 17 18 #ifndef SDIO_VENDOR_ID_TI 18 19 #define SDIO_VENDOR_ID_TI 0x0097 ··· 29 28 30 29 #ifndef SDIO_DEVICE_ID_STE_CW1200 31 30 #define SDIO_DEVICE_ID_STE_CW1200 0x2280 31 + #endif 32 + 33 + #ifndef SDIO_DEVICE_ID_MARVELL_8797_F0 34 + #define SDIO_DEVICE_ID_MARVELL_8797_F0 0x9128 32 35 #endif 33 36 34 37 /* ··· 62 57 63 58 SDIO_FIXUP(SDIO_VENDOR_ID_STE, SDIO_DEVICE_ID_STE_CW1200, 64 59 add_quirk, MMC_QUIRK_BROKEN_BYTE_MODE_512), 60 + 61 + SDIO_FIXUP(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797_F0, 62 + add_quirk, MMC_QUIRK_BROKEN_IRQ_POLLING), 65 63 66 64 END_FIXUP 67 65 };
+22 -15
drivers/mmc/core/sd.c
··· 11 11 */ 12 12 13 13 #include <linux/err.h> 14 + #include <linux/sizes.h> 14 15 #include <linux/slab.h> 15 16 #include <linux/stat.h> 16 17 #include <linux/pm_runtime.h> ··· 44 43 static const unsigned int tacc_mant[] = { 45 44 0, 10, 12, 13, 15, 20, 25, 30, 46 45 35, 40, 45, 50, 55, 60, 70, 80, 46 + }; 47 + 48 + static const unsigned int sd_au_size[] = { 49 + 0, SZ_16K / 512, SZ_32K / 512, SZ_64K / 512, 50 + SZ_128K / 512, SZ_256K / 512, SZ_512K / 512, SZ_1M / 512, 51 + SZ_2M / 512, SZ_4M / 512, SZ_8M / 512, (SZ_8M + SZ_4M) / 512, 52 + SZ_16M / 512, (SZ_16M + SZ_8M) / 512, SZ_32M / 512, SZ_64M / 512, 47 53 }; 48 54 49 55 #define UNSTUFF_BITS(resp,start,size) \ ··· 224 216 static int mmc_read_ssr(struct mmc_card *card) 225 217 { 226 218 unsigned int au, es, et, eo; 227 - int err, i, max_au; 219 + int err, i; 228 220 u32 *ssr; 229 221 230 222 if (!(card->csd.cmdclass & CCC_APP_SPEC)) { ··· 248 240 for (i = 0; i < 16; i++) 249 241 ssr[i] = be32_to_cpu(ssr[i]); 250 242 251 - /* SD3.0 increases max AU size to 64MB (0xF) from 4MB (0x9) */ 252 - max_au = card->scr.sda_spec3 ? 0xF : 0x9; 253 - 254 243 /* 255 244 * UNSTUFF_BITS only works with four u32s so we have to offset the 256 245 * bitfield positions accordingly. 257 246 */ 258 247 au = UNSTUFF_BITS(ssr, 428 - 384, 4); 259 - if (au > 0 && au <= max_au) { 260 - card->ssr.au = 1 << (au + 4); 261 - es = UNSTUFF_BITS(ssr, 408 - 384, 16); 262 - et = UNSTUFF_BITS(ssr, 402 - 384, 6); 263 - eo = UNSTUFF_BITS(ssr, 400 - 384, 2); 264 - if (es && et) { 265 - card->ssr.erase_timeout = (et * 1000) / es; 266 - card->ssr.erase_offset = eo * 1000; 248 + if (au) { 249 + if (au <= 9 || card->scr.sda_spec3) { 250 + card->ssr.au = sd_au_size[au]; 251 + es = UNSTUFF_BITS(ssr, 408 - 384, 16); 252 + et = UNSTUFF_BITS(ssr, 402 - 384, 6); 253 + if (es && et) { 254 + eo = UNSTUFF_BITS(ssr, 400 - 384, 2); 255 + card->ssr.erase_timeout = (et * 1000) / es; 256 + card->ssr.erase_offset = eo * 1000; 257 + } 258 + } else { 259 + pr_warning("%s: SD Status: Invalid Allocation Unit size.\n", 260 + mmc_hostname(card->host)); 267 261 } 268 - } else { 269 - pr_warning("%s: SD Status: Invalid Allocation Unit " 270 - "size.\n", mmc_hostname(card->host)); 271 262 } 272 263 out: 273 264 kfree(ssr);
+11
drivers/mmc/core/sdio_irq.c
··· 53 53 return ret; 54 54 } 55 55 56 + if (pending && mmc_card_broken_irq_polling(card) && 57 + !(host->caps & MMC_CAP_SDIO_IRQ)) { 58 + unsigned char dummy; 59 + 60 + /* A fake interrupt could be created when we poll SDIO_CCCR_INTx 61 + * register with a Marvell SD8797 card. A dummy CMD52 read to 62 + * function 0 register 0xff can avoid this. 63 + */ 64 + mmc_io_rw_direct(card, 0, 0, 0xff, 0, &dummy); 65 + } 66 + 56 67 count = 0; 57 68 for (i = 1; i <= 7; i++) { 58 69 if (pending & (1 << i)) {
+26 -2
drivers/mmc/host/Kconfig
··· 104 104 105 105 If unsure, say N. 106 106 107 + config MMC_SDHCI_OF_ARASAN 108 + tristate "SDHCI OF support for the Arasan SDHCI controllers" 109 + depends on MMC_SDHCI_PLTFM 110 + depends on OF 111 + help 112 + This selects the Arasan Secure Digital Host Controller Interface 113 + (SDHCI). This hardware is found e.g. in Xilinx' Zynq SoC. 114 + 115 + If you have a controller with this interface, say Y or M here. 116 + 117 + If unsure, say N. 118 + 107 119 config MMC_SDHCI_OF_ESDHC 108 120 tristate "SDHCI OF support for the Freescale eSDHC controller" 109 121 depends on MMC_SDHCI_PLTFM ··· 491 479 492 480 config MMC_SDHI 493 481 tristate "SH-Mobile SDHI SD/SDIO controller support" 494 - depends on SUPERH || ARCH_SHMOBILE 482 + depends on SUPERH || ARM 483 + depends on SUPERH || ARCH_SHMOBILE || COMPILE_TEST 495 484 select MMC_TMIO_CORE 496 485 help 497 486 This provides support for the SDHI SD/SDIO controller found in ··· 588 575 This selects support for Altera SoCFPGA specific extensions to the 589 576 Synopsys DesignWare Memory Card Interface driver. 590 577 578 + config MMC_DW_K3 579 + tristate "K3 specific extensions for Synopsys DW Memory Card Interface" 580 + depends on MMC_DW 581 + select MMC_DW_PLTFM 582 + select MMC_DW_IDMAC 583 + help 584 + This selects support for Hisilicon K3 SoC specific extensions to the 585 + Synopsys DesignWare Memory Card Interface driver. Select this option 586 + for platforms based on Hisilicon K3 SoC's. 587 + 591 588 config MMC_DW_PCI 592 589 tristate "Synopsys Designware MCI support on PCI bus" 593 590 depends on MMC_DW && PCI ··· 611 588 612 589 config MMC_SH_MMCIF 613 590 tristate "SuperH Internal MMCIF support" 614 - depends on MMC_BLOCK && (SUPERH || ARCH_SHMOBILE) 591 + depends on MMC_BLOCK 592 + depends on SUPERH || ARCH_SHMOBILE || COMPILE_TEST 615 593 help 616 594 This selects the MMC Host Interface controller (MMCIF). 617 595
+3
drivers/mmc/host/Makefile
··· 9 9 obj-$(CONFIG_MMC_SDHCI) += sdhci.o 10 10 obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o 11 11 obj-$(subst m,y,$(CONFIG_MMC_SDHCI_PCI)) += sdhci-pci-data.o 12 + obj-$(subst m,y,$(CONFIG_MMC_SDHCI_PCI)) += sdhci-pci-o2micro.o 12 13 obj-$(CONFIG_MMC_SDHCI_ACPI) += sdhci-acpi.o 13 14 obj-$(CONFIG_MMC_SDHCI_PXAV3) += sdhci-pxav3.o 14 15 obj-$(CONFIG_MMC_SDHCI_PXAV2) += sdhci-pxav2.o ··· 44 43 obj-$(CONFIG_MMC_DW_PLTFM) += dw_mmc-pltfm.o 45 44 obj-$(CONFIG_MMC_DW_EXYNOS) += dw_mmc-exynos.o 46 45 obj-$(CONFIG_MMC_DW_SOCFPGA) += dw_mmc-socfpga.o 46 + obj-$(CONFIG_MMC_DW_K3) += dw_mmc-k3.o 47 47 obj-$(CONFIG_MMC_DW_PCI) += dw_mmc-pci.o 48 48 obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o 49 49 obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o ··· 59 57 obj-$(CONFIG_MMC_SDHCI_ESDHC_IMX) += sdhci-esdhc-imx.o 60 58 obj-$(CONFIG_MMC_SDHCI_DOVE) += sdhci-dove.o 61 59 obj-$(CONFIG_MMC_SDHCI_TEGRA) += sdhci-tegra.o 60 + obj-$(CONFIG_MMC_SDHCI_OF_ARASAN) += sdhci-of-arasan.o 62 61 obj-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o 63 62 obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o 64 63 obj-$(CONFIG_MMC_SDHCI_BCM_KONA) += sdhci-bcm-kona.o
+19 -1
drivers/mmc/host/atmel-mci.c
··· 1192 1192 iflags |= ATMCI_CMDRDY; 1193 1193 cmd = mrq->cmd; 1194 1194 cmdflags = atmci_prepare_command(slot->mmc, cmd); 1195 - atmci_send_command(host, cmd, cmdflags); 1195 + 1196 + /* 1197 + * DMA transfer should be started before sending the command to avoid 1198 + * unexpected errors especially for read operations in SDIO mode. 1199 + * Unfortunately, in PDC mode, command has to be sent before starting 1200 + * the transfer. 1201 + */ 1202 + if (host->submit_data != &atmci_submit_data_dma) 1203 + atmci_send_command(host, cmd, cmdflags); 1196 1204 1197 1205 if (data) 1198 1206 host->submit_data(host, data); 1207 + 1208 + if (host->submit_data == &atmci_submit_data_dma) 1209 + atmci_send_command(host, cmd, cmdflags); 1199 1210 1200 1211 if (mrq->stop) { 1201 1212 host->stop_cmdr = atmci_prepare_command(slot->mmc, mrq->stop); ··· 1402 1391 clk_unprepare(host->mck); 1403 1392 1404 1393 switch (ios->power_mode) { 1394 + case MMC_POWER_OFF: 1395 + if (!IS_ERR(mmc->supply.vmmc)) 1396 + mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); 1397 + break; 1405 1398 case MMC_POWER_UP: 1406 1399 set_bit(ATMCI_CARD_NEED_INIT, &slot->flags); 1400 + if (!IS_ERR(mmc->supply.vmmc)) 1401 + mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd); 1407 1402 break; 1408 1403 default: 1409 1404 /* ··· 2221 2204 } 2222 2205 2223 2206 host->slot[id] = slot; 2207 + mmc_regulator_get_supply(mmc); 2224 2208 mmc_add_host(mmc); 2225 2209 2226 2210 if (gpio_is_valid(slot->detect_pin)) {
+95
drivers/mmc/host/dw_mmc-k3.c
··· 1 + /* 2 + * Copyright (c) 2013 Linaro Ltd. 3 + * Copyright (c) 2013 Hisilicon Limited. 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation; either version 2 of the License, or 8 + * (at your option) any later version. 9 + */ 10 + 11 + #include <linux/module.h> 12 + #include <linux/platform_device.h> 13 + #include <linux/clk.h> 14 + #include <linux/mmc/host.h> 15 + #include <linux/mmc/dw_mmc.h> 16 + #include <linux/of_address.h> 17 + 18 + #include "dw_mmc.h" 19 + #include "dw_mmc-pltfm.h" 20 + 21 + static void dw_mci_k3_set_ios(struct dw_mci *host, struct mmc_ios *ios) 22 + { 23 + int ret; 24 + 25 + ret = clk_set_rate(host->ciu_clk, ios->clock); 26 + if (ret) 27 + dev_warn(host->dev, "failed to set rate %uHz\n", ios->clock); 28 + 29 + host->bus_hz = clk_get_rate(host->ciu_clk); 30 + } 31 + 32 + static const struct dw_mci_drv_data k3_drv_data = { 33 + .set_ios = dw_mci_k3_set_ios, 34 + }; 35 + 36 + static const struct of_device_id dw_mci_k3_match[] = { 37 + { .compatible = "hisilicon,hi4511-dw-mshc", .data = &k3_drv_data, }, 38 + {}, 39 + }; 40 + MODULE_DEVICE_TABLE(of, dw_mci_k3_match); 41 + 42 + static int dw_mci_k3_probe(struct platform_device *pdev) 43 + { 44 + const struct dw_mci_drv_data *drv_data; 45 + const struct of_device_id *match; 46 + 47 + match = of_match_node(dw_mci_k3_match, pdev->dev.of_node); 48 + drv_data = match->data; 49 + 50 + return dw_mci_pltfm_register(pdev, drv_data); 51 + } 52 + 53 + static int dw_mci_k3_suspend(struct device *dev) 54 + { 55 + struct dw_mci *host = dev_get_drvdata(dev); 56 + int ret; 57 + 58 + ret = dw_mci_suspend(host); 59 + if (!ret) 60 + clk_disable_unprepare(host->ciu_clk); 61 + 62 + return ret; 63 + } 64 + 65 + static int dw_mci_k3_resume(struct device *dev) 66 + { 67 + struct dw_mci *host = dev_get_drvdata(dev); 68 + int ret; 69 + 70 + ret = clk_prepare_enable(host->ciu_clk); 71 + if (ret) { 72 + dev_err(host->dev, "failed to enable ciu clock\n"); 73 + return ret; 74 + } 75 + 76 + return dw_mci_resume(host); 77 + } 78 + 79 + static SIMPLE_DEV_PM_OPS(dw_mci_k3_pmops, dw_mci_k3_suspend, dw_mci_k3_resume); 80 + 81 + static struct platform_driver dw_mci_k3_pltfm_driver = { 82 + .probe = dw_mci_k3_probe, 83 + .remove = dw_mci_pltfm_remove, 84 + .driver = { 85 + .name = "dwmmc_k3", 86 + .of_match_table = dw_mci_k3_match, 87 + .pm = &dw_mci_k3_pmops, 88 + }, 89 + }; 90 + 91 + module_platform_driver(dw_mci_k3_pltfm_driver); 92 + 93 + MODULE_DESCRIPTION("K3 Specific DW-MSHC Driver Extension"); 94 + MODULE_LICENSE("GPL v2"); 95 + MODULE_ALIAS("platform:dwmmc-k3");
+41 -13
drivers/mmc/host/dw_mmc.c
··· 36 36 #include <linux/workqueue.h> 37 37 #include <linux/of.h> 38 38 #include <linux/of_gpio.h> 39 + #include <linux/mmc/slot-gpio.h> 39 40 40 41 #include "dw_mmc.h" 41 42 ··· 1033 1032 int present; 1034 1033 struct dw_mci_slot *slot = mmc_priv(mmc); 1035 1034 struct dw_mci_board *brd = slot->host->pdata; 1035 + struct dw_mci *host = slot->host; 1036 + int gpio_cd = mmc_gpio_get_cd(mmc); 1036 1037 1037 1038 /* Use platform get_cd function, else try onboard card detect */ 1038 1039 if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION) 1039 1040 present = 1; 1040 1041 else if (brd->get_cd) 1041 1042 present = !brd->get_cd(slot->id); 1043 + else if (!IS_ERR_VALUE(gpio_cd)) 1044 + present = gpio_cd; 1042 1045 else 1043 1046 present = (mci_readl(slot->host, CDETECT) & (1 << slot->id)) 1044 1047 == 0 ? 1 : 0; 1045 1048 1046 - if (present) 1049 + spin_lock_bh(&host->lock); 1050 + if (present) { 1051 + set_bit(DW_MMC_CARD_PRESENT, &slot->flags); 1047 1052 dev_dbg(&mmc->class_dev, "card is present\n"); 1048 - else 1053 + } else { 1054 + clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); 1049 1055 dev_dbg(&mmc->class_dev, "card is not present\n"); 1056 + } 1057 + spin_unlock_bh(&host->lock); 1050 1058 1051 1059 return present; 1052 1060 } ··· 1936 1926 /* Card change detected */ 1937 1927 slot->last_detect_state = present; 1938 1928 1939 - /* Mark card as present if applicable */ 1940 - if (present != 0) 1941 - set_bit(DW_MMC_CARD_PRESENT, &slot->flags); 1942 - 1943 1929 /* Clean up queue if present */ 1944 1930 mrq = slot->mrq; 1945 1931 if (mrq) { ··· 1983 1977 1984 1978 /* Power down slot */ 1985 1979 if (present == 0) { 1986 - clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); 1987 - 1988 1980 /* Clear down the FIFO */ 1989 1981 dw_mci_fifo_reset(host); 1990 1982 #ifdef CONFIG_MMC_DW_IDMAC ··· 2083 2079 2084 2080 return gpio; 2085 2081 } 2082 + 2083 + /* find the cd gpio for a given slot */ 2084 + static void dw_mci_of_get_cd_gpio(struct device *dev, u8 slot, 2085 + struct mmc_host *mmc) 2086 + { 2087 + struct device_node *np = dw_mci_of_find_slot_node(dev, slot); 2088 + int gpio; 2089 + 2090 + if (!np) 2091 + return; 2092 + 2093 + gpio = of_get_named_gpio(np, "cd-gpios", 0); 2094 + 2095 + /* Having a missing entry is valid; return silently */ 2096 + if (!gpio_is_valid(gpio)) 2097 + return; 2098 + 2099 + if (mmc_gpio_request_cd(mmc, gpio, 0)) 2100 + dev_warn(dev, "gpio [%d] request failed\n", gpio); 2101 + } 2086 2102 #else /* CONFIG_OF */ 2087 2103 static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot) 2088 2104 { ··· 2119 2095 static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot) 2120 2096 { 2121 2097 return -EINVAL; 2098 + } 2099 + static void dw_mci_of_get_cd_gpio(struct device *dev, u8 slot, 2100 + struct mmc_host *mmc) 2101 + { 2102 + return; 2122 2103 } 2123 2104 #endif /* CONFIG_OF */ 2124 2105 ··· 2226 2197 #endif /* CONFIG_MMC_DW_IDMAC */ 2227 2198 } 2228 2199 2229 - if (dw_mci_get_cd(mmc)) 2230 - set_bit(DW_MMC_CARD_PRESENT, &slot->flags); 2231 - else 2232 - clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); 2233 - 2234 2200 slot->wp_gpio = dw_mci_of_get_wp_gpio(host->dev, slot->id); 2201 + dw_mci_of_get_cd_gpio(host->dev, slot->id, mmc); 2235 2202 2236 2203 ret = mmc_add_host(mmc); 2237 2204 if (ret) ··· 2413 2388 2414 2389 if (of_find_property(np, "caps2-mmc-hs200-1_2v", NULL)) 2415 2390 pdata->caps2 |= MMC_CAP2_HS200_1_2V_SDR; 2391 + 2392 + if (of_get_property(np, "cd-inverted", NULL)) 2393 + pdata->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; 2416 2394 2417 2395 return pdata; 2418 2396 }
+19 -43
drivers/mmc/host/mxs-mmc.c
··· 38 38 #include <linux/mmc/host.h> 39 39 #include <linux/mmc/mmc.h> 40 40 #include <linux/mmc/sdio.h> 41 + #include <linux/mmc/slot-gpio.h> 41 42 #include <linux/gpio.h> 42 43 #include <linux/regulator/consumer.h> 43 44 #include <linux/module.h> ··· 70 69 unsigned char bus_width; 71 70 spinlock_t lock; 72 71 int sdio_irq_en; 73 - int wp_gpio; 74 - bool wp_inverted; 75 - bool cd_inverted; 76 - bool broken_cd; 77 - bool non_removable; 78 72 }; 79 - 80 - static int mxs_mmc_get_ro(struct mmc_host *mmc) 81 - { 82 - struct mxs_mmc_host *host = mmc_priv(mmc); 83 - int ret; 84 - 85 - if (!gpio_is_valid(host->wp_gpio)) 86 - return -EINVAL; 87 - 88 - ret = gpio_get_value(host->wp_gpio); 89 - 90 - if (host->wp_inverted) 91 - ret = !ret; 92 - 93 - return ret; 94 - } 95 73 96 74 static int mxs_mmc_get_cd(struct mmc_host *mmc) 97 75 { 98 76 struct mxs_mmc_host *host = mmc_priv(mmc); 99 77 struct mxs_ssp *ssp = &host->ssp; 78 + int present, ret; 100 79 101 - return host->non_removable || host->broken_cd || 102 - !(readl(ssp->base + HW_SSP_STATUS(ssp)) & 103 - BM_SSP_STATUS_CARD_DETECT) ^ host->cd_inverted; 80 + ret = mmc_gpio_get_cd(mmc); 81 + if (ret >= 0) 82 + return ret; 83 + 84 + present = !(readl(ssp->base + HW_SSP_STATUS(ssp)) & 85 + BM_SSP_STATUS_CARD_DETECT); 86 + 87 + if (mmc->caps2 & MMC_CAP2_CD_ACTIVE_HIGH) 88 + present = !present; 89 + 90 + return present; 104 91 } 105 92 106 93 static int mxs_mmc_reset(struct mxs_mmc_host *host) ··· 538 549 539 550 static const struct mmc_host_ops mxs_mmc_ops = { 540 551 .request = mxs_mmc_request, 541 - .get_ro = mxs_mmc_get_ro, 552 + .get_ro = mmc_gpio_get_ro, 542 553 .get_cd = mxs_mmc_get_cd, 543 554 .set_ios = mxs_mmc_set_ios, 544 555 .enable_sdio_irq = mxs_mmc_enable_sdio_irq, ··· 568 579 { 569 580 const struct of_device_id *of_id = 570 581 of_match_device(mxs_mmc_dt_ids, &pdev->dev); 571 - struct device_node *np = pdev->dev.of_node; 572 582 struct mxs_mmc_host *host; 573 583 struct mmc_host *mmc; 574 584 struct resource *iores; 575 585 int ret = 0, irq_err; 576 586 struct regulator *reg_vmmc; 577 - enum of_gpio_flags flags; 578 587 struct mxs_ssp *ssp; 579 - u32 bus_width = 0; 580 588 581 589 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 582 590 irq_err = platform_get_irq(pdev, 0); ··· 634 648 mmc->caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED | 635 649 MMC_CAP_SDIO_IRQ | MMC_CAP_NEEDS_POLL; 636 650 637 - of_property_read_u32(np, "bus-width", &bus_width); 638 - if (bus_width == 4) 639 - mmc->caps |= MMC_CAP_4_BIT_DATA; 640 - else if (bus_width == 8) 641 - mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA; 642 - host->broken_cd = of_property_read_bool(np, "broken-cd"); 643 - host->non_removable = of_property_read_bool(np, "non-removable"); 644 - if (host->non_removable) 645 - mmc->caps |= MMC_CAP_NONREMOVABLE; 646 - host->wp_gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, &flags); 647 - if (flags & OF_GPIO_ACTIVE_LOW) 648 - host->wp_inverted = 1; 649 - 650 - host->cd_inverted = of_property_read_bool(np, "cd-inverted"); 651 - 652 651 mmc->f_min = 400000; 653 652 mmc->f_max = 288000000; 653 + 654 + ret = mmc_of_parse(mmc); 655 + if (ret) 656 + goto out_clk_disable; 657 + 654 658 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 655 659 656 660 mmc->max_segs = 52;
+2
drivers/mmc/host/sdhci-acpi.c
··· 143 143 { "80860F14" , "3" , &sdhci_acpi_slot_int_sd }, 144 144 { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio }, 145 145 { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio }, 146 + { "INT3436" , NULL, &sdhci_acpi_slot_int_sdio }, 146 147 { "PNP0D40" }, 147 148 { }, 148 149 }; ··· 152 151 { "80860F14" }, 153 152 { "INT33BB" }, 154 153 { "INT33C6" }, 154 + { "INT3436" }, 155 155 { "PNP0D40" }, 156 156 { }, 157 157 };
+101 -27
drivers/mmc/host/sdhci-esdhc-imx.c
··· 27 27 #include <linux/of_gpio.h> 28 28 #include <linux/pinctrl/consumer.h> 29 29 #include <linux/platform_data/mmc-esdhc-imx.h> 30 + #include <linux/pm_runtime.h> 30 31 #include "sdhci-pltfm.h" 31 32 #include "sdhci-esdhc.h" 32 33 ··· 46 45 #define ESDHC_MIX_CTRL_FBCLK_SEL (1 << 25) 47 46 /* Bits 3 and 6 are not SDHCI standard definitions */ 48 47 #define ESDHC_MIX_CTRL_SDHCI_MASK 0xb7 48 + /* Tuning bits */ 49 + #define ESDHC_MIX_CTRL_TUNING_MASK 0x03c00000 49 50 50 51 /* dll control register */ 51 52 #define ESDHC_DLL_CTRL 0x60 ··· 388 385 return ret; 389 386 } 390 387 388 + if (unlikely(reg == SDHCI_TRANSFER_MODE)) { 389 + if (esdhc_is_usdhc(imx_data)) { 390 + u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL); 391 + ret = m & ESDHC_MIX_CTRL_SDHCI_MASK; 392 + /* Swap AC23 bit */ 393 + if (m & ESDHC_MIX_CTRL_AC23EN) { 394 + ret &= ~ESDHC_MIX_CTRL_AC23EN; 395 + ret |= SDHCI_TRNS_AUTO_CMD23; 396 + } 397 + } else { 398 + ret = readw(host->ioaddr + SDHCI_TRANSFER_MODE); 399 + } 400 + 401 + return ret; 402 + } 403 + 391 404 return readw(host->ioaddr + reg); 392 405 } 393 406 ··· 440 421 } else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) { 441 422 u32 v = readl(host->ioaddr + SDHCI_ACMD12_ERR); 442 423 u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL); 443 - new_val = readl(host->ioaddr + ESDHC_TUNING_CTRL); 444 - if (val & SDHCI_CTRL_EXEC_TUNING) { 445 - new_val |= ESDHC_STD_TUNING_EN | 446 - ESDHC_TUNING_START_TAP; 447 - v |= ESDHC_MIX_CTRL_EXE_TUNE; 448 - m |= ESDHC_MIX_CTRL_FBCLK_SEL; 424 + if (val & SDHCI_CTRL_TUNED_CLK) { 425 + v |= ESDHC_MIX_CTRL_SMPCLK_SEL; 449 426 } else { 450 - new_val &= ~ESDHC_STD_TUNING_EN; 451 - v &= ~ESDHC_MIX_CTRL_EXE_TUNE; 427 + v &= ~ESDHC_MIX_CTRL_SMPCLK_SEL; 452 428 m &= ~ESDHC_MIX_CTRL_FBCLK_SEL; 453 429 } 454 430 455 - if (val & SDHCI_CTRL_TUNED_CLK) 456 - v |= ESDHC_MIX_CTRL_SMPCLK_SEL; 457 - else 458 - v &= ~ESDHC_MIX_CTRL_SMPCLK_SEL; 431 + if (val & SDHCI_CTRL_EXEC_TUNING) { 432 + v |= ESDHC_MIX_CTRL_EXE_TUNE; 433 + m |= ESDHC_MIX_CTRL_FBCLK_SEL; 434 + } else { 435 + v &= ~ESDHC_MIX_CTRL_EXE_TUNE; 436 + } 459 437 460 - writel(new_val, host->ioaddr + ESDHC_TUNING_CTRL); 461 438 writel(v, host->ioaddr + SDHCI_ACMD12_ERR); 462 439 writel(m, host->ioaddr + ESDHC_MIX_CTRL); 463 440 } ··· 561 546 * Do it manually here. 562 547 */ 563 548 if (esdhc_is_usdhc(imx_data)) { 564 - writel(0, host->ioaddr + ESDHC_MIX_CTRL); 549 + /* the tuning bits should be kept during reset */ 550 + new_val = readl(host->ioaddr + ESDHC_MIX_CTRL); 551 + writel(new_val & ESDHC_MIX_CTRL_TUNING_MASK, 552 + host->ioaddr + ESDHC_MIX_CTRL); 565 553 imx_data->is_ddr = 0; 566 554 } 567 555 } ··· 576 558 struct pltfm_imx_data *imx_data = pltfm_host->priv; 577 559 struct esdhc_platform_data *boarddata = &imx_data->boarddata; 578 560 579 - u32 f_host = clk_get_rate(pltfm_host->clk); 580 - 581 - if (boarddata->f_max && (boarddata->f_max < f_host)) 561 + if (boarddata->f_max && (boarddata->f_max < pltfm_host->clock)) 582 562 return boarddata->f_max; 583 563 else 584 - return f_host; 564 + return pltfm_host->clock; 585 565 } 586 566 587 567 static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host) 588 568 { 589 569 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 590 570 591 - return clk_get_rate(pltfm_host->clk) / 256 / 16; 571 + return pltfm_host->clock / 256 / 16; 592 572 } 593 573 594 574 static inline void esdhc_pltfm_set_clock(struct sdhci_host *host, ··· 594 578 { 595 579 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 596 580 struct pltfm_imx_data *imx_data = pltfm_host->priv; 597 - unsigned int host_clock = clk_get_rate(pltfm_host->clk); 581 + unsigned int host_clock = pltfm_host->clock; 598 582 int pre_div = 2; 599 583 int div = 1; 600 584 u32 temp, val; ··· 697 681 /* FIXME: delay a bit for card to be ready for next tuning due to errors */ 698 682 mdelay(1); 699 683 684 + pm_runtime_get_sync(host->mmc->parent); 700 685 reg = readl(host->ioaddr + ESDHC_MIX_CTRL); 701 686 reg |= ESDHC_MIX_CTRL_EXE_TUNE | ESDHC_MIX_CTRL_SMPCLK_SEL | 702 687 ESDHC_MIX_CTRL_FBCLK_SEL; ··· 716 699 static int esdhc_send_tuning_cmd(struct sdhci_host *host, u32 opcode) 717 700 { 718 701 struct mmc_command cmd = {0}; 719 - struct mmc_request mrq = {0}; 702 + struct mmc_request mrq = {NULL}; 720 703 struct mmc_data data = {0}; 721 704 struct scatterlist sg; 722 705 char tuning_pattern[ESDHC_TUNING_BLOCK_PATTERN_LEN]; ··· 826 809 pinctrl = imx_data->pins_100mhz; 827 810 break; 828 811 case MMC_TIMING_UHS_SDR104: 812 + case MMC_TIMING_MMC_HS200: 829 813 pinctrl = imx_data->pins_200mhz; 830 814 break; 831 815 default: ··· 854 836 imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR50; 855 837 break; 856 838 case MMC_TIMING_UHS_SDR104: 839 + case MMC_TIMING_MMC_HS200: 857 840 imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR104; 858 841 break; 859 842 case MMC_TIMING_UHS_DDR50: ··· 995 976 } 996 977 997 978 pltfm_host->clk = imx_data->clk_per; 998 - 979 + pltfm_host->clock = clk_get_rate(pltfm_host->clk); 999 980 clk_prepare_enable(imx_data->clk_per); 1000 981 clk_prepare_enable(imx_data->clk_ipg); 1001 982 clk_prepare_enable(imx_data->clk_ahb); ··· 1028 1009 if (esdhc_is_usdhc(imx_data)) { 1029 1010 writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL); 1030 1011 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN; 1012 + host->mmc->caps |= MMC_CAP_1_8V_DDR; 1031 1013 } 1032 1014 1033 1015 if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) 1034 1016 sdhci_esdhc_ops.platform_execute_tuning = 1035 1017 esdhc_executing_tuning; 1018 + 1019 + if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) 1020 + writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) | 1021 + ESDHC_STD_TUNING_EN | ESDHC_TUNING_START_TAP, 1022 + host->ioaddr + ESDHC_TUNING_CTRL); 1023 + 1036 1024 boarddata = &imx_data->boarddata; 1037 1025 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) { 1038 1026 if (!host->mmc->parent->platform_data) { ··· 1079 1053 break; 1080 1054 1081 1055 case ESDHC_CD_PERMANENT: 1082 - host->mmc->caps = MMC_CAP_NONREMOVABLE; 1056 + host->mmc->caps |= MMC_CAP_NONREMOVABLE; 1083 1057 break; 1084 1058 1085 1059 case ESDHC_CD_NONE: ··· 1120 1094 if (err) 1121 1095 goto disable_clk; 1122 1096 1097 + pm_runtime_set_active(&pdev->dev); 1098 + pm_runtime_enable(&pdev->dev); 1099 + pm_runtime_set_autosuspend_delay(&pdev->dev, 50); 1100 + pm_runtime_use_autosuspend(&pdev->dev); 1101 + pm_suspend_ignore_children(&pdev->dev, 1); 1102 + 1123 1103 return 0; 1124 1104 1125 1105 disable_clk: ··· 1146 1114 1147 1115 sdhci_remove_host(host, dead); 1148 1116 1149 - clk_disable_unprepare(imx_data->clk_per); 1150 - clk_disable_unprepare(imx_data->clk_ipg); 1151 - clk_disable_unprepare(imx_data->clk_ahb); 1117 + pm_runtime_dont_use_autosuspend(&pdev->dev); 1118 + pm_runtime_disable(&pdev->dev); 1119 + 1120 + if (!IS_ENABLED(CONFIG_PM_RUNTIME)) { 1121 + clk_disable_unprepare(imx_data->clk_per); 1122 + clk_disable_unprepare(imx_data->clk_ipg); 1123 + clk_disable_unprepare(imx_data->clk_ahb); 1124 + } 1152 1125 1153 1126 sdhci_pltfm_free(pdev); 1154 1127 1155 1128 return 0; 1156 1129 } 1157 1130 1131 + #ifdef CONFIG_PM_RUNTIME 1132 + static int sdhci_esdhc_runtime_suspend(struct device *dev) 1133 + { 1134 + struct sdhci_host *host = dev_get_drvdata(dev); 1135 + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 1136 + struct pltfm_imx_data *imx_data = pltfm_host->priv; 1137 + int ret; 1138 + 1139 + ret = sdhci_runtime_suspend_host(host); 1140 + 1141 + clk_disable_unprepare(imx_data->clk_per); 1142 + clk_disable_unprepare(imx_data->clk_ipg); 1143 + clk_disable_unprepare(imx_data->clk_ahb); 1144 + 1145 + return ret; 1146 + } 1147 + 1148 + static int sdhci_esdhc_runtime_resume(struct device *dev) 1149 + { 1150 + struct sdhci_host *host = dev_get_drvdata(dev); 1151 + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 1152 + struct pltfm_imx_data *imx_data = pltfm_host->priv; 1153 + 1154 + clk_prepare_enable(imx_data->clk_per); 1155 + clk_prepare_enable(imx_data->clk_ipg); 1156 + clk_prepare_enable(imx_data->clk_ahb); 1157 + 1158 + return sdhci_runtime_resume_host(host); 1159 + } 1160 + #endif 1161 + 1162 + static const struct dev_pm_ops sdhci_esdhc_pmops = { 1163 + SET_SYSTEM_SLEEP_PM_OPS(sdhci_pltfm_suspend, sdhci_pltfm_resume) 1164 + SET_RUNTIME_PM_OPS(sdhci_esdhc_runtime_suspend, 1165 + sdhci_esdhc_runtime_resume, NULL) 1166 + }; 1167 + 1158 1168 static struct platform_driver sdhci_esdhc_imx_driver = { 1159 1169 .driver = { 1160 1170 .name = "sdhci-esdhc-imx", 1161 1171 .owner = THIS_MODULE, 1162 1172 .of_match_table = imx_esdhc_dt_ids, 1163 - .pm = SDHCI_PLTFM_PMOPS, 1173 + .pm = &sdhci_esdhc_pmops, 1164 1174 }, 1165 1175 .id_table = imx_esdhc_devtype, 1166 1176 .probe = sdhci_esdhc_imx_probe,
+224
drivers/mmc/host/sdhci-of-arasan.c
··· 1 + /* 2 + * Arasan Secure Digital Host Controller Interface. 3 + * Copyright (C) 2011 - 2012 Michal Simek <monstr@monstr.eu> 4 + * Copyright (c) 2012 Wind River Systems, Inc. 5 + * Copyright (C) 2013 Pengutronix e.K. 6 + * Copyright (C) 2013 Xilinx Inc. 7 + * 8 + * Based on sdhci-of-esdhc.c 9 + * 10 + * Copyright (c) 2007 Freescale Semiconductor, Inc. 11 + * Copyright (c) 2009 MontaVista Software, Inc. 12 + * 13 + * Authors: Xiaobo Xie <X.Xie@freescale.com> 14 + * Anton Vorontsov <avorontsov@ru.mvista.com> 15 + * 16 + * This program is free software; you can redistribute it and/or modify 17 + * it under the terms of the GNU General Public License as published by 18 + * the Free Software Foundation; either version 2 of the License, or (at 19 + * your option) any later version. 20 + */ 21 + 22 + #include <linux/module.h> 23 + #include "sdhci-pltfm.h" 24 + 25 + #define SDHCI_ARASAN_CLK_CTRL_OFFSET 0x2c 26 + 27 + #define CLK_CTRL_TIMEOUT_SHIFT 16 28 + #define CLK_CTRL_TIMEOUT_MASK (0xf << CLK_CTRL_TIMEOUT_SHIFT) 29 + #define CLK_CTRL_TIMEOUT_MIN_EXP 13 30 + 31 + /** 32 + * struct sdhci_arasan_data 33 + * @clk_ahb: Pointer to the AHB clock 34 + */ 35 + struct sdhci_arasan_data { 36 + struct clk *clk_ahb; 37 + }; 38 + 39 + static unsigned int sdhci_arasan_get_timeout_clock(struct sdhci_host *host) 40 + { 41 + u32 div; 42 + unsigned long freq; 43 + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 44 + 45 + div = readl(host->ioaddr + SDHCI_ARASAN_CLK_CTRL_OFFSET); 46 + div = (div & CLK_CTRL_TIMEOUT_MASK) >> CLK_CTRL_TIMEOUT_SHIFT; 47 + 48 + freq = clk_get_rate(pltfm_host->clk); 49 + freq /= 1 << (CLK_CTRL_TIMEOUT_MIN_EXP + div); 50 + 51 + return freq; 52 + } 53 + 54 + static struct sdhci_ops sdhci_arasan_ops = { 55 + .get_max_clock = sdhci_pltfm_clk_get_max_clock, 56 + .get_timeout_clock = sdhci_arasan_get_timeout_clock, 57 + }; 58 + 59 + static struct sdhci_pltfm_data sdhci_arasan_pdata = { 60 + .ops = &sdhci_arasan_ops, 61 + }; 62 + 63 + #ifdef CONFIG_PM_SLEEP 64 + /** 65 + * sdhci_arasan_suspend - Suspend method for the driver 66 + * @dev: Address of the device structure 67 + * Returns 0 on success and error value on error 68 + * 69 + * Put the device in a low power state. 70 + */ 71 + static int sdhci_arasan_suspend(struct device *dev) 72 + { 73 + struct platform_device *pdev = to_platform_device(dev); 74 + struct sdhci_host *host = platform_get_drvdata(pdev); 75 + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 76 + struct sdhci_arasan_data *sdhci_arasan = pltfm_host->priv; 77 + int ret; 78 + 79 + ret = sdhci_suspend_host(host); 80 + if (ret) 81 + return ret; 82 + 83 + clk_disable(pltfm_host->clk); 84 + clk_disable(sdhci_arasan->clk_ahb); 85 + 86 + return 0; 87 + } 88 + 89 + /** 90 + * sdhci_arasan_resume - Resume method for the driver 91 + * @dev: Address of the device structure 92 + * Returns 0 on success and error value on error 93 + * 94 + * Resume operation after suspend 95 + */ 96 + static int sdhci_arasan_resume(struct device *dev) 97 + { 98 + struct platform_device *pdev = to_platform_device(dev); 99 + struct sdhci_host *host = platform_get_drvdata(pdev); 100 + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 101 + struct sdhci_arasan_data *sdhci_arasan = pltfm_host->priv; 102 + int ret; 103 + 104 + ret = clk_enable(sdhci_arasan->clk_ahb); 105 + if (ret) { 106 + dev_err(dev, "Cannot enable AHB clock.\n"); 107 + return ret; 108 + } 109 + 110 + ret = clk_enable(pltfm_host->clk); 111 + if (ret) { 112 + dev_err(dev, "Cannot enable SD clock.\n"); 113 + clk_disable(sdhci_arasan->clk_ahb); 114 + return ret; 115 + } 116 + 117 + return sdhci_resume_host(host); 118 + } 119 + #endif /* ! CONFIG_PM_SLEEP */ 120 + 121 + static SIMPLE_DEV_PM_OPS(sdhci_arasan_dev_pm_ops, sdhci_arasan_suspend, 122 + sdhci_arasan_resume); 123 + 124 + static int sdhci_arasan_probe(struct platform_device *pdev) 125 + { 126 + int ret; 127 + struct clk *clk_xin; 128 + struct sdhci_host *host; 129 + struct sdhci_pltfm_host *pltfm_host; 130 + struct sdhci_arasan_data *sdhci_arasan; 131 + 132 + sdhci_arasan = devm_kzalloc(&pdev->dev, sizeof(*sdhci_arasan), 133 + GFP_KERNEL); 134 + if (!sdhci_arasan) 135 + return -ENOMEM; 136 + 137 + sdhci_arasan->clk_ahb = devm_clk_get(&pdev->dev, "clk_ahb"); 138 + if (IS_ERR(sdhci_arasan->clk_ahb)) { 139 + dev_err(&pdev->dev, "clk_ahb clock not found.\n"); 140 + return PTR_ERR(sdhci_arasan->clk_ahb); 141 + } 142 + 143 + clk_xin = devm_clk_get(&pdev->dev, "clk_xin"); 144 + if (IS_ERR(clk_xin)) { 145 + dev_err(&pdev->dev, "clk_xin clock not found.\n"); 146 + return PTR_ERR(clk_xin); 147 + } 148 + 149 + ret = clk_prepare_enable(sdhci_arasan->clk_ahb); 150 + if (ret) { 151 + dev_err(&pdev->dev, "Unable to enable AHB clock.\n"); 152 + return ret; 153 + } 154 + 155 + ret = clk_prepare_enable(clk_xin); 156 + if (ret) { 157 + dev_err(&pdev->dev, "Unable to enable SD clock.\n"); 158 + goto clk_dis_ahb; 159 + } 160 + 161 + host = sdhci_pltfm_init(pdev, &sdhci_arasan_pdata, 0); 162 + if (IS_ERR(host)) { 163 + ret = PTR_ERR(host); 164 + dev_err(&pdev->dev, "platform init failed (%u)\n", ret); 165 + goto clk_disable_all; 166 + } 167 + 168 + sdhci_get_of_property(pdev); 169 + pltfm_host = sdhci_priv(host); 170 + pltfm_host->priv = sdhci_arasan; 171 + pltfm_host->clk = clk_xin; 172 + 173 + ret = sdhci_add_host(host); 174 + if (ret) { 175 + dev_err(&pdev->dev, "platform register failed (%u)\n", ret); 176 + goto err_pltfm_free; 177 + } 178 + 179 + return 0; 180 + 181 + err_pltfm_free: 182 + sdhci_pltfm_free(pdev); 183 + clk_disable_all: 184 + clk_disable_unprepare(clk_xin); 185 + clk_dis_ahb: 186 + clk_disable_unprepare(sdhci_arasan->clk_ahb); 187 + 188 + return ret; 189 + } 190 + 191 + static int sdhci_arasan_remove(struct platform_device *pdev) 192 + { 193 + struct sdhci_host *host = platform_get_drvdata(pdev); 194 + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 195 + struct sdhci_arasan_data *sdhci_arasan = pltfm_host->priv; 196 + 197 + clk_disable_unprepare(pltfm_host->clk); 198 + clk_disable_unprepare(sdhci_arasan->clk_ahb); 199 + 200 + return sdhci_pltfm_unregister(pdev); 201 + } 202 + 203 + static const struct of_device_id sdhci_arasan_of_match[] = { 204 + { .compatible = "arasan,sdhci-8.9a" }, 205 + { } 206 + }; 207 + MODULE_DEVICE_TABLE(of, sdhci_arasan_of_match); 208 + 209 + static struct platform_driver sdhci_arasan_driver = { 210 + .driver = { 211 + .name = "sdhci-arasan", 212 + .owner = THIS_MODULE, 213 + .of_match_table = sdhci_arasan_of_match, 214 + .pm = &sdhci_arasan_dev_pm_ops, 215 + }, 216 + .probe = sdhci_arasan_probe, 217 + .remove = sdhci_arasan_remove, 218 + }; 219 + 220 + module_platform_driver(sdhci_arasan_driver); 221 + 222 + MODULE_DESCRIPTION("Driver for the Arasan SDHCI Controller"); 223 + MODULE_AUTHOR("Soeren Brinkmann <soren.brinkmann@xilinx.com>"); 224 + MODULE_LICENSE("GPL");
+321
drivers/mmc/host/sdhci-pci-o2micro.c
··· 1 + /* 2 + * Copyright (C) 2013 BayHub Technology Ltd. 3 + * 4 + * Authors: Peter Guo <peter.guo@bayhubtech.com> 5 + * Adam Lee <adam.lee@canonical.com> 6 + * 7 + * This software is licensed under the terms of the GNU General Public 8 + * License version 2, as published by the Free Software Foundation, and 9 + * may be copied, distributed, and modified under those terms. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + */ 17 + 18 + #include <linux/pci.h> 19 + 20 + #include "sdhci.h" 21 + #include "sdhci-pci.h" 22 + #include "sdhci-pci-o2micro.h" 23 + 24 + void sdhci_pci_o2_fujin2_pci_init(struct sdhci_pci_chip *chip) 25 + { 26 + u32 scratch_32; 27 + int ret; 28 + /* Improve write performance for SD3.0 */ 29 + ret = pci_read_config_dword(chip->pdev, O2_SD_DEV_CTRL, &scratch_32); 30 + if (ret) 31 + return; 32 + scratch_32 &= ~((1 << 12) | (1 << 13) | (1 << 14)); 33 + pci_write_config_dword(chip->pdev, O2_SD_DEV_CTRL, scratch_32); 34 + 35 + /* Enable Link abnormal reset generating Reset */ 36 + ret = pci_read_config_dword(chip->pdev, O2_SD_MISC_REG5, &scratch_32); 37 + if (ret) 38 + return; 39 + scratch_32 &= ~((1 << 19) | (1 << 11)); 40 + scratch_32 |= (1 << 10); 41 + pci_write_config_dword(chip->pdev, O2_SD_MISC_REG5, scratch_32); 42 + 43 + /* set card power over current protection */ 44 + ret = pci_read_config_dword(chip->pdev, O2_SD_TEST_REG, &scratch_32); 45 + if (ret) 46 + return; 47 + scratch_32 |= (1 << 4); 48 + pci_write_config_dword(chip->pdev, O2_SD_TEST_REG, scratch_32); 49 + 50 + /* adjust the output delay for SD mode */ 51 + pci_write_config_dword(chip->pdev, O2_SD_DELAY_CTRL, 0x00002492); 52 + 53 + /* Set the output voltage setting of Aux 1.2v LDO */ 54 + ret = pci_read_config_dword(chip->pdev, O2_SD_LD0_CTRL, &scratch_32); 55 + if (ret) 56 + return; 57 + scratch_32 &= ~(3 << 12); 58 + pci_write_config_dword(chip->pdev, O2_SD_LD0_CTRL, scratch_32); 59 + 60 + /* Set Max power supply capability of SD host */ 61 + ret = pci_read_config_dword(chip->pdev, O2_SD_CAP_REG0, &scratch_32); 62 + if (ret) 63 + return; 64 + scratch_32 &= ~(0x01FE); 65 + scratch_32 |= 0x00CC; 66 + pci_write_config_dword(chip->pdev, O2_SD_CAP_REG0, scratch_32); 67 + /* Set DLL Tuning Window */ 68 + ret = pci_read_config_dword(chip->pdev, 69 + O2_SD_TUNING_CTRL, &scratch_32); 70 + if (ret) 71 + return; 72 + scratch_32 &= ~(0x000000FF); 73 + scratch_32 |= 0x00000066; 74 + pci_write_config_dword(chip->pdev, O2_SD_TUNING_CTRL, scratch_32); 75 + 76 + /* Set UHS2 T_EIDLE */ 77 + ret = pci_read_config_dword(chip->pdev, 78 + O2_SD_UHS2_L1_CTRL, &scratch_32); 79 + if (ret) 80 + return; 81 + scratch_32 &= ~(0x000000FC); 82 + scratch_32 |= 0x00000084; 83 + pci_write_config_dword(chip->pdev, O2_SD_UHS2_L1_CTRL, scratch_32); 84 + 85 + /* Set UHS2 Termination */ 86 + ret = pci_read_config_dword(chip->pdev, O2_SD_FUNC_REG3, &scratch_32); 87 + if (ret) 88 + return; 89 + scratch_32 &= ~((1 << 21) | (1 << 30)); 90 + 91 + /* Set RTD3 function disabled */ 92 + scratch_32 |= ((1 << 29) | (1 << 28)); 93 + pci_write_config_dword(chip->pdev, O2_SD_FUNC_REG3, scratch_32); 94 + 95 + /* Set L1 Entrance Timer */ 96 + ret = pci_read_config_dword(chip->pdev, O2_SD_CAPS, &scratch_32); 97 + if (ret) 98 + return; 99 + scratch_32 &= ~(0xf0000000); 100 + scratch_32 |= 0x30000000; 101 + pci_write_config_dword(chip->pdev, O2_SD_CAPS, scratch_32); 102 + 103 + ret = pci_read_config_dword(chip->pdev, 104 + O2_SD_MISC_CTRL4, &scratch_32); 105 + if (ret) 106 + return; 107 + scratch_32 &= ~(0x000f0000); 108 + scratch_32 |= 0x00080000; 109 + pci_write_config_dword(chip->pdev, O2_SD_MISC_CTRL4, scratch_32); 110 + } 111 + EXPORT_SYMBOL_GPL(sdhci_pci_o2_fujin2_pci_init); 112 + 113 + int sdhci_pci_o2_probe_slot(struct sdhci_pci_slot *slot) 114 + { 115 + struct sdhci_pci_chip *chip; 116 + struct sdhci_host *host; 117 + u32 reg; 118 + 119 + chip = slot->chip; 120 + host = slot->host; 121 + switch (chip->pdev->device) { 122 + case PCI_DEVICE_ID_O2_SDS0: 123 + case PCI_DEVICE_ID_O2_SEABIRD0: 124 + case PCI_DEVICE_ID_O2_SEABIRD1: 125 + case PCI_DEVICE_ID_O2_SDS1: 126 + case PCI_DEVICE_ID_O2_FUJIN2: 127 + reg = sdhci_readl(host, O2_SD_VENDOR_SETTING); 128 + if (reg & 0x1) 129 + host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12; 130 + 131 + if (chip->pdev->device != PCI_DEVICE_ID_O2_FUJIN2) 132 + break; 133 + /* set dll watch dog timer */ 134 + reg = sdhci_readl(host, O2_SD_VENDOR_SETTING2); 135 + reg |= (1 << 12); 136 + sdhci_writel(host, reg, O2_SD_VENDOR_SETTING2); 137 + 138 + break; 139 + default: 140 + break; 141 + } 142 + 143 + return 0; 144 + } 145 + EXPORT_SYMBOL_GPL(sdhci_pci_o2_probe_slot); 146 + 147 + int sdhci_pci_o2_probe(struct sdhci_pci_chip *chip) 148 + { 149 + int ret; 150 + u8 scratch; 151 + u32 scratch_32; 152 + 153 + switch (chip->pdev->device) { 154 + case PCI_DEVICE_ID_O2_8220: 155 + case PCI_DEVICE_ID_O2_8221: 156 + case PCI_DEVICE_ID_O2_8320: 157 + case PCI_DEVICE_ID_O2_8321: 158 + /* This extra setup is required due to broken ADMA. */ 159 + ret = pci_read_config_byte(chip->pdev, 160 + O2_SD_LOCK_WP, &scratch); 161 + if (ret) 162 + return ret; 163 + scratch &= 0x7f; 164 + pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch); 165 + 166 + /* Set Multi 3 to VCC3V# */ 167 + pci_write_config_byte(chip->pdev, O2_SD_MULTI_VCC3V, 0x08); 168 + 169 + /* Disable CLK_REQ# support after media DET */ 170 + ret = pci_read_config_byte(chip->pdev, 171 + O2_SD_CLKREQ, &scratch); 172 + if (ret) 173 + return ret; 174 + scratch |= 0x20; 175 + pci_write_config_byte(chip->pdev, O2_SD_CLKREQ, scratch); 176 + 177 + /* Choose capabilities, enable SDMA. We have to write 0x01 178 + * to the capabilities register first to unlock it. 179 + */ 180 + ret = pci_read_config_byte(chip->pdev, O2_SD_CAPS, &scratch); 181 + if (ret) 182 + return ret; 183 + scratch |= 0x01; 184 + pci_write_config_byte(chip->pdev, O2_SD_CAPS, scratch); 185 + pci_write_config_byte(chip->pdev, O2_SD_CAPS, 0x73); 186 + 187 + /* Disable ADMA1/2 */ 188 + pci_write_config_byte(chip->pdev, O2_SD_ADMA1, 0x39); 189 + pci_write_config_byte(chip->pdev, O2_SD_ADMA2, 0x08); 190 + 191 + /* Disable the infinite transfer mode */ 192 + ret = pci_read_config_byte(chip->pdev, 193 + O2_SD_INF_MOD, &scratch); 194 + if (ret) 195 + return ret; 196 + scratch |= 0x08; 197 + pci_write_config_byte(chip->pdev, O2_SD_INF_MOD, scratch); 198 + 199 + /* Lock WP */ 200 + ret = pci_read_config_byte(chip->pdev, 201 + O2_SD_LOCK_WP, &scratch); 202 + if (ret) 203 + return ret; 204 + scratch |= 0x80; 205 + pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch); 206 + break; 207 + case PCI_DEVICE_ID_O2_SDS0: 208 + case PCI_DEVICE_ID_O2_SDS1: 209 + case PCI_DEVICE_ID_O2_FUJIN2: 210 + /* UnLock WP */ 211 + ret = pci_read_config_byte(chip->pdev, 212 + O2_SD_LOCK_WP, &scratch); 213 + if (ret) 214 + return ret; 215 + 216 + scratch &= 0x7f; 217 + pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch); 218 + 219 + /* Set timeout CLK */ 220 + ret = pci_read_config_dword(chip->pdev, 221 + O2_SD_CLK_SETTING, &scratch_32); 222 + if (ret) 223 + return ret; 224 + 225 + scratch_32 &= ~(0xFF00); 226 + scratch_32 |= 0x07E0C800; 227 + pci_write_config_dword(chip->pdev, 228 + O2_SD_CLK_SETTING, scratch_32); 229 + 230 + ret = pci_read_config_dword(chip->pdev, 231 + O2_SD_CLKREQ, &scratch_32); 232 + if (ret) 233 + return ret; 234 + scratch_32 |= 0x3; 235 + pci_write_config_dword(chip->pdev, O2_SD_CLKREQ, scratch_32); 236 + 237 + ret = pci_read_config_dword(chip->pdev, 238 + O2_SD_PLL_SETTING, &scratch_32); 239 + if (ret) 240 + return ret; 241 + 242 + scratch_32 &= ~(0x1F3F070E); 243 + scratch_32 |= 0x18270106; 244 + pci_write_config_dword(chip->pdev, 245 + O2_SD_PLL_SETTING, scratch_32); 246 + 247 + /* Disable UHS1 funciton */ 248 + ret = pci_read_config_dword(chip->pdev, 249 + O2_SD_CAP_REG2, &scratch_32); 250 + if (ret) 251 + return ret; 252 + scratch_32 &= ~(0xE0); 253 + pci_write_config_dword(chip->pdev, 254 + O2_SD_CAP_REG2, scratch_32); 255 + 256 + if (chip->pdev->device == PCI_DEVICE_ID_O2_FUJIN2) 257 + sdhci_pci_o2_fujin2_pci_init(chip); 258 + 259 + /* Lock WP */ 260 + ret = pci_read_config_byte(chip->pdev, 261 + O2_SD_LOCK_WP, &scratch); 262 + if (ret) 263 + return ret; 264 + scratch |= 0x80; 265 + pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch); 266 + break; 267 + case PCI_DEVICE_ID_O2_SEABIRD0: 268 + case PCI_DEVICE_ID_O2_SEABIRD1: 269 + /* UnLock WP */ 270 + ret = pci_read_config_byte(chip->pdev, 271 + O2_SD_LOCK_WP, &scratch); 272 + if (ret) 273 + return ret; 274 + 275 + scratch &= 0x7f; 276 + pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch); 277 + 278 + ret = pci_read_config_dword(chip->pdev, 279 + O2_SD_FUNC_REG0, &scratch_32); 280 + 281 + if ((scratch_32 & 0xff000000) == 0x01000000) { 282 + scratch_32 &= 0x0000FFFF; 283 + scratch_32 |= 0x1F340000; 284 + 285 + pci_write_config_dword(chip->pdev, 286 + O2_SD_PLL_SETTING, scratch_32); 287 + } else { 288 + scratch_32 &= 0x0000FFFF; 289 + scratch_32 |= 0x2c280000; 290 + 291 + pci_write_config_dword(chip->pdev, 292 + O2_SD_PLL_SETTING, scratch_32); 293 + 294 + ret = pci_read_config_dword(chip->pdev, 295 + O2_SD_FUNC_REG4, 296 + &scratch_32); 297 + scratch_32 |= (1 << 22); 298 + pci_write_config_dword(chip->pdev, 299 + O2_SD_FUNC_REG4, scratch_32); 300 + } 301 + 302 + /* Lock WP */ 303 + ret = pci_read_config_byte(chip->pdev, 304 + O2_SD_LOCK_WP, &scratch); 305 + if (ret) 306 + return ret; 307 + scratch |= 0x80; 308 + pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch); 309 + break; 310 + } 311 + 312 + return 0; 313 + } 314 + EXPORT_SYMBOL_GPL(sdhci_pci_o2_probe); 315 + 316 + int sdhci_pci_o2_resume(struct sdhci_pci_chip *chip) 317 + { 318 + sdhci_pci_o2_probe(chip); 319 + return 0; 320 + } 321 + EXPORT_SYMBOL_GPL(sdhci_pci_o2_resume);
+72
drivers/mmc/host/sdhci-pci-o2micro.h
··· 1 + /* 2 + * Copyright (C) 2013 BayHub Technology Ltd. 3 + * 4 + * Authors: Peter Guo <peter.guo@bayhubtech.com> 5 + * Adam Lee <adam.lee@canonical.com> 6 + * 7 + * This software is licensed under the terms of the GNU General Public 8 + * License version 2, as published by the Free Software Foundation, and 9 + * may be copied, distributed, and modified under those terms. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + */ 17 + 18 + #ifndef __SDHCI_PCI_O2MICRO_H 19 + #define __SDHCI_PCI_O2MICRO_H 20 + 21 + #include "sdhci-pci.h" 22 + 23 + /* 24 + * O2Micro device IDs 25 + */ 26 + 27 + #define PCI_DEVICE_ID_O2_SDS0 0x8420 28 + #define PCI_DEVICE_ID_O2_SDS1 0x8421 29 + #define PCI_DEVICE_ID_O2_FUJIN2 0x8520 30 + #define PCI_DEVICE_ID_O2_SEABIRD0 0x8620 31 + #define PCI_DEVICE_ID_O2_SEABIRD1 0x8621 32 + 33 + /* 34 + * O2Micro device registers 35 + */ 36 + 37 + #define O2_SD_MISC_REG5 0x64 38 + #define O2_SD_LD0_CTRL 0x68 39 + #define O2_SD_DEV_CTRL 0x88 40 + #define O2_SD_LOCK_WP 0xD3 41 + #define O2_SD_TEST_REG 0xD4 42 + #define O2_SD_FUNC_REG0 0xDC 43 + #define O2_SD_MULTI_VCC3V 0xEE 44 + #define O2_SD_CLKREQ 0xEC 45 + #define O2_SD_CAPS 0xE0 46 + #define O2_SD_ADMA1 0xE2 47 + #define O2_SD_ADMA2 0xE7 48 + #define O2_SD_INF_MOD 0xF1 49 + #define O2_SD_MISC_CTRL4 0xFC 50 + #define O2_SD_TUNING_CTRL 0x300 51 + #define O2_SD_PLL_SETTING 0x304 52 + #define O2_SD_CLK_SETTING 0x328 53 + #define O2_SD_CAP_REG2 0x330 54 + #define O2_SD_CAP_REG0 0x334 55 + #define O2_SD_UHS1_CAP_SETTING 0x33C 56 + #define O2_SD_DELAY_CTRL 0x350 57 + #define O2_SD_UHS2_L1_CTRL 0x35C 58 + #define O2_SD_FUNC_REG3 0x3E0 59 + #define O2_SD_FUNC_REG4 0x3E4 60 + 61 + #define O2_SD_VENDOR_SETTING 0x110 62 + #define O2_SD_VENDOR_SETTING2 0x1C8 63 + 64 + extern void sdhci_pci_o2_fujin2_pci_init(struct sdhci_pci_chip *chip); 65 + 66 + extern int sdhci_pci_o2_probe_slot(struct sdhci_pci_slot *slot); 67 + 68 + extern int sdhci_pci_o2_probe(struct sdhci_pci_chip *chip); 69 + 70 + extern int sdhci_pci_o2_resume(struct sdhci_pci_chip *chip); 71 + 72 + #endif /* __SDHCI_PCI_O2MICRO_H */
+58 -133
drivers/mmc/host/sdhci-pci.c
··· 27 27 #include <linux/mmc/sdhci-pci-data.h> 28 28 29 29 #include "sdhci.h" 30 - 31 - /* 32 - * PCI device IDs 33 - */ 34 - #define PCI_DEVICE_ID_INTEL_PCH_SDIO0 0x8809 35 - #define PCI_DEVICE_ID_INTEL_PCH_SDIO1 0x880a 36 - #define PCI_DEVICE_ID_INTEL_BYT_EMMC 0x0f14 37 - #define PCI_DEVICE_ID_INTEL_BYT_SDIO 0x0f15 38 - #define PCI_DEVICE_ID_INTEL_BYT_SD 0x0f16 39 - #define PCI_DEVICE_ID_INTEL_BYT_EMMC2 0x0f50 40 - #define PCI_DEVICE_ID_INTEL_MRFL_MMC 0x1190 41 - #define PCI_DEVICE_ID_INTEL_CLV_SDIO0 0x08f9 42 - #define PCI_DEVICE_ID_INTEL_CLV_SDIO1 0x08fa 43 - #define PCI_DEVICE_ID_INTEL_CLV_SDIO2 0x08fb 44 - #define PCI_DEVICE_ID_INTEL_CLV_EMMC0 0x08e5 45 - #define PCI_DEVICE_ID_INTEL_CLV_EMMC1 0x08e6 46 - 47 - /* 48 - * PCI registers 49 - */ 50 - 51 - #define PCI_SDHCI_IFPIO 0x00 52 - #define PCI_SDHCI_IFDMA 0x01 53 - #define PCI_SDHCI_IFVENDOR 0x02 54 - 55 - #define PCI_SLOT_INFO 0x40 /* 8 bits */ 56 - #define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7) 57 - #define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07 58 - 59 - #define MAX_SLOTS 8 60 - 61 - struct sdhci_pci_chip; 62 - struct sdhci_pci_slot; 63 - 64 - struct sdhci_pci_fixes { 65 - unsigned int quirks; 66 - unsigned int quirks2; 67 - bool allow_runtime_pm; 68 - 69 - int (*probe) (struct sdhci_pci_chip *); 70 - 71 - int (*probe_slot) (struct sdhci_pci_slot *); 72 - void (*remove_slot) (struct sdhci_pci_slot *, int); 73 - 74 - int (*suspend) (struct sdhci_pci_chip *); 75 - int (*resume) (struct sdhci_pci_chip *); 76 - }; 77 - 78 - struct sdhci_pci_slot { 79 - struct sdhci_pci_chip *chip; 80 - struct sdhci_host *host; 81 - struct sdhci_pci_data *data; 82 - 83 - int pci_bar; 84 - int rst_n_gpio; 85 - int cd_gpio; 86 - int cd_irq; 87 - 88 - void (*hw_reset)(struct sdhci_host *host); 89 - }; 90 - 91 - struct sdhci_pci_chip { 92 - struct pci_dev *pdev; 93 - 94 - unsigned int quirks; 95 - unsigned int quirks2; 96 - bool allow_runtime_pm; 97 - const struct sdhci_pci_fixes *fixes; 98 - 99 - int num_slots; /* Slots on controller */ 100 - struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */ 101 - }; 102 - 30 + #include "sdhci-pci.h" 31 + #include "sdhci-pci-o2micro.h" 103 32 104 33 /*****************************************************************************\ 105 34 * * ··· 225 296 static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = { 226 297 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 227 298 .allow_runtime_pm = true, 299 + .own_cd_for_runtime_pm = true, 228 300 }; 229 301 230 302 static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = { ··· 290 360 static const struct sdhci_pci_fixes sdhci_intel_byt_sd = { 291 361 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON, 292 362 .allow_runtime_pm = true, 363 + .own_cd_for_runtime_pm = true, 293 364 }; 294 365 295 366 /* Define Host controllers for Intel Merrifield platform */ ··· 312 381 313 382 static const struct sdhci_pci_fixes sdhci_intel_mrfl_mmc = { 314 383 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 384 + .quirks2 = SDHCI_QUIRK2_BROKEN_HS200, 315 385 .probe_slot = intel_mrfl_mmc_probe_slot, 316 386 }; 317 387 ··· 324 392 #define O2_SD_ADMA1 0xE2 325 393 #define O2_SD_ADMA2 0xE7 326 394 #define O2_SD_INF_MOD 0xF1 327 - 328 - static int o2_probe(struct sdhci_pci_chip *chip) 329 - { 330 - int ret; 331 - u8 scratch; 332 - 333 - switch (chip->pdev->device) { 334 - case PCI_DEVICE_ID_O2_8220: 335 - case PCI_DEVICE_ID_O2_8221: 336 - case PCI_DEVICE_ID_O2_8320: 337 - case PCI_DEVICE_ID_O2_8321: 338 - /* This extra setup is required due to broken ADMA. */ 339 - ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch); 340 - if (ret) 341 - return ret; 342 - scratch &= 0x7f; 343 - pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch); 344 - 345 - /* Set Multi 3 to VCC3V# */ 346 - pci_write_config_byte(chip->pdev, O2_SD_MULTI_VCC3V, 0x08); 347 - 348 - /* Disable CLK_REQ# support after media DET */ 349 - ret = pci_read_config_byte(chip->pdev, O2_SD_CLKREQ, &scratch); 350 - if (ret) 351 - return ret; 352 - scratch |= 0x20; 353 - pci_write_config_byte(chip->pdev, O2_SD_CLKREQ, scratch); 354 - 355 - /* Choose capabilities, enable SDMA. We have to write 0x01 356 - * to the capabilities register first to unlock it. 357 - */ 358 - ret = pci_read_config_byte(chip->pdev, O2_SD_CAPS, &scratch); 359 - if (ret) 360 - return ret; 361 - scratch |= 0x01; 362 - pci_write_config_byte(chip->pdev, O2_SD_CAPS, scratch); 363 - pci_write_config_byte(chip->pdev, O2_SD_CAPS, 0x73); 364 - 365 - /* Disable ADMA1/2 */ 366 - pci_write_config_byte(chip->pdev, O2_SD_ADMA1, 0x39); 367 - pci_write_config_byte(chip->pdev, O2_SD_ADMA2, 0x08); 368 - 369 - /* Disable the infinite transfer mode */ 370 - ret = pci_read_config_byte(chip->pdev, O2_SD_INF_MOD, &scratch); 371 - if (ret) 372 - return ret; 373 - scratch |= 0x08; 374 - pci_write_config_byte(chip->pdev, O2_SD_INF_MOD, scratch); 375 - 376 - /* Lock WP */ 377 - ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch); 378 - if (ret) 379 - return ret; 380 - scratch |= 0x80; 381 - pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch); 382 - } 383 - 384 - return 0; 385 - } 386 395 387 396 static int jmicron_pmos(struct sdhci_pci_chip *chip, int on) 388 397 { ··· 515 642 } 516 643 517 644 static const struct sdhci_pci_fixes sdhci_o2 = { 518 - .probe = o2_probe, 645 + .probe = sdhci_pci_o2_probe, 646 + .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 647 + .probe_slot = sdhci_pci_o2_probe_slot, 648 + .resume = sdhci_pci_o2_resume, 519 649 }; 520 650 521 651 static const struct sdhci_pci_fixes sdhci_jmicron = { ··· 931 1055 .driver_data = (kernel_ulong_t)&sdhci_o2, 932 1056 }, 933 1057 1058 + { 1059 + .vendor = PCI_VENDOR_ID_O2, 1060 + .device = PCI_DEVICE_ID_O2_FUJIN2, 1061 + .subvendor = PCI_ANY_ID, 1062 + .subdevice = PCI_ANY_ID, 1063 + .driver_data = (kernel_ulong_t)&sdhci_o2, 1064 + }, 1065 + 1066 + { 1067 + .vendor = PCI_VENDOR_ID_O2, 1068 + .device = PCI_DEVICE_ID_O2_SDS0, 1069 + .subvendor = PCI_ANY_ID, 1070 + .subdevice = PCI_ANY_ID, 1071 + .driver_data = (kernel_ulong_t)&sdhci_o2, 1072 + }, 1073 + 1074 + { 1075 + .vendor = PCI_VENDOR_ID_O2, 1076 + .device = PCI_DEVICE_ID_O2_SDS1, 1077 + .subvendor = PCI_ANY_ID, 1078 + .subdevice = PCI_ANY_ID, 1079 + .driver_data = (kernel_ulong_t)&sdhci_o2, 1080 + }, 1081 + 1082 + { 1083 + .vendor = PCI_VENDOR_ID_O2, 1084 + .device = PCI_DEVICE_ID_O2_SEABIRD0, 1085 + .subvendor = PCI_ANY_ID, 1086 + .subdevice = PCI_ANY_ID, 1087 + .driver_data = (kernel_ulong_t)&sdhci_o2, 1088 + }, 1089 + 1090 + { 1091 + .vendor = PCI_VENDOR_ID_O2, 1092 + .device = PCI_DEVICE_ID_O2_SEABIRD1, 1093 + .subvendor = PCI_ANY_ID, 1094 + .subdevice = PCI_ANY_ID, 1095 + .driver_data = (kernel_ulong_t)&sdhci_o2, 1096 + }, 1097 + 934 1098 { /* Generic SD host controller */ 935 1099 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00) 936 1100 }, ··· 1372 1456 goto remove; 1373 1457 1374 1458 sdhci_pci_add_own_cd(slot); 1459 + 1460 + /* 1461 + * Check if the chip needs a separate GPIO for card detect to wake up 1462 + * from runtime suspend. If it is not there, don't allow runtime PM. 1463 + * Note sdhci_pci_add_own_cd() sets slot->cd_gpio to -EINVAL on failure. 1464 + */ 1465 + if (chip->fixes && chip->fixes->own_cd_for_runtime_pm && 1466 + !gpio_is_valid(slot->cd_gpio)) 1467 + chip->allow_runtime_pm = false; 1375 1468 1376 1469 return slot; 1377 1470
+78
drivers/mmc/host/sdhci-pci.h
··· 1 + #ifndef __SDHCI_PCI_H 2 + #define __SDHCI_PCI_H 3 + 4 + /* 5 + * PCI device IDs 6 + */ 7 + 8 + #define PCI_DEVICE_ID_INTEL_PCH_SDIO0 0x8809 9 + #define PCI_DEVICE_ID_INTEL_PCH_SDIO1 0x880a 10 + #define PCI_DEVICE_ID_INTEL_BYT_EMMC 0x0f14 11 + #define PCI_DEVICE_ID_INTEL_BYT_SDIO 0x0f15 12 + #define PCI_DEVICE_ID_INTEL_BYT_SD 0x0f16 13 + #define PCI_DEVICE_ID_INTEL_BYT_EMMC2 0x0f50 14 + #define PCI_DEVICE_ID_INTEL_MRFL_MMC 0x1190 15 + #define PCI_DEVICE_ID_INTEL_CLV_SDIO0 0x08f9 16 + #define PCI_DEVICE_ID_INTEL_CLV_SDIO1 0x08fa 17 + #define PCI_DEVICE_ID_INTEL_CLV_SDIO2 0x08fb 18 + #define PCI_DEVICE_ID_INTEL_CLV_EMMC0 0x08e5 19 + #define PCI_DEVICE_ID_INTEL_CLV_EMMC1 0x08e6 20 + 21 + /* 22 + * PCI registers 23 + */ 24 + 25 + #define PCI_SDHCI_IFPIO 0x00 26 + #define PCI_SDHCI_IFDMA 0x01 27 + #define PCI_SDHCI_IFVENDOR 0x02 28 + 29 + #define PCI_SLOT_INFO 0x40 /* 8 bits */ 30 + #define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7) 31 + #define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07 32 + 33 + #define MAX_SLOTS 8 34 + 35 + struct sdhci_pci_chip; 36 + struct sdhci_pci_slot; 37 + 38 + struct sdhci_pci_fixes { 39 + unsigned int quirks; 40 + unsigned int quirks2; 41 + bool allow_runtime_pm; 42 + bool own_cd_for_runtime_pm; 43 + 44 + int (*probe) (struct sdhci_pci_chip *); 45 + 46 + int (*probe_slot) (struct sdhci_pci_slot *); 47 + void (*remove_slot) (struct sdhci_pci_slot *, int); 48 + 49 + int (*suspend) (struct sdhci_pci_chip *); 50 + int (*resume) (struct sdhci_pci_chip *); 51 + }; 52 + 53 + struct sdhci_pci_slot { 54 + struct sdhci_pci_chip *chip; 55 + struct sdhci_host *host; 56 + struct sdhci_pci_data *data; 57 + 58 + int pci_bar; 59 + int rst_n_gpio; 60 + int cd_gpio; 61 + int cd_irq; 62 + 63 + void (*hw_reset)(struct sdhci_host *host); 64 + }; 65 + 66 + struct sdhci_pci_chip { 67 + struct pci_dev *pdev; 68 + 69 + unsigned int quirks; 70 + unsigned int quirks2; 71 + bool allow_runtime_pm; 72 + const struct sdhci_pci_fixes *fixes; 73 + 74 + int num_slots; /* Slots on controller */ 75 + struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */ 76 + }; 77 + 78 + #endif /* __SDHCI_PCI_H */
+4 -2
drivers/mmc/host/sdhci-pltfm.c
··· 237 237 EXPORT_SYMBOL_GPL(sdhci_pltfm_unregister); 238 238 239 239 #ifdef CONFIG_PM 240 - static int sdhci_pltfm_suspend(struct device *dev) 240 + int sdhci_pltfm_suspend(struct device *dev) 241 241 { 242 242 struct sdhci_host *host = dev_get_drvdata(dev); 243 243 244 244 return sdhci_suspend_host(host); 245 245 } 246 + EXPORT_SYMBOL_GPL(sdhci_pltfm_suspend); 246 247 247 - static int sdhci_pltfm_resume(struct device *dev) 248 + int sdhci_pltfm_resume(struct device *dev) 248 249 { 249 250 struct sdhci_host *host = dev_get_drvdata(dev); 250 251 251 252 return sdhci_resume_host(host); 252 253 } 254 + EXPORT_SYMBOL_GPL(sdhci_pltfm_resume); 253 255 254 256 const struct dev_pm_ops sdhci_pltfm_pmops = { 255 257 .suspend = sdhci_pltfm_suspend,
+2
drivers/mmc/host/sdhci-pltfm.h
··· 111 111 } 112 112 113 113 #ifdef CONFIG_PM 114 + extern int sdhci_pltfm_suspend(struct device *dev); 115 + extern int sdhci_pltfm_resume(struct device *dev); 114 116 extern const struct dev_pm_ops sdhci_pltfm_pmops; 115 117 #define SDHCI_PLTFM_PMOPS (&sdhci_pltfm_pmops) 116 118 #else
+1
drivers/mmc/host/sdhci-tegra.c
··· 198 198 }; 199 199 200 200 static const struct of_device_id sdhci_tegra_dt_match[] = { 201 + { .compatible = "nvidia,tegra124-sdhci", .data = &soc_data_tegra114 }, 201 202 { .compatible = "nvidia,tegra114-sdhci", .data = &soc_data_tegra114 }, 202 203 { .compatible = "nvidia,tegra30-sdhci", .data = &soc_data_tegra30 }, 203 204 { .compatible = "nvidia,tegra20-sdhci", .data = &soc_data_tegra20 },
+28 -16
drivers/mmc/host/sdhci.c
··· 898 898 u16 mode; 899 899 struct mmc_data *data = cmd->data; 900 900 901 - if (data == NULL) 901 + if (data == NULL) { 902 + /* clear Auto CMD settings for no data CMDs */ 903 + mode = sdhci_readw(host, SDHCI_TRANSFER_MODE); 904 + sdhci_writew(host, mode & ~(SDHCI_TRNS_AUTO_CMD12 | 905 + SDHCI_TRNS_AUTO_CMD23), SDHCI_TRANSFER_MODE); 902 906 return; 907 + } 903 908 904 909 WARN_ON(!host->data); 905 910 ··· 1018 1013 mdelay(1); 1019 1014 } 1020 1015 1021 - mod_timer(&host->timer, jiffies + 10 * HZ); 1016 + timeout = jiffies; 1017 + if (!cmd->data && cmd->cmd_timeout_ms > 9000) 1018 + timeout += DIV_ROUND_UP(cmd->cmd_timeout_ms, 1000) * HZ + HZ; 1019 + else 1020 + timeout += 10 * HZ; 1021 + mod_timer(&host->timer, timeout); 1022 1022 1023 1023 host->cmd = cmd; 1024 1024 ··· 1401 1391 mmc->card->type == MMC_TYPE_MMC ? 1402 1392 MMC_SEND_TUNING_BLOCK_HS200 : 1403 1393 MMC_SEND_TUNING_BLOCK; 1394 + 1395 + /* Here we need to set the host->mrq to NULL, 1396 + * in case the pending finish_tasklet 1397 + * finishes it incorrectly. 1398 + */ 1399 + host->mrq = NULL; 1400 + 1404 1401 spin_unlock_irqrestore(&host->lock, flags); 1405 1402 sdhci_execute_tuning(mmc, tuning_opcode); 1406 1403 spin_lock_irqsave(&host->lock, flags); ··· 1862 1845 unsigned long timeout; 1863 1846 int err = 0; 1864 1847 bool requires_tuning_nonuhs = false; 1848 + unsigned long flags; 1865 1849 1866 1850 host = mmc_priv(mmc); 1867 1851 1868 1852 sdhci_runtime_pm_get(host); 1869 - disable_irq(host->irq); 1870 - spin_lock(&host->lock); 1853 + spin_lock_irqsave(&host->lock, flags); 1871 1854 1872 1855 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1873 1856 ··· 1887 1870 requires_tuning_nonuhs) 1888 1871 ctrl |= SDHCI_CTRL_EXEC_TUNING; 1889 1872 else { 1890 - spin_unlock(&host->lock); 1891 - enable_irq(host->irq); 1873 + spin_unlock_irqrestore(&host->lock, flags); 1892 1874 sdhci_runtime_pm_put(host); 1893 1875 return 0; 1894 1876 } 1895 1877 1896 1878 if (host->ops->platform_execute_tuning) { 1897 - spin_unlock(&host->lock); 1898 - enable_irq(host->irq); 1879 + spin_unlock_irqrestore(&host->lock, flags); 1899 1880 err = host->ops->platform_execute_tuning(host, opcode); 1900 1881 sdhci_runtime_pm_put(host); 1901 1882 return err; ··· 1966 1951 host->cmd = NULL; 1967 1952 host->mrq = NULL; 1968 1953 1969 - spin_unlock(&host->lock); 1970 - enable_irq(host->irq); 1971 - 1954 + spin_unlock_irqrestore(&host->lock, flags); 1972 1955 /* Wait for Buffer Read Ready interrupt */ 1973 1956 wait_event_interruptible_timeout(host->buf_ready_int, 1974 1957 (host->tuning_done == 1), 1975 1958 msecs_to_jiffies(50)); 1976 - disable_irq(host->irq); 1977 - spin_lock(&host->lock); 1959 + spin_lock_irqsave(&host->lock, flags); 1978 1960 1979 1961 if (!host->tuning_done) { 1980 1962 pr_info(DRIVER_NAME ": Timeout waiting for " ··· 2046 2034 err = 0; 2047 2035 2048 2036 sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier); 2049 - spin_unlock(&host->lock); 2050 - enable_irq(host->irq); 2037 + spin_unlock_irqrestore(&host->lock, flags); 2051 2038 sdhci_runtime_pm_put(host); 2052 2039 2053 2040 return err; ··· 3015 3004 /* SD3.0: SDR104 is supported so (for eMMC) the caps2 3016 3005 * field can be promoted to support HS200. 3017 3006 */ 3018 - mmc->caps2 |= MMC_CAP2_HS200; 3007 + if (!(host->quirks2 & SDHCI_QUIRK2_BROKEN_HS200)) 3008 + mmc->caps2 |= MMC_CAP2_HS200; 3019 3009 } else if (caps[1] & SDHCI_SUPPORT_SDR50) 3020 3010 mmc->caps |= MMC_CAP_UHS_SDR50; 3021 3011
+51 -49
drivers/mmc/host/sh_mmcif.c
··· 381 381 desc, cookie); 382 382 } 383 383 384 - static void sh_mmcif_request_dma(struct sh_mmcif_host *host, 385 - struct sh_mmcif_plat_data *pdata) 384 + static struct dma_chan * 385 + sh_mmcif_request_dma_one(struct sh_mmcif_host *host, 386 + struct sh_mmcif_plat_data *pdata, 387 + enum dma_transfer_direction direction) 386 388 { 387 - struct resource *res = platform_get_resource(host->pd, IORESOURCE_MEM, 0); 388 389 struct dma_slave_config cfg; 390 + struct dma_chan *chan; 391 + unsigned int slave_id; 392 + struct resource *res; 389 393 dma_cap_mask_t mask; 390 394 int ret; 391 395 396 + dma_cap_zero(mask); 397 + dma_cap_set(DMA_SLAVE, mask); 398 + 399 + if (pdata) 400 + slave_id = direction == DMA_MEM_TO_DEV 401 + ? pdata->slave_id_tx : pdata->slave_id_rx; 402 + else 403 + slave_id = 0; 404 + 405 + chan = dma_request_slave_channel_compat(mask, shdma_chan_filter, 406 + (void *)(unsigned long)slave_id, &host->pd->dev, 407 + direction == DMA_MEM_TO_DEV ? "tx" : "rx"); 408 + 409 + dev_dbg(&host->pd->dev, "%s: %s: got channel %p\n", __func__, 410 + direction == DMA_MEM_TO_DEV ? "TX" : "RX", chan); 411 + 412 + if (!chan) 413 + return NULL; 414 + 415 + res = platform_get_resource(host->pd, IORESOURCE_MEM, 0); 416 + 417 + /* In the OF case the driver will get the slave ID from the DT */ 418 + cfg.slave_id = slave_id; 419 + cfg.direction = direction; 420 + cfg.dst_addr = res->start + MMCIF_CE_DATA; 421 + cfg.src_addr = 0; 422 + ret = dmaengine_slave_config(chan, &cfg); 423 + if (ret < 0) { 424 + dma_release_channel(chan); 425 + return NULL; 426 + } 427 + 428 + return chan; 429 + } 430 + 431 + static void sh_mmcif_request_dma(struct sh_mmcif_host *host, 432 + struct sh_mmcif_plat_data *pdata) 433 + { 392 434 host->dma_active = false; 393 435 394 436 if (pdata) { ··· 441 399 } 442 400 443 401 /* We can only either use DMA for both Tx and Rx or not use it at all */ 444 - dma_cap_zero(mask); 445 - dma_cap_set(DMA_SLAVE, mask); 446 - 447 - host->chan_tx = dma_request_slave_channel_compat(mask, shdma_chan_filter, 448 - pdata ? (void *)pdata->slave_id_tx : NULL, 449 - &host->pd->dev, "tx"); 450 - dev_dbg(&host->pd->dev, "%s: TX: got channel %p\n", __func__, 451 - host->chan_tx); 452 - 402 + host->chan_tx = sh_mmcif_request_dma_one(host, pdata, DMA_MEM_TO_DEV); 453 403 if (!host->chan_tx) 454 404 return; 455 405 456 - /* In the OF case the driver will get the slave ID from the DT */ 457 - if (pdata) 458 - cfg.slave_id = pdata->slave_id_tx; 459 - cfg.direction = DMA_MEM_TO_DEV; 460 - cfg.dst_addr = res->start + MMCIF_CE_DATA; 461 - cfg.src_addr = 0; 462 - ret = dmaengine_slave_config(host->chan_tx, &cfg); 463 - if (ret < 0) 464 - goto ecfgtx; 465 - 466 - host->chan_rx = dma_request_slave_channel_compat(mask, shdma_chan_filter, 467 - pdata ? (void *)pdata->slave_id_rx : NULL, 468 - &host->pd->dev, "rx"); 469 - dev_dbg(&host->pd->dev, "%s: RX: got channel %p\n", __func__, 470 - host->chan_rx); 471 - 472 - if (!host->chan_rx) 473 - goto erqrx; 474 - 475 - if (pdata) 476 - cfg.slave_id = pdata->slave_id_rx; 477 - cfg.direction = DMA_DEV_TO_MEM; 478 - cfg.dst_addr = 0; 479 - cfg.src_addr = res->start + MMCIF_CE_DATA; 480 - ret = dmaengine_slave_config(host->chan_rx, &cfg); 481 - if (ret < 0) 482 - goto ecfgrx; 483 - 484 - return; 485 - 486 - ecfgrx: 487 - dma_release_channel(host->chan_rx); 488 - host->chan_rx = NULL; 489 - erqrx: 490 - ecfgtx: 491 - dma_release_channel(host->chan_tx); 492 - host->chan_tx = NULL; 406 + host->chan_rx = sh_mmcif_request_dma_one(host, pdata, DMA_DEV_TO_MEM); 407 + if (!host->chan_rx) { 408 + dma_release_channel(host->chan_tx); 409 + host->chan_tx = NULL; 410 + } 493 411 } 494 412 495 413 static void sh_mmcif_release_dma(struct sh_mmcif_host *host)
+21 -2
drivers/mmc/host/sh_mobile_sdhi.c
··· 33 33 34 34 #include "tmio_mmc.h" 35 35 36 + #define EXT_ACC 0xe4 37 + 36 38 struct sh_mobile_sdhi_of_data { 37 39 unsigned long tmio_flags; 38 40 }; ··· 56 54 struct mmc_host *mmc = platform_get_drvdata(pdev); 57 55 struct tmio_mmc_host *host = mmc_priv(mmc); 58 56 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data); 59 - int ret = clk_enable(priv->clk); 57 + int ret = clk_prepare_enable(priv->clk); 60 58 if (ret < 0) 61 59 return ret; 62 60 ··· 69 67 struct mmc_host *mmc = platform_get_drvdata(pdev); 70 68 struct tmio_mmc_host *host = mmc_priv(mmc); 71 69 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data); 72 - clk_disable(priv->clk); 70 + clk_disable_unprepare(priv->clk); 73 71 } 74 72 75 73 static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host) ··· 135 133 struct tmio_mmc_data *mmc_data; 136 134 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; 137 135 struct tmio_mmc_host *host; 136 + struct resource *res; 138 137 int irq, ret, i = 0; 139 138 bool multiplexed_isr = true; 140 139 struct tmio_mmc_dma *dma_priv; 140 + u16 ver; 141 + 142 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 143 + if (!res) 144 + return -EINVAL; 141 145 142 146 priv = devm_kzalloc(&pdev->dev, sizeof(struct sh_mobile_sdhi), GFP_KERNEL); 143 147 if (priv == NULL) { ··· 214 206 mmc_data->flags |= of_data->tmio_flags; 215 207 } 216 208 209 + /* SD control register space size is 0x100, 0x200 for bus_shift=1 */ 210 + mmc_data->bus_shift = resource_size(res) >> 9; 211 + 217 212 ret = tmio_mmc_host_probe(&host, pdev, mmc_data); 218 213 if (ret < 0) 219 214 goto eprobe; 215 + 216 + /* 217 + * FIXME: 218 + * this Workaround can be more clever method 219 + */ 220 + ver = sd_ctrl_read16(host, CTL_VERSION); 221 + if (ver == 0xCB0D) 222 + sd_ctrl_write16(host, EXT_ACC, 1); 220 223 221 224 /* 222 225 * Allow one or more specific (named) ISRs or
+9
drivers/mmc/host/tmio_mmc.c
··· 62 62 const struct mfd_cell *cell = mfd_get_cell(pdev); 63 63 struct tmio_mmc_data *pdata; 64 64 struct tmio_mmc_host *host; 65 + struct resource *res; 65 66 int ret = -EINVAL, irq; 66 67 67 68 if (pdev->num_resources != 2) ··· 84 83 if (ret) 85 84 goto out; 86 85 } 86 + 87 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 88 + if (!res) 89 + return -EINVAL; 90 + 91 + /* SD control register space size is 0x200, 0x400 for bus_shift=1 */ 92 + pdata->bus_shift = resource_size(res) >> 10; 93 + pdata->flags |= TMIO_MMC_HAVE_HIGH_REG; 87 94 88 95 ret = tmio_mmc_host_probe(&host, pdev, pdata); 89 96 if (ret)
+8 -9
drivers/mmc/host/tmio_mmc.h
··· 58 58 59 59 struct tmio_mmc_host { 60 60 void __iomem *ctl; 61 - unsigned long bus_shift; 62 61 struct mmc_command *cmd; 63 62 struct mmc_request *mrq; 64 63 struct mmc_data *data; ··· 175 176 176 177 static inline u16 sd_ctrl_read16(struct tmio_mmc_host *host, int addr) 177 178 { 178 - return readw(host->ctl + (addr << host->bus_shift)); 179 + return readw(host->ctl + (addr << host->pdata->bus_shift)); 179 180 } 180 181 181 182 static inline void sd_ctrl_read16_rep(struct tmio_mmc_host *host, int addr, 182 183 u16 *buf, int count) 183 184 { 184 - readsw(host->ctl + (addr << host->bus_shift), buf, count); 185 + readsw(host->ctl + (addr << host->pdata->bus_shift), buf, count); 185 186 } 186 187 187 188 static inline u32 sd_ctrl_read32(struct tmio_mmc_host *host, int addr) 188 189 { 189 - return readw(host->ctl + (addr << host->bus_shift)) | 190 - readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16; 190 + return readw(host->ctl + (addr << host->pdata->bus_shift)) | 191 + readw(host->ctl + ((addr + 2) << host->pdata->bus_shift)) << 16; 191 192 } 192 193 193 194 static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr, u16 val) ··· 197 198 */ 198 199 if (host->pdata->write16_hook && host->pdata->write16_hook(host, addr)) 199 200 return; 200 - writew(val, host->ctl + (addr << host->bus_shift)); 201 + writew(val, host->ctl + (addr << host->pdata->bus_shift)); 201 202 } 202 203 203 204 static inline void sd_ctrl_write16_rep(struct tmio_mmc_host *host, int addr, 204 205 u16 *buf, int count) 205 206 { 206 - writesw(host->ctl + (addr << host->bus_shift), buf, count); 207 + writesw(host->ctl + (addr << host->pdata->bus_shift), buf, count); 207 208 } 208 209 209 210 static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr, u32 val) 210 211 { 211 - writew(val, host->ctl + (addr << host->bus_shift)); 212 - writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift)); 212 + writew(val, host->ctl + (addr << host->pdata->bus_shift)); 213 + writew(val >> 16, host->ctl + ((addr + 2) << host->pdata->bus_shift)); 213 214 } 214 215 215 216
+1 -1
drivers/mmc/host/tmio_mmc_dma.c
··· 293 293 if (pdata->dma->chan_priv_tx) 294 294 cfg.slave_id = pdata->dma->slave_id_tx; 295 295 cfg.direction = DMA_MEM_TO_DEV; 296 - cfg.dst_addr = res->start + (CTL_SD_DATA_PORT << host->bus_shift); 296 + cfg.dst_addr = res->start + (CTL_SD_DATA_PORT << host->pdata->bus_shift); 297 297 cfg.src_addr = 0; 298 298 ret = dmaengine_slave_config(host->chan_tx, &cfg); 299 299 if (ret < 0)
+20 -18
drivers/mmc/host/tmio_mmc_pio.c
··· 161 161 162 162 static void tmio_mmc_clk_stop(struct tmio_mmc_host *host) 163 163 { 164 - struct resource *res = platform_get_resource(host->pdev, IORESOURCE_MEM, 0); 165 - 166 164 /* implicit BUG_ON(!res) */ 167 - if (resource_size(res) > 0x100) { 165 + if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) { 168 166 sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0000); 169 167 msleep(10); 170 168 } ··· 174 176 175 177 static void tmio_mmc_clk_start(struct tmio_mmc_host *host) 176 178 { 177 - struct resource *res = platform_get_resource(host->pdev, IORESOURCE_MEM, 0); 178 - 179 179 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, 0x0100 | 180 180 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); 181 181 msleep(10); 182 182 183 183 /* implicit BUG_ON(!res) */ 184 - if (resource_size(res) > 0x100) { 184 + if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) { 185 185 sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0100); 186 186 msleep(10); 187 187 } ··· 187 191 188 192 static void tmio_mmc_reset(struct tmio_mmc_host *host) 189 193 { 190 - struct resource *res = platform_get_resource(host->pdev, IORESOURCE_MEM, 0); 191 - 192 194 /* FIXME - should we set stop clock reg here */ 193 195 sd_ctrl_write16(host, CTL_RESET_SD, 0x0000); 194 196 /* implicit BUG_ON(!res) */ 195 - if (resource_size(res) > 0x100) 197 + if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) 196 198 sd_ctrl_write16(host, CTL_RESET_SDIO, 0x0000); 197 199 msleep(10); 198 200 sd_ctrl_write16(host, CTL_RESET_SD, 0x0001); 199 - if (resource_size(res) > 0x100) 201 + if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) 200 202 sd_ctrl_write16(host, CTL_RESET_SDIO, 0x0001); 201 203 msleep(10); 202 204 } ··· 938 944 .enable_sdio_irq = tmio_mmc_enable_sdio_irq, 939 945 }; 940 946 941 - static void tmio_mmc_init_ocr(struct tmio_mmc_host *host) 947 + static int tmio_mmc_init_ocr(struct tmio_mmc_host *host) 942 948 { 943 949 struct tmio_mmc_data *pdata = host->pdata; 944 950 struct mmc_host *mmc = host->mmc; 945 951 946 952 mmc_regulator_get_supply(mmc); 947 953 954 + /* use ocr_mask if no regulator */ 948 955 if (!mmc->ocr_avail) 949 - mmc->ocr_avail = pdata->ocr_mask ? : MMC_VDD_32_33 | MMC_VDD_33_34; 950 - else if (pdata->ocr_mask) 951 - dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n"); 956 + mmc->ocr_avail = pdata->ocr_mask; 957 + 958 + /* 959 + * try again. 960 + * There is possibility that regulator has not been probed 961 + */ 962 + if (!mmc->ocr_avail) 963 + return -EPROBE_DEFER; 964 + 965 + return 0; 952 966 } 953 967 954 968 static void tmio_mmc_of_parse(struct platform_device *pdev, ··· 1007 1005 _host->set_pwr = pdata->set_pwr; 1008 1006 _host->set_clk_div = pdata->set_clk_div; 1009 1007 1010 - /* SD control register space size is 0x200, 0x400 for bus_shift=1 */ 1011 - _host->bus_shift = resource_size(res_ctl) >> 10; 1008 + ret = tmio_mmc_init_ocr(_host); 1009 + if (ret < 0) 1010 + goto host_free; 1012 1011 1013 1012 _host->ctl = ioremap(res_ctl->start, resource_size(res_ctl)); 1014 1013 if (!_host->ctl) { ··· 1019 1016 1020 1017 mmc->ops = &tmio_mmc_ops; 1021 1018 mmc->caps |= MMC_CAP_4_BIT_DATA | pdata->capabilities; 1022 - mmc->caps2 = pdata->capabilities2; 1019 + mmc->caps2 |= pdata->capabilities2; 1023 1020 mmc->max_segs = 32; 1024 1021 mmc->max_blk_size = 512; 1025 1022 mmc->max_blk_count = (PAGE_CACHE_SIZE / mmc->max_blk_size) * 1026 1023 mmc->max_segs; 1027 1024 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; 1028 1025 mmc->max_seg_size = mmc->max_req_size; 1029 - tmio_mmc_init_ocr(_host); 1030 1026 1031 1027 _host->native_hotplug = !(pdata->flags & TMIO_MMC_USE_GPIO_CD || 1032 1028 mmc->caps & MMC_CAP_NEEDS_POLL ||
+8
include/linux/mfd/tmio.h
··· 76 76 */ 77 77 #define TMIO_MMC_USE_GPIO_CD (1 << 5) 78 78 79 + /* 80 + * Some controllers doesn't have over 0x100 register. 81 + * it is used to checking accessibility of 82 + * CTL_SD_CARD_CLK_CTL / CTL_CLK_AND_WAIT_CTL 83 + */ 84 + #define TMIO_MMC_HAVE_HIGH_REG (1 << 6) 85 + 79 86 int tmio_core_mmc_enable(void __iomem *cnf, int shift, unsigned long base); 80 87 int tmio_core_mmc_resume(void __iomem *cnf, int shift, unsigned long base); 81 88 void tmio_core_mmc_pwr(void __iomem *cnf, int shift, int state); ··· 109 102 unsigned long capabilities; 110 103 unsigned long capabilities2; 111 104 unsigned long flags; 105 + unsigned long bus_shift; 112 106 u32 ocr_mask; /* available voltages */ 113 107 struct tmio_mmc_dma *dma; 114 108 struct device *dev;
+7 -1
include/linux/mmc/card.h
··· 271 271 #define MMC_QUIRK_INAND_CMD38 (1<<6) /* iNAND devices have broken CMD38 */ 272 272 #define MMC_QUIRK_BLK_NO_CMD23 (1<<7) /* Avoid CMD23 for regular multiblock */ 273 273 #define MMC_QUIRK_BROKEN_BYTE_MODE_512 (1<<8) /* Avoid sending 512 bytes in */ 274 + /* byte mode */ 274 275 #define MMC_QUIRK_LONG_READ_TIME (1<<9) /* Data read time > CSD says */ 275 276 #define MMC_QUIRK_SEC_ERASE_TRIM_BROKEN (1<<10) /* Skip secure for erase/trim */ 276 - /* byte mode */ 277 + #define MMC_QUIRK_BROKEN_IRQ_POLLING (1<<11) /* Polling SDIO_CCCR_INTx could create a fake interrupt */ 277 278 278 279 unsigned int erase_size; /* erase size in sectors */ 279 280 unsigned int erase_shift; /* if erase unit is power 2 */ ··· 504 503 static inline int mmc_card_long_read_time(const struct mmc_card *c) 505 504 { 506 505 return c->quirks & MMC_QUIRK_LONG_READ_TIME; 506 + } 507 + 508 + static inline int mmc_card_broken_irq_polling(const struct mmc_card *c) 509 + { 510 + return c->quirks & MMC_QUIRK_BROKEN_IRQ_POLLING; 507 511 } 508 512 509 513 #define mmc_card_name(c) ((c)->cid.prod_name)
+2
include/linux/mmc/sdhci.h
··· 98 98 #define SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON (1<<4) 99 99 /* Controller has a non-standard host control register */ 100 100 #define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5) 101 + /* Controller does not support HS200 */ 102 + #define SDHCI_QUIRK2_BROKEN_HS200 (1<<6) 101 103 102 104 int irq; /* Device IRQ */ 103 105 void __iomem *ioaddr; /* Mapped address */
+1
include/linux/mmc/tmio.h
··· 33 33 #define CTL_SDIO_IRQ_MASK 0x38 34 34 #define CTL_DMA_ENABLE 0xd8 35 35 #define CTL_RESET_SD 0xe0 36 + #define CTL_VERSION 0xe2 36 37 #define CTL_SDIO_REGS 0x100 37 38 #define CTL_CLK_AND_WAIT_CTL 0x138 38 39 #define CTL_RESET_SDIO 0x1e0