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

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

Pull MMC updates from Chris Ball:
"Core:
- Add DT properties for card detection (broken-cd, cd-gpios,
non-removable)
- Don't poll non-removable devices
- Fixup/rework eMMC sleep mode/"power off notify" feature
- Support eMMC background operations (BKOPS). To set the one-time
programmable fuse that enables bkops on an eMMC that doesn't
already have it set, you can use the "mmc bkops enable" command in:

git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc-utils.git

Drivers:
- atmel-mci, dw_mmc, pxa-mci, dove, s3c, spear: Add device tree
support
- bfin_sdh: Add support for the controller in bf60x
- dw_mmc: Support Samsung Exynos SoCs
- eSDHC: Add ADMA support
- sdhci: Support testing a cd-gpio (from slot-gpio) instead of
presence bit
- sdhci-pltfm: Support broken-cd DT property
- tegra: Convert to only supporting DT (mach-tegra has gone DT-only)"

* tag 'mmc-merge-for-3.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc: (67 commits)
mmc: core: Fixup broken suspend and eMMC4.5 power off notify
mmc: sdhci-spear: Add clk_{un}prepare() support
mmc: sdhci-spear: add device tree bindings
mmc: sdhci-s3c: Add clk_(enable/disable) in runtime suspend/resume
mmc: core: Replace MMC_CAP2_BROKEN_VOLTAGE with test for fixed regulator
mmc: sdhci-pxav3: Use sdhci_get_of_property for parsing DT quirks
mmc: dt: Support "broken-cd" property in sdhci-pltfm
mmc: sdhci-s3c: fix the wrong number of max bus clocks
mmc: sh-mmcif: avoid oops on spurious interrupts
mmc: sh-mmcif: properly handle MMC_WRITE_MULTIPLE_BLOCK completion IRQ
mmc: sdhci-s3c: Fix crash on module insertion for second time
mmc: sdhci-s3c: Enable only required bus clock
mmc: Revert "mmc: dw_mmc: Add check for IDMAC configuration"
mmc: mxcmmc: fix bug that may block a data transfer forever
mmc: omap_hsmmc: Pass on the suspend failure to the PM core
mmc: atmel-mci: AP700x PDC is not connected to MCI
mmc: atmel-mci: DMA can be used with other controllers
mmc: mmci: use clk_prepare_enable and clk_disable_unprepare
mmc: sdhci-s3c: Add device tree support
mmc: dw_mmc: add support for exynos specific implementation of dw-mshc
...

