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