Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1 | /* |
Pierre Ossman | 70f1048 | 2007-07-11 20:04:50 +0200 | [diff] [blame] | 2 | * linux/drivers/mmc/host/sdhci.c - Secure Digital Host Controller Interface driver |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3 | * |
Pierre Ossman | b69c905 | 2008-03-08 23:44:25 +0100 | [diff] [blame] | 4 | * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved. |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Pierre Ossman | 643f720 | 2006-09-30 23:27:52 -0700 | [diff] [blame] | 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 (at |
| 9 | * your option) any later version. |
Pierre Ossman | 84c46a5 | 2007-12-02 19:58:16 +0100 | [diff] [blame] | 10 | * |
| 11 | * Thanks to the following companies for their support: |
| 12 | * |
| 13 | * - JMicron (hardware and technical support) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 16 | #include <linux/delay.h> |
| 17 | #include <linux/highmem.h> |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 18 | #include <linux/io.h> |
Paul Gortmaker | 88b4767 | 2011-07-03 15:15:51 -0400 | [diff] [blame] | 19 | #include <linux/module.h> |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 20 | #include <linux/dma-mapping.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Ralf Baechle | 1176360 | 2007-10-23 20:42:11 +0200 | [diff] [blame] | 22 | #include <linux/scatterlist.h> |
Marek Szyprowski | 9bea3c8 | 2010-08-10 18:01:59 -0700 | [diff] [blame] | 23 | #include <linux/regulator/consumer.h> |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 24 | #include <linux/pm_runtime.h> |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 25 | |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 26 | #include <linux/leds.h> |
| 27 | |
Aries Lee | 22113ef | 2010-12-15 08:14:24 +0100 | [diff] [blame] | 28 | #include <linux/mmc/mmc.h> |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 29 | #include <linux/mmc/host.h> |
Aaron Lu | 473b095 | 2012-07-03 17:27:49 +0800 | [diff] [blame] | 30 | #include <linux/mmc/card.h> |
Corneliu Doban | 85cc1c3 | 2015-02-09 16:06:29 -0800 | [diff] [blame^] | 31 | #include <linux/mmc/sdio.h> |
Guennadi Liakhovetski | bec9d4e | 2012-09-17 16:45:10 +0800 | [diff] [blame] | 32 | #include <linux/mmc/slot-gpio.h> |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 33 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 34 | #include "sdhci.h" |
| 35 | |
| 36 | #define DRIVER_NAME "sdhci" |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 37 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 38 | #define DBG(f, x...) \ |
Russell King | c656317 | 2006-03-29 09:30:20 +0100 | [diff] [blame] | 39 | pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 40 | |
Pierre Ossman | f913431 | 2008-12-21 17:01:48 +0100 | [diff] [blame] | 41 | #if defined(CONFIG_LEDS_CLASS) || (defined(CONFIG_LEDS_CLASS_MODULE) && \ |
| 42 | defined(CONFIG_MMC_SDHCI_MODULE)) |
| 43 | #define SDHCI_USE_LEDS_CLASS |
| 44 | #endif |
| 45 | |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 46 | #define MAX_TUNING_LOOP 40 |
| 47 | |
Pierre Ossman | df673b2 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 48 | static unsigned int debug_quirks = 0; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 49 | static unsigned int debug_quirks2; |
Pierre Ossman | 6743527 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 50 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 51 | static void sdhci_finish_data(struct sdhci_host *); |
| 52 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 53 | static void sdhci_finish_command(struct sdhci_host *); |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 54 | static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode); |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 55 | static void sdhci_tuning_timer(unsigned long data); |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 56 | static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable); |
Haibo Chen | 348487c | 2014-12-09 17:04:05 +0800 | [diff] [blame] | 57 | static int sdhci_pre_dma_transfer(struct sdhci_host *host, |
| 58 | struct mmc_data *data, |
| 59 | struct sdhci_host_next *next); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 60 | |
Rafael J. Wysocki | 162d6f9 | 2014-12-05 03:05:33 +0100 | [diff] [blame] | 61 | #ifdef CONFIG_PM |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 62 | static int sdhci_runtime_pm_get(struct sdhci_host *host); |
| 63 | static int sdhci_runtime_pm_put(struct sdhci_host *host); |
Adrian Hunter | f0710a5 | 2013-05-06 12:17:32 +0300 | [diff] [blame] | 64 | static void sdhci_runtime_pm_bus_on(struct sdhci_host *host); |
| 65 | static void sdhci_runtime_pm_bus_off(struct sdhci_host *host); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 66 | #else |
| 67 | static inline int sdhci_runtime_pm_get(struct sdhci_host *host) |
| 68 | { |
| 69 | return 0; |
| 70 | } |
| 71 | static inline int sdhci_runtime_pm_put(struct sdhci_host *host) |
| 72 | { |
| 73 | return 0; |
| 74 | } |
Adrian Hunter | f0710a5 | 2013-05-06 12:17:32 +0300 | [diff] [blame] | 75 | static void sdhci_runtime_pm_bus_on(struct sdhci_host *host) |
| 76 | { |
| 77 | } |
| 78 | static void sdhci_runtime_pm_bus_off(struct sdhci_host *host) |
| 79 | { |
| 80 | } |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 81 | #endif |
| 82 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 83 | static void sdhci_dumpregs(struct sdhci_host *host) |
| 84 | { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 85 | pr_debug(DRIVER_NAME ": =========== REGISTER DUMP (%s)===========\n", |
Philip Rakity | 412ab65 | 2010-09-22 15:25:13 -0700 | [diff] [blame] | 86 | mmc_hostname(host->mmc)); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 87 | |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 88 | pr_debug(DRIVER_NAME ": Sys addr: 0x%08x | Version: 0x%08x\n", |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 89 | sdhci_readl(host, SDHCI_DMA_ADDRESS), |
| 90 | sdhci_readw(host, SDHCI_HOST_VERSION)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 91 | pr_debug(DRIVER_NAME ": Blk size: 0x%08x | Blk cnt: 0x%08x\n", |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 92 | sdhci_readw(host, SDHCI_BLOCK_SIZE), |
| 93 | sdhci_readw(host, SDHCI_BLOCK_COUNT)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 94 | pr_debug(DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n", |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 95 | sdhci_readl(host, SDHCI_ARGUMENT), |
| 96 | sdhci_readw(host, SDHCI_TRANSFER_MODE)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 97 | pr_debug(DRIVER_NAME ": Present: 0x%08x | Host ctl: 0x%08x\n", |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 98 | sdhci_readl(host, SDHCI_PRESENT_STATE), |
| 99 | sdhci_readb(host, SDHCI_HOST_CONTROL)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 100 | pr_debug(DRIVER_NAME ": Power: 0x%08x | Blk gap: 0x%08x\n", |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 101 | sdhci_readb(host, SDHCI_POWER_CONTROL), |
| 102 | sdhci_readb(host, SDHCI_BLOCK_GAP_CONTROL)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 103 | pr_debug(DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n", |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 104 | sdhci_readb(host, SDHCI_WAKE_UP_CONTROL), |
| 105 | sdhci_readw(host, SDHCI_CLOCK_CONTROL)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 106 | pr_debug(DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n", |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 107 | sdhci_readb(host, SDHCI_TIMEOUT_CONTROL), |
| 108 | sdhci_readl(host, SDHCI_INT_STATUS)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 109 | pr_debug(DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n", |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 110 | sdhci_readl(host, SDHCI_INT_ENABLE), |
| 111 | sdhci_readl(host, SDHCI_SIGNAL_ENABLE)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 112 | pr_debug(DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n", |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 113 | sdhci_readw(host, SDHCI_ACMD12_ERR), |
| 114 | sdhci_readw(host, SDHCI_SLOT_INT_STATUS)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 115 | pr_debug(DRIVER_NAME ": Caps: 0x%08x | Caps_1: 0x%08x\n", |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 116 | sdhci_readl(host, SDHCI_CAPABILITIES), |
Philip Rakity | e8120ad | 2010-11-30 00:55:23 -0500 | [diff] [blame] | 117 | sdhci_readl(host, SDHCI_CAPABILITIES_1)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 118 | pr_debug(DRIVER_NAME ": Cmd: 0x%08x | Max curr: 0x%08x\n", |
Philip Rakity | e8120ad | 2010-11-30 00:55:23 -0500 | [diff] [blame] | 119 | sdhci_readw(host, SDHCI_COMMAND), |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 120 | sdhci_readl(host, SDHCI_MAX_CURRENT)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 121 | pr_debug(DRIVER_NAME ": Host ctl2: 0x%08x\n", |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 122 | sdhci_readw(host, SDHCI_HOST_CONTROL2)); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 123 | |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 124 | if (host->flags & SDHCI_USE_ADMA) { |
| 125 | if (host->flags & SDHCI_USE_64_BIT_DMA) |
| 126 | pr_debug(DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x%08x\n", |
| 127 | readl(host->ioaddr + SDHCI_ADMA_ERROR), |
| 128 | readl(host->ioaddr + SDHCI_ADMA_ADDRESS_HI), |
| 129 | readl(host->ioaddr + SDHCI_ADMA_ADDRESS)); |
| 130 | else |
| 131 | pr_debug(DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x\n", |
| 132 | readl(host->ioaddr + SDHCI_ADMA_ERROR), |
| 133 | readl(host->ioaddr + SDHCI_ADMA_ADDRESS)); |
| 134 | } |
Ben Dooks | be3f4ae | 2009-06-08 23:33:52 +0100 | [diff] [blame] | 135 | |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 136 | pr_debug(DRIVER_NAME ": ===========================================\n"); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /*****************************************************************************\ |
| 140 | * * |
| 141 | * Low level functions * |
| 142 | * * |
| 143 | \*****************************************************************************/ |
| 144 | |
Anton Vorontsov | 7260cf5 | 2009-03-17 00:13:48 +0300 | [diff] [blame] | 145 | static void sdhci_set_card_detection(struct sdhci_host *host, bool enable) |
| 146 | { |
Russell King | 5b4f1f6 | 2014-04-25 12:57:02 +0100 | [diff] [blame] | 147 | u32 present; |
Anton Vorontsov | 7260cf5 | 2009-03-17 00:13:48 +0300 | [diff] [blame] | 148 | |
Adrian Hunter | c79396c | 2011-12-27 15:48:42 +0200 | [diff] [blame] | 149 | if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) || |
Daniel Drake | 87b87a3 | 2012-04-10 00:14:20 +0100 | [diff] [blame] | 150 | (host->mmc->caps & MMC_CAP_NONREMOVABLE)) |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 151 | return; |
| 152 | |
Russell King | 5b4f1f6 | 2014-04-25 12:57:02 +0100 | [diff] [blame] | 153 | if (enable) { |
| 154 | present = sdhci_readl(host, SDHCI_PRESENT_STATE) & |
| 155 | SDHCI_CARD_PRESENT; |
Shawn Guo | d25928d | 2011-06-21 22:41:48 +0800 | [diff] [blame] | 156 | |
Russell King | 5b4f1f6 | 2014-04-25 12:57:02 +0100 | [diff] [blame] | 157 | host->ier |= present ? SDHCI_INT_CARD_REMOVE : |
| 158 | SDHCI_INT_CARD_INSERT; |
| 159 | } else { |
| 160 | host->ier &= ~(SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT); |
| 161 | } |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 162 | |
| 163 | sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); |
| 164 | sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); |
Anton Vorontsov | 7260cf5 | 2009-03-17 00:13:48 +0300 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static void sdhci_enable_card_detection(struct sdhci_host *host) |
| 168 | { |
| 169 | sdhci_set_card_detection(host, true); |
| 170 | } |
| 171 | |
| 172 | static void sdhci_disable_card_detection(struct sdhci_host *host) |
| 173 | { |
| 174 | sdhci_set_card_detection(host, false); |
| 175 | } |
| 176 | |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 177 | void sdhci_reset(struct sdhci_host *host, u8 mask) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 178 | { |
Pierre Ossman | e16514d8 | 2006-06-30 02:22:24 -0700 | [diff] [blame] | 179 | unsigned long timeout; |
Philip Rakity | 393c1a3 | 2011-01-21 11:26:40 -0800 | [diff] [blame] | 180 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 181 | sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 182 | |
Adrian Hunter | f0710a5 | 2013-05-06 12:17:32 +0300 | [diff] [blame] | 183 | if (mask & SDHCI_RESET_ALL) { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 184 | host->clock = 0; |
Adrian Hunter | f0710a5 | 2013-05-06 12:17:32 +0300 | [diff] [blame] | 185 | /* Reset-all turns off SD Bus Power */ |
| 186 | if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) |
| 187 | sdhci_runtime_pm_bus_off(host); |
| 188 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 189 | |
Pierre Ossman | e16514d8 | 2006-06-30 02:22:24 -0700 | [diff] [blame] | 190 | /* Wait max 100 ms */ |
| 191 | timeout = 100; |
| 192 | |
| 193 | /* hw clears the bit when it's done */ |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 194 | while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) { |
Pierre Ossman | e16514d8 | 2006-06-30 02:22:24 -0700 | [diff] [blame] | 195 | if (timeout == 0) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 196 | pr_err("%s: Reset 0x%x never completed.\n", |
Pierre Ossman | e16514d8 | 2006-06-30 02:22:24 -0700 | [diff] [blame] | 197 | mmc_hostname(host->mmc), (int)mask); |
| 198 | sdhci_dumpregs(host); |
| 199 | return; |
| 200 | } |
| 201 | timeout--; |
| 202 | mdelay(1); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 203 | } |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 204 | } |
| 205 | EXPORT_SYMBOL_GPL(sdhci_reset); |
Anton Vorontsov | 063a9db | 2009-03-17 00:14:02 +0300 | [diff] [blame] | 206 | |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 207 | static void sdhci_do_reset(struct sdhci_host *host, u8 mask) |
| 208 | { |
| 209 | if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) { |
| 210 | if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) & |
| 211 | SDHCI_CARD_PRESENT)) |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | host->ops->reset(host, mask); |
Philip Rakity | 393c1a3 | 2011-01-21 11:26:40 -0800 | [diff] [blame] | 216 | |
Russell King | da91a8f | 2014-04-25 13:00:12 +0100 | [diff] [blame] | 217 | if (mask & SDHCI_RESET_ALL) { |
| 218 | if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { |
| 219 | if (host->ops->enable_dma) |
| 220 | host->ops->enable_dma(host); |
| 221 | } |
| 222 | |
| 223 | /* Resetting the controller clears many */ |
| 224 | host->preset_enabled = false; |
Shaohui Xie | 3abc1e80 | 2011-12-29 16:33:00 +0800 | [diff] [blame] | 225 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 228 | static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios); |
| 229 | |
| 230 | static void sdhci_init(struct sdhci_host *host, int soft) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 231 | { |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 232 | if (soft) |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 233 | sdhci_do_reset(host, SDHCI_RESET_CMD|SDHCI_RESET_DATA); |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 234 | else |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 235 | sdhci_do_reset(host, SDHCI_RESET_ALL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 236 | |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 237 | host->ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT | |
| 238 | SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT | |
| 239 | SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC | |
| 240 | SDHCI_INT_TIMEOUT | SDHCI_INT_DATA_END | |
| 241 | SDHCI_INT_RESPONSE; |
| 242 | |
| 243 | sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); |
| 244 | sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 245 | |
| 246 | if (soft) { |
| 247 | /* force clock reconfiguration */ |
| 248 | host->clock = 0; |
| 249 | sdhci_set_ios(host->mmc, &host->mmc->ios); |
| 250 | } |
Anton Vorontsov | 7260cf5 | 2009-03-17 00:13:48 +0300 | [diff] [blame] | 251 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 252 | |
Anton Vorontsov | 7260cf5 | 2009-03-17 00:13:48 +0300 | [diff] [blame] | 253 | static void sdhci_reinit(struct sdhci_host *host) |
| 254 | { |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 255 | sdhci_init(host, 0); |
Aaron Lu | b67c6b4 | 2012-06-29 16:17:31 +0800 | [diff] [blame] | 256 | /* |
| 257 | * Retuning stuffs are affected by different cards inserted and only |
| 258 | * applicable to UHS-I cards. So reset these fields to their initial |
| 259 | * value when card is removed. |
| 260 | */ |
Aaron Lu | 973905f | 2012-07-04 13:29:09 +0800 | [diff] [blame] | 261 | if (host->flags & SDHCI_USING_RETUNING_TIMER) { |
| 262 | host->flags &= ~SDHCI_USING_RETUNING_TIMER; |
| 263 | |
Aaron Lu | b67c6b4 | 2012-06-29 16:17:31 +0800 | [diff] [blame] | 264 | del_timer_sync(&host->tuning_timer); |
| 265 | host->flags &= ~SDHCI_NEEDS_RETUNING; |
Aaron Lu | b67c6b4 | 2012-06-29 16:17:31 +0800 | [diff] [blame] | 266 | } |
Anton Vorontsov | 7260cf5 | 2009-03-17 00:13:48 +0300 | [diff] [blame] | 267 | sdhci_enable_card_detection(host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static void sdhci_activate_led(struct sdhci_host *host) |
| 271 | { |
| 272 | u8 ctrl; |
| 273 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 274 | ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 275 | ctrl |= SDHCI_CTRL_LED; |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 276 | sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static void sdhci_deactivate_led(struct sdhci_host *host) |
| 280 | { |
| 281 | u8 ctrl; |
| 282 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 283 | ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 284 | ctrl &= ~SDHCI_CTRL_LED; |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 285 | sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Pierre Ossman | f913431 | 2008-12-21 17:01:48 +0100 | [diff] [blame] | 288 | #ifdef SDHCI_USE_LEDS_CLASS |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 289 | static void sdhci_led_control(struct led_classdev *led, |
| 290 | enum led_brightness brightness) |
| 291 | { |
| 292 | struct sdhci_host *host = container_of(led, struct sdhci_host, led); |
| 293 | unsigned long flags; |
| 294 | |
| 295 | spin_lock_irqsave(&host->lock, flags); |
| 296 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 297 | if (host->runtime_suspended) |
| 298 | goto out; |
| 299 | |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 300 | if (brightness == LED_OFF) |
| 301 | sdhci_deactivate_led(host); |
| 302 | else |
| 303 | sdhci_activate_led(host); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 304 | out: |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 305 | spin_unlock_irqrestore(&host->lock, flags); |
| 306 | } |
| 307 | #endif |
| 308 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 309 | /*****************************************************************************\ |
| 310 | * * |
| 311 | * Core functions * |
| 312 | * * |
| 313 | \*****************************************************************************/ |
| 314 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 315 | static void sdhci_read_block_pio(struct sdhci_host *host) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 316 | { |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 317 | unsigned long flags; |
| 318 | size_t blksize, len, chunk; |
Steven Noonan | 7244b85 | 2008-10-01 01:50:25 -0700 | [diff] [blame] | 319 | u32 uninitialized_var(scratch); |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 320 | u8 *buf; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 321 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 322 | DBG("PIO reading\n"); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 323 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 324 | blksize = host->data->blksz; |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 325 | chunk = 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 326 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 327 | local_irq_save(flags); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 328 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 329 | while (blksize) { |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 330 | if (!sg_miter_next(&host->sg_miter)) |
| 331 | BUG(); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 332 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 333 | len = min(host->sg_miter.length, blksize); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 334 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 335 | blksize -= len; |
| 336 | host->sg_miter.consumed = len; |
Alex Dubov | 14d836e | 2007-04-13 19:04:38 +0200 | [diff] [blame] | 337 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 338 | buf = host->sg_miter.addr; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 339 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 340 | while (len) { |
| 341 | if (chunk == 0) { |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 342 | scratch = sdhci_readl(host, SDHCI_BUFFER); |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 343 | chunk = 4; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 344 | } |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 345 | |
| 346 | *buf = scratch & 0xFF; |
| 347 | |
| 348 | buf++; |
| 349 | scratch >>= 8; |
| 350 | chunk--; |
| 351 | len--; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 352 | } |
| 353 | } |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 354 | |
| 355 | sg_miter_stop(&host->sg_miter); |
| 356 | |
| 357 | local_irq_restore(flags); |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 358 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 359 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 360 | static void sdhci_write_block_pio(struct sdhci_host *host) |
| 361 | { |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 362 | unsigned long flags; |
| 363 | size_t blksize, len, chunk; |
| 364 | u32 scratch; |
| 365 | u8 *buf; |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 366 | |
| 367 | DBG("PIO writing\n"); |
| 368 | |
| 369 | blksize = host->data->blksz; |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 370 | chunk = 0; |
| 371 | scratch = 0; |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 372 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 373 | local_irq_save(flags); |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 374 | |
| 375 | while (blksize) { |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 376 | if (!sg_miter_next(&host->sg_miter)) |
| 377 | BUG(); |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 378 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 379 | len = min(host->sg_miter.length, blksize); |
Alex Dubov | 14d836e | 2007-04-13 19:04:38 +0200 | [diff] [blame] | 380 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 381 | blksize -= len; |
| 382 | host->sg_miter.consumed = len; |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 383 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 384 | buf = host->sg_miter.addr; |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 385 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 386 | while (len) { |
| 387 | scratch |= (u32)*buf << (chunk * 8); |
| 388 | |
| 389 | buf++; |
| 390 | chunk++; |
| 391 | len--; |
| 392 | |
| 393 | if ((chunk == 4) || ((len == 0) && (blksize == 0))) { |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 394 | sdhci_writel(host, scratch, SDHCI_BUFFER); |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 395 | chunk = 0; |
| 396 | scratch = 0; |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 397 | } |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 398 | } |
| 399 | } |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 400 | |
| 401 | sg_miter_stop(&host->sg_miter); |
| 402 | |
| 403 | local_irq_restore(flags); |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static void sdhci_transfer_pio(struct sdhci_host *host) |
| 407 | { |
| 408 | u32 mask; |
| 409 | |
| 410 | BUG_ON(!host->data); |
| 411 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 412 | if (host->blocks == 0) |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 413 | return; |
| 414 | |
| 415 | if (host->data->flags & MMC_DATA_READ) |
| 416 | mask = SDHCI_DATA_AVAILABLE; |
| 417 | else |
| 418 | mask = SDHCI_SPACE_AVAILABLE; |
| 419 | |
Pierre Ossman | 4a3cba3 | 2008-07-29 00:11:16 +0200 | [diff] [blame] | 420 | /* |
| 421 | * Some controllers (JMicron JMB38x) mess up the buffer bits |
| 422 | * for transfers < 4 bytes. As long as it is just one block, |
| 423 | * we can ignore the bits. |
| 424 | */ |
| 425 | if ((host->quirks & SDHCI_QUIRK_BROKEN_SMALL_PIO) && |
| 426 | (host->data->blocks == 1)) |
| 427 | mask = ~0; |
| 428 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 429 | while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) { |
Anton Vorontsov | 3e3bf20 | 2009-03-17 00:14:00 +0300 | [diff] [blame] | 430 | if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY) |
| 431 | udelay(100); |
| 432 | |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 433 | if (host->data->flags & MMC_DATA_READ) |
| 434 | sdhci_read_block_pio(host); |
| 435 | else |
| 436 | sdhci_write_block_pio(host); |
| 437 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 438 | host->blocks--; |
| 439 | if (host->blocks == 0) |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 440 | break; |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | DBG("PIO transfer complete.\n"); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 444 | } |
| 445 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 446 | static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags) |
| 447 | { |
| 448 | local_irq_save(*flags); |
Cong Wang | 482fce9 | 2011-11-27 13:27:00 +0800 | [diff] [blame] | 449 | return kmap_atomic(sg_page(sg)) + sg->offset; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static void sdhci_kunmap_atomic(void *buffer, unsigned long *flags) |
| 453 | { |
Cong Wang | 482fce9 | 2011-11-27 13:27:00 +0800 | [diff] [blame] | 454 | kunmap_atomic(buffer); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 455 | local_irq_restore(*flags); |
| 456 | } |
| 457 | |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 458 | static void sdhci_adma_write_desc(struct sdhci_host *host, void *desc, |
| 459 | dma_addr_t addr, int len, unsigned cmd) |
Ben Dooks | 118cd17 | 2010-03-05 13:43:26 -0800 | [diff] [blame] | 460 | { |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 461 | struct sdhci_adma2_64_desc *dma_desc = desc; |
Ben Dooks | 118cd17 | 2010-03-05 13:43:26 -0800 | [diff] [blame] | 462 | |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 463 | /* 32-bit and 64-bit descriptors have these members in same position */ |
Adrian Hunter | 0545230 | 2014-11-04 12:42:45 +0200 | [diff] [blame] | 464 | dma_desc->cmd = cpu_to_le16(cmd); |
| 465 | dma_desc->len = cpu_to_le16(len); |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 466 | dma_desc->addr_lo = cpu_to_le32((u32)addr); |
| 467 | |
| 468 | if (host->flags & SDHCI_USE_64_BIT_DMA) |
| 469 | dma_desc->addr_hi = cpu_to_le32((u64)addr >> 32); |
Ben Dooks | 118cd17 | 2010-03-05 13:43:26 -0800 | [diff] [blame] | 470 | } |
| 471 | |
Adrian Hunter | b5ffa67 | 2014-11-04 12:42:40 +0200 | [diff] [blame] | 472 | static void sdhci_adma_mark_end(void *desc) |
| 473 | { |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 474 | struct sdhci_adma2_64_desc *dma_desc = desc; |
Adrian Hunter | b5ffa67 | 2014-11-04 12:42:40 +0200 | [diff] [blame] | 475 | |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 476 | /* 32-bit and 64-bit descriptors have 'cmd' in same position */ |
Adrian Hunter | 0545230 | 2014-11-04 12:42:45 +0200 | [diff] [blame] | 477 | dma_desc->cmd |= cpu_to_le16(ADMA2_END); |
Adrian Hunter | b5ffa67 | 2014-11-04 12:42:40 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 480 | static int sdhci_adma_table_pre(struct sdhci_host *host, |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 481 | struct mmc_data *data) |
| 482 | { |
| 483 | int direction; |
| 484 | |
Adrian Hunter | 1c3d5f6 | 2014-11-04 12:42:41 +0200 | [diff] [blame] | 485 | void *desc; |
| 486 | void *align; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 487 | dma_addr_t addr; |
| 488 | dma_addr_t align_addr; |
| 489 | int len, offset; |
| 490 | |
| 491 | struct scatterlist *sg; |
| 492 | int i; |
| 493 | char *buffer; |
| 494 | unsigned long flags; |
| 495 | |
| 496 | /* |
| 497 | * The spec does not specify endianness of descriptor table. |
| 498 | * We currently guess that it is LE. |
| 499 | */ |
| 500 | |
| 501 | if (data->flags & MMC_DATA_READ) |
| 502 | direction = DMA_FROM_DEVICE; |
| 503 | else |
| 504 | direction = DMA_TO_DEVICE; |
| 505 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 506 | host->align_addr = dma_map_single(mmc_dev(host->mmc), |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 507 | host->align_buffer, host->align_buffer_sz, direction); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 508 | if (dma_mapping_error(mmc_dev(host->mmc), host->align_addr)) |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 509 | goto fail; |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 510 | BUG_ON(host->align_addr & host->align_mask); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 511 | |
Haibo Chen | 348487c | 2014-12-09 17:04:05 +0800 | [diff] [blame] | 512 | host->sg_count = sdhci_pre_dma_transfer(host, data, NULL); |
| 513 | if (host->sg_count < 0) |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 514 | goto unmap_align; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 515 | |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 516 | desc = host->adma_table; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 517 | align = host->align_buffer; |
| 518 | |
| 519 | align_addr = host->align_addr; |
| 520 | |
| 521 | for_each_sg(data->sg, sg, host->sg_count, i) { |
| 522 | addr = sg_dma_address(sg); |
| 523 | len = sg_dma_len(sg); |
| 524 | |
| 525 | /* |
| 526 | * The SDHCI specification states that ADMA |
| 527 | * addresses must be 32-bit aligned. If they |
| 528 | * aren't, then we use a bounce buffer for |
| 529 | * the (up to three) bytes that screw up the |
| 530 | * alignment. |
| 531 | */ |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 532 | offset = (host->align_sz - (addr & host->align_mask)) & |
| 533 | host->align_mask; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 534 | if (offset) { |
| 535 | if (data->flags & MMC_DATA_WRITE) { |
| 536 | buffer = sdhci_kmap_atomic(sg, &flags); |
| 537 | memcpy(align, buffer, offset); |
| 538 | sdhci_kunmap_atomic(buffer, &flags); |
| 539 | } |
| 540 | |
Ben Dooks | 118cd17 | 2010-03-05 13:43:26 -0800 | [diff] [blame] | 541 | /* tran, valid */ |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 542 | sdhci_adma_write_desc(host, desc, align_addr, offset, |
Adrian Hunter | 739d46d | 2014-11-04 12:42:44 +0200 | [diff] [blame] | 543 | ADMA2_TRAN_VALID); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 544 | |
| 545 | BUG_ON(offset > 65536); |
| 546 | |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 547 | align += host->align_sz; |
| 548 | align_addr += host->align_sz; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 549 | |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 550 | desc += host->desc_sz; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 551 | |
| 552 | addr += offset; |
| 553 | len -= offset; |
| 554 | } |
| 555 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 556 | BUG_ON(len > 65536); |
| 557 | |
Ben Dooks | 118cd17 | 2010-03-05 13:43:26 -0800 | [diff] [blame] | 558 | /* tran, valid */ |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 559 | sdhci_adma_write_desc(host, desc, addr, len, ADMA2_TRAN_VALID); |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 560 | desc += host->desc_sz; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 561 | |
| 562 | /* |
| 563 | * If this triggers then we have a calculation bug |
| 564 | * somewhere. :/ |
| 565 | */ |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 566 | WARN_ON((desc - host->adma_table) >= host->adma_table_sz); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 567 | } |
| 568 | |
Thomas Abraham | 70764a9 | 2010-05-26 14:42:04 -0700 | [diff] [blame] | 569 | if (host->quirks & SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC) { |
| 570 | /* |
| 571 | * Mark the last descriptor as the terminating descriptor |
| 572 | */ |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 573 | if (desc != host->adma_table) { |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 574 | desc -= host->desc_sz; |
Adrian Hunter | b5ffa67 | 2014-11-04 12:42:40 +0200 | [diff] [blame] | 575 | sdhci_adma_mark_end(desc); |
Thomas Abraham | 70764a9 | 2010-05-26 14:42:04 -0700 | [diff] [blame] | 576 | } |
| 577 | } else { |
| 578 | /* |
| 579 | * Add a terminating entry. |
| 580 | */ |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 581 | |
Thomas Abraham | 70764a9 | 2010-05-26 14:42:04 -0700 | [diff] [blame] | 582 | /* nop, end, valid */ |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 583 | sdhci_adma_write_desc(host, desc, 0, 0, ADMA2_NOP_END_VALID); |
Thomas Abraham | 70764a9 | 2010-05-26 14:42:04 -0700 | [diff] [blame] | 584 | } |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 585 | |
| 586 | /* |
| 587 | * Resync align buffer as we might have changed it. |
| 588 | */ |
| 589 | if (data->flags & MMC_DATA_WRITE) { |
| 590 | dma_sync_single_for_device(mmc_dev(host->mmc), |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 591 | host->align_addr, host->align_buffer_sz, direction); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 592 | } |
| 593 | |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 594 | return 0; |
| 595 | |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 596 | unmap_align: |
| 597 | dma_unmap_single(mmc_dev(host->mmc), host->align_addr, |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 598 | host->align_buffer_sz, direction); |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 599 | fail: |
| 600 | return -EINVAL; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static void sdhci_adma_table_post(struct sdhci_host *host, |
| 604 | struct mmc_data *data) |
| 605 | { |
| 606 | int direction; |
| 607 | |
| 608 | struct scatterlist *sg; |
| 609 | int i, size; |
Adrian Hunter | 1c3d5f6 | 2014-11-04 12:42:41 +0200 | [diff] [blame] | 610 | void *align; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 611 | char *buffer; |
| 612 | unsigned long flags; |
Russell King | de0b65a | 2014-04-25 12:58:29 +0100 | [diff] [blame] | 613 | bool has_unaligned; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 614 | |
| 615 | if (data->flags & MMC_DATA_READ) |
| 616 | direction = DMA_FROM_DEVICE; |
| 617 | else |
| 618 | direction = DMA_TO_DEVICE; |
| 619 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 620 | dma_unmap_single(mmc_dev(host->mmc), host->align_addr, |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 621 | host->align_buffer_sz, direction); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 622 | |
Russell King | de0b65a | 2014-04-25 12:58:29 +0100 | [diff] [blame] | 623 | /* Do a quick scan of the SG list for any unaligned mappings */ |
| 624 | has_unaligned = false; |
| 625 | for_each_sg(data->sg, sg, host->sg_count, i) |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 626 | if (sg_dma_address(sg) & host->align_mask) { |
Russell King | de0b65a | 2014-04-25 12:58:29 +0100 | [diff] [blame] | 627 | has_unaligned = true; |
| 628 | break; |
| 629 | } |
| 630 | |
| 631 | if (has_unaligned && data->flags & MMC_DATA_READ) { |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 632 | dma_sync_sg_for_cpu(mmc_dev(host->mmc), data->sg, |
| 633 | data->sg_len, direction); |
| 634 | |
| 635 | align = host->align_buffer; |
| 636 | |
| 637 | for_each_sg(data->sg, sg, host->sg_count, i) { |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 638 | if (sg_dma_address(sg) & host->align_mask) { |
| 639 | size = host->align_sz - |
| 640 | (sg_dma_address(sg) & host->align_mask); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 641 | |
| 642 | buffer = sdhci_kmap_atomic(sg, &flags); |
| 643 | memcpy(buffer, align, size); |
| 644 | sdhci_kunmap_atomic(buffer, &flags); |
| 645 | |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 646 | align += host->align_sz; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | } |
| 650 | |
Haibo Chen | 348487c | 2014-12-09 17:04:05 +0800 | [diff] [blame] | 651 | if (!data->host_cookie) |
| 652 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, |
| 653 | data->sg_len, direction); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 654 | } |
| 655 | |
Andrei Warkentin | a3c7778 | 2011-04-11 16:13:42 -0500 | [diff] [blame] | 656 | static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 657 | { |
Pierre Ossman | 1c8cde9 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 658 | u8 count; |
Andrei Warkentin | a3c7778 | 2011-04-11 16:13:42 -0500 | [diff] [blame] | 659 | struct mmc_data *data = cmd->data; |
Pierre Ossman | 1c8cde9 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 660 | unsigned target_timeout, current_timeout; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 661 | |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 662 | /* |
| 663 | * If the host controller provides us with an incorrect timeout |
| 664 | * value, just skip the check and use 0xE. The hardware may take |
| 665 | * longer to time out, but that's much better than having a too-short |
| 666 | * timeout value. |
| 667 | */ |
Pierre Ossman | 11a2f1b | 2009-06-21 20:59:33 +0200 | [diff] [blame] | 668 | if (host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL) |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 669 | return 0xE; |
Pierre Ossman | e538fbe | 2007-08-12 16:46:32 +0200 | [diff] [blame] | 670 | |
Andrei Warkentin | a3c7778 | 2011-04-11 16:13:42 -0500 | [diff] [blame] | 671 | /* Unspecified timeout, assume max */ |
Ulf Hansson | 1d4d774 | 2014-01-08 15:06:08 +0100 | [diff] [blame] | 672 | if (!data && !cmd->busy_timeout) |
Andrei Warkentin | a3c7778 | 2011-04-11 16:13:42 -0500 | [diff] [blame] | 673 | return 0xE; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 674 | |
Andrei Warkentin | a3c7778 | 2011-04-11 16:13:42 -0500 | [diff] [blame] | 675 | /* timeout in us */ |
| 676 | if (!data) |
Ulf Hansson | 1d4d774 | 2014-01-08 15:06:08 +0100 | [diff] [blame] | 677 | target_timeout = cmd->busy_timeout * 1000; |
Andy Shevchenko | 78a2ca2 | 2011-08-03 18:35:59 +0300 | [diff] [blame] | 678 | else { |
| 679 | target_timeout = data->timeout_ns / 1000; |
| 680 | if (host->clock) |
| 681 | target_timeout += data->timeout_clks / host->clock; |
| 682 | } |
Anton Vorontsov | 81b3980 | 2009-09-22 16:45:13 -0700 | [diff] [blame] | 683 | |
Pierre Ossman | 1c8cde9 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 684 | /* |
| 685 | * Figure out needed cycles. |
| 686 | * We do this in steps in order to fit inside a 32 bit int. |
| 687 | * The first step is the minimum timeout, which will have a |
| 688 | * minimum resolution of 6 bits: |
| 689 | * (1) 2^13*1000 > 2^22, |
| 690 | * (2) host->timeout_clk < 2^16 |
| 691 | * => |
| 692 | * (1) / (2) > 2^6 |
| 693 | */ |
| 694 | count = 0; |
| 695 | current_timeout = (1 << 13) * 1000 / host->timeout_clk; |
| 696 | while (current_timeout < target_timeout) { |
| 697 | count++; |
| 698 | current_timeout <<= 1; |
| 699 | if (count >= 0xF) |
| 700 | break; |
| 701 | } |
| 702 | |
| 703 | if (count >= 0xF) { |
Chris Ball | 09eeff5 | 2012-06-01 10:39:45 -0400 | [diff] [blame] | 704 | DBG("%s: Too large timeout 0x%x requested for CMD%d!\n", |
| 705 | mmc_hostname(host->mmc), count, cmd->opcode); |
Pierre Ossman | 1c8cde9 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 706 | count = 0xE; |
| 707 | } |
| 708 | |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 709 | return count; |
| 710 | } |
| 711 | |
Anton Vorontsov | 6aa943a | 2009-03-17 00:13:50 +0300 | [diff] [blame] | 712 | static void sdhci_set_transfer_irqs(struct sdhci_host *host) |
| 713 | { |
| 714 | u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL; |
| 715 | u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR; |
| 716 | |
| 717 | if (host->flags & SDHCI_REQ_USE_DMA) |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 718 | host->ier = (host->ier & ~pio_irqs) | dma_irqs; |
Anton Vorontsov | 6aa943a | 2009-03-17 00:13:50 +0300 | [diff] [blame] | 719 | else |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 720 | host->ier = (host->ier & ~dma_irqs) | pio_irqs; |
| 721 | |
| 722 | sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); |
| 723 | sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); |
Anton Vorontsov | 6aa943a | 2009-03-17 00:13:50 +0300 | [diff] [blame] | 724 | } |
| 725 | |
Aisheng Dong | b45e668 | 2014-08-27 15:26:29 +0800 | [diff] [blame] | 726 | static void sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 727 | { |
| 728 | u8 count; |
Aisheng Dong | b45e668 | 2014-08-27 15:26:29 +0800 | [diff] [blame] | 729 | |
| 730 | if (host->ops->set_timeout) { |
| 731 | host->ops->set_timeout(host, cmd); |
| 732 | } else { |
| 733 | count = sdhci_calc_timeout(host, cmd); |
| 734 | sdhci_writeb(host, count, SDHCI_TIMEOUT_CONTROL); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd) |
| 739 | { |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 740 | u8 ctrl; |
Andrei Warkentin | a3c7778 | 2011-04-11 16:13:42 -0500 | [diff] [blame] | 741 | struct mmc_data *data = cmd->data; |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 742 | int ret; |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 743 | |
| 744 | WARN_ON(host->data); |
| 745 | |
Aisheng Dong | b45e668 | 2014-08-27 15:26:29 +0800 | [diff] [blame] | 746 | if (data || (cmd->flags & MMC_RSP_BUSY)) |
| 747 | sdhci_set_timeout(host, cmd); |
Andrei Warkentin | a3c7778 | 2011-04-11 16:13:42 -0500 | [diff] [blame] | 748 | |
| 749 | if (!data) |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 750 | return; |
| 751 | |
| 752 | /* Sanity checks */ |
| 753 | BUG_ON(data->blksz * data->blocks > 524288); |
| 754 | BUG_ON(data->blksz > host->mmc->max_blk_size); |
| 755 | BUG_ON(data->blocks > 65535); |
| 756 | |
| 757 | host->data = data; |
| 758 | host->data_early = 0; |
Mikko Vinni | f6a03cb | 2011-04-12 09:36:18 -0400 | [diff] [blame] | 759 | host->data->bytes_xfered = 0; |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 760 | |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 761 | if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) |
Pierre Ossman | c9fddbc | 2007-12-02 19:52:11 +0100 | [diff] [blame] | 762 | host->flags |= SDHCI_REQ_USE_DMA; |
| 763 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 764 | /* |
| 765 | * FIXME: This doesn't account for merging when mapping the |
| 766 | * scatterlist. |
| 767 | */ |
| 768 | if (host->flags & SDHCI_REQ_USE_DMA) { |
| 769 | int broken, i; |
| 770 | struct scatterlist *sg; |
| 771 | |
| 772 | broken = 0; |
| 773 | if (host->flags & SDHCI_USE_ADMA) { |
| 774 | if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) |
| 775 | broken = 1; |
| 776 | } else { |
| 777 | if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE) |
| 778 | broken = 1; |
| 779 | } |
| 780 | |
| 781 | if (unlikely(broken)) { |
| 782 | for_each_sg(data->sg, sg, data->sg_len, i) { |
| 783 | if (sg->length & 0x3) { |
| 784 | DBG("Reverting to PIO because of " |
| 785 | "transfer size (%d)\n", |
| 786 | sg->length); |
| 787 | host->flags &= ~SDHCI_REQ_USE_DMA; |
| 788 | break; |
| 789 | } |
| 790 | } |
| 791 | } |
Pierre Ossman | c9fddbc | 2007-12-02 19:52:11 +0100 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | /* |
| 795 | * The assumption here being that alignment is the same after |
| 796 | * translation to device address space. |
| 797 | */ |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 798 | if (host->flags & SDHCI_REQ_USE_DMA) { |
| 799 | int broken, i; |
| 800 | struct scatterlist *sg; |
| 801 | |
| 802 | broken = 0; |
| 803 | if (host->flags & SDHCI_USE_ADMA) { |
| 804 | /* |
| 805 | * As we use 3 byte chunks to work around |
| 806 | * alignment problems, we need to check this |
| 807 | * quirk. |
| 808 | */ |
| 809 | if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) |
| 810 | broken = 1; |
| 811 | } else { |
| 812 | if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) |
| 813 | broken = 1; |
| 814 | } |
| 815 | |
| 816 | if (unlikely(broken)) { |
| 817 | for_each_sg(data->sg, sg, data->sg_len, i) { |
| 818 | if (sg->offset & 0x3) { |
| 819 | DBG("Reverting to PIO because of " |
| 820 | "bad alignment\n"); |
| 821 | host->flags &= ~SDHCI_REQ_USE_DMA; |
| 822 | break; |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 828 | if (host->flags & SDHCI_REQ_USE_DMA) { |
| 829 | if (host->flags & SDHCI_USE_ADMA) { |
| 830 | ret = sdhci_adma_table_pre(host, data); |
| 831 | if (ret) { |
| 832 | /* |
| 833 | * This only happens when someone fed |
| 834 | * us an invalid request. |
| 835 | */ |
| 836 | WARN_ON(1); |
Pierre Ossman | ebd6d35 | 2008-07-29 00:45:51 +0200 | [diff] [blame] | 837 | host->flags &= ~SDHCI_REQ_USE_DMA; |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 838 | } else { |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 839 | sdhci_writel(host, host->adma_addr, |
| 840 | SDHCI_ADMA_ADDRESS); |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 841 | if (host->flags & SDHCI_USE_64_BIT_DMA) |
| 842 | sdhci_writel(host, |
| 843 | (u64)host->adma_addr >> 32, |
| 844 | SDHCI_ADMA_ADDRESS_HI); |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 845 | } |
| 846 | } else { |
Tomas Winkler | c8b3e02 | 2008-07-05 19:52:04 +0300 | [diff] [blame] | 847 | int sg_cnt; |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 848 | |
Haibo Chen | 348487c | 2014-12-09 17:04:05 +0800 | [diff] [blame] | 849 | sg_cnt = sdhci_pre_dma_transfer(host, data, NULL); |
Tomas Winkler | c8b3e02 | 2008-07-05 19:52:04 +0300 | [diff] [blame] | 850 | if (sg_cnt == 0) { |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 851 | /* |
| 852 | * This only happens when someone fed |
| 853 | * us an invalid request. |
| 854 | */ |
| 855 | WARN_ON(1); |
Pierre Ossman | ebd6d35 | 2008-07-29 00:45:51 +0200 | [diff] [blame] | 856 | host->flags &= ~SDHCI_REQ_USE_DMA; |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 857 | } else { |
Pierre Ossman | 719a61b | 2008-07-22 13:23:23 +0200 | [diff] [blame] | 858 | WARN_ON(sg_cnt != 1); |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 859 | sdhci_writel(host, sg_dma_address(data->sg), |
| 860 | SDHCI_DMA_ADDRESS); |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | } |
| 864 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 865 | /* |
| 866 | * Always adjust the DMA selection as some controllers |
| 867 | * (e.g. JMicron) can't do PIO properly when the selection |
| 868 | * is ADMA. |
| 869 | */ |
| 870 | if (host->version >= SDHCI_SPEC_200) { |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 871 | ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 872 | ctrl &= ~SDHCI_CTRL_DMA_MASK; |
| 873 | if ((host->flags & SDHCI_REQ_USE_DMA) && |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 874 | (host->flags & SDHCI_USE_ADMA)) { |
| 875 | if (host->flags & SDHCI_USE_64_BIT_DMA) |
| 876 | ctrl |= SDHCI_CTRL_ADMA64; |
| 877 | else |
| 878 | ctrl |= SDHCI_CTRL_ADMA32; |
| 879 | } else { |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 880 | ctrl |= SDHCI_CTRL_SDMA; |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 881 | } |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 882 | sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); |
Pierre Ossman | c9fddbc | 2007-12-02 19:52:11 +0100 | [diff] [blame] | 883 | } |
| 884 | |
Pierre Ossman | 8f1934c | 2008-06-30 21:15:49 +0200 | [diff] [blame] | 885 | if (!(host->flags & SDHCI_REQ_USE_DMA)) { |
Sebastian Andrzej Siewior | da60a91 | 2009-06-18 09:33:32 +0200 | [diff] [blame] | 886 | int flags; |
| 887 | |
| 888 | flags = SG_MITER_ATOMIC; |
| 889 | if (host->data->flags & MMC_DATA_READ) |
| 890 | flags |= SG_MITER_TO_SG; |
| 891 | else |
| 892 | flags |= SG_MITER_FROM_SG; |
| 893 | sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 894 | host->blocks = data->blocks; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 895 | } |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 896 | |
Anton Vorontsov | 6aa943a | 2009-03-17 00:13:50 +0300 | [diff] [blame] | 897 | sdhci_set_transfer_irqs(host); |
| 898 | |
Mikko Vinni | f6a03cb | 2011-04-12 09:36:18 -0400 | [diff] [blame] | 899 | /* Set the DMA boundary value and block size */ |
| 900 | sdhci_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG, |
| 901 | data->blksz), SDHCI_BLOCK_SIZE); |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 902 | sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT); |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | static void sdhci_set_transfer_mode(struct sdhci_host *host, |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 906 | struct mmc_command *cmd) |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 907 | { |
Vincent Yang | d3fc5d7 | 2015-01-20 16:05:17 +0800 | [diff] [blame] | 908 | u16 mode = 0; |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 909 | struct mmc_data *data = cmd->data; |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 910 | |
Dong Aisheng | 2b558c1 | 2013-10-30 22:09:48 +0800 | [diff] [blame] | 911 | if (data == NULL) { |
Vincent Wan | 9b8ffea | 2014-11-05 14:09:00 +0800 | [diff] [blame] | 912 | if (host->quirks2 & |
| 913 | SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD) { |
| 914 | sdhci_writew(host, 0x0, SDHCI_TRANSFER_MODE); |
| 915 | } else { |
Dong Aisheng | 2b558c1 | 2013-10-30 22:09:48 +0800 | [diff] [blame] | 916 | /* clear Auto CMD settings for no data CMDs */ |
Vincent Wan | 9b8ffea | 2014-11-05 14:09:00 +0800 | [diff] [blame] | 917 | mode = sdhci_readw(host, SDHCI_TRANSFER_MODE); |
| 918 | sdhci_writew(host, mode & ~(SDHCI_TRNS_AUTO_CMD12 | |
Dong Aisheng | 2b558c1 | 2013-10-30 22:09:48 +0800 | [diff] [blame] | 919 | SDHCI_TRNS_AUTO_CMD23), SDHCI_TRANSFER_MODE); |
Vincent Wan | 9b8ffea | 2014-11-05 14:09:00 +0800 | [diff] [blame] | 920 | } |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 921 | return; |
Dong Aisheng | 2b558c1 | 2013-10-30 22:09:48 +0800 | [diff] [blame] | 922 | } |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 923 | |
Pierre Ossman | e538fbe | 2007-08-12 16:46:32 +0200 | [diff] [blame] | 924 | WARN_ON(!host->data); |
| 925 | |
Vincent Yang | d3fc5d7 | 2015-01-20 16:05:17 +0800 | [diff] [blame] | 926 | if (!(host->quirks2 & SDHCI_QUIRK2_SUPPORT_SINGLE)) |
| 927 | mode = SDHCI_TRNS_BLK_CNT_EN; |
| 928 | |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 929 | if (mmc_op_multi(cmd->opcode) || data->blocks > 1) { |
Vincent Yang | d3fc5d7 | 2015-01-20 16:05:17 +0800 | [diff] [blame] | 930 | mode = SDHCI_TRNS_BLK_CNT_EN | SDHCI_TRNS_MULTI; |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 931 | /* |
| 932 | * If we are sending CMD23, CMD12 never gets sent |
| 933 | * on successful completion (so no Auto-CMD12). |
| 934 | */ |
Corneliu Doban | 85cc1c3 | 2015-02-09 16:06:29 -0800 | [diff] [blame^] | 935 | if (!host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD12) && |
| 936 | (cmd->opcode != SD_IO_RW_EXTENDED)) |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 937 | mode |= SDHCI_TRNS_AUTO_CMD12; |
Andrei Warkentin | 8edf6371 | 2011-05-23 15:06:39 -0500 | [diff] [blame] | 938 | else if (host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) { |
| 939 | mode |= SDHCI_TRNS_AUTO_CMD23; |
| 940 | sdhci_writel(host, host->mrq->sbc->arg, SDHCI_ARGUMENT2); |
| 941 | } |
Jerry Huang | c4512f7 | 2010-08-10 18:01:59 -0700 | [diff] [blame] | 942 | } |
Andrei Warkentin | 8edf6371 | 2011-05-23 15:06:39 -0500 | [diff] [blame] | 943 | |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 944 | if (data->flags & MMC_DATA_READ) |
| 945 | mode |= SDHCI_TRNS_READ; |
Pierre Ossman | c9fddbc | 2007-12-02 19:52:11 +0100 | [diff] [blame] | 946 | if (host->flags & SDHCI_REQ_USE_DMA) |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 947 | mode |= SDHCI_TRNS_DMA; |
| 948 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 949 | sdhci_writew(host, mode, SDHCI_TRANSFER_MODE); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | static void sdhci_finish_data(struct sdhci_host *host) |
| 953 | { |
| 954 | struct mmc_data *data; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 955 | |
| 956 | BUG_ON(!host->data); |
| 957 | |
| 958 | data = host->data; |
| 959 | host->data = NULL; |
| 960 | |
Pierre Ossman | c9fddbc | 2007-12-02 19:52:11 +0100 | [diff] [blame] | 961 | if (host->flags & SDHCI_REQ_USE_DMA) { |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 962 | if (host->flags & SDHCI_USE_ADMA) |
| 963 | sdhci_adma_table_post(host, data); |
| 964 | else { |
Haibo Chen | 348487c | 2014-12-09 17:04:05 +0800 | [diff] [blame] | 965 | if (!data->host_cookie) |
| 966 | dma_unmap_sg(mmc_dev(host->mmc), |
| 967 | data->sg, data->sg_len, |
| 968 | (data->flags & MMC_DATA_READ) ? |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 969 | DMA_FROM_DEVICE : DMA_TO_DEVICE); |
| 970 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | /* |
Pierre Ossman | c9b74c5 | 2008-04-18 20:41:49 +0200 | [diff] [blame] | 974 | * The specification states that the block count register must |
| 975 | * be updated, but it does not specify at what point in the |
| 976 | * data flow. That makes the register entirely useless to read |
| 977 | * back so we have to assume that nothing made it to the card |
| 978 | * in the event of an error. |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 979 | */ |
Pierre Ossman | c9b74c5 | 2008-04-18 20:41:49 +0200 | [diff] [blame] | 980 | if (data->error) |
| 981 | data->bytes_xfered = 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 982 | else |
Pierre Ossman | c9b74c5 | 2008-04-18 20:41:49 +0200 | [diff] [blame] | 983 | data->bytes_xfered = data->blksz * data->blocks; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 984 | |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 985 | /* |
| 986 | * Need to send CMD12 if - |
| 987 | * a) open-ended multiblock transfer (no CMD23) |
| 988 | * b) error in multiblock transfer |
| 989 | */ |
| 990 | if (data->stop && |
| 991 | (data->error || |
| 992 | !host->mrq->sbc)) { |
| 993 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 994 | /* |
| 995 | * The controller needs a reset of internal state machines |
| 996 | * upon error conditions. |
| 997 | */ |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 998 | if (data->error) { |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 999 | sdhci_do_reset(host, SDHCI_RESET_CMD); |
| 1000 | sdhci_do_reset(host, SDHCI_RESET_DATA); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | sdhci_send_command(host, data->stop); |
| 1004 | } else |
| 1005 | tasklet_schedule(&host->finish_tasklet); |
| 1006 | } |
| 1007 | |
Dong Aisheng | c0e55129 | 2013-09-13 19:11:31 +0800 | [diff] [blame] | 1008 | void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1009 | { |
| 1010 | int flags; |
Pierre Ossman | fd2208d | 2006-06-30 02:22:28 -0700 | [diff] [blame] | 1011 | u32 mask; |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1012 | unsigned long timeout; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1013 | |
| 1014 | WARN_ON(host->cmd); |
| 1015 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1016 | /* Wait max 10 ms */ |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1017 | timeout = 10; |
Pierre Ossman | fd2208d | 2006-06-30 02:22:28 -0700 | [diff] [blame] | 1018 | |
| 1019 | mask = SDHCI_CMD_INHIBIT; |
| 1020 | if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY)) |
| 1021 | mask |= SDHCI_DATA_INHIBIT; |
| 1022 | |
| 1023 | /* We shouldn't wait for data inihibit for stop commands, even |
| 1024 | though they might use busy signaling */ |
| 1025 | if (host->mrq->data && (cmd == host->mrq->data->stop)) |
| 1026 | mask &= ~SDHCI_DATA_INHIBIT; |
| 1027 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1028 | while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) { |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1029 | if (timeout == 0) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 1030 | pr_err("%s: Controller never released " |
Pierre Ossman | acf1da4 | 2007-02-09 08:29:19 +0100 | [diff] [blame] | 1031 | "inhibit bit(s).\n", mmc_hostname(host->mmc)); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1032 | sdhci_dumpregs(host); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1033 | cmd->error = -EIO; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1034 | tasklet_schedule(&host->finish_tasklet); |
| 1035 | return; |
| 1036 | } |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1037 | timeout--; |
| 1038 | mdelay(1); |
| 1039 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1040 | |
Adrian Hunter | 3e1a689 | 2013-11-14 10:16:20 +0200 | [diff] [blame] | 1041 | timeout = jiffies; |
Ulf Hansson | 1d4d774 | 2014-01-08 15:06:08 +0100 | [diff] [blame] | 1042 | if (!cmd->data && cmd->busy_timeout > 9000) |
| 1043 | timeout += DIV_ROUND_UP(cmd->busy_timeout, 1000) * HZ + HZ; |
Adrian Hunter | 3e1a689 | 2013-11-14 10:16:20 +0200 | [diff] [blame] | 1044 | else |
| 1045 | timeout += 10 * HZ; |
| 1046 | mod_timer(&host->timer, timeout); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1047 | |
| 1048 | host->cmd = cmd; |
Chanho Min | e99783a | 2014-08-30 12:40:40 +0900 | [diff] [blame] | 1049 | host->busy_handle = 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1050 | |
Andrei Warkentin | a3c7778 | 2011-04-11 16:13:42 -0500 | [diff] [blame] | 1051 | sdhci_prepare_data(host, cmd); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1052 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1053 | sdhci_writel(host, cmd->arg, SDHCI_ARGUMENT); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1054 | |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 1055 | sdhci_set_transfer_mode(host, cmd); |
Pierre Ossman | c7fa996 | 2006-06-30 02:22:25 -0700 | [diff] [blame] | 1056 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1057 | if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 1058 | pr_err("%s: Unsupported response type!\n", |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1059 | mmc_hostname(host->mmc)); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1060 | cmd->error = -EINVAL; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1061 | tasklet_schedule(&host->finish_tasklet); |
| 1062 | return; |
| 1063 | } |
| 1064 | |
| 1065 | if (!(cmd->flags & MMC_RSP_PRESENT)) |
| 1066 | flags = SDHCI_CMD_RESP_NONE; |
| 1067 | else if (cmd->flags & MMC_RSP_136) |
| 1068 | flags = SDHCI_CMD_RESP_LONG; |
| 1069 | else if (cmd->flags & MMC_RSP_BUSY) |
| 1070 | flags = SDHCI_CMD_RESP_SHORT_BUSY; |
| 1071 | else |
| 1072 | flags = SDHCI_CMD_RESP_SHORT; |
| 1073 | |
| 1074 | if (cmd->flags & MMC_RSP_CRC) |
| 1075 | flags |= SDHCI_CMD_CRC; |
| 1076 | if (cmd->flags & MMC_RSP_OPCODE) |
| 1077 | flags |= SDHCI_CMD_INDEX; |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1078 | |
| 1079 | /* CMD19 is special in that the Data Present Select should be set */ |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 1080 | if (cmd->data || cmd->opcode == MMC_SEND_TUNING_BLOCK || |
| 1081 | cmd->opcode == MMC_SEND_TUNING_BLOCK_HS200) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1082 | flags |= SDHCI_CMD_DATA; |
| 1083 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1084 | sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1085 | } |
Dong Aisheng | c0e55129 | 2013-09-13 19:11:31 +0800 | [diff] [blame] | 1086 | EXPORT_SYMBOL_GPL(sdhci_send_command); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1087 | |
| 1088 | static void sdhci_finish_command(struct sdhci_host *host) |
| 1089 | { |
| 1090 | int i; |
| 1091 | |
| 1092 | BUG_ON(host->cmd == NULL); |
| 1093 | |
| 1094 | if (host->cmd->flags & MMC_RSP_PRESENT) { |
| 1095 | if (host->cmd->flags & MMC_RSP_136) { |
| 1096 | /* CRC is stripped so we need to do some shifting. */ |
| 1097 | for (i = 0;i < 4;i++) { |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1098 | host->cmd->resp[i] = sdhci_readl(host, |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1099 | SDHCI_RESPONSE + (3-i)*4) << 8; |
| 1100 | if (i != 3) |
| 1101 | host->cmd->resp[i] |= |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1102 | sdhci_readb(host, |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1103 | SDHCI_RESPONSE + (3-i)*4-1); |
| 1104 | } |
| 1105 | } else { |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1106 | host->cmd->resp[0] = sdhci_readl(host, SDHCI_RESPONSE); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1110 | host->cmd->error = 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1111 | |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 1112 | /* Finished CMD23, now send actual command. */ |
| 1113 | if (host->cmd == host->mrq->sbc) { |
| 1114 | host->cmd = NULL; |
| 1115 | sdhci_send_command(host, host->mrq->cmd); |
| 1116 | } else { |
Pierre Ossman | e538fbe | 2007-08-12 16:46:32 +0200 | [diff] [blame] | 1117 | |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 1118 | /* Processed actual command. */ |
| 1119 | if (host->data && host->data_early) |
| 1120 | sdhci_finish_data(host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1121 | |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 1122 | if (!host->cmd->data) |
| 1123 | tasklet_schedule(&host->finish_tasklet); |
| 1124 | |
| 1125 | host->cmd = NULL; |
| 1126 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1127 | } |
| 1128 | |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1129 | static u16 sdhci_get_preset_value(struct sdhci_host *host) |
| 1130 | { |
Russell King | d975f12 | 2014-04-25 12:59:31 +0100 | [diff] [blame] | 1131 | u16 preset = 0; |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1132 | |
Russell King | d975f12 | 2014-04-25 12:59:31 +0100 | [diff] [blame] | 1133 | switch (host->timing) { |
| 1134 | case MMC_TIMING_UHS_SDR12: |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1135 | preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR12); |
| 1136 | break; |
Russell King | d975f12 | 2014-04-25 12:59:31 +0100 | [diff] [blame] | 1137 | case MMC_TIMING_UHS_SDR25: |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1138 | preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR25); |
| 1139 | break; |
Russell King | d975f12 | 2014-04-25 12:59:31 +0100 | [diff] [blame] | 1140 | case MMC_TIMING_UHS_SDR50: |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1141 | preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR50); |
| 1142 | break; |
Russell King | d975f12 | 2014-04-25 12:59:31 +0100 | [diff] [blame] | 1143 | case MMC_TIMING_UHS_SDR104: |
| 1144 | case MMC_TIMING_MMC_HS200: |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1145 | preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR104); |
| 1146 | break; |
Russell King | d975f12 | 2014-04-25 12:59:31 +0100 | [diff] [blame] | 1147 | case MMC_TIMING_UHS_DDR50: |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1148 | preset = sdhci_readw(host, SDHCI_PRESET_FOR_DDR50); |
| 1149 | break; |
Adrian Hunter | e9fb05d | 2014-11-06 15:19:06 +0200 | [diff] [blame] | 1150 | case MMC_TIMING_MMC_HS400: |
| 1151 | preset = sdhci_readw(host, SDHCI_PRESET_FOR_HS400); |
| 1152 | break; |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1153 | default: |
| 1154 | pr_warn("%s: Invalid UHS-I mode selected\n", |
| 1155 | mmc_hostname(host->mmc)); |
| 1156 | preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR12); |
| 1157 | break; |
| 1158 | } |
| 1159 | return preset; |
| 1160 | } |
| 1161 | |
Russell King | 1771059 | 2014-04-25 12:58:55 +0100 | [diff] [blame] | 1162 | void sdhci_set_clock(struct sdhci_host *host, unsigned int clock) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1163 | { |
Arindam Nath | c3ed387 | 2011-05-05 12:19:06 +0530 | [diff] [blame] | 1164 | int div = 0; /* Initialized for compiler warning */ |
Giuseppe CAVALLARO | df16219 | 2011-11-04 13:53:19 +0100 | [diff] [blame] | 1165 | int real_div = div, clk_mul = 1; |
Arindam Nath | c3ed387 | 2011-05-05 12:19:06 +0530 | [diff] [blame] | 1166 | u16 clk = 0; |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1167 | unsigned long timeout; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1168 | |
Russell King | 1650d0c | 2014-04-25 12:58:50 +0100 | [diff] [blame] | 1169 | host->mmc->actual_clock = 0; |
| 1170 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1171 | sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1172 | |
| 1173 | if (clock == 0) |
Russell King | 373073e | 2014-04-25 12:58:45 +0100 | [diff] [blame] | 1174 | return; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1175 | |
Zhangfei Gao | 85105c5 | 2010-08-06 07:10:01 +0800 | [diff] [blame] | 1176 | if (host->version >= SDHCI_SPEC_300) { |
Russell King | da91a8f | 2014-04-25 13:00:12 +0100 | [diff] [blame] | 1177 | if (host->preset_enabled) { |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1178 | u16 pre_val; |
| 1179 | |
| 1180 | clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); |
| 1181 | pre_val = sdhci_get_preset_value(host); |
| 1182 | div = (pre_val & SDHCI_PRESET_SDCLK_FREQ_MASK) |
| 1183 | >> SDHCI_PRESET_SDCLK_FREQ_SHIFT; |
| 1184 | if (host->clk_mul && |
| 1185 | (pre_val & SDHCI_PRESET_CLKGEN_SEL_MASK)) { |
| 1186 | clk = SDHCI_PROG_CLOCK_MODE; |
| 1187 | real_div = div + 1; |
| 1188 | clk_mul = host->clk_mul; |
| 1189 | } else { |
| 1190 | real_div = max_t(int, 1, div << 1); |
| 1191 | } |
| 1192 | goto clock_set; |
| 1193 | } |
| 1194 | |
Arindam Nath | c3ed387 | 2011-05-05 12:19:06 +0530 | [diff] [blame] | 1195 | /* |
| 1196 | * Check if the Host Controller supports Programmable Clock |
| 1197 | * Mode. |
| 1198 | */ |
| 1199 | if (host->clk_mul) { |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1200 | for (div = 1; div <= 1024; div++) { |
| 1201 | if ((host->max_clk * host->clk_mul / div) |
| 1202 | <= clock) |
| 1203 | break; |
Zhangfei Gao | 85105c5 | 2010-08-06 07:10:01 +0800 | [diff] [blame] | 1204 | } |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1205 | /* |
| 1206 | * Set Programmable Clock Mode in the Clock |
| 1207 | * Control register. |
| 1208 | */ |
| 1209 | clk = SDHCI_PROG_CLOCK_MODE; |
| 1210 | real_div = div; |
| 1211 | clk_mul = host->clk_mul; |
| 1212 | div--; |
Arindam Nath | c3ed387 | 2011-05-05 12:19:06 +0530 | [diff] [blame] | 1213 | } else { |
| 1214 | /* Version 3.00 divisors must be a multiple of 2. */ |
| 1215 | if (host->max_clk <= clock) |
| 1216 | div = 1; |
| 1217 | else { |
| 1218 | for (div = 2; div < SDHCI_MAX_DIV_SPEC_300; |
| 1219 | div += 2) { |
| 1220 | if ((host->max_clk / div) <= clock) |
| 1221 | break; |
| 1222 | } |
| 1223 | } |
Giuseppe CAVALLARO | df16219 | 2011-11-04 13:53:19 +0100 | [diff] [blame] | 1224 | real_div = div; |
Arindam Nath | c3ed387 | 2011-05-05 12:19:06 +0530 | [diff] [blame] | 1225 | div >>= 1; |
Zhangfei Gao | 85105c5 | 2010-08-06 07:10:01 +0800 | [diff] [blame] | 1226 | } |
| 1227 | } else { |
| 1228 | /* Version 2.00 divisors must be a power of 2. */ |
Zhangfei Gao | 0397526 | 2010-09-20 15:15:18 -0400 | [diff] [blame] | 1229 | for (div = 1; div < SDHCI_MAX_DIV_SPEC_200; div *= 2) { |
Zhangfei Gao | 85105c5 | 2010-08-06 07:10:01 +0800 | [diff] [blame] | 1230 | if ((host->max_clk / div) <= clock) |
| 1231 | break; |
| 1232 | } |
Giuseppe CAVALLARO | df16219 | 2011-11-04 13:53:19 +0100 | [diff] [blame] | 1233 | real_div = div; |
Arindam Nath | c3ed387 | 2011-05-05 12:19:06 +0530 | [diff] [blame] | 1234 | div >>= 1; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1235 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1236 | |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1237 | clock_set: |
Aisheng Dong | 03d6f5f | 2014-08-27 15:26:32 +0800 | [diff] [blame] | 1238 | if (real_div) |
Giuseppe CAVALLARO | df16219 | 2011-11-04 13:53:19 +0100 | [diff] [blame] | 1239 | host->mmc->actual_clock = (host->max_clk * clk_mul) / real_div; |
Arindam Nath | c3ed387 | 2011-05-05 12:19:06 +0530 | [diff] [blame] | 1240 | clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT; |
Zhangfei Gao | 85105c5 | 2010-08-06 07:10:01 +0800 | [diff] [blame] | 1241 | clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN) |
| 1242 | << SDHCI_DIVIDER_HI_SHIFT; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1243 | clk |= SDHCI_CLOCK_INT_EN; |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1244 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1245 | |
Chris Ball | 27f6cb1 | 2009-09-22 16:45:31 -0700 | [diff] [blame] | 1246 | /* Wait max 20 ms */ |
| 1247 | timeout = 20; |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1248 | while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL)) |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1249 | & SDHCI_CLOCK_INT_STABLE)) { |
| 1250 | if (timeout == 0) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 1251 | pr_err("%s: Internal clock never " |
Pierre Ossman | acf1da4 | 2007-02-09 08:29:19 +0100 | [diff] [blame] | 1252 | "stabilised.\n", mmc_hostname(host->mmc)); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1253 | sdhci_dumpregs(host); |
| 1254 | return; |
| 1255 | } |
Pierre Ossman | 7cb2c76 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1256 | timeout--; |
| 1257 | mdelay(1); |
| 1258 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1259 | |
| 1260 | clk |= SDHCI_CLOCK_CARD_EN; |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1261 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1262 | } |
Russell King | 1771059 | 2014-04-25 12:58:55 +0100 | [diff] [blame] | 1263 | EXPORT_SYMBOL_GPL(sdhci_set_clock); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1264 | |
Russell King | 24fbb3c | 2014-04-25 13:00:06 +0100 | [diff] [blame] | 1265 | static void sdhci_set_power(struct sdhci_host *host, unsigned char mode, |
| 1266 | unsigned short vdd) |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1267 | { |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 1268 | struct mmc_host *mmc = host->mmc; |
Giuseppe Cavallaro | 8364248 | 2010-09-28 10:41:28 +0200 | [diff] [blame] | 1269 | u8 pwr = 0; |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1270 | |
Tim Kryger | 5222161 | 2014-06-25 00:25:34 -0700 | [diff] [blame] | 1271 | if (!IS_ERR(mmc->supply.vmmc)) { |
| 1272 | spin_unlock_irq(&host->lock); |
Markus Mayer | 4e743f1 | 2014-07-03 13:27:42 -0700 | [diff] [blame] | 1273 | mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); |
Tim Kryger | 5222161 | 2014-06-25 00:25:34 -0700 | [diff] [blame] | 1274 | spin_lock_irq(&host->lock); |
Tim Kryger | 3cbc612 | 2015-01-14 07:24:12 +0100 | [diff] [blame] | 1275 | |
| 1276 | if (mode != MMC_POWER_OFF) |
| 1277 | sdhci_writeb(host, SDHCI_POWER_ON, SDHCI_POWER_CONTROL); |
| 1278 | else |
| 1279 | sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); |
| 1280 | |
Tim Kryger | 5222161 | 2014-06-25 00:25:34 -0700 | [diff] [blame] | 1281 | return; |
| 1282 | } |
| 1283 | |
Russell King | 24fbb3c | 2014-04-25 13:00:06 +0100 | [diff] [blame] | 1284 | if (mode != MMC_POWER_OFF) { |
| 1285 | switch (1 << vdd) { |
Pierre Ossman | ae62890 | 2009-05-03 20:45:03 +0200 | [diff] [blame] | 1286 | case MMC_VDD_165_195: |
| 1287 | pwr = SDHCI_POWER_180; |
| 1288 | break; |
| 1289 | case MMC_VDD_29_30: |
| 1290 | case MMC_VDD_30_31: |
| 1291 | pwr = SDHCI_POWER_300; |
| 1292 | break; |
| 1293 | case MMC_VDD_32_33: |
| 1294 | case MMC_VDD_33_34: |
| 1295 | pwr = SDHCI_POWER_330; |
| 1296 | break; |
| 1297 | default: |
| 1298 | BUG(); |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | if (host->pwr == pwr) |
Russell King | e921a8b | 2014-04-25 13:00:01 +0100 | [diff] [blame] | 1303 | return; |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1304 | |
Pierre Ossman | ae62890 | 2009-05-03 20:45:03 +0200 | [diff] [blame] | 1305 | host->pwr = pwr; |
| 1306 | |
| 1307 | if (pwr == 0) { |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1308 | sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); |
Adrian Hunter | f0710a5 | 2013-05-06 12:17:32 +0300 | [diff] [blame] | 1309 | if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) |
| 1310 | sdhci_runtime_pm_bus_off(host); |
Russell King | 24fbb3c | 2014-04-25 13:00:06 +0100 | [diff] [blame] | 1311 | vdd = 0; |
Russell King | e921a8b | 2014-04-25 13:00:01 +0100 | [diff] [blame] | 1312 | } else { |
| 1313 | /* |
| 1314 | * Spec says that we should clear the power reg before setting |
| 1315 | * a new value. Some controllers don't seem to like this though. |
| 1316 | */ |
| 1317 | if (!(host->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE)) |
| 1318 | sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); |
Darren Salt | 9e9dc5f | 2007-01-27 15:32:31 +0100 | [diff] [blame] | 1319 | |
Russell King | e921a8b | 2014-04-25 13:00:01 +0100 | [diff] [blame] | 1320 | /* |
| 1321 | * At least the Marvell CaFe chip gets confused if we set the |
| 1322 | * voltage and set turn on power at the same time, so set the |
| 1323 | * voltage first. |
| 1324 | */ |
| 1325 | if (host->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER) |
| 1326 | sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1327 | |
Russell King | e921a8b | 2014-04-25 13:00:01 +0100 | [diff] [blame] | 1328 | pwr |= SDHCI_POWER_ON; |
| 1329 | |
Pierre Ossman | ae62890 | 2009-05-03 20:45:03 +0200 | [diff] [blame] | 1330 | sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); |
| 1331 | |
Russell King | e921a8b | 2014-04-25 13:00:01 +0100 | [diff] [blame] | 1332 | if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) |
| 1333 | sdhci_runtime_pm_bus_on(host); |
Andres Salomon | e08c169 | 2008-07-04 10:00:03 -0700 | [diff] [blame] | 1334 | |
Russell King | e921a8b | 2014-04-25 13:00:01 +0100 | [diff] [blame] | 1335 | /* |
| 1336 | * Some controllers need an extra 10ms delay of 10ms before |
| 1337 | * they can apply clock after applying power |
| 1338 | */ |
| 1339 | if (host->quirks & SDHCI_QUIRK_DELAY_AFTER_POWER) |
| 1340 | mdelay(10); |
| 1341 | } |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1344 | /*****************************************************************************\ |
| 1345 | * * |
| 1346 | * MMC callbacks * |
| 1347 | * * |
| 1348 | \*****************************************************************************/ |
| 1349 | |
| 1350 | static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) |
| 1351 | { |
| 1352 | struct sdhci_host *host; |
Shawn Guo | 505a868 | 2012-12-11 15:23:42 +0800 | [diff] [blame] | 1353 | int present; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1354 | unsigned long flags; |
Aaron Lu | 473b095 | 2012-07-03 17:27:49 +0800 | [diff] [blame] | 1355 | u32 tuning_opcode; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1356 | |
| 1357 | host = mmc_priv(mmc); |
| 1358 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1359 | sdhci_runtime_pm_get(host); |
| 1360 | |
Krzysztof Kozlowski | 2836766 | 2015-01-05 10:50:15 +0100 | [diff] [blame] | 1361 | present = mmc_gpio_get_cd(host->mmc); |
| 1362 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1363 | spin_lock_irqsave(&host->lock, flags); |
| 1364 | |
| 1365 | WARN_ON(host->mrq != NULL); |
| 1366 | |
Pierre Ossman | f913431 | 2008-12-21 17:01:48 +0100 | [diff] [blame] | 1367 | #ifndef SDHCI_USE_LEDS_CLASS |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1368 | sdhci_activate_led(host); |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 1369 | #endif |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 1370 | |
| 1371 | /* |
| 1372 | * Ensure we don't send the STOP for non-SET_BLOCK_COUNTED |
| 1373 | * requests if Auto-CMD12 is enabled. |
| 1374 | */ |
| 1375 | if (!mrq->sbc && (host->flags & SDHCI_AUTO_CMD12)) { |
Jerry Huang | c4512f7 | 2010-08-10 18:01:59 -0700 | [diff] [blame] | 1376 | if (mrq->stop) { |
| 1377 | mrq->data->stop = NULL; |
| 1378 | mrq->stop = NULL; |
| 1379 | } |
| 1380 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1381 | |
| 1382 | host->mrq = mrq; |
| 1383 | |
Shawn Guo | 505a868 | 2012-12-11 15:23:42 +0800 | [diff] [blame] | 1384 | /* |
| 1385 | * Firstly check card presence from cd-gpio. The return could |
| 1386 | * be one of the following possibilities: |
| 1387 | * negative: cd-gpio is not available |
| 1388 | * zero: cd-gpio is used, and card is removed |
| 1389 | * one: cd-gpio is used, and card is present |
| 1390 | */ |
Shawn Guo | 505a868 | 2012-12-11 15:23:42 +0800 | [diff] [blame] | 1391 | if (present < 0) { |
| 1392 | /* If polling, assume that the card is always present. */ |
| 1393 | if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) |
| 1394 | present = 1; |
| 1395 | else |
| 1396 | present = sdhci_readl(host, SDHCI_PRESENT_STATE) & |
| 1397 | SDHCI_CARD_PRESENT; |
Guennadi Liakhovetski | bec9d4e | 2012-09-17 16:45:10 +0800 | [diff] [blame] | 1398 | } |
| 1399 | |
Anton Vorontsov | 68d1fb7 | 2009-03-17 00:13:52 +0300 | [diff] [blame] | 1400 | if (!present || host->flags & SDHCI_DEVICE_DEAD) { |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1401 | host->mrq->cmd->error = -ENOMEDIUM; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1402 | tasklet_schedule(&host->finish_tasklet); |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 1403 | } else { |
| 1404 | u32 present_state; |
| 1405 | |
| 1406 | present_state = sdhci_readl(host, SDHCI_PRESENT_STATE); |
| 1407 | /* |
| 1408 | * Check if the re-tuning timer has already expired and there |
Yi Sun | 7756a96d | 2014-09-09 02:13:59 +0000 | [diff] [blame] | 1409 | * is no on-going data transfer and DAT0 is not busy. If so, |
| 1410 | * we need to execute tuning procedure before sending command. |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 1411 | */ |
| 1412 | if ((host->flags & SDHCI_NEEDS_RETUNING) && |
Yi Sun | 7756a96d | 2014-09-09 02:13:59 +0000 | [diff] [blame] | 1413 | !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ)) && |
| 1414 | (present_state & SDHCI_DATA_0_LVL_MASK)) { |
Chris Ball | 14efd95 | 2012-11-05 14:29:49 -0500 | [diff] [blame] | 1415 | if (mmc->card) { |
| 1416 | /* eMMC uses cmd21 but sd and sdio use cmd19 */ |
| 1417 | tuning_opcode = |
| 1418 | mmc->card->type == MMC_TYPE_MMC ? |
| 1419 | MMC_SEND_TUNING_BLOCK_HS200 : |
| 1420 | MMC_SEND_TUNING_BLOCK; |
Chuansheng Liu | 63c2118 | 2013-11-05 14:52:45 +0800 | [diff] [blame] | 1421 | |
| 1422 | /* Here we need to set the host->mrq to NULL, |
| 1423 | * in case the pending finish_tasklet |
| 1424 | * finishes it incorrectly. |
| 1425 | */ |
| 1426 | host->mrq = NULL; |
| 1427 | |
Chris Ball | 14efd95 | 2012-11-05 14:29:49 -0500 | [diff] [blame] | 1428 | spin_unlock_irqrestore(&host->lock, flags); |
| 1429 | sdhci_execute_tuning(mmc, tuning_opcode); |
| 1430 | spin_lock_irqsave(&host->lock, flags); |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 1431 | |
Chris Ball | 14efd95 | 2012-11-05 14:29:49 -0500 | [diff] [blame] | 1432 | /* Restore original mmc_request structure */ |
| 1433 | host->mrq = mrq; |
| 1434 | } |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 1435 | } |
| 1436 | |
Andrei Warkentin | 8edf6371 | 2011-05-23 15:06:39 -0500 | [diff] [blame] | 1437 | if (mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23)) |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 1438 | sdhci_send_command(host, mrq->sbc); |
| 1439 | else |
| 1440 | sdhci_send_command(host, mrq->cmd); |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 1441 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1442 | |
Pierre Ossman | 5f25a66 | 2006-10-04 02:15:39 -0700 | [diff] [blame] | 1443 | mmiowb(); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1444 | spin_unlock_irqrestore(&host->lock, flags); |
| 1445 | } |
| 1446 | |
Russell King | 2317f56 | 2014-04-25 12:57:07 +0100 | [diff] [blame] | 1447 | void sdhci_set_bus_width(struct sdhci_host *host, int width) |
| 1448 | { |
| 1449 | u8 ctrl; |
| 1450 | |
| 1451 | ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); |
| 1452 | if (width == MMC_BUS_WIDTH_8) { |
| 1453 | ctrl &= ~SDHCI_CTRL_4BITBUS; |
| 1454 | if (host->version >= SDHCI_SPEC_300) |
| 1455 | ctrl |= SDHCI_CTRL_8BITBUS; |
| 1456 | } else { |
| 1457 | if (host->version >= SDHCI_SPEC_300) |
| 1458 | ctrl &= ~SDHCI_CTRL_8BITBUS; |
| 1459 | if (width == MMC_BUS_WIDTH_4) |
| 1460 | ctrl |= SDHCI_CTRL_4BITBUS; |
| 1461 | else |
| 1462 | ctrl &= ~SDHCI_CTRL_4BITBUS; |
| 1463 | } |
| 1464 | sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); |
| 1465 | } |
| 1466 | EXPORT_SYMBOL_GPL(sdhci_set_bus_width); |
| 1467 | |
Russell King | 96d7b78 | 2014-04-25 12:59:26 +0100 | [diff] [blame] | 1468 | void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing) |
| 1469 | { |
| 1470 | u16 ctrl_2; |
| 1471 | |
| 1472 | ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
| 1473 | /* Select Bus Speed Mode for host */ |
| 1474 | ctrl_2 &= ~SDHCI_CTRL_UHS_MASK; |
| 1475 | if ((timing == MMC_TIMING_MMC_HS200) || |
| 1476 | (timing == MMC_TIMING_UHS_SDR104)) |
| 1477 | ctrl_2 |= SDHCI_CTRL_UHS_SDR104; |
| 1478 | else if (timing == MMC_TIMING_UHS_SDR12) |
| 1479 | ctrl_2 |= SDHCI_CTRL_UHS_SDR12; |
| 1480 | else if (timing == MMC_TIMING_UHS_SDR25) |
| 1481 | ctrl_2 |= SDHCI_CTRL_UHS_SDR25; |
| 1482 | else if (timing == MMC_TIMING_UHS_SDR50) |
| 1483 | ctrl_2 |= SDHCI_CTRL_UHS_SDR50; |
| 1484 | else if ((timing == MMC_TIMING_UHS_DDR50) || |
| 1485 | (timing == MMC_TIMING_MMC_DDR52)) |
| 1486 | ctrl_2 |= SDHCI_CTRL_UHS_DDR50; |
Adrian Hunter | e9fb05d | 2014-11-06 15:19:06 +0200 | [diff] [blame] | 1487 | else if (timing == MMC_TIMING_MMC_HS400) |
| 1488 | ctrl_2 |= SDHCI_CTRL_HS400; /* Non-standard */ |
Russell King | 96d7b78 | 2014-04-25 12:59:26 +0100 | [diff] [blame] | 1489 | sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); |
| 1490 | } |
| 1491 | EXPORT_SYMBOL_GPL(sdhci_set_uhs_signaling); |
| 1492 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1493 | static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1494 | { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1495 | unsigned long flags; |
| 1496 | u8 ctrl; |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 1497 | struct mmc_host *mmc = host->mmc; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1498 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1499 | spin_lock_irqsave(&host->lock, flags); |
| 1500 | |
Adrian Hunter | ceb6143 | 2011-12-27 15:48:41 +0200 | [diff] [blame] | 1501 | if (host->flags & SDHCI_DEVICE_DEAD) { |
| 1502 | spin_unlock_irqrestore(&host->lock, flags); |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 1503 | if (!IS_ERR(mmc->supply.vmmc) && |
| 1504 | ios->power_mode == MMC_POWER_OFF) |
Markus Mayer | 4e743f1 | 2014-07-03 13:27:42 -0700 | [diff] [blame] | 1505 | mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); |
Adrian Hunter | ceb6143 | 2011-12-27 15:48:41 +0200 | [diff] [blame] | 1506 | return; |
| 1507 | } |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1508 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1509 | /* |
| 1510 | * Reset the chip on each power off. |
| 1511 | * Should clear out any weird states. |
| 1512 | */ |
| 1513 | if (ios->power_mode == MMC_POWER_OFF) { |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1514 | sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); |
Anton Vorontsov | 7260cf5 | 2009-03-17 00:13:48 +0300 | [diff] [blame] | 1515 | sdhci_reinit(host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1516 | } |
| 1517 | |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1518 | if (host->version >= SDHCI_SPEC_300 && |
Dong Aisheng | 372c463 | 2013-10-18 19:48:50 +0800 | [diff] [blame] | 1519 | (ios->power_mode == MMC_POWER_UP) && |
| 1520 | !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1521 | sdhci_enable_preset_value(host, false); |
| 1522 | |
Russell King | 373073e | 2014-04-25 12:58:45 +0100 | [diff] [blame] | 1523 | if (!ios->clock || ios->clock != host->clock) { |
Russell King | 1771059 | 2014-04-25 12:58:55 +0100 | [diff] [blame] | 1524 | host->ops->set_clock(host, ios->clock); |
Russell King | 373073e | 2014-04-25 12:58:45 +0100 | [diff] [blame] | 1525 | host->clock = ios->clock; |
Aisheng Dong | 03d6f5f | 2014-08-27 15:26:32 +0800 | [diff] [blame] | 1526 | |
| 1527 | if (host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK && |
| 1528 | host->clock) { |
| 1529 | host->timeout_clk = host->mmc->actual_clock ? |
| 1530 | host->mmc->actual_clock / 1000 : |
| 1531 | host->clock / 1000; |
| 1532 | host->mmc->max_busy_timeout = |
| 1533 | host->ops->get_max_timeout_count ? |
| 1534 | host->ops->get_max_timeout_count(host) : |
| 1535 | 1 << 27; |
| 1536 | host->mmc->max_busy_timeout /= host->timeout_clk; |
| 1537 | } |
Russell King | 373073e | 2014-04-25 12:58:45 +0100 | [diff] [blame] | 1538 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1539 | |
Russell King | 24fbb3c | 2014-04-25 13:00:06 +0100 | [diff] [blame] | 1540 | sdhci_set_power(host, ios->power_mode, ios->vdd); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1541 | |
Philip Rakity | 643a81f | 2010-09-23 08:24:32 -0700 | [diff] [blame] | 1542 | if (host->ops->platform_send_init_74_clocks) |
| 1543 | host->ops->platform_send_init_74_clocks(host, ios->power_mode); |
| 1544 | |
Russell King | 2317f56 | 2014-04-25 12:57:07 +0100 | [diff] [blame] | 1545 | host->ops->set_bus_width(host, ios->bus_width); |
Philip Rakity | 15ec446 | 2010-11-19 16:48:39 -0500 | [diff] [blame] | 1546 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 1547 | ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); |
Pierre Ossman | cd9277c | 2007-02-18 12:07:47 +0100 | [diff] [blame] | 1548 | |
Philip Rakity | 3ab9c8d | 2010-10-06 11:57:23 -0700 | [diff] [blame] | 1549 | if ((ios->timing == MMC_TIMING_SD_HS || |
| 1550 | ios->timing == MMC_TIMING_MMC_HS) |
| 1551 | && !(host->quirks & SDHCI_QUIRK_NO_HISPD_BIT)) |
Pierre Ossman | cd9277c | 2007-02-18 12:07:47 +0100 | [diff] [blame] | 1552 | ctrl |= SDHCI_CTRL_HISPD; |
| 1553 | else |
| 1554 | ctrl &= ~SDHCI_CTRL_HISPD; |
| 1555 | |
Arindam Nath | d6d50a1 | 2011-05-05 12:18:59 +0530 | [diff] [blame] | 1556 | if (host->version >= SDHCI_SPEC_300) { |
Arindam Nath | 49c468f | 2011-05-05 12:19:01 +0530 | [diff] [blame] | 1557 | u16 clk, ctrl_2; |
Arindam Nath | 49c468f | 2011-05-05 12:19:01 +0530 | [diff] [blame] | 1558 | |
| 1559 | /* In case of UHS-I modes, set High Speed Enable */ |
Adrian Hunter | e9fb05d | 2014-11-06 15:19:06 +0200 | [diff] [blame] | 1560 | if ((ios->timing == MMC_TIMING_MMC_HS400) || |
| 1561 | (ios->timing == MMC_TIMING_MMC_HS200) || |
Seungwon Jeon | bb8175a | 2014-03-14 21:12:48 +0900 | [diff] [blame] | 1562 | (ios->timing == MMC_TIMING_MMC_DDR52) || |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 1563 | (ios->timing == MMC_TIMING_UHS_SDR50) || |
Arindam Nath | 49c468f | 2011-05-05 12:19:01 +0530 | [diff] [blame] | 1564 | (ios->timing == MMC_TIMING_UHS_SDR104) || |
| 1565 | (ios->timing == MMC_TIMING_UHS_DDR50) || |
Alexander Elbs | dd8df17 | 2012-01-03 23:26:53 -0500 | [diff] [blame] | 1566 | (ios->timing == MMC_TIMING_UHS_SDR25)) |
Arindam Nath | 49c468f | 2011-05-05 12:19:01 +0530 | [diff] [blame] | 1567 | ctrl |= SDHCI_CTRL_HISPD; |
Arindam Nath | d6d50a1 | 2011-05-05 12:18:59 +0530 | [diff] [blame] | 1568 | |
Russell King | da91a8f | 2014-04-25 13:00:12 +0100 | [diff] [blame] | 1569 | if (!host->preset_enabled) { |
Arindam Nath | 758535c | 2011-05-05 12:19:00 +0530 | [diff] [blame] | 1570 | sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); |
Arindam Nath | d6d50a1 | 2011-05-05 12:18:59 +0530 | [diff] [blame] | 1571 | /* |
| 1572 | * We only need to set Driver Strength if the |
| 1573 | * preset value enable is not set. |
| 1574 | */ |
Russell King | da91a8f | 2014-04-25 13:00:12 +0100 | [diff] [blame] | 1575 | ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
Arindam Nath | d6d50a1 | 2011-05-05 12:18:59 +0530 | [diff] [blame] | 1576 | ctrl_2 &= ~SDHCI_CTRL_DRV_TYPE_MASK; |
| 1577 | if (ios->drv_type == MMC_SET_DRIVER_TYPE_A) |
| 1578 | ctrl_2 |= SDHCI_CTRL_DRV_TYPE_A; |
| 1579 | else if (ios->drv_type == MMC_SET_DRIVER_TYPE_C) |
| 1580 | ctrl_2 |= SDHCI_CTRL_DRV_TYPE_C; |
| 1581 | |
| 1582 | sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); |
Arindam Nath | 758535c | 2011-05-05 12:19:00 +0530 | [diff] [blame] | 1583 | } else { |
| 1584 | /* |
| 1585 | * According to SDHC Spec v3.00, if the Preset Value |
| 1586 | * Enable in the Host Control 2 register is set, we |
| 1587 | * need to reset SD Clock Enable before changing High |
| 1588 | * Speed Enable to avoid generating clock gliches. |
| 1589 | */ |
Arindam Nath | 758535c | 2011-05-05 12:19:00 +0530 | [diff] [blame] | 1590 | |
| 1591 | /* Reset SD Clock Enable */ |
| 1592 | clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); |
| 1593 | clk &= ~SDHCI_CLOCK_CARD_EN; |
| 1594 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); |
| 1595 | |
| 1596 | sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); |
| 1597 | |
| 1598 | /* Re-enable SD Clock */ |
Russell King | 1771059 | 2014-04-25 12:58:55 +0100 | [diff] [blame] | 1599 | host->ops->set_clock(host, host->clock); |
Arindam Nath | d6d50a1 | 2011-05-05 12:18:59 +0530 | [diff] [blame] | 1600 | } |
Arindam Nath | 49c468f | 2011-05-05 12:19:01 +0530 | [diff] [blame] | 1601 | |
Arindam Nath | 49c468f | 2011-05-05 12:19:01 +0530 | [diff] [blame] | 1602 | /* Reset SD Clock Enable */ |
| 1603 | clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); |
| 1604 | clk &= ~SDHCI_CLOCK_CARD_EN; |
| 1605 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); |
| 1606 | |
Russell King | 96d7b78 | 2014-04-25 12:59:26 +0100 | [diff] [blame] | 1607 | host->ops->set_uhs_signaling(host, ios->timing); |
Russell King | d975f12 | 2014-04-25 12:59:31 +0100 | [diff] [blame] | 1608 | host->timing = ios->timing; |
Arindam Nath | 49c468f | 2011-05-05 12:19:01 +0530 | [diff] [blame] | 1609 | |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 1610 | if (!(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN) && |
| 1611 | ((ios->timing == MMC_TIMING_UHS_SDR12) || |
| 1612 | (ios->timing == MMC_TIMING_UHS_SDR25) || |
| 1613 | (ios->timing == MMC_TIMING_UHS_SDR50) || |
| 1614 | (ios->timing == MMC_TIMING_UHS_SDR104) || |
| 1615 | (ios->timing == MMC_TIMING_UHS_DDR50))) { |
| 1616 | u16 preset; |
| 1617 | |
| 1618 | sdhci_enable_preset_value(host, true); |
| 1619 | preset = sdhci_get_preset_value(host); |
| 1620 | ios->drv_type = (preset & SDHCI_PRESET_DRV_MASK) |
| 1621 | >> SDHCI_PRESET_DRV_SHIFT; |
| 1622 | } |
| 1623 | |
Arindam Nath | 49c468f | 2011-05-05 12:19:01 +0530 | [diff] [blame] | 1624 | /* Re-enable SD Clock */ |
Russell King | 1771059 | 2014-04-25 12:58:55 +0100 | [diff] [blame] | 1625 | host->ops->set_clock(host, host->clock); |
Arindam Nath | 758535c | 2011-05-05 12:19:00 +0530 | [diff] [blame] | 1626 | } else |
| 1627 | sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); |
Arindam Nath | d6d50a1 | 2011-05-05 12:18:59 +0530 | [diff] [blame] | 1628 | |
Leandro Dorileo | b835226 | 2007-07-25 23:47:04 +0200 | [diff] [blame] | 1629 | /* |
| 1630 | * Some (ENE) controllers go apeshit on some ios operation, |
| 1631 | * signalling timeout and CRC errors even on CMD0. Resetting |
| 1632 | * it on each ios seems to solve the problem. |
| 1633 | */ |
Mohammad Jamal | c63705e | 2015-01-13 20:47:24 +0530 | [diff] [blame] | 1634 | if (host->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS) |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 1635 | sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); |
Leandro Dorileo | b835226 | 2007-07-25 23:47:04 +0200 | [diff] [blame] | 1636 | |
Pierre Ossman | 5f25a66 | 2006-10-04 02:15:39 -0700 | [diff] [blame] | 1637 | mmiowb(); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1638 | spin_unlock_irqrestore(&host->lock, flags); |
| 1639 | } |
| 1640 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1641 | static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
| 1642 | { |
| 1643 | struct sdhci_host *host = mmc_priv(mmc); |
| 1644 | |
| 1645 | sdhci_runtime_pm_get(host); |
| 1646 | sdhci_do_set_ios(host, ios); |
| 1647 | sdhci_runtime_pm_put(host); |
| 1648 | } |
| 1649 | |
Kevin Liu | 94144a4 | 2013-02-28 17:35:53 +0800 | [diff] [blame] | 1650 | static int sdhci_do_get_cd(struct sdhci_host *host) |
| 1651 | { |
| 1652 | int gpio_cd = mmc_gpio_get_cd(host->mmc); |
| 1653 | |
| 1654 | if (host->flags & SDHCI_DEVICE_DEAD) |
| 1655 | return 0; |
| 1656 | |
| 1657 | /* If polling/nonremovable, assume that the card is always present. */ |
| 1658 | if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) || |
| 1659 | (host->mmc->caps & MMC_CAP_NONREMOVABLE)) |
| 1660 | return 1; |
| 1661 | |
| 1662 | /* Try slot gpio detect */ |
| 1663 | if (!IS_ERR_VALUE(gpio_cd)) |
| 1664 | return !!gpio_cd; |
| 1665 | |
| 1666 | /* Host native card detect */ |
| 1667 | return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT); |
| 1668 | } |
| 1669 | |
| 1670 | static int sdhci_get_cd(struct mmc_host *mmc) |
| 1671 | { |
| 1672 | struct sdhci_host *host = mmc_priv(mmc); |
| 1673 | int ret; |
| 1674 | |
| 1675 | sdhci_runtime_pm_get(host); |
| 1676 | ret = sdhci_do_get_cd(host); |
| 1677 | sdhci_runtime_pm_put(host); |
| 1678 | return ret; |
| 1679 | } |
| 1680 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1681 | static int sdhci_check_ro(struct sdhci_host *host) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1682 | { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1683 | unsigned long flags; |
Wolfram Sang | 2dfb579 | 2010-10-15 12:21:01 +0200 | [diff] [blame] | 1684 | int is_readonly; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1685 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1686 | spin_lock_irqsave(&host->lock, flags); |
| 1687 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1688 | if (host->flags & SDHCI_DEVICE_DEAD) |
Wolfram Sang | 2dfb579 | 2010-10-15 12:21:01 +0200 | [diff] [blame] | 1689 | is_readonly = 0; |
| 1690 | else if (host->ops->get_ro) |
| 1691 | is_readonly = host->ops->get_ro(host); |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1692 | else |
Wolfram Sang | 2dfb579 | 2010-10-15 12:21:01 +0200 | [diff] [blame] | 1693 | is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE) |
| 1694 | & SDHCI_WRITE_PROTECT); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1695 | |
| 1696 | spin_unlock_irqrestore(&host->lock, flags); |
| 1697 | |
Wolfram Sang | 2dfb579 | 2010-10-15 12:21:01 +0200 | [diff] [blame] | 1698 | /* This quirk needs to be replaced by a callback-function later */ |
| 1699 | return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ? |
| 1700 | !is_readonly : is_readonly; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 1701 | } |
| 1702 | |
Takashi Iwai | 82b0e23 | 2011-04-21 20:26:38 +0200 | [diff] [blame] | 1703 | #define SAMPLE_COUNT 5 |
| 1704 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1705 | static int sdhci_do_get_ro(struct sdhci_host *host) |
Takashi Iwai | 82b0e23 | 2011-04-21 20:26:38 +0200 | [diff] [blame] | 1706 | { |
Takashi Iwai | 82b0e23 | 2011-04-21 20:26:38 +0200 | [diff] [blame] | 1707 | int i, ro_count; |
| 1708 | |
Takashi Iwai | 82b0e23 | 2011-04-21 20:26:38 +0200 | [diff] [blame] | 1709 | if (!(host->quirks & SDHCI_QUIRK_UNSTABLE_RO_DETECT)) |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1710 | return sdhci_check_ro(host); |
Takashi Iwai | 82b0e23 | 2011-04-21 20:26:38 +0200 | [diff] [blame] | 1711 | |
| 1712 | ro_count = 0; |
| 1713 | for (i = 0; i < SAMPLE_COUNT; i++) { |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1714 | if (sdhci_check_ro(host)) { |
Takashi Iwai | 82b0e23 | 2011-04-21 20:26:38 +0200 | [diff] [blame] | 1715 | if (++ro_count > SAMPLE_COUNT / 2) |
| 1716 | return 1; |
| 1717 | } |
| 1718 | msleep(30); |
| 1719 | } |
| 1720 | return 0; |
| 1721 | } |
| 1722 | |
Adrian Hunter | 20758b6 | 2011-08-29 16:42:12 +0300 | [diff] [blame] | 1723 | static void sdhci_hw_reset(struct mmc_host *mmc) |
| 1724 | { |
| 1725 | struct sdhci_host *host = mmc_priv(mmc); |
| 1726 | |
| 1727 | if (host->ops && host->ops->hw_reset) |
| 1728 | host->ops->hw_reset(host); |
| 1729 | } |
| 1730 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1731 | static int sdhci_get_ro(struct mmc_host *mmc) |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1732 | { |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1733 | struct sdhci_host *host = mmc_priv(mmc); |
| 1734 | int ret; |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1735 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1736 | sdhci_runtime_pm_get(host); |
| 1737 | ret = sdhci_do_get_ro(host); |
| 1738 | sdhci_runtime_pm_put(host); |
| 1739 | return ret; |
| 1740 | } |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1741 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1742 | static void sdhci_enable_sdio_irq_nolock(struct sdhci_host *host, int enable) |
| 1743 | { |
Russell King | be13855 | 2014-04-25 12:55:56 +0100 | [diff] [blame] | 1744 | if (!(host->flags & SDHCI_DEVICE_DEAD)) { |
Russell King | ef10433 | 2014-04-25 12:55:41 +0100 | [diff] [blame] | 1745 | if (enable) |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 1746 | host->ier |= SDHCI_INT_CARD_INT; |
Russell King | ef10433 | 2014-04-25 12:55:41 +0100 | [diff] [blame] | 1747 | else |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 1748 | host->ier &= ~SDHCI_INT_CARD_INT; |
| 1749 | |
| 1750 | sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); |
| 1751 | sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); |
Russell King | ef10433 | 2014-04-25 12:55:41 +0100 | [diff] [blame] | 1752 | mmiowb(); |
| 1753 | } |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1754 | } |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1755 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1756 | static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable) |
| 1757 | { |
| 1758 | struct sdhci_host *host = mmc_priv(mmc); |
| 1759 | unsigned long flags; |
| 1760 | |
Russell King | ef10433 | 2014-04-25 12:55:41 +0100 | [diff] [blame] | 1761 | sdhci_runtime_pm_get(host); |
| 1762 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1763 | spin_lock_irqsave(&host->lock, flags); |
Russell King | ef10433 | 2014-04-25 12:55:41 +0100 | [diff] [blame] | 1764 | if (enable) |
| 1765 | host->flags |= SDHCI_SDIO_IRQ_ENABLED; |
| 1766 | else |
| 1767 | host->flags &= ~SDHCI_SDIO_IRQ_ENABLED; |
| 1768 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1769 | sdhci_enable_sdio_irq_nolock(host, enable); |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1770 | spin_unlock_irqrestore(&host->lock, flags); |
Russell King | ef10433 | 2014-04-25 12:55:41 +0100 | [diff] [blame] | 1771 | |
| 1772 | sdhci_runtime_pm_put(host); |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 1773 | } |
| 1774 | |
Philip Rakity | 6231f3d | 2012-07-23 15:56:23 -0700 | [diff] [blame] | 1775 | static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host, |
Fabio Estevam | 21f5998 | 2013-02-14 10:35:03 -0200 | [diff] [blame] | 1776 | struct mmc_ios *ios) |
Philip Rakity | 6231f3d | 2012-07-23 15:56:23 -0700 | [diff] [blame] | 1777 | { |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 1778 | struct mmc_host *mmc = host->mmc; |
Philip Rakity | 6231f3d | 2012-07-23 15:56:23 -0700 | [diff] [blame] | 1779 | u16 ctrl; |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1780 | int ret; |
Philip Rakity | 6231f3d | 2012-07-23 15:56:23 -0700 | [diff] [blame] | 1781 | |
| 1782 | /* |
| 1783 | * Signal Voltage Switching is only applicable for Host Controllers |
| 1784 | * v3.00 and above. |
| 1785 | */ |
| 1786 | if (host->version < SDHCI_SPEC_300) |
| 1787 | return 0; |
| 1788 | |
Philip Rakity | 6231f3d | 2012-07-23 15:56:23 -0700 | [diff] [blame] | 1789 | ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1790 | |
Fabio Estevam | 21f5998 | 2013-02-14 10:35:03 -0200 | [diff] [blame] | 1791 | switch (ios->signal_voltage) { |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1792 | case MMC_SIGNAL_VOLTAGE_330: |
| 1793 | /* Set 1.8V Signal Enable in the Host Control2 register to 0 */ |
| 1794 | ctrl &= ~SDHCI_CTRL_VDD_180; |
| 1795 | sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); |
| 1796 | |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 1797 | if (!IS_ERR(mmc->supply.vqmmc)) { |
| 1798 | ret = regulator_set_voltage(mmc->supply.vqmmc, 2700000, |
| 1799 | 3600000); |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1800 | if (ret) { |
Joe Perches | 6606110 | 2014-09-12 14:56:56 -0700 | [diff] [blame] | 1801 | pr_warn("%s: Switching to 3.3V signalling voltage failed\n", |
| 1802 | mmc_hostname(mmc)); |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1803 | return -EIO; |
| 1804 | } |
| 1805 | } |
| 1806 | /* Wait for 5ms */ |
| 1807 | usleep_range(5000, 5500); |
| 1808 | |
| 1809 | /* 3.3V regulator output should be stable within 5 ms */ |
| 1810 | ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
| 1811 | if (!(ctrl & SDHCI_CTRL_VDD_180)) |
| 1812 | return 0; |
| 1813 | |
Joe Perches | 6606110 | 2014-09-12 14:56:56 -0700 | [diff] [blame] | 1814 | pr_warn("%s: 3.3V regulator output did not became stable\n", |
| 1815 | mmc_hostname(mmc)); |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1816 | |
| 1817 | return -EAGAIN; |
| 1818 | case MMC_SIGNAL_VOLTAGE_180: |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 1819 | if (!IS_ERR(mmc->supply.vqmmc)) { |
| 1820 | ret = regulator_set_voltage(mmc->supply.vqmmc, |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1821 | 1700000, 1950000); |
| 1822 | if (ret) { |
Joe Perches | 6606110 | 2014-09-12 14:56:56 -0700 | [diff] [blame] | 1823 | pr_warn("%s: Switching to 1.8V signalling voltage failed\n", |
| 1824 | mmc_hostname(mmc)); |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1825 | return -EIO; |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | /* |
| 1830 | * Enable 1.8V Signal Enable in the Host Control2 |
| 1831 | * register |
| 1832 | */ |
| 1833 | ctrl |= SDHCI_CTRL_VDD_180; |
| 1834 | sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); |
| 1835 | |
Vincent Yang | 9d967a6 | 2015-01-20 16:05:15 +0800 | [diff] [blame] | 1836 | /* Some controller need to do more when switching */ |
| 1837 | if (host->ops->voltage_switch) |
| 1838 | host->ops->voltage_switch(host); |
| 1839 | |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1840 | /* 1.8V regulator output should be stable within 5 ms */ |
| 1841 | ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
| 1842 | if (ctrl & SDHCI_CTRL_VDD_180) |
| 1843 | return 0; |
| 1844 | |
Joe Perches | 6606110 | 2014-09-12 14:56:56 -0700 | [diff] [blame] | 1845 | pr_warn("%s: 1.8V regulator output did not became stable\n", |
| 1846 | mmc_hostname(mmc)); |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1847 | |
| 1848 | return -EAGAIN; |
| 1849 | case MMC_SIGNAL_VOLTAGE_120: |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 1850 | if (!IS_ERR(mmc->supply.vqmmc)) { |
| 1851 | ret = regulator_set_voltage(mmc->supply.vqmmc, 1100000, |
| 1852 | 1300000); |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1853 | if (ret) { |
Joe Perches | 6606110 | 2014-09-12 14:56:56 -0700 | [diff] [blame] | 1854 | pr_warn("%s: Switching to 1.2V signalling voltage failed\n", |
| 1855 | mmc_hostname(mmc)); |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1856 | return -EIO; |
| 1857 | } |
| 1858 | } |
| 1859 | return 0; |
| 1860 | default: |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 1861 | /* No signal voltage switch required */ |
| 1862 | return 0; |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1863 | } |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 1864 | } |
| 1865 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1866 | static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, |
Fabio Estevam | 21f5998 | 2013-02-14 10:35:03 -0200 | [diff] [blame] | 1867 | struct mmc_ios *ios) |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1868 | { |
| 1869 | struct sdhci_host *host = mmc_priv(mmc); |
| 1870 | int err; |
| 1871 | |
| 1872 | if (host->version < SDHCI_SPEC_300) |
| 1873 | return 0; |
| 1874 | sdhci_runtime_pm_get(host); |
Fabio Estevam | 21f5998 | 2013-02-14 10:35:03 -0200 | [diff] [blame] | 1875 | err = sdhci_do_start_signal_voltage_switch(host, ios); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1876 | sdhci_runtime_pm_put(host); |
| 1877 | return err; |
| 1878 | } |
| 1879 | |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 1880 | static int sdhci_card_busy(struct mmc_host *mmc) |
| 1881 | { |
| 1882 | struct sdhci_host *host = mmc_priv(mmc); |
| 1883 | u32 present_state; |
| 1884 | |
| 1885 | sdhci_runtime_pm_get(host); |
| 1886 | /* Check whether DAT[3:0] is 0000 */ |
| 1887 | present_state = sdhci_readl(host, SDHCI_PRESENT_STATE); |
| 1888 | sdhci_runtime_pm_put(host); |
| 1889 | |
| 1890 | return !(present_state & SDHCI_DATA_LVL_MASK); |
| 1891 | } |
| 1892 | |
Adrian Hunter | b5540ce | 2014-12-05 19:25:31 +0200 | [diff] [blame] | 1893 | static int sdhci_prepare_hs400_tuning(struct mmc_host *mmc, struct mmc_ios *ios) |
| 1894 | { |
| 1895 | struct sdhci_host *host = mmc_priv(mmc); |
| 1896 | unsigned long flags; |
| 1897 | |
| 1898 | spin_lock_irqsave(&host->lock, flags); |
| 1899 | host->flags |= SDHCI_HS400_TUNING; |
| 1900 | spin_unlock_irqrestore(&host->lock, flags); |
| 1901 | |
| 1902 | return 0; |
| 1903 | } |
| 1904 | |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 1905 | static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1906 | { |
Russell King | 4b6f37d | 2014-04-25 12:59:36 +0100 | [diff] [blame] | 1907 | struct sdhci_host *host = mmc_priv(mmc); |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1908 | u16 ctrl; |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1909 | int tuning_loop_counter = MAX_TUNING_LOOP; |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1910 | int err = 0; |
Aisheng Dong | 2b35bd8 | 2013-12-23 19:13:04 +0800 | [diff] [blame] | 1911 | unsigned long flags; |
Adrian Hunter | 38e40bf | 2014-12-05 19:25:30 +0200 | [diff] [blame] | 1912 | unsigned int tuning_count = 0; |
Adrian Hunter | b5540ce | 2014-12-05 19:25:31 +0200 | [diff] [blame] | 1913 | bool hs400_tuning; |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1914 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1915 | sdhci_runtime_pm_get(host); |
Aisheng Dong | 2b35bd8 | 2013-12-23 19:13:04 +0800 | [diff] [blame] | 1916 | spin_lock_irqsave(&host->lock, flags); |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1917 | |
Adrian Hunter | b5540ce | 2014-12-05 19:25:31 +0200 | [diff] [blame] | 1918 | hs400_tuning = host->flags & SDHCI_HS400_TUNING; |
| 1919 | host->flags &= ~SDHCI_HS400_TUNING; |
| 1920 | |
Adrian Hunter | 38e40bf | 2014-12-05 19:25:30 +0200 | [diff] [blame] | 1921 | if (host->tuning_mode == SDHCI_TUNING_MODE_1) |
| 1922 | tuning_count = host->tuning_count; |
| 1923 | |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1924 | /* |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 1925 | * The Host Controller needs tuning only in case of SDR104 mode |
| 1926 | * and for SDR50 mode when Use Tuning for SDR50 is set in the |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1927 | * Capabilities register. |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 1928 | * If the Host Controller supports the HS200 mode then the |
| 1929 | * tuning function has to be executed. |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1930 | */ |
Russell King | 4b6f37d | 2014-04-25 12:59:36 +0100 | [diff] [blame] | 1931 | switch (host->timing) { |
Adrian Hunter | b5540ce | 2014-12-05 19:25:31 +0200 | [diff] [blame] | 1932 | /* HS400 tuning is done in HS200 mode */ |
Adrian Hunter | e9fb05d | 2014-11-06 15:19:06 +0200 | [diff] [blame] | 1933 | case MMC_TIMING_MMC_HS400: |
Adrian Hunter | b5540ce | 2014-12-05 19:25:31 +0200 | [diff] [blame] | 1934 | err = -EINVAL; |
| 1935 | goto out_unlock; |
| 1936 | |
Russell King | 4b6f37d | 2014-04-25 12:59:36 +0100 | [diff] [blame] | 1937 | case MMC_TIMING_MMC_HS200: |
Adrian Hunter | b5540ce | 2014-12-05 19:25:31 +0200 | [diff] [blame] | 1938 | /* |
| 1939 | * Periodic re-tuning for HS400 is not expected to be needed, so |
| 1940 | * disable it here. |
| 1941 | */ |
| 1942 | if (hs400_tuning) |
| 1943 | tuning_count = 0; |
| 1944 | break; |
| 1945 | |
Russell King | 4b6f37d | 2014-04-25 12:59:36 +0100 | [diff] [blame] | 1946 | case MMC_TIMING_UHS_SDR104: |
| 1947 | break; |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 1948 | |
Russell King | 4b6f37d | 2014-04-25 12:59:36 +0100 | [diff] [blame] | 1949 | case MMC_TIMING_UHS_SDR50: |
| 1950 | if (host->flags & SDHCI_SDR50_NEEDS_TUNING || |
| 1951 | host->flags & SDHCI_SDR104_NEEDS_TUNING) |
| 1952 | break; |
| 1953 | /* FALLTHROUGH */ |
| 1954 | |
| 1955 | default: |
Adrian Hunter | d519c86 | 2014-12-05 19:25:29 +0200 | [diff] [blame] | 1956 | goto out_unlock; |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1957 | } |
| 1958 | |
Dong Aisheng | 4525181 | 2013-09-13 19:11:30 +0800 | [diff] [blame] | 1959 | if (host->ops->platform_execute_tuning) { |
Aisheng Dong | 2b35bd8 | 2013-12-23 19:13:04 +0800 | [diff] [blame] | 1960 | spin_unlock_irqrestore(&host->lock, flags); |
Dong Aisheng | 4525181 | 2013-09-13 19:11:30 +0800 | [diff] [blame] | 1961 | err = host->ops->platform_execute_tuning(host, opcode); |
| 1962 | sdhci_runtime_pm_put(host); |
| 1963 | return err; |
| 1964 | } |
| 1965 | |
Russell King | 4b6f37d | 2014-04-25 12:59:36 +0100 | [diff] [blame] | 1966 | ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
| 1967 | ctrl |= SDHCI_CTRL_EXEC_TUNING; |
Vincent Yang | 67d0d04 | 2015-01-20 16:05:16 +0800 | [diff] [blame] | 1968 | if (host->quirks2 & SDHCI_QUIRK2_TUNING_WORK_AROUND) |
| 1969 | ctrl |= SDHCI_CTRL_TUNED_CLK; |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1970 | sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); |
| 1971 | |
| 1972 | /* |
| 1973 | * As per the Host Controller spec v3.00, tuning command |
| 1974 | * generates Buffer Read Ready interrupt, so enable that. |
| 1975 | * |
| 1976 | * Note: The spec clearly says that when tuning sequence |
| 1977 | * is being performed, the controller does not generate |
| 1978 | * interrupts other than Buffer Read Ready interrupt. But |
| 1979 | * to make sure we don't hit a controller bug, we _only_ |
| 1980 | * enable Buffer Read Ready interrupt here. |
| 1981 | */ |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 1982 | sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_INT_ENABLE); |
| 1983 | sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_SIGNAL_ENABLE); |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1984 | |
| 1985 | /* |
| 1986 | * Issue CMD19 repeatedly till Execute Tuning is set to 0 or the number |
| 1987 | * of loops reaches 40 times or a timeout of 150ms occurs. |
| 1988 | */ |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1989 | do { |
| 1990 | struct mmc_command cmd = {0}; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1991 | struct mmc_request mrq = {NULL}; |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1992 | |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 1993 | cmd.opcode = opcode; |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 1994 | cmd.arg = 0; |
| 1995 | cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; |
| 1996 | cmd.retries = 0; |
| 1997 | cmd.data = NULL; |
| 1998 | cmd.error = 0; |
| 1999 | |
Al Cooper | 7ce45e9 | 2014-05-09 11:34:07 -0400 | [diff] [blame] | 2000 | if (tuning_loop_counter-- == 0) |
| 2001 | break; |
| 2002 | |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 2003 | mrq.cmd = &cmd; |
| 2004 | host->mrq = &mrq; |
| 2005 | |
| 2006 | /* |
| 2007 | * In response to CMD19, the card sends 64 bytes of tuning |
| 2008 | * block to the Host Controller. So we set the block size |
| 2009 | * to 64 here. |
| 2010 | */ |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 2011 | if (cmd.opcode == MMC_SEND_TUNING_BLOCK_HS200) { |
| 2012 | if (mmc->ios.bus_width == MMC_BUS_WIDTH_8) |
| 2013 | sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 128), |
| 2014 | SDHCI_BLOCK_SIZE); |
| 2015 | else if (mmc->ios.bus_width == MMC_BUS_WIDTH_4) |
| 2016 | sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64), |
| 2017 | SDHCI_BLOCK_SIZE); |
| 2018 | } else { |
| 2019 | sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64), |
| 2020 | SDHCI_BLOCK_SIZE); |
| 2021 | } |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 2022 | |
| 2023 | /* |
| 2024 | * The tuning block is sent by the card to the host controller. |
| 2025 | * So we set the TRNS_READ bit in the Transfer Mode register. |
| 2026 | * This also takes care of setting DMA Enable and Multi Block |
| 2027 | * Select in the same register to 0. |
| 2028 | */ |
| 2029 | sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE); |
| 2030 | |
| 2031 | sdhci_send_command(host, &cmd); |
| 2032 | |
| 2033 | host->cmd = NULL; |
| 2034 | host->mrq = NULL; |
| 2035 | |
Aisheng Dong | 2b35bd8 | 2013-12-23 19:13:04 +0800 | [diff] [blame] | 2036 | spin_unlock_irqrestore(&host->lock, flags); |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 2037 | /* Wait for Buffer Read Ready interrupt */ |
| 2038 | wait_event_interruptible_timeout(host->buf_ready_int, |
| 2039 | (host->tuning_done == 1), |
| 2040 | msecs_to_jiffies(50)); |
Aisheng Dong | 2b35bd8 | 2013-12-23 19:13:04 +0800 | [diff] [blame] | 2041 | spin_lock_irqsave(&host->lock, flags); |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 2042 | |
| 2043 | if (!host->tuning_done) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 2044 | pr_info(DRIVER_NAME ": Timeout waiting for " |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 2045 | "Buffer Read Ready interrupt during tuning " |
| 2046 | "procedure, falling back to fixed sampling " |
| 2047 | "clock\n"); |
| 2048 | ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
| 2049 | ctrl &= ~SDHCI_CTRL_TUNED_CLK; |
| 2050 | ctrl &= ~SDHCI_CTRL_EXEC_TUNING; |
| 2051 | sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); |
| 2052 | |
| 2053 | err = -EIO; |
| 2054 | goto out; |
| 2055 | } |
| 2056 | |
| 2057 | host->tuning_done = 0; |
| 2058 | |
| 2059 | ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
Nick Sanders | 197160d | 2014-05-06 18:52:38 -0700 | [diff] [blame] | 2060 | |
| 2061 | /* eMMC spec does not require a delay between tuning cycles */ |
| 2062 | if (opcode == MMC_SEND_TUNING_BLOCK) |
| 2063 | mdelay(1); |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 2064 | } while (ctrl & SDHCI_CTRL_EXEC_TUNING); |
| 2065 | |
| 2066 | /* |
| 2067 | * The Host Driver has exhausted the maximum number of loops allowed, |
| 2068 | * so use fixed sampling frequency. |
| 2069 | */ |
Al Cooper | 7ce45e9 | 2014-05-09 11:34:07 -0400 | [diff] [blame] | 2070 | if (tuning_loop_counter < 0) { |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 2071 | ctrl &= ~SDHCI_CTRL_TUNED_CLK; |
| 2072 | sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); |
Al Cooper | 7ce45e9 | 2014-05-09 11:34:07 -0400 | [diff] [blame] | 2073 | } |
| 2074 | if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) { |
| 2075 | pr_info(DRIVER_NAME ": Tuning procedure" |
| 2076 | " failed, falling back to fixed sampling" |
| 2077 | " clock\n"); |
Dong Aisheng | 114f2bf | 2013-10-18 19:48:45 +0800 | [diff] [blame] | 2078 | err = -EIO; |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | out: |
Adrian Hunter | 38e40bf | 2014-12-05 19:25:30 +0200 | [diff] [blame] | 2082 | host->flags &= ~SDHCI_NEEDS_RETUNING; |
| 2083 | |
| 2084 | if (tuning_count) { |
Aaron Lu | 973905f | 2012-07-04 13:29:09 +0800 | [diff] [blame] | 2085 | host->flags |= SDHCI_USING_RETUNING_TIMER; |
Adrian Hunter | 38e40bf | 2014-12-05 19:25:30 +0200 | [diff] [blame] | 2086 | mod_timer(&host->tuning_timer, jiffies + tuning_count * HZ); |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | /* |
| 2090 | * In case tuning fails, host controllers which support re-tuning can |
| 2091 | * try tuning again at a later time, when the re-tuning timer expires. |
| 2092 | * So for these controllers, we return 0. Since there might be other |
| 2093 | * controllers who do not have this capability, we return error for |
Aaron Lu | 973905f | 2012-07-04 13:29:09 +0800 | [diff] [blame] | 2094 | * them. SDHCI_USING_RETUNING_TIMER means the host is currently using |
| 2095 | * a retuning timer to do the retuning for the card. |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 2096 | */ |
Aaron Lu | 973905f | 2012-07-04 13:29:09 +0800 | [diff] [blame] | 2097 | if (err && (host->flags & SDHCI_USING_RETUNING_TIMER)) |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 2098 | err = 0; |
| 2099 | |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 2100 | sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); |
| 2101 | sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); |
Adrian Hunter | d519c86 | 2014-12-05 19:25:29 +0200 | [diff] [blame] | 2102 | out_unlock: |
Aisheng Dong | 2b35bd8 | 2013-12-23 19:13:04 +0800 | [diff] [blame] | 2103 | spin_unlock_irqrestore(&host->lock, flags); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2104 | sdhci_runtime_pm_put(host); |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 2105 | |
| 2106 | return err; |
| 2107 | } |
| 2108 | |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 2109 | |
| 2110 | static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable) |
Arindam Nath | 4d55c5a | 2011-05-05 12:19:05 +0530 | [diff] [blame] | 2111 | { |
Arindam Nath | 4d55c5a | 2011-05-05 12:19:05 +0530 | [diff] [blame] | 2112 | /* Host Controller v3.00 defines preset value registers */ |
| 2113 | if (host->version < SDHCI_SPEC_300) |
| 2114 | return; |
| 2115 | |
Arindam Nath | 4d55c5a | 2011-05-05 12:19:05 +0530 | [diff] [blame] | 2116 | /* |
| 2117 | * We only enable or disable Preset Value if they are not already |
| 2118 | * enabled or disabled respectively. Otherwise, we bail out. |
| 2119 | */ |
Russell King | da91a8f | 2014-04-25 13:00:12 +0100 | [diff] [blame] | 2120 | if (host->preset_enabled != enable) { |
| 2121 | u16 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
| 2122 | |
| 2123 | if (enable) |
| 2124 | ctrl |= SDHCI_CTRL_PRESET_VAL_ENABLE; |
| 2125 | else |
| 2126 | ctrl &= ~SDHCI_CTRL_PRESET_VAL_ENABLE; |
| 2127 | |
Arindam Nath | 4d55c5a | 2011-05-05 12:19:05 +0530 | [diff] [blame] | 2128 | sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); |
Russell King | da91a8f | 2014-04-25 13:00:12 +0100 | [diff] [blame] | 2129 | |
| 2130 | if (enable) |
| 2131 | host->flags |= SDHCI_PV_ENABLED; |
| 2132 | else |
| 2133 | host->flags &= ~SDHCI_PV_ENABLED; |
| 2134 | |
| 2135 | host->preset_enabled = enable; |
Arindam Nath | 4d55c5a | 2011-05-05 12:19:05 +0530 | [diff] [blame] | 2136 | } |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2137 | } |
| 2138 | |
Haibo Chen | 348487c | 2014-12-09 17:04:05 +0800 | [diff] [blame] | 2139 | static void sdhci_post_req(struct mmc_host *mmc, struct mmc_request *mrq, |
| 2140 | int err) |
| 2141 | { |
| 2142 | struct sdhci_host *host = mmc_priv(mmc); |
| 2143 | struct mmc_data *data = mrq->data; |
| 2144 | |
| 2145 | if (host->flags & SDHCI_REQ_USE_DMA) { |
| 2146 | if (data->host_cookie) |
| 2147 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, |
| 2148 | data->flags & MMC_DATA_WRITE ? |
| 2149 | DMA_TO_DEVICE : DMA_FROM_DEVICE); |
| 2150 | mrq->data->host_cookie = 0; |
| 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | static int sdhci_pre_dma_transfer(struct sdhci_host *host, |
| 2155 | struct mmc_data *data, |
| 2156 | struct sdhci_host_next *next) |
| 2157 | { |
| 2158 | int sg_count; |
| 2159 | |
| 2160 | if (!next && data->host_cookie && |
| 2161 | data->host_cookie != host->next_data.cookie) { |
| 2162 | pr_debug(DRIVER_NAME "[%s] invalid cookie: %d, next-cookie %d\n", |
| 2163 | __func__, data->host_cookie, host->next_data.cookie); |
| 2164 | data->host_cookie = 0; |
| 2165 | } |
| 2166 | |
| 2167 | /* Check if next job is already prepared */ |
| 2168 | if (next || |
| 2169 | (!next && data->host_cookie != host->next_data.cookie)) { |
| 2170 | sg_count = dma_map_sg(mmc_dev(host->mmc), data->sg, |
| 2171 | data->sg_len, |
| 2172 | data->flags & MMC_DATA_WRITE ? |
| 2173 | DMA_TO_DEVICE : DMA_FROM_DEVICE); |
| 2174 | |
| 2175 | } else { |
| 2176 | sg_count = host->next_data.sg_count; |
| 2177 | host->next_data.sg_count = 0; |
| 2178 | } |
| 2179 | |
| 2180 | |
| 2181 | if (sg_count == 0) |
| 2182 | return -EINVAL; |
| 2183 | |
| 2184 | if (next) { |
| 2185 | next->sg_count = sg_count; |
| 2186 | data->host_cookie = ++next->cookie < 0 ? 1 : next->cookie; |
| 2187 | } else |
| 2188 | host->sg_count = sg_count; |
| 2189 | |
| 2190 | return sg_count; |
| 2191 | } |
| 2192 | |
| 2193 | static void sdhci_pre_req(struct mmc_host *mmc, struct mmc_request *mrq, |
| 2194 | bool is_first_req) |
| 2195 | { |
| 2196 | struct sdhci_host *host = mmc_priv(mmc); |
| 2197 | |
| 2198 | if (mrq->data->host_cookie) { |
| 2199 | mrq->data->host_cookie = 0; |
| 2200 | return; |
| 2201 | } |
| 2202 | |
| 2203 | if (host->flags & SDHCI_REQ_USE_DMA) |
| 2204 | if (sdhci_pre_dma_transfer(host, |
| 2205 | mrq->data, |
| 2206 | &host->next_data) < 0) |
| 2207 | mrq->data->host_cookie = 0; |
| 2208 | } |
| 2209 | |
Guennadi Liakhovetski | 71e6921 | 2012-12-04 16:51:40 +0100 | [diff] [blame] | 2210 | static void sdhci_card_event(struct mmc_host *mmc) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2211 | { |
Guennadi Liakhovetski | 71e6921 | 2012-12-04 16:51:40 +0100 | [diff] [blame] | 2212 | struct sdhci_host *host = mmc_priv(mmc); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2213 | unsigned long flags; |
Krzysztof Kozlowski | 2836766 | 2015-01-05 10:50:15 +0100 | [diff] [blame] | 2214 | int present; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2215 | |
Christian Daudt | 722e128 | 2013-06-20 14:26:36 -0700 | [diff] [blame] | 2216 | /* First check if client has provided their own card event */ |
| 2217 | if (host->ops->card_event) |
| 2218 | host->ops->card_event(host); |
| 2219 | |
Krzysztof Kozlowski | 2836766 | 2015-01-05 10:50:15 +0100 | [diff] [blame] | 2220 | present = sdhci_do_get_cd(host); |
| 2221 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2222 | spin_lock_irqsave(&host->lock, flags); |
| 2223 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2224 | /* Check host->mrq first in case we are runtime suspended */ |
Krzysztof Kozlowski | 2836766 | 2015-01-05 10:50:15 +0100 | [diff] [blame] | 2225 | if (host->mrq && !present) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 2226 | pr_err("%s: Card removed during transfer!\n", |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2227 | mmc_hostname(host->mmc)); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 2228 | pr_err("%s: Resetting controller.\n", |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2229 | mmc_hostname(host->mmc)); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2230 | |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 2231 | sdhci_do_reset(host, SDHCI_RESET_CMD); |
| 2232 | sdhci_do_reset(host, SDHCI_RESET_DATA); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2233 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2234 | host->mrq->cmd->error = -ENOMEDIUM; |
| 2235 | tasklet_schedule(&host->finish_tasklet); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | spin_unlock_irqrestore(&host->lock, flags); |
Guennadi Liakhovetski | 71e6921 | 2012-12-04 16:51:40 +0100 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | static const struct mmc_host_ops sdhci_ops = { |
| 2242 | .request = sdhci_request, |
Haibo Chen | 348487c | 2014-12-09 17:04:05 +0800 | [diff] [blame] | 2243 | .post_req = sdhci_post_req, |
| 2244 | .pre_req = sdhci_pre_req, |
Guennadi Liakhovetski | 71e6921 | 2012-12-04 16:51:40 +0100 | [diff] [blame] | 2245 | .set_ios = sdhci_set_ios, |
Kevin Liu | 94144a4 | 2013-02-28 17:35:53 +0800 | [diff] [blame] | 2246 | .get_cd = sdhci_get_cd, |
Guennadi Liakhovetski | 71e6921 | 2012-12-04 16:51:40 +0100 | [diff] [blame] | 2247 | .get_ro = sdhci_get_ro, |
| 2248 | .hw_reset = sdhci_hw_reset, |
| 2249 | .enable_sdio_irq = sdhci_enable_sdio_irq, |
| 2250 | .start_signal_voltage_switch = sdhci_start_signal_voltage_switch, |
Adrian Hunter | b5540ce | 2014-12-05 19:25:31 +0200 | [diff] [blame] | 2251 | .prepare_hs400_tuning = sdhci_prepare_hs400_tuning, |
Guennadi Liakhovetski | 71e6921 | 2012-12-04 16:51:40 +0100 | [diff] [blame] | 2252 | .execute_tuning = sdhci_execute_tuning, |
Guennadi Liakhovetski | 71e6921 | 2012-12-04 16:51:40 +0100 | [diff] [blame] | 2253 | .card_event = sdhci_card_event, |
Kevin Liu | 20b92a3 | 2012-12-17 19:29:26 +0800 | [diff] [blame] | 2254 | .card_busy = sdhci_card_busy, |
Guennadi Liakhovetski | 71e6921 | 2012-12-04 16:51:40 +0100 | [diff] [blame] | 2255 | }; |
| 2256 | |
| 2257 | /*****************************************************************************\ |
| 2258 | * * |
| 2259 | * Tasklets * |
| 2260 | * * |
| 2261 | \*****************************************************************************/ |
| 2262 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2263 | static void sdhci_tasklet_finish(unsigned long param) |
| 2264 | { |
| 2265 | struct sdhci_host *host; |
| 2266 | unsigned long flags; |
| 2267 | struct mmc_request *mrq; |
| 2268 | |
| 2269 | host = (struct sdhci_host*)param; |
| 2270 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2271 | spin_lock_irqsave(&host->lock, flags); |
| 2272 | |
Chris Ball | 0c9c99a | 2011-04-27 17:35:31 -0400 | [diff] [blame] | 2273 | /* |
| 2274 | * If this tasklet gets rescheduled while running, it will |
| 2275 | * be run again afterwards but without any active request. |
| 2276 | */ |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2277 | if (!host->mrq) { |
| 2278 | spin_unlock_irqrestore(&host->lock, flags); |
Chris Ball | 0c9c99a | 2011-04-27 17:35:31 -0400 | [diff] [blame] | 2279 | return; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2280 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2281 | |
| 2282 | del_timer(&host->timer); |
| 2283 | |
| 2284 | mrq = host->mrq; |
| 2285 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2286 | /* |
| 2287 | * The controller needs a reset of internal state machines |
| 2288 | * upon error conditions. |
| 2289 | */ |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 2290 | if (!(host->flags & SDHCI_DEVICE_DEAD) && |
Ben Dooks | b7b4d34 | 2011-04-27 14:24:19 +0100 | [diff] [blame] | 2291 | ((mrq->cmd && mrq->cmd->error) || |
Andrew Gabbasov | fce9d33 | 2014-10-01 07:14:08 -0500 | [diff] [blame] | 2292 | (mrq->sbc && mrq->sbc->error) || |
| 2293 | (mrq->data && ((mrq->data->error && !mrq->data->stop) || |
| 2294 | (mrq->data->stop && mrq->data->stop->error))) || |
| 2295 | (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))) { |
Pierre Ossman | 645289d | 2006-06-30 02:22:33 -0700 | [diff] [blame] | 2296 | |
| 2297 | /* Some controllers need this kick or reset won't work here */ |
Andy Shevchenko | 8213af3 | 2013-01-07 16:31:08 +0200 | [diff] [blame] | 2298 | if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) |
Pierre Ossman | 645289d | 2006-06-30 02:22:33 -0700 | [diff] [blame] | 2299 | /* This is to force an update */ |
Russell King | 1771059 | 2014-04-25 12:58:55 +0100 | [diff] [blame] | 2300 | host->ops->set_clock(host, host->clock); |
Pierre Ossman | 645289d | 2006-06-30 02:22:33 -0700 | [diff] [blame] | 2301 | |
| 2302 | /* Spec says we should do both at the same time, but Ricoh |
| 2303 | controllers do not like that. */ |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 2304 | sdhci_do_reset(host, SDHCI_RESET_CMD); |
| 2305 | sdhci_do_reset(host, SDHCI_RESET_DATA); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | host->mrq = NULL; |
| 2309 | host->cmd = NULL; |
| 2310 | host->data = NULL; |
| 2311 | |
Pierre Ossman | f913431 | 2008-12-21 17:01:48 +0100 | [diff] [blame] | 2312 | #ifndef SDHCI_USE_LEDS_CLASS |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2313 | sdhci_deactivate_led(host); |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 2314 | #endif |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2315 | |
Pierre Ossman | 5f25a66 | 2006-10-04 02:15:39 -0700 | [diff] [blame] | 2316 | mmiowb(); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2317 | spin_unlock_irqrestore(&host->lock, flags); |
| 2318 | |
| 2319 | mmc_request_done(host->mmc, mrq); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2320 | sdhci_runtime_pm_put(host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | static void sdhci_timeout_timer(unsigned long data) |
| 2324 | { |
| 2325 | struct sdhci_host *host; |
| 2326 | unsigned long flags; |
| 2327 | |
| 2328 | host = (struct sdhci_host*)data; |
| 2329 | |
| 2330 | spin_lock_irqsave(&host->lock, flags); |
| 2331 | |
| 2332 | if (host->mrq) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 2333 | pr_err("%s: Timeout waiting for hardware " |
Pierre Ossman | acf1da4 | 2007-02-09 08:29:19 +0100 | [diff] [blame] | 2334 | "interrupt.\n", mmc_hostname(host->mmc)); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2335 | sdhci_dumpregs(host); |
| 2336 | |
| 2337 | if (host->data) { |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 2338 | host->data->error = -ETIMEDOUT; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2339 | sdhci_finish_data(host); |
| 2340 | } else { |
| 2341 | if (host->cmd) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 2342 | host->cmd->error = -ETIMEDOUT; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2343 | else |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 2344 | host->mrq->cmd->error = -ETIMEDOUT; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2345 | |
| 2346 | tasklet_schedule(&host->finish_tasklet); |
| 2347 | } |
| 2348 | } |
| 2349 | |
Pierre Ossman | 5f25a66 | 2006-10-04 02:15:39 -0700 | [diff] [blame] | 2350 | mmiowb(); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2351 | spin_unlock_irqrestore(&host->lock, flags); |
| 2352 | } |
| 2353 | |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 2354 | static void sdhci_tuning_timer(unsigned long data) |
| 2355 | { |
| 2356 | struct sdhci_host *host; |
| 2357 | unsigned long flags; |
| 2358 | |
| 2359 | host = (struct sdhci_host *)data; |
| 2360 | |
| 2361 | spin_lock_irqsave(&host->lock, flags); |
| 2362 | |
| 2363 | host->flags |= SDHCI_NEEDS_RETUNING; |
| 2364 | |
| 2365 | spin_unlock_irqrestore(&host->lock, flags); |
| 2366 | } |
| 2367 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2368 | /*****************************************************************************\ |
| 2369 | * * |
| 2370 | * Interrupt handling * |
| 2371 | * * |
| 2372 | \*****************************************************************************/ |
| 2373 | |
Adrian Hunter | 6154139 | 2014-09-24 10:27:27 +0300 | [diff] [blame] | 2374 | static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *mask) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2375 | { |
| 2376 | BUG_ON(intmask == 0); |
| 2377 | |
| 2378 | if (!host->cmd) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 2379 | pr_err("%s: Got command interrupt 0x%08x even " |
Pierre Ossman | b67ac3f | 2007-08-12 17:29:47 +0200 | [diff] [blame] | 2380 | "though no command operation was in progress.\n", |
| 2381 | mmc_hostname(host->mmc), (unsigned)intmask); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2382 | sdhci_dumpregs(host); |
| 2383 | return; |
| 2384 | } |
| 2385 | |
Pierre Ossman | 43b58b3 | 2007-07-25 23:15:27 +0200 | [diff] [blame] | 2386 | if (intmask & SDHCI_INT_TIMEOUT) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 2387 | host->cmd->error = -ETIMEDOUT; |
| 2388 | else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT | |
| 2389 | SDHCI_INT_INDEX)) |
| 2390 | host->cmd->error = -EILSEQ; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2391 | |
Pierre Ossman | e809517 | 2008-07-25 01:09:08 +0200 | [diff] [blame] | 2392 | if (host->cmd->error) { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2393 | tasklet_schedule(&host->finish_tasklet); |
Pierre Ossman | e809517 | 2008-07-25 01:09:08 +0200 | [diff] [blame] | 2394 | return; |
| 2395 | } |
| 2396 | |
| 2397 | /* |
| 2398 | * The host can send and interrupt when the busy state has |
| 2399 | * ended, allowing us to wait without wasting CPU cycles. |
| 2400 | * Unfortunately this is overloaded on the "data complete" |
| 2401 | * interrupt, so we need to take some care when handling |
| 2402 | * it. |
| 2403 | * |
| 2404 | * Note: The 1.0 specification is a bit ambiguous about this |
| 2405 | * feature so there might be some problems with older |
| 2406 | * controllers. |
| 2407 | */ |
| 2408 | if (host->cmd->flags & MMC_RSP_BUSY) { |
| 2409 | if (host->cmd->data) |
| 2410 | DBG("Cannot wait for busy signal when also " |
| 2411 | "doing a data transfer"); |
Chanho Min | e99783a | 2014-08-30 12:40:40 +0900 | [diff] [blame] | 2412 | else if (!(host->quirks & SDHCI_QUIRK_NO_BUSY_IRQ) |
| 2413 | && !host->busy_handle) { |
| 2414 | /* Mark that command complete before busy is ended */ |
| 2415 | host->busy_handle = 1; |
Pierre Ossman | e809517 | 2008-07-25 01:09:08 +0200 | [diff] [blame] | 2416 | return; |
Chanho Min | e99783a | 2014-08-30 12:40:40 +0900 | [diff] [blame] | 2417 | } |
Ben Dooks | f945405 | 2009-02-20 20:33:08 +0300 | [diff] [blame] | 2418 | |
| 2419 | /* The controller does not support the end-of-busy IRQ, |
| 2420 | * fall through and take the SDHCI_INT_RESPONSE */ |
Adrian Hunter | 6154139 | 2014-09-24 10:27:27 +0300 | [diff] [blame] | 2421 | } else if ((host->quirks2 & SDHCI_QUIRK2_STOP_WITH_TC) && |
| 2422 | host->cmd->opcode == MMC_STOP_TRANSMISSION && !host->data) { |
| 2423 | *mask &= ~SDHCI_INT_DATA_END; |
Pierre Ossman | e809517 | 2008-07-25 01:09:08 +0200 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | if (intmask & SDHCI_INT_RESPONSE) |
Pierre Ossman | 43b58b3 | 2007-07-25 23:15:27 +0200 | [diff] [blame] | 2427 | sdhci_finish_command(host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2428 | } |
| 2429 | |
George G. Davis | 0957c33 | 2010-02-18 12:32:12 -0500 | [diff] [blame] | 2430 | #ifdef CONFIG_MMC_DEBUG |
Adrian Hunter | 08621b1 | 2014-11-04 12:42:38 +0200 | [diff] [blame] | 2431 | static void sdhci_adma_show_error(struct sdhci_host *host) |
Ben Dooks | 6882a8c | 2009-06-14 13:52:38 +0100 | [diff] [blame] | 2432 | { |
| 2433 | const char *name = mmc_hostname(host->mmc); |
Adrian Hunter | 1c3d5f6 | 2014-11-04 12:42:41 +0200 | [diff] [blame] | 2434 | void *desc = host->adma_table; |
Ben Dooks | 6882a8c | 2009-06-14 13:52:38 +0100 | [diff] [blame] | 2435 | |
| 2436 | sdhci_dumpregs(host); |
| 2437 | |
| 2438 | while (true) { |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 2439 | struct sdhci_adma2_64_desc *dma_desc = desc; |
Ben Dooks | 6882a8c | 2009-06-14 13:52:38 +0100 | [diff] [blame] | 2440 | |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 2441 | if (host->flags & SDHCI_USE_64_BIT_DMA) |
| 2442 | DBG("%s: %p: DMA 0x%08x%08x, LEN 0x%04x, Attr=0x%02x\n", |
| 2443 | name, desc, le32_to_cpu(dma_desc->addr_hi), |
| 2444 | le32_to_cpu(dma_desc->addr_lo), |
| 2445 | le16_to_cpu(dma_desc->len), |
| 2446 | le16_to_cpu(dma_desc->cmd)); |
| 2447 | else |
| 2448 | DBG("%s: %p: DMA 0x%08x, LEN 0x%04x, Attr=0x%02x\n", |
| 2449 | name, desc, le32_to_cpu(dma_desc->addr_lo), |
| 2450 | le16_to_cpu(dma_desc->len), |
| 2451 | le16_to_cpu(dma_desc->cmd)); |
Ben Dooks | 6882a8c | 2009-06-14 13:52:38 +0100 | [diff] [blame] | 2452 | |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 2453 | desc += host->desc_sz; |
Ben Dooks | 6882a8c | 2009-06-14 13:52:38 +0100 | [diff] [blame] | 2454 | |
Adrian Hunter | 0545230 | 2014-11-04 12:42:45 +0200 | [diff] [blame] | 2455 | if (dma_desc->cmd & cpu_to_le16(ADMA2_END)) |
Ben Dooks | 6882a8c | 2009-06-14 13:52:38 +0100 | [diff] [blame] | 2456 | break; |
| 2457 | } |
| 2458 | } |
| 2459 | #else |
Adrian Hunter | 08621b1 | 2014-11-04 12:42:38 +0200 | [diff] [blame] | 2460 | static void sdhci_adma_show_error(struct sdhci_host *host) { } |
Ben Dooks | 6882a8c | 2009-06-14 13:52:38 +0100 | [diff] [blame] | 2461 | #endif |
| 2462 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2463 | static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) |
| 2464 | { |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 2465 | u32 command; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2466 | BUG_ON(intmask == 0); |
| 2467 | |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 2468 | /* CMD19 generates _only_ Buffer Read Ready interrupt */ |
| 2469 | if (intmask & SDHCI_INT_DATA_AVAIL) { |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 2470 | command = SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)); |
| 2471 | if (command == MMC_SEND_TUNING_BLOCK || |
| 2472 | command == MMC_SEND_TUNING_BLOCK_HS200) { |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 2473 | host->tuning_done = 1; |
| 2474 | wake_up(&host->buf_ready_int); |
| 2475 | return; |
| 2476 | } |
| 2477 | } |
| 2478 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2479 | if (!host->data) { |
| 2480 | /* |
Pierre Ossman | e809517 | 2008-07-25 01:09:08 +0200 | [diff] [blame] | 2481 | * The "data complete" interrupt is also used to |
| 2482 | * indicate that a busy state has ended. See comment |
| 2483 | * above in sdhci_cmd_irq(). |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2484 | */ |
Pierre Ossman | e809517 | 2008-07-25 01:09:08 +0200 | [diff] [blame] | 2485 | if (host->cmd && (host->cmd->flags & MMC_RSP_BUSY)) { |
Matthieu CASTET | c5abd5e | 2014-08-14 16:03:17 +0200 | [diff] [blame] | 2486 | if (intmask & SDHCI_INT_DATA_TIMEOUT) { |
| 2487 | host->cmd->error = -ETIMEDOUT; |
| 2488 | tasklet_schedule(&host->finish_tasklet); |
| 2489 | return; |
| 2490 | } |
Pierre Ossman | e809517 | 2008-07-25 01:09:08 +0200 | [diff] [blame] | 2491 | if (intmask & SDHCI_INT_DATA_END) { |
Chanho Min | e99783a | 2014-08-30 12:40:40 +0900 | [diff] [blame] | 2492 | /* |
| 2493 | * Some cards handle busy-end interrupt |
| 2494 | * before the command completed, so make |
| 2495 | * sure we do things in the proper order. |
| 2496 | */ |
| 2497 | if (host->busy_handle) |
| 2498 | sdhci_finish_command(host); |
| 2499 | else |
| 2500 | host->busy_handle = 1; |
Pierre Ossman | e809517 | 2008-07-25 01:09:08 +0200 | [diff] [blame] | 2501 | return; |
| 2502 | } |
| 2503 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2504 | |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 2505 | pr_err("%s: Got data interrupt 0x%08x even " |
Pierre Ossman | b67ac3f | 2007-08-12 17:29:47 +0200 | [diff] [blame] | 2506 | "though no data operation was in progress.\n", |
| 2507 | mmc_hostname(host->mmc), (unsigned)intmask); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2508 | sdhci_dumpregs(host); |
| 2509 | |
| 2510 | return; |
| 2511 | } |
| 2512 | |
| 2513 | if (intmask & SDHCI_INT_DATA_TIMEOUT) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 2514 | host->data->error = -ETIMEDOUT; |
Aries Lee | 22113ef | 2010-12-15 08:14:24 +0100 | [diff] [blame] | 2515 | else if (intmask & SDHCI_INT_DATA_END_BIT) |
| 2516 | host->data->error = -EILSEQ; |
| 2517 | else if ((intmask & SDHCI_INT_DATA_CRC) && |
| 2518 | SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)) |
| 2519 | != MMC_BUS_TEST_R) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 2520 | host->data->error = -EILSEQ; |
Ben Dooks | 6882a8c | 2009-06-14 13:52:38 +0100 | [diff] [blame] | 2521 | else if (intmask & SDHCI_INT_ADMA_ERROR) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 2522 | pr_err("%s: ADMA error\n", mmc_hostname(host->mmc)); |
Adrian Hunter | 08621b1 | 2014-11-04 12:42:38 +0200 | [diff] [blame] | 2523 | sdhci_adma_show_error(host); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 2524 | host->data->error = -EIO; |
Haijun Zhang | a4071fb | 2012-12-04 10:41:28 +0800 | [diff] [blame] | 2525 | if (host->ops->adma_workaround) |
| 2526 | host->ops->adma_workaround(host, intmask); |
Ben Dooks | 6882a8c | 2009-06-14 13:52:38 +0100 | [diff] [blame] | 2527 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2528 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 2529 | if (host->data->error) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2530 | sdhci_finish_data(host); |
| 2531 | else { |
Pierre Ossman | a406f5a | 2006-07-02 16:50:59 +0100 | [diff] [blame] | 2532 | if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2533 | sdhci_transfer_pio(host); |
| 2534 | |
Pierre Ossman | 6ba736a | 2007-05-13 22:39:23 +0200 | [diff] [blame] | 2535 | /* |
| 2536 | * We currently don't do anything fancy with DMA |
| 2537 | * boundaries, but as we can't disable the feature |
| 2538 | * we need to at least restart the transfer. |
Mikko Vinni | f6a03cb | 2011-04-12 09:36:18 -0400 | [diff] [blame] | 2539 | * |
| 2540 | * According to the spec sdhci_readl(host, SDHCI_DMA_ADDRESS) |
| 2541 | * should return a valid address to continue from, but as |
| 2542 | * some controllers are faulty, don't trust them. |
Pierre Ossman | 6ba736a | 2007-05-13 22:39:23 +0200 | [diff] [blame] | 2543 | */ |
Mikko Vinni | f6a03cb | 2011-04-12 09:36:18 -0400 | [diff] [blame] | 2544 | if (intmask & SDHCI_INT_DMA_END) { |
| 2545 | u32 dmastart, dmanow; |
| 2546 | dmastart = sg_dma_address(host->data->sg); |
| 2547 | dmanow = dmastart + host->data->bytes_xfered; |
| 2548 | /* |
| 2549 | * Force update to the next DMA block boundary. |
| 2550 | */ |
| 2551 | dmanow = (dmanow & |
| 2552 | ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1)) + |
| 2553 | SDHCI_DEFAULT_BOUNDARY_SIZE; |
| 2554 | host->data->bytes_xfered = dmanow - dmastart; |
| 2555 | DBG("%s: DMA base 0x%08x, transferred 0x%06x bytes," |
| 2556 | " next 0x%08x\n", |
| 2557 | mmc_hostname(host->mmc), dmastart, |
| 2558 | host->data->bytes_xfered, dmanow); |
| 2559 | sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS); |
| 2560 | } |
Pierre Ossman | 6ba736a | 2007-05-13 22:39:23 +0200 | [diff] [blame] | 2561 | |
Pierre Ossman | e538fbe | 2007-08-12 16:46:32 +0200 | [diff] [blame] | 2562 | if (intmask & SDHCI_INT_DATA_END) { |
| 2563 | if (host->cmd) { |
| 2564 | /* |
| 2565 | * Data managed to finish before the |
| 2566 | * command completed. Make sure we do |
| 2567 | * things in the proper order. |
| 2568 | */ |
| 2569 | host->data_early = 1; |
| 2570 | } else { |
| 2571 | sdhci_finish_data(host); |
| 2572 | } |
| 2573 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2574 | } |
| 2575 | } |
| 2576 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 2577 | static irqreturn_t sdhci_irq(int irq, void *dev_id) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2578 | { |
Russell King | 781e989 | 2014-04-25 12:55:46 +0100 | [diff] [blame] | 2579 | irqreturn_t result = IRQ_NONE; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2580 | struct sdhci_host *host = dev_id; |
Russell King | 4100500 | 2014-04-25 12:55:36 +0100 | [diff] [blame] | 2581 | u32 intmask, mask, unexpected = 0; |
Russell King | 781e989 | 2014-04-25 12:55:46 +0100 | [diff] [blame] | 2582 | int max_loops = 16; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2583 | |
| 2584 | spin_lock(&host->lock); |
| 2585 | |
Russell King | be13855 | 2014-04-25 12:55:56 +0100 | [diff] [blame] | 2586 | if (host->runtime_suspended && !sdhci_sdio_irq_enabled(host)) { |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2587 | spin_unlock(&host->lock); |
Adrian Hunter | 655bca7 | 2014-03-11 10:09:36 +0200 | [diff] [blame] | 2588 | return IRQ_NONE; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2589 | } |
| 2590 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 2591 | intmask = sdhci_readl(host, SDHCI_INT_STATUS); |
Mark Lord | 62df67a5 | 2007-03-06 13:30:13 +0100 | [diff] [blame] | 2592 | if (!intmask || intmask == 0xffffffff) { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2593 | result = IRQ_NONE; |
| 2594 | goto out; |
| 2595 | } |
| 2596 | |
Russell King | 4100500 | 2014-04-25 12:55:36 +0100 | [diff] [blame] | 2597 | do { |
| 2598 | /* Clear selected interrupts. */ |
| 2599 | mask = intmask & (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK | |
| 2600 | SDHCI_INT_BUS_POWER); |
| 2601 | sdhci_writel(host, mask, SDHCI_INT_STATUS); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2602 | |
Russell King | 4100500 | 2014-04-25 12:55:36 +0100 | [diff] [blame] | 2603 | DBG("*** %s got interrupt: 0x%08x\n", |
| 2604 | mmc_hostname(host->mmc), intmask); |
| 2605 | |
| 2606 | if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) { |
| 2607 | u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & |
| 2608 | SDHCI_CARD_PRESENT; |
| 2609 | |
| 2610 | /* |
| 2611 | * There is a observation on i.mx esdhc. INSERT |
| 2612 | * bit will be immediately set again when it gets |
| 2613 | * cleared, if a card is inserted. We have to mask |
| 2614 | * the irq to prevent interrupt storm which will |
| 2615 | * freeze the system. And the REMOVE gets the |
| 2616 | * same situation. |
| 2617 | * |
| 2618 | * More testing are needed here to ensure it works |
| 2619 | * for other platforms though. |
| 2620 | */ |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 2621 | host->ier &= ~(SDHCI_INT_CARD_INSERT | |
| 2622 | SDHCI_INT_CARD_REMOVE); |
| 2623 | host->ier |= present ? SDHCI_INT_CARD_REMOVE : |
| 2624 | SDHCI_INT_CARD_INSERT; |
| 2625 | sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); |
| 2626 | sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); |
Russell King | 4100500 | 2014-04-25 12:55:36 +0100 | [diff] [blame] | 2627 | |
| 2628 | sdhci_writel(host, intmask & (SDHCI_INT_CARD_INSERT | |
| 2629 | SDHCI_INT_CARD_REMOVE), SDHCI_INT_STATUS); |
Russell King | 3560db8 | 2014-04-25 12:55:51 +0100 | [diff] [blame] | 2630 | |
| 2631 | host->thread_isr |= intmask & (SDHCI_INT_CARD_INSERT | |
| 2632 | SDHCI_INT_CARD_REMOVE); |
| 2633 | result = IRQ_WAKE_THREAD; |
Russell King | 4100500 | 2014-04-25 12:55:36 +0100 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | if (intmask & SDHCI_INT_CMD_MASK) |
Adrian Hunter | 6154139 | 2014-09-24 10:27:27 +0300 | [diff] [blame] | 2637 | sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK, |
| 2638 | &intmask); |
Russell King | 4100500 | 2014-04-25 12:55:36 +0100 | [diff] [blame] | 2639 | |
| 2640 | if (intmask & SDHCI_INT_DATA_MASK) |
| 2641 | sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK); |
| 2642 | |
| 2643 | if (intmask & SDHCI_INT_BUS_POWER) |
| 2644 | pr_err("%s: Card is consuming too much power!\n", |
| 2645 | mmc_hostname(host->mmc)); |
| 2646 | |
Russell King | 781e989 | 2014-04-25 12:55:46 +0100 | [diff] [blame] | 2647 | if (intmask & SDHCI_INT_CARD_INT) { |
| 2648 | sdhci_enable_sdio_irq_nolock(host, false); |
| 2649 | host->thread_isr |= SDHCI_INT_CARD_INT; |
| 2650 | result = IRQ_WAKE_THREAD; |
| 2651 | } |
Russell King | 4100500 | 2014-04-25 12:55:36 +0100 | [diff] [blame] | 2652 | |
| 2653 | intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE | |
| 2654 | SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK | |
| 2655 | SDHCI_INT_ERROR | SDHCI_INT_BUS_POWER | |
| 2656 | SDHCI_INT_CARD_INT); |
| 2657 | |
| 2658 | if (intmask) { |
| 2659 | unexpected |= intmask; |
| 2660 | sdhci_writel(host, intmask, SDHCI_INT_STATUS); |
| 2661 | } |
| 2662 | |
Russell King | 781e989 | 2014-04-25 12:55:46 +0100 | [diff] [blame] | 2663 | if (result == IRQ_NONE) |
| 2664 | result = IRQ_HANDLED; |
Russell King | 4100500 | 2014-04-25 12:55:36 +0100 | [diff] [blame] | 2665 | |
| 2666 | intmask = sdhci_readl(host, SDHCI_INT_STATUS); |
Russell King | 4100500 | 2014-04-25 12:55:36 +0100 | [diff] [blame] | 2667 | } while (intmask && --max_loops); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2668 | out: |
| 2669 | spin_unlock(&host->lock); |
| 2670 | |
Alexander Stein | 6379b23 | 2012-03-14 09:52:10 +0100 | [diff] [blame] | 2671 | if (unexpected) { |
| 2672 | pr_err("%s: Unexpected interrupt 0x%08x.\n", |
| 2673 | mmc_hostname(host->mmc), unexpected); |
| 2674 | sdhci_dumpregs(host); |
| 2675 | } |
Pierre Ossman | f75979b | 2007-09-04 07:59:18 +0200 | [diff] [blame] | 2676 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2677 | return result; |
| 2678 | } |
| 2679 | |
Russell King | 781e989 | 2014-04-25 12:55:46 +0100 | [diff] [blame] | 2680 | static irqreturn_t sdhci_thread_irq(int irq, void *dev_id) |
| 2681 | { |
| 2682 | struct sdhci_host *host = dev_id; |
| 2683 | unsigned long flags; |
| 2684 | u32 isr; |
| 2685 | |
| 2686 | spin_lock_irqsave(&host->lock, flags); |
| 2687 | isr = host->thread_isr; |
| 2688 | host->thread_isr = 0; |
| 2689 | spin_unlock_irqrestore(&host->lock, flags); |
| 2690 | |
Russell King | 3560db8 | 2014-04-25 12:55:51 +0100 | [diff] [blame] | 2691 | if (isr & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) { |
| 2692 | sdhci_card_event(host->mmc); |
| 2693 | mmc_detect_change(host->mmc, msecs_to_jiffies(200)); |
| 2694 | } |
| 2695 | |
Russell King | 781e989 | 2014-04-25 12:55:46 +0100 | [diff] [blame] | 2696 | if (isr & SDHCI_INT_CARD_INT) { |
| 2697 | sdio_run_irqs(host->mmc); |
| 2698 | |
| 2699 | spin_lock_irqsave(&host->lock, flags); |
| 2700 | if (host->flags & SDHCI_SDIO_IRQ_ENABLED) |
| 2701 | sdhci_enable_sdio_irq_nolock(host, true); |
| 2702 | spin_unlock_irqrestore(&host->lock, flags); |
| 2703 | } |
| 2704 | |
| 2705 | return isr ? IRQ_HANDLED : IRQ_NONE; |
| 2706 | } |
| 2707 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2708 | /*****************************************************************************\ |
| 2709 | * * |
| 2710 | * Suspend/resume * |
| 2711 | * * |
| 2712 | \*****************************************************************************/ |
| 2713 | |
| 2714 | #ifdef CONFIG_PM |
Kevin Liu | ad080d7 | 2013-01-05 17:21:33 +0800 | [diff] [blame] | 2715 | void sdhci_enable_irq_wakeups(struct sdhci_host *host) |
| 2716 | { |
| 2717 | u8 val; |
| 2718 | u8 mask = SDHCI_WAKE_ON_INSERT | SDHCI_WAKE_ON_REMOVE |
| 2719 | | SDHCI_WAKE_ON_INT; |
| 2720 | |
| 2721 | val = sdhci_readb(host, SDHCI_WAKE_UP_CONTROL); |
| 2722 | val |= mask ; |
| 2723 | /* Avoid fake wake up */ |
| 2724 | if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) |
| 2725 | val &= ~(SDHCI_WAKE_ON_INSERT | SDHCI_WAKE_ON_REMOVE); |
| 2726 | sdhci_writeb(host, val, SDHCI_WAKE_UP_CONTROL); |
| 2727 | } |
| 2728 | EXPORT_SYMBOL_GPL(sdhci_enable_irq_wakeups); |
| 2729 | |
Fabio Estevam | 0b10f47 | 2014-08-30 14:53:13 -0300 | [diff] [blame] | 2730 | static void sdhci_disable_irq_wakeups(struct sdhci_host *host) |
Kevin Liu | ad080d7 | 2013-01-05 17:21:33 +0800 | [diff] [blame] | 2731 | { |
| 2732 | u8 val; |
| 2733 | u8 mask = SDHCI_WAKE_ON_INSERT | SDHCI_WAKE_ON_REMOVE |
| 2734 | | SDHCI_WAKE_ON_INT; |
| 2735 | |
| 2736 | val = sdhci_readb(host, SDHCI_WAKE_UP_CONTROL); |
| 2737 | val &= ~mask; |
| 2738 | sdhci_writeb(host, val, SDHCI_WAKE_UP_CONTROL); |
| 2739 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2740 | |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 2741 | int sdhci_suspend_host(struct sdhci_host *host) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2742 | { |
Anton Vorontsov | 7260cf5 | 2009-03-17 00:13:48 +0300 | [diff] [blame] | 2743 | sdhci_disable_card_detection(host); |
| 2744 | |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 2745 | /* Disable tuning since we are suspending */ |
Aaron Lu | 973905f | 2012-07-04 13:29:09 +0800 | [diff] [blame] | 2746 | if (host->flags & SDHCI_USING_RETUNING_TIMER) { |
Aaron Lu | c6ced0d | 2011-12-28 11:11:12 +0800 | [diff] [blame] | 2747 | del_timer_sync(&host->tuning_timer); |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 2748 | host->flags &= ~SDHCI_NEEDS_RETUNING; |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 2749 | } |
| 2750 | |
Kevin Liu | ad080d7 | 2013-01-05 17:21:33 +0800 | [diff] [blame] | 2751 | if (!device_may_wakeup(mmc_dev(host->mmc))) { |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 2752 | host->ier = 0; |
| 2753 | sdhci_writel(host, 0, SDHCI_INT_ENABLE); |
| 2754 | sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); |
Kevin Liu | ad080d7 | 2013-01-05 17:21:33 +0800 | [diff] [blame] | 2755 | free_irq(host->irq, host); |
| 2756 | } else { |
| 2757 | sdhci_enable_irq_wakeups(host); |
| 2758 | enable_irq_wake(host->irq); |
| 2759 | } |
Ulf Hansson | 4ee14ec | 2013-09-25 14:15:24 +0200 | [diff] [blame] | 2760 | return 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2761 | } |
| 2762 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2763 | EXPORT_SYMBOL_GPL(sdhci_suspend_host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2764 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2765 | int sdhci_resume_host(struct sdhci_host *host) |
| 2766 | { |
Ulf Hansson | 4ee14ec | 2013-09-25 14:15:24 +0200 | [diff] [blame] | 2767 | int ret = 0; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2768 | |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 2769 | if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2770 | if (host->ops->enable_dma) |
| 2771 | host->ops->enable_dma(host); |
| 2772 | } |
| 2773 | |
Kevin Liu | ad080d7 | 2013-01-05 17:21:33 +0800 | [diff] [blame] | 2774 | if (!device_may_wakeup(mmc_dev(host->mmc))) { |
Russell King | 781e989 | 2014-04-25 12:55:46 +0100 | [diff] [blame] | 2775 | ret = request_threaded_irq(host->irq, sdhci_irq, |
| 2776 | sdhci_thread_irq, IRQF_SHARED, |
| 2777 | mmc_hostname(host->mmc), host); |
Kevin Liu | ad080d7 | 2013-01-05 17:21:33 +0800 | [diff] [blame] | 2778 | if (ret) |
| 2779 | return ret; |
| 2780 | } else { |
| 2781 | sdhci_disable_irq_wakeups(host); |
| 2782 | disable_irq_wake(host->irq); |
| 2783 | } |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2784 | |
Adrian Hunter | 6308d29 | 2012-02-07 14:48:54 +0200 | [diff] [blame] | 2785 | if ((host->mmc->pm_flags & MMC_PM_KEEP_POWER) && |
| 2786 | (host->quirks2 & SDHCI_QUIRK2_HOST_OFF_CARD_ON)) { |
| 2787 | /* Card keeps power but host controller does not */ |
| 2788 | sdhci_init(host, 0); |
| 2789 | host->pwr = 0; |
| 2790 | host->clock = 0; |
| 2791 | sdhci_do_set_ios(host, &host->mmc->ios); |
| 2792 | } else { |
| 2793 | sdhci_init(host, (host->mmc->pm_flags & MMC_PM_KEEP_POWER)); |
| 2794 | mmiowb(); |
| 2795 | } |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2796 | |
Anton Vorontsov | 7260cf5 | 2009-03-17 00:13:48 +0300 | [diff] [blame] | 2797 | sdhci_enable_card_detection(host); |
| 2798 | |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 2799 | /* Set the re-tuning expiration flag */ |
Aaron Lu | 973905f | 2012-07-04 13:29:09 +0800 | [diff] [blame] | 2800 | if (host->flags & SDHCI_USING_RETUNING_TIMER) |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 2801 | host->flags |= SDHCI_NEEDS_RETUNING; |
| 2802 | |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 2803 | return ret; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | EXPORT_SYMBOL_GPL(sdhci_resume_host); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2807 | |
| 2808 | static int sdhci_runtime_pm_get(struct sdhci_host *host) |
| 2809 | { |
| 2810 | return pm_runtime_get_sync(host->mmc->parent); |
| 2811 | } |
| 2812 | |
| 2813 | static int sdhci_runtime_pm_put(struct sdhci_host *host) |
| 2814 | { |
| 2815 | pm_runtime_mark_last_busy(host->mmc->parent); |
| 2816 | return pm_runtime_put_autosuspend(host->mmc->parent); |
| 2817 | } |
| 2818 | |
Adrian Hunter | f0710a5 | 2013-05-06 12:17:32 +0300 | [diff] [blame] | 2819 | static void sdhci_runtime_pm_bus_on(struct sdhci_host *host) |
| 2820 | { |
| 2821 | if (host->runtime_suspended || host->bus_on) |
| 2822 | return; |
| 2823 | host->bus_on = true; |
| 2824 | pm_runtime_get_noresume(host->mmc->parent); |
| 2825 | } |
| 2826 | |
| 2827 | static void sdhci_runtime_pm_bus_off(struct sdhci_host *host) |
| 2828 | { |
| 2829 | if (host->runtime_suspended || !host->bus_on) |
| 2830 | return; |
| 2831 | host->bus_on = false; |
| 2832 | pm_runtime_put_noidle(host->mmc->parent); |
| 2833 | } |
| 2834 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2835 | int sdhci_runtime_suspend_host(struct sdhci_host *host) |
| 2836 | { |
| 2837 | unsigned long flags; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2838 | |
| 2839 | /* Disable tuning since we are suspending */ |
Aaron Lu | 973905f | 2012-07-04 13:29:09 +0800 | [diff] [blame] | 2840 | if (host->flags & SDHCI_USING_RETUNING_TIMER) { |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2841 | del_timer_sync(&host->tuning_timer); |
| 2842 | host->flags &= ~SDHCI_NEEDS_RETUNING; |
| 2843 | } |
| 2844 | |
| 2845 | spin_lock_irqsave(&host->lock, flags); |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 2846 | host->ier &= SDHCI_INT_CARD_INT; |
| 2847 | sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); |
| 2848 | sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2849 | spin_unlock_irqrestore(&host->lock, flags); |
| 2850 | |
Russell King | 781e989 | 2014-04-25 12:55:46 +0100 | [diff] [blame] | 2851 | synchronize_hardirq(host->irq); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2852 | |
| 2853 | spin_lock_irqsave(&host->lock, flags); |
| 2854 | host->runtime_suspended = true; |
| 2855 | spin_unlock_irqrestore(&host->lock, flags); |
| 2856 | |
Markus Pargmann | 8a125ba | 2014-06-04 15:24:29 +0200 | [diff] [blame] | 2857 | return 0; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2858 | } |
| 2859 | EXPORT_SYMBOL_GPL(sdhci_runtime_suspend_host); |
| 2860 | |
| 2861 | int sdhci_runtime_resume_host(struct sdhci_host *host) |
| 2862 | { |
| 2863 | unsigned long flags; |
Markus Pargmann | 8a125ba | 2014-06-04 15:24:29 +0200 | [diff] [blame] | 2864 | int host_flags = host->flags; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2865 | |
| 2866 | if (host_flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { |
| 2867 | if (host->ops->enable_dma) |
| 2868 | host->ops->enable_dma(host); |
| 2869 | } |
| 2870 | |
| 2871 | sdhci_init(host, 0); |
| 2872 | |
| 2873 | /* Force clock and power re-program */ |
| 2874 | host->pwr = 0; |
| 2875 | host->clock = 0; |
Jisheng Zhang | 3396e73 | 2015-01-29 17:42:12 +0800 | [diff] [blame] | 2876 | sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2877 | sdhci_do_set_ios(host, &host->mmc->ios); |
| 2878 | |
Kevin Liu | 5298338 | 2013-01-31 11:31:37 +0800 | [diff] [blame] | 2879 | if ((host_flags & SDHCI_PV_ENABLED) && |
| 2880 | !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) { |
| 2881 | spin_lock_irqsave(&host->lock, flags); |
| 2882 | sdhci_enable_preset_value(host, true); |
| 2883 | spin_unlock_irqrestore(&host->lock, flags); |
| 2884 | } |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2885 | |
| 2886 | /* Set the re-tuning expiration flag */ |
Aaron Lu | 973905f | 2012-07-04 13:29:09 +0800 | [diff] [blame] | 2887 | if (host->flags & SDHCI_USING_RETUNING_TIMER) |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2888 | host->flags |= SDHCI_NEEDS_RETUNING; |
| 2889 | |
| 2890 | spin_lock_irqsave(&host->lock, flags); |
| 2891 | |
| 2892 | host->runtime_suspended = false; |
| 2893 | |
| 2894 | /* Enable SDIO IRQ */ |
Russell King | ef10433 | 2014-04-25 12:55:41 +0100 | [diff] [blame] | 2895 | if (host->flags & SDHCI_SDIO_IRQ_ENABLED) |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2896 | sdhci_enable_sdio_irq_nolock(host, true); |
| 2897 | |
| 2898 | /* Enable Card Detection */ |
| 2899 | sdhci_enable_card_detection(host); |
| 2900 | |
| 2901 | spin_unlock_irqrestore(&host->lock, flags); |
| 2902 | |
Markus Pargmann | 8a125ba | 2014-06-04 15:24:29 +0200 | [diff] [blame] | 2903 | return 0; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2904 | } |
| 2905 | EXPORT_SYMBOL_GPL(sdhci_runtime_resume_host); |
| 2906 | |
Rafael J. Wysocki | 162d6f9 | 2014-12-05 03:05:33 +0100 | [diff] [blame] | 2907 | #endif /* CONFIG_PM */ |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2908 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2909 | /*****************************************************************************\ |
| 2910 | * * |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2911 | * Device allocation/registration * |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2912 | * * |
| 2913 | \*****************************************************************************/ |
| 2914 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2915 | struct sdhci_host *sdhci_alloc_host(struct device *dev, |
| 2916 | size_t priv_size) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2917 | { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2918 | struct mmc_host *mmc; |
| 2919 | struct sdhci_host *host; |
| 2920 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2921 | WARN_ON(dev == NULL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2922 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2923 | mmc = mmc_alloc_host(sizeof(struct sdhci_host) + priv_size, dev); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2924 | if (!mmc) |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2925 | return ERR_PTR(-ENOMEM); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2926 | |
| 2927 | host = mmc_priv(mmc); |
| 2928 | host->mmc = mmc; |
| 2929 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2930 | return host; |
| 2931 | } |
Pierre Ossman | 8a4da14 | 2006-10-04 02:15:40 -0700 | [diff] [blame] | 2932 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2933 | EXPORT_SYMBOL_GPL(sdhci_alloc_host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2934 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2935 | int sdhci_add_host(struct sdhci_host *host) |
| 2936 | { |
| 2937 | struct mmc_host *mmc; |
Philip Rakity | bd6a8c3 | 2012-06-27 21:49:27 -0700 | [diff] [blame] | 2938 | u32 caps[2] = {0, 0}; |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 2939 | u32 max_current_caps; |
| 2940 | unsigned int ocr_avail; |
Adrian Hunter | f5fa92e | 2014-09-24 10:27:32 +0300 | [diff] [blame] | 2941 | unsigned int override_timeout_clk; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2942 | int ret; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2943 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2944 | WARN_ON(host == NULL); |
| 2945 | if (host == NULL) |
| 2946 | return -EINVAL; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2947 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2948 | mmc = host->mmc; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2949 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2950 | if (debug_quirks) |
| 2951 | host->quirks = debug_quirks; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 2952 | if (debug_quirks2) |
| 2953 | host->quirks2 = debug_quirks2; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2954 | |
Adrian Hunter | f5fa92e | 2014-09-24 10:27:32 +0300 | [diff] [blame] | 2955 | override_timeout_clk = host->timeout_clk; |
| 2956 | |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 2957 | sdhci_do_reset(host, SDHCI_RESET_ALL); |
Pierre Ossman | d96649e | 2006-06-30 02:22:30 -0700 | [diff] [blame] | 2958 | |
Anton Vorontsov | 4e4141a | 2009-03-17 00:13:46 +0300 | [diff] [blame] | 2959 | host->version = sdhci_readw(host, SDHCI_HOST_VERSION); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 2960 | host->version = (host->version & SDHCI_SPEC_VER_MASK) |
| 2961 | >> SDHCI_SPEC_VER_SHIFT; |
Zhangfei Gao | 85105c5 | 2010-08-06 07:10:01 +0800 | [diff] [blame] | 2962 | if (host->version > SDHCI_SPEC_300) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 2963 | pr_err("%s: Unknown controller version (%d). " |
Pierre Ossman | b69c905 | 2008-03-08 23:44:25 +0100 | [diff] [blame] | 2964 | "You may experience problems.\n", mmc_hostname(mmc), |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 2965 | host->version); |
Pierre Ossman | 4a96550 | 2006-06-30 02:22:29 -0700 | [diff] [blame] | 2966 | } |
| 2967 | |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 2968 | caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps : |
Maxim Levitsky | ccc92c2 | 2010-08-10 18:01:42 -0700 | [diff] [blame] | 2969 | sdhci_readl(host, SDHCI_CAPABILITIES); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2970 | |
Philip Rakity | bd6a8c3 | 2012-06-27 21:49:27 -0700 | [diff] [blame] | 2971 | if (host->version >= SDHCI_SPEC_300) |
| 2972 | caps[1] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? |
| 2973 | host->caps1 : |
| 2974 | sdhci_readl(host, SDHCI_CAPABILITIES_1); |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 2975 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2976 | if (host->quirks & SDHCI_QUIRK_FORCE_DMA) |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 2977 | host->flags |= SDHCI_USE_SDMA; |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 2978 | else if (!(caps[0] & SDHCI_CAN_DO_SDMA)) |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 2979 | DBG("Controller doesn't have SDMA capability\n"); |
Pierre Ossman | 6743527 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 2980 | else |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 2981 | host->flags |= SDHCI_USE_SDMA; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 2982 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 2983 | if ((host->quirks & SDHCI_QUIRK_BROKEN_DMA) && |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 2984 | (host->flags & SDHCI_USE_SDMA)) { |
Rolf Eike Beer | cee687c | 2007-11-02 15:22:30 +0100 | [diff] [blame] | 2985 | DBG("Disabling DMA as it is marked broken\n"); |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 2986 | host->flags &= ~SDHCI_USE_SDMA; |
Feng Tang | 7c168e3 | 2007-09-30 12:44:18 +0200 | [diff] [blame] | 2987 | } |
| 2988 | |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 2989 | if ((host->version >= SDHCI_SPEC_200) && |
| 2990 | (caps[0] & SDHCI_CAN_DO_ADMA2)) |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 2991 | host->flags |= SDHCI_USE_ADMA; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 2992 | |
| 2993 | if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) && |
| 2994 | (host->flags & SDHCI_USE_ADMA)) { |
| 2995 | DBG("Disabling ADMA as it is marked broken\n"); |
| 2996 | host->flags &= ~SDHCI_USE_ADMA; |
| 2997 | } |
| 2998 | |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 2999 | /* |
| 3000 | * It is assumed that a 64-bit capable device has set a 64-bit DMA mask |
| 3001 | * and *must* do 64-bit DMA. A driver has the opportunity to change |
| 3002 | * that during the first call to ->enable_dma(). Similarly |
| 3003 | * SDHCI_QUIRK2_BROKEN_64_BIT_DMA must be left to the drivers to |
| 3004 | * implement. |
| 3005 | */ |
| 3006 | if (sdhci_readl(host, SDHCI_CAPABILITIES) & SDHCI_CAN_64BIT) |
| 3007 | host->flags |= SDHCI_USE_64_BIT_DMA; |
| 3008 | |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 3009 | if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 3010 | if (host->ops->enable_dma) { |
| 3011 | if (host->ops->enable_dma(host)) { |
Joe Perches | 6606110 | 2014-09-12 14:56:56 -0700 | [diff] [blame] | 3012 | pr_warn("%s: No suitable DMA available - falling back to PIO\n", |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 3013 | mmc_hostname(mmc)); |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 3014 | host->flags &= |
| 3015 | ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 3016 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3017 | } |
| 3018 | } |
| 3019 | |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 3020 | /* SDMA does not support 64-bit DMA */ |
| 3021 | if (host->flags & SDHCI_USE_64_BIT_DMA) |
| 3022 | host->flags &= ~SDHCI_USE_SDMA; |
| 3023 | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3024 | if (host->flags & SDHCI_USE_ADMA) { |
| 3025 | /* |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 3026 | * The DMA descriptor table size is calculated as the maximum |
| 3027 | * number of segments times 2, to allow for an alignment |
| 3028 | * descriptor for each segment, plus 1 for a nop end descriptor, |
| 3029 | * all multipled by the descriptor size. |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3030 | */ |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 3031 | if (host->flags & SDHCI_USE_64_BIT_DMA) { |
| 3032 | host->adma_table_sz = (SDHCI_MAX_SEGS * 2 + 1) * |
| 3033 | SDHCI_ADMA2_64_DESC_SZ; |
| 3034 | host->align_buffer_sz = SDHCI_MAX_SEGS * |
| 3035 | SDHCI_ADMA2_64_ALIGN; |
| 3036 | host->desc_sz = SDHCI_ADMA2_64_DESC_SZ; |
| 3037 | host->align_sz = SDHCI_ADMA2_64_ALIGN; |
| 3038 | host->align_mask = SDHCI_ADMA2_64_ALIGN - 1; |
| 3039 | } else { |
| 3040 | host->adma_table_sz = (SDHCI_MAX_SEGS * 2 + 1) * |
| 3041 | SDHCI_ADMA2_32_DESC_SZ; |
| 3042 | host->align_buffer_sz = SDHCI_MAX_SEGS * |
| 3043 | SDHCI_ADMA2_32_ALIGN; |
| 3044 | host->desc_sz = SDHCI_ADMA2_32_DESC_SZ; |
| 3045 | host->align_sz = SDHCI_ADMA2_32_ALIGN; |
| 3046 | host->align_mask = SDHCI_ADMA2_32_ALIGN - 1; |
| 3047 | } |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 3048 | host->adma_table = dma_alloc_coherent(mmc_dev(mmc), |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 3049 | host->adma_table_sz, |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 3050 | &host->adma_addr, |
| 3051 | GFP_KERNEL); |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 3052 | host->align_buffer = kmalloc(host->align_buffer_sz, GFP_KERNEL); |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 3053 | if (!host->adma_table || !host->align_buffer) { |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 3054 | dma_free_coherent(mmc_dev(mmc), host->adma_table_sz, |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 3055 | host->adma_table, host->adma_addr); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3056 | kfree(host->align_buffer); |
Joe Perches | 6606110 | 2014-09-12 14:56:56 -0700 | [diff] [blame] | 3057 | pr_warn("%s: Unable to allocate ADMA buffers - falling back to standard DMA\n", |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3058 | mmc_hostname(mmc)); |
| 3059 | host->flags &= ~SDHCI_USE_ADMA; |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 3060 | host->adma_table = NULL; |
Russell King | d1e49f7 | 2014-04-25 12:58:34 +0100 | [diff] [blame] | 3061 | host->align_buffer = NULL; |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 3062 | } else if (host->adma_addr & host->align_mask) { |
Joe Perches | 6606110 | 2014-09-12 14:56:56 -0700 | [diff] [blame] | 3063 | pr_warn("%s: unable to allocate aligned ADMA descriptor\n", |
| 3064 | mmc_hostname(mmc)); |
Russell King | d1e49f7 | 2014-04-25 12:58:34 +0100 | [diff] [blame] | 3065 | host->flags &= ~SDHCI_USE_ADMA; |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 3066 | dma_free_coherent(mmc_dev(mmc), host->adma_table_sz, |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 3067 | host->adma_table, host->adma_addr); |
Russell King | d1e49f7 | 2014-04-25 12:58:34 +0100 | [diff] [blame] | 3068 | kfree(host->align_buffer); |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 3069 | host->adma_table = NULL; |
Russell King | d1e49f7 | 2014-04-25 12:58:34 +0100 | [diff] [blame] | 3070 | host->align_buffer = NULL; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3071 | } |
| 3072 | } |
| 3073 | |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 3074 | /* |
| 3075 | * If we use DMA, then it's up to the caller to set the DMA |
| 3076 | * mask, but PIO does not need the hw shim so we set a new |
| 3077 | * mask here in that case. |
| 3078 | */ |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 3079 | if (!(host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))) { |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 3080 | host->dma_mask = DMA_BIT_MASK(64); |
Markus Mayer | 4e743f1 | 2014-07-03 13:27:42 -0700 | [diff] [blame] | 3081 | mmc_dev(mmc)->dma_mask = &host->dma_mask; |
Pierre Ossman | 7659150 | 2008-07-21 00:32:11 +0200 | [diff] [blame] | 3082 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3083 | |
Zhangfei Gao | c4687d5 | 2010-08-20 14:02:36 -0400 | [diff] [blame] | 3084 | if (host->version >= SDHCI_SPEC_300) |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3085 | host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK) |
Zhangfei Gao | c4687d5 | 2010-08-20 14:02:36 -0400 | [diff] [blame] | 3086 | >> SDHCI_CLOCK_BASE_SHIFT; |
| 3087 | else |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3088 | host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK) |
Zhangfei Gao | c4687d5 | 2010-08-20 14:02:36 -0400 | [diff] [blame] | 3089 | >> SDHCI_CLOCK_BASE_SHIFT; |
| 3090 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3091 | host->max_clk *= 1000000; |
Anton Vorontsov | f27f47e | 2010-05-26 14:41:53 -0700 | [diff] [blame] | 3092 | if (host->max_clk == 0 || host->quirks & |
| 3093 | SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN) { |
Ben Dooks | 4240ff0 | 2009-03-17 00:13:57 +0300 | [diff] [blame] | 3094 | if (!host->ops->get_max_clock) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 3095 | pr_err("%s: Hardware doesn't specify base clock " |
Ben Dooks | 4240ff0 | 2009-03-17 00:13:57 +0300 | [diff] [blame] | 3096 | "frequency.\n", mmc_hostname(mmc)); |
| 3097 | return -ENODEV; |
| 3098 | } |
| 3099 | host->max_clk = host->ops->get_max_clock(host); |
| 3100 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3101 | |
Haibo Chen | 348487c | 2014-12-09 17:04:05 +0800 | [diff] [blame] | 3102 | host->next_data.cookie = 1; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3103 | /* |
Arindam Nath | c3ed387 | 2011-05-05 12:19:06 +0530 | [diff] [blame] | 3104 | * In case of Host Controller v3.00, find out whether clock |
| 3105 | * multiplier is supported. |
| 3106 | */ |
| 3107 | host->clk_mul = (caps[1] & SDHCI_CLOCK_MUL_MASK) >> |
| 3108 | SDHCI_CLOCK_MUL_SHIFT; |
| 3109 | |
| 3110 | /* |
| 3111 | * In case the value in Clock Multiplier is 0, then programmable |
| 3112 | * clock mode is not supported, otherwise the actual clock |
| 3113 | * multiplier is one more than the value of Clock Multiplier |
| 3114 | * in the Capabilities Register. |
| 3115 | */ |
| 3116 | if (host->clk_mul) |
| 3117 | host->clk_mul += 1; |
| 3118 | |
| 3119 | /* |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3120 | * Set host parameters. |
| 3121 | */ |
| 3122 | mmc->ops = &sdhci_ops; |
Arindam Nath | c3ed387 | 2011-05-05 12:19:06 +0530 | [diff] [blame] | 3123 | mmc->f_max = host->max_clk; |
Marek Szyprowski | ce5f036 | 2010-08-10 18:01:56 -0700 | [diff] [blame] | 3124 | if (host->ops->get_min_clock) |
Anton Vorontsov | a9e58f2 | 2009-07-29 15:04:16 -0700 | [diff] [blame] | 3125 | mmc->f_min = host->ops->get_min_clock(host); |
Arindam Nath | c3ed387 | 2011-05-05 12:19:06 +0530 | [diff] [blame] | 3126 | else if (host->version >= SDHCI_SPEC_300) { |
| 3127 | if (host->clk_mul) { |
| 3128 | mmc->f_min = (host->max_clk * host->clk_mul) / 1024; |
| 3129 | mmc->f_max = host->max_clk * host->clk_mul; |
| 3130 | } else |
| 3131 | mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300; |
| 3132 | } else |
Zhangfei Gao | 0397526 | 2010-09-20 15:15:18 -0400 | [diff] [blame] | 3133 | mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200; |
Philip Rakity | 15ec446 | 2010-11-19 16:48:39 -0500 | [diff] [blame] | 3134 | |
Aisheng Dong | 28aab05 | 2014-08-27 15:26:31 +0800 | [diff] [blame] | 3135 | if (!(host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) { |
| 3136 | host->timeout_clk = (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >> |
| 3137 | SDHCI_TIMEOUT_CLK_SHIFT; |
| 3138 | if (host->timeout_clk == 0) { |
| 3139 | if (host->ops->get_timeout_clock) { |
| 3140 | host->timeout_clk = |
| 3141 | host->ops->get_timeout_clock(host); |
| 3142 | } else { |
| 3143 | pr_err("%s: Hardware doesn't specify timeout clock frequency.\n", |
| 3144 | mmc_hostname(mmc)); |
| 3145 | return -ENODEV; |
| 3146 | } |
Andy Shevchenko | 272308c | 2011-08-03 18:36:00 +0300 | [diff] [blame] | 3147 | } |
Andy Shevchenko | 272308c | 2011-08-03 18:36:00 +0300 | [diff] [blame] | 3148 | |
Aisheng Dong | 28aab05 | 2014-08-27 15:26:31 +0800 | [diff] [blame] | 3149 | if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT) |
| 3150 | host->timeout_clk *= 1000; |
Andy Shevchenko | 272308c | 2011-08-03 18:36:00 +0300 | [diff] [blame] | 3151 | |
Aisheng Dong | 28aab05 | 2014-08-27 15:26:31 +0800 | [diff] [blame] | 3152 | mmc->max_busy_timeout = host->ops->get_max_timeout_count ? |
Aisheng Dong | a6ff5ae | 2014-08-27 15:26:27 +0800 | [diff] [blame] | 3153 | host->ops->get_max_timeout_count(host) : 1 << 27; |
Aisheng Dong | 28aab05 | 2014-08-27 15:26:31 +0800 | [diff] [blame] | 3154 | mmc->max_busy_timeout /= host->timeout_clk; |
| 3155 | } |
Adrian Hunter | 58d1246 | 2011-06-28 17:16:03 +0300 | [diff] [blame] | 3156 | |
Adrian Hunter | f5fa92e | 2014-09-24 10:27:32 +0300 | [diff] [blame] | 3157 | if (override_timeout_clk) |
| 3158 | host->timeout_clk = override_timeout_clk; |
| 3159 | |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 3160 | mmc->caps |= MMC_CAP_SDIO_IRQ | MMC_CAP_ERASE | MMC_CAP_CMD23; |
Russell King | 781e989 | 2014-04-25 12:55:46 +0100 | [diff] [blame] | 3161 | mmc->caps2 |= MMC_CAP2_SDIO_IRQ_NOTHREAD; |
Andrei Warkentin | e89d456 | 2011-05-23 15:06:37 -0500 | [diff] [blame] | 3162 | |
| 3163 | if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) |
| 3164 | host->flags |= SDHCI_AUTO_CMD12; |
Anton Vorontsov | 5fe23c7 | 2009-06-18 00:14:08 +0400 | [diff] [blame] | 3165 | |
Andrei Warkentin | 8edf6371 | 2011-05-23 15:06:39 -0500 | [diff] [blame] | 3166 | /* Auto-CMD23 stuff only works in ADMA or PIO. */ |
Andrei Warkentin | 4f3d3e9 | 2011-05-25 10:42:50 -0400 | [diff] [blame] | 3167 | if ((host->version >= SDHCI_SPEC_300) && |
Andrei Warkentin | 8edf6371 | 2011-05-23 15:06:39 -0500 | [diff] [blame] | 3168 | ((host->flags & SDHCI_USE_ADMA) || |
Scott Branden | 3bfa6f0 | 2015-02-09 16:06:28 -0800 | [diff] [blame] | 3169 | !(host->flags & SDHCI_USE_SDMA)) && |
| 3170 | !(host->quirks2 & SDHCI_QUIRK2_ACMD23_BROKEN)) { |
Andrei Warkentin | 8edf6371 | 2011-05-23 15:06:39 -0500 | [diff] [blame] | 3171 | host->flags |= SDHCI_AUTO_CMD23; |
| 3172 | DBG("%s: Auto-CMD23 available\n", mmc_hostname(mmc)); |
| 3173 | } else { |
| 3174 | DBG("%s: Auto-CMD23 unavailable\n", mmc_hostname(mmc)); |
| 3175 | } |
| 3176 | |
Philip Rakity | 15ec446 | 2010-11-19 16:48:39 -0500 | [diff] [blame] | 3177 | /* |
| 3178 | * A controller may support 8-bit width, but the board itself |
| 3179 | * might not have the pins brought out. Boards that support |
| 3180 | * 8-bit width must set "mmc->caps |= MMC_CAP_8_BIT_DATA;" in |
| 3181 | * their platform code before calling sdhci_add_host(), and we |
| 3182 | * won't assume 8-bit width for hosts without that CAP. |
| 3183 | */ |
Anton Vorontsov | 5fe23c7 | 2009-06-18 00:14:08 +0400 | [diff] [blame] | 3184 | if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA)) |
Philip Rakity | 15ec446 | 2010-11-19 16:48:39 -0500 | [diff] [blame] | 3185 | mmc->caps |= MMC_CAP_4_BIT_DATA; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3186 | |
Jerry Huang | 63ef5d8 | 2012-10-25 13:47:19 +0800 | [diff] [blame] | 3187 | if (host->quirks2 & SDHCI_QUIRK2_HOST_NO_CMD23) |
| 3188 | mmc->caps &= ~MMC_CAP_CMD23; |
| 3189 | |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3190 | if (caps[0] & SDHCI_CAN_DO_HISPD) |
Zhangfei Gao | a29e7e1 | 2010-08-16 21:15:32 -0400 | [diff] [blame] | 3191 | mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; |
Pierre Ossman | cd9277c | 2007-02-18 12:07:47 +0100 | [diff] [blame] | 3192 | |
Jaehoon Chung | 176d1ed | 2010-09-27 09:42:20 +0100 | [diff] [blame] | 3193 | if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && |
Markus Mayer | 4e743f1 | 2014-07-03 13:27:42 -0700 | [diff] [blame] | 3194 | !(mmc->caps & MMC_CAP_NONREMOVABLE)) |
Anton Vorontsov | 68d1fb7 | 2009-03-17 00:13:52 +0300 | [diff] [blame] | 3195 | mmc->caps |= MMC_CAP_NEEDS_POLL; |
| 3196 | |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 3197 | /* If there are external regulators, get them */ |
| 3198 | if (mmc_regulator_get_supply(mmc) == -EPROBE_DEFER) |
| 3199 | return -EPROBE_DEFER; |
| 3200 | |
Philip Rakity | 6231f3d | 2012-07-23 15:56:23 -0700 | [diff] [blame] | 3201 | /* If vqmmc regulator and no 1.8V signalling, then there's no UHS */ |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 3202 | if (!IS_ERR(mmc->supply.vqmmc)) { |
| 3203 | ret = regulator_enable(mmc->supply.vqmmc); |
| 3204 | if (!regulator_is_supported_voltage(mmc->supply.vqmmc, 1700000, |
| 3205 | 1950000)) |
Kevin Liu | 8363c37 | 2012-11-17 17:55:51 -0500 | [diff] [blame] | 3206 | caps[1] &= ~(SDHCI_SUPPORT_SDR104 | |
| 3207 | SDHCI_SUPPORT_SDR50 | |
| 3208 | SDHCI_SUPPORT_DDR50); |
Chris Ball | a3361ab | 2013-03-11 17:51:53 -0400 | [diff] [blame] | 3209 | if (ret) { |
| 3210 | pr_warn("%s: Failed to enable vqmmc regulator: %d\n", |
| 3211 | mmc_hostname(mmc), ret); |
Adrian Hunter | 4bb7431 | 2014-11-06 15:19:04 +0200 | [diff] [blame] | 3212 | mmc->supply.vqmmc = ERR_PTR(-EINVAL); |
Chris Ball | a3361ab | 2013-03-11 17:51:53 -0400 | [diff] [blame] | 3213 | } |
Kevin Liu | 8363c37 | 2012-11-17 17:55:51 -0500 | [diff] [blame] | 3214 | } |
Philip Rakity | 6231f3d | 2012-07-23 15:56:23 -0700 | [diff] [blame] | 3215 | |
Daniel Drake | 6a66180 | 2012-11-25 13:01:19 -0500 | [diff] [blame] | 3216 | if (host->quirks2 & SDHCI_QUIRK2_NO_1_8_V) |
| 3217 | caps[1] &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | |
| 3218 | SDHCI_SUPPORT_DDR50); |
| 3219 | |
Al Cooper | 4188bba | 2012-03-16 15:54:17 -0400 | [diff] [blame] | 3220 | /* Any UHS-I mode in caps implies SDR12 and SDR25 support. */ |
| 3221 | if (caps[1] & (SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | |
| 3222 | SDHCI_SUPPORT_DDR50)) |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3223 | mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25; |
| 3224 | |
| 3225 | /* SDR104 supports also implies SDR50 support */ |
Giuseppe CAVALLARO | 156e14b | 2013-06-12 08:16:38 +0200 | [diff] [blame] | 3226 | if (caps[1] & SDHCI_SUPPORT_SDR104) { |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3227 | mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50; |
Giuseppe CAVALLARO | 156e14b | 2013-06-12 08:16:38 +0200 | [diff] [blame] | 3228 | /* SD3.0: SDR104 is supported so (for eMMC) the caps2 |
| 3229 | * field can be promoted to support HS200. |
| 3230 | */ |
Adrian Hunter | 549c0b1 | 2014-11-06 15:19:05 +0200 | [diff] [blame] | 3231 | if (!(host->quirks2 & SDHCI_QUIRK2_BROKEN_HS200)) |
David Cohen | 13868bf | 2013-10-29 10:58:26 -0700 | [diff] [blame] | 3232 | mmc->caps2 |= MMC_CAP2_HS200; |
Giuseppe CAVALLARO | 156e14b | 2013-06-12 08:16:38 +0200 | [diff] [blame] | 3233 | } else if (caps[1] & SDHCI_SUPPORT_SDR50) |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3234 | mmc->caps |= MMC_CAP_UHS_SDR50; |
| 3235 | |
Adrian Hunter | e9fb05d | 2014-11-06 15:19:06 +0200 | [diff] [blame] | 3236 | if (host->quirks2 & SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 && |
| 3237 | (caps[1] & SDHCI_SUPPORT_HS400)) |
| 3238 | mmc->caps2 |= MMC_CAP2_HS400; |
| 3239 | |
Adrian Hunter | 549c0b1 | 2014-11-06 15:19:05 +0200 | [diff] [blame] | 3240 | if ((mmc->caps2 & MMC_CAP2_HSX00_1_2V) && |
| 3241 | (IS_ERR(mmc->supply.vqmmc) || |
| 3242 | !regulator_is_supported_voltage(mmc->supply.vqmmc, 1100000, |
| 3243 | 1300000))) |
| 3244 | mmc->caps2 &= ~MMC_CAP2_HSX00_1_2V; |
| 3245 | |
Micky Ching | 9107ebb | 2014-02-21 18:40:35 +0800 | [diff] [blame] | 3246 | if ((caps[1] & SDHCI_SUPPORT_DDR50) && |
| 3247 | !(host->quirks2 & SDHCI_QUIRK2_BROKEN_DDR50)) |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3248 | mmc->caps |= MMC_CAP_UHS_DDR50; |
| 3249 | |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 3250 | /* Does the host need tuning for SDR50? */ |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 3251 | if (caps[1] & SDHCI_USE_SDR50_TUNING) |
| 3252 | host->flags |= SDHCI_SDR50_NEEDS_TUNING; |
| 3253 | |
Giuseppe CAVALLARO | 156e14b | 2013-06-12 08:16:38 +0200 | [diff] [blame] | 3254 | /* Does the host need tuning for SDR104 / HS200? */ |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 3255 | if (mmc->caps2 & MMC_CAP2_HS200) |
Giuseppe CAVALLARO | 156e14b | 2013-06-12 08:16:38 +0200 | [diff] [blame] | 3256 | host->flags |= SDHCI_SDR104_NEEDS_TUNING; |
Girish K S | 069c9f1 | 2012-01-06 09:56:39 +0530 | [diff] [blame] | 3257 | |
Arindam Nath | d6d50a1 | 2011-05-05 12:18:59 +0530 | [diff] [blame] | 3258 | /* Driver Type(s) (A, C, D) supported by the host */ |
| 3259 | if (caps[1] & SDHCI_DRIVER_TYPE_A) |
| 3260 | mmc->caps |= MMC_CAP_DRIVER_TYPE_A; |
| 3261 | if (caps[1] & SDHCI_DRIVER_TYPE_C) |
| 3262 | mmc->caps |= MMC_CAP_DRIVER_TYPE_C; |
| 3263 | if (caps[1] & SDHCI_DRIVER_TYPE_D) |
| 3264 | mmc->caps |= MMC_CAP_DRIVER_TYPE_D; |
| 3265 | |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 3266 | /* Initial value for re-tuning timer count */ |
| 3267 | host->tuning_count = (caps[1] & SDHCI_RETUNING_TIMER_COUNT_MASK) >> |
| 3268 | SDHCI_RETUNING_TIMER_COUNT_SHIFT; |
| 3269 | |
| 3270 | /* |
| 3271 | * In case Re-tuning Timer is not disabled, the actual value of |
| 3272 | * re-tuning timer will be 2 ^ (n - 1). |
| 3273 | */ |
| 3274 | if (host->tuning_count) |
| 3275 | host->tuning_count = 1 << (host->tuning_count - 1); |
| 3276 | |
| 3277 | /* Re-tuning mode supported by the Host Controller */ |
| 3278 | host->tuning_mode = (caps[1] & SDHCI_RETUNING_MODE_MASK) >> |
| 3279 | SDHCI_RETUNING_MODE_SHIFT; |
| 3280 | |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 3281 | ocr_avail = 0; |
Philip Rakity | bad37e1 | 2012-05-27 18:36:44 -0700 | [diff] [blame] | 3282 | |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3283 | /* |
| 3284 | * According to SD Host Controller spec v3.00, if the Host System |
| 3285 | * can afford more than 150mA, Host Driver should set XPC to 1. Also |
| 3286 | * the value is meaningful only if Voltage Support in the Capabilities |
| 3287 | * register is set. The actual current value is 4 times the register |
| 3288 | * value. |
| 3289 | */ |
| 3290 | max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT); |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 3291 | if (!max_current_caps && !IS_ERR(mmc->supply.vmmc)) { |
Chuanxiao.Dong | ae90603 | 2014-08-01 14:00:13 +0800 | [diff] [blame] | 3292 | int curr = regulator_get_current_limit(mmc->supply.vmmc); |
Philip Rakity | bad37e1 | 2012-05-27 18:36:44 -0700 | [diff] [blame] | 3293 | if (curr > 0) { |
| 3294 | |
| 3295 | /* convert to SDHCI_MAX_CURRENT format */ |
| 3296 | curr = curr/1000; /* convert to mA */ |
| 3297 | curr = curr/SDHCI_MAX_CURRENT_MULTIPLIER; |
| 3298 | |
| 3299 | curr = min_t(u32, curr, SDHCI_MAX_CURRENT_LIMIT); |
| 3300 | max_current_caps = |
| 3301 | (curr << SDHCI_MAX_CURRENT_330_SHIFT) | |
| 3302 | (curr << SDHCI_MAX_CURRENT_300_SHIFT) | |
| 3303 | (curr << SDHCI_MAX_CURRENT_180_SHIFT); |
| 3304 | } |
| 3305 | } |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3306 | |
| 3307 | if (caps[0] & SDHCI_CAN_VDD_330) { |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 3308 | ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34; |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3309 | |
Aaron Lu | 55c4665 | 2012-07-04 13:31:48 +0800 | [diff] [blame] | 3310 | mmc->max_current_330 = ((max_current_caps & |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3311 | SDHCI_MAX_CURRENT_330_MASK) >> |
| 3312 | SDHCI_MAX_CURRENT_330_SHIFT) * |
| 3313 | SDHCI_MAX_CURRENT_MULTIPLIER; |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3314 | } |
| 3315 | if (caps[0] & SDHCI_CAN_VDD_300) { |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 3316 | ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31; |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3317 | |
Aaron Lu | 55c4665 | 2012-07-04 13:31:48 +0800 | [diff] [blame] | 3318 | mmc->max_current_300 = ((max_current_caps & |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3319 | SDHCI_MAX_CURRENT_300_MASK) >> |
| 3320 | SDHCI_MAX_CURRENT_300_SHIFT) * |
| 3321 | SDHCI_MAX_CURRENT_MULTIPLIER; |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3322 | } |
| 3323 | if (caps[0] & SDHCI_CAN_VDD_180) { |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 3324 | ocr_avail |= MMC_VDD_165_195; |
| 3325 | |
Aaron Lu | 55c4665 | 2012-07-04 13:31:48 +0800 | [diff] [blame] | 3326 | mmc->max_current_180 = ((max_current_caps & |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3327 | SDHCI_MAX_CURRENT_180_MASK) >> |
| 3328 | SDHCI_MAX_CURRENT_180_SHIFT) * |
| 3329 | SDHCI_MAX_CURRENT_MULTIPLIER; |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3330 | } |
| 3331 | |
Tim Kryger | 5222161 | 2014-06-25 00:25:34 -0700 | [diff] [blame] | 3332 | /* If OCR set by external regulators, use it instead */ |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 3333 | if (mmc->ocr_avail) |
Tim Kryger | 5222161 | 2014-06-25 00:25:34 -0700 | [diff] [blame] | 3334 | ocr_avail = mmc->ocr_avail; |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 3335 | |
Haijun Zhang | c0b887b | 2013-08-26 09:19:23 +0800 | [diff] [blame] | 3336 | if (host->ocr_mask) |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 3337 | ocr_avail &= host->ocr_mask; |
Haijun Zhang | c0b887b | 2013-08-26 09:19:23 +0800 | [diff] [blame] | 3338 | |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 3339 | mmc->ocr_avail = ocr_avail; |
| 3340 | mmc->ocr_avail_sdio = ocr_avail; |
| 3341 | if (host->ocr_avail_sdio) |
| 3342 | mmc->ocr_avail_sdio &= host->ocr_avail_sdio; |
| 3343 | mmc->ocr_avail_sd = ocr_avail; |
| 3344 | if (host->ocr_avail_sd) |
| 3345 | mmc->ocr_avail_sd &= host->ocr_avail_sd; |
| 3346 | else /* normal SD controllers don't support 1.8V */ |
| 3347 | mmc->ocr_avail_sd &= ~MMC_VDD_165_195; |
| 3348 | mmc->ocr_avail_mmc = ocr_avail; |
| 3349 | if (host->ocr_avail_mmc) |
| 3350 | mmc->ocr_avail_mmc &= host->ocr_avail_mmc; |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 3351 | |
| 3352 | if (mmc->ocr_avail == 0) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 3353 | pr_err("%s: Hardware doesn't report any " |
Pierre Ossman | b69c905 | 2008-03-08 23:44:25 +0100 | [diff] [blame] | 3354 | "support voltages.\n", mmc_hostname(mmc)); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 3355 | return -ENODEV; |
Pierre Ossman | 146ad66 | 2006-06-30 02:22:23 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3358 | spin_lock_init(&host->lock); |
| 3359 | |
| 3360 | /* |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3361 | * Maximum number of segments. Depends on if the hardware |
| 3362 | * can do scatter/gather or not. |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3363 | */ |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3364 | if (host->flags & SDHCI_USE_ADMA) |
Adrian Hunter | 4fb213f | 2014-11-04 12:42:43 +0200 | [diff] [blame] | 3365 | mmc->max_segs = SDHCI_MAX_SEGS; |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 3366 | else if (host->flags & SDHCI_USE_SDMA) |
Martin K. Petersen | a36274e | 2010-09-10 01:33:59 -0400 | [diff] [blame] | 3367 | mmc->max_segs = 1; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3368 | else /* PIO */ |
Adrian Hunter | 4fb213f | 2014-11-04 12:42:43 +0200 | [diff] [blame] | 3369 | mmc->max_segs = SDHCI_MAX_SEGS; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3370 | |
| 3371 | /* |
Adrian Hunter | ac00531 | 2014-12-05 19:25:28 +0200 | [diff] [blame] | 3372 | * Maximum number of sectors in one transfer. Limited by SDMA boundary |
| 3373 | * size (512KiB). Note some tuning modes impose a 4MiB limit, but this |
| 3374 | * is less anyway. |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3375 | */ |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 3376 | mmc->max_req_size = 524288; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3377 | |
| 3378 | /* |
| 3379 | * Maximum segment size. Could be one segment with the maximum number |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3380 | * of bytes. When doing hardware scatter/gather, each entry cannot |
| 3381 | * be larger than 64 KiB though. |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3382 | */ |
Olof Johansson | 30652aa | 2011-01-01 18:37:32 -0600 | [diff] [blame] | 3383 | if (host->flags & SDHCI_USE_ADMA) { |
| 3384 | if (host->quirks & SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC) |
| 3385 | mmc->max_seg_size = 65535; |
| 3386 | else |
| 3387 | mmc->max_seg_size = 65536; |
| 3388 | } else { |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3389 | mmc->max_seg_size = mmc->max_req_size; |
Olof Johansson | 30652aa | 2011-01-01 18:37:32 -0600 | [diff] [blame] | 3390 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3391 | |
| 3392 | /* |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 3393 | * Maximum block size. This varies from controller to controller and |
| 3394 | * is specified in the capabilities register. |
| 3395 | */ |
Anton Vorontsov | 0633f65 | 2009-03-17 00:14:03 +0300 | [diff] [blame] | 3396 | if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) { |
| 3397 | mmc->max_blk_size = 2; |
| 3398 | } else { |
Arindam Nath | f2119df | 2011-05-05 12:18:57 +0530 | [diff] [blame] | 3399 | mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >> |
Anton Vorontsov | 0633f65 | 2009-03-17 00:14:03 +0300 | [diff] [blame] | 3400 | SDHCI_MAX_BLOCK_SHIFT; |
| 3401 | if (mmc->max_blk_size >= 3) { |
Joe Perches | 6606110 | 2014-09-12 14:56:56 -0700 | [diff] [blame] | 3402 | pr_warn("%s: Invalid maximum block size, assuming 512 bytes\n", |
| 3403 | mmc_hostname(mmc)); |
Anton Vorontsov | 0633f65 | 2009-03-17 00:14:03 +0300 | [diff] [blame] | 3404 | mmc->max_blk_size = 0; |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | mmc->max_blk_size = 512 << mmc->max_blk_size; |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 3409 | |
| 3410 | /* |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 3411 | * Maximum block count. |
| 3412 | */ |
Ben Dooks | 1388eef | 2009-06-14 12:40:53 +0100 | [diff] [blame] | 3413 | mmc->max_blk_count = (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535; |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 3414 | |
| 3415 | /* |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3416 | * Init tasklets. |
| 3417 | */ |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3418 | tasklet_init(&host->finish_tasklet, |
| 3419 | sdhci_tasklet_finish, (unsigned long)host); |
| 3420 | |
Al Viro | e4cad1b | 2006-10-10 22:47:07 +0100 | [diff] [blame] | 3421 | setup_timer(&host->timer, sdhci_timeout_timer, (unsigned long)host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3422 | |
Adrian Hunter | 250fb7b4 | 2014-12-05 19:41:10 +0200 | [diff] [blame] | 3423 | init_waitqueue_head(&host->buf_ready_int); |
Arindam Nath | b513ea2 | 2011-05-05 12:19:04 +0530 | [diff] [blame] | 3424 | |
Adrian Hunter | 250fb7b4 | 2014-12-05 19:41:10 +0200 | [diff] [blame] | 3425 | if (host->version >= SDHCI_SPEC_300) { |
Arindam Nath | cf2b5ee | 2011-05-05 12:19:07 +0530 | [diff] [blame] | 3426 | /* Initialize re-tuning timer */ |
| 3427 | init_timer(&host->tuning_timer); |
| 3428 | host->tuning_timer.data = (unsigned long)host; |
| 3429 | host->tuning_timer.function = sdhci_tuning_timer; |
| 3430 | } |
| 3431 | |
Shawn Guo | 2af502c | 2013-07-05 14:38:55 +0800 | [diff] [blame] | 3432 | sdhci_init(host, 0); |
| 3433 | |
Russell King | 781e989 | 2014-04-25 12:55:46 +0100 | [diff] [blame] | 3434 | ret = request_threaded_irq(host->irq, sdhci_irq, sdhci_thread_irq, |
| 3435 | IRQF_SHARED, mmc_hostname(mmc), host); |
Mark Brown | 0fc81ee | 2012-07-02 14:26:15 +0100 | [diff] [blame] | 3436 | if (ret) { |
| 3437 | pr_err("%s: Failed to request IRQ %d: %d\n", |
| 3438 | mmc_hostname(mmc), host->irq, ret); |
Pierre Ossman | 8ef1a14 | 2006-06-30 02:22:21 -0700 | [diff] [blame] | 3439 | goto untasklet; |
Mark Brown | 0fc81ee | 2012-07-02 14:26:15 +0100 | [diff] [blame] | 3440 | } |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3441 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3442 | #ifdef CONFIG_MMC_DEBUG |
| 3443 | sdhci_dumpregs(host); |
| 3444 | #endif |
| 3445 | |
Pierre Ossman | f913431 | 2008-12-21 17:01:48 +0100 | [diff] [blame] | 3446 | #ifdef SDHCI_USE_LEDS_CLASS |
Helmut Schaa | 5dbace0 | 2009-02-14 16:22:39 +0100 | [diff] [blame] | 3447 | snprintf(host->led_name, sizeof(host->led_name), |
| 3448 | "%s::", mmc_hostname(mmc)); |
| 3449 | host->led.name = host->led_name; |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 3450 | host->led.brightness = LED_OFF; |
| 3451 | host->led.default_trigger = mmc_hostname(mmc); |
| 3452 | host->led.brightness_set = sdhci_led_control; |
| 3453 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 3454 | ret = led_classdev_register(mmc_dev(mmc), &host->led); |
Mark Brown | 0fc81ee | 2012-07-02 14:26:15 +0100 | [diff] [blame] | 3455 | if (ret) { |
| 3456 | pr_err("%s: Failed to register LED device: %d\n", |
| 3457 | mmc_hostname(mmc), ret); |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 3458 | goto reset; |
Mark Brown | 0fc81ee | 2012-07-02 14:26:15 +0100 | [diff] [blame] | 3459 | } |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 3460 | #endif |
| 3461 | |
Pierre Ossman | 5f25a66 | 2006-10-04 02:15:39 -0700 | [diff] [blame] | 3462 | mmiowb(); |
| 3463 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3464 | mmc_add_host(mmc); |
| 3465 | |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 3466 | pr_info("%s: SDHCI controller on %s [%s] using %s\n", |
Kay Sievers | d1b2686 | 2008-11-08 21:37:46 +0100 | [diff] [blame] | 3467 | mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)), |
Adrian Hunter | e57a5f6 | 2014-11-04 12:42:46 +0200 | [diff] [blame] | 3468 | (host->flags & SDHCI_USE_ADMA) ? |
| 3469 | (host->flags & SDHCI_USE_64_BIT_DMA) ? "ADMA 64-bit" : "ADMA" : |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 3470 | (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO"); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3471 | |
Anton Vorontsov | 7260cf5 | 2009-03-17 00:13:48 +0300 | [diff] [blame] | 3472 | sdhci_enable_card_detection(host); |
| 3473 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3474 | return 0; |
| 3475 | |
Pierre Ossman | f913431 | 2008-12-21 17:01:48 +0100 | [diff] [blame] | 3476 | #ifdef SDHCI_USE_LEDS_CLASS |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 3477 | reset: |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 3478 | sdhci_do_reset(host, SDHCI_RESET_ALL); |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 3479 | sdhci_writel(host, 0, SDHCI_INT_ENABLE); |
| 3480 | sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 3481 | free_irq(host->irq, host); |
| 3482 | #endif |
Pierre Ossman | 8ef1a14 | 2006-06-30 02:22:21 -0700 | [diff] [blame] | 3483 | untasklet: |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3484 | tasklet_kill(&host->finish_tasklet); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3485 | |
| 3486 | return ret; |
| 3487 | } |
| 3488 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 3489 | EXPORT_SYMBOL_GPL(sdhci_add_host); |
| 3490 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 3491 | void sdhci_remove_host(struct sdhci_host *host, int dead) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3492 | { |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 3493 | struct mmc_host *mmc = host->mmc; |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 3494 | unsigned long flags; |
| 3495 | |
| 3496 | if (dead) { |
| 3497 | spin_lock_irqsave(&host->lock, flags); |
| 3498 | |
| 3499 | host->flags |= SDHCI_DEVICE_DEAD; |
| 3500 | |
| 3501 | if (host->mrq) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 3502 | pr_err("%s: Controller removed during " |
Markus Mayer | 4e743f1 | 2014-07-03 13:27:42 -0700 | [diff] [blame] | 3503 | " transfer!\n", mmc_hostname(mmc)); |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 3504 | |
| 3505 | host->mrq->cmd->error = -ENOMEDIUM; |
| 3506 | tasklet_schedule(&host->finish_tasklet); |
| 3507 | } |
| 3508 | |
| 3509 | spin_unlock_irqrestore(&host->lock, flags); |
| 3510 | } |
| 3511 | |
Anton Vorontsov | 7260cf5 | 2009-03-17 00:13:48 +0300 | [diff] [blame] | 3512 | sdhci_disable_card_detection(host); |
| 3513 | |
Markus Mayer | 4e743f1 | 2014-07-03 13:27:42 -0700 | [diff] [blame] | 3514 | mmc_remove_host(mmc); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3515 | |
Pierre Ossman | f913431 | 2008-12-21 17:01:48 +0100 | [diff] [blame] | 3516 | #ifdef SDHCI_USE_LEDS_CLASS |
Pierre Ossman | 2f730fe | 2008-03-17 10:29:38 +0100 | [diff] [blame] | 3517 | led_classdev_unregister(&host->led); |
| 3518 | #endif |
| 3519 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 3520 | if (!dead) |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 3521 | sdhci_do_reset(host, SDHCI_RESET_ALL); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3522 | |
Russell King | b537f94 | 2014-04-25 12:56:01 +0100 | [diff] [blame] | 3523 | sdhci_writel(host, 0, SDHCI_INT_ENABLE); |
| 3524 | sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3525 | free_irq(host->irq, host); |
| 3526 | |
| 3527 | del_timer_sync(&host->timer); |
| 3528 | |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3529 | tasklet_kill(&host->finish_tasklet); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3530 | |
Tim Kryger | 3a48edc | 2014-06-13 10:13:56 -0700 | [diff] [blame] | 3531 | if (!IS_ERR(mmc->supply.vqmmc)) |
| 3532 | regulator_disable(mmc->supply.vqmmc); |
Philip Rakity | 6231f3d | 2012-07-23 15:56:23 -0700 | [diff] [blame] | 3533 | |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 3534 | if (host->adma_table) |
Adrian Hunter | 76fe379 | 2014-11-04 12:42:42 +0200 | [diff] [blame] | 3535 | dma_free_coherent(mmc_dev(mmc), host->adma_table_sz, |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 3536 | host->adma_table, host->adma_addr); |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3537 | kfree(host->align_buffer); |
| 3538 | |
Adrian Hunter | 4efaa6f | 2014-11-04 12:42:39 +0200 | [diff] [blame] | 3539 | host->adma_table = NULL; |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 3540 | host->align_buffer = NULL; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3541 | } |
| 3542 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 3543 | EXPORT_SYMBOL_GPL(sdhci_remove_host); |
| 3544 | |
| 3545 | void sdhci_free_host(struct sdhci_host *host) |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3546 | { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 3547 | mmc_free_host(host->mmc); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3548 | } |
| 3549 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 3550 | EXPORT_SYMBOL_GPL(sdhci_free_host); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3551 | |
| 3552 | /*****************************************************************************\ |
| 3553 | * * |
| 3554 | * Driver init/exit * |
| 3555 | * * |
| 3556 | \*****************************************************************************/ |
| 3557 | |
| 3558 | static int __init sdhci_drv_init(void) |
| 3559 | { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 3560 | pr_info(DRIVER_NAME |
Pierre Ossman | 52fbf9c | 2007-02-09 08:23:41 +0100 | [diff] [blame] | 3561 | ": Secure Digital Host Controller Interface driver\n"); |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 3562 | pr_info(DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3563 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 3564 | return 0; |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | static void __exit sdhci_drv_exit(void) |
| 3568 | { |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3569 | } |
| 3570 | |
| 3571 | module_init(sdhci_drv_init); |
| 3572 | module_exit(sdhci_drv_exit); |
| 3573 | |
Pierre Ossman | df673b2 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 3574 | module_param(debug_quirks, uint, 0444); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 3575 | module_param(debug_quirks2, uint, 0444); |
Pierre Ossman | 6743527 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 3576 | |
Pierre Ossman | 32710e8 | 2009-04-08 20:14:54 +0200 | [diff] [blame] | 3577 | MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>"); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 3578 | MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver"); |
Pierre Ossman | d129bce | 2006-03-24 03:18:17 -0800 | [diff] [blame] | 3579 | MODULE_LICENSE("GPL"); |
Pierre Ossman | 6743527 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 3580 | |
Pierre Ossman | df673b2 | 2006-06-30 02:22:31 -0700 | [diff] [blame] | 3581 | MODULE_PARM_DESC(debug_quirks, "Force certain quirks."); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 3582 | MODULE_PARM_DESC(debug_quirks2, "Force certain other quirks."); |