+2277 -809
+68
Documentation/devicetree/bindings/mmc/atmel-hsmci.txt
··· 1 + * Atmel High Speed MultiMedia Card Interface 2 + 3 + This controller on atmel products provides an interface for MMC, SD and SDIO 4 + types of memory cards. 5 + 6 + This file documents differences between the core properties described 7 + by mmc.txt and the properties used by the atmel-mci driver. 8 + 9 + 1) MCI node 10 + 11 + Required properties: 12 + - compatible: should be "atmel,hsmci" 13 + - #address-cells: should be one. The cell is the slot id. 14 + - #size-cells: should be zero. 15 + - at least one slot node 16 + 17 + The node contains child nodes for each slot that the platform uses 18 + 19 + Example MCI node: 20 + 21 + mmc0: mmc@f0008000 { 22 + compatible = "atmel,hsmci"; 23 + reg = <0xf0008000 0x600>; 24 + interrupts = <12 4>; 25 + #address-cells = <1>; 26 + #size-cells = <0>; 27 + 28 + [ child node definitions...] 29 + }; 30 + 31 + 2) slot nodes 32 + 33 + Required properties: 34 + - reg: should contain the slot id. 35 + - bus-width: number of data lines connected to the controller 36 + 37 + Optional properties: 38 + - cd-gpios: specify GPIOs for card detection 39 + - cd-inverted: invert the value of external card detect gpio line 40 + - wp-gpios: specify GPIOs for write protection 41 + 42 + Example slot node: 43 + 44 + slot@0 { 45 + reg = <0>; 46 + bus-width = <4>; 47 + cd-gpios = <&pioD 15 0> 48 + cd-inverted; 49 + }; 50 + 51 + Example full MCI node: 52 + mmc0: mmc@f0008000 { 53 + compatible = "atmel,hsmci"; 54 + reg = <0xf0008000 0x600>; 55 + interrupts = <12 4>; 56 + #address-cells = <1>; 57 + #size-cells = <0>; 58 + slot@0 { 59 + reg = <0>; 60 + bus-width = <4>; 61 + cd-gpios = <&pioD 15 0> 62 + cd-inverted; 63 + }; 64 + slot@1 { 65 + reg = <1>; 66 + bus-width = <4>; 67 + }; 68 + };
+87
Documentation/devicetree/bindings/mmc/exynos-dw-mshc.txt
··· 1 + * Samsung Exynos specific extensions to the Synopsis Designware Mobile 2 + Storage Host Controller 3 + 4 + The Synopsis designware mobile storage host controller is used to interface 5 + a SoC with storage medium such as eMMC or SD/MMC cards. This file documents 6 + differences between the core Synopsis dw mshc controller properties described 7 + by synposis-dw-mshc.txt and the properties used by the Samsung Exynos specific 8 + extensions to the Synopsis Designware Mobile Storage Host Controller. 9 + 10 + Required Properties: 11 + 12 + * compatible: should be 13 + - "samsung,exynos4210-dw-mshc": for controllers with Samsung Exynos4210 14 + specific extentions. 15 + - "samsung,exynos4412-dw-mshc": for controllers with Samsung Exynos4412 16 + specific extentions. 17 + - "samsung,exynos5250-dw-mshc": for controllers with Samsung Exynos5250 18 + specific extentions. 19 + 20 + * samsung,dw-mshc-ciu-div: Specifies the divider value for the card interface 21 + unit (ciu) clock. This property is applicable only for Exynos5 SoC's and 22 + ignored for Exynos4 SoC's. The valid range of divider value is 0 to 7. 23 + 24 + * samsung,dw-mshc-sdr-timing: Specifies the value of CIU clock phase shift value 25 + in transmit mode and CIU clock phase shift value in receive mode for single 26 + data rate mode operation. Refer notes below for the order of the cells and the 27 + valid values. 28 + 29 + * samsung,dw-mshc-ddr-timing: Specifies the value of CUI clock phase shift value 30 + in transmit mode and CIU clock phase shift value in receive mode for double 31 + data rate mode operation. Refer notes below for the order of the cells and the 32 + valid values. 33 + 34 + Notes for the sdr-timing and ddr-timing values: 35 + 36 + The order of the cells should be 37 + - First Cell: CIU clock phase shift value for tx mode. 38 + - Second Cell: CIU clock phase shift value for rx mode. 39 + 40 + Valid values for SDR and DDR CIU clock timing for Exynos5250: 41 + - valid value for tx phase shift and rx phase shift is 0 to 7. 42 + - when CIU clock divider value is set to 3, all possible 8 phase shift 43 + values can be used. 44 + - if CIU clock divider value is 0 (that is divide by 1), both tx and rx 45 + phase shift clocks should be 0. 46 + 47 + Required properties for a slot: 48 + 49 + * gpios: specifies a list of gpios used for command, clock and data bus. The 50 + first gpio is the command line and the second gpio is the clock line. The 51 + rest of the gpios (depending on the bus-width property) are the data lines in 52 + no particular order. The format of the gpio specifier depends on the gpio 53 + controller. 54 + 55 + Example: 56 + 57 + The MSHC controller node can be split into two portions, SoC specific and 58 + board specific portions as listed below. 59 + 60 + dwmmc0@12200000 { 61 + compatible = "samsung,exynos5250-dw-mshc"; 62 + reg = <0x12200000 0x1000>; 63 + interrupts = <0 75 0>; 64 + #address-cells = <1>; 65 + #size-cells = <0>; 66 + }; 67 + 68 + dwmmc0@12200000 { 69 + num-slots = <1>; 70 + supports-highspeed; 71 + broken-cd; 72 + fifo-depth = <0x80>; 73 + card-detect-delay = <200>; 74 + samsung,dw-mshc-ciu-div = <3>; 75 + samsung,dw-mshc-sdr-timing = <2 3>; 76 + samsung,dw-mshc-ddr-timing = <1 2>; 77 + 78 + slot@0 { 79 + reg = <0>; 80 + bus-width = <8>; 81 + gpios = <&gpc0 0 2 0 3>, <&gpc0 1 2 0 3>, 82 + <&gpc1 0 2 3 3>, <&gpc1 1 2 3 3>, 83 + <&gpc1 2 2 3 3>, <&gpc1 3 2 3 3>, 84 + <&gpc0 3 2 3 3>, <&gpc0 4 2 3 3>, 85 + <&gpc0 5 2 3 3>, <&gpc0 6 2 3 3>; 86 + }; 87 + };
+7 -2
Documentation/devicetree/bindings/mmc/mmc.txt
··· 9 9 Required properties: 10 10 - bus-width: Number of data lines, can be <1>, <4>, or <8> 11 11 12 + Card detection: 13 + If no property below is supplied, standard SDHCI card detect is used. 14 + Only one of the properties in this section should be supplied: 15 + - broken-cd: There is no card detection available; polling must be used. 16 + - cd-gpios: Specify GPIOs for card detection, see gpio binding 17 + - non-removable: non-removable slot (like eMMC); assume always present. 18 + 12 19 Optional properties: 13 - - cd-gpios: Specify GPIOs for card detection, see gpio binding 14 20 - wp-gpios: Specify GPIOs for write protection, see gpio binding 15 21 - cd-inverted: when present, polarity on the cd gpio line is inverted 16 22 - wp-inverted: when present, polarity on the wp gpio line is inverted 17 - - non-removable: non-removable slot (like eMMC) 18 23 - max-frequency: maximum operating clock frequency 19 24 20 25 Example:
+25
Documentation/devicetree/bindings/mmc/pxa-mmc.txt
··· 1 + * PXA MMC drivers 2 + 3 + Driver bindings for the PXA MCI (MMC/SDIO) interfaces 4 + 5 + Required properties: 6 + - compatible: Should be "marvell,pxa-mmc". 7 + - vmmc-supply: A regulator for VMMC 8 + 9 + Optional properties: 10 + - marvell,detect-delay-ms: sets the detection delay timeout in ms. 11 + - marvell,gpio-power: GPIO spec for the card power enable pin 12 + 13 + This file documents differences between the core properties in mmc.txt 14 + and the properties used by the pxa-mmc driver. 15 + 16 + Examples: 17 + 18 + mmc0: mmc@41100000 { 19 + compatible = "marvell,pxa-mmc"; 20 + reg = <0x41100000 0x1000>; 21 + interrupts = <23>; 22 + cd-gpios = <&gpio 23 0>; 23 + wp-gpios = <&gpio 24 0>; 24 + }; 25 +
+53
Documentation/devicetree/bindings/mmc/samsung-sdhci.txt
··· 1 + * Samsung's SDHCI Controller device tree bindings 2 + 3 + Samsung's SDHCI controller is used as a connectivity interface with external 4 + MMC, SD and eMMC storage mediums. This file documents differences between the 5 + core mmc properties described by mmc.txt and the properties used by the 6 + Samsung implmentation of the SDHCI controller. 7 + 8 + Note: The mmc core bindings documentation states that if none of the core 9 + card-detect bindings are used, then the standard sdhci card detect mechanism 10 + is used. The Samsung's SDHCI controller bindings extends this as listed below. 11 + 12 + [A] The property "samsung,cd-pinmux-gpio" can be used as stated in the 13 + "Optional Board Specific Properties" section below. 14 + 15 + [B] If core card-detect bindings and "samsung,cd-pinmux-gpio" property 16 + is not specified, it is assumed that there is no card detection 17 + mechanism used. 18 + 19 + Required SoC Specific Properties: 20 + - compatible: should be one of the following 21 + - "samsung,s3c6410-sdhci": For controllers compatible with s3c6410 sdhci 22 + controller. 23 + - "samsung,exynos4210-sdhci": For controllers compatible with Exynos4 sdhci 24 + controller. 25 + 26 + Required Board Specific Properties: 27 + - gpios: Should specify the gpios used for clock, command and data lines. The 28 + gpio specifier format depends on the gpio controller. 29 + 30 + Optional Board Specific Properties: 31 + - samsung,cd-pinmux-gpio: Specifies the card detect line that is routed 32 + through a pinmux to the card-detect pin of the card slot. This property 33 + should be used only if none of the mmc core card-detect properties are 34 + used. 35 + 36 + Example: 37 + sdhci@12530000 { 38 + compatible = "samsung,exynos4210-sdhci"; 39 + reg = <0x12530000 0x100>; 40 + interrupts = <0 75 0>; 41 + bus-width = <4>; 42 + cd-gpios = <&gpk2 2 2 3 3>; 43 + gpios = <&gpk2 0 2 0 3>, /* clock line */ 44 + <&gpk2 1 2 0 3>, /* command line */ 45 + <&gpk2 3 2 3 3>, /* data line 0 */ 46 + <&gpk2 4 2 3 3>, /* data line 1 */ 47 + <&gpk2 5 2 3 3>, /* data line 2 */ 48 + <&gpk2 6 2 3 3>; /* data line 3 */ 49 + }; 50 + 51 + Note: This example shows both SoC specific and board specific properties 52 + in a single device node. The properties can be actually be seperated 53 + into SoC specific node and board specific node.
+14
Documentation/devicetree/bindings/mmc/sdhci-dove.txt
··· 1 + * Marvell sdhci-dove controller 2 + 3 + This file documents differences between the core properties in mmc.txt 4 + and the properties used by the sdhci-pxav2 and sdhci-pxav3 drivers. 5 + 6 + - compatible: Should be "marvell,dove-sdhci". 7 + 8 + Example: 9 + 10 + sdio0: sdio@92000 { 11 + compatible = "marvell,dove-sdhci"; 12 + reg = <0x92000 0x100>; 13 + interrupts = <35>; 14 + };
+18
Documentation/devicetree/bindings/mmc/sdhci-spear.txt
··· 1 + * SPEAr SDHCI Controller 2 + 3 + This file documents differences between the core properties in mmc.txt 4 + and the properties used by the sdhci-spear driver. 5 + 6 + Required properties: 7 + - compatible: "st,spear300-sdhci" 8 + 9 + Optional properties: 10 + - cd-gpios: card detect gpio, with zero flags. 11 + 12 + Example: 13 + 14 + sdhci@fc000000 { 15 + compatible = "st,spear300-sdhci"; 16 + reg = <0xfc000000 0x1000>; 17 + cd-gpios = <&gpio0 6 0>; 18 + };
+79
Documentation/devicetree/bindings/mmc/synposis-dw-mshc.txt
··· 1 + * Synopsis Designware Mobile Storage Host Controller 2 + 3 + The Synopsis designware mobile storage host controller is used to interface 4 + a SoC with storage medium such as eMMC or SD/MMC cards. This file documents 5 + differences between the core mmc properties described by mmc.txt and the 6 + properties used by the Synopsis Designware Mobile Storage Host Controller. 7 + 8 + Required Properties: 9 + 10 + * compatible: should be 11 + - snps,dw-mshc: for controllers compliant with synopsis dw-mshc. 12 + * #address-cells: should be 1. 13 + * #size-cells: should be 0. 14 + 15 + # Slots: The slot specific information are contained within child-nodes with 16 + each child-node representing a supported slot. There should be atleast one 17 + child node representing a card slot. The name of the child node representing 18 + the slot is recommended to be slot@n where n is the unique number of the slot 19 + connnected to the controller. The following are optional properties which 20 + can be included in the slot child node. 21 + 22 + * reg: specifies the physical slot number. The valid values of this 23 + property is 0 to (num-slots -1), where num-slots is the value 24 + specified by the num-slots property. 25 + 26 + * bus-width: as documented in mmc core bindings. 27 + 28 + * wp-gpios: specifies the write protect gpio line. The format of the 29 + gpio specifier depends on the gpio controller. If the write-protect 30 + line is not available, this property is optional. 31 + 32 + Optional properties: 33 + 34 + * num-slots: specifies the number of slots supported by the controller. 35 + The number of physical slots actually used could be equal or less than the 36 + value specified by num-slots. If this property is not specified, the value 37 + of num-slot property is assumed to be 1. 38 + 39 + * fifo-depth: The maximum size of the tx/rx fifo's. If this property is not 40 + specified, the default value of the fifo size is determined from the 41 + controller registers. 42 + 43 + * card-detect-delay: Delay in milli-seconds before detecting card after card 44 + insert event. The default value is 0. 45 + 46 + * supports-highspeed: Enables support for high speed cards (upto 50MHz) 47 + 48 + * broken-cd: as documented in mmc core bindings. 49 + 50 + Aliases: 51 + 52 + - All the MSHC controller nodes should be represented in the aliases node using 53 + the following format 'mshc{n}' where n is a unique number for the alias. 54 + 55 + Example: 56 + 57 + The MSHC controller node can be split into two portions, SoC specific and 58 + board specific portions as listed below. 59 + 60 + dwmmc0@12200000 { 61 + compatible = "snps,dw-mshc"; 62 + reg = <0x12200000 0x1000>; 63 + interrupts = <0 75 0>; 64 + #address-cells = <1>; 65 + #size-cells = <0>; 66 + }; 67 + 68 + dwmmc0@12200000 { 69 + num-slots = <1>; 70 + supports-highspeed; 71 + broken-cd; 72 + fifo-depth = <0x80>; 73 + card-detect-delay = <200>; 74 + 75 + slot@0 { 76 + reg = <0>; 77 + bus-width = <8>; 78 + }; 79 + };
+4 -2
MAINTAINERS
··· 1544 1544 F: drivers/rtc/rtc-bfin.c 1545 1545 1546 1546 BLACKFIN SDH DRIVER 1547 - M: Cliff Cai <cliff.cai@analog.com> 1547 + M: Sonic Zhang <sonic.zhang@analog.com> 1548 1548 L: uclinux-dist-devel@blackfin.uclinux.org 1549 1549 W: http://blackfin.uclinux.org 1550 1550 S: Supported ··· 5207 5207 F: drivers/mmc/host/omap.c 5208 5208 5209 5209 OMAP HS MMC SUPPORT 5210 + M: Venkatraman S <svenkatr@ti.com> 5211 + L: linux-mmc@vger.kernel.org 5210 5212 L: linux-omap@vger.kernel.org 5211 - S: Orphan 5213 + S: Maintained 5212 5214 F: drivers/mmc/host/omap_hsmmc.c 5213 5215 5214 5216 OMAP RANDOM NUMBER GENERATOR SUPPORT
+1 -2
arch/arm/boot/dts/spear300-evb.dts
··· 80 80 }; 81 81 82 82 sdhci@70000000 { 83 - int-gpio = <&gpio1 0 0>; 84 - power-gpio = <&gpio1 2 1>; 83 + cd-gpios = <&gpio1 0 0>; 85 84 status = "okay"; 86 85 }; 87 86
-2
arch/arm/boot/dts/spear320-evb.dts
··· 103 103 }; 104 104 105 105 sdhci@70000000 { 106 - power-gpio = <&gpio0 2 1>; 107 - power_always_enb; 108 106 status = "okay"; 109 107 }; 110 108
+169 -71
drivers/mmc/core/core.c
··· 26 26 #include <linux/suspend.h> 27 27 #include <linux/fault-inject.h> 28 28 #include <linux/random.h> 29 + #include <linux/slab.h> 29 30 30 31 #include <linux/mmc/card.h> 31 32 #include <linux/mmc/host.h> ··· 41 40 #include "mmc_ops.h" 42 41 #include "sd_ops.h" 43 42 #include "sdio_ops.h" 43 + 44 + /* 45 + * Background operations can take a long time, depending on the housekeeping 46 + * operations the card has to perform. 47 + */ 48 + #define MMC_BKOPS_MAX_TIMEOUT (4 * 60 * 1000) /* max time to wait in ms */ 44 49 45 50 static struct workqueue_struct *workqueue; 46 51 static const unsigned freqs[] = { 400000, 300000, 200000, 100000 }; ··· 252 245 host->ops->request(host, mrq); 253 246 } 254 247 248 + /** 249 + * mmc_start_bkops - start BKOPS for supported cards 250 + * @card: MMC card to start BKOPS 251 + * @form_exception: A flag to indicate if this function was 252 + * called due to an exception raised by the card 253 + * 254 + * Start background operations whenever requested. 255 + * When the urgent BKOPS bit is set in a R1 command response 256 + * then background operations should be started immediately. 257 + */ 258 + void mmc_start_bkops(struct mmc_card *card, bool from_exception) 259 + { 260 + int err; 261 + int timeout; 262 + bool use_busy_signal; 263 + 264 + BUG_ON(!card); 265 + 266 + if (!card->ext_csd.bkops_en || mmc_card_doing_bkops(card)) 267 + return; 268 + 269 + err = mmc_read_bkops_status(card); 270 + if (err) { 271 + pr_err("%s: Failed to read bkops status: %d\n", 272 + mmc_hostname(card->host), err); 273 + return; 274 + } 275 + 276 + if (!card->ext_csd.raw_bkops_status) 277 + return; 278 + 279 + if (card->ext_csd.raw_bkops_status < EXT_CSD_BKOPS_LEVEL_2 && 280 + from_exception) 281 + return; 282 + 283 + mmc_claim_host(card->host); 284 + if (card->ext_csd.raw_bkops_status >= EXT_CSD_BKOPS_LEVEL_2) { 285 + timeout = MMC_BKOPS_MAX_TIMEOUT; 286 + use_busy_signal = true; 287 + } else { 288 + timeout = 0; 289 + use_busy_signal = false; 290 + } 291 + 292 + err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 293 + EXT_CSD_BKOPS_START, 1, timeout, use_busy_signal); 294 + if (err) { 295 + pr_warn("%s: Error %d starting bkops\n", 296 + mmc_hostname(card->host), err); 297 + goto out; 298 + } 299 + 300 + /* 301 + * For urgent bkops status (LEVEL_2 and more) 302 + * bkops executed synchronously, otherwise 303 + * the operation is in progress 304 + */ 305 + if (!use_busy_signal) 306 + mmc_card_set_doing_bkops(card); 307 + out: 308 + mmc_release_host(card->host); 309 + } 310 + EXPORT_SYMBOL(mmc_start_bkops); 311 + 255 312 static void mmc_wait_done(struct mmc_request *mrq) 256 313 { 257 314 complete(&mrq->completion); ··· 425 354 if (host->areq) { 426 355 mmc_wait_for_req_done(host, host->areq->mrq); 427 356 err = host->areq->err_check(host->card, host->areq); 357 + /* 358 + * Check BKOPS urgency for each R1 response 359 + */ 360 + if (host->card && mmc_card_mmc(host->card) && 361 + ((mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1) || 362 + (mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1B)) && 363 + (host->areq->mrq->cmd->resp[0] & R1_EXCEPTION_EVENT)) 364 + mmc_start_bkops(host->card, true); 428 365 } 429 366 430 367 if (!err && areq) ··· 477 398 * @card: the MMC card associated with the HPI transfer 478 399 * 479 400 * Issued High Priority Interrupt, and check for card status 480 - * util out-of prg-state. 401 + * until out-of prg-state. 481 402 */ 482 403 int mmc_interrupt_hpi(struct mmc_card *card) 483 404 { ··· 503 424 case R1_STATE_IDLE: 504 425 case R1_STATE_READY: 505 426 case R1_STATE_STBY: 427 + case R1_STATE_TRAN: 506 428 /* 507 - * In idle states, HPI is not needed and the caller 429 + * In idle and transfer states, HPI is not needed and the caller 508 430 * can issue the next intended command immediately 509 431 */ 510 432 goto out; ··· 567 487 } 568 488 569 489 EXPORT_SYMBOL(mmc_wait_for_cmd); 490 + 491 + /** 492 + * mmc_stop_bkops - stop ongoing BKOPS 493 + * @card: MMC card to check BKOPS 494 + * 495 + * Send HPI command to stop ongoing background operations to 496 + * allow rapid servicing of foreground operations, e.g. read/ 497 + * writes. Wait until the card comes out of the programming state 498 + * to avoid errors in servicing read/write requests. 499 + */ 500 + int mmc_stop_bkops(struct mmc_card *card) 501 + { 502 + int err = 0; 503 + 504 + BUG_ON(!card); 505 + err = mmc_interrupt_hpi(card); 506 + 507 + /* 508 + * If err is EINVAL, we can't issue an HPI. 509 + * It should complete the BKOPS. 510 + */ 511 + if (!err || (err == -EINVAL)) { 512 + mmc_card_clr_doing_bkops(card); 513 + err = 0; 514 + } 515 + 516 + return err; 517 + } 518 + EXPORT_SYMBOL(mmc_stop_bkops); 519 + 520 + int mmc_read_bkops_status(struct mmc_card *card) 521 + { 522 + int err; 523 + u8 *ext_csd; 524 + 525 + /* 526 + * In future work, we should consider storing the entire ext_csd. 527 + */ 528 + ext_csd = kmalloc(512, GFP_KERNEL); 529 + if (!ext_csd) { 530 + pr_err("%s: could not allocate buffer to receive the ext_csd.\n", 531 + mmc_hostname(card->host)); 532 + return -ENOMEM; 533 + } 534 + 535 + mmc_claim_host(card->host); 536 + err = mmc_send_ext_csd(card, ext_csd); 537 + mmc_release_host(card->host); 538 + if (err) 539 + goto out; 540 + 541 + card->ext_csd.raw_bkops_status = ext_csd[EXT_CSD_BKOPS_STATUS]; 542 + card->ext_csd.raw_exception_status = ext_csd[EXT_CSD_EXP_EVENTS_STATUS]; 543 + out: 544 + kfree(ext_csd); 545 + return err; 546 + } 547 + EXPORT_SYMBOL(mmc_read_bkops_status); 570 548 571 549 /** 572 550 * mmc_set_data_timeout - set the timeout for a data command ··· 1113 975 int tmp; 1114 976 int voltage; 1115 977 1116 - /* REVISIT mmc_vddrange_to_ocrmask() may have set some 978 + /* 979 + * REVISIT mmc_vddrange_to_ocrmask() may have set some 1117 980 * bits this regulator doesn't quite support ... don't 1118 981 * be too picky, most cards and regulators are OK with 1119 982 * a 0.1V range goof (it's a small error percentage). ··· 1128 989 max_uV = min_uV + 100 * 1000; 1129 990 } 1130 991 1131 - /* avoid needless changes to this voltage; the regulator 1132 - * might not allow this operation 992 + /* 993 + * If we're using a fixed/static regulator, don't call 994 + * regulator_set_voltage; it would fail. 1133 995 */ 1134 996 voltage = regulator_get_voltage(supply); 1135 997 1136 - if (mmc->caps2 & MMC_CAP2_BROKEN_VOLTAGE) 998 + if (regulator_count_voltages(supply) == 1) 1137 999 min_uV = max_uV = voltage; 1138 1000 1139 1001 if (voltage < 0) ··· 1273 1133 mmc_host_clk_release(host); 1274 1134 } 1275 1135 1276 - static void mmc_poweroff_notify(struct mmc_host *host) 1277 - { 1278 - struct mmc_card *card; 1279 - unsigned int timeout; 1280 - unsigned int notify_type = EXT_CSD_NO_POWER_NOTIFICATION; 1281 - int err = 0; 1282 - 1283 - card = host->card; 1284 - mmc_claim_host(host); 1285 - 1286 - /* 1287 - * Send power notify command only if card 1288 - * is mmc and notify state is powered ON 1289 - */ 1290 - if (card && mmc_card_mmc(card) && 1291 - (card->poweroff_notify_state == MMC_POWERED_ON)) { 1292 - 1293 - if (host->power_notify_type == MMC_HOST_PW_NOTIFY_SHORT) { 1294 - notify_type = EXT_CSD_POWER_OFF_SHORT; 1295 - timeout = card->ext_csd.generic_cmd6_time; 1296 - card->poweroff_notify_state = MMC_POWEROFF_SHORT; 1297 - } else { 1298 - notify_type = EXT_CSD_POWER_OFF_LONG; 1299 - timeout = card->ext_csd.power_off_longtime; 1300 - card->poweroff_notify_state = MMC_POWEROFF_LONG; 1301 - } 1302 - 1303 - err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1304 - EXT_CSD_POWER_OFF_NOTIFICATION, 1305 - notify_type, timeout); 1306 - 1307 - if (err && err != -EBADMSG) 1308 - pr_err("Device failed to respond within %d poweroff " 1309 - "time. Forcefully powering down the device\n", 1310 - timeout); 1311 - 1312 - /* Set the card state to no notification after the poweroff */ 1313 - card->poweroff_notify_state = MMC_NO_POWER_NOTIFICATION; 1314 - } 1315 - mmc_release_host(host); 1316 - } 1317 - 1318 1136 /* 1319 1137 * Apply power to the MMC stack. This is a two-stage process. 1320 1138 * First, we enable power to the card without the clock running. ··· 1335 1237 1336 1238 void mmc_power_off(struct mmc_host *host) 1337 1239 { 1338 - int err = 0; 1339 - 1340 1240 if (host->ios.power_mode == MMC_POWER_OFF) 1341 1241 return; 1342 1242 ··· 1343 1247 host->ios.clock = 0; 1344 1248 host->ios.vdd = 0; 1345 1249 1346 - /* 1347 - * For eMMC 4.5 device send AWAKE command before 1348 - * POWER_OFF_NOTIFY command, because in sleep state 1349 - * eMMC 4.5 devices respond to only RESET and AWAKE cmd 1350 - */ 1351 - if (host->card && mmc_card_is_sleep(host->card) && 1352 - host->bus_ops->resume) { 1353 - err = host->bus_ops->resume(host); 1354 - 1355 - if (!err) 1356 - mmc_poweroff_notify(host); 1357 - else 1358 - pr_warning("%s: error %d during resume " 1359 - "(continue with poweroff sequence)\n", 1360 - mmc_hostname(host), err); 1361 - } 1362 1250 1363 1251 /* 1364 1252 * Reset ocr mask to be the highest possible voltage supported for ··· 2132 2052 if (host->rescan_disable) 2133 2053 return; 2134 2054 2055 + /* If there is a non-removable card registered, only scan once */ 2056 + if ((host->caps & MMC_CAP_NONREMOVABLE) && host->rescan_entered) 2057 + return; 2058 + host->rescan_entered = 1; 2059 + 2135 2060 mmc_bus_get(host); 2136 2061 2137 2062 /* ··· 2412 2327 2413 2328 mmc_bus_get(host); 2414 2329 if (host->bus_ops && !host->bus_dead) { 2415 - 2416 - if (host->bus_ops->suspend) 2330 + if (host->bus_ops->suspend) { 2331 + if (mmc_card_doing_bkops(host->card)) { 2332 + err = mmc_stop_bkops(host->card); 2333 + if (err) 2334 + goto out; 2335 + } 2417 2336 err = host->bus_ops->suspend(host); 2337 + } 2418 2338 2419 2339 if (err == -ENOSYS || !host->bus_ops->resume) { 2420 2340 /* ··· 2501 2411 struct mmc_host *host = container_of( 2502 2412 notify_block, struct mmc_host, pm_notify); 2503 2413 unsigned long flags; 2504 - 2414 + int err = 0; 2505 2415 2506 2416 switch (mode) { 2507 2417 case PM_HIBERNATION_PREPARE: 2508 2418 case PM_SUSPEND_PREPARE: 2419 + if (host->card && mmc_card_mmc(host->card) && 2420 + mmc_card_doing_bkops(host->card)) { 2421 + err = mmc_stop_bkops(host->card); 2422 + if (err) { 2423 + pr_err("%s: didn't stop bkops\n", 2424 + mmc_hostname(host)); 2425 + return err; 2426 + } 2427 + mmc_card_clr_doing_bkops(host->card); 2428 + } 2509 2429 2510 2430 spin_lock_irqsave(&host->lock, flags); 2511 2431 host->rescan_disable = 1; 2512 - host->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT; 2513 2432 spin_unlock_irqrestore(&host->lock, flags); 2514 2433 cancel_delayed_work_sync(&host->detect); 2515 2434 ··· 2542 2443 2543 2444 spin_lock_irqsave(&host->lock, flags); 2544 2445 host->rescan_disable = 0; 2545 - host->power_notify_type = MMC_HOST_PW_NOTIFY_LONG; 2546 2446 spin_unlock_irqrestore(&host->lock, flags); 2547 2447 mmc_detect_change(host, 0); 2548 2448
+1 -1
drivers/mmc/core/debugfs.c
··· 281 281 if (err) 282 282 goto out_free; 283 283 284 - for (i = 511; i >= 0; i--) 284 + for (i = 0; i < 512; i++) 285 285 n += sprintf(buf + n, "%02x", ext_csd[i]); 286 286 n += sprintf(buf + n, "\n"); 287 287 BUG_ON(n != EXT_CSD_STR_LEN);
+46 -11
drivers/mmc/core/mmc.c
··· 463 463 } 464 464 465 465 if (card->ext_csd.rev >= 5) { 466 + /* check whether the eMMC card supports BKOPS */ 467 + if (ext_csd[EXT_CSD_BKOPS_SUPPORT] & 0x1) { 468 + card->ext_csd.bkops = 1; 469 + card->ext_csd.bkops_en = ext_csd[EXT_CSD_BKOPS_EN]; 470 + card->ext_csd.raw_bkops_status = 471 + ext_csd[EXT_CSD_BKOPS_STATUS]; 472 + if (!card->ext_csd.bkops_en) 473 + pr_info("%s: BKOPS_EN bit is not set\n", 474 + mmc_hostname(card->host)); 475 + } 476 + 466 477 /* check whether the eMMC card supports HPI */ 467 478 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) { 468 479 card->ext_csd.hpi = 1; ··· 1007 996 * so check for success and update the flag 1008 997 */ 1009 998 if (!err) 1010 - card->poweroff_notify_state = MMC_POWERED_ON; 999 + card->ext_csd.power_off_notification = EXT_CSD_POWER_ON; 1011 1000 } 1012 1001 1013 1002 /* ··· 1273 1262 return err; 1274 1263 } 1275 1264 1265 + static int mmc_can_poweroff_notify(const struct mmc_card *card) 1266 + { 1267 + return card && 1268 + mmc_card_mmc(card) && 1269 + (card->ext_csd.power_off_notification == EXT_CSD_POWER_ON); 1270 + } 1271 + 1272 + static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) 1273 + { 1274 + unsigned int timeout = card->ext_csd.generic_cmd6_time; 1275 + int err; 1276 + 1277 + /* Use EXT_CSD_POWER_OFF_SHORT as default notification type. */ 1278 + if (notify_type == EXT_CSD_POWER_OFF_LONG) 1279 + timeout = card->ext_csd.power_off_longtime; 1280 + 1281 + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1282 + EXT_CSD_POWER_OFF_NOTIFICATION, 1283 + notify_type, timeout); 1284 + if (err) 1285 + pr_err("%s: Power Off Notification timed out, %u\n", 1286 + mmc_hostname(card->host), timeout); 1287 + 1288 + /* Disable the power off notification after the switch operation. */ 1289 + card->ext_csd.power_off_notification = EXT_CSD_NO_POWER_NOTIFICATION; 1290 + 1291 + return err; 1292 + } 1293 + 1276 1294 /* 1277 1295 * Host is being removed. Free up the current card. 1278 1296 */ ··· 1362 1322 BUG_ON(!host->card); 1363 1323 1364 1324 mmc_claim_host(host); 1365 - if (mmc_card_can_sleep(host)) { 1325 + if (mmc_can_poweroff_notify(host->card)) 1326 + err = mmc_poweroff_notify(host->card, EXT_CSD_POWER_OFF_SHORT); 1327 + else if (mmc_card_can_sleep(host)) 1366 1328 err = mmc_card_sleep(host); 1367 - if (!err) 1368 - mmc_card_set_sleep(host->card); 1369 - } else if (!mmc_host_is_spi(host)) 1329 + else if (!mmc_host_is_spi(host)) 1370 1330 err = mmc_deselect_cards(host); 1371 1331 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); 1372 1332 mmc_release_host(host); ··· 1388 1348 BUG_ON(!host->card); 1389 1349 1390 1350 mmc_claim_host(host); 1391 - if (mmc_card_is_sleep(host->card)) { 1392 - err = mmc_card_awake(host); 1393 - mmc_card_clr_sleep(host->card); 1394 - } else 1395 - err = mmc_init_card(host, host->ocr, host->card); 1351 + err = mmc_init_card(host, host->ocr, host->card); 1396 1352 mmc_release_host(host); 1397 1353 1398 1354 return err; ··· 1399 1363 int ret; 1400 1364 1401 1365 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); 1402 - mmc_card_clr_sleep(host->card); 1403 1366 mmc_claim_host(host); 1404 1367 ret = mmc_init_card(host, host->ocr, host->card); 1405 1368 mmc_release_host(host);
+64 -20
drivers/mmc/core/mmc_ops.c
··· 230 230 return 0; 231 231 } 232 232 233 + /* 234 + * NOTE: void *buf, caller for the buf is required to use DMA-capable 235 + * buffer or on-stack buffer (with some overhead in callee). 236 + */ 233 237 static int 234 238 mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host, 235 239 u32 opcode, void *buf, unsigned len) ··· 243 239 struct mmc_data data = {0}; 244 240 struct scatterlist sg; 245 241 void *data_buf; 242 + int is_on_stack; 246 243 247 - /* dma onto stack is unsafe/nonportable, but callers to this 248 - * routine normally provide temporary on-stack buffers ... 249 - */ 250 - data_buf = kmalloc(len, GFP_KERNEL); 251 - if (data_buf == NULL) 252 - return -ENOMEM; 244 + is_on_stack = object_is_on_stack(buf); 245 + if (is_on_stack) { 246 + /* 247 + * dma onto stack is unsafe/nonportable, but callers to this 248 + * routine normally provide temporary on-stack buffers ... 249 + */ 250 + data_buf = kmalloc(len, GFP_KERNEL); 251 + if (!data_buf) 252 + return -ENOMEM; 253 + } else 254 + data_buf = buf; 253 255 254 256 mrq.cmd = &cmd; 255 257 mrq.data = &data; ··· 290 280 291 281 mmc_wait_for_req(host, &mrq); 292 282 293 - memcpy(buf, data_buf, len); 294 - kfree(data_buf); 283 + if (is_on_stack) { 284 + memcpy(buf, data_buf, len); 285 + kfree(data_buf); 286 + } 295 287 296 288 if (cmd.error) 297 289 return cmd.error; ··· 306 294 int mmc_send_csd(struct mmc_card *card, u32 *csd) 307 295 { 308 296 int ret, i; 297 + u32 *csd_tmp; 309 298 310 299 if (!mmc_host_is_spi(card->host)) 311 300 return mmc_send_cxd_native(card->host, card->rca << 16, 312 301 csd, MMC_SEND_CSD); 313 302 314 - ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16); 303 + csd_tmp = kmalloc(16, GFP_KERNEL); 304 + if (!csd_tmp) 305 + return -ENOMEM; 306 + 307 + ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd_tmp, 16); 315 308 if (ret) 316 - return ret; 309 + goto err; 317 310 318 311 for (i = 0;i < 4;i++) 319 - csd[i] = be32_to_cpu(csd[i]); 312 + csd[i] = be32_to_cpu(csd_tmp[i]); 320 313 321 - return 0; 314 + err: 315 + kfree(csd_tmp); 316 + return ret; 322 317 } 323 318 324 319 int mmc_send_cid(struct mmc_host *host, u32 *cid) 325 320 { 326 321 int ret, i; 322 + u32 *cid_tmp; 327 323 328 324 if (!mmc_host_is_spi(host)) { 329 325 if (!host->card) ··· 340 320 cid, MMC_SEND_CID); 341 321 } 342 322 343 - ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16); 323 + cid_tmp = kmalloc(16, GFP_KERNEL); 324 + if (!cid_tmp) 325 + return -ENOMEM; 326 + 327 + ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid_tmp, 16); 344 328 if (ret) 345 - return ret; 329 + goto err; 346 330 347 331 for (i = 0;i < 4;i++) 348 - cid[i] = be32_to_cpu(cid[i]); 332 + cid[i] = be32_to_cpu(cid_tmp[i]); 349 333 350 - return 0; 334 + err: 335 + kfree(cid_tmp); 336 + return ret; 351 337 } 352 338 353 339 int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd) ··· 393 367 } 394 368 395 369 /** 396 - * mmc_switch - modify EXT_CSD register 370 + * __mmc_switch - modify EXT_CSD register 397 371 * @card: the MMC card associated with the data transfer 398 372 * @set: cmd set values 399 373 * @index: EXT_CSD register index 400 374 * @value: value to program into EXT_CSD register 401 375 * @timeout_ms: timeout (ms) for operation performed by register write, 402 376 * timeout of zero implies maximum possible timeout 377 + * @use_busy_signal: use the busy signal as response type 403 378 * 404 379 * Modifies the EXT_CSD register for selected card. 405 380 */ 406 - int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, 407 - unsigned int timeout_ms) 381 + int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, 382 + unsigned int timeout_ms, bool use_busy_signal) 408 383 { 409 384 int err; 410 385 struct mmc_command cmd = {0}; ··· 419 392 (index << 16) | 420 393 (value << 8) | 421 394 set; 422 - cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; 395 + cmd.flags = MMC_CMD_AC; 396 + if (use_busy_signal) 397 + cmd.flags |= MMC_RSP_SPI_R1B | MMC_RSP_R1B; 398 + else 399 + cmd.flags |= MMC_RSP_SPI_R1 | MMC_RSP_R1; 400 + 401 + 423 402 cmd.cmd_timeout_ms = timeout_ms; 424 403 425 404 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 426 405 if (err) 427 406 return err; 407 + 408 + /* No need to check card status in case of unblocking command */ 409 + if (!use_busy_signal) 410 + return 0; 428 411 429 412 /* Must check status to be sure of no errors */ 430 413 do { ··· 459 422 } 460 423 461 424 return 0; 425 + } 426 + EXPORT_SYMBOL_GPL(__mmc_switch); 427 + 428 + int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, 429 + unsigned int timeout_ms) 430 + { 431 + return __mmc_switch(card, set, index, value, timeout_ms, true); 462 432 } 463 433 EXPORT_SYMBOL_GPL(mmc_switch); 464 434
-7
drivers/mmc/core/sdio_bus.c
··· 193 193 } 194 194 195 195 #ifdef CONFIG_PM 196 - 197 - static int pm_no_operation(struct device *dev) 198 - { 199 - return 0; 200 - } 201 - 202 196 static const struct dev_pm_ops sdio_bus_pm_ops = { 203 - SET_SYSTEM_SLEEP_PM_OPS(pm_no_operation, pm_no_operation) 204 197 SET_RUNTIME_PM_OPS( 205 198 pm_generic_runtime_suspend, 206 199 pm_generic_runtime_resume,
+7 -1
drivers/mmc/core/slot-gpio.c
··· 100 100 101 101 ctx = host->slot.handler_priv; 102 102 103 - return gpio_request_one(gpio, GPIOF_DIR_IN, ctx->ro_label); 103 + ret = gpio_request_one(gpio, GPIOF_DIR_IN, ctx->ro_label); 104 + if (ret < 0) 105 + return ret; 106 + 107 + ctx->ro_gpio = gpio; 108 + 109 + return 0; 104 110 } 105 111 EXPORT_SYMBOL(mmc_gpio_request_ro); 106 112
+9
drivers/mmc/host/Kconfig
··· 540 540 541 541 If unsure, say Y. 542 542 543 + config MMC_DW_EXYNOS 544 + tristate "Exynos specific extentions for Synopsys DW Memory Card Interface" 545 + depends on MMC_DW 546 + select MMC_DW_PLTFM 547 + help 548 + This selects support for Samsung Exynos SoC specific extensions to the 549 + Synopsys DesignWare Memory Card Interface driver. Select this option 550 + for platforms based on Exynos4 and Exynos5 SoC's. 551 + 543 552 config MMC_DW_PCI 544 553 tristate "Synopsys Designware MCI support on PCI bus" 545 554 depends on MMC_DW && PCI
+1
drivers/mmc/host/Makefile
··· 39 39 obj-$(CONFIG_SDH_BFIN) += bfin_sdh.o 40 40 obj-$(CONFIG_MMC_DW) += dw_mmc.o 41 41 obj-$(CONFIG_MMC_DW_PLTFM) += dw_mmc-pltfm.o 42 + obj-$(CONFIG_MMC_DW_EXYNOS) += dw_mmc-exynos.o 42 43 obj-$(CONFIG_MMC_DW_PCI) += dw_mmc-pci.o 43 44 obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o 44 45 obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o
+7
drivers/mmc/host/atmel-mci-regs.h
··· 140 140 #define atmci_writel(port,reg,value) \ 141 141 __raw_writel((value), (port)->regs + reg) 142 142 143 + /* On AVR chips the Peripheral DMA Controller is not connected to MCI. */ 144 + #ifdef CONFIG_AVR32 145 + # define ATMCI_PDC_CONNECTED 0 146 + #else 147 + # define ATMCI_PDC_CONNECTED 1 148 + #endif 149 + 143 150 /* 144 151 * Fix sconfig's burst size according to atmel MCI. We need to convert them as: 145 152 * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3.
+97 -16
drivers/mmc/host/atmel-mci.c
··· 19 19 #include <linux/interrupt.h> 20 20 #include <linux/ioport.h> 21 21 #include <linux/module.h> 22 + #include <linux/of.h> 23 + #include <linux/of_device.h> 24 + #include <linux/of_gpio.h> 22 25 #include <linux/platform_device.h> 23 26 #include <linux/scatterlist.h> 24 27 #include <linux/seq_file.h> ··· 74 71 }; 75 72 76 73 struct atmel_mci_caps { 77 - bool has_dma; 74 + bool has_dma_conf_reg; 78 75 bool has_pdc; 79 76 bool has_cfg_reg; 80 77 bool has_cstor_reg; ··· 421 418 atmci_show_status_reg(s, "SR", buf[ATMCI_SR / 4]); 422 419 atmci_show_status_reg(s, "IMR", buf[ATMCI_IMR / 4]); 423 420 424 - if (host->caps.has_dma) { 421 + if (host->caps.has_dma_conf_reg) { 425 422 u32 val; 426 423 427 424 val = buf[ATMCI_DMA / 4]; ··· 502 499 err: 503 500 dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n"); 504 501 } 502 + 503 + #if defined(CONFIG_OF) 504 + static const struct of_device_id atmci_dt_ids[] = { 505 + { .compatible = "atmel,hsmci" }, 506 + { /* sentinel */ } 507 + }; 508 + 509 + MODULE_DEVICE_TABLE(of, atmci_dt_ids); 510 + 511 + static struct mci_platform_data __devinit* 512 + atmci_of_init(struct platform_device *pdev) 513 + { 514 + struct device_node *np = pdev->dev.of_node; 515 + struct device_node *cnp; 516 + struct mci_platform_data *pdata; 517 + u32 slot_id; 518 + 519 + if (!np) { 520 + dev_err(&pdev->dev, "device node not found\n"); 521 + return ERR_PTR(-EINVAL); 522 + } 523 + 524 + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 525 + if (!pdata) { 526 + dev_err(&pdev->dev, "could not allocate memory for pdata\n"); 527 + return ERR_PTR(-ENOMEM); 528 + } 529 + 530 + for_each_child_of_node(np, cnp) { 531 + if (of_property_read_u32(cnp, "reg", &slot_id)) { 532 + dev_warn(&pdev->dev, "reg property is missing for %s\n", 533 + cnp->full_name); 534 + continue; 535 + } 536 + 537 + if (slot_id >= ATMCI_MAX_NR_SLOTS) { 538 + dev_warn(&pdev->dev, "can't have more than %d slots\n", 539 + ATMCI_MAX_NR_SLOTS); 540 + break; 541 + } 542 + 543 + if (of_property_read_u32(cnp, "bus-width", 544 + &pdata->slot[slot_id].bus_width)) 545 + pdata->slot[slot_id].bus_width = 1; 546 + 547 + pdata->slot[slot_id].detect_pin = 548 + of_get_named_gpio(cnp, "cd-gpios", 0); 549 + 550 + pdata->slot[slot_id].detect_is_active_high = 551 + of_property_read_bool(cnp, "cd-inverted"); 552 + 553 + pdata->slot[slot_id].wp_pin = 554 + of_get_named_gpio(cnp, "wp-gpios", 0); 555 + } 556 + 557 + return pdata; 558 + } 559 + #else /* CONFIG_OF */ 560 + static inline struct mci_platform_data* 561 + atmci_of_init(struct platform_device *dev) 562 + { 563 + return ERR_PTR(-EINVAL); 564 + } 565 + #endif 505 566 506 567 static inline unsigned int atmci_get_version(struct atmel_mci *host) 507 568 { ··· 841 774 842 775 dev_vdbg(&host->pdev->dev, "DMA complete\n"); 843 776 844 - if (host->caps.has_dma) 777 + if (host->caps.has_dma_conf_reg) 845 778 /* Disable DMA hardware handshaking on MCI */ 846 779 atmci_writel(host, ATMCI_DMA, atmci_readl(host, ATMCI_DMA) & ~ATMCI_DMAEN); 847 780 ··· 1028 961 maxburst = atmci_convert_chksize(host->dma_conf.dst_maxburst); 1029 962 } 1030 963 1031 - atmci_writel(host, ATMCI_DMA, ATMCI_DMA_CHKSIZE(maxburst) | ATMCI_DMAEN); 964 + if (host->caps.has_dma_conf_reg) 965 + atmci_writel(host, ATMCI_DMA, ATMCI_DMA_CHKSIZE(maxburst) | 966 + ATMCI_DMAEN); 1032 967 1033 968 sglen = dma_map_sg(chan->device->dev, data->sg, 1034 969 data->sg_len, direction); ··· 2115 2046 slot->sdc_reg = sdc_reg; 2116 2047 slot->sdio_irq = sdio_irq; 2117 2048 2049 + dev_dbg(&mmc->class_dev, 2050 + "slot[%u]: bus_width=%u, detect_pin=%d, " 2051 + "detect_is_active_high=%s, wp_pin=%d\n", 2052 + id, slot_data->bus_width, slot_data->detect_pin, 2053 + slot_data->detect_is_active_high ? "true" : "false", 2054 + slot_data->wp_pin); 2055 + 2118 2056 mmc->ops = &atmci_ops; 2119 2057 mmc->f_min = DIV_ROUND_UP(host->bus_hz, 512); 2120 2058 mmc->f_max = host->bus_hz / 2; ··· 2245 2169 2246 2170 pdata = host->pdev->dev.platform_data; 2247 2171 2248 - if (pdata && find_slave_dev(pdata->dma_slave)) { 2172 + if (!pdata) 2173 + return false; 2174 + 2175 + if (pdata->dma_slave && find_slave_dev(pdata->dma_slave)) { 2249 2176 dma_cap_mask_t mask; 2250 2177 2251 2178 /* Try to grab a DMA channel */ ··· 2289 2210 dev_info(&host->pdev->dev, 2290 2211 "version: 0x%x\n", version); 2291 2212 2292 - host->caps.has_dma = 0; 2293 - host->caps.has_pdc = 1; 2213 + host->caps.has_dma_conf_reg = 0; 2214 + host->caps.has_pdc = ATMCI_PDC_CONNECTED; 2294 2215 host->caps.has_cfg_reg = 0; 2295 2216 host->caps.has_cstor_reg = 0; 2296 2217 host->caps.has_highspeed = 0; ··· 2307 2228 host->caps.has_odd_clk_div = 1; 2308 2229 case 0x400: 2309 2230 case 0x300: 2310 - #ifdef CONFIG_AT_HDMAC 2311 - host->caps.has_dma = 1; 2312 - #else 2313 - dev_info(&host->pdev->dev, 2314 - "has dma capability but dma engine is not selected, then use pio\n"); 2315 - #endif 2231 + host->caps.has_dma_conf_reg = 1; 2316 2232 host->caps.has_pdc = 0; 2317 2233 host->caps.has_cfg_reg = 1; 2318 2234 host->caps.has_cstor_reg = 1; ··· 2342 2268 if (!regs) 2343 2269 return -ENXIO; 2344 2270 pdata = pdev->dev.platform_data; 2345 - if (!pdata) 2346 - return -ENXIO; 2271 + if (!pdata) { 2272 + pdata = atmci_of_init(pdev); 2273 + if (IS_ERR(pdata)) { 2274 + dev_err(&pdev->dev, "platform data not available\n"); 2275 + return PTR_ERR(pdata); 2276 + } 2277 + } 2278 + 2347 2279 irq = platform_get_irq(pdev, 0); 2348 2280 if (irq < 0) 2349 2281 return irq; ··· 2388 2308 2389 2309 /* Get MCI capabilities and set operations according to it */ 2390 2310 atmci_get_cap(host); 2391 - if (host->caps.has_dma && atmci_configure_dma(host)) { 2311 + if (atmci_configure_dma(host)) { 2392 2312 host->prepare_data = &atmci_prepare_data_dma; 2393 2313 host->submit_data = &atmci_submit_data_dma; 2394 2314 host->stop_transfer = &atmci_stop_transfer_dma; ··· 2567 2487 .driver = { 2568 2488 .name = "atmel_mci", 2569 2489 .pm = ATMCI_PM_OPS, 2490 + .of_match_table = of_match_ptr(atmci_dt_ids), 2570 2491 }, 2571 2492 }; 2572 2493
+140 -72
drivers/mmc/host/bfin_sdh.c
··· 24 24 #include <asm/portmux.h> 25 25 #include <asm/bfin_sdh.h> 26 26 27 - #if defined(CONFIG_BF51x) 28 - #define bfin_read_SDH_PWR_CTL bfin_read_RSI_PWR_CTL 29 - #define bfin_write_SDH_PWR_CTL bfin_write_RSI_PWR_CTL 27 + #if defined(CONFIG_BF51x) || defined(__ADSPBF60x__) 30 28 #define bfin_read_SDH_CLK_CTL bfin_read_RSI_CLK_CTL 31 29 #define bfin_write_SDH_CLK_CTL bfin_write_RSI_CLK_CTL 32 30 #define bfin_write_SDH_ARGUMENT bfin_write_RSI_ARGUMENT ··· 43 45 #define bfin_write_SDH_E_STATUS bfin_write_RSI_E_STATUS 44 46 #define bfin_read_SDH_STATUS bfin_read_RSI_STATUS 45 47 #define bfin_write_SDH_MASK0 bfin_write_RSI_MASK0 48 + #define bfin_write_SDH_E_MASK bfin_write_RSI_E_MASK 46 49 #define bfin_read_SDH_CFG bfin_read_RSI_CFG 47 50 #define bfin_write_SDH_CFG bfin_write_RSI_CFG 51 + # if defined(__ADSPBF60x__) 52 + # define bfin_read_SDH_BLK_SIZE bfin_read_RSI_BLKSZ 53 + # define bfin_write_SDH_BLK_SIZE bfin_write_RSI_BLKSZ 54 + # else 55 + # define bfin_read_SDH_PWR_CTL bfin_read_RSI_PWR_CTL 56 + # define bfin_write_SDH_PWR_CTL bfin_write_RSI_PWR_CTL 57 + # endif 48 58 #endif 49 59 50 60 struct sdh_host { ··· 68 62 dma_addr_t sg_dma; 69 63 int dma_len; 70 64 65 + unsigned long sclk; 71 66 unsigned int imask; 72 67 unsigned int power_mode; 73 68 unsigned int clk_div; ··· 134 127 /* Only supports power-of-2 block size */ 135 128 if (data->blksz & (data->blksz - 1)) 136 129 return -EINVAL; 130 + #ifndef RSI_BLKSZ 137 131 data_ctl |= ((ffs(data->blksz) - 1) << 4); 132 + #else 133 + bfin_write_SDH_BLK_SIZE(data->blksz); 134 + #endif 138 135 139 136 bfin_write_SDH_DATA_CTL(data_ctl); 140 137 /* the time of a host clock period in ns */ 141 - cycle_ns = 1000000000 / (get_sclk() / (2 * (host->clk_div + 1))); 138 + cycle_ns = 1000000000 / (host->sclk / (2 * (host->clk_div + 1))); 142 139 timeout = data->timeout_ns / cycle_ns; 143 140 timeout += data->timeout_clks; 144 141 bfin_write_SDH_DATA_TIMER(timeout); ··· 156 145 157 146 sdh_enable_stat_irq(host, (DAT_CRC_FAIL | DAT_TIME_OUT | DAT_END)); 158 147 host->dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma_dir); 159 - #if defined(CONFIG_BF54x) 160 - dma_cfg |= DMAFLOW_ARRAY | NDSIZE_5 | RESTART | WDSIZE_32 | DMAEN; 148 + #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x) 149 + dma_cfg |= DMAFLOW_ARRAY | RESTART | WDSIZE_32 | DMAEN; 150 + # ifdef RSI_BLKSZ 151 + dma_cfg |= PSIZE_32 | NDSIZE_3; 152 + # else 153 + dma_cfg |= NDSIZE_5; 154 + # endif 161 155 { 162 156 struct scatterlist *sg; 163 157 int i; ··· 172 156 host->sg_cpu[i].x_count = sg_dma_len(sg) / 4; 173 157 host->sg_cpu[i].x_modify = 4; 174 158 dev_dbg(mmc_dev(host->mmc), "%d: start_addr:0x%lx, " 175 - "cfg:0x%x, x_count:0x%x, x_modify:0x%x\n", 159 + "cfg:0x%lx, x_count:0x%lx, x_modify:0x%lx\n", 176 160 i, host->sg_cpu[i].start_addr, 177 161 host->sg_cpu[i].cfg, host->sg_cpu[i].x_count, 178 162 host->sg_cpu[i].x_modify); ··· 188 172 set_dma_curr_desc_addr(host->dma_ch, (unsigned long *)host->sg_dma); 189 173 set_dma_x_count(host->dma_ch, 0); 190 174 set_dma_x_modify(host->dma_ch, 0); 175 + SSYNC(); 191 176 set_dma_config(host->dma_ch, dma_cfg); 192 177 #elif defined(CONFIG_BF51x) 193 178 /* RSI DMA doesn't work in array mode */ ··· 196 179 set_dma_start_addr(host->dma_ch, sg_dma_address(&data->sg[0])); 197 180 set_dma_x_count(host->dma_ch, length / 4); 198 181 set_dma_x_modify(host->dma_ch, 4); 182 + SSYNC(); 199 183 set_dma_config(host->dma_ch, dma_cfg); 200 184 #endif 201 185 bfin_write_SDH_DATA_CTL(bfin_read_SDH_DATA_CTL() | DTX_DMA_E | DTX_E); ··· 314 296 else 315 297 data->bytes_xfered = 0; 316 298 317 - sdh_disable_stat_irq(host, DAT_END | DAT_TIME_OUT | DAT_CRC_FAIL | RX_OVERRUN | TX_UNDERRUN); 318 299 bfin_write_SDH_STATUS_CLR(DAT_END_STAT | DAT_TIMEOUT_STAT | \ 319 300 DAT_CRC_FAIL_STAT | DAT_BLK_END_STAT | RX_OVERRUN | TX_UNDERRUN); 320 301 bfin_write_SDH_DATA_CTL(0); ··· 338 321 dev_dbg(mmc_dev(host->mmc), "%s enter, mrp:%p, cmd:%p\n", __func__, mrq, mrq->cmd); 339 322 WARN_ON(host->mrq != NULL); 340 323 324 + spin_lock(&host->lock); 341 325 host->mrq = mrq; 342 326 host->data = mrq->data; 343 327 344 328 if (mrq->data && mrq->data->flags & MMC_DATA_READ) { 345 329 ret = sdh_setup_data(host, mrq->data); 346 330 if (ret) 347 - return; 331 + goto data_err; 348 332 } 349 333 350 334 sdh_start_cmd(host, mrq->cmd); 335 + data_err: 336 + spin_unlock(&host->lock); 351 337 } 352 338 353 339 static void sdh_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) 354 340 { 355 341 struct sdh_host *host; 356 - unsigned long flags; 357 342 u16 clk_ctl = 0; 343 + #ifndef RSI_BLKSZ 358 344 u16 pwr_ctl = 0; 345 + #endif 359 346 u16 cfg; 360 347 host = mmc_priv(mmc); 361 348 362 - spin_lock_irqsave(&host->lock, flags); 363 - if (ios->clock) { 364 - unsigned long sys_clk, ios_clk; 349 + spin_lock(&host->lock); 350 + 351 + cfg = bfin_read_SDH_CFG(); 352 + cfg |= MWE; 353 + switch (ios->bus_width) { 354 + case MMC_BUS_WIDTH_4: 355 + #ifndef RSI_BLKSZ 356 + cfg &= ~PD_SDDAT3; 357 + #endif 358 + cfg |= PUP_SDDAT3; 359 + /* Enable 4 bit SDIO */ 360 + cfg |= SD4E; 361 + clk_ctl |= WIDE_BUS_4; 362 + break; 363 + case MMC_BUS_WIDTH_8: 364 + #ifndef RSI_BLKSZ 365 + cfg &= ~PD_SDDAT3; 366 + #endif 367 + cfg |= PUP_SDDAT3; 368 + /* Disable 4 bit SDIO */ 369 + cfg &= ~SD4E; 370 + clk_ctl |= BYTE_BUS_8; 371 + break; 372 + default: 373 + cfg &= ~PUP_SDDAT3; 374 + /* Disable 4 bit SDIO */ 375 + cfg &= ~SD4E; 376 + } 377 + 378 + host->power_mode = ios->power_mode; 379 + #ifndef RSI_BLKSZ 380 + if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) { 381 + pwr_ctl |= ROD_CTL; 382 + # ifndef CONFIG_SDH_BFIN_MISSING_CMD_PULLUP_WORKAROUND 383 + pwr_ctl |= SD_CMD_OD; 384 + # endif 385 + } 386 + 387 + if (ios->power_mode != MMC_POWER_OFF) 388 + pwr_ctl |= PWR_ON; 389 + else 390 + pwr_ctl &= ~PWR_ON; 391 + 392 + bfin_write_SDH_PWR_CTL(pwr_ctl); 393 + #else 394 + # ifndef CONFIG_SDH_BFIN_MISSING_CMD_PULLUP_WORKAROUND 395 + if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) 396 + cfg |= SD_CMD_OD; 397 + else 398 + cfg &= ~SD_CMD_OD; 399 + # endif 400 + 401 + 402 + if (ios->power_mode != MMC_POWER_OFF) 403 + cfg |= PWR_ON; 404 + else 405 + cfg &= ~PWR_ON; 406 + 407 + bfin_write_SDH_CFG(cfg); 408 + #endif 409 + SSYNC(); 410 + 411 + if (ios->power_mode == MMC_POWER_ON && ios->clock) { 365 412 unsigned char clk_div; 366 - ios_clk = 2 * ios->clock; 367 - sys_clk = get_sclk(); 368 - clk_div = sys_clk / ios_clk; 369 - if (sys_clk % ios_clk == 0) 370 - clk_div -= 1; 413 + clk_div = (get_sclk() / ios->clock - 1) / 2; 371 414 clk_div = min_t(unsigned char, clk_div, 0xFF); 372 415 clk_ctl |= clk_div; 373 416 clk_ctl |= CLK_E; 374 417 host->clk_div = clk_div; 418 + bfin_write_SDH_CLK_CTL(clk_ctl); 419 + 375 420 } else 376 421 sdh_stop_clock(host); 377 422 378 - if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) 379 - #ifdef CONFIG_SDH_BFIN_MISSING_CMD_PULLUP_WORKAROUND 380 - pwr_ctl |= ROD_CTL; 381 - #else 382 - pwr_ctl |= SD_CMD_OD | ROD_CTL; 383 - #endif 384 - 385 - if (ios->bus_width == MMC_BUS_WIDTH_4) { 386 - cfg = bfin_read_SDH_CFG(); 387 - cfg &= ~PD_SDDAT3; 388 - cfg |= PUP_SDDAT3; 389 - /* Enable 4 bit SDIO */ 390 - cfg |= (SD4E | MWE); 391 - bfin_write_SDH_CFG(cfg); 392 - clk_ctl |= WIDE_BUS; 393 - } else { 394 - cfg = bfin_read_SDH_CFG(); 395 - cfg |= MWE; 396 - bfin_write_SDH_CFG(cfg); 397 - } 398 - 399 - bfin_write_SDH_CLK_CTL(clk_ctl); 400 - 401 - host->power_mode = ios->power_mode; 423 + /* set up sdh interrupt mask*/ 402 424 if (ios->power_mode == MMC_POWER_ON) 403 - pwr_ctl |= PWR_ON; 404 - 405 - bfin_write_SDH_PWR_CTL(pwr_ctl); 425 + bfin_write_SDH_MASK0(DAT_END | DAT_TIME_OUT | DAT_CRC_FAIL | 426 + RX_OVERRUN | TX_UNDERRUN | CMD_SENT | CMD_RESP_END | 427 + CMD_TIME_OUT | CMD_CRC_FAIL); 428 + else 429 + bfin_write_SDH_MASK0(0); 406 430 SSYNC(); 407 431 408 - spin_unlock_irqrestore(&host->lock, flags); 432 + spin_unlock(&host->lock); 409 433 410 434 dev_dbg(mmc_dev(host->mmc), "SDH: clk_div = 0x%x actual clock:%ld expected clock:%d\n", 411 435 host->clk_div, ··· 463 405 { 464 406 struct sdh_host *host = devid; 465 407 466 - dev_dbg(mmc_dev(host->mmc), "%s enter, irq_stat: 0x%04x\n", __func__, 408 + dev_dbg(mmc_dev(host->mmc), "%s enter, irq_stat: 0x%04lx\n", __func__, 467 409 get_dma_curr_irqstat(host->dma_ch)); 468 410 clear_dma_irqstat(host->dma_ch); 469 411 SSYNC(); ··· 478 420 int handled = 0; 479 421 480 422 dev_dbg(mmc_dev(host->mmc), "%s enter\n", __func__); 423 + 424 + spin_lock(&host->lock); 425 + 481 426 status = bfin_read_SDH_E_STATUS(); 482 427 if (status & SD_CARD_DET) { 483 428 mmc_detect_change(host->mmc, 0); ··· 498 437 if (status & (DAT_END | DAT_TIME_OUT | DAT_CRC_FAIL | RX_OVERRUN | TX_UNDERRUN)) 499 438 handled |= sdh_data_done(host, status); 500 439 440 + spin_unlock(&host->lock); 441 + 501 442 dev_dbg(mmc_dev(host->mmc), "%s exit\n\n", __func__); 502 443 503 444 return IRQ_RETVAL(handled); 445 + } 446 + 447 + static void sdh_reset(void) 448 + { 449 + #if defined(CONFIG_BF54x) 450 + /* Secure Digital Host shares DMA with Nand controller */ 451 + bfin_write_DMAC1_PERIMUX(bfin_read_DMAC1_PERIMUX() | 0x1); 452 + #endif 453 + 454 + bfin_write_SDH_CFG(bfin_read_SDH_CFG() | CLKS_EN); 455 + SSYNC(); 456 + 457 + /* Disable card inserting detection pin. set MMC_CAP_NEEDS_POLL, and 458 + * mmc stack will do the detection. 459 + */ 460 + bfin_write_SDH_CFG((bfin_read_SDH_CFG() & 0x1F) | (PUP_SDDAT | PUP_SDDAT3)); 461 + SSYNC(); 504 462 } 505 463 506 464 static int __devinit sdh_probe(struct platform_device *pdev) ··· 542 462 } 543 463 544 464 mmc->ops = &sdh_ops; 545 - mmc->max_segs = 32; 465 + #if defined(CONFIG_BF51x) 466 + mmc->max_segs = 1; 467 + #else 468 + mmc->max_segs = PAGE_SIZE / sizeof(struct dma_desc_array); 469 + #endif 470 + #ifdef RSI_BLKSZ 471 + mmc->max_seg_size = -1; 472 + #else 546 473 mmc->max_seg_size = 1 << 16; 474 + #endif 547 475 mmc->max_blk_size = 1 << 11; 548 476 mmc->max_blk_count = 1 << 11; 549 477 mmc->max_req_size = PAGE_SIZE; ··· 561 473 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_NEEDS_POLL; 562 474 host = mmc_priv(mmc); 563 475 host->mmc = mmc; 476 + host->sclk = get_sclk(); 564 477 565 478 spin_lock_init(&host->lock); 566 479 host->irq = drv_data->irq_int0; ··· 586 497 } 587 498 588 499 platform_set_drvdata(pdev, mmc); 589 - mmc_add_host(mmc); 590 500 591 501 ret = request_irq(host->irq, sdh_stat_irq, 0, "SDH Status IRQ", host); 592 502 if (ret) { ··· 598 510 dev_err(&pdev->dev, "unable to request peripheral pins\n"); 599 511 goto out4; 600 512 } 601 - #if defined(CONFIG_BF54x) 602 - /* Secure Digital Host shares DMA with Nand controller */ 603 - bfin_write_DMAC1_PERIMUX(bfin_read_DMAC1_PERIMUX() | 0x1); 604 - #endif 605 513 606 - bfin_write_SDH_CFG(bfin_read_SDH_CFG() | CLKS_EN); 607 - SSYNC(); 514 + sdh_reset(); 608 515 609 - /* Disable card inserting detection pin. set MMC_CAP_NEES_POLL, and 610 - * mmc stack will do the detection. 611 - */ 612 - bfin_write_SDH_CFG((bfin_read_SDH_CFG() & 0x1F) | (PUP_SDDAT | PUP_SDDAT3)); 613 - SSYNC(); 614 - 516 + mmc_add_host(mmc); 615 517 return 0; 616 518 617 519 out4: ··· 649 571 if (mmc) 650 572 ret = mmc_suspend_host(mmc); 651 573 652 - bfin_write_SDH_PWR_CTL(bfin_read_SDH_PWR_CTL() & ~PWR_ON); 653 574 peripheral_free_list(drv_data->pin_req); 654 575 655 576 return ret; ··· 666 589 return ret; 667 590 } 668 591 669 - bfin_write_SDH_PWR_CTL(bfin_read_SDH_PWR_CTL() | PWR_ON); 670 - #if defined(CONFIG_BF54x) 671 - /* Secure Digital Host shares DMA with Nand controller */ 672 - bfin_write_DMAC1_PERIMUX(bfin_read_DMAC1_PERIMUX() | 0x1); 673 - #endif 674 - bfin_write_SDH_CFG(bfin_read_SDH_CFG() | CLKS_EN); 675 - SSYNC(); 676 - 677 - bfin_write_SDH_CFG((bfin_read_SDH_CFG() & 0x1F) | (PUP_SDDAT | PUP_SDDAT3)); 678 - SSYNC(); 592 + sdh_reset(); 679 593 680 594 if (mmc) 681 595 ret = mmc_resume_host(mmc);
+80 -187
drivers/mmc/host/davinci_mmc.c
··· 30 30 #include <linux/io.h> 31 31 #include <linux/irq.h> 32 32 #include <linux/delay.h> 33 + #include <linux/dmaengine.h> 33 34 #include <linux/dma-mapping.h> 35 + #include <linux/edma.h> 34 36 #include <linux/mmc/mmc.h> 35 37 36 38 #include <linux/platform_data/mmc-davinci.h> 37 - #include <mach/edma.h> 38 39 39 40 /* 40 41 * Register Definitions ··· 201 200 u32 bytes_left; 202 201 203 202 u32 rxdma, txdma; 203 + struct dma_chan *dma_tx; 204 + struct dma_chan *dma_rx; 204 205 bool use_dma; 205 206 bool do_dma; 206 207 bool sdio_int; 207 208 bool active_request; 208 - 209 - /* Scatterlist DMA uses one or more parameter RAM entries: 210 - * the main one (associated with rxdma or txdma) plus zero or 211 - * more links. The entries for a given transfer differ only 212 - * by memory buffer (address, length) and link field. 213 - */ 214 - struct edmacc_param tx_template; 215 - struct edmacc_param rx_template; 216 - unsigned n_link; 217 - u32 links[MAX_NR_SG - 1]; 218 209 219 210 /* For PIO we walk scatterlists one segment at a time. */ 220 211 unsigned int sg_len; ··· 403 410 404 411 static void davinci_abort_dma(struct mmc_davinci_host *host) 405 412 { 406 - int sync_dev; 413 + struct dma_chan *sync_dev; 407 414 408 415 if (host->data_dir == DAVINCI_MMC_DATADIR_READ) 409 - sync_dev = host->rxdma; 416 + sync_dev = host->dma_rx; 410 417 else 411 - sync_dev = host->txdma; 418 + sync_dev = host->dma_tx; 412 419 413 - edma_stop(sync_dev); 414 - edma_clean_channel(sync_dev); 420 + dmaengine_terminate_all(sync_dev); 415 421 } 416 422 417 - static void 418 - mmc_davinci_xfer_done(struct mmc_davinci_host *host, struct mmc_data *data); 419 - 420 - static void mmc_davinci_dma_cb(unsigned channel, u16 ch_status, void *data) 421 - { 422 - if (DMA_COMPLETE != ch_status) { 423 - struct mmc_davinci_host *host = data; 424 - 425 - /* Currently means: DMA Event Missed, or "null" transfer 426 - * request was seen. In the future, TC errors (like bad 427 - * addresses) might be presented too. 428 - */ 429 - dev_warn(mmc_dev(host->mmc), "DMA %s error\n", 430 - (host->data->flags & MMC_DATA_WRITE) 431 - ? "write" : "read"); 432 - host->data->error = -EIO; 433 - mmc_davinci_xfer_done(host, host->data); 434 - } 435 - } 436 - 437 - /* Set up tx or rx template, to be modified and updated later */ 438 - static void __init mmc_davinci_dma_setup(struct mmc_davinci_host *host, 439 - bool tx, struct edmacc_param *template) 440 - { 441 - unsigned sync_dev; 442 - const u16 acnt = 4; 443 - const u16 bcnt = rw_threshold >> 2; 444 - const u16 ccnt = 0; 445 - u32 src_port = 0; 446 - u32 dst_port = 0; 447 - s16 src_bidx, dst_bidx; 448 - s16 src_cidx, dst_cidx; 449 - 450 - /* 451 - * A-B Sync transfer: each DMA request is for one "frame" of 452 - * rw_threshold bytes, broken into "acnt"-size chunks repeated 453 - * "bcnt" times. Each segment needs "ccnt" such frames; since 454 - * we tell the block layer our mmc->max_seg_size limit, we can 455 - * trust (later) that it's within bounds. 456 - * 457 - * The FIFOs are read/written in 4-byte chunks (acnt == 4) and 458 - * EDMA will optimize memory operations to use larger bursts. 459 - */ 460 - if (tx) { 461 - sync_dev = host->txdma; 462 - 463 - /* src_prt, ccnt, and link to be set up later */ 464 - src_bidx = acnt; 465 - src_cidx = acnt * bcnt; 466 - 467 - dst_port = host->mem_res->start + DAVINCI_MMCDXR; 468 - dst_bidx = 0; 469 - dst_cidx = 0; 470 - } else { 471 - sync_dev = host->rxdma; 472 - 473 - src_port = host->mem_res->start + DAVINCI_MMCDRR; 474 - src_bidx = 0; 475 - src_cidx = 0; 476 - 477 - /* dst_prt, ccnt, and link to be set up later */ 478 - dst_bidx = acnt; 479 - dst_cidx = acnt * bcnt; 480 - } 481 - 482 - /* 483 - * We can't use FIFO mode for the FIFOs because MMC FIFO addresses 484 - * are not 256-bit (32-byte) aligned. So we use INCR, and the W8BIT 485 - * parameter is ignored. 486 - */ 487 - edma_set_src(sync_dev, src_port, INCR, W8BIT); 488 - edma_set_dest(sync_dev, dst_port, INCR, W8BIT); 489 - 490 - edma_set_src_index(sync_dev, src_bidx, src_cidx); 491 - edma_set_dest_index(sync_dev, dst_bidx, dst_cidx); 492 - 493 - edma_set_transfer_params(sync_dev, acnt, bcnt, ccnt, 8, ABSYNC); 494 - 495 - edma_read_slot(sync_dev, template); 496 - 497 - /* don't bother with irqs or chaining */ 498 - template->opt |= EDMA_CHAN_SLOT(sync_dev) << 12; 499 - } 500 - 501 - static void mmc_davinci_send_dma_request(struct mmc_davinci_host *host, 423 + static int mmc_davinci_send_dma_request(struct mmc_davinci_host *host, 502 424 struct mmc_data *data) 503 425 { 504 - struct edmacc_param *template; 505 - int channel, slot; 506 - unsigned link; 507 - struct scatterlist *sg; 508 - unsigned sg_len; 509 - unsigned bytes_left = host->bytes_left; 510 - const unsigned shift = ffs(rw_threshold) - 1; 426 + struct dma_chan *chan; 427 + struct dma_async_tx_descriptor *desc; 428 + int ret = 0; 511 429 512 430 if (host->data_dir == DAVINCI_MMC_DATADIR_WRITE) { 513 - template = &host->tx_template; 514 - channel = host->txdma; 431 + struct dma_slave_config dma_tx_conf = { 432 + .direction = DMA_MEM_TO_DEV, 433 + .dst_addr = host->mem_res->start + DAVINCI_MMCDXR, 434 + .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, 435 + .dst_maxburst = 436 + rw_threshold / DMA_SLAVE_BUSWIDTH_4_BYTES, 437 + }; 438 + chan = host->dma_tx; 439 + dmaengine_slave_config(host->dma_tx, &dma_tx_conf); 440 + 441 + desc = dmaengine_prep_slave_sg(host->dma_tx, 442 + data->sg, 443 + host->sg_len, 444 + DMA_MEM_TO_DEV, 445 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 446 + if (!desc) { 447 + dev_dbg(mmc_dev(host->mmc), 448 + "failed to allocate DMA TX descriptor"); 449 + ret = -1; 450 + goto out; 451 + } 515 452 } else { 516 - template = &host->rx_template; 517 - channel = host->rxdma; 453 + struct dma_slave_config dma_rx_conf = { 454 + .direction = DMA_DEV_TO_MEM, 455 + .src_addr = host->mem_res->start + DAVINCI_MMCDRR, 456 + .src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, 457 + .src_maxburst = 458 + rw_threshold / DMA_SLAVE_BUSWIDTH_4_BYTES, 459 + }; 460 + chan = host->dma_rx; 461 + dmaengine_slave_config(host->dma_rx, &dma_rx_conf); 462 + 463 + desc = dmaengine_prep_slave_sg(host->dma_rx, 464 + data->sg, 465 + host->sg_len, 466 + DMA_DEV_TO_MEM, 467 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 468 + if (!desc) { 469 + dev_dbg(mmc_dev(host->mmc), 470 + "failed to allocate DMA RX descriptor"); 471 + ret = -1; 472 + goto out; 473 + } 518 474 } 519 475 520 - /* We know sg_len and ccnt will never be out of range because 521 - * we told the mmc layer which in turn tells the block layer 522 - * to ensure that it only hands us one scatterlist segment 523 - * per EDMA PARAM entry. Update the PARAM 524 - * entries needed for each segment of this scatterlist. 525 - */ 526 - for (slot = channel, link = 0, sg = data->sg, sg_len = host->sg_len; 527 - sg_len-- != 0 && bytes_left; 528 - sg = sg_next(sg), slot = host->links[link++]) { 529 - u32 buf = sg_dma_address(sg); 530 - unsigned count = sg_dma_len(sg); 476 + dmaengine_submit(desc); 477 + dma_async_issue_pending(chan); 531 478 532 - template->link_bcntrld = sg_len 533 - ? (EDMA_CHAN_SLOT(host->links[link]) << 5) 534 - : 0xffff; 535 - 536 - if (count > bytes_left) 537 - count = bytes_left; 538 - bytes_left -= count; 539 - 540 - if (host->data_dir == DAVINCI_MMC_DATADIR_WRITE) 541 - template->src = buf; 542 - else 543 - template->dst = buf; 544 - template->ccnt = count >> shift; 545 - 546 - edma_write_slot(slot, template); 547 - } 548 - 549 - if (host->version == MMC_CTLR_VERSION_2) 550 - edma_clear_event(channel); 551 - 552 - edma_start(channel); 479 + out: 480 + return ret; 553 481 } 554 482 555 483 static int mmc_davinci_start_dma_transfer(struct mmc_davinci_host *host, ··· 478 564 { 479 565 int i; 480 566 int mask = rw_threshold - 1; 567 + int ret = 0; 481 568 482 569 host->sg_len = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len, 483 570 ((data->flags & MMC_DATA_WRITE) ··· 498 583 } 499 584 500 585 host->do_dma = 1; 501 - mmc_davinci_send_dma_request(host, data); 586 + ret = mmc_davinci_send_dma_request(host, data); 502 587 503 - return 0; 588 + return ret; 504 589 } 505 590 506 591 static void __init_or_module 507 592 davinci_release_dma_channels(struct mmc_davinci_host *host) 508 593 { 509 - unsigned i; 510 - 511 594 if (!host->use_dma) 512 595 return; 513 596 514 - for (i = 0; i < host->n_link; i++) 515 - edma_free_slot(host->links[i]); 516 - 517 - edma_free_channel(host->txdma); 518 - edma_free_channel(host->rxdma); 597 + dma_release_channel(host->dma_tx); 598 + dma_release_channel(host->dma_rx); 519 599 } 520 600 521 601 static int __init davinci_acquire_dma_channels(struct mmc_davinci_host *host) 522 602 { 523 - u32 link_size; 524 - int r, i; 603 + int r; 604 + dma_cap_mask_t mask; 525 605 526 - /* Acquire master DMA write channel */ 527 - r = edma_alloc_channel(host->txdma, mmc_davinci_dma_cb, host, 528 - EVENTQ_DEFAULT); 529 - if (r < 0) { 530 - dev_warn(mmc_dev(host->mmc), "alloc %s channel err %d\n", 531 - "tx", r); 532 - return r; 606 + dma_cap_zero(mask); 607 + dma_cap_set(DMA_SLAVE, mask); 608 + 609 + host->dma_tx = 610 + dma_request_channel(mask, edma_filter_fn, &host->txdma); 611 + if (!host->dma_tx) { 612 + dev_err(mmc_dev(host->mmc), "Can't get dma_tx channel\n"); 613 + return -ENODEV; 533 614 } 534 - mmc_davinci_dma_setup(host, true, &host->tx_template); 535 615 536 - /* Acquire master DMA read channel */ 537 - r = edma_alloc_channel(host->rxdma, mmc_davinci_dma_cb, host, 538 - EVENTQ_DEFAULT); 539 - if (r < 0) { 540 - dev_warn(mmc_dev(host->mmc), "alloc %s channel err %d\n", 541 - "rx", r); 616 + host->dma_rx = 617 + dma_request_channel(mask, edma_filter_fn, &host->rxdma); 618 + if (!host->dma_rx) { 619 + dev_err(mmc_dev(host->mmc), "Can't get dma_rx channel\n"); 620 + r = -ENODEV; 542 621 goto free_master_write; 543 622 } 544 - mmc_davinci_dma_setup(host, false, &host->rx_template); 545 - 546 - /* Allocate parameter RAM slots, which will later be bound to a 547 - * channel as needed to handle a scatterlist. 548 - */ 549 - link_size = min_t(unsigned, host->nr_sg, ARRAY_SIZE(host->links)); 550 - for (i = 0; i < link_size; i++) { 551 - r = edma_alloc_slot(EDMA_CTLR(host->txdma), EDMA_SLOT_ANY); 552 - if (r < 0) { 553 - dev_dbg(mmc_dev(host->mmc), "dma PaRAM alloc --> %d\n", 554 - r); 555 - break; 556 - } 557 - host->links[i] = r; 558 - } 559 - host->n_link = i; 560 623 561 624 return 0; 562 625 563 626 free_master_write: 564 - edma_free_channel(host->txdma); 627 + dma_release_channel(host->dma_tx); 565 628 566 629 return r; 567 630 } ··· 1252 1359 * Each hw_seg uses one EDMA parameter RAM slot, always one 1253 1360 * channel and then usually some linked slots. 1254 1361 */ 1255 - mmc->max_segs = 1 + host->n_link; 1362 + mmc->max_segs = MAX_NR_SG; 1256 1363 1257 1364 /* EDMA limit per hw segment (one or two MBytes) */ 1258 1365 mmc->max_seg_size = MAX_CCNT * rw_threshold;
+253
drivers/mmc/host/dw_mmc-exynos.c
··· 1 + /* 2 + * Exynos Specific Extensions for Synopsys DW Multimedia Card Interface driver 3 + * 4 + * Copyright (C) 2012, Samsung Electronics Co., Ltd. 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + */ 11 + 12 + #include <linux/module.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/clk.h> 15 + #include <linux/mmc/host.h> 16 + #include <linux/mmc/dw_mmc.h> 17 + #include <linux/of.h> 18 + #include <linux/of_gpio.h> 19 + 20 + #include "dw_mmc.h" 21 + #include "dw_mmc-pltfm.h" 22 + 23 + #define NUM_PINS(x) (x + 2) 24 + 25 + #define SDMMC_CLKSEL 0x09C 26 + #define SDMMC_CLKSEL_CCLK_SAMPLE(x) (((x) & 7) << 0) 27 + #define SDMMC_CLKSEL_CCLK_DRIVE(x) (((x) & 7) << 16) 28 + #define SDMMC_CLKSEL_CCLK_DIVIDER(x) (((x) & 7) << 24) 29 + #define SDMMC_CLKSEL_GET_DRV_WD3(x) (((x) >> 16) & 0x7) 30 + #define SDMMC_CLKSEL_TIMING(x, y, z) (SDMMC_CLKSEL_CCLK_SAMPLE(x) | \ 31 + SDMMC_CLKSEL_CCLK_DRIVE(y) | \ 32 + SDMMC_CLKSEL_CCLK_DIVIDER(z)) 33 + 34 + #define SDMMC_CMD_USE_HOLD_REG BIT(29) 35 + 36 + #define EXYNOS4210_FIXED_CIU_CLK_DIV 2 37 + #define EXYNOS4412_FIXED_CIU_CLK_DIV 4 38 + 39 + /* Variations in Exynos specific dw-mshc controller */ 40 + enum dw_mci_exynos_type { 41 + DW_MCI_TYPE_EXYNOS4210, 42 + DW_MCI_TYPE_EXYNOS4412, 43 + DW_MCI_TYPE_EXYNOS5250, 44 + }; 45 + 46 + /* Exynos implementation specific driver private data */ 47 + struct dw_mci_exynos_priv_data { 48 + enum dw_mci_exynos_type ctrl_type; 49 + u8 ciu_div; 50 + u32 sdr_timing; 51 + u32 ddr_timing; 52 + }; 53 + 54 + static struct dw_mci_exynos_compatible { 55 + char *compatible; 56 + enum dw_mci_exynos_type ctrl_type; 57 + } exynos_compat[] = { 58 + { 59 + .compatible = "samsung,exynos4210-dw-mshc", 60 + .ctrl_type = DW_MCI_TYPE_EXYNOS4210, 61 + }, { 62 + .compatible = "samsung,exynos4412-dw-mshc", 63 + .ctrl_type = DW_MCI_TYPE_EXYNOS4412, 64 + }, { 65 + .compatible = "samsung,exynos5250-dw-mshc", 66 + .ctrl_type = DW_MCI_TYPE_EXYNOS5250, 67 + }, 68 + }; 69 + 70 + static int dw_mci_exynos_priv_init(struct dw_mci *host) 71 + { 72 + struct dw_mci_exynos_priv_data *priv; 73 + int idx; 74 + 75 + priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); 76 + if (!priv) { 77 + dev_err(host->dev, "mem alloc failed for private data\n"); 78 + return -ENOMEM; 79 + } 80 + 81 + for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) { 82 + if (of_device_is_compatible(host->dev->of_node, 83 + exynos_compat[idx].compatible)) 84 + priv->ctrl_type = exynos_compat[idx].ctrl_type; 85 + } 86 + 87 + host->priv = priv; 88 + return 0; 89 + } 90 + 91 + static int dw_mci_exynos_setup_clock(struct dw_mci *host) 92 + { 93 + struct dw_mci_exynos_priv_data *priv = host->priv; 94 + 95 + if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5250) 96 + host->bus_hz /= (priv->ciu_div + 1); 97 + else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412) 98 + host->bus_hz /= EXYNOS4412_FIXED_CIU_CLK_DIV; 99 + else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210) 100 + host->bus_hz /= EXYNOS4210_FIXED_CIU_CLK_DIV; 101 + 102 + return 0; 103 + } 104 + 105 + static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr) 106 + { 107 + /* 108 + * Exynos4412 and Exynos5250 extends the use of CMD register with the 109 + * use of bit 29 (which is reserved on standard MSHC controllers) for 110 + * optionally bypassing the HOLD register for command and data. The 111 + * HOLD register should be bypassed in case there is no phase shift 112 + * applied on CMD/DATA that is sent to the card. 113 + */ 114 + if (SDMMC_CLKSEL_GET_DRV_WD3(mci_readl(host, CLKSEL))) 115 + *cmdr |= SDMMC_CMD_USE_HOLD_REG; 116 + } 117 + 118 + static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios) 119 + { 120 + struct dw_mci_exynos_priv_data *priv = host->priv; 121 + 122 + if (ios->timing == MMC_TIMING_UHS_DDR50) 123 + mci_writel(host, CLKSEL, priv->ddr_timing); 124 + else 125 + mci_writel(host, CLKSEL, priv->sdr_timing); 126 + } 127 + 128 + static int dw_mci_exynos_parse_dt(struct dw_mci *host) 129 + { 130 + struct dw_mci_exynos_priv_data *priv = host->priv; 131 + struct device_node *np = host->dev->of_node; 132 + u32 timing[2]; 133 + u32 div = 0; 134 + int ret; 135 + 136 + of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div); 137 + priv->ciu_div = div; 138 + 139 + ret = of_property_read_u32_array(np, 140 + "samsung,dw-mshc-sdr-timing", timing, 2); 141 + if (ret) 142 + return ret; 143 + 144 + priv->sdr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); 145 + 146 + ret = of_property_read_u32_array(np, 147 + "samsung,dw-mshc-ddr-timing", timing, 2); 148 + if (ret) 149 + return ret; 150 + 151 + priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); 152 + return 0; 153 + } 154 + 155 + static int dw_mci_exynos_setup_bus(struct dw_mci *host, 156 + struct device_node *slot_np, u8 bus_width) 157 + { 158 + int idx, gpio, ret; 159 + 160 + if (!slot_np) 161 + return -EINVAL; 162 + 163 + /* cmd + clock + bus-width pins */ 164 + for (idx = 0; idx < NUM_PINS(bus_width); idx++) { 165 + gpio = of_get_gpio(slot_np, idx); 166 + if (!gpio_is_valid(gpio)) { 167 + dev_err(host->dev, "invalid gpio: %d\n", gpio); 168 + return -EINVAL; 169 + } 170 + 171 + ret = devm_gpio_request(host->dev, gpio, "dw-mci-bus"); 172 + if (ret) { 173 + dev_err(host->dev, "gpio [%d] request failed\n", gpio); 174 + return -EBUSY; 175 + } 176 + } 177 + 178 + gpio = of_get_named_gpio(slot_np, "wp-gpios", 0); 179 + if (gpio_is_valid(gpio)) { 180 + if (devm_gpio_request(host->dev, gpio, "dw-mci-wp")) 181 + dev_info(host->dev, "gpio [%d] request failed\n", 182 + gpio); 183 + } else { 184 + dev_info(host->dev, "wp gpio not available"); 185 + host->pdata->quirks |= DW_MCI_QUIRK_NO_WRITE_PROTECT; 186 + } 187 + 188 + if (host->pdata->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION) 189 + return 0; 190 + 191 + gpio = of_get_named_gpio(slot_np, "samsung,cd-pinmux-gpio", 0); 192 + if (gpio_is_valid(gpio)) { 193 + if (devm_gpio_request(host->dev, gpio, "dw-mci-cd")) 194 + dev_err(host->dev, "gpio [%d] request failed\n", gpio); 195 + } else { 196 + dev_info(host->dev, "cd gpio not available"); 197 + } 198 + 199 + return 0; 200 + } 201 + 202 + /* Exynos5250 controller specific capabilities */ 203 + static unsigned long exynos5250_dwmmc_caps[4] = { 204 + MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR | 205 + MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23, 206 + MMC_CAP_CMD23, 207 + MMC_CAP_CMD23, 208 + MMC_CAP_CMD23, 209 + }; 210 + 211 + static struct dw_mci_drv_data exynos5250_drv_data = { 212 + .caps = exynos5250_dwmmc_caps, 213 + .init = dw_mci_exynos_priv_init, 214 + .setup_clock = dw_mci_exynos_setup_clock, 215 + .prepare_command = dw_mci_exynos_prepare_command, 216 + .set_ios = dw_mci_exynos_set_ios, 217 + .parse_dt = dw_mci_exynos_parse_dt, 218 + .setup_bus = dw_mci_exynos_setup_bus, 219 + }; 220 + 221 + static const struct of_device_id dw_mci_exynos_match[] = { 222 + { .compatible = "samsung,exynos5250-dw-mshc", 223 + .data = (void *)&exynos5250_drv_data, }, 224 + {}, 225 + }; 226 + MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match); 227 + 228 + int dw_mci_exynos_probe(struct platform_device *pdev) 229 + { 230 + struct dw_mci_drv_data *drv_data; 231 + const struct of_device_id *match; 232 + 233 + match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node); 234 + drv_data = match->data; 235 + return dw_mci_pltfm_register(pdev, drv_data); 236 + } 237 + 238 + static struct platform_driver dw_mci_exynos_pltfm_driver = { 239 + .probe = dw_mci_exynos_probe, 240 + .remove = __exit_p(dw_mci_pltfm_remove), 241 + .driver = { 242 + .name = "dwmmc_exynos", 243 + .of_match_table = of_match_ptr(dw_mci_exynos_match), 244 + .pm = &dw_mci_pltfm_pmops, 245 + }, 246 + }; 247 + 248 + module_platform_driver(dw_mci_exynos_pltfm_driver); 249 + 250 + MODULE_DESCRIPTION("Samsung Specific DW-MSHC Driver Extension"); 251 + MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com"); 252 + MODULE_LICENSE("GPL v2"); 253 + MODULE_ALIAS("platform:dwmmc-exynos");
+2 -13
drivers/mmc/host/dw_mmc-pci.c
··· 59 59 60 60 host->irq = pdev->irq; 61 61 host->irq_flags = IRQF_SHARED; 62 - host->dev = pdev->dev; 62 + host->dev = &pdev->dev; 63 63 host->pdata = &pci_board_data; 64 64 65 65 host->regs = pci_iomap(pdev, PCI_BAR_NO, COMPLETE_BAR); ··· 140 140 }, 141 141 }; 142 142 143 - static int __init dw_mci_init(void) 144 - { 145 - return pci_register_driver(&dw_mci_pci_driver); 146 - } 147 - 148 - static void __exit dw_mci_exit(void) 149 - { 150 - pci_unregister_driver(&dw_mci_pci_driver); 151 - } 152 - 153 - module_init(dw_mci_init); 154 - module_exit(dw_mci_exit); 143 + module_pci_driver(dw_mci_pci_driver); 155 144 156 145 MODULE_DESCRIPTION("DW Multimedia Card PCI Interface driver"); 157 146 MODULE_AUTHOR("Shashidhar Hiremath <shashidharh@vayavyalabs.com>");
+37 -25
drivers/mmc/host/dw_mmc-pltfm.c
··· 19 19 #include <linux/mmc/host.h> 20 20 #include <linux/mmc/mmc.h> 21 21 #include <linux/mmc/dw_mmc.h> 22 + #include <linux/of.h> 23 + 22 24 #include "dw_mmc.h" 23 25 24 - static int dw_mci_pltfm_probe(struct platform_device *pdev) 26 + int dw_mci_pltfm_register(struct platform_device *pdev, 27 + struct dw_mci_drv_data *drv_data) 25 28 { 26 29 struct dw_mci *host; 27 30 struct resource *regs; 28 31 int ret; 29 32 30 - host = kzalloc(sizeof(struct dw_mci), GFP_KERNEL); 33 + host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL); 31 34 if (!host) 32 35 return -ENOMEM; 33 36 34 37 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 35 - if (!regs) { 36 - ret = -ENXIO; 37 - goto err_free; 38 - } 38 + if (!regs) 39 + return -ENXIO; 39 40 40 41 host->irq = platform_get_irq(pdev, 0); 41 - if (host->irq < 0) { 42 - ret = host->irq; 43 - goto err_free; 44 - } 42 + if (host->irq < 0) 43 + return host->irq; 45 44 46 - host->dev = pdev->dev; 45 + host->drv_data = drv_data; 46 + host->dev = &pdev->dev; 47 47 host->irq_flags = 0; 48 48 host->pdata = pdev->dev.platform_data; 49 - ret = -ENOMEM; 50 - host->regs = ioremap(regs->start, resource_size(regs)); 49 + host->regs = devm_request_and_ioremap(&pdev->dev, regs); 51 50 if (!host->regs) 52 - goto err_free; 51 + return -ENOMEM; 52 + 53 + if (host->drv_data->init) { 54 + ret = host->drv_data->init(host); 55 + if (ret) 56 + return ret; 57 + } 58 + 53 59 platform_set_drvdata(pdev, host); 54 60 ret = dw_mci_probe(host); 55 - if (ret) 56 - goto err_out; 57 - return ret; 58 - err_out: 59 - iounmap(host->regs); 60 - err_free: 61 - kfree(host); 62 61 return ret; 63 62 } 63 + EXPORT_SYMBOL_GPL(dw_mci_pltfm_register); 64 64 65 - static int __exit dw_mci_pltfm_remove(struct platform_device *pdev) 65 + static int __devinit dw_mci_pltfm_probe(struct platform_device *pdev) 66 + { 67 + return dw_mci_pltfm_register(pdev, NULL); 68 + } 69 + 70 + static int __devexit dw_mci_pltfm_remove(struct platform_device *pdev) 66 71 { 67 72 struct dw_mci *host = platform_get_drvdata(pdev); 68 73 69 74 platform_set_drvdata(pdev, NULL); 70 75 dw_mci_remove(host); 71 - iounmap(host->regs); 72 - kfree(host); 73 76 return 0; 74 77 } 78 + EXPORT_SYMBOL_GPL(dw_mci_pltfm_remove); 75 79 76 80 #ifdef CONFIG_PM_SLEEP 77 81 /* ··· 109 105 #define dw_mci_pltfm_resume NULL 110 106 #endif /* CONFIG_PM_SLEEP */ 111 107 112 - static SIMPLE_DEV_PM_OPS(dw_mci_pltfm_pmops, dw_mci_pltfm_suspend, dw_mci_pltfm_resume); 108 + SIMPLE_DEV_PM_OPS(dw_mci_pltfm_pmops, dw_mci_pltfm_suspend, dw_mci_pltfm_resume); 109 + EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops); 110 + 111 + static const struct of_device_id dw_mci_pltfm_match[] = { 112 + { .compatible = "snps,dw-mshc", }, 113 + {}, 114 + }; 115 + MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match); 113 116 114 117 static struct platform_driver dw_mci_pltfm_driver = { 115 118 .remove = __exit_p(dw_mci_pltfm_remove), 116 119 .driver = { 117 120 .name = "dw_mmc", 121 + .of_match_table = of_match_ptr(dw_mci_pltfm_match), 118 122 .pm = &dw_mci_pltfm_pmops, 119 123 }, 120 124 };
+20
drivers/mmc/host/dw_mmc-pltfm.h
··· 1 + /* 2 + * Synopsys DesignWare Multimedia Card Interface Platform driver 3 + * 4 + * Copyright (C) 2012, Samsung Electronics Co., Ltd. 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + */ 11 + 12 + #ifndef _DW_MMC_PLTFM_H_ 13 + #define _DW_MMC_PLTFM_H_ 14 + 15 + extern int dw_mci_pltfm_register(struct platform_device *pdev, 16 + struct dw_mci_drv_data *drv_data); 17 + extern int __devexit dw_mci_pltfm_remove(struct platform_device *pdev); 18 + extern const struct dev_pm_ops dw_mci_pltfm_pmops; 19 + 20 + #endif /* _DW_MMC_PLTFM_H_ */
+262 -66
drivers/mmc/host/dw_mmc.c
··· 33 33 #include <linux/bitops.h> 34 34 #include <linux/regulator/consumer.h> 35 35 #include <linux/workqueue.h> 36 + #include <linux/of.h> 36 37 37 38 #include "dw_mmc.h" 38 39 ··· 231 230 static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd) 232 231 { 233 232 struct mmc_data *data; 233 + struct dw_mci_slot *slot = mmc_priv(mmc); 234 234 u32 cmdr; 235 235 cmd->error = -EINPROGRESS; 236 236 ··· 261 259 cmdr |= SDMMC_CMD_DAT_WR; 262 260 } 263 261 262 + if (slot->host->drv_data->prepare_command) 263 + slot->host->drv_data->prepare_command(slot->host, &cmdr); 264 + 264 265 return cmdr; 265 266 } 266 267 ··· 271 266 struct mmc_command *cmd, u32 cmd_flags) 272 267 { 273 268 host->cmd = cmd; 274 - dev_vdbg(&host->dev, 269 + dev_vdbg(host->dev, 275 270 "start command: ARGR=0x%08x CMDR=0x%08x\n", 276 271 cmd->arg, cmd_flags); 277 272 ··· 313 308 314 309 if (data) 315 310 if (!data->host_cookie) 316 - dma_unmap_sg(&host->dev, 311 + dma_unmap_sg(host->dev, 317 312 data->sg, 318 313 data->sg_len, 319 314 dw_mci_get_dma_dir(data)); ··· 339 334 { 340 335 struct mmc_data *data = host->data; 341 336 342 - dev_vdbg(&host->dev, "DMA complete\n"); 337 + dev_vdbg(host->dev, "DMA complete\n"); 343 338 344 339 host->dma_ops->cleanup(host); 345 340 ··· 410 405 static int dw_mci_idmac_init(struct dw_mci *host) 411 406 { 412 407 struct idmac_desc *p; 413 - int i, dma_support; 408 + int i; 414 409 415 410 /* Number of descriptors in the ring buffer */ 416 411 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc); 417 - 418 - /* Check if Hardware Configuration Register has support for DMA */ 419 - dma_support = (mci_readl(host, HCON) >> 16) & 0x3; 420 - 421 - if (!dma_support || dma_support > 2) { 422 - dev_err(&host->dev, 423 - "Host Controller does not support IDMA Tx.\n"); 424 - host->dma_ops = NULL; 425 - return -ENODEV; 426 - } 427 - 428 - dev_info(&host->dev, "Using internal DMA controller.\n"); 429 412 430 413 /* Forward link the descriptor list */ 431 414 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++) ··· 469 476 return -EINVAL; 470 477 } 471 478 472 - sg_len = dma_map_sg(&host->dev, 479 + sg_len = dma_map_sg(host->dev, 473 480 data->sg, 474 481 data->sg_len, 475 482 dw_mci_get_dma_dir(data)); ··· 512 519 return; 513 520 514 521 if (data->host_cookie) 515 - dma_unmap_sg(&slot->host->dev, 522 + dma_unmap_sg(slot->host->dev, 516 523 data->sg, 517 524 data->sg_len, 518 525 dw_mci_get_dma_dir(data)); ··· 538 545 539 546 host->using_dma = 1; 540 547 541 - dev_vdbg(&host->dev, 548 + dev_vdbg(host->dev, 542 549 "sd sg_cpu: %#lx sg_dma: %#lx sg_len: %d\n", 543 550 (unsigned long)host->sg_cpu, (unsigned long)host->sg_dma, 544 551 sg_len); ··· 807 814 slot->clock = ios->clock; 808 815 } 809 816 817 + if (slot->host->drv_data->set_ios) 818 + slot->host->drv_data->set_ios(slot->host, ios); 819 + 810 820 switch (ios->power_mode) { 811 821 case MMC_POWER_UP: 812 822 set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags); ··· 826 830 struct dw_mci_board *brd = slot->host->pdata; 827 831 828 832 /* Use platform get_ro function, else try on board write protect */ 829 - if (brd->get_ro) 833 + if (brd->quirks & DW_MCI_QUIRK_NO_WRITE_PROTECT) 834 + read_only = 0; 835 + else if (brd->get_ro) 830 836 read_only = brd->get_ro(slot->id); 831 837 else 832 838 read_only = ··· 937 939 slot = list_entry(host->queue.next, 938 940 struct dw_mci_slot, queue_node); 939 941 list_del(&slot->queue_node); 940 - dev_vdbg(&host->dev, "list not empty: %s is next\n", 942 + dev_vdbg(host->dev, "list not empty: %s is next\n", 941 943 mmc_hostname(slot->mmc)); 942 944 host->state = STATE_SENDING_CMD; 943 945 dw_mci_start_request(host, slot); 944 946 } else { 945 - dev_vdbg(&host->dev, "list empty\n"); 947 + dev_vdbg(host->dev, "list empty\n"); 946 948 host->state = STATE_IDLE; 947 949 } 948 950 ··· 1081 1083 data->bytes_xfered = 0; 1082 1084 data->error = -ETIMEDOUT; 1083 1085 } else { 1084 - dev_err(&host->dev, 1086 + dev_err(host->dev, 1085 1087 "data FIFO error " 1086 1088 "(status=%08x)\n", 1087 1089 status); ··· 1765 1767 } 1766 1768 } 1767 1769 1768 - static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id) 1770 + #ifdef CONFIG_OF 1771 + /* given a slot id, find out the device node representing that slot */ 1772 + static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot) 1773 + { 1774 + struct device_node *np; 1775 + const __be32 *addr; 1776 + int len; 1777 + 1778 + if (!dev || !dev->of_node) 1779 + return NULL; 1780 + 1781 + for_each_child_of_node(dev->of_node, np) { 1782 + addr = of_get_property(np, "reg", &len); 1783 + if (!addr || (len < sizeof(int))) 1784 + continue; 1785 + if (be32_to_cpup(addr) == slot) 1786 + return np; 1787 + } 1788 + return NULL; 1789 + } 1790 + 1791 + /* find out bus-width for a given slot */ 1792 + static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot) 1793 + { 1794 + struct device_node *np = dw_mci_of_find_slot_node(dev, slot); 1795 + u32 bus_wd = 1; 1796 + 1797 + if (!np) 1798 + return 1; 1799 + 1800 + if (of_property_read_u32(np, "bus-width", &bus_wd)) 1801 + dev_err(dev, "bus-width property not found, assuming width" 1802 + " as 1\n"); 1803 + return bus_wd; 1804 + } 1805 + #else /* CONFIG_OF */ 1806 + static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot) 1807 + { 1808 + return 1; 1809 + } 1810 + static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot) 1811 + { 1812 + return NULL; 1813 + } 1814 + #endif /* CONFIG_OF */ 1815 + 1816 + static int dw_mci_init_slot(struct dw_mci *host, unsigned int id) 1769 1817 { 1770 1818 struct mmc_host *mmc; 1771 1819 struct dw_mci_slot *slot; 1820 + int ctrl_id, ret; 1821 + u8 bus_width; 1772 1822 1773 - mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), &host->dev); 1823 + mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev); 1774 1824 if (!mmc) 1775 1825 return -ENOMEM; 1776 1826 ··· 1826 1780 slot->id = id; 1827 1781 slot->mmc = mmc; 1828 1782 slot->host = host; 1783 + host->slot[id] = slot; 1829 1784 1830 1785 mmc->ops = &dw_mci_ops; 1831 1786 mmc->f_min = DIV_ROUND_UP(host->bus_hz, 510); ··· 1847 1800 if (host->pdata->caps) 1848 1801 mmc->caps = host->pdata->caps; 1849 1802 1803 + if (host->dev->of_node) { 1804 + ctrl_id = of_alias_get_id(host->dev->of_node, "mshc"); 1805 + if (ctrl_id < 0) 1806 + ctrl_id = 0; 1807 + } else { 1808 + ctrl_id = to_platform_device(host->dev)->id; 1809 + } 1810 + if (host->drv_data && host->drv_data->caps) 1811 + mmc->caps |= host->drv_data->caps[ctrl_id]; 1812 + 1850 1813 if (host->pdata->caps2) 1851 1814 mmc->caps2 = host->pdata->caps2; 1852 1815 1853 1816 if (host->pdata->get_bus_wd) 1854 - if (host->pdata->get_bus_wd(slot->id) >= 4) 1855 - mmc->caps |= MMC_CAP_4_BIT_DATA; 1817 + bus_width = host->pdata->get_bus_wd(slot->id); 1818 + else if (host->dev->of_node) 1819 + bus_width = dw_mci_of_get_bus_wd(host->dev, slot->id); 1820 + else 1821 + bus_width = 1; 1822 + 1823 + if (host->drv_data->setup_bus) { 1824 + struct device_node *slot_np; 1825 + slot_np = dw_mci_of_find_slot_node(host->dev, slot->id); 1826 + ret = host->drv_data->setup_bus(host, slot_np, bus_width); 1827 + if (ret) 1828 + goto err_setup_bus; 1829 + } 1830 + 1831 + switch (bus_width) { 1832 + case 8: 1833 + mmc->caps |= MMC_CAP_8_BIT_DATA; 1834 + case 4: 1835 + mmc->caps |= MMC_CAP_4_BIT_DATA; 1836 + } 1856 1837 1857 1838 if (host->pdata->quirks & DW_MCI_QUIRK_HIGHSPEED) 1858 1839 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; 1859 - 1860 - if (mmc->caps2 & MMC_CAP2_POWEROFF_NOTIFY) 1861 - mmc->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT; 1862 - else 1863 - mmc->power_notify_type = MMC_HOST_PW_NOTIFY_NONE; 1864 1840 1865 1841 if (host->pdata->blk_settings) { 1866 1842 mmc->max_segs = host->pdata->blk_settings->max_segs; ··· 1920 1850 else 1921 1851 clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); 1922 1852 1923 - host->slot[id] = slot; 1924 1853 mmc_add_host(mmc); 1925 1854 1926 1855 #if defined(CONFIG_DEBUG_FS) ··· 1936 1867 queue_work(host->card_workqueue, &host->card_work); 1937 1868 1938 1869 return 0; 1870 + 1871 + err_setup_bus: 1872 + mmc_free_host(mmc); 1873 + return -EINVAL; 1939 1874 } 1940 1875 1941 1876 static void dw_mci_cleanup_slot(struct dw_mci_slot *slot, unsigned int id) ··· 1957 1884 static void dw_mci_init_dma(struct dw_mci *host) 1958 1885 { 1959 1886 /* Alloc memory for sg translation */ 1960 - host->sg_cpu = dma_alloc_coherent(&host->dev, PAGE_SIZE, 1887 + host->sg_cpu = dma_alloc_coherent(host->dev, PAGE_SIZE, 1961 1888 &host->sg_dma, GFP_KERNEL); 1962 1889 if (!host->sg_cpu) { 1963 - dev_err(&host->dev, "%s: could not alloc DMA memory\n", 1890 + dev_err(host->dev, "%s: could not alloc DMA memory\n", 1964 1891 __func__); 1965 1892 goto no_dma; 1966 1893 } ··· 1968 1895 /* Determine which DMA interface to use */ 1969 1896 #ifdef CONFIG_MMC_DW_IDMAC 1970 1897 host->dma_ops = &dw_mci_idmac_ops; 1898 + dev_info(&host->dev, "Using internal DMA controller.\n"); 1971 1899 #endif 1972 1900 1973 1901 if (!host->dma_ops) ··· 1977 1903 if (host->dma_ops->init && host->dma_ops->start && 1978 1904 host->dma_ops->stop && host->dma_ops->cleanup) { 1979 1905 if (host->dma_ops->init(host)) { 1980 - dev_err(&host->dev, "%s: Unable to initialize " 1906 + dev_err(host->dev, "%s: Unable to initialize " 1981 1907 "DMA Controller.\n", __func__); 1982 1908 goto no_dma; 1983 1909 } 1984 1910 } else { 1985 - dev_err(&host->dev, "DMA initialization not found.\n"); 1911 + dev_err(host->dev, "DMA initialization not found.\n"); 1986 1912 goto no_dma; 1987 1913 } 1988 1914 ··· 1990 1916 return; 1991 1917 1992 1918 no_dma: 1993 - dev_info(&host->dev, "Using PIO mode.\n"); 1919 + dev_info(host->dev, "Using PIO mode.\n"); 1994 1920 host->use_dma = 0; 1995 1921 return; 1996 1922 } ··· 2016 1942 return false; 2017 1943 } 2018 1944 1945 + #ifdef CONFIG_OF 1946 + static struct dw_mci_of_quirks { 1947 + char *quirk; 1948 + int id; 1949 + } of_quirks[] = { 1950 + { 1951 + .quirk = "supports-highspeed", 1952 + .id = DW_MCI_QUIRK_HIGHSPEED, 1953 + }, { 1954 + .quirk = "broken-cd", 1955 + .id = DW_MCI_QUIRK_BROKEN_CARD_DETECTION, 1956 + }, 1957 + }; 1958 + 1959 + static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host) 1960 + { 1961 + struct dw_mci_board *pdata; 1962 + struct device *dev = host->dev; 1963 + struct device_node *np = dev->of_node; 1964 + int idx, ret; 1965 + 1966 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 1967 + if (!pdata) { 1968 + dev_err(dev, "could not allocate memory for pdata\n"); 1969 + return ERR_PTR(-ENOMEM); 1970 + } 1971 + 1972 + /* find out number of slots supported */ 1973 + if (of_property_read_u32(dev->of_node, "num-slots", 1974 + &pdata->num_slots)) { 1975 + dev_info(dev, "num-slots property not found, " 1976 + "assuming 1 slot is available\n"); 1977 + pdata->num_slots = 1; 1978 + } 1979 + 1980 + /* get quirks */ 1981 + for (idx = 0; idx < ARRAY_SIZE(of_quirks); idx++) 1982 + if (of_get_property(np, of_quirks[idx].quirk, NULL)) 1983 + pdata->quirks |= of_quirks[idx].id; 1984 + 1985 + if (of_property_read_u32(np, "fifo-depth", &pdata->fifo_depth)) 1986 + dev_info(dev, "fifo-depth property not found, using " 1987 + "value of FIFOTH register as default\n"); 1988 + 1989 + of_property_read_u32(np, "card-detect-delay", &pdata->detect_delay_ms); 1990 + 1991 + if (host->drv_data->parse_dt) { 1992 + ret = host->drv_data->parse_dt(host); 1993 + if (ret) 1994 + return ERR_PTR(ret); 1995 + } 1996 + 1997 + return pdata; 1998 + } 1999 + 2000 + #else /* CONFIG_OF */ 2001 + static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host) 2002 + { 2003 + return ERR_PTR(-EINVAL); 2004 + } 2005 + #endif /* CONFIG_OF */ 2006 + 2019 2007 int dw_mci_probe(struct dw_mci *host) 2020 2008 { 2021 2009 int width, i, ret = 0; 2022 2010 u32 fifo_size; 2011 + int init_slots = 0; 2023 2012 2024 - if (!host->pdata || !host->pdata->init) { 2025 - dev_err(&host->dev, 2026 - "Platform data must supply init function\n"); 2027 - return -ENODEV; 2013 + if (!host->pdata) { 2014 + host->pdata = dw_mci_parse_dt(host); 2015 + if (IS_ERR(host->pdata)) { 2016 + dev_err(host->dev, "platform data not available\n"); 2017 + return -EINVAL; 2018 + } 2028 2019 } 2029 2020 2030 2021 if (!host->pdata->select_slot && host->pdata->num_slots > 1) { 2031 - dev_err(&host->dev, 2022 + dev_err(host->dev, 2032 2023 "Platform data must supply select_slot function\n"); 2033 2024 return -ENODEV; 2034 2025 } 2035 2026 2036 - if (!host->pdata->bus_hz) { 2037 - dev_err(&host->dev, 2038 - "Platform data must supply bus speed\n"); 2039 - return -ENODEV; 2027 + host->biu_clk = clk_get(host->dev, "biu"); 2028 + if (IS_ERR(host->biu_clk)) { 2029 + dev_dbg(host->dev, "biu clock not available\n"); 2030 + } else { 2031 + ret = clk_prepare_enable(host->biu_clk); 2032 + if (ret) { 2033 + dev_err(host->dev, "failed to enable biu clock\n"); 2034 + clk_put(host->biu_clk); 2035 + return ret; 2036 + } 2040 2037 } 2041 2038 2042 - host->bus_hz = host->pdata->bus_hz; 2039 + host->ciu_clk = clk_get(host->dev, "ciu"); 2040 + if (IS_ERR(host->ciu_clk)) { 2041 + dev_dbg(host->dev, "ciu clock not available\n"); 2042 + } else { 2043 + ret = clk_prepare_enable(host->ciu_clk); 2044 + if (ret) { 2045 + dev_err(host->dev, "failed to enable ciu clock\n"); 2046 + clk_put(host->ciu_clk); 2047 + goto err_clk_biu; 2048 + } 2049 + } 2050 + 2051 + if (IS_ERR(host->ciu_clk)) 2052 + host->bus_hz = host->pdata->bus_hz; 2053 + else 2054 + host->bus_hz = clk_get_rate(host->ciu_clk); 2055 + 2056 + if (host->drv_data->setup_clock) { 2057 + ret = host->drv_data->setup_clock(host); 2058 + if (ret) { 2059 + dev_err(host->dev, 2060 + "implementation specific clock setup failed\n"); 2061 + goto err_clk_ciu; 2062 + } 2063 + } 2064 + 2065 + if (!host->bus_hz) { 2066 + dev_err(host->dev, 2067 + "Platform data must supply bus speed\n"); 2068 + ret = -ENODEV; 2069 + goto err_clk_ciu; 2070 + } 2071 + 2043 2072 host->quirks = host->pdata->quirks; 2044 2073 2045 2074 spin_lock_init(&host->lock); ··· 2175 1998 } 2176 1999 2177 2000 /* Reset all blocks */ 2178 - if (!mci_wait_reset(&host->dev, host)) 2001 + if (!mci_wait_reset(host->dev, host)) 2179 2002 return -ENODEV; 2180 2003 2181 2004 host->dma_ops = host->pdata->dma_ops; ··· 2231 2054 /* We need at least one slot to succeed */ 2232 2055 for (i = 0; i < host->num_slots; i++) { 2233 2056 ret = dw_mci_init_slot(host, i); 2234 - if (ret) { 2235 - ret = -ENODEV; 2236 - goto err_init_slot; 2237 - } 2057 + if (ret) 2058 + dev_dbg(host->dev, "slot %d init failed\n", i); 2059 + else 2060 + init_slots++; 2061 + } 2062 + 2063 + if (init_slots) { 2064 + dev_info(host->dev, "%d slots initialized\n", init_slots); 2065 + } else { 2066 + dev_dbg(host->dev, "attempted to initialize %d slots, " 2067 + "but failed on all\n", host->num_slots); 2068 + goto err_init_slot; 2238 2069 } 2239 2070 2240 2071 /* ··· 2250 2065 * Need to check the version-id and set data-offset for DATA register. 2251 2066 */ 2252 2067 host->verid = SDMMC_GET_VERID(mci_readl(host, VERID)); 2253 - dev_info(&host->dev, "Version ID is %04x\n", host->verid); 2068 + dev_info(host->dev, "Version ID is %04x\n", host->verid); 2254 2069 2255 2070 if (host->verid < DW_MMC_240A) 2256 2071 host->data_offset = DATA_OFFSET; ··· 2267 2082 DW_MCI_ERROR_FLAGS | SDMMC_INT_CD); 2268 2083 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); /* Enable mci interrupt */ 2269 2084 2270 - dev_info(&host->dev, "DW MMC controller at irq %d, " 2085 + dev_info(host->dev, "DW MMC controller at irq %d, " 2271 2086 "%d bit host data width, " 2272 2087 "%u deep fifo\n", 2273 2088 host->irq, width, fifo_size); 2274 2089 if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) 2275 - dev_info(&host->dev, "Internal DMAC interrupt fix enabled.\n"); 2090 + dev_info(host->dev, "Internal DMAC interrupt fix enabled.\n"); 2276 2091 2277 2092 return 0; 2278 2093 2279 2094 err_init_slot: 2280 - /* De-init any initialized slots */ 2281 - while (i > 0) { 2282 - if (host->slot[i]) 2283 - dw_mci_cleanup_slot(host->slot[i], i); 2284 - i--; 2285 - } 2286 2095 free_irq(host->irq, host); 2287 2096 2288 2097 err_workqueue: ··· 2285 2106 err_dmaunmap: 2286 2107 if (host->use_dma && host->dma_ops->exit) 2287 2108 host->dma_ops->exit(host); 2288 - dma_free_coherent(&host->dev, PAGE_SIZE, 2109 + dma_free_coherent(host->dev, PAGE_SIZE, 2289 2110 host->sg_cpu, host->sg_dma); 2290 2111 2291 2112 if (host->vmmc) { 2292 2113 regulator_disable(host->vmmc); 2293 2114 regulator_put(host->vmmc); 2115 + } 2116 + 2117 + err_clk_ciu: 2118 + if (!IS_ERR(host->ciu_clk)) { 2119 + clk_disable_unprepare(host->ciu_clk); 2120 + clk_put(host->ciu_clk); 2121 + } 2122 + err_clk_biu: 2123 + if (!IS_ERR(host->biu_clk)) { 2124 + clk_disable_unprepare(host->biu_clk); 2125 + clk_put(host->biu_clk); 2294 2126 } 2295 2127 return ret; 2296 2128 } ··· 2315 2125 mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */ 2316 2126 2317 2127 for (i = 0; i < host->num_slots; i++) { 2318 - dev_dbg(&host->dev, "remove slot %d\n", i); 2128 + dev_dbg(host->dev, "remove slot %d\n", i); 2319 2129 if (host->slot[i]) 2320 2130 dw_mci_cleanup_slot(host->slot[i], i); 2321 2131 } ··· 2326 2136 2327 2137 free_irq(host->irq, host); 2328 2138 destroy_workqueue(host->card_workqueue); 2329 - dma_free_coherent(&host->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma); 2139 + dma_free_coherent(host->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma); 2330 2140 2331 2141 if (host->use_dma && host->dma_ops->exit) 2332 2142 host->dma_ops->exit(host); ··· 2336 2146 regulator_put(host->vmmc); 2337 2147 } 2338 2148 2149 + if (!IS_ERR(host->ciu_clk)) 2150 + clk_disable_unprepare(host->ciu_clk); 2151 + if (!IS_ERR(host->biu_clk)) 2152 + clk_disable_unprepare(host->biu_clk); 2153 + clk_put(host->ciu_clk); 2154 + clk_put(host->biu_clk); 2339 2155 } 2340 2156 EXPORT_SYMBOL(dw_mci_remove); 2341 2157 ··· 2384 2188 if (host->vmmc) 2385 2189 regulator_enable(host->vmmc); 2386 2190 2387 - if (!mci_wait_reset(&host->dev, host)) { 2191 + if (!mci_wait_reset(host->dev, host)) { 2388 2192 ret = -ENODEV; 2389 2193 return ret; 2390 2194 }
+24
drivers/mmc/host/dw_mmc.h
··· 182 182 extern int dw_mci_resume(struct dw_mci *host); 183 183 #endif 184 184 185 + /** 186 + * dw_mci driver data - dw-mshc implementation specific driver data. 187 + * @caps: mmc subsystem specified capabilities of the controller(s). 188 + * @init: early implementation specific initialization. 189 + * @setup_clock: implementation specific clock configuration. 190 + * @prepare_command: handle CMD register extensions. 191 + * @set_ios: handle bus specific extensions. 192 + * @parse_dt: parse implementation specific device tree properties. 193 + * @setup_bus: initialize io-interface 194 + * 195 + * Provide controller implementation specific extensions. The usage of this 196 + * data structure is fully optional and usage of each member in this structure 197 + * is optional as well. 198 + */ 199 + struct dw_mci_drv_data { 200 + unsigned long *caps; 201 + int (*init)(struct dw_mci *host); 202 + int (*setup_clock)(struct dw_mci *host); 203 + void (*prepare_command)(struct dw_mci *host, u32 *cmdr); 204 + void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios); 205 + int (*parse_dt)(struct dw_mci *host); 206 + int (*setup_bus)(struct dw_mci *host, 207 + struct device_node *slot_np, u8 bus_width); 208 + }; 185 209 #endif /* _DW_MMC_H_ */
+1 -14
drivers/mmc/host/mmc_spi.c
··· 1532 1532 .remove = __devexit_p(mmc_spi_remove), 1533 1533 }; 1534 1534 1535 - 1536 - static int __init mmc_spi_init(void) 1537 - { 1538 - return spi_register_driver(&mmc_spi_driver); 1539 - } 1540 - module_init(mmc_spi_init); 1541 - 1542 - 1543 - static void __exit mmc_spi_exit(void) 1544 - { 1545 - spi_unregister_driver(&mmc_spi_driver); 1546 - } 1547 - module_exit(mmc_spi_exit); 1548 - 1535 + module_spi_driver(mmc_spi_driver); 1549 1536 1550 1537 MODULE_AUTHOR("Mike Lavender, David Brownell, " 1551 1538 "Hans-Peter Nilsson, Jan Nikitenko");
+3 -10
drivers/mmc/host/mmci.c
··· 1309 1309 goto host_free; 1310 1310 } 1311 1311 1312 - ret = clk_prepare(host->clk); 1312 + ret = clk_prepare_enable(host->clk); 1313 1313 if (ret) 1314 1314 goto clk_free; 1315 - 1316 - ret = clk_enable(host->clk); 1317 - if (ret) 1318 - goto clk_unprep; 1319 1315 1320 1316 host->plat = plat; 1321 1317 host->variant = variant; ··· 1511 1515 err_gpio_cd: 1512 1516 iounmap(host->base); 1513 1517 clk_disable: 1514 - clk_disable(host->clk); 1515 - clk_unprep: 1516 - clk_unprepare(host->clk); 1518 + clk_disable_unprepare(host->clk); 1517 1519 clk_free: 1518 1520 clk_put(host->clk); 1519 1521 host_free: ··· 1558 1564 gpio_free(host->gpio_cd); 1559 1565 1560 1566 iounmap(host->base); 1561 - clk_disable(host->clk); 1562 - clk_unprepare(host->clk); 1567 + clk_disable_unprepare(host->clk); 1563 1568 clk_put(host->clk); 1564 1569 1565 1570 if (host->vcc)
+70 -6
drivers/mmc/host/mxcmmc.c
··· 44 44 #include <mach/hardware.h> 45 45 46 46 #define DRIVER_NAME "mxc-mmc" 47 + #define MXCMCI_TIMEOUT_MS 10000 47 48 48 49 #define MMC_REG_STR_STP_CLK 0x00 49 50 #define MMC_REG_STATUS 0x04 ··· 151 150 int dmareq; 152 151 struct dma_slave_config dma_slave_config; 153 152 struct imx_dma_data dma_data; 153 + 154 + struct timer_list watchdog; 154 155 }; 155 156 156 157 static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios); ··· 274 271 dmaengine_submit(host->desc); 275 272 dma_async_issue_pending(host->dma); 276 273 274 + mod_timer(&host->watchdog, jiffies + msecs_to_jiffies(MXCMCI_TIMEOUT_MS)); 275 + 277 276 return 0; 277 + } 278 + 279 + static void mxcmci_cmd_done(struct mxcmci_host *host, unsigned int stat); 280 + static void mxcmci_data_done(struct mxcmci_host *host, unsigned int stat); 281 + 282 + static void mxcmci_dma_callback(void *data) 283 + { 284 + struct mxcmci_host *host = data; 285 + u32 stat; 286 + 287 + del_timer(&host->watchdog); 288 + 289 + stat = readl(host->base + MMC_REG_STATUS); 290 + writel(stat & ~STATUS_DATA_TRANS_DONE, host->base + MMC_REG_STATUS); 291 + 292 + dev_dbg(mmc_dev(host->mmc), "%s: 0x%08x\n", __func__, stat); 293 + 294 + if (stat & STATUS_READ_OP_DONE) 295 + writel(STATUS_READ_OP_DONE, host->base + MMC_REG_STATUS); 296 + 297 + mxcmci_data_done(host, stat); 278 298 } 279 299 280 300 static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd, ··· 331 305 332 306 int_cntr = INT_END_CMD_RES_EN; 333 307 334 - if (mxcmci_use_dma(host)) 335 - int_cntr |= INT_READ_OP_EN | INT_WRITE_OP_DONE_EN; 308 + if (mxcmci_use_dma(host)) { 309 + if (host->dma_dir == DMA_FROM_DEVICE) { 310 + host->desc->callback = mxcmci_dma_callback; 311 + host->desc->callback_param = host; 312 + } else { 313 + int_cntr |= INT_WRITE_OP_DONE_EN; 314 + } 315 + } 336 316 337 317 spin_lock_irqsave(&host->lock, flags); 338 318 if (host->use_sdio) ··· 377 345 struct mmc_data *data = host->data; 378 346 int data_error; 379 347 380 - if (mxcmci_use_dma(host)) { 381 - dmaengine_terminate_all(host->dma); 348 + if (mxcmci_use_dma(host)) 382 349 dma_unmap_sg(host->dma->device->dev, data->sg, data->sg_len, 383 350 host->dma_dir); 384 - } 385 351 386 352 if (stat & STATUS_ERR_MASK) { 387 353 dev_dbg(mmc_dev(host->mmc), "request failed. status: 0x%08x\n", ··· 654 624 mxcmci_cmd_done(host, stat); 655 625 656 626 if (mxcmci_use_dma(host) && 657 - (stat & (STATUS_DATA_TRANS_DONE | STATUS_WRITE_OP_DONE))) 627 + (stat & (STATUS_DATA_TRANS_DONE | STATUS_WRITE_OP_DONE))) { 628 + del_timer(&host->watchdog); 658 629 mxcmci_data_done(host, stat); 630 + } 659 631 660 632 if (host->default_irq_mask && 661 633 (stat & (STATUS_CARD_INSERTION | STATUS_CARD_REMOVAL))) ··· 868 836 return true; 869 837 } 870 838 839 + static void mxcmci_watchdog(unsigned long data) 840 + { 841 + struct mmc_host *mmc = (struct mmc_host *)data; 842 + struct mxcmci_host *host = mmc_priv(mmc); 843 + struct mmc_request *req = host->req; 844 + unsigned int stat = readl(host->base + MMC_REG_STATUS); 845 + 846 + if (host->dma_dir == DMA_FROM_DEVICE) { 847 + dmaengine_terminate_all(host->dma); 848 + dev_err(mmc_dev(host->mmc), 849 + "%s: read time out (status = 0x%08x)\n", 850 + __func__, stat); 851 + } else { 852 + dev_err(mmc_dev(host->mmc), 853 + "%s: write time out (status = 0x%08x)\n", 854 + __func__, stat); 855 + mxcmci_softreset(host); 856 + } 857 + 858 + /* Mark transfer as erroneus and inform the upper layers */ 859 + 860 + host->data->error = -ETIMEDOUT; 861 + host->req = NULL; 862 + host->cmd = NULL; 863 + host->data = NULL; 864 + mmc_request_done(host->mmc, req); 865 + } 866 + 871 867 static const struct mmc_host_ops mxcmci_ops = { 872 868 .request = mxcmci_request, 873 869 .set_ios = mxcmci_set_ios, ··· 1027 967 } 1028 968 1029 969 mmc_add_host(mmc); 970 + 971 + init_timer(&host->watchdog); 972 + host->watchdog.function = &mxcmci_watchdog; 973 + host->watchdog.data = (unsigned long)mmc; 1030 974 1031 975 return 0; 1032 976
+17 -20
drivers/mmc/host/omap.c
··· 27 27 #include <linux/mmc/card.h> 28 28 #include <linux/clk.h> 29 29 #include <linux/scatterlist.h> 30 - #include <linux/i2c/tps65010.h> 31 30 #include <linux/slab.h> 32 31 33 - #include <asm/io.h> 34 - #include <asm/irq.h> 35 - 36 32 #include <plat/mmc.h> 37 - #include <asm/gpio.h> 38 33 #include <plat/dma.h> 39 - #include <plat/fpga.h> 40 34 41 35 #define OMAP_MMC_REG_CMD 0x00 42 36 #define OMAP_MMC_REG_ARGL 0x01 ··· 99 105 u16 saved_con; 100 106 u16 bus_mode; 101 107 unsigned int fclk_freq; 102 - unsigned powered:1; 103 108 104 109 struct tasklet_struct cover_tasklet; 105 110 struct timer_list cover_timer; ··· 130 137 unsigned int phys_base; 131 138 int irq; 132 139 unsigned char bus_mode; 133 - unsigned char hw_bus_mode; 134 140 unsigned int reg_shift; 135 141 136 142 struct work_struct cmd_abort_work; ··· 687 695 host->buffer += nwords; 688 696 } 689 697 690 - static inline void mmc_omap_report_irq(u16 status) 698 + #ifdef CONFIG_MMC_DEBUG 699 + static void mmc_omap_report_irq(struct mmc_omap_host *host, u16 status) 691 700 { 692 701 static const char *mmc_omap_status_bits[] = { 693 702 "EOC", "CD", "CB", "BRS", "EOFB", "DTO", "DCRC", "CTO", 694 703 "CCRC", "CRW", "AF", "AE", "OCRB", "CIRQ", "CERR" 695 704 }; 696 - int i, c = 0; 705 + int i; 706 + char res[64], *buf = res; 707 + 708 + buf += sprintf(buf, "MMC IRQ 0x%x:", status); 697 709 698 710 for (i = 0; i < ARRAY_SIZE(mmc_omap_status_bits); i++) 699 - if (status & (1 << i)) { 700 - if (c) 701 - printk(" "); 702 - printk("%s", mmc_omap_status_bits[i]); 703 - c++; 704 - } 711 + if (status & (1 << i)) 712 + buf += sprintf(buf, " %s", mmc_omap_status_bits[i]); 713 + dev_vdbg(mmc_dev(host->mmc), "%s\n", res); 705 714 } 715 + #else 716 + static void mmc_omap_report_irq(struct mmc_omap_host *host, u16 status) 717 + { 718 + } 719 + #endif 720 + 706 721 707 722 static irqreturn_t mmc_omap_irq(int irq, void *dev_id) 708 723 { ··· 743 744 cmd = host->cmd->opcode; 744 745 else 745 746 cmd = -1; 746 - #ifdef CONFIG_MMC_DEBUG 747 747 dev_dbg(mmc_dev(host->mmc), "MMC IRQ %04x (CMD %d): ", 748 748 status, cmd); 749 - mmc_omap_report_irq(status); 750 - printk("\n"); 751 - #endif 749 + mmc_omap_report_irq(host, status); 750 + 752 751 if (host->total_bytes_left) { 753 752 if ((status & OMAP_MMC_STAT_A_FULL) || 754 753 (status & OMAP_MMC_STAT_END_OF_DATA))
+33 -90
drivers/mmc/host/omap_hsmmc.c
··· 35 35 #include <linux/mmc/core.h> 36 36 #include <linux/mmc/mmc.h> 37 37 #include <linux/io.h> 38 - #include <linux/semaphore.h> 39 38 #include <linux/gpio.h> 40 39 #include <linux/regulator/consumer.h> 41 40 #include <linux/pm_runtime.h> ··· 43 44 #include <plat/cpu.h> 44 45 45 46 /* OMAP HSMMC Host Controller Registers */ 46 - #define OMAP_HSMMC_SYSCONFIG 0x0010 47 47 #define OMAP_HSMMC_SYSSTATUS 0x0014 48 48 #define OMAP_HSMMC_CON 0x002C 49 49 #define OMAP_HSMMC_BLK 0x0104 ··· 159 161 unsigned int dma_sg_idx; 160 162 unsigned char bus_mode; 161 163 unsigned char power_mode; 162 - u32 *buffer; 163 - u32 bytesleft; 164 164 int suspended; 165 165 int irq; 166 166 int use_dma, dma_ch; ··· 167 171 int slot_id; 168 172 int response_busy; 169 173 int context_loss; 170 - int vdd; 171 174 int protect_card; 172 175 int reqs_blocked; 173 176 int use_reg; ··· 295 300 struct regulator *reg; 296 301 int ocr_value = 0; 297 302 298 - mmc_slot(host).set_power = omap_hsmmc_set_power; 299 - 300 303 reg = regulator_get(host->dev, "vmmc"); 301 304 if (IS_ERR(reg)) { 302 305 dev_dbg(host->dev, "vmmc regulator missing\n"); 306 + return PTR_ERR(reg); 303 307 } else { 308 + mmc_slot(host).set_power = omap_hsmmc_set_power; 304 309 host->vcc = reg; 305 310 ocr_value = mmc_regulator_get_ocrmask(reg); 306 311 if (!mmc_slot(host).ocr_mask) { ··· 490 495 unsigned long regval; 491 496 unsigned long timeout; 492 497 493 - dev_dbg(mmc_dev(host->mmc), "Set clock to %uHz\n", ios->clock); 498 + dev_vdbg(mmc_dev(host->mmc), "Set clock to %uHz\n", ios->clock); 494 499 495 500 omap_hsmmc_stop_clock(host); 496 501 ··· 574 579 if (host->context_loss == context_loss) 575 580 return 1; 576 581 577 - /* Wait for hardware reset */ 578 - timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS); 579 - while ((OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) != RESETDONE 580 - && time_before(jiffies, timeout)) 581 - ; 582 - 583 - /* Do software reset */ 584 - OMAP_HSMMC_WRITE(host->base, SYSCONFIG, SOFTRESET); 585 - timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS); 586 - while ((OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) != RESETDONE 587 - && time_before(jiffies, timeout)) 588 - ; 589 - 590 - OMAP_HSMMC_WRITE(host->base, SYSCONFIG, 591 - OMAP_HSMMC_READ(host->base, SYSCONFIG) | AUTOIDLE); 582 + if (!OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) 583 + return 1; 592 584 593 585 if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { 594 586 if (host->power_mode != MMC_POWER_OFF && ··· 727 745 { 728 746 int cmdreg = 0, resptype = 0, cmdtype = 0; 729 747 730 - dev_dbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n", 748 + dev_vdbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n", 731 749 mmc_hostname(host->mmc), cmd->opcode, cmd->arg); 732 750 host->cmd = cmd; 733 751 ··· 916 934 buf += len; 917 935 } 918 936 919 - dev_dbg(mmc_dev(host->mmc), "%s\n", res); 937 + dev_vdbg(mmc_dev(host->mmc), "%s\n", res); 920 938 } 921 939 #else 922 940 static inline void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host *host, ··· 963 981 __func__); 964 982 } 965 983 984 + static void hsmmc_command_incomplete(struct omap_hsmmc_host *host, int err) 985 + { 986 + omap_hsmmc_reset_controller_fsm(host, SRC); 987 + host->cmd->error = err; 988 + 989 + if (host->data) { 990 + omap_hsmmc_reset_controller_fsm(host, SRD); 991 + omap_hsmmc_dma_cleanup(host, err); 992 + } 993 + 994 + } 995 + 966 996 static void omap_hsmmc_do_irq(struct omap_hsmmc_host *host, int status) 967 997 { 968 998 struct mmc_data *data; 969 999 int end_cmd = 0, end_trans = 0; 970 1000 971 - if (!host->req_in_progress) { 972 - do { 973 - OMAP_HSMMC_WRITE(host->base, STAT, status); 974 - /* Flush posted write */ 975 - status = OMAP_HSMMC_READ(host->base, STAT); 976 - } while (status & INT_EN_MASK); 977 - return; 978 - } 979 - 980 1001 data = host->data; 981 - dev_dbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status); 1002 + dev_vdbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status); 982 1003 983 1004 if (status & ERR) { 984 1005 omap_hsmmc_dbg_report_irq(host, status); 985 - if ((status & CMD_TIMEOUT) || 986 - (status & CMD_CRC)) { 987 - if (host->cmd) { 988 - if (status & CMD_TIMEOUT) { 989 - omap_hsmmc_reset_controller_fsm(host, 990 - SRC); 991 - host->cmd->error = -ETIMEDOUT; 992 - } else { 993 - host->cmd->error = -EILSEQ; 994 - } 995 - end_cmd = 1; 996 - } 997 - if (host->data || host->response_busy) { 998 - if (host->data) 999 - omap_hsmmc_dma_cleanup(host, 1000 - -ETIMEDOUT); 1001 - host->response_busy = 0; 1002 - omap_hsmmc_reset_controller_fsm(host, SRD); 1003 - } 1004 - } 1005 - if ((status & DATA_TIMEOUT) || 1006 - (status & DATA_CRC)) { 1007 - if (host->data || host->response_busy) { 1008 - int err = (status & DATA_TIMEOUT) ? 1009 - -ETIMEDOUT : -EILSEQ; 1006 + if (status & (CMD_TIMEOUT | DATA_TIMEOUT)) 1007 + hsmmc_command_incomplete(host, -ETIMEDOUT); 1008 + else if (status & (CMD_CRC | DATA_CRC)) 1009 + hsmmc_command_incomplete(host, -EILSEQ); 1010 1010 1011 - if (host->data) 1012 - omap_hsmmc_dma_cleanup(host, err); 1013 - else 1014 - host->mrq->cmd->error = err; 1015 - host->response_busy = 0; 1016 - omap_hsmmc_reset_controller_fsm(host, SRD); 1017 - end_trans = 1; 1018 - } 1019 - } 1020 - if (status & CARD_ERR) { 1021 - dev_dbg(mmc_dev(host->mmc), 1022 - "Ignoring card err CMD%d\n", host->cmd->opcode); 1023 - if (host->cmd) 1024 - end_cmd = 1; 1025 - if (host->data) 1026 - end_trans = 1; 1011 + end_cmd = 1; 1012 + if (host->data || host->response_busy) { 1013 + end_trans = 1; 1014 + host->response_busy = 0; 1027 1015 } 1028 1016 } 1029 - 1030 - OMAP_HSMMC_WRITE(host->base, STAT, status); 1031 1017 1032 1018 if (end_cmd || ((status & CC) && host->cmd)) 1033 1019 omap_hsmmc_cmd_done(host, host->cmd); ··· 1012 1062 int status; 1013 1063 1014 1064 status = OMAP_HSMMC_READ(host->base, STAT); 1015 - do { 1065 + while (status & INT_EN_MASK && host->req_in_progress) { 1016 1066 omap_hsmmc_do_irq(host, status); 1067 + 1017 1068 /* Flush posted write */ 1069 + OMAP_HSMMC_WRITE(host->base, STAT, status); 1018 1070 status = OMAP_HSMMC_READ(host->base, STAT); 1019 - } while (status & INT_EN_MASK); 1071 + } 1020 1072 1021 1073 return IRQ_HANDLED; 1022 1074 } ··· 1453 1501 case MMC_POWER_OFF: 1454 1502 mmc_slot(host).set_power(host->dev, host->slot_id, 1455 1503 0, 0); 1456 - host->vdd = 0; 1457 1504 break; 1458 1505 case MMC_POWER_UP: 1459 1506 mmc_slot(host).set_power(host->dev, host->slot_id, 1460 1507 1, ios->vdd); 1461 - host->vdd = ios->vdd; 1462 1508 break; 1463 1509 case MMC_POWER_ON: 1464 1510 do_send_init_stream = 1; ··· 1548 1598 value = OMAP_HSMMC_READ(host->base, CAPA); 1549 1599 OMAP_HSMMC_WRITE(host->base, CAPA, value | capa); 1550 1600 1551 - /* Set the controller to AUTO IDLE mode */ 1552 - value = OMAP_HSMMC_READ(host->base, SYSCONFIG); 1553 - OMAP_HSMMC_WRITE(host->base, SYSCONFIG, value | AUTOIDLE); 1554 - 1555 1601 /* Set SD bus power bit */ 1556 1602 set_sd_bus_power(host); 1557 1603 } ··· 1605 1659 1606 1660 pm_runtime_get_sync(host->dev); 1607 1661 1608 - seq_printf(s, "SYSCONFIG:\t0x%08x\n", 1609 - OMAP_HSMMC_READ(host->base, SYSCONFIG)); 1610 1662 seq_printf(s, "CON:\t\t0x%08x\n", 1611 1663 OMAP_HSMMC_READ(host->base, CON)); 1612 1664 seq_printf(s, "HCTL:\t\t0x%08x\n", ··· 2049 2105 if (ret) { 2050 2106 host->suspended = 0; 2051 2107 if (host->pdata->resume) { 2052 - ret = host->pdata->resume(dev, host->slot_id); 2053 - if (ret) 2108 + if (host->pdata->resume(dev, host->slot_id)) 2054 2109 dev_dbg(dev, "Unmask interrupt failed\n"); 2055 2110 } 2056 2111 goto err;
+52
drivers/mmc/host/pxamci.c
··· 30 30 #include <linux/regulator/consumer.h> 31 31 #include <linux/gpio.h> 32 32 #include <linux/gfp.h> 33 + #include <linux/of.h> 34 + #include <linux/of_gpio.h> 35 + #include <linux/of_device.h> 33 36 34 37 #include <asm/sizes.h> 35 38 ··· 576 573 return IRQ_HANDLED; 577 574 } 578 575 576 + #ifdef CONFIG_OF 577 + static const struct of_device_id pxa_mmc_dt_ids[] = { 578 + { .compatible = "marvell,pxa-mmc" }, 579 + { } 580 + }; 581 + 582 + MODULE_DEVICE_TABLE(of, pxa_mmc_dt_ids); 583 + 584 + static int __devinit pxamci_of_init(struct platform_device *pdev) 585 + { 586 + struct device_node *np = pdev->dev.of_node; 587 + struct pxamci_platform_data *pdata; 588 + u32 tmp; 589 + 590 + if (!np) 591 + return 0; 592 + 593 + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 594 + if (!pdata) 595 + return -ENOMEM; 596 + 597 + pdata->gpio_card_detect = 598 + of_get_named_gpio(np, "cd-gpios", 0); 599 + pdata->gpio_card_ro = 600 + of_get_named_gpio(np, "wp-gpios", 0); 601 + 602 + /* pxa-mmc specific */ 603 + pdata->gpio_power = 604 + of_get_named_gpio(np, "pxa-mmc,gpio-power", 0); 605 + 606 + if (of_property_read_u32(np, "pxa-mmc,detect-delay-ms", &tmp) == 0) 607 + pdata->detect_delay_ms = tmp; 608 + 609 + pdev->dev.platform_data = pdata; 610 + 611 + return 0; 612 + } 613 + #else 614 + static int __devinit pxamci_of_init(struct platform_device *pdev) 615 + { 616 + return 0; 617 + } 618 + #endif 619 + 579 620 static int pxamci_probe(struct platform_device *pdev) 580 621 { 581 622 struct mmc_host *mmc; 582 623 struct pxamci_host *host = NULL; 583 624 struct resource *r, *dmarx, *dmatx; 584 625 int ret, irq, gpio_cd = -1, gpio_ro = -1, gpio_power = -1; 626 + 627 + ret = pxamci_of_init(pdev); 628 + if (ret) 629 + return ret; 585 630 586 631 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 587 632 irq = platform_get_irq(pdev, 0); ··· 917 866 .driver = { 918 867 .name = DRIVER_NAME, 919 868 .owner = THIS_MODULE, 869 + .of_match_table = of_match_ptr(pxa_mmc_dt_ids), 920 870 #ifdef CONFIG_PM 921 871 .pm = &pxamci_pm_ops, 922 872 #endif
+8
drivers/mmc/host/sdhci-dove.c
··· 24 24 #include <linux/err.h> 25 25 #include <linux/module.h> 26 26 #include <linux/mmc/host.h> 27 + #include <linux/of.h> 27 28 28 29 #include "sdhci-pltfm.h" 29 30 ··· 127 126 return sdhci_pltfm_unregister(pdev); 128 127 } 129 128 129 + static const struct of_device_id sdhci_dove_of_match_table[] __devinitdata = { 130 + { .compatible = "marvell,dove-sdhci", }, 131 + {} 132 + }; 133 + MODULE_DEVICE_TABLE(of, sdhci_dove_of_match_table); 134 + 130 135 static struct platform_driver sdhci_dove_driver = { 131 136 .driver = { 132 137 .name = "sdhci-dove", 133 138 .owner = THIS_MODULE, 134 139 .pm = SDHCI_PLTFM_PMOPS, 140 + .of_match_table = of_match_ptr(sdhci_dove_of_match_table), 135 141 }, 136 142 .probe = sdhci_dove_probe, 137 143 .remove = __devexit_p(sdhci_dove_remove),
+33 -3
drivers/mmc/host/sdhci-of-esdhc.c
··· 21 21 #include "sdhci-pltfm.h" 22 22 #include "sdhci-esdhc.h" 23 23 24 + #define VENDOR_V_22 0x12 25 + static u32 esdhc_readl(struct sdhci_host *host, int reg) 26 + { 27 + u32 ret; 28 + 29 + ret = in_be32(host->ioaddr + reg); 30 + /* 31 + * The bit of ADMA flag in eSDHC is not compatible with standard 32 + * SDHC register, so set fake flag SDHCI_CAN_DO_ADMA2 when ADMA is 33 + * supported by eSDHC. 34 + * And for many FSL eSDHC controller, the reset value of field 35 + * SDHCI_CAN_DO_ADMA1 is one, but some of them can't support ADMA, 36 + * only these vendor version is greater than 2.2/0x12 support ADMA. 37 + * For FSL eSDHC, must aligned 4-byte, so use 0xFC to read the 38 + * the verdor version number, oxFE is SDHCI_HOST_VERSION. 39 + */ 40 + if ((reg == SDHCI_CAPABILITIES) && (ret & SDHCI_CAN_DO_ADMA1)) { 41 + u32 tmp = in_be32(host->ioaddr + SDHCI_SLOT_INT_STATUS); 42 + tmp = (tmp & SDHCI_VENDOR_VER_MASK) >> SDHCI_VENDOR_VER_SHIFT; 43 + if (tmp > VENDOR_V_22) 44 + ret |= SDHCI_CAN_DO_ADMA2; 45 + } 46 + 47 + return ret; 48 + } 49 + 24 50 static u16 esdhc_readw(struct sdhci_host *host, int reg) 25 51 { 26 52 u16 ret; ··· 170 144 #endif 171 145 172 146 static struct sdhci_ops sdhci_esdhc_ops = { 173 - .read_l = sdhci_be32bs_readl, 147 + .read_l = esdhc_readl, 174 148 .read_w = esdhc_readw, 175 149 .read_b = esdhc_readb, 176 150 .write_l = sdhci_be32bs_writel, ··· 187 161 }; 188 162 189 163 static struct sdhci_pltfm_data sdhci_esdhc_pdata = { 190 - /* card detection could be handled via GPIO */ 164 + /* 165 + * card detection could be handled via GPIO 166 + * eSDHC cannot support End Attribute in NOP ADMA descriptor 167 + */ 191 168 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION 192 - | SDHCI_QUIRK_NO_CARD_NO_RESET, 169 + | SDHCI_QUIRK_NO_CARD_NO_RESET 170 + | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 193 171 .ops = &sdhci_esdhc_ops, 194 172 }; 195 173
+1 -18
drivers/mmc/host/sdhci-pci.c
··· 1476 1476 }, 1477 1477 }; 1478 1478 1479 - /*****************************************************************************\ 1480 - * * 1481 - * Driver init/exit * 1482 - * * 1483 - \*****************************************************************************/ 1484 - 1485 - static int __init sdhci_drv_init(void) 1486 - { 1487 - return pci_register_driver(&sdhci_driver); 1488 - } 1489 - 1490 - static void __exit sdhci_drv_exit(void) 1491 - { 1492 - pci_unregister_driver(&sdhci_driver); 1493 - } 1494 - 1495 - module_init(sdhci_drv_init); 1496 - module_exit(sdhci_drv_exit); 1479 + module_pci_driver(sdhci_driver); 1497 1480 1498 1481 MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>"); 1499 1482 MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
+3
drivers/mmc/host/sdhci-pltfm.c
··· 75 75 if (sdhci_of_wp_inverted(np)) 76 76 host->quirks |= SDHCI_QUIRK_INVERTED_WRITE_PROTECT; 77 77 78 + if (of_get_property(np, "broken-cd", NULL)) 79 + host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; 80 + 78 81 if (of_device_is_compatible(np, "fsl,p2020-rev1-esdhc")) 79 82 host->quirks |= SDHCI_QUIRK_BROKEN_DMA; 80 83
+3 -3
drivers/mmc/host/sdhci-pxav2.c
··· 197 197 goto err_clk_get; 198 198 } 199 199 pltfm_host->clk = clk; 200 - clk_enable(clk); 200 + clk_prepare_enable(clk); 201 201 202 202 host->quirks = SDHCI_QUIRK_BROKEN_ADMA 203 203 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL ··· 239 239 return 0; 240 240 241 241 err_add_host: 242 - clk_disable(clk); 242 + clk_disable_unprepare(clk); 243 243 clk_put(clk); 244 244 err_clk_get: 245 245 sdhci_pltfm_free(pdev); ··· 255 255 256 256 sdhci_remove_host(host, 1); 257 257 258 - clk_disable(pltfm_host->clk); 258 + clk_disable_unprepare(pltfm_host->clk); 259 259 clk_put(pltfm_host->clk); 260 260 sdhci_pltfm_free(pdev); 261 261 kfree(pxa);
+31 -4
drivers/mmc/host/sdhci-pxav3.c
··· 24 24 #include <linux/gpio.h> 25 25 #include <linux/mmc/card.h> 26 26 #include <linux/mmc/host.h> 27 + #include <linux/mmc/slot-gpio.h> 27 28 #include <linux/platform_data/pxa_sdhci.h> 28 29 #include <linux/slab.h> 29 30 #include <linux/delay.h> 30 31 #include <linux/module.h> 31 32 #include <linux/of.h> 32 33 #include <linux/of_device.h> 34 + #include <linux/of_gpio.h> 33 35 34 36 #include "sdhci.h" 35 37 #include "sdhci-pltfm.h" ··· 184 182 struct device_node *np = dev->of_node; 185 183 u32 bus_width; 186 184 u32 clk_delay_cycles; 185 + enum of_gpio_flags gpio_flags; 187 186 188 187 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 189 188 if (!pdata) ··· 200 197 of_property_read_u32(np, "mrvl,clk-delay-cycles", &clk_delay_cycles); 201 198 if (clk_delay_cycles > 0) 202 199 pdata->clk_delay_cycles = clk_delay_cycles; 200 + 201 + pdata->ext_cd_gpio = of_get_named_gpio_flags(np, "cd-gpios", 0, &gpio_flags); 202 + if (gpio_flags != OF_GPIO_ACTIVE_LOW) 203 + pdata->host_caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; 203 204 204 205 return pdata; 205 206 } ··· 238 231 pltfm_host = sdhci_priv(host); 239 232 pltfm_host->priv = pxa; 240 233 241 - clk = clk_get(dev, "PXA-SDHCLK"); 234 + clk = clk_get(dev, NULL); 242 235 if (IS_ERR(clk)) { 243 236 dev_err(dev, "failed to get io clock\n"); 244 237 ret = PTR_ERR(clk); 245 238 goto err_clk_get; 246 239 } 247 240 pltfm_host->clk = clk; 248 - clk_enable(clk); 241 + clk_prepare_enable(clk); 249 242 250 243 host->quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL 251 244 | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC ··· 273 266 host->quirks |= pdata->quirks; 274 267 if (pdata->host_caps) 275 268 host->mmc->caps |= pdata->host_caps; 269 + if (pdata->host_caps2) 270 + host->mmc->caps2 |= pdata->host_caps2; 276 271 if (pdata->pm_caps) 277 272 host->mmc->pm_caps |= pdata->pm_caps; 273 + 274 + if (gpio_is_valid(pdata->ext_cd_gpio)) { 275 + ret = mmc_gpio_request_cd(host->mmc, pdata->ext_cd_gpio); 276 + if (ret) { 277 + dev_err(mmc_dev(host->mmc), 278 + "failed to allocate card detect gpio\n"); 279 + goto err_cd_req; 280 + } 281 + } 278 282 } 279 283 280 284 host->ops = &pxav3_sdhci_ops; 285 + 286 + sdhci_get_of_property(pdev); 281 287 282 288 ret = sdhci_add_host(host); 283 289 if (ret) { ··· 303 283 return 0; 304 284 305 285 err_add_host: 306 - clk_disable(clk); 286 + clk_disable_unprepare(clk); 307 287 clk_put(clk); 288 + mmc_gpio_free_cd(host->mmc); 289 + err_cd_req: 308 290 err_clk_get: 309 291 sdhci_pltfm_free(pdev); 310 292 kfree(pxa); ··· 318 296 struct sdhci_host *host = platform_get_drvdata(pdev); 319 297 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 320 298 struct sdhci_pxa *pxa = pltfm_host->priv; 299 + struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data; 321 300 322 301 sdhci_remove_host(host, 1); 323 302 324 - clk_disable(pltfm_host->clk); 303 + clk_disable_unprepare(pltfm_host->clk); 325 304 clk_put(pltfm_host->clk); 305 + 306 + if (gpio_is_valid(pdata->ext_cd_gpio)) 307 + mmc_gpio_free_cd(host->mmc); 308 + 326 309 sdhci_pltfm_free(pdev); 327 310 kfree(pxa); 328 311
+196 -20
drivers/mmc/host/sdhci-s3c.c
··· 34 34 35 35 #define MAX_BUS_CLK (4) 36 36 37 + /* Number of gpio's used is max data bus width + command and clock lines */ 38 + #define NUM_GPIOS(x) (x + 2) 39 + 37 40 /** 38 41 * struct sdhci_s3c - S3C SDHCI instance 39 42 * @host: The SDHCI host created ··· 44 41 * @ioarea: The resource created when we claimed the IO area. 45 42 * @pdata: The platform data for this controller. 46 43 * @cur_clk: The index of the current bus clock. 44 + * @gpios: List of gpio numbers parsed from device tree. 47 45 * @clk_io: The clock for the internal bus interface. 48 46 * @clk_bus: The clocks that are available for the SD/MMC bus clock. 49 47 */ ··· 56 52 unsigned int cur_clk; 57 53 int ext_cd_irq; 58 54 int ext_cd_gpio; 55 + int *gpios; 59 56 60 57 struct clk *clk_io; 61 58 struct clk *clk_bus[MAX_BUS_CLK]; ··· 171 166 dev_dbg(&ourhost->pdev->dev, "clk %d: rate %ld, want %d, got %ld\n", 172 167 src, rate, wanted, rate / div); 173 168 174 - return (wanted - (rate / div)); 169 + return wanted - (rate / div); 175 170 } 176 171 177 172 /** ··· 208 203 best_src, clock, best); 209 204 210 205 /* select the new clock source */ 211 - 212 206 if (ourhost->cur_clk != best_src) { 213 207 struct clk *clk = ourhost->clk_bus[best_src]; 208 + 209 + clk_enable(clk); 210 + clk_disable(ourhost->clk_bus[ourhost->cur_clk]); 214 211 215 212 /* turn clock off to card before changing clock source */ 216 213 writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL); ··· 295 288 static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock) 296 289 { 297 290 struct sdhci_s3c *ourhost = to_s3c(host); 291 + struct device *dev = &ourhost->pdev->dev; 298 292 unsigned long timeout; 299 293 u16 clk = 0; 300 294 ··· 317 309 while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL)) 318 310 & SDHCI_CLOCK_INT_STABLE)) { 319 311 if (timeout == 0) { 320 - printk(KERN_ERR "%s: Internal clock never " 321 - "stabilised.\n", mmc_hostname(host->mmc)); 312 + dev_err(dev, "%s: Internal clock never stabilised.\n", 313 + mmc_hostname(host->mmc)); 322 314 return; 323 315 } 324 316 timeout--; ··· 412 404 if (sc->ext_cd_irq && 413 405 request_threaded_irq(sc->ext_cd_irq, NULL, 414 406 sdhci_s3c_gpio_card_detect_thread, 415 - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 407 + IRQF_TRIGGER_RISING | 408 + IRQF_TRIGGER_FALLING | 409 + IRQF_ONESHOT, 416 410 dev_name(dev), sc) == 0) { 417 411 int status = gpio_get_value(sc->ext_cd_gpio); 418 412 if (pdata->ext_cd_gpio_invert) ··· 429 419 } 430 420 } 431 421 422 + #ifdef CONFIG_OF 423 + static int __devinit sdhci_s3c_parse_dt(struct device *dev, 424 + struct sdhci_host *host, struct s3c_sdhci_platdata *pdata) 425 + { 426 + struct device_node *node = dev->of_node; 427 + struct sdhci_s3c *ourhost = to_s3c(host); 428 + u32 max_width; 429 + int gpio, cnt, ret; 430 + 431 + /* if the bus-width property is not specified, assume width as 1 */ 432 + if (of_property_read_u32(node, "bus-width", &max_width)) 433 + max_width = 1; 434 + pdata->max_width = max_width; 435 + 436 + ourhost->gpios = devm_kzalloc(dev, NUM_GPIOS(pdata->max_width) * 437 + sizeof(int), GFP_KERNEL); 438 + if (!ourhost->gpios) 439 + return -ENOMEM; 440 + 441 + /* get the card detection method */ 442 + if (of_get_property(node, "broken-cd", 0)) { 443 + pdata->cd_type = S3C_SDHCI_CD_NONE; 444 + goto setup_bus; 445 + } 446 + 447 + if (of_get_property(node, "non-removable", 0)) { 448 + pdata->cd_type = S3C_SDHCI_CD_PERMANENT; 449 + goto setup_bus; 450 + } 451 + 452 + gpio = of_get_named_gpio(node, "cd-gpios", 0); 453 + if (gpio_is_valid(gpio)) { 454 + pdata->cd_type = S3C_SDHCI_CD_GPIO; 455 + goto found_cd; 456 + } else if (gpio != -ENOENT) { 457 + dev_err(dev, "invalid card detect gpio specified\n"); 458 + return -EINVAL; 459 + } 460 + 461 + gpio = of_get_named_gpio(node, "samsung,cd-pinmux-gpio", 0); 462 + if (gpio_is_valid(gpio)) { 463 + pdata->cd_type = S3C_SDHCI_CD_INTERNAL; 464 + goto found_cd; 465 + } else if (gpio != -ENOENT) { 466 + dev_err(dev, "invalid card detect gpio specified\n"); 467 + return -EINVAL; 468 + } 469 + 470 + dev_info(dev, "assuming no card detect line available\n"); 471 + pdata->cd_type = S3C_SDHCI_CD_NONE; 472 + 473 + found_cd: 474 + if (pdata->cd_type == S3C_SDHCI_CD_GPIO) { 475 + pdata->ext_cd_gpio = gpio; 476 + ourhost->ext_cd_gpio = -1; 477 + if (of_get_property(node, "cd-inverted", NULL)) 478 + pdata->ext_cd_gpio_invert = 1; 479 + } else if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) { 480 + ret = gpio_request(gpio, "sdhci-cd"); 481 + if (ret) { 482 + dev_err(dev, "card detect gpio request failed\n"); 483 + return -EINVAL; 484 + } 485 + ourhost->ext_cd_gpio = gpio; 486 + } 487 + 488 + setup_bus: 489 + /* get the gpios for command, clock and data lines */ 490 + for (cnt = 0; cnt < NUM_GPIOS(pdata->max_width); cnt++) { 491 + gpio = of_get_gpio(node, cnt); 492 + if (!gpio_is_valid(gpio)) { 493 + dev_err(dev, "invalid gpio[%d]\n", cnt); 494 + goto err_free_dt_cd_gpio; 495 + } 496 + ourhost->gpios[cnt] = gpio; 497 + } 498 + 499 + for (cnt = 0; cnt < NUM_GPIOS(pdata->max_width); cnt++) { 500 + ret = gpio_request(ourhost->gpios[cnt], "sdhci-gpio"); 501 + if (ret) { 502 + dev_err(dev, "gpio[%d] request failed\n", cnt); 503 + goto err_free_dt_gpios; 504 + } 505 + } 506 + 507 + return 0; 508 + 509 + err_free_dt_gpios: 510 + while (--cnt >= 0) 511 + gpio_free(ourhost->gpios[cnt]); 512 + err_free_dt_cd_gpio: 513 + if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) 514 + gpio_free(ourhost->ext_cd_gpio); 515 + return -EINVAL; 516 + } 517 + #else 518 + static int __devinit sdhci_s3c_parse_dt(struct device *dev, 519 + struct sdhci_host *host, struct s3c_sdhci_platdata *pdata) 520 + { 521 + return -EINVAL; 522 + } 523 + #endif 524 + 525 + static const struct of_device_id sdhci_s3c_dt_match[]; 526 + 432 527 static inline struct sdhci_s3c_drv_data *sdhci_s3c_get_driver_data( 433 528 struct platform_device *pdev) 434 529 { 530 + #ifdef CONFIG_OF 531 + if (pdev->dev.of_node) { 532 + const struct of_device_id *match; 533 + match = of_match_node(sdhci_s3c_dt_match, pdev->dev.of_node); 534 + return (struct sdhci_s3c_drv_data *)match->data; 535 + } 536 + #endif 435 537 return (struct sdhci_s3c_drv_data *) 436 538 platform_get_device_id(pdev)->driver_data; 437 539 } ··· 558 436 struct resource *res; 559 437 int ret, irq, ptr, clks; 560 438 561 - if (!pdev->dev.platform_data) { 439 + if (!pdev->dev.platform_data && !pdev->dev.of_node) { 562 440 dev_err(dev, "no device data specified\n"); 563 441 return -ENOENT; 564 442 } ··· 574 452 dev_err(dev, "sdhci_alloc_host() failed\n"); 575 453 return PTR_ERR(host); 576 454 } 455 + sc = sdhci_priv(host); 577 456 578 457 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 579 458 if (!pdata) { 580 459 ret = -ENOMEM; 581 - goto err_io_clk; 460 + goto err_pdata; 582 461 } 583 - memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata)); 462 + 463 + if (pdev->dev.of_node) { 464 + ret = sdhci_s3c_parse_dt(&pdev->dev, host, pdata); 465 + if (ret) 466 + goto err_pdata; 467 + } else { 468 + memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata)); 469 + sc->ext_cd_gpio = -1; /* invalid gpio number */ 470 + } 584 471 585 472 drv_data = sdhci_s3c_get_driver_data(pdev); 586 - sc = sdhci_priv(host); 587 473 588 474 sc->host = host; 589 475 sc->pdev = pdev; 590 476 sc->pdata = pdata; 591 - sc->ext_cd_gpio = -1; /* invalid gpio number */ 592 477 593 478 platform_set_drvdata(pdev, host); 594 479 ··· 615 486 616 487 snprintf(name, 14, "mmc_busclk.%d", ptr); 617 488 clk = clk_get(dev, name); 618 - if (IS_ERR(clk)) { 489 + if (IS_ERR(clk)) 619 490 continue; 620 - } 621 491 622 492 clks++; 623 493 sc->clk_bus[ptr] = clk; ··· 627 499 */ 628 500 sc->cur_clk = ptr; 629 501 630 - clk_enable(clk); 631 - 632 502 dev_info(dev, "clock source %d: %s (%ld Hz)\n", 633 503 ptr, name, clk_get_rate(clk)); 634 504 } ··· 636 510 ret = -ENOENT; 637 511 goto err_no_busclks; 638 512 } 513 + 514 + #ifndef CONFIG_PM_RUNTIME 515 + clk_enable(sc->clk_bus[sc->cur_clk]); 516 + #endif 639 517 640 518 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 641 519 host->ioaddr = devm_request_and_ioremap(&pdev->dev, res); ··· 746 616 gpio_is_valid(pdata->ext_cd_gpio)) 747 617 sdhci_s3c_setup_card_detect_gpio(sc); 748 618 619 + #ifdef CONFIG_PM_RUNTIME 620 + clk_disable(sc->clk_io); 621 + #endif 749 622 return 0; 750 623 751 624 err_req_regs: 625 + #ifndef CONFIG_PM_RUNTIME 626 + clk_disable(sc->clk_bus[sc->cur_clk]); 627 + #endif 752 628 for (ptr = 0; ptr < MAX_BUS_CLK; ptr++) { 753 629 if (sc->clk_bus[ptr]) { 754 - clk_disable(sc->clk_bus[ptr]); 755 630 clk_put(sc->clk_bus[ptr]); 756 631 } 757 632 } ··· 766 631 clk_put(sc->clk_io); 767 632 768 633 err_io_clk: 634 + for (ptr = 0; ptr < NUM_GPIOS(sc->pdata->max_width); ptr++) 635 + gpio_free(sc->gpios[ptr]); 636 + if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) 637 + gpio_free(sc->ext_cd_gpio); 638 + 639 + err_pdata: 769 640 sdhci_free_host(host); 770 641 771 642 return ret; ··· 779 638 780 639 static int __devexit sdhci_s3c_remove(struct platform_device *pdev) 781 640 { 782 - struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data; 783 641 struct sdhci_host *host = platform_get_drvdata(pdev); 784 642 struct sdhci_s3c *sc = sdhci_priv(host); 643 + struct s3c_sdhci_platdata *pdata = sc->pdata; 785 644 int ptr; 786 645 787 646 if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_cleanup) ··· 793 652 if (gpio_is_valid(sc->ext_cd_gpio)) 794 653 gpio_free(sc->ext_cd_gpio); 795 654 655 + #ifdef CONFIG_PM_RUNTIME 656 + clk_enable(sc->clk_io); 657 + #endif 796 658 sdhci_remove_host(host, 1); 797 659 660 + pm_runtime_dont_use_autosuspend(&pdev->dev); 798 661 pm_runtime_disable(&pdev->dev); 799 662 800 - for (ptr = 0; ptr < 3; ptr++) { 663 + #ifndef CONFIG_PM_RUNTIME 664 + clk_disable(sc->clk_bus[sc->cur_clk]); 665 + #endif 666 + for (ptr = 0; ptr < MAX_BUS_CLK; ptr++) { 801 667 if (sc->clk_bus[ptr]) { 802 - clk_disable(sc->clk_bus[ptr]); 803 668 clk_put(sc->clk_bus[ptr]); 804 669 } 805 670 } 806 671 clk_disable(sc->clk_io); 807 672 clk_put(sc->clk_io); 673 + 674 + if (pdev->dev.of_node) { 675 + for (ptr = 0; ptr < NUM_GPIOS(sc->pdata->max_width); ptr++) 676 + gpio_free(sc->gpios[ptr]); 677 + } 808 678 809 679 sdhci_free_host(host); 810 680 platform_set_drvdata(pdev, NULL); ··· 843 691 static int sdhci_s3c_runtime_suspend(struct device *dev) 844 692 { 845 693 struct sdhci_host *host = dev_get_drvdata(dev); 694 + struct sdhci_s3c *ourhost = to_s3c(host); 695 + struct clk *busclk = ourhost->clk_io; 696 + int ret; 846 697 847 - return sdhci_runtime_suspend_host(host); 698 + ret = sdhci_runtime_suspend_host(host); 699 + 700 + clk_disable(ourhost->clk_bus[ourhost->cur_clk]); 701 + clk_disable(busclk); 702 + return ret; 848 703 } 849 704 850 705 static int sdhci_s3c_runtime_resume(struct device *dev) 851 706 { 852 707 struct sdhci_host *host = dev_get_drvdata(dev); 708 + struct sdhci_s3c *ourhost = to_s3c(host); 709 + struct clk *busclk = ourhost->clk_io; 710 + int ret; 853 711 854 - return sdhci_runtime_resume_host(host); 712 + clk_enable(busclk); 713 + clk_enable(ourhost->clk_bus[ourhost->cur_clk]); 714 + ret = sdhci_runtime_resume_host(host); 715 + return ret; 855 716 } 856 717 #endif 857 718 ··· 902 737 }; 903 738 MODULE_DEVICE_TABLE(platform, sdhci_s3c_driver_ids); 904 739 740 + #ifdef CONFIG_OF 741 + static const struct of_device_id sdhci_s3c_dt_match[] = { 742 + { .compatible = "samsung,s3c6410-sdhci", }, 743 + { .compatible = "samsung,exynos4210-sdhci", 744 + .data = (void *)EXYNOS4_SDHCI_DRV_DATA }, 745 + {}, 746 + }; 747 + MODULE_DEVICE_TABLE(of, sdhci_s3c_dt_match); 748 + #endif 749 + 905 750 static struct platform_driver sdhci_s3c_driver = { 906 751 .probe = sdhci_s3c_probe, 907 752 .remove = __devexit_p(sdhci_s3c_remove), ··· 919 744 .driver = { 920 745 .owner = THIS_MODULE, 921 746 .name = "s3c-sdhci", 747 + .of_match_table = of_match_ptr(sdhci_s3c_dt_match), 922 748 .pm = SDHCI_S3C_PMOPS, 923 749 }, 924 750 };
+60 -7
drivers/mmc/host/sdhci-spear.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/interrupt.h> 22 22 #include <linux/irq.h> 23 + #include <linux/of.h> 24 + #include <linux/of_gpio.h> 23 25 #include <linux/platform_device.h> 24 26 #include <linux/pm.h> 25 27 #include <linux/slab.h> ··· 70 68 return IRQ_HANDLED; 71 69 } 72 70 71 + #ifdef CONFIG_OF 72 + static struct sdhci_plat_data * __devinit 73 + sdhci_probe_config_dt(struct platform_device *pdev) 74 + { 75 + struct device_node *np = pdev->dev.of_node; 76 + struct sdhci_plat_data *pdata = NULL; 77 + int cd_gpio; 78 + 79 + cd_gpio = of_get_named_gpio(np, "cd-gpios", 0); 80 + if (!gpio_is_valid(cd_gpio)) 81 + cd_gpio = -1; 82 + 83 + /* If pdata is required */ 84 + if (cd_gpio != -1) { 85 + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 86 + if (!pdata) { 87 + dev_err(&pdev->dev, "DT: kzalloc failed\n"); 88 + return ERR_PTR(-ENOMEM); 89 + } 90 + } 91 + 92 + pdata->card_int_gpio = cd_gpio; 93 + 94 + return pdata; 95 + } 96 + #else 97 + static struct sdhci_plat_data * __devinit 98 + sdhci_probe_config_dt(struct platform_device *pdev) 99 + { 100 + return ERR_PTR(-ENOSYS); 101 + } 102 + #endif 103 + 73 104 static int __devinit sdhci_probe(struct platform_device *pdev) 74 105 { 106 + struct device_node *np = pdev->dev.of_node; 75 107 struct sdhci_host *host; 76 108 struct resource *iomem; 77 109 struct spear_sdhci *sdhci; ··· 140 104 goto err; 141 105 } 142 106 143 - ret = clk_enable(sdhci->clk); 107 + ret = clk_prepare_enable(sdhci->clk); 144 108 if (ret) { 145 109 dev_dbg(&pdev->dev, "Error enabling clock\n"); 146 110 goto put_clk; 147 111 } 148 112 149 - /* overwrite platform_data */ 150 - sdhci->data = dev_get_platdata(&pdev->dev); 113 + if (np) { 114 + sdhci->data = sdhci_probe_config_dt(pdev); 115 + if (IS_ERR(sdhci->data)) { 116 + dev_err(&pdev->dev, "DT: Failed to get pdata\n"); 117 + return -ENODEV; 118 + } 119 + } else { 120 + sdhci->data = dev_get_platdata(&pdev->dev); 121 + } 122 + 151 123 pdev->dev.platform_data = sdhci; 152 124 153 125 if (pdev->dev.parent) ··· 260 216 free_host: 261 217 sdhci_free_host(host); 262 218 disable_clk: 263 - clk_disable(sdhci->clk); 219 + clk_disable_unprepare(sdhci->clk); 264 220 put_clk: 265 221 clk_put(sdhci->clk); 266 222 err: ··· 282 238 283 239 sdhci_remove_host(host, dead); 284 240 sdhci_free_host(host); 285 - clk_disable(sdhci->clk); 241 + clk_disable_unprepare(sdhci->clk); 286 242 clk_put(sdhci->clk); 287 243 288 244 return 0; ··· 297 253 298 254 ret = sdhci_suspend_host(host); 299 255 if (!ret) 300 - clk_disable(sdhci->clk); 256 + clk_disable_unprepare(sdhci->clk); 301 257 302 258 return ret; 303 259 } ··· 308 264 struct spear_sdhci *sdhci = dev_get_platdata(dev); 309 265 int ret; 310 266 311 - ret = clk_enable(sdhci->clk); 267 + ret = clk_prepare_enable(sdhci->clk); 312 268 if (ret) { 313 269 dev_dbg(dev, "Resume: Error enabling clock\n"); 314 270 return ret; ··· 320 276 321 277 static SIMPLE_DEV_PM_OPS(sdhci_pm_ops, sdhci_suspend, sdhci_resume); 322 278 279 + #ifdef CONFIG_OF 280 + static const struct of_device_id sdhci_spear_id_table[] = { 281 + { .compatible = "st,spear300-sdhci" }, 282 + {} 283 + }; 284 + MODULE_DEVICE_TABLE(of, sdhci_spear_id_table); 285 + #endif 286 + 323 287 static struct platform_driver sdhci_driver = { 324 288 .driver = { 325 289 .name = "sdhci", 326 290 .owner = THIS_MODULE, 327 291 .pm = &sdhci_pm_ops, 292 + .of_match_table = of_match_ptr(sdhci_spear_id_table), 328 293 }, 329 294 .probe = sdhci_probe, 330 295 .remove = __devexit_p(sdhci_remove),
+3 -4
drivers/mmc/host/sdhci-tegra.c
··· 257 257 int rc; 258 258 259 259 match = of_match_device(sdhci_tegra_dt_match, &pdev->dev); 260 - if (match) 261 - soc_data = match->data; 262 - else 263 - soc_data = &soc_data_tegra20; 260 + if (!match) 261 + return -EINVAL; 262 + soc_data = match->data; 264 263 265 264 host = sdhci_pltfm_init(pdev, soc_data->pdata); 266 265 if (IS_ERR(host))
+130 -77
drivers/mmc/host/sdhci.c
··· 28 28 #include <linux/mmc/mmc.h> 29 29 #include <linux/mmc/host.h> 30 30 #include <linux/mmc/card.h> 31 + #include <linux/mmc/slot-gpio.h> 31 32 32 33 #include "sdhci.h" 33 34 ··· 1294 1293 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & 1295 1294 SDHCI_CARD_PRESENT; 1296 1295 1296 + /* If we're using a cd-gpio, testing the presence bit might fail. */ 1297 + if (!present) { 1298 + int ret = mmc_gpio_get_cd(host->mmc); 1299 + if (ret > 0) 1300 + present = true; 1301 + } 1302 + 1297 1303 if (!present || host->flags & SDHCI_DEVICE_DEAD) { 1298 1304 host->mrq->cmd->error = -ENOMEDIUM; 1299 1305 tasklet_schedule(&host->finish_tasklet); ··· 1605 1597 spin_unlock_irqrestore(&host->lock, flags); 1606 1598 } 1607 1599 1608 - static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host, 1609 - struct mmc_ios *ios) 1600 + static int sdhci_do_3_3v_signal_voltage_switch(struct sdhci_host *host, 1601 + u16 ctrl) 1610 1602 { 1611 - u8 pwr; 1612 - u16 clk, ctrl; 1613 - u32 present_state; 1603 + int ret; 1614 1604 1615 - /* 1616 - * Signal Voltage Switching is only applicable for Host Controllers 1617 - * v3.00 and above. 1618 - */ 1619 - if (host->version < SDHCI_SPEC_300) 1620 - return 0; 1605 + /* Set 1.8V Signal Enable in the Host Control2 register to 0 */ 1606 + ctrl &= ~SDHCI_CTRL_VDD_180; 1607 + sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 1621 1608 1622 - /* 1623 - * We first check whether the request is to set signalling voltage 1624 - * to 3.3V. If so, we change the voltage to 3.3V and return quickly. 1625 - */ 1626 - ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1627 - if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) { 1628 - /* Set 1.8V Signal Enable in the Host Control2 register to 0 */ 1629 - ctrl &= ~SDHCI_CTRL_VDD_180; 1630 - sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 1631 - 1632 - /* Wait for 5ms */ 1633 - usleep_range(5000, 5500); 1634 - 1635 - /* 3.3V regulator output should be stable within 5 ms */ 1636 - ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1637 - if (!(ctrl & SDHCI_CTRL_VDD_180)) 1638 - return 0; 1639 - else { 1640 - pr_info(DRIVER_NAME ": Switching to 3.3V " 1641 - "signalling voltage failed\n"); 1609 + if (host->vqmmc) { 1610 + ret = regulator_set_voltage(host->vqmmc, 3300000, 3300000); 1611 + if (ret) { 1612 + pr_warning("%s: Switching to 3.3V signalling voltage " 1613 + " failed\n", mmc_hostname(host->mmc)); 1642 1614 return -EIO; 1643 1615 } 1644 - } else if (!(ctrl & SDHCI_CTRL_VDD_180) && 1645 - (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180)) { 1646 - /* Stop SDCLK */ 1647 - clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); 1648 - clk &= ~SDHCI_CLOCK_CARD_EN; 1649 - sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); 1616 + } 1617 + /* Wait for 5ms */ 1618 + usleep_range(5000, 5500); 1650 1619 1651 - /* Check whether DAT[3:0] is 0000 */ 1652 - present_state = sdhci_readl(host, SDHCI_PRESENT_STATE); 1653 - if (!((present_state & SDHCI_DATA_LVL_MASK) >> 1654 - SDHCI_DATA_LVL_SHIFT)) { 1655 - /* 1656 - * Enable 1.8V Signal Enable in the Host Control2 1657 - * register 1658 - */ 1620 + /* 3.3V regulator output should be stable within 5 ms */ 1621 + ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1622 + if (!(ctrl & SDHCI_CTRL_VDD_180)) 1623 + return 0; 1624 + 1625 + pr_warning("%s: 3.3V regulator output did not became stable\n", 1626 + mmc_hostname(host->mmc)); 1627 + 1628 + return -EIO; 1629 + } 1630 + 1631 + static int sdhci_do_1_8v_signal_voltage_switch(struct sdhci_host *host, 1632 + u16 ctrl) 1633 + { 1634 + u8 pwr; 1635 + u16 clk; 1636 + u32 present_state; 1637 + int ret; 1638 + 1639 + /* Stop SDCLK */ 1640 + clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); 1641 + clk &= ~SDHCI_CLOCK_CARD_EN; 1642 + sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); 1643 + 1644 + /* Check whether DAT[3:0] is 0000 */ 1645 + present_state = sdhci_readl(host, SDHCI_PRESENT_STATE); 1646 + if (!((present_state & SDHCI_DATA_LVL_MASK) >> 1647 + SDHCI_DATA_LVL_SHIFT)) { 1648 + /* 1649 + * Enable 1.8V Signal Enable in the Host Control2 1650 + * register 1651 + */ 1652 + if (host->vqmmc) 1653 + ret = regulator_set_voltage(host->vqmmc, 1654 + 1800000, 1800000); 1655 + else 1656 + ret = 0; 1657 + 1658 + if (!ret) { 1659 1659 ctrl |= SDHCI_CTRL_VDD_180; 1660 1660 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 1661 1661 ··· 1672 1656 1673 1657 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1674 1658 if (ctrl & SDHCI_CTRL_VDD_180) { 1675 - /* Provide SDCLK again and wait for 1ms*/ 1659 + /* Provide SDCLK again and wait for 1ms */ 1676 1660 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); 1677 1661 clk |= SDHCI_CLOCK_CARD_EN; 1678 1662 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); ··· 1689 1673 return 0; 1690 1674 } 1691 1675 } 1676 + } 1692 1677 1693 - /* 1694 - * If we are here, that means the switch to 1.8V signaling 1695 - * failed. We power cycle the card, and retry initialization 1696 - * sequence by setting S18R to 0. 1697 - */ 1698 - pwr = sdhci_readb(host, SDHCI_POWER_CONTROL); 1699 - pwr &= ~SDHCI_POWER_ON; 1700 - sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1701 - if (host->vmmc) 1702 - regulator_disable(host->vmmc); 1678 + /* 1679 + * If we are here, that means the switch to 1.8V signaling 1680 + * failed. We power cycle the card, and retry initialization 1681 + * sequence by setting S18R to 0. 1682 + */ 1683 + pwr = sdhci_readb(host, SDHCI_POWER_CONTROL); 1684 + pwr &= ~SDHCI_POWER_ON; 1685 + sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1686 + if (host->vmmc) 1687 + regulator_disable(host->vmmc); 1703 1688 1704 - /* Wait for 1ms as per the spec */ 1705 - usleep_range(1000, 1500); 1706 - pwr |= SDHCI_POWER_ON; 1707 - sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1708 - if (host->vmmc) 1709 - regulator_enable(host->vmmc); 1689 + /* Wait for 1ms as per the spec */ 1690 + usleep_range(1000, 1500); 1691 + pwr |= SDHCI_POWER_ON; 1692 + sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1693 + if (host->vmmc) 1694 + regulator_enable(host->vmmc); 1710 1695 1711 - pr_info(DRIVER_NAME ": Switching to 1.8V signalling " 1712 - "voltage failed, retrying with S18R set to 0\n"); 1713 - return -EAGAIN; 1714 - } else 1696 + pr_warning("%s: Switching to 1.8V signalling voltage failed, " 1697 + "retrying with S18R set to 0\n", mmc_hostname(host->mmc)); 1698 + 1699 + return -EAGAIN; 1700 + } 1701 + 1702 + static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host, 1703 + struct mmc_ios *ios) 1704 + { 1705 + u16 ctrl; 1706 + 1707 + /* 1708 + * Signal Voltage Switching is only applicable for Host Controllers 1709 + * v3.00 and above. 1710 + */ 1711 + if (host->version < SDHCI_SPEC_300) 1712 + return 0; 1713 + 1714 + /* 1715 + * We first check whether the request is to set signalling voltage 1716 + * to 3.3V. If so, we change the voltage to 3.3V and return quickly. 1717 + */ 1718 + ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1719 + if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) 1720 + return sdhci_do_3_3v_signal_voltage_switch(host, ctrl); 1721 + else if (!(ctrl & SDHCI_CTRL_VDD_180) && 1722 + (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180)) 1723 + return sdhci_do_1_8v_signal_voltage_switch(host, ctrl); 1724 + else 1715 1725 /* No signal voltage switch required */ 1716 1726 return 0; 1717 1727 } ··· 2844 2802 !(host->mmc->caps & MMC_CAP_NONREMOVABLE)) 2845 2803 mmc->caps |= MMC_CAP_NEEDS_POLL; 2846 2804 2805 + /* If vqmmc regulator and no 1.8V signalling, then there's no UHS */ 2806 + host->vqmmc = regulator_get(mmc_dev(mmc), "vqmmc"); 2807 + if (IS_ERR(host->vqmmc)) { 2808 + pr_info("%s: no vqmmc regulator found\n", mmc_hostname(mmc)); 2809 + host->vqmmc = NULL; 2810 + } 2811 + else if (regulator_is_supported_voltage(host->vqmmc, 1800000, 1800000)) 2812 + regulator_enable(host->vqmmc); 2813 + else 2814 + caps[1] &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | 2815 + SDHCI_SUPPORT_DDR50); 2816 + 2847 2817 /* Any UHS-I mode in caps implies SDR12 and SDR25 support. */ 2848 2818 if (caps[1] & (SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | 2849 2819 SDHCI_SUPPORT_DDR50)) ··· 2886 2832 if (caps[1] & SDHCI_DRIVER_TYPE_D) 2887 2833 mmc->caps |= MMC_CAP_DRIVER_TYPE_D; 2888 2834 2889 - /* 2890 - * If Power Off Notify capability is enabled by the host, 2891 - * set notify to short power off notify timeout value. 2892 - */ 2893 - if (mmc->caps2 & MMC_CAP2_POWEROFF_NOTIFY) 2894 - mmc->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT; 2895 - else 2896 - mmc->power_notify_type = MMC_HOST_PW_NOTIFY_NONE; 2897 - 2898 2835 /* Initial value for re-tuning timer count */ 2899 2836 host->tuning_count = (caps[1] & SDHCI_RETUNING_TIMER_COUNT_MASK) >> 2900 2837 SDHCI_RETUNING_TIMER_COUNT_SHIFT; ··· 2907 2862 if (IS_ERR(host->vmmc)) { 2908 2863 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc)); 2909 2864 host->vmmc = NULL; 2910 - } 2865 + } else 2866 + regulator_enable(host->vmmc); 2911 2867 2912 2868 #ifdef CONFIG_REGULATOR 2913 2869 if (host->vmmc) { ··· 3165 3119 tasklet_kill(&host->card_tasklet); 3166 3120 tasklet_kill(&host->finish_tasklet); 3167 3121 3168 - if (host->vmmc) 3122 + if (host->vmmc) { 3123 + regulator_disable(host->vmmc); 3169 3124 regulator_put(host->vmmc); 3125 + } 3126 + 3127 + if (host->vqmmc) { 3128 + regulator_disable(host->vqmmc); 3129 + regulator_put(host->vqmmc); 3130 + } 3170 3131 3171 3132 kfree(host->adma_desc); 3172 3133 kfree(host->align_buffer);
+7 -1
drivers/mmc/host/sh_mmcif.c
··· 1213 1213 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_BUFRE); 1214 1214 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MBUFRE); 1215 1215 } else if (state & INT_DTRANE) { 1216 - sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_DTRANE); 1216 + sh_mmcif_writel(host->addr, MMCIF_CE_INT, 1217 + ~(INT_CMD12DRE | INT_CMD12RBE | 1218 + INT_CMD12CRE | INT_DTRANE)); 1217 1219 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MDTRANE); 1218 1220 } else if (state & INT_CMD12RBE) { 1219 1221 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ··· 1230 1228 if (err) { 1231 1229 host->sd_error = true; 1232 1230 dev_dbg(&host->pd->dev, "int err state = %08x\n", state); 1231 + } 1232 + if (host->state == STATE_IDLE) { 1233 + dev_info(&host->pd->dev, "Spurious IRQ status 0x%x", state); 1234 + return IRQ_HANDLED; 1233 1235 } 1234 1236 if (state & ~(INT_CMD12RBE | INT_CMD12CRE)) { 1235 1237 if (!host->dma_active)
+1 -15
drivers/mmc/host/via-sdmmc.c
··· 1337 1337 .resume = via_sd_resume, 1338 1338 }; 1339 1339 1340 - static int __init via_sd_drv_init(void) 1341 - { 1342 - pr_info(DRV_NAME ": VIA SD/MMC Card Reader driver " 1343 - "(C) 2008 VIA Technologies, Inc.\n"); 1344 - 1345 - return pci_register_driver(&via_sd_driver); 1346 - } 1347 - 1348 - static void __exit via_sd_drv_exit(void) 1349 - { 1350 - pci_unregister_driver(&via_sd_driver); 1351 - } 1352 - 1353 - module_init(via_sd_drv_init); 1354 - module_exit(via_sd_drv_exit); 1340 + module_pci_driver(via_sd_driver); 1355 1341 1356 1342 MODULE_LICENSE("GPL"); 1357 1343 MODULE_AUTHOR("VIA Technologies Inc.");
+2 -2
drivers/mmc/host/vub300.c
··· 2358 2358 * which is contained at the end of struct mmc 2359 2359 */ 2360 2360 error4: 2361 - usb_free_urb(command_out_urb); 2362 - error1: 2363 2361 usb_free_urb(command_res_urb); 2362 + error1: 2363 + usb_free_urb(command_out_urb); 2364 2364 error0: 2365 2365 return retval; 2366 2366 }
+9 -9
include/linux/mmc/card.h
··· 57 57 unsigned int sa_timeout; /* Units: 100ns */ 58 58 unsigned int generic_cmd6_time; /* Units: 10ms */ 59 59 unsigned int power_off_longtime; /* Units: ms */ 60 + u8 power_off_notification; /* state */ 60 61 unsigned int hs_max_dtr; 61 62 #define MMC_HIGH_26_MAX_DTR 26000000 62 63 #define MMC_HIGH_52_MAX_DTR 52000000 ··· 77 76 bool hpi_en; /* HPI enablebit */ 78 77 bool hpi; /* HPI support bit */ 79 78 unsigned int hpi_cmd; /* cmd used as HPI */ 79 + bool bkops; /* background support bit */ 80 + bool bkops_en; /* background enable bit */ 80 81 unsigned int data_sector_size; /* 512 bytes or 4KB */ 81 82 unsigned int data_tag_unit_size; /* DATA TAG UNIT size */ 82 83 unsigned int boot_ro_lock; /* ro lock support */ 83 84 bool boot_ro_lockable; 85 + u8 raw_exception_status; /* 53 */ 84 86 u8 raw_partition_support; /* 160 */ 85 87 u8 raw_erased_mem_count; /* 181 */ 86 88 u8 raw_ext_csd_structure; /* 194 */ ··· 97 93 u8 raw_sec_erase_mult; /* 230 */ 98 94 u8 raw_sec_feature_support;/* 231 */ 99 95 u8 raw_trim_mult; /* 232 */ 96 + u8 raw_bkops_status; /* 246 */ 100 97 u8 raw_sectors[4]; /* 212 - 4 bytes */ 101 98 102 99 unsigned int feature_support; ··· 230 225 #define MMC_CARD_SDXC (1<<6) /* card is SDXC */ 231 226 #define MMC_CARD_REMOVED (1<<7) /* card has been removed */ 232 227 #define MMC_STATE_HIGHSPEED_200 (1<<8) /* card is in HS200 mode */ 233 - #define MMC_STATE_SLEEP (1<<9) /* card is in sleep state */ 228 + #define MMC_STATE_DOING_BKOPS (1<<10) /* card is doing BKOPS */ 234 229 unsigned int quirks; /* card quirks */ 235 230 #define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */ 236 231 #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */ ··· 246 241 #define MMC_QUIRK_LONG_READ_TIME (1<<9) /* Data read time > CSD says */ 247 242 #define MMC_QUIRK_SEC_ERASE_TRIM_BROKEN (1<<10) /* Skip secure for erase/trim */ 248 243 /* byte mode */ 249 - unsigned int poweroff_notify_state; /* eMMC4.5 notify feature */ 250 - #define MMC_NO_POWER_NOTIFICATION 0 251 - #define MMC_POWERED_ON 1 252 - #define MMC_POWEROFF_SHORT 2 253 - #define MMC_POWEROFF_LONG 3 254 244 255 245 unsigned int erase_size; /* erase size in sectors */ 256 246 unsigned int erase_shift; /* if erase unit is power 2 */ ··· 392 392 #define mmc_sd_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED) 393 393 #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC) 394 394 #define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED)) 395 - #define mmc_card_is_sleep(c) ((c)->state & MMC_STATE_SLEEP) 395 + #define mmc_card_doing_bkops(c) ((c)->state & MMC_STATE_DOING_BKOPS) 396 396 397 397 #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) 398 398 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) ··· 404 404 #define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED) 405 405 #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC) 406 406 #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED) 407 - #define mmc_card_set_sleep(c) ((c)->state |= MMC_STATE_SLEEP) 407 + #define mmc_card_set_doing_bkops(c) ((c)->state |= MMC_STATE_DOING_BKOPS) 408 + #define mmc_card_clr_doing_bkops(c) ((c)->state &= ~MMC_STATE_DOING_BKOPS) 408 409 409 - #define mmc_card_clr_sleep(c) ((c)->state &= ~MMC_STATE_SLEEP) 410 410 /* 411 411 * Quirk add/remove for MMC products. 412 412 */
+4
include/linux/mmc/core.h
··· 134 134 struct mmc_card; 135 135 struct mmc_async_req; 136 136 137 + extern int mmc_stop_bkops(struct mmc_card *); 138 + extern int mmc_read_bkops_status(struct mmc_card *); 137 139 extern struct mmc_async_req *mmc_start_req(struct mmc_host *, 138 140 struct mmc_async_req *, int *); 139 141 extern int mmc_interrupt_hpi(struct mmc_card *); ··· 144 142 extern int mmc_app_cmd(struct mmc_host *, struct mmc_card *); 145 143 extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *, 146 144 struct mmc_command *, int); 145 + extern void mmc_start_bkops(struct mmc_card *card, bool from_exception); 146 + extern int __mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int, bool); 147 147 extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int); 148 148 149 149 #define MMC_ERASE_ARG 0x00000000
+12 -3
include/linux/mmc/dw_mmc.h
··· 78 78 * @data_offset: Set the offset of DATA register according to VERID. 79 79 * @dev: Device associated with the MMC controller. 80 80 * @pdata: Platform data associated with the MMC controller. 81 + * @drv_data: Driver specific data for identified variant of the controller 82 + * @priv: Implementation defined private data. 83 + * @biu_clk: Pointer to bus interface unit clock instance. 84 + * @ciu_clk: Pointer to card interface unit clock instance. 81 85 * @slot: Slots sharing this MMC controller. 82 86 * @fifo_depth: depth of FIFO. 83 87 * @data_shift: log2 of FIFO item size. ··· 160 156 u32 fifoth_val; 161 157 u16 verid; 162 158 u16 data_offset; 163 - struct device dev; 159 + struct device *dev; 164 160 struct dw_mci_board *pdata; 161 + struct dw_mci_drv_data *drv_data; 162 + void *priv; 163 + struct clk *biu_clk; 164 + struct clk *ciu_clk; 165 165 struct dw_mci_slot *slot[MAX_MCI_SLOTS]; 166 166 167 167 /* FIFO push and pull */ ··· 209 201 #define DW_MCI_QUIRK_HIGHSPEED BIT(2) 210 202 /* Unreliable card detection */ 211 203 #define DW_MCI_QUIRK_BROKEN_CARD_DETECTION BIT(3) 212 - 204 + /* Write Protect detection not available */ 205 + #define DW_MCI_QUIRK_NO_WRITE_PROTECT BIT(4) 213 206 214 207 struct dma_pdata; 215 208 ··· 227 218 u32 num_slots; 228 219 229 220 u32 quirks; /* Workaround / Quirk flags */ 230 - unsigned int bus_hz; /* Bus speed */ 221 + unsigned int bus_hz; /* Clock speed at the cclk_in pad */ 231 222 232 223 unsigned int caps; /* Capabilities */ 233 224 unsigned int caps2; /* More capabilities */
+1 -4
include/linux/mmc/host.h
··· 259 259 #define MMC_CAP2_RO_ACTIVE_HIGH (1 << 11) /* Write-protect signal active high */ 260 260 261 261 mmc_pm_flag_t pm_caps; /* supported pm features */ 262 - unsigned int power_notify_type; 263 - #define MMC_HOST_PW_NOTIFY_NONE 0 264 - #define MMC_HOST_PW_NOTIFY_SHORT 1 265 - #define MMC_HOST_PW_NOTIFY_LONG 2 266 262 267 263 #ifdef CONFIG_MMC_CLKGATE 268 264 int clk_requests; /* internal reference counter */ ··· 296 300 #endif 297 301 298 302 int rescan_disable; /* disable card detection */ 303 + int rescan_entered; /* used with nonremovable devices */ 299 304 300 305 struct mmc_card *card; /* device attached to this host */ 301 306
+19
include/linux/mmc/mmc.h
··· 139 139 #define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9) /* sx, b (4 bits) */ 140 140 #define R1_READY_FOR_DATA (1 << 8) /* sx, a */ 141 141 #define R1_SWITCH_ERROR (1 << 7) /* sx, c */ 142 + #define R1_EXCEPTION_EVENT (1 << 6) /* sx, a */ 142 143 #define R1_APP_CMD (1 << 5) /* sr, c */ 143 144 144 145 #define R1_STATE_IDLE 0 ··· 275 274 #define EXT_CSD_FLUSH_CACHE 32 /* W */ 276 275 #define EXT_CSD_CACHE_CTRL 33 /* R/W */ 277 276 #define EXT_CSD_POWER_OFF_NOTIFICATION 34 /* R/W */ 277 + #define EXT_CSD_EXP_EVENTS_STATUS 54 /* RO */ 278 278 #define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */ 279 279 #define EXT_CSD_GP_SIZE_MULT 143 /* R/W */ 280 280 #define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */ 281 281 #define EXT_CSD_PARTITION_SUPPORT 160 /* RO */ 282 282 #define EXT_CSD_HPI_MGMT 161 /* R/W */ 283 283 #define EXT_CSD_RST_N_FUNCTION 162 /* R/W */ 284 + #define EXT_CSD_BKOPS_EN 163 /* R/W */ 285 + #define EXT_CSD_BKOPS_START 164 /* W */ 284 286 #define EXT_CSD_SANITIZE_START 165 /* W */ 285 287 #define EXT_CSD_WR_REL_PARAM 166 /* RO */ 286 288 #define EXT_CSD_BOOT_WP 173 /* R/W */ ··· 317 313 #define EXT_CSD_PWR_CL_200_360 237 /* RO */ 318 314 #define EXT_CSD_PWR_CL_DDR_52_195 238 /* RO */ 319 315 #define EXT_CSD_PWR_CL_DDR_52_360 239 /* RO */ 316 + #define EXT_CSD_BKOPS_STATUS 246 /* RO */ 320 317 #define EXT_CSD_POWER_OFF_LONG_TIME 247 /* RO */ 321 318 #define EXT_CSD_GENERIC_CMD6_TIME 248 /* RO */ 322 319 #define EXT_CSD_CACHE_SIZE 249 /* RO, 4 bytes */ 323 320 #define EXT_CSD_TAG_UNIT_SIZE 498 /* RO */ 324 321 #define EXT_CSD_DATA_TAG_SUPPORT 499 /* RO */ 322 + #define EXT_CSD_BKOPS_SUPPORT 502 /* RO */ 325 323 #define EXT_CSD_HPI_FEATURES 503 /* RO */ 326 324 327 325 /* ··· 383 377 #define EXT_CSD_PWR_CL_4BIT_MASK 0x0F /* 8 bit PWR CLS */ 384 378 #define EXT_CSD_PWR_CL_8BIT_SHIFT 4 385 379 #define EXT_CSD_PWR_CL_4BIT_SHIFT 0 380 + /* 381 + * EXCEPTION_EVENT_STATUS field 382 + */ 383 + #define EXT_CSD_URGENT_BKOPS BIT(0) 384 + #define EXT_CSD_DYNCAP_NEEDED BIT(1) 385 + #define EXT_CSD_SYSPOOL_EXHAUSTED BIT(2) 386 + #define EXT_CSD_PACKED_FAILURE BIT(3) 387 + 388 + /* 389 + * BKOPS status level 390 + */ 391 + #define EXT_CSD_BKOPS_LEVEL_2 0x2 392 + 386 393 /* 387 394 * MMC_SWITCH access modes 388 395 */
+2 -1
include/linux/mmc/sdhci.h
··· 97 97 98 98 const struct sdhci_ops *ops; /* Low level hw interface */ 99 99 100 - struct regulator *vmmc; /* Power regulator */ 100 + struct regulator *vmmc; /* Power regulator (vmmc) */ 101 + struct regulator *vqmmc; /* Signaling regulator (vccq) */ 101 102 102 103 /* Internal data */ 103 104 struct mmc_host *mmc; /* MMC structure */
+1
include/linux/platform_data/pxa_sdhci.h
··· 49 49 bool ext_cd_gpio_invert; 50 50 unsigned int max_speed; 51 51 unsigned int host_caps; 52 + unsigned int host_caps2; 52 53 unsigned int quirks; 53 54 unsigned int pm_caps; 54 55 };